diff options
author | Aokromes <aokromes@gmail.com> | 2017-03-26 13:32:28 +0200 |
---|---|---|
committer | Aokromes <aokromes@gmail.com> | 2017-03-26 13:32:28 +0200 |
commit | 0999ef0b774f2c93beefa6329d1a42a13377a35b (patch) | |
tree | 86293ced1ccfbb75d7a422e81b478ac83ef2edc6 | |
parent | de4043097e31d7ba968425f0a2ec55a9a1e5b117 (diff) |
Core/Scripts: Add support for spawn specific C++ scripts
By Krudor
-rw-r--r-- | sql/updates/world/3.3.5/2017_03_26_04_world.sql | 5 | ||||
-rw-r--r-- | src/server/game/Entities/Creature/Creature.cpp | 5 | ||||
-rw-r--r-- | src/server/game/Entities/Creature/Creature.h | 1 | ||||
-rw-r--r-- | src/server/game/Entities/GameObject/GameObject.cpp | 8 | ||||
-rw-r--r-- | src/server/game/Entities/GameObject/GameObject.h | 3 | ||||
-rw-r--r-- | src/server/game/Globals/ObjectMgr.cpp | 19 | ||||
-rw-r--r-- | src/server/game/Handlers/MiscHandler.cpp | 6 | ||||
-rw-r--r-- | src/server/game/Scripting/ScriptMgr.cpp | 2 |
8 files changed, 41 insertions, 8 deletions
diff --git a/sql/updates/world/3.3.5/2017_03_26_04_world.sql b/sql/updates/world/3.3.5/2017_03_26_04_world.sql new file mode 100644 index 00000000000..83b2ae9a0d2 --- /dev/null +++ b/sql/updates/world/3.3.5/2017_03_26_04_world.sql @@ -0,0 +1,5 @@ +-- +ALTER TABLE `creature` ADD COLUMN `ScriptName` CHAR(64) NULL DEFAULT '' AFTER `dynamicflags`; +ALTER TABLE `gameobject` ADD COLUMN `ScriptName` CHAR(64) NULL DEFAULT '' AFTER `state`; +-- + diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp index 952f0be0d19..51807373822 100644 --- a/src/server/game/Entities/Creature/Creature.cpp +++ b/src/server/game/Entities/Creature/Creature.cpp @@ -1013,7 +1013,7 @@ bool Creature::Create(ObjectGuid::LowType guidlow, Map* map, uint32 phaseMask, u Relocate(x, y, z, ang); } - LastUsedScriptID = GetCreatureTemplate()->ScriptID; + LastUsedScriptID = GetScriptId(); /// @todo Replace with spell, handle from DB if (IsSpiritHealer() || IsSpiritGuide()) @@ -2591,6 +2591,9 @@ std::string Creature::GetScriptName() const uint32 Creature::GetScriptId() const { + if (CreatureData const* creatureData = GetCreatureData()) + return creatureData->ScriptId; + return sObjectMgr->GetCreatureTemplate(GetEntry())->ScriptID; } diff --git a/src/server/game/Entities/Creature/Creature.h b/src/server/game/Entities/Creature/Creature.h index 1fc9833e376..dcffc7e0051 100644 --- a/src/server/game/Entities/Creature/Creature.h +++ b/src/server/game/Entities/Creature/Creature.h @@ -281,6 +281,7 @@ struct CreatureData uint32 npcflag; uint32 unit_flags; // enum UnitFlags mask values uint32 dynamicflags; + uint32 ScriptId; bool dbData; }; diff --git a/src/server/game/Entities/GameObject/GameObject.cpp b/src/server/game/Entities/GameObject/GameObject.cpp index 1e5e2a32458..d399de52cdf 100644 --- a/src/server/game/Entities/GameObject/GameObject.cpp +++ b/src/server/game/Entities/GameObject/GameObject.cpp @@ -1954,6 +1954,14 @@ void GameObject::EventInform(uint32 eventId, WorldObject* invoker /*= nullptr*/) bgMap->GetBG()->ProcessEvent(this, eventId, invoker); } +uint32 GameObject::GetScriptId() const +{ + if (GameObjectData const* gameObjectData = GetGOData()) + return gameObjectData->ScriptId; + + return GetGOInfo()->ScriptId; +} + // overwrite WorldObject function for proper name localization std::string const & GameObject::GetNameForLocaleIdx(LocaleConstant loc_idx) const { diff --git a/src/server/game/Entities/GameObject/GameObject.h b/src/server/game/Entities/GameObject/GameObject.h index bad48e0693d..26982066af9 100644 --- a/src/server/game/Entities/GameObject/GameObject.h +++ b/src/server/game/Entities/GameObject/GameObject.h @@ -654,6 +654,7 @@ struct GameObjectData GOState go_state; uint8 spawnMask; uint8 artKit; + uint32 ScriptId; bool dbData; }; @@ -872,7 +873,7 @@ class TC_GAME_API GameObject : public WorldObject, public GridObject<GameObject> void EventInform(uint32 eventId, WorldObject* invoker = NULL); - virtual uint32 GetScriptId() const { return GetGOInfo()->ScriptId; } + virtual uint32 GetScriptId() const; GameObjectAI* AI() const { return m_AI; } std::string GetAIName() const; diff --git a/src/server/game/Globals/ObjectMgr.cpp b/src/server/game/Globals/ObjectMgr.cpp index 43681910ac0..c847305173d 100644 --- a/src/server/game/Globals/ObjectMgr.cpp +++ b/src/server/game/Globals/ObjectMgr.cpp @@ -1735,7 +1735,9 @@ void ObjectMgr::LoadCreatures() // 0 1 2 3 4 5 6 7 8 9 10 QueryResult result = WorldDatabase.Query("SELECT creature.guid, id, map, modelid, equipment_id, position_x, position_y, position_z, orientation, spawntimesecs, spawndist, " // 11 12 13 14 15 16 17 18 19 20 21 - "currentwaypoint, curhealth, curmana, MovementType, spawnMask, phaseMask, eventEntry, pool_entry, creature.npcflag, creature.unit_flags, creature.dynamicflags " + "currentwaypoint, curhealth, curmana, MovementType, spawnMask, phaseMask, eventEntry, pool_entry, creature.npcflag, creature.unit_flags, creature.dynamicflags, " + // 22 + "creature.ScriptName " "FROM creature " "LEFT OUTER JOIN game_event_creature ON creature.guid = game_event_creature.guid " "LEFT OUTER JOIN pool_creature ON creature.guid = pool_creature.guid"); @@ -1792,6 +1794,9 @@ void ObjectMgr::LoadCreatures() data.npcflag = fields[19].GetUInt32(); data.unit_flags = fields[20].GetUInt32(); data.dynamicflags = fields[21].GetUInt32(); + data.ScriptId = GetScriptId(fields[23].GetString()); + if (!data.ScriptId) + data.ScriptId = cInfo->ScriptID; MapEntry const* mapEntry = sMapStore.LookupEntry(data.mapid); if (!mapEntry) @@ -2030,7 +2035,9 @@ void ObjectMgr::LoadGameobjects() // 0 1 2 3 4 5 6 QueryResult result = WorldDatabase.Query("SELECT gameobject.guid, id, map, position_x, position_y, position_z, orientation, " // 7 8 9 10 11 12 13 14 15 16 17 - "rotation0, rotation1, rotation2, rotation3, spawntimesecs, animprogress, state, spawnMask, phaseMask, eventEntry, pool_entry " + "rotation0, rotation1, rotation2, rotation3, spawntimesecs, animprogress, state, spawnMask, phaseMask, eventEntry, pool_entry, " + // 18 + "ScriptName " "FROM gameobject LEFT OUTER JOIN game_event_gameobject ON gameobject.guid = game_event_gameobject.guid " "LEFT OUTER JOIN pool_gameobject ON gameobject.guid = pool_gameobject.guid"); @@ -2129,6 +2136,10 @@ void ObjectMgr::LoadGameobjects() int16 gameEvent = fields[16].GetInt8(); uint32 PoolId = fields[17].GetUInt32(); + data.ScriptId = GetScriptId(fields[19].GetString()); + if (!data.ScriptId) + data.ScriptId = gInfo->ScriptId; + if (std::abs(data.orientation) > 2 * float(M_PI)) { TC_LOG_ERROR("sql.sql", "Table `gameobject` has gameobject (GUID: %u Entry: %u) with abs(`orientation`) > 2*PI (orientation is expressed in radians), normalized.", guid, data.id); @@ -8654,8 +8665,12 @@ void ObjectMgr::LoadScriptNames() "UNION " "SELECT DISTINCT(ScriptName) FROM battleground_template WHERE ScriptName <> '' " "UNION " + "SELECT DISTINCT(ScriptName) FROM creature WHERE ScriptName <> '' " + "UNION " "SELECT DISTINCT(ScriptName) FROM creature_template WHERE ScriptName <> '' " "UNION " + "SELECT DISTINCT(ScriptName) FROM gameobject WHERE ScriptName <> '' " + "UNION " "SELECT DISTINCT(ScriptName) FROM gameobject_template WHERE ScriptName <> '' " "UNION " "SELECT DISTINCT(ScriptName) FROM item_template WHERE ScriptName <> '' " diff --git a/src/server/game/Handlers/MiscHandler.cpp b/src/server/game/Handlers/MiscHandler.cpp index 3f408be545a..e360493cd89 100644 --- a/src/server/game/Handlers/MiscHandler.cpp +++ b/src/server/game/Handlers/MiscHandler.cpp @@ -132,13 +132,13 @@ void WorldSession::HandleGossipSelectOptionOpcode(WorldPacket& recvData) if (GetPlayer()->HasUnitState(UNIT_STATE_DIED)) GetPlayer()->RemoveAurasByType(SPELL_AURA_FEIGN_DEATH); - if ((unit && unit->GetCreatureTemplate()->ScriptID != unit->LastUsedScriptID) || (go && go->GetGOInfo()->ScriptId != go->LastUsedScriptID)) + if ((unit && unit->GetScriptId() != unit->LastUsedScriptID) || (go && go->GetScriptId() != go->LastUsedScriptID)) { TC_LOG_DEBUG("network", "WORLD: HandleGossipSelectOptionOpcode - Script reloaded while in use, ignoring and set new scipt id"); if (unit) - unit->LastUsedScriptID = unit->GetCreatureTemplate()->ScriptID; + unit->LastUsedScriptID = unit->GetScriptId(); if (go) - go->LastUsedScriptID = go->GetGOInfo()->ScriptId; + go->LastUsedScriptID = go->GetScriptId(); _player->PlayerTalkClass->SendCloseGossip(); return; } diff --git a/src/server/game/Scripting/ScriptMgr.cpp b/src/server/game/Scripting/ScriptMgr.cpp index 3e19033ef1d..fa2c23c978e 100644 --- a/src/server/game/Scripting/ScriptMgr.cpp +++ b/src/server/game/Scripting/ScriptMgr.cpp @@ -1658,7 +1658,7 @@ bool ScriptMgr::CanSpawn(ObjectGuid::LowType spawnId, uint32 entry, CreatureTemp CreatureTemplate const* baseTemplate = sObjectMgr->GetCreatureTemplate(entry); if (!baseTemplate) baseTemplate = actTemplate; - GET_SCRIPT_RET(CreatureScript, baseTemplate->ScriptID, tmpscript, true); + GET_SCRIPT_RET(CreatureScript, (cData ? cData->ScriptId : baseTemplate->ScriptID), tmpscript, true); return tmpscript->CanSpawn(spawnId, entry, baseTemplate, actTemplate, cData, map); } |