From: <rds...@us...> - 2007-12-03 06:15:26
|
Revision: 352 http://planeshift.svn.sourceforge.net/planeshift/?rev=352&view=rev Author: rdschulz Date: 2007-12-02 22:15:31 -0800 (Sun, 02 Dec 2007) Log Message: ----------- - Fix size check for adding items to stacks in container in inventory, thanks again to Rakhun (FS#690). Modified Paths: -------------- trunk/docs/history.txt trunk/src/server/bulkobjects/pscharinventory.cpp trunk/src/server/bulkobjects/pscharinventory.h Modified: trunk/docs/history.txt =================================================================== --- trunk/docs/history.txt 2007-12-03 03:27:59 UTC (rev 351) +++ trunk/docs/history.txt 2007-12-03 06:15:31 UTC (rev 352) @@ -8,6 +8,8 @@ - Add armor making skill as requested by TomT. - Added NO_RANDOM_QUALITY define to workmanager for testing crafting. - Added combine button to paws container window. +- Fix size check for adding items to stacks in container in inventory, + thanks again to Rakhun (FS#690). *** 2007-12-02 by Andrew Craig - Some code formatting clean ups and fixed a crash when Modified: trunk/src/server/bulkobjects/pscharinventory.cpp =================================================================== --- trunk/src/server/bulkobjects/pscharinventory.cpp 2007-12-03 03:27:59 UTC (rev 351) +++ trunk/src/server/bulkobjects/pscharinventory.cpp 2007-12-03 06:15:31 UTC (rev 352) @@ -504,6 +504,19 @@ return SIZET_NOT_FOUND; } +csArray<size_t> psCharacterInventory::FindCompatibleStackedItems(psItem *item) +{ + csArray<size_t> compatibleItems; + for (size_t i=1; i<inventory.GetSize(); i++) + { + if (inventory[i].item->CheckStackableWith(item, true)) + { + compatibleItems.Push(i); + } + } + return compatibleItems; +} + INVENTORY_SLOT_NUMBER psCharacterInventory::FindFreeEquipSlot(psItem* itemToPlace) { csArray<INVENTORY_SLOT_NUMBER> fitsIn; @@ -590,34 +603,44 @@ */ size_t i; size_t itemIndex = SIZET_NOT_FOUND; + csArray<size_t> itemIndices; // Next see if we can stack this with an existing stack in inventory if (stack && slot == ANY_BULK_SLOT && item->GetIsStackable()) { - itemIndex = FindCompatibleStackedItem(item); - if (itemIndex != SIZET_NOT_FOUND) // Found a compatible one + + itemIndices = FindCompatibleStackedItems(item); + for (i=0; i<itemIndices.GetSize(); i++) { - if (test) - return true; // not really doing it here + int size=0; + if(inventory[itemIndices[i]].item->GetContainerID()){ + size = GetContainedSize(FindItemID(inventory[itemIndices[i]].item->GetContainerID())); + } + if (!inventory[itemIndices[i]].item->GetContainerID() || size + item->GetTotalStackSize() <= FindItemID(inventory[itemIndices[i]].item->GetContainerID())->GetContainerMaxSize()) // adequate space in container + { + if (test) + return true; // not really doing it here - inventory[itemIndex].item->CombineStack(item); + inventory[itemIndices[i]].item->CombineStack(item); - // Here we update the passed in parameter so it points at the merged stack instead of the item that is gone now - item = inventory[itemIndex].item; + // Here we update the passed in parameter so it points at the merged stack instead of the item that is gone now + item = inventory[itemIndices[i]].item; - // Save new combined stack to db - inventory[itemIndex].item->Save(true); + // Save new combined stack to db + inventory[itemIndices[i]].item->Save(true); - UpdateEncumbrance(); + UpdateEncumbrance(); - if (owner->IsNPC() || owner->IsPet()) - psserver->GetNPCManager()->QueueInventoryPerception(owner->GetActor(), item, true); - - return true; + if (owner->IsNPC() || owner->IsPet()) + psserver->GetNPCManager()->QueueInventoryPerception(owner->GetActor(), item, true); + return true; + } } } + itemIndex = SIZET_NOT_FOUND; // We need to reset this in case a stack was found, but the container it was in was full + // Next check the main bulk slots if (itemIndex == SIZET_NOT_FOUND && slot < 0) { @@ -672,7 +695,7 @@ if (inventory[i].item->GetIsContainer()) { int size = GetContainedSize(inventory[i].item); - if (size + item->GetTotalStackSize() < inventory[i].item->GetContainerMaxSize()) // adequate space in container + if (size + item->GetTotalStackSize() <= inventory[i].item->GetContainerMaxSize()) // adequate space in container { INVENTORY_SLOT_NUMBER containerSlot = (INVENTORY_SLOT_NUMBER)FindFirstOpenSlot(inventory[i].item); if (containerSlot == PSCHARACTER_SLOT_NONE) Modified: trunk/src/server/bulkobjects/pscharinventory.h =================================================================== --- trunk/src/server/bulkobjects/pscharinventory.h 2007-12-03 03:27:59 UTC (rev 351) +++ trunk/src/server/bulkobjects/pscharinventory.h 2007-12-03 06:15:31 UTC (rev 352) @@ -398,6 +398,11 @@ */ size_t FindCompatibleStackedItem(psItem *item); + /** Returns an array of array indices for items that match the specified + * ones, so they can be combined. + */ + csArray<size_t> FindCompatibleStackedItems(psItem *item); + /// Allocate either a psItem or a psGlyph psItem *GetItemFactory(psItemStats *stats); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |