diff --git a/Config/Excel/Server/SceneConfig.xlsx b/Config/Excel/Server/SceneConfig.xlsx index 6ba3130..56dbff9 100644 Binary files a/Config/Excel/Server/SceneConfig.xlsx and b/Config/Excel/Server/SceneConfig.xlsx differ diff --git a/Config/Excel/Version.txt b/Config/Excel/Version.txt index a97e252..c7407f0 100644 --- a/Config/Excel/Version.txt +++ b/Config/Excel/Version.txt @@ -1 +1 @@ -{"WorksheetNames":[-8419147776733210060,-3495952183970875596,1720330851179383898,5812538452563588342],"Tables":{"-3495952183970875596":1756136538067,"-1088042625810372120":1753532052628,"1720330851179383898":1753711757684,"3730651590607244245":1753532052629,"5812538452563588342":1753532052630}} \ No newline at end of file +{"WorksheetNames":[-8419147776733210060,-3495952183970875596,1720330851179383898,5812538452563588342],"Tables":{"-3495952183970875596":1756213540397,"-1088042625810372120":1753532052628,"1720330851179383898":1753711757684,"3730651590607244245":1753532052629,"5812538452563588342":1753532052630}} \ No newline at end of file diff --git a/Config/NetworkProtocol/Inner/InnerMessage.proto b/Config/NetworkProtocol/Inner/InnerMessage.proto index 2423d5a..0709ff3 100644 --- a/Config/NetworkProtocol/Inner/InnerMessage.proto +++ b/Config/NetworkProtocol/Inner/InnerMessage.proto @@ -1,5 +1,6 @@ syntax = "proto3"; package Sining.Message; + ///通知游戏服角色进入该游戏服 message G2Common_EnterRequest // IRouteRequest,G2Common_EnterResponse { @@ -10,7 +11,7 @@ message G2Common_EnterRequest // IRouteRequest,G2Common_EnterResponse message G2Common_EnterResponse // IRouteResponse { - int64 RoleRouteId = 1; //实体的路由id + int64 UnitRouteId = 1; //实体的路由id int32 RouteType = 2; //登陆的场景类型 } @@ -50,3 +51,19 @@ message Club2Chat_CreateChannel // IRouteMessage { int64 ChannelId = 1; //频道id } + + + +/// 请求进入房间 +message G2Map_EnterRoomRequest // IRouteRequest,Map2G_EnterRoomResponse +{ + string RoomCode = 1; //房间代码 + int64 AccountId = 2; //账号id +} + +/// 请求进入房间响应 +message Map2G_EnterRoomResponse // IRouteResponse +{ + string RoomCode = 1; //房间代码 + repeated MapUnitInfo Units = 2; //房间玩家列表 +} \ No newline at end of file diff --git a/Config/NetworkProtocol/Outer/GameMessage.proto b/Config/NetworkProtocol/Outer/GameMessage.proto index 54b0540..2f5c1f6 100644 --- a/Config/NetworkProtocol/Outer/GameMessage.proto +++ b/Config/NetworkProtocol/Outer/GameMessage.proto @@ -1,44 +1,3 @@ syntax = "proto3"; package Fantasy.Network.Message; -/// 请求创建房间 -message C2Game_CreateRoomRequest // ICustomRouteRequest,Game2C_CreateRoomResponse,MapRoute -{ - int32 MapId = 1;//地图id - string Password = 2;//进入密码 -} - -/// 请求创建房间成功 -message Game2C_CreateRoomResponse // ICustomRouteResponse -{ - int32 MapId = 1;//地图id - int64 RoomId = 2;//房间id -} - -/// 请求进入地图 -message C2Game_EnterMapRequest // ICustomRouteRequest,Game2C_EnterMapResponse,MapRoute -{ - int32 MapId = 1; //房间id - int32 Type = 2; //进入地图方式 -} - -/// 请求进入地图响应 -message Game2C_EnterMapResponse // ICustomRouteResponse -{ - int32 MapId = 1; //地图id - int Pos = 2; //位置 -} - -/// 请求进入房间 -message C2Game_EnterRoomRequest // ICustomRouteRequest,Game2C_EnterRoomResponse,MapRoute -{ - int32 MapId = 1;//房间id - string Password = 2;//进入密码 -} - -/// 请求进入房间响应 -message Game2C_EnterRoomResponse // ICustomRouteResponse -{ - int32 MapId = 1;//地图id - int64 RoomId = 2;//房间id -} \ No newline at end of file diff --git a/Config/NetworkProtocol/Outer/MapMessage.proto b/Config/NetworkProtocol/Outer/MapMessage.proto index e69de29..1180e62 100644 --- a/Config/NetworkProtocol/Outer/MapMessage.proto +++ b/Config/NetworkProtocol/Outer/MapMessage.proto @@ -0,0 +1,40 @@ +syntax = "proto3"; +package Fantasy.Network.Message; + +/// 请求创建房间 +message C2Map_CreateRoomRequest // ICustomRouteRequest,Map2C_CreateRoomResponse,MapRoute +{ + int32 MapId = 1;//地图id +} + +/// 请求创建房间成功 +message Map2C_CreateRoomResponse // ICustomRouteResponse +{ + string RoomCode = 1; //房间代码 + repeated MapUnitInfo Units = 2; //房间玩家列表 +} + +/// 请求网关进入房间 +message C2G_EnterRoomRequest // IRequest,G2C_EnterRoomResponse +{ + string RoomCode = 1; //房间代码 +} +/// 请求网关进入房间响应 +message G2C_EnterRoomResponse // IResponse +{ + string RoomCode = 1; //房间代码 + repeated MapUnitInfo Units = 2; //房间玩家列表 +} + + + +message C2Map_EnterMapRequest // ICustomRouteRequest,Map2C_EnterMapResponse,MapRoute +{ + int32 MapId = 1;//地图id + int64 RoomId = 2;//房间id,如果联机则有 +} + +message Map2C_EnterMapResponse // ICustomRouteResponse +{ + int32 MapId = 1; //地图id +} \ No newline at end of file diff --git a/Config/NetworkProtocol/Outer/OuterMessage.proto b/Config/NetworkProtocol/Outer/OuterMessage.proto index 133ed58..efc4d42 100644 --- a/Config/NetworkProtocol/Outer/OuterMessage.proto +++ b/Config/NetworkProtocol/Outer/OuterMessage.proto @@ -31,16 +31,7 @@ message G2C_LoginResponse // IResponse int64 RoleId = 1; } -/// 客户端登陆聊天服 -message C2G_LoginChatRequest -{ - int32 Type = 1; -} -/// 客户端登陆聊天服响应 -message G2C_LoginChatResponse // IResponse -{ - int64 RouteId = 1; -} + /// 通知客户端重复登录 message G2C_RepeatLogin // IMessage diff --git a/Config/NetworkProtocol/Outer/RoomMessage.proto b/Config/NetworkProtocol/Outer/RoomMessage.proto index 836f09f..dfbfc29 100644 --- a/Config/NetworkProtocol/Outer/RoomMessage.proto +++ b/Config/NetworkProtocol/Outer/RoomMessage.proto @@ -1,72 +1,6 @@ syntax = "proto3"; package Fantasy.Network.Message; -message UnitGearItemInfo -{ - int64 Id = 1; //唯一id - int32 ConfigId = 2; //配置id -} - -message UnitGearInfo -{ - UnitGearItemInfo Rod = 1; - UnitGearItemInfo Reel = 2; - UnitGearItemInfo Bobber = 3; - UnitGearItemInfo Hook = 4; - UnitGearItemInfo Bait = 5; - UnitGearItemInfo Lure = 6; - UnitGearItemInfo Weight = 7; - UnitGearItemInfo Line = 8; - UnitGearItemInfo Leader = 9; - UnitGearItemInfo Feeder = 10; -} - -message Vector3Info -{ - float x = 1; - float y = 2; - float z = 3; -} -message QuaternionInfo -{ - float x = 1; - float y = 2; - float z = 3; - float w = 4; -} - -message UnitFishingInfo -{ - float LineLength = 1;//线长度 - float ReelSpeed = 2;//收线速度 - bool OpenLight = 3;//打开手电筒 - int RodSetting = 4; -} - -message UnitStateInfo -{ - int32 State = 1; //状态id - repeated string Args = 2; //状态参数 -} - -message MapUnitInfo -{ - int64 Id = 1; //用户id - RoleSimpleInfo RoleInfo = 2; //基础信息 - MapUnitPositionInfo Location = 3; //位置信息 - UnitStateInfo State = 4; //状态信息 - UnitGearInfo Gears = 5; //钓组数据 - UnitFishingInfo FishingInfo = 6; //钓鱼状态信息 - repeated KeyValueInt32 KV = 7; //属性信息 -} - -message MapUnitPositionInfo -{ - Vector3Info Position = 1; - QuaternionInfo Rotation = 2; -} - - message C2Map_EnterRoomRequest // ICustomRouteRequest,Map2C_EnterRoomResponse,MapRoute { @@ -80,17 +14,7 @@ message Map2C_EnterRoomResponse // ICustomRouteResponse int64 RoomId = 2;//房间id } -message C2Map_EnterMapRequest // ICustomRouteRequest,Map2C_EnterMapResponse,MapRoute -{ - int32 MapId = 1;//地图id - int64 RoomId = 2;//房间id,如果联机则有 -} -message Map2C_EnterMapResponse // ICustomRouteResponse -{ - repeated MapUnitInfo Roles = 1; //地图玩家列表 - int64 MapId = 2; //地图id -} message C2Map_Move // ICustomRouteMessage,MapRoute diff --git a/Config/NetworkProtocol/Outer/data/MapProtoData.proto b/Config/NetworkProtocol/Outer/data/MapProtoData.proto new file mode 100644 index 0000000..94739cd --- /dev/null +++ b/Config/NetworkProtocol/Outer/data/MapProtoData.proto @@ -0,0 +1,65 @@ + +message UnitGearItemInfo +{ + int64 Id = 1; //唯一id + int32 ConfigId = 2; //配置id +} + +message UnitGearInfo +{ + UnitGearItemInfo Rod = 1; + UnitGearItemInfo Reel = 2; + UnitGearItemInfo Bobber = 3; + UnitGearItemInfo Hook = 4; + UnitGearItemInfo Bait = 5; + UnitGearItemInfo Lure = 6; + UnitGearItemInfo Weight = 7; + UnitGearItemInfo Line = 8; + UnitGearItemInfo Leader = 9; + UnitGearItemInfo Feeder = 10; +} + +message Vector3Info +{ + float x = 1; + float y = 2; + float z = 3; +} +message QuaternionInfo +{ + float x = 1; + float y = 2; + float z = 3; + float w = 4; +} + +message UnitFishingInfo +{ + float LineLength = 1;//线长度 + float ReelSpeed = 2;//收线速度 + bool OpenLight = 3;//打开手电筒 + int RodSetting = 4; +} + +message UnitStateInfo +{ + int32 State = 1; //状态id + repeated string Args = 2; //状态参数 +} + +message MapUnitInfo +{ + int64 Id = 1; //用户id + RoleSimpleInfo RoleInfo = 2; //基础信息 + MapUnitPositionInfo Location = 3; //位置信息 + UnitStateInfo State = 4; //状态信息 + UnitGearInfo Gears = 5; //钓组数据 + UnitFishingInfo FishingInfo = 6; //钓鱼状态信息 + repeated KeyValueInt32 KV = 7; //属性信息 +} + +message MapUnitPositionInfo +{ + Vector3Info Position = 1; + QuaternionInfo Rotation = 2; +} diff --git a/Entity/Entity.csproj b/Entity/Entity.csproj index f0bf372..8e26470 100644 --- a/Entity/Entity.csproj +++ b/Entity/Entity.csproj @@ -29,7 +29,6 @@ - diff --git a/Entity/Generate/NetworkProtocol/GameMessage.cs b/Entity/Generate/NetworkProtocol/GameMessage.cs index 9c9cb9b..c4f45da 100644 --- a/Entity/Generate/NetworkProtocol/GameMessage.cs +++ b/Entity/Generate/NetworkProtocol/GameMessage.cs @@ -17,169 +17,4 @@ using Fantasy.Serialize; namespace Fantasy { - /// - /// 请求创建房间 - /// - [ProtoContract] - public partial class C2Game_CreateRoomRequest : AMessage, ICustomRouteRequest, IProto - { - public static C2Game_CreateRoomRequest Create(Scene scene) - { - return scene.MessagePoolComponent.Rent(); - } - public override void Dispose() - { - MapId = default; - Password = default; -#if FANTASY_NET || FANTASY_UNITY - GetScene().MessagePoolComponent.Return(this); -#endif - } - [ProtoIgnore] - public Game2C_CreateRoomResponse ResponseType { get; set; } - public uint OpCode() { return OuterOpcode.C2Game_CreateRoomRequest; } - [ProtoIgnore] - public int RouteType => Fantasy.RouteType.MapRoute; - [ProtoMember(1)] - public int MapId { get; set; } - [ProtoMember(2)] - public string Password { get; set; } - } - /// - /// 请求创建房间成功 - /// - [ProtoContract] - public partial class Game2C_CreateRoomResponse : AMessage, ICustomRouteResponse, IProto - { - public static Game2C_CreateRoomResponse Create(Scene scene) - { - return scene.MessagePoolComponent.Rent(); - } - public override void Dispose() - { - ErrorCode = default; - MapId = default; - RoomId = default; -#if FANTASY_NET || FANTASY_UNITY - GetScene().MessagePoolComponent.Return(this); -#endif - } - public uint OpCode() { return OuterOpcode.Game2C_CreateRoomResponse; } - [ProtoMember(1)] - public int MapId { get; set; } - [ProtoMember(2)] - public long RoomId { get; set; } - [ProtoMember(3)] - public uint ErrorCode { get; set; } - } - /// - /// 请求进入地图 - /// - [ProtoContract] - public partial class C2Game_EnterMapRequest : AMessage, ICustomRouteRequest, IProto - { - public static C2Game_EnterMapRequest Create(Scene scene) - { - return scene.MessagePoolComponent.Rent(); - } - public override void Dispose() - { - MapId = default; - Type = default; -#if FANTASY_NET || FANTASY_UNITY - GetScene().MessagePoolComponent.Return(this); -#endif - } - [ProtoIgnore] - public Game2C_EnterMapResponse ResponseType { get; set; } - public uint OpCode() { return OuterOpcode.C2Game_EnterMapRequest; } - [ProtoIgnore] - public int RouteType => Fantasy.RouteType.MapRoute; - [ProtoMember(1)] - public int MapId { get; set; } - [ProtoMember(2)] - public int Type { get; set; } - } - /// - /// 请求进入地图响应 - /// - [ProtoContract] - public partial class Game2C_EnterMapResponse : AMessage, ICustomRouteResponse, IProto - { - public static Game2C_EnterMapResponse Create(Scene scene) - { - return scene.MessagePoolComponent.Rent(); - } - public override void Dispose() - { - ErrorCode = default; - MapId = default; - Pos = default; -#if FANTASY_NET || FANTASY_UNITY - GetScene().MessagePoolComponent.Return(this); -#endif - } - public uint OpCode() { return OuterOpcode.Game2C_EnterMapResponse; } - [ProtoMember(1)] - public int MapId { get; set; } - [ProtoMember(2)] - public int Pos { get; set; } - [ProtoMember(3)] - public uint ErrorCode { get; set; } - } - /// - /// 请求进入房间 - /// - [ProtoContract] - public partial class C2Game_EnterRoomRequest : AMessage, ICustomRouteRequest, IProto - { - public static C2Game_EnterRoomRequest Create(Scene scene) - { - return scene.MessagePoolComponent.Rent(); - } - public override void Dispose() - { - MapId = default; - Password = default; -#if FANTASY_NET || FANTASY_UNITY - GetScene().MessagePoolComponent.Return(this); -#endif - } - [ProtoIgnore] - public Game2C_EnterRoomResponse ResponseType { get; set; } - public uint OpCode() { return OuterOpcode.C2Game_EnterRoomRequest; } - [ProtoIgnore] - public int RouteType => Fantasy.RouteType.MapRoute; - [ProtoMember(1)] - public int MapId { get; set; } - [ProtoMember(2)] - public string Password { get; set; } - } - /// - /// 请求进入房间响应 - /// - [ProtoContract] - public partial class Game2C_EnterRoomResponse : AMessage, ICustomRouteResponse, IProto - { - public static Game2C_EnterRoomResponse Create(Scene scene) - { - return scene.MessagePoolComponent.Rent(); - } - public override void Dispose() - { - ErrorCode = default; - MapId = default; - RoomId = default; -#if FANTASY_NET || FANTASY_UNITY - GetScene().MessagePoolComponent.Return(this); -#endif - } - public uint OpCode() { return OuterOpcode.Game2C_EnterRoomResponse; } - [ProtoMember(1)] - public int MapId { get; set; } - [ProtoMember(2)] - public long RoomId { get; set; } - [ProtoMember(3)] - public uint ErrorCode { get; set; } - } } diff --git a/Entity/Generate/NetworkProtocol/InnerMessage.cs b/Entity/Generate/NetworkProtocol/InnerMessage.cs index e5f64b7..2519fb0 100644 --- a/Entity/Generate/NetworkProtocol/InnerMessage.cs +++ b/Entity/Generate/NetworkProtocol/InnerMessage.cs @@ -56,7 +56,7 @@ namespace Fantasy public override void Dispose() { ErrorCode = default; - RoleRouteId = default; + UnitRouteId = default; RouteType = default; #if FANTASY_NET || FANTASY_UNITY GetScene().MessagePoolComponent.Return(this); @@ -64,7 +64,7 @@ namespace Fantasy } public uint OpCode() { return InnerOpcode.G2Common_EnterResponse; } [ProtoMember(1)] - public long RoleRouteId { get; set; } + public long UnitRouteId { get; set; } [ProtoMember(2)] public int RouteType { get; set; } [ProtoMember(3)] @@ -200,4 +200,57 @@ namespace Fantasy [ProtoMember(1)] public long ChannelId { get; set; } } + /// + /// 请求进入房间 + /// + [ProtoContract] + public partial class G2Map_EnterRoomRequest : AMessage, IRouteRequest, IProto + { + public static G2Map_EnterRoomRequest Create(Scene scene) + { + return scene.MessagePoolComponent.Rent(); + } + public override void Dispose() + { + RoomCode = default; + AccountId = default; +#if FANTASY_NET || FANTASY_UNITY + GetScene().MessagePoolComponent.Return(this); +#endif + } + [ProtoIgnore] + public Map2G_EnterRoomResponse ResponseType { get; set; } + public uint OpCode() { return InnerOpcode.G2Map_EnterRoomRequest; } + [ProtoMember(1)] + public string RoomCode { get; set; } + [ProtoMember(2)] + public long AccountId { get; set; } + } + /// + /// 请求进入房间响应 + /// + [ProtoContract] + public partial class Map2G_EnterRoomResponse : AMessage, IRouteResponse, IProto + { + public static Map2G_EnterRoomResponse Create(Scene scene) + { + return scene.MessagePoolComponent.Rent(); + } + public override void Dispose() + { + ErrorCode = default; + RoomCode = default; + Units.Clear(); +#if FANTASY_NET || FANTASY_UNITY + GetScene().MessagePoolComponent.Return(this); +#endif + } + public uint OpCode() { return InnerOpcode.Map2G_EnterRoomResponse; } + [ProtoMember(1)] + public string RoomCode { get; set; } + [ProtoMember(2)] + public List Units = new List(); + [ProtoMember(3)] + public uint ErrorCode { get; set; } + } } diff --git a/Entity/Generate/NetworkProtocol/InnerOpcode.cs b/Entity/Generate/NetworkProtocol/InnerOpcode.cs index 095a392..81c5c0b 100644 --- a/Entity/Generate/NetworkProtocol/InnerOpcode.cs +++ b/Entity/Generate/NetworkProtocol/InnerOpcode.cs @@ -10,5 +10,7 @@ namespace Fantasy public const uint G2S_GetPlayerBasicInfoResponse = 1207969555; public const uint S2G_ChatMessage = 939534097; public const uint Club2Chat_CreateChannel = 939534098; + public const uint G2Map_EnterRoomRequest = 1073751828; + public const uint Map2G_EnterRoomResponse = 1207969556; } } diff --git a/Entity/Generate/NetworkProtocol/MapMessage.cs b/Entity/Generate/NetworkProtocol/MapMessage.cs index c4f45da..9029d73 100644 --- a/Entity/Generate/NetworkProtocol/MapMessage.cs +++ b/Entity/Generate/NetworkProtocol/MapMessage.cs @@ -17,4 +17,152 @@ using Fantasy.Serialize; namespace Fantasy { + /// + /// 请求创建房间 + /// + [ProtoContract] + public partial class C2Map_CreateRoomRequest : AMessage, ICustomRouteRequest, IProto + { + public static C2Map_CreateRoomRequest Create(Scene scene) + { + return scene.MessagePoolComponent.Rent(); + } + public override void Dispose() + { + MapId = default; +#if FANTASY_NET || FANTASY_UNITY + GetScene().MessagePoolComponent.Return(this); +#endif + } + [ProtoIgnore] + public Map2C_CreateRoomResponse ResponseType { get; set; } + public uint OpCode() { return OuterOpcode.C2Map_CreateRoomRequest; } + [ProtoIgnore] + public int RouteType => Fantasy.RouteType.MapRoute; + [ProtoMember(1)] + public int MapId { get; set; } + } + /// + /// 请求创建房间成功 + /// + [ProtoContract] + public partial class Map2C_CreateRoomResponse : AMessage, ICustomRouteResponse, IProto + { + public static Map2C_CreateRoomResponse Create(Scene scene) + { + return scene.MessagePoolComponent.Rent(); + } + public override void Dispose() + { + ErrorCode = default; + RoomCode = default; + Units.Clear(); +#if FANTASY_NET || FANTASY_UNITY + GetScene().MessagePoolComponent.Return(this); +#endif + } + public uint OpCode() { return OuterOpcode.Map2C_CreateRoomResponse; } + [ProtoMember(1)] + public string RoomCode { get; set; } + [ProtoMember(2)] + public List Units = new List(); + [ProtoMember(3)] + public uint ErrorCode { get; set; } + } + /// + /// 请求网关进入房间 + /// + [ProtoContract] + public partial class C2G_EnterRoomRequest : AMessage, IRequest, IProto + { + public static C2G_EnterRoomRequest Create(Scene scene) + { + return scene.MessagePoolComponent.Rent(); + } + public override void Dispose() + { + RoomCode = default; +#if FANTASY_NET || FANTASY_UNITY + GetScene().MessagePoolComponent.Return(this); +#endif + } + [ProtoIgnore] + public G2C_EnterRoomResponse ResponseType { get; set; } + public uint OpCode() { return OuterOpcode.C2G_EnterRoomRequest; } + [ProtoMember(1)] + public string RoomCode { get; set; } + } + /// + /// 请求网关进入房间响应 + /// + [ProtoContract] + public partial class G2C_EnterRoomResponse : AMessage, IResponse, IProto + { + public static G2C_EnterRoomResponse Create(Scene scene) + { + return scene.MessagePoolComponent.Rent(); + } + public override void Dispose() + { + ErrorCode = default; + RoomCode = default; + Units.Clear(); +#if FANTASY_NET || FANTASY_UNITY + GetScene().MessagePoolComponent.Return(this); +#endif + } + public uint OpCode() { return OuterOpcode.G2C_EnterRoomResponse; } + [ProtoMember(1)] + public string RoomCode { get; set; } + [ProtoMember(2)] + public List Units = new List(); + [ProtoMember(3)] + public uint ErrorCode { get; set; } + } + [ProtoContract] + public partial class C2Map_EnterMapRequest : AMessage, ICustomRouteRequest, IProto + { + public static C2Map_EnterMapRequest Create(Scene scene) + { + return scene.MessagePoolComponent.Rent(); + } + public override void Dispose() + { + MapId = default; + RoomId = default; +#if FANTASY_NET || FANTASY_UNITY + GetScene().MessagePoolComponent.Return(this); +#endif + } + [ProtoIgnore] + public Map2C_EnterMapResponse ResponseType { get; set; } + public uint OpCode() { return OuterOpcode.C2Map_EnterMapRequest; } + [ProtoIgnore] + public int RouteType => Fantasy.RouteType.MapRoute; + [ProtoMember(1)] + public int MapId { get; set; } + [ProtoMember(2)] + public long RoomId { get; set; } + } + [ProtoContract] + public partial class Map2C_EnterMapResponse : AMessage, ICustomRouteResponse, IProto + { + public static Map2C_EnterMapResponse Create(Scene scene) + { + return scene.MessagePoolComponent.Rent(); + } + public override void Dispose() + { + ErrorCode = default; + MapId = default; +#if FANTASY_NET || FANTASY_UNITY + GetScene().MessagePoolComponent.Return(this); +#endif + } + public uint OpCode() { return OuterOpcode.Map2C_EnterMapResponse; } + [ProtoMember(1)] + public int MapId { get; set; } + [ProtoMember(2)] + public uint ErrorCode { get; set; } + } } diff --git a/Entity/Generate/NetworkProtocol/MapProtoData.cs b/Entity/Generate/NetworkProtocol/MapProtoData.cs new file mode 100644 index 0000000..d361b08 --- /dev/null +++ b/Entity/Generate/NetworkProtocol/MapProtoData.cs @@ -0,0 +1,234 @@ +using ProtoBuf; + +using System.Collections.Generic; +using MongoDB.Bson.Serialization.Attributes; +using Fantasy; +using Fantasy.Network.Interface; +using Fantasy.Serialize; +// ReSharper disable InconsistentNaming +// ReSharper disable RedundantUsingDirective +// ReSharper disable RedundantOverriddenMember +// ReSharper disable PartialTypeWithSinglePart +// ReSharper disable UnusedAutoPropertyAccessor.Global +// ReSharper disable MemberCanBePrivate.Global +// ReSharper disable CheckNamespace +#pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type. +#pragma warning disable CS8618 + +namespace Fantasy +{ + [ProtoContract] + public partial class UnitGearItemInfo : AMessage, IProto + { + public static UnitGearItemInfo Create(Scene scene) + { + return scene.MessagePoolComponent.Rent(); + } + public override void Dispose() + { + Id = default; + ConfigId = default; +#if FANTASY_NET || FANTASY_UNITY + GetScene().MessagePoolComponent.Return(this); +#endif + } + [ProtoMember(1)] + public long Id { get; set; } + [ProtoMember(2)] + public int ConfigId { get; set; } + } + [ProtoContract] + public partial class UnitGearInfo : AMessage, IProto + { + public static UnitGearInfo Create(Scene scene) + { + return scene.MessagePoolComponent.Rent(); + } + public override void Dispose() + { + Rod = default; + Reel = default; + Bobber = default; + Hook = default; + Bait = default; + Lure = default; + Weight = default; + Line = default; + Leader = default; + Feeder = default; +#if FANTASY_NET || FANTASY_UNITY + GetScene().MessagePoolComponent.Return(this); +#endif + } + [ProtoMember(1)] + public UnitGearItemInfo Rod { get; set; } + [ProtoMember(2)] + public UnitGearItemInfo Reel { get; set; } + [ProtoMember(3)] + public UnitGearItemInfo Bobber { get; set; } + [ProtoMember(4)] + public UnitGearItemInfo Hook { get; set; } + [ProtoMember(5)] + public UnitGearItemInfo Bait { get; set; } + [ProtoMember(6)] + public UnitGearItemInfo Lure { get; set; } + [ProtoMember(7)] + public UnitGearItemInfo Weight { get; set; } + [ProtoMember(8)] + public UnitGearItemInfo Line { get; set; } + [ProtoMember(9)] + public UnitGearItemInfo Leader { get; set; } + [ProtoMember(10)] + public UnitGearItemInfo Feeder { get; set; } + } + [ProtoContract] + public partial class Vector3Info : AMessage, IProto + { + public static Vector3Info Create(Scene scene) + { + return scene.MessagePoolComponent.Rent(); + } + public override void Dispose() + { + x = default; + y = default; + z = default; +#if FANTASY_NET || FANTASY_UNITY + GetScene().MessagePoolComponent.Return(this); +#endif + } + [ProtoMember(1)] + public float x { get; set; } + [ProtoMember(2)] + public float y { get; set; } + [ProtoMember(3)] + public float z { get; set; } + } + [ProtoContract] + public partial class QuaternionInfo : AMessage, IProto + { + public static QuaternionInfo Create(Scene scene) + { + return scene.MessagePoolComponent.Rent(); + } + public override void Dispose() + { + x = default; + y = default; + z = default; + w = default; +#if FANTASY_NET || FANTASY_UNITY + GetScene().MessagePoolComponent.Return(this); +#endif + } + [ProtoMember(1)] + public float x { get; set; } + [ProtoMember(2)] + public float y { get; set; } + [ProtoMember(3)] + public float z { get; set; } + [ProtoMember(4)] + public float w { get; set; } + } + [ProtoContract] + public partial class UnitFishingInfo : AMessage, IProto + { + public static UnitFishingInfo Create(Scene scene) + { + return scene.MessagePoolComponent.Rent(); + } + public override void Dispose() + { + LineLength = default; + ReelSpeed = default; + OpenLight = default; + RodSetting = default; +#if FANTASY_NET || FANTASY_UNITY + GetScene().MessagePoolComponent.Return(this); +#endif + } + [ProtoMember(1)] + public float LineLength { get; set; } + [ProtoMember(2)] + public float ReelSpeed { get; set; } + [ProtoMember(3)] + public bool OpenLight { get; set; } + [ProtoMember(4)] + public int RodSetting { get; set; } + } + [ProtoContract] + public partial class UnitStateInfo : AMessage, IProto + { + public static UnitStateInfo Create(Scene scene) + { + return scene.MessagePoolComponent.Rent(); + } + public override void Dispose() + { + State = default; + Args.Clear(); +#if FANTASY_NET || FANTASY_UNITY + GetScene().MessagePoolComponent.Return(this); +#endif + } + [ProtoMember(1)] + public int State { get; set; } + [ProtoMember(2)] + public List Args = new List(); + } + [ProtoContract] + public partial class MapUnitInfo : AMessage, IProto + { + public static MapUnitInfo Create(Scene scene) + { + return scene.MessagePoolComponent.Rent(); + } + public override void Dispose() + { + Id = default; + RoleInfo = default; + Location = default; + State = default; + Gears = default; + FishingInfo = default; + KV.Clear(); +#if FANTASY_NET || FANTASY_UNITY + GetScene().MessagePoolComponent.Return(this); +#endif + } + [ProtoMember(1)] + public long Id { get; set; } + [ProtoMember(2)] + public RoleSimpleInfo RoleInfo { get; set; } + [ProtoMember(3)] + public MapUnitPositionInfo Location { get; set; } + [ProtoMember(4)] + public UnitStateInfo State { get; set; } + [ProtoMember(5)] + public UnitGearInfo Gears { get; set; } + [ProtoMember(6)] + public UnitFishingInfo FishingInfo { get; set; } + [ProtoMember(7)] + public List KV = new List(); + } + [ProtoContract] + public partial class MapUnitPositionInfo : AMessage, IProto + { + public static MapUnitPositionInfo Create(Scene scene) + { + return scene.MessagePoolComponent.Rent(); + } + public override void Dispose() + { + Position = default; + Rotation = default; +#if FANTASY_NET || FANTASY_UNITY + GetScene().MessagePoolComponent.Return(this); +#endif + } + [ProtoMember(1)] + public Vector3Info Position { get; set; } + [ProtoMember(2)] + public QuaternionInfo Rotation { get; set; } + } +} diff --git a/Entity/Generate/NetworkProtocol/OuterMessage.cs b/Entity/Generate/NetworkProtocol/OuterMessage.cs index 18d4604..cb9c2d8 100644 --- a/Entity/Generate/NetworkProtocol/OuterMessage.cs +++ b/Entity/Generate/NetworkProtocol/OuterMessage.cs @@ -112,50 +112,6 @@ namespace Fantasy public uint ErrorCode { get; set; } } /// - /// 客户端登陆聊天服 - /// - [ProtoContract] - public partial class C2G_LoginChatRequest : AMessage, IProto - { - public static C2G_LoginChatRequest Create(Scene scene) - { - return scene.MessagePoolComponent.Rent(); - } - public override void Dispose() - { - Type = default; -#if FANTASY_NET || FANTASY_UNITY - GetScene().MessagePoolComponent.Return(this); -#endif - } - [ProtoMember(1)] - public int Type { get; set; } - } - /// - /// 客户端登陆聊天服响应 - /// - [ProtoContract] - public partial class G2C_LoginChatResponse : AMessage, IResponse, IProto - { - public static G2C_LoginChatResponse Create(Scene scene) - { - return scene.MessagePoolComponent.Rent(); - } - public override void Dispose() - { - ErrorCode = default; - RouteId = default; -#if FANTASY_NET || FANTASY_UNITY - GetScene().MessagePoolComponent.Return(this); -#endif - } - public uint OpCode() { return OuterOpcode.G2C_LoginChatResponse; } - [ProtoMember(1)] - public long RouteId { get; set; } - [ProtoMember(2)] - public uint ErrorCode { get; set; } - } - /// /// 通知客户端重复登录 /// [ProtoContract] diff --git a/Entity/Generate/NetworkProtocol/OuterOpcode.cs b/Entity/Generate/NetworkProtocol/OuterOpcode.cs index 425911b..e380a2c 100644 --- a/Entity/Generate/NetworkProtocol/OuterOpcode.cs +++ b/Entity/Generate/NetworkProtocol/OuterOpcode.cs @@ -2,61 +2,58 @@ namespace Fantasy { public static partial class OuterOpcode { - public const uint C2Game_CreateRoomRequest = 2281711377; - public const uint Game2C_CreateRoomResponse = 2415929105; - public const uint C2Game_EnterMapRequest = 2281711378; - public const uint Game2C_EnterMapResponse = 2415929106; - public const uint C2Game_EnterRoomRequest = 2281711379; - public const uint Game2C_EnterRoomResponse = 2415929107; - public const uint C2A_LoginRequest = 268445457; - public const uint A2C_LoginResponse = 402663185; - public const uint C2G_LoginRequest = 268445458; - public const uint G2C_LoginResponse = 402663186; - public const uint G2C_LoginChatResponse = 402663187; + public const uint C2Map_CreateRoomRequest = 2281711377; + public const uint Map2C_CreateRoomResponse = 2415929105; + public const uint C2G_EnterRoomRequest = 268445457; + public const uint G2C_EnterRoomResponse = 402663185; + public const uint C2Map_EnterMapRequest = 2281711378; + public const uint Map2C_EnterMapResponse = 2415929106; + public const uint C2A_LoginRequest = 268445458; + public const uint A2C_LoginResponse = 402663186; + public const uint C2G_LoginRequest = 268445459; + public const uint G2C_LoginResponse = 402663187; public const uint G2C_RepeatLogin = 134227729; - public const uint C2Game_GetRoleInfoRequest = 2281711380; - public const uint Game2C_GetRoleInfoResponse = 2415929108; - public const uint C2Map_EnterRoomRequest = 2281711381; - public const uint Map2C_EnterRoomResponse = 2415929109; - public const uint C2Map_EnterMapRequest = 2281711382; - public const uint Map2C_EnterMapResponse = 2415929110; + public const uint C2Game_GetRoleInfoRequest = 2281711379; + public const uint Game2C_GetRoleInfoResponse = 2415929107; + public const uint C2Map_EnterRoomRequest = 2281711380; + public const uint Map2C_EnterRoomResponse = 2415929108; public const uint C2Map_Move = 2147493649; public const uint Map2C_RoleEnterMapNotify = 2147493650; public const uint Map2C_RoleExitMapNotify = 2147493651; public const uint Map2C_RoleStateNotify = 2147493652; public const uint Map2C_RoleGearStateNotify = 2147493653; public const uint Map2C_RoleGearChangeNotify = 2147493654; - public const uint C2S_GetConversationsRequest = 2281711383; - public const uint S2C_GetConversationsResponse = 2415929111; - public const uint C2S_SendMailRequest = 2281711384; - public const uint S2C_SendMailResponse = 2415929112; - public const uint C2S_DeleteMailRequest = 2281711385; - public const uint S2C_DeleteMailResponse = 2415929113; + public const uint C2S_GetConversationsRequest = 2281711381; + public const uint S2C_GetConversationsResponse = 2415929109; + public const uint C2S_SendMailRequest = 2281711382; + public const uint S2C_SendMailResponse = 2415929110; + public const uint C2S_DeleteMailRequest = 2281711383; + public const uint S2C_DeleteMailResponse = 2415929111; public const uint S2C_HaveMail = 2147493655; public const uint S2C_MailState = 2147493656; - public const uint C2S_CreateChannelRequest = 2281711386; - public const uint S2C_CreateChannelResponse = 2415929114; - public const uint C2S_JoinChannelRequest = 2281711387; - public const uint S2C_JoinChannelResponse = 2415929115; - public const uint C2S_SendMessageRequest = 2281711388; - public const uint S2C_SendMessageResponse = 2415929116; + public const uint C2S_CreateChannelRequest = 2281711384; + public const uint S2C_CreateChannelResponse = 2415929112; + public const uint C2S_JoinChannelRequest = 2281711385; + public const uint S2C_JoinChannelResponse = 2415929113; + public const uint C2S_SendMessageRequest = 2281711386; + public const uint S2C_SendMessageResponse = 2415929114; public const uint S2C_Message = 2147493657; - public const uint C2S_CreateClubRequest = 2281711389; - public const uint S2C_CreateClubResponse = 2415929117; - public const uint C2S_GetClubInfoRequest = 2281711390; - public const uint S2C_GetClubInfoResponse = 2415929118; - public const uint C2S_GetMemberListRequest = 2281711391; - public const uint S2C_GetMemberListResponse = 2415929119; - public const uint C2S_GetClubListRequest = 2281711392; - public const uint S2C_GetClubListResponse = 2415929120; - public const uint C2S_JoinClubRequest = 2281711393; - public const uint S2C_JoinClubResponse = 2415929121; - public const uint C2S_LeaveClubRequest = 2281711394; - public const uint S2C_LeaveClubResponse = 2415929122; - public const uint C2S_DissolveClubRequest = 2281711395; - public const uint S2C_DissolveClubResponse = 2415929123; - public const uint C2S_DisposeJoinRequest = 2281711396; - public const uint S2C_DisposeJoinResponse = 2415929124; + public const uint C2S_CreateClubRequest = 2281711387; + public const uint S2C_CreateClubResponse = 2415929115; + public const uint C2S_GetClubInfoRequest = 2281711388; + public const uint S2C_GetClubInfoResponse = 2415929116; + public const uint C2S_GetMemberListRequest = 2281711389; + public const uint S2C_GetMemberListResponse = 2415929117; + public const uint C2S_GetClubListRequest = 2281711390; + public const uint S2C_GetClubListResponse = 2415929118; + public const uint C2S_JoinClubRequest = 2281711391; + public const uint S2C_JoinClubResponse = 2415929119; + public const uint C2S_LeaveClubRequest = 2281711392; + public const uint S2C_LeaveClubResponse = 2415929120; + public const uint C2S_DissolveClubRequest = 2281711393; + public const uint S2C_DissolveClubResponse = 2415929121; + public const uint C2S_DisposeJoinRequest = 2281711394; + public const uint S2C_DisposeJoinResponse = 2415929122; public const uint S2C_ClubChange = 2147493658; } } diff --git a/Entity/Generate/NetworkProtocol/RoomMessage.cs b/Entity/Generate/NetworkProtocol/RoomMessage.cs index c3d09da..e54e478 100644 --- a/Entity/Generate/NetworkProtocol/RoomMessage.cs +++ b/Entity/Generate/NetworkProtocol/RoomMessage.cs @@ -17,220 +17,6 @@ using Fantasy.Serialize; namespace Fantasy { - [ProtoContract] - public partial class UnitGearItemInfo : AMessage, IProto - { - public static UnitGearItemInfo Create(Scene scene) - { - return scene.MessagePoolComponent.Rent(); - } - public override void Dispose() - { - Id = default; - ConfigId = default; -#if FANTASY_NET || FANTASY_UNITY - GetScene().MessagePoolComponent.Return(this); -#endif - } - [ProtoMember(1)] - public long Id { get; set; } - [ProtoMember(2)] - public int ConfigId { get; set; } - } - [ProtoContract] - public partial class UnitGearInfo : AMessage, IProto - { - public static UnitGearInfo Create(Scene scene) - { - return scene.MessagePoolComponent.Rent(); - } - public override void Dispose() - { - Rod = default; - Reel = default; - Bobber = default; - Hook = default; - Bait = default; - Lure = default; - Weight = default; - Line = default; - Leader = default; - Feeder = default; -#if FANTASY_NET || FANTASY_UNITY - GetScene().MessagePoolComponent.Return(this); -#endif - } - [ProtoMember(1)] - public UnitGearItemInfo Rod { get; set; } - [ProtoMember(2)] - public UnitGearItemInfo Reel { get; set; } - [ProtoMember(3)] - public UnitGearItemInfo Bobber { get; set; } - [ProtoMember(4)] - public UnitGearItemInfo Hook { get; set; } - [ProtoMember(5)] - public UnitGearItemInfo Bait { get; set; } - [ProtoMember(6)] - public UnitGearItemInfo Lure { get; set; } - [ProtoMember(7)] - public UnitGearItemInfo Weight { get; set; } - [ProtoMember(8)] - public UnitGearItemInfo Line { get; set; } - [ProtoMember(9)] - public UnitGearItemInfo Leader { get; set; } - [ProtoMember(10)] - public UnitGearItemInfo Feeder { get; set; } - } - [ProtoContract] - public partial class Vector3Info : AMessage, IProto - { - public static Vector3Info Create(Scene scene) - { - return scene.MessagePoolComponent.Rent(); - } - public override void Dispose() - { - x = default; - y = default; - z = default; -#if FANTASY_NET || FANTASY_UNITY - GetScene().MessagePoolComponent.Return(this); -#endif - } - [ProtoMember(1)] - public float x { get; set; } - [ProtoMember(2)] - public float y { get; set; } - [ProtoMember(3)] - public float z { get; set; } - } - [ProtoContract] - public partial class QuaternionInfo : AMessage, IProto - { - public static QuaternionInfo Create(Scene scene) - { - return scene.MessagePoolComponent.Rent(); - } - public override void Dispose() - { - x = default; - y = default; - z = default; - w = default; -#if FANTASY_NET || FANTASY_UNITY - GetScene().MessagePoolComponent.Return(this); -#endif - } - [ProtoMember(1)] - public float x { get; set; } - [ProtoMember(2)] - public float y { get; set; } - [ProtoMember(3)] - public float z { get; set; } - [ProtoMember(4)] - public float w { get; set; } - } - [ProtoContract] - public partial class UnitFishingInfo : AMessage, IProto - { - public static UnitFishingInfo Create(Scene scene) - { - return scene.MessagePoolComponent.Rent(); - } - public override void Dispose() - { - LineLength = default; - ReelSpeed = default; - OpenLight = default; - RodSetting = default; -#if FANTASY_NET || FANTASY_UNITY - GetScene().MessagePoolComponent.Return(this); -#endif - } - [ProtoMember(1)] - public float LineLength { get; set; } - [ProtoMember(2)] - public float ReelSpeed { get; set; } - [ProtoMember(3)] - public bool OpenLight { get; set; } - [ProtoMember(4)] - public int RodSetting { get; set; } - } - [ProtoContract] - public partial class UnitStateInfo : AMessage, IProto - { - public static UnitStateInfo Create(Scene scene) - { - return scene.MessagePoolComponent.Rent(); - } - public override void Dispose() - { - State = default; - Args.Clear(); -#if FANTASY_NET || FANTASY_UNITY - GetScene().MessagePoolComponent.Return(this); -#endif - } - [ProtoMember(1)] - public int State { get; set; } - [ProtoMember(2)] - public List Args = new List(); - } - [ProtoContract] - public partial class MapUnitInfo : AMessage, IProto - { - public static MapUnitInfo Create(Scene scene) - { - return scene.MessagePoolComponent.Rent(); - } - public override void Dispose() - { - Id = default; - RoleInfo = default; - Location = default; - State = default; - Gears = default; - FishingInfo = default; - KV.Clear(); -#if FANTASY_NET || FANTASY_UNITY - GetScene().MessagePoolComponent.Return(this); -#endif - } - [ProtoMember(1)] - public long Id { get; set; } - [ProtoMember(2)] - public RoleSimpleInfo RoleInfo { get; set; } - [ProtoMember(3)] - public MapUnitPositionInfo Location { get; set; } - [ProtoMember(4)] - public UnitStateInfo State { get; set; } - [ProtoMember(5)] - public UnitGearInfo Gears { get; set; } - [ProtoMember(6)] - public UnitFishingInfo FishingInfo { get; set; } - [ProtoMember(7)] - public List KV = new List(); - } - [ProtoContract] - public partial class MapUnitPositionInfo : AMessage, IProto - { - public static MapUnitPositionInfo Create(Scene scene) - { - return scene.MessagePoolComponent.Rent(); - } - public override void Dispose() - { - Position = default; - Rotation = default; -#if FANTASY_NET || FANTASY_UNITY - GetScene().MessagePoolComponent.Return(this); -#endif - } - [ProtoMember(1)] - public Vector3Info Position { get; set; } - [ProtoMember(2)] - public QuaternionInfo Rotation { get; set; } - } [ProtoContract] public partial class C2Map_EnterRoomRequest : AMessage, ICustomRouteRequest, IProto { @@ -281,55 +67,6 @@ namespace Fantasy public uint ErrorCode { get; set; } } [ProtoContract] - public partial class C2Map_EnterMapRequest : AMessage, ICustomRouteRequest, IProto - { - public static C2Map_EnterMapRequest Create(Scene scene) - { - return scene.MessagePoolComponent.Rent(); - } - public override void Dispose() - { - MapId = default; - RoomId = default; -#if FANTASY_NET || FANTASY_UNITY - GetScene().MessagePoolComponent.Return(this); -#endif - } - [ProtoIgnore] - public Map2C_EnterMapResponse ResponseType { get; set; } - public uint OpCode() { return OuterOpcode.C2Map_EnterMapRequest; } - [ProtoIgnore] - public int RouteType => Fantasy.RouteType.MapRoute; - [ProtoMember(1)] - public int MapId { get; set; } - [ProtoMember(2)] - public long RoomId { get; set; } - } - [ProtoContract] - public partial class Map2C_EnterMapResponse : AMessage, ICustomRouteResponse, IProto - { - public static Map2C_EnterMapResponse Create(Scene scene) - { - return scene.MessagePoolComponent.Rent(); - } - public override void Dispose() - { - ErrorCode = default; - Roles.Clear(); - MapId = default; -#if FANTASY_NET || FANTASY_UNITY - GetScene().MessagePoolComponent.Return(this); -#endif - } - public uint OpCode() { return OuterOpcode.Map2C_EnterMapResponse; } - [ProtoMember(1)] - public List Roles = new List(); - [ProtoMember(2)] - public long MapId { get; set; } - [ProtoMember(3)] - public uint ErrorCode { get; set; } - } - [ProtoContract] public partial class C2Map_Move : AMessage, ICustomRouteMessage, IProto { public static C2Map_Move Create(Scene scene) diff --git a/Entity/Map/Component/MapManageComponent.cs b/Entity/Map/Component/MapManageComponent.cs new file mode 100644 index 0000000..0af5b52 --- /dev/null +++ b/Entity/Map/Component/MapManageComponent.cs @@ -0,0 +1,8 @@ +using Fantasy.Entitas; + +namespace NB.Map; + +public class MapManageComponent: Entity +{ + public readonly Dictionary Maps = new(); +} \ No newline at end of file diff --git a/Entity/Map/Component/MapUnitManageComponent.cs b/Entity/Map/Component/MapUnitManageComponent.cs new file mode 100644 index 0000000..260efe6 --- /dev/null +++ b/Entity/Map/Component/MapUnitManageComponent.cs @@ -0,0 +1,8 @@ +using Fantasy.Entitas; + +namespace NB.Map; + +public class MapUnitManageComponent : Entity +{ + public readonly Dictionary Units = new(); +} \ No newline at end of file diff --git a/Entity/Map/Component/RoomManageComponent.cs b/Entity/Map/Component/RoomManageComponent.cs new file mode 100644 index 0000000..84bc787 --- /dev/null +++ b/Entity/Map/Component/RoomManageComponent.cs @@ -0,0 +1,11 @@ +using Fantasy.Entitas; + +namespace NB.Map; + +public class RoomManageComponent : Entity +{ + public readonly Dictionary Rooms = new(); + + public readonly PriorityQueue FreeIds = new(); + public readonly HashSet InUseID = new(); +} \ No newline at end of file diff --git a/Entity/Map/Entity/Map.cs b/Entity/Map/Entity/Map.cs new file mode 100644 index 0000000..0a2046e --- /dev/null +++ b/Entity/Map/Entity/Map.cs @@ -0,0 +1,7 @@ +using Fantasy.Entitas; + +namespace NB.Map; + +public class Map : Entity +{ +} \ No newline at end of file diff --git a/Entity/Map/MapRoom.cs b/Entity/Map/Entity/MapRoom.cs similarity index 69% rename from Entity/Map/MapRoom.cs rename to Entity/Map/Entity/MapRoom.cs index a088240..adaf556 100644 --- a/Entity/Map/MapRoom.cs +++ b/Entity/Map/Entity/MapRoom.cs @@ -1,4 +1,5 @@ using Fantasy.Entitas; +using NB.Map; namespace NB.Map; @@ -7,10 +8,20 @@ namespace NB.Map; /// public class MapRoom : Entity { + /// + /// 房间序号id + /// + public int RoomId; + + /// + /// 房间代码 + /// + public string Code = string.Empty; + /// /// 房间密码 /// - public string Password; + public string Password = string.Empty; /// /// 房间玩家 diff --git a/Entity/Map/MapUnit.cs b/Entity/Map/Entity/MapUnit.cs similarity index 60% rename from Entity/Map/MapUnit.cs rename to Entity/Map/Entity/MapUnit.cs index faa74a1..edf10b7 100644 --- a/Entity/Map/MapUnit.cs +++ b/Entity/Map/Entity/MapUnit.cs @@ -17,4 +17,16 @@ public class MapUnit : Entity /// 旋转 /// public float4 Rotation; + + /// + /// 当前所在地图id + /// + public int MapId; + + /// + /// 当前所在房间id + /// + public int RoomId; + + public long GateRouteId; } \ No newline at end of file diff --git a/Entity/Model/Def/ErrorCode.cs b/Entity/Model/Def/ErrorCode.cs index 636a0f8..d57c45b 100644 --- a/Entity/Model/Def/ErrorCode.cs +++ b/Entity/Model/Def/ErrorCode.cs @@ -49,4 +49,24 @@ public class ErrorCode /// 没回复前不能再发消息 /// public const uint MailNotReply = 12021; + + /// + /// 创建房间失败,不在地图中 + /// + public const uint MapCreateRoomNotEnter = 13001; + + /// + /// 创建房间失败,房间数量超限 + /// + public const uint MapCreateRoomMax = 13002; + + /// + /// 房间id 错误 + /// + public const uint MapRoomIdError = 13003; + + /// + /// 已在房间,不能加入另一个 + /// + public const uint MapRoomHave = 13004; } \ No newline at end of file diff --git a/Hotfix/Common/Handler/G2Common_EnterRequestHandler.cs b/Hotfix/Common/Handler/G2Common_EnterRequestHandler.cs index 42c5e96..7aa9c4e 100644 --- a/Hotfix/Common/Handler/G2Common_EnterRequestHandler.cs +++ b/Hotfix/Common/Handler/G2Common_EnterRequestHandler.cs @@ -3,6 +3,7 @@ using Fantasy.Async; using Fantasy.Network.Interface; using NB.Chat; using NB.Game; +using NB.Map; namespace NB.Common; @@ -28,6 +29,7 @@ public class G2Common_EnterRequestHandler : RouteRPC(); - var account = await gameAccountManageComponent.Online(scene, request.AccountId, request.GateRouteId); + var account = await gameAccountManageComponent.Online(request.AccountId, request.GateRouteId); if (account == null) { response.ErrorCode = ErrorCode.ErrServer; return; } - response.RoleRouteId = account.RuntimeId; + response.UnitRouteId = account.RuntimeId; + Log.Info($"登录到游戏服成功,id={response.UnitRouteId}"); } private async FTask RunSocial(Scene scene, G2Common_EnterRequest request, G2Common_EnterResponse response) @@ -61,6 +64,23 @@ public class G2Common_EnterRequestHandler : RouteRPC(); + var account = await chatUnitManageComponent.Online(scene, request.AccountId, request.GateRouteId); + + if (account == null) + { + response.ErrorCode = ErrorCode.ErrServer; + return; + } + + response.UnitRouteId = account.RuntimeId; + Log.Info($"登录到地图服成功,id={response.UnitRouteId}"); } } \ No newline at end of file diff --git a/Hotfix/Common/Handler/G2Common_ExitRequestHandler.cs b/Hotfix/Common/Handler/G2Common_ExitRequestHandler.cs index 15b8568..6bb6aff 100644 --- a/Hotfix/Common/Handler/G2Common_ExitRequestHandler.cs +++ b/Hotfix/Common/Handler/G2Common_ExitRequestHandler.cs @@ -2,6 +2,8 @@ using Fantasy.Async; using Fantasy.Network.Interface; using NB.Chat; +using NB.Game; +using NB.Map; namespace NB.Common; @@ -25,6 +27,7 @@ public class G2Common_ExitRequestHandler : RouteRPC(); - // var account = await gameAccountManageComponent.Online(scene, request.AccountId, request.GateRouteId); - // if (account == null) - // { - // response.ErrorCode = ErrorCode.ErrServer; - // return; - // } - // - // response.RoleRouteId = account.RuntimeId; + // 在缓存中检查该账号是否存在 + var gameAccountManageComponent = scene.GetComponent(); + await gameAccountManageComponent.Offline(request.AccountId, request.GateRouteId); + Log.Info("退出游戏服成功=="); } private async FTask RunSocial(Scene scene, G2Common_ExitRequest request, Common2G_ExitResponse response) @@ -51,5 +48,14 @@ public class G2Common_ExitRequestHandler : RouteRPC(); await chatUnitManageComponent.Offline(scene, request.AccountId, request.GateRouteId); + Log.Info("退出聊天服成功=="); + } + + private async FTask RunMap(Scene scene, G2Common_ExitRequest request, Common2G_ExitResponse response) + { + // 在缓存中检查该账号是否存在 + var chatUnitManageComponent = scene.GetComponent(); + await chatUnitManageComponent.Offline(scene, request.AccountId, request.GateRouteId); + Log.Info("退出房间服成功=="); } } \ No newline at end of file diff --git a/Hotfix/Common/Helper/SceneConfigHelper.cs b/Hotfix/Common/Helper/SceneConfigHelper.cs index e12cb8d..f7f55c3 100644 --- a/Hotfix/Common/Helper/SceneConfigHelper.cs +++ b/Hotfix/Common/Helper/SceneConfigHelper.cs @@ -3,12 +3,38 @@ using Fantasy.Platform.Net; namespace NB.Common; -public class SceneConfigHelper +public static class SceneConfigHelper { + public static SceneConfig GetConfigByRouteType(int routeType) + { + var sceneType = SceneType.Game; + if (routeType == RouteType.GameRoute) + { + sceneType = SceneType.Game; + } + else if (routeType == RouteType.SocialRoute) + { + sceneType = SceneType.Social; + } + else if (routeType == RouteType.MapRoute) + { + sceneType = SceneType.Map; + } + else if (routeType == RouteType.GateRoute) + { + sceneType = SceneType.Gate; + } + + return GetConfig(sceneType); + } + public static SceneConfig GetConfig(int sceneType) { + var gameSceneConfigs = SceneConfigData.Instance.GetSceneBySceneType(sceneType); return gameSceneConfigs.First(); } + + } \ No newline at end of file diff --git a/Hotfix/Game/Handler/G2Game_EnterRequestHandler.cs b/Hotfix/Game/Handler/G2Game_EnterRequestHandler.cs deleted file mode 100644 index d1033f8..0000000 --- a/Hotfix/Game/Handler/G2Game_EnterRequestHandler.cs +++ /dev/null @@ -1,29 +0,0 @@ -// using Fantasy; -// using Fantasy.Async; -// using Fantasy.Entitas; -// using Fantasy.Helper; -// using Fantasy.Network; -// using Fantasy.Network.Interface; -// using NB; -// using NB.Gate; -// -// namespace NB.Game; -// -// public class G2Game_EnterRequestHandler : RouteRPC -// { -// protected override async FTask Run(Scene scene, G2Game_EnterRequest request, Game2G_EnterResponse response, -// Action reply) -// { -// Log.Debug("收到 G2Game_EnterRequestHandler"); -// -// -// // 在缓存中检查该账号是否存在 -// var gameAccountManageComponent = scene.GetComponent(); -// -// var account = await gameAccountManageComponent.Online(scene, request.AccountId, request.GateRouteId); -// -// response.RoleRouteId = account.RuntimeId; -// response.RoleInfo = account.GetRoleSimpleInfo(); -// await FTask.CompletedTask; -// } -// } \ No newline at end of file diff --git a/Hotfix/Game/Player/Components/PlayerManageComponentSystem.cs b/Hotfix/Game/Player/Components/PlayerManageComponentSystem.cs index d94b893..cb411db 100644 --- a/Hotfix/Game/Player/Components/PlayerManageComponentSystem.cs +++ b/Hotfix/Game/Player/Components/PlayerManageComponentSystem.cs @@ -40,24 +40,22 @@ public static class PlayerManageComponentSystem /// 玩家上线 /// /// - /// /// /// - public static async FTask Online(this PlayerManageComponent self, Scene scene, long accountId, - long gateRouteId) + public static async FTask Online(this PlayerManageComponent self, long accountId, long gateRouteId) { Log.Debug("检查账号是否在缓存中"); if (!self.TryGet(accountId, out var account)) { // 首先要先到数据库中查询是否有这个账号 - account = await PlayerHelper.LoadDataBase(scene, accountId); + account = await PlayerHelper.LoadDataBase(self.Scene, accountId); // 如果有的话,就直接加入在缓存中就可以了 if (account == null) { Log.Debug("检查到账号没有在数据库中,需要创建一个新的账号并且保存到数据库中"); // 如果没有,就要创建一个新的并且保存到数据库。 // 如果不存在,表示这是一个新的账号,需要创建一下这个账号。 - account = PlayerFactory.Create(scene, accountId); + account = PlayerFactory.Create(self.Scene, accountId); account.Level = 99; @@ -111,6 +109,19 @@ public static class PlayerManageComponentSystem return account; } + public static async FTask Offline(this PlayerManageComponent self, long accountId, long sessionId) + { + if (self.TryGet(accountId, out var account)) + { + if (account.SessionRunTimeId == sessionId) + { + //退出的是当前的 + await account.Save(); + self.Remove(accountId); + } + } + } + #endregion #region 获取&移除 diff --git a/Hotfix/Gate/Handler/Outer/C2G_EnterRoomRequestHandler.cs b/Hotfix/Gate/Handler/Outer/C2G_EnterRoomRequestHandler.cs new file mode 100644 index 0000000..bd56c76 --- /dev/null +++ b/Hotfix/Gate/Handler/Outer/C2G_EnterRoomRequestHandler.cs @@ -0,0 +1,63 @@ +using Fantasy; +using Fantasy.Async; +using Fantasy.Network; +using Fantasy.Network.Interface; +using Fantasy.Platform.Net; +using NB.Common; +using NB.Map; + +namespace NB.Gate.Handler; + +public class C2G_EnterRoomRequestHandler : MessageRPC +{ + protected override async FTask Run(Session session, C2G_EnterRoomRequest request, G2C_EnterRoomResponse response, + Action reply) + { + if (string.IsNullOrEmpty(request.RoomCode)) + { + response.ErrorCode = ErrorCode.MapRoomIdError; + return; + } + + var gateUnitSessionComponent = session.GetComponent(); + if (gateUnitSessionComponent == null) + { + response.ErrorCode = ErrorCode.ErrServer; + return; + } + + // 在缓存中检查该账号是否存在 + var gateUnitManageComponent = session.Scene.GetComponent(); + if (gateUnitManageComponent == null) + { + response.ErrorCode = ErrorCode.ErrServer; + return; + } + + var gateUnit = gateUnitManageComponent.Get(gateUnitSessionComponent.AccountID); + if (gateUnit == null) + { + response.ErrorCode = ErrorCode.ErrServer; + return; + } + + RoomHelper.ParseCode(request.RoomCode, out var serviceId, out var roomId); + if (serviceId < 1 || roomId < 1) + { + response.ErrorCode = ErrorCode.MapRoomIdError; + return; + } + + var sceneConfig = SceneConfigData.Instance.Get(serviceId); + if (sceneConfig == null) + { + response.ErrorCode = ErrorCode.MapRoomIdError; + return; + } + + //先判断是否需要更好地图服务器 + var mapRouteId = gateUnit.GetAddress(RouteType.MapRoute); + + //执行进入房间操作 + } +} \ No newline at end of file diff --git a/Hotfix/Gate/Handler/Outer/C2G_LoginRequestHandler.cs b/Hotfix/Gate/Handler/Outer/C2G_LoginRequestHandler.cs index d18b09f..7e77b22 100644 --- a/Hotfix/Gate/Handler/Outer/C2G_LoginRequestHandler.cs +++ b/Hotfix/Gate/Handler/Outer/C2G_LoginRequestHandler.cs @@ -5,7 +5,7 @@ using Fantasy.Network.Interface; using Fantasy.Platform.Net; using NB.Game; -namespace NB.Gate.Handler; +namespace NB.Gate; public sealed class C2G_LoginRequestHandler : MessageRPC { diff --git a/Hotfix/Gate/System/GateUnitSystem.cs b/Hotfix/Gate/System/GateUnitSystem.cs index b9d6757..6bbcc1e 100644 --- a/Hotfix/Gate/System/GateUnitSystem.cs +++ b/Hotfix/Gate/System/GateUnitSystem.cs @@ -21,7 +21,7 @@ public static class GateUnitSystem { #region Address - private static void RemoveAddress(this GateUnit self, int routType, long routeId) + public static void RemoveAddress(this GateUnit self, int routType, long routeId) { if (self.SceneRoutes.TryGetValue(routType, out var route)) { @@ -32,12 +32,12 @@ public static class GateUnitSystem } } - private static void AddAddress(this GateUnit self, int routType, long routeId) + public static void AddAddress(this GateUnit self, int routType, long routeId) { self.SceneRoutes[routType] = routeId; } - private static long GetAddress(this GateUnit self, int routType) + public static long GetAddress(this GateUnit self, int routType) { return self.SceneRoutes.GetValueOrDefault(routType, 0); } @@ -69,10 +69,10 @@ public static class GateUnitSystem { routeComponent = session.AddComponent(); } - - var gameSceneConfig = SceneConfigHelper.GetConfig(routeType); + + var gameSceneConfig = SceneConfigHelper.GetConfigByRouteType(routeType); var gameRouteId = gameSceneConfig.RouteId; - //连接到游戏中心服 + var gameResponse = (G2Common_EnterResponse)await self.Scene.NetworkMessagingComponent.CallInnerRoute( gameRouteId, new G2Common_EnterRequest() { @@ -85,8 +85,8 @@ public static class GateUnitSystem return gameResponse.ErrorCode; } - routeComponent.AddAddress(routeType, gameRouteId); - self.AddAddress(routeType, gameRouteId); + routeComponent.AddAddress(routeType, gameResponse.UnitRouteId); + self.AddAddress(routeType, gameResponse.UnitRouteId); return ErrorCode.Successful; } diff --git a/Hotfix/Hotfix.csproj b/Hotfix/Hotfix.csproj index 34e133c..8ccc1aa 100644 --- a/Hotfix/Hotfix.csproj +++ b/Hotfix/Hotfix.csproj @@ -13,10 +13,8 @@ + - - - diff --git a/Hotfix/Map/Handler/C2Map_CreateRoomRequestHandler.cs b/Hotfix/Map/Handler/C2Map_CreateRoomRequestHandler.cs index 6295c17..3d60f11 100644 --- a/Hotfix/Map/Handler/C2Map_CreateRoomRequestHandler.cs +++ b/Hotfix/Map/Handler/C2Map_CreateRoomRequestHandler.cs @@ -1,15 +1,44 @@ -// using Fantasy; -// using Fantasy.Async; -// using Fantasy.Network.Interface; -// -// namespace NB.Map; -// -// public class C2Map_CreateRoomRequestHandler : RouteRPC -// { -// protected override async FTask Run(Scene entity, C2Map_CreateRoomRequest request, Map2C_CreateRoomResponse response, -// Action reply) -// { -// Log.Info($"创建房间=== map:{request.MapId} pass:{request.Password}"); -// await FTask.CompletedTask; -// } -// } \ No newline at end of file +using Fantasy; +using Fantasy.Async; +using Fantasy.Entitas; +using Fantasy.Network.Interface; + +namespace NB.Map; + +public class C2Map_CreateRoomRequestHandler : RouteRPC +{ + protected override async FTask Run(MapUnit entity, C2Map_CreateRoomRequest request, + Map2C_CreateRoomResponse response, + Action reply) + { + if (entity.MapId != request.MapId) + { + response.ErrorCode = ErrorCode.MapCreateRoomNotEnter; + return; + } + + var roomManageComponent = entity.Scene.GetComponent(); + if (roomManageComponent == null) + { + response.ErrorCode = ErrorCode.ErrServer; + return; + } + + var roomId = roomManageComponent.AllocateId(); + if (roomId < 1) + { + response.ErrorCode = ErrorCode.MapCreateRoomMax; + return; + } + + // roomManageComponent.on + var room = Entity.Create(entity.Scene, true, true); + room.Owner = entity.Id; + room.RoomId = roomId; + room.Code = RoomHelper.GenerateCode(entity.Scene.SceneConfigId, roomId); + roomManageComponent.Add(room); + Log.Info( + $"创建房间=== sId={entity.Scene.SceneConfigId} map:{request.MapId} id={room.RoomId} code={room.Code}"); + await FTask.CompletedTask; + } +} \ No newline at end of file diff --git a/Hotfix/Map/Handler/C2Map_EnterMapRequestHandler.cs b/Hotfix/Map/Handler/C2Map_EnterMapRequestHandler.cs new file mode 100644 index 0000000..ba49003 --- /dev/null +++ b/Hotfix/Map/Handler/C2Map_EnterMapRequestHandler.cs @@ -0,0 +1,33 @@ +using Fantasy; +using Fantasy.Async; +using Fantasy.Network.Interface; + +namespace NB.Map; + +public class C2Map_EnterMapRequestHandler : RouteRPC +{ + protected override async FTask Run(MapUnit entity, C2Map_EnterMapRequest request, Map2C_EnterMapResponse response, + Action reply) + { + var roomManageComponent = entity.Scene.GetComponent(); + if (roomManageComponent == null) + { + response.ErrorCode = ErrorCode.ErrServer; + return; + } + + // if (entity.RoomId > 0) + // { + // response.ErrorCode = ErrorCode.MapRoomHave; + // return; + // } + // + // roomManageComponent.Enter(entity, request.RoomId); + + Log.Info($"进入地图=== map:{request.MapId}"); + entity.MapId = request.MapId; + response.MapId = request.MapId; + + await FTask.CompletedTask; + } +} \ No newline at end of file diff --git a/Hotfix/Map/Handler/Inner/G2Map_EnterRequestHandler.cs b/Hotfix/Map/Handler/Inner/G2Map_EnterRequestHandler.cs new file mode 100644 index 0000000..eeb03a6 --- /dev/null +++ b/Hotfix/Map/Handler/Inner/G2Map_EnterRequestHandler.cs @@ -0,0 +1,27 @@ +using Fantasy; +using Fantasy.Async; +using Fantasy.Network.Interface; + +namespace NB.Map.Inner; + +public class G2Map_EnterRequestHandler : RouteRPC +{ + protected override async FTask Run(Scene entity, G2Map_EnterRoomRequest request, Map2G_EnterRoomResponse response, + Action reply) + { + var roomManageComponent = entity.GetComponent(); + if (roomManageComponent == null) + { + response.ErrorCode = ErrorCode.ErrServer; + return; + } + + RoomHelper.ParseCode(request.RoomCode, out var serviceId, out var roomId); + if (serviceId < 1 || roomId < 1) + { + response.ErrorCode = ErrorCode.MapRoomIdError; + return; + } + // roomManageComponent.Enter(); + } +} \ No newline at end of file diff --git a/Hotfix/Map/Helper/MapUnitFactory.cs b/Hotfix/Map/Helper/MapUnitFactory.cs new file mode 100644 index 0000000..7d7f980 --- /dev/null +++ b/Hotfix/Map/Helper/MapUnitFactory.cs @@ -0,0 +1,19 @@ +using Fantasy; +using Fantasy.Entitas; + +namespace NB.Map; + +public static class MapUnitFactory +{ + /// + /// 创建一个新的Player + /// + /// + /// ToKen令牌传递过来的aId + /// + public static MapUnit Create(Scene scene, long aId) + { + var player = Entity.Create(scene, aId, true, true); + return player; + } +} \ No newline at end of file diff --git a/Hotfix/Map/Helper/RoomHelper.cs b/Hotfix/Map/Helper/RoomHelper.cs new file mode 100644 index 0000000..cf6f85b --- /dev/null +++ b/Hotfix/Map/Helper/RoomHelper.cs @@ -0,0 +1,69 @@ +using System.Text; + +namespace NB.Map; + +public static class RoomHelper +{ + #region 房间id + + private const string Base36Chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + private const int RoomSeqBits = 16; // 每个服务最多 65535 个房间 + + /// + /// 生成房间码(固定5位) + /// + /// + /// + /// + public static string GenerateCode(uint serviceId, int roomSeq) + { + long packed = ((long)serviceId << RoomSeqBits) | (uint)roomSeq; + string code = EncodeBase36(packed); + + // 固定5位,不够左侧补0 + return code.PadLeft(5, '0'); + } + + /// + /// 解析房间码 + /// + /// + /// + /// + public static void ParseCode(string code, out uint serviceId, out int roomSeq) + { + long packed = DecodeBase36(code); + roomSeq = (int)(packed & ((1 << RoomSeqBits) - 1)); + serviceId = (uint)(packed >> RoomSeqBits); + } + + private static string EncodeBase36(long value) + { + if (value == 0) return "0"; + StringBuilder sb = new StringBuilder(); + while (value > 0) + { + int remainder = (int)(value % 36); + sb.Insert(0, Base36Chars[remainder]); + value /= 36; + } + + return sb.ToString(); + } + + private static long DecodeBase36(string str) + { + long result = 0; + foreach (char c in str) + { + int val = Base36Chars.IndexOf(c); + if (val < 0) throw new ArgumentException("Invalid Base36 character: " + c); + result = result * 36 + val; + } + + return result; + } + + #endregion + +} \ No newline at end of file diff --git a/Hotfix/Map/System/MapRoomSystem.cs b/Hotfix/Map/System/MapRoomSystem.cs new file mode 100644 index 0000000..2b4cdfb --- /dev/null +++ b/Hotfix/Map/System/MapRoomSystem.cs @@ -0,0 +1,19 @@ +using Fantasy.Entitas.Interface; + +namespace NB.Map; + +public class MapRoomDestroySystem : DestroySystem +{ + protected override void Destroy(MapRoom self) + { + self.Map = 0; + self.Password = string.Empty; + self.CreateTime = 0; + self.Owner = 0; + self.Units.Clear(); + } +} + +public static class MapRoomSystem +{ +} \ No newline at end of file diff --git a/Hotfix/Map/System/MapUnitManageComponentSystem.cs b/Hotfix/Map/System/MapUnitManageComponentSystem.cs new file mode 100644 index 0000000..72af0a0 --- /dev/null +++ b/Hotfix/Map/System/MapUnitManageComponentSystem.cs @@ -0,0 +1,84 @@ +using Fantasy; +using Fantasy.Async; + +namespace NB.Map; + +public static class MapUnitManageComponentSystem +{ + #region 上线下线 + + /// + /// 玩家上线 + /// + /// + /// + /// + /// + public static async FTask Online(this MapUnitManageComponent self, Scene scene, + long accountId, + long gateRouteId) + { + if (!self.TryGet(accountId, out var unit)) + { + unit = MapUnitFactory.Create(scene, accountId); + self.Add(unit); + } + + if (unit != null) + { + unit.GateRouteId = gateRouteId; + } + + await FTask.CompletedTask; + return unit; + } + + public static async FTask Offline(this MapUnitManageComponent self, Scene scene, long accountId, long gateRouteId) + { + if (self.TryGet(accountId, out var unit) && unit != null) + { + if (unit.GateRouteId == gateRouteId) + { + self.Remove(accountId); //如果当前网关和下线的网关一致 + } + } + + await FTask.CompletedTask; + } + + #endregion + + #region 获取&移除 + + public static void Add(this MapUnitManageComponent self, MapUnit unit) + { + self.Units.Add(unit.Id, unit); + } + + public static MapUnit? Get(this MapUnitManageComponent self, long accountId) + { + return self.Units.GetValueOrDefault(accountId); + } + + public static bool TryGet(this MapUnitManageComponent self, long accountId, out MapUnit? unit) + { + return self.Units.TryGetValue(accountId, out unit); + } + + public static void Remove(this MapUnitManageComponent self, long accountId, bool isDispose = true) + { + if (!self.Units.Remove(accountId, out var account)) + { + return; + } + + if (!isDispose) + { + return; + } + + account.Dispose(); + } + + #endregion +} \ No newline at end of file diff --git a/Hotfix/Map/System/RoomManageComponentSystem.cs b/Hotfix/Map/System/RoomManageComponentSystem.cs new file mode 100644 index 0000000..d759524 --- /dev/null +++ b/Hotfix/Map/System/RoomManageComponentSystem.cs @@ -0,0 +1,93 @@ +using Fantasy.Entitas; +using Fantasy.Entitas.Interface; + +namespace NB.Map; + +public class RoomManageComponentAwakeSystem : AwakeSystem +{ + protected override void Awake(RoomManageComponent self) + { + for (int i = 1; i <= 65535; i++) + { + self.FreeIds.Enqueue(i, i); + } + } +} + +public class RoomManageComponentDestroySystem : DestroySystem +{ + protected override void Destroy(RoomManageComponent self) + { + foreach (var (_, room) in self.Rooms) + { + room.Dispose(); + } + + self.Rooms.Clear(); + } +} + +public static class RoomManageComponentSystem +{ + #region 增删 + + public static void Add(this RoomManageComponent self, MapRoom room) + { + self.Rooms[room.RoomId] = room; + } + + public static bool Remove(this RoomManageComponent self, int roomId) + { + if (self.Rooms.TryGetValue(roomId, out var room)) + { + self.ReleaseId(room.RoomId); + room.Dispose(); + } + + return true; + } + + #endregion + + #region 房间Id + + /// + /// 分配一个新的房间ID + /// + /// + /// + public static int AllocateId(this RoomManageComponent self) + { + if (self.FreeIds.Count == 0) return 0; + int id = self.FreeIds.Dequeue(); + self.InUseID.Add(id); + return id; + } + + /// + /// 释放房间ID + /// + /// + /// + public static void ReleaseId(this RoomManageComponent self, int id) + { + if (self.InUseID.Remove(id)) + { + self.FreeIds.Enqueue(id, id); + } + } + + #endregion + + #region 进入退出 + + public static void Enter(this RoomManageComponent self, MapUnit unit, long roomId) + { + } + + public static void Exit(this RoomManageComponent self, MapUnit unit) + { + } + + #endregion +} \ No newline at end of file diff --git a/Hotfix/OnCreateSceneEvent.cs b/Hotfix/OnCreateSceneEvent.cs index 7322027..82d262e 100644 --- a/Hotfix/OnCreateSceneEvent.cs +++ b/Hotfix/OnCreateSceneEvent.cs @@ -6,6 +6,7 @@ using Fantasy.Event; using Fantasy.Helper; using Fantasy.Serialize; using NB.Game; +using NB.Map; using ProtoBuf; namespace NB; @@ -66,6 +67,14 @@ public sealed class OnCreateSceneEvent : AsyncEventSystem case SceneType.Map: { Log.Debug($"Map Scene SceneRuntimeId:{scene.RuntimeId}"); + // uint serverId = 25255; + // for (int i = 1; i < 65535; i++) + // { + // var roomId = RoomHelper.GenerateCode(serverId, i); + // RoomHelper.ParseCode(roomId, out var pId, out var rId); + // Log.Info($"生成id测试,房间id={roomId} 原始服务id:{serverId} 原始房间id={i} 解析={pId} {rId}"); + // } + break; } case SceneType.Social: @@ -74,7 +83,6 @@ public sealed class OnCreateSceneEvent : AsyncEventSystem } case SceneType.Game: { - // // Begins transaction // using (var session = mongoClient.StartSession()) // { @@ -131,8 +139,8 @@ public sealed class OnCreateSceneEvent : AsyncEventSystem // // stopwatch.Stop(); // Log.Info($"创建100个号入库耗时={stopwatch.ElapsedMilliseconds}ms"); - - + + break; } case SceneType.Gate: diff --git a/Hotfix/OnSceneCreate_Init.cs b/Hotfix/OnSceneCreate_Init.cs index 4206cff..25f9913 100644 --- a/Hotfix/OnSceneCreate_Init.cs +++ b/Hotfix/OnSceneCreate_Init.cs @@ -5,6 +5,7 @@ using NB.Authentication; using NB.Chat; using NB.Game; using NB.Gate; +using NB.Map; namespace NB; @@ -50,6 +51,9 @@ public class OnSceneCreate_Init : AsyncEventSystem case SceneType.Map: { Log.Info("创建地图场景==="); + scene.AddComponent(); + scene.AddComponent(); + scene.AddComponent(); break; } } diff --git a/Main/Properties/launchSettings.json b/Main/Properties/launchSettings.json index cd8b993..b30e999 100644 --- a/Main/Properties/launchSettings.json +++ b/Main/Properties/launchSettings.json @@ -7,4 +7,4 @@ "commandLineArgs": "--m Develop" } } -} +} \ No newline at end of file diff --git a/Server.sln.DotSettings.user b/Server.sln.DotSettings.user index b23042f..3d97d67 100644 --- a/Server.sln.DotSettings.user +++ b/Server.sln.DotSettings.user @@ -16,6 +16,7 @@ ForceIncluded ForceIncluded ForceIncluded + ForceIncluded ForceIncluded ForceIncluded ForceIncluded @@ -55,6 +56,7 @@ ForceIncluded ForceIncluded ForceIncluded + ForceIncluded ForceIncluded ForceIncluded ForceIncluded @@ -66,6 +68,7 @@ ForceIncluded ForceIncluded ForceIncluded + ForceIncluded ForceIncluded ForceIncluded ForceIncluded