MapEventComponentSystem.cs 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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. [FriendOfAttribute(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. /** 玩家进场景后推的消息 **/
  35. public static void OnReady(this MapEventComponent self, WNPlayer player)
  36. {
  37. }
  38. /** 玩家登录事件 **/
  39. public static void OnPlayerLogin(this MapEventComponent self, WNPlayer player)
  40. {
  41. }
  42. /** 角色成功进入场景 **/
  43. public static void OnPlayerEntered(this MapEventComponent self, WNPlayer player)
  44. {
  45. }
  46. /** 单位死亡事件 **/
  47. public static void OnUnitDead(this MapEventComponent self, Map map, JObject msg)
  48. {
  49. int unitType = Convert.ToInt32(msg.SelectToken("unitType"));
  50. /*int objId = Convert.ToInt32(msg.SelectToken("objId"));
  51. int posX = Convert.ToInt32(msg.SelectToken("posX"));
  52. int posY = Convert.ToInt32(msg.SelectToken("posY"));
  53. // 攻击者
  54. long hitFinalPlayerId = msg.SelectToken("hitFinal").ToString() == ""? 0 : Convert.ToInt64(msg.SelectToken("hitFinal"));
  55. long belongPlayerId = msg.SelectToken("belongPlayerId").ToString() == ""? 0 : Convert.ToInt64(msg.SelectToken("belongPlayerId"));
  56. long[] atkAssistantList = JsonConvert.DeserializeObject<long[]>(Convert.ToString(msg.SelectToken("atkAssistantList")) ?? string.Empty);
  57. WNPlayer hitFinalPlayer = null;
  58. // 默认使用第一个摸怪玩家
  59. if (belongPlayerId > 0)
  60. {
  61. hitFinalPlayer = map.GetPlayer(belongPlayerId);
  62. }
  63. if (hitFinalPlayer == null && hitFinalPlayerId > 0)
  64. {
  65. hitFinalPlayer = map.GetPlayer(hitFinalPlayerId);
  66. }*/
  67. switch (unitType)
  68. {
  69. case 0:
  70. // 怪物死亡(玩家单位死亡, 延迟5秒复活)
  71. int unitTemplateId = Convert.ToInt32(msg.SelectToken("unitTemplateId"));
  72. Monster monsterProp = MonsterCategory.Instance.Get(unitTemplateId);
  73. if (monsterProp == null)
  74. {
  75. Log.Error($"单位死亡...找不到怪物配置 : unitTemplateId={unitTemplateId}, MapId={map.MapId}, data={msg}");
  76. return;
  77. }
  78. // 如果是塔
  79. if (monsterProp.Atype == 4)
  80. {
  81. if (!map.DeadUnits.Contains(unitTemplateId))
  82. {
  83. map.DeadUnits.Add(unitTemplateId);
  84. }
  85. }
  86. // 如果是单位玩家
  87. /*if (map.UnitObjIds.ContainsValue(objId) && !map.IsGameOver())
  88. {
  89. Log.Debug($"单位死亡...objId={objId}, unitTemplateId={unitTemplateId}, posX={posX}, posY={posY}");
  90. string unitOpenId = null;
  91. foreach (string key in from key in map.UnitObjIds.Keys where !string.IsNullOrEmpty(key) let value = map.UnitObjIds[key] where value >= 0 && value == objId select key)
  92. {
  93. unitOpenId = key;
  94. break;
  95. }
  96. if (unitOpenId != null)
  97. {
  98. unitTemplateId = map.GetUnitTemplateId(unitOpenId);
  99. if (unitTemplateId == 0)
  100. {
  101. int[] units = new int[] { 101, 111, 121 };
  102. unitTemplateId = RandomGenerator.RandomArray(units);
  103. }
  104. map.GetComponent<MapReliveTimeComponent>().ReliveDatas.Add(new Struct.UnitPlayerReliveData(map, unitOpenId, unitTemplateId, TimeHelper.ServerNow() + 5000, posX, posY));
  105. map.UnitObjIds.Remove(unitOpenId);
  106. }
  107. }*/
  108. break;
  109. /*case 1:
  110. // 玩家死亡(主播死亡立即复活)
  111. long unitPlayerId = Convert.ToInt64(msg.SelectToken("unitPlayerId"));
  112. if (hitFinalPlayerId <= 0)
  113. {
  114. // 被boss杀死
  115. int attackerTemplateId = Convert.ToInt32(msg.SelectToken("attackerTemplateId"));
  116. Log.Debug($"玩家死亡...被boss杀死...playerId={unitPlayerId}, bossId={attackerTemplateId}");
  117. }
  118. else
  119. {
  120. // 被玩家杀死
  121. Log.Debug($"玩家死亡...被玩家杀死...playerId={unitPlayerId}, 攻击者={hitFinalPlayerId}");
  122. }
  123. WNPlayer unitPlayer = map.GetPlayer(unitPlayerId);
  124. if (unitPlayer == null)
  125. {
  126. return;
  127. }
  128. // 原地复活
  129. unitPlayer.GetXmdsManager().revivePlayer(unitPlayer.GetId().ToString(), unitPlayer.Map.ReliveData(ReliveType.NOW));
  130. break;
  131. case 2:
  132. // 宠物死亡
  133. break;*/
  134. }
  135. }
  136. /** 副本消息 **/
  137. public static void OnMessageEvent(this MapEventComponent self, JObject msg)
  138. {
  139. }
  140. /** 场景结算事件 **/
  141. public static void OnGameOver(this MapEventComponent self, Map map)
  142. {
  143. map.IsGameOver = true;
  144. if (map?.Players is not { Count: > 0 })
  145. {
  146. return;
  147. }
  148. foreach (WNPlayer player in map.Players.Values.Where(player => player != null))
  149. {
  150. // 记录玩家历史
  151. map.SyncPlayerHistoryData(player);
  152. // 战斗服场景玩家离开
  153. map.PlayerLeaveRequest(player, false);
  154. // 本地场景移除玩家
  155. map.RemovePlayer(player, false);
  156. // 战斗服结束场景
  157. map.GetZoneManager().destroyZoneRequest(map.Id.ToString());
  158. player.Map = null;
  159. }
  160. }
  161. /** 拾取道具 **/
  162. public static void OnPickItem(this MapEventComponent self, JObject msg)
  163. {
  164. }
  165. /** 击杀boss **/
  166. public static void OnKillBoss(this MapEventComponent self, JObject msg)
  167. {
  168. }
  169. /** 战斗统计 **/
  170. public static void OnBattleReport(this MapEventComponent self, Map map, JObject msg)
  171. {
  172. string data = Convert.ToString(msg.SelectToken("data"));
  173. if (string.IsNullOrEmpty(data))
  174. {
  175. return;
  176. }
  177. List<Struct.BattleReports> list = new List<Struct.BattleReports>();
  178. List<Struct.BattleReports> battleReports = JsonConvert.DeserializeObject<List<Struct.BattleReports>>(data);
  179. if (battleReports is not { Count: > 0 })
  180. {
  181. return;
  182. }
  183. foreach (Struct.BattleReports report in battleReports)
  184. {
  185. // 过滤一下非我方单位
  186. if (report.Force != 1)
  187. {
  188. continue;
  189. }
  190. uint ID = report.ID;
  191. long PlayerUUID = string.IsNullOrEmpty(report.PlayerUUID)? 0 : Convert.ToInt64(report.PlayerUUID);
  192. int TemplateID = report.TemplateId;
  193. int Force = report.Force;
  194. int TotalDamage = report.TotalDamage;
  195. string name = "";
  196. if (PlayerUUID > 0)
  197. {
  198. name = "玩家-" + TemplateID;
  199. }
  200. else
  201. {
  202. if (TemplateID > 0)
  203. {
  204. Monster prop = MonsterCategory.Instance.Get(TemplateID);
  205. if (prop != null)
  206. {
  207. name = prop.Name;
  208. }
  209. }
  210. }
  211. list.Add(new Struct.BattleReports(ID, report.PlayerUUID, TemplateID, name, Force, TotalDamage));
  212. }
  213. map.GetComponent<MapRankComponent>().UpdateRank(list, map);
  214. }
  215. }
  216. }