MapEventComponentSystem.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. using System;
  2. using System.Linq;
  3. using Newtonsoft.Json;
  4. using Newtonsoft.Json.Linq;
  5. namespace ET.Server
  6. {
  7. [FriendOf(typeof(MapEventComponent))]
  8. [FriendOfAttribute(typeof(ET.Server.Map))]
  9. public static class MapEventComponentSystem
  10. {
  11. public class MapEventComponentAwakeSystem : AwakeSystem<MapEventComponent, Map>
  12. {
  13. /// <summary>
  14. /// 场景事件组件创建
  15. /// </summary>
  16. /// <param name="self"></param>
  17. /// <param name="map"></param>
  18. protected override void Awake(MapEventComponent self, Map map)
  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. Log.Debug($"单位死亡...");
  50. int unitType = Convert.ToInt32(msg.SelectToken("unitType"));
  51. // 攻击者
  52. long hitFinalPlayerId = msg.SelectToken("hitFinal").ToString() == "" ? 0 : Convert.ToInt64(msg.SelectToken("hitFinal"));
  53. long belongPlayerId = msg.SelectToken("belongPlayerId").ToString() == "" ? 0 : Convert.ToInt64(msg.SelectToken("belongPlayerId"));
  54. long[] atkAssistantList = JsonConvert.DeserializeObject<long[]>(Convert.ToString(msg.SelectToken("atkAssistantList")) ?? string.Empty);
  55. WNPlayer hitFinalPlayer = null;
  56. // 默认使用第一个摸怪玩家
  57. if (belongPlayerId > 0)
  58. {
  59. hitFinalPlayer = map.GetPlayer(belongPlayerId);
  60. }
  61. if (hitFinalPlayer == null && hitFinalPlayerId > 0)
  62. {
  63. hitFinalPlayer = map.GetPlayer(hitFinalPlayerId);
  64. }
  65. switch (unitType)
  66. {
  67. case 0:
  68. // 怪物死亡
  69. int unitTemplateId = Convert.ToInt32(msg.SelectToken("unitTemplateId"));
  70. Monster monsterProp = MonsterCategory.Instance.Get(unitTemplateId);
  71. if (monsterProp == null)
  72. {
  73. Log.Error($"unitDead not fount montster : {unitTemplateId}, {map.MapId}, {msg}");
  74. return;
  75. }
  76. // todo 怪物死亡处理逻辑
  77. Log.Debug($"怪物死亡处理...");
  78. break;
  79. case 1:
  80. // 玩家死亡
  81. long unitPlayerId = Convert.ToInt64(msg.SelectToken("unitPlayerId"));
  82. if (hitFinalPlayerId <= 0)
  83. {
  84. // 被boss杀死
  85. int attackerTemplateId = Convert.ToInt32(msg.SelectToken("attackerTemplateId"));
  86. Log.Debug($"玩家死亡...被boss杀死...playerId={unitPlayerId}, bossId={attackerTemplateId}");
  87. }
  88. else
  89. {
  90. // 被玩家杀死
  91. Log.Debug($"玩家死亡...被玩家杀死...playerId={unitPlayerId}, 攻击者={hitFinalPlayerId}");
  92. }
  93. // 复活
  94. WNPlayer unitPlayer = map.GetPlayer(unitPlayerId);
  95. if (unitPlayer == null)
  96. {
  97. return;
  98. }
  99. unitPlayer.AddComponent<PlayerReliveTimeComponent, WNPlayer>(unitPlayer);
  100. break;
  101. case 2:
  102. // 宠物死亡
  103. break;
  104. }
  105. }
  106. /** 副本消息 **/
  107. public static void OnMessageEvent(this MapEventComponent self, JObject msg)
  108. {
  109. }
  110. /** 场景结算事件 **/
  111. public static void OnGameOver(this MapEventComponent self, Map map)
  112. {
  113. if (map?.Players is not { Count: > 0 })
  114. {
  115. return;
  116. }
  117. foreach (WNPlayer player in map.Players.Values.Where(player => player != null))
  118. {
  119. // 记录玩家历史
  120. map.SyncPlayerHistoryData(player);
  121. // 战斗服场景玩家离开
  122. map.PlayerLeaveRequest(player, false);
  123. // 本地场景移除玩家
  124. map.RemovePlayer(player, false);
  125. // 战斗服结束场景
  126. map.GetZoneManager().destroyZoneRequest(map.Id.ToString());
  127. player.Map = null;
  128. }
  129. }
  130. /** 拾取道具 **/
  131. public static void OnPickItem(this MapEventComponent self, JObject msg)
  132. {
  133. }
  134. /** 击杀boss **/
  135. public static void OnKillBoss(this MapEventComponent self, JObject msg)
  136. {
  137. }
  138. /** 战斗统计 **/
  139. public static void OnBattleReport(this MapEventComponent self, JObject msg)
  140. {
  141. }
  142. }
  143. }