1
0

Implement horse inventory (#4053)

* Implement horse inventory

* Fix sign conversions

* Add API doc for ItemCategory::IsHorseArmor

* Improve HandleOpenHorseInventory comment and style fixes.
This commit is contained in:
peterbell10
2017-10-21 17:56:09 +01:00
committed by Alexander Harkness
parent e585595ae6
commit 0bacda3269
15 changed files with 473 additions and 27 deletions

View File

@@ -21,6 +21,7 @@
#include "../BlockArea.h"
#include "../EffectID.h"
#include "../ClientHandle.h"
#include "Mobs/Horse.h"
@@ -2596,3 +2597,121 @@ cItem * cSlotAreaTemporary::GetPlayerSlots(cPlayer & a_Player)
////////////////////////////////////////////////////////////////////////////////
// cSlotAreaHorse:
cSlotAreaHorse::cSlotAreaHorse(cHorse & a_Horse, cWindow & a_ParentWindow) :
cSlotArea(2, a_ParentWindow),
m_Horse(a_Horse)
{
}
void cSlotAreaHorse::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem)
{
cItem & DraggingItem = a_Player.GetDraggingItem();
switch (a_ClickAction)
{
case caLeftClick:
case caRightClick:
case caDblClick:
{
// Check for invalid item types
if (DraggingItem.IsEmpty())
{
break;
}
switch (a_SlotNum)
{
case SaddleSlot:
{
if (DraggingItem.m_ItemType != E_ITEM_SADDLE)
{
return;
}
}
case ArmorSlot:
{
if (!ItemCategory::IsHorseArmor(DraggingItem.m_ItemType))
{
return;
}
}
default: break;
}
}
default: break;
}
cSlotArea::Clicked(a_Player, a_SlotNum, a_ClickAction, a_ClickedItem);
}
const cItem * cSlotAreaHorse::GetSlot(int a_SlotNum, cPlayer & a_Player) const
{
static const cItem InvalidItem;
switch (a_SlotNum)
{
case SaddleSlot: return &m_Horse.GetHorseSaddle();
case ArmorSlot: return &m_Horse.GetHorseArmorItem();
default:
{
LOGWARN("cSlotAreaHorse::GetSlot: Invalid slot number %d", a_SlotNum);
return &InvalidItem;
}
}
}
void cSlotAreaHorse::SetSlot(int a_SlotNum, cPlayer & a_Player, const cItem & a_Item)
{
switch (a_SlotNum)
{
case SaddleSlot: m_Horse.SetHorseSaddle(a_Item); break;
case ArmorSlot: m_Horse.SetHorseArmor(a_Item); break;
default:
{
LOGWARN("cSlotAreaHorse::SetSlot: Invalid slot number %d", a_SlotNum);
}
}
}
void cSlotAreaHorse::DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_ShouldApply, bool a_KeepEmptySlots, bool a_BackFill)
{
if (ItemCategory::IsHorseArmor(a_ItemStack.m_ItemType) && m_Horse.GetHorseArmorItem().IsEmpty())
{
if (a_ShouldApply)
{
m_Horse.SetHorseArmor(a_ItemStack.CopyOne());
}
--a_ItemStack.m_ItemCount;
}
else if ((a_ItemStack.m_ItemType == E_ITEM_SADDLE) && !m_Horse.IsSaddled())
{
if (a_ShouldApply)
{
m_Horse.SetHorseSaddle(a_ItemStack.CopyOne());
}
--a_ItemStack.m_ItemCount;
}
}