Browse Source

调整服务器事件UnitDead

johnclot69 1 year ago
parent
commit
49ea2a0514

+ 1 - 63
DotNet/Hotfix/Helper/BattleServerEventHelper.cs

@@ -28,7 +28,7 @@ namespace ET.Server
             {
                 case "unitDead":
                 {
-                    OnUnitDead(map, msg);
+                    map.GetComponent<MapEventComponent>().OnUnitDead(map, msg);
                     return;
                 }
                 case "message":
@@ -123,67 +123,5 @@ namespace ET.Server
         {
             Log.Debug($"MapNotifyEvent msg: {JsonConvert.SerializeObject(msg, Formatting.Indented)}");
         }
-
-        /// <summary>
-        /// 单位死亡
-        /// </summary>
-        /// <param name="map"></param>
-        /// <param name="msg"></param>
-        private static void OnUnitDead(Map map, JObject msg)
-        {
-            int unitType = Convert.ToInt32(msg.SelectToken("unitType"));
-            // 攻击者
-            long hitFinalPlayerId = msg.SelectToken("hitFinal").ToString() == "" ? 0 : Convert.ToInt64(msg.SelectToken("hitFinal"));
-            long belongPlayerId = msg.SelectToken("belongPlayerId").ToString() == "" ? 0 : Convert.ToInt64(msg.SelectToken("belongPlayerId"));
-            long[] atkAssistantList = JsonConvert.DeserializeObject<long[]>(Convert.ToString(msg.SelectToken("atkAssistantList")) ?? string.Empty);
-            WNPlayer hitFinalPlayer = null;
-
-            // 默认使用第一个摸怪玩家
-            if (belongPlayerId > 0)
-            {
-                hitFinalPlayer = map.GetPlayer(belongPlayerId);
-            }
-
-            if (hitFinalPlayer == null && hitFinalPlayerId > 0)
-            {
-                hitFinalPlayer = map.GetPlayer(hitFinalPlayerId);
-            }
-
-            switch (unitType)
-            {
-                case 0:
-                    // 怪物死亡
-                    int unitTemplateId = Convert.ToInt32(msg.SelectToken("unitTemplateId"));
-                    Monster monsterProp = MonsterCategory.Instance.Get(unitTemplateId);
-                    if (monsterProp == null)
-                    {
-                        Log.Error($"unitDead not fount montster : {unitTemplateId}, {map.MapId}, {msg}");
-                    }
-                    else
-                    {
-                        map.GetComponent<MapEventComponent>().OnUnitDead(monsterProp, map);
-                    }
-                    break;
-                case 1:
-                    // 玩家死亡
-                    long unitPlayerId = Convert.ToInt64(msg.SelectToken("unitPlayerId"));
-
-                    if (hitFinalPlayerId <= 0)
-                    {
-                        // 被boss杀死
-                        int attackerTemplateId = Convert.ToInt32(msg.SelectToken("attackerTemplateId"));
-                        Log.Debug($"玩家死亡...被boss杀死...playerId={unitPlayerId}, bossId={attackerTemplateId}");
-                    }
-                    else
-                    {
-                        // 被玩家杀死
-                        Log.Debug($"玩家死亡...被玩家杀死...playerId={unitPlayerId}, 攻击者={hitFinalPlayerId}");
-                    }
-                    break;
-                case 2:
-                    // 宠物死亡
-                    break;
-            }
-        }
     }
 }

+ 56 - 2
DotNet/Hotfix/Scenes/Game/Map/MapEventComponentSystem.cs

@@ -1,4 +1,6 @@
-using System.Linq;
+using System;
+using System.Linq;
+using Newtonsoft.Json;
 using Newtonsoft.Json.Linq;
 
 namespace ET.Server
@@ -49,9 +51,61 @@ namespace ET.Server
         }
 
         /** 单位死亡事件 **/
-        public static void OnUnitDead(this MapEventComponent self, Monster monsterProp, Map map)
+        public static void OnUnitDead(this MapEventComponent self, Map map, JObject msg)
         {
             Log.Debug($"怪物死亡处理...");
+            int unitType = Convert.ToInt32(msg.SelectToken("unitType"));
+            // 攻击者
+            long hitFinalPlayerId = msg.SelectToken("hitFinal").ToString() == "" ? 0 : Convert.ToInt64(msg.SelectToken("hitFinal"));
+            long belongPlayerId = msg.SelectToken("belongPlayerId").ToString() == "" ? 0 : Convert.ToInt64(msg.SelectToken("belongPlayerId"));
+            long[] atkAssistantList = JsonConvert.DeserializeObject<long[]>(Convert.ToString(msg.SelectToken("atkAssistantList")) ?? string.Empty);
+            WNPlayer hitFinalPlayer = null;
+
+            // 默认使用第一个摸怪玩家
+            if (belongPlayerId > 0)
+            {
+                hitFinalPlayer = map.GetPlayer(belongPlayerId);
+            }
+
+            if (hitFinalPlayer == null && hitFinalPlayerId > 0)
+            {
+                hitFinalPlayer = map.GetPlayer(hitFinalPlayerId);
+            }
+
+            switch (unitType)
+            {
+                case 0:
+                    // 怪物死亡
+                    int unitTemplateId = Convert.ToInt32(msg.SelectToken("unitTemplateId"));
+                    Monster monsterProp = MonsterCategory.Instance.Get(unitTemplateId);
+                    if (monsterProp == null)
+                    {
+                        Log.Error($"unitDead not fount montster : {unitTemplateId}, {map.MapId}, {msg}");
+                        return;
+                    }
+                    // todo 怪物死亡处理逻辑,先暂时加入死亡列表
+                    self.MonsterDeadList.Add(unitTemplateId);
+                    break;
+                case 1:
+                    // 玩家死亡
+                    long unitPlayerId = Convert.ToInt64(msg.SelectToken("unitPlayerId"));
+
+                    if (hitFinalPlayerId <= 0)
+                    {
+                        // 被boss杀死
+                        int attackerTemplateId = Convert.ToInt32(msg.SelectToken("attackerTemplateId"));
+                        Log.Debug($"玩家死亡...被boss杀死...playerId={unitPlayerId}, bossId={attackerTemplateId}");
+                    }
+                    else
+                    {
+                        // 被玩家杀死
+                        Log.Debug($"玩家死亡...被玩家杀死...playerId={unitPlayerId}, 攻击者={hitFinalPlayerId}");
+                    }
+                    break;
+                case 2:
+                    // 宠物死亡
+                    break;
+            }
         }
 
         /** 副本消息 **/