Core/Entities: Created factory methods to create new areatriggers, creatures and gameobjects

This commit is contained in:
joschiwald
2018-01-27 23:02:46 +01:00
parent f963b8a225
commit 6226189a16
22 changed files with 346 additions and 371 deletions
@@ -197,7 +197,7 @@ void GameObject::RemoveFromWorld()
}
}
bool GameObject::Create(uint32 name_id, Map* map, Position const& pos, QuaternionData const& rotation, uint32 animprogress, GOState go_state, uint32 artKit /*= 0*/)
bool GameObject::Create(uint32 entry, Map* map, Position const& pos, QuaternionData const& rotation, uint32 animProgress, GOState goState, uint32 artKit)
{
ASSERT(map);
SetMap(map);
@@ -206,34 +206,34 @@ bool GameObject::Create(uint32 name_id, Map* map, Position const& pos, Quaternio
m_stationaryPosition.Relocate(pos);
if (!IsPositionValid())
{
TC_LOG_ERROR("misc", "Gameobject (Spawn id: " UI64FMTD " Entry: %u) not created. Suggested coordinates isn't valid (X: %f Y: %f)", GetSpawnId(), name_id, pos.GetPositionX(), pos.GetPositionY());
TC_LOG_ERROR("misc", "Gameobject (Spawn id: " UI64FMTD " Entry: %u) not created. Suggested coordinates isn't valid (X: %f Y: %f)", GetSpawnId(), entry, pos.GetPositionX(), pos.GetPositionY());
return false;
}
SetZoneScript();
if (m_zoneScript)
{
name_id = m_zoneScript->GetGameObjectEntry(m_spawnId, name_id);
if (!name_id)
entry = m_zoneScript->GetGameObjectEntry(m_spawnId, entry);
if (!entry)
return false;
}
GameObjectTemplate const* goinfo = sObjectMgr->GetGameObjectTemplate(name_id);
if (!goinfo)
GameObjectTemplate const* goInfo = sObjectMgr->GetGameObjectTemplate(entry);
if (!goInfo)
{
TC_LOG_ERROR("sql.sql", "Gameobject (Spawn id: " UI64FMTD " Entry: %u) not created: non-existing entry in `gameobject_template`. Map: %u (X: %f Y: %f Z: %f)", GetSpawnId(), name_id, map->GetId(), pos.GetPositionX(), pos.GetPositionY(), pos.GetPositionZ());
TC_LOG_ERROR("sql.sql", "Gameobject (Spawn id: " UI64FMTD " Entry: %u) not created: non-existing entry in `gameobject_template`. Map: %u (X: %f Y: %f Z: %f)", GetSpawnId(), entry, map->GetId(), pos.GetPositionX(), pos.GetPositionY(), pos.GetPositionZ());
return false;
}
if (goinfo->type == GAMEOBJECT_TYPE_MAP_OBJ_TRANSPORT)
if (goInfo->type == GAMEOBJECT_TYPE_MAP_OBJ_TRANSPORT)
{
TC_LOG_ERROR("sql.sql", "Gameobject (Spawn id: " UI64FMTD " Entry: %u) not created: gameobject type GAMEOBJECT_TYPE_MAP_OBJ_TRANSPORT cannot be manually created.", GetSpawnId(), name_id);
TC_LOG_ERROR("sql.sql", "Gameobject (Spawn id: " UI64FMTD " Entry: %u) not created: gameobject type GAMEOBJECT_TYPE_MAP_OBJ_TRANSPORT cannot be manually created.", GetSpawnId(), entry);
return false;
}
ObjectGuid guid;
if (goinfo->type != GAMEOBJECT_TYPE_TRANSPORT)
guid = ObjectGuid::Create<HighGuid::GameObject>(map->GetId(), goinfo->entry, map->GenerateLowGuid<HighGuid::GameObject>());
if (goInfo->type != GAMEOBJECT_TYPE_TRANSPORT)
guid = ObjectGuid::Create<HighGuid::GameObject>(map->GetId(), goInfo->entry, map->GenerateLowGuid<HighGuid::GameObject>());
else
{
guid = ObjectGuid::Create<HighGuid::Transport>(map->GenerateLowGuid<HighGuid::Transport>());
@@ -242,12 +242,12 @@ bool GameObject::Create(uint32 name_id, Map* map, Position const& pos, Quaternio
Object::_Create(guid);
m_goInfo = goinfo;
m_goTemplateAddon = sObjectMgr->GetGameObjectTemplateAddon(name_id);
m_goInfo = goInfo;
m_goTemplateAddon = sObjectMgr->GetGameObjectTemplateAddon(entry);
if (goinfo->type >= MAX_GAMEOBJECT_TYPE)
if (goInfo->type >= MAX_GAMEOBJECT_TYPE)
{
TC_LOG_ERROR("sql.sql", "Gameobject (%s Spawn id: " UI64FMTD " Entry: %u) not created: non-existing GO type '%u' in `gameobject_template`. It will crash client if created.", guid.ToString().c_str(), GetSpawnId(), name_id, goinfo->type);
TC_LOG_ERROR("sql.sql", "Gameobject (%s Spawn id: " UI64FMTD " Entry: %u) not created: non-existing GO type '%u' in `gameobject_template`. It will crash client if created.", guid.ToString().c_str(), GetSpawnId(), entry, goInfo->type);
return false;
}
@@ -261,7 +261,7 @@ bool GameObject::Create(uint32 name_id, Map* map, Position const& pos, Quaternio
SetParentRotation(parentRotation);
SetObjectScale(goinfo->size);
SetObjectScale(goInfo->size);
if (m_goTemplateAddon)
{
@@ -275,24 +275,24 @@ bool GameObject::Create(uint32 name_id, Map* map, Position const& pos, Quaternio
}
}
SetEntry(goinfo->entry);
SetEntry(goInfo->entry);
// set name for logs usage, doesn't affect anything ingame
SetName(goinfo->name);
SetName(goInfo->name);
SetDisplayId(goinfo->displayId);
SetDisplayId(goInfo->displayId);
m_model = CreateModel();
// GAMEOBJECT_BYTES_1, index at 0, 1, 2 and 3
SetGoType(GameobjectTypes(goinfo->type));
m_prevGoState = go_state;
SetGoState(go_state);
SetGoType(GameobjectTypes(goInfo->type));
m_prevGoState = goState;
SetGoState(goState);
SetGoArtKit(artKit);
switch (goinfo->type)
switch (goInfo->type)
{
case GAMEOBJECT_TYPE_FISHINGHOLE:
SetGoAnimProgress(animprogress);
SetGoAnimProgress(animProgress);
m_goValue.FishingHole.MaxOpens = urand(GetGOInfo()->fishingHole.minRestock, GetGOInfo()->fishingHole.maxRestock);
break;
case GAMEOBJECT_TYPE_DESTRUCTIBLE_BUILDING:
@@ -304,37 +304,37 @@ bool GameObject::Create(uint32 name_id, Map* map, Position const& pos, Quaternio
break;
case GAMEOBJECT_TYPE_TRANSPORT:
{
m_goValue.Transport.AnimationInfo = sTransportMgr->GetTransportAnimInfo(goinfo->entry);
m_goValue.Transport.AnimationInfo = sTransportMgr->GetTransportAnimInfo(goInfo->entry);
m_goValue.Transport.PathProgress = getMSTime();
if (m_goValue.Transport.AnimationInfo)
m_goValue.Transport.PathProgress -= m_goValue.Transport.PathProgress % GetTransportPeriod(); // align to period
m_goValue.Transport.CurrentSeg = 0;
m_goValue.Transport.StateUpdateTimer = 0;
m_goValue.Transport.StopFrames = new std::vector<uint32>();
if (goinfo->transport.Timeto2ndfloor > 0)
m_goValue.Transport.StopFrames->push_back(goinfo->transport.Timeto2ndfloor);
if (goinfo->transport.Timeto3rdfloor > 0)
m_goValue.Transport.StopFrames->push_back(goinfo->transport.Timeto3rdfloor);
if (goinfo->transport.Timeto4thfloor > 0)
m_goValue.Transport.StopFrames->push_back(goinfo->transport.Timeto4thfloor);
if (goinfo->transport.Timeto5thfloor > 0)
m_goValue.Transport.StopFrames->push_back(goinfo->transport.Timeto5thfloor);
if (goinfo->transport.Timeto6thfloor > 0)
m_goValue.Transport.StopFrames->push_back(goinfo->transport.Timeto6thfloor);
if (goinfo->transport.Timeto7thfloor > 0)
m_goValue.Transport.StopFrames->push_back(goinfo->transport.Timeto7thfloor);
if (goinfo->transport.Timeto8thfloor > 0)
m_goValue.Transport.StopFrames->push_back(goinfo->transport.Timeto8thfloor);
if (goinfo->transport.Timeto9thfloor > 0)
m_goValue.Transport.StopFrames->push_back(goinfo->transport.Timeto9thfloor);
if (goinfo->transport.Timeto10thfloor > 0)
m_goValue.Transport.StopFrames->push_back(goinfo->transport.Timeto10thfloor);
if (goinfo->transport.startOpen)
SetTransportState(GO_STATE_TRANSPORT_STOPPED, goinfo->transport.startOpen - 1);
if (goInfo->transport.Timeto2ndfloor > 0)
m_goValue.Transport.StopFrames->push_back(goInfo->transport.Timeto2ndfloor);
if (goInfo->transport.Timeto3rdfloor > 0)
m_goValue.Transport.StopFrames->push_back(goInfo->transport.Timeto3rdfloor);
if (goInfo->transport.Timeto4thfloor > 0)
m_goValue.Transport.StopFrames->push_back(goInfo->transport.Timeto4thfloor);
if (goInfo->transport.Timeto5thfloor > 0)
m_goValue.Transport.StopFrames->push_back(goInfo->transport.Timeto5thfloor);
if (goInfo->transport.Timeto6thfloor > 0)
m_goValue.Transport.StopFrames->push_back(goInfo->transport.Timeto6thfloor);
if (goInfo->transport.Timeto7thfloor > 0)
m_goValue.Transport.StopFrames->push_back(goInfo->transport.Timeto7thfloor);
if (goInfo->transport.Timeto8thfloor > 0)
m_goValue.Transport.StopFrames->push_back(goInfo->transport.Timeto8thfloor);
if (goInfo->transport.Timeto9thfloor > 0)
m_goValue.Transport.StopFrames->push_back(goInfo->transport.Timeto9thfloor);
if (goInfo->transport.Timeto10thfloor > 0)
m_goValue.Transport.StopFrames->push_back(goInfo->transport.Timeto10thfloor);
if (goInfo->transport.startOpen)
SetTransportState(GO_STATE_TRANSPORT_STOPPED, goInfo->transport.startOpen - 1);
else
SetTransportState(GO_STATE_TRANSPORT_ACTIVE);
SetGoAnimProgress(animprogress);
SetGoAnimProgress(animProgress);
break;
}
case GAMEOBJECT_TYPE_FISHINGNODE:
@@ -355,7 +355,7 @@ bool GameObject::Create(uint32 name_id, Map* map, Position const& pos, Quaternio
}
break;
default:
SetGoAnimProgress(animprogress);
SetGoAnimProgress(animProgress);
break;
}
@@ -380,19 +380,45 @@ bool GameObject::Create(uint32 name_id, Map* map, Position const& pos, Quaternio
if (uint32 linkedEntry = GetGOInfo()->GetLinkedGameObjectEntry())
{
GameObject* linkedGO = new GameObject();
if (linkedGO->Create(linkedEntry, map, pos, rotation, 255, GO_STATE_READY))
if (GameObject* linkedGo = GameObject::CreateGameObject(linkedEntry, map, pos, rotation, 255, GO_STATE_READY))
{
SetLinkedTrap(linkedGO);
map->AddToMap(linkedGO);
SetLinkedTrap(linkedGo);
if (!map->AddToMap(linkedGo))
delete linkedGo;
}
else
delete linkedGO;
}
return true;
}
GameObject* GameObject::CreateGameObject(uint32 entry, Map* map, Position const& pos, QuaternionData const& rotation, uint32 animProgress, GOState goState, uint32 artKit /*= 0*/)
{
GameObjectTemplate const* goInfo = sObjectMgr->GetGameObjectTemplate(entry);
if (!goInfo)
return nullptr;
GameObject* go = new GameObject();
if (!go->Create(entry, map, pos, rotation, animProgress, goState, artKit))
{
delete go;
return nullptr;
}
return go;
}
GameObject* GameObject::CreateGameObjectFromDB(ObjectGuid::LowType spawnId, Map* map, bool addToMap /*= true*/)
{
GameObject* go = new GameObject();
if (!go->LoadGameObjectFromDB(spawnId, map, addToMap))
{
delete go;
return nullptr;
}
return go;
}
void GameObject::Update(uint32 diff)
{
if (AI())