diff --git a/Config/NetworkProtocol/Outer/RoomMessage.proto b/Config/NetworkProtocol/Outer/RoomMessage.proto index 51f4327..08d0a0d 100644 --- a/Config/NetworkProtocol/Outer/RoomMessage.proto +++ b/Config/NetworkProtocol/Outer/RoomMessage.proto @@ -6,7 +6,7 @@ package Fantasy.Network.Message; ///用户进入地图 message Map2C_RoleEnterRoomNotify // ICustomRouteMessage,MapRoute { - MapUnitInfo Info = 1; + MapUnitInfo Info = 2; } ///用户离开地图 @@ -16,6 +16,10 @@ message Map2C_RoleExitRoomNotify // ICustomRouteMessage,MapRoute } //************** 参数变化 ********************** +message C2Map_RolePropertyChange // ICustomRouteMessage,MapRoute +{ + repeated KeyValueInt64 Propertys = 1; //变化的属性信息 +} ///玩家状态变化同步 message Map2C_RoleStateNotify // ICustomRouteMessage,MapRoute @@ -34,9 +38,12 @@ message Map2C_RoleGearChangeNotify // ICustomRouteMessage,MapRoute //玩家属性值变化 message Map2C_RolePropertyChangeNotify // ICustomRouteMessage,MapRoute { - repeated KeyValueInt32 Propertys = 1; //变化的属性信息 + int64 Id = 1; + repeated KeyValueInt64 Propertys = 2; //变化的属性信息 } + + //************** 移动 旋转 ********************** // 角色移动 @@ -46,7 +53,8 @@ message C2Map_Move // ICustomRouteMessage,MapRoute Vector3Info Rotation = 2; //角色方向 Vector3Info Direction = 3; // 移动方向 bool IsStop = 4; // 是否是停止移动 - int64 Timestamp = 5; // 时间点 + bool IsRun = 5; + int64 Timestamp = 6; // 时间点 } // 角色朝向变化 diff --git a/Config/NetworkProtocol/Outer/data/CommonProtoData.proto b/Config/NetworkProtocol/Outer/data/CommonProtoData.proto index 7bfbb9a..2198972 100644 --- a/Config/NetworkProtocol/Outer/data/CommonProtoData.proto +++ b/Config/NetworkProtocol/Outer/data/CommonProtoData.proto @@ -13,26 +13,12 @@ message RoleBaseInfo VipInfo VipInfo = 7; //vip信息 } -message KeyValueStringInt64 -{ - string Key = 1; //键 - int64 Value = 2; //值 -} -message KeyValueInt32 -{ - int32 Key = 1; //键 - int32 Value = 2; //值 -} + + message KeyValueInt64 { - int64 Key = 1; //键 - int64 Value = 2; //值 -} - -message KeyValueString -{ - string Key = 1; //键 - string Value = 2; //值 + int32 Key = 1; //键 + int64 Value = 2; // 值 } @@ -105,7 +91,7 @@ message ActivityInfo int64 Id = 1; //活动id int64 StartTime = 2; //开始时间 int64 EndTime = 3; //结束时间 - repeated KeyValueStringInt64 Data = 4; //活动数据 + repeated KeyValueInt64 Data = 4; //活动数据 } ///技能情况 diff --git a/Config/NetworkProtocol/Outer/data/MapProtoData.proto b/Config/NetworkProtocol/Outer/data/MapProtoData.proto index 011f57e..8b78858 100644 --- a/Config/NetworkProtocol/Outer/data/MapProtoData.proto +++ b/Config/NetworkProtocol/Outer/data/MapProtoData.proto @@ -23,20 +23,17 @@ message QuaternionInfo message GearInfo { int64 Rod = 1; - repeated int64 Rigs = 2; //钓组配件 - float LineLength = 3; //线长度 - float ReelSpeed = 4; //收线速度 - int32 State = 5; //杆子状态 - Vector3Info Position = 6; //钓组当前位置 - Vector3Info Rotation = 7; //钓组方向 + repeated int64 Rigs = 2; //钓组配件 + Vector3Info Position = 3; //钓组当前位置 + Vector3Info Rotation = 4; //钓组方向 + repeated KeyValueInt64 Propertys = 5; //钓组参数信息 } - message UnitStateInfo { int32 State = 1; //状态id - repeated string Args = 2; //状态参数 + repeated KeyValueInt64 Propertys = 2; //状态参数信息 } message MapUnitInfo @@ -46,7 +43,7 @@ message MapUnitInfo Vector3Info Position = 3; //当前位置 Vector3Info Rotation = 4; //角色方向 UnitStateInfo State = 5; //状态信息 - repeated GearInfo Gears = 7; //钓组数据 - repeated KeyValueInt32 Propertys = 8; //属性信息 + repeated GearInfo Gears = 6; //钓组数据 + repeated KeyValueInt64 Propertys = 7; //属性信息 } diff --git a/Entity/Generate/NetworkProtocol/CommonProtoData.cs b/Entity/Generate/NetworkProtocol/CommonProtoData.cs index a80f9b6..0078e79 100644 --- a/Entity/Generate/NetworkProtocol/CommonProtoData.cs +++ b/Entity/Generate/NetworkProtocol/CommonProtoData.cs @@ -56,46 +56,6 @@ namespace Fantasy public VipInfo VipInfo { get; set; } } [ProtoContract] - public partial class KeyValueStringInt64 : AMessage, IProto - { - public static KeyValueStringInt64 Create(Scene scene) - { - return scene.MessagePoolComponent.Rent(); - } - public override void Dispose() - { - Key = default; - Value = default; -#if FANTASY_NET || FANTASY_UNITY - GetScene().MessagePoolComponent.Return(this); -#endif - } - [ProtoMember(1)] - public string Key { get; set; } - [ProtoMember(2)] - public long Value { get; set; } - } - [ProtoContract] - public partial class KeyValueInt32 : AMessage, IProto - { - public static KeyValueInt32 Create(Scene scene) - { - return scene.MessagePoolComponent.Rent(); - } - public override void Dispose() - { - Key = default; - Value = default; -#if FANTASY_NET || FANTASY_UNITY - GetScene().MessagePoolComponent.Return(this); -#endif - } - [ProtoMember(1)] - public int Key { get; set; } - [ProtoMember(2)] - public int Value { get; set; } - } - [ProtoContract] public partial class KeyValueInt64 : AMessage, IProto { public static KeyValueInt64 Create(Scene scene) @@ -111,30 +71,10 @@ namespace Fantasy #endif } [ProtoMember(1)] - public long Key { get; set; } + public int Key { get; set; } [ProtoMember(2)] public long Value { get; set; } } - [ProtoContract] - public partial class KeyValueString : AMessage, IProto - { - public static KeyValueString Create(Scene scene) - { - return scene.MessagePoolComponent.Rent(); - } - public override void Dispose() - { - Key = default; - Value = default; -#if FANTASY_NET || FANTASY_UNITY - GetScene().MessagePoolComponent.Return(this); -#endif - } - [ProtoMember(1)] - public string Key { get; set; } - [ProtoMember(2)] - public string Value { get; set; } - } /// /// 角色信息 /// @@ -357,7 +297,7 @@ namespace Fantasy [ProtoMember(3)] public long EndTime { get; set; } [ProtoMember(4)] - public List Data = new List(); + public List Data = new List(); } /// /// 技能情况 diff --git a/Entity/Generate/NetworkProtocol/MapMessage.cs b/Entity/Generate/NetworkProtocol/MapMessage.cs index 0407359..2a02cc7 100644 --- a/Entity/Generate/NetworkProtocol/MapMessage.cs +++ b/Entity/Generate/NetworkProtocol/MapMessage.cs @@ -70,7 +70,7 @@ namespace Fantasy public uint ErrorCode { get; set; } } /// - /// 请求网关离开房间 + /// 请求网关离开房间(离开房间,但是不离开地图) /// [ProtoContract] public partial class C2G_ExitRoomRequest : AMessage, IRequest, IProto diff --git a/Entity/Generate/NetworkProtocol/MapProtoData.cs b/Entity/Generate/NetworkProtocol/MapProtoData.cs index 9efd7d7..23552c9 100644 --- a/Entity/Generate/NetworkProtocol/MapProtoData.cs +++ b/Entity/Generate/NetworkProtocol/MapProtoData.cs @@ -100,11 +100,9 @@ namespace Fantasy { Rod = default; Rigs.Clear(); - LineLength = default; - ReelSpeed = default; - State = default; Position = default; Rotation = default; + Propertys.Clear(); #if FANTASY_NET || FANTASY_UNITY GetScene().MessagePoolComponent.Return(this); #endif @@ -114,15 +112,11 @@ namespace Fantasy [ProtoMember(2)] public List Rigs = new List(); [ProtoMember(3)] - public float LineLength { get; set; } - [ProtoMember(4)] - public float ReelSpeed { get; set; } - [ProtoMember(5)] - public int State { get; set; } - [ProtoMember(6)] public Vector3Info Position { get; set; } - [ProtoMember(7)] + [ProtoMember(4)] public Vector3Info Rotation { get; set; } + [ProtoMember(5)] + public List Propertys = new List(); } [ProtoContract] public partial class UnitStateInfo : AMessage, IProto @@ -134,7 +128,7 @@ namespace Fantasy public override void Dispose() { State = default; - Args.Clear(); + Propertys.Clear(); #if FANTASY_NET || FANTASY_UNITY GetScene().MessagePoolComponent.Return(this); #endif @@ -142,7 +136,7 @@ namespace Fantasy [ProtoMember(1)] public int State { get; set; } [ProtoMember(2)] - public List Args = new List(); + public List Propertys = new List(); } [ProtoContract] public partial class MapUnitInfo : AMessage, IProto @@ -177,6 +171,6 @@ namespace Fantasy [ProtoMember(6)] public List Gears = new List(); [ProtoMember(7)] - public List Propertys = new List(); + public List Propertys = new List(); } } diff --git a/Entity/Generate/NetworkProtocol/OuterOpcode.cs b/Entity/Generate/NetworkProtocol/OuterOpcode.cs index 7bbce27..16493aa 100644 --- a/Entity/Generate/NetworkProtocol/OuterOpcode.cs +++ b/Entity/Generate/NetworkProtocol/OuterOpcode.cs @@ -18,28 +18,29 @@ namespace Fantasy public const uint Game2C_GetRoleInfoResponse = 2415929106; public const uint Map2C_RoleEnterRoomNotify = 2147493650; public const uint Map2C_RoleExitRoomNotify = 2147493651; - public const uint Map2C_RoleStateNotify = 2147493652; - public const uint Map2C_RoleGearChangeNotify = 2147493653; - public const uint Map2C_RolePropertyChangeNotify = 2147493654; - public const uint C2Map_Move = 2147493655; - public const uint C2Map_Look = 2147493656; - public const uint Map2C_MoveNotify = 2147493657; - public const uint Map2C_LookeNotify = 2147493658; + public const uint C2Map_RolePropertyChange = 2147493652; + public const uint Map2C_RoleStateNotify = 2147493653; + public const uint Map2C_RoleGearChangeNotify = 2147493654; + public const uint Map2C_RolePropertyChangeNotify = 2147493655; + public const uint C2Map_Move = 2147493656; + public const uint C2Map_Look = 2147493657; + public const uint Map2C_MoveNotify = 2147493658; + public const uint Map2C_LookeNotify = 2147493659; public const uint C2S_GetConversationsRequest = 2281711379; public const uint S2C_GetConversationsResponse = 2415929107; public const uint C2S_SendMailRequest = 2281711380; public const uint S2C_SendMailResponse = 2415929108; public const uint C2S_DeleteMailRequest = 2281711381; public const uint S2C_DeleteMailResponse = 2415929109; - public const uint S2C_HaveMail = 2147493659; - public const uint S2C_MailState = 2147493660; + public const uint S2C_HaveMail = 2147493660; + public const uint S2C_MailState = 2147493661; public const uint C2S_CreateChannelRequest = 2281711382; public const uint S2C_CreateChannelResponse = 2415929110; public const uint C2S_JoinChannelRequest = 2281711383; public const uint S2C_JoinChannelResponse = 2415929111; public const uint C2S_SendMessageRequest = 2281711384; public const uint S2C_SendMessageResponse = 2415929112; - public const uint S2C_Message = 2147493661; + public const uint S2C_Message = 2147493662; public const uint C2S_CreateClubRequest = 2281711385; public const uint S2C_CreateClubResponse = 2415929113; public const uint C2S_GetClubInfoRequest = 2281711386; @@ -56,6 +57,6 @@ namespace Fantasy public const uint S2C_DissolveClubResponse = 2415929119; public const uint C2S_DisposeJoinRequest = 2281711392; public const uint S2C_DisposeJoinResponse = 2415929120; - public const uint S2C_ClubChange = 2147493662; + public const uint S2C_ClubChange = 2147493663; } } diff --git a/Entity/Generate/NetworkProtocol/RoomMessage.cs b/Entity/Generate/NetworkProtocol/RoomMessage.cs index 02f9fc4..0a991e1 100644 --- a/Entity/Generate/NetworkProtocol/RoomMessage.cs +++ b/Entity/Generate/NetworkProtocol/RoomMessage.cs @@ -63,6 +63,26 @@ namespace Fantasy [ProtoMember(1)] public long Id { get; set; } } + [ProtoContract] + public partial class C2Map_RolePropertyChange : AMessage, ICustomRouteMessage, IProto + { + public static C2Map_RolePropertyChange Create(Scene scene) + { + return scene.MessagePoolComponent.Rent(); + } + public override void Dispose() + { + Propertys.Clear(); +#if FANTASY_NET || FANTASY_UNITY + GetScene().MessagePoolComponent.Return(this); +#endif + } + public uint OpCode() { return OuterOpcode.C2Map_RolePropertyChange; } + [ProtoIgnore] + public int RouteType => Fantasy.RouteType.MapRoute; + [ProtoMember(1)] + public List Propertys = new List(); + } /// /// 玩家状态变化同步 /// @@ -124,6 +144,7 @@ namespace Fantasy } public override void Dispose() { + Id = default; Propertys.Clear(); #if FANTASY_NET || FANTASY_UNITY GetScene().MessagePoolComponent.Return(this); @@ -133,7 +154,9 @@ namespace Fantasy [ProtoIgnore] public int RouteType => Fantasy.RouteType.MapRoute; [ProtoMember(1)] - public List Propertys = new List(); + public long Id { get; set; } + [ProtoMember(2)] + public List Propertys = new List(); } [ProtoContract] public partial class C2Map_Move : AMessage, ICustomRouteMessage, IProto @@ -148,6 +171,7 @@ namespace Fantasy Rotation = default; Direction = default; IsStop = default; + IsRun = default; Timestamp = default; #if FANTASY_NET || FANTASY_UNITY GetScene().MessagePoolComponent.Return(this); @@ -165,6 +189,8 @@ namespace Fantasy [ProtoMember(4)] public bool IsStop { get; set; } [ProtoMember(5)] + public bool IsRun { get; set; } + [ProtoMember(6)] public long Timestamp { get; set; } } [ProtoContract] diff --git a/Hotfix/Common/Handler/G2Common_ExitRequestHandler.cs b/Hotfix/Common/Handler/G2Common_ExitRequestHandler.cs index 6bb6aff..b6abef0 100644 --- a/Hotfix/Common/Handler/G2Common_ExitRequestHandler.cs +++ b/Hotfix/Common/Handler/G2Common_ExitRequestHandler.cs @@ -53,9 +53,7 @@ public class G2Common_ExitRequestHandler : RouteRPC(); - await chatUnitManageComponent.Offline(scene, request.AccountId, request.GateRouteId); + await MapHelper.Offline(scene, request.AccountId, request.GateRouteId); Log.Info("退出房间服成功=="); } } \ No newline at end of file diff --git a/Hotfix/Map/Handler/C2Map_LookHandler.cs b/Hotfix/Map/Handler/C2Map_LookHandler.cs index a905d91..4c0bb90 100644 --- a/Hotfix/Map/Handler/C2Map_LookHandler.cs +++ b/Hotfix/Map/Handler/C2Map_LookHandler.cs @@ -29,6 +29,7 @@ public class C2Map_LookHandler : Route foreach (var (_, unit) in room.Units) { + // if (unit.Id == entity.Id) continue; entity.Scene.NetworkMessagingComponent.SendInnerRoute(unit.GateRouteId, notifyMessage); } diff --git a/Hotfix/Map/Handler/C2Map_MoveHandler.cs b/Hotfix/Map/Handler/C2Map_MoveHandler.cs index 60151a5..8b7dccd 100644 --- a/Hotfix/Map/Handler/C2Map_MoveHandler.cs +++ b/Hotfix/Map/Handler/C2Map_MoveHandler.cs @@ -37,6 +37,7 @@ public class C2Map_MoveHandler : Route foreach (var (_, unit) in room.Units) { + // if (unit.Id == entity.Id) continue; entity.Scene.NetworkMessagingComponent.SendInnerRoute(unit.GateRouteId, notifyMessage); } diff --git a/Hotfix/Map/Handler/C2Map_RolePropertyChangeHandler.cs b/Hotfix/Map/Handler/C2Map_RolePropertyChangeHandler.cs new file mode 100644 index 0000000..6a456e9 --- /dev/null +++ b/Hotfix/Map/Handler/C2Map_RolePropertyChangeHandler.cs @@ -0,0 +1,34 @@ +using Fantasy; +using Fantasy.Async; +using Fantasy.Network.Interface; + +namespace NB.Map; + +public class C2Map_RolePropertyChangeHandler : Route +{ + protected override async FTask Run(MapUnit entity, C2Map_RolePropertyChange message) + { + var roomManageComponent = entity.Scene.GetComponent(); + var roomId = entity.RoomId; + var room = roomManageComponent.Get(roomId); + if (room == null) + { + return; + } + + var notifyMessage = new Map2C_RolePropertyChangeNotify() + { + Id = entity.Id, + Propertys = message.Propertys, + }; + + + foreach (var (_, unit) in room.Units) + { + if (unit.Id == entity.Id) continue; + entity.Scene.NetworkMessagingComponent.SendInnerRoute(unit.GateRouteId, notifyMessage); + } + + await FTask.CompletedTask; + } +} \ No newline at end of file diff --git a/Hotfix/Map/Helper/MapHelper.cs b/Hotfix/Map/Helper/MapHelper.cs new file mode 100644 index 0000000..193b0c1 --- /dev/null +++ b/Hotfix/Map/Helper/MapHelper.cs @@ -0,0 +1,30 @@ +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/System/MapRoomSystem.cs b/Hotfix/Map/System/MapRoomSystem.cs index eb6f25a..332bcc0 100644 --- a/Hotfix/Map/System/MapRoomSystem.cs +++ b/Hotfix/Map/System/MapRoomSystem.cs @@ -38,6 +38,12 @@ public static class MapRoomSystem return ErrorCode.Successful; } + public static async FTask Exit(this MapRoom self, long id) + { + self.Units.Remove(id); + await FTask.CompletedTask; + } + public static List ToMapUnitInfo(this MapRoom self) { List ret = new List(); diff --git a/Hotfix/Map/System/RoomManageComponentSystem.cs b/Hotfix/Map/System/RoomManageComponentSystem.cs index 66347ea..3ff4aa0 100644 --- a/Hotfix/Map/System/RoomManageComponentSystem.cs +++ b/Hotfix/Map/System/RoomManageComponentSystem.cs @@ -66,11 +66,23 @@ public static class RoomManageComponentSystem return true; } + public static void Check(this RoomManageComponent self, int roomId) + { + if (self.Rooms.TryGetValue(roomId, out var room)) + { + if (room.Units.Count < 1) + { + Log.Info($"房间没人了,解散房间,id={roomId}"); + // self.Remove(roomId); + } + } + } + public static MapRoom? Get(this RoomManageComponent self, int roomId) { return self.Rooms.GetValueOrDefault(roomId); } - + // public static MapRoom? Get(this RoomManageComponent self, long roomId) // { // return self.Rooms.GetValueOrDefault(roomId); diff --git a/Main/Properties/launchSettings.json b/Main/Properties/launchSettings.json index 90a0233..c31a6c9 100644 --- a/Main/Properties/launchSettings.json +++ b/Main/Properties/launchSettings.json @@ -3,7 +3,7 @@ "profiles": { "Main": { "commandName": "Project", - "workingDirectory": "$(OutputPath)", +// "workingDirectory": "$(OutputPath)", "environmentVariables": {}, "commandLineArgs": "--m Develop" }