diff --git a/src/ProtocolCode.lua b/src/ProtocolCode.lua index c137a00..2cc7eb7 100644 --- a/src/ProtocolCode.lua +++ b/src/ProtocolCode.lua @@ -100,6 +100,7 @@ actionCodes = { Hang_startBonusBattleRpc = 260, Hang_endBonusBattleRpc = 261, Hang_hangGiftRpc = 262, + Hang_bagFieldRpc = 263, Diner_updateProperty = 300, Diner_addSellRpc = 301, diff --git a/src/actions/HangAction.lua b/src/actions/HangAction.lua index 26acbaf..ce1d6ff 100644 --- a/src/actions/HangAction.lua +++ b/src/actions/HangAction.lua @@ -40,20 +40,54 @@ local function checkReward(role) for _, temp in pairs(carbonData.item:toArray()) do table.insert(pool, temp:toArray(true, "=")) end - local curTypeCount = 0 - for id, _ in pairs(items) do + local curFC = 0 + local curIC = 0 + for id, count in pairs(items) do if id ~= ItemId.Gold and id ~= ItemId.Exp and id ~= ItemId.PlayerExp then - curTypeCount = curTypeCount + 1 + curFC = curFC + math.ceil(count / globalCsv.idle_field_limit) + curIC = curIC + count end end - for i = 1, itemCount do - local cur = pool[math.randWeight(pool, 3)] - if items[cur[1]] or curTypeCount < role:getProperty("hangBagLimit") then - if not items[cur[1]] then - curTypeCount = curTypeCount + 1 + local selfFC = role:getProperty("hangBagLimit") --再加上月卡的栏位 TODO + local selfIC = selfFC * globalCsv.idle_field_limit + + local function randomItem() + if curIC >= selfIC then + return + end + local tempPool = clone(pool) + while #tempPool > 0 do + local idx = math.randWeight(tempPool, 3) + local cur = pool[idx] + if (items[cur[1]] and math.ceil((items[cur[1]] + cur[2]) / globalCsv.idle_field_limit) > math.ceil(items[cur[1]] / globalCsv.idle_field_limit)) + or not items[cur[1]] then --要占用新栏位的情况 + local addFC + if not items[cur[1]] then + addFC = math.ceil(cur[2] / globalCsv.idle_field_limit) + else + local frontC = items[cur[1]] % globalCsv.idle_field_limit + if frontC == 0 then + frontC = globalCsv.idle_field_limit + end + addFC = math.ceil((cur[2] - (globalCsv.idle_field_limit - frontC)) / globalCsv.idle_field_limit) + end + if curFC + addFC <= selfFC then + curFC = curFC + addFC + items[cur[1]] = (items[cur[1]] or 0) + cur[2] + break + else + --加不了,换别的东西 + table.remove(tempPool, idx) + end + else + items[cur[1]] = items[cur[1]] + cur[2] + break end - items[cur[1]] = (items[cur[1]] or 0) + cur[2] end + curIC = curIC + 1 + end + for i = 1, itemCount do + randomItem() end if coinCount > 0 or itemCount > 0 then @@ -61,8 +95,6 @@ local function checkReward(role) end end - - --开始一个新的关卡 function _M.startRpc( agent, data ) local role = agent.role @@ -511,5 +543,20 @@ function _M.hangGiftRpc(agent, data) return true end +function _M.bagFieldRpc(agent, data) + local role = agent.role + local curBL = role:getProperty("hangBagLimit") + local costD = globalCsv.idle_field_cost[curBL - globalCsv.idle_field_origin] + if not costD then + return 1 + end + if costD ~= 0 and not role:checkItemEnough({[ItemId.Diamond] = costD}) then + return 2 + end + role:updateProperty({field = "hangBagLimit", value = curBL + 1}) + role:costItems({[ItemId.Diamond] = costD}, {log = {desc = "bagField"}}) + SendPacket(actionCodes.Hang_bagFieldRpc, '') + return true +end return _M \ No newline at end of file -- libgit2 0.21.2