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"
|
2017-05-11 08:34:36 -04:00
|
|
|
#include "../LineBlockTracer.h"
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
2012-12-21 07:52:14 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
2020-03-22 11:50:34 -04:00
|
|
|
cAggressiveMonster::cAggressiveMonster(const AString & a_ConfigName, eMonsterType a_MobType, const AString & a_SoundHurt, const AString & a_SoundDeath, const AString & a_SoundAmbient, double a_Width, double a_Height) :
|
2020-04-13 12:38:06 -04:00
|
|
|
Super(a_ConfigName, a_MobType, a_SoundHurt, a_SoundDeath, a_SoundAmbient, 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
|
|
|
{
|
2020-04-13 12:38:06 -04: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-10-12 08:38:45 -04:00
|
|
|
void cAggressiveMonster::EventSeePlayer(cPlayer * a_Player, cChunk & a_Chunk)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2016-10-12 08:38:45 -04:00
|
|
|
if (!a_Player->CanMobsTarget())
|
2014-01-24 14:57:32 -05:00
|
|
|
{
|
2016-10-12 08:38:45 -04:00
|
|
|
return;
|
2014-01-24 14:57:32 -05:00
|
|
|
}
|
2016-10-12 08:38:45 -04:00
|
|
|
|
2020-04-13 12:38:06 -04:00
|
|
|
Super::EventSeePlayer(a_Player, a_Chunk);
|
2016-10-12 08:38:45 -04: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
|
|
|
{
|
2020-04-13 12:38:06 -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
|
|
|
|
2017-05-11 08:34:36 -04:00
|
|
|
auto target = GetTarget();
|
|
|
|
if (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
|
|
|
|
2017-05-11 08:34:36 -04:00
|
|
|
// TODO: Currently all mobs see through lava, but only Nether-native mobs should be able to.
|
2015-05-23 02:06:00 -04:00
|
|
|
Vector3d MyHeadPosition = GetPosition() + Vector3d(0, GetHeight(), 0);
|
2017-05-11 08:34:36 -04:00
|
|
|
Vector3d TargetPosition = target->GetPosition() + Vector3d(0, target->GetHeight(), 0);
|
|
|
|
if (
|
|
|
|
TargetIsInRange() &&
|
|
|
|
cLineBlockTracer::LineOfSightTrace(*GetWorld(), MyHeadPosition, TargetPosition, cLineBlockTracer::losAirWaterLava) &&
|
|
|
|
(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();
|
2020-03-19 13:13:41 -04:00
|
|
|
|
|
|
|
double KnockbackAmount = 9;
|
|
|
|
GetTarget()->TakeDamage(dtMobAttack, this, m_AttackDamage, KnockbackAmount);
|
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
|
|
|
}
|