From ec00f5fd9d20091dab81a069bedfc538dd324a88 Mon Sep 17 00:00:00 2001 From: EmosewaMC <39972741+EmosewaMC@users.noreply.github.com> Date: Fri, 9 Jun 2023 01:04:42 -0700 Subject: [PATCH] holy mother of const Use const everywhere that makes sense return const variables when it makes sense const functions and variables again, where it makes sense No raw access and modifications to protected members Move template definitions to tcc file idk how I feel about this one --- .editorconfig | 2 +- dGame/Entity.cpp | 59 +-- dGame/Entity.h | 361 ++++++------------ dGame/Entity.tcc | 158 ++++++++ dGame/Player.cpp | 8 +- dGame/Player.h | 6 +- dGame/dComponents/BaseCombatAIComponent.cpp | 2 +- dGame/dComponents/BuffComponent.cpp | 2 +- dGame/dComponents/MovementAIComponent.cpp | 2 +- dGame/dComponents/PetComponent.cpp | 8 +- dGame/dComponents/PetComponent.h | 4 +- dGame/dComponents/RebuildComponent.cpp | 2 +- dGame/dComponents/SwitchComponent.cpp | 2 +- dGame/dGameMessages/GameMessages.cpp | 2 +- dGame/dGameMessages/GameMessages.h | 2 +- dGame/dMission/MissionTask.cpp | 2 +- dGame/dPropertyBehaviors/ControlBehaviors.cpp | 8 +- dGame/dPropertyBehaviors/ControlBehaviors.h | 8 +- .../02_server/Enemy/Waves/WaveBossApe.cpp | 2 +- .../Enemy/Waves/WaveBossHammerling.cpp | 2 +- .../Enemy/Waves/WaveBossHorsemen.cpp | 2 +- .../Enemy/Waves/WaveBossSpiderling.cpp | 2 +- .../Map/NT/NtCombatChallengeServer.cpp | 2 +- .../Property/AG_Small/EnemySpiderSpawner.cpp | 2 +- dScripts/ai/ACT/ActMine.cpp | 2 +- dScripts/ai/WILD/WildNinjaBricks.cpp | 2 +- dScripts/ai/WILD/WildNinjaStudent.cpp | 2 +- dZoneManager/Spawner.cpp | 14 +- 28 files changed, 334 insertions(+), 336 deletions(-) create mode 100644 dGame/Entity.tcc diff --git a/.editorconfig b/.editorconfig index ebdfa7ac..447413cc 100644 --- a/.editorconfig +++ b/.editorconfig @@ -10,7 +10,7 @@ trim_trailing_whitespace=true end_of_line=lf insert_final_newline=true -[*.{c++,cc,cpp,cxx,h,h++,hh,hpp,hxx,inl,ipp,tlh,tli}] +[*.{c++,cc,cpp,cxx,h,h++,hh,hpp,hxx,inl,ipp,tlh,tli,tcc,tpp}] vc_generate_documentation_comments=doxygen_slash_star diff --git a/dGame/Entity.cpp b/dGame/Entity.cpp index bcb2a5b7..e073eaec 100644 --- a/dGame/Entity.cpp +++ b/dGame/Entity.cpp @@ -95,6 +95,7 @@ Entity::Entity(const LWOOBJID& objectID, EntityInfo info, Entity* parentEntity) m_GMLevel = eGameMasterLevel::CIVILIAN; m_CollectibleID = 0; m_NetworkID = 0; + m_Observers = 0; m_Groups = {}; m_OwnerOverride = LWOOBJID_EMPTY; m_Timers = {}; @@ -105,6 +106,9 @@ Entity::Entity(const LWOOBJID& objectID, EntityInfo info, Entity* parentEntity) m_DieCallbacks = {}; m_PhantomCollisionCallbacks = {}; m_IsParentChildDirty = true; + m_IsGhostingCandidate = false; + m_PlayerIsReadyForUpdates = false; + m_ShouldDestroyAfterUpdate = false; m_Settings = info.settings; m_NetworkSettings = info.networkSettings; @@ -382,7 +386,7 @@ bool Entity::operator==(const Entity& other) const { } bool Entity::operator!=(const Entity& other) const { - return other.m_ObjectID != m_ObjectID; + return !(other.m_ObjectID == m_ObjectID); } User* Entity::GetParentUser() const { @@ -393,27 +397,22 @@ User* Entity::GetParentUser() const { return static_cast(this)->GetParentUser(); } -const ComponentPtr Entity::GetComponent(eReplicaComponentType componentID) const { - const auto& index = m_Components.find(componentID); - return index != m_Components.end() ? index->second : nullptr; -} - bool Entity::HasComponent(const eReplicaComponentType componentId) const { return m_Components.find(componentId) != m_Components.end(); } -std::vector> Entity::GetScriptComponents() { - std::vector> comps; +std::vector Entity::GetScriptComponents() { + std::vector comps; for (const auto&[componentType, component] : m_Components) { if (componentType == eReplicaComponentType::SCRIPT) { - comps.push_back(std::dynamic_pointer_cast(component)); + comps.push_back(dynamic_cast(component.get())); } } return comps; } -void Entity::Subscribe(LWOOBJID scriptObjId, CppScripts::Script* scriptToAdd, const std::string& notificationName) { +void Entity::Subscribe(const LWOOBJID& scriptObjId, CppScripts::Script* scriptToAdd, const std::string& notificationName) { if (notificationName == "HitOrHealResult" || notificationName == "Hit") { auto destroyableComponent = GetComponent(); if (!destroyableComponent) return; @@ -421,7 +420,7 @@ void Entity::Subscribe(LWOOBJID scriptObjId, CppScripts::Script* scriptToAdd, co } } -void Entity::Unsubscribe(LWOOBJID scriptObjId, const std::string& notificationName) { +void Entity::Unsubscribe(const LWOOBJID& scriptObjId, const std::string& notificationName) { if (notificationName == "HitOrHealResult" || notificationName == "Hit") { auto destroyableComponent = GetComponent(); if (!destroyableComponent) return; @@ -429,12 +428,12 @@ void Entity::Unsubscribe(LWOOBJID scriptObjId, const std::string& notificationNa } } -void Entity::SetProximityRadius(float proxRadius, std::string name) { +void Entity::SetProximityRadius(const float proxRadius, const std::string& name) { auto proximityMonitorComponent = AddComponent(); if (proximityMonitorComponent) proximityMonitorComponent->SetProximityRadius(proxRadius, name); } -void Entity::SetProximityRadius(dpEntity* entity, std::string name) { +void Entity::SetProximityRadius(dpEntity* entity, const std::string& name) { auto proximityMonitorComponent = AddComponent(); if (proximityMonitorComponent) proximityMonitorComponent->SetProximityRadius(entity, name); } @@ -860,7 +859,7 @@ void Entity::OnChoiceBoxResponse(Entity* sender, int32_t button, const std::u16s } } -void Entity::RequestActivityExit(Entity* sender, LWOOBJID player, bool canceled) { +void Entity::RequestActivityExit(Entity* sender, const LWOOBJID& player, const bool canceled) { for (CppScripts::Script* script : CppScripts::GetEntityScripts(this)) { script->OnRequestActivityExit(sender, player, canceled); } @@ -1014,7 +1013,7 @@ void Entity::PickupItem(const LWOOBJID& objectID) { droppedLoot.erase(objectID); } -bool Entity::CanPickupCoins(uint64_t count) { +bool Entity::CanPickupCoins(const uint64_t& count) { if (!IsPlayer()) return false; auto* player = static_cast(this); auto droppedCoins = player->GetDroppedCoins(); @@ -1026,7 +1025,7 @@ bool Entity::CanPickupCoins(uint64_t count) { } } -void Entity::RegisterCoinDrop(uint64_t count) { +void Entity::RegisterCoinDrop(const uint64_t& count) { if (!IsPlayer()) return; auto* player = static_cast(this); auto droppedCoins = player->GetDroppedCoins(); @@ -1056,12 +1055,12 @@ void Entity::RemoveParent() { this->m_ParentEntity = nullptr; } -void Entity::AddTimer(std::string name, float time) { +void Entity::AddTimer(const std::string& name, float time) { EntityTimer* timer = new EntityTimer(name, time); m_PendingTimers.push_back(timer); } -void Entity::AddCallbackTimer(float time, std::function callback) { +void Entity::AddCallbackTimer(const float time, const std::function& callback) { EntityCallbackTimer* timer = new EntityCallbackTimer(time, callback); m_CallbackTimers.push_back(timer); } @@ -1148,22 +1147,10 @@ const NiQuaternion& Entity::GetDefaultRotation() const { return m_DefaultRotation; } -float Entity::GetDefaultScale() const { - return m_Scale; -} - -void Entity::SetOwnerOverride(const LWOOBJID value) { +void Entity::SetOwnerOverride(const LWOOBJID& value) { m_OwnerOverride = value; } -bool Entity::GetIsGhostingCandidate() const { - return m_IsGhostingCandidate; -} - -int8_t Entity::GetObservers() const { - return m_Observers; -} - void Entity::SetObservers(int8_t value) { if (value < 0) { value = 0; @@ -1251,7 +1238,7 @@ const NiQuaternion& Entity::GetRotation() const { return NiQuaternion::IDENTITY; } -void Entity::SetPosition(NiPoint3 position) { +void Entity::SetPosition(const NiPoint3& position) { auto controllable = GetComponent(); if (controllable != nullptr) { @@ -1279,7 +1266,7 @@ void Entity::SetPosition(NiPoint3 position) { EntityManager::Instance()->SerializeEntity(this); } -void Entity::SetRotation(NiQuaternion rotation) { +void Entity::SetRotation(const NiQuaternion& rotation) { auto controllable = GetComponent(); if (controllable != nullptr) { @@ -1341,10 +1328,6 @@ bool Entity::HasVar(const std::u16string& name) const { return false; } -uint16_t Entity::GetNetworkId() const { - return m_NetworkID; -} - void Entity::SetNetworkId(const uint16_t id) { m_NetworkID = id; } @@ -1406,7 +1389,7 @@ void Entity::Resurrect() { } } -void Entity::AddToGroup(const std::string& group) { +void Entity::AddToGroups(const std::string& group) { if (std::find(m_Groups.begin(), m_Groups.end(), group) == m_Groups.end()) { m_Groups.push_back(group); } diff --git a/dGame/Entity.h b/dGame/Entity.h index 8137e2b2..92608a4a 100644 --- a/dGame/Entity.h +++ b/dGame/Entity.h @@ -5,9 +5,9 @@ #include #include #include +#include #include #include -#include #include "NiPoint3.h" #include "NiQuaternion.h" @@ -44,10 +44,12 @@ namespace CppScripts { }; /** - * An entity in the world. Has multiple components. + * An entity in the world. + * Entities are composed of components which define their behavior. */ using ComponentPtr = std::shared_ptr; + class Entity { public: explicit Entity(const LWOOBJID& objectID, EntityInfo info, Entity* parentEntity = nullptr); @@ -61,20 +63,22 @@ public: /** * Getters */ + Character* GetCharacter() const { return m_Character; } + void SetCharacter(Character* value) { m_Character = value; } - const LWOOBJID& GetObjectID() const { return m_ObjectID; } + const LWOOBJID GetObjectID() const { return m_ObjectID; } const LOT GetLOT() const { return m_TemplateID; } - Character* GetCharacter() const { return m_Character; } - eGameMasterLevel GetGMLevel() const { return m_GMLevel; } + void SetGMLevel(const eGameMasterLevel value); - uint8_t GetCollectibleID() const { return uint8_t(m_CollectibleID); } + const uint32_t GetCollectibleID() const { return m_CollectibleID; } Entity* GetParentEntity() const { return m_ParentEntity; } - std::vector& GetGroups() { return m_Groups; }; + const std::vector& GetGroups() { return m_Groups; }; + void SetGroups(const std::vector& value) { m_Groups = value; } Spawner* GetSpawner() const { return m_Spawner; } @@ -87,113 +91,90 @@ public: bool GetIsDead() const; bool GetPlayerReadyForUpdates() const { return m_PlayerIsReadyForUpdates; } + void SetPlayerReadyForUpdates() { m_PlayerIsReadyForUpdates = true; } - bool GetIsGhostingCandidate() const; + const bool GetIsGhostingCandidate() const { return m_IsGhostingCandidate; } - int8_t GetObservers() const; + const int8_t GetObservers() const { return m_Observers; } + void SetObservers(const int8_t value); - uint16_t GetNetworkId() const; + const uint16_t GetNetworkId() const { return m_NetworkID; } + void SetNetworkId(const uint16_t id); Entity* GetOwner() const; + void SetOwnerOverride(const LWOOBJID& value); const NiPoint3& GetDefaultPosition() const; const NiQuaternion& GetDefaultRotation() const; - float GetDefaultScale() const; + const float GetDefaultScale() const { return m_Scale; } const NiPoint3& GetPosition() const; + void SetPosition(const NiPoint3& position); const NiQuaternion& GetRotation() const; + void SetRotation(const NiQuaternion& rotation); virtual User* GetParentUser() const; - virtual SystemAddress GetSystemAddress() const { return UNASSIGNED_SYSTEM_ADDRESS; }; + virtual const SystemAddress GetSystemAddress() const { return UNASSIGNED_SYSTEM_ADDRESS; }; - /** - * Setters - */ + virtual void SetRespawnPos(const NiPoint3& position) {}; - void SetCharacter(Character* value) { m_Character = value; } - - void SetGMLevel(eGameMasterLevel value); - - void SetOwnerOverride(LWOOBJID value); - - void SetPlayerReadyForUpdates() { m_PlayerIsReadyForUpdates = true; } - - void SetObservers(int8_t value); - - void SetNetworkId(uint16_t id); - - void SetPosition(NiPoint3 position); - - void SetRotation(NiQuaternion rotation); - - virtual void SetRespawnPos(NiPoint3 position) {} - - virtual void SetRespawnRot(NiQuaternion rotation) {} + virtual void SetRespawnRot(const NiQuaternion& rotation) {}; virtual void SetSystemAddress(const SystemAddress& value) {}; /** * Component management */ + bool HasComponent(const eReplicaComponentType componentId) const; - const ComponentPtr GetComponent(eReplicaComponentType componentID) const; + std::vector GetScriptComponents(); - template - std::shared_ptr GetComponent() const; + void Subscribe(const LWOOBJID& scriptObjId, CppScripts::Script* scriptToAdd, const std::string& notificationName); + void Unsubscribe(const LWOOBJID& scriptObjId, const std::string& notificationName); - bool HasComponent(eReplicaComponentType componentId) const; - - template - std::shared_ptr AddComponent(ConstructorValues... arguments); - - std::vector> GetScriptComponents(); - - void Subscribe(LWOOBJID scriptObjId, CppScripts::Script* scriptToAdd, const std::string& notificationName); - void Unsubscribe(LWOOBJID scriptObjId, const std::string& notificationName); - - void SetProximityRadius(float proxRadius, std::string name); - void SetProximityRadius(dpEntity* entity, std::string name); + void SetProximityRadius(const float proxRadius, const std::string& name); + void SetProximityRadius(dpEntity* entity, const std::string& name); void AddChild(Entity* child); void RemoveChild(Entity* child); void RemoveParent(); - void AddTimer(std::string name, float time); - void AddCallbackTimer(float time, std::function callback); + void AddTimer(const std::string& name, const float time); + void AddCallbackTimer(const float time, const std::function& callback); bool HasTimer(const std::string& name); void CancelCallbackTimers(); void CancelAllTimers(); void CancelTimer(const std::string& name); - void AddToGroup(const std::string& group); + void AddToGroups(const std::string& group); bool IsPlayer() const; - void WriteBaseReplicaData(RakNet::BitStream* outBitStream, eReplicaPacketType packetType); - void WriteComponents(RakNet::BitStream* outBitStream, eReplicaPacketType packetType); + void WriteBaseReplicaData(RakNet::BitStream* outBitStream, const eReplicaPacketType packetType); + void WriteComponents(RakNet::BitStream* outBitStream, const eReplicaPacketType packetType); void ResetFlags(); void UpdateXMLDoc(tinyxml2::XMLDocument* doc); void Update(float deltaTime); // Events - void OnCollisionProximity(LWOOBJID otherEntity, const std::string& proxName, const std::string& status); - void OnCollisionPhantom(LWOOBJID otherEntity); - void OnCollisionLeavePhantom(LWOOBJID otherEntity); + void OnCollisionProximity(const LWOOBJID otherEntity, const std::string& proxName, const std::string& status); + void OnCollisionPhantom(const LWOOBJID otherEntity); + void OnCollisionLeavePhantom(const LWOOBJID otherEntity); - void OnFireEventServerSide(Entity* sender, std::string args, int32_t param1 = -1, int32_t param2 = -1, int32_t param3 = -1); + void OnFireEventServerSide(Entity* sender, const std::string args, const int32_t param1 = -1, const int32_t param2 = -1, const int32_t param3 = -1); void OnActivityStateChangeRequest(const LWOOBJID senderID, const int32_t value1, const int32_t value2, const std::u16string& stringValue); - void OnCinematicUpdate(Entity* self, Entity* sender, eCinematicEvent event, const std::u16string& pathName, - float_t pathTime, float_t totalTime, int32_t waypoint); + void OnCinematicUpdate(Entity* self, Entity* sender, const eCinematicEvent event, const std::u16string& pathName, + const float pathTime, const float totalTime, const int32_t waypoint); - void NotifyObject(Entity* sender, const std::string& name, int32_t param1 = 0, int32_t param2 = 0); - void OnEmoteReceived(int32_t emote, Entity* target); + void NotifyObject(Entity* sender, const std::string& name, const int32_t param1 = 0, const int32_t param2 = 0); + void OnEmoteReceived(const int32_t emote, Entity* target); void OnUse(Entity* originator); - void OnHitOrHealResult(Entity* attacker, int32_t damage); + void OnHitOrHealResult(Entity* attacker, const int32_t damage); void OnHit(Entity* attacker); void OnZonePropertyEditBegin(); @@ -205,9 +186,9 @@ public: void OnZonePropertyModelRemovedWhileEquipped(Entity* player); void OnZonePropertyModelRotated(Entity* player); - void OnMessageBoxResponse(Entity* sender, int32_t button, const std::u16string& identifier, const std::u16string& userData); - void OnChoiceBoxResponse(Entity* sender, int32_t button, const std::u16string& buttonIdentifier, const std::u16string& identifier); - void RequestActivityExit(Entity* sender, LWOOBJID player, bool canceled); + void OnMessageBoxResponse(Entity* sender, const int32_t button, const std::u16string& identifier, const std::u16string& userData); + void OnChoiceBoxResponse(Entity* sender, const int32_t button, const std::u16string& buttonIdentifier, const std::u16string& identifier); + void RequestActivityExit(Entity* sender, const LWOOBJID& player, const bool canceled); void Smash(const LWOOBJID source = LWOOBJID_EMPTY, const eKillType killType = eKillType::VIOLENT, const std::u16string& deathType = u""); void Kill(Entity* murderer = nullptr); @@ -219,11 +200,11 @@ public: void AddLootItem(const Loot::Info& info); void PickupItem(const LWOOBJID& objectID); - bool CanPickupCoins(uint64_t count); - void RegisterCoinDrop(uint64_t count); + bool CanPickupCoins(const uint64_t& count); + void RegisterCoinDrop(const uint64_t& count); void ScheduleKillAfterUpdate(Entity* murderer = nullptr); - void TriggerEvent(eTriggerEventType event, Entity* optionalTarget = nullptr); + void TriggerEvent(const eTriggerEventType event, Entity* optionalTarget = nullptr); void ScheduleDestructionAfterUpdate() { m_ShouldDestroyAfterUpdate = true; } virtual NiPoint3 GetRespawnPosition() const { return NiPoint3::ZERO; } @@ -236,10 +217,8 @@ public: /* * Utility */ - /** - * Retroactively corrects the model vault size due to incorrect initialization in a previous patch. - * - */ + + //Retroactively corrects the model vault size due to incorrect initialization in a previous patch. void RetroactiveVaultSize(); bool GetBoolean(const std::u16string& name) const; int32_t GetI32(const std::u16string& name) const; @@ -251,29 +230,6 @@ public: bool HasVar(const std::u16string& name) const; - template - const T& GetVar(const std::u16string& name) const; - - template - void SetVar(const std::u16string& name, T value); - - void SendNetworkVar(const std::string& data, const SystemAddress& sysAddr); - - template - void SetNetworkVar(const std::u16string& name, T value, const SystemAddress& sysAddr = UNASSIGNED_SYSTEM_ADDRESS); - - template - void SetNetworkVar(const std::u16string& name, std::vector value, const SystemAddress& sysAddr = UNASSIGNED_SYSTEM_ADDRESS); - - template - T GetNetworkVar(const std::u16string& name); - - /** - * Get the LDF value and cast it as T. - */ - template - T GetVarAs(const std::u16string& name) const; - /** * Get the LDF data. */ @@ -291,7 +247,57 @@ public: Entity* GetScheduledKiller() { return m_ScheduleKiller; } - std::unordered_map& GetComponents() { return m_Components; } + const std::unordered_map& GetComponents() { return m_Components; } + + // Template declarations + template + const T& GetVar(const std::u16string& name) const; + + template + T GetVarAs(const std::u16string& name) const; + + template + void SetVar(const std::u16string& name, const T& value); + + template + T GetNetworkVar(const std::u16string& name); + + void SendNetworkVar(const std::string& data, const SystemAddress& sysAddr); + + template + void SetNetworkVar(const std::u16string& name, const T& value, const SystemAddress& sysAddr = UNASSIGNED_SYSTEM_ADDRESS); + + template + void SetNetworkVar(const std::u16string& name, const std::vector& value, const SystemAddress& sysAddr = UNASSIGNED_SYSTEM_ADDRESS); + /** + * @brief Get a non-owning reference to a component + * + * @tparam Cmpt The component to get a non-owning reference of + * @return Cmpt* The non-owning pointer to the component + */ + template + Cmpt* GetComponent() const; + + /** + * @brief Get an owning reference to a component. + * + * @tparam Cmpt The component to get a shared reference of + * @return std::shared_ptr The owning shared pointer + */ + template + std::shared_ptr GetSharedComponent() const; + + /** + * @brief Adds a component to this Entity. + * + * @tparam Cmpt The component to create + * @tparam ConstructorValues The constructor values to forward to the component + * @param arguments The constructor values to forward to the component + * @return Cmpt* A non-owning pointer to the created component, + * or a non-owning pointer to the existing component if the component already existed. + */ + template + Cmpt* AddComponent(ConstructorValues... arguments); protected: LWOOBJID m_ObjectID; @@ -316,30 +322,30 @@ protected: Entity* m_ParentEntity; //For spawners and the like std::vector m_ChildEntities; eGameMasterLevel m_GMLevel; - uint16_t m_CollectibleID; + uint32_t m_CollectibleID; std::vector m_Groups; uint16_t m_NetworkID; std::vector> m_DieCallbacks; - std::vector> m_PhantomCollisionCallbacks; + std::vector> m_PhantomCollisionCallbacks; std::unordered_map m_Components; std::vector m_Timers; std::vector m_PendingTimers; std::vector m_CallbackTimers; - bool m_ShouldDestroyAfterUpdate = false; + bool m_ShouldDestroyAfterUpdate; LWOOBJID m_OwnerOverride; Entity* m_ScheduleKiller; - bool m_PlayerIsReadyForUpdates = false; + bool m_PlayerIsReadyForUpdates; - bool m_IsGhostingCandidate = false; + bool m_IsGhostingCandidate; - int8_t m_Observers = 0; + int8_t m_Observers; - bool m_IsParentChildDirty = true; + bool m_IsParentChildDirty; /* * Collision @@ -347,151 +353,6 @@ protected: std::vector m_TargetsInPhantom; }; -template -std::shared_ptr Entity::GetComponent() const { - return std::dynamic_pointer_cast(GetComponent(T::ComponentType)); -} - -template -const T& Entity::GetVar(const std::u16string& name) const { - auto* data = GetVarData(name); - - if (data == nullptr) { - return LDFData::Default; - } - - auto* typed = dynamic_cast*>(data); - - if (typed == nullptr) { - return LDFData::Default; - } - - return typed->GetValue(); -} - -template -T Entity::GetVarAs(const std::u16string& name) const { - const auto data = GetVarAsString(name); - - T value; - - if (!GeneralUtils::TryParse(data, value)) { - return LDFData::Default; - } - - return value; -} - -template -void Entity::SetVar(const std::u16string& name, T value) { - auto* data = GetVarData(name); - - if (data == nullptr) { - auto* data = new LDFData(name, value); - - m_Settings.push_back(data); - - return; - } - - auto* typed = dynamic_cast*>(data); - - if (typed == nullptr) { - return; - } - - typed->SetValue(value); -} - -template -void Entity::SetNetworkVar(const std::u16string& name, T value, const SystemAddress& sysAddr) { - LDFData* newData = nullptr; - - for (auto* data : m_NetworkSettings) { - if (data->GetKey() != name) - continue; - - newData = dynamic_cast*>(data); - if (newData != nullptr) { - newData->SetValue(value); - } else { // If we're changing types - m_NetworkSettings.erase( - std::remove(m_NetworkSettings.begin(), m_NetworkSettings.end(), data), m_NetworkSettings.end() - ); - delete data; - } - - break; - } - - if (newData == nullptr) { - newData = new LDFData(name, value); - } - - m_NetworkSettings.push_back(newData); - SendNetworkVar(newData->GetString(true), sysAddr); -} - -template -void Entity::SetNetworkVar(const std::u16string& name, std::vector values, const SystemAddress& sysAddr) { - std::stringstream updates; - auto index = 1; - - for (const auto& value : values) { - LDFData* newData = nullptr; - const auto& indexedName = name + u"." + GeneralUtils::to_u16string(index); - - for (auto* data : m_NetworkSettings) { - if (data->GetKey() != indexedName) - continue; - - newData = dynamic_cast*>(data); - newData->SetValue(value); - break; - } - - if (newData == nullptr) { - newData = new LDFData(indexedName, value); - } - - m_NetworkSettings.push_back(newData); - - if (index == values.size()) { - updates << newData->GetString(true); - } else { - updates << newData->GetString(true) << "\n"; - } - - index++; - } - - SendNetworkVar(updates.str(), sysAddr); -} - -template -T Entity::GetNetworkVar(const std::u16string& name) { - for (auto* data : m_NetworkSettings) { - if (data == nullptr || data->GetKey() != name) - continue; - - auto* typed = dynamic_cast*>(data); - if (typed == nullptr) - continue; - - return typed->GetValue(); - } - - return LDFData::Default; -} - -template -std::shared_ptr Entity::AddComponent(ConstructorValues...arguments) { - auto component = GetComponent(); - if (component) return component; - - auto insertedComponent = m_Components.insert_or_assign(Cmpt::ComponentType, - std::make_shared(this, std::forward(arguments)...)).first->second; - return std::dynamic_pointer_cast(insertedComponent); -} +#include "Entity.tcc" #endif //!__ENTITY__H__ diff --git a/dGame/Entity.tcc b/dGame/Entity.tcc new file mode 100644 index 00000000..c3ee593f --- /dev/null +++ b/dGame/Entity.tcc @@ -0,0 +1,158 @@ +// Template definitions for Entity. + +#ifndef __ENTITY__H__ +#error "Include Entity.h instead of Entity.tpp" +#endif + +template +Cmpt* Entity::GetComponent() const { + const auto& componentItr = this->m_Components.find(Cmpt::ComponentType); + return componentItr == this->m_Components.end() ? nullptr : dynamic_cast(componentItr->second.get()); +} +template +std::shared_ptr Entity::GetSharedComponent() const { + const auto& componentItr = this->m_Components.find(Cmpt::ComponentType); + return componentItr == this->m_Components.end() ? nullptr : std::dynamic_pointer_cast(componentItr->second); +} + +template +const T& Entity::GetVar(const std::u16string& name) const { + auto* data = GetVarData(name); + + if (data == nullptr) { + return LDFData::Default; + } + + auto* typed = dynamic_cast*>(data); + + if (typed == nullptr) { + return LDFData::Default; + } + + return typed->GetValue(); +} + +template +T Entity::GetVarAs(const std::u16string& name) const { + const auto data = GetVarAsString(name); + + T value; + + if (!GeneralUtils::TryParse(data, value)) { + return LDFData::Default; + } + + return value; +} + +template +void Entity::SetVar(const std::u16string& name, const T& value) { + auto* data = GetVarData(name); + + if (data == nullptr) { + auto* data = new LDFData(name, value); + + m_Settings.push_back(data); + + return; + } + + auto* typed = dynamic_cast*>(data); + + if (typed == nullptr) { + return; + } + + typed->SetValue(value); +} + +template +void Entity::SetNetworkVar(const std::u16string& name, const T& value, const SystemAddress& sysAddr) { + LDFData* newData = nullptr; + + for (auto* data : m_NetworkSettings) { + if (data->GetKey() != name) + continue; + + newData = dynamic_cast*>(data); + if (newData != nullptr) { + newData->SetValue(value); + } else { // If we're changing types + m_NetworkSettings.erase( + std::remove(m_NetworkSettings.begin(), m_NetworkSettings.end(), data), m_NetworkSettings.end() + ); + delete data; + } + + break; + } + + if (newData == nullptr) { + newData = new LDFData(name, value); + } + + m_NetworkSettings.push_back(newData); + SendNetworkVar(newData->GetString(true), sysAddr); +} + +template +void Entity::SetNetworkVar(const std::u16string& name, const std::vector& values, const SystemAddress& sysAddr) { + std::stringstream updates; + auto index = 1; + + for (const auto& value : values) { + LDFData* newData = nullptr; + const auto& indexedName = name + u"." + GeneralUtils::to_u16string(index); + + for (auto* data : m_NetworkSettings) { + if (data->GetKey() != indexedName) + continue; + + newData = dynamic_cast*>(data); + newData->SetValue(value); + break; + } + + if (newData == nullptr) { + newData = new LDFData(indexedName, value); + } + + m_NetworkSettings.push_back(newData); + + if (index == values.size()) { + updates << newData->GetString(true); + } else { + updates << newData->GetString(true) << "\n"; + } + + index++; + } + + SendNetworkVar(updates.str(), sysAddr); +} + +template +T Entity::GetNetworkVar(const std::u16string& name) { + for (auto* data : m_NetworkSettings) { + if (data == nullptr || data->GetKey() != name) + continue; + + auto* typed = dynamic_cast*>(data); + if (typed == nullptr) + continue; + + return typed->GetValue(); + } + + return LDFData::Default; +} + +template +Cmpt* Entity::AddComponent(ConstructorValues...arguments) { + auto component = GetComponent(); + if (component) return dynamic_cast(component); + + auto& insertedComponent = m_Components.insert_or_assign(Cmpt::ComponentType, + std::make_shared(this, std::forward(arguments)...)).first->second; + return dynamic_cast(insertedComponent.get()); +} diff --git a/dGame/Player.cpp b/dGame/Player.cpp index c8e35c58..8c12d38a 100644 --- a/dGame/Player.cpp +++ b/dGame/Player.cpp @@ -51,21 +51,17 @@ User* Player::GetParentUser() const { return m_ParentUser; } -SystemAddress Player::GetSystemAddress() const { - return m_SystemAddress; -} - void Player::SetSystemAddress(const SystemAddress& value) { m_SystemAddress = value; } -void Player::SetRespawnPos(const NiPoint3 position) { +void Player::SetRespawnPos(const NiPoint3& position) { m_respawnPos = position; m_Character->SetRespawnPoint(dZoneManager::Instance()->GetZone()->GetWorldID(), position); } -void Player::SetRespawnRot(const NiQuaternion rotation) { +void Player::SetRespawnRot(const NiQuaternion& rotation) { m_respawnRot = rotation; } diff --git a/dGame/Player.h b/dGame/Player.h index 287ee613..1ae41b9c 100644 --- a/dGame/Player.h +++ b/dGame/Player.h @@ -20,7 +20,7 @@ public: User* GetParentUser() const override; - SystemAddress GetSystemAddress() const override; + const SystemAddress GetSystemAddress() const override { return m_SystemAddress; } NiPoint3 GetRespawnPosition() const override; @@ -44,9 +44,9 @@ public: void SetSystemAddress(const SystemAddress& value) override; - void SetRespawnPos(NiPoint3 position) override; + void SetRespawnPos(const NiPoint3& position) override; - void SetRespawnRot(NiQuaternion rotation) override; + void SetRespawnRot(const NiQuaternion& rotation) override; void SetGhostReferencePoint(const NiPoint3& value); diff --git a/dGame/dComponents/BaseCombatAIComponent.cpp b/dGame/dComponents/BaseCombatAIComponent.cpp index f95cab1c..e7c9e3b8 100644 --- a/dGame/dComponents/BaseCombatAIComponent.cpp +++ b/dGame/dComponents/BaseCombatAIComponent.cpp @@ -190,7 +190,7 @@ void BaseCombatAIComponent::Update(const float deltaTime) { } if (m_MovementAI == nullptr) { - m_MovementAI = m_OwningEntity->GetComponent(); + m_MovementAI = m_OwningEntity->GetSharedComponent(); if (m_MovementAI == nullptr) { return; } diff --git a/dGame/dComponents/BuffComponent.cpp b/dGame/dComponents/BuffComponent.cpp index 5d4b3f91..b49bb0a5 100644 --- a/dGame/dComponents/BuffComponent.cpp +++ b/dGame/dComponents/BuffComponent.cpp @@ -91,7 +91,7 @@ void BuffComponent::ApplyBuff(const int32_t id, const float duration, const LWOO return; } - GameMessages::SendAddBuff(const_cast(m_OwningEntity->GetObjectID()), source, (uint32_t)id, + GameMessages::SendAddBuff(m_OwningEntity->GetObjectID(), source, (uint32_t)id, (uint32_t)duration * 1000, addImmunity, cancelOnDamaged, cancelOnDeath, cancelOnLogout, cancelOnRemoveBuff, cancelOnUi, cancelOnUnequip, cancelOnZone); diff --git a/dGame/dComponents/MovementAIComponent.cpp b/dGame/dComponents/MovementAIComponent.cpp index d4629942..2c51a349 100644 --- a/dGame/dComponents/MovementAIComponent.cpp +++ b/dGame/dComponents/MovementAIComponent.cpp @@ -22,7 +22,7 @@ MovementAIComponent::MovementAIComponent(Entity* parent, MovementAIInfo info) : m_BaseCombatAI = nullptr; - m_BaseCombatAI = m_OwningEntity->GetComponent(); + m_BaseCombatAI = m_OwningEntity->GetSharedComponent(); //Try and fix the insane values: if (m_Info.wanderRadius > 5.0f) m_Info.wanderRadius = m_Info.wanderRadius * 0.5f; diff --git a/dGame/dComponents/PetComponent.cpp b/dGame/dComponents/PetComponent.cpp index a2d44168..4351fc93 100644 --- a/dGame/dComponents/PetComponent.cpp +++ b/dGame/dComponents/PetComponent.cpp @@ -363,7 +363,7 @@ void PetComponent::Update(float deltaTime) { } if (m_MovementAI == nullptr) { - m_MovementAI = m_OwningEntity->GetComponent(); + m_MovementAI = m_OwningEntity->GetSharedComponent(); if (!m_MovementAI) return; } @@ -792,7 +792,7 @@ void PetComponent::ClientFailTamingMinigame() { } void PetComponent::Wander() { - m_MovementAI = m_OwningEntity->GetComponent(); + if (!m_MovementAI) m_MovementAI = m_OwningEntity->GetSharedComponent(); if (m_MovementAI == nullptr || !m_MovementAI->AtFinalWaypoint()) { return; @@ -1038,7 +1038,7 @@ void PetComponent::SetAbility(PetAbilityType value) { m_Ability = value; } -std::shared_ptr PetComponent::GetTamingPet(LWOOBJID tamer) { +PetComponent* PetComponent::GetTamingPet(LWOOBJID tamer) { const auto& pair = currentActivities.find(tamer); if (pair == currentActivities.end()) { @@ -1056,7 +1056,7 @@ std::shared_ptr PetComponent::GetTamingPet(LWOOBJID tamer) { return entity->GetComponent(); } -std::shared_ptr PetComponent::GetActivePet(LWOOBJID owner) { +PetComponent* PetComponent::GetActivePet(LWOOBJID owner) { const auto& pair = activePets.find(owner); if (pair == activePets.end()) { diff --git a/dGame/dComponents/PetComponent.h b/dGame/dComponents/PetComponent.h index 4eaaa3bc..1d0d10bd 100644 --- a/dGame/dComponents/PetComponent.h +++ b/dGame/dComponents/PetComponent.h @@ -195,14 +195,14 @@ public: * @param tamer the entity that's currently taming * @return the pet component of the entity that's being tamed */ - static std::shared_ptr GetTamingPet(LWOOBJID tamer); + static PetComponent* GetTamingPet(LWOOBJID tamer); /** * Returns the pet that's currently spawned for some entity (if any) * @param owner the owner of the pet that's spawned * @return the pet component of the entity that was spawned by the owner */ - static std::shared_ptr GetActivePet(LWOOBJID owner); + static PetComponent* GetActivePet(LWOOBJID owner); /** * Adds the timer to the owner of this pet to drain imagination at the rate diff --git a/dGame/dComponents/RebuildComponent.cpp b/dGame/dComponents/RebuildComponent.cpp index d224402f..ef4baf4b 100644 --- a/dGame/dComponents/RebuildComponent.cpp +++ b/dGame/dComponents/RebuildComponent.cpp @@ -58,7 +58,7 @@ RebuildComponent::~RebuildComponent() { } void RebuildComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) { - if (m_OwningEntity->GetComponent(eReplicaComponentType::DESTROYABLE) == nullptr) { + if (!m_OwningEntity->GetComponent()) { if (bIsInitialUpdate) { outBitStream->Write(false); } diff --git a/dGame/dComponents/SwitchComponent.cpp b/dGame/dComponents/SwitchComponent.cpp index 32f5f80d..0e5cc0a3 100644 --- a/dGame/dComponents/SwitchComponent.cpp +++ b/dGame/dComponents/SwitchComponent.cpp @@ -10,7 +10,7 @@ SwitchComponent::SwitchComponent(Entity* parent) : Component(parent) { m_ResetTime = m_OwningEntity->GetVarAs(u"switch_reset_time"); - m_Rebuild = m_OwningEntity->GetComponent(); + m_Rebuild = m_OwningEntity->GetSharedComponent(); } SwitchComponent::~SwitchComponent() { diff --git a/dGame/dGameMessages/GameMessages.cpp b/dGame/dGameMessages/GameMessages.cpp index ce12011c..e48fa27b 100644 --- a/dGame/dGameMessages/GameMessages.cpp +++ b/dGame/dGameMessages/GameMessages.cpp @@ -4565,7 +4565,7 @@ void GameMessages::SendVehicleNotifyFinishedRace(LWOOBJID objectId, const System SEND_PACKET; } -void GameMessages::SendAddBuff(LWOOBJID& objectID, const LWOOBJID& casterID, uint32_t buffID, uint32_t msDuration, +void GameMessages::SendAddBuff(const LWOOBJID& objectID, const LWOOBJID& casterID, uint32_t buffID, uint32_t msDuration, bool addImmunity, bool cancelOnDamaged, bool cancelOnDeath, bool cancelOnLogout, bool cancelOnRemoveBuff, bool cancelOnUi, bool cancelOnUnequip, bool cancelOnZone, const SystemAddress& sysAddr) { diff --git a/dGame/dGameMessages/GameMessages.h b/dGame/dGameMessages/GameMessages.h index 7e7a8f70..e197dfe5 100644 --- a/dGame/dGameMessages/GameMessages.h +++ b/dGame/dGameMessages/GameMessages.h @@ -200,7 +200,7 @@ namespace GameMessages { // The success or failure response sent back to the client will preserve the same value for localID. void SendBBBSaveResponse(const LWOOBJID& objectId, const LWOOBJID& localID, unsigned char* buffer, uint32_t bufferSize, const SystemAddress& sysAddr); - void SendAddBuff(LWOOBJID& objectID, const LWOOBJID& casterID, uint32_t buffID, uint32_t msDuration, + void SendAddBuff(const LWOOBJID& objectID, const LWOOBJID& casterID, uint32_t buffID, uint32_t msDuration, bool addImmunity = false, bool cancelOnDamaged = false, bool cancelOnDeath = true, bool cancelOnLogout = false, bool cancelOnRemoveBuff = true, bool cancelOnUi = false, bool cancelOnUnequip = false, bool cancelOnZone = false, const SystemAddress& sysAddr = UNASSIGNED_SYSTEM_ADDRESS); diff --git a/dGame/dMission/MissionTask.cpp b/dGame/dMission/MissionTask.cpp index 6bd29bb0..77e6fc6e 100644 --- a/dGame/dMission/MissionTask.cpp +++ b/dGame/dMission/MissionTask.cpp @@ -213,7 +213,7 @@ void MissionTask::Progress(int32_t value, LWOOBJID associate, const std::string& } Entity* entity; - std::shared_ptr activity; + ScriptedActivityComponent* activity; uint32_t activityId; uint32_t lot; uint32_t collectionId; diff --git a/dGame/dPropertyBehaviors/ControlBehaviors.cpp b/dGame/dPropertyBehaviors/ControlBehaviors.cpp index 974dd9a2..67f51a43 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviors.cpp +++ b/dGame/dPropertyBehaviors/ControlBehaviors.cpp @@ -30,7 +30,7 @@ #include "UpdateActionMessage.h" #include "UpdateStripUiMessage.h" -void ControlBehaviors::RequestUpdatedID(int32_t behaviorID, std::shared_ptr modelComponent, Entity* modelOwner, const SystemAddress& sysAddr) { +void ControlBehaviors::RequestUpdatedID(int32_t behaviorID, ModelBehaviorComponent* modelComponent, Entity* modelOwner, const SystemAddress& sysAddr) { // auto behavior = modelComponent->FindBehavior(behaviorID); // if (behavior->GetBehaviorID() == -1 || behavior->GetShouldSetNewID()) { // ObjectIDManager::Instance()->RequestPersistentID( @@ -79,7 +79,7 @@ void ControlBehaviors::SendBehaviorListToClient(Entity* modelEntity, const Syste GameMessages::SendUIMessageServerToSingleClient(modelOwner, sysAddr, "UpdateBehaviorList", behaviorsToSerialize); } -void ControlBehaviors::ModelTypeChanged(AMFArrayValue* arguments, std::shared_ptr ModelBehaviorComponent) { +void ControlBehaviors::ModelTypeChanged(AMFArrayValue* arguments, ModelBehaviorComponent* ModelComponent) { auto* modelTypeAmf = arguments->Get("ModelType"); if (!modelTypeAmf) return; @@ -137,7 +137,7 @@ void ControlBehaviors::Rename(Entity* modelEntity, const SystemAddress& sysAddr, } // TODO This is also supposed to serialize the state of the behaviors in progress but those aren't implemented yet -void ControlBehaviors::SendBehaviorBlocksToClient(std::shared_ptr modelComponent, const SystemAddress& sysAddr, Entity* modelOwner, AMFArrayValue* arguments) { +void ControlBehaviors::SendBehaviorBlocksToClient(ModelBehaviorComponent* modelComponent, const SystemAddress& sysAddr, Entity* modelOwner, AMFArrayValue* arguments) { // uint32_t behaviorID = ControlBehaviors::GetBehaviorIDFromArgument(arguments); // auto modelBehavior = modelComponent->FindBehavior(behaviorID); @@ -266,7 +266,7 @@ void ControlBehaviors::UpdateAction(AMFArrayValue* arguments) { } } -void ControlBehaviors::MoveToInventory(std::shared_ptr modelComponent, const SystemAddress& sysAddr, Entity* modelOwner, AMFArrayValue* arguments) { +void ControlBehaviors::MoveToInventory(ModelBehaviorComponent* modelComponent, const SystemAddress& sysAddr, Entity* modelOwner, AMFArrayValue* arguments) { // This closes the UI menu should it be open while the player is removing behaviors AMFArrayValue args; diff --git a/dGame/dPropertyBehaviors/ControlBehaviors.h b/dGame/dPropertyBehaviors/ControlBehaviors.h index b8a1d13e..6259b4b8 100644 --- a/dGame/dPropertyBehaviors/ControlBehaviors.h +++ b/dGame/dPropertyBehaviors/ControlBehaviors.h @@ -41,9 +41,9 @@ public: */ BlockDefinition* GetBlockInfo(const BlockName& blockName); private: - void RequestUpdatedID(int32_t behaviorID, std::shared_ptr modelComponent, Entity* modelOwner, const SystemAddress& sysAddr); + void RequestUpdatedID(int32_t behaviorID, ModelBehaviorComponent* modelComponent, Entity* modelOwner, const SystemAddress& sysAddr); void SendBehaviorListToClient(Entity* modelEntity, const SystemAddress& sysAddr, Entity* modelOwner); - void ModelTypeChanged(AMFArrayValue* arguments, std::shared_ptr ModelBehaviorComponent); + void ModelTypeChanged(AMFArrayValue* arguments, ModelBehaviorComponent* ModelComponent); void ToggleExecutionUpdates(); void AddStrip(AMFArrayValue* arguments); void RemoveStrip(AMFArrayValue* arguments); @@ -56,9 +56,9 @@ private: void Add(AMFArrayValue* arguments); void RemoveActions(AMFArrayValue* arguments); void Rename(Entity* modelEntity, const SystemAddress& sysAddr, Entity* modelOwner, AMFArrayValue* arguments); - void SendBehaviorBlocksToClient(std::shared_ptr modelComponent, const SystemAddress& sysAddr, Entity* modelOwner, AMFArrayValue* arguments); + void SendBehaviorBlocksToClient(ModelBehaviorComponent* modelComponent, const SystemAddress& sysAddr, Entity* modelOwner, AMFArrayValue* arguments); void UpdateAction(AMFArrayValue* arguments); - void MoveToInventory(std::shared_ptr modelComponent, const SystemAddress& sysAddr, Entity* modelOwner, AMFArrayValue* arguments); + void MoveToInventory(ModelBehaviorComponent* modelComponent, const SystemAddress& sysAddr, Entity* modelOwner, AMFArrayValue* arguments); std::map blockTypes{}; // If false, property behaviors will not be able to be edited. diff --git a/dScripts/02_server/Enemy/Waves/WaveBossApe.cpp b/dScripts/02_server/Enemy/Waves/WaveBossApe.cpp index 359b37ee..5c768c9e 100644 --- a/dScripts/02_server/Enemy/Waves/WaveBossApe.cpp +++ b/dScripts/02_server/Enemy/Waves/WaveBossApe.cpp @@ -17,7 +17,7 @@ void WaveBossApe::OnStartup(Entity* self) { combatAIComponent->SetStunImmune(true); } - self->AddToGroup("boss"); + self->AddToGroups("boss"); BaseEnemyApe::OnStartup(self); } diff --git a/dScripts/02_server/Enemy/Waves/WaveBossHammerling.cpp b/dScripts/02_server/Enemy/Waves/WaveBossHammerling.cpp index fcbe1d4c..ee8ec166 100644 --- a/dScripts/02_server/Enemy/Waves/WaveBossHammerling.cpp +++ b/dScripts/02_server/Enemy/Waves/WaveBossHammerling.cpp @@ -11,7 +11,7 @@ void WaveBossHammerling::OnStartup(Entity* self) { combatAIComponent->SetStunImmune(true); } - self->AddToGroup("boss"); + self->AddToGroups("boss"); } void WaveBossHammerling::OnFireEventServerSide(Entity* self, Entity* sender, std::string args, int32_t param1, diff --git a/dScripts/02_server/Enemy/Waves/WaveBossHorsemen.cpp b/dScripts/02_server/Enemy/Waves/WaveBossHorsemen.cpp index fb685ef8..19a29002 100644 --- a/dScripts/02_server/Enemy/Waves/WaveBossHorsemen.cpp +++ b/dScripts/02_server/Enemy/Waves/WaveBossHorsemen.cpp @@ -11,7 +11,7 @@ void WaveBossHorsemen::OnStartup(Entity* self) { combatAIComponent->SetStunImmune(true); } - self->AddToGroup("boss"); + self->AddToGroups("boss"); } void diff --git a/dScripts/02_server/Enemy/Waves/WaveBossSpiderling.cpp b/dScripts/02_server/Enemy/Waves/WaveBossSpiderling.cpp index 908d29b7..22f61f2c 100644 --- a/dScripts/02_server/Enemy/Waves/WaveBossSpiderling.cpp +++ b/dScripts/02_server/Enemy/Waves/WaveBossSpiderling.cpp @@ -11,7 +11,7 @@ void WaveBossSpiderling::OnStartup(Entity* self) { combatAIComponent->SetStunImmune(true); } - self->AddToGroup("boss"); + self->AddToGroups("boss"); } void WaveBossSpiderling::OnFireEventServerSide(Entity* self, Entity* sender, std::string args, int32_t param1, diff --git a/dScripts/02_server/Map/NT/NtCombatChallengeServer.cpp b/dScripts/02_server/Map/NT/NtCombatChallengeServer.cpp index 30366b55..74df89b7 100644 --- a/dScripts/02_server/Map/NT/NtCombatChallengeServer.cpp +++ b/dScripts/02_server/Map/NT/NtCombatChallengeServer.cpp @@ -123,7 +123,7 @@ void NtCombatChallengeServer::OnChildLoaded(Entity* self, Entity* child) { EntityManager::Instance()->SerializeEntity(child); - child->GetGroups().push_back("targets_" + std::to_string(self->GetObjectID())); + child->AddToGroups("targets_" + std::to_string(self->GetObjectID())); } void NtCombatChallengeServer::ResetGame(Entity* self) { diff --git a/dScripts/02_server/Map/Property/AG_Small/EnemySpiderSpawner.cpp b/dScripts/02_server/Map/Property/AG_Small/EnemySpiderSpawner.cpp index 07db9a3a..2b96cf45 100644 --- a/dScripts/02_server/Map/Property/AG_Small/EnemySpiderSpawner.cpp +++ b/dScripts/02_server/Map/Property/AG_Small/EnemySpiderSpawner.cpp @@ -51,7 +51,7 @@ void EnemySpiderSpawner::OnTimerDone(Entity* self, std::string timerName) { Entity* newEntity = EntityManager::Instance()->CreateEntity(info, nullptr); if (newEntity) { EntityManager::Instance()->ConstructEntity(newEntity); - newEntity->GetGroups().push_back("BabySpider"); + newEntity->AddToGroups("BabySpider"); /* auto movementAi = newEntity->GetComponent(); diff --git a/dScripts/ai/ACT/ActMine.cpp b/dScripts/ai/ACT/ActMine.cpp index 13ab27df..d7c6abbd 100644 --- a/dScripts/ai/ACT/ActMine.cpp +++ b/dScripts/ai/ACT/ActMine.cpp @@ -18,7 +18,7 @@ void ActMine::OnRebuildNotifyState(Entity* self, eRebuildState state) { self->SetVar(u"RebuildComplete", true); self->SetVar(u"NumWarnings", 0); - self->AddToGroup("reset"); + self->AddToGroups("reset"); } } diff --git a/dScripts/ai/WILD/WildNinjaBricks.cpp b/dScripts/ai/WILD/WildNinjaBricks.cpp index 4fa65b01..243aceea 100644 --- a/dScripts/ai/WILD/WildNinjaBricks.cpp +++ b/dScripts/ai/WILD/WildNinjaBricks.cpp @@ -2,7 +2,7 @@ #include "Entity.h" void WildNinjaBricks::OnStartup(Entity* self) { - self->AddToGroup("Ninjastuff"); + self->AddToGroups("Ninjastuff"); } void WildNinjaBricks::OnNotifyObject(Entity* self, Entity* sender, const std::string& name, int32_t param1, int32_t param2) { diff --git a/dScripts/ai/WILD/WildNinjaStudent.cpp b/dScripts/ai/WILD/WildNinjaStudent.cpp index b7e2f585..57ac18b1 100644 --- a/dScripts/ai/WILD/WildNinjaStudent.cpp +++ b/dScripts/ai/WILD/WildNinjaStudent.cpp @@ -2,7 +2,7 @@ #include "GameMessages.h" void WildNinjaStudent::OnStartup(Entity* self) { - self->AddToGroup("Ninjastuff"); + self->AddToGroups("Ninjastuff"); GameMessages::SendPlayAnimation(self, u"bow"); } diff --git a/dZoneManager/Spawner.cpp b/dZoneManager/Spawner.cpp index 28f77fea..d80f096b 100644 --- a/dZoneManager/Spawner.cpp +++ b/dZoneManager/Spawner.cpp @@ -102,23 +102,23 @@ Entity* Spawner::Spawn(std::vector freeNodes, const bool force) { m_EntityInfo.spawnerID = m_Info.spawnerID; } - Entity* rezdE = EntityManager::Instance()->CreateEntity(m_EntityInfo, nullptr); + Entity* spawnedEntity = EntityManager::Instance()->CreateEntity(m_EntityInfo, nullptr); - rezdE->GetGroups() = m_Info.groups; + spawnedEntity->SetGroups(m_Info.groups); - EntityManager::Instance()->ConstructEntity(rezdE); + EntityManager::Instance()->ConstructEntity(spawnedEntity); - m_Entities.insert({ rezdE->GetObjectID(), spawnNode }); - spawnNode->entities.push_back(rezdE->GetObjectID()); + m_Entities.insert({ spawnedEntity->GetObjectID(), spawnNode }); + spawnNode->entities.push_back(spawnedEntity->GetObjectID()); if (m_Entities.size() == m_Info.amountMaintained) { m_NeedsUpdate = false; } for (const auto& cb : m_EntitySpawnedCallbacks) { - cb(rezdE); + cb(spawnedEntity); } - return rezdE; + return spawnedEntity; } return nullptr;