MapEventComponentSystem.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Newtonsoft.Json;
  5. using Newtonsoft.Json.Linq;
  6. namespace ET.Server
  7. {
  8. [FriendOf(typeof (MapEventComponent))]
  9. [FriendOf(typeof (Map))]
  10. public static class MapEventComponentSystem
  11. {
  12. public class MapEventComponentAwakeSystem: AwakeSystem<MapEventComponent>
  13. {
  14. /// <summary>
  15. /// 场景事件组件创建
  16. /// </summary>
  17. /// <param name="self"></param>
  18. protected override void Awake(MapEventComponent self)
  19. {
  20. Log.Info($"创建战斗服事件组件...");
  21. }
  22. }
  23. public class MapEventComponentDestroySystem: DestroySystem<MapEventComponent>
  24. {
  25. /// <summary>
  26. /// 场景事件组件销毁
  27. /// </summary>
  28. /// <param name="self"></param>
  29. protected override void Destroy(MapEventComponent self)
  30. {
  31. Log.Info($"销毁战斗服事件组件...");
  32. }
  33. }
  34. /// <summary>
  35. /// 单位死亡事件
  36. /// </summary>
  37. /// <param name="self"></param>
  38. /// <param name="msg"></param>
  39. public static void OnUnitDead(this MapEventComponent self, JObject msg)
  40. {
  41. }
  42. /// <summary>
  43. /// 塔死亡事件
  44. /// </summary>
  45. /// <param name="self"></param>
  46. /// <param name="msg"></param>
  47. public static void OnDead(this MapEventComponent self, JObject msg)
  48. {
  49. Log.Debug($"塔死亡事件...");
  50. }
  51. /// <summary>
  52. /// 副本消息
  53. /// </summary>
  54. /// <param name="self"></param>
  55. /// <param name="msg"></param>
  56. public static void OnMessageEvent(this MapEventComponent self, JObject msg)
  57. {
  58. }
  59. /// <summary>
  60. /// 场景结算事件
  61. /// </summary>
  62. /// <param name="self"></param>
  63. public static void OnGameOver(this MapEventComponent self)
  64. {
  65. Map map = self.GetParent<Map>();
  66. map.IsGameOver = true;
  67. if (map.Players is not { Count: > 0 })
  68. {
  69. return;
  70. }
  71. foreach (WNPlayer player in map.Players.Values.Where(player => player != null))
  72. {
  73. // 记录玩家历史
  74. map.SyncPlayerHistoryData(player);
  75. // 战斗服场景玩家离开
  76. map.PlayerLeaveRequest(player, false);
  77. // 本地场景移除玩家
  78. map.RemovePlayer(player, false);
  79. // 战斗服结束场景
  80. map.GetZoneManager().destroyZoneRequest(map.Id.ToString());
  81. player.Map = null;
  82. }
  83. }
  84. /// <summary>
  85. /// 拾取道具
  86. /// </summary>
  87. /// <param name="self"></param>
  88. /// <param name="msg"></param>
  89. public static void OnPickItem(this MapEventComponent self, JObject msg)
  90. {
  91. }
  92. /// <summary>
  93. /// 击杀boss
  94. /// </summary>
  95. /// <param name="self"></param>
  96. /// <param name="msg"></param>
  97. public static void OnKillBoss(this MapEventComponent self, JObject msg)
  98. {
  99. }
  100. /// <summary>
  101. /// 战报统计
  102. /// </summary>
  103. /// <param name="self"></param>
  104. /// <param name="msg"></param>
  105. public static void OnBattleReport(this MapEventComponent self, JObject msg)
  106. {
  107. string data = Convert.ToString(msg.SelectToken("data"));
  108. if (string.IsNullOrEmpty(data))
  109. {
  110. return;
  111. }
  112. List<Struct.BattleReports> battleReports = JsonConvert.DeserializeObject<List<Struct.BattleReports>>(data);
  113. if (battleReports is not { Count: > 0 })
  114. {
  115. return;
  116. }
  117. Map map = self.GetParent<Map>();
  118. List<Struct.BattleReports> list = (from report in battleReports
  119. where report.Force == 1
  120. let ID = report.ID
  121. let PlayerUUID = string.IsNullOrEmpty(report.PlayerUUID)? "0" : report.PlayerUUID
  122. let TemplateID = report.TemplateId
  123. let Name = "玩家" + ID + "." + TemplateID
  124. let Force = report.Force
  125. let TotalDamage = report.TotalDamage
  126. select new Struct.BattleReports(ID, PlayerUUID, TemplateID, Name, Force, TotalDamage)).ToList();
  127. map.GetComponent<MapRankComponent>().UpdateRank(list, map);
  128. }
  129. }
  130. }