Cuberite
A lightweight, fast and extensible game server for Minecraft
Blaze.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 "Blaze.h"
5 #include "../World.h"
6 #include "../Entities/FireChargeEntity.h"
7 
8 
9 
10 
12  Super("Blaze", mtBlaze, "entity.blaze.hurt", "entity.blaze.death", "entity.blaze.ambient", 0.6f, 1.8f),
13  m_IsCharging(false),
14  m_ChargeTimer(0)
15 {
16  SetGravity(-8.0f);
17  SetAirDrag(0.05f);
18 }
19 
20 
21 
22 
23 
24 bool cBlaze::Attack(std::chrono::milliseconds a_Dt)
25 {
26  if ((GetTarget() != nullptr) && (m_AttackCoolDownTicksLeft == 0) && (!m_IsCharging))
27  {
28  m_IsCharging = true;
29  return true;
30  }
31  return false;
32 }
33 
34 
35 
36 
37 
38 void cBlaze::GetDrops(cItems & a_Drops, cEntity * a_Killer)
39 {
40  if ((a_Killer != nullptr) && (a_Killer->IsPlayer() || a_Killer->IsA("cWolf")))
41  {
42  unsigned int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting);
43  AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_BLAZE_ROD);
44  }
45 }
46 
47 
48 
49 
50 
51 void cBlaze::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
52 {
53  Super::Tick(a_Dt, a_Chunk);
54  if (!IsTicking())
55  {
56  // The base class tick destroyed us
57  return;
58  }
59 
60  if (m_IsCharging)
61  {
62  m_ChargeTimer++;
63  if (
64  (m_ChargeTimer == 5) ||
65  (m_ChargeTimer == 10) ||
66  (m_ChargeTimer == 15)
67  )
68  {
69  Vector3d Speed = GetLookVector() * 20;
70  Speed.y = Speed.y + 1;
71 
72  auto FireCharge = std::make_unique<cFireChargeEntity>(this, GetPosition().addedY(1), Speed);
73  auto FireChargePtr = FireCharge.get();
74  FireChargePtr->Initialize(std::move(FireCharge), *m_World);
75 
76  m_World->BroadcastSoundEffect("entity.blaze.shoot", GetPosition(), 4.0f, 1.0f);
77  }
78  }
79 
80  if ((m_IsCharging) && (m_ChargeTimer > 15))
81  {
82  m_ChargeTimer = 0;
83  m_IsCharging = false;
85  }
86 }
@ E_ITEM_BLAZE_ROD
Definition: BlockType.h:414
@ mtBlaze
Definition: MonsterTypes.h:15
@ FireCharge
Definition: Chunk.h:36
unsigned int GetLevel(int a_EnchantmentID) const
Returns the level for the specified enchantment; 0 if not stored.
Definition: Entity.h:76
bool IsPlayer(void) const
Definition: Entity.h:160
bool IsTicking(void) const
Returns true if the entity is valid and ticking.
Definition: Entity.cpp:2259
void SetGravity(float a_Gravity)
Definition: Entity.h:282
virtual bool IsA(const char *a_ClassName) const
Returns true if the entity is of the specified class or a subclass (cPawn's IsA("cEntity") returns tr...
Definition: Entity.cpp:2072
cWorld * m_World
Definition: Entity.h:624
void SetAirDrag(float a_AirDrag)
Definition: Entity.h:286
virtual cItem GetEquippedWeapon(void) const
Returns the curently equipped weapon; empty item if none.
Definition: Entity.h:333
const Vector3d & GetPosition(void) const
Exported in ManualBindings.
Definition: Entity.h:297
Vector3d GetLookVector(void) const
Definition: Entity.cpp:2267
cEnchantments m_Enchantments
Definition: Item.h:166
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 bool Attack(std::chrono::milliseconds a_Dt) override
Try to perform attack returns true if attack was deemed successful (hit player, fired projectile,...
Definition: Blaze.cpp:24
virtual void Tick(std::chrono::milliseconds a_Dt, cChunk &a_Chunk) override
Definition: Blaze.cpp:51
int m_ChargeTimer
Number of ticks since the blaze started charging.
Definition: Blaze.h:33
bool m_IsCharging
Specifies whether or not the blaze has started shooting fireballs.
Definition: Blaze.h:29
cBlaze()
Definition: Blaze.cpp:11
virtual void GetDrops(cItems &a_Drops, cEntity *a_Killer=nullptr) override
Returns the list of drops for this pawn when it is killed.
Definition: Blaze.cpp:38
void ResetAttackCooldown()
Definition: Monster.cpp:937
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
cPawn * GetTarget()
Returns the current target.
Definition: Monster.cpp:1243
int m_AttackCoolDownTicksLeft
Definition: Monster.h:313
T y
Definition: Vector3.h:17
virtual void BroadcastSoundEffect(const AString &a_SoundName, Vector3d a_Position, float a_Volume, float a_Pitch, const cClientHandle *a_Exclude=nullptr) override