Commit 64e63ad06f9ae0501b1e1bd193f00d46684f8bfe
1 parent
759669cc
完成需求:挂机栏位物品数量上限和钻石购买栏位
Showing
2 changed files
with
59 additions
and
11 deletions
Show diff stats
src/ProtocolCode.lua
| @@ -100,6 +100,7 @@ actionCodes = { | @@ -100,6 +100,7 @@ actionCodes = { | ||
| 100 | Hang_startBonusBattleRpc = 260, | 100 | Hang_startBonusBattleRpc = 260, |
| 101 | Hang_endBonusBattleRpc = 261, | 101 | Hang_endBonusBattleRpc = 261, |
| 102 | Hang_hangGiftRpc = 262, | 102 | Hang_hangGiftRpc = 262, |
| 103 | + Hang_bagFieldRpc = 263, | ||
| 103 | 104 | ||
| 104 | Diner_updateProperty = 300, | 105 | Diner_updateProperty = 300, |
| 105 | Diner_addSellRpc = 301, | 106 | Diner_addSellRpc = 301, |
src/actions/HangAction.lua
| @@ -40,20 +40,54 @@ local function checkReward(role) | @@ -40,20 +40,54 @@ local function checkReward(role) | ||
| 40 | for _, temp in pairs(carbonData.item:toArray()) do | 40 | for _, temp in pairs(carbonData.item:toArray()) do |
| 41 | table.insert(pool, temp:toArray(true, "=")) | 41 | table.insert(pool, temp:toArray(true, "=")) |
| 42 | end | 42 | end |
| 43 | - local curTypeCount = 0 | ||
| 44 | - for id, _ in pairs(items) do | 43 | + local curFC = 0 |
| 44 | + local curIC = 0 | ||
| 45 | + for id, count in pairs(items) do | ||
| 45 | if id ~= ItemId.Gold and id ~= ItemId.Exp and id ~= ItemId.PlayerExp then | 46 | if id ~= ItemId.Gold and id ~= ItemId.Exp and id ~= ItemId.PlayerExp then |
| 46 | - curTypeCount = curTypeCount + 1 | 47 | + curFC = curFC + math.ceil(count / globalCsv.idle_field_limit) |
| 48 | + curIC = curIC + count | ||
| 47 | end | 49 | end |
| 48 | end | 50 | end |
| 49 | - for i = 1, itemCount do | ||
| 50 | - local cur = pool[math.randWeight(pool, 3)] | ||
| 51 | - if items[cur[1]] or curTypeCount < role:getProperty("hangBagLimit") then | ||
| 52 | - if not items[cur[1]] then | ||
| 53 | - curTypeCount = curTypeCount + 1 | 51 | + local selfFC = role:getProperty("hangBagLimit") --再加上月卡的栏位 TODO |
| 52 | + local selfIC = selfFC * globalCsv.idle_field_limit | ||
| 53 | + | ||
| 54 | + local function randomItem() | ||
| 55 | + if curIC >= selfIC then | ||
| 56 | + return | ||
| 57 | + end | ||
| 58 | + local tempPool = clone(pool) | ||
| 59 | + while #tempPool > 0 do | ||
| 60 | + local idx = math.randWeight(tempPool, 3) | ||
| 61 | + local cur = pool[idx] | ||
| 62 | + 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)) | ||
| 63 | + or not items[cur[1]] then --要占用新栏位的情况 | ||
| 64 | + local addFC | ||
| 65 | + if not items[cur[1]] then | ||
| 66 | + addFC = math.ceil(cur[2] / globalCsv.idle_field_limit) | ||
| 67 | + else | ||
| 68 | + local frontC = items[cur[1]] % globalCsv.idle_field_limit | ||
| 69 | + if frontC == 0 then | ||
| 70 | + frontC = globalCsv.idle_field_limit | ||
| 71 | + end | ||
| 72 | + addFC = math.ceil((cur[2] - (globalCsv.idle_field_limit - frontC)) / globalCsv.idle_field_limit) | ||
| 73 | + end | ||
| 74 | + if curFC + addFC <= selfFC then | ||
| 75 | + curFC = curFC + addFC | ||
| 76 | + items[cur[1]] = (items[cur[1]] or 0) + cur[2] | ||
| 77 | + break | ||
| 78 | + else | ||
| 79 | + --加不了,换别的东西 | ||
| 80 | + table.remove(tempPool, idx) | ||
| 81 | + end | ||
| 82 | + else | ||
| 83 | + items[cur[1]] = items[cur[1]] + cur[2] | ||
| 84 | + break | ||
| 54 | end | 85 | end |
| 55 | - items[cur[1]] = (items[cur[1]] or 0) + cur[2] | ||
| 56 | end | 86 | end |
| 87 | + curIC = curIC + 1 | ||
| 88 | + end | ||
| 89 | + for i = 1, itemCount do | ||
| 90 | + randomItem() | ||
| 57 | end | 91 | end |
| 58 | 92 | ||
| 59 | if coinCount > 0 or itemCount > 0 then | 93 | if coinCount > 0 or itemCount > 0 then |
| @@ -61,8 +95,6 @@ local function checkReward(role) | @@ -61,8 +95,6 @@ local function checkReward(role) | ||
| 61 | end | 95 | end |
| 62 | end | 96 | end |
| 63 | 97 | ||
| 64 | - | ||
| 65 | - | ||
| 66 | --开始一个新的关卡 | 98 | --开始一个新的关卡 |
| 67 | function _M.startRpc( agent, data ) | 99 | function _M.startRpc( agent, data ) |
| 68 | local role = agent.role | 100 | local role = agent.role |
| @@ -511,5 +543,20 @@ function _M.hangGiftRpc(agent, data) | @@ -511,5 +543,20 @@ function _M.hangGiftRpc(agent, data) | ||
| 511 | return true | 543 | return true |
| 512 | end | 544 | end |
| 513 | 545 | ||
| 546 | +function _M.bagFieldRpc(agent, data) | ||
| 547 | + local role = agent.role | ||
| 548 | + local curBL = role:getProperty("hangBagLimit") | ||
| 549 | + local costD = globalCsv.idle_field_cost[curBL - globalCsv.idle_field_origin] | ||
| 550 | + if not costD then | ||
| 551 | + return 1 | ||
| 552 | + end | ||
| 553 | + if costD ~= 0 and not role:checkItemEnough({[ItemId.Diamond] = costD}) then | ||
| 554 | + return 2 | ||
| 555 | + end | ||
| 556 | + role:updateProperty({field = "hangBagLimit", value = curBL + 1}) | ||
| 557 | + role:costItems({[ItemId.Diamond] = costD}, {log = {desc = "bagField"}}) | ||
| 558 | + SendPacket(actionCodes.Hang_bagFieldRpc, '') | ||
| 559 | + return true | ||
| 560 | +end | ||
| 514 | 561 | ||
| 515 | return _M | 562 | return _M |
| 516 | \ No newline at end of file | 563 | \ No newline at end of file |