Possessor and possessable additions (#619)

* possessor-fixup and possessable additions

* comment and docstring fixes

* fix possessable initialization

* split animation flags into it's own header
remove unnecessary checks
This commit is contained in:
Aaron Kimbrell 2022-07-08 22:25:15 -05:00 committed by GitHub
parent 22b2516107
commit 3865a186a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 178 additions and 89 deletions

View File

@ -664,7 +664,6 @@ enum ePlayerFlags {
NJ_WU_SHOW_DAILY_CHEST = 2099
};
//======== FUNC ===========
template<typename T>

View File

@ -0,0 +1,44 @@
#pragma once
#ifndef __EANINMATIONFLAGS__H__
#define __EANINMATIONFLAGS__H__
#include <cstdint>
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__

View File

@ -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) {

View File

@ -1,51 +1,43 @@
#include "PossessableComponent.h"
#include "PossessorComponent.h"
#include "EntityManager.h"
#include "Item.h"
PossessableComponent::PossessableComponent(Entity* parent) : Component(parent)
{
PossessableComponent::PossessableComponent(Entity* parent, uint32_t componentId) : Component(parent){
m_Possessor = LWOOBJID_EMPTY;
}
PossessableComponent::~PossessableComponent()
{
// Get the possession Type from the CDClient
auto query = CDClientDatabase::CreatePreppedStmt("SELECT possessionType, depossessOnHit FROM PossessableComponent WHERE id = ?;");
}
query.bind(1, static_cast<int>(componentId));
void PossessableComponent::SetPossessor(LWOOBJID value)
{
m_Possessor = value;
}
auto result = query.execQuery();
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();
// Should a result not exist for this default to attached visible
if (!result.eof()) {
m_PossessionType = static_cast<ePossessionType>(result.getIntField(0, 0));
m_DepossessOnHit = static_cast<bool>(result.getIntField(1, 0));
} else {
m_PossessionType = ePossessionType::ATTACHED_VISIBLE;
m_DepossessOnHit = false;
}
result.finalize();
}
void PossessableComponent::Update(float deltaTime)
{
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);
outBitStream->Write(m_AnimationFlag != eAnimationFlags::IDLE_INVALID);
if(m_AnimationFlag != eAnimationFlags::IDLE_INVALID) outBitStream->Write(m_AnimationFlag);
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
}

View File

@ -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:
public:
static const uint32_t ComponentType = COMPONENT_TYPE_POSSESSABLE;
PossessableComponent(Entity* parentEntity);
~PossessableComponent() override;
PossessableComponent(Entity* parentEntity, uint32_t componentId);
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags);
void Update(float deltaTime) override;
/**
* Sets the possessor of this entity
* @param value the ID of the possessor to set
*/
void SetPossessor(LWOOBJID value);
void SetPossessor(LWOOBJID value) { m_Possessor = value; m_DirtyPossessable = true;};
/**
* Returns the possessor of this entity
* @return the possessor of this entitythe
* @return the possessor of this entity
*/
LWOOBJID GetPossessor() const;
LWOOBJID GetPossessor() const { return m_Possessor; };
/**
* Handles an OnUsed event by some other entity, if said entity has a PossessorComponent it becomes the possessor
* 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:
private:
/**
* The possessor of this entity, e.g. the entity that controls this entity
* @brief Whether the possessor is dirty
*/
LWOOBJID m_Possessor;
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;
};

View File

@ -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;
};

View File

@ -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.

View File

@ -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<PossessorComponent>();
/*if (possessorComponent != nullptr) {
possessorComponent->SetPossessable(self->GetObjectID());
EntityManager::Instance()->SerializeEntity(player);
}*/
auto* characterComponent = player->GetComponent<CharacterComponent>();
if (characterComponent != nullptr) {
@ -111,7 +103,7 @@ void SGCannon::OnActivityStateChangeRequest(Entity *self, LWOOBJID senderID, int
auto possessor = player->GetComponent<PossessorComponent>();
if(possessor) {
possessor->SetPossessable(self->GetObjectID());
possessor->SetPossessableType(0);
possessor->SetPossessableType(ePossessionType::NO_POSSESSION);
}
EntityManager::Instance()->SerializeEntity(player);