Oprava spawnování monster, optimalizace v CommandProcessor a EventProcessor. Přesunutí některých tříd do vlastních namespaců, pročištění kódu, úpravy formátování, odstranění nepoužívaných souborů a zakomentovaného kódu
This commit is contained in:
parent
e5d746d597
commit
243f071a43
62 changed files with 873 additions and 1217 deletions
97
ONDClient/Net/CommandManager.cs
Normal file
97
ONDClient/Net/CommandManager.cs
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using GlobalClassLib;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
using MonoGameLibrary.Input;
|
||||
using ONDClient.GUI;
|
||||
using ONDClient.Map;
|
||||
using ONDClient.Sound;
|
||||
using PacketLib;
|
||||
|
||||
namespace ONDClient.Net;
|
||||
|
||||
public static class CommandManager {
|
||||
private static readonly (string label, Keys key, Action action)[] keybinds = [
|
||||
("Toggle camera", Keys.Space, SendToggleCamera),
|
||||
("Toggle left door", Keys.A, ToggleDoorLeft),
|
||||
("Toggle centre door", Keys.W, ToggleDoorCentre),
|
||||
("Toggle right door", Keys.D, ToggleDoorRight),
|
||||
("Toggle back door", Keys.S, ToggleDoorBack),
|
||||
("Toggle light", Keys.F, ToggleLight)
|
||||
];
|
||||
|
||||
private static InputListenerHook AllControlsHook{ get; } = new(true);
|
||||
|
||||
public static void InitInputListeners() {
|
||||
Array.ForEach(keybinds, tuple => InputManager.AddListener(tuple.label, tuple.key, () => tuple.action(), InputTiming.PRESS, AllControlsHook));
|
||||
}
|
||||
|
||||
public static void AllowGameControls(bool state) {
|
||||
AllControlsHook.Enabled = state;
|
||||
}
|
||||
|
||||
private static void SendToggleCamera() {
|
||||
Client.Player.State.MonitorUp = !Client.Player.State.MonitorUp;
|
||||
UIManager.ChangeMonitorState(Client.Player.State.MonitorUp);
|
||||
Client.SendCommands([PlayerCommand.SET_MONITOR(Client.Player.State.MonitorUp)]);
|
||||
SoundManager.PlayMonitorFlip();
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
private static Dictionary<Direction, TileConnectorProjection> currentDoorBinds = new();
|
||||
|
||||
private static void ToggleLight() => SendToggleLight(Client.Player.State.Camera, !ClientMapManager.Get(Client.Player.State.Camera).Lit);
|
||||
|
||||
private static void SendToggleDoor(Direction direction) {
|
||||
if (Screen.CurrentScreen.Label == UIManager.ScreenTypes.CAMERAS){
|
||||
SendToggleRemoteDoor(direction);
|
||||
return;
|
||||
}
|
||||
|
||||
if (direction == Direction.SOUTH) return;
|
||||
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])]);
|
||||
}
|
||||
|
||||
private static void SendToggleRemoteDoor(Direction direction) {
|
||||
if (!currentDoorBinds.TryGetValue(direction, out var connector)) return;
|
||||
if (connector.Owner != Client.Player) return;
|
||||
|
||||
connector.Blocked = !connector.Blocked;
|
||||
Client.SendCommands([PlayerCommand.SET_DOOR_REMOTE(connector.Id, connector.Blocked)]);
|
||||
SoundManager.PlayDoorRemote(connector.Blocked);
|
||||
UIManager.ChangeRemoteDoorState(connector.Id, connector.Blocked);
|
||||
}
|
||||
|
||||
public static void SendChangeCamera(int id) {
|
||||
if (id == Client.Player.State.OfficeTileId || id == Client.Opponent.State.OfficeTileId) return;
|
||||
|
||||
Client.Player.State.Camera = id;
|
||||
UIManager.ChangeCamera(id);
|
||||
SoundManager.PlayCameraSwitch();
|
||||
Client.SendCommands([PlayerCommand.SWITCH_CAM(id)]);
|
||||
MapTileProjection tile = ClientMapManager.Get(id);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
private static void SendToggleLight(int id, bool state) {
|
||||
if(!Client.Player.State.MonitorUp || ClientMapManager.Get(id).Owner != Client.Player) return;
|
||||
ClientMapManager.Get(id).Lit = state;
|
||||
UIManager.UpdateCameras([id]);
|
||||
SoundManager.PlayLight(state);
|
||||
Client.SendCommands([PlayerCommand.SET_LIGHT(id, state)]);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue