88 lines
2.7 KiB
C#
88 lines
2.7 KiB
C#
/*
|
|
* @Author: 白哉
|
|
* @Description:
|
|
* @Date: 2025年09月08日 星期一 17:09:18
|
|
* @Modify:
|
|
*/
|
|
|
|
|
|
using System;
|
|
using Logic.Action;
|
|
using Logic.AI;
|
|
using RuntimeData;
|
|
using Steamworks;
|
|
using TH1_Logic.Core;
|
|
using UnityEngine;
|
|
|
|
|
|
namespace TH1_Logic.Steam
|
|
{
|
|
public class GameNetSender
|
|
{
|
|
public static GameNetSender Instance { get; } = new GameNetSender();
|
|
|
|
public void SendMessage<T>(T message, bool reliable = true) where T : BaseMessage
|
|
{
|
|
byte[] messageBytes = MemoryPack.MemoryPackSerializer.Serialize(message);
|
|
SteamLobbyManager.Instance.SendMessageToPeer(SteamLobbyManager.Instance.CachedOwner, messageBytes);
|
|
}
|
|
|
|
public void BroadcastMessage<T>(T message, bool reliable = true) where T : BaseMessage
|
|
{
|
|
byte[] messageBytes = MemoryPack.MemoryPackSerializer.Serialize(message);
|
|
SteamLobbyManager.Instance.BroadcastMessage(messageBytes);
|
|
}
|
|
|
|
// 游戏开始
|
|
public void GameStart()
|
|
{
|
|
var data = new GameStartMessage();
|
|
data.MapData = Main.MapData;
|
|
BroadcastMessage(data);
|
|
}
|
|
|
|
// 请求行为 (成员 => 房主)
|
|
public void ActionConfirm(CommonActionId id, CommonActionParams param)
|
|
{
|
|
var actionData = new ActionNetData();
|
|
actionData.Version = Main.MapData.Net.GetActionVersion();
|
|
actionData.MapHash = NetData.GetMapDataHash(Main.MapData);
|
|
actionData.Param = param;
|
|
actionData.ActionId = id;
|
|
|
|
var data = new ActionConfirmMessage();
|
|
data.ActionData = actionData;
|
|
SendMessage(data);
|
|
}
|
|
|
|
// 行为执行 (房主 => 所有成员)
|
|
public void ActionExcute(CommonActionId id, CommonActionParams param)
|
|
{
|
|
var actionData = new ActionNetData();
|
|
actionData.Version = Main.MapData.Net.GetActionVersion();
|
|
actionData.MapHash = NetData.GetMapDataHash(Main.MapData);
|
|
actionData.Param = param;
|
|
actionData.ActionId = id;
|
|
|
|
var data = new ActionExcuteMessage();
|
|
data.ActionData = actionData;
|
|
BroadcastMessage(data);
|
|
}
|
|
|
|
// 请求回合结束 (成员 => 房主)
|
|
public void TurnEndConfirm()
|
|
{
|
|
var data = new TurnEndMessage();
|
|
data.PlayerId = Main.MapData.PlayerMap.SelfPlayerId;
|
|
SendMessage(data);
|
|
}
|
|
|
|
// 回合切换广播 (房主 => 所有成员)
|
|
public void TurnChange(uint playerId)
|
|
{
|
|
var data = new TurnChangeMessage();
|
|
data.PlayerId = playerId;
|
|
BroadcastMessage(data);
|
|
}
|
|
}
|
|
} |