TH1/Unity/Assets/Scripts/TH1_Logic/Steam/SteamObjectSerializer.cs
2026-01-27 15:59:51 +08:00

220 lines
6.6 KiB
C#

/*
* @Author: 白哉
* @Description:
* @Date: 2025年11月05日 星期三 11:11:14
* @Modify:
*/
using Logic;
using Logic.AI;
using MemoryPack;
using RuntimeData;
using System.Collections.Generic;
using TH1_Logic.Chat;
/*
* 房主开始游戏 -> 主端直接开始,广播所有客户端游戏开始,走从端开游戏逻辑
* 游戏开始后
* 回合结束回合开始都由主端进行广播
* 主端回合操作直接通过,广播操作行为,从端复刻
* 从端回合操作发往主端,主端验证完毕后广播操作行为,从端复刻
*/
namespace TH1_Logic.Steam
{
public enum P2PMsgType : byte
{
None = 0,
// 基础字符串消息
String = 1,
// 游戏开始 (房主 => 所有成员)
GameStart = 2,
// 请求行为 (成员 => 房主)
ActionConfirm = 3,
// 行为执行 (房主 => 所有成员)
ActionExcute = 4,
// 请求回合结束 (成员 => 房主)
TurnEnd = 5,
// 游戏校验 (成员 => 房主)
MapConfirm = 6,
// 强制更新 (房主 => 所有成员)
ForceUpdate = 7,
// 组队界面修改阵营 (成员 => 房主)
ChangeCiv = 8,
// 同步游戏房间数据 (房主 => 所有成员)
UpdateLobbyData = 9,
// 请求房间数据 (成员 => 房主)
RequestLobbyData = 10,
// 心跳 (成员 => 房主)
Heartbeat = 11,
// 成员状态同步 (房主 => 所有成员)
MemberStateSync = 12,
// 请求重连 (成员 => 房主)
RequestForceUpdate = 13,
// 心跳包回复 (任意成员 => 任意成员)
HeartbeatReply = 14,
// 聊天
ChatMessage = 15,
// 邀请
InviteMessage = 16,
}
[MemoryPackable]
[MemoryPackUnion(1, typeof(StringMessage))]
[MemoryPackUnion(2, typeof(GameStartMessage))]
[MemoryPackUnion(3, typeof(ActionConfirmMessage))]
[MemoryPackUnion(4, typeof(ActionExcuteMessage))]
[MemoryPackUnion(5, typeof(TurnEndMessage))]
[MemoryPackUnion(6, typeof(MapConfirmMessage))]
[MemoryPackUnion(7, typeof(ForceUpdateMessage))]
[MemoryPackUnion(8, typeof(ChangeCivMessage))]
[MemoryPackUnion(9, typeof(UpdateLobbyDataMessage))]
[MemoryPackUnion(10, typeof(RequestLobbyDataMessage))]
[MemoryPackUnion(11, typeof(HeartbeatMessage))]
[MemoryPackUnion(12, typeof(MemberStateSyncMessage))]
[MemoryPackUnion(13, typeof(RequestForceUpdateMessage))]
[MemoryPackUnion(14, typeof(HeartbeatReplyMessage))]
[MemoryPackUnion(15, typeof(ChatMessage))]
[MemoryPackUnion(16, typeof(InviteMessage))]
public abstract partial class BaseMessage
{
public abstract P2PMsgType MessageType { get; }
}
[MemoryPackable]
public partial class StringMessage : BaseMessage
{
public override P2PMsgType MessageType => P2PMsgType.String;
public string Content { get; set; }
}
[MemoryPackable]
public partial class GameStartMessage : BaseMessage
{
public override P2PMsgType MessageType => P2PMsgType.GameStart;
public MapData MapData { get; set; }
public float Progress { get; set; }
}
[MemoryPackable]
public partial class ActionConfirmMessage : BaseMessage
{
public override P2PMsgType MessageType => P2PMsgType.ActionConfirm;
public ActionNetData ActionData { get; set; }
}
[MemoryPackable]
public partial class ActionExcuteMessage : BaseMessage
{
public override P2PMsgType MessageType => P2PMsgType.ActionExcute;
public ActionNetData ActionData { get; set; }
public MapData Map { get; set; }
}
[MemoryPackable]
public partial class TurnEndMessage : BaseMessage
{
public override P2PMsgType MessageType => P2PMsgType.TurnEnd;
public uint PlayerId { get; set; }
}
[MemoryPackable]
public partial class MapConfirmMessage : BaseMessage
{
public override P2PMsgType MessageType => P2PMsgType.MapConfirm;
public ulong MemberId { get; set; }
public uint PlayerId { get; set; }
public int Index { get; set; }
public ActionNetData ActionData { get; set; }
}
[MemoryPackable]
public partial class ForceUpdateMessage : BaseMessage
{
public override P2PMsgType MessageType => P2PMsgType.ForceUpdate;
public MapData MapData { get; set; }
}
[MemoryPackable]
public partial class ChangeCivMessage : BaseMessage
{
public override P2PMsgType MessageType => P2PMsgType.ChangeCiv;
public MemberCiv Civ { get; set; }
}
[MemoryPackable]
public partial class UpdateLobbyDataMessage : BaseMessage
{
public override P2PMsgType MessageType => P2PMsgType.UpdateLobbyData;
public MapConfig Config { get; set; }
}
[MemoryPackable]
public partial class RequestLobbyDataMessage : BaseMessage
{
public override P2PMsgType MessageType => P2PMsgType.RequestLobbyData;
public ulong MemberId { get; set; }
}
[MemoryPackable]
public partial class HeartbeatMessage : BaseMessage
{
public override P2PMsgType MessageType => P2PMsgType.Heartbeat;
public ulong MemberId { get; set; }
public GameState State { get; set; }
}
[MemoryPackable]
public partial class MemberStateSyncMessage : BaseMessage
{
public override P2PMsgType MessageType => P2PMsgType.MemberStateSync;
public GameState State { get; set; }
public ulong MemberId { get; set; }
public Dictionary<ulong, PlayerConfirmData> PlayerConfirm;
}
[MemoryPackable]
public partial class RequestForceUpdateMessage : BaseMessage
{
public override P2PMsgType MessageType => P2PMsgType.RequestForceUpdate;
public ulong MemberId { get; set; }
}
[MemoryPackable]
public partial class HeartbeatReplyMessage : BaseMessage
{
public override P2PMsgType MessageType => P2PMsgType.HeartbeatReply;
public ulong MemberId { get; set; }
}
[MemoryPackable]
public partial class ChatMessage : BaseMessage
{
public override P2PMsgType MessageType => P2PMsgType.ChatMessage;
public ChatItem Item { get; set; }
}
[MemoryPackable]
public partial class InviteMessage : BaseMessage
{
public override P2PMsgType MessageType => P2PMsgType.InviteMessage;
public LobbyListInfo LobbyInfo { get; set; }
}
}