瀏覽代碼

【优化】简化玩家对象和玩家组件创建时的过多参数,保持和et风格一致

johnclot69 1 年之前
父節點
當前提交
d8c7265ef7

+ 0 - 38
DotNet/Hotfix/Helper/PlayerFactory.cs

@@ -1,38 +0,0 @@
-namespace ET.Server
-{
-    public static class PlayerFactory
-    {
-        /// <summary>
-        /// 创建玩家实体
-        /// </summary>
-        /// <param name="session"></param>
-        /// <param name="playerInfo"></param>
-        /// <returns></returns>
-        public static async ETTask<WNPlayer> CreatPlayer(Session session, PlayerInfo playerInfo)
-        {
-            WNPlayer player = session.DomainScene().GetComponent<GamePlayerComponent>()
-                    .AddChild<WNPlayer, Session, PlayerInfo>(session, playerInfo);
-
-            // 绑定sessionId
-            player.GameSessionActorId = session.InstanceId;
-            player.Session = session;
-            player.BasicProp = CharacterConfigCategory.Instance.Get(playerInfo.Pro);
-            player.BornType = (int)BORN_TYPE.NORMAL;
-            player.EnterState = (int)ENTER_STATE.online;
-
-            // 玩家基础数据组件
-            player.AddComponent<PlayerDataComponent, PlayerInfo, WNPlayer>(playerInfo, player);
-            // 玩家临时数据组件
-            player.AddComponent<PlayerTempDataComponent, WNPlayer>(player).Init();
-            // 玩家技能组件
-            player.AddComponent<PlayerSkillComponent, WNPlayer>(player).Init();
-            // 玩家货币组件
-            player.AddComponent<PlayerMoneyComponent, WNPlayer>(player).Init();
-            // 玩家属性组件
-            player.AddComponent<PlayerBtlComponent, WNPlayer>(player).Init();
-
-            await ETTask.CompletedTask;
-            return player;
-        }
-    }
-}

+ 2 - 2
DotNet/Hotfix/Scenes/Game/Handler/C2G_BindPlayerHandler.cs

@@ -40,8 +40,7 @@ namespace ET.Server
             }
             else
             {
-                PlayerInfo playerInfo = session.GetComponent<SessionPlayerComponent>().PlayerInfo;
-                player = await PlayerFactory.CreatPlayer(session, playerInfo);
+                player = scene.GetComponent<GamePlayerComponent>().AddChild<WNPlayer, Session>(session);
             }
 
             // 绑定选择的玩家
@@ -61,6 +60,7 @@ namespace ET.Server
             response.Player.mapId = map.MapId;
 
             reply();
+            await ETTask.CompletedTask;
         }
     }
 }

+ 0 - 9
DotNet/Hotfix/Scenes/Game/Map/MapSystem.cs

@@ -12,11 +12,6 @@ namespace ET.Server
     {
         public class MapAwakeSystem: AwakeSystem<Map, JObject>
         {
-            /// <summary>
-            /// 本地地图场景实体创建
-            /// </summary>
-            /// <param name="self"></param>
-            /// <param name="opts"></param>
             protected override void Awake(Map self, JObject opts)
             {
                 self.createTime = TimeHelper.ServerNow();
@@ -41,10 +36,6 @@ namespace ET.Server
 
         public class MapDestroySystem: DestroySystem<Map>
         {
-            /// <summary>
-            /// 本地地图场景实体销毁
-            /// </summary>
-            /// <param name="self"></param>
             protected override void Destroy(Map self)
             {
             }

+ 5 - 5
DotNet/Hotfix/Scenes/Game/Player/PlayerBtlComponentSystem.cs

@@ -9,16 +9,16 @@ namespace ET.Server
     [FriendOf(typeof (PlayerBtlComponent))]
     public static class PlayerBtlComponentSystem
     {
-        public class PlayerBtlComponentAwakeSystem: AwakeSystem<PlayerBtlComponent, WNPlayer>
+        public class PlayerBtlComponentAwakeSystem: AwakeSystem<PlayerBtlComponent>
         {
-            protected override void Awake(PlayerBtlComponent self, WNPlayer player)
+            protected override void Awake(PlayerBtlComponent self)
             {
                 Log.Info($"创建玩家属性组件...");
-                self.Player = player;
-                self.CharacterProp = player.BasicProp;
+                self.Player = self.GetParent<WNPlayer>();
+                self.CharacterProp = self.Player.BasicProp;
                 if (self.CharacterProp == null)
                 {
-                    Log.Warning($"PlayerBtlComponentSystem 玩家职业信息为空: playerId={player.GetId()}, 职业={player.GetPro()}");
+                    Log.Warning($"PlayerBtlComponentSystem 玩家职业信息为空: playerId={self.Player.GetId()}, 职业={self.Player.GetPro()}");
                 }
 
             }

+ 3 - 13
DotNet/Hotfix/Scenes/Game/Player/PlayerDataComponentSystem.cs

@@ -3,28 +3,18 @@ namespace ET.Server
     [FriendOf(typeof (PlayerDataComponent))]
     public static class PlayerDataComponentSystem
     {
-        public class PlayerDataComponentaAwakeSystem: AwakeSystem<PlayerDataComponent, PlayerInfo, WNPlayer>
+        public class PlayerDataComponentaAwakeSystem: AwakeSystem<PlayerDataComponent, PlayerInfo>
         {
-            /// <summary>
-            /// 玩家基础数据组件创建
-            /// </summary>
-            /// <param name="self"></param>
-            /// <param name="info"></param>
-            /// <param name="player"></param>
-            protected override void Awake(PlayerDataComponent self, PlayerInfo info, WNPlayer player)
+            protected override void Awake(PlayerDataComponent self, PlayerInfo info)
             {
                 Log.Info($"创建玩家基础数据组件...");
-                self.Player = player;
                 self.Data = info;
+                self.Player = self.GetParent<WNPlayer>();
             }
         }
 
         public class PlayerDataComponentDestroySystem: DestroySystem<PlayerDataComponent>
         {
-            /// <summary>
-            /// 玩家基础数据组件销毁
-            /// </summary>
-            /// <param name="self"></param>
             protected override void Destroy(PlayerDataComponent self)
             {
                 // todo 暂时去掉数据落地逻辑

+ 3 - 12
DotNet/Hotfix/Scenes/Game/Player/PlayerMoneyComponentSystem.cs

@@ -3,26 +3,17 @@
     [FriendOf(typeof (PlayerMoneyComponent))]
     public static class PlayerMoneyComponentSystem
     {
-        public class PlayerMoneyComponentAwakeSystem: AwakeSystem<PlayerMoneyComponent, WNPlayer>
+        public class PlayerMoneyComponentAwakeSystem: AwakeSystem<PlayerMoneyComponent>
         {
-            /// <summary>
-            /// 玩家货币组件创建
-            /// </summary>
-            /// <param name="self"></param>
-            /// <param name="player"></param>
-            protected override void Awake(PlayerMoneyComponent self, WNPlayer player)
+            protected override void Awake(PlayerMoneyComponent self)
             {
                 Log.Info($"创建玩家货币组件...");
-                self.Player = player;
+                self.Player = self.GetParent<WNPlayer>();
             }
         }
 
         public class PlayerMoneyComponentDestroySystem: DestroySystem<PlayerMoneyComponent>
         {
-            /// <summary>
-            /// 玩家货币组件销毁
-            /// </summary>
-            /// <param name="self"></param>
             protected override void Destroy(PlayerMoneyComponent self)
             {
                 // Log.Debug($"玩家货币数据保存");

+ 3 - 12
DotNet/Hotfix/Scenes/Game/Player/PlayerSkillComponentSystem.cs

@@ -6,26 +6,17 @@ namespace ET.Server
     [FriendOf(typeof (PlayerSkillComponent))]
     public static class PlayerSkillComponentSystem
     {
-        public class PlayerSkillComponentAwakeSystem: AwakeSystem<PlayerSkillComponent, WNPlayer>
+        public class PlayerSkillComponentAwakeSystem: AwakeSystem<PlayerSkillComponent>
         {
-            /// <summary>
-            /// 玩家技能组件创建
-            /// </summary>
-            /// <param name="self"></param>
-            /// <param name="player"></param>
-            protected override void Awake(PlayerSkillComponent self, WNPlayer player)
+            protected override void Awake(PlayerSkillComponent self)
             {
                 Log.Info($"创建玩家技能组件...");
-                self.Player = player;
+                self.Player = self.GetParent<WNPlayer>();
             }
         }
 
         public class PlayerSkillComponentDestroySystem: DestroySystem<PlayerSkillComponent>
         {
-            /// <summary>
-            /// 玩家技能组件销毁
-            /// </summary>
-            /// <param name="self"></param>
             protected override void Destroy(PlayerSkillComponent self)
             {
                 // todo 暂时去掉数据落地逻辑

+ 21 - 12
DotNet/Hotfix/Scenes/Game/Player/PlayerSystem.cs

@@ -9,26 +9,35 @@ namespace ET.Server
     [FriendOf(typeof (BattleIceAgentComponent))]
     public static class PlayerSystem
     {
-        public class PlayerAwakeSystem: AwakeSystem<WNPlayer, Session, PlayerInfo>
+        public class PlayerAwakeSystem: AwakeSystem<WNPlayer, Session>
         {
-            /// <summary>
-            /// 玩家实体创建
-            /// </summary>
-            /// <param name="self"></param>
-            /// <param name="session"></param>
-            /// <param name="playerInfo"></param>
-            protected override void Awake(WNPlayer self, Session session, PlayerInfo playerInfo)
+            protected override void Awake(WNPlayer self, Session session)
             {
                 Log.Info($"创建玩家实体...");
+                PlayerInfo playerInfo = session.GetComponent<SessionPlayerComponent>().PlayerInfo;
+
+                // 绑定sessionId
+                self.GameSessionActorId = session.InstanceId;
+                self.Session = session;
+                self.BasicProp = CharacterConfigCategory.Instance.Get(playerInfo.Pro);
+                self.BornType = (int)BORN_TYPE.NORMAL;
+                self.EnterState = (int)ENTER_STATE.online;
+
+                // 玩家基础数据组件
+                self.AddComponent<PlayerDataComponent, PlayerInfo>(playerInfo);
+                // 玩家临时数据组件
+                self.AddComponent<PlayerTempDataComponent>().Init();
+                // 玩家技能组件
+                self.AddComponent<PlayerSkillComponent>().Init();
+                // 玩家货币组件
+                self.AddComponent<PlayerMoneyComponent>().Init();
+                // 玩家属性组件
+                self.AddComponent<PlayerBtlComponent>().Init();
             }
         }
 
         public class PlayerDestroySystem: DestroySystem<WNPlayer>
         {
-            /// <summary>
-            /// 玩家实体销毁
-            /// </summary>
-            /// <param name="self"></param>
             protected override void Destroy(WNPlayer self)
             {
                 Log.Info($"销毁玩家实体...");

+ 3 - 12
DotNet/Hotfix/Scenes/Game/Player/PlayerTempDataComponentSystem.cs

@@ -6,26 +6,17 @@ namespace ET.Server
     [FriendOf(typeof (PlayerTempDataComponent))]
     public static class PlayerTempDataComponentSystem
     {
-        public class PlayerTempDataComponentAwakeSystem: AwakeSystem<PlayerTempDataComponent, WNPlayer>
+        public class PlayerTempDataComponentAwakeSystem: AwakeSystem<PlayerTempDataComponent>
         {
-            /// <summary>
-            /// 玩家临时数据组件创建
-            /// </summary>
-            /// <param name="self"></param>
-            /// <param name="player"></param>
-            protected override void Awake(PlayerTempDataComponent self, WNPlayer player)
+            protected override void Awake(PlayerTempDataComponent self)
             {
                 Log.Info($"创建玩家临时数据组件...");
-                self.Player = player;
+                self.Player = self.GetParent<WNPlayer>();
             }
         }
 
         public class PlayerTempDataComponentDestroySystem: DestroySystem<PlayerTempDataComponent>
         {
-            /// <summary>
-            /// 玩家临时数据组件销毁
-            /// </summary>
-            /// <param name="self"></param>
             protected override void Destroy(PlayerTempDataComponent self)
             {
                 // todo 暂时去掉数据落地逻辑

+ 1 - 1
DotNet/Model/Scenes/Game/Player/PlayerBtlComponent.cs

@@ -3,7 +3,7 @@
 namespace ET.Server
 {
     [ComponentOf(typeof (WNPlayer))]
-    public class PlayerBtlComponent: Entity, IAwake<WNPlayer>, IDestroy
+    public class PlayerBtlComponent: Entity, IAwake, IDestroy
     {
         [StaticField]
         public int Tenthousand = 10000;

+ 1 - 1
DotNet/Model/Scenes/Game/Player/PlayerDataComponent.cs

@@ -1,7 +1,7 @@
 namespace ET.Server
 {
     [ComponentOf(typeof (WNPlayer))]
-    public class PlayerDataComponent: Entity, IAwake<PlayerInfo, WNPlayer>, IDestroy
+    public class PlayerDataComponent: Entity, IAwake<PlayerInfo>, IDestroy
     {
         /** 玩家基础数据 **/
         public PlayerInfo Data { get; set; }

+ 1 - 1
DotNet/Model/Scenes/Game/Player/PlayerMoneyComponent.cs

@@ -1,7 +1,7 @@
 namespace ET.Server
 {
     [ComponentOf(typeof (WNPlayer))]
-    public class PlayerMoneyComponent: Entity, IAwake<WNPlayer>, IDestroy
+    public class PlayerMoneyComponent: Entity, IAwake, IDestroy
     {
         /** 玩家对象 **/
         public WNPlayer Player { get; set; }

+ 1 - 1
DotNet/Model/Scenes/Game/Player/PlayerSkillComponent.cs

@@ -3,7 +3,7 @@
 namespace ET.Server
 {
     [ComponentOf(typeof (WNPlayer))]
-    public class PlayerSkillComponent: Entity, IAwake<WNPlayer>, IDestroy
+    public class PlayerSkillComponent: Entity, IAwake, IDestroy
     {
         /** 玩家技能数据 **/
         public PlayerSkillInfo Data { get; set; }

+ 1 - 1
DotNet/Model/Scenes/Game/Player/PlayerTempDataComponent.cs

@@ -3,7 +3,7 @@
 namespace ET.Server
 {
     [ComponentOf(typeof (WNPlayer))]
-    public class PlayerTempDataComponent: Entity, IAwake<WNPlayer>, IDestroy
+    public class PlayerTempDataComponent: Entity, IAwake, IDestroy
     {
         /** 玩家场景数据 **/
         public PlayerMapInfo MapData { get; set; }

+ 1 - 1
DotNet/Model/Scenes/Game/Player/WNPlayer.cs

@@ -6,7 +6,7 @@ namespace ET.Server
     /// 玩家实体
     /// </summary>
     [ChildOf(typeof (GamePlayerComponent))]
-    public class WNPlayer: Entity, IAwake<Session, PlayerInfo>, IDestroy
+    public class WNPlayer: Entity, IAwake<Session>, IDestroy
     {
         /** 游戏服session InstanceId **/
         public long GameSessionActorId { get; set; }