1
0
Fork 0
cuberite-2a/src/Mobs/AggressiveMonster.cpp

104 lines
2.1 KiB
C++
Raw Permalink Normal View History

#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "AggressiveMonster.h"
#include "../World.h"
#include "../Entities/Player.h"
#include "../LineBlockTracer.h"
2021-04-06 15:09:16 +00:00
cAggressiveMonster::cAggressiveMonster(const AString & a_ConfigName, eMonsterType a_MobType, const AString & a_SoundHurt, const AString & a_SoundDeath, const AString & a_SoundAmbient, float a_Width, float a_Height) :
2020-04-13 16:38:06 +00:00
Super(a_ConfigName, a_MobType, a_SoundHurt, a_SoundDeath, a_SoundAmbient, a_Width, a_Height)
{
m_EMPersonality = AGGRESSIVE;
}
// What to do if in Chasing State
2015-12-22 05:43:50 +00:00
void cAggressiveMonster::InStateChasing(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
{
2020-04-13 16:38:06 +00:00
Super::InStateChasing(a_Dt, a_Chunk);
if (GetTarget() != nullptr)
{
MoveToPosition(GetTarget()->GetPosition());
}
2014-07-17 20:50:58 +00:00
}
2016-10-12 12:38:45 +00:00
void cAggressiveMonster::EventSeePlayer(cPlayer * a_Player, cChunk & a_Chunk)
{
2020-04-13 16:38:06 +00:00
Super::EventSeePlayer(a_Player, a_Chunk);
2016-10-12 12:38:45 +00:00
m_EMState = CHASING;
}
void cAggressiveMonster::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
{
2020-04-13 16:38:06 +00:00
Super::Tick(a_Dt, a_Chunk);
if (!IsTicking())
{
// The base class tick destroyed us
return;
}
// Set or clear m_Target depending on rules for this Monster:
if (m_EMState == CHASING)
{
CheckEventLostPlayer(a_Dt);
}
else
{
CheckEventSeePlayer(a_Chunk);
}
if (
(GetTarget() != nullptr) &&
TargetIsInRange() &&
cLineBlockTracer::LineOfSightTrace(
*GetWorld(),
GetPosition().addedY(GetHeight()),
GetTarget()->GetPosition().addedY(GetTarget()->GetHeight()),
(IsNetherNative() ? cLineBlockTracer::losAirWaterLava : cLineBlockTracer::losAirWater)
) &&
(GetHealth() > 0.0)
)
{
// Attack if reached destination, target isn't null, and have a clear line of sight to target (so won't attack through walls)
Attack(a_Dt);
}
}
fix cavespider poisoning even if attack is in cooldown make attack function more responsive fix cavespider poisoning even if attack is in cooldown make attack function more responsive Merge branch 'cavespider-attack' of github.com:Gargaj/cuberite into cavespider-attack code style fix cavespider poisoning even if attack is in cooldown make attack function more responsive fix cavespider poisoning even if attack is in cooldown make attack function more responsive Merge branch 'cavespider-attack' of github.com:Gargaj/cuberite into cavespider-attack code style Merge branch 'cavespider-attack' of github.com:Gargaj/cuberite into cavespider-attack Merge branch 'master' into cavespider-attack Merge branch 'master' into cavespider-attack fix cavespider poisoning even if attack is in cooldown make attack function more responsive fix cavespider poisoning even if attack is in cooldown make attack function more responsive Merge branch 'cavespider-attack' of github.com:Gargaj/cuberite into cavespider-attack code style fix cavespider poisoning even if attack is in cooldown make attack function more responsive fix cavespider poisoning even if attack is in cooldown make attack function more responsive Merge branch 'cavespider-attack' of github.com:Gargaj/cuberite into cavespider-attack code style Merge branch 'cavespider-attack' of github.com:Gargaj/cuberite into cavespider-attack Merge branch 'master' into cavespider-attack Merge branch 'master' into cavespider-attack Merge branch 'cavespider-attack' of github.com:Gargaj/cuberite into cavespider-attack
2015-11-08 12:44:17 +00:00
bool cAggressiveMonster::Attack(std::chrono::milliseconds a_Dt)
{
if ((GetTarget() == nullptr) || (m_AttackCoolDownTicksLeft != 0))
{
fix cavespider poisoning even if attack is in cooldown make attack function more responsive fix cavespider poisoning even if attack is in cooldown make attack function more responsive Merge branch 'cavespider-attack' of github.com:Gargaj/cuberite into cavespider-attack code style fix cavespider poisoning even if attack is in cooldown make attack function more responsive fix cavespider poisoning even if attack is in cooldown make attack function more responsive Merge branch 'cavespider-attack' of github.com:Gargaj/cuberite into cavespider-attack code style Merge branch 'cavespider-attack' of github.com:Gargaj/cuberite into cavespider-attack Merge branch 'master' into cavespider-attack Merge branch 'master' into cavespider-attack fix cavespider poisoning even if attack is in cooldown make attack function more responsive fix cavespider poisoning even if attack is in cooldown make attack function more responsive Merge branch 'cavespider-attack' of github.com:Gargaj/cuberite into cavespider-attack code style fix cavespider poisoning even if attack is in cooldown make attack function more responsive fix cavespider poisoning even if attack is in cooldown make attack function more responsive Merge branch 'cavespider-attack' of github.com:Gargaj/cuberite into cavespider-attack code style Merge branch 'cavespider-attack' of github.com:Gargaj/cuberite into cavespider-attack Merge branch 'master' into cavespider-attack Merge branch 'master' into cavespider-attack Merge branch 'cavespider-attack' of github.com:Gargaj/cuberite into cavespider-attack
2015-11-08 12:44:17 +00:00
return false;
}
2015-04-29 16:24:14 +00:00
// Setting this higher gives us more wiggle room for attackrate
2016-01-12 10:11:10 +00:00
ResetAttackCooldown();
double KnockbackAmount = 9;
GetTarget()->TakeDamage(dtMobAttack, this, m_AttackDamage, KnockbackAmount);
fix cavespider poisoning even if attack is in cooldown make attack function more responsive fix cavespider poisoning even if attack is in cooldown make attack function more responsive Merge branch 'cavespider-attack' of github.com:Gargaj/cuberite into cavespider-attack code style fix cavespider poisoning even if attack is in cooldown make attack function more responsive fix cavespider poisoning even if attack is in cooldown make attack function more responsive Merge branch 'cavespider-attack' of github.com:Gargaj/cuberite into cavespider-attack code style Merge branch 'cavespider-attack' of github.com:Gargaj/cuberite into cavespider-attack Merge branch 'master' into cavespider-attack Merge branch 'master' into cavespider-attack fix cavespider poisoning even if attack is in cooldown make attack function more responsive fix cavespider poisoning even if attack is in cooldown make attack function more responsive Merge branch 'cavespider-attack' of github.com:Gargaj/cuberite into cavespider-attack code style fix cavespider poisoning even if attack is in cooldown make attack function more responsive fix cavespider poisoning even if attack is in cooldown make attack function more responsive Merge branch 'cavespider-attack' of github.com:Gargaj/cuberite into cavespider-attack code style Merge branch 'cavespider-attack' of github.com:Gargaj/cuberite into cavespider-attack Merge branch 'master' into cavespider-attack Merge branch 'master' into cavespider-attack Merge branch 'cavespider-attack' of github.com:Gargaj/cuberite into cavespider-attack
2015-11-08 12:44:17 +00:00
return true;
}