local Rival_Model = {} local private = {} local EventSystem = require('Event/EventSystem') local rival_opt_pb = require("Proto/rival_opt_pb") ---------- start 辅助相关 start ---------- -- 新的table 老的table 里的对应key值,并返回是否发生过变化 local function UpdateTableChangeByKey(oldTb, newTb, key) local oldV = oldTb[key] local newV = newTb[key] if oldV ~= newV then oldTb[key] = newV return true end return false end -- 恩怨簿排序(按照记录时间顺序排序,时间越近越靠前) local function SortRivalRecord(a, b) return a.TimeStamp > b.TimeStamp end -- 移除仇敌追踪过期信息 local function RemoveOverdueData(tb) local curTime = UTL.Time.GetServerTimestamp() for i = #tb, 1, -1 do local data = tb[i] if curTime >= data.closeTime then table.remove(tb, i) end end end local TIME_IGNORE = DataSheetManager.ConstData:GetDataByID("WorldBossHelpIgoreCD").IntValue ---------- end 辅助相关 end ---------- -- 仇人状态 Rival_Model.RivalInfoPageIdentity = { Stranger = rival_opt_pb.Stranger, -- 陌生人 CommonEnemy = rival_opt_pb.CommonEnemy, -- 仇敌 SwornEnemy = rival_opt_pb.SwornEnemy, -- 死敌 } -- 仇人操作 Rival_Model.RivalOperationType = { RivalOptCommonEnemy = rival_opt_pb.RivalOptCommonEnemy, -- 设置(新增/修改)目标为仇敌 RivalOptSwornEnemy = rival_opt_pb.RivalOptSwornEnemy, -- 设置(新增/修改)目标为死敌 RivalOptRemoveList = rival_opt_pb.RivalOptRemoveList, -- 仇敌名单中移除。 } -- 设置界面key Rival_Model.RivalSettingKeyList = { OpenAutoConvert = "OpenAutoConvert", OpenRivalShoutingBlistering = "OpenRivalShoutingBlistering", OpenCommonShoutingBlistering = "OpenCommonShoutingBlistering", RivalShoutingContent = "RivalShoutingContent", CommonShoutingContent = "CommonShoutingContent", } -- 恩怨簿界面Tab页签 Rival_Model.RivalInfoType = { RivalInfoBeKilled = rival_opt_pb.RivalInfoBeKilled, RivalInfoKill = rival_opt_pb.RivalInfoKill, RivalInfoRecord = rival_opt_pb.RivalInfoRecord, } -- private.rivalSetting = { -- OpenAutoConvert = true or false, // 开启自动转换仇敌为死敌 -- OpenRivalShoutingBlistering = true or false, // 开启击杀仇敌后喊话 -- OpenCommonShoutingBlistering = true or false, // 开启击杀非仇敌喊话 -- RivalShoutingContent = XXX, // 仇杀喊话内容 -- CommonShoutingContent = XXX, // 普杀喊话内容 -- } function Rival_Model.OnStartup() private.rivalSetting = {} -- 仇敌系统设置 private.rivalRecord = {BeKilled = {}, Kill = {}, RivalHistory = {}} -- 恩怨簿 private.rivalTrackingList = {} -- 仇敌追踪列表 NetManager.RegisterMsgCB(MessageEnums.MessageRivalOperation, private.RivalOperationResponse) NetManager.RegisterMsgCB(MessageEnums.MessageG2CPushRivalOperation, private.SyncRivalOperation) NetManager.RegisterMsgCB(MessageEnums.MessageRivalSetting, private.RivalSettingResponse) NetManager.RegisterMsgCB(MessageEnums.MessageGetRivalHistoryInfo, private.GetRivalHistoryInfoResponse) NetManager.RegisterMsgCB(MessageEnums.MessageG2CPushPlayerSetSwornRival, private.SyncPlayerSetRival) NetManager.RegisterMsgCB(MessageEnums.MessageG2CPushRialTrackingInfo, private.SyncRialTrackingInfo) end ---------- start 协议相关 start ---------- -- #region 仇敌操作 function Rival_Model.RivalOperationRequest(targetAcid, optType) local msg = rival_opt_pb.RivalOperationReq() msg.TargetACID = targetAcid msg.OptType = optType NetManager.SendMessage(MessageEnums.MessageRivalOperation, msg) end function private.RivalOperationResponse(msgResp) -- 此处不做任何处理,等待 服务器推送 SyncRivalOperation 函数进行处理 end function private.SyncRivalOperation(msg) if msg.Success then if msg.OptType == Rival_Model.RivalOperationType.RivalOptCommonEnemy then if msg.Desc == rival_opt_pb.RelieveSwornRival then CTL.Tips.AddTipsMsg(string.FormatByIdsId(Const_IDS.IDS_Rival_DeleteEnemyTip, msg.TargetName)) else CTL.Tips.AddTipsMsg(string.FormatByIdsId(Const_IDS.IDS_Rival_AddRivalTip, msg.TargetName)) end elseif msg.OptType == Rival_Model.RivalOperationType.RivalOptSwornEnemy then CTL.Tips.AddTipsMsg(string.FormatByIdsId(Const_IDS.IDS_Rival_AddEnemyTip, msg.TargetName)) elseif msg.OptType == Rival_Model.RivalOperationType.RivalOptRemoveList then CTL.Tips.AddTipsMsg(string.FormatByIdsId(Const_IDS.IDS_Rival_DeleteRivalTip, msg.TargetName)) end -- 恩怨簿处理 EventSystem.Dispatch(EventID.UI_Rival_RequestRecord) else if msg.FailType == rival_opt_pb.FailAddRival then CTL.Tips.AddTipsMsg(Const_IDS.IDS_RivalNumLimit) elseif msg.FailType == rival_opt_pb.FailRemoveRival then CTL.Tips.AddTipsMsg(Const_IDS.IDS_Rival_TargetNotInRivalList) end end end -- #endregion -- #region 仇敌系统设置 -- context = { -- OpenAutoConvert = true or false, // 开启自动转换仇敌为死敌 -- OpenRivalShoutingBlistering = true or false, // 开启击杀仇敌后喊话 -- OpenCommonShoutingBlistering = true or false, // 开启击杀非仇敌喊话 -- RivalShoutingContent = XXX, // 仇杀喊话内容 -- CommonShoutingContent = XXX, // 普杀喊话内容 -- } -- context 不用全部包含字段,只会修改包含的字段 function Rival_Model.RivalSettingRequest(context) local msg = rival_opt_pb.RivalSettingReq() for k, v in pairs(private.rivalSetting) do local arg = context[k] if arg ~= nil then msg[k] = arg else msg[k] = v end end NetManager.SendMessage(MessageEnums.MessageRivalSetting, msg) end function private.RivalSettingResponse(msgResp) if msgResp.Resp.Code == 0 then CTL.Tips.AddTipsMsg(Const_IDS.IDS_Guild_CommonSucceed2) EventSystem.Dispatch(EventID.UI_Rival_CloseSlogan) end end -- #endregion -- #region 恩怨簿 function Rival_Model.GetRivalHistoryInfoRequest(infoType) local msg = rival_opt_pb.GetRivalHistoryInfoReq() msg.RivalInfoType = infoType NetManager.SendMessage(MessageEnums.MessageGetRivalHistoryInfo, msg) end function private.GetRivalHistoryInfoResponse(msgResp) if msgResp.Resp.Code ~= 0 then return end if IsServerDataNotNil(msgResp.BeKilledPageRecords) then for i, v in ipairs(msgResp.BeKilledPageRecords) do private.rivalRecord.BeKilled[i] = v end for i = #private.rivalRecord.BeKilled, #msgResp.BeKilledPageRecords + 1, -1 do table.remove(private.rivalRecord.BeKilled, i) end table.sort(private.rivalRecord.BeKilled, SortRivalRecord) end if IsServerDataNotNil(msgResp.KillPageRecords) then for i, v in ipairs(msgResp.KillPageRecords) do private.rivalRecord.Kill[i] = v end for i = #private.rivalRecord.Kill, #msgResp.KillPageRecords + 1, -1 do table.remove(private.rivalRecord.Kill, i) end table.sort(private.rivalRecord.Kill, SortRivalRecord) end if IsServerDataNotNil(msgResp.RivalHistoryRecords) then for i, v in ipairs(msgResp.RivalHistoryRecords) do private.rivalRecord.RivalHistory[i] = v end for i = #private.rivalRecord.RivalHistory, #msgResp.RivalHistoryRecords + 1, -1 do table.remove(private.rivalRecord.RivalHistory, i) end table.sort(private.rivalRecord.RivalHistory, SortRivalRecord) end EventSystem.Dispatch(EventID.UI_Rival_RefreshRecord) end -- #endregion -- #region 某玩家对我执行了死敌操作 function private.SyncPlayerSetRival(msg) if msg.NotifyType == rival_opt_pb.SetSwornRival then -- 设置为死敌 CTL.Tips.AddTipsMsg(string.FormatByIdsId(Const_IDS.IDS_Rival_AddEnemyReminder, msg.Name)) elseif msg.NotifyType == rival_opt_pb.RelieveSwornRival then -- 解除死敌 CTL.Tips.AddTipsMsg(string.FormatByIdsId(Const_IDS.IDS_Rival_DeleteEnemyReminder, msg.Name)) elseif msg.NotifyType == rival_opt_pb.SetCommonRival then -- 设置为仇敌 CTL.Tips.AddTipsMsg(string.FormatByIdsId(Const_IDS.IDS_Rival_AddRivalReminder, msg.Name)) end end -- #endregion -- #region 玩家仇杀追踪推送 function private.SyncRialTrackingInfo(msg) -- 在相同队伍 or 相同势力时不展示仇杀追踪 -- if CTL.Team.IsMemberInTeam(msg.PlayerShowInfo.acid) or MDL.Guild.IsSameGuild(msg.PlayerShowInfo.guildId) then -- return -- end -- 找出已经有的Acid信息 local trackingInfo = nil local findIndex = 0 for i, v in ipairs(private.rivalTrackingList) do if v.acid == msg.PlayerShowInfo.acid then findIndex = i trackingInfo = v end end -- 如果列表中存在该Acid的玩家,则更新记录,否侧创建新记录 if trackingInfo then -- 玩家展示信息 trackingInfo.acid = msg.PlayerShowInfo.acid trackingInfo.icon = msg.PlayerShowInfo.mainHeroId trackingInfo.playerName = msg.PlayerShowInfo.name trackingInfo.guildName = msg.PlayerShowInfo.guildName trackingInfo.guildId = msg.PlayerShowInfo.guildId trackingInfo.sceneID = msg.PlayerShowInfo.SceneID trackingInfo.portraitId = msg.PlayerShowInfo.PortraitId trackingInfo.frameId = msg.PlayerShowInfo.FrameId trackingInfo.isCross = msg.PlayerShowInfo.IsCross -- 玩家战斗信息 trackingInfo.syncBattleMapID = msg.PlayerBattleInfo.SyncBattleMapID trackingInfo.syncBattleSubID = msg.PlayerBattleInfo.SyncBattleSubID trackingInfo.syncBattleGRoomID = msg.PlayerBattleInfo.SyncBattleGRoomID trackingInfo.hatred = msg.Hatred trackingInfo.rivalTrackingReason = msg.RivalTrackingReason -- 推送原因 trackingInfo.closeTime = UTL.Time.GetServerTimestamp() + TIME_IGNORE -- 过期时间 table.remove(private.rivalTrackingList, findIndex) else trackingInfo = { acid = msg.PlayerShowInfo.acid, icon = msg.PlayerShowInfo.mainHeroId, playerName = msg.PlayerShowInfo.name, guildName = msg.PlayerShowInfo.guildName, guildId = msg.PlayerShowInfo.guildId, sceneID = msg.PlayerShowInfo.SceneID, portraitId = msg.PlayerShowInfo.PortraitId, frameId = msg.PlayerShowInfo.FrameId, isCross = msg.PlayerShowInfo.IsCross, -- 玩家战斗信息 syncBattleMapID = msg.PlayerBattleInfo.SyncBattleMapID, syncBattleSubID = msg.PlayerBattleInfo.SyncBattleSubID, syncBattleGRoomID = msg.PlayerBattleInfo.SyncBattleGRoomID, hatred = msg.Hatred, rivalTrackingReason = msg.RivalTrackingReason, -- 推送原因 closeTime = UTL.Time.GetServerTimestamp() + TIME_IGNORE, } end table.insert(private.rivalTrackingList, trackingInfo) CTL.Rival.ShowRivalRemind(#private.rivalTrackingList > 0) EventSystem.Dispatch(EventID.UI_Rival_RefreshRemindMessageList) end -- #endregion function Rival_Model.SyncRivalBriefInfo(msg) -- 仇人红点逻辑(此版本暂时不处理) -- local redPointChange = false -- 仇人设置 local settingChange = false for _, key in pairs(Rival_Model.RivalSettingKeyList) do local isChange = UpdateTableChangeByKey(private.rivalSetting, msg, key) if key == Rival_Model.RivalSettingKeyList.RivalShoutingContent then if string.isNilOrEmpty(private.rivalSetting[key]) then private.rivalSetting[key] = UIUtils.GetLocalizedTxt(Const_IDS.IDS_Rival_InitialtRevengeShoutoutText) end elseif key == Rival_Model.RivalSettingKeyList.CommonShoutingContent then if string.isNilOrEmpty(private.rivalSetting[key]) then private.rivalSetting[key] = UIUtils.GetLocalizedTxt(Const_IDS.IDS_Rival_InitialtKillShoutoutText) end end settingChange = settingChange or isChange end if settingChange then EventSystem.Dispatch(EventID.UI_Rival_RefreshSetting) end end ---------- end 协议相关 end ---------- ---------- start 数据相关 start ---------- function Rival_Model.GetRivalSettingIterator() return pairs(private.rivalSetting) end function Rival_Model.GetRivalRecordIteratorByType(infoType) if infoType == Rival_Model.RivalInfoType.RivalInfoBeKilled then return ipairs(private.rivalRecord.BeKilled) elseif infoType == Rival_Model.RivalInfoType.RivalInfoKill then return ipairs(private.rivalRecord.Kill) elseif infoType == Rival_Model.RivalInfoType.RivalInfoRecord then return ipairs(private.rivalRecord.RivalHistory) else return ipairs({}) end end function Rival_Model.AutoShowRivalRemind() -- 移除过期信息 RemoveOverdueData(private.rivalTrackingList) CTL.Rival.ShowRivalRemind(#private.rivalTrackingList > 0) end function Rival_Model.GetRivalTrackingIterator() -- 移除过期信息 RemoveOverdueData(private.rivalTrackingList) return ipairs(private.rivalTrackingList) end function Rival_Model.GetLastRivalTrackingAndAllCount() -- 移除过期信息 RemoveOverdueData(private.rivalTrackingList) local count = #private.rivalTrackingList if count >= 1 then return private.rivalTrackingList[count], count else return nil, count end end function Rival_Model.DeleteRivalTracking(acid) for i, v in ipairs(private.rivalTrackingList) do if v.acid == acid then table.remove(private.rivalTrackingList, i) break end end -- 移除过期信息 RemoveOverdueData(private.rivalTrackingList) EventSystem.Dispatch(EventID.UI_Rival_RefreshRemindMessageList) if #private.rivalTrackingList <= 0 then CTL.Rival.ShowRivalRemind(false) end end function Rival_Model.ClearAllRivalTracking() table.clearArray(private.rivalTrackingList) CTL.Rival.ShowRivalRemind(false) EventSystem.Dispatch(EventID.UI_Rival_RefreshRemindMessageList) end ---------- end 数据相关 end ---------- return Rival_Model