2023-06-26 17:36:36 +00:00
|
|
|
#include "PossessionComponent.h"
|
2022-09-02 18:49:19 +00:00
|
|
|
#include "PossessableComponent.h"
|
|
|
|
#include "CharacterComponent.h"
|
|
|
|
#include "EntityManager.h"
|
|
|
|
#include "GameMessages.h"
|
|
|
|
#include "eUnequippableActiveType.h"
|
2023-05-02 22:39:21 +00:00
|
|
|
#include "eControlScheme.h"
|
|
|
|
#include "eStateChangeType.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-06-26 17:36:36 +00:00
|
|
|
PossessionComponent::PossessionComponent(Entity* parent) : Component(parent) {
|
2022-06-29 23:50:24 +00:00
|
|
|
m_Possessable = LWOOBJID_EMPTY;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2023-06-26 17:36:36 +00:00
|
|
|
PossessionComponent::~PossessionComponent() {
|
2023-07-10 05:37:28 +00:00
|
|
|
if (m_Possessable == LWOOBJID_EMPTY) return;
|
|
|
|
|
|
|
|
auto* mount = EntityManager::Instance()->GetEntity(m_Possessable);
|
|
|
|
if (!mount) return;
|
|
|
|
|
|
|
|
auto* possessable = mount->GetComponent<PossessableComponent>();
|
|
|
|
if (!possessable) return;
|
|
|
|
|
|
|
|
if (possessable->GetIsItemSpawned()) {
|
|
|
|
GameMessages::SendMarkInventoryItemAsActive(m_ParentEntity->GetObjectID(), false, eUnequippableActiveType::MOUNT, GetMountItemID(), m_ParentEntity->GetSystemAddress());
|
2022-09-02 18:49:19 +00:00
|
|
|
}
|
2023-07-10 05:37:28 +00:00
|
|
|
possessable->Dismount();
|
2022-09-02 18:49:19 +00:00
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-06-26 17:36:36 +00:00
|
|
|
void PossessionComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) {
|
2022-06-29 23:50:24 +00:00
|
|
|
outBitStream->Write(m_DirtyPossesor || bIsInitialUpdate);
|
|
|
|
if (m_DirtyPossesor || bIsInitialUpdate) {
|
|
|
|
outBitStream->Write(m_Possessable != LWOOBJID_EMPTY);
|
2023-07-10 05:37:28 +00:00
|
|
|
if (m_Possessable != LWOOBJID_EMPTY) outBitStream->Write(m_Possessable);
|
|
|
|
|
2022-06-29 23:50:24 +00:00
|
|
|
outBitStream->Write(m_PossessableType);
|
2023-07-10 05:37:28 +00:00
|
|
|
if (!bIsInitialUpdate) m_DirtyPossesor = false;
|
2022-06-29 23:50:24 +00:00
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
2022-09-02 18:49:19 +00:00
|
|
|
|
2023-06-26 17:36:36 +00:00
|
|
|
void PossessionComponent::Mount(Entity* mount) {
|
2022-09-02 18:49:19 +00:00
|
|
|
// Don't do anything if we are busy dismounting
|
|
|
|
if (GetIsDismounting() || !mount) return;
|
|
|
|
|
2023-06-09 09:46:01 +00:00
|
|
|
GameMessages::SendSetMountInventoryID(m_ParentEntity, mount->GetObjectID(), UNASSIGNED_SYSTEM_ADDRESS);
|
2023-06-09 08:27:05 +00:00
|
|
|
auto* possessableComponent = mount->GetComponent<PossessableComponent>();
|
2022-09-02 18:49:19 +00:00
|
|
|
if (possessableComponent) {
|
2023-06-09 09:46:01 +00:00
|
|
|
possessableComponent->SetPossessor(m_ParentEntity->GetObjectID());
|
2022-09-02 18:49:19 +00:00
|
|
|
SetPossessable(mount->GetObjectID());
|
|
|
|
SetPossessableType(possessableComponent->GetPossessionType());
|
|
|
|
}
|
|
|
|
|
2023-06-09 09:46:01 +00:00
|
|
|
auto* characterComponent = m_ParentEntity->GetComponent<CharacterComponent>();
|
2022-09-02 18:49:19 +00:00
|
|
|
if (characterComponent) characterComponent->SetIsRacing(true);
|
|
|
|
|
|
|
|
// GM's to send
|
2023-06-09 09:46:01 +00:00
|
|
|
GameMessages::SendSetJetPackMode(m_ParentEntity, false);
|
|
|
|
GameMessages::SendVehicleUnlockInput(mount->GetObjectID(), false, m_ParentEntity->GetSystemAddress());
|
|
|
|
GameMessages::SendSetStunned(m_ParentEntity->GetObjectID(), eStateChangeType::PUSH, m_ParentEntity->GetSystemAddress(), LWOOBJID_EMPTY, true, false, true, false, false, false, false, true, true, true, true, true, true, true, true, true);
|
2022-09-02 18:49:19 +00:00
|
|
|
|
2023-06-09 09:46:01 +00:00
|
|
|
EntityManager::Instance()->SerializeEntity(m_ParentEntity);
|
2022-09-02 18:49:19 +00:00
|
|
|
EntityManager::Instance()->SerializeEntity(mount);
|
|
|
|
}
|
|
|
|
|
2023-06-26 17:36:36 +00:00
|
|
|
void PossessionComponent::Dismount(Entity* mount, bool forceDismount) {
|
2022-09-02 18:49:19 +00:00
|
|
|
// Don't do anything if we are busy dismounting
|
|
|
|
if (GetIsDismounting() || !mount) return;
|
|
|
|
SetIsDismounting(true);
|
|
|
|
// Make sure we don't have wacky controls
|
2023-06-09 09:46:01 +00:00
|
|
|
GameMessages::SendSetPlayerControlScheme(m_ParentEntity, eControlScheme::SCHEME_A);
|
2023-07-10 05:37:28 +00:00
|
|
|
|
|
|
|
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);
|
2022-09-02 18:49:19 +00:00
|
|
|
}
|