breakout possessor from char comp (#606)

* breakout possessor from char comp
Use the correct component for possessor
cleanup scirps that were using possessor improperly
beginnings of mounts

* fix comments
added bounds check
This commit is contained in:
Aaron Kimbrell 2022-06-29 18:50:24 -05:00 committed by GitHub
parent a55162775e
commit 1497d9b35a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 76 additions and 106 deletions

View File

@ -407,8 +407,8 @@ enum eReplicaComponentType : int32_t {
COMPONENT_TYPE_MISSION = 84, //!< The Mission Component
COMPONENT_TYPE_ROCKET_LAUNCH_LUP = 97, //!< The LUP Launchpad Componen
COMPONENT_TYPE_RAIL_ACTIVATOR = 104,
COMPONENT_TYPE_POSSESSOR = 107, //!< The Component 107
COMPONENT_TYPE_POSSESSABLE = 108, //!< The Component 108
COMPONENT_TYPE_POSSESSABLE = 108, //!< The Possessable Component
COMPONENT_TYPE_POSSESSOR = 110, //!< The Possessor Component
COMPONENT_TYPE_BUILD_BORDER = 114, //!< The Build Border Component
COMPONENT_TYPE_DESTROYABLE = 1000, //!< The Destroyable Component

View File

@ -435,6 +435,8 @@ void Entity::Initialize()
}*/
if (compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_CHARACTER) > 0 || m_Character) {
// Character Component always has a possessor component
m_Components.insert(std::make_pair(COMPONENT_TYPE_POSSESSOR, new PossessorComponent(this)));
CharacterComponent* comp = new CharacterComponent(this, m_Character);
m_Components.insert(std::make_pair(COMPONENT_TYPE_CHARACTER, comp));
}
@ -606,10 +608,6 @@ void Entity::Initialize()
m_Components.insert(std::make_pair(COMPONENT_TYPE_RENDER, render));
}
if ((compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_POSSESSOR) > 0) || m_Character) {
m_Components.insert(std::make_pair(COMPONENT_TYPE_POSSESSOR, new PossessorComponent(this)));
}
if ((compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_MISSION_OFFER) > 0) || m_Character) {
m_Components.insert(std::make_pair(COMPONENT_TYPE_MISSION_OFFER, new MissionOfferComponent(this, m_TemplateID)));
}
@ -1057,8 +1055,15 @@ void Entity::WriteComponents(RakNet::BitStream* outBitStream, eReplicaPacketType
}
CharacterComponent* characterComponent;
if (TryGetComponent(COMPONENT_TYPE_CHARACTER, characterComponent))
{
if (TryGetComponent(COMPONENT_TYPE_CHARACTER, characterComponent)) {
PossessorComponent* possessorComponent;
if (TryGetComponent(COMPONENT_TYPE_POSSESSOR, possessorComponent)) {
possessorComponent->Serialize(outBitStream, bIsInitialUpdate, flags);
} else {
// Should never happen, but just to be safe
outBitStream->Write0();
}
characterComponent->Serialize(outBitStream, bIsInitialUpdate, flags);
}
@ -1164,11 +1169,10 @@ void Entity::WriteComponents(RakNet::BitStream* outBitStream, eReplicaPacketType
outBitStream->Write<uint32_t>(0x40000000);
}
PossessorComponent* possessorComponent;
if (TryGetComponent(COMPONENT_TYPE_POSSESSOR, possessorComponent))
{
possessorComponent->Serialize(outBitStream, bIsInitialUpdate, flags);
}
// BBB Component, unused currently
// Need to to write0 so that is serlaizese correctly
// TODO: Implement BBB Component
outBitStream->Write0();
/*
if (m_Trigger != nullptr)

View File

@ -10,7 +10,6 @@
#include "InventoryComponent.h"
#include "ControllablePhysicsComponent.h"
#include "EntityManager.h"
#include "PossessorComponent.h"
#include "VehiclePhysicsComponent.h"
#include "GameMessages.h"
#include "Item.h"
@ -81,13 +80,6 @@ CharacterComponent::~CharacterComponent() {
}
void CharacterComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) {
outBitStream->Write(m_IsRacing);
if (m_IsRacing) {
outBitStream->Write1();
outBitStream->Write(m_VehicleObjectID);
outBitStream->Write<uint8_t>(0);
}
outBitStream->Write1();
outBitStream->Write(m_Level);
outBitStream->Write0();

View File

@ -143,24 +143,6 @@ public:
*/
void SetIsRacing(bool isRacing) { m_IsRacing = isRacing; }
/**
* Gets the (optional) object ID of the vehicle the character is currently in
* @return the object ID of the vehilce the character is in
*/
const LWOOBJID GetVehicleObjectID() const { return m_VehicleObjectID; }
/**
* Sets the (optional) object ID of the vehicle the character is currently in
* @param vehicleObjectID the ID of the vehicle the character is in
*/
void SetVehicleObjectID(LWOOBJID vehicleObjectID) { m_VehicleObjectID = vehicleObjectID; }
/**
* 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; }
/**
* Gets whether this character has PvP enabled, allowing combat between players
* @return
@ -304,11 +286,6 @@ private:
*/
bool m_IsRacing;
/**
* The object ID of the vehicle the character is currently in
*/
LWOOBJID m_VehicleObjectID;
/**
* Possessible type, used by the shooting gallery
*/

View File

@ -986,19 +986,11 @@ void InventoryComponent::EquipItem(Item* item, const bool skipChecks)
// #107
auto* possessorComponent = m_Parent->GetComponent<PossessorComponent>();
if (possessorComponent != nullptr)
{
previousPossessorID = possessorComponent->GetPossessable();
possessorComponent->SetPossessable(carEntity->GetObjectID());
}
if (possessorComponent) possessorComponent->SetPossessable(carEntity->GetObjectID());
auto* characterComponent = m_Parent->GetComponent<CharacterComponent>();
if (characterComponent != nullptr)
{
characterComponent->SetIsRacing(true);
characterComponent->SetVehicleObjectID(carEntity->GetObjectID());
}
if (characterComponent) characterComponent->SetIsRacing(true);
EntityManager::Instance()->ConstructEntity(carEntity);
EntityManager::Instance()->SerializeEntity(m_Parent);

View File

@ -1,35 +1,21 @@
#include "PossessorComponent.h"
PossessorComponent::PossessorComponent(Entity* parent) : Component(parent)
{
PossessorComponent::PossessorComponent(Entity* parent) : Component(parent) {
m_Possessable = LWOOBJID_EMPTY;
}
PossessorComponent::~PossessorComponent()
{
PossessorComponent::~PossessorComponent() {}
}
void PossessorComponent::SetPossessable(LWOOBJID value)
{
m_Possessable = value;
}
LWOOBJID PossessorComponent::GetPossessable() const
{
return m_Possessable;
}
void PossessorComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags)
{
void PossessorComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) {
outBitStream->Write(m_DirtyPossesor || bIsInitialUpdate);
if (m_DirtyPossesor || bIsInitialUpdate) {
m_DirtyPossesor = false;
outBitStream->Write(m_Possessable != LWOOBJID_EMPTY);
if (m_Possessable != LWOOBJID_EMPTY)
{
if (m_Possessable != LWOOBJID_EMPTY) {
outBitStream->Write(m_Possessable);
}
}
void PossessorComponent::Update(float deltaTime)
{
outBitStream->Write(m_PossessableType);
}
}

View File

@ -8,31 +8,48 @@
* Represents an entity that can posess other entities. Generally used by players to drive a car.
*/
class PossessorComponent : public Component {
public:
public:
static const uint32_t ComponentType = COMPONENT_TYPE_POSSESSOR;
PossessorComponent(Entity* parent);
~PossessorComponent() override;
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags);
void Update(float deltaTime) override;
/**
* Sets the entity that this entity is possessing
* @param value the ID of the entity this ID should posess
*/
void SetPossessable(LWOOBJID value);
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;
LWOOBJID GetPossessable() const { return m_Possessable; }
private:
private:
/**
* The ID of the entity this entity is possessing (e.g. the ID of a car)
*/
LWOOBJID m_Possessable;
/**
* @brief possessable type
*
*/
uint8_t m_PossessableType;
/**
* @brief if the possessor is dirty
*
*/
bool m_DirtyPossesor;
};

View File

@ -219,7 +219,6 @@ void RacingControlComponent::LoadPlayerVehicle(Entity *player,
if (characterComponent != nullptr) {
characterComponent->SetIsRacing(true);
characterComponent->SetVehicleObjectID(carEntity->GetObjectID());
}
// Init the player's racing entry.

View File

@ -107,9 +107,12 @@ void SGCannon::OnActivityStateChangeRequest(Entity *self, LWOOBJID senderID, int
if (characterComponent != nullptr) {
characterComponent->SetIsRacing(true);
characterComponent->SetVehicleObjectID(self->GetObjectID());
characterComponent->SetPossessableType(0);
characterComponent->SetCurrentActivity(2);
auto possessor = player->GetComponent<PossessorComponent>();
if(possessor) {
possessor->SetPossessable(self->GetObjectID());
possessor->SetPossessableType(0);
}
EntityManager::Instance()->SerializeEntity(player);
}