Commit 261a541fb8d51021044651cb9e29990d0560b1cd

Authored by zhangqijia
1 parent 83987977

fix: 优化 findMinKeyByItem 函数

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)} 517 + cost = {[ItemId.Jade] = table.findMinKeyByItem(globalCsv.adv_buy_cost, advCount, globalCsv.adv_daily_buy_num)}
518 end 518 end
519 519
520 520
src/actions/HangAction.lua
@@ -476,10 +476,9 @@ function _M.quickRpc(agent , data) @@ -476,10 +476,9 @@ function _M.quickRpc(agent , data)
476 --local expCarbonData = csvdb["idle_battleCsv"][hangInfo.expCarbonId] 476 --local expCarbonData = csvdb["idle_battleCsv"][hangInfo.expCarbonId]
477 local expCarbonData = hangInfo.expData or {} 477 local expCarbonData = hangInfo.expData or {}
478 478
  479 + local change = globalCsv.idle_quickproduce_time / 3600
479 local curCount = role.dailyData:getProperty("hangQC") + 1 480 local curCount = role.dailyData:getProperty("hangQC") + 1
480 - local curT = curCount * (globalCsv.idle_quickproduce_time / 3600)  
481 - local costCount = table.findMinKeyByItem(globalCsv.idle_quickproduce_cost, curT)  
482 - 481 + local costCount = table.findMinKeyByItem(globalCsv.idle_quickproduce_cost, curCount * change, change)
483 482
484 if not role:checkItemEnough({[ItemId.Jade] = costCount}) then return 2 end 483 if not role:checkItemEnough({[ItemId.Jade] = costCount}) then return 2 end
485 role:costItems({[ItemId.Jade] = costCount}, {log = {desc = "quickHang", int1 = hangInfo.carbonId}}) 484 role:costItems({[ItemId.Jade] = costCount}, {log = {desc = "quickHang", int1 = hangInfo.carbonId}})
@@ -576,7 +575,7 @@ function _M.buyBonusCountRpc(agent, data) @@ -576,7 +575,7 @@ function _M.buyBonusCountRpc(agent, data)
576 --if math.illegalNum(count, 1, lastCount) then return 1 end 575 --if math.illegalNum(count, 1, lastCount) then return 1 end
577 576
578 local costCount = bonusC[btype]["b"] + count 577 local costCount = bonusC[btype]["b"] + count
579 - local cost = table.findMinKeyByItem(globalCsv.bonus_buy_cost, costCount) 578 + local cost = table.findMinKeyByItem(globalCsv.bonus_buy_cost, costCount, 1)
580 579
581 if not role:checkItemEnough({[ItemId.Jade] = cost}) then return 2 end 580 if not role:checkItemEnough({[ItemId.Jade] = cost}) then return 2 end
582 581
src/shared/functions.lua
@@ -865,27 +865,10 @@ function table.array2Table(arr) @@ -865,27 +865,10 @@ function table.array2Table(arr)
865 return ret 865 return ret
866 end 866 end
867 867
868 -function table.findMinKeyByItem(t, item)  
869 - if not t[item] then  
870 - local max = table.maxkey(t)  
871 - if item > max then return t[max] end  
872 -  
873 - local tk = {}  
874 - for k, v in pairs(t) do  
875 - table.insert(tk, k)  
876 - end  
877 - if next(tk) then  
878 - table.insert(tk, item)  
879 - table.sort(tk)  
880 - local index = 0  
881 - for i, k in ipairs(tk) do  
882 - if k == item then  
883 - index = i - 1  
884 - break  
885 - end  
886 - end  
887 - return t[tk[index]]  
888 - end 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)
889 else 872 else
890 return t[item] 873 return t[item]
891 end 874 end