mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-15 18:10:26 +00:00
refactor(CORE/scripts): Clearer error when script unassigned or alrea… (#2576)
This commit is contained in:
@@ -65,103 +65,6 @@ template class ScriptRegistry<GameEventScript>;
|
||||
|
||||
#include "ScriptMgrMacros.h"
|
||||
|
||||
// This is the global static registry of scripts.
|
||||
/*template<class TScript>
|
||||
class ScriptRegistry
|
||||
{
|
||||
public:
|
||||
|
||||
typedef std::map<uint32, TScript*> ScriptMap;
|
||||
typedef typename ScriptMap::iterator ScriptMapIterator;
|
||||
|
||||
// The actual list of scripts. This will be accessed concurrently, so it must not be modified
|
||||
// after server startup.
|
||||
static ScriptMap ScriptPointerList;
|
||||
|
||||
static void AddScript(TScript* const script)
|
||||
{
|
||||
ASSERT(script);
|
||||
|
||||
// See if the script is using the same memory as another script. If this happens, it means that
|
||||
// someone forgot to allocate new memory for a script.
|
||||
for (ScriptMapIterator it = ScriptPointerList.begin(); it != ScriptPointerList.end(); ++it)
|
||||
{
|
||||
if (it->second == script)
|
||||
{
|
||||
sLog->outError("Script '%s' has same memory pointer as '%s'.",
|
||||
script->GetName().c_str(), it->second->GetName().c_str());
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (script->IsDatabaseBound())
|
||||
{
|
||||
// Get an ID for the script. An ID only exists if it's a script that is assigned in the database
|
||||
// through a script name (or similar).
|
||||
uint32 id = sObjectMgr->GetScriptId(script->GetName().c_str());
|
||||
if (id)
|
||||
{
|
||||
// Try to find an existing script.
|
||||
bool existing = false;
|
||||
for (ScriptMapIterator it = ScriptPointerList.begin(); it != ScriptPointerList.end(); ++it)
|
||||
{
|
||||
// If the script names match...
|
||||
if (it->second->GetName() == script->GetName())
|
||||
{
|
||||
// ... It exists.
|
||||
existing = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// If the script isn't assigned -> assign it!
|
||||
if (!existing)
|
||||
{
|
||||
ScriptPointerList[id] = script;
|
||||
sScriptMgr->IncrementScriptCount();
|
||||
}
|
||||
else
|
||||
{
|
||||
// If the script is already assigned -> delete it!
|
||||
sLog->outError("Script '%s' already assigned with the same script name, so the script can't work.",
|
||||
script->GetName().c_str());
|
||||
|
||||
ABORT(); // Error that should be fixed ASAP.
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// The script uses a script name from database, but isn't assigned to anything.
|
||||
if (script->GetName().find("example") == std::string::npos && script->GetName().find("Smart") == std::string::npos)
|
||||
sLog->outErrorDb("Script named '%s' does not have a script name assigned in database.",
|
||||
script->GetName().c_str());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// We're dealing with a code-only script; just add it.
|
||||
ScriptPointerList[_scriptIdCounter++] = script;
|
||||
sScriptMgr->IncrementScriptCount();
|
||||
}
|
||||
}
|
||||
|
||||
// Gets a script by its ID (assigned by ObjectMgr).
|
||||
static TScript* GetScriptById(uint32 id)
|
||||
{
|
||||
ScriptMapIterator it = ScriptPointerList.find(id);
|
||||
if (it != ScriptPointerList.end())
|
||||
return it->second;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
// Counter used for code-only scripts.
|
||||
static uint32 _scriptIdCounter;
|
||||
};*/
|
||||
|
||||
ScriptMgr::ScriptMgr()
|
||||
: _scriptCount(0), _scheduledScripts(0)
|
||||
{
|
||||
@@ -294,7 +197,7 @@ void ScriptMgr::CheckIfScriptsInDatabaseExist()
|
||||
!ScriptRegistry<BGScript>::GetScriptById(sid) &&
|
||||
!ScriptRegistry<SpellSC>::GetScriptById(sid) &&
|
||||
!ScriptRegistry<GroupScript>::GetScriptById(sid))
|
||||
sLog->outErrorDb("Script named '%s' is assigned in database, but has no code!", (*itr).c_str());
|
||||
sLog->outErrorDb("Script named '%s' is assigned in the database, but has no code!", (*itr).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -714,7 +617,7 @@ void ScriptMgr::OnPlayerLeaveMap(Map* map, Player* player)
|
||||
#endif
|
||||
|
||||
FOREACH_SCRIPT(AllMapScript)->OnPlayerLeaveAll(map, player);
|
||||
|
||||
|
||||
SCR_MAP_BGN(WorldMapScript, map, itr, end, entry, IsWorldMap);
|
||||
itr->second->OnPlayerLeave(map, player);
|
||||
SCR_MAP_END;
|
||||
@@ -1964,7 +1867,7 @@ void ScriptMgr::OnAfterInitializeLockedDungeons(Player* player)
|
||||
FOREACH_SCRIPT(GlobalScript)->OnAfterInitializeLockedDungeons(player);
|
||||
}
|
||||
|
||||
void ScriptMgr::OnAfterUpdateEncounterState(Map* map, EncounterCreditType type, uint32 creditEntry, Unit* source, Difficulty difficulty_fixed, DungeonEncounterList const* encounters, uint32 dungeonCompleted, bool updated)
|
||||
void ScriptMgr::OnAfterUpdateEncounterState(Map* map, EncounterCreditType type, uint32 creditEntry, Unit* source, Difficulty difficulty_fixed, DungeonEncounterList const* encounters, uint32 dungeonCompleted, bool updated)
|
||||
{
|
||||
FOREACH_SCRIPT(GlobalScript)->OnAfterUpdateEncounterState(map, type, creditEntry, source, difficulty_fixed, encounters, dungeonCompleted, updated);
|
||||
}
|
||||
@@ -2024,7 +1927,7 @@ void ScriptMgr::OnBeforeBuyItemFromVendor(Player* player, uint64 vendorguid, uin
|
||||
FOREACH_SCRIPT(PlayerScript)->OnBeforeBuyItemFromVendor(player, vendorguid, vendorslot, item, count, bag, slot);
|
||||
}
|
||||
|
||||
void ScriptMgr::OnAfterStoreOrEquipNewItem(Player* player, uint32 vendorslot, uint32 &item, uint8 count, uint8 bag, uint8 slot, ItemTemplate const* pProto, Creature* pVendor, VendorItem const* crItem, bool bStore)
|
||||
void ScriptMgr::OnAfterStoreOrEquipNewItem(Player* player, uint32 vendorslot, uint32 &item, uint8 count, uint8 bag, uint8 slot, ItemTemplate const* pProto, Creature* pVendor, VendorItem const* crItem, bool bStore)
|
||||
{
|
||||
FOREACH_SCRIPT(PlayerScript)->OnAfterStoreOrEquipNewItem(player, vendorslot, item, count, bag, slot, pProto, pVendor, crItem, bStore);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user