1
0

Applies splash potion effects to mobs as well as players

This commit is contained in:
archshift 2014-06-08 18:14:34 -07:00
parent 68011a004a
commit 52abd90a28
2 changed files with 12 additions and 8 deletions

View File

@ -1,7 +1,7 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "SplashPotionEntity.h" #include "SplashPotionEntity.h"
#include "Player.h" #include "Pawn.h"
@ -44,8 +44,7 @@ void cSplashPotionEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_
void cSplashPotionEntity::Splash(const Vector3d & a_HitPos) 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->ForEachPlayer(Callback); m_World->ForEachEntity(Callback);
// TODO: Should be for each pawn
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_PotionName);
} }
@ -66,9 +65,9 @@ cSplashPotionEntity::cSplashPotionCallback::cSplashPotionCallback(const Vector3d
bool cSplashPotionEntity::cSplashPotionCallback::Item(cPlayer * a_Player) bool cSplashPotionEntity::cSplashPotionCallback::Item(cEntity * a_Entity)
{ {
double distance_splash = (a_Player->GetPosition() - m_HitPos).Length(); double distance_splash = (a_Entity->GetPosition() - m_HitPos).Length();
if (distance_splash < 20) if (distance_splash < 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.
@ -77,7 +76,11 @@ bool cSplashPotionEntity::cSplashPotionCallback::Item(cPlayer * a_Player)
if (reduction < 0) reduction = 0; if (reduction < 0) reduction = 0;
m_EntityEffect.SetDistanceModifier(reduction); m_EntityEffect.SetDistanceModifier(reduction);
a_Player->AddEntityEffect(m_EntityEffectType, m_EntityEffect);
if (a_Entity->IsMob() || a_Entity->IsPlayer())
{
((cPawn *) a_Entity)->AddEntityEffect(m_EntityEffectType, m_EntityEffect);
}
} }
return false; return false;
} }

View File

@ -7,6 +7,7 @@
#include "ProjectileEntity.h" #include "ProjectileEntity.h"
#include "EntityEffects.h" #include "EntityEffects.h"
#include "../World.h" #include "../World.h"
#include "Entity.h"
@ -42,12 +43,12 @@ protected:
int m_PotionName; int m_PotionName;
class cSplashPotionCallback : class cSplashPotionCallback :
public cPlayerListCallback public cEntityCallback
{ {
public: public:
cSplashPotionCallback(const Vector3d & a_HitPos, cEntityEffect::eType &a_EntityEffectType, cEntityEffect &a_EntityEffect); cSplashPotionCallback(const Vector3d & a_HitPos, cEntityEffect::eType &a_EntityEffectType, cEntityEffect &a_EntityEffect);
virtual bool Item(cPlayer * a_Player) override; virtual bool Item(cEntity *a_Entity) override;
private: private:
const Vector3d &m_HitPos; const Vector3d &m_HitPos;