2021-12-05 17:54:36 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <functional>
|
|
|
|
#include <typeinfo>
|
|
|
|
#include <type_traits>
|
2023-01-07 05:17:05 +00:00
|
|
|
#include <unordered_map>
|
2021-12-05 17:54:36 +00:00
|
|
|
#include <vector>
|
2023-06-07 03:48:30 +00:00
|
|
|
#include <memory>
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
#include "NiPoint3.h"
|
|
|
|
#include "NiQuaternion.h"
|
|
|
|
#include "LDFFormat.h"
|
2023-05-02 22:39:21 +00:00
|
|
|
#include "eKillType.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-01-07 05:17:05 +00:00
|
|
|
namespace Loot {
|
|
|
|
class Info;
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace tinyxml2 {
|
|
|
|
class XMLDocument;
|
|
|
|
};
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
class Player;
|
2023-01-07 05:17:05 +00:00
|
|
|
class EntityInfo;
|
|
|
|
class User;
|
2021-12-05 17:54:36 +00:00
|
|
|
class Spawner;
|
|
|
|
class ScriptComponent;
|
|
|
|
class dpEntity;
|
2023-01-07 05:17:05 +00:00
|
|
|
class EntityTimer;
|
2021-12-05 17:54:36 +00:00
|
|
|
class Component;
|
2022-12-21 22:33:41 +00:00
|
|
|
class Item;
|
2021-12-05 17:54:36 +00:00
|
|
|
class Character;
|
2023-01-07 05:17:05 +00:00
|
|
|
class EntityCallbackTimer;
|
2023-02-10 08:29:53 +00:00
|
|
|
enum class eTriggerEventType;
|
2023-03-24 23:16:45 +00:00
|
|
|
enum class eGameMasterLevel : uint8_t;
|
2023-03-04 07:16:37 +00:00
|
|
|
enum class eReplicaComponentType : uint32_t;
|
2023-05-02 22:39:21 +00:00
|
|
|
enum class eReplicaPacketType : uint8_t;
|
|
|
|
enum class eCinematicEvent : uint32_t;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-12-21 22:33:41 +00:00
|
|
|
namespace CppScripts {
|
|
|
|
class Script;
|
|
|
|
};
|
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* An entity in the world. Has multiple components.
|
|
|
|
*/
|
2023-06-07 03:48:30 +00:00
|
|
|
|
|
|
|
using ComponentPtr = std::shared_ptr<Component>;
|
2021-12-05 17:54:36 +00:00
|
|
|
class Entity {
|
|
|
|
public:
|
2022-07-28 13:39:57 +00:00
|
|
|
explicit Entity(const LWOOBJID& objectID, EntityInfo info, Entity* parentEntity = nullptr);
|
|
|
|
virtual ~Entity();
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
virtual void Initialize();
|
2022-07-28 13:39:57 +00:00
|
|
|
|
|
|
|
bool operator==(const Entity& other) const;
|
|
|
|
bool operator!=(const Entity& other) const;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Getters
|
|
|
|
*/
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
const LWOOBJID& GetObjectID() const { return m_ObjectID; }
|
|
|
|
|
|
|
|
const LOT GetLOT() const { return m_TemplateID; }
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
Character* GetCharacter() const { return m_Character; }
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-03-24 23:16:45 +00:00
|
|
|
eGameMasterLevel GetGMLevel() const { return m_GMLevel; }
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
uint8_t GetCollectibleID() const { return uint8_t(m_CollectibleID); }
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
Entity* GetParentEntity() const { return m_ParentEntity; }
|
|
|
|
|
|
|
|
std::vector<std::string>& GetGroups() { return m_Groups; };
|
|
|
|
|
|
|
|
Spawner* GetSpawner() const { return m_Spawner; }
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
LWOOBJID GetSpawnerID() const { return m_SpawnerID; }
|
|
|
|
|
|
|
|
const std::vector<LDFBaseData*>& GetSettings() const { return m_Settings; }
|
|
|
|
|
|
|
|
const std::vector<LDFBaseData*>& GetNetworkSettings() const { return m_NetworkSettings; }
|
|
|
|
|
|
|
|
bool GetIsDead() const;
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
bool GetPlayerReadyForUpdates() const { return m_PlayerIsReadyForUpdates; }
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
bool GetIsGhostingCandidate() const;
|
|
|
|
|
|
|
|
int8_t GetObservers() const;
|
|
|
|
|
|
|
|
uint16_t GetNetworkId() const;
|
|
|
|
|
|
|
|
Entity* GetOwner() const;
|
|
|
|
|
|
|
|
const NiPoint3& GetDefaultPosition() const;
|
|
|
|
|
|
|
|
const NiQuaternion& GetDefaultRotation() const;
|
|
|
|
|
|
|
|
float GetDefaultScale() const;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
const NiPoint3& GetPosition() const;
|
|
|
|
|
|
|
|
const NiQuaternion& GetRotation() const;
|
|
|
|
|
|
|
|
virtual User* GetParentUser() const;
|
|
|
|
|
|
|
|
virtual SystemAddress GetSystemAddress() const { return UNASSIGNED_SYSTEM_ADDRESS; };
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Setters
|
|
|
|
*/
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void SetCharacter(Character* value) { m_Character = value; }
|
|
|
|
|
2023-03-24 23:16:45 +00:00
|
|
|
void SetGMLevel(eGameMasterLevel value);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
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) {}
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
virtual void SetSystemAddress(const SystemAddress& value) {};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Component management
|
|
|
|
*/
|
|
|
|
|
2023-06-07 03:48:30 +00:00
|
|
|
const ComponentPtr GetComponent(eReplicaComponentType componentID) const;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
template<typename T>
|
2023-06-07 03:48:30 +00:00
|
|
|
std::shared_ptr<T> GetComponent() const;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-03-04 07:16:37 +00:00
|
|
|
bool HasComponent(eReplicaComponentType componentId) const;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-06-07 03:48:30 +00:00
|
|
|
template<typename ComponentType, typename...ConstructorValues>
|
|
|
|
std::shared_ptr<ComponentType> AddComponent(ConstructorValues... arguments);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-06-07 03:48:30 +00:00
|
|
|
std::vector<std::shared_ptr<ScriptComponent>> GetScriptComponents();
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-12-21 22:33:41 +00:00
|
|
|
void Subscribe(LWOOBJID scriptObjId, CppScripts::Script* scriptToAdd, const std::string& notificationName);
|
|
|
|
void Unsubscribe(LWOOBJID scriptObjId, const std::string& notificationName);
|
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
void SetProximityRadius(float proxRadius, std::string name);
|
|
|
|
void SetProximityRadius(dpEntity* entity, std::string name);
|
|
|
|
|
|
|
|
void AddChild(Entity* child);
|
2022-06-17 00:50:33 +00:00
|
|
|
void RemoveChild(Entity* child);
|
2022-07-17 04:39:13 +00:00
|
|
|
void RemoveParent();
|
2021-12-05 17:54:36 +00:00
|
|
|
void AddTimer(std::string name, float time);
|
|
|
|
void AddCallbackTimer(float time, std::function<void()> callback);
|
|
|
|
bool HasTimer(const std::string& name);
|
|
|
|
void CancelCallbackTimers();
|
|
|
|
void CancelAllTimers();
|
|
|
|
void CancelTimer(const std::string& name);
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void AddToGroup(const std::string& group);
|
2021-12-05 17:54:36 +00:00
|
|
|
bool IsPlayer() const;
|
|
|
|
|
|
|
|
void WriteBaseReplicaData(RakNet::BitStream* outBitStream, eReplicaPacketType packetType);
|
|
|
|
void WriteComponents(RakNet::BitStream* outBitStream, eReplicaPacketType packetType);
|
2022-07-28 13:39:57 +00:00
|
|
|
void ResetFlags();
|
|
|
|
void UpdateXMLDoc(tinyxml2::XMLDocument* doc);
|
2021-12-05 17:54:36 +00:00
|
|
|
void Update(float deltaTime);
|
|
|
|
|
|
|
|
// Events
|
|
|
|
void OnCollisionProximity(LWOOBJID otherEntity, const std::string& proxName, const std::string& status);
|
|
|
|
void OnCollisionPhantom(LWOOBJID otherEntity);
|
2022-07-28 13:39:57 +00:00
|
|
|
void OnCollisionLeavePhantom(LWOOBJID otherEntity);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void OnFireEventServerSide(Entity* sender, std::string args, int32_t param1 = -1, int32_t param2 = -1, 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);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
void NotifyObject(Entity* sender, const std::string& name, int32_t param1 = 0, int32_t param2 = 0);
|
|
|
|
void OnEmoteReceived(int32_t emote, Entity* target);
|
2022-07-28 13:39:57 +00:00
|
|
|
|
|
|
|
void OnUse(Entity* originator);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
void OnHitOrHealResult(Entity* attacker, int32_t damage);
|
|
|
|
void OnHit(Entity* attacker);
|
|
|
|
|
|
|
|
void OnZonePropertyEditBegin();
|
|
|
|
void OnZonePropertyEditEnd();
|
|
|
|
void OnZonePropertyModelEquipped();
|
|
|
|
void OnZonePropertyModelPlaced(Entity* player);
|
|
|
|
void OnZonePropertyModelPickedUp(Entity* player);
|
|
|
|
void OnZonePropertyModelRemoved(Entity* player);
|
|
|
|
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);
|
2023-05-11 00:26:04 +00:00
|
|
|
void RequestActivityExit(Entity* sender, LWOOBJID player, bool canceled);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
void Smash(const LWOOBJID source = LWOOBJID_EMPTY, const eKillType killType = eKillType::VIOLENT, const std::u16string& deathType = u"");
|
|
|
|
void Kill(Entity* murderer = nullptr);
|
2022-07-28 13:39:57 +00:00
|
|
|
void AddRebuildCompleteCallback(const std::function<void(Entity* user)>& callback) const;
|
2021-12-05 17:54:36 +00:00
|
|
|
void AddCollisionPhantomCallback(const std::function<void(Entity* target)>& callback);
|
|
|
|
void AddDieCallback(const std::function<void()>& callback);
|
|
|
|
void Resurrect();
|
|
|
|
|
|
|
|
void AddLootItem(const Loot::Info& info);
|
|
|
|
void PickupItem(const LWOOBJID& objectID);
|
|
|
|
|
2021-12-11 13:57:15 +00:00
|
|
|
bool CanPickupCoins(uint64_t count);
|
|
|
|
void RegisterCoinDrop(uint64_t count);
|
2021-12-11 13:21:00 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
void ScheduleKillAfterUpdate(Entity* murderer = nullptr);
|
2023-02-10 08:29:53 +00:00
|
|
|
void TriggerEvent(eTriggerEventType event, Entity* optionalTarget = nullptr);
|
2021-12-05 17:54:36 +00:00
|
|
|
void ScheduleDestructionAfterUpdate() { m_ShouldDestroyAfterUpdate = true; }
|
|
|
|
|
|
|
|
virtual NiPoint3 GetRespawnPosition() const { return NiPoint3::ZERO; }
|
|
|
|
virtual NiQuaternion GetRespawnRotation() const { return NiQuaternion::IDENTITY; }
|
|
|
|
|
|
|
|
void Sleep();
|
|
|
|
void Wake();
|
|
|
|
bool IsSleeping() const;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Utility
|
|
|
|
*/
|
2022-07-28 13:39:57 +00:00
|
|
|
/**
|
|
|
|
* Retroactively corrects the model vault size due to incorrect initialization in a previous patch.
|
|
|
|
*
|
|
|
|
*/
|
2022-04-13 08:49:55 +00:00
|
|
|
void RetroactiveVaultSize();
|
2021-12-05 17:54:36 +00:00
|
|
|
bool GetBoolean(const std::u16string& name) const;
|
|
|
|
int32_t GetI32(const std::u16string& name) const;
|
|
|
|
int64_t GetI64(const std::u16string& name) const;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
void SetBoolean(const std::u16string& name, bool value);
|
|
|
|
void SetI32(const std::u16string& name, int32_t value);
|
|
|
|
void SetI64(const std::u16string& name, int64_t value);
|
|
|
|
|
|
|
|
bool HasVar(const std::u16string& name) const;
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
const T& GetVar(const std::u16string& name) const;
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
void SetVar(const std::u16string& name, T value);
|
|
|
|
|
|
|
|
void SendNetworkVar(const std::string& data, const SystemAddress& sysAddr);
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
void SetNetworkVar(const std::u16string& name, T value, const SystemAddress& sysAddr = UNASSIGNED_SYSTEM_ADDRESS);
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
template<typename T>
|
|
|
|
void SetNetworkVar(const std::u16string& name, std::vector<T> value, const SystemAddress& sysAddr = UNASSIGNED_SYSTEM_ADDRESS);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
template<typename T>
|
|
|
|
T GetNetworkVar(const std::u16string& name);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the LDF value and cast it as T.
|
|
|
|
*/
|
|
|
|
template<typename T>
|
|
|
|
T GetVarAs(const std::u16string& name) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the LDF data.
|
|
|
|
*/
|
|
|
|
LDFBaseData* GetVarData(const std::u16string& name) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the LDF value and convert it to a string.
|
|
|
|
*/
|
|
|
|
std::string GetVarAsString(const std::u16string& name) const;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Collision
|
|
|
|
*/
|
|
|
|
std::vector<LWOOBJID>& GetTargetsInPhantom();
|
|
|
|
|
|
|
|
Entity* GetScheduledKiller() { return m_ScheduleKiller; }
|
|
|
|
|
|
|
|
protected:
|
2022-07-28 13:39:57 +00:00
|
|
|
LWOOBJID m_ObjectID;
|
|
|
|
|
|
|
|
LOT m_TemplateID;
|
|
|
|
|
|
|
|
std::vector<LDFBaseData*> m_Settings;
|
|
|
|
std::vector<LDFBaseData*> m_NetworkSettings;
|
|
|
|
|
|
|
|
NiPoint3 m_DefaultPosition;
|
|
|
|
NiQuaternion m_DefaultRotation;
|
2021-12-05 17:54:36 +00:00
|
|
|
float m_Scale;
|
|
|
|
|
|
|
|
Spawner* m_Spawner;
|
2022-07-28 13:39:57 +00:00
|
|
|
LWOOBJID m_SpawnerID;
|
|
|
|
|
|
|
|
bool m_HasSpawnerNodeID;
|
|
|
|
uint32_t m_SpawnerNodeID;
|
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
Character* m_Character;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
|
|
|
Entity* m_ParentEntity; //For spawners and the like
|
2021-12-05 17:54:36 +00:00
|
|
|
std::vector<Entity*> m_ChildEntities;
|
2023-03-24 23:16:45 +00:00
|
|
|
eGameMasterLevel m_GMLevel;
|
2022-07-28 13:39:57 +00:00
|
|
|
uint16_t m_CollectibleID;
|
2021-12-05 17:54:36 +00:00
|
|
|
std::vector<std::string> m_Groups;
|
|
|
|
uint16_t m_NetworkID;
|
|
|
|
std::vector<std::function<void()>> m_DieCallbacks;
|
2022-07-28 13:39:57 +00:00
|
|
|
std::vector<std::function<void(Entity* target)>> m_PhantomCollisionCallbacks;
|
|
|
|
|
2023-06-07 03:48:30 +00:00
|
|
|
std::unordered_map<eReplicaComponentType, ComponentPtr> m_Components;
|
2021-12-05 17:54:36 +00:00
|
|
|
std::vector<EntityTimer*> m_Timers;
|
2022-07-17 01:21:35 +00:00
|
|
|
std::vector<EntityTimer*> m_PendingTimers;
|
2021-12-05 17:54:36 +00:00
|
|
|
std::vector<EntityCallbackTimer*> m_CallbackTimers;
|
|
|
|
|
|
|
|
bool m_ShouldDestroyAfterUpdate = false;
|
|
|
|
|
|
|
|
LWOOBJID m_OwnerOverride;
|
|
|
|
|
|
|
|
Entity* m_ScheduleKiller;
|
|
|
|
|
|
|
|
bool m_PlayerIsReadyForUpdates = false;
|
|
|
|
|
|
|
|
bool m_IsGhostingCandidate = false;
|
|
|
|
|
|
|
|
int8_t m_Observers = 0;
|
|
|
|
|
2022-06-16 05:58:38 +00:00
|
|
|
bool m_IsParentChildDirty = true;
|
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/*
|
|
|
|
* Collision
|
|
|
|
*/
|
|
|
|
std::vector<LWOOBJID> m_TargetsInPhantom;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
2023-06-07 03:48:30 +00:00
|
|
|
std::shared_ptr<T> Entity::GetComponent() const {
|
|
|
|
return std::dynamic_pointer_cast<T>(GetComponent(T::ComponentType));
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
2022-07-28 13:39:57 +00:00
|
|
|
const T& Entity::GetVar(const std::u16string& name) const {
|
2021-12-05 17:54:36 +00:00
|
|
|
auto* data = GetVarData(name);
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (data == nullptr) {
|
2021-12-05 17:54:36 +00:00
|
|
|
return LDFData<T>::Default;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto* typed = dynamic_cast<LDFData<T>*>(data);
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (typed == nullptr) {
|
2021-12-05 17:54:36 +00:00
|
|
|
return LDFData<T>::Default;
|
|
|
|
}
|
|
|
|
|
|
|
|
return typed->GetValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
2022-07-28 13:39:57 +00:00
|
|
|
T Entity::GetVarAs(const std::u16string& name) const {
|
2021-12-05 17:54:36 +00:00
|
|
|
const auto data = GetVarAsString(name);
|
|
|
|
|
|
|
|
T value;
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (!GeneralUtils::TryParse(data, value)) {
|
2021-12-05 17:54:36 +00:00
|
|
|
return LDFData<T>::Default;
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
2022-07-28 13:39:57 +00:00
|
|
|
void Entity::SetVar(const std::u16string& name, T value) {
|
2021-12-05 17:54:36 +00:00
|
|
|
auto* data = GetVarData(name);
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (data == nullptr) {
|
2021-12-05 17:54:36 +00:00
|
|
|
auto* data = new LDFData<T>(name, value);
|
|
|
|
|
|
|
|
m_Settings.push_back(data);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto* typed = dynamic_cast<LDFData<T>*>(data);
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (typed == nullptr) {
|
2021-12-05 17:54:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
typed->SetValue(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
void Entity::SetNetworkVar(const std::u16string& name, T value, const SystemAddress& sysAddr) {
|
2022-07-28 13:39:57 +00:00
|
|
|
LDFData<T>* newData = nullptr;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
for (auto* data : m_NetworkSettings) {
|
|
|
|
if (data->GetKey() != name)
|
|
|
|
continue;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
newData = dynamic_cast<LDFData<T>*>(data);
|
|
|
|
if (newData != nullptr) {
|
|
|
|
newData->SetValue(value);
|
|
|
|
} else { // If we're changing types
|
|
|
|
m_NetworkSettings.erase(
|
2021-12-05 17:54:36 +00:00
|
|
|
std::remove(m_NetworkSettings.begin(), m_NetworkSettings.end(), data), m_NetworkSettings.end()
|
|
|
|
);
|
2022-07-28 13:39:57 +00:00
|
|
|
delete data;
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
break;
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (newData == nullptr) {
|
|
|
|
newData = new LDFData<T>(name, value);
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
m_NetworkSettings.push_back(newData);
|
|
|
|
SendNetworkVar(newData->GetString(true), sysAddr);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
void Entity::SetNetworkVar(const std::u16string& name, std::vector<T> values, const SystemAddress& sysAddr) {
|
2022-07-28 13:39:57 +00:00
|
|
|
std::stringstream updates;
|
|
|
|
auto index = 1;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
for (const auto& value : values) {
|
|
|
|
LDFData<T>* newData = nullptr;
|
|
|
|
const auto& indexedName = name + u"." + GeneralUtils::to_u16string(index);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
for (auto* data : m_NetworkSettings) {
|
|
|
|
if (data->GetKey() != indexedName)
|
|
|
|
continue;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
newData = dynamic_cast<LDFData<T>*>(data);
|
|
|
|
newData->SetValue(value);
|
|
|
|
break;
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (newData == nullptr) {
|
|
|
|
newData = new LDFData<T>(indexedName, value);
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
m_NetworkSettings.push_back(newData);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (index == values.size()) {
|
|
|
|
updates << newData->GetString(true);
|
|
|
|
} else {
|
|
|
|
updates << newData->GetString(true) << "\n";
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
index++;
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
SendNetworkVar(updates.str(), sysAddr);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
T Entity::GetNetworkVar(const std::u16string& name) {
|
2022-07-28 13:39:57 +00:00
|
|
|
for (auto* data : m_NetworkSettings) {
|
|
|
|
if (data == nullptr || data->GetKey() != name)
|
|
|
|
continue;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
auto* typed = dynamic_cast<LDFData<T>*>(data);
|
|
|
|
if (typed == nullptr)
|
|
|
|
continue;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
return typed->GetValue();
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
return LDFData<T>::Default;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
2023-06-07 03:48:30 +00:00
|
|
|
|
|
|
|
template<typename ComponentType, typename...ConstructorValues>
|
|
|
|
std::shared_ptr<ComponentType> Entity::AddComponent(ConstructorValues...arguments) {
|
|
|
|
if (GetComponent<ComponentType>()) return nullptr;
|
|
|
|
|
|
|
|
m_Components.insert_or_assign(ComponentType::ComponentType, std::make_shared<ComponentType>(arguments...));
|
|
|
|
}
|