Procházet zdrojové kódy

【调整】玩家死亡后的复活流程

johnclot69 před 1 rokem
rodič
revize
efc6d95137

binární
Config/Excel/Monster@s.xlsx


+ 5 - 1
DotNet/Hotfix/Scenes/Game/Handler/C2G_AddUnitsToMapHandler.cs

@@ -51,7 +51,11 @@ namespace ET.Server
             }
             unit.autoGuard = true;
 
-            await player.Map.AddUnits(unit, false);
+            int objId = await player.Map.AddUnits(unit, false);
+            if (objId > 0 && !player.Map.UnitObjIds.Contains(objId))
+            {
+                player.Map.UnitObjIds.Add(objId);
+            }
 
             reply();
         }

+ 25 - 8
DotNet/Hotfix/Scenes/Game/Map/MapEventComponentSystem.cs

@@ -52,8 +52,10 @@ namespace ET.Server
         /** 单位死亡事件 **/
         public static void OnUnitDead(this MapEventComponent self, Map map, JObject msg)
         {
-            Log.Debug($"单位死亡...");
             int unitType = Convert.ToInt32(msg.SelectToken("unitType"));
+            int objId = Convert.ToInt32(msg.SelectToken("objId"));
+            int posX = Convert.ToInt32(msg.SelectToken("posX"));
+            int posY = Convert.ToInt32(msg.SelectToken("posY"));
             // 攻击者
             long hitFinalPlayerId = msg.SelectToken("hitFinal").ToString() == ""? 0 : Convert.ToInt64(msg.SelectToken("hitFinal"));
             long belongPlayerId = msg.SelectToken("belongPlayerId").ToString() == ""? 0 : Convert.ToInt64(msg.SelectToken("belongPlayerId"));
@@ -74,7 +76,7 @@ namespace ET.Server
             switch (unitType)
             {
                 case 0:
-                    // 怪物死亡
+                    // 怪物死亡(玩家单位死亡, 延迟5秒复活)
                     int unitTemplateId = Convert.ToInt32(msg.SelectToken("unitTemplateId"));
                     Monster monsterProp = MonsterCategory.Instance.Get(unitTemplateId);
                     if (monsterProp == null)
@@ -83,11 +85,27 @@ namespace ET.Server
                         return;
                     }
 
-                    // todo 怪物死亡处理逻辑
-                    Log.Debug($"怪物死亡处理...");
+                    // 如果是塔
+                    if (monsterProp.Atype == 4)
+                    {
+                        if (!map.DeadUnits.Contains(unitTemplateId))
+                        {
+                            map.DeadUnits.Add(unitTemplateId);
+                        }
+                    }
+                    // 如果是单位玩家
+                    if (map.UnitObjIds.Contains(objId) && !map.IsGameOver())
+                    {
+                        Log.Debug($"单位死亡...objId={objId}, unitTemplateId={unitTemplateId}, posX={Convert.ToInt32(msg.SelectToken("posX"))}, posY={Convert.ToInt32(msg.SelectToken("posY"))}");
+
+                        map.UnitObjIds.Remove(objId);
+
+                        map.GetComponent<MapReliveTimeComponent>().ReliveDatas.Add(new Struct.UnitPlayerReliveData(map, unitTemplateId, TimeHelper.ServerNow() + 5000, posX, posY));
+                    }
+
                     break;
                 case 1:
-                    // 玩家死亡
+                    // 玩家死亡(主播死亡立即复活)
                     long unitPlayerId = Convert.ToInt64(msg.SelectToken("unitPlayerId"));
 
                     if (hitFinalPlayerId <= 0)
@@ -102,14 +120,13 @@ namespace ET.Server
                         Log.Debug($"玩家死亡...被玩家杀死...playerId={unitPlayerId}, 攻击者={hitFinalPlayerId}");
                     }
 
-                    // 复活
                     WNPlayer unitPlayer = map.GetPlayer(unitPlayerId);
                     if (unitPlayer == null)
                     {
                         return;
                     }
-
-                    unitPlayer.AddComponent<PlayerReliveTimeComponent, WNPlayer>(unitPlayer);
+                    // 原地复活
+                    unitPlayer.GetXmdsManager().revivePlayer(unitPlayer.GetId().ToString(), unitPlayer.Map.ReliveData(ReliveType.NOW));
 
                     break;
                 case 2:

+ 60 - 0
DotNet/Hotfix/Scenes/Game/Map/MapReliveTimeComponentSystem.cs

@@ -0,0 +1,60 @@
+using System;
+using System.Collections.Generic;
+
+namespace ET.Server
+{
+    [FriendOf(typeof (MapReliveTimeComponent))]
+    public static class MapReliveTimeComponentSystem
+    {
+        public class MapReliveTimeComponentAwakeSystem: AwakeSystem<MapReliveTimeComponent>
+        {
+            protected override void Awake(MapReliveTimeComponent self)
+            {
+                Log.Info($"创建单位玩家复活组件...");
+                self.ReliveDatas = new List<Struct.UnitPlayerReliveData>();
+            }
+        }
+
+        public class MapReliveTimeComponentUpdateSystem: UpdateSystem<MapReliveTimeComponent>
+        {
+            protected override void Update(MapReliveTimeComponent self)
+            {
+                if (self.ReliveDatas.Count <= 0)
+                {
+                    return;
+                }
+
+                for (int i = self.ReliveDatas.Count - 1; i >= 0; i--)
+                {
+                    Struct.UnitPlayerReliveData data = self.ReliveDatas[i];
+                    if (data == null)
+                    {
+                        continue;
+                    }
+
+                    if (TimeHelper.ServerNow() < data.ReliveTime)
+                    {
+                        continue;
+                    }
+
+                    // 复活(添加一个单位)
+                    Struct.MonsterUnit unit = new Struct.MonsterUnit();
+                    unit.id = data.ID;
+                    unit.force = 1;
+                    unit.x = data.x;
+                    unit.y = data.y;
+                    unit.autoGuard = true;
+
+                    int objId = data.Map.AddUnits(unit, false).GetResult();
+
+                    if (objId > 0 && !data.Map.UnitObjIds.Contains(objId))
+                    {
+                        data.Map.UnitObjIds.Add(objId);
+                    }
+
+                    self.ReliveDatas.Remove(data);
+                }
+            }
+        }
+    }
+}

+ 16 - 2
DotNet/Hotfix/Scenes/Game/Map/MapSystem.cs

@@ -26,8 +26,11 @@ namespace ET.Server
                 self.MapId = Convert.ToInt32(opts.SelectToken("areaId"));
                 self.Prop = MapConfigCategory.Instance.Get(self.MapId);
                 self.Type = self.Prop.Type;
+                self.UnitObjIds = new List<int>();
                 // 场景事件组件
                 self.AddComponent<MapEventComponent>();
+                // 场景复活组件
+                self.AddComponent<MapReliveTimeComponent>();
                 // 场景排行榜组件
                 self.AddComponent<MapRankComponent>();
             }
@@ -163,17 +166,18 @@ namespace ET.Server
             listData.Add(unit);
 
             int addUnitsResult = 0;
+            int objId = 0;
 
             if (needReturn) {
                 addUnitsResult = self.GetXmdsManager().addUnits(self.Id.ToString().Trim(), JsonConvert.SerializeObject(listData, Formatting.Indented));
                 Log.Info($"addUnits needReturn : mapId={self.MapId}, instanceId={self.Id.ToString().Trim()}, data={listData}, add units result={addUnitsResult}");
             } else
             {
-                int objId = await self.AddUnits(self.Id.ToString().Trim(), JsonConvert.SerializeObject(listData, Formatting.Indented));
+                objId = await self.AddUnits(self.Id.ToString().Trim(), JsonConvert.SerializeObject(listData, Formatting.Indented));
                 Log.Info($"addUnits: mapId={self.MapId}, instanceId={self.Id.ToString().Trim()}, objId={objId}");
             }
 
-            return addUnitsResult;
+            return objId;
         }
 
         /** 移除单位 **/
@@ -198,5 +202,15 @@ namespace ET.Server
             jsonObject.Add("mp", 0);
             return JsonConvert.SerializeObject(jsonObject, Formatting.Indented);
         }
+
+        /// <summary>
+        /// 是否结束
+        /// </summary>
+        /// <param name="self"></param>
+        /// <returns></returns>
+        public static bool IsGameOver(this Map self)
+        {
+            return self.DeadUnits.Contains(1001) && self.DeadUnits.Contains(1002) && self.DeadUnits.Contains(1003);
+        }
     }
 }

+ 0 - 38
DotNet/Hotfix/Scenes/Game/Player/PlayerReliveTimeComponentSystem.cs

@@ -1,38 +0,0 @@
-using System;
-
-namespace ET.Server
-{
-    [FriendOf(typeof (PlayerReliveTimeComponent))]
-    public static class PlayerReliveTimeComponentSystem
-    {
-        public class PlayerReliveTimeComponentAwakeSystem: AwakeSystem<PlayerReliveTimeComponent, WNPlayer>
-        {
-            protected override void Awake(PlayerReliveTimeComponent self, WNPlayer player)
-            {
-                Log.Info($"创建玩家复活倒计时组件...");
-                self.ReliveTime = TimeHelper.ServerNow() + 5000;
-                self.Player = player;
-            }
-        }
-
-        public class PlayerReliveTimeComponentUpdateSystem: UpdateSystem<PlayerReliveTimeComponent>
-        {
-            protected override void Update(PlayerReliveTimeComponent self)
-            {
-                if (!(TimeHelper.ServerNow() - self.ReliveTime > 5000) || self.ReliveTime == 0)
-                {
-                    return;
-                }
-
-                // 设置时间
-                self.ReliveTime = 0;
-
-                // 复活
-                self.Player.GetXmdsManager().revivePlayer(self.Player.GetId().ToString(), self.Player.Map.ReliveData(ReliveType.NOW));
-
-                // 复活后销毁组件
-                self.Dispose();
-            }
-        }
-    }
-}

+ 6 - 0
DotNet/Model/Scenes/Game/Map/Map.cs

@@ -24,5 +24,11 @@ namespace ET.Server
         /** 场景里的角色 **/
         [StaticField]
         public Dictionary<long, WNPlayer> Players = new Dictionary<long, WNPlayer>();
+        /** 场景中单位玩家objId列表 **/
+        public List<int> UnitObjIds { get; set; }
+
+        /** 死亡的单位 **/
+        [StaticField]
+        public List<int> DeadUnits = new List<int>();
     }
 }

+ 11 - 0
DotNet/Model/Scenes/Game/Map/MapReliveTimeComponent.cs

@@ -0,0 +1,11 @@
+using System.Collections.Generic;
+
+namespace ET.Server
+{
+    [ComponentOf(typeof (Map))]
+    public class MapReliveTimeComponent: Entity, IAwake, IUpdate
+    {
+        /** 单位玩家复活数据 **/
+        public List<Struct.UnitPlayerReliveData> ReliveDatas { get; set; }
+    }
+}

+ 0 - 11
DotNet/Model/Scenes/Game/Player/PlayerReliveTimeComponent.cs

@@ -1,11 +0,0 @@
-namespace ET.Server
-{
-    [ComponentOf(typeof (WNPlayer))]
-    public class PlayerReliveTimeComponent: Entity, IAwake<WNPlayer>, IUpdate
-    {
-        /** 复活时间 **/
-        public long ReliveTime { get; set; }
-        /** 玩家实体 **/
-        public WNPlayer Player { get; set; }
-    }
-}

+ 144 - 20
Unity/Assets/Scripts/Codes/Model/Share/Const/Struct.cs

@@ -27,14 +27,19 @@
         {
             /** 技能id **/
             public int id { get; set; }
+
             /** 技能等级 **/
             public int level { get; set; }
+
             /** 斩妖特殊含义: 冷却时间减少,触发几率增加,持续时间增加 **/
             public int[] talentLevel = new int[3];
+
             /** 技能类型 **/
             public int type { get; set; }
+
             /** 技能到期时间戳 **/
             public long skillTime { get; set; }
+
             /** 技能cd变更,万分比 **/
             public int cdTime { get; set; }
 
@@ -48,10 +53,13 @@
         {
             /** 技能id **/
             public int id { get; set; }
+
             /** 技能等级 **/
             public int level { get; set; }
+
             /** 是否已解锁 */
             public bool unlock { get; set; }
+
             /** 技能到期时间戳 **/
             public long skillTime { get; set; }
 
@@ -64,52 +72,127 @@
             }
 
             /** 是否已解锁 */
-            public bool isUnlock() {
+            public bool isUnlock()
+            {
                 return this.unlock;
             }
         }
 
+        /// <summary>
+        /// 场景数据
+        /// </summary>
+        public class AreaData
+        {
+            public MapConfig prop { get; set; }
+            public int areaId { get; set; }
+            public long instanceId { get; set; }
+            public float targetX { get; set; }
+            public float targetY { get; set; }
+            public int logicServerId { get; set; }
+            public ENTER_TYPE enterType = ENTER_TYPE.NONE;
+
+            public AreaData(int areaId)
+            {
+                this.prop = MapConfigCategory.Instance.Get(areaId);
+                this.areaId = areaId;
+            }
+
+            public AreaData(MapConfig prop)
+            {
+                this.areaId = prop.Id;
+                this.prop = prop;
+            }
+
+            public AreaData(int areaId, long instanceId)
+            {
+                this.prop = MapConfigCategory.Instance.Get(areaId);
+                this.areaId = areaId;
+                this.instanceId = instanceId;
+            }
+
+            public AreaData(int areaId, float targetX, float targetY)
+            {
+                this.prop = MapConfigCategory.Instance.Get(areaId);
+                this.areaId = areaId;
+                this.targetX = targetX;
+                this.targetY = targetY;
+            }
+
+            public AreaData(int areaId, float targetX, float targetY, ENTER_TYPE enterType)
+            {
+                this.prop = MapConfigCategory.Instance.Get(areaId);
+                this.areaId = areaId;
+                this.targetX = targetX;
+                this.targetY = targetY;
+                this.enterType = enterType;
+            }
+
+            public AreaData(int areaId, long instanceId, ENTER_TYPE enterType)
+            {
+                this.prop = MapConfigCategory.Instance.Get(areaId);
+                this.areaId = areaId;
+                this.instanceId = instanceId;
+                this.enterType = enterType;
+            }
+        }
+
         /// <summary>
         /// 怪物单位数据
         /// </summary>
         public class MonsterUnit
         {
             /** 怪物名字 **/
-            public string name{ get; set; }
+            public string name { get; set; }
+
             /** 怪物模板ID **/
-            public int id{ get; set; }
+            public int id { get; set; }
+
             /** 阵营信息 **/
-            public int force{ get; set; }
+            public int force { get; set; }
+
             /** 刷新点名字,为空才去读x, y **/
-            public string flag{ get; set; }
+            public string flag { get; set; }
+
+            public bool autoGuard { get; set; }
 
-            public bool autoGuard{ get; set; }
             /** 同一个Area是否只能同时有一个怪存在 **/
             public bool unique = false;
+
             /** 坐标x **/
-            public int x{ get; set; }
+            public int x { get; set; }
+
             /** 坐标y **/
-            public int y{ get; set; }
+            public int y { get; set; }
+
             /** 是否是任务 共享怪 **/
-            public int shareType{ get; set; }
+            public int shareType { get; set; }
+
             /** 动态怪物等级,战斗服根据此计算怪物的动态数值 **/
-            public int level{ get; set; }
+            public int level { get; set; }
+
             /** 初始朝向 **/
-            public float birthDirection{ get; set; }
+            public float birthDirection { get; set; }
+
             /** 服务器标记字段,怪物死亡时,会回传回来 **/
-            public int gsFlag{ get; set; }
+            public int gsFlag { get; set; }
+
             /** 指定血量 **/
-            public int hp{ get; set; }
-            public int maxHP{ get; set; }
+            public int hp { get; set; }
+
+            public int maxHP { get; set; }
+
             /** 指定追击玩家id(必须是无限追击怪才会联动生效) **/
-            public string attackPlayer{ get; set; }
+            public string attackPlayer { get; set; }
+
             /** 创建护卫怪,主人ObjectId(主人脱战或者死亡消失) **/
-            public int masterID{ get; set; }
+            public int masterID { get; set; }
 
-            public MonsterUnit() {
+            public MonsterUnit()
+            {
             }
 
-            public MonsterUnit(int monsterID, int force, bool unique, int x, int y) {
+            public MonsterUnit(int monsterID, int force, bool unique, int x, int y)
+            {
                 this.id = monsterID;
                 this.force = force;
                 this.unique = unique;
@@ -117,14 +200,16 @@
                 this.y = y;
             }
 
-            public MonsterUnit(int monsterID, string refrushEvent, bool unique, int force) {
+            public MonsterUnit(int monsterID, string refrushEvent, bool unique, int force)
+            {
                 this.id = monsterID;
                 this.force = force;
                 this.unique = unique;
                 this.flag = refrushEvent;
             }
 
-            public MonsterUnit(int monsterID, string refrushEvent, bool unique, int force, float birthDirection) {
+            public MonsterUnit(int monsterID, string refrushEvent, bool unique, int force, float birthDirection)
+            {
                 this.id = monsterID;
                 this.force = force;
                 this.unique = unique;
@@ -140,14 +225,19 @@
         {
             public uint ID { get; set; }
             public string PlayerUUID { get; set; }
+
             /** 模板id **/
             public int TemplateId { get; set; }
+
             /** 单位名称 **/
             public string Name { get; set; }
+
             /** 阵营 **/
             public int Force { get; set; }
+
             /** 对所有单位输出的总伤害 **/
             public int TotalDamage { get; set; }
+
             /** 对所有单位输出的总治疗量 **/
             public int TotalHealing { get; set; }
 
@@ -161,5 +251,39 @@
                 this.TotalDamage = totalDamage;
             }
         }
+
+        /// <summary>
+        /// 玩家单位复活数据
+        /// </summary>
+        public class UnitPlayerReliveData
+        {
+            /** 复活场景 **/
+            public Map Map { get; set; }
+
+            /** 复活单位模板id **/
+            public int ID { get; set; }
+
+            /** 复活时间 **/
+            public long ReliveTime { get; set; }
+
+            /** 复活位置x **/
+            public int x { get; set; }
+
+            /** 复活位置y **/
+            public int y { get; set; }
+
+            public UnitPlayerReliveData()
+            {
+            }
+
+            public UnitPlayerReliveData(Map map, int id, long time, int x, int y)
+            {
+                this.Map = map;
+                this.ID = id;
+                this.ReliveTime = time;
+                this.x = x;
+                this.y = y;
+            }
+        }
     }
 }