diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Entities/EntityEffects.cpp | 8 | ||||
-rw-r--r-- | src/Entities/EntityEffects.h | 13 | ||||
-rw-r--r-- | src/Entities/Pawn.cpp | 24 |
3 files changed, 23 insertions, 22 deletions
diff --git a/src/Entities/EntityEffects.cpp b/src/Entities/EntityEffects.cpp index c74463bfa..e8448a6f1 100644 --- a/src/Entities/EntityEffects.cpp +++ b/src/Entities/EntityEffects.cpp @@ -8,6 +8,7 @@ cEntityEffect::cEntityEffect(): m_Ticks(0), + m_Duration(0), m_Intensity(0), m_User(NULL), m_DistanceModifier(1) @@ -19,11 +20,12 @@ cEntityEffect::cEntityEffect(): -cEntityEffect::cEntityEffect(int a_Ticks, short a_Intensity, cPawn *a_User, double a_DistanceModifier): - m_Ticks(a_Ticks), +cEntityEffect::cEntityEffect(int a_Duration, short a_Intensity, cPawn *a_User, double a_DistanceModifier): + m_Ticks(0), + m_Duration(a_Duration), m_Intensity(a_Intensity), m_User(a_User), m_DistanceModifier(a_DistanceModifier) { -}
\ No newline at end of file +} diff --git a/src/Entities/EntityEffects.h b/src/Entities/EntityEffects.h index 26d2c92e5..6b2532aae 100644 --- a/src/Entities/EntityEffects.h +++ b/src/Entities/EntityEffects.h @@ -35,9 +35,12 @@ public: effSaturation = 23, } ; - /** The duration of the effect */ + /** How many ticks this effect has been active for */ int m_Ticks; + /** Returns the duration of the effect */ + int GetDuration() { return m_Duration; } + /** Returns how strong the effect will be applied */ short GetIntensity() { return m_Intensity; } @@ -47,6 +50,7 @@ public: /** Returns the distance modifier for affecting potency */ double GetDistanceModifier() { return m_DistanceModifier; } + void SetDuration(int a_Duration) { m_Duration = a_Duration; } void SetIntensity(short a_Intensity) { m_Intensity = a_Intensity; } void SetUser(cPawn *a_User) { m_User = a_User; } void SetDistanceModifier(double a_DistanceModifier) { m_DistanceModifier = a_DistanceModifier; } @@ -58,14 +62,17 @@ public: /** * An entity effect - * @param a_Ticks The duration of the effect + * @param a_Duration How long this effect will last * @param a_Intensity How strong the effect will be applied * @param a_User The pawn that used this entity effect * @param a_DistanceModifier The distance modifier for affecting potency, defaults to 1 */ - cEntityEffect(int a_Ticks, short a_Intensity, cPawn *a_User, double a_DistanceModifier = 1); + cEntityEffect(int a_Duration, short a_Intensity, cPawn *a_User, double a_DistanceModifier = 1); private: + /** How long this effect will last */ + int m_Duration; + /** How strong the effect will be applied */ short m_Intensity; diff --git a/src/Entities/Pawn.cpp b/src/Entities/Pawn.cpp index 186e7df2a..0273981f9 100644 --- a/src/Entities/Pawn.cpp +++ b/src/Entities/Pawn.cpp @@ -30,14 +30,14 @@ void cPawn::Tick(float a_Dt, cChunk & a_Chunk) // Apply entity effect HandleEntityEffect(effect_type, effect_values); - // Reduce the effect's duration - effect_values.m_Ticks--; + // Increase the effect's tick counter + effect_values.m_Ticks++; // Iterates (must be called before any possible erasure) ++iter; // Remove effect if duration has elapsed - if (effect_values.m_Ticks <= 0) + if (effect_values.GetDuration() - effect_values.m_Ticks <= 0) { RemoveEntityEffect(effect_type); } @@ -68,8 +68,9 @@ void cPawn::AddEntityEffect(cEntityEffect::eType a_EffectType, cEntityEffect a_E return; } + a_Effect.SetDuration(a_Effect.GetDuration() * a_Effect.GetDistanceModifier()); m_EntityEffects[a_EffectType] = a_Effect; - m_World->BroadcastEntityEffect(*this, a_EffectType, a_Effect.GetIntensity(), a_Effect.m_Ticks * a_Effect.GetDistanceModifier()); + m_World->BroadcastEntityEffect(*this, a_EffectType, a_Effect.GetIntensity(), a_Effect.GetDuration()); } @@ -143,12 +144,9 @@ void cPawn::HandleEntityEffect(cEntityEffect::eType a_EffectType, cEntityEffect // Regen frequency = 50 ticks, divided by potion level (Regen II = 25 ticks) int frequency = std::floor(50.0 / (double)(a_Effect.GetIntensity() + 1)); - // TODO: The counter needs to be specific to one cPawn, make it a member variable. - static short counter = 0; - if (++counter >= frequency) + if (a_Effect.m_Ticks % frequency == 0) { Heal(1); - counter = 0; } return; @@ -158,16 +156,13 @@ void cPawn::HandleEntityEffect(cEntityEffect::eType a_EffectType, cEntityEffect // Poison frequency = 25 ticks, divided by potion level (Poison II = 12 ticks) int frequency = std::floor(25.0 / (double)(a_Effect.GetIntensity() + 1)); - // TODO: The counter needs to be specific to one cPawn, make it a member variable. - static short counter = 0; - if (++counter >= frequency) + if (a_Effect.m_Ticks % frequency == 0) { // Cannot take poison damage when health is at 1 if (GetHealth() > 1) { TakeDamage(dtPoisoning, a_Effect.GetUser(), 1, 0); } - counter = 0; } return; @@ -177,12 +172,9 @@ void cPawn::HandleEntityEffect(cEntityEffect::eType a_EffectType, cEntityEffect // Poison frequency = 40 ticks, divided by effect level (Wither II = 20 ticks) int frequency = std::floor(25.0 / (double)(a_Effect.GetIntensity() + 1)); - // TODO: The counter needs to be specific to one cPawn, make it a member variable. - static short counter = 0; - if (++counter >= frequency) + if (a_Effect.m_Ticks % frequency == 0) { TakeDamage(dtWither, a_Effect.GetUser(), 1, 0); - counter = 0; } //TODO: "<Player> withered away> return; |