MapEventComponentSystem.cs 5.8 KB

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