diff options
author | Tycho <work.tycho+git@gmail.com> | 2014-04-02 15:05:55 +0200 |
---|---|---|
committer | Tycho <work.tycho+git@gmail.com> | 2014-04-02 15:05:55 +0200 |
commit | dcaea749ae502366c23f2c04f3b42882cb71d0d6 (patch) | |
tree | 56e499098895a03bc66beac5aa33ba4ee261f17e /src/Mobs | |
parent | Merge branch 'master' into globals (diff) | |
parent | Merge pull request #831 from mc-server/Wither (diff) | |
download | cuberite-dcaea749ae502366c23f2c04f3b42882cb71d0d6.tar cuberite-dcaea749ae502366c23f2c04f3b42882cb71d0d6.tar.gz cuberite-dcaea749ae502366c23f2c04f3b42882cb71d0d6.tar.bz2 cuberite-dcaea749ae502366c23f2c04f3b42882cb71d0d6.tar.lz cuberite-dcaea749ae502366c23f2c04f3b42882cb71d0d6.tar.xz cuberite-dcaea749ae502366c23f2c04f3b42882cb71d0d6.tar.zst cuberite-dcaea749ae502366c23f2c04f3b42882cb71d0d6.zip |
Diffstat (limited to 'src/Mobs')
-rw-r--r-- | src/Mobs/Monster.cpp | 11 | ||||
-rw-r--r-- | src/Mobs/Villager.h | 2 | ||||
-rw-r--r-- | src/Mobs/Wither.cpp | 78 | ||||
-rw-r--r-- | src/Mobs/Wither.h | 17 |
4 files changed, 101 insertions, 7 deletions
diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index 6e3c91d58..d3e0f1c26 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -82,11 +82,11 @@ cMonster::cMonster(const AString & a_ConfigName, eType a_MobType, const AString , m_AttackRange(2) , m_AttackInterval(0) , m_SightDistance(25) - , m_DropChanceWeapon(0.085) - , m_DropChanceHelmet(0.085) - , m_DropChanceChestplate(0.085) - , m_DropChanceLeggings(0.085) - , m_DropChanceBoots(0.085) + , m_DropChanceWeapon(0.085f) + , m_DropChanceHelmet(0.085f) + , m_DropChanceChestplate(0.085f) + , m_DropChanceLeggings(0.085f) + , m_DropChanceBoots(0.085f) , m_CanPickUpLoot(true) , m_BurnsInDaylight(false) { @@ -758,6 +758,7 @@ cMonster::eFamily cMonster::FamilyFromType(eType a_Type) case mtSquid: return mfWater; case mtVillager: return mfPassive; case mtWitch: return mfHostile; + case mtWither: return mfHostile; case mtWolf: return mfHostile; case mtZombie: return mfHostile; case mtZombiePigman: return mfHostile; diff --git a/src/Mobs/Villager.h b/src/Mobs/Villager.h index b99ae876f..5bba4d4ba 100644 --- a/src/Mobs/Villager.h +++ b/src/Mobs/Villager.h @@ -29,7 +29,7 @@ public: CLASS_PROTODEF(cVillager); - // Override functions + // cEntity overrides virtual void DoTakeDamage(TakeDamageInfo & a_TDI) override; virtual void Tick (float a_Dt, cChunk & a_Chunk) override; diff --git a/src/Mobs/Wither.cpp b/src/Mobs/Wither.cpp index c46e0beab..8f5d28b68 100644 --- a/src/Mobs/Wither.cpp +++ b/src/Mobs/Wither.cpp @@ -2,14 +2,90 @@ #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "Wither.h" +#include "../World.h" cWither::cWither(void) : - super("Wither", mtWither, "mob.wither.hurt", "mob.wither.death", 0.9, 4.0) + super("Wither", mtWither, "mob.wither.hurt", "mob.wither.death", 0.9, 4.0), + m_InvulnerableTicks(220) { + SetMaxHealth(300); +} + + + + + +bool cWither::IsArmored(void) const +{ + return GetHealth() <= (GetMaxHealth() / 2); +} + + + + + +bool cWither::Initialize(cWorld * a_World) +{ + // Set health before BroadcastSpawnEntity() + SetHealth(GetMaxHealth() / 3); + + return super::Initialize(a_World); +} + + + + + +void cWither::DoTakeDamage(TakeDamageInfo & a_TDI) +{ + if (a_TDI.DamageType == dtDrowning) + { + return; + } + + if (m_InvulnerableTicks > 0) + { + return; + } + + if (IsArmored() && (a_TDI.DamageType == dtRangedAttack)) + { + return; + } + + super::DoTakeDamage(a_TDI); +} + + + + + +void cWither::Tick(float a_Dt, cChunk & a_Chunk) +{ + super::Tick(a_Dt, a_Chunk); + + if (m_InvulnerableTicks > 0) + { + unsigned int NewTicks = m_InvulnerableTicks - 1; + + if (NewTicks == 0) + { + m_World->DoExplosionAt(7.0, GetPosX(), GetPosY(), GetPosZ(), false, esWitherBirth, this); + } + + m_InvulnerableTicks = NewTicks; + + if ((NewTicks % 10) == 0) + { + Heal(10); + } + } + + m_World->BroadcastEntityMetadata(*this); } diff --git a/src/Mobs/Wither.h b/src/Mobs/Wither.h index 56effc6bb..bc78bfaad 100644 --- a/src/Mobs/Wither.h +++ b/src/Mobs/Wither.h @@ -16,8 +16,25 @@ public: cWither(void); CLASS_PROTODEF(cWither); + + unsigned int GetNumInvulnerableTicks(void) const { return m_InvulnerableTicks; } + + void SetNumInvulnerableTicks(unsigned int a_Ticks) { m_InvulnerableTicks = a_Ticks; } + + /** Returns whether the wither is invulnerable to arrows. */ + bool IsArmored(void) const; + // cEntity overrides + virtual bool Initialize(cWorld * a_World) override; virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) override; + virtual void DoTakeDamage(TakeDamageInfo & a_TDI) override; + virtual void Tick(float a_Dt, cChunk & a_Chunk) override; + +private: + + /** The number of ticks of invulnerability left after being initially created. Zero once invulnerability has expired. */ + unsigned int m_InvulnerableTicks; + } ; |