2021-12-05 17:54:36 +00:00
|
|
|
#include "ForceMovementBehavior.h"
|
|
|
|
#include "BehaviorBranchContext.h"
|
|
|
|
#include "BehaviorContext.h"
|
2021-12-11 10:59:29 +00:00
|
|
|
#include "ControllablePhysicsComponent.h"
|
|
|
|
#include "EntityManager.h"
|
2022-12-16 21:23:02 +00:00
|
|
|
#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 ForceMovementBehavior::Handle(BehaviorContext* context, RakNet::BitStream& bitStream, const BehaviorBranchContext branch) {
|
2021-12-11 10:59:29 +00:00
|
|
|
if (this->m_hitAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY && this->m_hitEnemyAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY && this->m_hitFactionAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY) {
|
|
|
|
return;
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-12-16 21:23:02 +00:00
|
|
|
uint32_t handle{};
|
2024-02-27 07:25:44 +00:00
|
|
|
if (!bitStream.Read(handle)) {
|
2024-03-08 21:44:02 +00:00
|
|
|
Log::Warn("Unable to read handle from bitStream, aborting Handle! {:d}", bitStream.GetNumberOfUnreadBits());
|
2022-12-16 21:23:02 +00:00
|
|
|
return;
|
|
|
|
}
|
2023-04-05 13:57:47 +00:00
|
|
|
context->RegisterSyncBehavior(handle, this, branch, this->m_Duration);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2024-02-27 07:25:44 +00:00
|
|
|
void ForceMovementBehavior::Sync(BehaviorContext* context, RakNet::BitStream& bitStream, BehaviorBranchContext branch) {
|
2022-12-16 21:23:02 +00:00
|
|
|
uint32_t next{};
|
2024-02-27 07:25:44 +00:00
|
|
|
if (!bitStream.Read(next)) {
|
2024-03-08 21:44:02 +00:00
|
|
|
Log::Warn("Unable to read target from bitStream, aborting Sync! {:d}", bitStream.GetNumberOfUnreadBits());
|
2022-12-16 21:23:02 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-12-11 10:59:29 +00:00
|
|
|
|
2022-12-16 21:23:02 +00:00
|
|
|
LWOOBJID target{};
|
2024-02-27 07:25:44 +00:00
|
|
|
if (!bitStream.Read(target)) {
|
2024-03-08 21:44:02 +00:00
|
|
|
Log::Warn("Unable to read target from bitStream, aborting Sync! {:d}", bitStream.GetNumberOfUnreadBits());
|
2022-12-16 21:23:02 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2021-12-11 10:59:29 +00:00
|
|
|
branch.target = target;
|
|
|
|
auto* behavior = CreateBehavior(next);
|
|
|
|
behavior->Handle(context, bitStream, branch);
|
|
|
|
}
|
|
|
|
|
2024-02-27 07:25:44 +00:00
|
|
|
void ForceMovementBehavior::Calculate(BehaviorContext* context, RakNet::BitStream& bitStream, BehaviorBranchContext branch) {
|
2021-12-11 10:59:29 +00:00
|
|
|
if (this->m_hitAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY && this->m_hitEnemyAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY && this->m_hitFactionAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY) {
|
|
|
|
return;
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-07-15 20:56:33 +00:00
|
|
|
auto* casterEntity = Game::entityManager->GetEntity(context->caster);
|
2021-12-11 10:59:29 +00:00
|
|
|
if (casterEntity != nullptr) {
|
|
|
|
auto* controllablePhysicsComponent = casterEntity->GetComponent<ControllablePhysicsComponent>();
|
|
|
|
if (controllablePhysicsComponent != nullptr) {
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2021-12-11 10:59:29 +00:00
|
|
|
if (m_Forward == 1) {
|
|
|
|
controllablePhysicsComponent->SetVelocity(controllablePhysicsComponent->GetRotation().GetForwardVector() * 25);
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-07-15 20:56:33 +00:00
|
|
|
Game::entityManager->SerializeEntity(casterEntity);
|
2021-12-11 10:59:29 +00:00
|
|
|
}
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2021-12-11 10:59:29 +00:00
|
|
|
const auto skillHandle = context->GetUniqueSkillId();
|
2024-02-27 07:25:44 +00:00
|
|
|
bitStream.Write(skillHandle);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2021-12-11 10:59:29 +00:00
|
|
|
context->SyncCalculation(skillHandle, this->m_Duration, this, branch);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ForceMovementBehavior::Load() {
|
2021-12-11 10:59:29 +00:00
|
|
|
this->m_hitAction = GetAction("hit_action");
|
|
|
|
this->m_hitEnemyAction = GetAction("hit_action_enemy");
|
|
|
|
this->m_hitFactionAction = GetAction("hit_action_faction");
|
|
|
|
this->m_Duration = GetFloat("duration");
|
|
|
|
this->m_Forward = GetFloat("forward");
|
|
|
|
this->m_Left = GetFloat("left");
|
|
|
|
this->m_Yaw = GetFloat("yaw");
|
|
|
|
}
|
|
|
|
|
2024-02-27 07:25:44 +00:00
|
|
|
void ForceMovementBehavior::SyncCalculation(BehaviorContext* context, RakNet::BitStream& bitStream, BehaviorBranchContext branch) {
|
2023-07-15 20:56:33 +00:00
|
|
|
auto* casterEntity = Game::entityManager->GetEntity(context->caster);
|
2021-12-11 10:59:29 +00:00
|
|
|
if (casterEntity != nullptr) {
|
|
|
|
auto* controllablePhysicsComponent = casterEntity->GetComponent<ControllablePhysicsComponent>();
|
|
|
|
if (controllablePhysicsComponent != nullptr) {
|
|
|
|
|
|
|
|
controllablePhysicsComponent->SetPosition(controllablePhysicsComponent->GetPosition() + controllablePhysicsComponent->GetVelocity() * m_Duration);
|
|
|
|
controllablePhysicsComponent->SetVelocity({});
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-07-15 20:56:33 +00:00
|
|
|
Game::entityManager->SerializeEntity(casterEntity);
|
2021-12-11 10:59:29 +00:00
|
|
|
}
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2021-12-11 10:59:29 +00:00
|
|
|
this->m_hitAction->Calculate(context, bitStream, branch);
|
|
|
|
this->m_hitEnemyAction->Calculate(context, bitStream, branch);
|
2022-12-08 07:13:25 +00:00
|
|
|
this->m_hitFactionAction->Calculate(context, bitStream, branch);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|