2021-12-05 17:54:36 +00:00
|
|
|
#include "PossessableComponent.h"
|
|
|
|
#include "PossessorComponent.h"
|
|
|
|
#include "EntityManager.h"
|
2022-07-17 07:35:11 +00:00
|
|
|
#include "Inventory.h"
|
2022-07-09 03:25:15 +00:00
|
|
|
#include "Item.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-09 03:25:15 +00:00
|
|
|
PossessableComponent::PossessableComponent(Entity* parent, uint32_t componentId) : Component(parent) {
|
|
|
|
m_Possessor = LWOOBJID_EMPTY;
|
2022-07-17 07:35:11 +00:00
|
|
|
CDItemComponent item = Inventory::FindItemComponent(m_Parent->GetLOT());
|
|
|
|
m_AnimationFlag = static_cast<eAnimationFlags>(item.animationFlag);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-09 03:25:15 +00:00
|
|
|
// Get the possession Type from the CDClient
|
|
|
|
auto query = CDClientDatabase::CreatePreppedStmt("SELECT possessionType, depossessOnHit FROM PossessableComponent WHERE id = ?;");
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-09 03:25:15 +00:00
|
|
|
query.bind(1, static_cast<int>(componentId));
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-09 03:25:15 +00:00
|
|
|
auto result = query.execQuery();
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-09 03:25:15 +00:00
|
|
|
// Should a result not exist for this default to attached visible
|
|
|
|
if (!result.eof()) {
|
2024-04-14 04:41:51 +00:00
|
|
|
m_PossessionType = static_cast<ePossessionType>(result.getIntField("possessionType", 1)); // Default to Attached Visible
|
|
|
|
m_DepossessOnHit = static_cast<bool>(result.getIntField("depossessOnHit", 0));
|
2022-07-09 03:25:15 +00:00
|
|
|
} else {
|
|
|
|
m_PossessionType = ePossessionType::ATTACHED_VISIBLE;
|
|
|
|
m_DepossessOnHit = false;
|
|
|
|
}
|
|
|
|
result.finalize();
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2024-02-27 07:25:44 +00:00
|
|
|
void PossessableComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) {
|
|
|
|
outBitStream.Write(m_DirtyPossessable || bIsInitialUpdate);
|
2022-07-09 03:25:15 +00:00
|
|
|
if (m_DirtyPossessable || bIsInitialUpdate) {
|
2022-09-02 18:49:19 +00:00
|
|
|
m_DirtyPossessable = false; // reset flag
|
2024-02-27 07:25:44 +00:00
|
|
|
outBitStream.Write(m_Possessor != LWOOBJID_EMPTY);
|
|
|
|
if (m_Possessor != LWOOBJID_EMPTY) outBitStream.Write(m_Possessor);
|
2022-07-09 03:25:15 +00:00
|
|
|
|
2024-02-27 07:25:44 +00:00
|
|
|
outBitStream.Write(m_AnimationFlag != eAnimationFlags::IDLE_NONE);
|
|
|
|
if (m_AnimationFlag != eAnimationFlags::IDLE_NONE) outBitStream.Write(m_AnimationFlag);
|
2022-07-09 03:25:15 +00:00
|
|
|
|
2024-02-27 07:25:44 +00:00
|
|
|
outBitStream.Write(m_ImmediatelyDepossess);
|
2022-09-02 18:49:19 +00:00
|
|
|
m_ImmediatelyDepossess = false; // reset flag
|
2022-07-09 03:25:15 +00:00
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2022-09-02 18:49:19 +00:00
|
|
|
void PossessableComponent::Dismount() {
|
|
|
|
SetPossessor(LWOOBJID_EMPTY);
|
|
|
|
if (m_ItemSpawned) m_Parent->ScheduleKillAfterUpdate();
|
|
|
|
}
|
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
void PossessableComponent::OnUse(Entity* originator) {
|
2022-09-02 18:49:19 +00:00
|
|
|
auto* possessor = originator->GetComponent<PossessorComponent>();
|
|
|
|
if (possessor) {
|
|
|
|
possessor->Mount(m_Parent);
|
|
|
|
}
|
2022-07-09 03:25:15 +00:00
|
|
|
}
|