DarkflameServer/dGame/dBehaviors/VerifyBehavior.cpp

61 lines
1.4 KiB
C++
Raw Normal View History

#include "VerifyBehavior.h"
#include "BehaviorBranchContext.h"
#include "EntityManager.h"
#include "NiPoint3.h"
#include "BehaviorContext.h"
#include "Game.h"
#include "dLogger.h"
2022-07-28 13:39:57 +00:00
void VerifyBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
auto* entity = EntityManager::Instance()->GetEntity(branch.target);
auto success = true;
2022-07-28 13:39:57 +00:00
if (entity == nullptr) {
success = false;
2022-07-28 13:39:57 +00:00
} else if (this->m_rangeCheck) {
auto* self = EntityManager::Instance()->GetEntity(context->originator);
2022-07-28 13:39:57 +00:00
if (self == nullptr) {
Game::logger->Log("VerifyBehavior", "Invalid self for (%llu)", context->originator);
return;
}
const auto distance = Vector3::DistanceSquared(self->GetPosition(), entity->GetPosition());
2022-07-28 13:39:57 +00:00
if (distance > this->m_range * this->m_range) {
success = false;
}
2022-07-28 13:39:57 +00:00
} else if (this->m_blockCheck) {
// TODO
}
2022-07-28 13:39:57 +00:00
if (branch.target != LWOOBJID_EMPTY && branch.target != context->originator) {
bitStream->Write(success);
2022-07-28 13:39:57 +00:00
if (success) {
bitStream->Write<uint32_t>(1);
bitStream->Write0();
bitStream->Write0();
}
}
2022-07-28 13:39:57 +00:00
if (!success) {
branch.target = LWOOBJID_EMPTY;
}
m_action->Calculate(context, bitStream, branch);
}
2022-07-28 13:39:57 +00:00
void VerifyBehavior::Load() {
this->m_rangeCheck = GetBoolean("check_range");
this->m_blockCheck = GetBoolean("check blocking");
this->m_action = GetAction("action");
this->m_range = GetFloat("range");
}