diff --git a/dCommon/dCommonVars.h b/dCommon/dCommonVars.h index 4cbdb61c..e941413b 100644 --- a/dCommon/dCommonVars.h +++ b/dCommon/dCommonVars.h @@ -664,7 +664,6 @@ enum ePlayerFlags { NJ_WU_SHOW_DAILY_CHEST = 2099 }; - //======== FUNC =========== template diff --git a/dCommon/eAninmationFlags.h b/dCommon/eAninmationFlags.h new file mode 100644 index 00000000..09cfde22 --- /dev/null +++ b/dCommon/eAninmationFlags.h @@ -0,0 +1,44 @@ +#pragma once + +#ifndef __EANINMATIONFLAGS__H__ +#define __EANINMATIONFLAGS__H__ + +#include + +enum class eAnimationFlags : uint32_t { + IDLE_INVALID = 0, // made up, for internal use!!! + IDLE_BASIC, + IDLE_SWIM, + IDLE_CARRY, + IDLE_SWORD, + IDLE_HAMMER, + IDLE_SPEAR, + IDLE_PISTOL, + IDLE_BOW, + IDLE_COMBAT, + IDLE_JETPACK, + IDLE_HORSE, + IDLE_SG, + IDLE_ORGAN, + IDLE_SKATEBOARD, + IDLE_DAREDEVIL, + IDLE_SAMURAI, + IDLE_SUMMONER, + IDLE_BUCCANEER, + IDLE_MISC, + IDLE_NINJA, + IDLE_MISC1, + IDLE_MISC2, + IDLE_MISC3, + IDLE_MISC4, + IDLE_MISC5, + IDLE_MISC6, + IDLE_MISC7, + IDLE_MISC8, + IDLE_MISC9, + IDLE_MISC10, + IDLE_MISC11, + IDLE_MISC12 +}; + +#endif //!__EANINMATIONFLAGS__H__ \ No newline at end of file diff --git a/dGame/Entity.cpp b/dGame/Entity.cpp index bb7e0335..68277cd8 100644 --- a/dGame/Entity.cpp +++ b/dGame/Entity.cpp @@ -208,8 +208,9 @@ void Entity::Initialize() m_Components.insert(std::make_pair(COMPONENT_TYPE_ZONE_CONTROL, nullptr)); } - if (compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_POSSESSABLE) > 0) { - m_Components.insert(std::make_pair(COMPONENT_TYPE_POSSESSABLE, new PossessableComponent(this))); + uint32_t possessableComponentId = compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_POSSESSABLE); + if (possessableComponentId > 0) { + m_Components.insert(std::make_pair(COMPONENT_TYPE_POSSESSABLE, new PossessableComponent(this, possessableComponentId))); } if (compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_MODULE_ASSEMBLY) > 0) { diff --git a/dGame/dComponents/PossessableComponent.cpp b/dGame/dComponents/PossessableComponent.cpp index d4fd0d62..1d721466 100644 --- a/dGame/dComponents/PossessableComponent.cpp +++ b/dGame/dComponents/PossessableComponent.cpp @@ -1,51 +1,43 @@ #include "PossessableComponent.h" - #include "PossessorComponent.h" #include "EntityManager.h" +#include "Item.h" -PossessableComponent::PossessableComponent(Entity* parent) : Component(parent) -{ - m_Possessor = LWOOBJID_EMPTY; +PossessableComponent::PossessableComponent(Entity* parent, uint32_t componentId) : Component(parent){ + m_Possessor = LWOOBJID_EMPTY; + + // Get the possession Type from the CDClient + auto query = CDClientDatabase::CreatePreppedStmt("SELECT possessionType, depossessOnHit FROM PossessableComponent WHERE id = ?;"); + + query.bind(1, static_cast(componentId)); + + auto result = query.execQuery(); + + // Should a result not exist for this default to attached visible + if (!result.eof()) { + m_PossessionType = static_cast(result.getIntField(0, 0)); + m_DepossessOnHit = static_cast(result.getIntField(1, 0)); + } else { + m_PossessionType = ePossessionType::ATTACHED_VISIBLE; + m_DepossessOnHit = false; + } + result.finalize(); } -PossessableComponent::~PossessableComponent() -{ - -} +void PossessableComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) { + outBitStream->Write(m_DirtyPossessable || bIsInitialUpdate); + if (m_DirtyPossessable || bIsInitialUpdate) { + m_DirtyPossessable = false; + outBitStream->Write(m_Possessor != LWOOBJID_EMPTY); + if (m_Possessor != LWOOBJID_EMPTY) outBitStream->Write(m_Possessor); -void PossessableComponent::SetPossessor(LWOOBJID value) -{ - m_Possessor = value; -} + outBitStream->Write(m_AnimationFlag != eAnimationFlags::IDLE_INVALID); + if(m_AnimationFlag != eAnimationFlags::IDLE_INVALID) outBitStream->Write(m_AnimationFlag); -LWOOBJID PossessableComponent::GetPossessor() const -{ - return m_Possessor; -} - -void PossessableComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) -{ - outBitStream->Write(m_Possessor != LWOOBJID_EMPTY); - if (m_Possessor != LWOOBJID_EMPTY) - { - outBitStream->Write1(); - outBitStream->Write(m_Possessor); - outBitStream->Write0(); - outBitStream->Write0(); - } -} - -void PossessableComponent::Update(float deltaTime) -{ - + outBitStream->Write(m_ImmediatelyDepossess); + } } void PossessableComponent::OnUse(Entity* originator) { - PossessorComponent* possessorComponent; - if (originator->TryGetComponent(COMPONENT_TYPE_POSSESSOR, possessorComponent)) { - SetPossessor(originator->GetObjectID()); - possessorComponent->SetPossessable(m_Parent->GetObjectID()); - EntityManager::Instance()->SerializeEntity(m_Parent); - EntityManager::Instance()->SerializeEntity(originator); - } -} + // TODO: Implement this +} \ No newline at end of file diff --git a/dGame/dComponents/PossessableComponent.h b/dGame/dComponents/PossessableComponent.h index 744ebfc5..5eefaaf4 100644 --- a/dGame/dComponents/PossessableComponent.h +++ b/dGame/dComponents/PossessableComponent.h @@ -3,44 +3,96 @@ #include "BitStream.h" #include "Entity.h" #include "Component.h" +#include "Item.h" +#include "PossessorComponent.h" +#include "eAninmationFlags.h" /** * Represents an entity that can be controlled by some other entity, generally used by cars to indicate that some * player is controlling it. */ class PossessableComponent : public Component { -public: - static const uint32_t ComponentType = COMPONENT_TYPE_POSSESSABLE; - - PossessableComponent(Entity* parentEntity); - ~PossessableComponent() override; + public: + static const uint32_t ComponentType = COMPONENT_TYPE_POSSESSABLE; - void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags); - void Update(float deltaTime) override; + PossessableComponent(Entity* parentEntity, uint32_t componentId); - /** - * Sets the possessor of this entity - * @param value the ID of the possessor to set - */ - void SetPossessor(LWOOBJID value); + void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags); - /** - * Returns the possessor of this entity - * @return the possessor of this entitythe - */ - LWOOBJID GetPossessor() const; + /** + * Sets the possessor of this entity + * @param value the ID of the possessor to set + */ + void SetPossessor(LWOOBJID value) { m_Possessor = value; m_DirtyPossessable = true;}; - /** - * Handles an OnUsed event by some other entity, if said entity has a PossessorComponent it becomes the possessor - * of this entity - * @param originator the entity that caused the event to trigger - */ - void OnUse(Entity* originator) override; + /** + * Returns the possessor of this entity + * @return the possessor of this entity + */ + LWOOBJID GetPossessor() const { return m_Possessor; }; -private: + /** + * Sets the animation Flag of the possessable + * @param value the animation flag to set to + */ + void SetAnimationFlag(eAnimationFlags value) { m_AnimationFlag = value; m_DirtyPossessable = true;}; + + /** + * Returns the possession type of this entity + * @return the possession type of this entity + */ + ePossessionType GetPossessionType() const { return m_PossessionType; }; + + /** + * Returns if the entity should deposses on hit + * @return if the entity should deposses on hit + */ + bool GetDepossessOnHit() const { return m_DepossessOnHit; }; + + /** + * Forcibly depossess the entity + */ + void ForceDepossess() { m_ImmediatelyDepossess = true; m_DirtyPossessable = true;}; + + /** + * Handles an OnUsed event by some other entity, if said entity has a Possessor it becomes the possessor + * of this entity + * @param originator the entity that caused the event to trigger + */ + void OnUse(Entity* originator) override; + + private: + + /** + * @brief Whether the possessor is dirty + */ + bool m_DirtyPossessable = true; + + /** + * @brief The possessor of this entity, e.g. the entity that controls this entity + */ + LWOOBJID m_Possessor = LWOOBJID_EMPTY; + + /** + * @brief The type of possesstion to use on this entity + */ + ePossessionType m_PossessionType = ePossessionType::NO_POSSESSION; + + /** + * @brief Should the possessable be dismount on hit + */ + bool m_DepossessOnHit = false; + + /** + * @brief What animaiton flag to use + * + */ + eAnimationFlags m_AnimationFlag = eAnimationFlags::IDLE_INVALID; + + /** + * @brief Should this be immediately depossessed + * + */ + bool m_ImmediatelyDepossess = false; - /** - * The possessor of this entity, e.g. the entity that controls this entity - */ - LWOOBJID m_Possessor; }; diff --git a/dGame/dComponents/PossessorComponent.h b/dGame/dComponents/PossessorComponent.h index f3389274..f202b907 100644 --- a/dGame/dComponents/PossessorComponent.h +++ b/dGame/dComponents/PossessorComponent.h @@ -4,6 +4,14 @@ #include "Entity.h" #include "Component.h" +// possession types +enum class ePossessionType : uint8_t { + NO_POSSESSION = 0, + ATTACHED_VISIBLE, + NOT_ATTACHED_VISIBLE, + NOT_ATTACHED_NOT_VISIBLE, +}; + /** * Represents an entity that can posess other entities. Generally used by players to drive a car. */ @@ -22,34 +30,34 @@ class PossessorComponent : public Component { */ void SetPossessable(LWOOBJID value) { m_Possessable = value; m_DirtyPossesor = true; } - /** - * Sets the possesible type that's currently used, merely used by the shooting gallery if it's 0 - * @param value the possesible type to set - */ - void SetPossessableType(uint8_t value) { m_PossessableType = value; m_DirtyPossesor = true; } - /** * Returns the entity that this entity is currently posessing * @return the entity that this entity is currently posessing */ LWOOBJID GetPossessable() const { return m_Possessable; } + /** + * Sets the possesible type that's currently used, merely used by the shooting gallery if it's 0 + * @param value the possesible type to set + */ + void SetPossessableType(ePossessionType value) { m_PossessableType = value; m_DirtyPossesor = true; } + private: /** * The ID of the entity this entity is possessing (e.g. the ID of a car) */ - LWOOBJID m_Possessable; + LWOOBJID m_Possessable = LWOOBJID_EMPTY; /** * @brief possessable type * */ - uint8_t m_PossessableType; + ePossessionType m_PossessableType = ePossessionType::NO_POSSESSION; /** * @brief if the possessor is dirty * */ - bool m_DirtyPossesor; + bool m_DirtyPossesor = false; }; diff --git a/dGame/dComponents/RacingControlComponent.cpp b/dGame/dComponents/RacingControlComponent.cpp index d8794114..7bea03f6 100644 --- a/dGame/dComponents/RacingControlComponent.cpp +++ b/dGame/dComponents/RacingControlComponent.cpp @@ -212,6 +212,7 @@ void RacingControlComponent::LoadPlayerVehicle(Entity *player, if (possessorComponent != nullptr) { possessorComponent->SetPossessable(carEntity->GetObjectID()); + possessorComponent->SetPossessableType(ePossessionType::ATTACHED_VISIBLE); // for racing it's always Attached_Visible } // Set the player's current activity as racing. diff --git a/dScripts/SGCannon.cpp b/dScripts/SGCannon.cpp index b1f64b64..ab179226 100644 --- a/dScripts/SGCannon.cpp +++ b/dScripts/SGCannon.cpp @@ -95,14 +95,6 @@ void SGCannon::OnActivityStateChangeRequest(Entity *self, LWOOBJID senderID, int Game::logger->Log("SGCannon", "Shooting gallery component is null\n"); } - auto* possessorComponent = player->GetComponent(); - - /*if (possessorComponent != nullptr) { - possessorComponent->SetPossessable(self->GetObjectID()); - - EntityManager::Instance()->SerializeEntity(player); - }*/ - auto* characterComponent = player->GetComponent(); if (characterComponent != nullptr) { @@ -111,7 +103,7 @@ void SGCannon::OnActivityStateChangeRequest(Entity *self, LWOOBJID senderID, int auto possessor = player->GetComponent(); if(possessor) { possessor->SetPossessable(self->GetObjectID()); - possessor->SetPossessableType(0); + possessor->SetPossessableType(ePossessionType::NO_POSSESSION); } EntityManager::Instance()->SerializeEntity(player);