2022-07-09 00:04:57 +00:00
|
|
|
#include "FallSpeedBehavior.h"
|
|
|
|
|
|
|
|
#include "ControllablePhysicsComponent.h"
|
|
|
|
#include "BehaviorContext.h"
|
|
|
|
#include "BehaviorBranchContext.h"
|
|
|
|
|
|
|
|
|
|
|
|
void FallSpeedBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
2023-05-11 01:03:02 +00:00
|
|
|
// make sure required parameter has non-default value
|
|
|
|
if (m_PercentSlowed == 0.0f) return;
|
2022-07-09 00:04:57 +00:00
|
|
|
auto* target = EntityManager::Instance()->GetEntity(branch.target);
|
|
|
|
if (!target) return;
|
|
|
|
|
|
|
|
auto* controllablePhysicsComponent = target->GetComponent<ControllablePhysicsComponent>();
|
|
|
|
if (!controllablePhysicsComponent) return;
|
2023-05-11 15:04:05 +00:00
|
|
|
controllablePhysicsComponent->SetGravityScale(m_PercentSlowed);
|
2022-07-09 00:04:57 +00:00
|
|
|
EntityManager::Instance()->SerializeEntity(target);
|
|
|
|
|
|
|
|
if (branch.duration > 0.0f) {
|
|
|
|
context->RegisterTimerBehavior(this, branch);
|
|
|
|
} else if (branch.start > 0) {
|
|
|
|
context->RegisterEndBehavior(this, branch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-11 00:41:29 +00:00
|
|
|
void FallSpeedBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
|
|
|
Handle(context, bitStream, branch);
|
|
|
|
}
|
2022-07-09 00:04:57 +00:00
|
|
|
|
2023-05-11 00:41:29 +00:00
|
|
|
void FallSpeedBehavior::Timer(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second) {
|
|
|
|
End(context, branch, second);
|
2022-07-09 00:04:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FallSpeedBehavior::UnCast(BehaviorContext* context, BehaviorBranchContext branch) {
|
2023-05-11 00:41:29 +00:00
|
|
|
End(context, branch, LWOOBJID_EMPTY);
|
2022-07-09 00:04:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FallSpeedBehavior::End(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second) {
|
|
|
|
auto* target = EntityManager::Instance()->GetEntity(branch.target);
|
|
|
|
if (!target) return;
|
|
|
|
|
|
|
|
auto* controllablePhysicsComponent = target->GetComponent<ControllablePhysicsComponent>();
|
|
|
|
if (!controllablePhysicsComponent) return;
|
2023-05-11 15:04:05 +00:00
|
|
|
controllablePhysicsComponent->SetGravityScale(1);
|
2022-07-09 00:04:57 +00:00
|
|
|
EntityManager::Instance()->SerializeEntity(target);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FallSpeedBehavior::Load(){
|
|
|
|
m_PercentSlowed = GetFloat("percent_slowed");
|
|
|
|
}
|