From 3c0ea5fb7070be0765111105354d334ffb613176 Mon Sep 17 00:00:00 2001 From: zhouhaihai Date: Thu, 14 May 2020 17:06:48 +0800 Subject: [PATCH] 抽英雄 --- src/GlobalVar.lua | 3 +++ src/actions/HeroAction.lua | 336 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------------------------------------------------------------------------------------------------------------- src/agent.lua | 9 +++++++++ src/models/Role.lua | 8 +++++--- src/models/RolePlugin.lua | 8 ++++++++ src/services/watchdog.lua | 2 +- 6 files changed, 219 insertions(+), 147 deletions(-) diff --git a/src/GlobalVar.lua b/src/GlobalVar.lua index 951cfca..398a9cb 100644 --- a/src/GlobalVar.lua +++ b/src/GlobalVar.lua @@ -134,6 +134,9 @@ TimeReset = { DailyBattle2 = 14, -- 特殊-每日副本(贴纸) DailyBattle1 = 15, -- 特殊-每日副本(装备) DailyBattle3 = 16, -- 特殊-每日副本(时钟箱) + DrawType1 = 17, -- 变异 抽卡加成 + DrawType2 = 18, -- 通常 抽卡加成 + DrawType3 = 19, -- 魔法 抽卡加成 } GuideStep = { diff --git a/src/actions/HeroAction.lua b/src/actions/HeroAction.lua index 6eac4c5..9993bf0 100644 --- a/src/actions/HeroAction.lua +++ b/src/actions/HeroAction.lua @@ -233,7 +233,7 @@ function _M.commentHeroRpc(agent, data) result.status = 1 else local commentKey = getCommentKey(heroType) - local SERV = string.format(".chatd%d", math.random(1, 5)) + local SERV = string.format(".chated%d", math.random(1, 5)) local legal, mod = skynet.call(SERV, "lua", "check", content) if not legal then content = mod or "" @@ -668,208 +668,258 @@ function _M.getResetRewardRpc(agent, data) 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_" .. curPool]: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) if not role:isFuncUnlock(FuncUnlock.GetHero) then return end - local pool = msg.pool -- 1 2 3 + local btype = msg.pool -- 1 2 3 4 local drawType = msg.type -- 1 单抽 2 十连 - local buildTypeData = csvdb["build_typeCsv"][pool] + local buildTypeData = csvdb["build_typeCsv"][btype] if not buildTypeData then return 1 end - local costs = {{"draw_card", "draw_coin"}, {"draw10_card", "draw10_coin"}} -- 抽取消耗 local drawCount = {1, 10} -- 抽取次数 + if not drawCount[drawType] then return 2 end - local costT = costs[drawType] - if not costT then return 2 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 3 + local newerDraw + if btype == 4 then + newerDraw = role:getProperty("newerDraw") + if math.illegalNum(globalCsv.draw_newer[2] - (newerDraw[1] or 0), drawCount[drawType], globalCsv.draw_newer[2]) then return 11 end + end + + local cost = {} + local lastCount = drawCount[drawType] + for _, costType in ipairs({"draw_card", "draw_coin"}) do + if buildTypeData[costType] ~= "" then + local curCost = buildTypeData[costType]:toArray(true, "=") + local hadCount = role:getItemCount(curCost[1]) + local curCount = math.floor(hadCount / curCost[2]) + if curCount >= lastCount then + cost[curCost[1]] = curCost[2] * lastCount + lastCount = 0 + break + elseif curCount > 0 then + cost[curCost[1]] = curCost[2] * curCount + lastCount = lastCount - curCount + end end end + if lastCount > 0 then -- 钱不够 + return 3 + end - -- 开始抽 - local rateTypes = {"unitRate", "fragmentRate", "itemRate"} + -- pool 固定的 + local poolEnum = { + [1] = { + [1] = 1, + [2] = 2, + [3] = 3, + }, + [2] = 10, + [3] = 11, + [4] = 12, + } - local typePool = {} - for _, rateType in ipairs(rateTypes) do - table.insert(typePool, {buildTypeData[rateType]}) + -- 抽取的池子 + local pool = poolEnum[btype] + if btype == 1 then + -- 超级卡池子 每周轮换 有活动覆盖之 + --TODO 活动判断 + if false then + else + for idx, poolId in pairs(pool) do + if role:isTimeResetOpen(TimeReset["DrawType" .. idx]) then + pool = poolId + break + end + end + if type(pool) ~= "number" then + pool = -1 + end + end end + local unitPool = csvdb["build_unitCsv"][pool] + if not unitPool then return 4 end + -- 开始抽 local resultPool = {} + local function fillDrawPool(fixRare, fixCamp, ssrUp) + local condition = {"rare", "camp"} + local values = {fixRare, fixCamp} + + for idx, field in ipairs(condition) do + if not values[idx] then + local lpool = {} + local curIdx = 1 + while unitPool[field .. "_" .. curIdx] do + lpool[curIdx] = {unitPool[field .. "_" .. curIdx]} + curIdx = curIdx + 1 + end - local fillPoolFunc = { - unitRate = function(fixRare, fixCamp, fixJob) - local condition = {"rare", "camp", "job"} - local values = randomDrawCondition(csvdb["build_unitCsv"][pool], condition) - values[1] = fixRare or values[1] - values[2] = fixCamp or values[2] - values[3] = fixJob or values[3] - 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 + -- 稀有度 ssr up + if field == "rare" then + local all = 0 + for _, weight in pairs(lpool) do + all = all + weight[1] + end + + lpool[4][1] = lpool[4][1] + (ssrUp or 0) * all end - return true - end) - end, - fragmentRate = function(fixRare, fixCamp, fixJob) - local condition = {"rare", "camp", "job"} - local values = randomDrawCondition(csvdb["build_fragmentCsv"][pool], condition) - values[1] = fixRare or values[1] - values[2] = fixCamp or values[2] - values[3] = fixJob or values[3] - 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 + + if next(lpool) then + values[idx] = math.randWeight(lpool, 1) 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, - } + end + end - role:costItems(cost, {log = {desc = "drawHero", short1 = pool}}) - local floorHeroCount = role:getProperty("floorHero")[pool] or 0 + for itemId, oneData in pairs(csvdb["build_poolCsv"]) do + if oneData["pool_" .. pool] and oneData["pool_" .. pool] ~= "" then + local itemData = csvdb["itemCsv"][itemId] + while itemData do + if itemData.type ~= ItemType.Hero then break end + local heroData = csvdb["unitCsv"][itemData.id - ItemStartId.Hero] + if not heroData then break end + local ok = true + for idx, field in ipairs(condition) do + if heroData[field] ~= values[idx] then ok = false break end + end + if not ok then break end + resultPool[itemId] = {oneData["pool_" .. pool]} -- itemId, count, 概率 + break + end + end + end + end + + role:costItems(cost, {log = {desc = "drawHero", short1 = btype, int1 = pool}}) + + local draw_floor_back_counts = globalCsv.draw_floor_back_counts[btype] + local draw_ssr_up_count_rate = globalCsv.draw_ssr_up_count_rate[btype] + local floorHeroCount = role:getProperty("floorHero")[btype] or 0 + local ssrUpCount = role:getProperty("ssrUp")[btype] or 0 + + local newerDrawCount, newerHadSSR + if btype == 4 then + newerDrawCount = newerDraw[1] or 0 + newerHadSSR = newerDraw[2] or 0 + end local ssrCount = 0 local reward = {} for i = 1, drawCount[drawType] do floorHeroCount = floorHeroCount + 1 + if btype == 4 then + newerDrawCount = newerDrawCount + 1 + end resultPool = {} - local isFloorBack = globalCsv.draw_floor_back_counts[pool] and floorHeroCount >= globalCsv.draw_floor_back_counts[pool] - while not next(resultPool) do - local rateType + local isFloorBack = draw_floor_back_counts and floorHeroCount >= draw_floor_back_counts + local isNewerSSR = btype == 4 and (newerHadSSR == 0 and newerDrawCount >= globalCsv.draw_newer[1]) or false - if isFloorBack then - rateType = 1 --保底英雄 - else - rateType = math.randWeight(typePool, 1) - end - if not fillPoolFunc[rateTypes[rateType]] then return 4 end - if isFloorBack then - fillPoolFunc[rateTypes[rateType]](3) -- 保底 sr 【郑斌】明确 + local ssrUp = 0 + if draw_ssr_up_count_rate then + ssrUp = math.floor(ssrUpCount / draw_ssr_up_count_rate[1]) * draw_ssr_up_count_rate[2] / 100 + end + while not next(resultPool) do + if isNewerSSR then + fillDrawPool(4) -- 新手保底的 ssr + elseif isFloorBack then + fillDrawPool(3) -- 保底 sr 【郑斌】明确 else - fillPoolFunc[rateTypes[rateType]]() + fillDrawPool(nil, nil, ssrUp) end end - local idx = math.randWeight(resultPool, 3) - local temp = resultPool[idx] - local itemData = csvdb["itemCsv"][temp[1]] + local itemId = math.randWeight(resultPool, 1) + local itemData = csvdb["itemCsv"][itemId] - if itemData.type == ItemType.Hero then - if itemData.quality == 4 then - ssrCount = ssrCount + 1 - elseif itemData.quality == 3 then - floorHeroCount = 0 + if itemData.quality == 4 then + ssrCount = ssrCount + 1 + ssrUpCount = 0 + + if btype == 4 then + newerHadSSR = newerHadSSR + 1 end + elseif itemData.quality == 3 then + floorHeroCount = 0 + ssrUpCount = ssrUpCount + 1 + else + ssrUpCount = ssrUpCount + 1 end - if itemData.type == ItemType.Hero and role:isHaveHero(itemData.id - ItemStartId.Hero) then + if 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}, {log = {desc = "drawHero", short1 = pool}}) - table.insert(reward, {id = fragId, count = count, from = temp[1], fcount = temp[2]}) + local count = globalCsv.draw_unit_tofragment[heroData.rare] + role:award({[fragId] = count}, {log = {desc = "drawHero", short1 = btype, int1 = pool}}) + table.insert(reward, {id = fragId, count = count, from = itemId, fcount = 1}) else - role:award({[temp[1]] = temp[2]}, {log = {desc = "drawHero", short1 = pool}}) - table.insert(reward, {id = temp[1], count = temp[2]}) + role:award({[itemId] = 1}, {log = {desc = "drawHero", short1 = btype, int1 = pool}}) + table.insert(reward, {id = itemId, count = 1}) end end - if globalCsv.draw_floor_back_counts[pool] then + if draw_floor_back_counts then local floorHero = role:getProperty("floorHero") floorHero[pool] = floorHeroCount - role:updateProperty({field = "floorHero", value = floorHero}) + role:setProperty("floorHero", floorHero) + end + + if draw_ssr_up_count_rate then + local ssrUp = role:getProperty("ssrUp") + ssrUp[pool] = ssrUpCount + role:setProperty("ssrUp", ssrUp) end - if pool == 1 then - local repayHero = role:getProperty("repayHero") - repayHero = math.min(globalCsv.draw_super_repay_count, repayHero + drawCount[drawType]) - role:updateProperty({field = "repayHero", value = repayHero}) + if btype == 4 then + newerDraw[1] = newerDrawCount + newerDraw[2] = newerHadSSR + role:updateProperty({field = "newerDraw", value = newerDraw}) end + -- if pool == 1 then + -- local repayHero = role:getProperty("repayHero") + -- repayHero = math.min(globalCsv.draw_super_repay_count, repayHero + drawCount[drawType]) + -- role:updateProperty({field = "repayHero", value = repayHero}) + -- end + role:checkTaskEnter("DrawHero", {pool = pool, count = drawCount[drawType]}) if ssrCount > 0 then role:checkTaskEnter("DrawSSR", {count = ssrCount}) end - role:log("hero_action", {desc = "drawHero", short1 = pool, int1 = drawCount[drawType]}) + role:log("hero_action", {desc = "drawHero", short1 = btype, int1 = drawCount[drawType], int2 = pool}) SendPacket(actionCodes.Hero_drawHeroRpc, MsgPack.pack({reward = reward})) -- 这个 reward 是数组 return true end -function _M.repayHeroRpc(agent, data) - local role = agent.role - - local repayHero = role:getProperty("repayHero") - if repayHero < globalCsv.draw_super_repay_count then - return - end +-- function _M.repayHeroRpc(agent, data) +-- local role = agent.role - role:updateProperty({field = "repayHero", value = 0}) - local id = math.randWeight(csvdb["build_giftCsv"], "pool_1") +-- local repayHero = role:getProperty("repayHero") +-- if repayHero < globalCsv.draw_super_repay_count then +-- return +-- end - local reward = {} - local itemData = csvdb["itemCsv"][id] - 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] - role:award({[fragId] = count}, {log = {desc = "heroRepay"}}) - reward = {id = fragId, count = count, from = id, fcount = 1} - else - role:award({[id] = 1}, {log = {desc = "heroRepay"}}) - reward = {id = id, count = 1} - end - role:log("hero_action", {desc = "heroRepay"}) - SendPacket(actionCodes.Hero_repayHeroRpc, MsgPack.pack({reward = reward})) - return true -end +-- role:updateProperty({field = "repayHero", value = 0}) +-- local id = math.randWeight(csvdb["build_giftCsv"], "pool_1") + +-- local reward = {} +-- local itemData = csvdb["itemCsv"][id] +-- 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] +-- role:award({[fragId] = count}, {log = {desc = "heroRepay"}}) +-- reward = {id = fragId, count = count, from = id, fcount = 1} +-- else +-- role:award({[id] = 1}, {log = {desc = "heroRepay"}}) +-- reward = {id = id, count = 1} +-- end +-- role:log("hero_action", {desc = "heroRepay"}) +-- SendPacket(actionCodes.Hero_repayHeroRpc, MsgPack.pack({reward = reward})) +-- return true +-- end return _M \ No newline at end of file diff --git a/src/agent.lua b/src/agent.lua index 2395744..1552306 100644 --- a/src/agent.lua +++ b/src/agent.lua @@ -325,6 +325,15 @@ skynet.start(function() end end) + skynet.info_func(function() + local info = {} + info.ip = agentInfo.ip + if agentInfo.role then + info.roldId = agentInfo.role:getProperty("id") + end + return info + end) + redisd = skynet.localname(".redis") if tonumber(skynet.getenv "logd") == 1 then logd = skynet.localname(".log") diff --git a/src/models/Role.lua b/src/models/Role.lua index 550f574..5873fe1 100644 --- a/src/models/Role.lua +++ b/src/models/Role.lua @@ -144,8 +144,10 @@ Role.schema = { emailSync = {"number", 0}, -- 已经同步到的邮件Id - repayHero = {"number", 0}, -- 超级招募 回馈 + -- repayHero = {"number", 0}, -- 超级招募 回馈 floorHero = {"table", {}}, -- 招募保底 -- {[poolId] = count} + ssrUp = {"table", {}}, -- ssr up -- {[poolId] = count} + newerDraw = {"table", {}}, -- 新手池子 {N, 1} 抽了多少次, 是否出了ssr } @@ -349,8 +351,8 @@ function Role:data() dinerS = self:getProperty("dinerS"), rmbC = self:getProperty("rmbC"), - repayHero = self:getProperty("repayHero"), - floorHero = self:getProperty("floorHero"), + -- repayHero = self:getProperty("repayHero"), + newerDraw = self:getProperty("newerDraw"), } end diff --git a/src/models/RolePlugin.lua b/src/models/RolePlugin.lua index 9c2e954..93a73b8 100644 --- a/src/models/RolePlugin.lua +++ b/src/models/RolePlugin.lua @@ -401,10 +401,18 @@ function RolePlugin.bind(Role) redisproxy:sadd(string.format(R_HEROS, roleId), heroId) + local wakeL = 1 + if unitData.rare == 3 then + wakeL = 2 + elseif unitData.rare == 4 then + wakeL = 3 + end + local heroInfo = { key = string.format(R_HERO, roleId, heroId), id = heroId, type= heroType, + wakeL = wakeL, } local newHero = require("models.Hero").new(heroInfo) diff --git a/src/services/watchdog.lua b/src/services/watchdog.lua index 6a0a83e..3cc96d2 100644 --- a/src/services/watchdog.lua +++ b/src/services/watchdog.lua @@ -51,7 +51,7 @@ local use_logd = tonumber(skynet.getenv "logd") -- @desc: agent状态定时检测 function check_agent_status() pcall(agent_ctrl.check_agent_status, agent_ctrl) - skynet.timeout(1, check_agent_status) + skynet.timeout(100, check_agent_status) end -- 创建world以及union channel 用于广播 -- libgit2 0.21.2