diff --git a/src/ProtocolCode.lua b/src/ProtocolCode.lua index 862c96d..904b48b 100644 --- a/src/ProtocolCode.lua +++ b/src/ProtocolCode.lua @@ -57,6 +57,7 @@ actionCodes = { Hero_referRunesRpc = 217, Hero_createHeroRandomRpc = 218, Hero_getResetRewardRpc = 219, + Hero_drawHeroRpc = 220, Hang_startRpc = 251, Hang_checkRpc = 252, diff --git a/src/actions/HeroAction.lua b/src/actions/HeroAction.lua index 188065f..1078a51 100644 --- a/src/actions/HeroAction.lua +++ b/src/actions/HeroAction.lua @@ -15,6 +15,7 @@ local tconcat = table.concat local table_unpack = table.unpack local _M = {} + function _M.levelUpRpc( agent, data ) local role = agent.role local msg = MsgPack.unpack(data) @@ -610,8 +611,6 @@ end function _M.getResetRewardRpc(agent, data) local role = agent.role local msg = MsgPack.unpack(data) - - local msg = MsgPack.unpack(data) local hero = role.heros[msg.id] if not hero then return end @@ -679,4 +678,130 @@ function _M.getResetRewardRpc(agent, data) return true end + +local function randomDrawCondition(pool, condition) + local value = {} + for idx, field in ipairs(condition) do + local lpool = {} + local curIdx = 1 + while pool[field .. "_" .. curIdx] do + table.insert(lpool, {pool[field .. "_" .. curIdx]}) + curIdx = curIdx + 1 + end + if next(lpool) then + value[idx] = math.randWeight(lpool, 1) + end + end + return value +end + + +local function fillDrawPool(curPool, resultPool, isNeedFunc) + for itemId, oneData in pairs(csvdb["build_poolCsv"]) do + if oneData["pool_" .. curPool] and oneData["pool_" .. curPool] ~= "" then + local itemData = csvdb["itemCsv"][itemId] + if itemData and isNeedFunc(itemData) then + for _, one in ipairs(oneData["pool_" .. pool]:toTableArray(true)) do + table.insert(resultPool, {itemId, one[1], one[2]}) -- itemId, count, 概率 + end + end + end + end +end + +function _M.drawHeroRpc(agent, data) + local role = agent.role + local msg = MsgPack.unpack(data) + + local pool = msg.pool -- 1 2 3 + local drawType = msg.type -- 1 单抽 2 十连 + + local buildTypeData = csvdb["build_typeCsv"][pool] + if not buildTypeData then return end + + local costs = {{"draw_card", "draw_coin"}, {"draw10_card", "draw10_coin"}} -- 抽取消耗 + local drawCount = {1, 10} -- 抽取次数 + + local costT = costs[drawType] + if not costT then return end + local cost = buildTypeData[costT[1]]:toNumMap() + if not role:checkItemEnough(cost) then + cost = buildTypeData[costT[2]]:toNumMap() + if not role:checkItemEnough(cost) then + return + end + end + + -- 开始抽 + local rateTypes = {"unitRate", "fragmentRate", "itemRate"} + + local typePool = {} + for _, rateType in ipairs(rateTypes) do + table.insert(typePool, {buildTypeData[rateType]}) + end + local rateType = math.randWeight(typePool, 1) + + local resultPool = {} + + local fillPoolFunc = { + unitRate = function() + local condition = {"rare", "camp", "job"} + local values = randomDrawCondition(csvdb["build_unitCsv"][pool], condition) + fillDrawPool(pool, resultPool, function(itemData) + if itemData.type ~= ItemType.Hero then return end + local heroData = csvdb["unitCsv"][itemData.id - ItemStartId.Hero] + if not heroData then return end + for idx, field in ipairs(condition) do + if heroData[field] ~= values[idx] then return end + end + return true + end) + end, + fragmentRate = function() + local condition = {"rare", "camp", "job"} + local values = randomDrawCondition(csvdb["build_fragmentCsv"][pool], condition) + fillDrawPool(pool, resultPool, function(itemData) + if itemData.type ~= ItemType.HeroFragment then return end + local heroData = csvdb["unitCsv"][itemData.id] + if not heroData then return end + for idx, field in ipairs(condition) do + if heroData[field] ~= values[idx] then return end + end + return true + end) + end, + itemRate = function() + fillDrawPool(pool, resultPool, function(itemData) + if itemData.type == ItemType.HeroFragment or itemData.type == ItemType.Hero then return end + return true + end) + end, + } + + if not fillPoolFunc[rateTypes[rateType]] then return end + fillPoolFunc[rateTypes[rateType]]() + if not next(resultPool) then return end + role:costItems(cost) + + local reward = {} + for i = 1, drawCount[drawType] do + local idx = math.randWeight(resultPool, 3) + local temp = resultPool[idx] + local itemData = csvdb["itemCsv"][temp[1]] + if itemData.type == ItemType.Hero and role:isHaveHero(itemData.id - ItemStartId.Hero) then + local fragId = itemData.id - ItemStartId.Hero + local heroData = csvdb["unitCsv"][fragId] + local count = globalCsv.draw_unit_tofragment[heroData.rare] * temp[2] + role:award({[fragId] = count}) + table.insert(reward, {id = fragId, count = count, from = temp[1], fcount = temp[2]}) + else + role:award({[temp[1]] = temp[2]}) + table.insert(reward, {id = temp[1], count = temp[2]}) + end + end + + SendPacket(actionCodes.Hero_drawHeroRpc, MsgPack.pack({reward = reward})) -- 这个 reward 是数组 + return true +end + return _M \ No newline at end of file diff --git a/src/adv/AdvPassive.lua b/src/adv/AdvPassive.lua index 5922cd6..24232a4 100644 --- a/src/adv/AdvPassive.lua +++ b/src/adv/AdvPassive.lua @@ -246,13 +246,15 @@ function Passive:effect(trigger) self["effect" .. effType](self, effValue, trigger) end end - if self.count <= 0 and self.passiveData.refresh == 1 then -- 次数 <= 0 并且一次冒险内不刷新,被动可以直接移除 - self.isDel = true - end + if self.count > 0 then self.count = self.count < 999 and self.count - 1 or self.count self.round = self.passiveData.round end + + if self.count <= 0 and self.passiveData.refresh == 1 then -- 次数 <= 0 并且一次冒险内不刷新,被动可以直接移除 + self.isDel = true + end end function Passive:afterRound() -- libgit2 0.21.2