DarkflameServer/dGame/dBehaviors/SpeedBehavior.cpp

55 lines
1.7 KiB
C++
Raw Permalink Normal View History

#include "SpeedBehavior.h"
#include "ControllablePhysicsComponent.h"
#include "BehaviorContext.h"
#include "BehaviorBranchContext.h"
#include "Logger.h"
2022-07-28 13:39:57 +00:00
void SpeedBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
if (m_AffectsCaster) branch.target = context->caster;
auto* target = Game::entityManager->GetEntity(branch.target);
if (!target) return;
2022-07-28 13:39:57 +00:00
auto* controllablePhysicsComponent = target->GetComponent<ControllablePhysicsComponent>();
if (!controllablePhysicsComponent) return;
controllablePhysicsComponent->AddSpeedboost(m_RunSpeed);
Game::entityManager->SerializeEntity(target);
2022-07-28 13:39:57 +00:00
if (branch.duration > 0.0f) {
context->RegisterTimerBehavior(this, branch);
} else if (branch.start > 0) {
context->RegisterEndBehavior(this, branch);
}
}
void SpeedBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
Handle(context, bitStream, branch);
}
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);
}
2022-07-28 13:39:57 +00:00
void SpeedBehavior::End(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second) {
auto* target = Game::entityManager->GetEntity(branch.target);
if (!target) return;
2022-07-28 13:39:57 +00:00
auto* controllablePhysicsComponent = target->GetComponent<ControllablePhysicsComponent>();
if (!controllablePhysicsComponent) return;
controllablePhysicsComponent->RemoveSpeedboost(m_RunSpeed);
Game::entityManager->SerializeEntity(target);
}
2022-07-28 13:39:57 +00:00
void SpeedBehavior::Load() {
m_RunSpeed = GetFloat("run_speed");
m_AffectsCaster = GetBoolean("affects_caster");
}