From 1663460594b058c17c9d4eda37410cd03be7e579 Mon Sep 17 00:00:00 2001 From: liuzujun <307836273@qq.com> Date: Wed, 18 Nov 2020 17:45:42 +0800 Subject: [PATCH] 多队挂机,天赋道具合成 --- src/ProtocolCode.lua | 6 +++--- src/actions/HeroAction.lua | 19 +++++++++++++++++++ src/actions/RadioAction.lua | 140 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------- src/csvdata | 2 +- src/models/Hero.lua | 4 ++++ src/models/Role.lua | 2 ++ src/models/RoleLog.lua | 2 ++ 7 files changed, 157 insertions(+), 18 deletions(-) diff --git a/src/ProtocolCode.lua b/src/ProtocolCode.lua index 29f63f3..5933add 100644 --- a/src/ProtocolCode.lua +++ b/src/ProtocolCode.lua @@ -99,6 +99,7 @@ actionCodes = { Hero_unlockPoolRpc = 222, Hero_changeCrown = 223, Hero_drawHeroExtraRewardNtf = 224, + Hero_itemComposeRpc = 225, Hang_startRpc = 251, Hang_checkRpc = 252, @@ -217,9 +218,8 @@ actionCodes = { Activity_actCalendaTaskRpc = 655, Activity_actPaySignRpc = 656, - Radio_listRpc = 700, -- 获取电台讨伐任务列表 - Radio_startQuestRpc = 701, - Radio_finishQuestRpc = 702, + Radio_startQuestRpc = 700, + Radio_finishQuestRpc = 701, } rpcResponseBegin = 10000 diff --git a/src/actions/HeroAction.lua b/src/actions/HeroAction.lua index e2e045f..df032e0 100644 --- a/src/actions/HeroAction.lua +++ b/src/actions/HeroAction.lua @@ -1038,4 +1038,23 @@ function _M.changeCrown(agent, data) return true end +function _M.itemComposeRpc(agent, data) + local role = agent.role + local msg = MsgPack.unpack(data) + + local itemId = msg.id + local count = msg.count + if not csvdb["itemCsv"][itemId] then return 1 end + local config = csvdb["item_processCsv"][itemId] + if not config then return 2 end + + local cost = config.cost:toNumMap() + if not role:checkItemEnough(cost) then return 2 end + role:costItems(cost, {log = {desc = "itemCompose", int1 = itemId, int2 = count}}) + role:award({[itemId] = count}, {log = {desc = "itemCompose"}}) + + SendPacket(actionCodes.Hero_itemComposeRpc, "") + return true +end + return _M diff --git a/src/actions/RadioAction.lua b/src/actions/RadioAction.lua index fac01d0..e3f46a9 100644 --- a/src/actions/RadioAction.lua +++ b/src/actions/RadioAction.lua @@ -1,19 +1,38 @@ local _M = {} -function _M.listRpc(agent, data) - local role = agent.role - local roleId = role:getProperty("id") - local now = skynet.timex() - local result = {} - +-- 获取英雄大成功率 +local function getHeroCoef(hero, condition) + -- 基础概率 + local rareMap = {[HeroQuality.N] = 10, [HeroQuality.R] = 10, [HeroQuality.SR] = 15, [HeroQuality.SSR] = 20} + local rare = hero:getRare() + local result = 0 + for _, it in ipairs(condition:toTableArray(true)) do + local type = it[1] + local value = it[2] + local add = it[3] + if type == 1 then -- 种族加成 + if hero:getCamp() == value then + result = result + add + end + elseif type == 2 then -- 定位加成 + if hero:getPosition() == value then + result = result + add + end + end + end - SendPacket(actionCodes.Email_listRpc, MsgPack.pack({list = result})) - return true + return result + (rareMap[rare] or 0) end --- 获取英雄大成功率 -local function getHeroCoef() - return 0 +local function getQuestMax(role) + local count = 0 + for _, carbonId in ipairs(globalCsv.crusade_team_unlock or {}) do + if role:checkHangPass(carbonId) then + count = count + 1 + end + end + + return count + (globalCsv.cursade_team_count_initial or 0) end function _M.startQuestRpc(agent, data) @@ -22,11 +41,67 @@ function _M.startQuestRpc(agent, data) local id = msg.id local heros = msg.heros local result = {} + local radioTask = role:getProperty("radioTask") + if table.numbers(radioTask) >= getQuestMax(role) then + return 1 + end -- check id + local config = csvdb["crusadeCsv"][id] + if not config then return 2 end + if not role:checkHangPass(config.unlock) then return 3 end + if radioTask[id] then return 4 end -- check hero + --1=指定等级=人数 + --2=指定稀有度=人数 + --3=人数 + local needHeroCnt = 0 + local lvlMap = {} + local rareMap = {} + for _, it in ipairs(config.condition:toTableArray(true)) do + local type = it[1] + if type == 1 then + lvlMap[1] = it[2] + lvlMap[2] = it[3] + elseif type == 2 then + rareMap[1] = it[2] + rareMap[2] = it[3] + elseif type == 3 then + needHeroCnt = it[2] + end + end + for _, heroId in ipairs(heros) do + local hero = role.heros[heroId] + if hero then + needHeroCnt = needHeroCnt - 1 + if next(lvlMap) then + if hero:getProperty("level") >= lvlMap[1] then + lvlMap[2] = lvlMap[2] - 1 + if lvlMap[2] <= 0 then + lvlMap = {} + end + end + end + if next(rareMap) then + if hero:getRare() >= rareMap[1] then + rareMap[2] = rareMap[2] - 1 + end + if rareMap[2] <= 0 then + rareMap = {} + end + end + end + end + if needHeroCnt > 0 or next(rareMap) or next(lvlMap) then + return 5 + end -- start quest, set finish time + local taskData = {} + taskData["time"] = skynet.timex() + config.time + taskData["heros"] = heros + radioTask[id] = taskData + role:updateProperty({field="radioTask", value=radioTask, notNotify=true}) - SendPacket(actionCodes.Email_listRpc, MsgPack.pack({list = result})) + SendPacket(actionCodes.Radio_startQuestRpc, MsgPack.pack({id=id, task=taskData})) return true end @@ -34,13 +109,50 @@ function _M.finishQuestRpc(agent, data) local role = agent.role local msg = MsgPack.unpack(data) local id = msg.id - local result = {} -- check finish time + local radioTask = role:getProperty("radioTask") + local task = radioTask[id] + if not task then return 1 end + if skynet.timex() < task.time then return 2 end -- check id + local config = csvdb["crusadeCsv"][id] + if not config then return 3 end + local carbonData = csvdb["idle_battleCsv"][config.unlock] + if not carbonData then return 4 end -- get heros + local totalCoef = 0 + for _, heroId in ipairs(task.heros) do + local hero = role.heros[heroId] + if hero then + totalCoef = totalCoef + getHeroCoef(hero, config.success) + end + end -- send award + local bigSuccess = false + local result = math.randomInt(0, 100) + if result < totalCoef then + bigSuccess = true + end + local money = math.ceil(carbonData.money / 5) * config.time * config.money_clear + local exp = math.ceil(carbonData.exp / 5) * config.time * config.exp_clear + local itemReward = config.item_clear_special:toNumMap() + itemReward[ItemId.Gold] = (itemReward[ItemId.Gold] or 0) + money + itemReward[ItemId.Exp] = (itemReward[ItemId.Exp] or 0) + exp + if bigSuccess then + for key, value in pairs(itemReward) do + itemReward[key] = math.ceil(1.5 * value) + end + end + + local r, change = role:award(itemReward, {log = {desc = "radioQuest", int1 = id}}) + + radioTask[id] = nil + role:updateProperty({field="radioTask", value=radioTask, notNotify = true}) - SendPacket(actionCodes.Email_listRpc, MsgPack.pack({list = result})) + local msg = role:packReward(r, change) + msg["big"] = bigSuccess + msg["id"] = id + SendPacket(actionCodes.Radio_finishQuestRpc, MsgPack.pack(msg)) return true end diff --git a/src/csvdata b/src/csvdata index 0f60ee4..b4c54b2 160000 --- a/src/csvdata +++ b/src/csvdata @@ -1 +1 @@ -Subproject commit 0f60ee4ca695995942574454c696747a4390ee5d +Subproject commit b4c54b229a7ac8c5ac938e72bd6cc4870a264c58 diff --git a/src/models/Hero.lua b/src/models/Hero.lua index 780b1e7..5be87e8 100644 --- a/src/models/Hero.lua +++ b/src/models/Hero.lua @@ -115,4 +115,8 @@ function Hero:getRare() return csvdb["unitCsv"][self:getProperty("type")].rare end +function Hero:getPosition() + return csvdb["unitCsv"][self:getProperty("type")].position +end + return Hero \ No newline at end of file diff --git a/src/models/Role.lua b/src/models/Role.lua index 039b1cf..c19c841 100644 --- a/src/models/Role.lua +++ b/src/models/Role.lua @@ -181,6 +181,7 @@ Role.schema = { feedback = {"table", {}}, -- 反馈相关信息 {flag = false, count = 0} flag是否评论过,count 提示次数 calTask = {"table", {}}, -- 英雄令活动 日历任务活动 + radioTask = {"table", {}}, -- 电台任务 {id = {time=end_ts,heros=heros}} 表crusadeCsv } @@ -406,6 +407,7 @@ function Role:data() feedback = self:getProperty("feedback"), ctime = self:getProperty("ctime"), calTask = self:getProperty("calTask"), + radioTask = self:getProperty("radioTask"), } end diff --git a/src/models/RoleLog.lua b/src/models/RoleLog.lua index a7e2e68..a2397ef 100644 --- a/src/models/RoleLog.lua +++ b/src/models/RoleLog.lua @@ -107,6 +107,8 @@ local ItemReason = { unlockPool = 1208, -- 解锁英雄定向抽卡池 downloadCv = 1209, -- 下载 cv包奖励 refer = 1210, -- 穿戴 + itemCompose = 1211, -- 天赋道具合成 + radioQuest = 1212, -- 电台任务奖励 -- pvp pvpCHead = 1301, -- pvp 跨服竞技场头像 -- libgit2 0.21.2