summaryrefslogtreecommitdiffstats
path: root/src/Mobs/Behaviors/BehaviorItemDropper.cpp
blob: d39993012bb28ae2119042f5c688da835c666a0a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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 == 6000) && 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 == 12000)
	{
		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++;
	}
}