diff options
author | LogicParrot <LogicParrot@users.noreply.github.com> | 2017-08-29 18:53:06 +0200 |
---|---|---|
committer | LogicParrot <LogicParrot@users.noreply.github.com> | 2017-08-29 18:53:06 +0200 |
commit | a53d1051d9033a1be708b76b8a50bca6f5d2bbd9 (patch) | |
tree | 698439a8455592d4d9cbf6b23835eea5e0ca8a18 | |
parent | Merge branch 'master' into mobs2 (diff) | |
download | cuberite-a53d1051d9033a1be708b76b8a50bca6f5d2bbd9.tar cuberite-a53d1051d9033a1be708b76b8a50bca6f5d2bbd9.tar.gz cuberite-a53d1051d9033a1be708b76b8a50bca6f5d2bbd9.tar.bz2 cuberite-a53d1051d9033a1be708b76b8a50bca6f5d2bbd9.tar.lz cuberite-a53d1051d9033a1be708b76b8a50bca6f5d2bbd9.tar.xz cuberite-a53d1051d9033a1be708b76b8a50bca6f5d2bbd9.tar.zst cuberite-a53d1051d9033a1be708b76b8a50bca6f5d2bbd9.zip |
Diffstat (limited to '')
-rw-r--r-- | src/Mobs/Behaviors/BehaviorItemDropper.cpp | 49 | ||||
-rw-r--r-- | src/Mobs/Behaviors/BehaviorItemDropper.h | 14 | ||||
-rw-r--r-- | src/Mobs/Chicken.cpp | 65 | ||||
-rw-r--r-- | src/Mobs/Chicken.h | 30 |
4 files changed, 96 insertions, 62 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; +}; diff --git a/src/Mobs/Chicken.cpp b/src/Mobs/Chicken.cpp index 80cff7fb8..cc691fa5b 100644 --- a/src/Mobs/Chicken.cpp +++ b/src/Mobs/Chicken.cpp @@ -6,48 +6,15 @@ cChicken::cChicken(void) : - super("Chicken", mtChicken, "entity.chicken.hurt", "entity.chicken.death", 0.3, 0.4), - m_EggDropTimer(0) + super("Chicken", mtChicken, "entity.chicken.hurt", "entity.chicken.death", 0.3, 0.4) { - SetGravity(-2.0f); - SetAirDrag(0.0f); -} - - - - -void cChicken::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) -{ - super::Tick(a_Dt, a_Chunk); - if (!IsTicking()) - { - // The base class tick destroyed us - return; - } - - if (IsBaby()) - { - return; // Babies don't lay eggs - } - - if ((m_EggDropTimer == 6000) && GetRandomProvider().RandBool()) - { - cItems Drops; - m_EggDropTimer = 0; - Drops.push_back(cItem(E_ITEM_EGG, 1)); - m_World->SpawnItemPickups(Drops, GetPosX(), GetPosY(), GetPosZ(), 10); - } - else if (m_EggDropTimer == 12000) - { - cItems Drops; - m_EggDropTimer = 0; - Drops.push_back(cItem(E_ITEM_EGG, 1)); - m_World->SpawnItemPickups(Drops, GetPosX(), GetPosY(), GetPosZ(), 10); - } - else - { - m_EggDropTimer++; - } + SetGravity(-2.0f); + SetAirDrag(0.0f); + m_BehaviorBreeder.AttachToMonster(*this); + m_BehaviorCoward.AttachToMonster(*this); + m_BehaviorItemFollower.AttachToMonster(*this); + m_BehaviorWanderer.AttachToMonster(*this); + m_BehaviorItemDropper.AttachToMonster(*this); } @@ -56,13 +23,13 @@ void cChicken::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) void cChicken::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - unsigned int LootingLevel = 0; - if (a_Killer != nullptr) - { - LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); - } - AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_FEATHER); - AddRandomDropItem(a_Drops, 1, 1, IsOnFire() ? E_ITEM_COOKED_CHICKEN : E_ITEM_RAW_CHICKEN); + unsigned int LootingLevel = 0; + if (a_Killer != nullptr) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); + } + AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_FEATHER); + AddRandomDropItem(a_Drops, 1, 1, IsOnFire() ? E_ITEM_COOKED_CHICKEN : E_ITEM_RAW_CHICKEN); } @@ -71,7 +38,7 @@ void cChicken::GetDrops(cItems & a_Drops, cEntity * a_Killer) void cChicken::HandleFalling(void) { - // empty - chickens don't take fall damage + // empty - chickens don't take fall damage } diff --git a/src/Mobs/Chicken.h b/src/Mobs/Chicken.h index b954c19ec..6d99dd8c2 100644 --- a/src/Mobs/Chicken.h +++ b/src/Mobs/Chicken.h @@ -1,34 +1,38 @@ #pragma once #include "PassiveMonster.h" - +#include "Behaviors/BehaviorItemDropper.h" class cChicken : - public cPassiveMonster + public cMonster { - typedef cPassiveMonster super; + typedef cMonster super; public: - cChicken(void); + cChicken(void); - CLASS_PROTODEF(cChicken) + CLASS_PROTODEF(cChicken) - virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr) override; - virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; + virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr) override; - virtual void GetFollowedItems(cItems & a_Items) override - { - a_Items.Add(E_ITEM_SEEDS); - } + virtual void GetFollowedItems(cItems & a_Items) override + { + a_Items.Add(E_ITEM_SEEDS); + } - virtual void HandleFalling(void) override; + virtual void HandleFalling(void) override; private: + // Tick controlling behaviors + cBehaviorBreeder m_BehaviorBreeder; + cBehaviorItemFollower m_BehaviorItemFollower; + cBehaviorCoward m_BehaviorCoward; + cBehaviorWanderer m_BehaviorWanderer; - int m_EggDropTimer; + cBehaviorItemDropper m_BehaviorItemDropper; } ; |