协议修改

This commit is contained in:
2025-09-25 23:22:07 +08:00
parent ddffaac7b3
commit 5218bc7585
16 changed files with 159 additions and 125 deletions

View File

@@ -6,7 +6,7 @@ package Fantasy.Network.Message;
///用户进入地图 ///用户进入地图
message Map2C_RoleEnterRoomNotify // ICustomRouteMessage,MapRoute 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 message Map2C_RoleStateNotify // ICustomRouteMessage,MapRoute
@@ -34,9 +38,12 @@ message Map2C_RoleGearChangeNotify // ICustomRouteMessage,MapRoute
//玩家属性值变化 //玩家属性值变化
message Map2C_RolePropertyChangeNotify // 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 Rotation = 2; //角色方向
Vector3Info Direction = 3; // 移动方向 Vector3Info Direction = 3; // 移动方向
bool IsStop = 4; // 是否是停止移动 bool IsStop = 4; // 是否是停止移动
int64 Timestamp = 5; // 时间点 bool IsRun = 5;
int64 Timestamp = 6; // 时间点
} }
// 角色朝向变化 // 角色朝向变化

View File

@@ -13,26 +13,12 @@ message RoleBaseInfo
VipInfo VipInfo = 7; //vip信息 VipInfo VipInfo = 7; //vip信息
} }
message KeyValueStringInt64
{
string Key = 1; //键
int64 Value = 2; //值
}
message KeyValueInt32
{
int32 Key = 1; //键
int32 Value = 2; //值
}
message KeyValueInt64 message KeyValueInt64
{ {
int64 Key = 1; //键 int32 Key = 1; //键
int64 Value = 2; //值 int64 Value = 2; //
}
message KeyValueString
{
string Key = 1; //键
string Value = 2; //值
} }
@@ -105,7 +91,7 @@ message ActivityInfo
int64 Id = 1; //活动id int64 Id = 1; //活动id
int64 StartTime = 2; //开始时间 int64 StartTime = 2; //开始时间
int64 EndTime = 3; //结束时间 int64 EndTime = 3; //结束时间
repeated KeyValueStringInt64 Data = 4; //活动数据 repeated KeyValueInt64 Data = 4; //活动数据
} }
///技能情况 ///技能情况

View File

@@ -23,20 +23,17 @@ message QuaternionInfo
message GearInfo message GearInfo
{ {
int64 Rod = 1; int64 Rod = 1;
repeated int64 Rigs = 2; //钓组配件 repeated int64 Rigs = 2; //钓组配件
float LineLength = 3; //线长度 Vector3Info Position = 3; //钓组当前位置
float ReelSpeed = 4; //收线速度 Vector3Info Rotation = 4; //钓组方向
int32 State = 5; //杆子状态 repeated KeyValueInt64 Propertys = 5; //钓组参数信息
Vector3Info Position = 6; //钓组当前位置
Vector3Info Rotation = 7; //钓组方向
} }
message UnitStateInfo message UnitStateInfo
{ {
int32 State = 1; //状态id int32 State = 1; //状态id
repeated string Args = 2; //状态参数 repeated KeyValueInt64 Propertys = 2; //状态参数信息
} }
message MapUnitInfo message MapUnitInfo
@@ -46,7 +43,7 @@ message MapUnitInfo
Vector3Info Position = 3; //当前位置 Vector3Info Position = 3; //当前位置
Vector3Info Rotation = 4; //角色方向 Vector3Info Rotation = 4; //角色方向
UnitStateInfo State = 5; //状态信息 UnitStateInfo State = 5; //状态信息
repeated GearInfo Gears = 7; //钓组数据 repeated GearInfo Gears = 6; //钓组数据
repeated KeyValueInt32 Propertys = 8; //属性信息 repeated KeyValueInt64 Propertys = 7; //属性信息
} }

View File

@@ -56,46 +56,6 @@ namespace Fantasy
public VipInfo VipInfo { get; set; } public VipInfo VipInfo { get; set; }
} }
[ProtoContract] [ProtoContract]
public partial class KeyValueStringInt64 : AMessage, IProto
{
public static KeyValueStringInt64 Create(Scene scene)
{
return scene.MessagePoolComponent.Rent<KeyValueStringInt64>();
}
public override void Dispose()
{
Key = default;
Value = default;
#if FANTASY_NET || FANTASY_UNITY
GetScene().MessagePoolComponent.Return<KeyValueStringInt64>(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<KeyValueInt32>();
}
public override void Dispose()
{
Key = default;
Value = default;
#if FANTASY_NET || FANTASY_UNITY
GetScene().MessagePoolComponent.Return<KeyValueInt32>(this);
#endif
}
[ProtoMember(1)]
public int Key { get; set; }
[ProtoMember(2)]
public int Value { get; set; }
}
[ProtoContract]
public partial class KeyValueInt64 : AMessage, IProto public partial class KeyValueInt64 : AMessage, IProto
{ {
public static KeyValueInt64 Create(Scene scene) public static KeyValueInt64 Create(Scene scene)
@@ -111,30 +71,10 @@ namespace Fantasy
#endif #endif
} }
[ProtoMember(1)] [ProtoMember(1)]
public long Key { get; set; } public int Key { get; set; }
[ProtoMember(2)] [ProtoMember(2)]
public long Value { get; set; } public long Value { get; set; }
} }
[ProtoContract]
public partial class KeyValueString : AMessage, IProto
{
public static KeyValueString Create(Scene scene)
{
return scene.MessagePoolComponent.Rent<KeyValueString>();
}
public override void Dispose()
{
Key = default;
Value = default;
#if FANTASY_NET || FANTASY_UNITY
GetScene().MessagePoolComponent.Return<KeyValueString>(this);
#endif
}
[ProtoMember(1)]
public string Key { get; set; }
[ProtoMember(2)]
public string Value { get; set; }
}
/// <summary> /// <summary>
/// 角色信息 /// 角色信息
/// </summary> /// </summary>
@@ -357,7 +297,7 @@ namespace Fantasy
[ProtoMember(3)] [ProtoMember(3)]
public long EndTime { get; set; } public long EndTime { get; set; }
[ProtoMember(4)] [ProtoMember(4)]
public List<KeyValueStringInt64> Data = new List<KeyValueStringInt64>(); public List<KeyValueInt64> Data = new List<KeyValueInt64>();
} }
/// <summary> /// <summary>
/// 技能情况 /// 技能情况

View File

@@ -70,7 +70,7 @@ namespace Fantasy
public uint ErrorCode { get; set; } public uint ErrorCode { get; set; }
} }
/// <summary> /// <summary>
/// 请求网关离开房间 /// 请求网关离开房间(离开房间,但是不离开地图)
/// </summary> /// </summary>
[ProtoContract] [ProtoContract]
public partial class C2G_ExitRoomRequest : AMessage, IRequest, IProto public partial class C2G_ExitRoomRequest : AMessage, IRequest, IProto

View File

@@ -100,11 +100,9 @@ namespace Fantasy
{ {
Rod = default; Rod = default;
Rigs.Clear(); Rigs.Clear();
LineLength = default;
ReelSpeed = default;
State = default;
Position = default; Position = default;
Rotation = default; Rotation = default;
Propertys.Clear();
#if FANTASY_NET || FANTASY_UNITY #if FANTASY_NET || FANTASY_UNITY
GetScene().MessagePoolComponent.Return<GearInfo>(this); GetScene().MessagePoolComponent.Return<GearInfo>(this);
#endif #endif
@@ -114,15 +112,11 @@ namespace Fantasy
[ProtoMember(2)] [ProtoMember(2)]
public List<long> Rigs = new List<long>(); public List<long> Rigs = new List<long>();
[ProtoMember(3)] [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; } public Vector3Info Position { get; set; }
[ProtoMember(7)] [ProtoMember(4)]
public Vector3Info Rotation { get; set; } public Vector3Info Rotation { get; set; }
[ProtoMember(5)]
public List<KeyValueInt64> Propertys = new List<KeyValueInt64>();
} }
[ProtoContract] [ProtoContract]
public partial class UnitStateInfo : AMessage, IProto public partial class UnitStateInfo : AMessage, IProto
@@ -134,7 +128,7 @@ namespace Fantasy
public override void Dispose() public override void Dispose()
{ {
State = default; State = default;
Args.Clear(); Propertys.Clear();
#if FANTASY_NET || FANTASY_UNITY #if FANTASY_NET || FANTASY_UNITY
GetScene().MessagePoolComponent.Return<UnitStateInfo>(this); GetScene().MessagePoolComponent.Return<UnitStateInfo>(this);
#endif #endif
@@ -142,7 +136,7 @@ namespace Fantasy
[ProtoMember(1)] [ProtoMember(1)]
public int State { get; set; } public int State { get; set; }
[ProtoMember(2)] [ProtoMember(2)]
public List<string> Args = new List<string>(); public List<KeyValueInt64> Propertys = new List<KeyValueInt64>();
} }
[ProtoContract] [ProtoContract]
public partial class MapUnitInfo : AMessage, IProto public partial class MapUnitInfo : AMessage, IProto
@@ -177,6 +171,6 @@ namespace Fantasy
[ProtoMember(6)] [ProtoMember(6)]
public List<GearInfo> Gears = new List<GearInfo>(); public List<GearInfo> Gears = new List<GearInfo>();
[ProtoMember(7)] [ProtoMember(7)]
public List<KeyValueInt32> Propertys = new List<KeyValueInt32>(); public List<KeyValueInt64> Propertys = new List<KeyValueInt64>();
} }
} }

View File

@@ -18,28 +18,29 @@ namespace Fantasy
public const uint Game2C_GetRoleInfoResponse = 2415929106; public const uint Game2C_GetRoleInfoResponse = 2415929106;
public const uint Map2C_RoleEnterRoomNotify = 2147493650; public const uint Map2C_RoleEnterRoomNotify = 2147493650;
public const uint Map2C_RoleExitRoomNotify = 2147493651; public const uint Map2C_RoleExitRoomNotify = 2147493651;
public const uint Map2C_RoleStateNotify = 2147493652; public const uint C2Map_RolePropertyChange = 2147493652;
public const uint Map2C_RoleGearChangeNotify = 2147493653; public const uint Map2C_RoleStateNotify = 2147493653;
public const uint Map2C_RolePropertyChangeNotify = 2147493654; public const uint Map2C_RoleGearChangeNotify = 2147493654;
public const uint C2Map_Move = 2147493655; public const uint Map2C_RolePropertyChangeNotify = 2147493655;
public const uint C2Map_Look = 2147493656; public const uint C2Map_Move = 2147493656;
public const uint Map2C_MoveNotify = 2147493657; public const uint C2Map_Look = 2147493657;
public const uint Map2C_LookeNotify = 2147493658; public const uint Map2C_MoveNotify = 2147493658;
public const uint Map2C_LookeNotify = 2147493659;
public const uint C2S_GetConversationsRequest = 2281711379; public const uint C2S_GetConversationsRequest = 2281711379;
public const uint S2C_GetConversationsResponse = 2415929107; public const uint S2C_GetConversationsResponse = 2415929107;
public const uint C2S_SendMailRequest = 2281711380; public const uint C2S_SendMailRequest = 2281711380;
public const uint S2C_SendMailResponse = 2415929108; public const uint S2C_SendMailResponse = 2415929108;
public const uint C2S_DeleteMailRequest = 2281711381; public const uint C2S_DeleteMailRequest = 2281711381;
public const uint S2C_DeleteMailResponse = 2415929109; public const uint S2C_DeleteMailResponse = 2415929109;
public const uint S2C_HaveMail = 2147493659; public const uint S2C_HaveMail = 2147493660;
public const uint S2C_MailState = 2147493660; public const uint S2C_MailState = 2147493661;
public const uint C2S_CreateChannelRequest = 2281711382; public const uint C2S_CreateChannelRequest = 2281711382;
public const uint S2C_CreateChannelResponse = 2415929110; public const uint S2C_CreateChannelResponse = 2415929110;
public const uint C2S_JoinChannelRequest = 2281711383; public const uint C2S_JoinChannelRequest = 2281711383;
public const uint S2C_JoinChannelResponse = 2415929111; public const uint S2C_JoinChannelResponse = 2415929111;
public const uint C2S_SendMessageRequest = 2281711384; public const uint C2S_SendMessageRequest = 2281711384;
public const uint S2C_SendMessageResponse = 2415929112; 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 C2S_CreateClubRequest = 2281711385;
public const uint S2C_CreateClubResponse = 2415929113; public const uint S2C_CreateClubResponse = 2415929113;
public const uint C2S_GetClubInfoRequest = 2281711386; public const uint C2S_GetClubInfoRequest = 2281711386;
@@ -56,6 +57,6 @@ namespace Fantasy
public const uint S2C_DissolveClubResponse = 2415929119; public const uint S2C_DissolveClubResponse = 2415929119;
public const uint C2S_DisposeJoinRequest = 2281711392; public const uint C2S_DisposeJoinRequest = 2281711392;
public const uint S2C_DisposeJoinResponse = 2415929120; public const uint S2C_DisposeJoinResponse = 2415929120;
public const uint S2C_ClubChange = 2147493662; public const uint S2C_ClubChange = 2147493663;
} }
} }

View File

@@ -63,6 +63,26 @@ namespace Fantasy
[ProtoMember(1)] [ProtoMember(1)]
public long Id { get; set; } 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<C2Map_RolePropertyChange>();
}
public override void Dispose()
{
Propertys.Clear();
#if FANTASY_NET || FANTASY_UNITY
GetScene().MessagePoolComponent.Return<C2Map_RolePropertyChange>(this);
#endif
}
public uint OpCode() { return OuterOpcode.C2Map_RolePropertyChange; }
[ProtoIgnore]
public int RouteType => Fantasy.RouteType.MapRoute;
[ProtoMember(1)]
public List<KeyValueInt64> Propertys = new List<KeyValueInt64>();
}
/// <summary> /// <summary>
/// 玩家状态变化同步 /// 玩家状态变化同步
/// </summary> /// </summary>
@@ -124,6 +144,7 @@ namespace Fantasy
} }
public override void Dispose() public override void Dispose()
{ {
Id = default;
Propertys.Clear(); Propertys.Clear();
#if FANTASY_NET || FANTASY_UNITY #if FANTASY_NET || FANTASY_UNITY
GetScene().MessagePoolComponent.Return<Map2C_RolePropertyChangeNotify>(this); GetScene().MessagePoolComponent.Return<Map2C_RolePropertyChangeNotify>(this);
@@ -133,7 +154,9 @@ namespace Fantasy
[ProtoIgnore] [ProtoIgnore]
public int RouteType => Fantasy.RouteType.MapRoute; public int RouteType => Fantasy.RouteType.MapRoute;
[ProtoMember(1)] [ProtoMember(1)]
public List<KeyValueInt32> Propertys = new List<KeyValueInt32>(); public long Id { get; set; }
[ProtoMember(2)]
public List<KeyValueInt64> Propertys = new List<KeyValueInt64>();
} }
[ProtoContract] [ProtoContract]
public partial class C2Map_Move : AMessage, ICustomRouteMessage, IProto public partial class C2Map_Move : AMessage, ICustomRouteMessage, IProto
@@ -148,6 +171,7 @@ namespace Fantasy
Rotation = default; Rotation = default;
Direction = default; Direction = default;
IsStop = default; IsStop = default;
IsRun = default;
Timestamp = default; Timestamp = default;
#if FANTASY_NET || FANTASY_UNITY #if FANTASY_NET || FANTASY_UNITY
GetScene().MessagePoolComponent.Return<C2Map_Move>(this); GetScene().MessagePoolComponent.Return<C2Map_Move>(this);
@@ -165,6 +189,8 @@ namespace Fantasy
[ProtoMember(4)] [ProtoMember(4)]
public bool IsStop { get; set; } public bool IsStop { get; set; }
[ProtoMember(5)] [ProtoMember(5)]
public bool IsRun { get; set; }
[ProtoMember(6)]
public long Timestamp { get; set; } public long Timestamp { get; set; }
} }
[ProtoContract] [ProtoContract]

View File

@@ -53,9 +53,7 @@ public class G2Common_ExitRequestHandler : RouteRPC<Scene, G2Common_ExitRequest,
private async FTask RunMap(Scene scene, G2Common_ExitRequest request, Common2G_ExitResponse response) private async FTask RunMap(Scene scene, G2Common_ExitRequest request, Common2G_ExitResponse response)
{ {
// 在缓存中检查该账号是否存在 await MapHelper.Offline(scene, request.AccountId, request.GateRouteId);
var chatUnitManageComponent = scene.GetComponent<MapUnitManageComponent>();
await chatUnitManageComponent.Offline(scene, request.AccountId, request.GateRouteId);
Log.Info("退出房间服成功=="); Log.Info("退出房间服成功==");
} }
} }

View File

@@ -29,6 +29,7 @@ public class C2Map_LookHandler : Route<MapUnit, C2Map_Look>
foreach (var (_, unit) in room.Units) foreach (var (_, unit) in room.Units)
{ {
// if (unit.Id == entity.Id) continue;
entity.Scene.NetworkMessagingComponent.SendInnerRoute(unit.GateRouteId, notifyMessage); entity.Scene.NetworkMessagingComponent.SendInnerRoute(unit.GateRouteId, notifyMessage);
} }

View File

@@ -37,6 +37,7 @@ public class C2Map_MoveHandler : Route<MapUnit, C2Map_Move>
foreach (var (_, unit) in room.Units) foreach (var (_, unit) in room.Units)
{ {
// if (unit.Id == entity.Id) continue;
entity.Scene.NetworkMessagingComponent.SendInnerRoute(unit.GateRouteId, notifyMessage); entity.Scene.NetworkMessagingComponent.SendInnerRoute(unit.GateRouteId, notifyMessage);
} }

View File

@@ -0,0 +1,34 @@
using Fantasy;
using Fantasy.Async;
using Fantasy.Network.Interface;
namespace NB.Map;
public class C2Map_RolePropertyChangeHandler : Route<MapUnit, C2Map_RolePropertyChange>
{
protected override async FTask Run(MapUnit entity, C2Map_RolePropertyChange message)
{
var roomManageComponent = entity.Scene.GetComponent<RoomManageComponent>();
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;
}
}

View File

@@ -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<MapUnitManageComponent>();
if (chatUnitManageComponent == null) return;
var mapUnit = chatUnitManageComponent.Get(accountId);
if (mapUnit == null) return;
var roomManageComponent = scene.GetComponent<RoomManageComponent>();
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);
}
}

View File

@@ -38,6 +38,12 @@ public static class MapRoomSystem
return ErrorCode.Successful; return ErrorCode.Successful;
} }
public static async FTask Exit(this MapRoom self, long id)
{
self.Units.Remove(id);
await FTask.CompletedTask;
}
public static List<MapUnitInfo> ToMapUnitInfo(this MapRoom self) public static List<MapUnitInfo> ToMapUnitInfo(this MapRoom self)
{ {
List<MapUnitInfo> ret = new List<MapUnitInfo>(); List<MapUnitInfo> ret = new List<MapUnitInfo>();

View File

@@ -66,11 +66,23 @@ public static class RoomManageComponentSystem
return true; 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) public static MapRoom? Get(this RoomManageComponent self, int roomId)
{ {
return self.Rooms.GetValueOrDefault(roomId); return self.Rooms.GetValueOrDefault(roomId);
} }
// public static MapRoom? Get(this RoomManageComponent self, long roomId) // public static MapRoom? Get(this RoomManageComponent self, long roomId)
// { // {
// return self.Rooms.GetValueOrDefault(roomId); // return self.Rooms.GetValueOrDefault(roomId);

View File

@@ -3,7 +3,7 @@
"profiles": { "profiles": {
"Main": { "Main": {
"commandName": "Project", "commandName": "Project",
"workingDirectory": "$(OutputPath)", // "workingDirectory": "$(OutputPath)",
"environmentVariables": {}, "environmentVariables": {},
"commandLineArgs": "--m Develop" "commandLineArgs": "--m Develop"
} }