1
0

Entity Effects: Clarified user, added it to AddEntityEffect

Added second AddEntityEffect with a pass-by-value of the class.
This commit is contained in:
archshift 2014-06-13 02:41:43 -07:00
parent e289fe4dd7
commit 9e8361976b
7 changed files with 32 additions and 15 deletions

View File

@ -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 */

View File

@ -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());
}

View File

@ -25,11 +25,20 @@ 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

View File

@ -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);
}

View File

@ -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;
}

View File

@ -146,7 +146,7 @@ public:
virtual bool EatItem(cPlayer * a_Player, cItem * a_Item) override
{
// Called when potion is a drinkable potion
a_Player->AddEntityEffect(GetEntityEffectType(a_Item->m_ItemDamage), GetEntityEffectDuration(a_Item->m_ItemDamage), GetEntityEffectIntensity(a_Item->m_ItemDamage));
a_Player->AddEntityEffect(GetEntityEffectType(a_Item->m_ItemDamage), GetEntityEffectDuration(a_Item->m_ItemDamage), GetEntityEffectIntensity(a_Item->m_ItemDamage), a_Player);
a_Player->GetInventory().RemoveOneEquippedItem();
a_Player->GetInventory().AddItem(E_ITEM_GLASS_BOTTLE);
return true;

View File

@ -34,7 +34,7 @@ void cCaveSpider::Attack(float a_Dt)
if (m_Target->IsPawn())
{
// TODO: Easy = no poison, Medium = 7 seconds, Hard = 15 seconds
((cPawn *) m_Target)->AddEntityEffect(cEntityEffect::effPoison, 7 * 20, 0);
((cPawn *) m_Target)->AddEntityEffect(cEntityEffect::effPoison, 7 * 20, 0, this);
}
}