Commit 5d620aefb2f4b7932dfa5aae6b7dfac1bfeaf5a2

Authored by chenyueqi
1 parent 5e0e0aff

拆解室指定某一项为必得奖励

Showing 1 changed file with 15 additions and 5 deletions   Show diff stats
src/actions/RoleAction.lua
... ... @@ -481,16 +481,26 @@ function _M.openTimeBoxRpc(agent, data)
481 481 -- 随机奖励
482 482 local randomGift = randomData.random_gift
483 483 local randomNum = randomData.random_num
484   - if boxL[slot].gem ~= 0 then
485   - randomNum = randomData[boxL[slot].gem .. "_gem_num"]
486   - randomGift = randomData[boxL[slot].gem .. "_gem_gift"]
487   - end
  484 + local gemId = boxL[slot].gem
488 485  
489 486 if randomNum > 0 and randomGift and randomGift ~= "" then
  487 + local selectGift = {}
490 488 local pool = {}
491 489 for _, temp in ipairs(randomGift:toArray()) do
492   - table.insert(pool, temp:toArray(true, "="))
  490 + local set = temp:toArray(true, "=")
  491 + if gemId == set[1] then
  492 + table.insert(selectGift, set)
  493 + else
  494 + table.insert(pool, set)
  495 + end
  496 + end
  497 +
  498 + if gemId ~= 0 and next(selectGift) then
  499 + randomNum = randomNum - 1
  500 + local idx = math.randWeight(pool, 3)
  501 + reward[pool[idx][1]] = (reward[pool[idx][1]] or 0) + pool[idx][2]
493 502 end
  503 +
494 504 local needCount = math.min(#pool, randomNum)
495 505 for j = 1, needCount do
496 506 local idx = math.randWeight(pool, 3)
... ...