Commit 1632e6ed51a080e414eae3eaebe9631cfda19e69

Authored by zhangqijia
1 parent 1c77df08

fix: 优化 findMinKeyByIndex 函数, 修改命名

src/actions/AdvAction.lua
@@ -514,7 +514,7 @@ function _M.buyAdvCountRpc(agent , data) @@ -514,7 +514,7 @@ function _M.buyAdvCountRpc(agent , data)
514 else 514 else
515 --if math.illegalNum(count, 1, globalCsv.adv_daily_buy_count - role.dailyData:getProperty("advBC")) then return end 515 --if math.illegalNum(count, 1, globalCsv.adv_daily_buy_count - role.dailyData:getProperty("advBC")) then return end
516 local advCount = (role.dailyData:getProperty("advBC") + count ) * globalCsv.adv_daily_buy_num 516 local advCount = (role.dailyData:getProperty("advBC") + count ) * globalCsv.adv_daily_buy_num
517 - cost = {[ItemId.Jade] = table.findMinKeyByItem(globalCsv.adv_buy_cost, advCount, globalCsv.adv_daily_buy_num)} 517 + cost = {[ItemId.Jade] = table.findMinKeyByIndex(globalCsv.adv_buy_cost, advCount, globalCsv.adv_daily_buy_num)}
518 end 518 end
519 519
520 520
src/actions/HangAction.lua
@@ -478,7 +478,7 @@ function _M.quickRpc(agent , data) @@ -478,7 +478,7 @@ function _M.quickRpc(agent , data)
478 478
479 local change = globalCsv.idle_quickproduce_time / 3600 479 local change = globalCsv.idle_quickproduce_time / 3600
480 local curCount = role.dailyData:getProperty("hangQC") + 1 480 local curCount = role.dailyData:getProperty("hangQC") + 1
481 - local costCount = table.findMinKeyByItem(globalCsv.idle_quickproduce_cost, curCount * change, change) 481 + local costCount = table.findMinKeyByIndex(globalCsv.idle_quickproduce_cost, curCount * change, change)
482 482
483 if not role:checkItemEnough({[ItemId.Jade] = costCount}) then return 2 end 483 if not role:checkItemEnough({[ItemId.Jade] = costCount}) then return 2 end
484 role:costItems({[ItemId.Jade] = costCount}, {log = {desc = "quickHang", int1 = hangInfo.carbonId}}) 484 role:costItems({[ItemId.Jade] = costCount}, {log = {desc = "quickHang", int1 = hangInfo.carbonId}})
@@ -575,7 +575,7 @@ function _M.buyBonusCountRpc(agent, data) @@ -575,7 +575,7 @@ function _M.buyBonusCountRpc(agent, data)
575 --if math.illegalNum(count, 1, lastCount) then return 1 end 575 --if math.illegalNum(count, 1, lastCount) then return 1 end
576 576
577 local costCount = bonusC[btype]["b"] + count 577 local costCount = bonusC[btype]["b"] + count
578 - local cost = table.findMinKeyByItem(globalCsv.bonus_buy_cost, costCount, 1) 578 + local cost = table.findMinKeyByIndex(globalCsv.bonus_buy_cost, costCount, 1)
579 579
580 if not role:checkItemEnough({[ItemId.Jade] = cost}) then return 2 end 580 if not role:checkItemEnough({[ItemId.Jade] = cost}) then return 2 end
581 581
src/shared/functions.lua
@@ -865,12 +865,13 @@ function table.array2Table(arr) @@ -865,12 +865,13 @@ function table.array2Table(arr)
865 return ret 865 return ret
866 end 866 end
867 867
868 -function table.findMinKeyByItem(t, item, change)  
869 - if next(t) and not t[item] then  
870 - item = item - change  
871 - return table.findMinKeyByItem(t, item, change) 868 +function table.findMinKeyByIndex(t, index, change)
  869 + if not next(t or {}) then return nil end
  870 + if not t[index] then
  871 + index = index - change
  872 + return table.findMinKeyByIndex(t, index, change)
872 else 873 else
873 - return t[item] 874 + return t[index]
874 end 875 end
875 end 876 end
876 877