Restructured cSplashPotionEntity code.
The callback doesn't need declaration in the header. Renamed PotionName to PotionParticleType.
This commit is contained in:
parent
f5259d7651
commit
cc452f51c8
@ -7,7 +7,7 @@ class cEntityEffect
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/** All types of entity effects (numbers correspond to IDs) */
|
/** All types of entity effects (numbers correspond to protocol / storage types) */
|
||||||
enum eType
|
enum eType
|
||||||
{
|
{
|
||||||
effNoEffect = 0,
|
effNoEffect = 0,
|
||||||
@ -66,21 +66,30 @@ public:
|
|||||||
static cEntityEffect * CreateEntityEffect(cEntityEffect::eType a_EffectType, int a_Duration, short a_Intensity, double a_DistanceModifier);
|
static cEntityEffect * CreateEntityEffect(cEntityEffect::eType a_EffectType, int a_Duration, short a_Intensity, double a_DistanceModifier);
|
||||||
|
|
||||||
/** Returns how many ticks this effect has been active for */
|
/** Returns how many ticks this effect has been active for */
|
||||||
int GetTicks() { return m_Ticks; }
|
int GetTicks(void) const { return m_Ticks; }
|
||||||
|
|
||||||
/** Returns the duration of the effect */
|
/** Returns the duration of the effect */
|
||||||
int GetDuration() { return m_Duration; }
|
int GetDuration(void) const { return m_Duration; }
|
||||||
|
|
||||||
/** Returns how strong the effect will be applied */
|
/** Returns how strong the effect will be applied */
|
||||||
short GetIntensity() { return m_Intensity; }
|
short GetIntensity(void) const { return m_Intensity; }
|
||||||
|
|
||||||
/** Returns the distance modifier for affecting potency */
|
/** Returns the distance modifier for affecting potency */
|
||||||
double GetDistanceModifier() { return m_DistanceModifier; }
|
double GetDistanceModifier(void) const { return m_DistanceModifier; }
|
||||||
|
|
||||||
void SetTicks(int a_Ticks) { m_Ticks = a_Ticks; }
|
void SetTicks(int a_Ticks) { m_Ticks = a_Ticks; }
|
||||||
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 SetDistanceModifier(double a_DistanceModifier) { m_DistanceModifier = a_DistanceModifier; }
|
void SetDistanceModifier(double a_DistanceModifier) { m_DistanceModifier = a_DistanceModifier; }
|
||||||
|
|
||||||
|
/** Called on each tick.
|
||||||
|
By default increases the m_Ticks, descendants may override to provide additional processing. */
|
||||||
virtual void OnTick(cPawn & a_Target);
|
virtual void OnTick(cPawn & a_Target);
|
||||||
|
|
||||||
|
/** Called when the effect is first added to an entity */
|
||||||
virtual void OnActivate(cPawn & a_Target) { }
|
virtual void OnActivate(cPawn & a_Target) { }
|
||||||
|
|
||||||
|
/** Called when the effect is removed from an entity */
|
||||||
virtual void OnDeactivate(cPawn & a_Target) { }
|
virtual void OnDeactivate(cPawn & a_Target) { }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -7,11 +7,77 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
cSplashPotionEntity::cSplashPotionEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed, cEntityEffect::eType a_EntityEffectType, cEntityEffect a_EntityEffect, int a_PotionName) :
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// cSplashPotionEntityCallback:
|
||||||
|
|
||||||
|
/** Used to distribute the splashed potion effect among nearby entities */
|
||||||
|
class cSplashPotionCallback :
|
||||||
|
public cEntityCallback
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/** Creates the callback.
|
||||||
|
@param a_HitPos The position where the splash potion has splashed
|
||||||
|
@param a_EntityEffectType The effect type of the potion
|
||||||
|
@param a_EntityEffect The effect description */
|
||||||
|
cSplashPotionCallback(const Vector3d & a_HitPos, cEntityEffect::eType a_EntityEffectType, const cEntityEffect & a_EntityEffect) :
|
||||||
|
m_HitPos(a_HitPos),
|
||||||
|
m_EntityEffectType(a_EntityEffectType),
|
||||||
|
m_EntityEffect(a_EntityEffect)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Called by cWorld::ForEachEntity(), adds the stored entity effect to the entity, if it is close enough. */
|
||||||
|
virtual bool Item(cEntity * a_Entity) override
|
||||||
|
{
|
||||||
|
double SplashDistance = (a_Entity->GetPosition() - m_HitPos).Length();
|
||||||
|
if (SplashDistance >= 20)
|
||||||
|
{
|
||||||
|
// Too far away
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!a_Entity->IsPawn())
|
||||||
|
{
|
||||||
|
// Not an entity that can take effects
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// y = -0.25x + 1, where x is the distance from the player. Approximation for potion splash.
|
||||||
|
// TODO: better equation
|
||||||
|
double Reduction = -0.25 * SplashDistance + 1.0;
|
||||||
|
if (Reduction < 0)
|
||||||
|
{
|
||||||
|
Reduction = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
((cPawn *) a_Entity)->AddEntityEffect(m_EntityEffectType, m_EntityEffect.GetDuration(), m_EntityEffect.GetIntensity(), Reduction);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
const Vector3d & m_HitPos;
|
||||||
|
cEntityEffect::eType m_EntityEffectType;
|
||||||
|
const cEntityEffect & m_EntityEffect;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// cSplashPotionEntity:
|
||||||
|
|
||||||
|
cSplashPotionEntity::cSplashPotionEntity(
|
||||||
|
cEntity * a_Creator,
|
||||||
|
double a_X, double a_Y, double a_Z,
|
||||||
|
const Vector3d & a_Speed,
|
||||||
|
cEntityEffect::eType a_EntityEffectType,
|
||||||
|
cEntityEffect a_EntityEffect,
|
||||||
|
int a_PotionParticleType
|
||||||
|
) :
|
||||||
super(pkSplashPotion, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25),
|
super(pkSplashPotion, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25),
|
||||||
m_EntityEffectType(a_EntityEffectType),
|
m_EntityEffectType(a_EntityEffectType),
|
||||||
m_EntityEffect(a_EntityEffect),
|
m_EntityEffect(a_EntityEffect),
|
||||||
m_PotionName(a_PotionName)
|
m_PotionParticleType(a_PotionParticleType)
|
||||||
{
|
{
|
||||||
SetSpeed(a_Speed);
|
SetSpeed(a_Speed);
|
||||||
}
|
}
|
||||||
@ -46,42 +112,7 @@ void cSplashPotionEntity::Splash(const Vector3d & a_HitPos)
|
|||||||
cSplashPotionCallback Callback(a_HitPos, m_EntityEffectType, m_EntityEffect);
|
cSplashPotionCallback Callback(a_HitPos, m_EntityEffectType, m_EntityEffect);
|
||||||
m_World->ForEachEntity(Callback);
|
m_World->ForEachEntity(Callback);
|
||||||
|
|
||||||
m_World->BroadcastSoundParticleEffect(2002, a_HitPos.x, a_HitPos.y, a_HitPos.z, m_PotionName);
|
m_World->BroadcastSoundParticleEffect(2002, a_HitPos.x, a_HitPos.y, a_HitPos.z, m_PotionParticleType);
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
cSplashPotionEntity::cSplashPotionCallback::cSplashPotionCallback(const Vector3d & a_HitPos, cEntityEffect::eType &a_EntityEffectType, cEntityEffect &a_EntityEffect):
|
|
||||||
m_HitPos(a_HitPos),
|
|
||||||
m_EntityEffectType(a_EntityEffectType),
|
|
||||||
m_EntityEffect(a_EntityEffect)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool cSplashPotionEntity::cSplashPotionCallback::Item(cEntity * a_Entity)
|
|
||||||
{
|
|
||||||
double SplashDistance = (a_Entity->GetPosition() - m_HitPos).Length();
|
|
||||||
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
|
|
||||||
double Reduction = -0.25 * SplashDistance + 1.0;
|
|
||||||
if (Reduction < 0)
|
|
||||||
{
|
|
||||||
Reduction = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_EntityEffect.SetDistanceModifier(Reduction);
|
|
||||||
((cPawn *) a_Entity)->AddEntityEffect(m_EntityEffectType, m_EntityEffect.GetDuration(), m_EntityEffect.GetIntensity(), Reduction);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,43 +25,35 @@ public:
|
|||||||
|
|
||||||
CLASS_PROTODEF(cSplashPotionEntity);
|
CLASS_PROTODEF(cSplashPotionEntity);
|
||||||
|
|
||||||
cSplashPotionEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed, cEntityEffect::eType a_EntityEffectType, cEntityEffect a_EntityEffect, int a_PotionName);
|
cSplashPotionEntity(
|
||||||
|
cEntity * a_Creator,
|
||||||
|
double a_X, double a_Y, double a_Z,
|
||||||
|
const Vector3d & a_Speed,
|
||||||
|
cEntityEffect::eType a_EntityEffectType,
|
||||||
|
cEntityEffect a_EntityEffect,
|
||||||
|
int a_PotionParticleType
|
||||||
|
);
|
||||||
|
|
||||||
cEntityEffect::eType GetEntityEffectType() { return m_EntityEffectType; }
|
cEntityEffect::eType GetEntityEffectType (void) const { return m_EntityEffectType; }
|
||||||
cEntityEffect GetEntityEffect() { return m_EntityEffect; }
|
cEntityEffect GetEntityEffect (void) const { return m_EntityEffect; }
|
||||||
int GetPotionName() { return m_PotionName; }
|
int GetPotionParticleType(void) const { return m_PotionParticleType; }
|
||||||
|
|
||||||
void SetEntityEffectType(cEntityEffect::eType a_EntityEffectType) { m_EntityEffectType = a_EntityEffectType; }
|
void SetEntityEffectType(cEntityEffect::eType a_EntityEffectType) { m_EntityEffectType = a_EntityEffectType; }
|
||||||
void SetEntityEffect(cEntityEffect a_EntityEffect) { m_EntityEffect = a_EntityEffect; }
|
void SetEntityEffect(cEntityEffect a_EntityEffect) { m_EntityEffect = a_EntityEffect; }
|
||||||
void SetPotionName(int a_PotionName) { m_PotionName = a_PotionName; }
|
void SetPotionParticleType(int a_PotionParticleType) { m_PotionParticleType = a_PotionParticleType; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
cEntityEffect::eType m_EntityEffectType;
|
||||||
|
cEntityEffect m_EntityEffect;
|
||||||
|
int m_PotionParticleType;
|
||||||
|
|
||||||
|
|
||||||
// cProjectileEntity overrides:
|
// cProjectileEntity overrides:
|
||||||
virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override;
|
virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override;
|
||||||
virtual void OnHitEntity (cEntity & a_EntityHit, const Vector3d & a_HitPos) override;
|
virtual void OnHitEntity (cEntity & a_EntityHit, const Vector3d & a_HitPos) override;
|
||||||
|
|
||||||
/** Splashes the potion, fires its particle effects and sounds
|
/** Splashes the potion, fires its particle effects and sounds
|
||||||
* @param a_HitPos The position where the potion will splash
|
@param a_HitPos The position where the potion will splash */
|
||||||
*/
|
|
||||||
void Splash(const Vector3d & a_HitPos);
|
void Splash(const Vector3d & a_HitPos);
|
||||||
|
|
||||||
cEntityEffect::eType m_EntityEffectType;
|
|
||||||
cEntityEffect m_EntityEffect;
|
|
||||||
int m_PotionName;
|
|
||||||
|
|
||||||
class cSplashPotionCallback :
|
|
||||||
public cEntityCallback
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
cSplashPotionCallback(const Vector3d & a_HitPos, cEntityEffect::eType &a_EntityEffectType, cEntityEffect &a_EntityEffect);
|
|
||||||
|
|
||||||
virtual bool Item(cEntity *a_Entity) override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
const Vector3d &m_HitPos;
|
|
||||||
cEntityEffect::eType &m_EntityEffectType;
|
|
||||||
cEntityEffect &m_EntityEffect;
|
|
||||||
};
|
|
||||||
|
|
||||||
} ; // tolua_export
|
} ; // tolua_export
|
||||||
|
@ -613,7 +613,7 @@ void cNBTChunkSerializer::AddProjectileEntity(cProjectileEntity * a_Projectile)
|
|||||||
m_Writer.AddInt("EffectDuration", (Int16)Potion->GetEntityEffect().GetDuration());
|
m_Writer.AddInt("EffectDuration", (Int16)Potion->GetEntityEffect().GetDuration());
|
||||||
m_Writer.AddShort("EffectIntensity", Potion->GetEntityEffect().GetIntensity());
|
m_Writer.AddShort("EffectIntensity", Potion->GetEntityEffect().GetIntensity());
|
||||||
m_Writer.AddDouble("EffectDistanceModifier", Potion->GetEntityEffect().GetDistanceModifier());
|
m_Writer.AddDouble("EffectDistanceModifier", Potion->GetEntityEffect().GetDistanceModifier());
|
||||||
m_Writer.AddInt("PotionName", Potion->GetPotionName());
|
m_Writer.AddInt("PotionName", Potion->GetPotionParticleType());
|
||||||
}
|
}
|
||||||
case cProjectileEntity::pkGhastFireball:
|
case cProjectileEntity::pkGhastFireball:
|
||||||
{
|
{
|
||||||
|
@ -1681,7 +1681,7 @@ void cWSSAnvil::LoadSplashPotionFromNBT(cEntityList & a_Entities, const cParsedN
|
|||||||
|
|
||||||
SplashPotion->SetEntityEffectType((cEntityEffect::eType) a_NBT.FindChildByName(a_TagIdx, "EffectType"));
|
SplashPotion->SetEntityEffectType((cEntityEffect::eType) a_NBT.FindChildByName(a_TagIdx, "EffectType"));
|
||||||
SplashPotion->SetEntityEffect(cEntityEffect(EffectDuration, EffectIntensity, EffectDistanceModifier));
|
SplashPotion->SetEntityEffect(cEntityEffect(EffectDuration, EffectIntensity, EffectDistanceModifier));
|
||||||
SplashPotion->SetPotionName(a_NBT.FindChildByName(a_TagIdx, "PotionName"));
|
SplashPotion->SetPotionParticleType(a_NBT.FindChildByName(a_TagIdx, "PotionName"));
|
||||||
|
|
||||||
// Store the new splash potion in the entities list:
|
// Store the new splash potion in the entities list:
|
||||||
a_Entities.push_back(SplashPotion.release());
|
a_Entities.push_back(SplashPotion.release());
|
||||||
|
Loading…
Reference in New Issue
Block a user