1
0
Fork 0

Add armor items directly to the armor slots.

This commit is contained in:
Howaner 2014-07-20 01:22:58 +02:00
parent e32b0ce4fa
commit 897d68dc35
3 changed files with 16 additions and 3 deletions

View File

@ -103,6 +103,19 @@ int cInventory::AddItem(const cItem & a_Item, bool a_AllowNewStacks, bool a_tryT
cItem ToAdd(a_Item);
int res = 0;
// When the item is a armor, try to set it directly to the armor slot.
if (ItemCategory::IsArmor(a_Item.m_ItemType))
{
for (size_t i = 0; i < (size_t)m_ArmorSlots.GetNumSlots(); i++)
{
if (m_ArmorSlots.GetSlot(i).IsEmpty() && cSlotAreaArmor::CanPlaceArmorInSlot(i, a_Item))
{
m_ArmorSlots.SetSlot(i, a_Item);
return a_Item.m_ItemCount;
}
}
}
res += m_HotbarSlots.AddItem(ToAdd, a_AllowNewStacks, a_tryToFillEquippedFirst ? m_EquippedSlotNum : -1);
ToAdd.m_ItemCount = a_Item.m_ItemCount - res;
if (ToAdd.m_ItemCount == 0)

View File

@ -1926,7 +1926,7 @@ void cSlotAreaArmor::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_C
return;
}
if (DraggingItem.IsEmpty() || CanPlaceInSlot(a_SlotNum, DraggingItem))
if (DraggingItem.IsEmpty() || CanPlaceArmorInSlot(a_SlotNum, DraggingItem))
{
// Swap contents
cItem tmp(DraggingItem);
@ -1945,7 +1945,7 @@ void cSlotAreaArmor::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_C
bool cSlotAreaArmor::CanPlaceInSlot(int a_SlotNum, const cItem & a_Item)
bool cSlotAreaArmor::CanPlaceArmorInSlot(int a_SlotNum, const cItem & a_Item)
{
switch (a_SlotNum)
{

View File

@ -161,7 +161,7 @@ public:
/** Called when a player clicks in the window. Parameters taken from the click packet. */
virtual void Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) override;
bool CanPlaceInSlot(int a_SlotNum, const cItem & a_Item);
static bool CanPlaceArmorInSlot(int a_SlotNum, const cItem & a_Item);
} ;