2021-12-05 17:54:36 +00:00
|
|
|
#include "SpeedBehavior.h"
|
|
|
|
|
|
|
|
#include "ControllablePhysicsComponent.h"
|
|
|
|
#include "BehaviorContext.h"
|
|
|
|
#include "BehaviorBranchContext.h"
|
|
|
|
#include "dLogger.h"
|
|
|
|
|
|
|
|
|
2022-07-28 13:39:57 +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
|
|
|
|
|
|
|
auto* target = EntityManager::Instance()->GetEntity(branch.target);
|
2022-12-19 19:45:50 +00:00
|
|
|
if (!target) return;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-06-07 07:23:50 +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);
|
2022-07-28 13:39:57 +00:00
|
|
|
EntityManager::Instance()->SerializeEntity(target);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
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);
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void SpeedBehavior::End(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second) {
|
|
|
|
auto* target = EntityManager::Instance()->GetEntity(branch.target);
|
2022-12-19 19:45:50 +00:00
|
|
|
if (!target) return;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-06-07 07:23:50 +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);
|
2022-07-28 13:39:57 +00:00
|
|
|
EntityManager::Instance()->SerializeEntity(target);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void SpeedBehavior::Load() {
|
|
|
|
m_RunSpeed = GetFloat("run_speed");
|
|
|
|
m_AffectsCaster = GetBoolean("affects_caster");
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|