diff --git a/src/server/game/Scripting/ScriptMgr.cpp b/src/server/game/Scripting/ScriptMgr.cpp index af25a8122..0d82d3225 100644 --- a/src/server/game/Scripting/ScriptMgr.cpp +++ b/src/server/game/Scripting/ScriptMgr.cpp @@ -65,103 +65,6 @@ template class ScriptRegistry; #include "ScriptMgrMacros.h" -// This is the global static registry of scripts. -/*template -class ScriptRegistry -{ - public: - - typedef std::map 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::GetScriptById(sid) && !ScriptRegistry::GetScriptById(sid) && !ScriptRegistry::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); } diff --git a/src/server/game/Scripting/ScriptMgr.h b/src/server/game/Scripting/ScriptMgr.h index ae002cc6d..67e7c7b76 100644 --- a/src/server/game/Scripting/ScriptMgr.h +++ b/src/server/game/Scripting/ScriptMgr.h @@ -469,11 +469,11 @@ public: class MovementHandlerScript : public ScriptObject { protected: - + MovementHandlerScript(const char* name); - + public: - + //Called whenever a player moves virtual void OnPlayerMove(Player* /*player*/, MovementInfo /*movementInfo*/, uint32 /*opcode*/) { } }; @@ -762,7 +762,7 @@ class AchievementCriteriaScript : public ScriptObject bool IsDatabaseBound() const { return true; } // Called when an additional criteria is checked. - virtual bool OnCheck(Player* source, Unit* target, uint32 /*criteria_id*/) { + virtual bool OnCheck(Player* source, Unit* target, uint32 /*criteria_id*/) { return OnCheck(source, target); } // deprecated/legacy @@ -777,7 +777,7 @@ class PlayerScript : public ScriptObject public: virtual void OnPlayerReleasedGhost(Player* /*player*/) { } - + // Called when a player completes a quest virtual void OnPlayerCompleteQuest(Player* /*player*/, Quest const* /*quest_id*/) { } @@ -921,7 +921,7 @@ class PlayerScript : public ScriptObject // To change behaviour of set visible item slot virtual void OnAfterSetVisibleItemSlot(Player* /*player*/, uint8 /*slot*/, Item* /*item*/) { } - + // After an item has been moved from inventory virtual void OnAfterMoveItemFromInventory(Player* /*player*/, Item* /*it*/, uint8 /*bag*/, uint8 /*slot*/, bool /*update*/) { } @@ -933,7 +933,7 @@ class PlayerScript : public ScriptObject // After player enters queue for Arena virtual void OnPlayerJoinArena(Player* /*player*/) { } - + //After looting item virtual void OnLootItem(Player* /*player*/, Item* /*item*/, uint32 /*count*/, uint64 /*lootguid*/) { } @@ -1079,7 +1079,7 @@ class GlobalScript : public ScriptObject // items virtual void OnItemDelFromDB(SQLTransaction& /*trans*/, uint32 /*itemGuid*/) { } virtual void OnMirrorImageDisplayItem(const Item* /*item*/, uint32& /*display*/) { } - + // loot virtual void OnAfterRefCount(Player const* /*player*/, LootStoreItem* /*LootStoreItem*/, Loot& /*loot*/, bool /*canRate*/, uint16 /*lootMode*/, uint32& /*maxcount*/, LootStore const& /*store*/) { } virtual void OnBeforeDropAddItem(Player const* /*player*/, Loot& /*loot*/, bool /*canRate*/, uint16 /*lootMode*/, LootStoreItem* /*LootStoreItem*/, LootStore const& /*store*/) { } @@ -1087,10 +1087,10 @@ class GlobalScript : public ScriptObject virtual void OnInitializeLockedDungeons(Player* /*player*/, uint8& /*level*/, uint32& /*lockData*/) { } virtual void OnAfterInitializeLockedDungeons(Player* /*player*/) { } - + // On Before arena points distribution virtual void OnBeforeUpdateArenaPoints(ArenaTeam* /*at*/, std::map & /*ap*/) { } - + // Called when a dungeon encounter is updated. virtual void OnAfterUpdateEncounterState(Map* /*map*/, EncounterCreditType /*type*/, uint32 /*creditEntry*/, Unit* /*source*/, Difficulty /*difficulty_fixed*/, DungeonEncounterList const* /*encounters*/, uint32 /*dungeonCompleted*/, bool /*updated*/) { } }; @@ -1145,7 +1145,7 @@ public: bool IsDatabaseBound() const { return false; } - // Calculate max duration in applying aura + // Calculate max duration in applying aura virtual void OnCalcMaxDuration(Aura const* /*aura*/, int32& /*maxDuration*/) { } }; @@ -1167,7 +1167,7 @@ protected: public: // Runs on start event virtual void OnStart(uint16 /*EventID*/) { } - + // Runs on stop event virtual void OnStop(uint16 /*EventID*/) { } }; @@ -1479,11 +1479,11 @@ class ScriptMgr uint32 DealDamage(Unit* AttackerUnit, Unit *pVictim, uint32 damage, DamageEffectType damagetype); void OnBeforeRollMeleeOutcomeAgainst(const Unit* attacker, const Unit* victim, WeaponAttackType attType, int32 &attackerMaxSkillValueForLevel, int32 &victimMaxSkillValueForLevel, int32 &attackerWeaponSkill, int32 &victimDefenseSkill, int32 &crit_chance, int32 &miss_chance, int32 &dodge_chance, int32 &parry_chance, int32 &block_chance); - + public: /* MovementHandlerScript */ - + void OnPlayerMove(Player* player, MovementInfo movementInfo, uint32 opcode); - + public: /* AllCreatureScript */ //listener function (OnAllCreatureUpdate) is called by OnCreatureUpdate @@ -1512,7 +1512,7 @@ class ScriptMgr bool CanSendMessageQueue(BattlegroundQueue* queue, Player* leader, Battleground* bg, PvPDifficultyEntry const* bracketEntry); public: /* SpellSC */ - + void OnCalcMaxDuration(Aura const* aura, int32& maxDuration); public: /* GameEventScript */ @@ -1606,7 +1606,7 @@ class ScriptRegistry 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.", + sLog->outError("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. @@ -1616,7 +1616,7 @@ class ScriptRegistry { // The script uses a script name from database, but isn't assigned to anything. if (script->GetName().find("Smart") == std::string::npos) - sLog->outErrorDb("Script named '%s' does not have a script name assigned in database.", + sLog->outErrorDb("Script named '%s' is not assigned in the database.", script->GetName().c_str()); } } else {