diff options
| author | joschiwald <joschiwald.trinity@gmail.com> | 2018-01-27 21:47:37 +0100 |
|---|---|---|
| committer | joschiwald <joschiwald.trinity@gmail.com> | 2018-01-27 23:02:46 +0100 |
| commit | 6226189a1687e1a2b4fb5a490031c22b5f334dc6 (patch) | |
| tree | d48fbc4a586203c0c4ae3721697d3428773e9e00 /src/server/game/Entities/GameObject | |
| parent | f963b8a225a70e7007536d5d4787483a2cade978 (diff) | |
Core/Entities: Created factory methods to create new areatriggers, creatures and gameobjects
Diffstat (limited to 'src/server/game/Entities/GameObject')
| -rw-r--r-- | src/server/game/Entities/GameObject/GameObject.cpp | 132 | ||||
| -rw-r--r-- | src/server/game/Entities/GameObject/GameObject.h | 11 |
2 files changed, 88 insertions, 55 deletions
diff --git a/src/server/game/Entities/GameObject/GameObject.cpp b/src/server/game/Entities/GameObject/GameObject.cpp index e33d099b2ac..ba2d4501301 100644 --- a/src/server/game/Entities/GameObject/GameObject.cpp +++ b/src/server/game/Entities/GameObject/GameObject.cpp @@ -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()) diff --git a/src/server/game/Entities/GameObject/GameObject.h b/src/server/game/Entities/GameObject/GameObject.h index 73730efd58a..d43306e9983 100644 --- a/src/server/game/Entities/GameObject/GameObject.h +++ b/src/server/game/Entities/GameObject/GameObject.h @@ -91,7 +91,12 @@ class TC_GAME_API GameObject : public WorldObject, public GridObject<GameObject> void RemoveFromWorld() override; void CleanupsBeforeDelete(bool finalCleanup = true) override; - bool Create(uint32 name_id, Map* map, Position const& pos, QuaternionData const& rotation, uint32 animprogress, GOState go_state, uint32 artKit = 0); + private: + bool Create(uint32 entry, Map* map, Position const& pos, QuaternionData const& rotation, uint32 animProgress, GOState goState, uint32 artKit); + public: + static GameObject* CreateGameObject(uint32 entry, Map* map, Position const& pos, QuaternionData const& rotation, uint32 animProgress, GOState goState, uint32 artKit = 0); + static GameObject* CreateGameObjectFromDB(ObjectGuid::LowType spawnId, Map* map, bool addToMap = true); + void Update(uint32 p_time) override; GameObjectTemplate const* GetGOInfo() const { return m_goInfo; } GameObjectTemplateAddon const* GetTemplateAddon() const { return m_goTemplateAddon; } @@ -116,7 +121,9 @@ class TC_GAME_API GameObject : public WorldObject, public GridObject<GameObject> void SaveToDB(); void SaveToDB(uint32 mapid, uint64 spawnMask); bool LoadFromDB(ObjectGuid::LowType spawnId, Map* map) { return LoadGameObjectFromDB(spawnId, map, false); } - bool LoadGameObjectFromDB(ObjectGuid::LowType spawnId, Map* map, bool addToMap = true); + private: + bool LoadGameObjectFromDB(ObjectGuid::LowType spawnId, Map* map, bool addToMap); + public: void DeleteFromDB(); void SetOwnerGUID(ObjectGuid owner) |
