MapEventComponentSystem.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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 OnMessageEvent(this MapEventComponent self, JObject msg)
  48. {
  49. switch (Convert.ToString(msg.SelectToken("msg")))
  50. {
  51. case "Dead:Tower1":
  52. {
  53. Log.Debug($"塔1死亡事件...");
  54. self.GetParent<Map>().DeadUnits.Add(1001);
  55. return;
  56. }
  57. case "Dead:Tower2":
  58. {
  59. Log.Debug($"塔2死亡事件...");
  60. self.GetParent<Map>().DeadUnits.Add(1002);
  61. return;
  62. }
  63. case "Dead:Tower3":
  64. {
  65. Log.Debug($"塔3死亡事件...");
  66. self.GetParent<Map>().DeadUnits.Add(1003);
  67. return;
  68. }
  69. }
  70. }
  71. /// <summary>
  72. /// 场景结算事件
  73. /// </summary>
  74. /// <param name="self"></param>
  75. public static void OnGameOver(this MapEventComponent self)
  76. {
  77. Map map = self.GetParent<Map>();
  78. map.IsGameOver = true;
  79. if (map.Players is not { Count: > 0 })
  80. {
  81. return;
  82. }
  83. foreach (WNPlayer player in map.Players.Values.Where(player => player != null))
  84. {
  85. // 记录玩家历史
  86. map.SyncPlayerHistoryData(player);
  87. // 战斗服场景玩家离开
  88. map.PlayerLeaveRequest(player, false);
  89. // 本地场景移除玩家
  90. map.RemovePlayer(player, false);
  91. // 战斗服结束场景
  92. map.GetZoneManager().destroyZoneRequest(map.Id.ToString());
  93. player.Map = null;
  94. }
  95. }
  96. /// <summary>
  97. /// 拾取道具
  98. /// </summary>
  99. /// <param name="self"></param>
  100. /// <param name="msg"></param>
  101. public static void OnPickItem(this MapEventComponent self, JObject msg)
  102. {
  103. }
  104. /// <summary>
  105. /// 击杀boss
  106. /// </summary>
  107. /// <param name="self"></param>
  108. /// <param name="msg"></param>
  109. public static void OnKillBoss(this MapEventComponent self, JObject msg)
  110. {
  111. }
  112. /// <summary>
  113. /// 战报统计
  114. /// </summary>
  115. /// <param name="self"></param>
  116. /// <param name="msg"></param>
  117. public static void OnBattleReport(this MapEventComponent self, JObject msg)
  118. {
  119. string data = Convert.ToString(msg.SelectToken("data"));
  120. if (string.IsNullOrEmpty(data))
  121. {
  122. return;
  123. }
  124. List<Struct.BattleReports> battleReports = JsonConvert.DeserializeObject<List<Struct.BattleReports>>(data);
  125. if (battleReports is not { Count: > 0 })
  126. {
  127. return;
  128. }
  129. Map map = self.GetParent<Map>();
  130. List<Struct.BattleReports> list = (from report in battleReports
  131. where report.Force == 1
  132. let ID = report.ID
  133. let PlayerUUID = string.IsNullOrEmpty(report.PlayerUUID)? "0" : report.PlayerUUID
  134. let TemplateID = report.TemplateId
  135. let Name = "玩家" + ID + "." + TemplateID
  136. let Force = report.Force
  137. let TotalDamage = report.TotalDamage
  138. select new Struct.BattleReports(ID, PlayerUUID, TemplateID, Name, Force, TotalDamage)).ToList();
  139. map.GetComponent<MapRankComponent>().UpdateRank(list, map);
  140. }
  141. }
  142. }