This commit is contained in:
Aaron Kimbre 2023-05-10 19:41:29 -05:00
parent 565b23227e
commit 7d3f538456
3 changed files with 8 additions and 49 deletions

View File

@ -22,6 +22,7 @@ set(DGAME_DBEHAVIORS_SOURCES "AirMovementBehavior.cpp"
"DurationBehavior.cpp" "DurationBehavior.cpp"
"EmptyBehavior.cpp" "EmptyBehavior.cpp"
"EndBehavior.cpp" "EndBehavior.cpp"
"FallSpeedBehavior.cpp"
"ForceMovementBehavior.cpp" "ForceMovementBehavior.cpp"
"HealBehavior.cpp" "HealBehavior.cpp"
"ImaginationBehavior.cpp" "ImaginationBehavior.cpp"

View File

@ -7,19 +7,13 @@
void FallSpeedBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) { void FallSpeedBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
branch.target = context->caster; branch.target = context->caster;
auto* target = EntityManager::Instance()->GetEntity(branch.target); auto* target = EntityManager::Instance()->GetEntity(branch.target);
if (!target) return; if (!target) return;
auto* controllablePhysicsComponent = target->GetComponent<ControllablePhysicsComponent>(); auto* controllablePhysicsComponent = target->GetComponent<ControllablePhysicsComponent>();
if (!controllablePhysicsComponent) return; if (!controllablePhysicsComponent) return;
const auto current = controllablePhysicsComponent->GetGravityScale(); const auto current = controllablePhysicsComponent->GetGravityScale();
controllablePhysicsComponent->SetGravityScale(m_PercentSlowed); controllablePhysicsComponent->SetGravityScale(m_PercentSlowed);
EntityManager::Instance()->SerializeEntity(target); EntityManager::Instance()->SerializeEntity(target);
if (branch.duration > 0.0f) { 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) { void FallSpeedBehavior::Timer(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second) {
auto* target = EntityManager::Instance()->GetEntity(branch.target); End(context, branch, second);
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) { void FallSpeedBehavior::UnCast(BehaviorContext* context, BehaviorBranchContext branch) {
auto* target = EntityManager::Instance()->GetEntity(branch.target); End(context, branch, LWOOBJID_EMPTY);
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) { void FallSpeedBehavior::End(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second) {
auto* target = EntityManager::Instance()->GetEntity(branch.target); auto* target = EntityManager::Instance()->GetEntity(branch.target);
if (!target) return; if (!target) return;
auto* controllablePhysicsComponent = target->GetComponent<ControllablePhysicsComponent>(); auto* controllablePhysicsComponent = target->GetComponent<ControllablePhysicsComponent>();
if (!controllablePhysicsComponent) return; if (!controllablePhysicsComponent) return;
// const auto current = controllablePhysicsComponent->GetGravityScale();
controllablePhysicsComponent->SetIgnoreMultipliers(false); controllablePhysicsComponent->SetIgnoreMultipliers(false);
controllablePhysicsComponent->SetGravityScale(1); controllablePhysicsComponent->SetGravityScale(1);
EntityManager::Instance()->SerializeEntity(target); EntityManager::Instance()->SerializeEntity(target);
} }

View File

@ -4,20 +4,13 @@
class FallSpeedBehavior final : public Behavior class FallSpeedBehavior final : public Behavior
{ {
public: public:
/*
* Inherited
*/
explicit FallSpeedBehavior(const uint32_t behaviorId) : Behavior(behaviorId) {} explicit FallSpeedBehavior(const uint32_t behaviorId) : Behavior(behaviorId) {}
void Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override; 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 Timer(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second) override;
void End(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second) override; void End(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second) override;
void UnCast(BehaviorContext* context, BehaviorBranchContext branch) override; void UnCast(BehaviorContext* context, BehaviorBranchContext branch) override;
void Load() override; void Load() override;
private: private: