summaryrefslogtreecommitdiffstats
path: root/src/Mobs/Behaviors/BehaviorItemDropper.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/Mobs/Behaviors/BehaviorItemDropper.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/Mobs/Behaviors/BehaviorItemDropper.cpp b/src/Mobs/Behaviors/BehaviorItemDropper.cpp
index 8b1378917..0ca718990 100644
--- a/src/Mobs/Behaviors/BehaviorItemDropper.cpp
+++ b/src/Mobs/Behaviors/BehaviorItemDropper.cpp
@@ -1 +1,50 @@
+#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
+#include "BehaviorItemDropper.h"
+#include "../Monster.h"
+#include "../../World.h"
+
+
+void cBehaviorItemDropper::AttachToMonster(cMonster & a_Parent)
+{
+ m_Parent = &a_Parent;
+ m_EggDropTimer = 0;
+ m_Parent->AttachPostTickBehavior(this);
+}
+
+
+
+
+
+void cBehaviorItemDropper::PostTick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
+{
+ if (!m_Parent->IsTicking())
+ {
+ // The base class tick destroyed us
+ return;
+ }
+
+ if (m_Parent->IsBaby())
+ {
+ return; // Babies don't lay eggs
+ }
+
+ if ((m_EggDropTimer == 120) && GetRandomProvider().RandBool())
+ {
+ cItems Drops;
+ m_EggDropTimer = 0;
+ Drops.push_back(cItem(E_ITEM_EGG, 1));
+ m_Parent->GetWorld()->SpawnItemPickups(Drops, m_Parent->GetPosX(), m_Parent->GetPosY(), m_Parent->GetPosZ(), 10);
+ }
+ else if (m_EggDropTimer == 150)
+ {
+ cItems Drops;
+ m_EggDropTimer = 0;
+ Drops.push_back(cItem(E_ITEM_EGG, 1));
+ m_Parent->GetWorld()->SpawnItemPickups(Drops, m_Parent->GetPosX(), m_Parent->GetPosY(), m_Parent->GetPosZ(), 10);
+ }
+ else
+ {
+ m_EggDropTimer++;
+ }
+}