Cuberite
A lightweight, fast and extensible game server for Minecraft
Wither.cpp
Go to the documentation of this file.
1 
2 #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
3 
4 #include "Wither.h"
5 
6 #include "../World.h"
7 #include "../Entities/Player.h"
8 
9 
10 
11 
12 
14  super("Wither", mtWither, "entity.wither.hurt", "entity.wither.death", 0.9, 4.0),
15  m_WitherInvulnerableTicks(220)
16 {
17  SetMaxHealth(300);
18  SetHealth(GetMaxHealth() / 3);
19 }
20 
21 
22 
23 
24 
25 bool cWither::IsArmored(void) const
26 {
27  return GetHealth() <= (GetMaxHealth() / 2);
28 }
29 
30 
31 
32 
33 
35 {
36  if (a_TDI.DamageType == dtDrowning)
37  {
38  return false;
39  }
40 
42  {
43  return false;
44  }
45 
46  if (IsArmored() && (a_TDI.DamageType == dtRangedAttack))
47  {
48  return false;
49  }
50 
51  return super::DoTakeDamage(a_TDI);
52 }
53 
54 
55 
56 
57 
58 void cWither::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
59 {
60  super::Tick(a_Dt, a_Chunk);
61  if (!IsTicking())
62  {
63  // The base class tick destroyed us
64  return;
65  }
66 
68  {
69  unsigned int NewTicks = m_WitherInvulnerableTicks - 1;
70 
71  if (NewTicks == 0)
72  {
73  m_World->DoExplosionAt(7.0, GetPosX(), GetPosY(), GetPosZ(), false, esWitherBirth, this);
74  }
75 
76  m_WitherInvulnerableTicks = NewTicks;
77 
78  if ((NewTicks % 10) == 0)
79  {
80  Heal(10);
81  }
82  }
83 
85 }
86 
87 
88 
89 
90 
91 void cWither::GetDrops(cItems & a_Drops, cEntity * a_Killer)
92 {
93  AddRandomDropItem(a_Drops, 1, 1, E_ITEM_NETHER_STAR);
94 }
95 
96 
97 
98 
99 
101 {
102  super::KilledBy(a_TDI);
103 
104  Vector3d Pos = GetPosition();
105  m_World->ForEachPlayer([=](cPlayer & a_Player)
106  {
107  // TODO 2014-05-21 xdot: Vanilla minecraft uses an AABB check instead of a radius one
108  double Dist = (a_Player.GetPosition() - Pos).Length();
109  if (Dist < 50.0)
110  {
111  // If player is close, award achievement
113  }
114  return false;
115  }
116  );
117 }
118 
119 
120 
121 
virtual void Tick(std::chrono::milliseconds a_Dt, cChunk &a_Chunk) override
Definition: Wither.cpp:58
double GetPosY(void) const
Definition: Entity.h:207
double GetPosX(void) const
Definition: Entity.h:206
unsigned int AwardAchievement(const eStatistic a_Ach)
Awards the player an achievement.
Definition: Player.cpp:1605
virtual void Tick(std::chrono::milliseconds a_Dt, cChunk &a_Chunk) override
virtual void BroadcastEntityMetadata(const cEntity &a_Entity, const cClientHandle *a_Exclude=nullptr) override
cWorld * m_World
Definition: Entity.h:620
Definition: Player.h:27
bool IsArmored(void) const
Returns whether the wither is invulnerable to arrows.
Definition: Wither.cpp:25
void AddRandomDropItem(cItems &a_Drops, unsigned int a_Min, unsigned int a_Max, short a_Item, short a_ItemHealth=0)
Adds a random number of a_Item between a_Min and a_Max to itemdrops a_Drops.
Definition: Monster.cpp:1215
eDamageType DamageType
Definition: Entity.h:59
virtual void KilledBy(TakeDamageInfo &a_TDI) override
Called when the health drops below zero.
Definition: Monster.cpp:593
Definition: Chunk.h:49
void SetMaxHealth(float a_MaxHealth)
Sets the maximum value for the health.
Definition: Entity.cpp:1798
virtual bool DoTakeDamage(TakeDamageInfo &a_TDI) override
Makes this entity take damage specified in the a_TDI.
Definition: Wither.cpp:34
bool IsTicking(void) const
Returns true if the entity is valid and ticking.
Definition: Entity.cpp:2201
virtual bool DoTakeDamage(TakeDamageInfo &a_TDI) override
Makes this entity take damage specified in the a_TDI.
Definition: Monster.cpp:563
virtual void GetDrops(cItems &a_Drops, cEntity *a_Killer=nullptr) override
Returns the list of drops for this pawn when it is killed.
Definition: Wither.cpp:91
float GetHealth(void) const
Returns the health of this entity.
Definition: Entity.h:380
float GetMaxHealth(void) const
Definition: Entity.h:417
virtual void Heal(int a_HitPoints)
Heals the specified amount of HPs.
Definition: Entity.cpp:822
virtual void KilledBy(TakeDamageInfo &a_TDI) override
Called when the health drops below zero.
Definition: Wither.cpp:100
virtual void DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_BlockY, double a_BlockZ, bool a_CanCauseFire, eExplosionSource a_Source, void *a_SourceData) override
Does an explosion with the specified strength at the specified coordinates.
Definition: World.cpp:1399
Definition: Entity.h:73
const Vector3d & GetPosition(void) const
Exported in ManualBindings.
Definition: Entity.h:307
unsigned int m_WitherInvulnerableTicks
The number of ticks of invulnerability left after being initially created.
Definition: Wither.h:38
double GetPosZ(void) const
Definition: Entity.h:208
void SetHealth(float a_Health)
Sets the health of this entity; doesn&#39;t broadcast any hurt animation.
Definition: Entity.cpp:832
This class bridges a vector of cItem for safe access via Lua.
Definition: Item.h:234
cWither(void)
Definition: Wither.cpp:13
virtual bool ForEachPlayer(cPlayerListCallback a_Callback) override
Calls the callback for each player in the list; returns true if all players processed, false if the callback aborted by returning true.
Definition: World.cpp:2549