| | |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using UnityEngine; |
| | | using LitJson; |
| | | using System; |
| | |
| | | public class ArenaManager : GameSystemManager<ArenaManager> |
| | | { |
| | | public readonly int rankType = 1; // 榜单类型 |
| | | public readonly int corssRankType = 151; // 榜单类型 |
| | | public readonly int funcId = 27; // 功能Id |
| | | public readonly int DeployTroopsFuncId = 31; // 布阵功能ID |
| | | public readonly int BattleChangeTabFuncId = 32; // 战斗能切换页签功能ID |
| | |
| | | public Dictionary<int, int[][]> dailyRankRewards; // 每日排行奖励 {"名次":[[物品ID, 个数,是否拍品], ...], ...} 配置的名次key,自动按小于等于对应名次给奖励 |
| | | public Dictionary<int, int[][]> seasonRankRewards; // 赛季排行奖励 {"名次":[[物品ID, 个数,是否拍品], ...], ...} |
| | | |
| | | public Dictionary<int, int> crossRewardTemps;//数值2:跨服赛季排行奖励模版 {"互通服务器数";对应活动排行奖励表模版编号, ...} 按小于等于判断,大于最大配置的服务器数时默认取配置中最大服务器数对应奖励 |
| | | public Dictionary<int, int[][]> crossWeekRewards; |
| | | public uint score; // 当前积分 |
| | | public int totalWinCnt; //累计胜利次数 |
| | | |
| | |
| | | public event Action OnArenaMatchListEvent; |
| | | public event Action OnUpdateArenaPlayerInfo; |
| | | public event Action OnUpdateGameRecInfo; |
| | | |
| | | private int lastLocalWeekday; // 上次本服weekday (1-7, 周一=1, 周日=7) |
| | | private int lastCrossWeekday; // 上次跨服weekday |
| | | |
| | | public override void Init() |
| | | { |
| | | DTC0102_tagCDBPlayer.beforePlayerDataInitializeEventOnRelogin += BeforePlayerDataInitializeEventOnRelogin; |
| | | PlayerDatas.Instance.playerDataRefreshEvent += PlayerDataRefresh; |
| | | GlobalTimeEvent.Instance.secondEvent += OnSecondEvent; |
| | | CrossServerBaseManager.Instance.OnCrossZoneInfoUpdateEvent += OnCrossZoneInfoUpdate; |
| | | InitTable(); |
| | | InitRedpoint(); |
| | | InitCrossServerState(); |
| | | } |
| | | |
| | | public override void Release() |
| | | { |
| | | DTC0102_tagCDBPlayer.beforePlayerDataInitializeEventOnRelogin -= BeforePlayerDataInitializeEventOnRelogin; |
| | | PlayerDatas.Instance.playerDataRefreshEvent -= PlayerDataRefresh; |
| | | GlobalTimeEvent.Instance.secondEvent -= OnSecondEvent; |
| | | CrossServerBaseManager.Instance.OnCrossZoneInfoUpdateEvent -= OnCrossZoneInfoUpdate; |
| | | } |
| | | |
| | | void InitCrossServerState() |
| | | { |
| | | lastLocalWeekday = TimeUtility.GetCommonWeekday(); // zoneID=0本服 |
| | | int crossZoneID = GetCrossZoneID(); |
| | | lastCrossWeekday = crossZoneID > 0 ? TimeUtility.GetCommonWeekday(crossZoneID) : lastLocalWeekday; |
| | | } |
| | | |
| | | void OnSecondEvent() |
| | | { |
| | | CheckCrossWeekChange(); |
| | | } |
| | | |
| | | // 跨服状态更新事件处理 |
| | | void OnCrossZoneInfoUpdate(int mapID) |
| | | { |
| | | if (mapID != DataMapID) |
| | | return; |
| | | |
| | | bool currentIsOpenCrossServer = IsOpenCrossServer(); |
| | | |
| | | // 只会从未跨服变为跨服,变为跨服时关闭ArenaWin |
| | | if (currentIsOpenCrossServer) |
| | | { |
| | | CloseArenaWinAndClearData(); |
| | | } |
| | | |
| | | int crossZoneID = GetCrossZoneID(); |
| | | lastCrossWeekday = crossZoneID > 0 ? TimeUtility.GetCommonWeekday(crossZoneID) : TimeUtility.GetCommonWeekday(); |
| | | } |
| | | |
| | | int GetCrossZoneID() |
| | | { |
| | | var crossZoneInfo = CrossServerBaseManager.Instance.GetCrossZoneInfo(DataMapID); |
| | | return crossZoneInfo != null ? (int)crossZoneInfo.ZoneID : 0; |
| | | } |
| | | |
| | | void CheckCrossWeekChange() |
| | | { |
| | | int currentLocalWeekday = TimeUtility.GetCommonWeekday(); // zoneID=0本服 |
| | | int crossZoneID = GetCrossZoneID(); |
| | | int currentCrossWeekday = crossZoneID > 0 ? TimeUtility.GetCommonWeekday(crossZoneID) : currentLocalWeekday; |
| | | |
| | | // 条件1: 本服时间过周 (weekday从7变为1, 周日->周一) |
| | | if (lastLocalWeekday == 7 && currentLocalWeekday == 1) |
| | | { |
| | | CloseArenaWinAndClearData(); |
| | | } |
| | | lastLocalWeekday = currentLocalWeekday; |
| | | |
| | | bool currentIsOpenCrossServer = IsOpenCrossServer(); |
| | | if (!currentIsOpenCrossServer) |
| | | return; |
| | | // 条件2: 跨服时间过周 (weekday从7变为1, 周日->周一) |
| | | if (crossZoneID > 0 && lastCrossWeekday == 7 && currentCrossWeekday == 1) |
| | | { |
| | | CloseArenaWinAndClearData(); |
| | | } |
| | | lastCrossWeekday = currentCrossWeekday; |
| | | } |
| | | |
| | | void CloseArenaWinAndClearData() |
| | | { |
| | | if (UIManager.Instance.IsOpened<ArenaWin>()) |
| | | { |
| | | UIManager.Instance.CloseWindow<ArenaWin>(); |
| | | } |
| | | matchInfoList.Clear(); |
| | | gameRecDict.Clear(); |
| | | } |
| | | |
| | | public void BeforePlayerDataInitializeEventOnRelogin() |
| | |
| | | config = FuncConfigConfig.Get("ArenaBillboradAward"); |
| | | dailyRankRewards = ConfigParse.ParseIntArray2Dict(config.Numerical1); |
| | | seasonRankRewards = ConfigParse.ParseIntArray2Dict(config.Numerical2); |
| | | |
| | | config = FuncConfigConfig.Get("ArenaCross"); |
| | | crossRewardTemps = ConfigParse.ParseIntDict(config.Numerical2); |
| | | } |
| | | public void UpdateRedPonit() |
| | | { |
| | |
| | | RealmLV = item.RealmLV, |
| | | FightPower = (ulong)item.FightPowerEx * 100000000 + (ulong)item.FightPower, |
| | | Face = item.Face, |
| | | FacePic = item.FacePic |
| | | FacePic = item.FacePic, |
| | | TitleID = item.TitleID, |
| | | ServerID = item.ServerID, |
| | | }; |
| | | matchInfoList.Add(matchInfo); |
| | | allFaceInfoDict[item.PlayerID] = matchInfo; |
| | |
| | | string name = userData["Name"].ToString(); |
| | | int addScore = int.Parse(userData["AddScore"].ToString()); |
| | | ulong fightPower = ulong.Parse(userData["FightPower"].ToString()); |
| | | uint serverID = 0; |
| | | if (userData.ContainsKey("ServerID")) |
| | | { |
| | | serverID = uint.Parse(userData["ServerID"].ToString()); |
| | | } |
| | | uint cross = 0; |
| | | if (userData.ContainsKey("Cross")) |
| | | { |
| | | cross = uint.Parse(userData["Cross"].ToString()); |
| | | } |
| | | |
| | | var arenaGameRec = new ArenaGameRec |
| | | { |
| | |
| | | Value8 = rec.Value8, |
| | | Name = name, |
| | | AddScore = addScore, |
| | | FightPower = fightPower |
| | | FightPower = fightPower, |
| | | ServerID = serverID, |
| | | Cross = cross |
| | | }; |
| | | |
| | | gameRecDict[recID].Add(arenaGameRec); |
| | |
| | | seasonEndDate = new DateTime(sunday.Year, sunday.Month, sunday.Day, 23, 59, 59); |
| | | } |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// 根据recID获取按时间从大到小排序的List<ArenaGameRec> |
| | | /// </summary> |
| | |
| | | PlayerDatas.Instance.baseData.FightPower : |
| | | FightPowerManager.Instance.GetTeamFightPower(TeamManager.Instance.GetTeamID(BattlePreSetType.Arena), false); |
| | | } |
| | | |
| | | public readonly int DataMapID = 3; |
| | | public bool IsOpenCrossServer() |
| | | { |
| | | bool isOpenCrossServer = CrossServerBaseManager.Instance.IsOpenCrossServer(DataMapID); |
| | | return isOpenCrossServer; |
| | | } |
| | | |
| | | public Dictionary<int, int[][]> GetCrossArenaAwardDict(int functionOrder) |
| | | { |
| | | return functionOrder switch |
| | | { |
| | | 0 => dailyRankRewards, |
| | | 1 => seasonRankRewards, |
| | | 2 => GetCrossWeekRewards(), |
| | | _ => new Dictionary<int, int[][]>() |
| | | }; |
| | | } |
| | | public Dictionary<int, int[][]> GetCrossWeekRewards() |
| | | { |
| | | var crossZoneInfo = CrossServerBaseManager.Instance.GetCrossZoneInfo(DataMapID); |
| | | if (crossZoneInfo == null || crossZoneInfo.ServerIDList == null || crossRewardTemps.IsNullOrEmpty()) |
| | | { |
| | | return new Dictionary<int, int[][]>(); |
| | | } |
| | | |
| | | int serverCount = crossZoneInfo.ServerIDList.Length; |
| | | |
| | | // 先对key进行排序,避免遍历顺序依赖 |
| | | var sortedKeys = crossRewardTemps.Keys.OrderBy(k => k).ToList(); |
| | | |
| | | int templateID = 0; |
| | | int matchedKey = 0; |
| | | |
| | | foreach (var key in sortedKeys) |
| | | { |
| | | if (key <= serverCount && key >= matchedKey) |
| | | { |
| | | matchedKey = key; |
| | | templateID = crossRewardTemps[key]; |
| | | } |
| | | } |
| | | |
| | | // 如果没有匹配的key(serverCount小于所有配置的key),取最小key对应的奖励 |
| | | if (templateID == 0 && sortedKeys.Count > 0) |
| | | { |
| | | var minKey = sortedKeys[0]; |
| | | templateID = crossRewardTemps[minKey]; |
| | | } |
| | | |
| | | if (templateID == 0) return new Dictionary<int, int[][]>(); |
| | | |
| | | var rankList = ActBillboardAwardConfig.GetRankASortList(templateID); |
| | | if (rankList.IsNullOrEmpty()) return new Dictionary<int, int[][]>(); |
| | | |
| | | var result = new Dictionary<int, int[][]>(); |
| | | foreach (var rankA in rankList) |
| | | { |
| | | var config = ActBillboardAwardConfig.GetConfig(templateID, rankA); |
| | | if (config?.AwardItemList != null) |
| | | { |
| | | result[rankA] = config.AwardItemList; |
| | | } |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获得当前赛季的起止日期(跨服版本)。赛季从周一 00:00:00 开始,到周日 23:59:59 结束。 |
| | | /// 服务端定义周一为每周的第一天。 |
| | | /// </summary> |
| | | /// <param name="zoneID">跨服zoneID,0表示本服时间,非0表示跨服时间</param> |
| | | /// <param name="seasonStartDate">输出参数:赛季的起始日期(本周一 00:00:00)</param> |
| | | /// <param name="seasonEndDate">输出参数:赛季的结束日期(本周日 23:59:59)</param> |
| | | public void GetCrossCurrentSeasonDates(int zoneID, out DateTime seasonStartDate, out DateTime seasonEndDate) |
| | | { |
| | | DateTime now = TimeUtility.GetCommServerNow(zoneID); |
| | | // 为了符合周一是一周第一天的计算标准,将周日视为一周的第7天。 |
| | | int currentDayOfWeek = (int)now.DayOfWeek; |
| | | if (currentDayOfWeek == 0) // 如果是周日 (Sunday = 0) |
| | | { |
| | | currentDayOfWeek = 7; |
| | | } |
| | | DateTime monday = now.AddDays(-(currentDayOfWeek - 1)); |
| | | seasonStartDate = new DateTime(monday.Year, monday.Month, monday.Day, 0, 0, 0); |
| | | DateTime sunday = seasonStartDate.AddDays(6); |
| | | seasonEndDate = new DateTime(sunday.Year, sunday.Month, sunday.Day, 23, 59, 59); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | public ulong FightPower; //战力 |
| | | public uint Face; //基本脸型 |
| | | public uint FacePic; //头像框 |
| | | public uint ServerID; |
| | | |
| | | } |
| | | |
| | |
| | | public int AddScore; //本次自己变更的积分,有正负 |
| | | public ulong FightPower; //目标战力 |
| | | public int TitileId; //未来接入 |
| | | public uint ServerID; //对手区服ID |
| | | public uint Cross; //是否跨服记录 |
| | | |
| | | } |