Skip to content

Commit

Permalink
configurable itemtype stack size
Browse files Browse the repository at this point in the history
  • Loading branch information
ArturKnopik committed Nov 24, 2024
1 parent be19380 commit 436710e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
43 changes: 27 additions & 16 deletions data/npc/lib/npc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,39 @@ function doNpcSellItem(cid, itemid, amount, subType, ignoreCap, inBackpacks, bac
local subType = subType or 0
local startingAmount = amount
local result = RETURNVALUE_NOERROR

local bpSize = 20
local itemType = ItemType(itemid)

if itemType:isStackable() then
local stuff
local bpsToAdd = math.ceil(amount / itemType:getStackSize() / bpSize)
if inBackpacks then
stuff = Game.createItem(backpack, 1)
local itemAdded = true
while startingAmount > 0 and itemAdded do
local item = stuff:addItem(itemid, math.min(itemType:getStackSize(), startingAmount))
if item then
print("item Added")
startingAmount = startingAmount - math.min(itemType:getStackSize(), startingAmount)
itemAdded = true
else
print("item Not Added")
itemAdded = false
local bps = {}
for i = 1, bpsToAdd, 1 do
stuff = Game.createItem(backpack, 1)
local itemAdded = true
while startingAmount > 0 and itemAdded do
local item = stuff:addItem(itemid, math.min(itemType:getStackSize(), startingAmount))
if item then
startingAmount = startingAmount - math.min(itemType:getStackSize(), startingAmount)
itemAdded = true
else
itemAdded = false
end
end
bps[i] = stuff
end
for i = 1, bpsToAdd, 1 do
result = result and Player(cid):addItemEx(bps[i], ignoreCap)
end

if result ~= RETURNVALUE_NOERROR then
for i = 1, bpsToAdd, 1 do
if bps[i] then
bps[i]:remove()
end
end
end
print(startingAmount)
result = Player(cid):addItemEx(stuff, ignoreCap)
else
while startingAmount > 0 and result == RETURNVALUE_NOERROR do
stuff = Game.createItem(itemid, math.min(itemType:getStackSize(), startingAmount))
Expand All @@ -47,8 +60,6 @@ function doNpcSellItem(cid, itemid, amount, subType, ignoreCap, inBackpacks, bac
end
end

print(result)

return result ~= RETURNVALUE_NOERROR and 0 or amount - startingAmount, 0
end

Expand Down
2 changes: 1 addition & 1 deletion src/container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ Cylinder* Container::queryDestination(int32_t& index, const Thing& thing, Item**
// try find a suitable item to stack with
uint32_t n = 0;
for (Item* listItem : itemlist) {
if (listItem != item && listItem->equals(item) && listItem->getItemCount() < (*destItem)->getStackSize()) {
if (listItem != item && listItem->equals(item) && listItem->getItemCount() < item->getStackSize()) {
*destItem = listItem;
index = n;
return this;
Expand Down

0 comments on commit 436710e

Please sign in to comment.