summaryrefslogblamecommitdiffstats
path: root/src/Mobs/Behaviors/BehaviorItemFollower.cpp
blob: 22c20d6b427cb6815800b358639036b666668656 (plain) (tree)
1
2
3
4
5
6
7
8
9






                                                                                              
 
                                                                   
                          
 

                                    





 























                                                                                                        
 











                                                                                     


                         
 
#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"


cBehaviorItemFollower::cBehaviorItemFollower(cMonster * a_Parent) :
	m_Parent(a_Parent)
{
	m_Parent = a_Parent;
	ASSERT(m_Parent != nullptr);
}





bool cBehaviorItemFollower::IsControlDesired()
{
	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()
{
	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);
			}
		}
	}
}