From 1632e6ed51a080e414eae3eaebe9631cfda19e69 Mon Sep 17 00:00:00 2001 From: zqj <582132116@qq.com> Date: Fri, 10 Sep 2021 19:02:12 +0800 Subject: [PATCH] fix: 优化 findMinKeyByIndex 函数, 修改命名 --- src/actions/AdvAction.lua | 2 +- src/actions/HangAction.lua | 4 ++-- src/shared/functions.lua | 11 ++++++----- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/actions/AdvAction.lua b/src/actions/AdvAction.lua index eaad039..3cfba20 100644 --- a/src/actions/AdvAction.lua +++ b/src/actions/AdvAction.lua @@ -514,7 +514,7 @@ function _M.buyAdvCountRpc(agent , data) else --if math.illegalNum(count, 1, globalCsv.adv_daily_buy_count - role.dailyData:getProperty("advBC")) then return end local advCount = (role.dailyData:getProperty("advBC") + count ) * globalCsv.adv_daily_buy_num - cost = {[ItemId.Jade] = table.findMinKeyByItem(globalCsv.adv_buy_cost, advCount, globalCsv.adv_daily_buy_num)} + cost = {[ItemId.Jade] = table.findMinKeyByIndex(globalCsv.adv_buy_cost, advCount, globalCsv.adv_daily_buy_num)} end diff --git a/src/actions/HangAction.lua b/src/actions/HangAction.lua index c77e510..186808e 100644 --- a/src/actions/HangAction.lua +++ b/src/actions/HangAction.lua @@ -478,7 +478,7 @@ function _M.quickRpc(agent , data) local change = globalCsv.idle_quickproduce_time / 3600 local curCount = role.dailyData:getProperty("hangQC") + 1 - local costCount = table.findMinKeyByItem(globalCsv.idle_quickproduce_cost, curCount * change, change) + local costCount = table.findMinKeyByIndex(globalCsv.idle_quickproduce_cost, curCount * change, change) if not role:checkItemEnough({[ItemId.Jade] = costCount}) then return 2 end role:costItems({[ItemId.Jade] = costCount}, {log = {desc = "quickHang", int1 = hangInfo.carbonId}}) @@ -575,7 +575,7 @@ function _M.buyBonusCountRpc(agent, data) --if math.illegalNum(count, 1, lastCount) then return 1 end local costCount = bonusC[btype]["b"] + count - local cost = table.findMinKeyByItem(globalCsv.bonus_buy_cost, costCount, 1) + local cost = table.findMinKeyByIndex(globalCsv.bonus_buy_cost, costCount, 1) if not role:checkItemEnough({[ItemId.Jade] = cost}) then return 2 end diff --git a/src/shared/functions.lua b/src/shared/functions.lua index ae7ab42..61c8644 100644 --- a/src/shared/functions.lua +++ b/src/shared/functions.lua @@ -865,12 +865,13 @@ function table.array2Table(arr) return ret end -function table.findMinKeyByItem(t, item, change) - if next(t) and not t[item] then - item = item - change - return table.findMinKeyByItem(t, item, change) +function table.findMinKeyByIndex(t, index, change) + if not next(t or {}) then return nil end + if not t[index] then + index = index - change + return table.findMinKeyByIndex(t, index, change) else - return t[item] + return t[index] end end -- libgit2 0.21.2