mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-11-09 17:58:20 +00:00
Make it more robust like speedboost
add check for default Fix error in GetActiveSpeedboosts
This commit is contained in:
parent
7d3f538456
commit
37f60d9177
@ -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);
|
||||
}
|
||||
|
||||
|
@ -388,3 +388,29 @@ 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);
|
||||
}
|
||||
|
@ -276,7 +276,7 @@ public:
|
||||
* The speed boosts of 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
|
||||
@ -317,6 +317,24 @@ 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
|
||||
@ -473,6 +491,16 @@ 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
|
||||
|
Loading…
Reference in New Issue
Block a user