From 98d32f9218d90cad222d51af75b932b799626195 Mon Sep 17 00:00:00 2001 From: liuzujun <307836273@qq.com> Date: Thu, 5 Nov 2020 20:00:08 +0800 Subject: [PATCH] 多编队 --- src/GlobalVar.lua | 8 ++++++++ src/ProtocolCode.lua | 3 +++ src/actions/AdvAction.lua | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------- src/actions/HangAction.lua | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------- src/actions/RoleAction.lua | 24 ++++++++++++++++++++++++ src/models/Role.lua | 6 +++++- src/models/RoleBattle.lua | 6 ++++-- src/models/RolePlugin.lua | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 8 files changed, 219 insertions(+), 27 deletions(-) diff --git a/src/GlobalVar.lua b/src/GlobalVar.lua index 1c17338..730a761 100644 --- a/src/GlobalVar.lua +++ b/src/GlobalVar.lua @@ -321,4 +321,12 @@ DrawCardType = { SpecifyDraw = 1, NormalDraw = 2, FriendDraw = 3 +} + +-- 阵容系统类型 +TeamSystemType = { + Hang = 1, + BonusBattle = 2, + Tower = 3, + Dinner = 4, } \ No newline at end of file diff --git a/src/ProtocolCode.lua b/src/ProtocolCode.lua index fd97aee..fcb857d 100644 --- a/src/ProtocolCode.lua +++ b/src/ProtocolCode.lua @@ -49,6 +49,7 @@ actionCodes = { Role_updateFeedbackInfoRpc = 133, Role_useSelectItemRpc = 134, -- 使用多选一礼包 Role_broadGetSSR = 135, -- 全服广播 获得ssr英雄 + Role_renameTeamRpc = 136, -- 编队改名 Adv_startAdvRpc = 151, Adv_startHangRpc = 152, @@ -71,6 +72,7 @@ actionCodes = { Adv_rankRpc = 169, Adv_quickHangRpc = 170, Adv_refreshSupportRpc = 171, + Adv_selectTeamRpc = 172, Hero_loadInfos = 201, Hero_updateProperty = 202, @@ -111,6 +113,7 @@ actionCodes = { Hang_hangGiftRpc = 262, Hang_bagFieldRpc = 263, Hang_chatLineRpc = 264, + Hang_selectTeamRpc = 265, Diner_updateProperty = 300, Diner_addSellRpc = 301, diff --git a/src/actions/AdvAction.lua b/src/actions/AdvAction.lua index 38fb04b..1094180 100644 --- a/src/actions/AdvAction.lua +++ b/src/actions/AdvAction.lua @@ -47,6 +47,10 @@ local function checkFormat(role, format, checkAdvTeam) end end + if not format then + format = role:getProperty("advTeam") + end + if checkAdvTeam then for _, heroId in pairs(role:getProperty("advTeam").heros or {}) do hadHero[heroId] = true @@ -83,7 +87,7 @@ function _M.startAdvRpc( agent, data ) local msg = MsgPack.unpack(data) local chapterId = msg.chapterId --关卡id local layer = msg.layer or 1 --选择层数 - local format = msg.format --编队 + --local format = msg.format --编队 local supportIdx = msg.supportIdx --选择的支援效果 if not role:isFuncUnlock(FuncUnlock.Adv) then return end @@ -127,18 +131,18 @@ function _M.startAdvRpc( agent, data ) end end - if not checkFormat(role, format) then return 7 end - - local advTeam = role:getProperty("advTeam") - table.clear(advTeam) - - advTeam.heros = {} - for slot, heroId in pairs(format.heros) do - advTeam.heros[slot] = heroId - end - advTeam.leader = format.leader - advTeam.leader2 = format.leader2 - role:updateProperty({field = "advTeam", value = advTeam}) + if not checkFormat(role) then return 7 end + + --local advTeam = role:getProperty("advTeam") + --table.clear(advTeam) + + --advTeam.heros = {} + --for slot, heroId in pairs(format.heros) do + -- advTeam.heros[slot] = heroId + --end + --advTeam.leader = format.leader + --advTeam.leader2 = format.leader2 + --role:updateProperty({field = "advTeam", value = advTeam}) if AdvCommon.isEndless(chapterId) then role.dailyData:updateProperty({field = "advElC", delta = 1}) else @@ -950,4 +954,56 @@ function _M.refreshSupportRpc(agent, data) return true end +function _M.roleFormatRpc(agent , data) + local role = agent.role + local msg = MsgPack.unpack(data) + local index = msg.index -- 阵容索引 + local title = msg.title -- 阵容名称 + local team = {} + for slot, heroId in pairs(msg.heros) do + if not role.heros[heroId] then + return 1 + end + end + + if index > 10 then + return 2 + end + + team.heros = {} + for slot, heroId in pairs(msg.heros) do + team.heros[slot] = heroId + end + team.leader = msg.leader + team.leader2 = msg.leader2 + team.title = title + role:setAdvTeamFormat(index, team) + + local advTeam = role:getProperty("advTeam") + table.clear(advTeam) + + advTeam.heros = {} + for slot, heroId in pairs(msg.heros) do + advTeam.heros[slot] = heroId + end + advTeam.leader = msg.leader + advTeam.leader2 = msg.leader2 + role:updateProperty({field = "advTeam", value = advTeam}) + + SendPacket(actionCodes.Adv_roleFormatRpc, '') + return true +end + +function _M.selectTeamRpc(agent, data) + local role = agent.role + local msg = MsgPack.unpack(data) + local index = msg.index -- 阵容索引 + local team = role:getAdvTeamFormat(index) + if not next(team) then return end + role:updateProperty({field = "advTeam", value = team}) + + SendPacket(actionCodes.Adv_selectTeamRpc, '') + return true +end + return _M \ No newline at end of file diff --git a/src/actions/HangAction.lua b/src/actions/HangAction.lua index b87d9a5..bc61fe0 100644 --- a/src/actions/HangAction.lua +++ b/src/actions/HangAction.lua @@ -269,7 +269,15 @@ function _M.endBattleRpc(agent, data) local nextCarbonId = role:getNextCarbonId(carbonId) -- 设置挂机关卡 if isWin then --and (hangInfo.carbonId or 0) < nextCarbonId then - hangInfo.expCarbonId = carbonId + if not hangInfo.expCarbonId then + hangInfo.expCarbonId = carbonId + else + local oldCarbonData = csvdb["idle_battleCsv"][hangInfo.expCarbonId] + local newCarbonData = csvdb["idle_battleCsv"][carbonId] + if oldCarbonData.money < newCarbonData.money then + hangInfo.expCarbonId = carbonId + end + end --local cfg = csvdb["idle_battleCsv"][nextCarbonId] --if cfg then -- hangInfo.bossTime = skynet.timex() + cfg.idle_time @@ -305,7 +313,10 @@ end function _M.roleFormatRpc(agent , data) local role = agent.role local msg = MsgPack.unpack(data) - local hangTeam = role:getProperty("hangTeam") + local index = msg.index -- 阵容索引 + local title = msg.title -- 阵容名称 + local type = msg.type -- 系统类型 + local team = {} for slot, heroId in pairs(msg.heros) do if not role.heros[heroId] then return 1 @@ -321,15 +332,31 @@ function _M.roleFormatRpc(agent , data) end if not checkLeader(msg.heros, msg.leader) then return 4 end - table.clear(hangTeam) - hangTeam.heros = {} + if index > 10 then + return 5 + end + + if #title > 100 then + return 6 + end + + team.heros = {} for slot, heroId in pairs(msg.heros) do - hangTeam.heros[slot] = heroId + team.heros[slot] = heroId + end + team.leader = msg.leader + team.supports = supports + team.title = title + + role:setTeamFormat(index, team) + if type == TeamSystemType.Hang then + role:finishGuide(5) + role:updateHangTeamInfo() + elseif type == TeamSystemType.BonusBattle then + elseif type == TeamSystemType.Tower then + elseif type == TeamSystemType.Dinner then end - hangTeam.leader = msg.leader - hangTeam.supports = supports - role:saveHangTeam(hangTeam) - role:finishGuide(5) + SendPacket(actionCodes.Hang_roleFormatRpc, '') return true end @@ -523,7 +550,8 @@ function _M.startBonusBattleRpc(agent, data) if not bonusData then return 3 end if not role:checkHangPass(bonusData.unlock) then return 4 end - if not next(role:getProperty("bTeam")) then return 5 end + local bTeam = role:getTeamFormatByType(TeamSystemType.BonusBattle) + if not next(bTeam) then return 5 end local bonusC = role.dailyData:getProperty("bonusC") bonusC[bonusData.type] = bonusC[bonusData.type] or {c = 0, b = 0} @@ -666,4 +694,24 @@ function _M.chatLineRpc(agent, data) return true end +function _M.selectTeamRpc(agent, data) + local role = agent.role + local msg = MsgPack.unpack(data) + local index = msg.index -- 阵容索引 + local type = msg.type -- 系统类型 + + if index > 10 then + return 1 + end + local team = role:getTeamFormat(index) + if not next(team) then return 2 end + + local teamIndex = role:getProperty("teamIndex") or {} + teamIndex[type] = index + role:updateProperty({field = "teamIndex", value = teamIndex}) + + SendPacket(actionCodes.Hang_selectTeamRpc, '') + return true +end + return _M \ No newline at end of file diff --git a/src/actions/RoleAction.lua b/src/actions/RoleAction.lua index 0658ae2..9e14290 100644 --- a/src/actions/RoleAction.lua +++ b/src/actions/RoleAction.lua @@ -1255,4 +1255,28 @@ function _M.useSelectItemRpc(agent, data) return true end +function _M.renameTeamRpc(agent, data) + local role = agent.role + local msg = MsgPack.unpack(data) + local title = msg.title + local index = msg.index + local ispve = msg.ispve + if ispve then + local teams = role:getProperty("hangTeams") + local team = role:getTeamFormat(index) + team.title = title + teams[index] = team + role:updateProperty({field = "hangTeams", value = teams, notNotify = false}) + else + local teams = role:getProperty("advTeams") + local team = role:getAdvTeamFormat(index) + team.title = title + teams[index] = team + role:updateProperty({field = "advTeams", value = teams, notNotify = false}) + end + + SendPacket(actionCodes.Role_renameTeamRpc, "") + return true +end + return _M \ No newline at end of file diff --git a/src/models/Role.lua b/src/models/Role.lua index caddc08..f50be69 100644 --- a/src/models/Role.lua +++ b/src/models/Role.lua @@ -112,7 +112,9 @@ Role.schema = { hangBag = {"table", {}}, -- 背包 hangBagLimit = {"number", globalCsv.idle_field_origin}, --背包上限 bTeam = {"table", {}}, -- 奖励副本队伍 - heroFormate = {"table", {}}, -- 自选编队 {adv={}, hang={}} + hangTeams = {"table", {}}, -- pve自选编队 + teamIndex = {"table", {}}, -- 各个系统使用的编队索引 type->index 见TeamSystemType + advTeams = {"table", {}}, -- 拾荒自选编队 --引导相关 newerGuide = {"string","1=1"}, -- 新手引导 master=slave @@ -359,6 +361,8 @@ function Role:data() hangBag = self:getProperty("hangBag"), hangBagLimit = self:getProperty("hangBagLimit"), bTeam = self:getProperty("bTeam"), + hangTeams = self:getProperty("hangTeams"), + teamIndex = self:getProperty("teamIndex"), newerGuide = self:getProperty("newerGuide"), funcGuide = self:getProperty("funcGuide"), diff --git a/src/models/RoleBattle.lua b/src/models/RoleBattle.lua index eabb6f6..56e320a 100644 --- a/src/models/RoleBattle.lua +++ b/src/models/RoleBattle.lua @@ -57,7 +57,8 @@ function Role:checkBattle(battleType, params) end end, tower = function() - local towerF = self:getProperty("towerF") + --local towerF = self:getProperty("towerF") + local towerF = self:getTeamFormatByType(TeamSystemType.Tower) for slot, hero in pairs(self:getTeamHerosInfo(towerF.heros)) do selflist[slot] = hero.type end @@ -72,7 +73,8 @@ function Role:checkBattle(battleType, params) end end, bonus = function() - local bTeam = self:getProperty("bTeam") + --local bTeam = self:getProperty("bTeam") + local bTeam = self:getTeamFormatByType(TeamSystemType.BonusBattle) for slot, hero in pairs(self:getTeamHerosInfo(bTeam.heros)) do selflist[slot] = hero.type end diff --git a/src/models/RolePlugin.lua b/src/models/RolePlugin.lua index 4d83433..4eaa9a3 100644 --- a/src/models/RolePlugin.lua +++ b/src/models/RolePlugin.lua @@ -1132,7 +1132,8 @@ function RolePlugin.bind(Role) local now = skynet.timex() local ct = math.ceil((now - StdTowerRankTime) / 86400) --按天计算 365 * 27 < 10000 可以维持 27 年 local ct = 10000 - ct -- 越早的排名越靠前 - local towerTeam = self:getProperty("towerF") + --local towerTeam = self:getProperty("towerF") + local towerTeam = self:getTeamFormatByType(TeamSystemType.Tower) local battleV = self:getTeamBattleValue(towerTeam.heros) local score = (level * 10000 + ct) * 10000000 + battleV @@ -1324,6 +1325,52 @@ function RolePlugin.bind(Role) }) end + function Role:updateHangTeamInfo() + local team = self:getTeamFormatByType(TeamSystemType.Hang) + if not team then return end + + self:setProperties({ + hangTS = self:getTeamHerosInfo(team.heros), + hangTB = self:getTeamBattleInfo(team), + hangTBV = self:getTeamBattleValue(team.heros), + }) + end + + -- 设置pve阵容 + function Role:getTeamFormat(index) + local teams = self:getProperty("hangTeams") or {} + local team = teams[index] or {} + return team + end + + function Role:getTeamFormatByType(type) + local teamIndex = self:getProperty("teamIndex") or {} + local index = teamIndex[type] + if not index then return {} end + + return self:getTeamFormat(index) + end + + function Role:setTeamFormat(index, team) + local teams = self:getProperty("hangTeams") or {} + teams[index] = team + self:updateProperty({field = "hangTeams", value = teams, notNotify = false}) + end + + -- 设置拾荒编队阵容 + function Role:getAdvTeamFormat(index) + local teams = self:getProperty("advTeams") or {} + local team = teams[index] or {} + return team + end + + function Role:setAdvTeamFormat(index, team) + local teams = self:getProperty("advTeams") or {} + teams[index] = team + self:updateProperty({field = "advTeams", value = teams, notNotify = false}) + end + + function Role:savePvpCTeam(team) if not team then team = self:getProperty("pvpTC") -- libgit2 0.21.2