diff --git a/src/actions/StoreAction.lua b/src/actions/StoreAction.lua index 919d998..da3b4e0 100644 --- a/src/actions/StoreAction.lua +++ b/src/actions/StoreAction.lua @@ -365,7 +365,7 @@ function _M.shopBuyRpc(agent , data) local id = msg.id local count = msg.count or 1 - local dataSet = csvdb["shop_normalCsv"][id] + local dataSet = csvdb["shop_normalCsv"][id] if not dataSet then return end if dataSet.unlock ~= "" then @@ -382,20 +382,13 @@ function _M.shopBuyRpc(agent , data) if not role.activity:isOpenById(dataSet.activity_id, "ActShopGoods") then return 3 end end - local buyRecord = role.storeData:getProperty("buyR") - if math.illegalNum(count, 1, (dataSet.limit == 0 and 10000 or dataSet.limit - (buyRecord[id] or 0))) then - skynet.error(string.format("shop buy over limit, user_id:%d, goods_id:%d", role:getProperty("id"), id)) - return 6 - end - - local cost - if dataSet.disount == 0 then + local cost + if dataSet.disount == 0 then cost = {[dataSet.icon] = math.ceil(dataSet.cost * count)} else cost = {[dataSet.icon] = math.ceil(dataSet.cost * count * ((dataSet.disount or 10) / 10))} end - local desc = "unknowShop" if dataSet.shop == 1 then -- 普通商店 desc = "dailyShop" @@ -406,14 +399,20 @@ function _M.shopBuyRpc(agent , data) end if not role:checkItemEnough(cost) then return 4 end + if not role:costItems(cost, {log = {desc = desc, int1 = id, int2 = count, long1= dataSet.shop}}) then return 5 end - local limitStr = "" + local buyRecord = role.storeData:getProperty("buyR") + if math.illegalNum(count, 1, (dataSet.limit == 0 and 10000 or dataSet.limit - (buyRecord[id] or 0))) then + skynet.error(string.format("shop buy over limit, user_id:%d, goods_id:%d", role:getProperty("id"), id)) + return 6 + end + + local limitStr = "" if dataSet.limit ~= 0 then buyRecord[id] = (buyRecord[id] or 0) + count role.storeData:updateProperty({field = "buyR", value = buyRecord}) - limitStr = string.format("%s/%s", buyRecord[id], dataSet.limit) + limitStr = string.format("%s/%s", buyRecord[id], dataSet.limit) end - if not role:costItems(cost, {log = {desc = desc, int1 = id, int2 = count, long1= dataSet.shop}}) then return 5 end local gift = {} for _id, _count in pairs(dataSet.gift:toNumMap()) do -- libgit2 0.21.2