123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace ET.Server
- {
- [FriendOf(typeof (MapRankComponent))]
- [FriendOfAttribute(typeof (Map))]
- public static class MapRankComponentSystem
- {
- public class MapRankComponentAwakeSystem: AwakeSystem<MapRankComponent>
- {
- /// <summary>
- /// 场景贡献榜组件创建
- /// </summary>
- /// <param name="self"></param>
- protected override void Awake(MapRankComponent self)
- {
- Log.Info($"创建场景贡献榜组件");
- }
- }
- public class MapRankComponentDestroySystem: DestroySystem<MapRankComponent>
- {
- /// <summary>
- /// 场景贡献榜组件销毁
- /// </summary>
- /// <param name="self"></param>
- protected override void Destroy(MapRankComponent self)
- {
- Log.Debug($"销毁场景贡献榜组件");
- }
- }
- /// <summary>
- /// 更新排行榜数据
- /// </summary>
- /// <param name="self"></param>
- /// <param name="dataList"></param>
- /// <param name="map"></param>
- public static void UpdateRank(this MapRankComponent self, List<Struct.BattleReports> dataList, Map map)
- {
- foreach (Struct.BattleReports data in dataList)
- {
- bool isExist = false;
- foreach (Struct.BattleReports br in self.RankList.Where(br => data.ID == br.ID))
- {
- isExist = true;
- br.TotalDamage = data.TotalDamage;
- }
- if (!isExist)
- {
- self.RankList.Add(data);
- }
- }
- self.Sort(map);
- }
- /// <summary>
- /// 排序
- /// </summary>
- /// <param name="self"></param>
- /// <param name="map"></param>
- private static void Sort(this MapRankComponent self, Map map)
- {
- List<Struct.BattleReports> list = new List<Struct.BattleReports>();
- self.RankList.ForEach(br => list.Add(br));
- if (list is { Count: > 0 })
- {
- list.Sort((r1, r2) => r2.TotalDamage.CompareTo(r1.TotalDamage));
- }
- int ranking = 1;
- List<RankInfo> infoListProto = new List<RankInfo>();
- foreach (Struct.BattleReports battleReports in list.Where(battleReports => ranking <= 3))
- {
- // 客户端消息
- RankInfo info = new RankInfo();
- info.Name = battleReports.Name;
- info.Ranking = ranking;
- infoListProto.Add(info);
- ranking += 1;
- }
- bool isEqual = self.IsEqual(infoListProto);
- if (isEqual)
- {
- return;
- }
- self.LastInfoListProto = infoListProto;
- // 推送客户端
- if (map.Player != null)
- {
- MessageHelper.SendToClient(map.Player, new G2C_RankNotify() { InfoList = infoListProto });
- }
- }
- private static bool IsEqual(this MapRankComponent self, List<RankInfo> infoList)
- {
- if (self.LastInfoListProto.Count != infoList.Count)
- {
- return false;
- }
- for (int i = 0; i < infoList.Count; i++)
- {
- RankInfo info1 = infoList[i];
- RankInfo info2 = self.LastInfoListProto[i];
- if (info1 != null && info2 != null && (!info1.Name.Trim().Equals(info2.Name.Trim()) || info1.Ranking != info2.Ranking))
- {
- return false;
- }
- }
- return true;
- }
- }
- }
|