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", 0.6, 1.8)
13 {
14  SetGravity(-8.0f);
15  SetAirDrag(0.05f);
16 }
17 
18 
19 
20 
21 
22 void cBlaze::GetDrops(cItems & a_Drops, cEntity * a_Killer)
23 {
24  if ((a_Killer != nullptr) && (a_Killer->IsPlayer() || a_Killer->IsA("cWolf")))
25  {
26  unsigned int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting);
27  AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_BLAZE_ROD);
28  }
29 }
30 
31 
32 
33 
34 
35 bool cBlaze::Attack(std::chrono::milliseconds a_Dt)
36 {
37  if ((GetTarget() != nullptr) && (m_AttackCoolDownTicksLeft == 0))
38  {
39  // Setting this higher gives us more wiggle room for attackrate
40  Vector3d Speed = GetLookVector() * 20;
41  Speed.y = Speed.y + 1;
42 
43  auto FireCharge = cpp14::make_unique<cFireChargeEntity>(this, GetPosition().addedY(1), Speed);
44  auto FireChargePtr = FireCharge.get();
45  if (!FireChargePtr->Initialize(std::move(FireCharge), *m_World))
46  {
47  return false;
48  }
49 
51  // ToDo: Shoot 3 fireballs instead of 1.
52 
53  return true;
54  }
55  return false;
56 }
cWorld * m_World
Definition: Entity.h:620
cPawn * GetTarget()
Returns the current target.
Definition: Monster.cpp:1120
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
unsigned int GetLevel(int a_EnchantmentID) const
Returns the level for the specified enchantment; 0 if not stored.
T y
Definition: Vector3.h:17
Vector3< T > addedY(T a_AddY) const
Returns a copy of this vector moved by the specified amount on the y axis.
Definition: Vector3.h:299
cEnchantments m_Enchantments
Definition: Item.h:212
Vector3d GetLookVector(void) const
Definition: Entity.cpp:2209
virtual bool IsA(const char *a_ClassName) const
Returns true if the entity is of the specified class or a subclass (cPawn&#39;s IsA("cEntity") returns tr...
Definition: Entity.cpp:2005
int m_AttackCoolDownTicksLeft
Definition: Monster.h:274
void SetGravity(float a_Gravity)
Definition: Entity.h:288
bool IsPlayer(void) const
Definition: Entity.h:171
void ResetAttackCooldown()
Definition: Monster.cpp:853
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:35
virtual cItem GetEquippedWeapon(void) const
Returns the curently equipped weapon; empty item if none.
Definition: Entity.h:346
Definition: Entity.h:73
const Vector3d & GetPosition(void) const
Exported in ManualBindings.
Definition: Entity.h:307
void SetAirDrag(float a_AirDrag)
Definition: Entity.h:292
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:22
This class bridges a vector of cItem for safe access via Lua.
Definition: Item.h:234
cBlaze(void)
Definition: Blaze.cpp:11