DarkflameServer/dGame/dBehaviors/ChangeOrientationBehavior.cpp

45 lines
1.4 KiB
C++
Raw Permalink Normal View History

#include "ChangeOrientationBehavior.h"
#include "BehaviorBranchContext.h"
#include "BehaviorContext.h"
#include "EntityManager.h"
#include "BaseCombatAIComponent.h"
2022-07-28 13:39:57 +00:00
void ChangeOrientationBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
}
2022-07-28 13:39:57 +00:00
void ChangeOrientationBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
if (!m_ToTarget) return; // TODO: Add the other arguments to this behavior
2022-07-28 13:39:57 +00:00
auto* self = EntityManager::Instance()->GetEntity(context->originator);
auto* other = EntityManager::Instance()->GetEntity(branch.target);
2022-07-28 13:39:57 +00:00
if (self == nullptr || other == nullptr) return;
2022-07-28 13:39:57 +00:00
const auto source = self->GetPosition();
const auto destination = self->GetPosition();
2022-07-28 13:39:57 +00:00
if (m_OrientCaster) {
auto* baseCombatAIComponent = self->GetComponent<BaseCombatAIComponent>();
2022-07-28 13:39:57 +00:00
/*if (baseCombatAIComponent != nullptr)
{
baseCombatAIComponent->LookAt(destination);
}
else*/
{
self->SetRotation(NiQuaternion::LookAt(source, destination));
}
2022-07-28 13:39:57 +00:00
EntityManager::Instance()->SerializeEntity(self);
} else {
other->SetRotation(NiQuaternion::LookAt(destination, source));
2022-07-28 13:39:57 +00:00
EntityManager::Instance()->SerializeEntity(other);
}
}
2022-07-28 13:39:57 +00:00
void ChangeOrientationBehavior::Load() {
m_OrientCaster = GetBoolean("orient_caster");
m_ToTarget = GetBoolean("to_target");
}