summaryrefslogtreecommitdiffstats
path: root/src/Mobs/AggressiveMonster.cpp
diff options
context:
space:
mode:
authorTycho <work.tycho+git@gmail.com>2014-01-26 15:28:51 +0100
committerTycho <work.tycho+git@gmail.com>2014-01-26 15:28:51 +0100
commitbed2ee22e8283a2e8bd0790a89124839319c2fc3 (patch)
treeee9e66a7b7c63995797a502f209079c1422ce9c9 /src/Mobs/AggressiveMonster.cpp
parentRefactored cBlockHandler::OnUse and dependents (diff)
parentMerge pull request #589 from mc-server/minecartimprovements (diff)
downloadcuberite-bed2ee22e8283a2e8bd0790a89124839319c2fc3.tar
cuberite-bed2ee22e8283a2e8bd0790a89124839319c2fc3.tar.gz
cuberite-bed2ee22e8283a2e8bd0790a89124839319c2fc3.tar.bz2
cuberite-bed2ee22e8283a2e8bd0790a89124839319c2fc3.tar.lz
cuberite-bed2ee22e8283a2e8bd0790a89124839319c2fc3.tar.xz
cuberite-bed2ee22e8283a2e8bd0790a89124839319c2fc3.tar.zst
cuberite-bed2ee22e8283a2e8bd0790a89124839319c2fc3.zip
Diffstat (limited to '')
-rw-r--r--src/Mobs/AggressiveMonster.cpp67
1 files changed, 33 insertions, 34 deletions
diff --git a/src/Mobs/AggressiveMonster.cpp b/src/Mobs/AggressiveMonster.cpp
index cc7e7da2b..f2f0c404c 100644
--- a/src/Mobs/AggressiveMonster.cpp
+++ b/src/Mobs/AggressiveMonster.cpp
@@ -4,7 +4,6 @@
#include "AggressiveMonster.h"
#include "../World.h"
-#include "../Vector3f.h"
#include "../Entities/Player.h"
#include "../MersenneTwister.h"
@@ -13,8 +12,7 @@
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_ChaseTime(999999)
+ super(a_ConfigName, a_MobType, a_SoundHurt, a_SoundDeath, a_Width, a_Height)
{
m_EMPersonality = AGGRESSIVE;
}
@@ -27,32 +25,23 @@ cAggressiveMonster::cAggressiveMonster(const AString & a_ConfigName, eType a_Mob
void cAggressiveMonster::InStateChasing(float a_Dt)
{
super::InStateChasing(a_Dt);
- m_ChaseTime += a_Dt;
+
if (m_Target != NULL)
{
if (m_Target->IsPlayer())
{
- cPlayer * Player = (cPlayer *) m_Target;
- if (Player->IsGameModeCreative())
+ if (((cPlayer *)m_Target)->IsGameModeCreative())
{
m_EMState = IDLE;
return;
}
}
- Vector3f Pos = Vector3f( GetPosition() );
- Vector3f Their = Vector3f( m_Target->GetPosition() );
- if ((Their - Pos).Length() <= m_AttackRange)
+ if (((float)m_FinalDestination.x != (float)m_Target->GetPosX()) || ((float)m_FinalDestination.z != (float)m_Target->GetPosZ()))
{
- Attack(a_Dt);
+ MoveToPosition(m_Target->GetPosition());
}
- MoveToPosition(Their + Vector3f(0, 0.65f, 0));
}
- else if (m_ChaseTime > 5.f)
- {
- m_ChaseTime = 0;
- m_EMState = IDLE;
- }
}
@@ -61,8 +50,11 @@ void cAggressiveMonster::InStateChasing(float a_Dt)
void cAggressiveMonster::EventSeePlayer(cEntity * a_Entity)
{
- super::EventSeePlayer(a_Entity);
- m_EMState = CHASING;
+ if (!((cPlayer *)a_Entity)->IsGameModeCreative())
+ {
+ super::EventSeePlayer(a_Entity);
+ m_EMState = CHASING;
+ }
}
@@ -73,25 +65,32 @@ void cAggressiveMonster::Tick(float a_Dt, cChunk & a_Chunk)
{
super::Tick(a_Dt, a_Chunk);
- m_SeePlayerInterval += a_Dt;
-
- if (m_SeePlayerInterval > 1)
+ if (m_EMState == CHASING)
+ {
+ CheckEventLostPlayer();
+ }
+ else
{
- int rem = m_World->GetTickRandomNumber(3) + 1; // Check most of the time but miss occasionally
+ CheckEventSeePlayer();
+ }
+}
- m_SeePlayerInterval = 0.0;
- if (rem >= 2)
- {
- 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);
}
}
+
+