summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLogicParrot <LogicParrot@users.noreply.github.com>2017-09-02 14:16:44 +0200
committerLogicParrot <LogicParrot@users.noreply.github.com>2017-09-02 14:16:44 +0200
commit77a3b65abe5ae07f3a77ac4574559730afcc6a20 (patch)
treeaaee6818ccf2d72f07655ede91dc58af84621189
parentcreeper initial behaviors (diff)
downloadcuberite-77a3b65abe5ae07f3a77ac4574559730afcc6a20.tar
cuberite-77a3b65abe5ae07f3a77ac4574559730afcc6a20.tar.gz
cuberite-77a3b65abe5ae07f3a77ac4574559730afcc6a20.tar.bz2
cuberite-77a3b65abe5ae07f3a77ac4574559730afcc6a20.tar.lz
cuberite-77a3b65abe5ae07f3a77ac4574559730afcc6a20.tar.xz
cuberite-77a3b65abe5ae07f3a77ac4574559730afcc6a20.tar.zst
cuberite-77a3b65abe5ae07f3a77ac4574559730afcc6a20.zip
-rw-r--r--src/Mobs/Behaviors/BehaviorAttackerSuicideBomber.cpp60
-rw-r--r--src/Mobs/Behaviors/BehaviorAttackerSuicideBomber.h7
-rw-r--r--src/Mobs/Creeper.cpp59
-rw-r--r--src/Mobs/Creeper.h10
4 files changed, 77 insertions, 59 deletions
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<float>((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; }
diff --git a/src/Mobs/Creeper.cpp b/src/Mobs/Creeper.cpp
index 8996db38e..8d98a567f 100644
--- a/src/Mobs/Creeper.cpp
+++ b/src/Mobs/Creeper.cpp
@@ -11,11 +11,7 @@
cCreeper::cCreeper(void) :
- super(mtCreeper, "entity.creeper.hurt", "entity.creeper.death", 0.6, 1.8),
- m_bIsBlowing(false),
- m_bIsCharged(false),
- m_BurnedWithFlintAndSteel(false),
- m_ExplodingTimer(0)
+ super(mtCreeper, "entity.creeper.hurt", "entity.creeper.death", 0.6, 1.8)
{
m_EMPersonality = AGGRESSIVE;
GetMonsterConfig("Creeper");
@@ -27,7 +23,7 @@ cCreeper::cCreeper(void) :
void cCreeper::GetDrops(cItems & a_Drops, cEntity * a_Killer)
{
- if (m_ExplodingTimer == 30)
+ if (IsBlowing())
{
// Exploded creepers drop naught but charred flesh, which Minecraft doesn't have
return;
@@ -71,60 +67,25 @@ void cCreeper::GetDrops(cItems & a_Drops, cEntity * a_Killer)
-bool cCreeper::DoTakeDamage(TakeDamageInfo & a_TDI)
+bool cCreeper::IsBlowing(void) const
{
- if (!super::DoTakeDamage(a_TDI))
- {
- return false;
- }
-
- if (a_TDI.DamageType == dtLightning)
- {
- m_bIsCharged = true;
- }
-
- m_World->BroadcastEntityMetadata(*this);
- return true;
+ return m_BehaviorSuicideBomber.IsBlowing();
}
-// mobTODO
-/*
-bool cCreeper::Attack(std::chrono::milliseconds a_Dt)
-{
- UNUSED(a_Dt);
-
- if (!m_bIsBlowing)
- {
- m_World->BroadcastSoundEffect("entity.creeper.primed", GetPosX(), GetPosY(), GetPosZ(), 1.f, (0.75f + (static_cast<float>((GetUniqueID() * 23) % 32)) / 64));
- m_bIsBlowing = true;
- m_World->BroadcastEntityMetadata(*this);
- return true;
- }
- return false;
-}*/
+bool cCreeper::IsCharged(void) const
+{
+ return m_BehaviorSuicideBomber.IsCharged();
+}
-void cCreeper::OnRightClicked(cPlayer & a_Player)
+bool cCreeper::IsBurnedWithFlintAndSteel(void) const
{
- super::OnRightClicked(a_Player);
-
- if ((a_Player.GetEquippedItem().m_ItemType == E_ITEM_FLINT_AND_STEEL))
- {
- if (!a_Player.IsGameModeCreative())
- {
- a_Player.UseEquippedItem();
- }
- m_World->BroadcastSoundEffect("entity.creeper.primed", GetPosX(), GetPosY(), GetPosZ(), 1.f, (0.75f + (static_cast<float>((GetUniqueID() * 23) % 32)) / 64));
- m_bIsBlowing = true;
- m_World->BroadcastEntityMetadata(*this);
- m_BurnedWithFlintAndSteel = true;
- }
+ return m_BehaviorSuicideBomber.IsBurnedWithFlintAndSteel();
}
-
diff --git a/src/Mobs/Creeper.h b/src/Mobs/Creeper.h
index efb7cda23..3d1af2ed1 100644
--- a/src/Mobs/Creeper.h
+++ b/src/Mobs/Creeper.h
@@ -18,15 +18,13 @@ public:
CLASS_PROTODEF(cCreeper)
virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr) override;
- virtual bool DoTakeDamage(TakeDamageInfo & a_TDI) override;
- virtual void OnRightClicked(cPlayer & a_Player) override;
- bool IsBlowing(void) const {return m_BehaviorSuicideBomber.IsBlowing(); }
- bool IsCharged(void) const {return m_BehaviorSuicideBomber.IsCharged(); }
- bool IsBurnedWithFlintAndSteel(void) const {return m_BehaviorSuicideBomber.IsBurnedWithFlintAndSteel(); }
+ bool IsBlowing(void) const;
+ bool IsCharged(void) const;
+ bool IsBurnedWithFlintAndSteel(void) const;
private:
- cBehaviorSuicideBomer m_BehaviorSuicideBomber;
+ cBehaviorAttackerSuicideBomber m_BehaviorSuicideBomber;
} ;