2012-06-14 13:06:06 +00:00
|
|
|
|
|
|
|
|
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
|
|
|
|
|
2012-09-23 20:53:08 +00:00
|
|
|
#include "AggressiveMonster.h"
|
2012-06-14 13:06:06 +00:00
|
|
|
|
2013-08-16 10:48:19 +02:00
|
|
|
#include "../World.h"
|
2013-08-19 11:39:13 +02:00
|
|
|
#include "../Entities/Player.h"
|
2017-05-11 14:34:36 +02:00
|
|
|
#include "../LineBlockTracer.h"
|
2012-06-14 13:06:06 +00:00
|
|
|
|
|
|
|
|
|
2012-12-21 12:52:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-09-17 18:40:10 +01: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 19:57:32 +00:00
|
|
|
super(a_ConfigName, a_MobType, a_SoundHurt, a_SoundDeath, a_Width, a_Height)
|
2012-06-14 13:06:06 +00:00
|
|
|
{
|
|
|
|
|
m_EMPersonality = AGGRESSIVE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-12-21 12:52:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// What to do if in Chasing State
|
2015-12-22 07:43:50 +02:00
|
|
|
void cAggressiveMonster::InStateChasing(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
|
2012-12-21 12:52:14 +00:00
|
|
|
{
|
2015-12-22 07:43:50 +02:00
|
|
|
super::InStateChasing(a_Dt, a_Chunk);
|
2014-01-24 19:57:32 +00:00
|
|
|
|
2016-02-01 22:49:34 +02:00
|
|
|
if (GetTarget() != nullptr)
|
2012-06-14 13:06:06 +00:00
|
|
|
{
|
2016-02-01 22:49:34 +02:00
|
|
|
MoveToPosition(GetTarget()->GetPosition());
|
2012-12-21 12:52:14 +00:00
|
|
|
}
|
2014-07-17 22:50:58 +02:00
|
|
|
}
|
2012-06-14 13:06:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-12-21 12:52:14 +00:00
|
|
|
|
|
|
|
|
|
2016-10-12 14:38:45 +02:00
|
|
|
void cAggressiveMonster::EventSeePlayer(cPlayer * a_Player, cChunk & a_Chunk)
|
2012-06-14 13:06:06 +00:00
|
|
|
{
|
2016-10-12 14:38:45 +02:00
|
|
|
if (!a_Player->CanMobsTarget())
|
2014-01-24 19:57:32 +00:00
|
|
|
{
|
2016-10-12 14:38:45 +02:00
|
|
|
return;
|
2014-01-24 19:57:32 +00:00
|
|
|
}
|
2016-10-12 14:38:45 +02:00
|
|
|
|
|
|
|
|
super::EventSeePlayer(a_Player, a_Chunk);
|
|
|
|
|
m_EMState = CHASING;
|
2012-06-14 13:06:06 +00:00
|
|
|
}
|
|
|
|
|
|
2012-12-21 12:52:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-01-11 21:12:26 +00:00
|
|
|
void cAggressiveMonster::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
|
2012-06-14 13:06:06 +00:00
|
|
|
{
|
2013-04-13 21:02:10 +00:00
|
|
|
super::Tick(a_Dt, a_Chunk);
|
2016-09-03 14:31:27 +03:00
|
|
|
if (!IsTicking())
|
|
|
|
|
{
|
|
|
|
|
// The base class tick destroyed us
|
|
|
|
|
return;
|
|
|
|
|
}
|
2012-06-14 13:06:06 +00:00
|
|
|
|
2014-01-24 19:57:32 +00:00
|
|
|
if (m_EMState == CHASING)
|
|
|
|
|
{
|
|
|
|
|
CheckEventLostPlayer();
|
|
|
|
|
}
|
|
|
|
|
else
|
2012-06-14 13:06:06 +00:00
|
|
|
{
|
2016-01-17 16:09:25 +02:00
|
|
|
CheckEventSeePlayer(a_Chunk);
|
2014-01-24 19:57:32 +00:00
|
|
|
}
|
2014-02-11 22:09:56 +00:00
|
|
|
|
2017-05-11 14:34:36 +02:00
|
|
|
auto target = GetTarget();
|
|
|
|
|
if (target == nullptr)
|
2014-12-05 16:59:11 +01:00
|
|
|
{
|
2014-02-12 21:53:21 +00:00
|
|
|
return;
|
2014-12-05 16:59:11 +01:00
|
|
|
}
|
2014-02-12 21:53:21 +00:00
|
|
|
|
2017-05-11 14:34:36 +02:00
|
|
|
// TODO: Currently all mobs see through lava, but only Nether-native mobs should be able to.
|
2015-05-23 09:06:00 +03:00
|
|
|
Vector3d MyHeadPosition = GetPosition() + Vector3d(0, GetHeight(), 0);
|
2017-05-11 14:34:36 +02: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 22:09:56 +00: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 19:37:39 +01:00
|
|
|
Attack(a_Dt);
|
2014-02-11 22:09:56 +00:00
|
|
|
}
|
2014-01-24 19:57:32 +00:00
|
|
|
}
|
2012-06-14 13:06:06 +00:00
|
|
|
|
2014-01-24 19:57:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-11-08 13:44:17 +01:00
|
|
|
bool cAggressiveMonster::Attack(std::chrono::milliseconds a_Dt)
|
2014-01-24 19:57:32 +00:00
|
|
|
{
|
2016-02-01 22:49:34 +02:00
|
|
|
if ((GetTarget() == nullptr) || (m_AttackCoolDownTicksLeft != 0))
|
2014-01-24 19:57:32 +00:00
|
|
|
{
|
2015-11-08 13:44:17 +01:00
|
|
|
return false;
|
2012-06-14 13:06:06 +00:00
|
|
|
}
|
2015-04-29 19:24:14 +03:00
|
|
|
|
2014-06-11 16:21:47 -07:00
|
|
|
// Setting this higher gives us more wiggle room for attackrate
|
2016-01-12 12:11:10 +02:00
|
|
|
ResetAttackCooldown();
|
2020-03-19 19:13:41 +02:00
|
|
|
|
|
|
|
|
double KnockbackAmount = 9;
|
|
|
|
|
GetTarget()->TakeDamage(dtMobAttack, this, m_AttackDamage, KnockbackAmount);
|
2015-12-13 07:51:13 +02:00
|
|
|
|
2015-11-08 13:44:17 +01:00
|
|
|
return true;
|
2012-12-21 12:52:14 +00:00
|
|
|
}
|