From 8405b8969f205ffae219361dfc03f3b4c680ce73 Mon Sep 17 00:00:00 2001 From: 12xx12 <44411062+12xx12@users.noreply.github.com> Date: Fri, 5 Mar 2021 16:08:30 +0100 Subject: Adding Boss bar (#5025) + Add boss bar Co-authored-by: Tiger Wang --- src/Mobs/EnderDragon.cpp | 25 ++++++++++++++++ src/Mobs/EnderDragon.h | 6 ++-- src/Mobs/Wither.cpp | 78 +++++++++++++++++++++++++++++------------------- src/Mobs/Wither.h | 12 +++----- 4 files changed, 78 insertions(+), 43 deletions(-) (limited to 'src/Mobs') diff --git a/src/Mobs/EnderDragon.cpp b/src/Mobs/EnderDragon.cpp index a3ba5f937..e33fb21f1 100644 --- a/src/Mobs/EnderDragon.cpp +++ b/src/Mobs/EnderDragon.cpp @@ -2,6 +2,8 @@ #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "EnderDragon.h" +#include "../ClientHandle.h" +#include "../CompositeChat.h" @@ -17,6 +19,21 @@ cEnderDragon::cEnderDragon(void) : +bool cEnderDragon::DoTakeDamage(TakeDamageInfo & a_TDI) +{ + if (!Super::DoTakeDamage(a_TDI)) + { + return false; + } + + m_World->BroadcastBossBarUpdateHealth(*this, GetUniqueID(), GetHealth() / GetMaxHealth()); + return true; +} + + + + + void cEnderDragon::GetDrops(cItems & a_Drops, cEntity * a_Killer) { // No drops @@ -25,3 +42,11 @@ void cEnderDragon::GetDrops(cItems & a_Drops, cEntity * a_Killer) + +void cEnderDragon::SpawnOn(cClientHandle & a_Client) +{ + Super::SpawnOn(a_Client); + + // Red boss bar with no divisions that plays boss music and creates fog: + a_Client.SendBossBarAdd(GetUniqueID(), cCompositeChat("Ender Dragon"), GetHealth() / GetMaxHealth(), BossBarColor::Red, BossBarDivisionType::None, false, true, true); +} diff --git a/src/Mobs/EnderDragon.h b/src/Mobs/EnderDragon.h index 1856d165c..ffc39218c 100644 --- a/src/Mobs/EnderDragon.h +++ b/src/Mobs/EnderDragon.h @@ -18,9 +18,7 @@ public: CLASS_PROTODEF(cEnderDragon) + virtual bool DoTakeDamage(TakeDamageInfo & a_TDI) override; virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr) override; + virtual void SpawnOn(cClientHandle & a_Client) override; } ; - - - - diff --git a/src/Mobs/Wither.cpp b/src/Mobs/Wither.cpp index fc02b2971..bdbbfcadb 100644 --- a/src/Mobs/Wither.cpp +++ b/src/Mobs/Wither.cpp @@ -5,6 +5,8 @@ #include "../World.h" #include "../Entities/Player.h" +#include "../ClientHandle.h" +#include "../CompositeChat.h" @@ -48,40 +50,13 @@ bool cWither::DoTakeDamage(TakeDamageInfo & a_TDI) return false; } - return Super::DoTakeDamage(a_TDI); -} - - - - - -void cWither::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) -{ - Super::Tick(a_Dt, a_Chunk); - if (!IsTicking()) - { - // The base class tick destroyed us - return; - } - - if (m_WitherInvulnerableTicks > 0) + if (!Super::DoTakeDamage(a_TDI)) { - unsigned int NewTicks = m_WitherInvulnerableTicks - 1; - - if (NewTicks == 0) - { - m_World->DoExplosionAt(7.0, GetPosX(), GetPosY(), GetPosZ(), false, esWitherBirth, this); - } - - m_WitherInvulnerableTicks = NewTicks; - - if ((NewTicks % 10) == 0) - { - Heal(10); - } + return false; } - m_World->BroadcastEntityMetadata(*this); + m_World->BroadcastBossBarUpdateHealth(*this, GetUniqueID(), GetHealth() / GetMaxHealth()); + return true; } @@ -119,3 +94,44 @@ void cWither::KilledBy(TakeDamageInfo & a_TDI) + +void cWither::SpawnOn(cClientHandle & a_Client) +{ + Super::SpawnOn(a_Client); + + // Purple boss bar with no divisions that darkens the sky: + a_Client.SendBossBarAdd(GetUniqueID(), cCompositeChat("Wither"), GetHealth() / GetMaxHealth(), BossBarColor::Purple, BossBarDivisionType::None, true, false, false); +} + + + + + +void cWither::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) +{ + Super::Tick(a_Dt, a_Chunk); + if (!IsTicking()) + { + // The base class tick destroyed us + return; + } + + if (m_WitherInvulnerableTicks > 0) + { + unsigned int NewTicks = m_WitherInvulnerableTicks - 1; + + if (NewTicks == 0) + { + m_World->DoExplosionAt(7.0, GetPosX(), GetPosY(), GetPosZ(), false, esWitherBirth, this); + } + + m_WitherInvulnerableTicks = NewTicks; + + if ((NewTicks % 10) == 0) + { + Heal(10); + } + } + + m_World->BroadcastEntityMetadata(*this); +} diff --git a/src/Mobs/Wither.h b/src/Mobs/Wither.h index 21e6aecf8..f6afb1e6d 100644 --- a/src/Mobs/Wither.h +++ b/src/Mobs/Wither.h @@ -26,12 +26,12 @@ public: bool IsArmored(void) const; // cEntity overrides - virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr) override; virtual bool DoTakeDamage(TakeDamageInfo & a_TDI) override; - virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; - virtual void KilledBy(TakeDamageInfo & a_TDI) override; - + virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr) override; virtual bool IsUndead(void) override { return true; } + virtual void KilledBy(TakeDamageInfo & a_TDI) override; + virtual void SpawnOn(cClientHandle & a_Client) override; + virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; private: @@ -39,7 +39,3 @@ private: unsigned int m_WitherInvulnerableTicks; } ; - - - - -- cgit v1.2.3