2021-12-05 17:54:36 +00:00
|
|
|
#include "ChangeOrientationBehavior.h"
|
|
|
|
#include "BehaviorBranchContext.h"
|
|
|
|
#include "BehaviorContext.h"
|
|
|
|
#include "EntityManager.h"
|
|
|
|
|
|
|
|
void ChangeOrientationBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
2023-04-03 13:21:23 +00:00
|
|
|
Entity* sourceEntity;
|
2023-07-15 20:56:33 +00:00
|
|
|
if (this->m_orientCaster) sourceEntity = Game::entityManager->GetEntity(context->originator);
|
|
|
|
else sourceEntity = Game::entityManager->GetEntity(branch.target);
|
2023-04-03 13:21:23 +00:00
|
|
|
if (!sourceEntity) return;
|
|
|
|
|
|
|
|
if (this->m_toTarget) {
|
|
|
|
Entity* destinationEntity;
|
2023-07-15 20:56:33 +00:00
|
|
|
if (this->m_orientCaster) destinationEntity = Game::entityManager->GetEntity(branch.target);
|
|
|
|
else destinationEntity = Game::entityManager->GetEntity(context->originator);
|
2023-04-03 13:21:23 +00:00
|
|
|
if (!destinationEntity) return;
|
|
|
|
|
2023-04-03 13:29:39 +00:00
|
|
|
sourceEntity->SetRotation(
|
|
|
|
NiQuaternion::LookAt(sourceEntity->GetPosition(), destinationEntity->GetPosition())
|
|
|
|
);
|
2023-04-03 13:21:23 +00:00
|
|
|
} else if (this->m_toAngle){
|
2023-04-03 18:10:51 +00:00
|
|
|
auto baseAngle = NiPoint3(0, 0, this->m_angle);
|
|
|
|
if (this->m_relative) baseAngle += sourceEntity->GetRotation().GetForwardVector();
|
2023-04-03 13:29:39 +00:00
|
|
|
sourceEntity->SetRotation(NiQuaternion::FromEulerAngles(baseAngle));
|
2023-04-03 13:21:23 +00:00
|
|
|
} else return;
|
2023-07-15 20:56:33 +00:00
|
|
|
Game::entityManager->SerializeEntity(sourceEntity);
|
2023-04-03 13:21:23 +00:00
|
|
|
return;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ChangeOrientationBehavior::Load() {
|
2023-04-03 13:21:23 +00:00
|
|
|
this->m_orientCaster = GetBoolean("orient_caster", true);
|
|
|
|
this->m_toTarget = GetBoolean("to_target", false);
|
|
|
|
this->m_toAngle = GetBoolean("to_angle", false);
|
|
|
|
this->m_angle = GetFloat("angle", 0.0f);
|
|
|
|
this->m_relative = GetBoolean("relative", false);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|