MapEventComponentSystem.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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 json)
  41. {
  42. string msg = Convert.ToString(json.SelectToken("msg"));
  43. string[] parames = msg.Split(":");
  44. switch (parames[0])
  45. {
  46. case "Dead":
  47. {
  48. if ("Tower1".Equals(parames[1]))
  49. {
  50. Map map = self.GetParent<Map>();
  51. map.CurBattleIndex = 1;
  52. self.TransferUnitsToNewTower();
  53. return;
  54. }
  55. else if ("Tower2".Equals(parames[1]))
  56. {
  57. Log.Debug($"塔2死亡事件...");
  58. Map map = self.GetParent<Map>();
  59. map.CurBattleIndex = 2;
  60. self.TransferUnitsToNewTower();
  61. return;
  62. }
  63. else if ("Tower3".Equals(parames[1]))
  64. {
  65. Log.Debug($"塔3死亡事件...");
  66. Map map = self.GetParent<Map>();
  67. map.CurBattleIndex = 3;
  68. self.TransferUnitsToNewTower();
  69. return;
  70. }
  71. else
  72. {
  73. int objId = int.Parse(parames[1]);
  74. if (objId > 0)
  75. {
  76. Log.Debug($"单位:{objId}死亡事件...");
  77. Map map = self.GetParent<Map>();
  78. Struct.UnitPlayerData unitPlayerData = map.GetUnitPlayerByObjId(objId);
  79. if (unitPlayerData != null)
  80. {
  81. unitPlayerData.DeadState = 1;
  82. }
  83. return;
  84. }
  85. }
  86. return;
  87. }
  88. case "Revive":
  89. {
  90. int objId = int.Parse(parames[1]);
  91. if (objId > 0)
  92. {
  93. Log.Debug($"单位:{objId}复活事件...");
  94. Map map = self.GetParent<Map>();
  95. Struct.UnitPlayerData unitPlayerData = map.GetUnitPlayerByObjId(objId);
  96. if (unitPlayerData != null)
  97. {
  98. unitPlayerData.DeadState = 0;
  99. }
  100. return;
  101. }
  102. return;
  103. }
  104. }
  105. }
  106. private static void TransferUnitsToNewTower(this MapEventComponent self)
  107. {
  108. Map map = self.GetParent<Map>();
  109. foreach(Struct.UnitPlayerData player in map.UnitPlayers.Values)
  110. {
  111. var pos = map.GetRandomPlayerPos();
  112. map.GetXmdsManager().transferUnit(map.Id.ToString(), player.ObjId, pos.X, pos.Y);
  113. }
  114. Log.Debug($"transfer unit: {map.UnitPlayers.Count}");
  115. }
  116. /// <summary>
  117. /// 场景结算事件
  118. /// </summary>
  119. /// <param name="self"></param>
  120. public static void OnGameOver(this MapEventComponent self)
  121. {
  122. Map map = self.GetParent<Map>();
  123. map.IsGameOver = true;
  124. if (map.Player == null)
  125. {
  126. return;
  127. }
  128. // 场景结束逻辑
  129. map.GetComponent<MapRankComponent>().OnGameOver();
  130. // 记录玩家历史
  131. map.SyncPlayerHistoryData(map.Player);
  132. // 战斗服场景玩家离开
  133. map.PlayerLeaveRequest(map.Player, false);
  134. // 本地场景移除玩家
  135. map.RemovePlayer(map.Player, false);
  136. // 战斗服结束场景
  137. map.GetZoneManager().destroyZoneRequest(map.Id.ToString());
  138. map.Player.Map = null;
  139. }
  140. /// <summary>
  141. /// 拾取道具
  142. /// </summary>
  143. /// <param name="self"></param>
  144. /// <param name="msg"></param>
  145. public static void OnPickItem(this MapEventComponent self, JObject msg)
  146. {
  147. }
  148. /// <summary>
  149. /// 击杀boss
  150. /// </summary>
  151. /// <param name="self"></param>
  152. /// <param name="msg"></param>
  153. public static void OnKillBoss(this MapEventComponent self, JObject msg)
  154. {
  155. }
  156. /// <summary>
  157. /// 战报统计
  158. /// </summary>
  159. /// <param name="self"></param>
  160. /// <param name="msg"></param>
  161. public static void OnBattleReport(this MapEventComponent self, JObject msg)
  162. {
  163. }
  164. }
  165. }