mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-08-04 17:54:01 +00:00
Possessor and possessable additions (#619)
* possessor-fixup and possessable additions * comment and docstring fixes * fix possessable initialization * split animation flags into it's own header remove unnecessary checks
This commit is contained in:
@@ -1,51 +1,43 @@
|
||||
#include "PossessableComponent.h"
|
||||
|
||||
#include "PossessorComponent.h"
|
||||
#include "EntityManager.h"
|
||||
#include "Item.h"
|
||||
|
||||
PossessableComponent::PossessableComponent(Entity* parent) : Component(parent)
|
||||
{
|
||||
m_Possessor = LWOOBJID_EMPTY;
|
||||
PossessableComponent::PossessableComponent(Entity* parent, uint32_t componentId) : Component(parent){
|
||||
m_Possessor = LWOOBJID_EMPTY;
|
||||
|
||||
// Get the possession Type from the CDClient
|
||||
auto query = CDClientDatabase::CreatePreppedStmt("SELECT possessionType, depossessOnHit FROM PossessableComponent WHERE id = ?;");
|
||||
|
||||
query.bind(1, static_cast<int>(componentId));
|
||||
|
||||
auto result = query.execQuery();
|
||||
|
||||
// Should a result not exist for this default to attached visible
|
||||
if (!result.eof()) {
|
||||
m_PossessionType = static_cast<ePossessionType>(result.getIntField(0, 0));
|
||||
m_DepossessOnHit = static_cast<bool>(result.getIntField(1, 0));
|
||||
} else {
|
||||
m_PossessionType = ePossessionType::ATTACHED_VISIBLE;
|
||||
m_DepossessOnHit = false;
|
||||
}
|
||||
result.finalize();
|
||||
}
|
||||
|
||||
PossessableComponent::~PossessableComponent()
|
||||
{
|
||||
|
||||
}
|
||||
void PossessableComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) {
|
||||
outBitStream->Write(m_DirtyPossessable || bIsInitialUpdate);
|
||||
if (m_DirtyPossessable || bIsInitialUpdate) {
|
||||
m_DirtyPossessable = false;
|
||||
outBitStream->Write(m_Possessor != LWOOBJID_EMPTY);
|
||||
if (m_Possessor != LWOOBJID_EMPTY) outBitStream->Write(m_Possessor);
|
||||
|
||||
void PossessableComponent::SetPossessor(LWOOBJID value)
|
||||
{
|
||||
m_Possessor = value;
|
||||
}
|
||||
outBitStream->Write(m_AnimationFlag != eAnimationFlags::IDLE_INVALID);
|
||||
if(m_AnimationFlag != eAnimationFlags::IDLE_INVALID) outBitStream->Write(m_AnimationFlag);
|
||||
|
||||
LWOOBJID PossessableComponent::GetPossessor() const
|
||||
{
|
||||
return m_Possessor;
|
||||
}
|
||||
|
||||
void PossessableComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags)
|
||||
{
|
||||
outBitStream->Write(m_Possessor != LWOOBJID_EMPTY);
|
||||
if (m_Possessor != LWOOBJID_EMPTY)
|
||||
{
|
||||
outBitStream->Write1();
|
||||
outBitStream->Write(m_Possessor);
|
||||
outBitStream->Write0();
|
||||
outBitStream->Write0();
|
||||
}
|
||||
}
|
||||
|
||||
void PossessableComponent::Update(float deltaTime)
|
||||
{
|
||||
|
||||
outBitStream->Write(m_ImmediatelyDepossess);
|
||||
}
|
||||
}
|
||||
|
||||
void PossessableComponent::OnUse(Entity* originator) {
|
||||
PossessorComponent* possessorComponent;
|
||||
if (originator->TryGetComponent(COMPONENT_TYPE_POSSESSOR, possessorComponent)) {
|
||||
SetPossessor(originator->GetObjectID());
|
||||
possessorComponent->SetPossessable(m_Parent->GetObjectID());
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
EntityManager::Instance()->SerializeEntity(originator);
|
||||
}
|
||||
}
|
||||
// TODO: Implement this
|
||||
}
|
Reference in New Issue
Block a user