Changed the AddEntityEffect() params for easier calls.
This commit is contained in:
parent
22761bb6ad
commit
e289fe4dd7
@ -3,7 +3,8 @@
|
|||||||
class cPawn;
|
class cPawn;
|
||||||
|
|
||||||
// tolua_begin
|
// tolua_begin
|
||||||
class cEntityEffect {
|
class cEntityEffect
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/** All types of entity effects (numbers correspond to IDs) */
|
/** All types of entity effects (numbers correspond to IDs) */
|
||||||
@ -52,25 +53,21 @@ public:
|
|||||||
|
|
||||||
void SetDuration(int a_Duration) { m_Duration = a_Duration; }
|
void SetDuration(int a_Duration) { m_Duration = a_Duration; }
|
||||||
void SetIntensity(short a_Intensity) { m_Intensity = a_Intensity; }
|
void SetIntensity(short a_Intensity) { m_Intensity = a_Intensity; }
|
||||||
void SetUser(cPawn *a_User) { m_User = a_User; }
|
void SetUser(cPawn * a_User) { m_User = a_User; }
|
||||||
void SetDistanceModifier(double a_DistanceModifier) { m_DistanceModifier = a_DistanceModifier; }
|
void SetDistanceModifier(double a_DistanceModifier) { m_DistanceModifier = a_DistanceModifier; }
|
||||||
|
|
||||||
/**
|
/** Creates an empty entity effect */
|
||||||
* An empty entity effect
|
cEntityEffect(void);
|
||||||
*/
|
|
||||||
cEntityEffect();
|
|
||||||
|
|
||||||
/**
|
/** Creates an entity effect of the specified type
|
||||||
* An entity effect
|
@param a_Duration How long this effect will last, in ticks
|
||||||
* @param a_Duration How long this effect will last
|
@param a_Intensity How strong the effect will be applied
|
||||||
* @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 used this entity effect
|
@param a_DistanceModifier The distance modifier for affecting potency, defaults to 1 */
|
||||||
* @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);
|
||||||
*/
|
|
||||||
cEntityEffect(int a_Duration, short a_Intensity, cPawn *a_User, double a_DistanceModifier = 1);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/** How long this effect will last */
|
/** How long this effect will last, in ticks */
|
||||||
int m_Duration;
|
int m_Duration;
|
||||||
|
|
||||||
/** How strong the effect will be applied */
|
/** How strong the effect will be applied */
|
||||||
|
@ -8,9 +8,9 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
cPawn::cPawn(eEntityType a_EntityType, double a_Width, double a_Height)
|
cPawn::cPawn(eEntityType a_EntityType, double a_Width, double a_Height):
|
||||||
: cEntity(a_EntityType, 0, 0, 0, a_Width, a_Height)
|
super(a_EntityType, 0, 0, 0, a_Width, a_Height),
|
||||||
, m_EntityEffects(tEffectMap())
|
m_EntityEffects(tEffectMap())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -24,22 +24,22 @@ void cPawn::Tick(float a_Dt, cChunk & a_Chunk)
|
|||||||
for (tEffectMap::iterator iter = m_EntityEffects.begin(); iter != m_EntityEffects.end();)
|
for (tEffectMap::iterator iter = m_EntityEffects.begin(); iter != m_EntityEffects.end();)
|
||||||
{
|
{
|
||||||
// Copies values to prevent pesky wrong accesses and erasures
|
// Copies values to prevent pesky wrong accesses and erasures
|
||||||
cEntityEffect::eType effect_type = iter->first;
|
cEntityEffect::eType EffectType = iter->first;
|
||||||
cEntityEffect &effect_values = iter->second;
|
cEntityEffect & EffectValues = iter->second;
|
||||||
|
|
||||||
// Apply entity effect
|
// Apply entity effect
|
||||||
HandleEntityEffect(effect_type, effect_values);
|
HandleEntityEffect(EffectType, EffectValues);
|
||||||
|
|
||||||
// Increase the effect's tick counter
|
// Reduce the effect's duration
|
||||||
effect_values.m_Ticks++;
|
EffectValues.m_Ticks++;
|
||||||
|
|
||||||
// Iterates (must be called before any possible erasure)
|
// Iterates (must be called before any possible erasure)
|
||||||
++iter;
|
++iter;
|
||||||
|
|
||||||
// Remove effect if duration has elapsed
|
// Remove effect if duration has elapsed
|
||||||
if (effect_values.GetDuration() - effect_values.m_Ticks <= 0)
|
if (EffectValues.GetDuration() - EffectValues.m_Ticks <= 0)
|
||||||
{
|
{
|
||||||
RemoveEntityEffect(effect_type);
|
RemoveEntityEffect(EffectType);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Check for discrepancies between client and server effect values
|
// TODO: Check for discrepancies between client and server effect values
|
||||||
@ -52,7 +52,7 @@ void cPawn::Tick(float a_Dt, cChunk & a_Chunk)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cPawn::KilledBy(cEntity *a_Killer)
|
void cPawn::KilledBy(cEntity * a_Killer)
|
||||||
{
|
{
|
||||||
ClearEntityEffects();
|
ClearEntityEffects();
|
||||||
}
|
}
|
||||||
@ -61,16 +61,15 @@ void cPawn::KilledBy(cEntity *a_Killer)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cPawn::AddEntityEffect(cEntityEffect::eType a_EffectType, cEntityEffect a_Effect)
|
void cPawn::AddEntityEffect(cEntityEffect::eType a_EffectType, int a_EffectDurationTicks, short a_EffectIntensity, double a_DistanceModifier)
|
||||||
{
|
{
|
||||||
if (a_EffectType == cEntityEffect::effNoEffect)
|
if (a_EffectType == cEntityEffect::effNoEffect)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
a_Effect.SetDuration(a_Effect.GetDuration() * a_Effect.GetDistanceModifier());
|
m_EntityEffects[a_EffectType] = cEntityEffect(a_EffectDurationTicks, a_EffectIntensity, this, a_DistanceModifier);
|
||||||
m_EntityEffects[a_EffectType] = a_Effect;
|
m_World->BroadcastEntityEffect(*this, a_EffectType, a_EffectIntensity, (short)(a_EffectDurationTicks * a_DistanceModifier));
|
||||||
m_World->BroadcastEntityEffect(*this, a_EffectType, a_Effect.GetIntensity(), a_Effect.GetDuration());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -93,13 +92,13 @@ void cPawn::ClearEntityEffects()
|
|||||||
for (tEffectMap::iterator iter = m_EntityEffects.begin(); iter != m_EntityEffects.end();)
|
for (tEffectMap::iterator iter = m_EntityEffects.begin(); iter != m_EntityEffects.end();)
|
||||||
{
|
{
|
||||||
// Copy values to prevent pesky wrong erasures
|
// Copy values to prevent pesky wrong erasures
|
||||||
cEntityEffect::eType effect_type = iter->first;
|
cEntityEffect::eType EffectType = iter->first;
|
||||||
|
|
||||||
// Iterates (must be called before any possible erasure)
|
// Iterates (must be called before any possible erasure)
|
||||||
++iter;
|
++iter;
|
||||||
|
|
||||||
// Remove effect
|
// Remove effect
|
||||||
RemoveEntityEffect(effect_type);
|
RemoveEntityEffect(EffectType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,19 +24,21 @@ public:
|
|||||||
virtual void KilledBy(cEntity * a_Killer) override;
|
virtual void KilledBy(cEntity * a_Killer) override;
|
||||||
|
|
||||||
// tolua_begin
|
// tolua_begin
|
||||||
|
|
||||||
/** Applies an entity effect
|
/** Applies an entity effect
|
||||||
* @param a_EffectType The entity effect to apply
|
@param a_EffectType The entity effect to apply
|
||||||
* @param a_Effect The parameters of the effect
|
@param a_Effect The parameters of the effect
|
||||||
*/
|
*/
|
||||||
void AddEntityEffect(cEntityEffect::eType a_EffectType, cEntityEffect a_Effect);
|
void AddEntityEffect(cEntityEffect::eType a_EffectType, int a_EffectDurationTicks, short a_EffectIntensity, double a_DistanceModifier = 1);
|
||||||
|
|
||||||
/** Removes a currently applied entity effect
|
/** Removes a currently applied entity effect
|
||||||
* @param a_EffectType The entity effect to remove
|
@param a_EffectType The entity effect to remove
|
||||||
*/
|
*/
|
||||||
void RemoveEntityEffect(cEntityEffect::eType a_EffectType);
|
void RemoveEntityEffect(cEntityEffect::eType a_EffectType);
|
||||||
|
|
||||||
/** Removes all currently applied entity effects (used when drinking milk) */
|
/** Removes all currently applied entity effects (used when drinking milk) */
|
||||||
void ClearEntityEffects();
|
void ClearEntityEffects(void);
|
||||||
|
|
||||||
// tolua_end
|
// tolua_end
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -570,7 +570,7 @@ bool cPlayer::Feed(int a_Food, double a_Saturation)
|
|||||||
|
|
||||||
void cPlayer::FoodPoison(int a_NumTicks)
|
void cPlayer::FoodPoison(int a_NumTicks)
|
||||||
{
|
{
|
||||||
AddEntityEffect(cEntityEffect::effHunger, cEntityEffect(a_NumTicks, 0, NULL));
|
AddEntityEffect(cEntityEffect::effHunger, a_NumTicks, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -67,20 +67,25 @@ cSplashPotionEntity::cSplashPotionCallback::cSplashPotionCallback(const Vector3d
|
|||||||
|
|
||||||
bool cSplashPotionEntity::cSplashPotionCallback::Item(cEntity * a_Entity)
|
bool cSplashPotionEntity::cSplashPotionCallback::Item(cEntity * a_Entity)
|
||||||
{
|
{
|
||||||
double distance_splash = (a_Entity->GetPosition() - m_HitPos).Length();
|
double SplashDistance = (a_Entity->GetPosition() - m_HitPos).Length();
|
||||||
if (distance_splash < 20)
|
if (SplashDistance < 20)
|
||||||
{
|
{
|
||||||
// y = -0.25x + 1, where x is the distance from the player. Approximation for potion splash.
|
// y = -0.25x + 1, where x is the distance from the player. Approximation for potion splash.
|
||||||
// TODO: better equation
|
// TODO: better equation
|
||||||
double reduction = -0.25 * distance_splash + 1.0;
|
double Reduction = -0.25 * SplashDistance + 1.0;
|
||||||
if (reduction < 0) reduction = 0;
|
if (Reduction < 0)
|
||||||
|
{
|
||||||
m_EntityEffect.SetDistanceModifier(reduction);
|
Reduction = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (a_Entity->IsPawn())
|
if (a_Entity->IsPawn())
|
||||||
{
|
{
|
||||||
((cPawn *) a_Entity)->AddEntityEffect(m_EntityEffectType, m_EntityEffect);
|
((cPawn *) a_Entity)->AddEntityEffect(m_EntityEffectType, m_EntityEffect.m_Ticks, m_EntityEffect.GetIntensity(), Reduction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -146,8 +146,7 @@ public:
|
|||||||
virtual bool EatItem(cPlayer * a_Player, cItem * a_Item) override
|
virtual bool EatItem(cPlayer * a_Player, cItem * a_Item) override
|
||||||
{
|
{
|
||||||
// Called when potion is a drinkable potion
|
// Called when potion is a drinkable potion
|
||||||
short potion_damage = a_Item->m_ItemDamage;
|
a_Player->AddEntityEffect(GetEntityEffectType(a_Item->m_ItemDamage), GetEntityEffectDuration(a_Item->m_ItemDamage), GetEntityEffectIntensity(a_Item->m_ItemDamage));
|
||||||
a_Player->AddEntityEffect(GetEntityEffectType(potion_damage), cEntityEffect(GetEntityEffectDuration(potion_damage), GetEntityEffectIntensity(potion_damage), a_Player));
|
|
||||||
a_Player->GetInventory().RemoveOneEquippedItem();
|
a_Player->GetInventory().RemoveOneEquippedItem();
|
||||||
a_Player->GetInventory().AddItem(E_ITEM_GLASS_BOTTLE);
|
a_Player->GetInventory().AddItem(E_ITEM_GLASS_BOTTLE);
|
||||||
return true;
|
return true;
|
||||||
|
@ -34,7 +34,7 @@ void cCaveSpider::Attack(float a_Dt)
|
|||||||
if (m_Target->IsPawn())
|
if (m_Target->IsPawn())
|
||||||
{
|
{
|
||||||
// TODO: Easy = no poison, Medium = 7 seconds, Hard = 15 seconds
|
// TODO: Easy = no poison, Medium = 7 seconds, Hard = 15 seconds
|
||||||
((cPawn *) m_Target)->AddEntityEffect(cEntityEffect::effPoison, cEntityEffect(140, 0, this));
|
((cPawn *) m_Target)->AddEntityEffect(cEntityEffect::effPoison, 7 * 20, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user