Cuberite
A lightweight, fast and extensible game server for Minecraft
ZombieVillager.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 "ZombieVillager.h"
5 #include "../World.h"
6 #include "../LineBlockTracer.h"
7 #include "../Entities/Player.h"
8 
9 
10 
11 
12 
14  Super("ZombieVillager", mtZombieVillager, "entity.zombie_villager.hurt", "entity.zombie_villager.death", "entity.ambient", 0.6f, 1.95f),
15  m_ConversionTime(-1),
16  m_Profession(a_Profession)
17 {
18  SetBurnsInDaylight(true);
19 }
20 
21 
22 
23 
24 
25 void cZombieVillager::GetDrops(cItems & a_Drops, cEntity * a_Killer)
26 {
27  unsigned int LootingLevel = 0;
28  if (a_Killer != nullptr)
29  {
31  }
32  AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_ROTTEN_FLESH);
33  cItems RareDrops;
34  RareDrops.Add(cItem(E_ITEM_IRON));
35  RareDrops.Add(cItem(E_ITEM_CARROT));
36  RareDrops.Add(cItem(E_ITEM_POTATO));
37  AddRandomRareDropItem(a_Drops, RareDrops, LootingLevel);
38  AddRandomArmorDropItem(a_Drops, LootingLevel);
39  AddRandomWeaponDropItem(a_Drops, LootingLevel);
40 }
41 
42 
43 
44 
45 
46 void cZombieVillager::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
47 {
48  Super::Tick(a_Dt, a_Chunk);
49  if (!IsTicking())
50  {
51  // The base class tick destroyed us
52  return;
53  }
54 
55  LOGD("Conversion time: %d", m_ConversionTime);
56 
57  if (m_ConversionTime == 0)
58  {
59  m_World->BroadcastSoundEffect("entity.zombie_villager.cure", GetPosition(), 1.0f, 1.0f);
60  Destroy();
62  }
63  else if (m_ConversionTime > 0)
64  {
66  }
67 }
68 
69 
70 
71 
72 
74 {
75  Super::OnRightClicked(a_Player);
76 
77  const cItem & EquippedItem = a_Player.GetEquippedItem();
78  if ((EquippedItem.m_ItemType == E_ITEM_GOLDEN_APPLE) && GetEntityEffect(cEntityEffect::effWeakness) != nullptr)
79  {
80  if (!a_Player.IsGameModeCreative())
81  {
83  }
84 
85  m_ConversionTime = 6000;
86  }
87 }
@ E_ITEM_IRON
Definition: BlockType.h:309
@ E_ITEM_ROTTEN_FLESH
Definition: BlockType.h:412
@ E_ITEM_GOLDEN_APPLE
Definition: BlockType.h:366
@ E_ITEM_CARROT
Definition: BlockType.h:437
@ E_ITEM_POTATO
Definition: BlockType.h:438
#define LOGD
Definition: LoggerSimple.h:83
@ mtZombieVillager
Definition: MonsterTypes.h:82
@ mtVillager
Definition: MonsterTypes.h:71
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 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
void Destroy()
Destroys the entity, schedules it for memory freeing and broadcasts the DestroyEntity packet.
Definition: Entity.cpp:243
double GetPosY(void) const
Definition: Entity.h:196
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
cEntityEffect * GetEntityEffect(cEntityEffect::eType a_EffectType) const
Returns the entity effect, if it is currently applied or nullptr if not.
Definition: Pawn.cpp:597
Definition: Player.h:29
const cItem & GetEquippedItem(void) const
Definition: Player.h:162
bool IsGameModeCreative(void) const
Returns true if the player is in Creative mode, either explicitly, or by inheriting from current worl...
Definition: Player.cpp:1025
cInventory & GetInventory(void)
Definition: Player.h:156
bool RemoveOneEquippedItem(void)
Removes one item out of the currently equipped item stack, returns true if successful,...
Definition: Inventory.cpp:232
Definition: Item.h:37
cEnchantments m_Enchantments
Definition: Item.h:166
short m_ItemType
Definition: Item.h:163
This class bridges a vector of cItem for safe access via Lua.
Definition: Item.h:215
void Add(const cItem &a_Item)
Definition: Item.h:233
virtual void Tick(std::chrono::milliseconds a_Dt, cChunk &a_Chunk) override
void SetBurnsInDaylight(bool a_BurnsInDaylight)
Definition: Monster.h:145
void AddRandomRareDropItem(cItems &a_Drops, cItems &a_Items, unsigned int a_LootingLevel)
Adds one rare item out of the list of rare items a_Items modified by the looting level a_LootingLevel...
Definition: Monster.cpp:1549
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 void OnRightClicked(cPlayer &a_Player) override
Called when the specified player right-clicks this entity.
Definition: Monster.cpp:697
void AddRandomWeaponDropItem(cItems &a_Drops, unsigned int a_LootingLevel)
Adds weapon that is equipped with the chance saved in m_DropChance... to the drop.
Definition: Monster.cpp:1606
void AddRandomArmorDropItem(cItems &a_Drops, unsigned int a_LootingLevel)
Adds armor that is equipped with the chance saved in m_DropChance... to the drop.
Definition: Monster.cpp:1563
eVillagerType
Definition: Villager.h:19
cZombieVillager(cVillager::eVillagerType a_Profession)
virtual void Tick(std::chrono::milliseconds a_Dt, cChunk &a_Chunk) override
virtual void OnRightClicked(cPlayer &a_Player) override
Called when the specified player right-clicks this entity.
virtual void GetDrops(cItems &a_Drops, cEntity *a_Killer=nullptr) override
Returns the list of drops for this pawn when it is killed.
virtual UInt32 SpawnMob(double a_PosX, double a_PosY, double a_PosZ, eMonsterType a_MonsterType, bool a_Baby=false) override
Spawns a mob of the specified type.
Definition: World.cpp:2897
virtual void BroadcastSoundEffect(const AString &a_SoundName, Vector3d a_Position, float a_Volume, float a_Pitch, const cClientHandle *a_Exclude=nullptr) override