1
0
This commit is contained in:
Tiger Wang 2015-05-18 14:30:16 +01:00
parent 007bac638b
commit 0dbba305b6
6 changed files with 33 additions and 16 deletions

View File

@ -228,6 +228,7 @@ bool cPickup::CollectedBy(cPlayer & a_Dest)
m_Item.m_ItemCount -= NumAdded;
m_World->BroadcastCollectEntity(*this, a_Dest);
// Also send the "pop" sound effect with a somewhat random pitch (fast-random using EntityID ;)
m_World->BroadcastSoundEffect("random.pop", GetPosX(), GetPosY(), GetPosZ(), 0.5, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64));
if (m_Item.m_ItemCount <= 0)

View File

@ -98,7 +98,7 @@ int cInventory::HowManyCanFit(const cItem & a_ItemStack, int a_BeginSlotNum, int
int cInventory::AddItem(const cItem & a_Item, bool a_AllowNewStacks, bool a_tryToFillEquippedFirst)
int cInventory::AddItem(const cItem & a_Item, bool a_AllowNewStacks)
{
cItem ToAdd(a_Item);
int res = 0;
@ -116,8 +116,30 @@ int cInventory::AddItem(const cItem & a_Item, bool a_AllowNewStacks, bool a_tryT
}
}
res += m_HotbarSlots.AddItem(ToAdd, a_AllowNewStacks, a_tryToFillEquippedFirst ? m_EquippedSlotNum : -1);
for (int SlotIdx = 0; SlotIdx < m_InventorySlots.GetNumSlots(); ++SlotIdx)
{
auto & Slot = m_InventorySlots.GetSlot(SlotIdx);
if (Slot.IsEqual(a_Item))
{
cItemHandler Handler(Slot.m_ItemType);
int AmountToAdd = std::min(static_cast<char>(Handler.GetMaxStackSize() - Slot.m_ItemCount), ToAdd.m_ItemCount);
res += AmountToAdd;
cItem SlotAdjusted(Slot);
SlotAdjusted.m_ItemCount += AmountToAdd;
m_InventorySlots.SetSlot(SlotIdx, SlotAdjusted);
ToAdd.m_ItemCount -= AmountToAdd;
if (ToAdd.m_ItemCount == 0)
{
return res;
}
}
}
res += m_HotbarSlots.AddItem(ToAdd, a_AllowNewStacks);
ToAdd.m_ItemCount = a_Item.m_ItemCount - res;
if (ToAdd.m_ItemCount == 0)
{
return res;
@ -131,12 +153,12 @@ int cInventory::AddItem(const cItem & a_Item, bool a_AllowNewStacks, bool a_tryT
int cInventory::AddItems(cItems & a_ItemStackList, bool a_AllowNewStacks, bool a_tryToFillEquippedFirst)
int cInventory::AddItems(cItems & a_ItemStackList, bool a_AllowNewStacks)
{
int TotalAdded = 0;
for (cItems::iterator itr = a_ItemStackList.begin(); itr != a_ItemStackList.end();)
{
int NumAdded = AddItem(*itr, a_AllowNewStacks, a_tryToFillEquippedFirst);
int NumAdded = AddItem(*itr, a_AllowNewStacks);
if (itr->m_ItemCount == NumAdded)
{
itr = a_ItemStackList.erase(itr);

View File

@ -70,23 +70,17 @@ public:
/** Adds as many items out of a_ItemStack as can fit.
If a_AllowNewStacks is set to false, only existing stacks can be topped up;
if a_AllowNewStacks is set to true, empty slots can be used for the rest.
If a_tryToFillEquippedFirst is set to true, the currently equipped slot will be used first (if empty or
compatible with added items)
if a_tryToFillEquippedFirst is set to false, the regular order applies.
Returns the number of items that fit.
*/
int AddItem(const cItem & a_ItemStack, bool a_AllowNewStacks = true, bool a_tryToFillEquippedFirst = false);
int AddItem(const cItem & a_ItemStack, bool a_AllowNewStacks = true);
/** Same as AddItem, but works on an entire list of item stacks.
The a_ItemStackList is modified to reflect the leftover items.
If a_AllowNewStacks is set to false, only existing stacks can be topped up;
if a_AllowNewStacks is set to true, empty slots can be used for the rest.
If a_tryToFillEquippedFirst is set to true, the currently equipped slot will be used first (if empty or
compatible with added items)
if a_tryToFillEquippedFirst is set to false, the regular order applies.
Returns the total number of items that fit.
*/
int AddItems(cItems & a_ItemStackList, bool a_AllowNewStacks, bool a_tryToFillEquippedFirst);
int AddItems(cItems & a_ItemStackList, bool a_AllowNewStacks);
/** Removes the specified item from the inventory, as many as possible, up to a_ItemStack.m_ItemCount.
Returns the number of items that were removed. */

View File

@ -96,7 +96,7 @@ public:
ASSERT(!"Inventory bucket mismatch");
return true;
}
if (a_Player->GetInventory().AddItem(cItem(NewItem), true, true) != 1)
if (a_Player->GetInventory().AddItem(cItem(NewItem)) != 1)
{
// The bucket didn't fit, toss it as a pickup:
a_Player->TossPickup(cItem(NewItem));
@ -137,7 +137,7 @@ public:
return false;
}
cItem Item(E_ITEM_BUCKET, 1);
if (!a_Player->GetInventory().AddItem(Item, true, true))
if (!a_Player->GetInventory().AddItem(Item))
{
return false;
}

View File

@ -60,7 +60,7 @@ public:
return true;
}
a_Player->GetInventory().AddItem(cItem(E_ITEM_MAP, 1, (short)(NewMap->GetID() & 0x7fff)), true, true);
a_Player->GetInventory().AddItem(cItem(E_ITEM_MAP, 1, (short)(NewMap->GetID() & 0x7fff)));
return true;
}

View File

@ -41,7 +41,7 @@ public:
// Return a bowl to the inventory
if (!a_Player->IsGameModeCreative())
{
a_Player->GetInventory().AddItem(cItem(E_ITEM_BOWL), true, true);
a_Player->GetInventory().AddItem(cItem(E_ITEM_BOWL));
}
return true;
}