Core/Scripts: Add support for spawn specific C++ scripts

Closes #19247
This commit is contained in:
Krudor
2017-03-18 11:31:31 +01:00
committed by Shauren
parent 0a35c473c8
commit 5a36a2eb17
8 changed files with 40 additions and 10 deletions

View File

@@ -0,0 +1,2 @@
ALTER TABLE `creature` ADD COLUMN `ScriptName` CHAR(64) NULL DEFAULT '' AFTER `dynamicflags`;
ALTER TABLE `gameobject` ADD COLUMN `ScriptName` CHAR(64) NULL DEFAULT '' AFTER `state`;

View File

@@ -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;
}

View File

@@ -543,6 +543,7 @@ struct CreatureData
uint32 dynamicflags;
uint32 phaseid;
uint32 phaseGroup;
uint32 ScriptId;
bool dbData;
};

View File

@@ -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
{

View File

@@ -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;

View File

@@ -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 <> '' "

View File

@@ -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;
}

View File

@@ -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);
}