PossessionComponent pass

This commit is contained in:
David Markowitz 2023-07-09 22:37:28 -07:00
parent 59831fc15d
commit 4d88f63338
2 changed files with 36 additions and 30 deletions

View File

@ -12,29 +12,28 @@ PossessionComponent::PossessionComponent(Entity* parent) : Component(parent) {
} }
PossessionComponent::~PossessionComponent() { PossessionComponent::~PossessionComponent() {
if (m_Possessable != LWOOBJID_EMPTY) { if (m_Possessable == LWOOBJID_EMPTY) return;
auto* mount = EntityManager::Instance()->GetEntity(m_Possessable);
if (mount) { auto* mount = EntityManager::Instance()->GetEntity(m_Possessable);
auto* possessable = mount->GetComponent<PossessableComponent>(); if (!mount) return;
if (possessable) {
if (possessable->GetIsItemSpawned()) { auto* possessable = mount->GetComponent<PossessableComponent>();
GameMessages::SendMarkInventoryItemAsActive(m_ParentEntity->GetObjectID(), false, eUnequippableActiveType::MOUNT, GetMountItemID(), m_ParentEntity->GetSystemAddress()); if (!possessable) return;
}
possessable->Dismount(); if (possessable->GetIsItemSpawned()) {
} GameMessages::SendMarkInventoryItemAsActive(m_ParentEntity->GetObjectID(), false, eUnequippableActiveType::MOUNT, GetMountItemID(), m_ParentEntity->GetSystemAddress());
}
} }
possessable->Dismount();
} }
void PossessionComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) { void PossessionComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) {
outBitStream->Write(m_DirtyPossesor || bIsInitialUpdate); outBitStream->Write(m_DirtyPossesor || bIsInitialUpdate);
if (m_DirtyPossesor || bIsInitialUpdate) { if (m_DirtyPossesor || bIsInitialUpdate) {
m_DirtyPossesor = false;
outBitStream->Write(m_Possessable != LWOOBJID_EMPTY); outBitStream->Write(m_Possessable != LWOOBJID_EMPTY);
if (m_Possessable != LWOOBJID_EMPTY) { if (m_Possessable != LWOOBJID_EMPTY) outBitStream->Write(m_Possessable);
outBitStream->Write(m_Possessable);
}
outBitStream->Write(m_PossessableType); outBitStream->Write(m_PossessableType);
if (!bIsInitialUpdate) m_DirtyPossesor = false;
} }
} }
@ -66,19 +65,18 @@ void PossessionComponent::Dismount(Entity* mount, bool forceDismount) {
// Don't do anything if we are busy dismounting // Don't do anything if we are busy dismounting
if (GetIsDismounting() || !mount) return; if (GetIsDismounting() || !mount) return;
SetIsDismounting(true); SetIsDismounting(true);
if (mount) {
auto* possessableComponent = mount->GetComponent<PossessableComponent>();
if (possessableComponent) {
possessableComponent->SetPossessor(LWOOBJID_EMPTY);
if (forceDismount) possessableComponent->ForceDepossess();
}
EntityManager::Instance()->SerializeEntity(m_ParentEntity);
EntityManager::Instance()->SerializeEntity(mount);
auto* characterComponent = m_ParentEntity->GetComponent<CharacterComponent>();
if (characterComponent) characterComponent->SetIsRacing(false);
}
// Make sure we don't have wacky controls // Make sure we don't have wacky controls
GameMessages::SendSetPlayerControlScheme(m_ParentEntity, eControlScheme::SCHEME_A); GameMessages::SendSetPlayerControlScheme(m_ParentEntity, eControlScheme::SCHEME_A);
if (!mount) return;
auto* possessableComponent = mount->GetComponent<PossessableComponent>();
if (possessableComponent) {
possessableComponent->SetPossessor(LWOOBJID_EMPTY);
if (forceDismount) possessableComponent->ForceDepossess();
}
EntityManager::Instance()->SerializeEntity(m_ParentEntity);
EntityManager::Instance()->SerializeEntity(mount);
auto* characterComponent = m_ParentEntity->GetComponent<CharacterComponent>();
if (characterComponent) characterComponent->SetIsRacing(false);
} }

View File

@ -44,7 +44,11 @@ public:
* Sets the ID that this entity is possessing * Sets the ID that this entity is possessing
* @param value The ID that this entity is possessing * @param value The ID that this entity is possessing
*/ */
void SetPossessable(LWOOBJID value) { m_Possessable = value; m_DirtyPossesor = true; } void SetPossessable(const LWOOBJID& value) {
if (m_Possessable == value) return;
m_Possessable = value;
m_DirtyPossesor = true;
}
/** /**
* Returns the entity that this entity is currently posessing * Returns the entity that this entity is currently posessing
@ -68,7 +72,11 @@ public:
* Sets the possesible type that's currently used, merely used by the shooting gallery if it's 0 * 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 * @param value The possesible type to set
*/ */
void SetPossessableType(ePossessionType value) { m_PossessableType = value; m_DirtyPossesor = true; } void SetPossessableType(ePossessionType value) {
if (m_PossessableType == value) return;
m_PossessableType = value;
m_DirtyPossesor = true;
}
/** /**