--[[ 这里为以后的自由选将功能打基础 添加新的自选将 1. FuncType定义新类型 2. GetFreeLineUpLineNumber定义自选将国别阵容 ]] local FreeLineUp_Model = {} local private = {} local EventSystem = require('Event/EventSystem') local free_lineup_pb = require('Proto/free_lineup_pb') local free_lineup_opt_pb = require('Proto/free_lineup_opt_pb') local free_lineup_opt_async_pb = require 'Proto.free_lineup_opt_async_pb' FreeLineUp_Model.FuncType = { Common = free_lineup_pb.Common, -- 通用选将 DemonGod = free_lineup_pb.DemonGod, -- 魔神降世 NationClimbTower = free_lineup_pb.NationTower, -- 四国爬塔 GvGFight = free_lineup_pb.GvGFight, -- GVG Storm = free_lineup_pb.Storm, -- 暴风自选将 TeamWar = free_lineup_pb.TeamWar, -- 天地群雄3v3——战团布阵 GuildMine = free_lineup_pb.Mine, -- 矿场 ThreeTeamFight = free_lineup_pb.ThreeTeamsPK, -- 三队演武 HeroMatch1v1 = free_lineup_pb.HeroMatch1v1, -- 天地群雄1v1 ChangAnSiege = free_lineup_pb.Siege, -- 长安城池战 SlgGvE = free_lineup_pb.SlgGve, -- 汉中风云 CountryNightBoss = free_lineup_pb.CountryNightBoss, -- 晚间boss DragonArtery = free_lineup_pb.DragonArtery, -- 龙脉 } FreeLineUp_Model.SetType = { Simulate = 1, -- 模拟上阵 Official = 2, -- 正式阵容 } FreeLineUp_Model.TeamIDS = { [1] = "IDS_NationClimbTower_QianJun", [2] = "IDS_NationClimbTower_ZhongJun", [3] = "IDS_NationClimbTower_HouJun", } FreeLineUp_Model.TabTypeIDS = { [1] = "IDS_Hero", [2] = "IDS_Equip_Equip", [3] = "IDS_Type_Horse", [4] = "IDS_FunctionName_Treasure", [5] = "IDS_Pet", } FreeLineUp_Model.TabIcons = { "wj", "zb", "zq", "bw", "cw", } -- 缓存的队伍数量 FreeLineUp_Model.TeamNums = { Single = 1, -- 一只队伍 Multi = 2, -- 多只队伍 } FreeLineUp_Model.FreeLineUpSlotUnlockList = DataSheetManager.ConstData:GetDataByID("DemonGodLineup").IntListValue function private.SortBasicHeroOrder(a, b) if a.heroBaseGs == b.heroBaseGs then -- 按照品质排序 local qualityA = DataSheetManager.HeroNum:GetDataByID(a.heroId).HeroQuality local qualityB = DataSheetManager.HeroNum:GetDataByID(b.heroId).HeroQuality if qualityA ~= qualityB then return qualityA > qualityB else if a.Rank ~= b.Rank then return a.Rank < b.Rank else return a.heroId < b.heroId end end end return a.heroBaseGs > b.heroBaseGs end function FreeLineUp_Model.OnStartup() NetManager.RegisterMsgCB(MessageEnums.MessageFreeLineUpGetInfo, private.FreeLineUpGetInfoResponse) -- 通用选将-请求玩法选将数据 NetManager.RegisterMsgCB(MessageEnums.MessageFreeLineUpGetInfoRepeated, private.FreeLineUpGetInfoRepeatedResponse) -- 通用选将-请求玩法选将数据 NetManager.RegisterMsgCB(MessageEnums.MessageFreeLineUpSet, private.FreeLineUpSetResponse) -- 通用选将-设置阵容 NetManager.RegisterMsgCB(MessageEnums.MessageUpdateLineUp,private.UpdateLineUpResp) -- 通用布阵-设置武将顺序 NetManager.RegisterMsgCB(MessageEnums.MessageFreeLineUpGetSlotInfo,private.FreeLineUpGetSlotInfoResponse) -- 通用布阵-请求阵容详情数据 NetManager.RegisterMsgCB(MessageEnums.MessageFreeLineUpSlotSet, private.FreeLineUpSlotSetResponse) -- 通用选将-设置阵容详情数据 NetManager.RegisterMsgCB(MessageEnums.MessageFreeLineUpLockOrClear, private.FreeLineUpLockOrClearResp) -- 通用选将-锁定阵容和阵容详情信息 NetManager.RegisterMsgCB(MessageEnums.MessageFreeLineUpExchange, private.FreeLineUpExchangeResp) -- 通用选将-选将阵容互换 -- 异步更新自由选将数据 NetManager.RegisterMsgCB(MessageEnums.MessageG2CFreeLineUpGetInfo, private.G2CFreeLineUpGetInfoResponse) -- 请求玩法选将数据 NetManager.RegisterMsgCB(MessageEnums.MessageG2CFreeLineUpSet,private.G2CFreeLineUpSetResponse) -- 通用布阵-设置武将顺序 NetManager.RegisterMsgCB(MessageEnums.MessageG2CFreeLineUpGetSlotInfo,private.G2CFreeLineUpGetSlotInfoResponse) -- 通用布阵-请求阵容详情数据 NetManager.RegisterMsgCB(MessageEnums.MessageG2CFreeLineUpSlotSet, private.G2CFreeLineUpSlotSetResponse) -- 通用选将-设置阵容详情数据 NetManager.RegisterMsgCB(MessageEnums.MessageG2CLineUpTypeExchange, private.G2CLineUpTypeExchange) NetManager.RegisterMsgCB(MessageEnums.MessageG2CPushFreeLineRedPoint, private.G2CPushFreeLineRedPoint) private.LineUpInfoList = {} -- 缓存所有玩法的布阵信息 private.SpareHeroInfoList = {} -- 已有武将的战力信息 private.LineUpSlotInfoList = {} -- 缓存所有玩法的阵容详情信息(装备、宝物、战骑、武将) private.CommonLineUpInfoDic = {} -- k:FunctionType; v:lineUpHeroIds -- 多人版布阵数据 private.LineUpDetailDict = {} -- 缓存所有玩法的布阵信息 k=FunctionType; v=FreeLineUpDetail private.SpareHeroInfoDict = {} -- 已有武将的战力信息 k=acid; v=hasHeroList end function FreeLineUp_Model.GetLineUpInfoByFunctionType(funcType, acid) if funcType == FreeLineUp_Model.FuncType.TeamWar then for _,v in ipairs(private.LineUpDetailDict[funcType]) do if v.acid == acid then return v end end return nil else return private.LineUpInfoList[funcType] end end function FreeLineUp_Model.IsLineUpHero(funcType) local lineUps = FreeLineUp_Model.GetLineUpInfoByFunctionType(funcType) if lineUps then for k,teamInfo in ipairs(lineUps) do for _, heroInfo in ipairs(teamInfo.heroInfos) do if heroInfo.heroId > 0 then return true end end end end return false end function FreeLineUp_Model.GetLineUpArrayIdListByFunctionType(funcType, isDetail) local lineNumber = FreeLineUp_Model.GetFreeLineUpLineNumber(funcType) local arrayIdList = {} local lineUpList = FreeLineUp_Model.GetLineUpInfoByFunctionType(funcType) if lineUpList and lineUpList[lineNumber] then local heroInfoList = lineUpList[lineNumber].heroInfos for _, v in ipairs(heroInfoList) do if isDetail then table.insert(arrayIdList, { heroId = v.heroId, isAwaken = v.heroAwaken }) else table.insert(arrayIdList, v.heroId) end end end if #arrayIdList > 0 then return arrayIdList else return MDL.Player.GetHeroLinUpIds() end end function FreeLineUp_Model.GetLineUpPowerListByFunctionType(funcType) local lineNumber = FreeLineUp_Model.GetFreeLineUpLineNumber(funcType) local lineUpPowerList = {0, 0, 0, 0, 0, 0} local lineUpList = FreeLineUp_Model.GetLineUpInfoByFunctionType(funcType) if lineUpList and lineUpList[lineNumber] then local heroInfoList = lineUpList[lineNumber].heroInfos for i, v in ipairs(heroInfoList) do lineUpPowerList[i] = v.heroBaseGs + v.lineUpGs end end return lineUpPowerList end function FreeLineUp_Model.GetLineUpTotalGsByFunctionType(funcType) local lineNumber = FreeLineUp_Model.GetFreeLineUpLineNumber(funcType) local lineUpList = FreeLineUp_Model.GetLineUpInfoByFunctionType(funcType) if lineUpList and lineUpList[lineNumber] then return lineUpList[lineNumber].TotalGs end return 0 end function FreeLineUp_Model.GetLineUpSpareHeroInfoList(funcType, acid) if funcType then local heroInfoList = private.SpareHeroInfoDict[funcType][acid] return (heroInfoList and #heroInfoList > 0) and heroInfoList or nil else return #private.SpareHeroInfoList > 0 and private.SpareHeroInfoList or nil end end --lineNumber 国别或者队列数 function FreeLineUp_Model.GetLineupHeroStar(funcType, index, acid, lineNumber) if funcType == FreeLineUp_Model.FuncType.TeamWar then local functionInfo = FreeLineUp_Model.GetLineUpInfoByFunctionType(funcType, acid) return functionInfo.lineUps[1].heroInfos[index].HeroBreakLv or 0 elseif funcType == FreeLineUp_Model.FuncType.ThreeTeamFight then local info = FreeLineUp_Model.GetLineNumberInfo(funcType, MDL.ThreeTeamFight.CurEditLineNumber) if info then if info.heroInfos then return info.heroInfos[index].HeroBreakLv or 0 end end return 0 else if lineNumber then for i, v in ipairs(FreeLineUp_Model.GetLineUpInfoByFunctionType(funcType)) do if v.lineNumber == lineNumber then return v.heroInfos[index].HeroBreakLv end end end return FreeLineUp_Model.GetLineUpInfoByFunctionType(funcType)[1].heroInfos[index].HeroBreakLv or 0 end end --lineNumber 国别或者队列数 function FreeLineUp_Model.GetLineupHeroAwaken(funcType, index, acid, lineNumber) if funcType == FreeLineUp_Model.FuncType.TeamWar then local functionInfo = FreeLineUp_Model.GetLineUpInfoByFunctionType(funcType, acid) return functionInfo.lineUps[1].heroInfos[index].heroAwaken elseif funcType == FreeLineUp_Model.FuncType.ThreeTeamFight then local info = FreeLineUp_Model.GetLineNumberInfo(funcType, MDL.ThreeTeamFight.CurEditLineNumber) if info then if info.heroInfos then return info.heroInfos[index].heroAwaken end end else if lineNumber then for i, v in ipairs(FreeLineUp_Model.GetLineUpInfoByFunctionType(funcType)) do if v.lineNumber == lineNumber then return v.heroInfos[index].heroAwaken end end end return FreeLineUp_Model.GetLineUpInfoByFunctionType(funcType)[1].heroInfos[index].heroAwaken end return false end -- 布阵槽位是否解锁 function FreeLineUp_Model.IsTeamSlotLocked(teamIndex) local teamLevel, unlockLv = MDL.HeroSelect.GetTeamLevel(), FreeLineUp_Model.FreeLineUpSlotUnlockList[teamIndex] if unlockLv == 999 then return true end return teamLevel < unlockLv end --region ***************** 协议 ******************** -- 获取系统的自由选将信息 function FreeLineUp_Model.FreeLineUpGetInfoRequest(funcType, srcLineNumber, destLineNumber) local msg = free_lineup_opt_pb.FreeLineUpGetInfoReq() msg.funcType = funcType if srcLineNumber and destLineNumber then for i, v in ipairs(srcLineNumber) do table.insert(msg.srcLineNumber, v) end for i, v in ipairs(destLineNumber) do table.insert(msg.destLineNumber, v) end end NetManager.SendMessage(MessageEnums.MessageFreeLineUpGetInfo, msg) end function private.FreeLineUpGetInfoResponse(msgResp) if msgResp.lineUpInfo.funcType then private.SetLineUpInfoList(msgResp.lineUpInfo) end private.SpareHeroInfoList = msgResp.spareHeroInfos table.sort(private.SpareHeroInfoList , private.SortBasicHeroOrder) EventSystem.Dispatch(EventID.UI_FreeLineUp_RefreshUI, msgResp.lineUpInfo.funcType) EventSystem.Dispatch(EventID.UI_FreeLineUp_RefreshSilk, msgResp.lineUpInfo.funcType, msgResp.lineUpInfo.silkBag) end -- 设置阵容 function FreeLineUp_Model.FreeLineUpSetRequest(funcType, lineNumber, setType, heroIds, isClose, acid, silkBag) local msg = free_lineup_opt_pb.FreeLineUpSetReq() msg.acid = acid or BattleDataGetter.GetAcID() msg.funcType = funcType msg.lineNumber = lineNumber msg.setType = setType for _, v in ipairs (heroIds) do table.insert(msg.heroIds, v) end if isClose ~= nil then msg.isClose = isClose end if silkBag then for _, v in ipairs (silkBag) do table.insert(msg.silkBag, v) end end NetManager.SendMessage(MessageEnums.MessageFreeLineUpSet, msg) end function private.FreeLineUpSetResponse(msgResp) local lineUps = private.LineUpInfoList[msgResp.funcType] if lineUps then local process = false for _, new in ipairs(msgResp.funcInfo.lineUps) do local lineNumber = new.lineNumber local find = false for i, old in ipairs(lineUps) do if old.lineNumber == lineNumber then process = true lineUps[i] = new find = true break end end if find == false then process = true table.insert(lineUps, new) end end if process == false then private.LineUpInfoList[msgResp.funcType] = msgResp.funcInfo.lineUps end else private.LineUpInfoList[msgResp.funcType] = msgResp.funcInfo.lineUps end EventSystem.Dispatch(EventID.UI_FreeLineUp_RefreshUI, msgResp.funcType) EventSystem.Dispatch(EventID.UI_FreeLineUp_RefreshSilk, msgResp.funcType, msgResp.funcInfo.silkBag) end -- 获取阵容详情的信息 function FreeLineUp_Model.FreeLineUpGetSlotInfoRequest(funcType, lineNumber, acid) local msg = free_lineup_opt_pb.FreeLineUpGetSlotInfoReq() msg.funcType = funcType msg.lineNumber = lineNumber msg.acid = acid or BattleDataGetter.GetAcID() NetManager.SendMessage(MessageEnums.MessageFreeLineUpGetSlotInfo, msg) end function private.FreeLineUpGetSlotInfoResponse(msgResp) if msgResp.funcType then if not private.LineUpSlotInfoList[msgResp.funcType] then private.LineUpSlotInfoList[msgResp.funcType] = {} end private.LineUpSlotInfoList[msgResp.funcType][msgResp.lineNumber] = msgResp.slotInfos EventSystem.Dispatch(EventID.UI_FreeLineUp_RefreshSlotDetailUI, msgResp.slotInfos, msgResp.slotsDetails, msgResp.petSlotNum, msgResp.petInfo, msgResp.petSlotBreak, msgResp.LineUpType) end end -- 设置阵容详情的信息 function FreeLineUp_Model.FreeLineUpSlotSetRequest(funcType, slotInfos, setType) local msg = free_lineup_opt_pb.FreeLineUpSlotSetReq() msg.funcType = funcType msg.lineNumber = FreeLineUp_Model.GetFreeLineUpLineNumber(funcType) for i,v in ipairs(slotInfos) do table.insert(msg.slotInfos,i,v) end msg.setType = setType or MDL.FreeLineUp.SetType.Official private.curFuncType = funcType NetManager.SendMessage(MessageEnums.MessageFreeLineUpSlotSet, msg) end function private.FreeLineUpSlotSetResponse(msgResp) --选择武将界面刷新继承战力 if msgResp.Resp.Code == 0 then MDL.FreeLineUp.FreeLineUpGetInfoRequest(private.curFuncType) end end --endregion ***************** 协议 ******************** --region **************** 异步刷新协议 ************************* -- 获取系统的自由选将信息,返回多份(例如heromatch3v3战团布阵) function FreeLineUp_Model.C2GFreeLineUpGetInfoRepeatRequest(funcType) local msg = free_lineup_opt_async_pb.C2GFreeLineUpGetInfoRepeat() msg.funcType = funcType NetManager.SendMessage(MessageEnums.MessageC2GFreeLineUpGetInfoRepeat, msg) end function private.G2CFreeLineUpGetInfoResponse(msgResp) -- 天地群雄3v3 布阵数据是三人版 local type = msgResp.lineUpInfo.funcType if not private.LineUpDetailDict[type] then private.LineUpDetailDict[type] = {} private.SpareHeroInfoDict[type] = {} end local isAdd = true for k,v in ipairs(private.LineUpDetailDict[type]) do if v.acid == msgResp.lineUpInfo.acid then private.LineUpDetailDict[type][k] = msgResp.lineUpInfo isAdd = false end end if isAdd then table.insert(private.LineUpDetailDict[type], msgResp.lineUpInfo) end private.SpareHeroInfoDict[type][msgResp.lineUpInfo.acid] = {} private.SpareHeroInfoDict[type][msgResp.lineUpInfo.acid] = msgResp.spareHeroInfos table.sort(private.SpareHeroInfoDict[type][msgResp.lineUpInfo.acid] , private.SortBasicHeroOrder) EventSystem.Dispatch(EventID.UI_FreeLineUp_RefreshUI, type, msgResp.LineUpType) end -- 设置阵容 function FreeLineUp_Model.C2GFreeLineUpSetRequest(funcType, lineNumber, setType, heroIds, isClose, OpAcid, silkBag) local msg = free_lineup_opt_async_pb.C2GFreeLineUpSet() msg.OpAcid = OpAcid msg.ReqAcid = BattleDataGetter.GetAcID() msg.funcType = funcType msg.lineNumber = lineNumber msg.setType = setType for _, v in ipairs (heroIds) do table.insert(msg.heroIds, v) end if isClose ~= nil then msg.isClose = isClose end if silkBag then for _, v in ipairs (silkBag) do table.insert(msg.silkBag, v) end end NetManager.SendMessage(MessageEnums.MessageC2GFreeLineUpSet, msg) end function private.G2CFreeLineUpSetResponse(msgResp) if msgResp.Code == 0 then if msgResp.funcType == FreeLineUp_Model.FuncType.TeamWar then for k,v in ipairs(private.LineUpDetailDict[msgResp.funcType]) do if v.acid == msgResp.funcInfo.acid then private.LineUpDetailDict[msgResp.funcType][k] = msgResp.funcInfo break end end else private.LineUpInfoList[msgResp.funcType] = msgResp.funcInfo.lineUps end EventSystem.Dispatch(EventID.UI_FreeLineUp_RefreshUI, msgResp.funcType) end end -- 获取阵容详情的信息 function FreeLineUp_Model.C2GFreeLineUpGetSlotInfoRequest(funcType, lineNumber, OpAcid) local msg = free_lineup_opt_async_pb.C2GFreeLineUpGetSlotInfo() msg.funcType = funcType msg.lineNumber = lineNumber msg.OpAcid = OpAcid msg.ReqAcid = BattleDataGetter.GetAcID() NetManager.SendMessage(MessageEnums.MessageC2GFreeLineUpGetSlotInfo, msg) end function private.G2CFreeLineUpGetSlotInfoResponse(msgResp) if (not msgResp.Code or msgResp.Code == 0) then if not private.LineUpSlotInfoList[msgResp.funcType] then private.LineUpSlotInfoList[msgResp.funcType] = {} end private.LineUpSlotInfoList[msgResp.funcType][msgResp.lineNumber] = msgResp.slotInfos EventSystem.Dispatch(EventID.UI_FreeLineUp_RefreshSlotDetailUI, msgResp.slotInfos, msgResp.slotsDetails, msgResp.petSlotNum, msgResp.petInfo, msgResp.petSlotBreak, msgResp.LineUpType) end end -- 设置槽位信息 function FreeLineUp_Model.C2GFreeLineUpSlotSetRequest(funcType, slotInfos, OpAcid) local msg = free_lineup_opt_async_pb.C2GFreeLineUpSlotSet() msg.OpAcid = OpAcid msg.ReqAcid = BattleDataGetter.GetAcID() msg.funcType = funcType msg.lineNumber = FreeLineUp_Model.GetFreeLineUpLineNumber(funcType) for i,v in ipairs(slotInfos) do table.insert(msg.slotInfos,i,v) end private.curFuncType = funcType NetManager.SendMessage(MessageEnums.MessageC2GFreeLineUpSlotSet, msg) end function private.G2CFreeLineUpSlotSetResponse(msgResp) --选择武将界面刷新继承战力 if msgResp.Code == 0 then MDL.FreeLineUp.C2GFreeLineUpGetInfoRepeatRequest(private.curFuncType) end end function FreeLineUp_Model.C2GLineUpTypeExchange(funcType, lineNumber1, lineNumber2) local msg = NetManager.GetPB("free_lineup_opt_async_pb").C2GLineUpTypeExchange() msg.ReqAcid = "" msg.funcType = funcType msg.lineUpTypeIdx1 = lineNumber1 msg.lineUpTypeIdx2 = lineNumber2 NetManager.SendMessage(MessageEnums.MessageC2GLineUpTypeExchange, msg) end --服务器异步比较麻烦,客户端请求 function private.G2CLineUpTypeExchange(msgResp) if msgResp.Code == 0 then MDL.FreeLineUp.C2GFreeLineUpGetInfoRepeatRequest(msgResp.funcType) end end function private.G2CPushFreeLineRedPoint(msgResp) if msgResp then for _, v in ipairs(msgResp.redPointInfos) do for funcName, funcType in pairs(FreeLineUp_Model.FuncType) do if v.funcType == funcType then CTL.RedPoint.AddRedPoint(CTL.RedPoint.RedPointKey[funcName .. "LineUp"]) break end end end end end --endregion ***************** 异步刷新协议 ******************** --region **************** 通用布阵 ************************* -- 获取通用布阵信息 function FreeLineUp_Model.GetCommonLineUpInfoByFunctionType(functionType) return private.CommonLineUpInfoDic[functionType] or MDL.Player.GetHeroLinUpIds() end -- 同步布阵信息 function FreeLineUp_Model.SyncCommonLineUpInfo(msg) for k,v in ipairs(msg) do private.CommonLineUpInfoDic[v.funcId] = v.lineUpHeroIds end EventSystem.Dispatch(EventID.UI_FreeLineUp_RefreshUI) end function FreeLineUp_Model.UpdateLineUpReq(lineUps, funcId) local msg = free_lineup_opt_pb.UpdateLineUpReq() msg.funcId = funcId for i,v in ipairs(lineUps) do table.insert(msg.lineUpHeroIds,v) end private.CommonLineUpInfoDic[funcId] = lineUps NetManager.SendMessage(MessageEnums.MessageUpdateLineUp,msg) end function private.UpdateLineUpResp(msg) -- 设置布阵数据成功后通过PlayerChange同步,这里不做处理 end -- 确认阵容信息锁定 function FreeLineUp_Model.FreeLineUpLockOrClearReq(funcType, isLock) local msg = free_lineup_opt_pb.FreeLineUpLockOrClearReq() msg.funcType = funcType msg.Lock = isLock or false msg.lineNumber = FreeLineUp_Model.GetFreeLineUpLineNumber(funcType) NetManager.SendMessage(MessageEnums.MessageFreeLineUpLockOrClear, msg) end function private.FreeLineUpLockOrClearResp(msg) if msg.Resp.Code == 0 then if msg.funcType == FreeLineUp_Model.FuncType.Storm then MDL.Storm.GetStormMainPanelInfoReq() elseif msg.funcType == FreeLineUp_Model.FuncType.GuildMine then EventSystem.Dispatch(EventID.UI_GuildMine_LineUpLockOrClear) elseif msg.funcType == FreeLineUp_Model.FuncType.ChangAnSiege or msg.funcType == FreeLineUp_Model.FuncType.DragonArtery then EventSystem.Dispatch(EventID.UI_ChangAnSiege_LineUpLockOrClear) elseif msg.funcType == FreeLineUp_Model.FuncType.CountryNightBoss then EventSystem.Dispatch(EventID.UI_CountryNightBoss_LineUpLockOrClear) elseif msg.funcType == FreeLineUp_Model.FuncType.SlgGvE then --阵容锁定后重新请求,需要更新客户端目前的缓存临时阵容信息 MDL.FreeLineUp.FreeLineUpGetInfoRequest(MDL.FreeLineUp.FuncType.SlgGvE) EventSystem.Dispatch(EventID.UI_SlgGvE_LineUpLockOrClear, true) end end end --自由选将阵容互换 function FreeLineUp_Model.FreeLineUpExchangeReq(funcType, lineNumber1, lineNumber2) local msg = free_lineup_opt_pb.FreeLineUpExchangeReq() msg.funcType = funcType msg.lineNumber1 = lineNumber1 msg.lineNumber2 = lineNumber2 NetManager.SendMessage(MessageEnums.MessageFreeLineUpExchange, msg) end function private.FreeLineUpExchangeResp(msgResp) if msgResp.Resp.Code == 0 then if not private.LineUpInfoList[msgResp.funcType] then return end local lineUps1, lineUps2, lineUpsIndex1, lineUpsIndex2 for i, v in ipairs(private.LineUpInfoList[msgResp.funcType]) do if v.lineNumber == msgResp.lineNumber1 then lineUps1 = v lineUpsIndex1 = i elseif v.lineNumber == msgResp.lineNumber2 then lineUps2 = v lineUpsIndex2 = i end if lineUps1 and lineUps2 and lineUpsIndex1 and lineUpsIndex2 then break end end if lineUps1 and lineUps2 and lineUpsIndex1 and lineUpsIndex2 then private.LineUpInfoList[msgResp.funcType][lineUpsIndex1] = lineUps2 private.LineUpInfoList[msgResp.funcType][lineUpsIndex1].lineNumber = msgResp.lineNumber1 private.LineUpInfoList[msgResp.funcType][lineUpsIndex2] = lineUps1 private.LineUpInfoList[msgResp.funcType][lineUpsIndex2].lineNumber = msgResp.lineNumber2 end EventSystem.Dispatch(EventID.UI_FreeLineUp_RefreshUI, msgResp.funcType) end end function private.SetLineUpInfoList(lineUpInfo) if not private.LineUpInfoList[lineUpInfo.funcType] then private.LineUpInfoList[lineUpInfo.funcType] = {} end private.LineUpInfoList[lineUpInfo.funcType] = lineUpInfo.lineUps EventSystem.Dispatch(EventID.UI_FreeLineUp_RefreshUI, lineUpInfo.funcType) end function FreeLineUp_Model.UpdateLineUpInfoList(funcType, lineUps) if not private.LineUpInfoList[funcType] then private.LineUpInfoList[funcType] = lineUps else for _, updateVo in ipairs(lineUps) do local hasLineNumber = false for i, v in ipairs(private.LineUpInfoList[funcType]) do if updateVo.lineNumber == v.lineNumber then hasLineNumber = true private.LineUpInfoList[funcType][i] = updateVo break end end if hasLineNumber == false then table.insert(private.LineUpInfoList[funcType], updateVo) end end end EventSystem.Dispatch(EventID.UI_FreeLineUp_RefreshUI, funcType) end --endregion **************** 通用布阵 ************************* --region ***************** 阵容详情(装备、宝物、战骑、武将) ******************** function FreeLineUp_Model.GetFreeLineUpSlotInfo(functionType) if private.LineUpSlotInfoList[functionType] then local lineNumber = FreeLineUp_Model.GetFreeLineUpLineNumber(functionType) return private.LineUpSlotInfoList[functionType][lineNumber] end end -- 获取这个玩法当前正在设置的队列序号。队列:一个玩法可以支持多组配置,一组配置称为一个队列,其索引序号为LineNumber function FreeLineUp_Model.GetFreeLineUpLineNumber(functionType) if functionType == FreeLineUp_Model.FuncType.DemonGod or functionType == FreeLineUp_Model.FuncType.GvGFight or functionType == FreeLineUp_Model.FuncType.TeamWar or functionType == FreeLineUp_Model.FuncType.HeroMatch1v1 then return 1 elseif functionType == FreeLineUp_Model.FuncType.NationClimbTower then --返回当前国别 return MDL.NationClimbTower.GetTowerOpenInfo() elseif functionType == FreeLineUp_Model.FuncType.GuildMine then --返回当前国别 return MDL.GuildMine.GetMineCurKingdomId() elseif functionType == FreeLineUp_Model.FuncType.Storm then return MDL.Storm.GetStormInfo().countryId elseif functionType == FreeLineUp_Model.FuncType.ThreeTeamFight then return MDL.ThreeTeamFight.CurEditLineNumber elseif functionType == FreeLineUp_Model.FuncType.CountryNightBoss then return CTL.CountryNightBoss.GetCurLimitKingdom() elseif functionType == FreeLineUp_Model.FuncType.ChangAnSiege then return CTL.ChangAnSiege.GetCurLimitKingdom() elseif functionType == FreeLineUp_Model.FuncType.DragonArtery then return CTL.DragonArtery.GetCurLimitKingdom() elseif functionType == FreeLineUp_Model.FuncType.SlgGvE then return CTL.SlgGvE.GetCurSelectTeamId() end end --获取武将的位置 function FreeLineUp_Model.GetHeroPosNumber(heroId, functionType, lineNumber) local lineUpList = MDL.FreeLineUp.GetLineUpInfoByFunctionType(functionType) if lineUpList then for _, v in ipairs(lineUpList) do if v.lineNumber == lineNumber then for i, heroInfo in ipairs(v.heroInfos) do if heroInfo.heroId == heroId then return heroInfo.posNumber end end break end end end return -1 end --判断阵容是否非法 function FreeLineUp_Model.CheckLineNumberIllegal(functionType, lineNumber) local lineUpList = MDL.FreeLineUp.GetLineUpInfoByFunctionType(functionType) if lineUpList and #lineUpList > 0 then for _, v in ipairs(lineUpList) do if v.lineNumber == lineNumber then if v.heroInfos == nil or #v.heroInfos == 0 then return true, Const_IDS.IDS_3TeamsPK_LaunchReminder1 else --1、不允许只上副将 for _, info1 in ipairs(v.heroInfos) do if info1.posNumber % 2 == 0 and info1.heroId > 0 then local hasMain = false for _, info2 in ipairs(v.heroInfos) do if info2.posNumber == info1.posNumber - 1 then hasMain = true if info2.heroId <= 0 then return true, Const_IDS.IDS_DemonGod_UI_12 else break end end end if hasMain == false then return true, Const_IDS.IDS_DemonGod_UI_12 end end end --2、至少上阵一组主副将 for _, info1 in ipairs(v.heroInfos) do if info1.posNumber % 2 == 1 and info1.heroId > 0 then for _, info2 in ipairs(v.heroInfos) do if info2.posNumber == info1.posNumber + 1 then if info2.heroId > 0 then return false else break end end end end end return true, Const_IDS.IDS_3TeamsPK_LaunchReminder1 end end end end return true, Const_IDS.IDS_3TeamsPK_LaunchReminder1 end --判断两组阵容是否有区别 function FreeLineUp_Model.CheckLineNumbersDiff(functionType, lineNumbers1, lineNumbers2) if #lineNumbers1 ~= #lineNumbers2 then return true end for i = 1, #lineNumbers1 do local lineNumber1 = lineNumbers1[i] local lineNumber2 = lineNumbers2[i] if FreeLineUp_Model.CheckSingleLineNumberDiff(functionType, lineNumber1, lineNumber2) then return true end end return false end function FreeLineUp_Model.CheckSingleLineNumberDiff(functionType, lineNumber1, lineNumber2) local lineUpList = MDL.FreeLineUp.GetLineUpInfoByFunctionType(functionType) if lineUpList then local heroInfos1, heroInfos2 for _, v in ipairs(lineUpList) do if v.lineNumber == lineNumber1 then heroInfos1 = v.heroInfos elseif v.lineNumber == lineNumber2 then heroInfos2 = v.heroInfos end end if heroInfos1 == nil and heroInfos2 == nil then return false end local count1 = heroInfos1 and #heroInfos1 or 0 local count2 = heroInfos2 and #heroInfos2 or 0 if count1 ~= count2 then return true end if count1 > 0 then for i, v in ipairs(heroInfos1) do local heroId1 = v.heroId local heroId2 = heroInfos2[i].heroId if heroId1 ~= heroId2 then return true end end end end return false end function FreeLineUp_Model.GetLineNumberInfo(functionType, lineNumber) local lineupInfo = FreeLineUp_Model.GetLineUpInfoByFunctionType(functionType) for i, v in ipairs(lineupInfo) do if lineNumber == v.lineNumber then return v end end return nil end --协议里的totalGS战力多了些别的模块的战力,与阵容内的武将战力对不上,需要单独计算 function FreeLineUp_Model.GetTotalGs(functionType, lineNumber) local info = FreeLineUp_Model.GetLineNumberInfo(functionType, lineNumber) if info and info.heroInfos then local totalFight = 0 for i, v in ipairs(info.heroInfos) do totalFight = totalFight + v.heroBaseGs + v.lineUpGs end return totalFight end return 0 end local function CountryIdSort(a,b) return a < b end --组合国别 -- 比如魏国1、蜀国2 ==> curKingdom为12; 魏国1、蜀国2、吴国3 ==> curKingdom为123 -- 如果四国 是Country_Model.CountryType.Han function FreeLineUp_Model.GetMultiCountryId(countryIdArray) table.sort(countryIdArray, CountryIdSort) local kingdomId = 0 for _, v in ipairs(countryIdArray) do kingdomId = kingdomId * 10 + v end if kingdomId > 1000 then kingdomId = MDL.Country.CountryType.Han end return kingdomId end --endregion return FreeLineUp_Model