summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-rw-r--r--source/Inventory.cpp37
-rw-r--r--source/Inventory.h1
-rw-r--r--source/Pickup.cpp8
-rw-r--r--source/Player.cpp11
-rw-r--r--source/UI/SlotArea.cpp3
5 files changed, 52 insertions, 8 deletions
diff --git a/source/Inventory.cpp b/source/Inventory.cpp
index 5ed2e0763..9417f6a14 100644
--- a/source/Inventory.cpp
+++ b/source/Inventory.cpp
@@ -89,6 +89,36 @@ bool cInventory::AddItem( cItem & a_Item )
+bool cInventory::AddItemAnyAmount( cItem & a_Item )
+{
+ bool ChangedSlots[c_NumSlots];
+ memset( ChangedSlots, false, c_NumSlots * sizeof( bool ) );
+
+ char StartCount = a_Item.m_ItemCount;
+ if( a_Item.m_ItemCount > 0 ) AddToBar( a_Item, c_HotOffset, c_HotSlots, ChangedSlots, 0 );
+ if( a_Item.m_ItemCount > 0 ) AddToBar( a_Item, c_MainOffset, c_MainSlots, ChangedSlots, 0 );
+ if( a_Item.m_ItemCount > 0 ) AddToBar( a_Item, c_HotOffset, c_HotSlots, ChangedSlots, 2 );
+ if( a_Item.m_ItemCount > 0 ) AddToBar( a_Item, c_MainOffset, c_MainSlots, ChangedSlots, 2 );
+
+ if (a_Item.m_ItemCount == StartCount)
+ return false;
+
+ for (unsigned int i = 0; i < c_NumSlots; i++)
+ {
+ if (ChangedSlots[i])
+ {
+ LOGD("cInventory::AddItemAnyAmount(): Item was added to %i ID:%i Count:%i", i, m_Slots[i].m_ItemID, m_Slots[i].m_ItemCount);
+ SendSlot(i);
+ }
+ }
+
+ return true;
+}
+
+
+
+
+
// TODO: Right now if you dont have enough items, the items you did have are removed, and the function returns false anyway
bool cInventory::RemoveItem( cItem & a_Item )
{
@@ -347,11 +377,12 @@ bool cInventory::AddToBar( cItem & a_Item, const int a_Offset, const int a_Size,
// Fill already present stacks
if( a_Mode < 2 )
{
+ int MaxStackSize = cItemHandler::GetItemHandler(a_Item.m_ItemType)->GetMaxStackSize();
for(int i = 0; i < a_Size; i++)
{
- if( m_Slots[i + a_Offset].m_ItemID == a_Item.m_ItemID && m_Slots[i + a_Offset].m_ItemCount < 64 && m_Slots[i + a_Offset].m_ItemHealth == a_Item.m_ItemHealth )
+ if( m_Slots[i + a_Offset].m_ItemType == a_Item.m_ItemType && m_Slots[i + a_Offset].m_ItemCount < MaxStackSize && m_Slots[i + a_Offset].m_ItemHealth == a_Item.m_ItemHealth )
{
- int NumFree = 64 - m_Slots[i + a_Offset].m_ItemCount;
+ int NumFree = MaxStackSize - m_Slots[i + a_Offset].m_ItemCount;
if( NumFree >= a_Item.m_ItemCount )
{
@@ -377,7 +408,7 @@ bool cInventory::AddToBar( cItem & a_Item, const int a_Offset, const int a_Size,
// If we got more left, find first empty slot
for(int i = 0; i < a_Size && a_Item.m_ItemCount > 0; i++)
{
- if( m_Slots[i + a_Offset].m_ItemID == -1 )
+ if( m_Slots[i + a_Offset].m_ItemType == -1 )
{
m_Slots[i + a_Offset] = a_Item;
a_Item.m_ItemCount = 0;
diff --git a/source/Inventory.h b/source/Inventory.h
index 1dd22deec..bc6cb27f3 100644
--- a/source/Inventory.h
+++ b/source/Inventory.h
@@ -31,6 +31,7 @@ public:
int GetSlotCountForType( int a_Type );
bool AddItem( cItem & a_Item ); //tolua_export
+ bool AddItemAnyAmount( cItem & a_Item ); //tolua_export
bool RemoveItem( cItem & a_Item ); //tolua_export
void SaveToJson(Json::Value & a_Value);
diff --git a/source/Pickup.cpp b/source/Pickup.cpp
index ea1f603a4..7ea730708 100644
--- a/source/Pickup.cpp
+++ b/source/Pickup.cpp
@@ -256,12 +256,16 @@ bool cPickup::CollectedBy( cPlayer* a_Dest )
return false;
}
- if (a_Dest->GetInventory().AddItem(*m_Item))
+ if (a_Dest->GetInventory().AddItemAnyAmount(*m_Item))
{
m_World->BroadcastCollectPickup(*this, *a_Dest);
-
m_bCollected = true;
m_Timer = 0;
+ if( m_Item->m_ItemCount != 0 ) {
+ cItems Pickup;
+ Pickup.push_back(cItem(*m_Item));
+ m_World->SpawnItemPickups(Pickup, m_Pos.x, m_Pos.y, m_Pos.z);
+ }
return true;
}
diff --git a/source/Player.cpp b/source/Player.cpp
index c7784c1b0..708eca9f4 100644
--- a/source/Player.cpp
+++ b/source/Player.cpp
@@ -443,6 +443,11 @@ void cPlayer::CloseWindow(char a_WindowType)
if (m_CurrentWindow == m_InventoryWindow)
{
// The inventory window must not be closed and must not be even sent a close packet
+ if (IsDraggingItem()) // But we need to check if player is holding anything
+ {
+ LOGD("Player holds item in inventory window! Dropping it...");
+ TossItem(true, GetDraggingItem().m_ItemCount);
+ }
return;
}
@@ -791,10 +796,12 @@ void cPlayer::TossItem(
cItem & Item = GetDraggingItem();
if (!Item.IsEmpty())
{
+ char OriginalItemAmount = Item.m_ItemCount;
+ Item.m_ItemCount = MIN(OriginalItemAmount, a_Amount);
Drops.push_back(Item);
- if (Item.m_ItemCount > a_Amount)
+ if (OriginalItemAmount > a_Amount)
{
- Item.m_ItemCount -= (char)a_Amount;
+ Item.m_ItemCount = OriginalItemAmount - (char)a_Amount;
}
else
{
diff --git a/source/UI/SlotArea.cpp b/source/UI/SlotArea.cpp
index ec1192f2c..4b6d237ba 100644
--- a/source/UI/SlotArea.cpp
+++ b/source/UI/SlotArea.cpp
@@ -138,11 +138,12 @@ void cSlotArea::Clicked(cPlayer & a_Player, int a_SlotNum, bool a_IsRightClick,
}
}
+ SetSlot(a_SlotNum, a_Player, Slot);
if (bAsync)
{
m_ParentWindow.BroadcastWholeWindow();
}
- SetSlot(a_SlotNum, a_Player, Slot);
+
}