Cuberite
A lightweight, fast and extensible game server for Minecraft
Spider.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 "Spider.h"
5 
6 #include "../World.h"
7 #include "../Entities/Player.h"
8 #include "../Chunk.h"
9 
10 
12  Super("Spider", mtSpider, "entity.spider.hurt", "entity.spider.death", "entity.spider.ambient", 1.4f, 0.9f)
13 {
14 }
15 
16 
17 
18 
19 
20 void cSpider::GetDrops(cItems & a_Drops, cEntity * a_Killer)
21 {
22  unsigned int LootingLevel = 0;
23  if (a_Killer != nullptr)
24  {
26  }
27  AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_STRING);
28  if ((a_Killer != nullptr) && (a_Killer->IsPlayer() || a_Killer->IsA("cWolf")))
29  {
31  }
32 }
33 
34 
35 
36 
37 
38 void cSpider::EventSeePlayer(cPlayer * a_Player, cChunk & a_Chunk)
39 {
40  if (!GetWorld()->IsChunkLighted(GetChunkX(), GetChunkZ()))
41  {
42  return;
43  }
44 
46  if (!RelSuccess)
47  {
48  return;
49  }
50 
51  if ((Chunk->GetSkyLightAltered(Rel.x, Rel.y, Rel.z) <= 11) && (Chunk->GetBlockLight(Rel.x, Rel.y, Rel.z) <= 11))
52  {
53  Super::EventSeePlayer(a_Player, a_Chunk);
54  }
55 }
56 
57 
58 
59 
60 
62 {
63  if (!Super::DoTakeDamage(a_TDI))
64  {
65  return false;
66  }
67 
68  // If the source of the damage is not from an pawn entity, switch to idle
69  if ((a_TDI.Attacker == nullptr) || !a_TDI.Attacker->IsPawn())
70  {
71  m_EMState = IDLE;
72  }
73  else
74  {
75  // If the source of the damage is from a pawn entity, chase that entity
77  }
78 
79  return true;
80 }
@ E_ITEM_STRING
Definition: BlockType.h:331
@ E_ITEM_SPIDER_EYE
Definition: BlockType.h:421
#define PREPARE_REL_AND_CHUNK(Position, OriginalChunk)
Definition: Chunk.h:32
@ mtSpider
Definition: MonsterTypes.h:63
Definition: Chunk.h:36
unsigned int GetLevel(int a_EnchantmentID) const
Returns the level for the specified enchantment; 0 if not stored.
cEntity * Attacker
Definition: Entity.h:62
Definition: Entity.h:76
int GetChunkZ(void) const
Definition: Entity.h:208
bool IsPlayer(void) const
Definition: Entity.h:160
int GetChunkX(void) const
Definition: Entity.h:207
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
bool IsPawn(void) const
Definition: Entity.h:163
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
cWorld * GetWorld(void) const
Definition: Entity.h:190
Definition: Player.h:29
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 EventSeePlayer(cPlayer *a_Player, cChunk &a_Chunk) override
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
@ IDLE
Definition: Monster.h:40
@ CHASING
Definition: Monster.h:40
enum cMonster::MState m_EMState
void AddRandomUncommonDropItem(cItems &a_Drops, float a_Chance, short a_Item, short a_ItemHealth=0)
Adds a item a_Item with the chance of a_Chance (in percent) to itemdrops a_Drops.
Definition: Monster.cpp:1537
virtual bool DoTakeDamage(TakeDamageInfo &a_TDI) override
Makes this entity take damage specified in the a_TDI.
Definition: Spider.cpp:61
virtual void EventSeePlayer(cPlayer *, cChunk &a_Chunk) override
Definition: Spider.cpp:38
virtual void GetDrops(cItems &a_Drops, cEntity *a_Killer=nullptr) override
Returns the list of drops for this pawn when it is killed.
Definition: Spider.cpp:20
cSpider()
Definition: Spider.cpp:11