2022-08-06 03:01:59 +00:00
|
|
|
#include "VerifyBehavior.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
#include "BehaviorBranchContext.h"
|
|
|
|
#include "EntityManager.h"
|
|
|
|
#include "NiPoint3.h"
|
|
|
|
#include "BehaviorContext.h"
|
|
|
|
#include "Game.h"
|
2023-10-21 23:31:55 +00:00
|
|
|
#include "Logger.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
|
2024-02-27 07:25:44 +00:00
|
|
|
void VerifyBehavior::Calculate(BehaviorContext* context, RakNet::BitStream& bitStream, BehaviorBranchContext branch) {
|
2023-07-15 20:56:33 +00:00
|
|
|
auto* entity = Game::entityManager->GetEntity(branch.target);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
auto success = true;
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (entity == nullptr) {
|
2021-12-05 17:54:36 +00:00
|
|
|
success = false;
|
2022-07-28 13:39:57 +00:00
|
|
|
} else if (this->m_rangeCheck) {
|
2023-07-15 20:56:33 +00:00
|
|
|
auto* self = Game::entityManager->GetEntity(context->originator);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (self == nullptr) {
|
2024-03-13 02:10:01 +00:00
|
|
|
Log::Warn("Invalid self for ({})", context->originator);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
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) {
|
2021-12-05 17:54:36 +00:00
|
|
|
success = false;
|
|
|
|
}
|
2022-07-28 13:39:57 +00:00
|
|
|
} else if (this->m_blockCheck) {
|
2021-12-05 17:54:36 +00:00
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (branch.target != LWOOBJID_EMPTY && branch.target != context->originator) {
|
2024-02-27 07:25:44 +00:00
|
|
|
bitStream.Write(success);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (success) {
|
2024-02-27 07:25:44 +00:00
|
|
|
bitStream.Write<uint32_t>(1);
|
|
|
|
bitStream.Write0();
|
|
|
|
bitStream.Write0();
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (!success) {
|
2021-12-05 17:54:36 +00:00
|
|
|
branch.target = LWOOBJID_EMPTY;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_action->Calculate(context, bitStream, branch);
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void VerifyBehavior::Load() {
|
2021-12-05 17:54:36 +00:00
|
|
|
this->m_rangeCheck = GetBoolean("check_range");
|
|
|
|
|
|
|
|
this->m_blockCheck = GetBoolean("check blocking");
|
|
|
|
|
|
|
|
this->m_action = GetAction("action");
|
|
|
|
|
|
|
|
this->m_range = GetFloat("range");
|
|
|
|
}
|