diff --git a/Entity/Entity.csproj b/Entity/Entity.csproj index 3641447..1155bae 100644 --- a/Entity/Entity.csproj +++ b/Entity/Entity.csproj @@ -18,4 +18,8 @@ + + + + \ No newline at end of file diff --git a/Entity/Fantasy.config b/Entity/Fantasy.config index b50d8ab..14f6c58 100644 --- a/Entity/Fantasy.config +++ b/Entity/Fantasy.config @@ -65,13 +65,13 @@ networkProtocol="" outerPort="0" innerPort="11051" /> - + + + + + + + \ No newline at end of file diff --git a/Entity/Game/Item/Item.cs b/Entity/Game/Item/Item.cs index d70a420..9b371cb 100644 --- a/Entity/Game/Item/Item.cs +++ b/Entity/Game/Item/Item.cs @@ -8,7 +8,15 @@ public enum ItemBasicType None, Currency = 1, Item = 2, - Fish = 3, + Rod = 3, + Reel =4, + Bobber = 5, + Line = 6, + Bait = 7, + Lure = 8, + Hook = 9, + Weight = 10, + Feeder = 11, } public class Item : Entity @@ -47,4 +55,9 @@ public class Item : Entity /// 物品所属的容器 /// [BsonIgnore] PlayerItemContainerComponent Container; + + /// + /// 正则使用中 + /// + [BsonIgnore] public bool InUse; } \ No newline at end of file diff --git a/Entity/Map/Component/MapManageComponent.cs b/Entity/Game/Map/Component/MapManageComponent.cs similarity index 59% rename from Entity/Map/Component/MapManageComponent.cs rename to Entity/Game/Map/Component/MapManageComponent.cs index 0af5b52..3b3cdd7 100644 --- a/Entity/Map/Component/MapManageComponent.cs +++ b/Entity/Game/Map/Component/MapManageComponent.cs @@ -1,8 +1,8 @@ using Fantasy.Entitas; -namespace NB.Map; +namespace NB.Game; -public class MapManageComponent: Entity +public class MapManageComponent : Entity { public readonly Dictionary Maps = new(); } \ No newline at end of file diff --git a/Entity/Map/Component/RoomManageComponent.cs b/Entity/Game/Map/Component/RoomManageComponent.cs similarity index 82% rename from Entity/Map/Component/RoomManageComponent.cs rename to Entity/Game/Map/Component/RoomManageComponent.cs index 4d193a5..b20f77f 100644 --- a/Entity/Map/Component/RoomManageComponent.cs +++ b/Entity/Game/Map/Component/RoomManageComponent.cs @@ -1,6 +1,6 @@ using Fantasy.Entitas; -namespace NB.Map; +namespace NB.Game; public class RoomManageComponent : Entity { @@ -8,6 +8,4 @@ public class RoomManageComponent : Entity public readonly PriorityQueue FreeIds = new(); public readonly HashSet InUseID = new(); - - public string TestRoomCode; } \ No newline at end of file diff --git a/Entity/Map/Entity/Map.cs b/Entity/Game/Map/Entity/Map.cs similarity index 67% rename from Entity/Map/Entity/Map.cs rename to Entity/Game/Map/Entity/Map.cs index 3bbc832..e10ed70 100644 --- a/Entity/Map/Entity/Map.cs +++ b/Entity/Game/Map/Entity/Map.cs @@ -1,6 +1,6 @@ using Fantasy.Entitas; -namespace NB.Map; +namespace NB.Game; public class Map : Entity { @@ -12,5 +12,5 @@ public class Map : Entity /// /// 地图玩家 /// - public Dictionary Units = new Dictionary(); + public Dictionary Units = new Dictionary(); } \ No newline at end of file diff --git a/Entity/Map/Entity/MapRoom.cs b/Entity/Game/Map/Entity/MapRoom.cs similarity index 86% rename from Entity/Map/Entity/MapRoom.cs rename to Entity/Game/Map/Entity/MapRoom.cs index adaf556..88e2b0b 100644 --- a/Entity/Map/Entity/MapRoom.cs +++ b/Entity/Game/Map/Entity/MapRoom.cs @@ -1,7 +1,6 @@ using Fantasy.Entitas; -using NB.Map; -namespace NB.Map; +namespace NB.Game; /// /// 地图房间 @@ -26,7 +25,7 @@ public class MapRoom : Entity /// /// 房间玩家 /// - public Dictionary Units = new Dictionary(); + public Dictionary Units = new Dictionary(); /// /// 房主 diff --git a/Entity/Map/Entity/MapUnit.cs b/Entity/Game/Map/Entity/MapUnitComponent.cs similarity index 60% rename from Entity/Map/Entity/MapUnit.cs rename to Entity/Game/Map/Entity/MapUnitComponent.cs index a453728..a8261ae 100644 --- a/Entity/Map/Entity/MapUnit.cs +++ b/Entity/Game/Map/Entity/MapUnitComponent.cs @@ -1,19 +1,13 @@ -using Fantasy; -using Fantasy.Entitas; +using Fantasy.Entitas; using Unity.Mathematics; -namespace NB.Map; +namespace NB.Game; /// -/// 地图玩家单元 +/// /// -public class MapUnit : Entity +public class MapUnitComponent : Entity { - /// - /// 角色基础信息 - /// - public RoleSimpleInfo Info; - /// /// 位置 /// @@ -24,20 +18,18 @@ public class MapUnit : Entity /// public float3 Rotation; - /// - /// 当前所在地图id - /// - public int MapId; - - /// - /// 当前所在的房间id - /// - public int RoomId; - - public long GateRouteId; - /// /// 钓组信息 /// public List Gears = new List(); + + /// + /// 房间Id + /// + public int RoomId; + + /// + /// 地图id + /// + public int MapId; } \ No newline at end of file diff --git a/Entity/Map/Entity/MapUnitGear.cs b/Entity/Game/Map/Entity/MapUnitGear.cs similarity index 93% rename from Entity/Map/Entity/MapUnitGear.cs rename to Entity/Game/Map/Entity/MapUnitGear.cs index 56f85e6..bcf7bfd 100644 --- a/Entity/Map/Entity/MapUnitGear.cs +++ b/Entity/Game/Map/Entity/MapUnitGear.cs @@ -1,7 +1,7 @@ using Fantasy.Entitas; using Unity.Mathematics; -namespace NB.Map; +namespace NB.Game; public enum MapGearState { @@ -18,7 +18,7 @@ public class MapUnitGear : Entity /// /// 杆子 /// - public long Rod; + public long Item; /// /// 杆子配件 diff --git a/Entity/Game/Player/Player.cs b/Entity/Game/Player/Player.cs index bd2dbd6..483bea1 100644 --- a/Entity/Game/Player/Player.cs +++ b/Entity/Game/Player/Player.cs @@ -63,4 +63,5 @@ public sealed class Player : Entity [BsonIgnore] public long SessionRunTimeId; + } \ No newline at end of file diff --git a/Entity/Generate/NetworkProtocol/GameMessage.cs b/Entity/Generate/NetworkProtocol/GameMessage.cs index 9bf8583..275d181 100644 --- a/Entity/Generate/NetworkProtocol/GameMessage.cs +++ b/Entity/Generate/NetworkProtocol/GameMessage.cs @@ -85,6 +85,7 @@ namespace Fantasy } public override void Dispose() { + ItemId = default; #if FANTASY_NET || FANTASY_UNITY GetScene().MessagePoolComponent.Return(this); #endif @@ -94,6 +95,8 @@ namespace Fantasy public uint OpCode() { return OuterOpcode.C2Game_UseItemRequest; } [ProtoIgnore] public int RouteType => Fantasy.RouteType.GameRoute; + [ProtoMember(1)] + public long ItemId { get; set; } } /// /// 请求使用物品响应 @@ -509,5 +512,57 @@ namespace Fantasy [ProtoMember(1)] public List Awards = new List(); } + /// + /// /////////// ******** GM *******///////////// + /// + /// + /// 请求执行GM + /// + [ProtoContract] + public partial class C2Game_GMRequest : AMessage, ICustomRouteRequest + { + public static C2Game_GMRequest Create(Scene scene) + { + return scene.MessagePoolComponent.Rent(); + } + public override void Dispose() + { + Cmd = default; + Args = default; +#if FANTASY_NET || FANTASY_UNITY + GetScene().MessagePoolComponent.Return(this); +#endif + } + [ProtoIgnore] + public Game2C_GMResponse ResponseType { get; set; } + public uint OpCode() { return OuterOpcode.C2Game_GMRequest; } + [ProtoIgnore] + public int RouteType => Fantasy.RouteType.GameRoute; + [ProtoMember(1)] + public string Cmd { get; set; } + [ProtoMember(2)] + public string Args { get; set; } + } + /// + /// 执行GM返回 + /// + [ProtoContract] + public partial class Game2C_GMResponse : AMessage, ICustomRouteResponse + { + public static Game2C_GMResponse Create(Scene scene) + { + return scene.MessagePoolComponent.Rent(); + } + public override void Dispose() + { + ErrorCode = default; +#if FANTASY_NET || FANTASY_UNITY + GetScene().MessagePoolComponent.Return(this); +#endif + } + public uint OpCode() { return OuterOpcode.Game2C_GMResponse; } + [ProtoMember(1)] + public uint ErrorCode { get; set; } + } } diff --git a/Entity/Generate/NetworkProtocol/MapMessage.cs b/Entity/Generate/NetworkProtocol/MapMessage.cs index f36fb38..738256b 100644 --- a/Entity/Generate/NetworkProtocol/MapMessage.cs +++ b/Entity/Generate/NetworkProtocol/MapMessage.cs @@ -39,7 +39,7 @@ namespace Fantasy public Map2C_CreateRoomResponse ResponseType { get; set; } public uint OpCode() { return OuterOpcode.C2Map_CreateRoomRequest; } [ProtoIgnore] - public int RouteType => Fantasy.RouteType.MapRoute; + public int RouteType => Fantasy.RouteType.GameRoute; [ProtoMember(1)] public int MapId { get; set; } } @@ -193,7 +193,7 @@ namespace Fantasy } public uint OpCode() { return OuterOpcode.Map2C_ChangeMap; } [ProtoIgnore] - public int RouteType => Fantasy.RouteType.MapRoute; + public int RouteType => Fantasy.RouteType.GameRoute; [ProtoMember(1)] public int MapId { get; set; } [ProtoMember(2)] diff --git a/Entity/Generate/NetworkProtocol/MapProtoData.cs b/Entity/Generate/NetworkProtocol/MapProtoData.cs index 2578965..d3d5c33 100644 --- a/Entity/Generate/NetworkProtocol/MapProtoData.cs +++ b/Entity/Generate/NetworkProtocol/MapProtoData.cs @@ -99,25 +99,31 @@ namespace Fantasy } public override void Dispose() { - Rod = default; - Rigs.Clear(); + Item = default; + Binds.Clear(); Position = default; Rotation = default; Propertys.Clear(); + InUse = default; + InHand = default; #if FANTASY_NET || FANTASY_UNITY GetScene().MessagePoolComponent.Return(this); #endif } [ProtoMember(1)] - public long Rod { get; set; } + public ItemInfo Item { get; set; } [ProtoMember(2)] - public List Rigs = new List(); + public List Binds = new List(); [ProtoMember(3)] public Vector3Info Position { get; set; } [ProtoMember(4)] public Vector3Info Rotation { get; set; } [ProtoMember(5)] public List Propertys = new List(); + [ProtoMember(6)] + public bool InUse { get; set; } + [ProtoMember(7)] + public bool InHand { get; set; } } [ProtoContract] public partial class UnitStateInfo : AMessage diff --git a/Entity/Generate/NetworkProtocol/OuterOpcode.cs b/Entity/Generate/NetworkProtocol/OuterOpcode.cs index e4d8a73..b4451ba 100644 --- a/Entity/Generate/NetworkProtocol/OuterOpcode.cs +++ b/Entity/Generate/NetworkProtocol/OuterOpcode.cs @@ -21,8 +21,10 @@ namespace Fantasy public const uint C2Game_BuyRequest = 2281711384; public const uint Game2C_BuyResponse = 2415929112; public const uint Game2C_RewardNotify = 2147493651; - public const uint C2Map_CreateRoomRequest = 2281711385; - public const uint Map2C_CreateRoomResponse = 2415929113; + public const uint C2Game_GMRequest = 2281711385; + public const uint Game2C_GMResponse = 2415929113; + public const uint C2Map_CreateRoomRequest = 2281711386; + public const uint Map2C_CreateRoomResponse = 2415929114; public const uint C2G_ExitRoomRequest = 268445457; public const uint G2C_ExitRoomResponse = 402663185; public const uint C2G_EnterMapRequest = 268445458; @@ -33,10 +35,12 @@ namespace Fantasy public const uint C2G_LoginRequest = 268445460; public const uint G2C_LoginResponse = 402663188; public const uint G2C_RepeatLogin = 134227729; - public const uint C2Game_GetRoleInfoRequest = 2281711386; - public const uint Game2C_GetRoleInfoResponse = 2415929114; + public const uint C2Game_GetRoleInfoRequest = 2281711387; + public const uint Game2C_GetRoleInfoResponse = 2415929115; public const uint Map2C_RoleEnterRoomNotify = 2147493653; public const uint Map2C_RoleExitRoomNotify = 2147493654; + public const uint C2Map_TakeItemRequest = 2281711388; + public const uint Map2C_TakeItemResponse = 2415929116; public const uint C2Map_RolePropertyChange = 2147493655; public const uint Map2C_RoleStateNotify = 2147493656; public const uint Map2C_RoleGearChangeNotify = 2147493657; @@ -45,37 +49,37 @@ namespace Fantasy public const uint C2Map_Look = 2147493660; public const uint Map2C_MoveNotify = 2147493661; public const uint Map2C_LookeNotify = 2147493662; - public const uint C2S_GetConversationsRequest = 2281711387; - public const uint S2C_GetConversationsResponse = 2415929115; - public const uint C2S_SendMailRequest = 2281711388; - public const uint S2C_SendMailResponse = 2415929116; - public const uint C2S_DeleteMailRequest = 2281711389; - public const uint S2C_DeleteMailResponse = 2415929117; + public const uint C2S_GetConversationsRequest = 2281711389; + public const uint S2C_GetConversationsResponse = 2415929117; + public const uint C2S_SendMailRequest = 2281711390; + public const uint S2C_SendMailResponse = 2415929118; + public const uint C2S_DeleteMailRequest = 2281711391; + public const uint S2C_DeleteMailResponse = 2415929119; public const uint S2C_HaveMail = 2147493663; public const uint S2C_MailState = 2147493664; - public const uint C2S_CreateChannelRequest = 2281711390; - public const uint S2C_CreateChannelResponse = 2415929118; - public const uint C2S_JoinChannelRequest = 2281711391; - public const uint S2C_JoinChannelResponse = 2415929119; - public const uint C2S_SendMessageRequest = 2281711392; - public const uint S2C_SendMessageResponse = 2415929120; + public const uint C2S_CreateChannelRequest = 2281711392; + public const uint S2C_CreateChannelResponse = 2415929120; + public const uint C2S_JoinChannelRequest = 2281711393; + public const uint S2C_JoinChannelResponse = 2415929121; + public const uint C2S_SendMessageRequest = 2281711394; + public const uint S2C_SendMessageResponse = 2415929122; public const uint S2C_Message = 2147493665; - public const uint C2S_CreateClubRequest = 2281711393; - public const uint S2C_CreateClubResponse = 2415929121; - public const uint C2S_GetClubInfoRequest = 2281711394; - public const uint S2C_GetClubInfoResponse = 2415929122; - public const uint C2S_GetMemberListRequest = 2281711395; - public const uint S2C_GetMemberListResponse = 2415929123; - public const uint C2S_GetClubListRequest = 2281711396; - public const uint S2C_GetClubListResponse = 2415929124; - public const uint C2S_JoinClubRequest = 2281711397; - public const uint S2C_JoinClubResponse = 2415929125; - public const uint C2S_LeaveClubRequest = 2281711398; - public const uint S2C_LeaveClubResponse = 2415929126; - public const uint C2S_DissolveClubRequest = 2281711399; - public const uint S2C_DissolveClubResponse = 2415929127; - public const uint C2S_DisposeJoinRequest = 2281711400; - public const uint S2C_DisposeJoinResponse = 2415929128; + public const uint C2S_CreateClubRequest = 2281711395; + public const uint S2C_CreateClubResponse = 2415929123; + public const uint C2S_GetClubInfoRequest = 2281711396; + public const uint S2C_GetClubInfoResponse = 2415929124; + public const uint C2S_GetMemberListRequest = 2281711397; + public const uint S2C_GetMemberListResponse = 2415929125; + public const uint C2S_GetClubListRequest = 2281711398; + public const uint S2C_GetClubListResponse = 2415929126; + public const uint C2S_JoinClubRequest = 2281711399; + public const uint S2C_JoinClubResponse = 2415929127; + public const uint C2S_LeaveClubRequest = 2281711400; + public const uint S2C_LeaveClubResponse = 2415929128; + public const uint C2S_DissolveClubRequest = 2281711401; + public const uint S2C_DissolveClubResponse = 2415929129; + public const uint C2S_DisposeJoinRequest = 2281711402; + public const uint S2C_DisposeJoinResponse = 2415929130; public const uint S2C_ClubChange = 2147493666; } } diff --git a/Entity/Generate/NetworkProtocol/RoomMessage.cs b/Entity/Generate/NetworkProtocol/RoomMessage.cs index 41c37e0..15ab853 100644 --- a/Entity/Generate/NetworkProtocol/RoomMessage.cs +++ b/Entity/Generate/NetworkProtocol/RoomMessage.cs @@ -37,7 +37,7 @@ namespace Fantasy } public uint OpCode() { return OuterOpcode.Map2C_RoleEnterRoomNotify; } [ProtoIgnore] - public int RouteType => Fantasy.RouteType.MapRoute; + public int RouteType => Fantasy.RouteType.GameRoute; [ProtoMember(1)] public MapUnitInfo Info { get; set; } } @@ -60,10 +60,65 @@ namespace Fantasy } public uint OpCode() { return OuterOpcode.Map2C_RoleExitRoomNotify; } [ProtoIgnore] - public int RouteType => Fantasy.RouteType.MapRoute; + public int RouteType => Fantasy.RouteType.GameRoute; [ProtoMember(1)] public long Id { get; set; } } + /// + /// 请求拿起物品 + /// + [ProtoContract] + public partial class C2Map_TakeItemRequest : AMessage, ICustomRouteRequest + { + public static C2Map_TakeItemRequest Create(Scene scene) + { + return scene.MessagePoolComponent.Rent(); + } + public override void Dispose() + { + Id = default; + Task = default; +#if FANTASY_NET || FANTASY_UNITY + GetScene().MessagePoolComponent.Return(this); +#endif + } + [ProtoIgnore] + public Map2C_TakeItemResponse ResponseType { get; set; } + public uint OpCode() { return OuterOpcode.C2Map_TakeItemRequest; } + [ProtoIgnore] + public int RouteType => Fantasy.RouteType.GameRoute; + [ProtoMember(1)] + public int Id { get; set; } + [ProtoMember(2)] + public bool Task { get; set; } + } + /// + /// 请求拿起物品响应 + /// + [ProtoContract] + public partial class Map2C_TakeItemResponse : AMessage, ICustomRouteResponse + { + public static Map2C_TakeItemResponse Create(Scene scene) + { + return scene.MessagePoolComponent.Rent(); + } + public override void Dispose() + { + ErrorCode = default; + Id = default; + Task = default; +#if FANTASY_NET || FANTASY_UNITY + GetScene().MessagePoolComponent.Return(this); +#endif + } + public uint OpCode() { return OuterOpcode.Map2C_TakeItemResponse; } + [ProtoMember(1)] + public int Id { get; set; } + [ProtoMember(2)] + public bool Task { get; set; } + [ProtoMember(3)] + public uint ErrorCode { get; set; } + } [ProtoContract] public partial class C2Map_RolePropertyChange : AMessage, ICustomRouteMessage { @@ -80,7 +135,7 @@ namespace Fantasy } public uint OpCode() { return OuterOpcode.C2Map_RolePropertyChange; } [ProtoIgnore] - public int RouteType => Fantasy.RouteType.MapRoute; + public int RouteType => Fantasy.RouteType.GameRoute; [ProtoMember(1)] public List Propertys = new List(); } @@ -104,7 +159,7 @@ namespace Fantasy } public uint OpCode() { return OuterOpcode.Map2C_RoleStateNotify; } [ProtoIgnore] - public int RouteType => Fantasy.RouteType.MapRoute; + public int RouteType => Fantasy.RouteType.GameRoute; [ProtoMember(1)] public long Id { get; set; } [ProtoMember(2)] @@ -130,7 +185,7 @@ namespace Fantasy } public uint OpCode() { return OuterOpcode.Map2C_RoleGearChangeNotify; } [ProtoIgnore] - public int RouteType => Fantasy.RouteType.MapRoute; + public int RouteType => Fantasy.RouteType.GameRoute; [ProtoMember(1)] public long Id { get; set; } [ProtoMember(2)] @@ -153,7 +208,7 @@ namespace Fantasy } public uint OpCode() { return OuterOpcode.Map2C_RolePropertyChangeNotify; } [ProtoIgnore] - public int RouteType => Fantasy.RouteType.MapRoute; + public int RouteType => Fantasy.RouteType.GameRoute; [ProtoMember(1)] public long Id { get; set; } [ProtoMember(2)] @@ -180,7 +235,7 @@ namespace Fantasy } public uint OpCode() { return OuterOpcode.C2Map_Move; } [ProtoIgnore] - public int RouteType => Fantasy.RouteType.MapRoute; + public int RouteType => Fantasy.RouteType.GameRoute; [ProtoMember(1)] public Vector3Info Position { get; set; } [ProtoMember(2)] @@ -211,7 +266,7 @@ namespace Fantasy } public uint OpCode() { return OuterOpcode.C2Map_Look; } [ProtoIgnore] - public int RouteType => Fantasy.RouteType.MapRoute; + public int RouteType => Fantasy.RouteType.GameRoute; [ProtoMember(1)] public Vector3Info Rotation { get; set; } [ProtoMember(2)] @@ -242,7 +297,7 @@ namespace Fantasy } public uint OpCode() { return OuterOpcode.Map2C_MoveNotify; } [ProtoIgnore] - public int RouteType => Fantasy.RouteType.MapRoute; + public int RouteType => Fantasy.RouteType.GameRoute; [ProtoMember(1)] public long Id { get; set; } [ProtoMember(2)] @@ -279,7 +334,7 @@ namespace Fantasy } public uint OpCode() { return OuterOpcode.Map2C_LookeNotify; } [ProtoIgnore] - public int RouteType => Fantasy.RouteType.MapRoute; + public int RouteType => Fantasy.RouteType.GameRoute; [ProtoMember(1)] public long Id { get; set; } [ProtoMember(2)] diff --git a/Entity/Generate/NetworkProtocol/RouteType.cs b/Entity/Generate/NetworkProtocol/RouteType.cs index 01cebe1..ec20017 100644 --- a/Entity/Generate/NetworkProtocol/RouteType.cs +++ b/Entity/Generate/NetworkProtocol/RouteType.cs @@ -6,6 +6,5 @@ namespace Fantasy public const int GateRoute = 1001; // Gate public const int SocialRoute = 1002; // Social public const int GameRoute = 1003; // Game - public const int MapRoute = 1004; // 地图 } } diff --git a/Entity/Map/Component/MapUnitManageComponent.cs b/Entity/Map/Component/MapUnitManageComponent.cs deleted file mode 100644 index 260efe6..0000000 --- a/Entity/Map/Component/MapUnitManageComponent.cs +++ /dev/null @@ -1,8 +0,0 @@ -using Fantasy.Entitas; - -namespace NB.Map; - -public class MapUnitManageComponent : Entity -{ - public readonly Dictionary Units = new(); -} \ No newline at end of file diff --git a/Hotfix/Common/Handler/G2Common_EnterRequestHandler.cs b/Hotfix/Common/Handler/G2Common_EnterRequestHandler.cs index 7aa9c4e..915d292 100644 --- a/Hotfix/Common/Handler/G2Common_EnterRequestHandler.cs +++ b/Hotfix/Common/Handler/G2Common_EnterRequestHandler.cs @@ -3,7 +3,6 @@ using Fantasy.Async; using Fantasy.Network.Interface; using NB.Chat; using NB.Game; -using NB.Map; namespace NB.Common; @@ -27,11 +26,11 @@ 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}"); - } + // private async FTask RunMap(Scene scene, G2Common_EnterRequest request, G2Common_EnterResponse response) + // { + // // 在缓存中检查该账号是否存在 + // var chatUnitManageComponent = scene.GetComponent(); + // 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 b6abef0..45259bf 100644 --- a/Hotfix/Common/Handler/G2Common_ExitRequestHandler.cs +++ b/Hotfix/Common/Handler/G2Common_ExitRequestHandler.cs @@ -3,7 +3,6 @@ using Fantasy.Async; using Fantasy.Network.Interface; using NB.Chat; using NB.Game; -using NB.Map; namespace NB.Common; @@ -25,11 +24,11 @@ public class G2Common_ExitRequestHandler : RouteRPC +{ + protected override async FTask Run(Player entity, C2Game_UseItemRequest request, Game2C_UseItemResponse response, + Action reply) + { + var itemContainer = entity.GetComponent(); + if (itemContainer == null) + { + response.ErrorCode = ErrorCode.ErrArgs; + return; + } + + if (!itemContainer.Items.TryGetValue(request.ItemId, out var item)) + { + response.ErrorCode = ErrorCode.ErrArgs; + return; + } + + var itemType = ItemHelper.GetType(item.ConfigId); + if (itemType == ItemBasicType.Rod) + { + //鱼竿 + } + } +} \ No newline at end of file diff --git a/Hotfix/Game/Item/Helper/ItemFactory.cs b/Hotfix/Game/Item/Helper/ItemFactory.cs index 09faab1..12d4209 100644 --- a/Hotfix/Game/Item/Helper/ItemFactory.cs +++ b/Hotfix/Game/Item/Helper/ItemFactory.cs @@ -1,6 +1,5 @@ using Fantasy; using Fantasy.Entitas; -using NB.Map; namespace NB.Game; diff --git a/Hotfix/Game/Item/Helper/ItemHelper.cs b/Hotfix/Game/Item/Helper/ItemHelper.cs index fc75258..721c67c 100644 --- a/Hotfix/Game/Item/Helper/ItemHelper.cs +++ b/Hotfix/Game/Item/Helper/ItemHelper.cs @@ -4,17 +4,22 @@ public static class ItemHelper { public static ItemBasicType GetType(uint id) { - var type = (int)(id / 10000); - if (type == 1) - { - return ItemBasicType.Currency; - } - - if (type == 21) - { - return ItemBasicType.Fish; - } - - return ItemBasicType.Item; + return (ItemBasicType)(id / 10000); } + + // public static ItemBasicType GetType(uint id) + // { + // var type = (int)(id / 10000); + // if (type == 1) + // { + // return ItemBasicType.Currency; + // } + // + // if (type == 21) + // { + // return ItemBasicType.Fish; + // } + // + // return ItemBasicType.Item; + // } } \ No newline at end of file diff --git a/Hotfix/Game/Item/ItemSystem.cs b/Hotfix/Game/Item/ItemSystem.cs index aec60f3..174a76d 100644 --- a/Hotfix/Game/Item/ItemSystem.cs +++ b/Hotfix/Game/Item/ItemSystem.cs @@ -18,6 +18,9 @@ public class ItemDestroySystem : DestroySystem public static class ItemSystem { + + + public static ItemInfo ToItemInfo(this Item self) { return new ItemInfo() diff --git a/Hotfix/Map/Handler/C2Map_CreateRoomRequestHandler.cs b/Hotfix/Game/Map/Handler/C2Map_CreateRoomRequestHandler.cs similarity index 66% rename from Hotfix/Map/Handler/C2Map_CreateRoomRequestHandler.cs rename to Hotfix/Game/Map/Handler/C2Map_CreateRoomRequestHandler.cs index e3c1f5f..f041928 100644 --- a/Hotfix/Map/Handler/C2Map_CreateRoomRequestHandler.cs +++ b/Hotfix/Game/Map/Handler/C2Map_CreateRoomRequestHandler.cs @@ -3,15 +3,22 @@ using Fantasy.Async; using Fantasy.Entitas; using Fantasy.Network.Interface; -namespace NB.Map; +namespace NB.Game; -public class C2Map_CreateRoomRequestHandler : RouteRPC +public class C2Map_CreateRoomRequestHandler : RouteRPC { - protected override async FTask Run(MapUnit entity, C2Map_CreateRoomRequest request, + protected override async FTask Run(Player entity, C2Map_CreateRoomRequest request, Map2C_CreateRoomResponse response, Action reply) { - if (entity.MapId != request.MapId) + var mapUnit = entity.GetComponent(); + if (mapUnit == null) + { + response.ErrorCode = ErrorCode.ErrServer; + return; + } + + if (mapUnit.MapId != request.MapId) { response.ErrorCode = ErrorCode.MapCreateRoomNotEnter; return; @@ -31,12 +38,12 @@ public class C2Map_CreateRoomRequestHandler : RouteRPC +public class C2Map_LookHandler : Route { - protected override async FTask Run(MapUnit entity, C2Map_Look message) + protected override async FTask Run(Player entity, C2Map_Look message) { + var mapUnit = entity.GetComponent(); + if (mapUnit == null) + { + // response.ErrorCode = ErrorCode.ErrServer; + return; + } + + var roomId = mapUnit.RoomId; var roomManageComponent = entity.Scene.GetComponent(); - var roomId = entity.RoomId; var room = roomManageComponent.Get(roomId); if (room == null) { @@ -23,14 +30,14 @@ public class C2Map_LookHandler : Route Timestamp = message.Timestamp }; - entity.Rotation.x = message.Rotation.x; - entity.Rotation.y = message.Rotation.y; - entity.Rotation.z = message.Rotation.z; + // entity.Rotation.x = message.Rotation.x; + // entity.Rotation.y = message.Rotation.y; + // entity.Rotation.z = message.Rotation.z; foreach (var (_, unit) in room.Units) { // if (unit.Id == entity.Id) continue; - entity.Scene.NetworkMessagingComponent.SendInnerRoute(unit.GateRouteId, notifyMessage); + entity.Scene.NetworkMessagingComponent.SendInnerRoute(unit.SessionRunTimeId, notifyMessage); } await FTask.CompletedTask; diff --git a/Hotfix/Map/Handler/C2Map_MoveHandler.cs b/Hotfix/Game/Map/Handler/C2Map_MoveHandler.cs similarity index 55% rename from Hotfix/Map/Handler/C2Map_MoveHandler.cs rename to Hotfix/Game/Map/Handler/C2Map_MoveHandler.cs index 8b7dccd..a5cb4e3 100644 --- a/Hotfix/Map/Handler/C2Map_MoveHandler.cs +++ b/Hotfix/Game/Map/Handler/C2Map_MoveHandler.cs @@ -3,14 +3,21 @@ using Fantasy.Async; using Fantasy.Helper; using Fantasy.Network.Interface; -namespace NB.Map; +namespace NB.Game; -public class C2Map_MoveHandler : Route +public class C2Map_MoveHandler : Route { - protected override async FTask Run(MapUnit entity, C2Map_Move message) + protected override async FTask Run(Player entity, C2Map_Move message) { + var mapUnit = entity.GetComponent(); + if (mapUnit == null) + { + // response.ErrorCode = ErrorCode.ErrServer; + return; + } + var roomManageComponent = entity.Scene.GetComponent(); - var roomId = entity.RoomId; + var roomId = mapUnit.RoomId; var room = roomManageComponent.Get(roomId); if (room == null) { @@ -27,18 +34,18 @@ public class C2Map_MoveHandler : Route Timestamp = TimeHelper.Now }; - entity.Position.x = message.Position.x; - entity.Position.y = message.Position.y; - entity.Position.z = message.Position.z; - - entity.Rotation.x = message.Rotation.x; - entity.Rotation.y = message.Rotation.y; - entity.Rotation.z = message.Rotation.z; + // entity.Position.x = message.Position.x; + // entity.Position.y = message.Position.y; + // entity.Position.z = message.Position.z; + // + // entity.Rotation.x = message.Rotation.x; + // entity.Rotation.y = message.Rotation.y; + // entity.Rotation.z = message.Rotation.z; foreach (var (_, unit) in room.Units) { // if (unit.Id == entity.Id) continue; - entity.Scene.NetworkMessagingComponent.SendInnerRoute(unit.GateRouteId, notifyMessage); + entity.Scene.NetworkMessagingComponent.SendInnerRoute(unit.SessionRunTimeId, notifyMessage); } diff --git a/Hotfix/Map/Handler/C2Map_RolePropertyChangeHandler.cs b/Hotfix/Game/Map/Handler/C2Map_RolePropertyChangeHandler.cs similarity index 59% rename from Hotfix/Map/Handler/C2Map_RolePropertyChangeHandler.cs rename to Hotfix/Game/Map/Handler/C2Map_RolePropertyChangeHandler.cs index 6a456e9..d00d3b0 100644 --- a/Hotfix/Map/Handler/C2Map_RolePropertyChangeHandler.cs +++ b/Hotfix/Game/Map/Handler/C2Map_RolePropertyChangeHandler.cs @@ -2,14 +2,21 @@ using Fantasy.Async; using Fantasy.Network.Interface; -namespace NB.Map; +namespace NB.Game; -public class C2Map_RolePropertyChangeHandler : Route +public class C2Map_RolePropertyChangeHandler : Route { - protected override async FTask Run(MapUnit entity, C2Map_RolePropertyChange message) + protected override async FTask Run(Player entity, C2Map_RolePropertyChange message) { + var mapUnit = entity.GetComponent(); + if (mapUnit == null) + { + // response.ErrorCode = ErrorCode.ErrServer; + return; + } + var roomManageComponent = entity.Scene.GetComponent(); - var roomId = entity.RoomId; + var roomId = mapUnit.RoomId; var room = roomManageComponent.Get(roomId); if (room == null) { @@ -26,7 +33,7 @@ public class C2Map_RolePropertyChangeHandler : Route +{ + protected override async FTask Run(Player entity, C2Map_TakeItemRequest request, Map2C_TakeItemResponse response, + Action reply) + { + var itemContainer = entity.GetComponent(); + if (itemContainer == null) + { + response.ErrorCode = ErrorCode.ErrArgs; + return; + } + + if (!itemContainer.Items.TryGetValue(request.Id, out var item)) + { + response.ErrorCode = ErrorCode.ErrArgs; + return; + } + + var mapUnit = entity.GetComponent(); + if (mapUnit == null) + { + response.ErrorCode = ErrorCode.ErrArgs; + return; + } + + var itemType = ItemHelper.GetType(item.ConfigId); + if (itemType == ItemBasicType.Rod) + { + itemContainer.Binding.TryGetValue(item.Id, out var itemRod); + //鱼竿 + var itemGear = mapUnit.GetOrAddItemGear(item); + if (itemRod != null) + { + itemGear.Rings.AddRange(itemRod); + } + } + + + var roomManageComponent = entity.Scene.GetComponent(); + var roomId = mapUnit.RoomId; + var room = roomManageComponent.Get(roomId); + if (room != null) + { + var notifyMessage = new Map2C_RoleGearChangeNotify(); + // notifyMessage + // return; + foreach (var (_, unit) in room.Units) + { + // if (unit.Id == entity.Id) continue; + entity.Scene.NetworkMessagingComponent.SendInnerRoute(unit.SessionRunTimeId, notifyMessage); + } + } + } +} \ No newline at end of file diff --git a/Hotfix/Map/Handler/Inner/G2Map_EnterMapRequestHandler.cs b/Hotfix/Game/Map/Handler/Inner/G2Map_EnterMapRequestHandler.cs similarity index 68% rename from Hotfix/Map/Handler/Inner/G2Map_EnterMapRequestHandler.cs rename to Hotfix/Game/Map/Handler/Inner/G2Map_EnterMapRequestHandler.cs index d256b14..8199610 100644 --- a/Hotfix/Map/Handler/Inner/G2Map_EnterMapRequestHandler.cs +++ b/Hotfix/Game/Map/Handler/Inner/G2Map_EnterMapRequestHandler.cs @@ -1,8 +1,9 @@ using Fantasy; using Fantasy.Async; using Fantasy.Network.Interface; +using NB.Game; -namespace NB.Map.Inner; +namespace NB.Game.Inner; /// /// 请求进入地图 @@ -19,32 +20,43 @@ public class G2Map_EnterMapRequestHandler : RouteRPC(); + var mapUnitManage = entity.GetComponent(); if (mapUnitManage == null) { response.ErrorCode = ErrorCode.ErrServer; return; } - var mapUnit = mapUnitManage.Get(request.AccountId); + var player = mapUnitManage.Get(request.AccountId); + if (player == null) + { + response.ErrorCode = ErrorCode.ErrServer; + return; + } + + var mapUnit = player.GetComponent(); if (mapUnit == null) { response.ErrorCode = ErrorCode.ErrServer; return; } - //进入地图 - response.ErrorCode = await mapUnit.EnterMap(request.MapId); - if (response.ErrorCode != 0) + var mapManageComponent = entity.GetComponent(); + var map = mapManageComponent.Get(request.MapId); + if (map == null) { + response.ErrorCode = ErrorCode.MapIdError; return; } + mapUnit.MapId = request.MapId; + + // 如果没有房间代码,则只是进入地图,直接返回,不执行后续逻辑 if (string.IsNullOrEmpty(request.RoomCode)) { - response.Units = [mapUnit.ToMapUnitInfo()]; + response.Units = [player.ToMapUnitInfo()]; return; } @@ -60,7 +72,7 @@ public class G2Map_EnterMapRequestHandler : RouteRPC +{ + protected override async FTask Run(Scene entity, G2Map_ExitRoomRequest request, Map2G_ExiRoomResponse response, + Action reply) + { + var roomManageComponent = entity.GetComponent(); + if (roomManageComponent == null) + { + response.ErrorCode = ErrorCode.ErrServer; + return; + } + + var mapUnitManage = entity.GetComponent(); + if (mapUnitManage == null) + { + response.ErrorCode = ErrorCode.ErrServer; + return; + } + + var player = mapUnitManage.Get(request.AccountId); + if (player == null) + { + response.ErrorCode = ErrorCode.ErrServer; + return; + } + + var mapUnit = player.GetComponent(); + if (mapUnit == null) + { + response.ErrorCode = ErrorCode.ErrServer; + return; + } + + var room = roomManageComponent.Get(mapUnit.RoomId); + if (room == null) + { + response.ErrorCode = ErrorCode.ErrServer; + return; + } + + player.RemoveComponent(); + response.ErrorCode = await room.Enter(player); + // room.Units.Remove(mapUnit.Id); + } +} \ No newline at end of file diff --git a/Hotfix/Map/Helper/MapFactory.cs b/Hotfix/Game/Map/Helper/MapFactory.cs similarity index 95% rename from Hotfix/Map/Helper/MapFactory.cs rename to Hotfix/Game/Map/Helper/MapFactory.cs index dad3195..09221c4 100644 --- a/Hotfix/Map/Helper/MapFactory.cs +++ b/Hotfix/Game/Map/Helper/MapFactory.cs @@ -1,7 +1,7 @@ using Fantasy; using Fantasy.Entitas; -namespace NB.Map; +namespace NB.Game; public class MapFactory { diff --git a/Hotfix/Map/Helper/RoomHelper.cs b/Hotfix/Game/Map/Helper/RoomHelper.cs similarity index 98% rename from Hotfix/Map/Helper/RoomHelper.cs rename to Hotfix/Game/Map/Helper/RoomHelper.cs index cf6f85b..806ab7c 100644 --- a/Hotfix/Map/Helper/RoomHelper.cs +++ b/Hotfix/Game/Map/Helper/RoomHelper.cs @@ -1,6 +1,6 @@ using System.Text; -namespace NB.Map; +namespace NB.Game; public static class RoomHelper { @@ -65,5 +65,4 @@ public static class RoomHelper } #endregion - } \ No newline at end of file diff --git a/Hotfix/Map/System/MapManageComponentSystem.cs b/Hotfix/Game/Map/System/MapManageComponentSystem.cs similarity index 98% rename from Hotfix/Map/System/MapManageComponentSystem.cs rename to Hotfix/Game/Map/System/MapManageComponentSystem.cs index 900bc2c..26c26bb 100644 --- a/Hotfix/Map/System/MapManageComponentSystem.cs +++ b/Hotfix/Game/Map/System/MapManageComponentSystem.cs @@ -1,7 +1,7 @@ using Fantasy.Entitas; using Fantasy.Entitas.Interface; -namespace NB.Map; +namespace NB.Game; public class MapManageComponentDestroySystem : DestroySystem { diff --git a/Hotfix/Map/System/MapRoomSystem.cs b/Hotfix/Game/Map/System/MapRoomSystem.cs similarity index 63% rename from Hotfix/Map/System/MapRoomSystem.cs rename to Hotfix/Game/Map/System/MapRoomSystem.cs index 332bcc0..5aec035 100644 --- a/Hotfix/Map/System/MapRoomSystem.cs +++ b/Hotfix/Game/Map/System/MapRoomSystem.cs @@ -2,7 +2,7 @@ using Fantasy.Async; using Fantasy.Entitas.Interface; -namespace NB.Map; +namespace NB.Game; public class MapRoomDestroySystem : DestroySystem { @@ -18,21 +18,21 @@ public class MapRoomDestroySystem : DestroySystem public static class MapRoomSystem { - public static async FTask Enter(this MapRoom self, MapUnit unit) + public static async FTask Enter(this MapRoom self, Player unit) { self.Units.TryAdd(unit.Id, unit); - var notifyMessage = new Map2C_RoleEnterRoomNotify() - { - Info = unit.ToMapUnitInfo(), - }; - - foreach (var (_, roomUnit) in self.Units) - { - // if (roomUnit.Id == unit.Id) continue; - // 同步其他客户端 - self.Scene.NetworkMessagingComponent.SendInnerRoute(roomUnit.GateRouteId, notifyMessage); - } + // var notifyMessage = new Map2C_RoleEnterRoomNotify() + // { + // Info = unit.ToMapUnitInfo(), + // }; + // + // foreach (var (_, roomUnit) in self.Units) + // { + // // if (roomUnit.Id == unit.Id) continue; + // // 同步其他客户端 + // self.Scene.NetworkMessagingComponent.SendInnerRoute(roomUnit.GateRouteId, notifyMessage); + // } await FTask.CompletedTask; return ErrorCode.Successful; diff --git a/Hotfix/Map/System/MapSystem.cs b/Hotfix/Game/Map/System/MapSystem.cs similarity index 92% rename from Hotfix/Map/System/MapSystem.cs rename to Hotfix/Game/Map/System/MapSystem.cs index a27e3d5..eaba19b 100644 --- a/Hotfix/Map/System/MapSystem.cs +++ b/Hotfix/Game/Map/System/MapSystem.cs @@ -1,6 +1,6 @@ using Fantasy.Entitas.Interface; -namespace NB.Map; +namespace NB.Game; public class MapDestroySystem : DestroySystem { diff --git a/Hotfix/Game/Map/System/MapUnitSystem.cs b/Hotfix/Game/Map/System/MapUnitSystem.cs new file mode 100644 index 0000000..c165d83 --- /dev/null +++ b/Hotfix/Game/Map/System/MapUnitSystem.cs @@ -0,0 +1,31 @@ +using Fantasy; +using Fantasy.Async; + +namespace NB.Game; + +public static class MapUnitComponentSystem +{ + public static MapUnitGear GetOrAddItemGear(this MapUnitComponent self, Item item) + { + var mapItem = self.Gears.Find(t => t.Item == item.Id); + if (mapItem == null) + { + mapItem = new MapUnitGear(); + mapItem.Item = item.Id; + self.Gears.Add(mapItem); + } + + return mapItem; + } + + public static List ToMapUnitInfo(this MapUnitComponent self) + { + List ret = new List(); + // foreach (var (_, unit) in self.Units) + // { + // // ret.Add(unit.ToMapUnitInfo()); + // } + + return ret; + } +} \ No newline at end of file diff --git a/Hotfix/Map/System/RoomManageComponentSystem.cs b/Hotfix/Game/Map/System/RoomManageComponentSystem.cs similarity index 99% rename from Hotfix/Map/System/RoomManageComponentSystem.cs rename to Hotfix/Game/Map/System/RoomManageComponentSystem.cs index 3ff4aa0..4c57c94 100644 --- a/Hotfix/Map/System/RoomManageComponentSystem.cs +++ b/Hotfix/Game/Map/System/RoomManageComponentSystem.cs @@ -2,7 +2,7 @@ using Fantasy.Entitas; using Fantasy.Entitas.Interface; -namespace NB.Map; +namespace NB.Game; public class RoomManageComponentAwakeSystem : AwakeSystem { diff --git a/Hotfix/Game/Player/Components/PlayerManageComponentSystem.cs b/Hotfix/Game/Player/Components/PlayerManageComponentSystem.cs index 7fb734e..365ba35 100644 --- a/Hotfix/Game/Player/Components/PlayerManageComponentSystem.cs +++ b/Hotfix/Game/Player/Components/PlayerManageComponentSystem.cs @@ -62,6 +62,7 @@ public static class PlayerManageComponentSystem await account.TryComponent(); await account.TryComponent(); await account.TryComponent(); + account.GetOrAddComponent(); if (needInit) { diff --git a/Hotfix/Game/Player/Entity/PlayerSystem.cs b/Hotfix/Game/Player/Entity/PlayerSystem.cs index 172eb1c..3361666 100644 --- a/Hotfix/Game/Player/Entity/PlayerSystem.cs +++ b/Hotfix/Game/Player/Entity/PlayerSystem.cs @@ -63,45 +63,26 @@ public static class PlayerSystem } #endregion - - #region 测试数据 - - public static void SetTestData(this Player player) + + public static MapUnitInfo ToMapUnitInfo(this Player self) { + var ret = new MapUnitInfo() + { + Id = self.Id, + Position = Vector3Info.Create(self.Scene), + Rotation = Vector3Info.Create(self.Scene), + }; - // Dictionary> rigDic = new Dictionary>() - // { - // { 30001, [50001, 60001, 70002, 90001, 100001] }, - // { 30002, [40001, 50001, 60001, 70002, 00001, 100001] }, - // { 30003, [40001, 60001, 80001] } - // }; - // - // var itemContainer = player.GetComponent(); - // - // //添加测试数据 - // if (itemContainer != null && itemContainer.FishingRig.Count < 1) - // { - // foreach (var (rod, list) in rigDic) - // { - // if (itemContainer.GetFistItemByConfigId(rod, out var item) && item != null) - // { - // var childs = new List(); - // foreach (var i in list) - // { - // if (itemContainer.GetFistItemByConfigId(i, out var itemChild) && itemChild != null) - // { - // childs.Add(itemChild.Id); - // } - // } - // - // itemContainer.FishingRig[item.Id] = childs; - // } - // } - // - // itemContainer.Save(); - // } + var mapUnit = self.GetComponent(); + ret.Position.x = mapUnit.Position.x; + ret.Position.y = mapUnit.Position.y; + ret.Position.z = mapUnit.Position.z; + + ret.Rotation.x = mapUnit.Rotation.x; + ret.Rotation.y = mapUnit.Rotation.y; + ret.Rotation.z = mapUnit.Rotation.z; + + return ret; } - - #endregion } \ No newline at end of file diff --git a/Hotfix/Gate/Handler/Outer/C2G_EnterMapRequestHandler.cs b/Hotfix/Gate/Handler/Outer/C2G_EnterMapRequestHandler.cs index 06cec60..34014a8 100644 --- a/Hotfix/Gate/Handler/Outer/C2G_EnterMapRequestHandler.cs +++ b/Hotfix/Gate/Handler/Outer/C2G_EnterMapRequestHandler.cs @@ -3,7 +3,7 @@ using Fantasy.Async; using Fantasy.Network; using Fantasy.Network.Interface; using Fantasy.Platform.Net; -using NB.Map; +using NB.Game; namespace NB.Gate; @@ -55,7 +55,7 @@ public class C2G_EnterMapRequestHandler : MessageRPC -{ - protected override async FTask Run(Scene entity, G2Map_ExitRoomRequest request, Map2G_ExiRoomResponse response, - Action reply) - { - } -} \ No newline at end of file diff --git a/Hotfix/Map/Helper/MapHelper.cs b/Hotfix/Map/Helper/MapHelper.cs deleted file mode 100644 index 193b0c1..0000000 --- a/Hotfix/Map/Helper/MapHelper.cs +++ /dev/null @@ -1,30 +0,0 @@ -using Fantasy; -using Fantasy.Async; - -namespace NB.Map; - -public static class MapHelper -{ - public static async FTask Offline(Scene scene, long accountId, long gateRouteId) - { - // 在缓存中检查该账号是否存在 - var chatUnitManageComponent = scene.GetComponent(); - if (chatUnitManageComponent == null) return; - var mapUnit = chatUnitManageComponent.Get(accountId); - if (mapUnit == null) return; - - var roomManageComponent = scene.GetComponent(); - - if (mapUnit.RoomId > 0) - { - var room = roomManageComponent.Get(mapUnit.RoomId); - if (room != null) - { - await room.Exit(accountId); - roomManageComponent.Check(mapUnit.RoomId); - } - } - - await chatUnitManageComponent.Offline(scene, accountId, gateRouteId); - } -} \ No newline at end of file diff --git a/Hotfix/Map/Helper/MapUnitFactory.cs b/Hotfix/Map/Helper/MapUnitFactory.cs deleted file mode 100644 index 7d7f980..0000000 --- a/Hotfix/Map/Helper/MapUnitFactory.cs +++ /dev/null @@ -1,19 +0,0 @@ -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/System/MapUnitManageComponentSystem.cs b/Hotfix/Map/System/MapUnitManageComponentSystem.cs deleted file mode 100644 index 72af0a0..0000000 --- a/Hotfix/Map/System/MapUnitManageComponentSystem.cs +++ /dev/null @@ -1,84 +0,0 @@ -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/MapUnitSystem.cs b/Hotfix/Map/System/MapUnitSystem.cs deleted file mode 100644 index 44276a6..0000000 --- a/Hotfix/Map/System/MapUnitSystem.cs +++ /dev/null @@ -1,70 +0,0 @@ -using Fantasy; -using Fantasy.Async; -using Fantasy.Entitas.Interface; -using Unity.Mathematics; - -namespace NB.Map; - -public class MapUnitSystemDestroySystem : DestroySystem -{ - protected override void Destroy(MapUnit self) - { - self.MapId = 0; - self.Position = float3.zero; - self.Rotation = float3.zero; - self.GateRouteId = 0L; - } -} - -public static class MapUnitSystem -{ - public static async FTask EnterMap(this MapUnit self, int mapId) - { - var mapManageComponent = self.Scene.GetComponent(); - - var map = mapManageComponent.Get(mapId); - if (map == null) - { - return ErrorCode.MapIdError; - } - - if (map.Units.TryAdd(self.Id, self)) - { - // 同步客户端 - // self.Scene.NetworkMessagingComponent.SendInnerRoute(self.GateRouteId, new Map2C_ChangeMap() - // { - // Node = 1, - // MapId = mapId - // }); - } - - self.MapId = mapId; - - - await FTask.CompletedTask; - - - return ErrorCode.Successful; - } - - - public static MapUnitInfo ToMapUnitInfo(this MapUnit self) - { - var ret = new MapUnitInfo() - { - Id = self.Id, - Position = Vector3Info.Create(self.Scene), - Rotation = Vector3Info.Create(self.Scene), - }; - - ret.Position.x = self.Position.x; - ret.Position.y = self.Position.y; - ret.Position.z = self.Position.z; - - ret.Rotation.x = self.Rotation.x; - ret.Rotation.y = self.Rotation.y; - ret.Rotation.z = self.Rotation.z; - - return ret; - } -} \ No newline at end of file diff --git a/Hotfix/OnCreateSceneEvent.cs b/Hotfix/OnCreateSceneEvent.cs index 3188443..520ab29 100644 --- a/Hotfix/OnCreateSceneEvent.cs +++ b/Hotfix/OnCreateSceneEvent.cs @@ -6,7 +6,6 @@ using NB.Authentication; using NB.Chat; using NB.Game; using NB.Gate; -using NB.Map; namespace NBF; @@ -40,11 +39,11 @@ public sealed class OnCreateSceneEvent : AsyncEventSystem await InitializeGateScene(scene); break; } - case SceneType.Map: - { - await InitializeMapScene(scene); - break; - } + // case SceneType.Map: + // { + // await InitializeMapScene(scene); + // break; + // } case SceneType.Social: { // Gate 场景初始化 @@ -117,24 +116,24 @@ public sealed class OnCreateSceneEvent : AsyncEventSystem // Log.Debug(instanceList[0].Dic[1]); } - private async FTask InitializeMapScene(Scene scene) - { - // Map 场景特定的初始化逻辑 - Log.Info($"初始化 Map 场景: {scene.Id}"); - Log.Info("创建地图场景==="); - scene.AddComponent(); - var roomManageComponent = scene.AddComponent(); - scene.AddComponent(); - - var room = roomManageComponent.Create(361499030775398402); - if (room != null) - { - roomManageComponent.TestRoomCode = room.Code; - Log.Info($"测试房间代码 = {room.Code}"); - } - - await FTask.CompletedTask; - } + // private async FTask InitializeMapScene(Scene scene) + // { + // // Map 场景特定的初始化逻辑 + // Log.Info($"初始化 Map 场景: {scene.Id}"); + // Log.Info("创建地图场景==="); + // scene.AddComponent(); + // var roomManageComponent = scene.AddComponent(); + // scene.AddComponent(); + // + // var room = roomManageComponent.Create(361499030775398402); + // if (room != null) + // { + // roomManageComponent.TestRoomCode = room.Code; + // Log.Info($"测试房间代码 = {room.Code}"); + // } + // + // await FTask.CompletedTask; + // } private async FTask InitializeSocialScene(Scene scene) { @@ -153,6 +152,19 @@ public sealed class OnCreateSceneEvent : AsyncEventSystem //用于管理玩家的组件 scene.AddComponent(); scene.AddComponent(); + + + Log.Info("创建地图场景==="); + var roomManageComponent = scene.AddComponent(); + scene.AddComponent(); + + var room = roomManageComponent.Create(361499030775398402); + if (room != null) + { + // roomManageComponent.TestRoomCode = room.Code; + Log.Info($"测试房间代码 = {room.Code}"); + } + await FTask.CompletedTask; // var rod = RodConfig.Get(30001); diff --git a/Tools/NetworkProtocol/Outer/GameMessage.proto b/Tools/NetworkProtocol/Outer/GameMessage.proto index e34f4ac..f603983 100644 --- a/Tools/NetworkProtocol/Outer/GameMessage.proto +++ b/Tools/NetworkProtocol/Outer/GameMessage.proto @@ -20,7 +20,7 @@ message Game2C_GetItemsResponse // ICustomRouteResponse ///请求使用物品 message C2Game_UseItemRequest // ICustomRouteRequest,Game2C_UseItemResponse,GameRoute { - + int64 ItemId = 1;//主物体id } ///请求使用物品响应 diff --git a/Tools/NetworkProtocol/Outer/MapMessage.proto b/Tools/NetworkProtocol/Outer/MapMessage.proto index abfe9a1..5ed1002 100644 --- a/Tools/NetworkProtocol/Outer/MapMessage.proto +++ b/Tools/NetworkProtocol/Outer/MapMessage.proto @@ -2,7 +2,7 @@ syntax = "proto3"; package Fantasy.Network.Message; /// 请求创建房间 -message C2Map_CreateRoomRequest // ICustomRouteRequest,Map2C_CreateRoomResponse,MapRoute +message C2Map_CreateRoomRequest // ICustomRouteRequest,Map2C_CreateRoomResponse,GameRoute { int32 MapId = 1;//地图id } @@ -43,22 +43,11 @@ message G2C_EnterMapResponse // IResponse } -// // 请求进入地图 -// message C2Map_EnterMapRequest // ICustomRouteRequest,Map2C_EnterMapResponse,MapRoute -// { -// int32 MapId = 1;//地图id -// string RoomCode = 2;//房间id,如果是进入房间 -// } -// message Map2C_EnterMapResponse // ICustomRouteResponse -// { - -// } - /// 通知客户端切换地图 -message Map2C_ChangeMap // ICustomRouteMessage,MapRoute +message Map2C_ChangeMap // ICustomRouteMessage,GameRoute { int32 MapId = 1; //地图id int32 Node = 2; //站位节点 diff --git a/Tools/NetworkProtocol/Outer/RoomMessage.proto b/Tools/NetworkProtocol/Outer/RoomMessage.proto index 569a5bc..104793f 100644 --- a/Tools/NetworkProtocol/Outer/RoomMessage.proto +++ b/Tools/NetworkProtocol/Outer/RoomMessage.proto @@ -4,39 +4,56 @@ package Fantasy.Network.Message; //************** 进入 离开 ********************** ///用户进入地图 -message Map2C_RoleEnterRoomNotify // ICustomRouteMessage,MapRoute +message Map2C_RoleEnterRoomNotify // ICustomRouteMessage,GameRoute { MapUnitInfo Info = 2; } ///用户离开地图 -message Map2C_RoleExitRoomNotify // ICustomRouteMessage,MapRoute +message Map2C_RoleExitRoomNotify // ICustomRouteMessage,GameRoute { int64 Id = 1;//离开人员 } +//************** 物品变化 ********************** + +/// 请求拿起物品 +message C2Map_TakeItemRequest // ICustomRouteRequest,Map2C_TakeItemResponse,GameRoute +{ + int32 Id = 1; //物品id + bool Task = 2; //拿起 +} + +/// 请求拿起物品响应 +message Map2C_TakeItemResponse // ICustomRouteResponse +{ + int32 Id = 1; //物品id + bool Task = 2; //拿起 +} + + //************** 参数变化 ********************** -message C2Map_RolePropertyChange // ICustomRouteMessage,MapRoute +message C2Map_RolePropertyChange // ICustomRouteMessage,GameRoute { repeated KeyValueInt64 Propertys = 1; //变化的属性信息 } ///玩家状态变化同步 -message Map2C_RoleStateNotify // ICustomRouteMessage,MapRoute +message Map2C_RoleStateNotify // ICustomRouteMessage,GameRoute { int64 Id = 1; UnitStateInfo State = 2; } ///玩家钓组变化 -message Map2C_RoleGearChangeNotify // ICustomRouteMessage,MapRoute +message Map2C_RoleGearChangeNotify // ICustomRouteMessage,GameRoute { int64 Id = 1; repeated GearInfo Gears = 2; //钓组数据 } //玩家属性值变化 -message Map2C_RolePropertyChangeNotify // ICustomRouteMessage,MapRoute +message Map2C_RolePropertyChangeNotify // ICustomRouteMessage,GameRoute { int64 Id = 1; repeated KeyValueInt64 Propertys = 2; //变化的属性信息 @@ -47,7 +64,7 @@ message Map2C_RolePropertyChangeNotify // ICustomRouteMessage,MapRoute //************** 移动 旋转 ********************** // 角色移动 -message C2Map_Move // ICustomRouteMessage,MapRoute +message C2Map_Move // ICustomRouteMessage,GameRoute { Vector3Info Position = 1; //当前位置 Vector3Info Rotation = 2; //角色方向 @@ -58,14 +75,14 @@ message C2Map_Move // ICustomRouteMessage,MapRoute } // 角色朝向变化 -message C2Map_Look // ICustomRouteMessage,MapRoute +message C2Map_Look // ICustomRouteMessage,GameRoute { Vector3Info Rotation = 1; //角色方向 int64 Timestamp = 2; // 时间点 } ///玩家移动推送 -message Map2C_MoveNotify // ICustomRouteMessage,MapRoute +message Map2C_MoveNotify // ICustomRouteMessage,GameRoute { int64 Id = 1; // id Vector3Info Position = 2; //当前位置 @@ -77,9 +94,11 @@ message Map2C_MoveNotify // ICustomRouteMessage,MapRoute } ///玩家旋转推送 -message Map2C_LookeNotify // ICustomRouteMessage,MapRoute +message Map2C_LookeNotify // ICustomRouteMessage,GameRoute { int64 Id = 1; // id Vector3Info Rotation = 2; //角色方向 int64 Timestamp = 3; // 时间点 -} \ No newline at end of file +} + + diff --git a/Tools/NetworkProtocol/Outer/data/MapProtoData.proto b/Tools/NetworkProtocol/Outer/data/MapProtoData.proto index 8b78858..6c97a21 100644 --- a/Tools/NetworkProtocol/Outer/data/MapProtoData.proto +++ b/Tools/NetworkProtocol/Outer/data/MapProtoData.proto @@ -22,11 +22,13 @@ message QuaternionInfo ///玩家当前使用钓组信息 message GearInfo { - int64 Rod = 1; - repeated int64 Rigs = 2; //钓组配件 - Vector3Info Position = 3; //钓组当前位置 - Vector3Info Rotation = 4; //钓组方向 - repeated KeyValueInt64 Propertys = 5; //钓组参数信息 + ItemInfo Item = 1; //主物品id + repeated ItemInfo Binds = 2; //物品配件 + Vector3Info Position = 3; //物品当前位置 + Vector3Info Rotation = 4; //物品方向 + repeated KeyValueInt64 Propertys = 5; //物品参数信息 + bool InUse = 6; //使用中 + bool InHand = 7; //在手中 } @@ -43,7 +45,7 @@ message MapUnitInfo Vector3Info Position = 3; //当前位置 Vector3Info Rotation = 4; //角色方向 UnitStateInfo State = 5; //状态信息 - repeated GearInfo Gears = 6; //钓组数据 + repeated GearInfo Gears = 6; //钓组数据 repeated KeyValueInt64 Propertys = 7; //属性信息 } diff --git a/Tools/NetworkProtocol/RouteType.Config b/Tools/NetworkProtocol/RouteType.Config index 78df07a..82e1593 100644 --- a/Tools/NetworkProtocol/RouteType.Config +++ b/Tools/NetworkProtocol/RouteType.Config @@ -1,5 +1,4 @@ // Route协议定义(需要定义1000以上、因为1000以内的框架预留) GateRoute = 1001 // Gate SocialRoute = 1002 // Social -GameRoute = 1003 // Game -MapRoute = 1004 // 地图 \ No newline at end of file +GameRoute = 1003 // Game \ No newline at end of file