diff --git a/BotrisBattle.NET/BotrisBot.cs b/BotrisBattle.NET/BotrisBot.cs index 427c179..812ecf0 100644 --- a/BotrisBattle.NET/BotrisBot.cs +++ b/BotrisBattle.NET/BotrisBot.cs @@ -8,8 +8,8 @@ public class BotrisBot public event Action GameStart; public event Action GameReset; - public event Action RequestMove; + public event Action UpdateConfig; public void SendMove(Command[] commands) { @@ -27,9 +27,14 @@ public BotrisBot(string token) { _websocket = new BotrisWebsocket(token); - _websocket.On("roomData", (payload) => + _websocket.On("room_data", payload => { - //Console.WriteLine("房间信息:{0}", payload.roomData.id); + UpdateConfig?.Invoke( + new UpdateConfigPayload + { + Duration = (int)Math.Floor(1000 / payload.roomData.pps) + } + ); }); _websocket.On("authenticated", (payload) => @@ -37,10 +42,7 @@ public BotrisBot(string token) //Console.WriteLine("认证成功:{0}", payload.SessionId); }); - _websocket.On("game_started", () => - { - GameStart?.Invoke(); - }); + _websocket.On("game_started", () => { GameStart?.Invoke(); }); _websocket.On("request_move", (payload) => { @@ -48,19 +50,13 @@ public BotrisBot(string token) RequestMove?.Invoke(payload); }); - _websocket.On("game_reset", () => - { - GameReset?.Invoke(); - }); + _websocket.On("game_reset", () => { GameReset?.Invoke(); }); } - public async void Connect(string room, CancellationToken token) { await _websocket.Connect(room, token); } - - } -} +} \ No newline at end of file diff --git a/BotrisBattle.NET/BotrisType.cs b/BotrisBattle.NET/BotrisType.cs index 80f601f..194d271 100644 --- a/BotrisBattle.NET/BotrisType.cs +++ b/BotrisBattle.NET/BotrisType.cs @@ -5,6 +5,8 @@ using System.Text.Json; using System.Threading.Tasks; +// ReSharper disable InconsistentNaming + namespace BotrisBattle.NET { @@ -22,9 +24,9 @@ public class GameEvent: BotrisMessage; public class PlayerInfo { - public string userId { get; set; } - public string creator { get; set; } - public string bot { get; set; } + public required string userId { get; set; } + public required string creator { get; set; } + public required string bot { get; set; } } public class PlayerData @@ -66,12 +68,11 @@ public class GameState public class RoomData { - public string id { get; set; } - public PlayerInfo host { get; set; } + public required string id { get; set; } + public required PlayerInfo host { get; set; } public bool @private { get; set; } public int ft { get; set; } - public int initialPps { get; set; } - public int finalPps { get; set; } + public double pps { get; set; } public int startMargin { get; set; } public int endMargin { get; set; } public int maxPlayers { get; set; } @@ -79,9 +80,9 @@ public class RoomData public bool roundOngoing { get; set; } public long? startedAt { get; set; } public long? endedAt { get; set; } - public string lastWinner { get; set; } // Assuming SessionId is a string - public List players { get; set; } - public List banned { get; set; } + public string? lastWinner { get; set; } + public List players { get; set; } = []; + public List banned { get; set; } = []; } // Enum for Piece diff --git a/BotrisBattle.NET/PayloadType.cs b/BotrisBattle.NET/PayloadType.cs index 73345b0..7386c2e 100644 --- a/BotrisBattle.NET/PayloadType.cs +++ b/BotrisBattle.NET/PayloadType.cs @@ -21,64 +21,53 @@ public class ErrorPayload public string Payload { get; set; } } - public class PlayerJoinedPayload { public PlayerData PlayerData { get; set; } } - - public class PlayerLeftPayload { public string SessionId { get; set; } } - - public class PlayerBannedPayload { public PlayerInfo PlayerInfo { get; set; } } - public class PlayerUnbannedPayload { public PlayerInfo PlayerInfo { get; set; } } + public class SettingsChangedPayload { public RoomData RoomData { get; set; } } - public class HostChangedPayload { public PlayerInfo HostInfo { get; set; } } - - public class RoundStartedPayload { public long StartsAt { get; set; } public RoomData RoomData { get; set; } } - public class RequestMovePayload { public GameState GameState { get; set; } public List Players { get; set; } } - public class ActionPayload { public Command[] Commands { get; set; } } - public class PlayerActionPayload { public string SessionId { get; set; } @@ -94,7 +83,6 @@ public class PlayerDamageReceivedPayload public GameState GameState { get; set; } } - public class RoundOverPayload { public string WinnerId { get; set; } @@ -102,7 +90,6 @@ public class RoundOverPayload public RoomData RoomData { get; set; } } - public class GameOverPayload { public string WinnerId { get; set; } @@ -110,9 +97,13 @@ public class GameOverPayload public RoomData RoomData { get; set; } } - public class GameResetPayload { public RoomData RoomData { get; set; } } -} + + public class UpdateConfigPayload + { + public int Duration = 1; + } +} \ No newline at end of file