MapRankComponentSystem.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. namespace ET.Server
  5. {
  6. [FriendOf(typeof (MapRankComponent))]
  7. [FriendOfAttribute(typeof (Map))]
  8. public static class MapRankComponentSystem
  9. {
  10. public class MapRankComponentAwakeSystem: AwakeSystem<MapRankComponent>
  11. {
  12. /// <summary>
  13. /// 场景贡献榜组件创建
  14. /// </summary>
  15. /// <param name="self"></param>
  16. protected override void Awake(MapRankComponent self)
  17. {
  18. Log.Info($"创建场景贡献榜组件");
  19. }
  20. }
  21. public class MapRankComponentDestroySystem: DestroySystem<MapRankComponent>
  22. {
  23. /// <summary>
  24. /// 场景贡献榜组件销毁
  25. /// </summary>
  26. /// <param name="self"></param>
  27. protected override void Destroy(MapRankComponent self)
  28. {
  29. Log.Debug($"销毁场景贡献榜组件");
  30. }
  31. }
  32. /// <summary>
  33. /// 更新排行榜数据
  34. /// </summary>
  35. /// <param name="self"></param>
  36. /// <param name="dataList"></param>
  37. /// <param name="map"></param>
  38. public static void UpdateRank(this MapRankComponent self, List<Struct.BattleReports> dataList, Map map)
  39. {
  40. foreach (Struct.BattleReports data in dataList)
  41. {
  42. bool isExist = false;
  43. foreach (Struct.BattleReports br in self.RankList.Where(br => data.ID == br.ID))
  44. {
  45. isExist = true;
  46. br.TotalDamage = data.TotalDamage;
  47. }
  48. if (!isExist)
  49. {
  50. self.RankList.Add(data);
  51. }
  52. }
  53. self.Sort(map);
  54. }
  55. /// <summary>
  56. /// 排序
  57. /// </summary>
  58. /// <param name="self"></param>
  59. /// <param name="map"></param>
  60. private static void Sort(this MapRankComponent self, Map map)
  61. {
  62. List<Struct.BattleReports> list = new List<Struct.BattleReports>();
  63. self.RankList.ForEach(br => list.Add(br));
  64. if (list is { Count: > 0 })
  65. {
  66. list.Sort((r1, r2) => r2.TotalDamage.CompareTo(r1.TotalDamage));
  67. }
  68. self.ViewRankList.Clear();
  69. int ranking = 1;
  70. List<RankInfo> infoListProto = new List<RankInfo>();
  71. foreach (Struct.BattleReports battleReports in list.Where(battleReports => ranking <= 3))
  72. {
  73. // 客户端消息
  74. RankInfo info = new RankInfo();
  75. info.Name = battleReports.Name;
  76. info.Value = battleReports.TotalDamage;
  77. info.Ranking = ranking;
  78. infoListProto.Add(info);
  79. self.ViewRankList.Add(ranking, battleReports);
  80. ranking += 1;
  81. }
  82. bool isEqual = self.ViewRankList.Values.SequenceEqual(list);
  83. if (isEqual)
  84. {
  85. return;
  86. }
  87. foreach (WNPlayer player in map.Players.Values)
  88. {
  89. MessageHelper.SendToClient(player, new G2C_RankNotify() { InfoList = infoListProto });
  90. }
  91. }
  92. }
  93. }