From 7d3f538456cf0f10216f386fb7648859ae15914b Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Wed, 10 May 2023 19:41:29 -0500 Subject: [PATCH] Fixup --- dGame/dBehaviors/CMakeLists.txt | 1 + dGame/dBehaviors/FallSpeedBehavior.cpp | 47 ++++---------------------- dGame/dBehaviors/FallSpeedBehavior.h | 9 +---- 3 files changed, 8 insertions(+), 49 deletions(-) diff --git a/dGame/dBehaviors/CMakeLists.txt b/dGame/dBehaviors/CMakeLists.txt index 7b331fe0..8a9368b9 100644 --- a/dGame/dBehaviors/CMakeLists.txt +++ b/dGame/dBehaviors/CMakeLists.txt @@ -22,6 +22,7 @@ set(DGAME_DBEHAVIORS_SOURCES "AirMovementBehavior.cpp" "DurationBehavior.cpp" "EmptyBehavior.cpp" "EndBehavior.cpp" + "FallSpeedBehavior.cpp" "ForceMovementBehavior.cpp" "HealBehavior.cpp" "ImaginationBehavior.cpp" diff --git a/dGame/dBehaviors/FallSpeedBehavior.cpp b/dGame/dBehaviors/FallSpeedBehavior.cpp index 1f2c7480..c485f5c2 100644 --- a/dGame/dBehaviors/FallSpeedBehavior.cpp +++ b/dGame/dBehaviors/FallSpeedBehavior.cpp @@ -7,19 +7,13 @@ void FallSpeedBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) { branch.target = context->caster; - auto* target = EntityManager::Instance()->GetEntity(branch.target); - if (!target) return; auto* controllablePhysicsComponent = target->GetComponent(); - if (!controllablePhysicsComponent) return; - const auto current = controllablePhysicsComponent->GetGravityScale(); - controllablePhysicsComponent->SetGravityScale(m_PercentSlowed); - EntityManager::Instance()->SerializeEntity(target); if (branch.duration > 0.0f) { @@ -31,55 +25,26 @@ void FallSpeedBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitS } } +void FallSpeedBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) { + Handle(context, bitStream, branch); +} + void FallSpeedBehavior::Timer(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second) { - auto* target = EntityManager::Instance()->GetEntity(branch.target); - - if (!target) return; - - auto* controllablePhysicsComponent = target->GetComponent(); - - if (!controllablePhysicsComponent) return; - - const auto current = controllablePhysicsComponent->GetGravityScale(); - - controllablePhysicsComponent->SetGravityScale(m_PercentSlowed); - - EntityManager::Instance()->SerializeEntity(target); + End(context, branch, second); } void FallSpeedBehavior::UnCast(BehaviorContext* context, BehaviorBranchContext branch) { - auto* target = EntityManager::Instance()->GetEntity(branch.target); - - if (!target) return; - - auto* controllablePhysicsComponent = target->GetComponent(); - - if (!controllablePhysicsComponent) return; - - // const auto current = controllablePhysicsComponent->GetGravityScale(); - - controllablePhysicsComponent->SetIgnoreMultipliers(false); - - controllablePhysicsComponent->SetGravityScale(1); - - EntityManager::Instance()->SerializeEntity(target); + End(context, branch, LWOOBJID_EMPTY); } void FallSpeedBehavior::End(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second) { auto* target = EntityManager::Instance()->GetEntity(branch.target); - if (!target) return; auto* controllablePhysicsComponent = target->GetComponent(); - if (!controllablePhysicsComponent) return; - - // const auto current = controllablePhysicsComponent->GetGravityScale(); - controllablePhysicsComponent->SetIgnoreMultipliers(false); - controllablePhysicsComponent->SetGravityScale(1); - EntityManager::Instance()->SerializeEntity(target); } diff --git a/dGame/dBehaviors/FallSpeedBehavior.h b/dGame/dBehaviors/FallSpeedBehavior.h index 3e1a1887..01f0143f 100644 --- a/dGame/dBehaviors/FallSpeedBehavior.h +++ b/dGame/dBehaviors/FallSpeedBehavior.h @@ -4,20 +4,13 @@ class FallSpeedBehavior final : public Behavior { public: - - /* - * Inherited - */ explicit FallSpeedBehavior(const uint32_t behaviorId) : Behavior(behaviorId) {} void Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override; - + void Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override; void Timer(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second) override; - void End(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second) override; - void UnCast(BehaviorContext* context, BehaviorBranchContext branch) override; - void Load() override; private: