simplify and address feedback

This commit is contained in:
Aaron Kimbre 2023-05-11 10:04:05 -05:00
parent 37f60d9177
commit 0e7be44ab6
3 changed files with 3 additions and 59 deletions

View File

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

View File

@ -320,7 +320,7 @@ void ControllablePhysicsComponent::RemoveSpeedboost(float value) {
// Recalculate speedboost since we removed one
m_SpeedBoost = 0.0f;
if (m_ActiveSpeedBoosts.size() == 0) { // no active speed boosts left, so return to base speed
if (m_ActiveSpeedBoosts.empty()) { // no active speed boosts left, so return to base speed
auto* levelProgressionComponent = m_Parent->GetComponent<LevelProgressionComponent>();
if (levelProgressionComponent) m_SpeedBoost = levelProgressionComponent->GetSpeedBase();
} else { // Used the last applied speedboost
@ -388,29 +388,3 @@ void ControllablePhysicsComponent::SetStunImmunity(
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

@ -317,24 +317,6 @@ public:
const bool GetImmuneToStunTurn() { return m_ImmuneToStunTurnCount > 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:
/**
* The entity that owns this component
@ -491,16 +473,6 @@ private:
int32_t m_ImmuneToStunMoveCount;
int32_t m_ImmuneToStunTurnCount;
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