MapEventComponentSystem.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5. using Newtonsoft.Json;
  6. using Newtonsoft.Json.Linq;
  7. namespace ET.Server
  8. {
  9. [FriendOf(typeof (MapEventComponent))]
  10. [FriendOf(typeof (Map))]
  11. public static class MapEventComponentSystem
  12. {
  13. public class MapEventComponentAwakeSystem: AwakeSystem<MapEventComponent>
  14. {
  15. /// <summary>
  16. /// 场景事件组件创建
  17. /// </summary>
  18. /// <param name="self"></param>
  19. protected override void Awake(MapEventComponent self)
  20. {
  21. Log.Info($"创建战斗服事件组件...");
  22. }
  23. }
  24. public class MapEventComponentDestroySystem: DestroySystem<MapEventComponent>
  25. {
  26. /// <summary>
  27. /// 场景事件组件销毁
  28. /// </summary>
  29. /// <param name="self"></param>
  30. protected override void Destroy(MapEventComponent self)
  31. {
  32. Log.Info($"销毁战斗服事件组件...");
  33. }
  34. }
  35. /// <summary>
  36. /// 副本消息
  37. /// </summary>
  38. /// <param name="self"></param>
  39. /// <param name="msg"></param>
  40. public static void OnMessage(this MapEventComponent self, JObject msg)
  41. {
  42. string str = Convert.ToString(msg.SelectToken("msg"));
  43. string[] parames = str.Split(":");
  44. switch (parames[0])
  45. {
  46. case "Dead":
  47. {
  48. if ("Tower1".Equals(parames[1]))
  49. {
  50. Log.Debug($"塔1死亡事件...");
  51. Map map = self.GetParent<Map>();
  52. map.CurBattleIndex = 1;
  53. map.TransferUnitsToNewTower();
  54. return;
  55. }
  56. else if ("Tower2".Equals(parames[1]))
  57. {
  58. Log.Debug($"塔2死亡事件...");
  59. Map map = self.GetParent<Map>();
  60. map.CurBattleIndex = 2;
  61. map.TransferUnitsToNewTower();
  62. return;
  63. }
  64. else if ("Tower3".Equals(parames[1]))
  65. {
  66. Log.Debug($"塔3死亡事件...");
  67. return;
  68. }
  69. else
  70. {
  71. int objId = int.Parse(parames[1]);
  72. if (objId > 0)
  73. {
  74. Log.Debug($"单位:{objId}死亡事件...");
  75. Map map = self.GetParent<Map>();
  76. Struct.UnitPlayerData unitPlayerData = map.GetUnitPlayerByObjId(objId);
  77. if (unitPlayerData != null)
  78. {
  79. unitPlayerData.DeadState = 1;
  80. map.DeadUnitPlayer.Add(unitPlayerData.ObjId);
  81. }
  82. }
  83. }
  84. break;
  85. }
  86. case "Revive":
  87. {
  88. int objId = int.Parse(parames[1]);
  89. if (objId > 0)
  90. {
  91. Log.Debug($"单位:{objId}复活事件...");
  92. Map map = self.GetParent<Map>();
  93. Struct.UnitPlayerData unitPlayerData = map.GetUnitPlayerByObjId(objId);
  94. if (unitPlayerData != null)
  95. {
  96. unitPlayerData.DeadState = 0;
  97. map.DeadUnitPlayer.Remove(unitPlayerData.ObjId);
  98. }
  99. }
  100. break;
  101. }
  102. }
  103. }
  104. /// <summary>
  105. /// 场景结算事件
  106. /// </summary>
  107. /// <param name="self"></param>
  108. public static void OnGameOver(this MapEventComponent self)
  109. {
  110. Map map = self.GetParent<Map>();
  111. map.IsGameOver = true;
  112. if (map.Player == null)
  113. {
  114. return;
  115. }
  116. // 场景结束排行榜逻辑
  117. map.GetComponent<MapRankComponent>().OnGameOver();
  118. // 玩家离开
  119. map.Player.GetComponent<PlayerTempDataComponent>().MapData.ready = false;
  120. // 记录玩家历史
  121. map.SyncPlayerHistoryData(map.Player);
  122. // 战斗服场景玩家离开
  123. map.PlayerLeaveRequest(map.Player, false);
  124. // 本地场景移除玩家
  125. map.RemovePlayer(map.Player, false);
  126. // 战斗服结束场景
  127. map.GetZoneManager().destroyZoneRequest(map.Id.ToString());
  128. // 移除本地场景数据
  129. map.DomainScene().GetComponent<GameMapComponent>().Remove(map.Id, map.RoomId);
  130. map.Player.Map = null;
  131. map.Dispose();
  132. }
  133. /// <summary>
  134. /// 拾取道具
  135. /// </summary>
  136. /// <param name="self"></param>
  137. /// <param name="msg"></param>
  138. public static void OnPickItem(this MapEventComponent self, JObject msg)
  139. {
  140. }
  141. /// <summary>
  142. /// 击杀boss
  143. /// </summary>
  144. /// <param name="self"></param>
  145. /// <param name="msg"></param>
  146. public static void OnKillBoss(this MapEventComponent self, JObject msg)
  147. {
  148. }
  149. /// <summary>
  150. /// 战报统计
  151. /// </summary>
  152. /// <param name="self"></param>
  153. /// <param name="msg"></param>
  154. public static void OnBattleReport(this MapEventComponent self, JObject msg)
  155. {
  156. }
  157. }
  158. }