1
0
Fork 0
cuberite-2a/src/Mobs/AggressiveMonster.cpp

97 lines
1.6 KiB
C++
Raw Normal View History

#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "AggressiveMonster.h"
#include "../World.h"
#include "../Entities/Player.h"
#include "../MersenneTwister.h"
2013-10-20 08:23:30 +00:00
cAggressiveMonster::cAggressiveMonster(const AString & a_ConfigName, eType a_MobType, const AString & a_SoundHurt, const AString & a_SoundDeath, double a_Width, double a_Height) :
super(a_ConfigName, a_MobType, a_SoundHurt, a_SoundDeath, a_Width, a_Height)
{
m_EMPersonality = AGGRESSIVE;
}
// What to do if in Chasing State
void cAggressiveMonster::InStateChasing(float a_Dt)
{
super::InStateChasing(a_Dt);
if (m_Target != NULL)
{
if (m_Target->IsPlayer())
{
if (((cPlayer *)m_Target)->IsGameModeCreative())
{
m_EMState = IDLE;
return;
}
}
if (((float)m_FinalDestination.x != (float)m_Target->GetPosX()) || ((float)m_FinalDestination.z != (float)m_Target->GetPosZ()))
{
MoveToPosition(m_Target->GetPosition());
}
}
}
void cAggressiveMonster::EventSeePlayer(cEntity * a_Entity)
{
if (!((cPlayer *)a_Entity)->IsGameModeCreative())
{
2014-01-25 19:00:50 +00:00
super::EventSeePlayer(a_Entity);
m_EMState = CHASING;
}
}
void cAggressiveMonster::Tick(float a_Dt, cChunk & a_Chunk)
{
super::Tick(a_Dt, a_Chunk);
if (m_EMState == CHASING)
{
CheckEventLostPlayer();
}
else
{
CheckEventSeePlayer();
}
}
void cAggressiveMonster::Attack(float a_Dt)
{
super::Attack(a_Dt);
if ((m_Target != NULL) && (m_AttackInterval > 3.0))
{
// Setting this higher gives us more wiggle room for attackrate
m_AttackInterval = 0.0;
m_Target->TakeDamage(dtMobAttack, this, m_AttackDamage, 0);
}
}