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
|
|
|
|
2014-10-20 16:55:07 -04:00
|
|
|
if (m_Target != nullptr)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2015-04-29 12:24:14 -04:00
|
|
|
MoveToPosition(m_Target->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
|
|
|
|
|
|
|
|
2013-04-13 17:02:10 -04:00
|
|
|
void cAggressiveMonster::EventSeePlayer(cEntity * a_Entity)
|
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
|
|
|
{
|
2014-01-25 14:00:50 -05:00
|
|
|
super::EventSeePlayer(a_Entity);
|
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);
|
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
|
|
|
{
|
2014-01-24 14:57:32 -05:00
|
|
|
CheckEventSeePlayer();
|
|
|
|
}
|
2014-02-11 17:09:56 -05:00
|
|
|
|
2014-10-20 16:55:07 -04:00
|
|
|
if (m_Target == 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);
|
|
|
|
Vector3d AttackDirection(m_Target->GetPosition() + Vector3d(0, m_Target->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-05-28 10:45:47 -04:00
|
|
|
StopMovingToPosition();
|
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
|
|
|
{
|
2015-03-12 14:37:39 -04:00
|
|
|
m_AttackInterval += (static_cast<float>(a_Dt.count()) / 1000) * m_AttackRate;
|
2014-10-20 16:55:07 -04:00
|
|
|
if ((m_Target == nullptr) || (m_AttackInterval < 3.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
|
|
|
|
m_AttackInterval = 0.0;
|
|
|
|
m_Target->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
|
|
|
}
|