2013-09-18 17:17:43 -04:00
|
|
|
|
|
|
|
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
|
|
|
|
|
|
|
#include "Wither.h"
|
2014-05-20 08:52:59 -04:00
|
|
|
|
2014-03-24 06:29:19 -04:00
|
|
|
#include "../World.h"
|
2014-05-20 08:52:59 -04:00
|
|
|
#include "../Entities/Player.h"
|
2021-03-05 10:08:30 -05:00
|
|
|
#include "../ClientHandle.h"
|
|
|
|
#include "../CompositeChat.h"
|
2013-09-18 17:17:43 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cWither::cWither(void) :
|
2021-04-06 11:09:16 -04:00
|
|
|
Super("Wither", mtWither, "entity.wither.hurt", "entity.wither.death", "entity.wither.ambient", 0.9f, 3.5f),
|
2014-04-28 07:51:40 -04:00
|
|
|
m_WitherInvulnerableTicks(220)
|
2013-09-18 17:17:43 -04:00
|
|
|
{
|
2014-03-24 06:29:19 -04:00
|
|
|
SetMaxHealth(300);
|
2016-12-19 15:12:23 -05:00
|
|
|
SetHealth(GetMaxHealth() / 3);
|
2014-03-24 06:29:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-03-25 04:32:58 -04:00
|
|
|
bool cWither::IsArmored(void) const
|
|
|
|
{
|
|
|
|
return GetHealth() <= (GetMaxHealth() / 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-04-25 18:32:30 -04:00
|
|
|
bool cWither::DoTakeDamage(TakeDamageInfo & a_TDI)
|
2014-03-24 06:29:19 -04:00
|
|
|
{
|
|
|
|
if (a_TDI.DamageType == dtDrowning)
|
|
|
|
{
|
2014-04-25 18:32:30 -04:00
|
|
|
return false;
|
2014-03-24 06:29:19 -04:00
|
|
|
}
|
|
|
|
|
2014-04-28 07:51:40 -04:00
|
|
|
if (m_WitherInvulnerableTicks > 0)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-03-25 04:32:58 -04:00
|
|
|
if (IsArmored() && (a_TDI.DamageType == dtRangedAttack))
|
|
|
|
{
|
2014-04-25 18:32:30 -04:00
|
|
|
return false;
|
2014-03-25 04:32:58 -04:00
|
|
|
}
|
|
|
|
|
2021-03-05 10:08:30 -05:00
|
|
|
if (!Super::DoTakeDamage(a_TDI))
|
2014-03-24 06:29:19 -04:00
|
|
|
{
|
2021-03-05 10:08:30 -05:00
|
|
|
return false;
|
2014-03-24 06:29:19 -04:00
|
|
|
}
|
2014-03-25 04:32:58 -04:00
|
|
|
|
2021-03-05 10:08:30 -05:00
|
|
|
m_World->BroadcastBossBarUpdateHealth(*this, GetUniqueID(), GetHealth() / GetMaxHealth());
|
|
|
|
return true;
|
2013-09-18 17:17:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cWither::GetDrops(cItems & a_Drops, cEntity * a_Killer)
|
|
|
|
{
|
|
|
|
AddRandomDropItem(a_Drops, 1, 1, E_ITEM_NETHER_STAR);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-05-20 08:52:59 -04:00
|
|
|
|
2014-07-04 05:55:09 -04:00
|
|
|
void cWither::KilledBy(TakeDamageInfo & a_TDI)
|
2014-05-20 08:52:59 -04:00
|
|
|
{
|
2020-04-13 12:38:06 -04:00
|
|
|
Super::KilledBy(a_TDI);
|
2014-05-20 08:52:59 -04:00
|
|
|
|
2017-09-11 17:20:49 -04:00
|
|
|
Vector3d Pos = GetPosition();
|
|
|
|
m_World->ForEachPlayer([=](cPlayer & a_Player)
|
2014-05-20 08:52:59 -04:00
|
|
|
{
|
2014-05-21 03:59:14 -04:00
|
|
|
// TODO 2014-05-21 xdot: Vanilla minecraft uses an AABB check instead of a radius one
|
2017-09-11 17:20:49 -04:00
|
|
|
double Dist = (a_Player.GetPosition() - Pos).Length();
|
2014-05-20 08:52:59 -04:00
|
|
|
if (Dist < 50.0)
|
|
|
|
{
|
|
|
|
// If player is close, award achievement
|
2021-05-03 16:07:09 -04:00
|
|
|
a_Player.AwardAchievement(CustomStatistic::AchKillWither);
|
2014-05-20 08:52:59 -04:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2017-09-11 17:20:49 -04:00
|
|
|
);
|
2014-05-20 08:52:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-03-05 10:08:30 -05:00
|
|
|
|
|
|
|
void cWither::SpawnOn(cClientHandle & a_Client)
|
|
|
|
{
|
|
|
|
Super::SpawnOn(a_Client);
|
|
|
|
|
|
|
|
// Purple boss bar with no divisions that darkens the sky:
|
|
|
|
a_Client.SendBossBarAdd(GetUniqueID(), cCompositeChat("Wither"), GetHealth() / GetMaxHealth(), BossBarColor::Purple, BossBarDivisionType::None, true, false, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cWither::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
|
|
|
|
{
|
|
|
|
Super::Tick(a_Dt, a_Chunk);
|
|
|
|
if (!IsTicking())
|
|
|
|
{
|
|
|
|
// The base class tick destroyed us
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_WitherInvulnerableTicks > 0)
|
|
|
|
{
|
|
|
|
unsigned int NewTicks = m_WitherInvulnerableTicks - 1;
|
|
|
|
|
|
|
|
if (NewTicks == 0)
|
|
|
|
{
|
|
|
|
m_World->DoExplosionAt(7.0, GetPosX(), GetPosY(), GetPosZ(), false, esWitherBirth, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_WitherInvulnerableTicks = NewTicks;
|
|
|
|
|
|
|
|
if ((NewTicks % 10) == 0)
|
|
|
|
{
|
|
|
|
Heal(10);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_World->BroadcastEntityMetadata(*this);
|
|
|
|
}
|