summaryrefslogtreecommitdiffstats
path: root/src/Mobs/AggressiveMonster.cpp
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2014-01-25 22:36:32 +0100
committerMattes D <github@xoft.cz>2014-01-25 22:36:32 +0100
commitcdcad2237a91dfd18cde539c300034f84bc8c07b (patch)
tree5f3266637858980f29ff3ee4cc4c116e575797d3 /src/Mobs/AggressiveMonster.cpp
parentMerge pull request #583 from mc-server/ChangeToPolarSSL (diff)
parentDid what xoft recommended (diff)
downloadcuberite-cdcad2237a91dfd18cde539c300034f84bc8c07b.tar
cuberite-cdcad2237a91dfd18cde539c300034f84bc8c07b.tar.gz
cuberite-cdcad2237a91dfd18cde539c300034f84bc8c07b.tar.bz2
cuberite-cdcad2237a91dfd18cde539c300034f84bc8c07b.tar.lz
cuberite-cdcad2237a91dfd18cde539c300034f84bc8c07b.tar.xz
cuberite-cdcad2237a91dfd18cde539c300034f84bc8c07b.tar.zst
cuberite-cdcad2237a91dfd18cde539c300034f84bc8c07b.zip
Diffstat (limited to 'src/Mobs/AggressiveMonster.cpp')
-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);
}
}
+
+