summaryrefslogtreecommitdiffstats
path: root/src/Mobs/Behaviors/BehaviorItemReplacer.cpp
blob: b53f08b33cbdaefb1697e596c00cad84e2233ffb (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
#include "Globals.h"  // NOTE: MSVC stupidness requires this to be the same across all modules

#include "BehaviorItemReplacer.h"
#include "../Monster.h"
#include "../Entities/Player.h"


cBehaviorItemReplacer::cBehaviorItemReplacer(short a_OriginalItem, short a_NewItem) :
	m_OriginalItem(a_OriginalItem) ,
	m_NewItem(a_NewItem)
{

}





void cBehaviorItemReplacer::AttachToMonster(cMonster & a_Parent)
{
	m_Parent = &a_Parent;
	m_Parent->AttachRightClickBehavior(this);
}





void cBehaviorItemReplacer::OnRightClicked(cPlayer & a_Player)
{
	short HeldItem = a_Player.GetEquippedItem().m_ItemType;
	if (HeldItem == m_OriginalItem)
	{
		if (!a_Player.IsGameModeCreative())
		{
			a_Player.GetInventory().RemoveOneEquippedItem();
			a_Player.GetInventory().AddItem(m_NewItem);
		}
	}
}