2025-12-19 17:54:50 +01:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2026-02-14 14:35:29 +01:00
|
|
|
using System.Linq;
|
|
|
|
|
using GlobalClassLib;
|
2025-12-19 17:54:50 +01:00
|
|
|
using Microsoft.Xna.Framework.Input;
|
|
|
|
|
using MonoGameLibrary.Input;
|
2026-03-22 18:31:05 +01:00
|
|
|
using ONDClient.GUI;
|
|
|
|
|
using ONDClient.Map;
|
2026-03-28 09:59:31 +01:00
|
|
|
using ONDClient.Sound;
|
2025-12-19 17:54:50 +01:00
|
|
|
using PacketLib;
|
|
|
|
|
|
2026-03-28 09:59:31 +01:00
|
|
|
namespace ONDClient.Net;
|
2025-12-19 17:54:50 +01:00
|
|
|
|
2026-03-28 09:59:31 +01:00
|
|
|
public static class CommandManager {
|
|
|
|
|
private static readonly (string label, Keys key, Action action)[] keybinds = [
|
2026-02-14 14:35:29 +01:00
|
|
|
("Toggle camera", Keys.Space, SendToggleCamera),
|
2026-01-26 09:39:17 +01:00
|
|
|
("Toggle left door", Keys.A, ToggleDoorLeft),
|
|
|
|
|
("Toggle centre door", Keys.W, ToggleDoorCentre),
|
2026-02-14 14:35:29 +01:00
|
|
|
("Toggle right door", Keys.D, ToggleDoorRight),
|
2026-03-16 20:43:53 +01:00
|
|
|
("Toggle back door", Keys.S, ToggleDoorBack),
|
|
|
|
|
("Toggle light", Keys.F, ToggleLight)
|
2025-12-19 17:54:50 +01:00
|
|
|
];
|
|
|
|
|
|
2026-03-28 09:59:31 +01:00
|
|
|
private static InputListenerHook AllControlsHook{ get; } = new(true);
|
2025-12-19 17:54:50 +01:00
|
|
|
|
|
|
|
|
public static void InitInputListeners() {
|
2026-03-28 09:59:31 +01:00
|
|
|
Array.ForEach(keybinds, tuple => InputManager.AddListener(tuple.label, tuple.key, () => tuple.action(), InputTiming.PRESS, AllControlsHook));
|
2026-03-09 20:05:21 +01:00
|
|
|
}
|
|
|
|
|
|
2026-03-11 22:35:30 +01:00
|
|
|
public static void AllowGameControls(bool state) {
|
2026-03-28 09:59:31 +01:00
|
|
|
AllControlsHook.Enabled = state;
|
2025-12-19 17:54:50 +01:00
|
|
|
}
|
|
|
|
|
|
2026-01-26 09:39:17 +01:00
|
|
|
private static void SendToggleCamera() {
|
2026-03-28 09:59:31 +01:00
|
|
|
Client.Player.State.MonitorUp = !Client.Player.State.MonitorUp;
|
|
|
|
|
UIManager.ChangeMonitorState(Client.Player.State.MonitorUp);
|
|
|
|
|
Client.SendCommands([PlayerCommand.SET_MONITOR(Client.Player.State.MonitorUp)]);
|
2026-03-19 20:10:45 +01:00
|
|
|
SoundManager.PlayMonitorFlip();
|
2025-12-19 17:54:50 +01:00
|
|
|
}
|
2026-01-29 19:37:40 +01:00
|
|
|
|
2026-02-14 14:35:29 +01:00
|
|
|
private static void ToggleDoorLeft() => SendToggleDoor(Direction.EAST);
|
|
|
|
|
private static void ToggleDoorCentre() => SendToggleDoor(Direction.NORTH);
|
|
|
|
|
private static void ToggleDoorRight() => SendToggleDoor(Direction.WEST);
|
|
|
|
|
private static void ToggleDoorBack() => SendToggleDoor(Direction.SOUTH);
|
|
|
|
|
|
2026-02-21 18:42:44 +01:00
|
|
|
private static Dictionary<Direction, TileConnectorProjection> currentDoorBinds = new();
|
2026-01-25 11:16:54 +01:00
|
|
|
|
2026-03-28 09:59:31 +01:00
|
|
|
private static void ToggleLight() => SendToggleLight(Client.Player.State.Camera, !ClientMapManager.Get(Client.Player.State.Camera).Lit);
|
2026-03-16 20:43:53 +01:00
|
|
|
|
2026-02-14 14:35:29 +01:00
|
|
|
private static void SendToggleDoor(Direction direction) {
|
2026-01-26 09:39:17 +01:00
|
|
|
if (Screen.CurrentScreen.Label == UIManager.ScreenTypes.CAMERAS){
|
2026-02-14 14:35:29 +01:00
|
|
|
SendToggleRemoteDoor(direction);
|
2026-01-26 09:39:17 +01:00
|
|
|
return;
|
|
|
|
|
}
|
2026-03-08 16:55:49 +01:00
|
|
|
|
|
|
|
|
if (direction == Direction.SOUTH) return;
|
2026-03-28 09:59:31 +01:00
|
|
|
Client.Player.State.DoorStates[(int)direction] = !Client.Player.State.DoorStates[(int)direction];
|
|
|
|
|
UIManager.ChangeDoorState(direction, Client.Player.State.DoorStates[(int)direction]);
|
|
|
|
|
SoundManager.PlayDoor(Client.Player.State.DoorStates[(int)direction]);
|
|
|
|
|
Client.SendCommands([PlayerCommand.SET_DOOR_OFFICE(direction, Client.Player.State.DoorStates[(int)direction])]);
|
2026-02-14 14:35:29 +01:00
|
|
|
}
|
|
|
|
|
|
2026-02-21 18:42:44 +01:00
|
|
|
private static void SendToggleRemoteDoor(Direction direction) {
|
2026-03-12 22:33:35 +01:00
|
|
|
if (!currentDoorBinds.TryGetValue(direction, out var connector)) return;
|
|
|
|
|
if (connector.Owner != Client.Player) return;
|
|
|
|
|
|
2026-02-21 18:42:44 +01:00
|
|
|
connector.Blocked = !connector.Blocked;
|
|
|
|
|
Client.SendCommands([PlayerCommand.SET_DOOR_REMOTE(connector.Id, connector.Blocked)]);
|
2026-03-19 20:10:45 +01:00
|
|
|
SoundManager.PlayDoorRemote(connector.Blocked);
|
2026-02-21 18:42:44 +01:00
|
|
|
UIManager.ChangeRemoteDoorState(connector.Id, connector.Blocked);
|
2026-01-25 11:16:54 +01:00
|
|
|
}
|
2026-01-29 19:37:40 +01:00
|
|
|
|
2026-02-21 18:42:44 +01:00
|
|
|
public static void SendChangeCamera(int id) {
|
2026-03-28 09:59:31 +01:00
|
|
|
if (id == Client.Player.State.OfficeTileId || id == Client.Opponent.State.OfficeTileId) return;
|
2026-03-12 22:33:35 +01:00
|
|
|
|
2026-03-28 09:59:31 +01:00
|
|
|
Client.Player.State.Camera = id;
|
2026-02-26 16:24:55 +01:00
|
|
|
UIManager.ChangeCamera(id);
|
2026-03-19 20:10:45 +01:00
|
|
|
SoundManager.PlayCameraSwitch();
|
2026-02-21 18:42:44 +01:00
|
|
|
Client.SendCommands([PlayerCommand.SWITCH_CAM(id)]);
|
|
|
|
|
MapTileProjection tile = ClientMapManager.Get(id);
|
2026-03-28 09:59:31 +01:00
|
|
|
|
2026-02-21 18:42:44 +01:00
|
|
|
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);
|
|
|
|
|
}
|
2026-01-29 19:37:40 +01:00
|
|
|
}
|
2026-03-16 20:43:53 +01:00
|
|
|
|
|
|
|
|
private static void SendToggleLight(int id, bool state) {
|
2026-03-28 09:59:31 +01:00
|
|
|
if(!Client.Player.State.MonitorUp || ClientMapManager.Get(id).Owner != Client.Player) return;
|
2026-03-16 20:43:53 +01:00
|
|
|
ClientMapManager.Get(id).Lit = state;
|
|
|
|
|
UIManager.UpdateCameras([id]);
|
2026-03-19 20:10:45 +01:00
|
|
|
SoundManager.PlayLight(state);
|
2026-03-16 20:43:53 +01:00
|
|
|
Client.SendCommands([PlayerCommand.SET_LIGHT(id, state)]);
|
|
|
|
|
}
|
2025-12-19 17:54:50 +01:00
|
|
|
}
|