summaryrefslogtreecommitdiffstats
path: root/src/Entities
diff options
context:
space:
mode:
Diffstat (limited to 'src/Entities')
-rw-r--r--src/Entities/EntityEffects.h6
-rw-r--r--src/Entities/Pawn.cpp16
-rw-r--r--src/Entities/Pawn.h11
-rw-r--r--src/Entities/Player.cpp2
-rw-r--r--src/Entities/SplashPotionEntity.cpp8
5 files changed, 30 insertions, 13 deletions
diff --git a/src/Entities/EntityEffects.h b/src/Entities/EntityEffects.h
index c0e8abd28..2a4d0f723 100644
--- a/src/Entities/EntityEffects.h
+++ b/src/Entities/EntityEffects.h
@@ -45,7 +45,7 @@ public:
/** Returns how strong the effect will be applied */
short GetIntensity() { return m_Intensity; }
- /** Returns the pawn that used this entity effect */
+ /** Returns the pawn that produced this entity effect */
cPawn *GetUser() { return m_User; }
/** Returns the distance modifier for affecting potency */
@@ -62,7 +62,7 @@ public:
/** Creates an entity effect of the specified type
@param a_Duration How long this effect will last, in ticks
@param a_Intensity How strong the effect will be applied
- @param a_User The pawn that used this entity effect
+ @param a_User The pawn that produced this entity effect
@param a_DistanceModifier The distance modifier for affecting potency, defaults to 1 */
cEntityEffect(int a_Duration, short a_Intensity, cPawn * a_User, double a_DistanceModifier = 1);
@@ -73,7 +73,7 @@ private:
/** How strong the effect will be applied */
short m_Intensity;
- /** The pawn that used this entity effect */
+ /** The pawn that produced this entity effect (threw the potion, etc) */
cPawn *m_User;
/** The distance modifier for affecting potency */
diff --git a/src/Entities/Pawn.cpp b/src/Entities/Pawn.cpp
index ec829f6f8..2986799b7 100644
--- a/src/Entities/Pawn.cpp
+++ b/src/Entities/Pawn.cpp
@@ -61,15 +61,25 @@ void cPawn::KilledBy(cEntity * a_Killer)
-void cPawn::AddEntityEffect(cEntityEffect::eType a_EffectType, int a_EffectDurationTicks, short a_EffectIntensity, double a_DistanceModifier)
+void cPawn::AddEntityEffect(cEntityEffect::eType a_EffectType, int a_EffectDurationTicks, short a_EffectIntensity, cPawn * a_User, double a_DistanceModifier)
+{
+ AddEntityEffect(a_EffectType, cEntityEffect(a_EffectDurationTicks, a_EffectIntensity, a_User, a_DistanceModifier));
+}
+
+
+
+
+
+void cPawn::AddEntityEffect(cEntityEffect::eType a_EffectType, cEntityEffect a_Effect)
{
if (a_EffectType == cEntityEffect::effNoEffect)
{
return;
}
- m_EntityEffects[a_EffectType] = cEntityEffect(a_EffectDurationTicks, a_EffectIntensity, this, a_DistanceModifier);
- m_World->BroadcastEntityEffect(*this, a_EffectType, a_EffectIntensity, (short)(a_EffectDurationTicks * a_DistanceModifier));
+ 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.GetDuration());
}
diff --git a/src/Entities/Pawn.h b/src/Entities/Pawn.h
index 399e02e64..3b83ec52f 100644
--- a/src/Entities/Pawn.h
+++ b/src/Entities/Pawn.h
@@ -26,10 +26,19 @@ public:
// tolua_begin
/** Applies an entity effect
+ @param a_EffectType The entity effect to apply
+ @param a_EffectDurationTicks The duration of the effect
+ @param a_EffectIntensity The level of the effect (0 = Potion I, 1 = Potion II, etc)
+ @param a_User The pawn that produced the effect (e.g. threw the potion)
+ @param a_DistanceModifier The scalar multiplied to the potion duration, only applies to splash potions)
+ */
+ void AddEntityEffect(cEntityEffect::eType a_EffectType, int a_EffectDurationTicks, short a_EffectIntensity, cPawn * a_User, double a_DistanceModifier = 1);
+
+ /** Applies an entity effect
@param a_EffectType The entity effect to apply
@param a_Effect The parameters of the effect
*/
- void AddEntityEffect(cEntityEffect::eType a_EffectType, int a_EffectDurationTicks, short a_EffectIntensity, double a_DistanceModifier = 1);
+ void AddEntityEffect(cEntityEffect::eType a_EffectType, cEntityEffect a_Effect);
/** Removes a currently applied entity effect
@param a_EffectType The entity effect to remove
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index f2ec81957..b7a315a40 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -570,7 +570,7 @@ bool cPlayer::Feed(int a_Food, double a_Saturation)
void cPlayer::FoodPoison(int a_NumTicks)
{
- AddEntityEffect(cEntityEffect::effHunger, a_NumTicks, 0);
+ AddEntityEffect(cEntityEffect::effHunger, a_NumTicks, 0, NULL);
}
diff --git a/src/Entities/SplashPotionEntity.cpp b/src/Entities/SplashPotionEntity.cpp
index 4035b4794..714e4021d 100644
--- a/src/Entities/SplashPotionEntity.cpp
+++ b/src/Entities/SplashPotionEntity.cpp
@@ -68,7 +68,7 @@ cSplashPotionEntity::cSplashPotionCallback::cSplashPotionCallback(const Vector3d
bool cSplashPotionEntity::cSplashPotionCallback::Item(cEntity * a_Entity)
{
double SplashDistance = (a_Entity->GetPosition() - m_HitPos).Length();
- if (SplashDistance < 20)
+ if (SplashDistance < 20 && a_Entity->IsPawn())
{
// y = -0.25x + 1, where x is the distance from the player. Approximation for potion splash.
// TODO: better equation
@@ -78,10 +78,8 @@ bool cSplashPotionEntity::cSplashPotionCallback::Item(cEntity * a_Entity)
Reduction = 0;
}
- if (a_Entity->IsPawn())
- {
- ((cPawn *) a_Entity)->AddEntityEffect(m_EntityEffectType, m_EntityEffect.m_Ticks, m_EntityEffect.GetIntensity(), Reduction);
- }
+ m_EntityEffect.SetDistanceModifier(Reduction);
+ ((cPawn *) a_Entity)->AddEntityEffect(m_EntityEffectType, m_EntityEffect);
}
return false;
}