summaryrefslogtreecommitdiffstats
path: root/src/Mobs/Behaviors/BehaviorItemFollower.cpp
blob: 6978b2765300df0e7d25577138e6272e4b7df6d0 (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "Globals.h"  // NOTE: MSVC stupidness requires this to be the same across all modules

#include "BehaviorItemFollower.h"
#include "../Monster.h"
#include "../../World.h"
#include "../../Entities/Player.h"


void cBehaviorItemFollower::AttachToMonster(cMonster & a_Parent)
{
	LOGD("mobDebug - Behavior ItemFollower: Attach");
	m_Parent = &a_Parent;
	m_Parent->AttachTickBehavior(this);
}





bool cBehaviorItemFollower::IsControlDesired(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
{
	UNUSED(a_Dt);
	UNUSED(a_Chunk);
	cItems FollowedItems;
	m_Parent->GetFollowedItems(FollowedItems);
	if (FollowedItems.Size() > 0)
	{
		cPlayer * a_Closest_Player = m_Parent->GetNearestPlayer();
		if (a_Closest_Player != nullptr)
		{
			cItem EquippedItem = a_Closest_Player->GetEquippedItem();
			if (FollowedItems.ContainsType(EquippedItem))
			{
				return true;  // We take control of the monster. Now it'll call our tick
			}
		}
	}
	return false;
}





void cBehaviorItemFollower::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
{
	UNUSED(a_Dt);
	UNUSED(a_Chunk);
	cItems FollowedItems;
	m_Parent->GetFollowedItems(FollowedItems);
	if (FollowedItems.Size() > 0)
	{
		cPlayer * a_Closest_Player = m_Parent->GetNearestPlayer();
		if (a_Closest_Player != nullptr)
		{
			cItem EquippedItem = a_Closest_Player->GetEquippedItem();
			if (FollowedItems.ContainsType(EquippedItem))
			{
				Vector3d PlayerPos = a_Closest_Player->GetPosition();
				m_Parent->MoveToPosition(PlayerPos);
			}
		}
	}
}