diff options
Diffstat (limited to 'src/Mobs/Behaviors')
-rw-r--r-- | src/Mobs/Behaviors/BehaviorItemDropper.cpp | 49 | ||||
-rw-r--r-- | src/Mobs/Behaviors/BehaviorItemDropper.h | 14 |
2 files changed, 63 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++; + } +} diff --git a/src/Mobs/Behaviors/BehaviorItemDropper.h b/src/Mobs/Behaviors/BehaviorItemDropper.h index 8b1378917..320b0c8d8 100644 --- a/src/Mobs/Behaviors/BehaviorItemDropper.h +++ b/src/Mobs/Behaviors/BehaviorItemDropper.h @@ -1 +1,15 @@ +#pragma once +// mobTodo a more generic, not chickenspecific dropper +#include "Behavior.h" + +class cBehaviorItemDropper : cBehavior +{ +public: + void AttachToMonster(cMonster & a_Parent); + void PostTick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; + +private: + cMonster * m_Parent; // Our Parent + int m_EggDropTimer; +}; |