2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
|
|
|
|
2012-09-23 16:53:08 -04:00
|
|
|
#include "AggressiveMonster.h"
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-08-16 04:48:19 -04:00
|
|
|
#include "../World.h"
|
2013-08-19 05:39:13 -04:00
|
|
|
#include "../Entities/Player.h"
|
2014-02-11 17:09:56 -05:00
|
|
|
#include "../Tracer.h"
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
2012-12-21 07:52:14 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
2014-09-17 13:40:10 -04:00
|
|
|
cAggressiveMonster::cAggressiveMonster(const AString & a_ConfigName, eMonsterType a_MobType, const AString & a_SoundHurt, const AString & a_SoundDeath, double a_Width, double a_Height) :
|
2014-01-24 14:57:32 -05:00
|
|
|
super(a_ConfigName, a_MobType, a_SoundHurt, a_SoundDeath, a_Width, a_Height)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
m_EMPersonality = AGGRESSIVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-12-21 07:52:14 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// What to do if in Chasing State
|
2015-12-22 00:43:50 -05:00
|
|
|
void cAggressiveMonster::InStateChasing(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
|
2012-12-21 07:52:14 -05:00
|
|
|
{
|
2015-12-22 00:43:50 -05:00
|
|
|
super::InStateChasing(a_Dt, a_Chunk);
|
2014-01-24 14:57:32 -05:00
|
|
|
|
2016-02-01 15:49:34 -05:00
|
|
|
if (GetTarget() != nullptr)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2016-02-01 15:49:34 -05:00
|
|
|
MoveToPosition(GetTarget()->GetPosition());
|
2012-12-21 07:52:14 -05:00
|
|
|
}
|
2014-07-17 16:50:58 -04:00
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
2012-12-21 07:52:14 -05:00
|
|
|
|
|
|
|
|
2016-01-17 09:09:25 -05:00
|
|
|
void cAggressiveMonster::EventSeePlayer(cEntity * a_Entity, cChunk & a_Chunk)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2015-05-24 07:56:56 -04:00
|
|
|
if (!static_cast<cPlayer *>(a_Entity)->IsGameModeCreative())
|
2014-01-24 14:57:32 -05:00
|
|
|
{
|
2016-01-17 09:09:25 -05:00
|
|
|
super::EventSeePlayer(a_Entity, a_Chunk);
|
2014-01-24 14:57:32 -05:00
|
|
|
m_EMState = CHASING;
|
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
2012-12-21 07:52:14 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-01-11 16:12:26 -05:00
|
|
|
void cAggressiveMonster::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-04-13 17:02:10 -04:00
|
|
|
super::Tick(a_Dt, a_Chunk);
|
2016-09-03 07:31:27 -04:00
|
|
|
if (!IsTicking())
|
|
|
|
{
|
|
|
|
// The base class tick destroyed us
|
|
|
|
return;
|
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2014-01-24 14:57:32 -05:00
|
|
|
if (m_EMState == CHASING)
|
|
|
|
{
|
|
|
|
CheckEventLostPlayer();
|
|
|
|
}
|
|
|
|
else
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2016-01-17 09:09:25 -05:00
|
|
|
CheckEventSeePlayer(a_Chunk);
|
2014-01-24 14:57:32 -05:00
|
|
|
}
|
2014-02-11 17:09:56 -05:00
|
|
|
|
2016-02-01 15:49:34 -05:00
|
|
|
if (GetTarget() == nullptr)
|
2014-12-05 10:59:11 -05:00
|
|
|
{
|
2014-02-12 16:53:21 -05:00
|
|
|
return;
|
2014-12-05 10:59:11 -05:00
|
|
|
}
|
2014-02-12 16:53:21 -05:00
|
|
|
|
2014-02-11 17:09:56 -05:00
|
|
|
cTracer LineOfSight(GetWorld());
|
2015-05-23 02:06:00 -04:00
|
|
|
Vector3d MyHeadPosition = GetPosition() + Vector3d(0, GetHeight(), 0);
|
2016-02-01 15:49:34 -05:00
|
|
|
Vector3d AttackDirection(GetTarget()->GetPosition() + Vector3d(0, GetTarget()->GetHeight(), 0) - MyHeadPosition);
|
2014-02-12 16:53:21 -05:00
|
|
|
|
2015-05-23 02:06:00 -04:00
|
|
|
|
2015-11-07 07:48:00 -05:00
|
|
|
if (TargetIsInRange() && !LineOfSight.Trace(MyHeadPosition, AttackDirection, static_cast<int>(AttackDirection.Length())) && (GetHealth() > 0.0))
|
2014-02-11 17:09:56 -05:00
|
|
|
{
|
|
|
|
// Attack if reached destination, target isn't null, and have a clear line of sight to target (so won't attack through walls)
|
2015-03-12 14:37:39 -04:00
|
|
|
Attack(a_Dt);
|
2014-02-11 17:09:56 -05:00
|
|
|
}
|
2014-01-24 14:57:32 -05:00
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2014-01-24 14:57:32 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-11-08 07:44:17 -05:00
|
|
|
bool cAggressiveMonster::Attack(std::chrono::milliseconds a_Dt)
|
2014-01-24 14:57:32 -05:00
|
|
|
{
|
2016-02-01 15:49:34 -05:00
|
|
|
if ((GetTarget() == nullptr) || (m_AttackCoolDownTicksLeft != 0))
|
2014-01-24 14:57:32 -05:00
|
|
|
{
|
2015-11-08 07:44:17 -05:00
|
|
|
return false;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
2015-04-29 12:24:14 -04:00
|
|
|
|
2014-06-11 19:21:47 -04:00
|
|
|
// Setting this higher gives us more wiggle room for attackrate
|
2016-01-12 05:11:10 -05:00
|
|
|
ResetAttackCooldown();
|
2016-02-01 15:49:34 -05:00
|
|
|
GetTarget()->TakeDamage(dtMobAttack, this, m_AttackDamage, 0);
|
2015-12-13 00:51:13 -05:00
|
|
|
|
2015-11-08 07:44:17 -05:00
|
|
|
return true;
|
2012-12-21 07:52:14 -05:00
|
|
|
}
|