From 82bfdc566fe791f2c62a90e72fcf8ebf8ada0eb1 Mon Sep 17 00:00:00 2001 From: BeniS Date: Tue, 31 Jul 2012 21:47:24 +1200 Subject: [PATCH] Fix market issue with non stackable items. --- modules/game_market/market.lua | 83 ++++++++++++++++++++-------------- 1 file changed, 49 insertions(+), 34 deletions(-) diff --git a/modules/game_market/market.lua b/modules/game_market/market.lua index 875a15f7..1aa5b0d3 100644 --- a/modules/game_market/market.lua +++ b/modules/game_market/market.lua @@ -358,31 +358,39 @@ local function updateDepotItemCount(itemId, amount) if depotItem and itemId == depotItem.ptr:getId() then local depotItemCount = depotItem.ptr:getCount() - if depotItemCount <= 100 and depotItemCount >= amount then - if (depotItemCount - amount) <= 0 then - table.remove(information.depotItems, i) - else - depotItem.ptr:setCount(depotItemCount - amount) - information.depotItems[i] = depotItem - end - return true - else - local removeCount = math.floor(amount/100) - local remainder = amount % depotItemCount - if remainder > 0 then - removeCount = removeCount + 1 - end - for i = 1, removeCount do - if i == removeCount and remainder > 0 then - updateDepotItemCount(itemId, remainder) + if depotItem.ptr:isStackable() then + if depotItemCount <= 100 and depotItemCount >= amount then + if (depotItemCount - amount) <= 0 then + table.remove(information.depotItems, i) else - updateDepotItemCount(itemId, 100) + depotItem.ptr:setCount(depotItemCount - amount) + information.depotItems[i] = depotItem end + return true + else + local removeCount = math.floor(amount/100) + local remainder = amount % depotItemCount + if remainder > 0 then + removeCount = removeCount + 1 + end + for j = 1, removeCount do + if j == removeCount and remainder > 0 then + updateDepotItemCount(itemId, remainder) + else + updateDepotItemCount(itemId, 100) + end + end + return true + end + else + if amount > 0 then + table.remove(information.depotItems, i) + amount = amount - 1 end - return true end end end + return false end local function updateFee(price, amount) @@ -873,25 +881,32 @@ function Market.loadDepotItems(depotItems) local data = depotItems[i] local id, count = data[1], data[2] - if count > 100 then - local createCount = math.floor(count/100) - local remainder = count % 100 - if remainder > 0 then - createCount = createCount + 1 - end - for i = 1, createCount do - local newItem = Item.create(id) - if i == createCount and remainder > 0 then - newItem:setCount(remainder) - else - newItem:setCount(100) + local tmpItem = Item.create(id) + if tmpItem:isStackable() then + if count > 100 then + local createCount = math.floor(count/100) + local remainder = count % 100 + if remainder > 0 then + createCount = createCount + 1 end + for i = 1, createCount do + local newItem = Item.create(id) + if i == createCount and remainder > 0 then + newItem:setCount(remainder) + else + newItem:setCount(100) + end + table.insert(items, newItem) + end + else + local newItem = Item.create(id) + newItem:setCount(count) table.insert(items, newItem) end else - local newItem = Item.create(id) - newItem:setCount(count) - table.insert(items, newItem) + for i = 1, count do + table.insert(items, Item.create(id)) + end end end