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 #include "../ClientHandle.h"
9 #include "../CompositeChat.h"
10 
11 
12 
13 
14 
16  Super("Wither", mtWither, "entity.wither.hurt", "entity.wither.death", "entity.wither.ambient", 0.9f, 3.5f),
17  m_WitherInvulnerableTicks(220)
18 {
19  SetMaxHealth(300);
20  SetHealth(GetMaxHealth() / 3);
21 }
22 
23 
24 
25 
26 
27 bool cWither::IsArmored(void) const
28 {
29  return GetHealth() <= (GetMaxHealth() / 2);
30 }
31 
32 
33 
34 
35 
37 {
38  if (a_TDI.DamageType == dtDrowning)
39  {
40  return false;
41  }
42 
44  {
45  return false;
46  }
47 
48  if (IsArmored() && (a_TDI.DamageType == dtRangedAttack))
49  {
50  return false;
51  }
52 
53  if (!Super::DoTakeDamage(a_TDI))
54  {
55  return false;
56  }
57 
59  return true;
60 }
61 
62 
63 
64 
65 
66 void cWither::GetDrops(cItems & a_Drops, cEntity * a_Killer)
67 {
68  AddRandomDropItem(a_Drops, 1, 1, E_ITEM_NETHER_STAR);
69 }
70 
71 
72 
73 
74 
76 {
77  Super::KilledBy(a_TDI);
78 
79  Vector3d Pos = GetPosition();
80  m_World->ForEachPlayer([=](cPlayer & a_Player)
81  {
82  // TODO 2014-05-21 xdot: Vanilla minecraft uses an AABB check instead of a radius one
83  double Dist = (a_Player.GetPosition() - Pos).Length();
84  if (Dist < 50.0)
85  {
86  // If player is close, award achievement
88  }
89  return false;
90  }
91  );
92 }
93 
94 
95 
96 
97 
99 {
100  Super::SpawnOn(a_Client);
101 
102  // Purple boss bar with no divisions that darkens the sky:
104 }
105 
106 
107 
108 
109 
110 void cWither::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
111 {
112  Super::Tick(a_Dt, a_Chunk);
113  if (!IsTicking())
114  {
115  // The base class tick destroyed us
116  return;
117  }
118 
120  {
121  unsigned int NewTicks = m_WitherInvulnerableTicks - 1;
122 
123  if (NewTicks == 0)
124  {
125  m_World->DoExplosionAt(7.0, GetPosX(), GetPosY(), GetPosZ(), false, esWitherBirth, this);
126  }
127 
128  m_WitherInvulnerableTicks = NewTicks;
129 
130  if ((NewTicks % 10) == 0)
131  {
132  Heal(10);
133  }
134  }
135 
137 }
@ E_ITEM_NETHER_STAR
Definition: BlockType.h:445
@ esWitherBirth
Definition: Defines.h:318
@ dtDrowning
Definition: Defines.h:250
@ dtRangedAttack
Definition: Defines.h:247
@ mtWither
Definition: MonsterTypes.h:75
Definition: Chunk.h:36
void SendBossBarAdd(UInt32 a_UniqueID, const cCompositeChat &a_Title, float a_FractionFilled, BossBarColor a_Color, BossBarDivisionType a_DivisionType, bool a_DarkenSky, bool a_PlayEndMusic, bool a_CreateFog)
Container for a single chat message composed of multiple functional parts.
Definition: CompositeChat.h:34
eDamageType DamageType
Definition: Entity.h:61
Definition: Entity.h:76
float GetMaxHealth(void) const
Definition: Entity.h:407
void SetHealth(float a_Health)
Sets the health of this entity; doesn't broadcast any hurt animation.
Definition: Entity.cpp:900
bool IsTicking(void) const
Returns true if the entity is valid and ticking.
Definition: Entity.cpp:2259
double GetPosX(void) const
Definition: Entity.h:195
cWorld * m_World
Definition: Entity.h:624
double GetPosZ(void) const
Definition: Entity.h:197
UInt32 GetUniqueID(void) const
Definition: Entity.h:253
double GetPosY(void) const
Definition: Entity.h:196
float GetHealth(void) const
Returns the health of this entity.
Definition: Entity.h:367
void SetMaxHealth(float a_MaxHealth)
Sets the maximum value for the health.
Definition: Entity.cpp:1887
const Vector3d & GetPosition(void) const
Exported in ManualBindings.
Definition: Entity.h:297
virtual void Heal(int a_HitPoints)
Heals the specified amount of HPs.
Definition: Entity.cpp:890
Definition: Player.h:29
void AwardAchievement(CustomStatistic a_Ach)
Awards the player an achievement.
Definition: Player.cpp:1372
This class bridges a vector of cItem for safe access via Lua.
Definition: Item.h:215
virtual void Tick(std::chrono::milliseconds a_Dt, cChunk &a_Chunk) override
virtual void SpawnOn(cClientHandle &a_ClientHandle) override
Descendants override this function to send a command to the specified client to spawn the entity on t...
Definition: Monster.cpp:167
virtual void KilledBy(TakeDamageInfo &a_TDI) override
Called when the health drops below zero.
Definition: Monster.cpp:602
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:1518
virtual bool DoTakeDamage(TakeDamageInfo &a_TDI) override
Makes this entity take damage specified in the a_TDI.
Definition: Monster.cpp:572
virtual void Tick(std::chrono::milliseconds a_Dt, cChunk &a_Chunk) override
Definition: Wither.cpp:110
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:66
virtual void SpawnOn(cClientHandle &a_Client) override
Descendants override this function to send a command to the specified client to spawn the entity on t...
Definition: Wither.cpp:98
virtual bool DoTakeDamage(TakeDamageInfo &a_TDI) override
Makes this entity take damage specified in the a_TDI.
Definition: Wither.cpp:36
cWither()
Definition: Wither.cpp:15
unsigned int m_WitherInvulnerableTicks
The number of ticks of invulnerability left after being initially created.
Definition: Wither.h:39
bool IsArmored(void) const
Returns whether the wither is invulnerable to arrows.
Definition: Wither.cpp:27
virtual void KilledBy(TakeDamageInfo &a_TDI) override
Called when the health drops below zero.
Definition: Wither.cpp:75
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:1384
virtual void BroadcastEntityMetadata(const cEntity &a_Entity, const cClientHandle *a_Exclude=nullptr) override
virtual void BroadcastBossBarUpdateHealth(const cEntity &a_Entity, UInt32 a_UniqueID, float a_FractionFilled) override
virtual bool ForEachPlayer(cPlayerListCallback a_Callback) override
Calls the callback for each player in the list; returns true if all players processed,...
Definition: World.cpp:2266