瀏覽代碼

【BUG】1.解决创建房间时的推送消息报错;2.解决创建房间后房间没数据但状态切换了;

johnclot69 11 月之前
父節點
當前提交
0a219fc24e

+ 1 - 1
DotNet/Hotfix/Helper/MessageHelper.cs

@@ -7,7 +7,7 @@ namespace ET.Server
     {
         public static void SendToClient(Player player, IActorMessage message)
         {
-            SendActor(player.Id, message);
+            SendActor(player.GameSessionActorId, message);
         }
         
         

+ 1 - 2
DotNet/Hotfix/Scenes/Game/Handler/C2G_LoginGameHandler.cs

@@ -30,8 +30,7 @@ namespace ET.Server
 			// 移除session自动超时组件
 			session.RemoveComponent<SessionAcceptTimeoutComponent>();
 
-			GamePlayerComponent gamePlayerComponent = scene.GetComponent<GamePlayerComponent>();
-			Player player = gamePlayerComponent.AddChild<Player, string>(account);
+			Player player = scene.GetComponent<GamePlayerComponent>().AddChild<Player, Session>(session);
 			
 			// 添加session组件,用于绑定角色
 			session.AddComponent<SessionPlayerComponent>().PlayerId = player.Id;

+ 6 - 3
DotNet/Hotfix/Scenes/Game/Player/PlayerSystem.cs

@@ -6,12 +6,15 @@ namespace ET.Server
     public static class PlayerSystem
     {
         [ObjectSystem]
-        public class PlayerAwakeSystem : AwakeSystem<Player, string>
+        public class PlayerAwakeSystem : AwakeSystem<Player, Session>
         {
-            protected override void Awake(Player self, string a)
+            protected override void Awake(Player self, Session session)
             {
                 Log.Info($"创建玩家实体...");
-                self.Account = a;
+                self.GameSessionActorId = session.InstanceId;
+                self.Session = session;
+                
+                // self.Account = a;
                 self.IsOnline = true;
                 self.LoginTime = TimeHelper.ServerNow();
                 self.RemainCards = new List<int>();

+ 48 - 48
DotNet/Hotfix/Scenes/Game/Room/HGHHMainCheckerComponentSystem.cs

@@ -4,67 +4,67 @@ using System.Linq;
 
 namespace ET.Server
 {
-    [Invoke(TimerInvokeType.HGHHMainChecker)]
-    public class HGHHMainChecker: ATimer<HGHHMainCheckerComponent>
+    [FriendOf(typeof (HGHHMainCheckerComponent))]
+    public static class HGHHMainCheckerComponentSystem
     {
-        protected override void Run(HGHHMainCheckerComponent self)
+        [ObjectSystem]
+        public class HGHHMainCheckerComponentAwakeSystem: AwakeSystem<HGHHMainCheckerComponent>
         {
-            Room room = self.GetParent<Room>();
-            if (room == null)
-            {
-                Log.Error($"黄冈晃晃主逻辑组件获取不到主实体...");
-                return;
-            }
-            Log.Debug($"检测: 黄冈晃晃-房间号:{room.RoomId}, 状态:{self.State}...");
-            
-            try
+            protected override void Awake(HGHHMainCheckerComponent self)
             {
-                self.Check(room);
+                Log.Info($"创建黄冈晃晃主逻辑组件...");
+                self.Flag = false;
+                self.Time = 0;
+                self.State = 0;
+                self.Players = new Player[4];
+                self.CurrentRound = 0;
+                self.CardList = new List<int>();
+                // 初始化牌库
+                for (int i = 0; i < 4; i++)
+                {
+                    foreach (int value in HghhConstValue.Values)
+                    {
+                        self.CardList.Add(value);
+                    }
+                    RandomGenerator.Shuffle(self.CardList);
+                }
             }
-            catch (Exception e)
+        }
+    
+        [ObjectSystem]
+        public class HGHHMainCheckerComponentDestroySystem: DestroySystem<HGHHMainCheckerComponent>
+        {
+            protected override void Destroy(HGHHMainCheckerComponent self)
             {
-                Log.Error($"move timer error: {self.Id}\n{e}");
+                Log.Info($"销毁黄冈晃晃主逻辑组件...");
             }
         }
-    }
-    
-    [ObjectSystem]
-    public class HGHHMainCheckerComponentAwakeSystem: AwakeSystem<HGHHMainCheckerComponent>
-    {
-        protected override void Awake(HGHHMainCheckerComponent self)
+
+        [ObjectSystem]
+        public class HGHHMainCheckerComponentUpdateSystem: UpdateSystem<HGHHMainCheckerComponent>
         {
-            Log.Info($"创建黄冈晃晃主逻辑组件...");
-            self.Flag = false;
-            self.Time = 0;
-            self.Players = new Player[4];
-            self.CurrentRound = 0;
-            self.CardList = new List<int>();
-            // 初始化牌库
-            for (int i = 0; i < 4; i++)
+            protected override void Update(HGHHMainCheckerComponent self)
             {
-                foreach (int value in HghhConstValue.Values)
+                Room room = self.GetParent<Room>();
+                if (room == null)
+                {
+                    Log.Error($"黄冈晃晃主逻辑组件获取不到主实体...");
+                    return;
+                }
+                Log.Debug($"检测: 黄冈晃晃-房间号:{room.RoomId}, 状态:{self.State}...");
+            
+                try
                 {
-                    self.CardList.Add(value);
+                    self.Check(room);
+                }
+                catch (Exception e)
+                {
+                    Log.Error($"move timer error: {self.Id}\n{e}");
                 }
-                RandomGenerator.Shuffle(self.CardList);
             }
-            self.RepeatedTimer = TimerComponent.Instance.NewRepeatedTimer(1000, TimerInvokeType.HGHHMainChecker, self);
-        }
-    }
-    
-    [ObjectSystem]
-    public class HGHHMainCheckerComponentDestroySystem: DestroySystem<HGHHMainCheckerComponent>
-    {
-        protected override void Destroy(HGHHMainCheckerComponent self)
-        {
-            Log.Info($"销毁黄冈晃晃主逻辑组件...");
-            TimerComponent.Instance?.Remove(ref self.RepeatedTimer);
         }
-    }
 
-    public static class HGHHMainCheckerComponentSystem
-    {
-        public static void Check(this HGHHMainCheckerComponent self, Room room)
+        private static void Check(this HGHHMainCheckerComponent self, Room room)
         {
             Log.Debug($"检测: 黄冈晃晃-房间号:{room.RoomId}...");
             switch (self.State)
@@ -129,7 +129,7 @@ namespace ET.Server
         }
 
         /// <summary>
-        /// 检测是否开始 3秒倒计时开始
+        /// 检测是否开始 3秒倒计时开始
         /// </summary>
         /// <param name="self"></param>
         /// <param name="room"></param>

+ 1 - 0
DotNet/Hotfix/Scenes/Game/Room/RoomSystem.cs

@@ -12,6 +12,7 @@ namespace ET.Server
             {
                 Log.Info($"创建房间实体...");
                 self.RoomId = RandomGenerator.RandRoomId();
+                self.MaxNum = 4;
                 self.Type = 1;
                 self.OwnerId = owner.Id;
                 self.CreateTime = TimeHelper.ServerNow();

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

@@ -3,8 +3,12 @@
 namespace ET.Server
 {
     [ChildOf(typeof(GamePlayerComponent))]
-    public sealed class Player : Entity, IAwake<string>, IDestroy
+    public sealed class Player : Entity, IAwake<Session>, IDestroy
     {
+        /** 游戏服session InstanceId **/
+        public long GameSessionActorId { get; set; }
+        /** 玩家session **/
+        public Session Session { get; set; }
         /** 账号 **/
         public string Account { get; set; }
         /** 服务器id **/

+ 1 - 3
DotNet/Model/Scenes/Game/Room/HGHHMainCheckerComponent.cs

@@ -3,7 +3,7 @@
 namespace ET.Server
 {
     [ComponentOf(typeof(Room))]
-    public class HGHHMainCheckerComponent: Entity, IAwake, IDestroy
+    public class HGHHMainCheckerComponent: Entity, IAwake, IDestroy, IUpdate
     {
         /** 检测标记 **/
         public bool Flag { get; set; }
@@ -32,7 +32,5 @@ namespace ET.Server
 
         /** 牌库 **/
         public List<int> CardList { get; set; }
-
-        public long RepeatedTimer;
     }
 }

+ 1 - 1
DotNet/Model/Scenes/Game/Room/Room.cs

@@ -5,7 +5,7 @@ namespace ET.Server
     /// <summary>
     /// 玩家房间实体
     /// </summary>
-    [ChildOf(typeof(GameRoomComponent))]
+    [ChildOf(typeof (GameRoomComponent))]
     public class Room : Entity, IAwake<Player>, IDestroy
     {
         /** 房间号 **/

+ 0 - 1
Unity/Assets/Scripts/Codes/Model/Share/TimerInvokeType.cs

@@ -8,7 +8,6 @@
         public const int SessionIdleChecker = 101;
         public const int ActorLocationSenderChecker = 102;
         public const int ActorMessageSenderChecker = 103;
-        public const int HGHHMainChecker = 104;
         
         // 框架层100-200,逻辑层的timer type 200-300
         public const int MoveTimer = 201;