Hacky FallSpeedBehavior

This commit is contained in:
Aaron Kimbre 2022-07-08 19:04:57 -05:00
parent 22b2516107
commit 4e5b38d602
3 changed files with 118 additions and 2 deletions

View File

@ -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:

View File

@ -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<ControllablePhysicsComponent>();
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<ControllablePhysicsComponent>();
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<ControllablePhysicsComponent>();
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<ControllablePhysicsComponent>();
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");
}

View File

@ -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;
};