XNet/XNet.Business/Dto/SyncMsg.cs
2025-12-30 17:55:08 +08:00

311 lines
7.8 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using MessagePack;
using XNet.Business.Dto;
using XNet.Business.Net;
namespace XNet.Business
{
// WebSocket消息类型枚举
public enum WsMsgType : ushort
{
SUBSCRIBE_ROOM = 0x0000, // 客户端订阅实例
/// <summary>
/// 登录
/// </summary>
LOGIN = 0x0001,
/// <summary>
/// 房间群发信息
/// </summary>
ROOM_MSG = 0x0002,
/// <summary>
/// 房间群发信息,自己不接收
/// </summary>
ROOM_MSG_OTHER = 0x0003,
/// <summary>
/// 用户下线
/// </summary>
OFFLINE = 0x0004,
/// <summary>
/// 用户做主机
/// </summary>
HOST = 0x0005,
/// <summary>
/// 本局游戏结束
/// </summary>
GAME_END = 0x0006,
/// <summary>
/// 心跳包请求
/// </summary>
HEART_BEAT = 0x0007,
/// <summary>
/// 心跳包响应
/// </summary>
HEART_BEAT_REPLY = 0x0008,
/// <summary>
/// 加入或者创建房间
/// </summary>
CREATE_OR_JOIN_ROOM = 0x0009,
/// <summary>
/// 个人私有的消息
/// </summary>
PRIVATGE = 0x0010,
/// <summary>
/// 添加AI玩家
/// </summary>
ADD_AI_PLAYER = 0x0011,
/// <summary>
/// 删除所有AI
/// </summary>
DELETE_ALL_AI_PLAYER = 0x0012,
/// <summary>
/// 发送给自己的消息
/// </summary>
TO_SELF = 0x0013,
/// <summary>
/// 公开或者关闭房间
/// </summary>
ENABLE_ROOM_PUBLIC = 0x0014,
/// <summary>
/// 启用或者关闭AI
/// </summary>
ENABLE_AI = 0x0015,
/// <summary>
/// 游戏将要结束,改变倒计时文字为闪烁或红色
/// </summary>
GAME_WILLOVER = 0x0016,
/// <summary>
/// 本局游戏将要结束
/// </summary>
GAME_WILL_END = 0x0017,
/// <summary>
/// Agent位置同步消息
/// </summary>
AGENT_POSITION_SYNC = 0x0018,
/// <summary>
/// Agent角度同步消息
/// </summary>
AGENT_ROTATION_SYNC = 0x0019,
/// <summary>
/// 更改房间地图信息
/// </summary>
CHANGE_ROOM_KEY_NAME = 0x1016,
}
[MessagePackObject]
public class SubscribeRoom
{
[Key("roomId")]
public string RoomId { get; set; } = string.Empty;
}
// 客户端订阅实例的请求消息
[MessagePackObject]
public class CreateOrJoinRoomReq
{
[Key("roomId")]
public string RoomId { get; set; } = string.Empty;
[Key("headImageUrl")]
public string HeadImageUrl { get; set; } = string.Empty;
[Key("mapKey")]
public string MapKey { get; set; } = string.Empty;
[Key("aiCount")]
public int AICount { get; set; } = 0;
[Key("nickName")]
public string NickName { get; set; } = string.Empty;
[Key("playerId")]
public string PlayerId { get; set; } = string.Empty;
}
[MessagePackObject]
public class PlayerPosReq
{
[Key("roomId")]
public string RoomId { get; set; } = string.Empty;
[Key("isAI")]
public bool IsAI { get; set; } = false;
[Key("endPos")]
public Vec3? EndPos { get; set; }
}
[MessagePackObject]
public class PlayerInitReq
{
[Key("roomId")]
public string RoomId { get; set; } = string.Empty;
[Key("isAI")]
public bool IsAI { get; set; } = false;
[Key("hostPlayerId")]
public string HostPlayerId { get; set; } = string.Empty;
[Key("playerId")]
public string PlayerId { get; set; } = string.Empty;
[Key("nickName")]
public string NickName { get; set; } = string.Empty;
[Key("findFaceDistance")]
public float FindFaceDistance { get; set; } = 0;
[Key("radius")]
public float Radius { get; set; } = 0;
[Key("attackPower")]
public float AttackPower { get; set; } = 0;
[Key("armor")]
public float Armor { get; set; } = 0;
[Key("speed")]
public float Speed { get; set; } = 0;
[Key("blood")]
public float Blood { get; set; } = 0;
[Key("bodyIdx")]
public int BodyIdx { get; set; } = 0;
[Key("weaponIdx")]
public int WeaponIdx { get; set; } = 0;
[Key("armorIdx")]
public int ArmorIdx { get; set; } = 0;
[Key("chassisIdx")]
public int ChassisIdx { get; set; } = 0;
[Key("deviceColor")]
public string DeviceColor { get; set; } = "#FFFFFF";
[Key("startPos")]
public Vec3? StartPos { get; set; }
[Key("euler")]
public Vec3? Euler { get; set; }
}
// 客户端订阅实例的请求消息
[MessagePackObject]
public class SubscribeInstanceReq
{
[Key("roomId")]
public string RoomId { get; set; } = string.Empty;
[Key("mapKey")]
public string MapKey { get; set; } = string.Empty;
}
[MessagePackObject]
public class EnterRoomReply
{
[Key("type")]
public WsMsgType Type { get; set; }
[Key("mapKey")]
public string MapKey { get; set; } = string.Empty;
}
// Agent位置同步消息服务端推送
[MessagePackObject]
public class AgentLocationSyncMsg
{
[Key("agentIdx")]
public int AgentIdx { get; set; }
[Key("position")]
public Vec3? Position { get; set; }
[Key("rotation")]
public Vec3? Rotation { get; set; }
}
/// <summary>
/// 房间信息
/// </summary>
[MessagePackObject]
public class BaseRoomMsg<T>
{
[Key("roomId")]
public string RoomId { get; set; } = string.Empty;
[Key("type")]
public WsMsgType Type { get; set; }
[Key("senderId")]
public string SenderId { get; set; } = string.Empty;
[Key("data")]
public T? Data { get; set; } = default;
}
/// <summary>
/// 房间用户同步信息
/// </summary>
[MessagePackObject]
public class RoomUserSync
{
[Key("type")]
public WsMsgType Type { get; set; }
[Key("roomId")]
public string RoomId { get; set; } = string.Empty;
[Key("playerId")]
public string PlayerId { get; set; } = string.Empty;
[Key("nickName")]
public string NickName { get; set; } = string.Empty;
[Key("headImageUrl")]
public string? HeadImageUrl { get; set; } = null;
[Key("setIdx")]
public int SetIdx { get; set; } = 0;
[Key("isPublic")]
public bool IsPublic { get; set; } = true;
}
/// <summary>
/// 消息基类
/// </summary>
[MessagePackObject]
public class TypeBaseMsg<T>
{
[Key("type")]
public WsMsgType Type { get; set; }
[Key("senderId")]
public string SenderId { get; set; } = string.Empty;
[Key("data")]
public T? Data { get; set; } = default;
}
/// <summary>
/// 消息基类
/// </summary>
[MessagePackObject]
public class BaseMsg
{
[Key("type")]
public WsMsgType Type { get; set; }
[Key("senderId")]
public string SenderId { get; set; } = string.Empty;
[Key("data")]
public byte[]? Data { get; set; } = default;
}
//// WebSocket通用消息包装
//[MessagePackObject]
//public class WsMessage<T>
//{
// [Key("type")]
// public WsMsgType Type { get; set; }
// [Key("data")]
// public T? Data { get; set; } = default;
//}
}