mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-16 07:30:42 +01:00
Core/Scripts: implemented a guid map in InstanceScript, this way you can easier store guids and access its objects
This commit is contained in:
@@ -52,6 +52,43 @@ bool InstanceScript::IsEncounterInProgress() const
|
||||
return false;
|
||||
}
|
||||
|
||||
void InstanceScript::OnCreatureCreate(Creature* creature)
|
||||
{
|
||||
AddObject(creature, true);
|
||||
AddMinion(creature, true);
|
||||
}
|
||||
|
||||
void InstanceScript::OnCreatureRemove(Creature* creature)
|
||||
{
|
||||
AddObject(creature, false);
|
||||
AddMinion(creature, false);
|
||||
}
|
||||
|
||||
void InstanceScript::OnGameObjectCreate(GameObject* go)
|
||||
{
|
||||
AddObject(go, true);
|
||||
AddDoor(go, true);
|
||||
}
|
||||
|
||||
void InstanceScript::OnGameObjectRemove(GameObject* go)
|
||||
{
|
||||
AddObject(go, false);
|
||||
AddDoor(go, false);
|
||||
}
|
||||
|
||||
ObjectGuid InstanceScript::GetObjectGuid(uint32 type) const
|
||||
{
|
||||
ObjectGuidMap::const_iterator i = _objectGuids.find(type);
|
||||
if (i != _objectGuids.end())
|
||||
return i->second;
|
||||
return ObjectGuid::Empty;
|
||||
}
|
||||
|
||||
ObjectGuid InstanceScript::GetGuidData(uint32 type) const
|
||||
{
|
||||
return GetObjectGuid(type);
|
||||
}
|
||||
|
||||
void InstanceScript::SetHeaders(std::string const& dataHeaders)
|
||||
{
|
||||
for (char header : dataHeaders)
|
||||
@@ -83,6 +120,27 @@ void InstanceScript::LoadDoorData(const DoorData* data)
|
||||
TC_LOG_DEBUG("scripts", "InstanceScript::LoadDoorData: " UI64FMTD " doors loaded.", uint64(doors.size()));
|
||||
}
|
||||
|
||||
void InstanceScript::LoadObjectData(ObjectData const* creatureData, ObjectData const* gameObjectData)
|
||||
{
|
||||
if (creatureData)
|
||||
LoadObjectData(creatureData, _creatureInfo);
|
||||
|
||||
if (gameObjectData)
|
||||
LoadObjectData(gameObjectData, _gameObjectInfo);
|
||||
|
||||
TC_LOG_ERROR("scripts", "InstanceScript::LoadObjectData: " SZFMTD " objects loaded.", _creatureInfo.size() + _gameObjectInfo.size());
|
||||
}
|
||||
|
||||
void InstanceScript::LoadObjectData(ObjectData const* data, ObjectInfoMap& objectInfo)
|
||||
{
|
||||
while (data->entry)
|
||||
{
|
||||
ASSERT(objectInfo.find(data->entry) == objectInfo.end());
|
||||
objectInfo[data->entry] = data->type;
|
||||
++data;
|
||||
}
|
||||
}
|
||||
|
||||
void InstanceScript::UpdateMinionState(Creature* minion, EncounterState state)
|
||||
{
|
||||
switch (state)
|
||||
@@ -133,6 +191,32 @@ void InstanceScript::UpdateDoorState(GameObject* door)
|
||||
door->SetGoState(open ? GO_STATE_ACTIVE : GO_STATE_READY);
|
||||
}
|
||||
|
||||
void InstanceScript::AddObject(Creature* obj, bool add)
|
||||
{
|
||||
ObjectInfoMap::const_iterator j = _creatureInfo.find(obj->GetEntry());
|
||||
if (j != _creatureInfo.end())
|
||||
AddObject(obj, j->second, add);
|
||||
}
|
||||
|
||||
void InstanceScript::AddObject(GameObject* obj, bool add)
|
||||
{
|
||||
ObjectInfoMap::const_iterator j = _gameObjectInfo.find(obj->GetEntry());
|
||||
if (j != _gameObjectInfo.end())
|
||||
AddObject(obj, j->second, add);
|
||||
}
|
||||
|
||||
void InstanceScript::AddObject(WorldObject* obj, uint32 type, bool add)
|
||||
{
|
||||
if (add)
|
||||
_objectGuids[type] = obj->GetGUID();
|
||||
else
|
||||
{
|
||||
ObjectGuidMap::iterator i = _objectGuids.find(type);
|
||||
if (i != _objectGuids.end() && i->second == obj->GetGUID())
|
||||
_objectGuids.erase(i);
|
||||
}
|
||||
}
|
||||
|
||||
void InstanceScript::AddDoor(GameObject* door, bool add)
|
||||
{
|
||||
DoorInfoMapBounds range = doors.equal_range(door->GetEntry());
|
||||
|
||||
Reference in New Issue
Block a user