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() {
if (m_Possessable != LWOOBJID_EMPTY) {
if (m_Possessable == LWOOBJID_EMPTY) return;
auto* mount = EntityManager::Instance()->GetEntity(m_Possessable);
if (mount) {
if (!mount) return;
auto* possessable = mount->GetComponent<PossessableComponent>();
if (possessable) {
if (!possessable) return;
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) {
outBitStream->Write(m_DirtyPossesor || bIsInitialUpdate);
if (m_DirtyPossesor || bIsInitialUpdate) {
m_DirtyPossesor = false;
outBitStream->Write(m_Possessable != LWOOBJID_EMPTY);
if (m_Possessable != LWOOBJID_EMPTY) {
outBitStream->Write(m_Possessable);
}
if (m_Possessable != LWOOBJID_EMPTY) outBitStream->Write(m_Possessable);
outBitStream->Write(m_PossessableType);
if (!bIsInitialUpdate) m_DirtyPossesor = false;
}
}
@ -66,8 +65,10 @@ void PossessionComponent::Dismount(Entity* mount, bool forceDismount) {
// Don't do anything if we are busy dismounting
if (GetIsDismounting() || !mount) return;
SetIsDismounting(true);
// Make sure we don't have wacky controls
GameMessages::SendSetPlayerControlScheme(m_ParentEntity, eControlScheme::SCHEME_A);
if (mount) {
if (!mount) return;
auto* possessableComponent = mount->GetComponent<PossessableComponent>();
if (possessableComponent) {
possessableComponent->SetPossessor(LWOOBJID_EMPTY);
@ -79,6 +80,3 @@ void PossessionComponent::Dismount(Entity* mount, bool forceDismount) {
auto* characterComponent = m_ParentEntity->GetComponent<CharacterComponent>();
if (characterComponent) characterComponent->SetIsRacing(false);
}
// Make sure we don't have wacky controls
GameMessages::SendSetPlayerControlScheme(m_ParentEntity, eControlScheme::SCHEME_A);
}

View File

@ -44,7 +44,11 @@ public:
* Sets 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
@ -68,7 +72,11 @@ public:
* 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; }
void SetPossessableType(ePossessionType value) {
if (m_PossessableType == value) return;
m_PossessableType = value;
m_DirtyPossesor = true;
}
/**