Browse Source

【增加】创建房间的初步逻辑

johnclot69 1 year ago
parent
commit
eecd005ce2

+ 1 - 1
Config/Proto/CommonProto_CS_10001.proto

@@ -19,7 +19,7 @@ message UnitInfo
 	MoveInfo MoveInfo = 7;
 }
 
-message Player
+message PlayerInfo
 {
   int64 id = 1;
   string name = 2;

+ 16 - 1
Config/Proto/OuterMessage_C_30001.proto

@@ -151,10 +151,25 @@ message G2C_LoginGame // IResponse
 	int32 RpcId = 1;
 	int32 Error = 2;
 	string Message = 3;
-	Player Player = 4;
+	PlayerInfo Player = 4;
 	bool IsInRoom = 5;	// 是否在房间中
 }
 
+//ResponseType G2C_CreatRoom
+message C2G_CreatRoom // IRequest
+{
+	int32 RpcId = 1;
+}
+
+message G2C_CreatRoom // IResponse
+{
+	int32 RpcId = 1;
+	int32 Error = 2;
+	string Message = 3;
+	int64 OwnerId = 4;		// 房主id
+	repeated PlayerInfo PlayerList = 5;		// 房间玩家列表
+}
+
 message G2C_TestHotfixMessage // IMessage
 {
 	string Info = 1;

+ 2 - 2
DotNet/Hotfix/Helper/PlayerHelper.cs

@@ -10,9 +10,9 @@
         /// </summary>
         /// <param name="player"></param>
         /// <returns></returns>
-        public static ET.Player PlayerInfoToProto(Player player)
+        public static PlayerInfo PlayerToProto(Player player)
         {
-            return new ET.Player()
+            return new PlayerInfo()
             {
                 id = player.Id,
                 name = player.Name,

+ 57 - 0
DotNet/Hotfix/Scenes/Game/Handler/C2G_CreatRoomHandler.cs

@@ -0,0 +1,57 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+
+namespace ET.Server
+{
+    /// <summary>
+    /// 创建房间
+    /// </summary>
+    [MessageHandler(SceneType.Game)]
+    public class C2G_CreatRoomHandler : AMRpcHandler<C2G_CreatRoom, G2C_CreatRoom>
+    {
+        protected override async ETTask Run(Session session, C2G_CreatRoom request, G2C_CreatRoom response, Action reply)
+        {
+            Player player = session.GetComponent<SessionPlayerComponent>().GetMyPlayer();
+            if (player == null)
+            {
+                response.Error = ErrorCode.ERR_OperationError;
+                response.Message = "玩家不存在或离线...";
+                reply();
+                return;
+            }
+            
+            // 玩家是否在房间
+            if (player.RoomID > 0)
+            { 
+                response.Error = ErrorCode.ERR_OperationError;
+                response.Message = "玩家已在房间,不可创建房间...";
+                reply();
+                return;
+            }
+            
+            Scene scene = session.DomainScene();
+            
+            // 创建房间
+            Room room = scene.GetComponent<GameRoomComponent>().AddChild<Room, Player>(player);
+
+            if (room == null)
+            {
+                response.Error = ErrorCode.ERR_SystemError;
+                response.Message = "创建房间失败...";
+                reply();
+                return;
+            }
+            
+            // 返回房间数据
+            response.OwnerId = room.OwnerId;
+            response.PlayerList = new List<PlayerInfo>();
+            foreach (Player p in room.Players.Where(p => p != null))
+            {
+                response.PlayerList.Add(PlayerHelper.PlayerToProto(p));
+            }
+        
+            await ETTask.CompletedTask;
+        }
+    }
+}

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

@@ -37,8 +37,8 @@ namespace ET.Server
 			session.AddComponent<SessionPlayerComponent>().PlayerId = player.Id;
 			session.AddComponent<MailBoxComponent, MailboxType>(MailboxType.GameSession);
 
-			response.Player = PlayerHelper.PlayerInfoToProto(player);
-			response.IsInRoom = player.IsInRoom;
+			response.Player = PlayerHelper.PlayerToProto(player);
+			response.IsInRoom = player.RoomID > 0;
 			reply();
 			await ETTask.CompletedTask;
 		}

+ 1 - 2
DotNet/Hotfix/Scenes/Game/Player/PlayerSystem.cs

@@ -12,8 +12,7 @@
                 self.Account = a;
                 self.IsOnline = true;
                 self.LoginTime = TimeHelper.ServerNow();
-                // 测试数据,后面需要改成正式版
-                self.IsInRoom = false;
+                self.RoomID = 0;
                 // 添加本地玩家数据
                 self.DomainScene().GetComponent<GamePlayerComponent>().Add(self);
             }

+ 5 - 4
DotNet/Hotfix/Scenes/Game/Room/RoomSystem.cs

@@ -6,16 +6,17 @@ namespace ET.Server;
 public static class RoomSystem
 {
     [ObjectSystem]
-    public class RoomAwakeSystem : AwakeSystem<Room>
+    public class RoomAwakeSystem : AwakeSystem<Room, Player>
     {
-        protected override void Awake(Room self)
+        protected override void Awake(Room self, Player owner)
         {
             Log.Info($"创建房间实体...");
             self.Type = 2;
+            self.OwnerId = owner.Id;
             self.Players = new List<Player>();
             self.CreateTime = TimeHelper.ServerNow();
-            // 添加本地房间数据
-            self.DomainScene().GetComponent<GameRoomComponent>().Add(self);
+            // 添加房间玩家集合
+            self.Players.Add(owner);
         }
         
         [ObjectSystem]

+ 3 - 3
DotNet/Model/Generate/Message/CommonProto_CS_10001.cs

@@ -45,9 +45,9 @@ namespace ET
 
 	}
 
-	[Message(CommonProto.Player)]
+	[Message(CommonProto.PlayerInfo)]
 	[ProtoContract]
-	public partial class Player: ProtoObject
+	public partial class PlayerInfo: ProtoObject
 	{
 		[ProtoMember(1)]
 		public long id { get; set; }
@@ -73,6 +73,6 @@ namespace ET
 	{
 		 public const ushort MoveInfo = 10002;
 		 public const ushort UnitInfo = 10003;
-		 public const ushort Player = 10004;
+		 public const ushort PlayerInfo = 10004;
 	}
 }

+ 39 - 6
DotNet/Model/Generate/Message/OuterMessage_C_30001.cs

@@ -307,13 +307,44 @@ namespace ET
 		public string Message { get; set; }
 
 		[ProtoMember(4)]
-		public Player Player { get; set; }
+		public PlayerInfo Player { get; set; }
 
 		[ProtoMember(5)]
 		public bool IsInRoom { get; set; }
 
 	}
 
+	[ResponseType(nameof(G2C_CreatRoom))]
+	[Message(OuterMessage.C2G_CreatRoom)]
+	[ProtoContract]
+	public partial class C2G_CreatRoom: ProtoObject, IRequest
+	{
+		[ProtoMember(1)]
+		public int RpcId { get; set; }
+
+	}
+
+	[Message(OuterMessage.G2C_CreatRoom)]
+	[ProtoContract]
+	public partial class G2C_CreatRoom: ProtoObject, IResponse
+	{
+		[ProtoMember(1)]
+		public int RpcId { get; set; }
+
+		[ProtoMember(2)]
+		public int Error { get; set; }
+
+		[ProtoMember(3)]
+		public string Message { get; set; }
+
+		[ProtoMember(4)]
+		public long OwnerId { get; set; }
+
+		[ProtoMember(5)]
+		public List<PlayerInfo> PlayerList { get; set; }
+
+	}
+
 	[Message(OuterMessage.G2C_TestHotfixMessage)]
 	[ProtoContract]
 	public partial class G2C_TestHotfixMessage: ProtoObject, IMessage
@@ -397,10 +428,12 @@ namespace ET
 		 public const ushort R2C_Login = 30021;
 		 public const ushort C2G_LoginGame = 30022;
 		 public const ushort G2C_LoginGame = 30023;
-		 public const ushort G2C_TestHotfixMessage = 30024;
-		 public const ushort C2M_TransferMap = 30025;
-		 public const ushort M2C_TransferMap = 30026;
-		 public const ushort C2G_Benchmark = 30027;
-		 public const ushort G2C_Benchmark = 30028;
+		 public const ushort C2G_CreatRoom = 30024;
+		 public const ushort G2C_CreatRoom = 30025;
+		 public const ushort G2C_TestHotfixMessage = 30026;
+		 public const ushort C2M_TransferMap = 30027;
+		 public const ushort M2C_TransferMap = 30028;
+		 public const ushort C2G_Benchmark = 30029;
+		 public const ushort G2C_Benchmark = 30030;
 	}
 }

+ 2 - 2
DotNet/Model/Scenes/Game/Player/Player.cs

@@ -17,8 +17,8 @@
         /** 在线状态 **/
         public bool IsOnline { get; set; }
         
-        /** 是否在房间中 **/
-        public bool IsInRoom { get; set; }
+        /** 房间id **/
+        public long RoomID { get; set; }
 
         /** 头像 **/
         public string AvatarUrl { get; set; }

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

@@ -6,10 +6,13 @@ namespace ET.Server;
 /// 玩家房间
 /// </summary>
 [ChildOf(typeof(GameRoomComponent))]
-public class Room : Entity, IAwake, IDestroy
+public class Room : Entity, IAwake<Player>, IDestroy
 {
     /** 房间玩法类型 1:麻将 2:斗地主 **/
     public int Type { get; set; }
+    
+    /** 房主id **/
+    public long OwnerId { get; set; }
 
     /** 房间玩家集合 **/
     public List<Player> Players { get; set; }

+ 3 - 3
Unity/Assets/Scripts/Codes/Model/Generate/Client/Message/CommonProto_CS_10001.cs

@@ -45,9 +45,9 @@ namespace ET
 
 	}
 
-	[Message(CommonProto.Player)]
+	[Message(CommonProto.PlayerInfo)]
 	[ProtoContract]
-	public partial class Player: ProtoObject
+	public partial class PlayerInfo: ProtoObject
 	{
 		[ProtoMember(1)]
 		public long id { get; set; }
@@ -73,6 +73,6 @@ namespace ET
 	{
 		 public const ushort MoveInfo = 10002;
 		 public const ushort UnitInfo = 10003;
-		 public const ushort Player = 10004;
+		 public const ushort PlayerInfo = 10004;
 	}
 }

+ 39 - 6
Unity/Assets/Scripts/Codes/Model/Generate/Client/Message/OuterMessage_C_30001.cs

@@ -307,13 +307,44 @@ namespace ET
 		public string Message { get; set; }
 
 		[ProtoMember(4)]
-		public Player Player { get; set; }
+		public PlayerInfo Player { get; set; }
 
 		[ProtoMember(5)]
 		public bool IsInRoom { get; set; }
 
 	}
 
+	[ResponseType(nameof(G2C_CreatRoom))]
+	[Message(OuterMessage.C2G_CreatRoom)]
+	[ProtoContract]
+	public partial class C2G_CreatRoom: ProtoObject, IRequest
+	{
+		[ProtoMember(1)]
+		public int RpcId { get; set; }
+
+	}
+
+	[Message(OuterMessage.G2C_CreatRoom)]
+	[ProtoContract]
+	public partial class G2C_CreatRoom: ProtoObject, IResponse
+	{
+		[ProtoMember(1)]
+		public int RpcId { get; set; }
+
+		[ProtoMember(2)]
+		public int Error { get; set; }
+
+		[ProtoMember(3)]
+		public string Message { get; set; }
+
+		[ProtoMember(4)]
+		public long OwnerId { get; set; }
+
+		[ProtoMember(5)]
+		public List<PlayerInfo> PlayerList { get; set; }
+
+	}
+
 	[Message(OuterMessage.G2C_TestHotfixMessage)]
 	[ProtoContract]
 	public partial class G2C_TestHotfixMessage: ProtoObject, IMessage
@@ -397,10 +428,12 @@ namespace ET
 		 public const ushort R2C_Login = 30021;
 		 public const ushort C2G_LoginGame = 30022;
 		 public const ushort G2C_LoginGame = 30023;
-		 public const ushort G2C_TestHotfixMessage = 30024;
-		 public const ushort C2M_TransferMap = 30025;
-		 public const ushort M2C_TransferMap = 30026;
-		 public const ushort C2G_Benchmark = 30027;
-		 public const ushort G2C_Benchmark = 30028;
+		 public const ushort C2G_CreatRoom = 30024;
+		 public const ushort G2C_CreatRoom = 30025;
+		 public const ushort G2C_TestHotfixMessage = 30026;
+		 public const ushort C2M_TransferMap = 30027;
+		 public const ushort M2C_TransferMap = 30028;
+		 public const ushort C2G_Benchmark = 30029;
+		 public const ushort G2C_Benchmark = 30030;
 	}
 }

+ 3 - 3
Unity/Assets/Scripts/Codes/Model/Generate/ClientServer/Message/CommonProto_CS_10001.cs

@@ -45,9 +45,9 @@ namespace ET
 
 	}
 
-	[Message(CommonProto.Player)]
+	[Message(CommonProto.PlayerInfo)]
 	[ProtoContract]
-	public partial class Player: ProtoObject
+	public partial class PlayerInfo: ProtoObject
 	{
 		[ProtoMember(1)]
 		public long id { get; set; }
@@ -73,6 +73,6 @@ namespace ET
 	{
 		 public const ushort MoveInfo = 10002;
 		 public const ushort UnitInfo = 10003;
-		 public const ushort Player = 10004;
+		 public const ushort PlayerInfo = 10004;
 	}
 }

+ 39 - 6
Unity/Assets/Scripts/Codes/Model/Generate/ClientServer/Message/OuterMessage_C_30001.cs

@@ -307,13 +307,44 @@ namespace ET
 		public string Message { get; set; }
 
 		[ProtoMember(4)]
-		public Player Player { get; set; }
+		public PlayerInfo Player { get; set; }
 
 		[ProtoMember(5)]
 		public bool IsInRoom { get; set; }
 
 	}
 
+	[ResponseType(nameof(G2C_CreatRoom))]
+	[Message(OuterMessage.C2G_CreatRoom)]
+	[ProtoContract]
+	public partial class C2G_CreatRoom: ProtoObject, IRequest
+	{
+		[ProtoMember(1)]
+		public int RpcId { get; set; }
+
+	}
+
+	[Message(OuterMessage.G2C_CreatRoom)]
+	[ProtoContract]
+	public partial class G2C_CreatRoom: ProtoObject, IResponse
+	{
+		[ProtoMember(1)]
+		public int RpcId { get; set; }
+
+		[ProtoMember(2)]
+		public int Error { get; set; }
+
+		[ProtoMember(3)]
+		public string Message { get; set; }
+
+		[ProtoMember(4)]
+		public long OwnerId { get; set; }
+
+		[ProtoMember(5)]
+		public List<PlayerInfo> PlayerList { get; set; }
+
+	}
+
 	[Message(OuterMessage.G2C_TestHotfixMessage)]
 	[ProtoContract]
 	public partial class G2C_TestHotfixMessage: ProtoObject, IMessage
@@ -397,10 +428,12 @@ namespace ET
 		 public const ushort R2C_Login = 30021;
 		 public const ushort C2G_LoginGame = 30022;
 		 public const ushort G2C_LoginGame = 30023;
-		 public const ushort G2C_TestHotfixMessage = 30024;
-		 public const ushort C2M_TransferMap = 30025;
-		 public const ushort M2C_TransferMap = 30026;
-		 public const ushort C2G_Benchmark = 30027;
-		 public const ushort G2C_Benchmark = 30028;
+		 public const ushort C2G_CreatRoom = 30024;
+		 public const ushort G2C_CreatRoom = 30025;
+		 public const ushort G2C_TestHotfixMessage = 30026;
+		 public const ushort C2M_TransferMap = 30027;
+		 public const ushort M2C_TransferMap = 30028;
+		 public const ushort C2G_Benchmark = 30029;
+		 public const ushort G2C_Benchmark = 30030;
 	}
 }

+ 2 - 2
Unity/Packages/manifest.json

@@ -1,10 +1,10 @@
 {
   "dependencies": {
-    "com.unity.ide.rider": "3.0.27",
+    "com.unity.ide.rider": "3.0.28",
     "com.unity.ide.visualstudio": "2.0.22",
     "com.unity.ide.vscode": "1.2.5",
     "com.unity.render-pipelines.universal": "12.1.8",
-    "com.unity.textmeshpro": "3.0.6",
+    "com.unity.textmeshpro": "3.0.8",
     "com.unity.timeline": "1.7.1",
     "com.unity.ugui": "1.0.0",
     "com.unity.modules.ai": "1.0.0",

+ 2 - 2
Unity/Packages/packages-lock.json

@@ -23,7 +23,7 @@
       "url": "https://packages.unity.cn"
     },
     "com.unity.ide.rider": {
-      "version": "3.0.27",
+      "version": "3.0.28",
       "depth": 0,
       "source": "registry",
       "dependencies": {
@@ -103,7 +103,7 @@
       "url": "https://packages.unity.cn"
     },
     "com.unity.textmeshpro": {
-      "version": "3.0.6",
+      "version": "3.0.8",
       "depth": 0,
       "source": "registry",
       "dependencies": {