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) { 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; 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(); controllablePhysicsComponent->AddFallSpeed(m_PercentSlowed);
controllablePhysicsComponent->SetGravityScale(m_PercentSlowed);
EntityManager::Instance()->SerializeEntity(target); EntityManager::Instance()->SerializeEntity(target);
if (branch.duration > 0.0f) { if (branch.duration > 0.0f) {
context->RegisterTimerBehavior(this, branch); context->RegisterTimerBehavior(this, branch);
} else if (branch.start > 0) { } else if (branch.start > 0) {
controllablePhysicsComponent->SetIgnoreMultipliers(true);
context->RegisterEndBehavior(this, branch); context->RegisterEndBehavior(this, branch);
} }
} }
@ -43,8 +43,7 @@ void FallSpeedBehavior::End(BehaviorContext* context, BehaviorBranchContext bran
auto* controllablePhysicsComponent = target->GetComponent<ControllablePhysicsComponent>(); auto* controllablePhysicsComponent = target->GetComponent<ControllablePhysicsComponent>();
if (!controllablePhysicsComponent) return; if (!controllablePhysicsComponent) return;
controllablePhysicsComponent->SetIgnoreMultipliers(false); controllablePhysicsComponent->RemoveFallSpeed(m_PercentSlowed);
controllablePhysicsComponent->SetGravityScale(1);
EntityManager::Instance()->SerializeEntity(target); EntityManager::Instance()->SerializeEntity(target);
} }

View File

@ -388,3 +388,29 @@ void ControllablePhysicsComponent::SetStunImmunity(
bImmuneToStunUseItem bImmuneToStunUseItem
); );
} }
void ControllablePhysicsComponent::AddFallSpeed(float value) {
m_ActiveFallSpeeds.push_back(value);
m_FallSpeed = value;
SetGravityScale(value);
}
void ControllablePhysicsComponent::RemoveFallSpeed(float value) {
const auto pos = std::find(m_ActiveFallSpeeds.begin(), m_ActiveFallSpeeds.end(), value);
if (pos != m_ActiveFallSpeeds.end()) {
m_ActiveFallSpeeds.erase(pos);
} else {
Game::logger->LogDebug("ControllablePhysicsComponent", "Warning: Could not find FallSpeed %f in list of active FallSpeeds. List has %i active FallSpeeds.", value, m_ActiveFallSpeeds.size());
return;
}
// Recalculate FallSpeed since we removed one
m_FallSpeed = 0.0f;
if (m_ActiveFallSpeeds.size() == 0) { // no active fall speeds left, so return to base gravity
m_FallSpeed = 1;
} else { // Used the last applied FallSpeed
m_FallSpeed = m_ActiveFallSpeeds.back();
}
SetSpeedMultiplier(m_FallSpeed); // 500 being the base speed
EntityManager::Instance()->SerializeEntity(m_Parent);
}

View File

@ -276,7 +276,7 @@ public:
* The speed boosts of this component. * The speed boosts of this component.
* @return All active Speed boosts for this component. * @return All active Speed boosts for this component.
*/ */
std::vector<float> GetActiveSpeedboosts() { return m_ActivePickupRadiusScales; }; std::vector<float> GetActiveSpeedboosts() { return m_ActiveSpeedBoosts; };
/** /**
* Activates the Bubble Buff * Activates the Bubble Buff
@ -317,6 +317,24 @@ public:
const bool GetImmuneToStunTurn() { return m_ImmuneToStunTurnCount > 0;}; const bool GetImmuneToStunTurn() { return m_ImmuneToStunTurnCount > 0;};
const bool GetImmuneToStunUseItem() { return m_ImmuneToStunUseItemCount > 0;}; const bool GetImmuneToStunUseItem() { return m_ImmuneToStunUseItemCount > 0;};
/**
* Add a Fall Speed to the entity
* This will recalculate the Fall Speed based on what is being added
*/
void AddFallSpeed(float value);
/**
* Remove Fall Speed from entity
* This will recalculate the Fall Speed based on what is the last one in te vector
*/
void RemoveFallSpeed(float value);
/**
* The Fall Speeds of this component.
* @return All active Fall Speeds for this component.
*/
std::vector<float> GetActiveFallSpeeds() { return m_ActiveFallSpeeds; };
private: private:
/** /**
* The entity that owns this component * The entity that owns this component
@ -473,6 +491,16 @@ private:
int32_t m_ImmuneToStunMoveCount; int32_t m_ImmuneToStunMoveCount;
int32_t m_ImmuneToStunTurnCount; int32_t m_ImmuneToStunTurnCount;
int32_t m_ImmuneToStunUseItemCount; int32_t m_ImmuneToStunUseItemCount;
/**
* The list of fall speeds for this entity
*/
std::vector<float> m_ActiveFallSpeeds;
/**
* The active fall speed for this entity
*/
float m_FallSpeed;
}; };
#endif // CONTROLLABLEPHYSICSCOMPONENT_H #endif // CONTROLLABLEPHYSICSCOMPONENT_H