From 77a3b65abe5ae07f3a77ac4574559730afcc6a20 Mon Sep 17 00:00:00 2001 From: LogicParrot Date: Sat, 2 Sep 2017 15:16:44 +0300 Subject: Initial creeper behaviors --- .../Behaviors/BehaviorAttackerSuicideBomber.cpp | 60 ++++++++++++++++++++-- src/Mobs/Behaviors/BehaviorAttackerSuicideBomber.h | 7 ++- 2 files changed, 63 insertions(+), 4 deletions(-) (limited to 'src/Mobs/Behaviors') diff --git a/src/Mobs/Behaviors/BehaviorAttackerSuicideBomber.cpp b/src/Mobs/Behaviors/BehaviorAttackerSuicideBomber.cpp index 27d5c408c..d7791319d 100644 --- a/src/Mobs/Behaviors/BehaviorAttackerSuicideBomber.cpp +++ b/src/Mobs/Behaviors/BehaviorAttackerSuicideBomber.cpp @@ -6,15 +6,31 @@ #include "../../Entities/Player.h" #include "../../BlockID.h" + + + +cBehaviorAttackerSuicideBomber::cBehaviorAttackerSuicideBomber() : + m_bIsBlowing(false), + m_bIsCharged(false), + m_BurnedWithFlintAndSteel(false), + m_ExplodingTimer(0) +{ + +} + + + + + void cBehaviorAttackerSuicideBomber::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { - if (((GetTarget() == nullptr) || !TargetIsInRange()) && !m_BurnedWithFlintAndSteel) + if (((GetTarget() == nullptr) || !TargetIsInStrikeRadius()) && !m_BurnedWithFlintAndSteel) { if (m_bIsBlowing) { m_ExplodingTimer = 0; m_bIsBlowing = false; - m_Parent->GetWorld()->BroadcastEntityMetadata(*this); + m_Parent->GetWorld()->BroadcastEntityMetadata(*m_Parent); } } else @@ -46,7 +62,7 @@ bool cBehaviorAttackerSuicideBomber::StrikeTarget(int a_StrikeTickCnt) { m_Parent->GetWorld()->BroadcastSoundEffect("entity.creeper.primed", m_Parent->GetPosX(), m_Parent->GetPosY(), m_Parent->GetPosZ(), 1.f, (0.75f + (static_cast((m_Parent->GetUniqueID() * 23) % 32)) / 64)); m_bIsBlowing = true; - m_Parent->GetWorld()->BroadcastEntityMetadata(*this); + m_Parent->GetWorld()->BroadcastEntityMetadata(*m_Parent); return true; } @@ -71,3 +87,41 @@ void cBehaviorAttackerSuicideBomber::OnRightClicked(cPlayer & a_Player) m_BurnedWithFlintAndSteel = true; } } + + +bool cBehaviorAttackerSuicideBomber::IsBlowing(void) const +{ + return m_bIsBlowing; +} + + + + + +bool cBehaviorAttackerSuicideBomber::IsCharged(void) const +{ + return m_bIsCharged; +} + + + + + +bool cBehaviorAttackerSuicideBomber::IsBurnedWithFlintAndSteel(void) const +{ + return m_BurnedWithFlintAndSteel; +} + + + + + +void cBehaviorAttackerSuicideBomber::DoTakeDamage(TakeDamageInfo & a_TDI) +{ + if (a_TDI.DamageType == dtLightning) + { + m_bIsCharged = true; + m_Parent->GetWorld()->BroadcastEntityMetadata(*m_Parent); + } + cBehaviorAttacker::DoTakeDamage(a_TDI); +} diff --git a/src/Mobs/Behaviors/BehaviorAttackerSuicideBomber.h b/src/Mobs/Behaviors/BehaviorAttackerSuicideBomber.h index 05611611c..99707f083 100644 --- a/src/Mobs/Behaviors/BehaviorAttackerSuicideBomber.h +++ b/src/Mobs/Behaviors/BehaviorAttackerSuicideBomber.h @@ -7,8 +7,13 @@ Use BehaviorAttackerMelee::SetTarget to attack. */ class cBehaviorAttackerSuicideBomber : public cBehaviorAttacker { public: - bool StrikeTarget(int a_StrikeTickCnt) override; + cBehaviorAttackerSuicideBomber(); + + // cBehaviorAttacker also implements those and we need to call super on them void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; + void DoTakeDamage(TakeDamageInfo & a_TDI) override; + + bool StrikeTarget(int a_StrikeTickCnt) override; void OnRightClicked(cPlayer & a_Player) override; bool IsBlowing(void) const {return m_bIsBlowing; } -- cgit v1.2.3