diff --git a/dGame/dBehaviors/Behavior.cpp b/dGame/dBehaviors/Behavior.cpp index 7305ed2d..6188f536 100644 --- a/dGame/dBehaviors/Behavior.cpp +++ b/dGame/dBehaviors/Behavior.cpp @@ -58,6 +58,7 @@ #include "SpeedBehavior.h" #include "DamageReductionBehavior.h" #include "JetPackBehavior.h" +#include "FallSpeedBehavior.h" //CDClient includes #include "CDBehaviorParameterTable.h" @@ -165,7 +166,9 @@ Behavior* Behavior::CreateBehavior(const uint32_t behaviorId) case BehaviorTemplates::BEHAVIOR_CAR_BOOST: behavior = new CarBoostBehavior(behaviorId); break; - case BehaviorTemplates::BEHAVIOR_FALL_SPEED: break; + case BehaviorTemplates::BEHAVIOR_FALL_SPEED: + behavior = new FallSpeedBehavior(behaviorId); + break; case BehaviorTemplates::BEHAVIOR_SHIELD: break; case BehaviorTemplates::BEHAVIOR_REPAIR_ARMOR: behavior = new RepairBehavior(behaviorId); @@ -174,7 +177,7 @@ Behavior* Behavior::CreateBehavior(const uint32_t behaviorId) behavior = new SpeedBehavior(behaviorId); break; case BehaviorTemplates::BEHAVIOR_DARK_INSPIRATION: break; - case BehaviorTemplates::BEHAVIOR_LOOT_BUFF: + case BehaviorTemplates::BEHAVIOR_LOOT_BUFF: behavior = new LootBuffBehavior(behaviorId); break; case BehaviorTemplates::BEHAVIOR_VENTURE_VISION: diff --git a/dGame/dBehaviors/FallSpeedBehavior.cpp b/dGame/dBehaviors/FallSpeedBehavior.cpp new file mode 100644 index 00000000..1f2c7480 --- /dev/null +++ b/dGame/dBehaviors/FallSpeedBehavior.cpp @@ -0,0 +1,88 @@ +#include "FallSpeedBehavior.h" + +#include "ControllablePhysicsComponent.h" +#include "BehaviorContext.h" +#include "BehaviorBranchContext.h" + + +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) { + context->RegisterTimerBehavior(this, branch); + } else if (branch.start > 0) { + controllablePhysicsComponent->SetIgnoreMultipliers(true); + + context->RegisterEndBehavior(this, 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); +} + +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); +} + +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); +} + +void FallSpeedBehavior::Load(){ + m_PercentSlowed = GetFloat("percent_slowed"); +} diff --git a/dGame/dBehaviors/FallSpeedBehavior.h b/dGame/dBehaviors/FallSpeedBehavior.h new file mode 100644 index 00000000..3e1a1887 --- /dev/null +++ b/dGame/dBehaviors/FallSpeedBehavior.h @@ -0,0 +1,25 @@ +#pragma once +#include "Behavior.h" + +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 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: + float m_PercentSlowed; +};