MapEventComponentSystem.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. self.MonsterDeadList.Add(unitTemplateId);
  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. break;
  94. case 2:
  95. // 宠物死亡
  96. break;
  97. }
  98. }
  99. /** 副本消息 **/
  100. public static void OnMessageEvent(this MapEventComponent self, JObject msg)
  101. {
  102. }
  103. /** 场景结算事件 **/
  104. public static void OnGameOver(this MapEventComponent self, Map map)
  105. {
  106. if (map?.Players is not { Count: > 0 })
  107. {
  108. return;
  109. }
  110. foreach (WNPlayer player in map.Players.Values.Where(player => player != null))
  111. {
  112. // 记录玩家历史
  113. map.SyncPlayerHistoryData(player);
  114. // 战斗服场景玩家离开
  115. map.PlayerLeaveRequest(player, false);
  116. // 本地场景移除玩家
  117. map.RemovePlayer(player, false);
  118. // 移除本地组件数据
  119. map.DomainScene().GetComponent<GamePlayerComponent>().Remove(player.GetId());
  120. // 战斗服结束场景
  121. map.GetZoneManager().destroyZoneRequest(map.Id.ToString());
  122. // 销毁
  123. player.Dispose();
  124. }
  125. }
  126. /** 拾取道具 **/
  127. public static void OnPickItem(this MapEventComponent self, JObject msg)
  128. {
  129. }
  130. /** 击杀boss **/
  131. public static void OnKillBoss(this MapEventComponent self, JObject msg)
  132. {
  133. }
  134. /** 战斗统计 **/
  135. public static void OnBattleReport(this MapEventComponent self, JObject msg)
  136. {
  137. }
  138. }
  139. }