Cuberite
A lightweight, fast and extensible game server for Minecraft
CaveSpider.cpp
Go to the documentation of this file.
1 #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
2 
3 #include "CaveSpider.h"
4 #include "../World.h"
5 
6 
7 
8 
9 
11  Super("CaveSpider", mtCaveSpider, "entity.spider.hurt", "entity.spider.death", "entity.spider.ambient", 0.7f, 0.5f)
12 {
13 }
14 
15 
16 
17 
18 
19 void cCaveSpider::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
20 {
21  Super::Tick(a_Dt, a_Chunk);
22  if (!IsTicking())
23  {
24  // The base class tick destroyed us
25  return;
26  }
27 
28  m_EMPersonality = (GetWorld()->GetTimeOfDay() < 13000_tick) ? PASSIVE : AGGRESSIVE;
29 }
30 
31 
32 
33 
34 
35 bool cCaveSpider::Attack(std::chrono::milliseconds a_Dt)
36 {
37  if (!Super::Attack(a_Dt))
38  {
39  return false;
40  }
41 
42  if (GetTarget()->IsPawn())
43  {
44  // TODO: Easy = no poison, Medium = 7 seconds, Hard = 15 seconds
45  static_cast<cPawn *>(GetTarget())->AddEntityEffect(cEntityEffect::effPoison, 7 * 20, 0);
46  }
47  return true;
48 }
49 
50 
51 
52 
53 
54 void cCaveSpider::GetDrops(cItems & a_Drops, cEntity * a_Killer)
55 {
56  unsigned int LootingLevel = 0;
57  if (a_Killer != nullptr)
58  {
60  }
61  AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_STRING);
62  if ((a_Killer != nullptr) && (a_Killer->IsPlayer() || a_Killer->IsA("cWolf")))
63  {
65  }
66 }
67 
68 
69 
70 
@ E_ITEM_STRING
Definition: BlockType.h:331
@ E_ITEM_SPIDER_EYE
Definition: BlockType.h:421
@ mtCaveSpider
Definition: MonsterTypes.h:17
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
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
cWorld * GetWorld(void) const
Definition: Entity.h:190
Definition: Pawn.h:17
void AddEntityEffect(cEntityEffect::eType a_EffectType, int a_EffectDurationTicks, short a_EffectIntensity, double a_DistanceModifier=1)
Applies an entity effect.
Definition: Pawn.cpp:186
cEnchantments m_Enchantments
Definition: Item.h:166
This class bridges a vector of cItem for safe access via Lua.
Definition: Item.h:215
virtual bool Attack(std::chrono::milliseconds a_Dt)
Try to perform attack returns true if attack was deemed successful (hit player, fired projectile,...
virtual void Tick(std::chrono::milliseconds a_Dt, cChunk &a_Chunk) override
virtual void Tick(std::chrono::milliseconds a_Dt, cChunk &a_Chunk) override
Definition: CaveSpider.cpp:19
virtual void GetDrops(cItems &a_Drops, cEntity *a_Killer=nullptr) override
Returns the list of drops for this pawn when it is killed.
Definition: CaveSpider.cpp:54
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: CaveSpider.cpp:35
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
@ AGGRESSIVE
Definition: Monster.h:41
@ PASSIVE
Definition: Monster.h:41
enum cMonster::MPersonality m_EMPersonality
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 cTickTime GetTimeOfDay(void) const override
Definition: World.cpp:480