Remote dveře lze na mapě otevírat a zavírat. Office dveře hráče lze vidět na mapě (ukazují se ale pouze pro hráče 1). PlayerCommandy, které přepínají mezi dvěma stavy mají přidaný parametr state - client tudíž určuje jejich nový stav. Pokud se neshoduje stav v GameEventu se stavem odeslaným v Commandu, zobrazí se v konzoli varování. Client již nečeká na odpověď serveru při změně UI. Connectory se neklonují, oba tily používají stejnou instanci.

This commit is contained in:
Perry 2026-02-21 18:42:44 +01:00
parent 70b5debb22
commit cea56112ea
14 changed files with 112 additions and 48 deletions

View file

@ -79,7 +79,7 @@ public class Client {
ClientMapManager.InitMap(); ClientMapManager.InitMap();
TileConnectorProjection[] connectors = connectorsData.Select(c => new TileConnectorProjection(ClientMapManager.Get(c.id1), ClientMapManager.Get(c.id2), c.type)).ToArray(); TileConnectorProjection[] connectors = connectorsData.Select(c => new TileConnectorProjection(ClientMapManager.Get(c.id1), ClientMapManager.Get(c.id2), c.type)).ToArray();
ClientMapManager.InitConnectors(connectors); ClientMapManager.InitConnectors(connectors);
UIManager.SpawnDoors(connectors); UIManager.SpawnDoors(connectors.Where(c => c.Type == ConnectorType.DOOR_REMOTE).ToArray());
} }
public static void Update() { public static void Update() {
@ -99,21 +99,26 @@ public class Client {
Console.WriteLine("E: Player left"); Console.WriteLine("E: Player left");
break; break;
case 2: // switch cam case 2: // switch cam
if (Player.state.pid == e.Args[0]){ if (Player.state.pid != e.Args[0]) return;
Player.state.camera = e.Args[1]; if (Player.state.camera != e.Args[1]) Console.WriteLine("!!! DESYNC: CAMERA STATE");
} Console.WriteLine($"E: player {e.Args[0]} switched to camera {e.Args[1]}");
Console.WriteLine($"E: player {e.Args[0]} switched to camera {e.Args[1]}-{e.Args[2]}");
break; break;
case 3: // toggle cam case 3: // toggle cam
Player.state.monitorUp = e.Args[1] == 1; if (Player.state.monitorUp != (e.Args[1] == 1)) Console.WriteLine("!!! DESYNC: MONITOR STATE");
UIManager.ChangeMonitorState(e.Args[1] == 1); UIManager.ChangeMonitorState(e.Args[1] == 1);
Console.WriteLine($"E: Player {e.Args[0]} toggled monitor {(e.Args[1] == 0 ? "off" : "on")}"); Console.WriteLine($"E: Player {e.Args[0]} toggled monitor {(e.Args[1] == 0 ? "off" : "on")}");
break; break;
case 4: // toggle door case 4: // toggle door
Player.state.doorStates[e.Args[1]] = e.Args[2] == 1; if (Player.state.doorStates[e.Args[1]] != (e.Args[2] == 1)) Console.WriteLine("!!! DESYNC: DOOR STATE");
UIManager.ChangeDoorState((Direction)e.Args[1], e.Args[2] == 1);
// UIManager.ChangeDoorState((Direction)e.Args[1], e.Args[2] == 1);
Console.WriteLine($"E: Player {e.Args[0]} {(e.Args[2] == 1 ? "closed" : "opened")} door {e.Args[1]}"); Console.WriteLine($"E: Player {e.Args[0]} {(e.Args[2] == 1 ? "closed" : "opened")} door {e.Args[1]}");
break; break;
case 5: // toggle remote door
if (ClientMapManager.GetConnector((e.Args[1], e.Args[2])).Blocked != (e.Args[3] == 1)) Console.WriteLine("!!! DESYNC: REMOTE DOOR STATE");
Console.WriteLine($"E: Player {e.Args[0]} {(e.Args[3] == 1 ? "closed" : "opened")} door {e.Args[1]}-{e.Args[2]}");
break;
case -1: // movement case -1: // movement
throw new NotImplementedException(); throw new NotImplementedException();

View file

@ -26,7 +26,8 @@ public class CommandManager {
} }
private static void SendToggleCamera() { private static void SendToggleCamera() {
Client.SendCommands([PlayerCommand.TOGGLE_MONITOR()]); Client.Player.state.monitorUp = !Client.Player.state.monitorUp;
Client.SendCommands([PlayerCommand.SET_MONITOR(Client.Player.state.monitorUp)]);
} }
private static void ToggleDoorLeft() => SendToggleDoor(Direction.EAST); private static void ToggleDoorLeft() => SendToggleDoor(Direction.EAST);
@ -34,23 +35,38 @@ public class CommandManager {
private static void ToggleDoorRight() => SendToggleDoor(Direction.WEST); private static void ToggleDoorRight() => SendToggleDoor(Direction.WEST);
private static void ToggleDoorBack() => SendToggleDoor(Direction.SOUTH); private static void ToggleDoorBack() => SendToggleDoor(Direction.SOUTH);
private static Dictionary<Direction, TileConnectorProjection> currentDoorBinds = new();
private static void SendToggleDoor(Direction direction) { private static void SendToggleDoor(Direction direction) {
if (Screen.CurrentScreen.Label == UIManager.ScreenTypes.CAMERAS){ if (Screen.CurrentScreen.Label == UIManager.ScreenTypes.CAMERAS){
SendToggleRemoteDoor(direction); SendToggleRemoteDoor(direction);
return; return;
} }
Client.SendCommands([PlayerCommand.TOGGLE_DOOR_OFFICE(direction)]); Client.Player.state.doorStates[(int)direction] = !Client.Player.state.doorStates[(int)direction];
UIManager.ChangeDoorState(direction, Client.Player.state.doorStates[(int)direction]);
Client.SendCommands([PlayerCommand.SET_DOOR_OFFICE(direction, Client.Player.state.doorStates[(int)direction])]);
} }
private static void SendToggleRemoteDoor(Direction direction) { // WIP private static void SendToggleRemoteDoor(Direction direction) {
TileConnectorProjection[] connectors = ClientMapManager.GetConnectors(Client.Player.state.camera).Where(c => c.Type == ConnectorType.DOOR_REMOTE).ToArray(); if (!currentDoorBinds.TryGetValue(direction, out var val)) return;
TileConnectorProjection connector = val;
connector.Blocked = !connector.Blocked;
// Client.SendCommands([PlayerCommand.TOGGLE_DOOR_REMOTE()]); Client.SendCommands([PlayerCommand.SET_DOOR_REMOTE(connector.Id, connector.Blocked)]);
UIManager.ChangeRemoteDoorState(connector.Id, connector.Blocked);
// Console.WriteLine("Changed door state to: " + (connector.Blocked ? "blocked" : "open") + " for door " + connector);
// add UIManager toggle door
} }
public static void SendChangeCamera(int idx, int idy) { public static void SendChangeCamera(int id) {
Client.SendCommands([PlayerCommand.SWITCH_CAM(idx, idy)]); Client.Player.state.camera = id;
Client.SendCommands([PlayerCommand.SWITCH_CAM(id)]);
MapTileProjection tile = ClientMapManager.Get(id);
// add UIManager switch camera
currentDoorBinds.Clear();
foreach (var c in tile.GetAllConnectors().Where(c => c.Type == ConnectorType.DOOR_REMOTE)){
Direction dir = c.GetDirection(tile);
if (dir == Direction.NONE) return;
currentDoorBinds.Add(dir, c);
}
} }
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.6 KiB

After

Width:  |  Height:  |  Size: 4.6 KiB

Before After
Before After

View file

@ -48,11 +48,6 @@ public class UIManager {
monitorScreen.AddElement("view-frame", new UIElement(monitorAtlas[1], new Point(62, 55))); monitorScreen.AddElement("view-frame", new UIElement(monitorAtlas[1], new Point(62, 55)));
monitorScreen.AddElement("map-frame", new UIElement(monitorAtlas[2], new Point(334, 135))); monitorScreen.AddElement("map-frame", new UIElement(monitorAtlas[2], new Point(334, 135)));
monitorScreen.AddElement("map", new UIElement(monitorAtlas[3], new Point(334, 135))); monitorScreen.AddElement("map", new UIElement(monitorAtlas[3], new Point(334, 135)));
// Dictionary<(int,int),string> doorPositions = new(){
// {(0, 0),"2-5"},{ (1, 0), "2-4" }, { (1, 1), "2-3" }, { (3, 0), "2-2" }, { (3, 1), "2-1" }, { (4, 0), "2-0" }, // TODO: generate this dynamically from server map info
// {(0, 3),"1-0"},{ (1, 3), "1-1" }, { (1, 2), "1-2" }, { (3, 3), "1-3" }, { (3, 2), "1-4" }, { (4, 3), "1-5" }
// };
for (int i = 0; i < 5; i++){ // NOTE: this loop does y in reverse, y labels are inverted to match server for (int i = 0; i < 5; i++){ // NOTE: this loop does y in reverse, y labels are inverted to match server
for (int j = 0; j < 5; j++){ for (int j = 0; j < 5; j++){
@ -61,7 +56,7 @@ public class UIManager {
Point point1 = new Point(336 + (32 * i), 144 + (32 * j)); Point point1 = new Point(336 + (32 * i), 144 + (32 * j));
Point point2 = new Point(367 + (32 * i), 175 + (32 * j)); Point point2 = new Point(367 + (32 * i), 175 + (32 * j));
monitorScreen.AddElement($"room{MapTileProjection.CoordsToId(i, 4 - j)}", new UIElement(point1, point2) monitorScreen.AddElement($"room{MapTileProjection.CoordsToId(i, 4 - j)}", new UIElement(point1, point2)
{Pressable = true, OnMousePress = (() => CommandManager.SendChangeCamera(i1, 4 - j1))}); {Pressable = true, OnMousePress = (() => CommandManager.SendChangeCamera(MapTileProjection.CoordsToId(i1, 4 - j1)))});
// //
// if (doorPositions.ContainsKey((i, j))){ // if (doorPositions.ContainsKey((i, j))){
// monitorScreen.AddElement("door"+doorPositions[(i, j)], new UIElement([monitorAtlas[5], monitorAtlas[6]], point1)); // monitorScreen.AddElement("door"+doorPositions[(i, j)], new UIElement([monitorAtlas[5], monitorAtlas[6]], point1));
@ -79,24 +74,42 @@ public class UIManager {
if (dpos.y == 1){ if (dpos.y == 1){
int targetId = door.Tiles.tile1.GridPosition.y > door.Tiles.tile2.GridPosition.y ? door.Tiles.tile1.Id : door.Tiles.tile2.Id; int targetId = door.Tiles.tile1.GridPosition.y > door.Tiles.tile2.GridPosition.y ? door.Tiles.tile1.Id : door.Tiles.tile2.Id;
UIElement tile = monitorScreen["room"+targetId]; UIElement tile = monitorScreen["room"+targetId];
monitorScreen.AddElement("door"+targetId+"-"+(targetId == door.Tiles.tile1.Id ? door.Tiles.tile2.Id : door.Tiles.tile1.Id), new UIElement([monitorAtlas[5], monitorAtlas[6]], tile.Bounds.Item1)); monitorScreen.AddElement("door"+targetId+"-"+(targetId == door.Tiles.tile1.Id ? door.Tiles.tile2.Id : door.Tiles.tile1.Id), new UIElement([monitorAtlas[5], monitorAtlas[6]], tile.Bounds.Item1));
} }
} }
monitorScreen.AddElement("p1-office-door-left", new UIElement([monitorAtlas[7], monitorAtlas[8]], new Point(400, 272)));
monitorScreen.AddElement("p1-office-door-centre", new UIElement([monitorAtlas[9], monitorAtlas[10]], new Point(400, 272)));
monitorScreen.AddElement("p1-office-door-right", new UIElement([monitorAtlas[11], monitorAtlas[12]], new Point(400, 272)));
monitorScreen.AddElement("p2-office-door-right", new UIElement([monitorAtlas[13], monitorAtlas[14]], new Point(400, 144)));
monitorScreen.AddElement("p2-office-door-centre", new UIElement([monitorAtlas[15], monitorAtlas[16]], new Point(400, 144)));
monitorScreen.AddElement("p2-office-door-left", new UIElement([monitorAtlas[17], monitorAtlas[18]], new Point(400, 144)));
} }
public static void ChangeDoorState(Direction dir, bool state) { public static void ChangeDoorState(Direction dir, bool state) { // TODO: make this also change for p2
int stateInt = state ? 1 : 0;
switch ((int)dir){ switch ((int)dir){
case 0: case 0:
officeScreen["office_left"].SetTexture(state ? 1 : 0); officeScreen["office_left"].SetTexture(stateInt);
monitorScreen["p1-office-door-left"].SetTexture(stateInt);
break; break;
case 1: case 1:
officeScreen["office_centre"].SetTexture(state ? 1 : 0); officeScreen["office_centre"].SetTexture(stateInt);
monitorScreen["p1-office-door-centre"].SetTexture(stateInt);
break; break;
case 2: case 2:
officeScreen["office_right"].SetTexture(state ? 1 : 0); officeScreen["office_right"].SetTexture(stateInt);
monitorScreen["p1-office-door-right"].SetTexture(stateInt);
break; break;
} }
} }
public static void ChangeRemoteDoorState((int, int) id, bool state) {
monitorScreen["door"+Math.Max(id.Item1, id.Item2)+"-"+Math.Min(id.Item1, id.Item2)].SetTexture(state ? 1 : 0);
}
public static void ChangeMonitorState(bool state) { public static void ChangeMonitorState(bool state) {
Screen.SetScreen(state ? ScreenTypes.CAMERAS : ScreenTypes.OFFICE); Screen.SetScreen(state ? ScreenTypes.CAMERAS : ScreenTypes.OFFICE);

View file

@ -20,7 +20,7 @@ public class GameMain() : Core("fnafkooo", 1280, 720, false) {
Client.Connect("127.0.0.1", 9012); Client.Connect("127.0.0.1", 9012);
CommandManager.InitInputListeners(); CommandManager.InitInputListeners();
InputManager.AddListener(InputManager.MouseButton.LEFT, (() => Console.WriteLine("LMB pressed at: " + InputManager.MouseState.Position)), InputTiming.PRESS, new InputListenerHook(true)); // InputManager.AddListener(InputManager.MouseButton.LEFT, (() => Console.WriteLine("LMB pressed at: " + InputManager.MouseState.Position)), InputTiming.PRESS, new InputListenerHook(true));
base.Initialize(); base.Initialize();

View file

@ -4,7 +4,7 @@ namespace FNAF_Clone.Map;
public class ClientMapManager { public class ClientMapManager {
private static MapTileProjection[,] map = new MapTileProjection[5, 5]; private static MapTileProjection[,] map = new MapTileProjection[5, 5];
private static MapTileProjection Get((int x, int y) coords) => map[coords.x, coords.y]; public static MapTileProjection Get((int x, int y) coords) => map[coords.x, coords.y];
public static MapTileProjection Get(int tileId) => Get(MapTileProjection.IdToCoords(tileId)); public static MapTileProjection Get(int tileId) => Get(MapTileProjection.IdToCoords(tileId));
public static void InitMap() { public static void InitMap() {
for (int i = 0; i < 5; i++){ for (int i = 0; i < 5; i++){
@ -17,8 +17,6 @@ public class ClientMapManager {
} }
} }
} }
public static void InitConnectors(TileConnectorProjection[] connectors) { public static void InitConnectors(TileConnectorProjection[] connectors) {
@ -29,7 +27,7 @@ public class ClientMapManager {
} }
} }
public static TileConnectorProjection GetConnector((int, int) id) => Get(id.Item1).GetConnector(id.Item2);
public static TileConnectorProjection[] GetConnectors(int tileId) => Get(MapTileProjection.IdToCoords(tileId)).GetAllConnectors(); public static TileConnectorProjection[] GetConnectors(int tileId) => Get(MapTileProjection.IdToCoords(tileId)).GetAllConnectors();
} }

View file

@ -1,3 +1,4 @@
using FNAF_Server.Map;
using PacketLib; using PacketLib;
namespace FNAF_Server; namespace FNAF_Server;
@ -9,21 +10,28 @@ public class CommandProcessor {
foreach (var playerCommand in commands){ foreach (var playerCommand in commands){
switch (playerCommand.ID){ switch (playerCommand.ID){
case 0: case 0:
Console.WriteLine($"C: Player {pid} switched to camera {playerCommand.Args[0]}-{playerCommand.Args[1]}"); Console.WriteLine($"C: Player {pid} switched to camera {playerCommand.Args[0]}");
Server.SendUpdateToAll([GameEvent.SWITCH_CAM(pid, playerCommand.Args[0], playerCommand.Args[1])]); Server.SendUpdateToAll([GameEvent.SWITCH_CAM(pid, playerCommand.Args[0])]);
break; break;
case 1: case 1:
bool monitorState = !currentPlayer.state.monitorUp; bool monitorState = playerCommand.Args[0] == 1;
currentPlayer.state.monitorUp = monitorState; currentPlayer.state.monitorUp = monitorState;
Console.WriteLine($"C: Player {pid} toggled camera {(monitorState ? "on" : "off")}"); Console.WriteLine($"C: Player {pid} toggled camera {(monitorState ? "on" : "off")}");
Server.SendUpdateToAll([GameEvent.TOGGLE_MONITOR(pid, monitorState)]); Server.SendUpdateToAll([GameEvent.TOGGLE_MONITOR(pid, monitorState)]);
break; break;
case 2: case 2:
bool doorState = !currentPlayer.state.doorStates[playerCommand.Args[0]]; bool doorState = playerCommand.Args[1] == 1;
currentPlayer.state.doorStates[playerCommand.Args[0]] = doorState; currentPlayer.state.doorStates[playerCommand.Args[0]] = doorState;
Console.WriteLine($" Player {pid} {(doorState ? "closed" : "opened")} door {playerCommand.Args[0]}"); Console.WriteLine($"C: Player {pid} {(doorState ? "closed" : "opened")} door {playerCommand.Args[0]}");
Server.SendUpdateToAll([GameEvent.TOGGLE_DOOR_OFFICE(pid,playerCommand.Args[0] ,doorState)]); Server.SendUpdateToAll([GameEvent.TOGGLE_DOOR_OFFICE(pid,playerCommand.Args[0] ,doorState)]);
break; break;
case 3:
TileConnector? door = MapManager.Get(playerCommand.Args[0]).GetConnector(playerCommand.Args[1]);
if(door == null) return;
door.Blocked = playerCommand.Args[2] == 1;
Console.WriteLine($"C: Player {pid} {(door.Blocked ? "closed" : "opened")} door {(playerCommand.Args[0], playerCommand.Args[1])}");
Server.SendUpdateToAll([GameEvent.TOGGLE_DOOR_REMOTE(pid, (playerCommand.Args[0], playerCommand.Args[1]), door.Blocked)]);
break;
} }
} }
} }

View file

@ -4,6 +4,10 @@ namespace FNAF_Server.Map;
public static class MapManager { public static class MapManager {
private static MapTile[,] map = new MapTile[5, 5]; private static MapTile[,] map = new MapTile[5, 5];
public static MapTile Get((int x, int y) coords) => map[coords.x, coords.y];
public static MapTile Get(int tileId) => Get(MapTile.IdToCoords(tileId));
private static Dictionary<(int x1, int y1), (int x2, int y2, int value, ConnectorType type)[]> halfConnectors = new(){ private static Dictionary<(int x1, int y1), (int x2, int y2, int value, ConnectorType type)[]> halfConnectors = new(){
[(0, 0)] =[(1, 0, 1, ConnectorType.HALL), (0, 1, 1, ConnectorType.DOOR_REMOTE)], [(0, 0)] =[(1, 0, 1, ConnectorType.HALL), (0, 1, 1, ConnectorType.DOOR_REMOTE)],
@ -53,8 +57,9 @@ public static class MapManager {
for (int i = 0; i < 5; i++){ for (int i = 0; i < 5; i++){
for (int j = 0; j < 5; j++){ for (int j = 0; j < 5; j++){
Array.ForEach(map[i, j].GetAllConnectors(), c => { MapTile tile = map[i, j];
if(c.Tiles.tile1.Id < c.Tiles.tile2.Id) Array.ForEach(tile.GetAllConnectors(), c => {
if(tile.Id < c.OtherTile(tile).Id)
connectors.Add(c); connectors.Add(c);
}); });
} }

View file

@ -4,7 +4,6 @@ namespace FNAF_Server.Map;
public class TileConnector : GlobalTileConnector<MapTile,TileConnector> { public class TileConnector : GlobalTileConnector<MapTile,TileConnector> {
public int Value{ get; set; } public int Value{ get; set; }
public bool Blocked { get; set; }
public TileConnector(MapTile tile1, MapTile tile2, ConnectorType type, int value) : base(tile1, tile2, type) { public TileConnector(MapTile tile1, MapTile tile2, ConnectorType type, int value) : base(tile1, tile2, type) {
Value = value; Value = value;
} }

View file

@ -4,5 +4,6 @@ public enum Direction {
EAST = 0, EAST = 0,
NORTH = 1, NORTH = 1,
WEST = 2, WEST = 2,
SOUTH = 3 SOUTH = 3,
NONE = 4
} }

View file

@ -15,13 +15,13 @@ public abstract class GlobalMapTile<TCon, TTile> where TCon : GlobalTileConnecto
connector = connector.Clone(); connector = connector.Clone();
connector.Tiles.tile1 = (TTile)this; connector.Tiles.tile1 = (TTile)this;
connectors.Add(connector); connectors.Add(connector);
connector.Tiles.tile2._AddConnectorNoRepeat(connector.Clone()); connector.Tiles.tile2._AddConnectorNoRepeat(connector);
// connectors.Add(new TCon(this, tile, type)); // connectors.Add(new TCon(this, tile, type));
// tile.connectors.Add(new GlobalTileConnector(tile, this, type)); // tile.connectors.Add(new GlobalTileConnector(tile, this, type));
} }
private void _AddConnectorNoRepeat(TCon connector) { private void _AddConnectorNoRepeat(TCon connector) {
(connector.Tiles.tile1, connector.Tiles.tile2) = (connector.Tiles.tile2, connector.Tiles.tile1); // (connector.Tiles.tile1, connector.Tiles.tile2) = (connector.Tiles.tile2, connector.Tiles.tile1);
connectors.Add(connector); connectors.Add(connector);
} }

View file

@ -16,11 +16,28 @@ public abstract class GlobalTileConnector<TTile, TCon> where TTile : GlobalMapTi
} }
public (TTile tile1, TTile tile2) Tiles; public (TTile tile1, TTile tile2) Tiles;
public bool Blocked { get; set; }
public (int, int) Id => (Tiles.tile1.Id, Tiles.tile2.Id); public (int, int) Id => (Tiles.tile1.Id, Tiles.tile2.Id);
public ConnectorType Type { get; set; } public ConnectorType Type { get; set; }
public TTile OtherTile(TTile tile) => Tiles.Item1 == tile ? Tiles.Item2 : Tiles.Item1; public TTile OtherTile(TTile tile) => Tiles.Item1 == tile ? Tiles.Item2 : Tiles.Item1;
public Direction GetDirection(TTile tile) {
if (tile != Tiles.tile1 && tile != Tiles.tile2) return Direction.NONE;
TTile other = OtherTile(tile);
(int, int) dpos = (other.GridPosition.x - tile.GridPosition.x, other.GridPosition.y - tile.GridPosition.y);
switch (dpos){
case (0, 1): return Direction.NORTH;
case (1, 0): return Direction.EAST;
case (0, -1): return Direction.SOUTH;
case (-1, 0): return Direction.WEST;
default: return Direction.NONE;
}
}
public override string ToString() => $"Con ({Tiles.Item1.PositionAsString} -> {Tiles.Item2.PositionAsString})"; public override string ToString() => $"Con ({Tiles.Item1.PositionAsString} -> {Tiles.Item2.PositionAsString})";

View file

@ -7,9 +7,11 @@ namespace PacketLib;
public struct GameEvent : INetSerializable{ public struct GameEvent : INetSerializable{
public static GameEvent PLAYER_JOIN(int pid) => new(){ID = 0, Args = [pid] }; public static GameEvent PLAYER_JOIN(int pid) => new(){ID = 0, Args = [pid] };
public static GameEvent PLAYER_LEAVE(int pid) => new(){ID = 1, Args = [pid] }; public static GameEvent PLAYER_LEAVE(int pid) => new(){ID = 1, Args = [pid] };
public static GameEvent SWITCH_CAM(int pid, int idx, int idy) => new(){ID = 2, Args = [pid, idx, idy] }; public static GameEvent SWITCH_CAM(int pid, int id) => new(){ID = 2, Args = [pid, id] };
public static GameEvent TOGGLE_MONITOR(int pid, bool state) => new(){ID = 3, Args = [pid, state ? 1 : 0]}; public static GameEvent TOGGLE_MONITOR(int pid, bool state) => new(){ID = 3, Args = [pid, state ? 1 : 0]};
public static GameEvent TOGGLE_DOOR_OFFICE(int pid, int doorId, bool state) => new(){ID = 4, Args = [pid, doorId, state ? 1 : 0]}; public static GameEvent TOGGLE_DOOR_OFFICE(int pid, int doorId, bool state) => new(){ID = 4, Args = [pid, doorId, state ? 1 : 0]};
public static GameEvent TOGGLE_DOOR_REMOTE(int pid, (int, int) doorId, bool state) => new(){ID = 5, Args = [pid, doorId.Item1, doorId.Item2, state ? 1 : 0]};

View file

@ -4,10 +4,10 @@ using LiteNetLib.Utils;
namespace PacketLib; namespace PacketLib;
public struct PlayerCommand : INetSerializable { public struct PlayerCommand : INetSerializable {
public static PlayerCommand SWITCH_CAM(int idx, int idy) => new(){ID = 0, Args = [idx, idy] }; public static PlayerCommand SWITCH_CAM(int id) => new(){ID = 0, Args = [id] };
public static PlayerCommand TOGGLE_MONITOR() => new(){ID = 1, Args = []}; public static PlayerCommand SET_MONITOR(bool state) => new(){ID = 1, Args = [state ? 1 : 0]};
public static PlayerCommand TOGGLE_DOOR_OFFICE(Direction direction) => new(){ID = 2, Args = [(int)direction]}; public static PlayerCommand SET_DOOR_OFFICE(Direction direction, bool state) => new(){ID = 2, Args = [(int)direction, state ? 1 : 0]};
public static PlayerCommand TOGGLE_DOOR_REMOTE(int remoteDoorId) => new(){ID = 3, Args = [remoteDoorId]}; public static PlayerCommand SET_DOOR_REMOTE((int, int) remoteDoorId, bool state) => new(){ID = 3, Args = [remoteDoorId.Item1, remoteDoorId.Item2, state ? 1 : 0]};
public int ID{ get; set; } public int ID{ get; set; }
public bool Hideable => ID < 0; public bool Hideable => ID < 0;
public int[] Args{ get; private set; } public int[] Args{ get; private set; }