Fix market issue with non stackable items.

This commit is contained in:
BeniS 2012-07-31 21:47:24 +12:00
parent f4641333f4
commit 82bfdc566f
1 changed files with 49 additions and 34 deletions

View File

@ -358,6 +358,7 @@ local function updateDepotItemCount(itemId, amount)
if depotItem and itemId == depotItem.ptr:getId() then if depotItem and itemId == depotItem.ptr:getId() then
local depotItemCount = depotItem.ptr:getCount() local depotItemCount = depotItem.ptr:getCount()
if depotItem.ptr:isStackable() then
if depotItemCount <= 100 and depotItemCount >= amount then if depotItemCount <= 100 and depotItemCount >= amount then
if (depotItemCount - amount) <= 0 then if (depotItemCount - amount) <= 0 then
table.remove(information.depotItems, i) table.remove(information.depotItems, i)
@ -372,8 +373,8 @@ local function updateDepotItemCount(itemId, amount)
if remainder > 0 then if remainder > 0 then
removeCount = removeCount + 1 removeCount = removeCount + 1
end end
for i = 1, removeCount do for j = 1, removeCount do
if i == removeCount and remainder > 0 then if j == removeCount and remainder > 0 then
updateDepotItemCount(itemId, remainder) updateDepotItemCount(itemId, remainder)
else else
updateDepotItemCount(itemId, 100) updateDepotItemCount(itemId, 100)
@ -381,9 +382,16 @@ local function updateDepotItemCount(itemId, amount)
end end
return true return true
end end
else
if amount > 0 then
table.remove(information.depotItems, i)
amount = amount - 1
end end
end end
end end
end
return false
end
local function updateFee(price, amount) local function updateFee(price, amount)
fee = math.ceil(price / 100 * amount) fee = math.ceil(price / 100 * amount)
@ -873,6 +881,8 @@ function Market.loadDepotItems(depotItems)
local data = depotItems[i] local data = depotItems[i]
local id, count = data[1], data[2] local id, count = data[1], data[2]
local tmpItem = Item.create(id)
if tmpItem:isStackable() then
if count > 100 then if count > 100 then
local createCount = math.floor(count/100) local createCount = math.floor(count/100)
local remainder = count % 100 local remainder = count % 100
@ -893,6 +903,11 @@ function Market.loadDepotItems(depotItems)
newItem:setCount(count) newItem:setCount(count)
table.insert(items, newItem) table.insert(items, newItem)
end end
else
for i = 1, count do
table.insert(items, Item.create(id))
end
end
end end
for _, newItem in pairs(items) do for _, newItem in pairs(items) do