mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-15 18:10:26 +00:00
feat(Core/Modules): Preparation to implement progression-system module. (#8837)
This commit is contained in:
@@ -117,6 +117,7 @@ void ScriptMgr::Unload()
|
||||
SCR_CLEAR(PetScript);
|
||||
SCR_CLEAR(ArenaScript);
|
||||
SCR_CLEAR(CommandSC);
|
||||
SCR_CLEAR(DatabaseScript);
|
||||
|
||||
#undef SCR_CLEAR
|
||||
|
||||
@@ -190,7 +191,8 @@ void ScriptMgr::CheckIfScriptsInDatabaseExist()
|
||||
!ScriptRegistry<PetScript>::GetScriptById(sid) &&
|
||||
!ScriptRegistry<CommandSC>::GetScriptById(sid) &&
|
||||
!ScriptRegistry<ArenaScript>::GetScriptById(sid) &&
|
||||
!ScriptRegistry<GroupScript>::GetScriptById(sid))
|
||||
!ScriptRegistry<GroupScript>::GetScriptById(sid) &&
|
||||
!ScriptRegistry<DatabaseScript>::GetScriptById(sid))
|
||||
{
|
||||
LOG_ERROR("sql.sql", "Script named '%s' is assigned in the database, but has no code!", scriptName.c_str());
|
||||
}
|
||||
@@ -3148,6 +3150,11 @@ void ScriptMgr::OnHandleDevCommand(Player* player, std::string& argstr)
|
||||
FOREACH_SCRIPT(CommandSC)->OnHandleDevCommand(player, argstr);
|
||||
}
|
||||
|
||||
void ScriptMgr::OnAfterDatabasesLoaded(uint32 updateFlags)
|
||||
{
|
||||
FOREACH_SCRIPT(DatabaseScript)->OnAfterDatabasesLoaded(updateFlags);
|
||||
}
|
||||
|
||||
///-
|
||||
AllMapScript::AllMapScript(const char* name)
|
||||
: ScriptObject(name)
|
||||
@@ -3426,6 +3433,11 @@ CommandSC::CommandSC(const char* name)
|
||||
ScriptRegistry<CommandSC>::AddScript(this);
|
||||
}
|
||||
|
||||
DatabaseScript::DatabaseScript(const char* name) : ScriptObject(name)
|
||||
{
|
||||
ScriptRegistry<DatabaseScript>::AddScript(this);
|
||||
}
|
||||
|
||||
// Specialize for each script type class like so:
|
||||
template class ScriptRegistry<SpellScriptLoader>;
|
||||
template class ScriptRegistry<ServerScript>;
|
||||
@@ -3467,3 +3479,4 @@ template class ScriptRegistry<MiscScript>;
|
||||
template class ScriptRegistry<PetScript>;
|
||||
template class ScriptRegistry<ArenaScript>;
|
||||
template class ScriptRegistry<CommandSC>;
|
||||
template class ScriptRegistry<DatabaseScript>;
|
||||
|
||||
@@ -1453,7 +1453,20 @@ public:
|
||||
|
||||
bool IsDatabaseBound() const { return false; }
|
||||
|
||||
virtual void OnHandleDevCommand(Player* /*player*/, std::string& /*argstr*/) { }
|
||||
virtual void OnHandleDevCommand(Player* /*player*/, std::string& /*argstr*/) { }
|
||||
};
|
||||
|
||||
class DatabaseScript : public ScriptObject
|
||||
{
|
||||
protected:
|
||||
|
||||
DatabaseScript(const char* name);
|
||||
|
||||
public:
|
||||
|
||||
bool IsDatabaseBound() const { return false; }
|
||||
|
||||
virtual void OnAfterDatabasesLoaded(uint32 /*updateFlags*/) {}
|
||||
};
|
||||
|
||||
// Manages registration, loading, and execution of scripts.
|
||||
@@ -1938,6 +1951,10 @@ public: /* AchievementScript */
|
||||
|
||||
void OnHandleDevCommand(Player* player, std::string& argstr);
|
||||
|
||||
public: /* DatabaseScript */
|
||||
|
||||
void OnAfterDatabasesLoaded(uint32 updateFlags);
|
||||
|
||||
private:
|
||||
uint32 _scriptCount;
|
||||
|
||||
@@ -2007,31 +2024,31 @@ public:
|
||||
if (id)
|
||||
{
|
||||
// Try to find an existing script.
|
||||
bool existing = false;
|
||||
TScript const* oldScript = nullptr;
|
||||
for (auto iterator = ScriptPointerList.begin(); iterator != ScriptPointerList.end(); ++iterator)
|
||||
{
|
||||
// If the script names match...
|
||||
if (iterator->second->GetName() == script->GetName())
|
||||
{
|
||||
// ... It exists.
|
||||
existing = true;
|
||||
oldScript = iterator->second;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// If the script isn't assigned -> assign it!
|
||||
if (!existing)
|
||||
// If the script is already assigned -> delete it!
|
||||
if (oldScript)
|
||||
{
|
||||
ScriptPointerList[id] = script;
|
||||
sScriptMgr->IncrementScriptCount();
|
||||
delete oldScript;
|
||||
}
|
||||
else
|
||||
{
|
||||
// If the script is already assigned -> delete it!
|
||||
LOG_ERROR("scripts", "Script named '%s' is already assigned (two or more scripts have the same name), so the script can't work, aborting...",
|
||||
script->GetName().c_str());
|
||||
|
||||
ABORT(); // Error that should be fixed ASAP.
|
||||
// Assign new script!
|
||||
ScriptPointerList[id] = script;
|
||||
|
||||
// Increment script count only with new scripts
|
||||
if (!oldScript)
|
||||
{
|
||||
sScriptMgr->IncrementScriptCount();
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user