diff options
-rw-r--r-- | src/Mobs/Behaviors/BehaviorAttackerSuicideBomber.cpp | 65 | ||||
-rw-r--r-- | src/Mobs/Behaviors/BehaviorAttackerSuicideBomber.h | 8 | ||||
-rw-r--r-- | src/Mobs/Creeper.h | 13 |
3 files changed, 59 insertions, 27 deletions
diff --git a/src/Mobs/Behaviors/BehaviorAttackerSuicideBomber.cpp b/src/Mobs/Behaviors/BehaviorAttackerSuicideBomber.cpp index a2ca50e5f..27d5c408c 100644 --- a/src/Mobs/Behaviors/BehaviorAttackerSuicideBomber.cpp +++ b/src/Mobs/Behaviors/BehaviorAttackerSuicideBomber.cpp @@ -3,29 +3,18 @@ #include "BehaviorAttackerSuicideBomber.h" #include "../Monster.h" #include "../../Entities/Pawn.h" +#include "../../Entities/Player.h" #include "../../BlockID.h" -bool cBehaviorAttackerSuicideBomber::StrikeTarget(int a_StrikeTickCnt) +void cBehaviorAttackerSuicideBomber::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { - UNUSED(a_StrikeTickCnt); - //mobTodo - return true; // Finish the strike. It only takes 1 tick. -} - -/* - if (!IsTicking()) - { - // The base class tick destroyed us - return; - } - if (((GetTarget() == nullptr) || !TargetIsInRange()) && !m_BurnedWithFlintAndSteel) { if (m_bIsBlowing) { m_ExplodingTimer = 0; m_bIsBlowing = false; - m_World->BroadcastEntityMetadata(*this); + m_Parent->GetWorld()->BroadcastEntityMetadata(*this); } } else @@ -35,10 +24,50 @@ bool cBehaviorAttackerSuicideBomber::StrikeTarget(int a_StrikeTickCnt) m_ExplodingTimer += 1; } - if ((m_ExplodingTimer == 30) && (GetHealth() > 0.0)) // only explode when not already dead + if ((m_ExplodingTimer == 30) && (m_Parent->GetHealth() > 0.0)) // only explode when not already dead { - m_World->DoExplosionAt((m_bIsCharged ? 5 : 3), GetPosX(), GetPosY(), GetPosZ(), false, esMonster, this); - Destroy(); // Just in case we aren't killed by the explosion + m_Parent->GetWorld()->DoExplosionAt((m_bIsCharged ? 5 : 3), m_Parent->GetPosX(), m_Parent->GetPosY(), m_Parent->GetPosZ(), false, esMonster, this); + m_Parent->Destroy(); // Just in case we aren't killed by the explosion } } - */ + + cBehaviorAttacker::Tick(a_Dt, a_Chunk); +} + + + + + +bool cBehaviorAttackerSuicideBomber::StrikeTarget(int a_StrikeTickCnt) +{ + UNUSED(a_StrikeTickCnt); + + if (!m_bIsBlowing) + { + m_Parent->GetWorld()->BroadcastSoundEffect("entity.creeper.primed", m_Parent->GetPosX(), m_Parent->GetPosY(), m_Parent->GetPosZ(), 1.f, (0.75f + (static_cast<float>((m_Parent->GetUniqueID() * 23) % 32)) / 64)); + m_bIsBlowing = true; + m_Parent->GetWorld()->BroadcastEntityMetadata(*this); + + return true; + } + return false; +} + + + + + +void cBehaviorAttackerSuicideBomber::OnRightClicked(cPlayer & a_Player) +{ + if ((a_Player.GetEquippedItem().m_ItemType == E_ITEM_FLINT_AND_STEEL)) + { + if (!a_Player.IsGameModeCreative()) + { + a_Player.UseEquippedItem(); + } + m_Parent->GetWorld()->BroadcastSoundEffect("entity.creeper.primed", m_Parent->GetPosX(), m_Parent->GetPosY(), m_Parent->GetPosZ(), 1.f, (0.75f + (static_cast<float>((m_Parent->GetUniqueID() * 23) % 32)) / 64)); + m_bIsBlowing = true; + m_Parent->GetWorld()->BroadcastEntityMetadata(*m_Parent); + m_BurnedWithFlintAndSteel = true; + } +} diff --git a/src/Mobs/Behaviors/BehaviorAttackerSuicideBomber.h b/src/Mobs/Behaviors/BehaviorAttackerSuicideBomber.h index dc071e2f4..05611611c 100644 --- a/src/Mobs/Behaviors/BehaviorAttackerSuicideBomber.h +++ b/src/Mobs/Behaviors/BehaviorAttackerSuicideBomber.h @@ -8,8 +8,14 @@ class cBehaviorAttackerSuicideBomber : public cBehaviorAttacker { public: bool StrikeTarget(int a_StrikeTickCnt) override; + void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; void OnRightClicked(cPlayer & a_Player) override; -private: + bool IsBlowing(void) const {return m_bIsBlowing; } + bool IsCharged(void) const {return m_bIsCharged; } + bool IsBurnedWithFlintAndSteel(void) const {return m_BurnedWithFlintAndSteel; } +private: + bool m_bIsBlowing, m_bIsCharged, m_BurnedWithFlintAndSteel; + int m_ExplodingTimer; }; diff --git a/src/Mobs/Creeper.h b/src/Mobs/Creeper.h index 8e74160dc..efb7cda23 100644 --- a/src/Mobs/Creeper.h +++ b/src/Mobs/Creeper.h @@ -2,7 +2,7 @@ #pragma once #include "Monster.h" - +#include "Behaviors/BehaviorAttackerSuicideBomber.h" @@ -21,15 +21,12 @@ public: virtual bool DoTakeDamage(TakeDamageInfo & a_TDI) override; virtual void OnRightClicked(cPlayer & a_Player) override; - bool IsBlowing(void) const {return m_bIsBlowing; } - bool IsCharged(void) const {return m_bIsCharged; } - bool IsBurnedWithFlintAndSteel(void) const {return m_BurnedWithFlintAndSteel; } + bool IsBlowing(void) const {return m_BehaviorSuicideBomber.IsBlowing(); } + bool IsCharged(void) const {return m_BehaviorSuicideBomber.IsCharged(); } + bool IsBurnedWithFlintAndSteel(void) const {return m_BehaviorSuicideBomber.IsBurnedWithFlintAndSteel(); } private: - - bool m_bIsBlowing, m_bIsCharged, m_BurnedWithFlintAndSteel; - int m_ExplodingTimer; - + cBehaviorSuicideBomer m_BehaviorSuicideBomber; } ; |