Make it more robust like speedboost

add check for default
Fix error in GetActiveSpeedboosts
This commit is contained in:
Aaron Kimbre
2023-05-10 20:03:02 -05:00
parent 7d3f538456
commit 37f60d9177
3 changed files with 60 additions and 7 deletions

View File

@@ -6,21 +6,21 @@
void FallSpeedBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
// make sure required parameter has non-default value
if (m_PercentSlowed == 0.0f) return;
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);
controllablePhysicsComponent->AddFallSpeed(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);
}
}
@@ -43,8 +43,7 @@ void FallSpeedBehavior::End(BehaviorContext* context, BehaviorBranchContext bran
auto* controllablePhysicsComponent = target->GetComponent<ControllablePhysicsComponent>();
if (!controllablePhysicsComponent) return;
controllablePhysicsComponent->SetIgnoreMultipliers(false);
controllablePhysicsComponent->SetGravityScale(1);
controllablePhysicsComponent->RemoveFallSpeed(m_PercentSlowed);
EntityManager::Instance()->SerializeEntity(target);
}