2021-12-05 17:54:36 +00:00
|
|
|
#include "SpeedBehavior.h"
|
|
|
|
|
|
|
|
#include "ControllablePhysicsComponent.h"
|
|
|
|
#include "BehaviorContext.h"
|
|
|
|
#include "BehaviorBranchContext.h"
|
2023-10-21 23:31:55 +00:00
|
|
|
#include "Logger.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
void SpeedBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
2022-12-19 19:45:50 +00:00
|
|
|
if (m_AffectsCaster) branch.target = context->caster;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-07-15 20:56:33 +00:00
|
|
|
auto* target = Game::entityManager->GetEntity(branch.target);
|
2022-12-19 19:45:50 +00:00
|
|
|
if (!target) return;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
auto* controllablePhysicsComponent = target->GetComponent<ControllablePhysicsComponent>();
|
2022-12-19 19:45:50 +00:00
|
|
|
if (!controllablePhysicsComponent) return;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-12-19 19:45:50 +00:00
|
|
|
controllablePhysicsComponent->AddSpeedboost(m_RunSpeed);
|
2023-07-15 20:56:33 +00:00
|
|
|
Game::entityManager->SerializeEntity(target);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
if (branch.duration > 0.0f) {
|
|
|
|
context->RegisterTimerBehavior(this, branch);
|
|
|
|
} else if (branch.start > 0) {
|
|
|
|
context->RegisterEndBehavior(this, branch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-19 19:45:50 +00:00
|
|
|
void SpeedBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
|
|
|
Handle(context, bitStream, branch);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2022-12-31 08:46:25 +00:00
|
|
|
void SpeedBehavior::UnCast(BehaviorContext* context, BehaviorBranchContext branch) {
|
|
|
|
End(context, branch, LWOOBJID_EMPTY);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpeedBehavior::Timer(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second) {
|
|
|
|
End(context, branch, second);
|
|
|
|
}
|
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
void SpeedBehavior::End(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second) {
|
2023-07-15 20:56:33 +00:00
|
|
|
auto* target = Game::entityManager->GetEntity(branch.target);
|
2022-12-19 19:45:50 +00:00
|
|
|
if (!target) return;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
auto* controllablePhysicsComponent = target->GetComponent<ControllablePhysicsComponent>();
|
2022-12-19 19:45:50 +00:00
|
|
|
if (!controllablePhysicsComponent) return;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-12-19 19:45:50 +00:00
|
|
|
controllablePhysicsComponent->RemoveSpeedboost(m_RunSpeed);
|
2023-07-15 20:56:33 +00:00
|
|
|
Game::entityManager->SerializeEntity(target);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SpeedBehavior::Load() {
|
|
|
|
m_RunSpeed = GetFloat("run_speed");
|
|
|
|
m_AffectsCaster = GetBoolean("affects_caster");
|
|
|
|
}
|