aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKrudor <erikstrandberg93@hotmail.com>2017-03-18 11:31:31 +0100
committerShauren <shauren.trinity@gmail.com>2017-03-18 11:31:31 +0100
commit5a36a2eb17aeec937b4375f341239fdb9dce5fda (patch)
treeeac8a498a243fa145877636402f8bf86528a7cfb /src
parent0a35c473c8df41ec5e0699873e0746700eeb6b41 (diff)
Core/Scripts: Add support for spawn specific C++ scripts
Closes #19247
Diffstat (limited to 'src')
-rw-r--r--src/server/game/Entities/Creature/Creature.cpp5
-rw-r--r--src/server/game/Entities/Creature/Creature.h1
-rw-r--r--src/server/game/Entities/GameObject/GameObject.cpp8
-rw-r--r--src/server/game/Entities/GameObject/GameObject.h3
-rw-r--r--src/server/game/Globals/ObjectMgr.cpp23
-rw-r--r--src/server/game/Handlers/NPCHandler.cpp6
-rw-r--r--src/server/game/Scripting/ScriptMgr.cpp2
7 files changed, 38 insertions, 10 deletions
diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp
index 68c0065095b..3d6c0a25740 100644
--- a/src/server/game/Entities/Creature/Creature.cpp
+++ b/src/server/game/Entities/Creature/Creature.cpp
@@ -936,7 +936,7 @@ bool Creature::Create(ObjectGuid::LowType guidlow, Map* map, uint32 /*phaseMask*
SetByteValue(UNIT_FIELD_BYTES_0, UNIT_BYTES_0_OFFSET_GENDER, minfo->gender);
}
- LastUsedScriptID = GetCreatureTemplate()->ScriptID;
+ LastUsedScriptID = GetScriptId();
/// @todo Replace with spell, handle from DB
if (IsSpiritHealer() || IsSpiritGuide())
@@ -2500,6 +2500,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 8bcebd60bf7..d5cebc6bd06 100644
--- a/src/server/game/Entities/Creature/Creature.h
+++ b/src/server/game/Entities/Creature/Creature.h
@@ -543,6 +543,7 @@ struct CreatureData
uint32 dynamicflags;
uint32 phaseid;
uint32 phaseGroup;
+ uint32 ScriptId;
bool dbData;
};
diff --git a/src/server/game/Entities/GameObject/GameObject.cpp b/src/server/game/Entities/GameObject/GameObject.cpp
index d5931dc1718..e2dfed4fb8c 100644
--- a/src/server/game/Entities/GameObject/GameObject.cpp
+++ b/src/server/game/Entities/GameObject/GameObject.cpp
@@ -1988,6 +1988,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 0e22c841022..7e265ebf2cd 100644
--- a/src/server/game/Entities/GameObject/GameObject.h
+++ b/src/server/game/Entities/GameObject/GameObject.h
@@ -913,6 +913,7 @@ struct GameObjectData
uint8 artKit;
uint32 phaseid;
uint32 phaseGroup;
+ uint32 ScriptId;
bool dbData;
};
@@ -1124,7 +1125,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 c07f6bd83bf..a6ddfc172fa 100644
--- a/src/server/game/Globals/ObjectMgr.cpp
+++ b/src/server/game/Globals/ObjectMgr.cpp
@@ -1843,8 +1843,10 @@ 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 22
- "currentwaypoint, curhealth, curmana, MovementType, spawnMask, eventEntry, pool_entry, creature.npcflag, creature.unit_flags, creature.dynamicflags, creature.phaseid, creature.phasegroup "
+ // 11 12 13 14 15 16 17 18 19 20 21
+ "currentwaypoint, curhealth, curmana, MovementType, spawnMask, eventEntry, pool_entry, creature.npcflag, creature.unit_flags, creature.dynamicflags, creature.phaseid, "
+ // 22 23
+ "creature.phasegroup, 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");
@@ -1901,6 +1903,9 @@ void ObjectMgr::LoadCreatures()
data.dynamicflags = fields[20].GetUInt32();
data.phaseid = fields[21].GetUInt32();
data.phaseGroup = fields[22].GetUInt32();
+ data.ScriptId = GetScriptId(fields[23].GetString());
+ if (!data.ScriptId)
+ data.ScriptId = cInfo->ScriptID;
MapEntry const* mapEntry = sMapStore.LookupEntry(data.mapid);
if (!mapEntry)
@@ -2172,8 +2177,10 @@ 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 18
- "rotation0, rotation1, rotation2, rotation3, spawntimesecs, animprogress, state, spawnMask, eventEntry, pool_entry, phaseid, phasegroup "
+ // 7 8 9 10 11 12 13 14 15 16
+ "rotation0, rotation1, rotation2, rotation3, spawntimesecs, animprogress, state, spawnMask, eventEntry, pool_entry, "
+ // 17 18 19
+ "phaseid, phasegroup, 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");
@@ -2314,6 +2321,10 @@ void ObjectMgr::LoadGameobjects()
}
}
+ 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: " UI64FMTD " Entry: %u) with abs(`orientation`) > 2*PI (orientation is expressed in radians), normalized.", guid, data.id);
@@ -8851,10 +8862,14 @@ void ObjectMgr::LoadScriptNames()
QueryResult result = WorldDatabase.Query(
"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 criteria_data WHERE ScriptName <> '' AND type = 11 "
"UNION "
+ "SELECT DISTINCT(ScriptName) FROM gameobject WHERE ScriptName <> '' "
+ "UNION "
"SELECT DISTINCT(ScriptName) FROM gameobject_template WHERE ScriptName <> '' "
"UNION "
"SELECT DISTINCT(ScriptName) FROM item_script_names WHERE ScriptName <> '' "
diff --git a/src/server/game/Handlers/NPCHandler.cpp b/src/server/game/Handlers/NPCHandler.cpp
index 2a4a96a3827..53578310324 100644
--- a/src/server/game/Handlers/NPCHandler.cpp
+++ b/src/server/game/Handlers/NPCHandler.cpp
@@ -347,14 +347,14 @@ void WorldSession::HandleGossipSelectOptionOpcode(WorldPackets::NPC::GossipSelec
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 97e1410bd0f..4bb870e9e0a 100644
--- a/src/server/game/Scripting/ScriptMgr.cpp
+++ b/src/server/game/Scripting/ScriptMgr.cpp
@@ -1714,7 +1714,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);
}