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
7
.idea/.idea.OneNightDuel/.idea/dictionaries/project.xml
generated
Normal file
7
.idea/.idea.OneNightDuel/.idea/dictionaries/project.xml
generated
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
<component name="ProjectDictionaryState">
|
||||||
|
<dictionary name="project">
|
||||||
|
<words>
|
||||||
|
<w>jumpscare</w>
|
||||||
|
</words>
|
||||||
|
</dictionary>
|
||||||
|
</component>
|
||||||
|
|
@ -1,28 +0,0 @@
|
||||||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
|
||||||
<s:Boolean x:Key="/Default/AddReferences/RecentPaths/=_002Fhome_002Fperry_002FRiderProjects_002FFNAF_005FClone_002FFNAF_005FClone_002Flib_002FMonoGameLibrary_002Edll/@EntryIndexedValue">True</s:Boolean>
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AContentManager_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fa69b121f85054691b2a8d28643003c23136600_003F49_003F5cd111e0_003FContentManager_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ACore_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F4e0fe18725844db38e9480edfd0e34983e00_003Fb5_003F8dc24573_003FCore_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ADictionary_00602_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F5e56f40aa42e4fc4b94786ec57da7544d1a400_003F07_003F804b4506_003FDictionary_00602_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AEnumerable_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F419320464d0849fb89a7e518f7ff8bc978a00_003Fe8_003F1faf66e3_003FEnumerable_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AEventChannel_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F384e456bc26f45f5a6a6a20ae50c6e0dd1a400_003Ffb_003Fca10f160_003FEventChannel_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AEventManifestOptions_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Ffd792102e2a04b889c29784ca9de4981d1a000_003Fe5_003F92feb77a_003FEventManifestOptions_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AGame_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fa69b121f85054691b2a8d28643003c23136600_003Fc7_003F517f8541_003FGame_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AINetSerializable_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F3d47105f47a240929625d0f531812b9e1c000_003F0f_003Fe2eeb2cd_003FINetSerializable_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AInputManager_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F4e0fe18725844db38e9480edfd0e34983e00_003F41_003Fc6f0d8ab_003FInputManager_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AKeyValuePair_00602_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F384e456bc26f45f5a6a6a20ae50c6e0dd1a400_003Fe8_003F7272ae72_003FKeyValuePair_00602_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AList_00601_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F5e56f40aa42e4fc4b94786ec57da7544d1a400_003Fe4_003F9c3fcf71_003FList_00601_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ANetManager_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F3d47105f47a240929625d0f531812b9e1c000_003Fd6_003Fec041615_003FNetManager_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ANetPacketProcessor_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F3d47105f47a240929625d0f531812b9e1c000_003F68_003Fc826a80a_003FNetPacketProcessor_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ANetSerializer_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F3d47105f47a240929625d0f531812b9e1c000_003Fcc_003F8a34584a_003FNetSerializer_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ASdlGamePlatform_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fa69b121f85054691b2a8d28643003c23136600_003F57_003F45ea073b_003FSdlGamePlatform_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ASpriteBatch_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fa69b121f85054691b2a8d28643003c23136600_003F98_003F17ad8de4_003FSpriteBatch_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AThread_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F5e56f40aa42e4fc4b94786ec57da7544d1a400_003Fb3_003F92670209_003FThread_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AThread_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Ffd792102e2a04b889c29784ca9de4981d1a000_003F2a_003Fa31b08a3_003FThread_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AThrowHelpers_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F5e56f40aa42e4fc4b94786ec57da7544d1a400_003F48_003F95b0ef9d_003FThrowHelpers_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AThrowHelper_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F5e56f40aa42e4fc4b94786ec57da7544d1a400_003Ffb_003Fa0fd6fc3_003FThrowHelper_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AThrowHelper_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Ffd792102e2a04b889c29784ca9de4981d1a000_003F8f_003F6419ac7c_003FThrowHelper_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ATitleContainer_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fa69b121f85054691b2a8d28643003c23136600_003F62_003F374a72ad_003FTitleContainer_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AValueTuple_00602_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F5e56f40aa42e4fc4b94786ec57da7544d1a400_003F09_003F312b9770_003FValueTuple_00602_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
|
||||||
<s:String x:Key="/Default/Environment/AssemblyExplorer/XmlDocument/@EntryValue"><AssemblyExplorer>
|
|
||||||
<Assembly Path="/home/perry/RiderProjects/FNAF_Clone/FNAF_Clone/link/MonoGameLibrary.dll" />
|
|
||||||
</AssemblyExplorer></s:String></wpf:ResourceDictionary>
|
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
using System.Diagnostics.Contracts;
|
|
||||||
|
|
||||||
namespace GlobalClassLib;
|
namespace GlobalClassLib;
|
||||||
|
|
||||||
public enum EnemyType {
|
public enum EnemyType {
|
||||||
|
|
|
||||||
|
|
@ -3,29 +3,24 @@ namespace GlobalClassLib;
|
||||||
public abstract class GlobalEnemy<TTile, TCon> where TTile : GlobalMapTile<TCon, TTile> where TCon : GlobalTileConnector<TTile, TCon> {
|
public abstract class GlobalEnemy<TTile, TCon> where TTile : GlobalMapTile<TCon, TTile> where TCon : GlobalTileConnector<TTile, TCon> {
|
||||||
public TTile? Location { get; set; }
|
public TTile? Location { get; set; }
|
||||||
public bool Visible { get; set; }
|
public bool Visible { get; set; }
|
||||||
public abstract string Name{ get; }
|
|
||||||
|
|
||||||
public abstract int TypeId{ get; }
|
|
||||||
public int Id { get; }
|
public int Id { get; }
|
||||||
|
public abstract string Name{ get; }
|
||||||
|
public abstract EnemyType Type{ get; }
|
||||||
|
|
||||||
|
// ReSharper disable once StaticMemberInGenericType
|
||||||
private static int nextId = 0;
|
private static int nextId = 0;
|
||||||
|
|
||||||
|
|
||||||
// public static Dictionary<TTile, GlobalEnemy<TTile, TCon>> PresentEnemies = new();
|
|
||||||
|
|
||||||
public GlobalEnemy() {
|
public GlobalEnemy() {
|
||||||
|
|
||||||
Id = nextId++;
|
Id = nextId++;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GlobalEnemy(int id) {
|
public GlobalEnemy(int id) {
|
||||||
Id = id;
|
Id = id;
|
||||||
}
|
}
|
||||||
public virtual void Spawn(TTile? location) {
|
public virtual void Spawn(TTile location) {
|
||||||
// PresentEnemies.Add(location, this);
|
|
||||||
Location = location;
|
Location = location;
|
||||||
Visible = true;
|
Visible = true;
|
||||||
Console.WriteLine($"Enemy {Id} ({Name}) spawned at {(location == null ? "" : location.Id)} {(location == null ? "" : location.GridPosition)}");
|
Console.WriteLine($"Enemy {Id} ({Name}) spawned at {location.Id} {location.GridPosition}");
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void Update() { }
|
public virtual void Update() { }
|
||||||
|
|
|
||||||
|
|
@ -1,27 +1,22 @@
|
||||||
namespace GlobalClassLib;
|
namespace GlobalClassLib;
|
||||||
|
|
||||||
public abstract class GlobalMapTile<TCon, TTile> where TCon : GlobalTileConnector<TTile, TCon> where TTile : GlobalMapTile<TCon, TTile> { // TTile should be the inheriting class
|
public abstract class GlobalMapTile<TCon, TTile>(int id, (int x, int y) gridPosition)
|
||||||
public int Id { get; }
|
where TCon : GlobalTileConnector<TTile, TCon>
|
||||||
|
where TTile : GlobalMapTile<TCon, TTile> { // TTile should be the inheriting class
|
||||||
|
public int Id { get; } = id;
|
||||||
public bool Lit { get; set; } = false;
|
public bool Lit { get; set; } = false;
|
||||||
public (int x, int y) GridPosition { get; private set; }
|
public (int x, int y) GridPosition { get; private set; } = gridPosition;
|
||||||
|
|
||||||
private List<TCon> connectors = new();
|
private readonly List<TCon> connectors = new();
|
||||||
|
|
||||||
public GlobalMapTile(int id, (int x, int y) gridPosition) {
|
|
||||||
Id = id;
|
|
||||||
GridPosition = gridPosition;
|
|
||||||
}
|
|
||||||
public void AddConnector(TCon connector) { // tile1 is ignored when provided
|
public void AddConnector(TCon connector) { // tile1 is ignored when provided
|
||||||
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);
|
connector.Tiles.tile2._AddConnectorNoRepeat(connector);
|
||||||
// connectors.Add(new TCon(this, tile, 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);
|
|
||||||
connectors.Add(connector);
|
connectors.Add(connector);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -30,7 +25,7 @@ public abstract class GlobalMapTile<TCon, TTile> where TCon : GlobalTileConnecto
|
||||||
|
|
||||||
public override string ToString() => $"[{Id}] -> {string.Join(", ", connectors.Select(c => $"[{c.OtherTile((TTile)this).Id}]"))}";
|
public override string ToString() => $"[{Id}] -> {string.Join(", ", connectors.Select(c => $"[{c.OtherTile((TTile)this).Id}]"))}";
|
||||||
public override int GetHashCode() => Id.GetHashCode();
|
public override int GetHashCode() => Id.GetHashCode();
|
||||||
public string PositionAsString => $"[{Id}]"; // for debug purposes
|
public string IdAsString => $"[{Id}]"; // debug
|
||||||
|
|
||||||
public TCon? GetConnector(int id) {
|
public TCon? GetConnector(int id) {
|
||||||
foreach (var con in connectors){
|
foreach (var con in connectors){
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,15 @@
|
||||||
namespace GlobalClassLib;
|
namespace GlobalClassLib;
|
||||||
|
|
||||||
public abstract class GlobalTileConnector<TTile, TCon> where TTile : GlobalMapTile<TCon,TTile> where TCon : GlobalTileConnector<TTile, TCon> {
|
public abstract class GlobalTileConnector<TTile, TCon>
|
||||||
// private readonly TTile _tile1;
|
where TTile : GlobalMapTile<TCon,TTile>
|
||||||
// private readonly TTile _tile2;
|
where TCon : GlobalTileConnector<TTile, TCon> {
|
||||||
|
|
||||||
|
public (TTile tile1, TTile tile2) Tiles;
|
||||||
|
public bool Blocked { get; set; }
|
||||||
|
public (int, int) Id => (Tiles.tile1.Id, Tiles.tile2.Id);
|
||||||
|
public ConnectorType Type { get; set; }
|
||||||
|
|
||||||
|
public TTile OtherTile(TTile tile) => Tiles.tile1 == tile ? Tiles.tile2 : Tiles.tile1;
|
||||||
public GlobalTileConnector(TTile tile1, TTile tile2, ConnectorType type) {
|
public GlobalTileConnector(TTile tile1, TTile tile2, ConnectorType type) {
|
||||||
Tiles.tile1 = tile1;
|
Tiles.tile1 = tile1;
|
||||||
Tiles.tile2 = tile2;
|
Tiles.tile2 = tile2;
|
||||||
|
|
@ -15,15 +21,6 @@ public abstract class GlobalTileConnector<TTile, TCon> where TTile : GlobalMapTi
|
||||||
Type = type;
|
Type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public (TTile tile1, TTile tile2) Tiles;
|
|
||||||
public bool Blocked { get; set; }
|
|
||||||
|
|
||||||
public (int, int) Id => (Tiles.tile1.Id, Tiles.tile2.Id);
|
|
||||||
|
|
||||||
public ConnectorType Type { get; set; }
|
|
||||||
|
|
||||||
public TTile OtherTile(TTile tile) => Tiles.Item1 == tile ? Tiles.Item2 : Tiles.Item1;
|
|
||||||
|
|
||||||
public Direction GetDirection(TTile tile) {
|
public Direction GetDirection(TTile tile) {
|
||||||
if (tile != Tiles.tile1 && tile != Tiles.tile2) return Direction.NONE;
|
if (tile != Tiles.tile1 && tile != Tiles.tile2) return Direction.NONE;
|
||||||
|
|
||||||
|
|
@ -39,7 +36,7 @@ public abstract class GlobalTileConnector<TTile, TCon> where TTile : GlobalMapTi
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString() => $"Con ({Tiles.Item1.PositionAsString} -> {Tiles.Item2.PositionAsString})";
|
public override string ToString() => $"Con ({Tiles.Item1.IdAsString} -> {Tiles.Item2.IdAsString})";
|
||||||
|
|
||||||
public abstract TCon Clone();
|
public abstract TCon Clone();
|
||||||
}
|
}
|
||||||
|
|
@ -1,28 +0,0 @@
|
||||||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
|
||||||
<s:Boolean x:Key="/Default/AddReferences/RecentPaths/=_002Fhome_002Fperry_002FRiderProjects_002FFNAF_005FClone_002FFNAF_005FClone_002Flib_002FMonoGameLibrary_002Edll/@EntryIndexedValue">True</s:Boolean>
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AContentManager_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fa69b121f85054691b2a8d28643003c23136600_003F49_003F5cd111e0_003FContentManager_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ACore_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F4e0fe18725844db38e9480edfd0e34983e00_003Fb5_003F8dc24573_003FCore_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ADictionary_00602_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F5e56f40aa42e4fc4b94786ec57da7544d1a400_003F07_003F804b4506_003FDictionary_00602_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AEnumerable_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F419320464d0849fb89a7e518f7ff8bc978a00_003Fe8_003F1faf66e3_003FEnumerable_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AEventChannel_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F384e456bc26f45f5a6a6a20ae50c6e0dd1a400_003Ffb_003Fca10f160_003FEventChannel_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AEventManifestOptions_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Ffd792102e2a04b889c29784ca9de4981d1a000_003Fe5_003F92feb77a_003FEventManifestOptions_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AGame_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fa69b121f85054691b2a8d28643003c23136600_003Fc7_003F517f8541_003FGame_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AINetSerializable_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F3d47105f47a240929625d0f531812b9e1c000_003F0f_003Fe2eeb2cd_003FINetSerializable_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AInputManager_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F4e0fe18725844db38e9480edfd0e34983e00_003F41_003Fc6f0d8ab_003FInputManager_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AKeyValuePair_00602_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F384e456bc26f45f5a6a6a20ae50c6e0dd1a400_003Fe8_003F7272ae72_003FKeyValuePair_00602_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AList_00601_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F5e56f40aa42e4fc4b94786ec57da7544d1a400_003Fe4_003F9c3fcf71_003FList_00601_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ANetManager_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F3d47105f47a240929625d0f531812b9e1c000_003Fd6_003Fec041615_003FNetManager_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ANetSerializer_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F3d47105f47a240929625d0f531812b9e1c000_003Fcc_003F8a34584a_003FNetSerializer_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ASpriteBatch_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fa69b121f85054691b2a8d28643003c23136600_003F98_003F17ad8de4_003FSpriteBatch_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AThread_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F5e56f40aa42e4fc4b94786ec57da7544d1a400_003Fb3_003F92670209_003FThread_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AThrowHelpers_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F5e56f40aa42e4fc4b94786ec57da7544d1a400_003F48_003F95b0ef9d_003FThrowHelpers_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AThrowHelper_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F5e56f40aa42e4fc4b94786ec57da7544d1a400_003Ffb_003Fa0fd6fc3_003FThrowHelper_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ATitleContainer_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fa69b121f85054691b2a8d28643003c23136600_003F62_003F374a72ad_003FTitleContainer_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AValueTuple_00602_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F5e56f40aa42e4fc4b94786ec57da7544d1a400_003F09_003F312b9770_003FValueTuple_00602_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AThread_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Ffd792102e2a04b889c29784ca9de4981d1a000_003F2a_003Fa31b08a3_003FThread_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ASdlGamePlatform_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fa69b121f85054691b2a8d28643003c23136600_003F57_003F45ea073b_003FSdlGamePlatform_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AThrowHelper_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Ffd792102e2a04b889c29784ca9de4981d1a000_003F8f_003F6419ac7c_003FThrowHelper_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ANetPacketProcessor_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F3d47105f47a240929625d0f531812b9e1c000_003F68_003Fc826a80a_003FNetPacketProcessor_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
|
||||||
<s:String x:Key="/Default/Environment/AssemblyExplorer/XmlDocument/@EntryValue"><AssemblyExplorer>
|
|
||||||
<Assembly Path="/home/perry/RiderProjects/FNAF_Clone/FNAF_Clone/link/MonoGameLibrary.dll" />
|
|
||||||
</AssemblyExplorer></s:String></wpf:ResourceDictionary>
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
using PacketLib;
|
|
||||||
|
|
||||||
namespace ONDClient;
|
|
||||||
|
|
||||||
public class ClientPlayer {
|
|
||||||
public PlayerState state;
|
|
||||||
public string username;
|
|
||||||
}
|
|
||||||
|
|
@ -1,24 +1,20 @@
|
||||||
using GlobalClassLib;
|
using GlobalClassLib;
|
||||||
using MonoGameLibrary.Graphics;
|
|
||||||
using ONDClient.GUI;
|
using ONDClient.GUI;
|
||||||
using ONDClient.Map;
|
using ONDClient.Map;
|
||||||
|
|
||||||
namespace ONDClient;
|
namespace ONDClient.Enemies;
|
||||||
|
|
||||||
public class ClientEnemy : GlobalEnemy<MapTileProjection, TileConnectorProjection> {
|
public class ClientEnemy : GlobalEnemy<MapTileProjection, TileConnectorProjection> {
|
||||||
public ClientEnemy(int typeId, string name, int id, EnemyUIElement sprite, int difficulty, MapTileProjection location, JumpscareUIElement jumpscareSprite) : base(id) {
|
public UIElement Sprite { get; set; }
|
||||||
|
public override string Name{ get; }
|
||||||
|
public override EnemyType Type{ get; }
|
||||||
|
public JumpscareUIElement JumpscareSprite { get; set; }
|
||||||
|
|
||||||
|
public ClientEnemy(EnemyType type, string name, int id, EnemyUIElement sprite, MapTileProjection location, JumpscareUIElement jumpscareSprite) : base(id) {
|
||||||
Name = name;
|
Name = name;
|
||||||
TypeId = typeId;
|
Type = type;
|
||||||
Sprite = sprite;
|
Sprite = sprite;
|
||||||
Location = location;
|
Location = location;
|
||||||
JumpscareSprite = jumpscareSprite;
|
JumpscareSprite = jumpscareSprite;
|
||||||
}
|
}
|
||||||
|
|
||||||
// public TextureRegion Sprite { get; set; }
|
|
||||||
|
|
||||||
public UIElement Sprite { get; set; }
|
|
||||||
public override string Name{ get; }
|
|
||||||
public override int TypeId{ get; }
|
|
||||||
|
|
||||||
public JumpscareUIElement JumpscareSprite { get; set; }
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,47 +1,43 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data;
|
|
||||||
using System.Linq;
|
|
||||||
using GlobalClassLib;
|
using GlobalClassLib;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using MonoGameLibrary.Graphics;
|
|
||||||
using ONDClient.GUI;
|
using ONDClient.GUI;
|
||||||
using ONDClient.Map;
|
using ONDClient.Map;
|
||||||
|
|
||||||
namespace ONDClient;
|
namespace ONDClient.Enemies;
|
||||||
|
|
||||||
public static class ClientEnemyManager {
|
public static class ClientEnemyManager {
|
||||||
private static Dictionary<int, ClientEnemy> enemies = new();
|
|
||||||
private static Point cameraCorner = new(64, 64);
|
|
||||||
|
|
||||||
private static Action defaultAfterJumpscare = UIManager.ShowDeathScreen;
|
private static Dictionary<int, ClientEnemy> enemies = new();
|
||||||
|
private static readonly Point cameraCorner = new(64, 64);
|
||||||
|
private static readonly Action defaultAfterJumpscare = UIManager.ShowDeathScreen;
|
||||||
|
|
||||||
public static void AddEnemy(ClientEnemy enemy) {
|
public static void AddEnemy(ClientEnemy enemy) {
|
||||||
enemies.Add(enemy.Id, enemy);
|
enemies.Add(enemy.Id, enemy);
|
||||||
UIManager.AddEnemySprite(enemy.Id, enemy.Sprite, enemy.JumpscareSprite);
|
UIManager.AddEnemySprite(enemy.Id, enemy.Sprite, enemy.JumpscareSprite);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void AddEnemyByTemplate(EnemyType type, int id, int difficulty, MapTileProjection location) {
|
public static void AddEnemyByTemplate(EnemyType type, int id, MapTileProjection location) {
|
||||||
switch (type){
|
switch (type){
|
||||||
case EnemyType.LURK:
|
case EnemyType.LURK:
|
||||||
AddEnemy(new ClientEnemy(
|
AddEnemy(new ClientEnemy(
|
||||||
(int)type,
|
type,
|
||||||
"Lurk",
|
"Lurk",
|
||||||
id,
|
id,
|
||||||
new EnemyUIElement(UIManager.EnemyAtlas["lurk-lit"], UIManager.EnemyAtlas["lurk-unlit"], cameraCorner),
|
new EnemyUIElement(UIManager.EnemyAtlas["lurk-lit"], UIManager.EnemyAtlas["lurk-unlit"], cameraCorner),
|
||||||
difficulty,
|
|
||||||
location,
|
location,
|
||||||
new JumpscareUIElement(UIManager.EnemyAtlas["lurk-lit"], new(0, 0), 3, 2, 2, 0.1f, afterStop:defaultAfterJumpscare)
|
new JumpscareUIElement(UIManager.EnemyAtlas["lurk-lit"], new(0, 0), 3, 2, 2, afterStop:defaultAfterJumpscare)
|
||||||
));
|
));
|
||||||
break;
|
break;
|
||||||
case EnemyType.NEKO:
|
case EnemyType.NEKO:
|
||||||
AddEnemy(new ClientEnemy(
|
AddEnemy(new ClientEnemy(
|
||||||
(int)type,
|
type,
|
||||||
"Neko",
|
"Neko",
|
||||||
id,
|
id,
|
||||||
new EnemyUIElement(UIManager.EnemyAtlas["neko-lit"], UIManager.EnemyAtlas["neko-unlit"], cameraCorner, 1),
|
new EnemyUIElement(UIManager.EnemyAtlas["neko-lit"], UIManager.EnemyAtlas["neko-unlit"], cameraCorner, 1),
|
||||||
difficulty,
|
|
||||||
location,
|
location,
|
||||||
new JumpscareUIElement(UIManager.EnemyAtlas["neko-lit"], new(0, -30), 3, 2, 2, 0.1f, afterStop:defaultAfterJumpscare)
|
new JumpscareUIElement(UIManager.EnemyAtlas["neko-lit"], new(0, -30), 3, 2, 2, afterStop:defaultAfterJumpscare)
|
||||||
));
|
));
|
||||||
break;
|
break;
|
||||||
case EnemyType.SPOT:
|
case EnemyType.SPOT:
|
||||||
|
|
@ -49,35 +45,32 @@ public static class ClientEnemyManager {
|
||||||
new EnemyUIElement([UIManager.EnemyAtlas["spot-awake-lit"], UIManager.EnemyAtlas["spot-asleep-lit"]],[UIManager.EnemyAtlas["spot-awake-unlit"], UIManager.EnemyAtlas["spot-asleep-unlit"]], cameraCorner, 2);
|
new EnemyUIElement([UIManager.EnemyAtlas["spot-awake-lit"], UIManager.EnemyAtlas["spot-asleep-lit"]],[UIManager.EnemyAtlas["spot-awake-unlit"], UIManager.EnemyAtlas["spot-asleep-unlit"]], cameraCorner, 2);
|
||||||
element.SetTexture(true, 1);
|
element.SetTexture(true, 1);
|
||||||
AddEnemy(new ClientEnemy(
|
AddEnemy(new ClientEnemy(
|
||||||
(int)type,
|
type,
|
||||||
"Spot",
|
"Spot",
|
||||||
id,
|
id,
|
||||||
element,
|
element,
|
||||||
difficulty,
|
|
||||||
location,
|
location,
|
||||||
new JumpscareUIElement(UIManager.EnemyAtlas["spot-awake-lit"], new(0, 0), 3, 2, 2, 0.1f, afterStop:defaultAfterJumpscare)
|
new JumpscareUIElement(UIManager.EnemyAtlas["spot-awake-lit"], new(0, 0), 3, 2, 2, afterStop:defaultAfterJumpscare)
|
||||||
));
|
));
|
||||||
break;
|
break;
|
||||||
case EnemyType.DASH:
|
case EnemyType.DASH:
|
||||||
AddEnemy(new ClientEnemy(
|
AddEnemy(new ClientEnemy(
|
||||||
(int)type,
|
type,
|
||||||
"Dash",
|
"Dash",
|
||||||
id,
|
id,
|
||||||
new EnemyUIElement(UIManager.EnemyAtlas["dash-lit"], UIManager.EnemyAtlas["dash-unlit"], cameraCorner, 3),
|
new EnemyUIElement(UIManager.EnemyAtlas["dash-lit"], UIManager.EnemyAtlas["dash-unlit"], cameraCorner, 3),
|
||||||
difficulty,
|
|
||||||
location,
|
location,
|
||||||
new JumpscareUIElement(UIManager.EnemyAtlas["dash-lit"], new(0, 0), 3, 2, 2, 0.1f, afterStop:defaultAfterJumpscare)
|
new JumpscareUIElement(UIManager.EnemyAtlas["dash-lit"], new(0, 0), 3, 2, 2, afterStop:defaultAfterJumpscare)
|
||||||
));
|
));
|
||||||
break;
|
break;
|
||||||
case EnemyType.MARE:
|
case EnemyType.MARE:
|
||||||
AddEnemy(new ClientEnemy(
|
AddEnemy(new ClientEnemy(
|
||||||
(int)type,
|
type,
|
||||||
"Mare",
|
"Mare",
|
||||||
id,
|
id,
|
||||||
new EnemyUIElement(UIManager.EnemyAtlas["mare-lit"], UIManager.EnemyAtlas["mare-unlit"], cameraCorner),
|
new EnemyUIElement(UIManager.EnemyAtlas["mare-lit"], UIManager.EnemyAtlas["mare-unlit"], cameraCorner),
|
||||||
difficulty,
|
|
||||||
location,
|
location,
|
||||||
new JumpscareUIElement(UIManager.EnemyAtlas["mare-lit"], new(0, 0), 3, 2, 2, 0.1f, afterStop:defaultAfterJumpscare)
|
new JumpscareUIElement(UIManager.EnemyAtlas["mare-lit"], new(0, 0), 3, 2, 2, afterStop:defaultAfterJumpscare)
|
||||||
));
|
));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -1,188 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Linq;
|
|
||||||
using GlobalClassLib;
|
|
||||||
using MonoGameLibrary.Input;
|
|
||||||
using ONDClient.GUI;
|
|
||||||
using ONDClient.Map;
|
|
||||||
using PacketLib;
|
|
||||||
|
|
||||||
namespace ONDClient;
|
|
||||||
|
|
||||||
public class EventProcessor {
|
|
||||||
public static void Evaluate(GameEvent[] events) {
|
|
||||||
foreach (var e in events){
|
|
||||||
switch (e.ID){
|
|
||||||
case 0: // join
|
|
||||||
Console.WriteLine("E: Player joined");
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 1: // leave
|
|
||||||
Console.WriteLine("E: Player left");
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 2: // switch cam
|
|
||||||
if (Client.Player.state.pid != e.Args[0]){
|
|
||||||
UIManager.ChangeCameraOpponent(e.Args[1]);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (Client.Player.state.camera != e.Args[1]) Console.WriteLine("!!! DESYNC: CAMERA STATE");
|
|
||||||
Console.WriteLine($"E: player {e.Args[0]} switched to camera {e.Args[1]}");
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 3: // toggle cam
|
|
||||||
Console.WriteLine($"E: Player {e.Args[0]} toggled monitor {(e.Args[1] == 0 ? "off" : "on")}");
|
|
||||||
|
|
||||||
if (e.Args[0] != Client.Player.state.pid){
|
|
||||||
UIManager.ChangeMonitorStateOpponent(e.Args[1] == 1);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Client.Player.state.monitorUp != (e.Args[1] == 1)) Console.WriteLine("!!! DESYNC: MONITOR STATE");
|
|
||||||
|
|
||||||
// UIManager.ChangeMonitorState(e.Args[1] == 1);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 4: // toggle door
|
|
||||||
Console.WriteLine($"E: Player {e.Args[0]} {(e.Args[2] == 1 ? "closed" : "opened")} door {e.Args[1]}");
|
|
||||||
|
|
||||||
if (e.Args[0] == Client.Player.state.pid){
|
|
||||||
if (Client.Player.state.doorStates[e.Args[1]] != (e.Args[2] == 1)) Console.WriteLine("!!! DESYNC: DOOR STATE");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
Client.Opponent.state.doorStates[e.Args[1]] = e.Args[2] == 1;
|
|
||||||
UIManager.ChangeDoorStateOpponent((Direction)e.Args[1], e.Args[2] == 1);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 5: // toggle remote door
|
|
||||||
Console.WriteLine($"E: Player {e.Args[0]} {(e.Args[3] == 1 ? "closed" : "opened")} door {e.Args[1]}-{e.Args[2]}");
|
|
||||||
|
|
||||||
if (e.Args[0] == Client.Player.state.pid){
|
|
||||||
if (ClientMapManager.GetConnector((e.Args[1], e.Args[2])).Blocked != (e.Args[3] == 1)) Console.WriteLine("!!! DESYNC: REMOTE DOOR STATE");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
ClientMapManager.GetConnector((e.Args[1], e.Args[2])).Blocked = e.Args[3] == 1;
|
|
||||||
UIManager.ChangeRemoteDoorState((e.Args[1], e.Args[2]), e.Args[3] == 1);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 6: // spawn
|
|
||||||
Console.WriteLine($"E: Spawned enemy {e.Args[0]} at {e.Args[3]}");
|
|
||||||
ClientEnemyManager.AddEnemyByTemplate((EnemyType)e.Args[0], e.Args[1], e.Args[2], ClientMapManager.Get(e.Args[3]));
|
|
||||||
UIManager.UpdateCameras([e.Args[3]]);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 7: // movement
|
|
||||||
Console.WriteLine($"E: Enemy {e.Args[0]} moved to {e.Args[1]}");
|
|
||||||
int oldPos = ClientEnemyManager.Get(e.Args[0]).Location!.Id;
|
|
||||||
ClientEnemyManager.Move(e.Args[0], ClientMapManager.Get(e.Args[1]));
|
|
||||||
UIManager.UpdateCameras([oldPos, e.Args[1]]);
|
|
||||||
SoundManager.PlayEnemyMove(ClientEnemyManager.Get(e.Args[0]));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 8: // attack
|
|
||||||
Console.WriteLine($"E: Enemy {e.Args[0]} attacked player {e.Args[1]}"); // TODO: add an arg to indicate lethality
|
|
||||||
if (e.Args[1] == Client.Player.state.pid) {
|
|
||||||
UIManager.Jumpscare(ClientEnemyManager.Get(e.Args[0]));
|
|
||||||
SoundManager.PlayJumpscare();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 9: // reset
|
|
||||||
Console.WriteLine($"E: Enemy {e.Args[0]} reset to {e.Args[1]}");
|
|
||||||
int preResetPos = ClientEnemyManager.Get(e.Args[0]).Location!.Id;
|
|
||||||
ClientEnemyManager.Move(e.Args[0], ClientMapManager.Get(e.Args[1]));
|
|
||||||
UIManager.UpdateCameras([preResetPos, e.Args[1]]);
|
|
||||||
SoundManager.PlayEnemyReset(ClientEnemyManager.Get(e.Args[0]));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 10:
|
|
||||||
Console.WriteLine($"E: Spot:{e.Args[0]} turned {(e.Args[1] == 1 ? "on" : " off")}");
|
|
||||||
ClientEnemyManager.Get(e.Args[0]).Sprite.SetTexture(e.Args[1] == 1 ? 0 : 1);
|
|
||||||
SoundManager.PlaySpotActivate();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 11:
|
|
||||||
Console.WriteLine($"E: Player {e.Args[0]} won");
|
|
||||||
if(Client.Player.state.pid == e.Args[0]) UIManager.ShowVictoryScreen();
|
|
||||||
Client.Disconnect();
|
|
||||||
ClientEnemyManager.ClearEnemies();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 12: // game start
|
|
||||||
Console.WriteLine("E: Game started");
|
|
||||||
UIManager.DisplayGameUI();
|
|
||||||
UIManager.StartTimer();
|
|
||||||
SoundManager.StartAmbience();
|
|
||||||
Client.State = Client.ConnectionState.GAME_IN_PROGRESS;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 13:
|
|
||||||
// Console.WriteLine($"E: power tick {e.Args[0]}: {e.Args[1]}");
|
|
||||||
if (e.Args[0] == Client.Player.state.pid){
|
|
||||||
Client.Player.state.power = e.Args[1];
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
Client.Opponent.state.power = e.Args[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 14: // powerout
|
|
||||||
Console.WriteLine($"E: Player {e.Args[0]} powered out");
|
|
||||||
ClientMapManager.GetAllConnectors().Where(c =>
|
|
||||||
(c.Type == ConnectorType.DOOR_REMOTE || c.Type == ConnectorType.DOOR_OFFICE) &&
|
|
||||||
c.Owner == Client.GetPlayer(e.Args[0])).ToList().ForEach(c =>
|
|
||||||
{
|
|
||||||
c.Blocked = false;
|
|
||||||
if(c.Type == ConnectorType.DOOR_REMOTE)
|
|
||||||
UIManager.ChangeRemoteDoorState(c.Id, false);
|
|
||||||
});
|
|
||||||
foreach (var tile in ClientMapManager.GetAllTiles()){
|
|
||||||
tile.Lit = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (e.Args[0] == Client.Player.state.pid){
|
|
||||||
UIManager.ChangeDoorState(Direction.EAST, false);
|
|
||||||
UIManager.ChangeDoorState(Direction.NORTH, false);
|
|
||||||
UIManager.ChangeDoorState(Direction.WEST, false);
|
|
||||||
CommandManager.AllowGameControls(false);
|
|
||||||
UIManager.ChangeMonitorState(false);
|
|
||||||
SoundManager.PlayPowerOut();
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
UIManager.ChangeDoorStateOpponent(Direction.EAST, false);
|
|
||||||
UIManager.ChangeDoorStateOpponent(Direction.NORTH, false);
|
|
||||||
UIManager.ChangeDoorStateOpponent(Direction.WEST, false);
|
|
||||||
UIManager.ChangeMonitorStateOpponent(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 15: // light
|
|
||||||
bool lightState = e.Args[2] == 1;
|
|
||||||
Console.WriteLine($"E: Player {e.Args[0]} {(lightState ? "lit": "unlit")} tile {e.Args[1]}");
|
|
||||||
if (e.Args[0] == Client.Player.state.pid){
|
|
||||||
if (ClientMapManager.Get(e.Args[1]).Lit != lightState) Console.WriteLine("!!! DESYNC: LIGHT STATE");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
ClientMapManager.Get(e.Args[1]).Lit = lightState;
|
|
||||||
UIManager.UpdateCameras([e.Args[1]]);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 16: // neko anger
|
|
||||||
SoundManager.PlayNekoAnger();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 17:
|
|
||||||
SoundManager.PlayVentWalk();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 18:
|
|
||||||
SoundManager.PlayBell();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -5,7 +5,7 @@ using MonoGameLibrary.Graphics;
|
||||||
namespace ONDClient.GUI;
|
namespace ONDClient.GUI;
|
||||||
|
|
||||||
public class EnemyUIElement : UIElement {
|
public class EnemyUIElement : UIElement {
|
||||||
private int unlitTexturesId;
|
private readonly int unlitTexturesId;
|
||||||
private bool currentlyLit = true;
|
private bool currentlyLit = true;
|
||||||
|
|
||||||
public EnemyUIElement(TextureRegion litTexture, TextureRegion unlitTexture, Point position, int drawPriority = 0) : base([litTexture, unlitTexture], position, drawPriority) {
|
public EnemyUIElement(TextureRegion litTexture, TextureRegion unlitTexture, Point position, int drawPriority = 0) : base([litTexture, unlitTexture], position, drawPriority) {
|
||||||
|
|
@ -28,6 +28,6 @@ public class EnemyUIElement : UIElement {
|
||||||
public void SetTexture(bool lit) {
|
public void SetTexture(bool lit) {
|
||||||
if(lit == currentlyLit) return;
|
if(lit == currentlyLit) return;
|
||||||
currentlyLit = lit;
|
currentlyLit = lit;
|
||||||
SetTexture(lit ? currentTextureId - unlitTexturesId : currentTextureId);
|
SetTexture(lit ? CurrentTextureId - unlitTexturesId : CurrentTextureId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -10,29 +10,23 @@ public class JumpscareUIElement : UIElement {
|
||||||
private int twitchVertical;
|
private int twitchVertical;
|
||||||
private Point positionDefault;
|
private Point positionDefault;
|
||||||
private Random random;
|
private Random random;
|
||||||
private float defaultScaleMultiplier;
|
|
||||||
private float twitchScale;
|
|
||||||
|
|
||||||
private bool playing = false;
|
private bool playing = false;
|
||||||
private Stopwatch stopwatch = new();
|
private Stopwatch stopwatch = new();
|
||||||
private int duration;
|
private int duration;
|
||||||
|
|
||||||
public JumpscareUIElement(TextureRegion texture, Point positionDefault, int twitchHorizontal, int twitchVertical, float defaultScaleMultiplier, float twitchScale, int durationMs = 2000, Action afterStop = null) : base(texture, positionDefault) {
|
public JumpscareUIElement(TextureRegion texture, Point positionDefault, int twitchHorizontal, int twitchVertical, float defaultScaleMultiplier, int durationMs = 2000, Action afterStop = null) : base(texture, positionDefault) {
|
||||||
this.twitchHorizontal = twitchHorizontal;
|
this.twitchHorizontal = twitchHorizontal;
|
||||||
this.twitchVertical = twitchVertical;
|
this.twitchVertical = twitchVertical;
|
||||||
this.positionDefault = positionDefault;
|
this.positionDefault = positionDefault;
|
||||||
random = new Random();
|
random = new Random();
|
||||||
this.defaultScaleMultiplier = defaultScaleMultiplier;
|
|
||||||
ScaleMultiplier = defaultScaleMultiplier;
|
ScaleMultiplier = defaultScaleMultiplier;
|
||||||
this.twitchScale = twitchScale;
|
|
||||||
duration = durationMs;
|
duration = durationMs;
|
||||||
Active = false;
|
Active = false;
|
||||||
Visible = false;
|
Visible = false;
|
||||||
AfterStop = afterStop;
|
AfterStop = afterStop;
|
||||||
}
|
}
|
||||||
|
|
||||||
// public JumpscareUIElement(UIElement element) : base(element.GetTextures(), element.Bounds.Item1) {}
|
|
||||||
|
|
||||||
public void Play() {
|
public void Play() {
|
||||||
playing = true;
|
playing = true;
|
||||||
Active = true;
|
Active = true;
|
||||||
|
|
@ -51,8 +45,6 @@ public class JumpscareUIElement : UIElement {
|
||||||
AfterStop();
|
AfterStop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ScaleMultiplier = defaultScaleMultiplier + (float)(random.NextDouble() * twitchScale * new[]{-1, 1}[random.Next(2)]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Action AfterStop;
|
private Action AfterStop;
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,17 @@
|
||||||
using System;
|
using System;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using ONDClient.Net;
|
||||||
|
|
||||||
namespace ONDClient.GUI;
|
namespace ONDClient.GUI;
|
||||||
|
|
||||||
public class LoadingUIElement : TextUIElement {
|
public class LoadingUIElement : TextUIElement {
|
||||||
private Func<string> expectedEndpointGetter;
|
private readonly Func<string> expectedEndpointGetter;
|
||||||
private Client.ConnectionState lastState = Client.ConnectionState.IDLE;
|
private Client.ConnectionState lastState = Client.ConnectionState.IDLE;
|
||||||
|
|
||||||
public LoadingUIElement(Point corner1, SpriteFont font, Func<string> expectedEndpointGetter, Alignment alignment = Alignment.CENTER, bool autoBounds = true) : base(corner1, font, alignment, autoBounds) {
|
public LoadingUIElement(Point corner1, SpriteFont font, Func<string> expectedEndpointGetter, Alignment alignment = Alignment.CENTER, bool autoBounds = true) : base(corner1, font, alignment, autoBounds) {
|
||||||
this.expectedEndpointGetter = expectedEndpointGetter;
|
this.expectedEndpointGetter = expectedEndpointGetter;
|
||||||
Active = true;
|
Active = true;
|
||||||
// Color = Color.LightGray;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Update() {
|
public override void Update() {
|
||||||
|
|
@ -29,9 +29,8 @@ public class LoadingUIElement : TextUIElement {
|
||||||
Text = "Waiting for opponent...";
|
Text = "Waiting for opponent...";
|
||||||
break;
|
break;
|
||||||
case Client.ConnectionState.GAME_STARTING:
|
case Client.ConnectionState.GAME_STARTING:
|
||||||
Text = "Opponent: " + Client.Opponent.username;
|
Text = "Opponent: " + Client.Opponent.Username;
|
||||||
Color = Color.White;
|
Color = Color.White;
|
||||||
// ScaleMultiplier = 1.5f;
|
|
||||||
break;
|
break;
|
||||||
case Client.ConnectionState.IDLE:
|
case Client.ConnectionState.IDLE:
|
||||||
Text = "Idle";
|
Text = "Idle";
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,11 @@
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
using MonoGameLibrary.Graphics;
|
|
||||||
|
|
||||||
namespace ONDClient.GUI;
|
namespace ONDClient.GUI;
|
||||||
|
|
||||||
public class MenuInputField : UIElement {
|
public class MenuInputField : UIElement {
|
||||||
private TextUIElement labelElement;
|
private readonly TextUIElement labelElement;
|
||||||
private TextBoxUIElement textBoxElement;
|
private readonly TextBoxUIElement textBoxElement;
|
||||||
|
|
||||||
public MenuInputField(SpriteFont font, Point position, string label, string defaultValue = "") : base(position, position) {
|
public MenuInputField(SpriteFont font, Point position, string label, string defaultValue = "") : base(position, position) {
|
||||||
labelElement =
|
labelElement =
|
||||||
|
|
|
||||||
|
|
@ -1,26 +1,27 @@
|
||||||
using GlobalClassLib;
|
using GlobalClassLib;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using ONDClient.Net;
|
||||||
|
|
||||||
namespace ONDClient.GUI;
|
namespace ONDClient.GUI;
|
||||||
|
|
||||||
public class PowerIndicator : TextUIElement {
|
public class PowerIndicator : TextUIElement {
|
||||||
private string label;
|
private readonly string label;
|
||||||
private ClientPlayer player;
|
private readonly ClientPlayer player;
|
||||||
private int lastPowerValue;
|
private int lastPowerValue;
|
||||||
|
|
||||||
public PowerIndicator(Point corner1, SpriteFont font, ClientPlayer player, string label, Alignment alignment = Alignment.LEFT) : base(corner1, font, alignment, autoBounds:true) {
|
public PowerIndicator(Point corner1, SpriteFont font, ClientPlayer player, string label, Alignment alignment = Alignment.LEFT) : base(corner1, font, alignment, autoBounds:true) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.label = label;
|
this.label = label;
|
||||||
lastPowerValue = player.state.power;
|
lastPowerValue = player.State.Power;
|
||||||
Text = GetText();
|
Text = GetText();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Update() {
|
public override void Update() {
|
||||||
if (player.state.power == lastPowerValue) return;
|
if (player.State.Power == lastPowerValue) return;
|
||||||
lastPowerValue = player.state.power;
|
lastPowerValue = player.State.Power;
|
||||||
Text = GetText();
|
Text = GetText();
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetText() => $"{label}{(int)(((float)player.state.power / Power.MAX_POWER_VALUE) * 100)}";
|
private string GetText() => $"{label}{(int)(((float)player.State.Power / Power.MAX_POWER_VALUE) * 100)}";
|
||||||
}
|
}
|
||||||
|
|
@ -2,6 +2,7 @@ using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
using Microsoft.Xna.Framework.Input;
|
using Microsoft.Xna.Framework.Input;
|
||||||
using MonoGameLibrary.Input;
|
using MonoGameLibrary.Input;
|
||||||
|
using ONDClient.Net;
|
||||||
|
|
||||||
namespace ONDClient.GUI;
|
namespace ONDClient.GUI;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Microsoft.VisualBasic.CompilerServices;
|
using System.Linq;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
using Microsoft.Xna.Framework.Input;
|
using Microsoft.Xna.Framework.Input;
|
||||||
using MonoGameLibrary.Input;
|
using MonoGameLibrary.Input;
|
||||||
|
|
@ -9,36 +9,36 @@ namespace ONDClient.GUI;
|
||||||
|
|
||||||
public class Screen {
|
public class Screen {
|
||||||
|
|
||||||
public static Dictionary<string, Screen> Screens = new();
|
private static Dictionary<string, Screen> screens = new();
|
||||||
public static Screen CurrentScreen{ get; private set; } = Empty;
|
public static Screen CurrentScreen{ get; private set; } = Empty;
|
||||||
public static Screen OverlayScreen{ get; private set; } = Empty;
|
public static Screen OverlayScreen{ get; private set; } = Empty;
|
||||||
|
|
||||||
public static void AddScreens(Screen[] screens) {
|
public static void AddScreens(Screen[] screensToAdd) {
|
||||||
foreach (var screen in screens){
|
foreach (var screen in screensToAdd){
|
||||||
Screens.Add(screen.Label, screen);
|
Screen.screens.Add(screen.Label, screen);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static void AddScreen(string id, Screen screen, bool activate = false) {
|
public static void AddScreen(string id, Screen screen, bool activate = false) {
|
||||||
Screens.Add(id, screen);
|
screens.Add(id, screen);
|
||||||
if (activate) SetScreen(id);
|
if (activate) SetScreen(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SetScreen(string id) {
|
public static void SetScreen(string id) {
|
||||||
if (CurrentScreen.temporary){
|
if (CurrentScreen.temporary){
|
||||||
Screens.Remove(CurrentScreen.Label);
|
screens.Remove(CurrentScreen.Label);
|
||||||
}
|
}
|
||||||
|
|
||||||
CurrentScreen.Active = false;
|
CurrentScreen.Active = false;
|
||||||
CurrentScreen = Screens[id];
|
CurrentScreen = screens[id];
|
||||||
CurrentScreen.Active = true;
|
CurrentScreen.Active = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void RemoveScreen(string id) {
|
public static void RemoveScreen(string id) {
|
||||||
Screens.Remove(id);
|
screens.Remove(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void UpdateAll() {
|
public static void UpdateAll() {
|
||||||
foreach (var screen in Screens.Values){
|
foreach (var screen in screens.Values){
|
||||||
if (!screen.Active) continue;
|
if (!screen.Active) continue;
|
||||||
screen.Update();
|
screen.Update();
|
||||||
}
|
}
|
||||||
|
|
@ -47,11 +47,11 @@ public class Screen {
|
||||||
|
|
||||||
public static void SetOverlayScreen(string id) {
|
public static void SetOverlayScreen(string id) {
|
||||||
if (OverlayScreen.temporary){
|
if (OverlayScreen.temporary){
|
||||||
Screens.Remove(OverlayScreen.Label);
|
screens.Remove(OverlayScreen.Label);
|
||||||
}
|
}
|
||||||
|
|
||||||
OverlayScreen.Active = false;
|
OverlayScreen.Active = false;
|
||||||
OverlayScreen = Screens[id];
|
OverlayScreen = screens[id];
|
||||||
OverlayScreen.Active = true;
|
OverlayScreen.Active = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -64,6 +64,8 @@ public class Screen {
|
||||||
OverlayScreen.Draw(spriteBatch);
|
OverlayScreen.Draw(spriteBatch);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Screen[] GetAllScreens() => screens.Values.ToArray();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public string Label{ get; }
|
public string Label{ get; }
|
||||||
|
|
@ -118,15 +120,6 @@ public class Screen {
|
||||||
temporaryElements.Clear();
|
temporaryElements.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetActive(bool active) {
|
|
||||||
Active = active;
|
|
||||||
if (Active == active) return;
|
|
||||||
foreach (var keyValuePair in elements){
|
|
||||||
keyValuePair.Value.Active = Active;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ProcessMouseInput(MouseState mouseState) {
|
private void ProcessMouseInput(MouseState mouseState) {
|
||||||
if (!Active){
|
if (!Active){
|
||||||
return;
|
return;
|
||||||
|
|
@ -135,19 +128,19 @@ public class Screen {
|
||||||
if (!element.Pressable) continue;
|
if (!element.Pressable) continue;
|
||||||
|
|
||||||
if (element.IsWithinBounds(mouseState.Position)){
|
if (element.IsWithinBounds(mouseState.Position)){
|
||||||
element.OnMousePress(); // TODO: differentiate between press, hold and release events
|
element.OnMousePress();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Update() {
|
private void Update() {
|
||||||
foreach (var element in elements.Values){
|
foreach (var element in elements.Values){
|
||||||
if (!element.Active) continue;
|
if (!element.Active) continue;
|
||||||
element.Update();
|
element.Update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Draw(SpriteBatch spriteBatch) {
|
private void Draw(SpriteBatch spriteBatch) {
|
||||||
foreach (var val in elementsInDrawOrder){
|
foreach (var val in elementsInDrawOrder){
|
||||||
val.Draw(spriteBatch);
|
val.Draw(spriteBatch);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ using System;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
using MonoGameLibrary;
|
using MonoGameLibrary;
|
||||||
using MonoGameLibrary.Graphics;
|
|
||||||
using MonoGameLibrary.Input;
|
using MonoGameLibrary.Input;
|
||||||
|
|
||||||
namespace ONDClient.GUI;
|
namespace ONDClient.GUI;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
using MonoGameLibrary.Graphics;
|
|
||||||
|
|
||||||
namespace ONDClient.GUI;
|
namespace ONDClient.GUI;
|
||||||
|
|
||||||
|
|
@ -20,6 +19,7 @@ public class TextUIElement : UIElement {
|
||||||
|
|
||||||
public Color Color{ get; set; } = Color.White;
|
public Color Color{ get; set; } = Color.White;
|
||||||
public bool AutoBounds{ get; protected set; } = false;
|
public bool AutoBounds{ get; protected set; } = false;
|
||||||
|
|
||||||
private Vector2 origin;
|
private Vector2 origin;
|
||||||
private const float UNIVERSAL_TEXT_SCALE_MULTIPLIER = 0.3f;
|
private const float UNIVERSAL_TEXT_SCALE_MULTIPLIER = 0.3f;
|
||||||
|
|
||||||
|
|
@ -39,7 +39,7 @@ public class TextUIElement : UIElement {
|
||||||
if(!Visible || !Active) return;
|
if(!Visible || !Active) return;
|
||||||
base.Draw(spriteBatch);
|
base.Draw(spriteBatch);
|
||||||
align();
|
align();
|
||||||
spriteBatch.DrawString(Font, Text, screenSpaceBounds.Item1.ToVector2(), Color, 0, origin, pixelScaleMultiplier * UNIVERSAL_TEXT_SCALE_MULTIPLIER, SpriteEffects.None, 0);
|
spriteBatch.DrawString(Font, Text, ScreenSpaceBounds.Item1.ToVector2(), Color, 0, origin, pixelScaleMultiplier * UNIVERSAL_TEXT_SCALE_MULTIPLIER, SpriteEffects.None, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Align(Alignment alignment) {
|
public void Align(Alignment alignment) {
|
||||||
|
|
@ -60,7 +60,7 @@ public class TextUIElement : UIElement {
|
||||||
protected override void UpdateBounds() {
|
protected override void UpdateBounds() {
|
||||||
Point inSpaceOrigin = Bounds.Item1 + origin.ToPoint();
|
Point inSpaceOrigin = Bounds.Item1 + origin.ToPoint();
|
||||||
_bounds = ((Bounds.Item1 - inSpaceOrigin).MultiplyByScalar(ScaleMultiplier) + inSpaceOrigin, (Bounds.Item2 - Bounds.Item1).MultiplyByScalar(ScaleMultiplier) + inSpaceOrigin);
|
_bounds = ((Bounds.Item1 - inSpaceOrigin).MultiplyByScalar(ScaleMultiplier) + inSpaceOrigin, (Bounds.Item2 - Bounds.Item1).MultiplyByScalar(ScaleMultiplier) + inSpaceOrigin);
|
||||||
screenSpaceBounds = (Bounds.Item1.MultiplyByScalar(pixelScaleMultiplier), Bounds.Item2.MultiplyByScalar(pixelScaleMultiplier));
|
ScreenSpaceBounds = (Bounds.Item1.MultiplyByScalar(pixelScaleMultiplier), Bounds.Item2.MultiplyByScalar(pixelScaleMultiplier));
|
||||||
Align(CurrentAlignment);
|
Align(CurrentAlignment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
using System;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
|
@ -8,7 +7,6 @@ namespace ONDClient.GUI;
|
||||||
public class TimerUIElement : TextUIElement{
|
public class TimerUIElement : TextUIElement{
|
||||||
private Stopwatch stopwatch = new();
|
private Stopwatch stopwatch = new();
|
||||||
|
|
||||||
|
|
||||||
public TimerUIElement(Point corner1, SpriteFont font) : base(corner1, font) {
|
public TimerUIElement(Point corner1, SpriteFont font) : base(corner1, font) {
|
||||||
Text = "00:00.000";
|
Text = "00:00.000";
|
||||||
Bounds = (corner1, corner1 + new Point((int)Measure().X, (int)Measure().Y));
|
Bounds = (corner1, corner1 + new Point((int)Measure().X, (int)Measure().Y));
|
||||||
|
|
@ -17,7 +15,6 @@ public class TimerUIElement : TextUIElement{
|
||||||
public override void Update() {
|
public override void Update() {
|
||||||
if (stopwatch.IsRunning){
|
if (stopwatch.IsRunning){
|
||||||
Text = stopwatch.Elapsed.ToString("mm\\:ss\\.fff");
|
Text = stopwatch.Elapsed.ToString("mm\\:ss\\.fff");
|
||||||
// Text = stopwatch.ElapsedMilliseconds.ToString();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,31 +1,28 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Net.Mime;
|
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
using MonoGameLibrary;
|
|
||||||
using MonoGameLibrary.Graphics;
|
using MonoGameLibrary.Graphics;
|
||||||
using MonoGameLibrary.Input;
|
|
||||||
|
|
||||||
namespace ONDClient.GUI;
|
namespace ONDClient.GUI;
|
||||||
|
|
||||||
public class UIElement {
|
public class UIElement {
|
||||||
|
public static int GlobalPixelMultiplier{ get; set; }
|
||||||
|
|
||||||
public bool Active { get; set; } = true;
|
public bool Active { get; set; } = true;
|
||||||
public bool Pressable { get; set; } = false;
|
public bool Pressable { get; set; } = false;
|
||||||
public bool Visible { get; set; } = true;
|
public bool Visible { get; set; } = true;
|
||||||
public int DrawPriority { get; } = 0;
|
public int DrawPriority { get; } = 0;
|
||||||
|
|
||||||
protected (Point, Point) _bounds;
|
|
||||||
public (Point, Point) Bounds{
|
public (Point, Point) Bounds{
|
||||||
get => _bounds;
|
get => _bounds;
|
||||||
protected set { _bounds = value; UpdateBounds(); }
|
protected set { _bounds = value; UpdateBounds(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
protected (Point, Point) screenSpaceBounds;
|
protected (Point, Point) _bounds;
|
||||||
public List<TextureRegion> Textures = new();
|
protected (Point, Point) ScreenSpaceBounds;
|
||||||
protected int currentTextureId = 0;
|
protected int CurrentTextureId = 0;
|
||||||
|
|
||||||
|
private List<TextureRegion> textures = new();
|
||||||
private float _scaleMultiplier = 1;
|
private float _scaleMultiplier = 1;
|
||||||
public float ScaleMultiplier{
|
public float ScaleMultiplier{
|
||||||
get{
|
get{
|
||||||
|
|
@ -38,23 +35,23 @@ public class UIElement {
|
||||||
}
|
}
|
||||||
protected int pixelScaleMultiplier = 1;
|
protected int pixelScaleMultiplier = 1;
|
||||||
private void LoadPixelScaleMultiplier() {
|
private void LoadPixelScaleMultiplier() {
|
||||||
pixelScaleMultiplier = (int)(UIManager.GlobalPixelMultiplier * _scaleMultiplier); // TODO: move GlobalPixelMultiplier somewhere where it would make sense
|
pixelScaleMultiplier = (int)(GlobalPixelMultiplier * _scaleMultiplier);
|
||||||
UpdateBounds();
|
UpdateBounds();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void UpdateBounds() {
|
protected virtual void UpdateBounds() {
|
||||||
_bounds = (Bounds.Item1, (Bounds.Item2 - Bounds.Item1).MultiplyByScalar(ScaleMultiplier) + Bounds.Item1);
|
_bounds = (Bounds.Item1, (Bounds.Item2 - Bounds.Item1).MultiplyByScalar(ScaleMultiplier) + Bounds.Item1);
|
||||||
screenSpaceBounds = (Bounds.Item1.MultiplyByScalar(pixelScaleMultiplier), Bounds.Item2.MultiplyByScalar(pixelScaleMultiplier));
|
ScreenSpaceBounds = (Bounds.Item1.MultiplyByScalar(pixelScaleMultiplier), Bounds.Item2.MultiplyByScalar(pixelScaleMultiplier));
|
||||||
}
|
}
|
||||||
|
|
||||||
public UIElement(TextureRegion texture, Point position, int drawPriority = 0) {
|
public UIElement(TextureRegion texture, Point position, int drawPriority = 0) {
|
||||||
Textures.Add(texture);
|
textures.Add(texture);
|
||||||
Bounds = (position, position + new Point(texture.Width, texture.Height));
|
Bounds = (position, position + new Point(texture.Width, texture.Height));
|
||||||
DrawPriority = drawPriority;
|
DrawPriority = drawPriority;
|
||||||
LoadPixelScaleMultiplier();
|
LoadPixelScaleMultiplier();
|
||||||
}
|
}
|
||||||
public UIElement(TextureRegion[] textures, Point position, int drawPriority = 0) {
|
public UIElement(TextureRegion[] textures, Point position, int drawPriority = 0) {
|
||||||
this.Textures.AddRange(textures);
|
this.textures.AddRange(textures);
|
||||||
Bounds = (position, position + new Point(textures[0].Width, textures[0].Height));
|
Bounds = (position, position + new Point(textures[0].Width, textures[0].Height));
|
||||||
DrawPriority = drawPriority;
|
DrawPriority = drawPriority;
|
||||||
LoadPixelScaleMultiplier();
|
LoadPixelScaleMultiplier();
|
||||||
|
|
@ -67,44 +64,41 @@ public class UIElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void SetTexture(int textureId) {
|
public virtual void SetTexture(int textureId) {
|
||||||
if (textureId >= Textures.Count){
|
if (textureId >= textures.Count){
|
||||||
Console.WriteLine($"WARNING: TEXTURE {textureId} OUT OF BOUNDS");
|
Console.WriteLine($"WARNING: TEXTURE {textureId} OUT OF BOUNDS");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
currentTextureId = textureId;
|
CurrentTextureId = textureId;
|
||||||
}
|
}
|
||||||
public virtual void Update() { }
|
public virtual void Update() { }
|
||||||
|
|
||||||
public bool IsWithinBounds(Point pos) {
|
public bool IsWithinBounds(Point pos) {
|
||||||
return pos.X >= Math.Min(screenSpaceBounds.Item1.X, screenSpaceBounds.Item2.X) && pos.X <= Math.Max(screenSpaceBounds.Item1.X, screenSpaceBounds.Item2.X) &&
|
return pos.X >= Math.Min(ScreenSpaceBounds.Item1.X, ScreenSpaceBounds.Item2.X) && pos.X <= Math.Max(ScreenSpaceBounds.Item1.X, ScreenSpaceBounds.Item2.X) &&
|
||||||
pos.Y >= Math.Min(screenSpaceBounds.Item1.Y, screenSpaceBounds.Item2.Y) && pos.Y <= Math.Max(screenSpaceBounds.Item1.Y, screenSpaceBounds.Item2.Y);
|
pos.Y >= Math.Min(ScreenSpaceBounds.Item1.Y, ScreenSpaceBounds.Item2.Y) && pos.Y <= Math.Max(ScreenSpaceBounds.Item1.Y, ScreenSpaceBounds.Item2.Y);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Action OnMousePress{ get; set; }
|
public Action OnMousePress{ get; set; }
|
||||||
|
|
||||||
// public virtual void OnMousePress() { }
|
// public virtual void OnMouseRelease() { }
|
||||||
|
// public virtual void OnMouseHold() { }
|
||||||
public virtual void OnMouseRelease() { }
|
|
||||||
|
|
||||||
public virtual void OnMouseHold() { }
|
|
||||||
|
|
||||||
public virtual void Draw(SpriteBatch spriteBatch) {
|
public virtual void Draw(SpriteBatch spriteBatch) {
|
||||||
if (!Visible || !Active || Textures.Count == 0){
|
if (!Visible || !Active || textures.Count == 0){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Textures[currentTextureId].Draw(spriteBatch, screenSpaceBounds.Item1.ToVector2(), Color.White, 0, Vector2.Zero, pixelScaleMultiplier, SpriteEffects.None, 0);
|
textures[CurrentTextureId].Draw(spriteBatch, ScreenSpaceBounds.Item1.ToVector2(), Color.White, 0, Vector2.Zero, pixelScaleMultiplier, SpriteEffects.None, 0);
|
||||||
// texture.Draw(spriteBatch, bounds.Item1.ToVector2(), Color.White);
|
// texture.Draw(spriteBatch, bounds.Item1.ToVector2(), Color.White);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetPosition(Point position) {
|
public void SetPosition(Point position) {
|
||||||
Bounds = (position, position + new Point(Textures[0].Width, Textures[0].Height));
|
Bounds = (position, position + new Point(textures[0].Width, textures[0].Height));
|
||||||
}
|
}
|
||||||
|
|
||||||
public UIElement Clone() {
|
public UIElement Clone() {
|
||||||
return new UIElement(Textures.ToArray(), Bounds.Item1);
|
return new UIElement(textures.ToArray(), Bounds.Item1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TextureRegion[] GetTextures() => Textures.ToArray();
|
public TextureRegion[] GetTextures() => textures.ToArray();
|
||||||
}
|
}
|
||||||
|
|
@ -8,11 +8,14 @@ using Microsoft.Xna.Framework.Input;
|
||||||
using MonoGameLibrary;
|
using MonoGameLibrary;
|
||||||
using MonoGameLibrary.Graphics;
|
using MonoGameLibrary.Graphics;
|
||||||
using MonoGameLibrary.Input;
|
using MonoGameLibrary.Input;
|
||||||
|
using ONDClient.Enemies;
|
||||||
using ONDClient.Map;
|
using ONDClient.Map;
|
||||||
|
using ONDClient.Net;
|
||||||
|
using ONDClient.Sound;
|
||||||
|
|
||||||
namespace ONDClient.GUI;
|
namespace ONDClient.GUI;
|
||||||
|
|
||||||
public class UIManager {
|
public static class UIManager {
|
||||||
|
|
||||||
public static class ScreenTypes {
|
public static class ScreenTypes {
|
||||||
public const string OFFICE = "office";
|
public const string OFFICE = "office";
|
||||||
|
|
@ -24,35 +27,31 @@ public class UIManager {
|
||||||
public const string LOADING = "loading";
|
public const string LOADING = "loading";
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Screen officeScreen = new(ScreenTypes.OFFICE);
|
private static readonly Screen officeScreen = new(ScreenTypes.OFFICE);
|
||||||
private static Screen monitorScreen = new(ScreenTypes.CAMERAS);
|
private static readonly Screen monitorScreen = new(ScreenTypes.CAMERAS);
|
||||||
private static Screen overlayScreen = new(ScreenTypes.OVERLAY);
|
private static readonly Screen overlayScreen = new(ScreenTypes.OVERLAY);
|
||||||
private static Screen winScreen = new(ScreenTypes.WIN);
|
private static readonly Screen winScreen = new(ScreenTypes.WIN);
|
||||||
private static Screen loseScreen = new(ScreenTypes.LOSE);
|
private static readonly Screen loseScreen = new(ScreenTypes.LOSE);
|
||||||
private static Screen menuScreen = new(ScreenTypes.MENU);
|
private static readonly Screen menuScreen = new(ScreenTypes.MENU);
|
||||||
private static Screen loadingScreen = new(ScreenTypes.LOADING);
|
private static readonly Screen loadingScreen = new(ScreenTypes.LOADING);
|
||||||
|
|
||||||
private static TextureAtlas testAtlas;
|
// private static TextureAtlas testAtlas;
|
||||||
public static TextureAtlas OfficeAtlas{ get; private set; }
|
public static TextureAtlas OfficeAtlas{ get; private set; }
|
||||||
public static TextureAtlas MonitorAtlas{ get; private set; }
|
public static TextureAtlas MonitorAtlas{ get; private set; }
|
||||||
public static TextureAtlas EnemyAtlas{ get; private set; }
|
public static TextureAtlas EnemyAtlas{ get; private set; }
|
||||||
public static TextureAtlas RoomAtlas{ get; private set; }
|
public static TextureAtlas RoomAtlas{ get; private set; }
|
||||||
public static SpriteFont PixelMonoFont{ get; private set; }
|
public static SpriteFont PixelMonoFont{ get; private set; }
|
||||||
|
|
||||||
public static int GlobalPixelMultiplier{ get; private set; }
|
|
||||||
|
|
||||||
// private Dictionary<(int, int), UIElement> doorElements = new();
|
// private Dictionary<(int, int), UIElement> doorElements = new();
|
||||||
private static Dictionary<int, UIElement> enemyElements = new();
|
private static Dictionary<int, UIElement> enemyElements = new();
|
||||||
private static TimerUIElement timerElement;
|
private static TimerUIElement timerElement;
|
||||||
private static UIElement cameraView;
|
private static UIElement cameraView;
|
||||||
private static Dictionary<int, UIElement> lightIndicators = new();
|
private static Dictionary<int, UIElement> lightIndicators = new();
|
||||||
|
|
||||||
private static InputListenerHook monitorSwitchHook;
|
|
||||||
|
|
||||||
private static bool fullBright = false; // Debug
|
private static bool fullBright = false; // Debug
|
||||||
|
|
||||||
public static void LoadAssets() {
|
public static void LoadAssets() {
|
||||||
testAtlas = TextureAtlas.FromFile(Core.content, "images/testBlocks-definition.xml");
|
// testAtlas = TextureAtlas.FromFile(Core.content, "images/testBlocks-definition.xml");
|
||||||
OfficeAtlas = TextureAtlas.FromFile(Core.content, "images/office-definition.xml");
|
OfficeAtlas = TextureAtlas.FromFile(Core.content, "images/office-definition.xml");
|
||||||
MonitorAtlas = TextureAtlas.FromFile(Core.content, "images/monitor-definition.xml");
|
MonitorAtlas = TextureAtlas.FromFile(Core.content, "images/monitor-definition.xml");
|
||||||
EnemyAtlas = TextureAtlas.FromFile(Core.content, "images/enemies-definition.xml");
|
EnemyAtlas = TextureAtlas.FromFile(Core.content, "images/enemies-definition.xml");
|
||||||
|
|
@ -61,21 +60,16 @@ public class UIManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void InitUI() {
|
public static void InitUI() {
|
||||||
GlobalPixelMultiplier = Core.graphicsDevice.Viewport.Height / 360;
|
UIElement.GlobalPixelMultiplier = Core.graphicsDevice.Viewport.Height / 360;
|
||||||
|
|
||||||
Screen.AddScreens([officeScreen, monitorScreen, overlayScreen, winScreen, loseScreen, menuScreen, loadingScreen]);
|
Screen.AddScreens([officeScreen, monitorScreen, overlayScreen, winScreen, loseScreen, menuScreen, loadingScreen]);
|
||||||
// Screen.SetScreen(ScreenTypes.OFFICE);
|
|
||||||
// Screen.SetOverlayScreen(ScreenTypes.OVERLAY);
|
|
||||||
|
|
||||||
|
// office
|
||||||
officeScreen.AddElement("office_left", new UIElement([OfficeAtlas["left-open"], OfficeAtlas["left-closed"]], Point.Zero));
|
officeScreen.AddElement("office_left", new UIElement([OfficeAtlas["left-open"], OfficeAtlas["left-closed"]], Point.Zero));
|
||||||
officeScreen.AddElement("office_centre", new UIElement([OfficeAtlas["centre-open"], OfficeAtlas["centre-closed"]], new Point(200, 0)));
|
officeScreen.AddElement("office_centre", new UIElement([OfficeAtlas["centre-open"], OfficeAtlas["centre-closed"]], new Point(200, 0)));
|
||||||
officeScreen.AddElement("office_right", new UIElement([OfficeAtlas["right-open"], OfficeAtlas["right-closed"]], new Point(440, 0)));
|
officeScreen.AddElement("office_right", new UIElement([OfficeAtlas["right-open"], OfficeAtlas["right-closed"]], new Point(440, 0)));
|
||||||
|
|
||||||
// officeScreen.AddElement("test",
|
// monitor
|
||||||
// new UIElement(testAtlas[0], Point.Zero)
|
|
||||||
// {Pressable = true, OnMousePress = () => Console.WriteLine("Pressed!")}
|
|
||||||
// );
|
|
||||||
|
|
||||||
monitorScreen.AddElement("screen", new UIElement(MonitorAtlas["screen"], Point.Zero));
|
monitorScreen.AddElement("screen", new UIElement(MonitorAtlas["screen"], Point.Zero));
|
||||||
monitorScreen.AddElement("view-frame", new UIElement(MonitorAtlas["view-frame"], new Point(62, 55)));
|
monitorScreen.AddElement("view-frame", new UIElement(MonitorAtlas["view-frame"], new Point(62, 55)));
|
||||||
monitorScreen.AddElement("map-frame", new UIElement(MonitorAtlas["map-frame"], new Point(334, 135)));
|
monitorScreen.AddElement("map-frame", new UIElement(MonitorAtlas["map-frame"], new Point(334, 135)));
|
||||||
|
|
@ -95,19 +89,18 @@ public class UIManager {
|
||||||
monitorScreen.AddElement("p2-office-door-centre", new UIElement([MonitorAtlas["door-office-p2-centre-open"], MonitorAtlas["door-office-p2-centre-closed"]], new Point(400, 144)));
|
monitorScreen.AddElement("p2-office-door-centre", new UIElement([MonitorAtlas["door-office-p2-centre-open"], MonitorAtlas["door-office-p2-centre-closed"]], new Point(400, 144)));
|
||||||
monitorScreen.AddElement("p2-office-door-left", new UIElement([MonitorAtlas["door-office-p2-left-open"], MonitorAtlas["door-office-p2-left-closed"]], new Point(400, 144)));
|
monitorScreen.AddElement("p2-office-door-left", new UIElement([MonitorAtlas["door-office-p2-left-open"], MonitorAtlas["door-office-p2-left-closed"]], new Point(400, 144)));
|
||||||
|
|
||||||
|
// timer and power
|
||||||
// main menu
|
|
||||||
timerElement = new(new(0, 0), PixelMonoFont);
|
timerElement = new(new(0, 0), PixelMonoFont);
|
||||||
overlayScreen.AddElement("timer", timerElement);
|
overlayScreen.AddElement("timer", timerElement);
|
||||||
officeScreen.AddElement("power-p1-office", new PowerIndicator(new(timerElement.Bounds.Item1.X, timerElement.Bounds.Item2.Y + 5), PixelMonoFont, Client.Player, "POWER: "));
|
officeScreen.AddElement("power-p1-office", new PowerIndicator(new(timerElement.Bounds.Item1.X, timerElement.Bounds.Item2.Y + 5), PixelMonoFont, Client.Player, "POWER: "));
|
||||||
|
|
||||||
|
|
||||||
TextUIElement powerLabel = (TextUIElement)
|
TextUIElement powerLabel = (TextUIElement)
|
||||||
monitorScreen.AddElement("power-label", new TextUIElement(new(510, 150), PixelMonoFont){Text = "POWER:"});
|
monitorScreen.AddElement("power-label", new TextUIElement(new(510, 150), PixelMonoFont){Text = "POWER:"});
|
||||||
TextUIElement powerP1 = (TextUIElement)
|
TextUIElement powerP1 = (TextUIElement)
|
||||||
monitorScreen.AddElement("power-p2", new PowerIndicator(new(powerLabel.Bounds.Item1.X + 10, powerLabel.Bounds.Item2.Y + 10), PixelMonoFont, Client.Opponent, ""){Color = new Color(220, 10, 10, 255)});
|
monitorScreen.AddElement("power-p2", new PowerIndicator(new(powerLabel.Bounds.Item1.X + 10, powerLabel.Bounds.Item2.Y + 10), PixelMonoFont, Client.Opponent, ""){Color = new Color(220, 10, 10, 255)});
|
||||||
monitorScreen.AddElement("power-p1", new PowerIndicator( new (powerP1.Bounds.Item1.X, powerP1.Bounds.Item2.Y + 5), PixelMonoFont, Client.Player, ""){Color = new Color(15, 190, 247, 255)});
|
monitorScreen.AddElement("power-p1", new PowerIndicator( new (powerP1.Bounds.Item1.X, powerP1.Bounds.Item2.Y + 5), PixelMonoFont, Client.Player, ""){Color = new Color(15, 190, 247, 255)});
|
||||||
|
|
||||||
|
// loading
|
||||||
ReturnToMenuElement returnToMenuElement = new ReturnToMenuElement(new(320, 290), PixelMonoFont);
|
ReturnToMenuElement returnToMenuElement = new ReturnToMenuElement(new(320, 290), PixelMonoFont);
|
||||||
winScreen.AddElement("win-text", new TextUIElement(new(320, 180), PixelMonoFont, TextUIElement.Alignment.CENTER){Text = "YOU WIN", Color = Color.Green});
|
winScreen.AddElement("win-text", new TextUIElement(new(320, 180), PixelMonoFont, TextUIElement.Alignment.CENTER){Text = "YOU WIN", Color = Color.Green});
|
||||||
loseScreen.AddElement("lose-text", new TextUIElement(new(320, 180), PixelMonoFont, TextUIElement.Alignment.CENTER){Text = "YOU LOSE", Color = Color.Red});
|
loseScreen.AddElement("lose-text", new TextUIElement(new(320, 180), PixelMonoFont, TextUIElement.Alignment.CENTER){Text = "YOU LOSE", Color = Color.Red});
|
||||||
|
|
@ -115,6 +108,7 @@ public class UIManager {
|
||||||
loseScreen.AddElement("press-space", returnToMenuElement);
|
loseScreen.AddElement("press-space", returnToMenuElement);
|
||||||
loadingScreen.AddElement("press-space", returnToMenuElement);
|
loadingScreen.AddElement("press-space", returnToMenuElement);
|
||||||
|
|
||||||
|
// main menu
|
||||||
MenuInputField usernameField = (MenuInputField)menuScreen.AddElement("username-field", new MenuInputField(PixelMonoFont, new(20, 20), "USERNAME: "));
|
MenuInputField usernameField = (MenuInputField)menuScreen.AddElement("username-field", new MenuInputField(PixelMonoFont, new(20, 20), "USERNAME: "));
|
||||||
MenuInputField field = (MenuInputField)menuScreen.AddElement("server-ip-field", new MenuInputField(PixelMonoFont, new(usernameField.Bounds.Item1.X, usernameField.Bounds.Item2.Y + 20), "SERVER IP: ", "127.0.0.1"));
|
MenuInputField field = (MenuInputField)menuScreen.AddElement("server-ip-field", new MenuInputField(PixelMonoFont, new(usernameField.Bounds.Item1.X, usernameField.Bounds.Item2.Y + 20), "SERVER IP: ", "127.0.0.1"));
|
||||||
UIElement connectButton = menuScreen.AddElement("server-ip-submit", new TextUIElement(new Point(field.Bounds.Item1.X, field.Bounds.Item2.Y), PixelMonoFont)
|
UIElement connectButton = menuScreen.AddElement("server-ip-submit", new TextUIElement(new Point(field.Bounds.Item1.X, field.Bounds.Item2.Y), PixelMonoFont)
|
||||||
|
|
@ -123,7 +117,7 @@ public class UIManager {
|
||||||
Pressable = true,
|
Pressable = true,
|
||||||
OnMousePress = () => {
|
OnMousePress = () => {
|
||||||
|
|
||||||
Client.Player.username = usernameField.Text;
|
Client.Player.Username = usernameField.Text;
|
||||||
Client.Connect(field.Text, 9012);
|
Client.Connect(field.Text, 9012);
|
||||||
Screen.SetScreen(ScreenTypes.LOADING);
|
Screen.SetScreen(ScreenTypes.LOADING);
|
||||||
}
|
}
|
||||||
|
|
@ -132,7 +126,7 @@ public class UIManager {
|
||||||
new TextUIElement(new(connectButton.Bounds.Item1.X, connectButton.Bounds.Item2.Y + 30), PixelMonoFont) {Text = "HOST", Pressable = true,
|
new TextUIElement(new(connectButton.Bounds.Item1.X, connectButton.Bounds.Item2.Y + 30), PixelMonoFont) {Text = "HOST", Pressable = true,
|
||||||
OnMousePress = () => {
|
OnMousePress = () => {
|
||||||
Client.StartServer();
|
Client.StartServer();
|
||||||
Client.Player.username = usernameField.Text;
|
Client.Player.Username = usernameField.Text;
|
||||||
Client.Connect("127.0.0.1", 9012);
|
Client.Connect("127.0.0.1", 9012);
|
||||||
Screen.SetScreen(ScreenTypes.LOADING);
|
Screen.SetScreen(ScreenTypes.LOADING);
|
||||||
|
|
||||||
|
|
@ -146,17 +140,14 @@ public class UIManager {
|
||||||
ResetUI();
|
ResetUI();
|
||||||
Screen.SetScreen(ScreenTypes.MENU);
|
Screen.SetScreen(ScreenTypes.MENU);
|
||||||
CommandManager.AllowGameControls(false);
|
CommandManager.AllowGameControls(false);
|
||||||
// if(Client.Player.username != null)
|
|
||||||
// ((MenuInputField)menuScreen["username-field"]).Text = Client.Player.username;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SpawnMapElements(TileConnectorProjection[] doors) {
|
public static void SpawnMapElements(TileConnectorProjection[] doors) {
|
||||||
|
|
||||||
|
|
||||||
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++){
|
||||||
int id = ClientMapManager.CoordsToId(i, 4 - j);
|
int id = ClientMapManager.CoordsToId(i, 4 - j);
|
||||||
if (Client.Player.state.officeTileId == id || Client.Opponent.state.officeTileId == id) continue; // TODO: remove the other check for office
|
if (Client.Player.State.OfficeTileId == id || Client.Opponent.State.OfficeTileId == id) continue;
|
||||||
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(
|
monitorScreen.AddElement(
|
||||||
|
|
@ -168,16 +159,11 @@ public class UIManager {
|
||||||
$"light{id}", new UIElement(MonitorAtlas["map-light-indicator"], point1)
|
$"light{id}", new UIElement(MonitorAtlas["map-light-indicator"], point1)
|
||||||
{Visible = false},
|
{Visible = false},
|
||||||
true));
|
true));
|
||||||
|
|
||||||
//
|
|
||||||
// if (doorPositions.ContainsKey((i, j))){
|
|
||||||
// monitorScreen.AddElement("door"+doorPositions[(i, j)], new UIElement([monitorAtlas[5], monitorAtlas[6]], point1));
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
monitorScreen.AddElement("eye-player", new UIElement(MonitorAtlas["eye-small-player"], monitorScreen["room"+Client.Player.state.camera].Bounds.Item1), true);
|
monitorScreen.AddElement("eye-player", new UIElement(MonitorAtlas["eye-small-player"], monitorScreen["room"+Client.Player.State.Camera].Bounds.Item1), true);
|
||||||
monitorScreen.AddElement("eye-opponent", new UIElement([MonitorAtlas["eye-small-opponent-closed"], MonitorAtlas["eye-small-opponent-open"]], monitorScreen["room"+Client.Opponent.state.camera].Bounds.Item1), true);
|
monitorScreen.AddElement("eye-opponent", new UIElement([MonitorAtlas["eye-small-opponent-closed"], MonitorAtlas["eye-small-opponent-open"]], monitorScreen["room"+Client.Opponent.State.Camera].Bounds.Item1), true);
|
||||||
|
|
||||||
foreach (var door in doors){
|
foreach (var door in doors){
|
||||||
if(door.Type != ConnectorType.DOOR_REMOTE) continue;
|
if(door.Type != ConnectorType.DOOR_REMOTE) continue;
|
||||||
|
|
@ -198,8 +184,8 @@ public class UIManager {
|
||||||
Screen.SetOverlayScreen(ScreenTypes.OVERLAY);
|
Screen.SetOverlayScreen(ScreenTypes.OVERLAY);
|
||||||
|
|
||||||
CommandManager.AllowGameControls(true);
|
CommandManager.AllowGameControls(true);
|
||||||
UpdateCameras([Client.Player.state.camera]); // in case there is an enemy on the default camera
|
UpdateCameras([Client.Player.State.Camera]); // in case there is an enemy on the default camera
|
||||||
cameraView.SetTexture(Client.Player.state.camera);
|
cameraView.SetTexture(Client.Player.State.Camera);
|
||||||
}
|
}
|
||||||
public static void StartTimer() {
|
public static void StartTimer() {
|
||||||
timerElement.Start();
|
timerElement.Start();
|
||||||
|
|
@ -236,17 +222,17 @@ public class UIManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ChangeDoorStateOpponent(Direction dir, bool state) { // TODO: overload to avoid excessive casting
|
public static void ChangeDoorStateOpponent(Direction dir, bool state) {
|
||||||
int stateInt = state ? 1 : 0;
|
int stateInt = state ? 1 : 0;
|
||||||
|
|
||||||
switch ((int)dir){
|
switch (dir){
|
||||||
case 0:
|
case Direction.EAST:
|
||||||
monitorScreen["p2-office-door-left"].SetTexture(stateInt);
|
monitorScreen["p2-office-door-left"].SetTexture(stateInt);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case Direction.NORTH:
|
||||||
monitorScreen["p2-office-door-centre"].SetTexture(stateInt);
|
monitorScreen["p2-office-door-centre"].SetTexture(stateInt);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case Direction.WEST:
|
||||||
monitorScreen["p2-office-door-right"].SetTexture(stateInt);
|
monitorScreen["p2-office-door-right"].SetTexture(stateInt);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -258,7 +244,7 @@ public class UIManager {
|
||||||
|
|
||||||
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);
|
||||||
UpdateCameras([Client.Player.state.camera]);
|
UpdateCameras([Client.Player.State.Camera]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ChangeMonitorStateOpponent(bool state) {
|
public static void ChangeMonitorStateOpponent(bool state) {
|
||||||
|
|
@ -274,15 +260,15 @@ public class UIManager {
|
||||||
public static void UpdateCameras(int[] camIds) {
|
public static void UpdateCameras(int[] camIds) {
|
||||||
foreach (var id in camIds){
|
foreach (var id in camIds){
|
||||||
MapTileProjection tile = ClientMapManager.Get(id);
|
MapTileProjection tile = ClientMapManager.Get(id);
|
||||||
if(tile.Owner == null || tile.Id == Client.Player.state.officeTileId || tile.Id == Client.Opponent.state.officeTileId) continue;
|
if(tile.Owner == null || tile.Id == Client.Player.State.OfficeTileId || tile.Id == Client.Opponent.State.OfficeTileId) continue;
|
||||||
lightIndicators[id].Visible = tile.Lit;
|
lightIndicators[id].Visible = tile.Lit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (camIds.Contains(Client.Player.state.camera)){
|
if (camIds.Contains(Client.Player.State.Camera)){
|
||||||
bool lit = ClientMapManager.Get(Client.Player.state.camera).Lit || fullBright;
|
bool lit = ClientMapManager.Get(Client.Player.State.Camera).Lit || fullBright;
|
||||||
cameraView.Visible = lit;
|
cameraView.Visible = lit;
|
||||||
enemyElements.Values.Where(e => e.Visible).ToList().ForEach(e => e.Visible = false);
|
enemyElements.Values.Where(e => e.Visible).ToList().ForEach(e => e.Visible = false);
|
||||||
ClientEnemy[] enemies = ClientEnemyManager.GetByLocation(ClientMapManager.Get(Client.Player.state.camera));
|
ClientEnemy[] enemies = ClientEnemyManager.GetByLocation(ClientMapManager.Get(Client.Player.State.Camera));
|
||||||
foreach (var enemy in enemies){
|
foreach (var enemy in enemies){
|
||||||
enemyElements.TryGetValue(enemy.Id, out var element);
|
enemyElements.TryGetValue(enemy.Id, out var element);
|
||||||
if (element == null) continue;
|
if (element == null) continue;
|
||||||
|
|
@ -291,7 +277,7 @@ public class UIManager {
|
||||||
enemyElement.SetTexture(lit);
|
enemyElement.SetTexture(lit);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!lit && Client.Player.state.monitorUp && enemies.Any(e => e.TypeId == (int)EnemyType.NEKO)){
|
if (!lit && Client.Player.State.MonitorUp && enemies.Any(e => e.Type == EnemyType.NEKO)){
|
||||||
SoundManager.StartNekoPurr();
|
SoundManager.StartNekoPurr();
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
|
@ -302,7 +288,6 @@ public class UIManager {
|
||||||
|
|
||||||
public static void ChangeCameraOpponent(int id) {
|
public static void ChangeCameraOpponent(int id) {
|
||||||
monitorScreen["eye-opponent"].SetPosition(monitorScreen["room"+id].Bounds.Item1);
|
monitorScreen["eye-opponent"].SetPosition(monitorScreen["room"+id].Bounds.Item1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Jumpscare(ClientEnemy enemy) {
|
public static void Jumpscare(ClientEnemy enemy) {
|
||||||
|
|
@ -310,10 +295,6 @@ public class UIManager {
|
||||||
enemy.JumpscareSprite.Play();
|
enemy.JumpscareSprite.Play();
|
||||||
timerElement.Stop();
|
timerElement.Stop();
|
||||||
CommandManager.AllowGameControls(false);
|
CommandManager.AllowGameControls(false);
|
||||||
// UIElement jumpscareElement = enemy.Sprite.Clone();
|
|
||||||
// jumpscareElement.ScaleMultiplier = 2;
|
|
||||||
// jumpscareElement.SetPosition(new Point(0, 0));
|
|
||||||
// officeScreen.AddElement("jumpscare", jumpscareElement);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ShowVictoryScreen() {
|
public static void ShowVictoryScreen() {
|
||||||
|
|
@ -322,7 +303,6 @@ public class UIManager {
|
||||||
CommandManager.AllowGameControls(false);
|
CommandManager.AllowGameControls(false);
|
||||||
SoundManager.StopAmbience();
|
SoundManager.StopAmbience();
|
||||||
SoundManager.StopNekoPurr();
|
SoundManager.StopNekoPurr();
|
||||||
// InputManager.AddListener(Keys.Space, DisplayMainMenu, InputTiming.PRESS, new InputListenerHook(true, true));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ShowDeathScreen() {
|
public static void ShowDeathScreen() {
|
||||||
|
|
@ -331,11 +311,10 @@ public class UIManager {
|
||||||
CommandManager.AllowGameControls(false);
|
CommandManager.AllowGameControls(false);
|
||||||
SoundManager.StopAmbience();
|
SoundManager.StopAmbience();
|
||||||
SoundManager.StopNekoPurr();
|
SoundManager.StopNekoPurr();
|
||||||
// InputManager.AddListener(Keys.Space, DisplayMainMenu, InputTiming.PRESS, new InputListenerHook(true, true));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ResetUI() {
|
public static void ResetUI() {
|
||||||
foreach (Screen screen in Screen.Screens.Values){
|
foreach (Screen screen in Screen.GetAllScreens()){
|
||||||
screen.RemoveTemporary();
|
screen.RemoveTemporary();
|
||||||
}
|
}
|
||||||
lightIndicators.Clear();
|
lightIndicators.Clear();
|
||||||
|
|
@ -343,13 +322,4 @@ public class UIManager {
|
||||||
|
|
||||||
timerElement.Stop();
|
timerElement.Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
// private static Point GetRoomUIPos((int x, int y) pos) {
|
|
||||||
// return new Point(336 + (32 * pos.x), 144 + (32 * pos.y));
|
|
||||||
// }
|
|
||||||
|
|
||||||
public static void SetLoadingScreenMessage(string text) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,30 +1,22 @@
|
||||||
using System;
|
using Microsoft.Xna.Framework;
|
||||||
using System.Collections.Generic;
|
|
||||||
using Microsoft.Xna.Framework;
|
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
using Microsoft.Xna.Framework.Input;
|
using Microsoft.Xna.Framework.Input;
|
||||||
using MonoGameLibrary;
|
using MonoGameLibrary;
|
||||||
using MonoGameLibrary.Graphics;
|
|
||||||
using MonoGameLibrary.Input;
|
using MonoGameLibrary.Input;
|
||||||
using ONDClient.GUI;
|
using ONDClient.GUI;
|
||||||
|
using ONDClient.Net;
|
||||||
|
using ONDClient.Sound;
|
||||||
|
|
||||||
namespace ONDClient;
|
namespace ONDClient;
|
||||||
|
|
||||||
public class GameMain() : Core("OND", 1280, 720, false) {
|
public class GameMain() : Core("OND", 1280, 720, false) {
|
||||||
// private GraphicsDeviceManager _graphics;
|
|
||||||
// private SpriteBatch _spriteBatch;
|
|
||||||
|
|
||||||
|
|
||||||
protected override void Initialize() {
|
protected override void Initialize() {
|
||||||
Exiting += (_, _) => {
|
Exiting += (_, _) => {
|
||||||
Client.Disconnect();
|
Client.Disconnect();
|
||||||
};
|
};
|
||||||
|
|
||||||
// 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));
|
|
||||||
|
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
|
|
||||||
Client.Init();
|
Client.Init();
|
||||||
|
|
@ -35,8 +27,6 @@ public class GameMain() : Core("OND", 1280, 720, false) {
|
||||||
protected override void LoadContent() {
|
protected override void LoadContent() {
|
||||||
UIManager.LoadAssets();
|
UIManager.LoadAssets();
|
||||||
SoundManager.LoadSounds();
|
SoundManager.LoadSounds();
|
||||||
// spriteBatch = new SpriteBatch(GraphicsDevice);
|
|
||||||
// font = Content.Load<SpriteFont>("font");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Update(GameTime gameTime) {
|
protected override void Update(GameTime gameTime) {
|
||||||
|
|
@ -58,8 +48,6 @@ public class GameMain() : Core("OND", 1280, 720, false) {
|
||||||
spriteBatch.Begin(samplerState:SamplerState.PointClamp);
|
spriteBatch.Begin(samplerState:SamplerState.PointClamp);
|
||||||
|
|
||||||
Screen.DrawCurrentAndOverlay(spriteBatch);
|
Screen.DrawCurrentAndOverlay(spriteBatch);
|
||||||
// Screen.CurrentScreen.Draw(spriteBatch);
|
|
||||||
// spriteBatch.DrawString(font, "Elapsed time: " + gameTime.TotalGameTime.Milliseconds, new Vector2(10, 10), Color.White);
|
|
||||||
|
|
||||||
spriteBatch.End();
|
spriteBatch.End();
|
||||||
base.Draw(gameTime);
|
base.Draw(gameTime);
|
||||||
|
|
|
||||||
|
|
@ -1,29 +1,24 @@
|
||||||
|
#nullable enable
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.InteropServices.JavaScript;
|
|
||||||
using GlobalClassLib;
|
using GlobalClassLib;
|
||||||
using ONDClient.GUI;
|
using ONDClient.GUI;
|
||||||
using PacketLib;
|
using ONDClient.Net;
|
||||||
|
|
||||||
namespace ONDClient.Map;
|
namespace ONDClient.Map;
|
||||||
|
|
||||||
public class ClientMapManager {
|
public static class ClientMapManager {
|
||||||
private static MapTileProjection[,] map = new MapTileProjection[5, 5];
|
private static MapTileProjection[,] map = new MapTileProjection[5, 5];
|
||||||
public 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(IdToCoords(tileId));
|
public static MapTileProjection Get(int tileId) => Get(IdToCoords(tileId));
|
||||||
|
|
||||||
private static bool inverted;
|
|
||||||
public static void InitMap(int[] connectors, int[] yourTiles, int[] opponentTiles, int[] litTiles, bool upsideDown ) {
|
public static void InitMap(int[] connectors, int[] yourTiles, int[] opponentTiles, int[] litTiles, bool upsideDown ) {
|
||||||
|
|
||||||
(int id1, int id2, ConnectorType type, ClientPlayer? owner)[] connectorsData = new (int, int , ConnectorType, ClientPlayer?)[connectors.Length / 4];
|
(int id1, int id2, ConnectorType type, ClientPlayer? owner)[] connectorsData = new (int, int , ConnectorType, ClientPlayer?)[connectors.Length / 4];
|
||||||
for (int i = 0; i < connectors.Length / 4; i++){
|
for (int i = 0; i < connectors.Length / 4; i++){
|
||||||
connectorsData[i] = (connectors[i * 4], connectors[i * 4 + 1], (ConnectorType)connectors[i * 4 + 2], connectors[i * 4 + 3] == -1 ? null : Client.GetPlayer(connectors[i * 4 + 3]));
|
connectorsData[i] = (connectors[i * 4], connectors[i * 4 + 1], (ConnectorType)connectors[i * 4 + 2], connectors[i * 4 + 3] == -1 ? null : Client.GetPlayer(connectors[i * 4 + 3]));
|
||||||
}
|
}
|
||||||
// ClientMapManager.InitMap(upsideDown);
|
|
||||||
|
|
||||||
inverted = upsideDown;
|
|
||||||
|
|
||||||
IdToCoords = upsideDown ? _IdToCoordsInverse : _IdToCoords;
|
IdToCoords = upsideDown ? _IdToCoordsInverse : _IdToCoords;
|
||||||
CoordsToId = upsideDown ? _CoordsToIdInverse : _CoordsToId;
|
CoordsToId = upsideDown ? _CoordsToIdInverse : _CoordsToId;
|
||||||
|
|
@ -62,13 +57,11 @@ public class ClientMapManager {
|
||||||
|
|
||||||
public static void InitConnectors(TileConnectorProjection[] connectors) {
|
public static void InitConnectors(TileConnectorProjection[] connectors) {
|
||||||
foreach (var con in connectors){
|
foreach (var con in connectors){
|
||||||
// (int x, int y) coords1 = MapTileProjection.IdToCoords(con.Tiles.tile1.Id);
|
|
||||||
// (int x, int y) coords2 = MapTileProjection.IdToCoords(con.Tiles.tile2.Id);
|
|
||||||
map[con.Tiles.tile1.GridPosition.x, con.Tiles.tile1.GridPosition.y].AddConnector(con);
|
map[con.Tiles.tile1.GridPosition.x, con.Tiles.tile1.GridPosition.y].AddConnector(con);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TileConnectorProjection GetConnector((int, int) id) => Get(id.Item1).GetConnector(id.Item2);
|
public static TileConnectorProjection? GetConnector((int, int) id) => Get(id.Item1).GetConnector(id.Item2);
|
||||||
|
|
||||||
public static TileConnectorProjection[] GetConnectors(int tileId) => Get(IdToCoords(tileId)).GetAllConnectors();
|
public static TileConnectorProjection[] GetConnectors(int tileId) => Get(IdToCoords(tileId)).GetAllConnectors();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,10 @@
|
||||||
|
#nullable enable
|
||||||
using GlobalClassLib;
|
using GlobalClassLib;
|
||||||
|
using ONDClient.Net;
|
||||||
|
|
||||||
namespace ONDClient.Map;
|
namespace ONDClient.Map;
|
||||||
|
|
||||||
public class MapTileProjection : GlobalMapTile<TileConnectorProjection, MapTileProjection> {
|
public class MapTileProjection(int id)
|
||||||
|
: GlobalMapTile<TileConnectorProjection, MapTileProjection>(id, ClientMapManager.IdToCoords(id)) {
|
||||||
public ClientPlayer? Owner { get; set; }
|
public ClientPlayer? Owner { get; set; }
|
||||||
|
|
||||||
public MapTileProjection(int id) : base(id, ClientMapManager.IdToCoords(id)) {
|
|
||||||
Lit = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
|
#nullable enable
|
||||||
using GlobalClassLib;
|
using GlobalClassLib;
|
||||||
|
using ONDClient.Net;
|
||||||
|
|
||||||
namespace ONDClient.Map;
|
namespace ONDClient.Map;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,14 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
|
||||||
using System.Net;
|
|
||||||
using System.Net.Sockets;
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using ONDClient.GUI;
|
|
||||||
using GlobalClassLib;
|
|
||||||
using LiteNetLib;
|
using LiteNetLib;
|
||||||
using LiteNetLib.Utils;
|
using LiteNetLib.Utils;
|
||||||
using ONDClient.Map;
|
using ONDClient.Map;
|
||||||
using PacketLib;
|
using PacketLib;
|
||||||
|
|
||||||
namespace ONDClient;
|
namespace ONDClient.Net;
|
||||||
|
|
||||||
public class Client {
|
public static class Client {
|
||||||
public enum ConnectionState {
|
public enum ConnectionState {
|
||||||
IDLE,
|
IDLE,
|
||||||
CONNECTING,
|
CONNECTING,
|
||||||
|
|
@ -24,20 +19,22 @@ public class Client {
|
||||||
GAME_IN_PROGRESS,
|
GAME_IN_PROGRESS,
|
||||||
ERROR
|
ERROR
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string StatusText{ get; private set; }
|
public static string StatusText{ get; private set; }
|
||||||
|
|
||||||
public static ConnectionState State { get; set; } = ConnectionState.IDLE;
|
public static ConnectionState State { get; set; } = ConnectionState.IDLE;
|
||||||
|
|
||||||
|
public static ClientPlayer Player { get; } = new();
|
||||||
|
public static ClientPlayer Opponent { get; } = new();
|
||||||
|
|
||||||
private static EventBasedNetListener listener = new();
|
private static EventBasedNetListener listener = new();
|
||||||
private static NetManager client;
|
private static NetManager client;
|
||||||
private static NetPeer server;
|
private static NetPeer server;
|
||||||
|
|
||||||
private static NetDataWriter writer;
|
private static NetDataWriter writer;
|
||||||
private static NetPacketProcessor processor;
|
private static NetPacketProcessor processor;
|
||||||
public static ClientPlayer Player { get; } = new();
|
|
||||||
public static ClientPlayer Opponent { get; } = new();
|
|
||||||
|
|
||||||
public static ClientPlayer GetPlayer(int pid) => Player.state.pid == pid ? Player : Opponent;
|
public static ClientPlayer GetPlayer(int pid) => Player.State.Pid == pid ? Player : Opponent;
|
||||||
|
|
||||||
public static void Init() {
|
public static void Init() {
|
||||||
writer = new NetDataWriter();
|
writer = new NetDataWriter();
|
||||||
|
|
@ -48,11 +45,7 @@ public class Client {
|
||||||
processor.SubscribeReusable<JoinAcceptPacket>(OnJoinAccept);
|
processor.SubscribeReusable<JoinAcceptPacket>(OnJoinAccept);
|
||||||
processor.SubscribeReusable<UpdatePlayerPacket>(OnPlayerUpdate);
|
processor.SubscribeReusable<UpdatePlayerPacket>(OnPlayerUpdate);
|
||||||
processor.SubscribeReusable<MapInitPacket>(OnMapInit);
|
processor.SubscribeReusable<MapInitPacket>(OnMapInit);
|
||||||
processor.SubscribeReusable<OpponentInitPacket>(packet => { // TODO: move this to a method
|
processor.SubscribeReusable<OpponentInitPacket>(OnOpponentInit);
|
||||||
Opponent.state = packet.state;
|
|
||||||
Opponent.username = packet.username;
|
|
||||||
State = ConnectionState.GAME_STARTING;
|
|
||||||
});
|
|
||||||
|
|
||||||
client = new NetManager(listener){
|
client = new NetManager(listener){
|
||||||
AutoRecycle = true
|
AutoRecycle = true
|
||||||
|
|
@ -66,7 +59,7 @@ public class Client {
|
||||||
Console.WriteLine("Connected to Server");
|
Console.WriteLine("Connected to Server");
|
||||||
server = peer;
|
server = peer;
|
||||||
State = ConnectionState.CONNECTED;
|
State = ConnectionState.CONNECTED;
|
||||||
SendPacket(new JoinPacket {username = Player.username == "" ? "Anonymous" : Player.username}, DeliveryMethod.ReliableOrdered);
|
SendPacket(new JoinPacket {Username = Player.Username == "" ? "Anonymous" : Player.Username}, DeliveryMethod.ReliableOrdered);
|
||||||
};
|
};
|
||||||
|
|
||||||
listener.PeerDisconnectedEvent += (peer, info) => {
|
listener.PeerDisconnectedEvent += (peer, info) => {
|
||||||
|
|
@ -83,7 +76,7 @@ public class Client {
|
||||||
client.Start();
|
client.Start();
|
||||||
Console.WriteLine($"Connecting to server @ {endPoint}:{port}");
|
Console.WriteLine($"Connecting to server @ {endPoint}:{port}");
|
||||||
|
|
||||||
new Thread(() => client.Connect(endPoint, port, "")).Start(); // TODO: figure out how keys work
|
new Thread(() => client.Connect(endPoint, port, "")).Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SendPacket<T>(T packet, DeliveryMethod deliveryMethod) where T : class, new() {
|
public static void SendPacket<T>(T packet, DeliveryMethod deliveryMethod) where T : class, new() {
|
||||||
|
|
@ -94,7 +87,7 @@ public class Client {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static void SendCommands(PlayerCommand[] pCommands) {
|
public static void SendCommands(PlayerCommand[] pCommands) {
|
||||||
SendPacket(new PlayerCommandPacket{commands = pCommands}, DeliveryMethod.ReliableOrdered);
|
SendPacket(new PlayerCommandPacket{Commands = pCommands}, DeliveryMethod.ReliableOrdered);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void OnNetworkReceive(NetPeer peer, NetPacketReader reader, DeliveryMethod deliveryMethod) {
|
private static void OnNetworkReceive(NetPeer peer, NetPacketReader reader, DeliveryMethod deliveryMethod) {
|
||||||
|
|
@ -102,23 +95,17 @@ public class Client {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void OnJoinAccept(JoinAcceptPacket packet) {
|
private static void OnJoinAccept(JoinAcceptPacket packet) {
|
||||||
Console.WriteLine($"Accepted by server, pid: {packet.state.pid}");
|
Console.WriteLine($"Accepted by server, pid: {packet.State.Pid}");
|
||||||
State = ConnectionState.ACCEPTED;
|
State = ConnectionState.ACCEPTED;
|
||||||
Player.state = packet.state;
|
Player.State = packet.State;
|
||||||
}
|
|
||||||
|
|
||||||
#nullable enable
|
|
||||||
private static void OnMapInit(MapInitPacket packet) {
|
|
||||||
ClientMapManager.InitMap(packet.Connectors, packet.YourTiles, packet.OpponentTiles, packet.LitTiles, packet.UpsideDown);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Update() {
|
public static void Update() {
|
||||||
client.PollEvents();
|
client.PollEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void OnPlayerUpdate(UpdatePlayerPacket packet) { // TODO: move this to a separate class
|
public static void OnPlayerUpdate(UpdatePlayerPacket packet) {
|
||||||
EventProcessor.Evaluate(packet.events);
|
EventProcessor.Evaluate(packet.Events);
|
||||||
//Player.state = Player.state.pid == 0 ? packet.stateP1 : packet.stateP2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Disconnect() {
|
public static void Disconnect() {
|
||||||
|
|
@ -130,7 +117,19 @@ public class Client {
|
||||||
|
|
||||||
public static void StartServer() {
|
public static void StartServer() {
|
||||||
Process.Start("ONDServer");
|
Process.Start("ONDServer");
|
||||||
// new Thread(() => Server.Start(9012)).Start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#nullable enable
|
||||||
|
private static void OnMapInit(MapInitPacket packet) {
|
||||||
|
ClientMapManager.InitMap(packet.Connectors, packet.YourTiles, packet.OpponentTiles, packet.LitTiles, packet.UpsideDown);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void OnOpponentInit(OpponentInitPacket packet) {
|
||||||
|
Opponent.State = packet.State;
|
||||||
|
Opponent.Username = packet.Username;
|
||||||
|
State = ConnectionState.GAME_STARTING;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
8
ONDClient/Net/ClientPlayer.cs
Normal file
8
ONDClient/Net/ClientPlayer.cs
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
using PacketLib;
|
||||||
|
|
||||||
|
namespace ONDClient.Net;
|
||||||
|
|
||||||
|
public class ClientPlayer {
|
||||||
|
public PlayerState State;
|
||||||
|
public string Username;
|
||||||
|
}
|
||||||
|
|
@ -6,12 +6,13 @@ using Microsoft.Xna.Framework.Input;
|
||||||
using MonoGameLibrary.Input;
|
using MonoGameLibrary.Input;
|
||||||
using ONDClient.GUI;
|
using ONDClient.GUI;
|
||||||
using ONDClient.Map;
|
using ONDClient.Map;
|
||||||
|
using ONDClient.Sound;
|
||||||
using PacketLib;
|
using PacketLib;
|
||||||
|
|
||||||
namespace ONDClient;
|
namespace ONDClient.Net;
|
||||||
|
|
||||||
public class CommandManager {
|
public static class CommandManager {
|
||||||
private static (string label, Keys key, Action action)[] keybinds = [
|
private static readonly (string label, Keys key, Action action)[] keybinds = [
|
||||||
("Toggle camera", Keys.Space, SendToggleCamera),
|
("Toggle camera", Keys.Space, SendToggleCamera),
|
||||||
("Toggle left door", Keys.A, ToggleDoorLeft),
|
("Toggle left door", Keys.A, ToggleDoorLeft),
|
||||||
("Toggle centre door", Keys.W, ToggleDoorCentre),
|
("Toggle centre door", Keys.W, ToggleDoorCentre),
|
||||||
|
|
@ -20,20 +21,20 @@ public class CommandManager {
|
||||||
("Toggle light", Keys.F, ToggleLight)
|
("Toggle light", Keys.F, ToggleLight)
|
||||||
];
|
];
|
||||||
|
|
||||||
private static InputListenerHook allControlsHook{ get; } = new(true);
|
private static InputListenerHook AllControlsHook{ get; } = new(true);
|
||||||
|
|
||||||
public static void InitInputListeners() {
|
public static void InitInputListeners() {
|
||||||
Array.ForEach(keybinds, tuple => InputManager.AddListener(tuple.label, tuple.key, () => tuple.action(), InputTiming.PRESS, allControlsHook));
|
Array.ForEach(keybinds, tuple => InputManager.AddListener(tuple.label, tuple.key, () => tuple.action(), InputTiming.PRESS, AllControlsHook));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void AllowGameControls(bool state) {
|
public static void AllowGameControls(bool state) {
|
||||||
allControlsHook.Enabled = state;
|
AllControlsHook.Enabled = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void SendToggleCamera() {
|
private static void SendToggleCamera() {
|
||||||
Client.Player.state.monitorUp = !Client.Player.state.monitorUp;
|
Client.Player.State.MonitorUp = !Client.Player.State.MonitorUp;
|
||||||
UIManager.ChangeMonitorState(Client.Player.state.monitorUp);
|
UIManager.ChangeMonitorState(Client.Player.State.MonitorUp);
|
||||||
Client.SendCommands([PlayerCommand.SET_MONITOR(Client.Player.state.monitorUp)]);
|
Client.SendCommands([PlayerCommand.SET_MONITOR(Client.Player.State.MonitorUp)]);
|
||||||
SoundManager.PlayMonitorFlip();
|
SoundManager.PlayMonitorFlip();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -44,7 +45,7 @@ public class CommandManager {
|
||||||
|
|
||||||
private static Dictionary<Direction, TileConnectorProjection> currentDoorBinds = new();
|
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 ToggleLight() => SendToggleLight(Client.Player.State.Camera, !ClientMapManager.Get(Client.Player.State.Camera).Lit);
|
||||||
|
|
||||||
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){
|
||||||
|
|
@ -53,10 +54,10 @@ public class CommandManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (direction == Direction.SOUTH) return;
|
if (direction == Direction.SOUTH) return;
|
||||||
Client.Player.state.doorStates[(int)direction] = !Client.Player.state.doorStates[(int)direction];
|
Client.Player.State.DoorStates[(int)direction] = !Client.Player.State.DoorStates[(int)direction];
|
||||||
UIManager.ChangeDoorState(direction, Client.Player.state.doorStates[(int)direction]);
|
UIManager.ChangeDoorState(direction, Client.Player.State.DoorStates[(int)direction]);
|
||||||
SoundManager.PlayDoor(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])]);
|
Client.SendCommands([PlayerCommand.SET_DOOR_OFFICE(direction, Client.Player.State.DoorStates[(int)direction])]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void SendToggleRemoteDoor(Direction direction) {
|
private static void SendToggleRemoteDoor(Direction direction) {
|
||||||
|
|
@ -67,19 +68,17 @@ public class CommandManager {
|
||||||
Client.SendCommands([PlayerCommand.SET_DOOR_REMOTE(connector.Id, connector.Blocked)]);
|
Client.SendCommands([PlayerCommand.SET_DOOR_REMOTE(connector.Id, connector.Blocked)]);
|
||||||
SoundManager.PlayDoorRemote(connector.Blocked);
|
SoundManager.PlayDoorRemote(connector.Blocked);
|
||||||
UIManager.ChangeRemoteDoorState(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 id) {
|
public static void SendChangeCamera(int id) {
|
||||||
if (id == Client.Player.state.officeTileId || id == Client.Opponent.state.officeTileId) return;
|
if (id == Client.Player.State.OfficeTileId || id == Client.Opponent.State.OfficeTileId) return;
|
||||||
|
|
||||||
Client.Player.state.camera = id;
|
Client.Player.State.Camera = id;
|
||||||
UIManager.ChangeCamera(id);
|
UIManager.ChangeCamera(id);
|
||||||
SoundManager.PlayCameraSwitch();
|
SoundManager.PlayCameraSwitch();
|
||||||
Client.SendCommands([PlayerCommand.SWITCH_CAM(id)]);
|
Client.SendCommands([PlayerCommand.SWITCH_CAM(id)]);
|
||||||
MapTileProjection tile = ClientMapManager.Get(id);
|
MapTileProjection tile = ClientMapManager.Get(id);
|
||||||
// add UIManager switch camera
|
|
||||||
currentDoorBinds.Clear();
|
currentDoorBinds.Clear();
|
||||||
foreach (var c in tile.GetAllConnectors().Where(c => c.Type == ConnectorType.DOOR_REMOTE)){
|
foreach (var c in tile.GetAllConnectors().Where(c => c.Type == ConnectorType.DOOR_REMOTE)){
|
||||||
Direction dir = c.GetDirection(tile);
|
Direction dir = c.GetDirection(tile);
|
||||||
|
|
@ -89,7 +88,7 @@ public class CommandManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void SendToggleLight(int id, bool state) {
|
private static void SendToggleLight(int id, bool state) {
|
||||||
if(!Client.Player.state.monitorUp || ClientMapManager.Get(id).Owner != Client.Player) return;
|
if(!Client.Player.State.MonitorUp || ClientMapManager.Get(id).Owner != Client.Player) return;
|
||||||
ClientMapManager.Get(id).Lit = state;
|
ClientMapManager.Get(id).Lit = state;
|
||||||
UIManager.UpdateCameras([id]);
|
UIManager.UpdateCameras([id]);
|
||||||
SoundManager.PlayLight(state);
|
SoundManager.PlayLight(state);
|
||||||
212
ONDClient/Net/EventProcessor.cs
Normal file
212
ONDClient/Net/EventProcessor.cs
Normal file
|
|
@ -0,0 +1,212 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using GlobalClassLib;
|
||||||
|
using ONDClient.Enemies;
|
||||||
|
using ONDClient.GUI;
|
||||||
|
using ONDClient.Map;
|
||||||
|
using ONDClient.Sound;
|
||||||
|
using PacketLib;
|
||||||
|
|
||||||
|
namespace ONDClient.Net;
|
||||||
|
|
||||||
|
public static class EventProcessor {
|
||||||
|
|
||||||
|
private static readonly Dictionary<int, Action<GameEvent>> eventHandlers = new(){
|
||||||
|
[0] = _ => PlayerJoin(),
|
||||||
|
[1] = _ => PlayerLeave(),
|
||||||
|
[2] = e => SwitchCam(e.Args[0], e.Args[1]),
|
||||||
|
[3] = e => ChangeMonitorState(e.Args[0], e.Args[1] == 1),
|
||||||
|
[4] = e => ChangeDoorStateOffice(e.Args[0], e.Args[1], e.Args[2] == 1),
|
||||||
|
[5] = e => ChangeDoorStateRemote(e.Args[0], (e.Args[1], e.Args[2]), e.Args[3] == 1),
|
||||||
|
[6] = e => SpawnEnemy((EnemyType)e.Args[0], e.Args[1], e.Args[3]),
|
||||||
|
[7] = e => MoveEnemy(e.Args[0], e.Args[1]),
|
||||||
|
[8] = e => EnemyAttack(e.Args[0], e.Args[1]),
|
||||||
|
[9] = e => EnemyReset(e.Args[0], e.Args[1]),
|
||||||
|
[10] = e => SpotSetActive(e.Args[0], e.Args[1] == 1),
|
||||||
|
[11] = e => PlayerWin(e.Args[0]),
|
||||||
|
[12] = _ => StartGame(),
|
||||||
|
[13] = e => PowerTick(e.Args[0], e.Args[1]),
|
||||||
|
[14] = e => PowerOut(e.Args[0]),
|
||||||
|
[15] = e => ChangeLightState(e.Args[0], e.Args[1], e.Args[2] == 1),
|
||||||
|
[16] = _ => NekoAnger(),
|
||||||
|
[17] = _ => VentWalk(),
|
||||||
|
[18] = _ => NextPhase()
|
||||||
|
};
|
||||||
|
|
||||||
|
public static void Evaluate(GameEvent[] events) {
|
||||||
|
foreach (var e in events){
|
||||||
|
eventHandlers[e.Id](e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void PlayerJoin() {
|
||||||
|
Console.WriteLine("E: Player joined");
|
||||||
|
}
|
||||||
|
private static void PlayerLeave() {
|
||||||
|
Console.WriteLine("E: Player left");
|
||||||
|
}
|
||||||
|
private static void SwitchCam(int pid, int camId) {
|
||||||
|
if (Client.Player.State.Pid != pid){
|
||||||
|
UIManager.ChangeCameraOpponent(camId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (Client.Player.State.Camera != camId) Console.WriteLine("!!! DESYNC: CAMERA STATE");
|
||||||
|
Console.WriteLine($"E: player {pid} switched to camera {camId}");
|
||||||
|
}
|
||||||
|
private static void ChangeMonitorState(int pid, bool state) {
|
||||||
|
Console.WriteLine($"E: Player {pid} toggled monitor {(state ? "off" : "on")}");
|
||||||
|
|
||||||
|
if (pid != Client.Player.State.Pid){
|
||||||
|
UIManager.ChangeMonitorStateOpponent(state);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Client.Player.State.MonitorUp != state) Console.WriteLine("!!! DESYNC: MONITOR STATE");
|
||||||
|
}
|
||||||
|
private static void ChangeDoorStateOffice(int pid, int doorId, bool state) {
|
||||||
|
Console.WriteLine($"E: Player {pid} {(state ? "closed" : "opened")} door {doorId}");
|
||||||
|
|
||||||
|
if (pid == Client.Player.State.Pid){
|
||||||
|
if (Client.Player.State.DoorStates[doorId] != state) Console.WriteLine("!!! DESYNC: DOOR STATE");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Client.Opponent.State.DoorStates[doorId] = state;
|
||||||
|
UIManager.ChangeDoorStateOpponent((Direction)doorId, state);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ChangeDoorStateRemote(int pid, (int tile1, int tile2) connectorId, bool state) {
|
||||||
|
Console.WriteLine($"E: Player {pid} {(state ? "closed" : "opened")} door {connectorId.tile1}-{connectorId.tile2}");
|
||||||
|
TileConnectorProjection connector = ClientMapManager.GetConnector(connectorId);
|
||||||
|
if (connector == null){
|
||||||
|
Console.WriteLine($"!!! Connector {connectorId} not found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pid == Client.Player.State.Pid){
|
||||||
|
if (connector.Blocked != state) Console.WriteLine("!!! DESYNC: REMOTE DOOR STATE");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
connector.Blocked = state;
|
||||||
|
UIManager.ChangeRemoteDoorState(connectorId, state);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void SpawnEnemy(EnemyType type, int id, int camId) {
|
||||||
|
Console.WriteLine($"E: Spawned enemy {type} at {camId}");
|
||||||
|
ClientEnemyManager.AddEnemyByTemplate(type, id, ClientMapManager.Get(camId));
|
||||||
|
UIManager.UpdateCameras([camId]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void MoveEnemy(int id, int camId) {
|
||||||
|
Console.WriteLine($"E: Enemy {id} moved to {camId}");
|
||||||
|
int oldPos = ClientEnemyManager.Get(id).Location!.Id;
|
||||||
|
ClientEnemyManager.Move(id, ClientMapManager.Get(camId));
|
||||||
|
UIManager.UpdateCameras([oldPos, camId]);
|
||||||
|
SoundManager.PlayEnemyMove(ClientEnemyManager.Get(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void EnemyAttack(int enemyId, int pid) {
|
||||||
|
Console.WriteLine($"E: Enemy {enemyId} attacked player {pid}");
|
||||||
|
if (pid == Client.Player.State.Pid) {
|
||||||
|
UIManager.Jumpscare(ClientEnemyManager.Get(pid));
|
||||||
|
SoundManager.PlayJumpscare();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void EnemyReset(int id, int camId) {
|
||||||
|
Console.WriteLine($"E: Enemy {id} reset to {camId}");
|
||||||
|
int preResetPos = ClientEnemyManager.Get(id).Location!.Id;
|
||||||
|
ClientEnemyManager.Move(id, ClientMapManager.Get(camId));
|
||||||
|
UIManager.UpdateCameras([preResetPos, camId]);
|
||||||
|
SoundManager.PlayEnemyReset(ClientEnemyManager.Get(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void SpotSetActive(int id, bool state) {
|
||||||
|
ClientEnemy enemy = ClientEnemyManager.Get(id);
|
||||||
|
if (enemy.Type != EnemyType.SPOT) return;
|
||||||
|
Console.WriteLine($"E: Spot:{id} turned {(state ? "on" : " off")}");
|
||||||
|
ClientEnemyManager.Get(id).Sprite.SetTexture(state ? 0 : 1);
|
||||||
|
SoundManager.PlaySpotActivate();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void PlayerWin(int pid) {
|
||||||
|
Console.WriteLine($"E: Player {pid} won");
|
||||||
|
if(Client.Player.State.Pid == pid) UIManager.ShowVictoryScreen();
|
||||||
|
Client.Disconnect();
|
||||||
|
ClientEnemyManager.ClearEnemies();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void StartGame() {
|
||||||
|
Console.WriteLine("E: Game started");
|
||||||
|
UIManager.DisplayGameUI();
|
||||||
|
UIManager.StartTimer();
|
||||||
|
SoundManager.StartAmbience();
|
||||||
|
Client.State = Client.ConnectionState.GAME_IN_PROGRESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void PowerTick(int pid, int value) {
|
||||||
|
// Console.WriteLine($"E: power tick {e.Args[0]}: {e.Args[1]}");
|
||||||
|
if (pid == Client.Player.State.Pid){
|
||||||
|
Client.Player.State.Power = value;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
Client.Opponent.State.Power = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void PowerOut(int pid) {
|
||||||
|
Console.WriteLine($"E: Player {pid} powered out");
|
||||||
|
ClientMapManager.GetAllConnectors().Where(c =>
|
||||||
|
(c.Type == ConnectorType.DOOR_REMOTE || c.Type == ConnectorType.DOOR_OFFICE) &&
|
||||||
|
c.Owner == Client.GetPlayer(pid)).ToList().ForEach(c =>
|
||||||
|
{
|
||||||
|
c.Blocked = false;
|
||||||
|
if(c.Type == ConnectorType.DOOR_REMOTE)
|
||||||
|
UIManager.ChangeRemoteDoorState(c.Id, false);
|
||||||
|
});
|
||||||
|
foreach (var tile in ClientMapManager.GetAllTiles()){
|
||||||
|
tile.Lit = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pid == Client.Player.State.Pid){
|
||||||
|
UIManager.ChangeDoorState(Direction.EAST, false);
|
||||||
|
UIManager.ChangeDoorState(Direction.NORTH, false);
|
||||||
|
UIManager.ChangeDoorState(Direction.WEST, false);
|
||||||
|
CommandManager.AllowGameControls(false);
|
||||||
|
UIManager.ChangeMonitorState(false);
|
||||||
|
SoundManager.PlayPowerOut();
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
UIManager.ChangeDoorStateOpponent(Direction.EAST, false);
|
||||||
|
UIManager.ChangeDoorStateOpponent(Direction.NORTH, false);
|
||||||
|
UIManager.ChangeDoorStateOpponent(Direction.WEST, false);
|
||||||
|
UIManager.ChangeMonitorStateOpponent(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ChangeLightState(int pid, int camId, bool state) {
|
||||||
|
Console.WriteLine($"E: Player {pid} {(state ? "lit": "unlit")} tile {camId}");
|
||||||
|
if (pid == Client.Player.State.Pid){
|
||||||
|
if (ClientMapManager.Get(camId).Lit != state) Console.WriteLine("!!! DESYNC: LIGHT STATE");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ClientMapManager.Get(camId).Lit = state;
|
||||||
|
UIManager.UpdateCameras([camId]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void NekoAnger() {
|
||||||
|
SoundManager.PlayNekoAnger();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void VentWalk() {
|
||||||
|
SoundManager.PlayVentWalk();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void NextPhase() {
|
||||||
|
SoundManager.PlayBell();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2,8 +2,9 @@ using System;
|
||||||
using GlobalClassLib;
|
using GlobalClassLib;
|
||||||
using Microsoft.Xna.Framework.Audio;
|
using Microsoft.Xna.Framework.Audio;
|
||||||
using MonoGameLibrary;
|
using MonoGameLibrary;
|
||||||
|
using ONDClient.Enemies;
|
||||||
|
|
||||||
namespace ONDClient;
|
namespace ONDClient.Sound;
|
||||||
|
|
||||||
public static class SoundManager {
|
public static class SoundManager {
|
||||||
private static SoundEffect ambience;
|
private static SoundEffect ambience;
|
||||||
|
|
@ -128,6 +129,7 @@ public static class SoundManager {
|
||||||
nekoPurrInstance.Stop();
|
nekoPurrInstance.Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// unused
|
||||||
private static SoundEffectInstance GetRandomisedPitchInstance(SoundEffect effect) {
|
private static SoundEffectInstance GetRandomisedPitchInstance(SoundEffect effect) {
|
||||||
SoundEffectInstance instance = effect.CreateInstance();
|
SoundEffectInstance instance = effect.CreateInstance();
|
||||||
instance.Pitch = (float)(random.NextDouble() - 0.5) / 5;
|
instance.Pitch = (float)(random.NextDouble() - 0.5) / 5;
|
||||||
|
|
@ -136,7 +138,7 @@ public static class SoundManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void PlayEnemyMove(ClientEnemy enemy) {
|
public static void PlayEnemyMove(ClientEnemy enemy) {
|
||||||
switch ((EnemyType)enemy.TypeId){
|
switch (enemy.Type){
|
||||||
case EnemyType.NEKO:
|
case EnemyType.NEKO:
|
||||||
PlayNekoMove();
|
PlayNekoMove();
|
||||||
break;
|
break;
|
||||||
|
|
@ -150,7 +152,7 @@ public static class SoundManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void PlayEnemyReset(ClientEnemy enemy) {
|
public static void PlayEnemyReset(ClientEnemy enemy) {
|
||||||
switch ((EnemyType)enemy.TypeId){
|
switch (enemy.Type){
|
||||||
case EnemyType.NEKO:
|
case EnemyType.NEKO:
|
||||||
PlayNekoMove();
|
PlayNekoMove();
|
||||||
break;
|
break;
|
||||||
|
|
@ -1,70 +0,0 @@
|
||||||
using ONDServer.Map;
|
|
||||||
using PacketLib;
|
|
||||||
|
|
||||||
namespace ONDServer;
|
|
||||||
|
|
||||||
public class CommandProcessor {
|
|
||||||
public static void Evaluate(PlayerCommand[] commands, int pid) {
|
|
||||||
ServerPlayer currentPlayer = Server.Players[pid];
|
|
||||||
|
|
||||||
foreach (var playerCommand in commands){
|
|
||||||
switch (playerCommand.ID){
|
|
||||||
case 0:
|
|
||||||
Console.WriteLine($"C: Player {pid} switched to camera {playerCommand.Args[0]}");
|
|
||||||
currentPlayer.state.camera = playerCommand.Args[0];
|
|
||||||
Server.SendUpdateToAll([GameEvent.SWITCH_CAM(pid, playerCommand.Args[0])]);
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
bool monitorState = playerCommand.Args[0] == 1;
|
|
||||||
currentPlayer.state.monitorUp = monitorState;
|
|
||||||
Console.WriteLine($"C: Player {pid} toggled camera {(monitorState ? "on" : "off")}");
|
|
||||||
Server.SendUpdateToAll([GameEvent.TOGGLE_MONITOR(pid, monitorState)]);
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
bool doorState = playerCommand.Args[1] == 1;
|
|
||||||
currentPlayer.state.doorStates[playerCommand.Args[0]] = doorState;
|
|
||||||
TileConnector? officeDoor = MapManager.Get(currentPlayer.state.officeTileId).GetConnector(currentPlayer.state.neighbouringTiles[playerCommand.Args[0]]);
|
|
||||||
officeDoor.Blocked = doorState;
|
|
||||||
|
|
||||||
if (doorState){
|
|
||||||
GameLogic.PowerConsumers[officeDoor] = (GameLogic.OfficeDoorUsage, pid);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
GameLogic.PowerConsumers.Remove(officeDoor);
|
|
||||||
}
|
|
||||||
|
|
||||||
Console.WriteLine($"C: Player {pid} {(doorState ? "closed" : "opened")} door {playerCommand.Args[0]}");
|
|
||||||
Server.SendUpdateToAll([GameEvent.TOGGLE_DOOR_OFFICE(pid,playerCommand.Args[0] ,doorState)]);
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
TileConnector? door = MapManager.Get(playerCommand.Args[0]).GetConnector(playerCommand.Args[1]);
|
|
||||||
if(door == null) return;
|
|
||||||
|
|
||||||
door.Blocked = playerCommand.Args[2] == 1;
|
|
||||||
if (door.Blocked){
|
|
||||||
GameLogic.PowerConsumers[door] = (GameLogic.RemoteDoorUsage, pid);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
GameLogic.PowerConsumers.Remove(door);
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
case 4:
|
|
||||||
bool lit = playerCommand.Args[1] == 1;
|
|
||||||
MapTile lightTile = MapManager.Get(playerCommand.Args[0]);
|
|
||||||
lightTile.Lit = lit;
|
|
||||||
if (lit){
|
|
||||||
GameLogic.PowerConsumers[lightTile] = (GameLogic.LightUsage, pid);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
GameLogic.PowerConsumers.Remove(lightTile);
|
|
||||||
}
|
|
||||||
|
|
||||||
Server.SendUpdateToAll([GameEvent.TOGGLE_LIGHT(pid, playerCommand.Args[0], lit)]);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,22 +1,20 @@
|
||||||
using System.Net.Mime;
|
|
||||||
using GlobalClassLib;
|
using GlobalClassLib;
|
||||||
using ONDServer.Map;
|
using ONDServer.Map;
|
||||||
|
using ONDServer.Net;
|
||||||
using PacketLib;
|
using PacketLib;
|
||||||
|
|
||||||
namespace ONDServer.Enemies;
|
namespace ONDServer.Enemies;
|
||||||
|
|
||||||
public class DashEnemy : Enemy {
|
public class DashEnemy : Enemy {
|
||||||
public DashEnemy(int difficulty) : base(difficulty, 5000) {
|
public DashEnemy(int difficulty) : base(difficulty, 5000) {
|
||||||
movementOpportunity = new(5000);
|
MovementOpportunity = new(5000);
|
||||||
SetDifficulty(difficulty);
|
SetDifficulty(difficulty);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string Name{ get; } = "Dash";
|
public override string Name{ get; } = "Dash";
|
||||||
public override int TypeId{ get; } = (int)EnemyType.DASH;
|
public override EnemyType Type{ get; } = EnemyType.DASH;
|
||||||
public override bool BlocksTile{ get; set; } = false;
|
public override bool BlocksTile{ get; set; } = false;
|
||||||
|
|
||||||
// private MovementOpportunity movementOpportunity;
|
|
||||||
|
|
||||||
private readonly (MapTile tile, Direction p1AttackDir, Direction p2AttackDir)[] positions =[
|
private readonly (MapTile tile, Direction p1AttackDir, Direction p2AttackDir)[] positions =[
|
||||||
(MapManager.Get(7), Direction.EAST, Direction.WEST),
|
(MapManager.Get(7), Direction.EAST, Direction.WEST),
|
||||||
(MapManager.Get(12), Direction.NORTH, Direction.NORTH),
|
(MapManager.Get(12), Direction.NORTH, Direction.NORTH),
|
||||||
|
|
@ -34,11 +32,6 @@ public class DashEnemy : Enemy {
|
||||||
Server.SendUpdateToAll([GameEvent.ENEMY_RESET(Id, Location.Id)]);
|
Server.SendUpdateToAll([GameEvent.ENEMY_RESET(Id, Location.Id)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// public override void SetDifficulty(int difficulty) {
|
|
||||||
// Difficulty = difficulty;
|
|
||||||
// movementOpportunity.MovementChance = (2 * Math.Sign(difficulty) + difficulty) / 12.0;
|
|
||||||
// }
|
|
||||||
|
|
||||||
public override void Spawn(MapTile location) {
|
public override void Spawn(MapTile location) {
|
||||||
currentPosIndex = positions.ToList().FindIndex(p => p.tile == location);
|
currentPosIndex = positions.ToList().FindIndex(p => p.tile == location);
|
||||||
if (currentPosIndex == -1){
|
if (currentPosIndex == -1){
|
||||||
|
|
@ -47,16 +40,16 @@ public class DashEnemy : Enemy {
|
||||||
}
|
}
|
||||||
base.Spawn(location);
|
base.Spawn(location);
|
||||||
|
|
||||||
movementOpportunity.Start();
|
MovementOpportunity.Start();
|
||||||
Server.SendUpdateToAll([GameEvent.ENEMY_SPAWN(TypeId, Id, Difficulty, Location.Id)]);
|
Server.SendUpdateToAll([GameEvent.ENEMY_SPAWN(Type, Id, Difficulty, Location!.Id)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Update() {
|
public override void Update() {
|
||||||
base.Update();
|
base.Update();
|
||||||
|
|
||||||
if (movementOpportunity.CheckAndRoll()){
|
if (MovementOpportunity.CheckAndRoll()){
|
||||||
bool attackP1 = !Server.P1.state.doorStates[(int)positions[currentPosIndex].p1AttackDir];
|
bool attackP1 = !Server.P1.State.DoorStates[(int)positions[currentPosIndex].p1AttackDir];
|
||||||
bool attackP2 = !Server.P2.state.doorStates[(int)positions[currentPosIndex].p2AttackDir];
|
bool attackP2 = !Server.P2.State.DoorStates[(int)positions[currentPosIndex].p2AttackDir];
|
||||||
|
|
||||||
if (attackP1 != attackP2){
|
if (attackP1 != attackP2){
|
||||||
if(attackP1) Attack(Server.P1);
|
if(attackP1) Attack(Server.P1);
|
||||||
|
|
|
||||||
|
|
@ -1,25 +1,25 @@
|
||||||
using GlobalClassLib;
|
using GlobalClassLib;
|
||||||
using ONDServer.Map;
|
using ONDServer.Map;
|
||||||
|
using ONDServer.Net;
|
||||||
using PacketLib;
|
using PacketLib;
|
||||||
|
|
||||||
namespace ONDServer.Enemies;
|
namespace ONDServer.Enemies;
|
||||||
|
|
||||||
public abstract class Enemy : GlobalEnemy<MapTile, TileConnector> {
|
public abstract class Enemy : GlobalEnemy<MapTile, TileConnector> {
|
||||||
public int Difficulty { get; protected set; }
|
public int Difficulty { get; protected set; }
|
||||||
|
|
||||||
protected MovementOpportunity movementOpportunity;
|
|
||||||
|
|
||||||
|
|
||||||
protected Enemy(int difficulty, int movementInterval) {
|
|
||||||
movementOpportunity = new(movementInterval);
|
|
||||||
SetDifficulty(difficulty);
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract bool BlocksTile { get; set; }
|
public abstract bool BlocksTile { get; set; }
|
||||||
public bool Spawned { get; set; }
|
public bool Spawned { get; set; }
|
||||||
|
|
||||||
|
protected OpportunityTimer MovementOpportunity;
|
||||||
|
|
||||||
|
protected Enemy(int difficulty, int movementInterval) {
|
||||||
|
MovementOpportunity = new(movementInterval);
|
||||||
|
SetDifficulty(difficulty);
|
||||||
|
}
|
||||||
|
|
||||||
|
// unused
|
||||||
public virtual void SpawnSilent(MapTile location) {
|
public virtual void SpawnSilent(MapTile location) {
|
||||||
Console.WriteLine($"!!! Silent spawn not implemented for enemy {TypeId} ({Name}), reverting to regular spawn");
|
Console.WriteLine($"!!! Silent spawn not implemented for enemy {Type} ({Name}), reverting to regular spawn");
|
||||||
Spawn(location);
|
Spawn(location);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -31,12 +31,13 @@ public abstract class Enemy : GlobalEnemy<MapTile, TileConnector> {
|
||||||
public abstract void Reset();
|
public abstract void Reset();
|
||||||
|
|
||||||
public virtual void Attack(ServerPlayer player) {
|
public virtual void Attack(ServerPlayer player) {
|
||||||
Server.SendUpdateToAll([GameEvent.ENEMY_ATTACK(Id, player.state.pid)]);
|
Server.SendUpdateToAll([GameEvent.ENEMY_ATTACK(Id, player.State.Pid)]);
|
||||||
GameLogic.DeclareWinner(Server.OtherPlayer(player));
|
GameLogic.DeclareWinner(Server.OtherPlayer(player));
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void SetDifficulty(int difficulty) {
|
public virtual void SetDifficulty(int difficulty) {
|
||||||
|
if (difficulty > 10) return;
|
||||||
Difficulty = difficulty;
|
Difficulty = difficulty;
|
||||||
movementOpportunity.MovementChance = ((5 + Math.Pow(1.5f, Difficulty)) * Math.Sign(Difficulty)) / (5 + Math.Pow(1.5f, 10));
|
MovementOpportunity.MovementChance = ((5 + Math.Pow(1.5f, Difficulty)) * Math.Sign(Difficulty)) / (5 + Math.Pow(1.5f, 10));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2,7 +2,7 @@ using ONDServer.Map;
|
||||||
|
|
||||||
namespace ONDServer.Enemies;
|
namespace ONDServer.Enemies;
|
||||||
|
|
||||||
public class EnemyManager {
|
public static class EnemyManager {
|
||||||
private static Dictionary<int, Enemy> enemies = new();
|
private static Dictionary<int, Enemy> enemies = new();
|
||||||
|
|
||||||
public static void Update() {
|
public static void Update() {
|
||||||
|
|
|
||||||
|
|
@ -2,40 +2,32 @@ using System.Diagnostics;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using GlobalClassLib;
|
using GlobalClassLib;
|
||||||
using ONDServer.Map;
|
using ONDServer.Map;
|
||||||
|
using ONDServer.Net;
|
||||||
using PacketLib;
|
using PacketLib;
|
||||||
|
|
||||||
namespace ONDServer.Enemies;
|
namespace ONDServer.Enemies;
|
||||||
|
|
||||||
public class LurkEnemy : Enemy {
|
public class LurkEnemy : Enemy {
|
||||||
public override string Name{ get; } = "Lurk";
|
public override string Name{ get; } = "Lurk";
|
||||||
public override int TypeId{ get; } = (int)EnemyType.LURK;
|
public override EnemyType Type{ get; } = EnemyType.LURK;
|
||||||
|
|
||||||
public override bool BlocksTile{ get; set; } = true;
|
public override bool BlocksTile{ get; set; } = true;
|
||||||
|
|
||||||
private LurkPathfinder pathfinder;
|
|
||||||
|
|
||||||
// private int movementRollInterval = 5000;
|
|
||||||
// private static readonly double CHANCE_DENOMINATOR = 2 + Math.Pow(1.5f, 10); // d10 Lurk will have a 100% chance to move
|
|
||||||
// private double movementChance => (2 + Math.Pow(1.5f, Difficulty)) / CHANCE_DENOMINATOR; // chance scales exponentially using a constant multiplier
|
|
||||||
|
|
||||||
public ServerPlayer? Target{ get; set; }
|
public ServerPlayer? Target{ get; set; }
|
||||||
|
|
||||||
|
private readonly RoamingPathfinder pathfinder;
|
||||||
|
|
||||||
public LurkEnemy(int difficulty) : base(difficulty, 5000) {
|
public LurkEnemy(int difficulty) : base(difficulty, 5000) {
|
||||||
pathfinder = new LurkPathfinder(this, 1);
|
pathfinder = new RoamingPathfinder(this, 1);
|
||||||
// movementOpportunity = new MovementOpportunity(5000);
|
|
||||||
Target = null;
|
Target = null;
|
||||||
// SetDifficulty(difficulty);
|
|
||||||
}
|
}
|
||||||
public override void Spawn(MapTile location) {
|
public override void Spawn(MapTile location) {
|
||||||
base.Spawn(location);
|
base.Spawn(location);
|
||||||
// stopwatch.Start();
|
MovementOpportunity.Start();
|
||||||
movementOpportunity.Start();
|
pathfinder.TakenPath.Add(Location!);
|
||||||
pathfinder.TakenPath.Add(Location);
|
Server.SendUpdateToAll([GameEvent.ENEMY_SPAWN(Type, Id, Difficulty, Location!.Id)]);
|
||||||
Server.SendUpdateToAll([GameEvent.ENEMY_SPAWN(TypeId, Id, Difficulty, Location.Id)]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Reset() {
|
public override void Reset() {
|
||||||
Target.state.power -= 80;
|
if (Target != null) Target.State.Power -= 80;
|
||||||
|
|
||||||
MapTile[] resetLocations = new[]{MapManager.Get(7), MapManager.Get(12), MapManager.Get(17)}.Where(t => EnemyManager.GetByLocation(t).Length == 0).ToArray();
|
MapTile[] resetLocations = new[]{MapManager.Get(7), MapManager.Get(12), MapManager.Get(17)}.Where(t => EnemyManager.GetByLocation(t).Length == 0).ToArray();
|
||||||
Location = resetLocations[new Random().Next(resetLocations.Length)];
|
Location = resetLocations[new Random().Next(resetLocations.Length)];
|
||||||
|
|
@ -45,26 +37,23 @@ public class LurkEnemy : Enemy {
|
||||||
Server.SendUpdateToAll([GameEvent.ENEMY_RESET(Id, Location.Id)]);
|
Server.SendUpdateToAll([GameEvent.ENEMY_RESET(Id, Location.Id)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// public override void SetDifficulty(int difficulty) {
|
|
||||||
// Difficulty = difficulty;
|
|
||||||
// movementOpportunity.MovementChance = ((5 + Math.Pow(1.5f, Difficulty)) * Math.Sign(Difficulty)) / (5 + Math.Pow(1.5f, 10));
|
|
||||||
// }
|
|
||||||
|
|
||||||
public override void Update() {
|
public override void Update() {
|
||||||
base.Update();
|
base.Update();
|
||||||
|
|
||||||
if (movementOpportunity.CheckAndRoll()){
|
if(Location == null) return;
|
||||||
if (Server.P1.state.power > Server.P2.state.power){
|
|
||||||
|
if (MovementOpportunity.CheckAndRoll()){
|
||||||
|
if (Server.P1.State.Power > Server.P2.State.Power){
|
||||||
Target = Server.P1;
|
Target = Server.P1;
|
||||||
}
|
}
|
||||||
else if (Server.P1.state.power < Server.P2.state.power){
|
else if (Server.P1.State.Power < Server.P2.State.Power){
|
||||||
Target = Server.P2;
|
Target = Server.P2;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Pathfinder.Decision decision = pathfinder.DecideNext(MapManager.Get(Target.state.officeTileId));
|
Pathfinder.Decision decision = pathfinder.DecideNext(MapManager.Get(Target.State.OfficeTileId));
|
||||||
switch (decision.type){
|
switch (decision.type){
|
||||||
case Pathfinder.Decision.MoveType:
|
case Pathfinder.Decision.MoveType:
|
||||||
if (Location.GetConnector(decision.nextTile!)!.Type == ConnectorType.VENT){
|
if (Location.GetConnector(decision.nextTile!)!.Type == ConnectorType.VENT){
|
||||||
|
|
@ -72,7 +61,7 @@ public class LurkEnemy : Enemy {
|
||||||
}
|
}
|
||||||
Location = decision.nextTile!;
|
Location = decision.nextTile!;
|
||||||
Server.SendUpdateToAll([GameEvent.ENEMY_MOVEMENT(Id, Location.Id)]);
|
Server.SendUpdateToAll([GameEvent.ENEMY_MOVEMENT(Id, Location.Id)]);
|
||||||
Console.WriteLine($"Enemy {TypeId} ({Name}) moving to {Location.PositionAsString})");
|
Console.WriteLine($"Enemy {Type} ({Name}) moving to {Location.IdAsString})");
|
||||||
break;
|
break;
|
||||||
case Pathfinder.Decision.AttackType:
|
case Pathfinder.Decision.AttackType:
|
||||||
Attack(decision.attackTarget!);
|
Attack(decision.attackTarget!);
|
||||||
|
|
@ -85,45 +74,4 @@ public class LurkEnemy : Enemy {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class LurkPathfinder : RoamingPathfinder {
|
|
||||||
// private Random random = new();
|
|
||||||
|
|
||||||
public LurkPathfinder(Enemy enemy, int tolerance) : base(enemy, tolerance) {
|
|
||||||
this.tolerance = tolerance;
|
|
||||||
}
|
|
||||||
|
|
||||||
// public override Decision DecideNext(MapTile goal) {
|
|
||||||
// Dictionary<MapTile, int> distances = Crawl(goal);
|
|
||||||
//
|
|
||||||
// List<MapTile> closerTiles = GetNeighbours(Enemy.Location,
|
|
||||||
// c => !c.Blocked || c.Type == ConnectorType.DOOR_OFFICE,
|
|
||||||
// t => distances.ContainsKey(t) && distances[t] <= distances[Enemy.Location] + tolerance);
|
|
||||||
// if (closerTiles.Contains(goal)){
|
|
||||||
// if (Enemy.Location.GetConnector(goal)!.Blocked){
|
|
||||||
// return Decision.Reset();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return Decision.Attack(((LurkEnemy)Enemy).Target);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if (closerTiles.Count != 0 && closerTiles.All(t => takenPath.Contains(t))){
|
|
||||||
// takenPath.Clear();
|
|
||||||
// return DecideNext(goal);
|
|
||||||
// }
|
|
||||||
// closerTiles.RemoveAll(t => takenPath.Contains(t));
|
|
||||||
//
|
|
||||||
// closerTiles.ForEach(t => distances[t] += Enemy.Location.GetConnector(t)!.Value);
|
|
||||||
// double roll = random.NextDouble() * closerTiles.Sum(t => 1.0 / distances[t]);
|
|
||||||
// foreach (var tile in closerTiles){
|
|
||||||
// if (roll <= 1.0 / distances[tile]){
|
|
||||||
// takenPath.Add(tile);
|
|
||||||
// return Decision.Move(tile);
|
|
||||||
// }
|
|
||||||
// roll -= 1.0 / distances[tile];
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return Decision.Wait();
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
using GlobalClassLib;
|
using GlobalClassLib;
|
||||||
using ONDServer.Map;
|
using ONDServer.Map;
|
||||||
|
using ONDServer.Net;
|
||||||
using PacketLib;
|
using PacketLib;
|
||||||
|
|
||||||
namespace ONDServer.Enemies;
|
namespace ONDServer.Enemies;
|
||||||
|
|
@ -7,24 +8,20 @@ namespace ONDServer.Enemies;
|
||||||
public class MareEnemy : Enemy {
|
public class MareEnemy : Enemy {
|
||||||
|
|
||||||
public override string Name{ get; } = "Mare";
|
public override string Name{ get; } = "Mare";
|
||||||
public override int TypeId{ get; } = (int)EnemyType.MARE;
|
public override EnemyType Type{ get; } = EnemyType.MARE;
|
||||||
public override bool BlocksTile{ get; set; } = true;
|
public override bool BlocksTile{ get; set; } = true;
|
||||||
|
|
||||||
private MarePathfinder pathfinder;
|
private readonly RoamingPathfinder pathfinder;
|
||||||
// private MovementOpportunity movementOpportunity;
|
|
||||||
|
|
||||||
public ServerPlayer? Target{ get; set; }
|
public ServerPlayer? Target{ get; set; }
|
||||||
public MareEnemy(int difficulty) : base(difficulty, 6000) {
|
public MareEnemy(int difficulty) : base(difficulty, 6000) {
|
||||||
pathfinder = new MarePathfinder(this, 1);
|
pathfinder = new RoamingPathfinder(this, 1){ AdditionalConnectorFilter = c => c.Type != ConnectorType.VENT };
|
||||||
|
|
||||||
// movementOpportunity = new MovementOpportunity(5000);
|
|
||||||
// SetDifficulty(difficulty);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Reset() {
|
public override void Reset() {
|
||||||
pathfinder.TakenPath.Clear();
|
pathfinder.TakenPath.Clear();
|
||||||
Target = Server.OtherPlayer(Target);
|
Target = Server.OtherPlayer(Target);
|
||||||
Pathfinder.Decision decision = pathfinder.DecideNext(MapManager.Get(Target.state.officeTileId));
|
Pathfinder.Decision decision = pathfinder.DecideNext(MapManager.Get(Target.State.OfficeTileId));
|
||||||
if (decision.type == Pathfinder.Decision.MoveType){
|
if (decision.type == Pathfinder.Decision.MoveType){
|
||||||
Location = decision.nextTile!;
|
Location = decision.nextTile!;
|
||||||
}
|
}
|
||||||
|
|
@ -32,47 +29,39 @@ public class MareEnemy : Enemy {
|
||||||
Server.SendUpdateToAll([GameEvent.ENEMY_RESET(Id, Location.Id)]);
|
Server.SendUpdateToAll([GameEvent.ENEMY_RESET(Id, Location.Id)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// public override void SetDifficulty(int difficulty) {
|
|
||||||
// Difficulty = difficulty;
|
|
||||||
// movementOpportunity.MovementChance =
|
|
||||||
// ((5 + Math.Pow(1.5f, Difficulty)) * Math.Sign(Difficulty)) / (5 + Math.Pow(1.5f, 10));
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
public override void Spawn(MapTile location) {
|
public override void Spawn(MapTile location) {
|
||||||
base.Spawn(location);
|
base.Spawn(location);
|
||||||
// stopwatch.Start()
|
if (Server.P1.State.Power > Server.P2.State.Power){
|
||||||
if (Server.P1.state.power > Server.P2.state.power){
|
|
||||||
Target = Server.P2;
|
Target = Server.P2;
|
||||||
}
|
}
|
||||||
else if(Server.P1.state.power < Server.P2.state.power){
|
else if(Server.P1.State.Power < Server.P2.State.Power){
|
||||||
Target = Server.P1;
|
Target = Server.P1;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
Target = new Random().Next(2) == 0 ? Server.P1 : Server.P2;
|
Target = new Random().Next(2) == 0 ? Server.P1 : Server.P2;
|
||||||
}
|
}
|
||||||
|
|
||||||
movementOpportunity.Start();
|
MovementOpportunity.Start();
|
||||||
pathfinder.TakenPath.Add(Location);
|
pathfinder.TakenPath.Add(Location);
|
||||||
Server.SendUpdateToAll([GameEvent.ENEMY_SPAWN(TypeId, Id, Difficulty, Location.Id)]);
|
Server.SendUpdateToAll([GameEvent.ENEMY_SPAWN(Type, Id, Difficulty, Location.Id)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Update() {
|
public override void Update() {
|
||||||
base.Update();
|
base.Update();
|
||||||
|
|
||||||
if (movementOpportunity.CheckAndRoll()){
|
if (MovementOpportunity.CheckAndRoll()){
|
||||||
if (Location.Owner != null && Location.Lit){
|
if (Location.Owner != null && Location.Lit){
|
||||||
Attack(Location.Owner);
|
Attack(Location.Owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Target == null) return;
|
if (Target == null) return;
|
||||||
|
|
||||||
Pathfinder.Decision decision = pathfinder.DecideNext(MapManager.Get(Target.state.officeTileId));
|
Pathfinder.Decision decision = pathfinder.DecideNext(MapManager.Get(Target.State.OfficeTileId));
|
||||||
switch (decision.type){
|
switch (decision.type){
|
||||||
case Pathfinder.Decision.MoveType:
|
case Pathfinder.Decision.MoveType:
|
||||||
Location = decision.nextTile!;
|
Location = decision.nextTile!;
|
||||||
Server.SendUpdateToAll([GameEvent.ENEMY_MOVEMENT(Id, Location.Id)]);
|
Server.SendUpdateToAll([GameEvent.ENEMY_MOVEMENT(Id, Location.Id)]);
|
||||||
Console.WriteLine($"Enemy {TypeId} ({Name}) moving to {Location.PositionAsString})");
|
Console.WriteLine($"Enemy {Type} ({Name}) moving to {Location.IdAsString})");
|
||||||
break;
|
break;
|
||||||
case Pathfinder.Decision.AttackType:
|
case Pathfinder.Decision.AttackType:
|
||||||
Attack(decision.attackTarget!);
|
Attack(decision.attackTarget!);
|
||||||
|
|
@ -85,48 +74,4 @@ public class MareEnemy : Enemy {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private class MarePathfinder : RoamingPathfinder {
|
|
||||||
// private Random random = new();
|
|
||||||
|
|
||||||
public MarePathfinder(Enemy enemy, int tolerance) : base(enemy, tolerance) {
|
|
||||||
this.tolerance = tolerance;
|
|
||||||
AdditionalConnectorFilter = c => c.Type != ConnectorType.VENT;
|
|
||||||
}
|
|
||||||
|
|
||||||
// public override Decision DecideNext(MapTile goal) {
|
|
||||||
// Dictionary<MapTile, int> distances = Crawl(goal);
|
|
||||||
//
|
|
||||||
// List<MapTile> closerTiles = GetNeighbours(Enemy.Location,
|
|
||||||
// c => !c.Blocked || c.Type == ConnectorType.DOOR_OFFICE,
|
|
||||||
// t => distances.ContainsKey(t) && distances[t] <= distances[Enemy.Location] + tolerance);
|
|
||||||
// if (closerTiles.Contains(goal)){
|
|
||||||
// if (Enemy.Location.GetConnector(goal)!.Blocked){
|
|
||||||
// return Decision.Reset();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return Decision.Attack(((MareEnemy)Enemy).Target);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if (closerTiles.Count != 0 && closerTiles.All(t => takenPath.Contains(t))){
|
|
||||||
// takenPath.Clear();
|
|
||||||
// return DecideNext(goal);
|
|
||||||
// }
|
|
||||||
// closerTiles.RemoveAll(t => takenPath.Contains(t));
|
|
||||||
//
|
|
||||||
// closerTiles.ForEach(t => distances[t] += Enemy.Location.GetConnector(t)!.Value);
|
|
||||||
// double roll = random.NextDouble() * closerTiles.Sum(t => 1.0 / distances[t]);
|
|
||||||
// foreach (var tile in closerTiles){
|
|
||||||
// if (roll <= 1.0 / distances[tile]){
|
|
||||||
// takenPath.Add(tile);
|
|
||||||
// return Decision.Move(tile);
|
|
||||||
// }
|
|
||||||
// roll -= 1.0 / distances[tile];
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return Decision.Wait();
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,35 +1,29 @@
|
||||||
using GlobalClassLib;
|
using GlobalClassLib;
|
||||||
using ONDServer.Map;
|
using ONDServer.Map;
|
||||||
|
using ONDServer.Net;
|
||||||
using PacketLib;
|
using PacketLib;
|
||||||
|
|
||||||
namespace ONDServer.Enemies;
|
namespace ONDServer.Enemies;
|
||||||
|
|
||||||
public class NekoEnemy : Enemy {
|
public class NekoEnemy : Enemy {
|
||||||
// private MovementOpportunity movementOpportunity;
|
|
||||||
private RoamingPathfinder pathfinder;
|
public override string Name{ get; } = "Neko";
|
||||||
|
public override EnemyType Type{ get; } = EnemyType.NEKO;
|
||||||
|
public override bool BlocksTile{ get; set; } = true;
|
||||||
|
public bool Aggressive = false;
|
||||||
|
public ServerPlayer? Target{ get; set; }
|
||||||
|
|
||||||
|
private readonly RoamingPathfinder pathfinder;
|
||||||
|
|
||||||
public NekoEnemy(int difficulty) : base(difficulty, 4000) {
|
public NekoEnemy(int difficulty) : base(difficulty, 4000) {
|
||||||
pathfinder = new RoamingPathfinder(this, 1){AdditionalTileFilter = t => Aggressive || t.Owner == null || !t.Lit};
|
pathfinder = new RoamingPathfinder(this, 1){AdditionalTileFilter = t => Aggressive || t.Owner == null || !t.Lit};
|
||||||
// movementOpportunity = new MovementOpportunity(5000);
|
|
||||||
// SetDifficulty(difficulty);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string Name{ get; } = "Neko";
|
|
||||||
public override int TypeId{ get; } = (int)EnemyType.NEKO;
|
|
||||||
public override bool BlocksTile{ get; set; } = true;
|
|
||||||
|
|
||||||
public bool Aggressive = false;
|
|
||||||
|
|
||||||
public ServerPlayer? Target{ get; set; }
|
|
||||||
|
|
||||||
|
|
||||||
public override void Spawn(MapTile location) {
|
public override void Spawn(MapTile location) {
|
||||||
base.Spawn(location);
|
base.Spawn(location);
|
||||||
// stopwatch.Start();
|
MovementOpportunity.Start();
|
||||||
movementOpportunity.Start();
|
pathfinder.TakenPath.Add(Location!);
|
||||||
pathfinder.TakenPath.Add(Location);
|
Server.SendUpdateToAll([GameEvent.ENEMY_SPAWN(Type, Id, Difficulty, Location!.Id)]);
|
||||||
Server.SendUpdateToAll([GameEvent.ENEMY_SPAWN(TypeId, Id, Difficulty, Location.Id)]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Reset() {
|
public override void Reset() {
|
||||||
|
|
@ -38,29 +32,25 @@ public class NekoEnemy : Enemy {
|
||||||
pathfinder.TakenPath.Clear();
|
pathfinder.TakenPath.Clear();
|
||||||
pathfinder.TakenPath.Add(Location);
|
pathfinder.TakenPath.Add(Location);
|
||||||
Aggressive = false;
|
Aggressive = false;
|
||||||
Target = Server.OtherPlayer(Target);
|
Target = Server.OtherPlayer(Target!);
|
||||||
Server.SendUpdateToAll([GameEvent.ENEMY_RESET(Id, Location.Id)]);
|
Server.SendUpdateToAll([GameEvent.ENEMY_RESET(Id, Location.Id)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// public override void SetDifficulty(int difficulty) {
|
|
||||||
// Difficulty = difficulty;
|
|
||||||
// movementOpportunity.MovementChance =
|
|
||||||
// ((5 + Math.Pow(1.5f, Difficulty)) * Math.Sign(Difficulty)) / (5 + Math.Pow(1.5f, 10));
|
|
||||||
// }
|
|
||||||
|
|
||||||
public override void Update() {
|
public override void Update() {
|
||||||
base.Update();
|
base.Update();
|
||||||
|
|
||||||
|
if(Location == null) return;
|
||||||
|
|
||||||
if (Location.Owner != null && Location.Lit && !Aggressive){
|
if (Location.Owner != null && Location.Lit && !Aggressive){
|
||||||
Aggressive = true;
|
Aggressive = true;
|
||||||
Server.SendUpdateToAll([GameEvent.NEKO_ANGERED(Location.Owner.state.pid, Id)]);
|
Server.SendUpdateToAll([GameEvent.NEKO_ANGERED(Location.Owner.State.Pid, Id)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Target == null){
|
if (Target == null){
|
||||||
if (Server.P1.state.power > Server.P2.state.power){
|
if (Server.P1.State.Power > Server.P2.State.Power){
|
||||||
Target = Server.P2;
|
Target = Server.P2;
|
||||||
}
|
}
|
||||||
else if (Server.P1.state.power < Server.P2.state.power){
|
else if (Server.P1.State.Power < Server.P2.State.Power){
|
||||||
Target = Server.P1;
|
Target = Server.P1;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
|
@ -71,9 +61,9 @@ public class NekoEnemy : Enemy {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool succeed = movementOpportunity.CheckAndRoll();
|
bool succeed = MovementOpportunity.CheckAndRoll();
|
||||||
if (Target != null && (succeed || (Aggressive && GameLogic.NSecondUpdate))){
|
if (Target != null && (succeed || (Aggressive && GameLogic.NSecondUpdate))){
|
||||||
Pathfinder.Decision decision = pathfinder.DecideNext(MapManager.Get(Target.state.officeTileId));
|
Pathfinder.Decision decision = pathfinder.DecideNext(MapManager.Get(Target.State.OfficeTileId));
|
||||||
switch (decision.type){
|
switch (decision.type){
|
||||||
case Pathfinder.Decision.MoveType:
|
case Pathfinder.Decision.MoveType:
|
||||||
if (Location.GetConnector(decision.nextTile!)!.Type == ConnectorType.VENT){
|
if (Location.GetConnector(decision.nextTile!)!.Type == ConnectorType.VENT){
|
||||||
|
|
@ -81,7 +71,7 @@ public class NekoEnemy : Enemy {
|
||||||
}
|
}
|
||||||
Location = decision.nextTile!;
|
Location = decision.nextTile!;
|
||||||
Server.SendUpdateToAll([GameEvent.ENEMY_MOVEMENT(Id, Location.Id)]);
|
Server.SendUpdateToAll([GameEvent.ENEMY_MOVEMENT(Id, Location.Id)]);
|
||||||
Console.WriteLine($"Enemy {TypeId} ({Name}) moving to {Location.PositionAsString})");
|
Console.WriteLine($"Enemy {Type} ({Name}) moving to {Location.IdAsString})");
|
||||||
break;
|
break;
|
||||||
case Pathfinder.Decision.AttackType:
|
case Pathfinder.Decision.AttackType:
|
||||||
Attack(decision.attackTarget!);
|
Attack(decision.attackTarget!);
|
||||||
|
|
@ -95,48 +85,4 @@ public class NekoEnemy : Enemy {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class NekoPathfinder : RoamingPathfinder {
|
|
||||||
// private Random random = new();
|
|
||||||
|
|
||||||
public NekoPathfinder(Enemy enemy, int tolerance) : base(enemy, tolerance) {
|
|
||||||
this.tolerance = tolerance;
|
|
||||||
AdditionalTileFilter = t => ((NekoEnemy)Enemy).Aggressive || t.Owner == null || !t.Lit;
|
|
||||||
}
|
|
||||||
|
|
||||||
// public override Decision DecideNext(MapTile goal) {
|
|
||||||
// Dictionary<MapTile, int> distances = Crawl(goal);
|
|
||||||
//
|
|
||||||
// List<MapTile> closerTiles = GetNeighbours(Enemy.Location,
|
|
||||||
// c => !c.Blocked || c.Type == ConnectorType.DOOR_OFFICE,
|
|
||||||
// t =>
|
|
||||||
// distances.ContainsKey(t) &&
|
|
||||||
// distances[t] <= distances[Enemy.Location] + tolerance);
|
|
||||||
// if (closerTiles.Contains(goal)){
|
|
||||||
// if (Enemy.Location.GetConnector(goal)!.Blocked){
|
|
||||||
// return Decision.Reset();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return Decision.Attack(((NekoEnemy)Enemy).Target);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if (closerTiles.Count != 0 && closerTiles.All(t => takenPath.Contains(t))){
|
|
||||||
// takenPath.Clear();
|
|
||||||
// return DecideNext(goal);
|
|
||||||
// }
|
|
||||||
// closerTiles.RemoveAll(t => takenPath.Contains(t));
|
|
||||||
//
|
|
||||||
// closerTiles.ForEach(t => distances[t] += Enemy.Location.GetConnector(t)!.Value);
|
|
||||||
// double roll = random.NextDouble() * closerTiles.Sum(t => 1.0 / distances[t]);
|
|
||||||
// foreach (var tile in closerTiles){
|
|
||||||
// if (roll <= 1.0 / distances[tile]){
|
|
||||||
// takenPath.Add(tile);
|
|
||||||
// return Decision.Move(tile);
|
|
||||||
// }
|
|
||||||
// roll -= 1.0 / distances[tile];
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return Decision.Wait();
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
@ -2,9 +2,8 @@ using System.Diagnostics;
|
||||||
|
|
||||||
namespace ONDServer.Enemies;
|
namespace ONDServer.Enemies;
|
||||||
|
|
||||||
public class MovementOpportunity {
|
public class OpportunityTimer {
|
||||||
public int Interval{ get; set; }
|
public int Interval{ get; set; }
|
||||||
// public double ChanceDenominator;
|
|
||||||
public double MovementChance{
|
public double MovementChance{
|
||||||
get;
|
get;
|
||||||
set{
|
set{
|
||||||
|
|
@ -20,12 +19,12 @@ public class MovementOpportunity {
|
||||||
|
|
||||||
private Random random = new();
|
private Random random = new();
|
||||||
|
|
||||||
public MovementOpportunity(int intervalMs, double movementChance) {
|
public OpportunityTimer(int intervalMs, double movementChance) {
|
||||||
Interval = intervalMs;
|
Interval = intervalMs;
|
||||||
MovementChance = movementChance;
|
MovementChance = movementChance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MovementOpportunity(int intervalMs) {
|
public OpportunityTimer(int intervalMs) {
|
||||||
Interval = intervalMs;
|
Interval = intervalMs;
|
||||||
MovementChance = 1;
|
MovementChance = 1;
|
||||||
}
|
}
|
||||||
|
|
@ -41,7 +40,6 @@ public class MovementOpportunity {
|
||||||
if (stopwatch.ElapsedMilliseconds - stopwatchOffset >= Interval){
|
if (stopwatch.ElapsedMilliseconds - stopwatchOffset >= Interval){
|
||||||
int overshoot = (int)(stopwatch.ElapsedMilliseconds - stopwatchOffset - Interval);
|
int overshoot = (int)(stopwatch.ElapsedMilliseconds - stopwatchOffset - Interval);
|
||||||
stopwatchOffset = stopwatch.ElapsedMilliseconds - overshoot;
|
stopwatchOffset = stopwatch.ElapsedMilliseconds - overshoot;
|
||||||
// stopwatch.Restart();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using ONDServer.Map;
|
using ONDServer.Map;
|
||||||
|
using ONDServer.Net;
|
||||||
|
|
||||||
namespace ONDServer.Enemies;
|
namespace ONDServer.Enemies;
|
||||||
|
|
||||||
|
|
@ -8,7 +9,6 @@ public abstract class Pathfinder {
|
||||||
Enemy = enemy;
|
Enemy = enemy;
|
||||||
}
|
}
|
||||||
public abstract Decision DecideNext(MapTile goal);
|
public abstract Decision DecideNext(MapTile goal);
|
||||||
// protected abstract Dictionary<MapTile, int> Crawl(MapTile tile); // fill Distances with all reachable tiles
|
|
||||||
|
|
||||||
protected virtual List<MapTile> GetNeighbours(MapTile tile, Predicate<TileConnector> connectorFilter, Predicate<MapTile> tileFilter) {
|
protected virtual List<MapTile> GetNeighbours(MapTile tile, Predicate<TileConnector> connectorFilter, Predicate<MapTile> tileFilter) {
|
||||||
return tile.GetAllConnectors().Where(c => connectorFilter(c)).Select(c => c.OtherTile(tile)).Where(t => tileFilter(t)).ToList();
|
return tile.GetAllConnectors().Where(c => connectorFilter(c)).Select(c => c.OtherTile(tile)).Where(t => tileFilter(t)).ToList();
|
||||||
|
|
|
||||||
|
|
@ -1,25 +1,19 @@
|
||||||
using GlobalClassLib;
|
using GlobalClassLib;
|
||||||
using ONDServer.Map;
|
using ONDServer.Map;
|
||||||
|
using ONDServer.Net;
|
||||||
|
|
||||||
namespace ONDServer.Enemies;
|
namespace ONDServer.Enemies;
|
||||||
|
|
||||||
public class RoamingPathfinder : Pathfinder {
|
public class RoamingPathfinder(Enemy enemy, int tolerance) : Pathfinder(enemy) {
|
||||||
|
|
||||||
public Predicate<MapTile> AdditionalTileFilter{ get; set; } = _ => true;
|
public Predicate<MapTile> AdditionalTileFilter{ get; set; } = _ => true;
|
||||||
public Predicate<TileConnector> AdditionalConnectorFilter{ get; set; } = _ => true;
|
public Predicate<TileConnector> AdditionalConnectorFilter{ get; set; } = _ => true;
|
||||||
|
|
||||||
protected int tolerance;
|
protected int Tolerance = tolerance;
|
||||||
public List<MapTile> TakenPath { get; } = new();
|
public List<MapTile> TakenPath { get; } = new();
|
||||||
|
|
||||||
private Random random = new();
|
private Random random = new();
|
||||||
|
|
||||||
// private Queue<MapTile> tilesToCrawl = new();
|
|
||||||
// private Dictionary<MapTile, int> distances = new();
|
|
||||||
// private Func<TileConnector, MapTile, bool> defaultConnectorFilter;
|
|
||||||
public RoamingPathfinder(Enemy enemy, int tolerance) : base(enemy) {
|
|
||||||
this.tolerance = tolerance;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Dictionary<MapTile, int> Search(MapTile startingTile) {
|
protected Dictionary<MapTile, int> Search(MapTile startingTile) {
|
||||||
Dictionary<MapTile, int> distances = new(){ [startingTile] = 0 };
|
Dictionary<MapTile, int> distances = new(){ [startingTile] = 0 };
|
||||||
Queue<MapTile> tilesToSearch = new();
|
Queue<MapTile> tilesToSearch = new();
|
||||||
|
|
@ -36,7 +30,7 @@ public class RoamingPathfinder : Pathfinder {
|
||||||
t =>
|
t =>
|
||||||
AdditionalTileFilter(t) &&
|
AdditionalTileFilter(t) &&
|
||||||
(!Enemy.BlocksTile || EnemyManager.GetByLocation(t).All(e => !e.BlocksTile || e == Enemy)) &&
|
(!Enemy.BlocksTile || EnemyManager.GetByLocation(t).All(e => !e.BlocksTile || e == Enemy)) &&
|
||||||
Server.Players.All(p => p.Value.state.officeTileId != t.Id));
|
Server.Players.All(p => p.Value.State.OfficeTileId != t.Id));
|
||||||
|
|
||||||
neighbours.ForEach(t => {
|
neighbours.ForEach(t => {
|
||||||
distances[t] = distances[currentTile] + currentTile.GetConnector(t)!.Value;
|
distances[t] = distances[currentTile] + currentTile.GetConnector(t)!.Value;
|
||||||
|
|
@ -47,37 +41,20 @@ public class RoamingPathfinder : Pathfinder {
|
||||||
return distances;
|
return distances;
|
||||||
}
|
}
|
||||||
|
|
||||||
// private void CrawlStep(MapTile tile) {
|
|
||||||
// List<MapTile> neighbours = GetNeighbours(tile,
|
|
||||||
// c =>
|
|
||||||
// AdditionalConnectorFilter(c) &&
|
|
||||||
// (!c.Blocked || c.Type == ConnectorType.DOOR_OFFICE) &&
|
|
||||||
// tile != Enemy.Location &&
|
|
||||||
// (!distances.ContainsKey(c.OtherTile(tile)) || distances[c.OtherTile(tile)] > distances[tile] + c.Value),
|
|
||||||
// t =>
|
|
||||||
// AdditionalTileFilter(t) &&
|
|
||||||
// (!Enemy.BlocksTile || EnemyManager.GetByLocation(t).All(e => !e.BlocksTile || e == Enemy)) &&
|
|
||||||
// Server.Players.All(p => p.Value.state.officeTileId != t.Id));
|
|
||||||
//
|
|
||||||
// neighbours.ForEach(t => distances[t] = distances[tile] + tile.GetConnector(t)!.Value);
|
|
||||||
//
|
|
||||||
// if (neighbours.Count != 0){
|
|
||||||
// neighbours.ForEach(t => CrawlStep(t));
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
public override Decision DecideNext(MapTile goal) {
|
public override Decision DecideNext(MapTile goal) {
|
||||||
|
if (Enemy.Location == null) return Decision.Wait();
|
||||||
|
|
||||||
Dictionary<MapTile, int> distances = Search(goal);
|
Dictionary<MapTile, int> distances = Search(goal);
|
||||||
|
|
||||||
List<MapTile> closerTiles = GetNeighbours(Enemy.Location,
|
List<MapTile> closerTiles = GetNeighbours(Enemy.Location,
|
||||||
c => AdditionalConnectorFilter(c) && !c.Blocked || c.Type == ConnectorType.DOOR_OFFICE,
|
c => AdditionalConnectorFilter(c) && !c.Blocked || c.Type == ConnectorType.DOOR_OFFICE,
|
||||||
t => AdditionalTileFilter(t) && distances.ContainsKey(t) && distances[t] + t.GetConnector(Enemy.Location).Value <= distances[Enemy.Location] + tolerance);
|
t => AdditionalTileFilter(t) && distances.ContainsKey(t) && distances[t] + t.GetConnector(Enemy.Location)!.Value <= distances[Enemy.Location] + Tolerance);
|
||||||
if (closerTiles.Contains(goal)){
|
if (closerTiles.Contains(goal)){
|
||||||
if (Enemy.Location.GetConnector(goal)!.Blocked){
|
if (Enemy.Location.GetConnector(goal)!.Blocked){
|
||||||
return Decision.Reset();
|
return Decision.Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
IEnumerable<ServerPlayer> players = Server.Players.Values.Where(p => p.state.officeTileId == goal.Id);
|
IEnumerable<ServerPlayer> players = Server.Players.Values.Where(p => p.State.OfficeTileId == goal.Id);
|
||||||
if (players.Count() == 1){
|
if (players.Count() == 1){
|
||||||
return Decision.Attack(players.First());
|
return Decision.Attack(players.First());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
using GlobalClassLib;
|
using GlobalClassLib;
|
||||||
using ONDServer.Map;
|
using ONDServer.Map;
|
||||||
|
using ONDServer.Net;
|
||||||
using PacketLib;
|
using PacketLib;
|
||||||
|
|
||||||
namespace ONDServer.Enemies;
|
namespace ONDServer.Enemies;
|
||||||
|
|
@ -8,17 +9,14 @@ public class SpotEnemy : Enemy {
|
||||||
public SpotEnemy(int difficulty) : base(difficulty, 6000) {
|
public SpotEnemy(int difficulty) : base(difficulty, 6000) {
|
||||||
path = [MapManager.Get(10), MapManager.Get(11), MapManager.Get(12), MapManager.Get(13), MapManager.Get(14)];
|
path = [MapManager.Get(10), MapManager.Get(11), MapManager.Get(12), MapManager.Get(13), MapManager.Get(14)];
|
||||||
pathId = 2;
|
pathId = 2;
|
||||||
// movementOpportunity = new(6000);
|
|
||||||
// SetDifficulty(difficulty);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string Name{ get; } = "Spot";
|
public override string Name{ get; } = "Spot";
|
||||||
public override int TypeId{ get; } = (int)EnemyType.SPOT;
|
public override EnemyType Type{ get; } = EnemyType.SPOT;
|
||||||
public override bool BlocksTile{ get; set; } = false;
|
public override bool BlocksTile{ get; set; } = false;
|
||||||
|
|
||||||
public bool Active{ get; set; } = false;
|
public bool Active{ get; set; } = false;
|
||||||
|
|
||||||
// private MovementOpportunity movementOpportunity;
|
|
||||||
private MapTile[] path;
|
private MapTile[] path;
|
||||||
private int pathId;
|
private int pathId;
|
||||||
|
|
||||||
|
|
@ -27,42 +25,37 @@ public class SpotEnemy : Enemy {
|
||||||
|
|
||||||
public override void Reset() {
|
public override void Reset() {
|
||||||
if (Location.Owner != null){
|
if (Location.Owner != null){
|
||||||
Location.Owner.state.power -= 200;
|
Location.Owner.State.Power -= 200;
|
||||||
}
|
}
|
||||||
pathId = 2;
|
pathId = 2;
|
||||||
Location = path[pathId];
|
Location = path[pathId];
|
||||||
Server.SendUpdateToAll([GameEvent.ENEMY_RESET(Id, Location.Id)]);
|
Server.SendUpdateToAll([GameEvent.ENEMY_RESET(Id, Location.Id)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// public override void SetDifficulty(int difficulty) {
|
|
||||||
// Difficulty = difficulty;
|
|
||||||
// movementOpportunity.MovementChance = (2 * Math.Sign(difficulty) + difficulty) / 12.0;
|
|
||||||
// }
|
|
||||||
|
|
||||||
public override void Update() {
|
public override void Update() {
|
||||||
if (GameLogic.NSecondUpdate){
|
if (GameLogic.NSecondUpdate){
|
||||||
if(!movementOpportunity.Running)
|
if(!MovementOpportunity.Running)
|
||||||
movementOpportunity.Start();
|
MovementOpportunity.Start();
|
||||||
|
|
||||||
if (Active){
|
if (Active){
|
||||||
if (Server.P1.state.monitorUp && Server.P1.state.camera == Location.Id) p1WatchCounter++;
|
if (Server.P1.State.MonitorUp && Server.P1.State.Camera == Location.Id) p1WatchCounter++;
|
||||||
if (Server.P2.state.monitorUp && Server.P2.state.camera == Location.Id) p2WatchCounter++;
|
if (Server.P2.State.MonitorUp && Server.P2.State.Camera == Location.Id) p2WatchCounter++;
|
||||||
|
|
||||||
Console.WriteLine($"P1: {p1WatchCounter} | P2: {p2WatchCounter}");
|
Console.WriteLine($"P1: {p1WatchCounter} | P2: {p2WatchCounter}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (movementOpportunity.CheckAndRoll()){
|
if (MovementOpportunity.CheckAndRoll()){
|
||||||
if(!Active) {
|
if(!Active) {
|
||||||
Active = true;
|
Active = true;
|
||||||
movementOpportunity.Interval = 10_000;
|
MovementOpportunity.Interval = 10_000;
|
||||||
movementOpportunity.GuaranteeSuccess(true);
|
MovementOpportunity.GuaranteeSuccess(true);
|
||||||
Server.SendUpdateToAll([GameEvent.SPOT_SET_ACTIVE(Id, true)]);
|
Server.SendUpdateToAll([GameEvent.SPOT_SET_ACTIVE(Id, true)]);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
movementOpportunity.Interval = 6000;
|
MovementOpportunity.Interval = 6000;
|
||||||
movementOpportunity.GuaranteeSuccess(false);
|
MovementOpportunity.GuaranteeSuccess(false);
|
||||||
movementOpportunity.Stop();
|
MovementOpportunity.Stop();
|
||||||
|
|
||||||
if (p1WatchCounter > p2WatchCounter){
|
if (p1WatchCounter > p2WatchCounter){
|
||||||
pathId++;
|
pathId++;
|
||||||
|
|
@ -94,7 +87,7 @@ public class SpotEnemy : Enemy {
|
||||||
|
|
||||||
public override void Spawn(MapTile location) {
|
public override void Spawn(MapTile location) {
|
||||||
base.Spawn(location);
|
base.Spawn(location);
|
||||||
Server.SendUpdateToAll([GameEvent.ENEMY_SPAWN(TypeId, Id, Difficulty, Location.Id)]);
|
Server.SendUpdateToAll([GameEvent.ENEMY_SPAWN(Type, Id, Difficulty, Location.Id)]);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2,16 +2,17 @@ using System.Diagnostics;
|
||||||
using GlobalClassLib;
|
using GlobalClassLib;
|
||||||
using ONDServer.Enemies;
|
using ONDServer.Enemies;
|
||||||
using ONDServer.Map;
|
using ONDServer.Map;
|
||||||
|
using ONDServer.Net;
|
||||||
using PacketLib;
|
using PacketLib;
|
||||||
|
|
||||||
namespace ONDServer;
|
namespace ONDServer;
|
||||||
|
|
||||||
public class GameLogic {
|
public static class GameLogic {
|
||||||
|
|
||||||
public const int START_CAMERA = 12;
|
public const int START_CAMERA = 12;
|
||||||
|
|
||||||
private static MovementOpportunity secondCycleTimer = new(1000);
|
private static readonly OpportunityTimer secondCycleTimer = new(1000);
|
||||||
private static MovementOpportunity gamePhaseTimer = new(60_000);
|
private static readonly OpportunityTimer gamePhaseTimer = new(60_000);
|
||||||
public static bool NSecondUpdate{ get; private set; } = false;
|
public static bool NSecondUpdate{ get; private set; } = false;
|
||||||
|
|
||||||
public static MapTile P1Office;
|
public static MapTile P1Office;
|
||||||
|
|
@ -25,17 +26,12 @@ public class GameLogic {
|
||||||
|
|
||||||
private static List<List<Enemy>> spawnOrder;
|
private static List<List<Enemy>> spawnOrder;
|
||||||
|
|
||||||
private static int[] defaultSpawnPoints = [2, 22];
|
private static readonly int[] defaultSpawnPoints = [2, 22];
|
||||||
|
|
||||||
private static Random random = new();
|
private static readonly Random random = new();
|
||||||
|
|
||||||
private static bool unlimitedPower = false; // Debug
|
private const bool UNLIMITED_POWER = false; // Debug
|
||||||
private static bool noPhases = true; // Debug
|
private const bool NO_PHASES = false; // Debug
|
||||||
|
|
||||||
// public const int POWER_MAX = 1000;
|
|
||||||
// public static int P1Power{ get; set; } = Power.MAX_POWER_VALUE;
|
|
||||||
// public static int P2Power{ get; set; } = Power.MAX_POWER_VALUE;
|
|
||||||
// public static int[] PowerValues =>[P1Power, P2Power];
|
|
||||||
|
|
||||||
public static Dictionary<object, (int usage, int pid)> PowerConsumers{ get; set; } = new();
|
public static Dictionary<object, (int usage, int pid)> PowerConsumers{ get; set; } = new();
|
||||||
|
|
||||||
|
|
@ -44,10 +40,6 @@ public class GameLogic {
|
||||||
MapManager.InitMap();
|
MapManager.InitMap();
|
||||||
P1Office = MapManager.Get(10);
|
P1Office = MapManager.Get(10);
|
||||||
P2Office = MapManager.Get(14);
|
P2Office = MapManager.Get(14);
|
||||||
//
|
|
||||||
// foreach (var player in Server.Players.Values){
|
|
||||||
// player.state.power = Power.MAX_POWER_VALUE;
|
|
||||||
// }
|
|
||||||
|
|
||||||
//Send map to client
|
//Send map to client
|
||||||
TileConnector[] connectors = MapManager.GetAllConnectors();
|
TileConnector[] connectors = MapManager.GetAllConnectors();
|
||||||
|
|
@ -56,7 +48,7 @@ public class GameLogic {
|
||||||
connectorsConverted[i * 4] = connectors[i].Tiles.tile1.Id;
|
connectorsConverted[i * 4] = connectors[i].Tiles.tile1.Id;
|
||||||
connectorsConverted[i * 4 + 1] = connectors[i].Tiles.tile2.Id;
|
connectorsConverted[i * 4 + 1] = connectors[i].Tiles.tile2.Id;
|
||||||
connectorsConverted[i * 4 + 2] = (int)connectors[i].Type;
|
connectorsConverted[i * 4 + 2] = (int)connectors[i].Type;
|
||||||
connectorsConverted[i * 4 + 3] = connectors[i].Owner == null ? -1 : connectors[i].Owner.state.pid;
|
connectorsConverted[i * 4 + 3] = connectors[i].Owner == null ? -1 : connectors[i].Owner!.State.Pid;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<int> p1Tiles = new();
|
List<int> p1Tiles = new();
|
||||||
|
|
@ -68,25 +60,26 @@ public class GameLogic {
|
||||||
else if(tile.Owner == Server.P2) p2Tiles.Add(tile.Id);
|
else if(tile.Owner == Server.P2) p2Tiles.Add(tile.Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
Server.SendPacket(new MapInitPacket{Connectors = connectorsConverted, UpsideDown = false, YourTiles = p1Tiles.ToArray(), OpponentTiles = p2Tiles.ToArray(), LitTiles = neutralTiles.ToArray()}, Server.P1.peer);
|
Server.SendPacket(new MapInitPacket{Connectors = connectorsConverted, UpsideDown = false, YourTiles = p1Tiles.ToArray(), OpponentTiles = p2Tiles.ToArray(), LitTiles = neutralTiles.ToArray()}, Server.P1.Peer);
|
||||||
Server.SendPacket(new MapInitPacket{Connectors = connectorsConverted, UpsideDown = true, YourTiles = p2Tiles.ToArray(), OpponentTiles = p1Tiles.ToArray(), LitTiles = neutralTiles.ToArray()}, Server.P2.peer);
|
Server.SendPacket(new MapInitPacket{Connectors = connectorsConverted, UpsideDown = true, YourTiles = p2Tiles.ToArray(), OpponentTiles = p1Tiles.ToArray(), LitTiles = neutralTiles.ToArray()}, Server.P2.Peer);
|
||||||
|
|
||||||
spawnOrder = [[new SpotEnemy(3), new MareEnemy(3)], [new DashEnemy(6)], [new LurkEnemy(3), new NekoEnemy(3)]];
|
spawnOrder = [[new SpotEnemy(3), new MareEnemy(3)], [new DashEnemy(6)], [new LurkEnemy(3), new NekoEnemy(3)]];
|
||||||
// Enemy test = new SpotEnemy(3);
|
spawnOrder.ForEach(l => l.ForEach(e => EnemyManager.AddEnemy(e)));
|
||||||
|
|
||||||
Thread.Sleep(3000);
|
Thread.Sleep(3000);
|
||||||
secondCycleTimer.Start();
|
secondCycleTimer.Start();
|
||||||
gamePhaseTimer.Start();
|
gamePhaseTimer.Start();
|
||||||
Server.SendUpdateToAll([GameEvent.GAME_START()]);
|
Server.SendUpdateToAll([GameEvent.GAME_START()]);
|
||||||
|
|
||||||
|
// debug
|
||||||
// EnemyManager.AddEnemy(new SpotEnemy(10)).Spawn(MapManager.Get(12));
|
// EnemyManager.AddEnemy(new SpotEnemy(10)).Spawn(MapManager.Get(12));
|
||||||
// EnemyManager.AddEnemy(new LurkEnemy(10)).Spawn(MapManager.Get(12));
|
// EnemyManager.AddEnemy(new LurkEnemy(10)).Spawn(MapManager.Get(12));
|
||||||
EnemyManager.AddEnemy(new NekoEnemy(7)).Spawn(MapManager.Get(2));
|
// EnemyManager.AddEnemy(new NekoEnemy(7)).Spawn(MapManager.Get(2));
|
||||||
// EnemyManager.AddEnemy(new DashEnemy(10)).Spawn(MapManager.Get(12));
|
// EnemyManager.AddEnemy(new DashEnemy(10)).Spawn(MapManager.Get(12));
|
||||||
// EnemyManager.AddEnemy(new MareEnemy(10)).Spawn(MapManager.Get(22));
|
// EnemyManager.AddEnemy(new MareEnemy(10)).Spawn(MapManager.Get(22));
|
||||||
|
|
||||||
// EnemyManager.AddEnemy(new LurkEnemy(4)).Spawn(MapManager.Get(2));
|
EnemyManager.AddEnemy(new LurkEnemy(4)).Spawn(MapManager.Get(2));
|
||||||
// EnemyManager.AddEnemy(new NekoEnemy(4)).Spawn(MapManager.Get(22));
|
EnemyManager.AddEnemy(new NekoEnemy(4)).Spawn(MapManager.Get(22));
|
||||||
|
|
||||||
}
|
}
|
||||||
public static void Update() {
|
public static void Update() {
|
||||||
|
|
@ -94,24 +87,23 @@ public class GameLogic {
|
||||||
|
|
||||||
if (NSecondUpdate){
|
if (NSecondUpdate){
|
||||||
(int p1, int p2) powerUsage = CalculatePowerUsage();
|
(int p1, int p2) powerUsage = CalculatePowerUsage();
|
||||||
Server.P1.state.power -= powerUsage.p1;
|
Server.P1.State.Power -= powerUsage.p1;
|
||||||
Server.P2.state.power -= powerUsage.p2;
|
Server.P2.State.Power -= powerUsage.p2;
|
||||||
|
|
||||||
foreach (var player in Server.Players.Values){
|
foreach (var player in Server.Players.Values){
|
||||||
if (player.state.power < 0){
|
if (player.State.Power < 0){
|
||||||
player.state.poweredOut = true;
|
player.State.PoweredOut = true;
|
||||||
player.state.power = 0;
|
player.State.Power = 0;
|
||||||
PowerOut(player);
|
PowerOut(player);
|
||||||
}
|
}
|
||||||
// Server.SendUpdateToAll([GameEvent.POWER_OUT(player.state.pid)]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unlimitedPower){ // Debug
|
if (UNLIMITED_POWER){ // Debug
|
||||||
Server.P1.state.power = Power.MAX_POWER_VALUE;
|
Server.P1.State.Power = Power.MAX_POWER_VALUE;
|
||||||
Server.P2.state.power = Power.MAX_POWER_VALUE;
|
Server.P2.State.Power = Power.MAX_POWER_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
Server.SendUpdateToAll([GameEvent.POWER_TICK(Server.P1.state.pid, Server.P1.state.power), GameEvent.POWER_TICK(Server.P2.state.pid, Server.P2.state.power)]);
|
Server.SendUpdateToAll([GameEvent.POWER_TICK(Server.P1.State.Pid, Server.P1.State.Power), GameEvent.POWER_TICK(Server.P2.State.Pid, Server.P2.State.Power)]);
|
||||||
|
|
||||||
if (gamePhaseTimer.Check()){
|
if (gamePhaseTimer.Check()){
|
||||||
NextPhase();
|
NextPhase();
|
||||||
|
|
@ -125,8 +117,8 @@ public class GameLogic {
|
||||||
|
|
||||||
public static void DeclareWinner(ServerPlayer player) {
|
public static void DeclareWinner(ServerPlayer player) {
|
||||||
if (Server.Players.Count == 2){
|
if (Server.Players.Count == 2){
|
||||||
Server.SendUpdateToAll([GameEvent.PLAYER_WIN(player.state.pid)]);
|
Server.SendUpdateToAll([GameEvent.PLAYER_WIN(player.State.Pid)]);
|
||||||
Console.WriteLine("Player " + player.state.pid + " won!");
|
Console.WriteLine("Player " + player.State.Pid + " won!");
|
||||||
}
|
}
|
||||||
Thread.Sleep(1000);
|
Thread.Sleep(1000);
|
||||||
Server.Stop();
|
Server.Stop();
|
||||||
|
|
@ -141,10 +133,10 @@ public class GameLogic {
|
||||||
int p2Usage = 0;
|
int p2Usage = 0;
|
||||||
|
|
||||||
foreach (var consumer in PowerConsumers){
|
foreach (var consumer in PowerConsumers){
|
||||||
if (consumer.Value.pid == Server.P1.state.pid){
|
if (consumer.Value.pid == Server.P1.State.Pid){
|
||||||
p1Usage += consumer.Value.usage;
|
p1Usage += consumer.Value.usage;
|
||||||
}
|
}
|
||||||
else if (consumer.Value.pid == Server.P2.state.pid){
|
else if (consumer.Value.pid == Server.P2.State.Pid){
|
||||||
p2Usage += consumer.Value.usage;
|
p2Usage += consumer.Value.usage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -159,53 +151,60 @@ public class GameLogic {
|
||||||
foreach (var tile in MapManager.GetAllTiles().Where(t => t.Owner == player)){
|
foreach (var tile in MapManager.GetAllTiles().Where(t => t.Owner == player)){
|
||||||
tile.Lit = false;
|
tile.Lit = false;
|
||||||
}
|
}
|
||||||
PowerConsumers.Where(c => c.Value.pid == player.state.pid).ToList().ForEach(c => PowerConsumers.Remove(c.Key));
|
PowerConsumers.Where(c => c.Value.pid == player.State.Pid).ToList().ForEach(c => PowerConsumers.Remove(c.Key));
|
||||||
Server.SendUpdateToAll([GameEvent.POWER_OUT(player.state.pid)]);
|
Server.SendUpdateToAll([GameEvent.POWER_OUT(player.State.Pid)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void NextPhase() {
|
private static void NextPhase() {
|
||||||
if(noPhases) return;
|
if(NO_PHASES) return;
|
||||||
|
|
||||||
PhaseCounter++;
|
PhaseCounter++;
|
||||||
Server.SendUpdateToAll([GameEvent.NEXT_PHASE()]);
|
Server.SendUpdateToAll([GameEvent.NEXT_PHASE()]);
|
||||||
|
|
||||||
int roll = spawnOrder.Count > 0 ? random.Next(3) : random.Next(1,3);
|
int roll = spawnOrder.Count == 0 ? random.Next(1, 3) : random.Next(3);
|
||||||
switch (roll){
|
if (roll == 0){
|
||||||
case 0:
|
|
||||||
int spawnRoll = random.Next(spawnOrder[0].Count);
|
int spawnRoll = random.Next(spawnOrder[0].Count);
|
||||||
SpawnNext(spawnOrder[0][spawnRoll]);
|
if (SpawnNext(spawnOrder[0][spawnRoll])){
|
||||||
spawnOrder[0].RemoveAt(spawnRoll);
|
spawnOrder[0].RemoveAt(spawnRoll);
|
||||||
if (spawnOrder[0].Count == 0){
|
if (spawnOrder[0].Count == 0){
|
||||||
spawnOrder.RemoveAt(0);
|
spawnOrder.RemoveAt(0);
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
case 1:
|
else{
|
||||||
Enemy[] allEnemies = EnemyManager.GetAll();
|
roll = random.Next(1, 3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (roll == 1){
|
||||||
|
Enemy[] allEnemies = EnemyManager.GetAll().Where(e => e.Difficulty <= 10).ToArray();
|
||||||
|
if (allEnemies.Length == 0) return;
|
||||||
for (int i = 0; i < 2; i++){
|
for (int i = 0; i < 2; i++){
|
||||||
Enemy enemy = allEnemies[random.Next(allEnemies.Length)];
|
Enemy enemy = allEnemies[random.Next(allEnemies.Length)];
|
||||||
enemy.SetDifficulty(enemy.Difficulty + 2);
|
enemy.SetDifficulty(enemy.Difficulty + 2);
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
case 2:
|
else if (roll == 2){
|
||||||
Enemy[] enemies = EnemyManager.GetAll();
|
Enemy[] enemies = EnemyManager.GetAll();
|
||||||
for (int i = 0; i < enemies.Length; i++){
|
for (int i = 0; i < enemies.Length; i++){
|
||||||
enemies[i].SetDifficulty(enemies[i].Difficulty + 1);
|
enemies[i].SetDifficulty(enemies[i].Difficulty + 1);
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void SpawnNext(Enemy enemy) {
|
private static bool SpawnNext(Enemy enemy) {
|
||||||
if ((EnemyType)enemy.TypeId == EnemyType.NEKO || (EnemyType)enemy.TypeId == EnemyType.LURK || (EnemyType)enemy.TypeId == EnemyType.MARE){
|
if (enemy.Type == EnemyType.NEKO || enemy.Type == EnemyType.LURK || enemy.Type == EnemyType.MARE){
|
||||||
MapTile[] spawnLocations = defaultSpawnPoints.Select(i => MapManager.Get(i)).Where(t => EnemyManager.GetByLocation(t).All(e => !e.BlocksTile)).ToArray();
|
MapTile[] spawnLocations = defaultSpawnPoints.Select(i => MapManager.Get(i)).Where(t => EnemyManager.GetByLocation(t).All(e => !e.BlocksTile)).ToArray();
|
||||||
if (spawnLocations.Length == 0){
|
if (spawnLocations.Length == 0){
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
enemy.Spawn(spawnLocations[random.Next(spawnLocations.Length)]);
|
enemy.Spawn(spawnLocations[random.Next(spawnLocations.Length)]);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
else if ((EnemyType)enemy.TypeId == EnemyType.SPOT || (EnemyType)enemy.TypeId == EnemyType.DASH){
|
|
||||||
|
if (enemy.Type == EnemyType.SPOT || enemy.Type == EnemyType.DASH){
|
||||||
enemy.Spawn(MapManager.Get(12));
|
enemy.Spawn(MapManager.Get(12));
|
||||||
}
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using GlobalClassLib;
|
using GlobalClassLib;
|
||||||
|
using ONDServer.Net;
|
||||||
|
|
||||||
namespace ONDServer.Map;
|
namespace ONDServer.Map;
|
||||||
|
|
||||||
|
|
@ -10,9 +11,16 @@ public static class MapManager {
|
||||||
|
|
||||||
public static MapTile Get((int x, int y) coords) => map[coords.x, coords.y];
|
public static MapTile Get((int x, int y) coords) => map[coords.x, coords.y];
|
||||||
public static MapTile Get(int tileId) => Get(IdToCoords(tileId));
|
public static MapTile Get(int tileId) => Get(IdToCoords(tileId));
|
||||||
|
public static MapTile? TryGet(int tileId) {
|
||||||
|
try{
|
||||||
|
return Get(tileId);
|
||||||
|
}
|
||||||
|
catch (Exception){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static readonly 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)],
|
||||||
[(1, 0)] =[(2, 0, 1, ConnectorType.DOOR_OFFICE), (1, 1, 1, ConnectorType.DOOR_REMOTE)],
|
[(1, 0)] =[(2, 0, 1, ConnectorType.DOOR_OFFICE), (1, 1, 1, ConnectorType.DOOR_REMOTE)],
|
||||||
[(3, 0)] =[(2, 0, 1, ConnectorType.DOOR_OFFICE), (4, 0, 1, ConnectorType.HALL), (3, 1, 1, ConnectorType.DOOR_REMOTE)],
|
[(3, 0)] =[(2, 0, 1, ConnectorType.DOOR_OFFICE), (4, 0, 1, ConnectorType.HALL), (3, 1, 1, ConnectorType.DOOR_REMOTE)],
|
||||||
|
|
@ -23,14 +31,14 @@ public static class MapManager {
|
||||||
[(3, 1)] =[(3, 2, 1, ConnectorType.DOOR_REMOTE), (4, 1, 1, ConnectorType.HALL)]
|
[(3, 1)] =[(3, 2, 1, ConnectorType.DOOR_REMOTE), (4, 1, 1, ConnectorType.HALL)]
|
||||||
};
|
};
|
||||||
|
|
||||||
private static Dictionary<(int x1, int y1), (int x2, int y2, int value)[]> mainHallwayConnectors = new(){
|
private static readonly Dictionary<(int x1, int y1), (int x2, int y2, int value)[]> mainHallwayConnectors = new(){
|
||||||
[(0,2)] = [(1,2,1)],
|
[(0,2)] = [(1,2,1)],
|
||||||
[(1,2)] = [(2,2,1)],
|
[(1,2)] = [(2,2,1)],
|
||||||
[(2,2)] = [(3,2,1)],
|
[(2,2)] = [(3,2,1)],
|
||||||
[(3,2)] = [(4,2,1)]
|
[(3,2)] = [(4,2,1)]
|
||||||
};
|
};
|
||||||
|
|
||||||
private static (int x, int y)[] ventTiles =[(0, 1), (4, 1), (2, 2), (0, 3), (4, 3)];
|
private static readonly (int x, int y)[] ventTiles =[(0, 1), (4, 1), (2, 2), (0, 3), (4, 3)];
|
||||||
|
|
||||||
public static void InitMap() {
|
public static void InitMap() {
|
||||||
for (int i = 0; i < 5; i++){
|
for (int i = 0; i < 5; i++){
|
||||||
|
|
@ -95,9 +103,9 @@ public static class MapManager {
|
||||||
return tiles.ToArray();
|
return tiles.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public const int ID_X_OFFSET = 5; // map grid height
|
private const int MAP_SIDE_LENGTH_X = 5;
|
||||||
public static int CoordsToId(int x, int y) => x * ID_X_OFFSET + y;
|
public static int CoordsToId(int x, int y) => x * MAP_SIDE_LENGTH_X + y;
|
||||||
public static (int, int) IdToCoords(int id) => (id / ID_X_OFFSET, id % ID_X_OFFSET);
|
public static (int, int) IdToCoords(int id) => (id / MAP_SIDE_LENGTH_X, id % MAP_SIDE_LENGTH_X);
|
||||||
|
|
||||||
public static TileConnector[] GetDoors() => doors.ToArray();
|
public static TileConnector[] GetDoors() => doors.ToArray();
|
||||||
public static TileConnector[] GetDoors(ServerPlayer player) => player == Server.P1 ? doorsP1.ToArray() : doorsP2.ToArray();
|
public static TileConnector[] GetDoors(ServerPlayer player) => player == Server.P1 ? doorsP1.ToArray() : doorsP2.ToArray();
|
||||||
|
|
|
||||||
|
|
@ -1,43 +1,9 @@
|
||||||
using System.Net.Security;
|
using System.Net.Security;
|
||||||
using GlobalClassLib;
|
using GlobalClassLib;
|
||||||
|
using ONDServer.Net;
|
||||||
|
|
||||||
namespace ONDServer.Map;
|
namespace ONDServer.Map;
|
||||||
|
|
||||||
public class MapTile : GlobalMapTile<TileConnector, MapTile> {
|
public class MapTile(int id) : GlobalMapTile<TileConnector, MapTile>(id, MapManager.IdToCoords(id)) {
|
||||||
public ServerPlayer? Owner{ get; set; }
|
public ServerPlayer? Owner{ get; set; }
|
||||||
|
|
||||||
public MapTile(int id) : base(id, MapManager.IdToCoords(id)) {
|
|
||||||
}
|
|
||||||
|
|
||||||
// public int Id { get; private set; }
|
|
||||||
// public ServerPlayer Owner { get; private set; }
|
|
||||||
// public bool Lit { get; set; } = false;
|
|
||||||
//
|
|
||||||
// private List<TileConnector> connectors = new();
|
|
||||||
//
|
|
||||||
// public MapTile(int id, ServerPlayer owner) {
|
|
||||||
// Id = id;
|
|
||||||
// Owner = owner;
|
|
||||||
// }
|
|
||||||
// public void AddConnector(MapTile tile, TileConnector.ConnectorType type, int value) {
|
|
||||||
// connectors.Add(new TileConnector(this, tile, type, value));
|
|
||||||
// tile.connectors.Add(new TileConnector(tile, this, type, value));
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void AddConnectors((MapTile tile, TileConnector.ConnectorType type, int value)[] connectors) =>
|
|
||||||
// Array.ForEach(connectors, c => AddConnector(c.tile, c.type, c.value));
|
|
||||||
//
|
|
||||||
// public override string ToString() => $"{PositionAsString} -> {string.Join(", ", connectors.Select(c => c.Tiles.Item2.PositionAsString))}";
|
|
||||||
// public string PositionAsString => $"[{Id}]"; // for debug purposes
|
|
||||||
//
|
|
||||||
// public TileConnector? GetConnector(int id) {
|
|
||||||
// foreach (var con in connectors){
|
|
||||||
// if (con.Tiles.Item2.Id == id) return con;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return null;
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using GlobalClassLib;
|
using GlobalClassLib;
|
||||||
|
using ONDServer.Net;
|
||||||
|
|
||||||
namespace ONDServer.Map;
|
namespace ONDServer.Map;
|
||||||
|
|
||||||
|
|
@ -13,33 +14,5 @@ public class TileConnector : GlobalTileConnector<MapTile,TileConnector> {
|
||||||
Value = value;
|
Value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// private readonly MapTile _tile1;
|
|
||||||
// private readonly MapTile _tile2;
|
|
||||||
//
|
|
||||||
// public TileConnector(MapTile tile1, MapTile tile2, TileConnector.ConnectorType type, int value) {
|
|
||||||
// _tile1 = tile1;
|
|
||||||
// _tile2 = tile2;
|
|
||||||
// Type = type;
|
|
||||||
// Value = value;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public (MapTile, MapTile) Tiles => (tile1: _tile1, tile2: _tile2);
|
|
||||||
//
|
|
||||||
// public ConnectorType Type { get; set; }
|
|
||||||
// public bool Blocked { get; set; } = false;
|
|
||||||
// public int Value{ get; set; }
|
|
||||||
//
|
|
||||||
// public MapTile OtherTile(MapTile tile) => Tiles.Item1 == tile ? Tiles.Item2 : Tiles.Item1;
|
|
||||||
//
|
|
||||||
// public override string ToString() => $"Con ({Tiles.Item1.PositionAsString} -> {Tiles.Item2.PositionAsString})";
|
|
||||||
// public enum ConnectorType {
|
|
||||||
// HALL,
|
|
||||||
// DOOR_REMOTE,
|
|
||||||
// DOOR_OFFICE,
|
|
||||||
// VENT
|
|
||||||
// }
|
|
||||||
|
|
||||||
public override TileConnector Clone() => new(Tiles.tile1, Tiles.tile2, Type, Value){Owner = Owner};
|
public override TileConnector Clone() => new(Tiles.tile1, Tiles.tile2, Type, Value){Owner = Owner};
|
||||||
}
|
}
|
||||||
139
ONDServer/Net/CommandProcessor.cs
Normal file
139
ONDServer/Net/CommandProcessor.cs
Normal file
|
|
@ -0,0 +1,139 @@
|
||||||
|
using ONDServer.Map;
|
||||||
|
using PacketLib;
|
||||||
|
|
||||||
|
namespace ONDServer.Net;
|
||||||
|
|
||||||
|
public static class CommandProcessor {
|
||||||
|
private static readonly Dictionary<int, Action<ServerPlayer, PlayerCommand>> commandHandlers = new(){
|
||||||
|
[0] = (p, c) => SwitchCamera(p, c.Args[0]),
|
||||||
|
[1] = (p, c) => SetMonitorState(p, c.Args[0] == 1),
|
||||||
|
[2] = (p, c) => SetDoorStateOffice(p, c.Args[0], c.Args[1] == 1),
|
||||||
|
[3] = (p, c) => SetDoorStateRemote(p.State.Pid, (c.Args[0], c.Args[1]), c.Args[2] == 1),
|
||||||
|
[4] = (p, c) => SetLightState(p, c.Args[0], c.Args[1] == 1)
|
||||||
|
};
|
||||||
|
|
||||||
|
public static void Evaluate(PlayerCommand[] commands, int pid) {
|
||||||
|
ServerPlayer currentPlayer = Server.Players[pid];
|
||||||
|
|
||||||
|
foreach (var playerCommand in commands){
|
||||||
|
commandHandlers[playerCommand.Id](currentPlayer, playerCommand);
|
||||||
|
// switch (playerCommand.ID){
|
||||||
|
// case 0:
|
||||||
|
// Console.WriteLine($"C: Player {pid} switched to camera {playerCommand.Args[0]}");
|
||||||
|
// currentPlayer.state.camera = playerCommand.Args[0];
|
||||||
|
// Server.SendUpdateToAll([GameEvent.SWITCH_CAM(pid, playerCommand.Args[0])]);
|
||||||
|
// break;
|
||||||
|
// case 1:
|
||||||
|
// bool monitorState = playerCommand.Args[0] == 1;
|
||||||
|
// currentPlayer.state.monitorUp = monitorState;
|
||||||
|
// Console.WriteLine($"C: Player {pid} toggled camera {(monitorState ? "on" : "off")}");
|
||||||
|
// Server.SendUpdateToAll([GameEvent.TOGGLE_MONITOR(pid, monitorState)]);
|
||||||
|
// break;
|
||||||
|
// case 2:
|
||||||
|
// bool doorState = playerCommand.Args[1] == 1;
|
||||||
|
// currentPlayer.state.doorStates[playerCommand.Args[0]] = doorState;
|
||||||
|
// TileConnector? officeDoor = MapManager.Get(currentPlayer.state.officeTileId).GetConnector(currentPlayer.state.neighbouringTiles[playerCommand.Args[0]]);
|
||||||
|
// officeDoor.Blocked = doorState;
|
||||||
|
//
|
||||||
|
// if (doorState){
|
||||||
|
// GameLogic.PowerConsumers[officeDoor] = (GameLogic.OfficeDoorUsage, pid);
|
||||||
|
// }
|
||||||
|
// else{
|
||||||
|
// GameLogic.PowerConsumers.Remove(officeDoor);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// Console.WriteLine($"C: Player {pid} {(doorState ? "closed" : "opened")} door {playerCommand.Args[0]}");
|
||||||
|
// Server.SendUpdateToAll([GameEvent.TOGGLE_DOOR_OFFICE(pid,playerCommand.Args[0] ,doorState)]);
|
||||||
|
// break;
|
||||||
|
// case 3:
|
||||||
|
// TileConnector? door = MapManager.Get(playerCommand.Args[0]).GetConnector(playerCommand.Args[1]);
|
||||||
|
// if(door == null) return;
|
||||||
|
//
|
||||||
|
// door.Blocked = playerCommand.Args[2] == 1;
|
||||||
|
// if (door.Blocked){
|
||||||
|
// GameLogic.PowerConsumers[door] = (GameLogic.RemoteDoorUsage, pid);
|
||||||
|
// }
|
||||||
|
// else{
|
||||||
|
// GameLogic.PowerConsumers.Remove(door);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// 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;
|
||||||
|
// case 4:
|
||||||
|
// bool lit = playerCommand.Args[1] == 1;
|
||||||
|
// MapTile lightTile = MapManager.Get(playerCommand.Args[0]);
|
||||||
|
// lightTile.Lit = lit;
|
||||||
|
// if (lit){
|
||||||
|
// GameLogic.PowerConsumers[lightTile] = (GameLogic.LightUsage, pid);
|
||||||
|
// }
|
||||||
|
// else{
|
||||||
|
// GameLogic.PowerConsumers.Remove(lightTile);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// Server.SendUpdateToAll([GameEvent.TOGGLE_LIGHT(pid, playerCommand.Args[0], lit)]);
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void SwitchCamera(ServerPlayer currentPlayer, int cameraId) {
|
||||||
|
if (MapManager.TryGet(cameraId) == null || Server.Players.Values.Any(p => p.State.OfficeTileId == cameraId)) return;
|
||||||
|
Console.WriteLine($"C: Player {currentPlayer.State.Pid} switched to camera {cameraId}");
|
||||||
|
currentPlayer.State.Camera = cameraId;
|
||||||
|
Server.SendUpdateToAll([GameEvent.SWITCH_CAM(currentPlayer.State.Pid, cameraId)]);
|
||||||
|
}
|
||||||
|
private static void SetMonitorState(ServerPlayer currentPlayer, bool monitorState) {
|
||||||
|
currentPlayer.State.MonitorUp = monitorState;
|
||||||
|
Console.WriteLine($"C: Player {currentPlayer.State.Pid} toggled camera {(monitorState ? "on" : "off")}");
|
||||||
|
Server.SendUpdateToAll([GameEvent.TOGGLE_MONITOR(currentPlayer.State.Pid, monitorState)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void SetDoorStateOffice(ServerPlayer currentPlayer, int doorId, bool doorState) {
|
||||||
|
if (doorId < 0 || currentPlayer.State.DoorStates.Length <= doorId) return;
|
||||||
|
currentPlayer.State.DoorStates[doorId] = doorState;
|
||||||
|
TileConnector? officeDoor = MapManager.Get(currentPlayer.State.OfficeTileId).GetConnector(currentPlayer.State.NeighbouringTiles[doorId]);
|
||||||
|
if (officeDoor == null) return;
|
||||||
|
officeDoor.Blocked = doorState;
|
||||||
|
|
||||||
|
if (doorState){
|
||||||
|
GameLogic.PowerConsumers[officeDoor] = (GameLogic.OfficeDoorUsage, currentPlayer.State.Pid);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
GameLogic.PowerConsumers.Remove(officeDoor);
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.WriteLine($"C: Player {currentPlayer.State.Pid} {(doorState ? "closed" : "opened")} door {doorId}");
|
||||||
|
Server.SendUpdateToAll([GameEvent.TOGGLE_DOOR_OFFICE(currentPlayer.State.Pid, doorId ,doorState)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void SetDoorStateRemote(int pid, (int tile1, int tile2) doorId, bool state) {
|
||||||
|
TileConnector? door = MapManager.Get(doorId.tile1).GetConnector(doorId.tile2);
|
||||||
|
if(door == null) return;
|
||||||
|
|
||||||
|
door.Blocked = state;
|
||||||
|
if (door.Blocked){
|
||||||
|
GameLogic.PowerConsumers[door] = (GameLogic.RemoteDoorUsage, pid);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
GameLogic.PowerConsumers.Remove(door);
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.WriteLine($"C: Player {pid} {(door.Blocked ? "closed" : "opened")} door {doorId}");
|
||||||
|
Server.SendUpdateToAll([GameEvent.TOGGLE_DOOR_REMOTE(pid, doorId, door.Blocked)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void SetLightState(ServerPlayer currentPlayer, int tileId, bool state) {
|
||||||
|
MapTile lightTile = MapManager.Get(tileId);
|
||||||
|
lightTile.Lit = state;
|
||||||
|
if (state){
|
||||||
|
GameLogic.PowerConsumers[lightTile] = (GameLogic.LightUsage, currentPlayer.State.Pid);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
GameLogic.PowerConsumers.Remove(lightTile);
|
||||||
|
}
|
||||||
|
|
||||||
|
Server.SendUpdateToAll([GameEvent.TOGGLE_LIGHT(currentPlayer.State.Pid, tileId, state)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,35 +1,32 @@
|
||||||
using System;
|
|
||||||
using System.Collections;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Threading;
|
|
||||||
using ONDServer.Map;
|
|
||||||
using GlobalClassLib;
|
using GlobalClassLib;
|
||||||
using LiteNetLib;
|
using LiteNetLib;
|
||||||
using LiteNetLib.Utils;
|
using LiteNetLib.Utils;
|
||||||
using PacketLib;
|
using PacketLib;
|
||||||
|
|
||||||
namespace ONDServer;
|
namespace ONDServer.Net;
|
||||||
|
|
||||||
public class Server {
|
public static class Server {
|
||||||
public static ServerPlayer P1;
|
public static ServerPlayer P1;
|
||||||
public static ServerPlayer P2;
|
public static ServerPlayer P2;
|
||||||
public static readonly Dictionary<int, ServerPlayer> Players = new();
|
public static readonly Dictionary<int, ServerPlayer> Players = new();
|
||||||
public static ServerPlayer OtherPlayer(ServerPlayer player) => player.state.pid == P1.state.pid ? P2 : P1;
|
public static ServerPlayer OtherPlayer(ServerPlayer player) => player.State.Pid == P1.State.Pid ? P2 : P1;
|
||||||
|
|
||||||
public static bool AutoStop{ get; set; } = true;
|
public static bool AutoStop{ get; set; } = true;
|
||||||
|
|
||||||
private static EventBasedNetListener listener;
|
private static EventBasedNetListener listener;
|
||||||
private static NetManager server;
|
private static NetManager server;
|
||||||
|
|
||||||
private const int TargetTickRate = 30;
|
private const int TARGET_TICK_RATE = 30;
|
||||||
private const double TargetDeltaTime = 1.0 / TargetTickRate;
|
private const double TARGET_DELTA_TIME = 1.0 / TARGET_TICK_RATE;
|
||||||
private const long TargetTickTimeMs = 1000 / TargetTickRate;
|
private const long TARGET_TICK_TIME_MS = 1000 / TARGET_TICK_RATE;
|
||||||
|
|
||||||
private static NetDataWriter writer;
|
private static NetDataWriter writer;
|
||||||
private static NetPacketProcessor processor;
|
private static NetPacketProcessor processor;
|
||||||
|
|
||||||
private static bool isRunning;
|
private static bool isRunning;
|
||||||
|
|
||||||
|
// AI generated
|
||||||
public static void Start(int port) {
|
public static void Start(int port) {
|
||||||
writer = new NetDataWriter();
|
writer = new NetDataWriter();
|
||||||
processor = new NetPacketProcessor();
|
processor = new NetPacketProcessor();
|
||||||
|
|
@ -61,9 +58,7 @@ public class Server {
|
||||||
OnNetworkReceive(peer, reader, method);
|
OnNetworkReceive(peer, reader, method);
|
||||||
};
|
};
|
||||||
|
|
||||||
listener.PeerDisconnectedEvent += (peer, info) => {
|
listener.PeerDisconnectedEvent += OnPeerDisconnected;
|
||||||
OnPeerDisconnected(peer, info);
|
|
||||||
};
|
|
||||||
|
|
||||||
server.Start(port);
|
server.Start(port);
|
||||||
|
|
||||||
|
|
@ -78,58 +73,50 @@ public class Server {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static void SendPacket<T>(T packet, int pid, DeliveryMethod deliveryMethod = DeliveryMethod.ReliableOrdered) where T : class, new() {
|
public static void SendPacket<T>(T packet, int pid, DeliveryMethod deliveryMethod = DeliveryMethod.ReliableOrdered) where T : class, new() {
|
||||||
SendPacket(packet, Players[pid].peer, deliveryMethod);
|
SendPacket(packet, Players[pid].Peer, deliveryMethod);
|
||||||
}
|
}
|
||||||
public static void SendPacketToAll<T>(T packet, DeliveryMethod deliveryMethod = DeliveryMethod.ReliableOrdered) where T : class, new() {
|
public static void SendPacketToAll<T>(T packet, DeliveryMethod deliveryMethod = DeliveryMethod.ReliableOrdered) where T : class, new() {
|
||||||
foreach (var player in Players.Values){
|
foreach (var player in Players.Values){
|
||||||
SendPacket(packet, player.peer, deliveryMethod);
|
SendPacket(packet, player.Peer, deliveryMethod);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SendUpdate(GameEvent[] gevents, int pid) {
|
public static void SendUpdate(GameEvent[] gevents, int pid) {
|
||||||
// SendPacket(new UpdatePlayerPacket{eventQueue = new EventQueue{Events = events}}, pid);
|
SendPacket(new UpdatePlayerPacket{Events = gevents}, pid);
|
||||||
SendPacket(new UpdatePlayerPacket{events = gevents}, pid);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SendUpdateToAll(GameEvent[] gevents) {
|
public static void SendUpdateToAll(GameEvent[] gevents) {
|
||||||
// SendPacketToAll(new UpdatePlayerPacket{eventQueue = new EventQueue{Events = events}});
|
SendPacketToAll(new UpdatePlayerPacket{Events = gevents});
|
||||||
SendPacketToAll(new UpdatePlayerPacket{events = gevents});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void OnJoinReceived(JoinPacket packet, NetPeer peer) {
|
public static void OnJoinReceived(JoinPacket packet, NetPeer peer) {
|
||||||
Console.WriteLine($"Received join from {packet.username} (pid: {(uint)peer.Id})");
|
Console.WriteLine($"Received join from {packet.Username} (pid: {(uint)peer.Id})");
|
||||||
|
|
||||||
ServerPlayer newPlayer = (Players[peer.Id] = new ServerPlayer {
|
ServerPlayer newPlayer = (Players[peer.Id] = new ServerPlayer {
|
||||||
peer = peer,
|
Peer = peer,
|
||||||
state = new PlayerState {
|
State = new PlayerState(peer.Id, GameLogic.START_CAMERA, [false, false, false],
|
||||||
pid = peer.Id,
|
Power.MAX_POWER_VALUE, false),
|
||||||
camera = GameLogic.START_CAMERA,
|
Username = packet.Username
|
||||||
doorStates = [false, false, false],
|
|
||||||
power = Power.MAX_POWER_VALUE,
|
|
||||||
poweredOut = false
|
|
||||||
},
|
|
||||||
username = packet.username
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
if (Players.Count == 1){
|
if (Players.Count == 1){
|
||||||
newPlayer.state.officeTileId = 10;
|
newPlayer.State.OfficeTileId = 10;
|
||||||
newPlayer.state.neighbouringTiles = [5, 11, 15];
|
newPlayer.State.NeighbouringTiles = [5, 11, 15];
|
||||||
SendPacket(new JoinAcceptPacket { state = newPlayer.state }, peer);
|
SendPacket(new JoinAcceptPacket { State = newPlayer.State }, peer);
|
||||||
P1 = newPlayer;
|
P1 = newPlayer;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
newPlayer.state.officeTileId = 14;
|
newPlayer.State.OfficeTileId = 14;
|
||||||
newPlayer.state.neighbouringTiles = [19, 13, 9];
|
newPlayer.State.NeighbouringTiles = [19, 13, 9];
|
||||||
|
|
||||||
SendPacket(new JoinAcceptPacket { state = newPlayer.state }, peer);
|
SendPacket(new JoinAcceptPacket { State = newPlayer.State }, peer);
|
||||||
P2 = newPlayer;
|
P2 = newPlayer;
|
||||||
|
|
||||||
SendPacket(new OpponentInitPacket{state = newPlayer.state, username = newPlayer.username}, P1.peer);
|
SendPacket(new OpponentInitPacket{State = newPlayer.State, Username = newPlayer.Username}, P1.Peer);
|
||||||
SendPacket(new OpponentInitPacket{state = P1.state, username = P1.username}, P2.peer);
|
SendPacket(new OpponentInitPacket{State = P1.State, Username = P1.Username}, P2.Peer);
|
||||||
GameLogic.Init();
|
GameLogic.Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -141,7 +128,7 @@ public class Server {
|
||||||
|
|
||||||
public static void OnPeerDisconnected(NetPeer peer, DisconnectInfo disconnectInfo) {
|
public static void OnPeerDisconnected(NetPeer peer, DisconnectInfo disconnectInfo) {
|
||||||
if (Players.Count == 2){
|
if (Players.Count == 2){
|
||||||
GameLogic.DeclareWinner(OtherPlayer(Players.Values.First(p => Equals(p.peer, peer))));
|
GameLogic.DeclareWinner(OtherPlayer(Players.Values.First(p => Equals(p.Peer, peer))));
|
||||||
}
|
}
|
||||||
|
|
||||||
Players.Remove(peer.Id);
|
Players.Remove(peer.Id);
|
||||||
|
|
@ -151,15 +138,15 @@ public class Server {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void OnCommandReceived(PlayerCommandPacket packet, NetPeer peer) {
|
public static void OnCommandReceived(PlayerCommandPacket packet, NetPeer peer) {
|
||||||
CommandProcessor.Evaluate(packet.commands, peer.Id);
|
CommandProcessor.Evaluate(packet.Commands, peer.Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Update() {
|
public static void Update() {
|
||||||
server.PollEvents();
|
server.PollEvents();
|
||||||
// Console.WriteLine("update");
|
|
||||||
GameLogic.Update();
|
GameLogic.Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AI generated
|
||||||
public static void Run(CancellationToken cancellationToken = default)
|
public static void Run(CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
isRunning = true;
|
isRunning = true;
|
||||||
|
|
@ -171,26 +158,26 @@ public class Server {
|
||||||
long currentTicks = stopwatch.ElapsedMilliseconds;
|
long currentTicks = stopwatch.ElapsedMilliseconds;
|
||||||
long elapsed = currentTicks - previousTicks;
|
long elapsed = currentTicks - previousTicks;
|
||||||
|
|
||||||
if (elapsed >= TargetTickTimeMs)
|
if (elapsed >= TARGET_TICK_TIME_MS)
|
||||||
{
|
{
|
||||||
Update();
|
Update();
|
||||||
|
|
||||||
previousTicks = currentTicks;
|
previousTicks = currentTicks;
|
||||||
if (elapsed > TargetTickTimeMs * 2)
|
if (elapsed > TARGET_TICK_TIME_MS * 2)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Warning: Tick took {elapsed}ms (target: {TargetTickTimeMs}ms)");
|
Console.WriteLine($"Warning: Tick took {elapsed}ms (target: {TARGET_TICK_TIME_MS}ms)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
int sleepTime = (int)(TargetTickTimeMs - elapsed - 2);
|
int sleepTime = (int)(TARGET_TICK_TIME_MS - elapsed - 2);
|
||||||
if (sleepTime > 0)
|
if (sleepTime > 0)
|
||||||
{
|
{
|
||||||
Thread.Sleep(sleepTime);
|
Thread.Sleep(sleepTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (stopwatch.ElapsedMilliseconds - previousTicks < TargetTickTimeMs){
|
while (stopwatch.ElapsedMilliseconds - previousTicks < TARGET_TICK_TIME_MS){
|
||||||
Thread.SpinWait(1);
|
Thread.SpinWait(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
10
ONDServer/Net/ServerPlayer.cs
Normal file
10
ONDServer/Net/ServerPlayer.cs
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
using LiteNetLib;
|
||||||
|
using PacketLib;
|
||||||
|
|
||||||
|
namespace ONDServer.Net;
|
||||||
|
|
||||||
|
public class ServerPlayer {
|
||||||
|
public NetPeer Peer;
|
||||||
|
public PlayerState State;
|
||||||
|
public string Username;
|
||||||
|
}
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using ONDServer.Net;
|
||||||
|
|
||||||
namespace ONDServer;
|
namespace ONDServer;
|
||||||
|
|
||||||
public class Program {
|
public static class Program {
|
||||||
public static void Main(string[] args) {
|
public static void Main(string[] args) {
|
||||||
if (args.Contains("--persistent")){
|
if (args.Contains("--persistent")){
|
||||||
Server.AutoStop = false;
|
Server.AutoStop = false;
|
||||||
|
|
|
||||||
|
|
@ -1,10 +0,0 @@
|
||||||
using LiteNetLib;
|
|
||||||
using PacketLib;
|
|
||||||
|
|
||||||
namespace ONDServer;
|
|
||||||
|
|
||||||
public class ServerPlayer {
|
|
||||||
public NetPeer peer;
|
|
||||||
public PlayerState state;
|
|
||||||
public string username;
|
|
||||||
}
|
|
||||||
|
|
@ -12,6 +12,4 @@ public struct EventQueue : INetSerializable {
|
||||||
public void Deserialize(NetDataReader reader) {
|
public void Deserialize(NetDataReader reader) {
|
||||||
Events = reader.GetArray<GameEvent>();
|
Events = reader.GetArray<GameEvent>();
|
||||||
}
|
}
|
||||||
|
|
||||||
// public GameEvent this[int index] => Events[index];
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,44 +1,44 @@
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using GlobalClassLib;
|
||||||
using LiteNetLib.Utils;
|
using LiteNetLib.Utils;
|
||||||
|
|
||||||
namespace PacketLib;
|
namespace PacketLib;
|
||||||
|
|
||||||
#nullable disable
|
#nullable disable
|
||||||
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 id) => new(){ID = 2, Args = [pid, id] };
|
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]};
|
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]};
|
||||||
|
|
||||||
public static GameEvent ENEMY_SPAWN(int enemyTypeId, int enemyId, int difficulty, int camId) => new(){ ID = 6, Args = [enemyTypeId, enemyId, difficulty, camId] };
|
public static GameEvent ENEMY_SPAWN(EnemyType enemyTypeId, int enemyId, int difficulty, int camId) => new(){ Id = 6, Args = [(int)enemyTypeId, enemyId, difficulty, camId] };
|
||||||
public static GameEvent ENEMY_MOVEMENT(int enemyId, int camId) => new(){ID = 7, Args = [enemyId, camId]};
|
public static GameEvent ENEMY_MOVEMENT(int enemyId, int camId) => new(){Id = 7, Args = [enemyId, camId]};
|
||||||
public static GameEvent ENEMY_ATTACK(int enemyId, int pid) => new(){ ID = 8, Args =[enemyId, pid] };
|
public static GameEvent ENEMY_ATTACK(int enemyId, int pid) => new(){ Id = 8, Args =[enemyId, pid] };
|
||||||
public static GameEvent ENEMY_RESET(int enemyId, int camId) => new(){ID = 9, Args = [enemyId, camId]};
|
public static GameEvent ENEMY_RESET(int enemyId, int camId) => new(){Id = 9, Args = [enemyId, camId]};
|
||||||
|
|
||||||
public static GameEvent SPOT_SET_ACTIVE(int enemyId, bool state) => new(){ ID = 10, Args = [enemyId, state ? 1 : 0] };
|
public static GameEvent SPOT_SET_ACTIVE(int enemyId, bool state) => new(){ Id = 10, Args = [enemyId, state ? 1 : 0] };
|
||||||
|
|
||||||
public static GameEvent PLAYER_WIN(int pid) => new(){ID = 11, Args = [pid]};
|
public static GameEvent PLAYER_WIN(int pid) => new(){Id = 11, Args = [pid]};
|
||||||
public static GameEvent GAME_START() => new(){ID = 12};
|
public static GameEvent GAME_START() => new(){Id = 12};
|
||||||
public static GameEvent POWER_TICK(int pid, int power) => new(){ID = 13, Args = [pid, power]};
|
public static GameEvent POWER_TICK(int pid, int power) => new(){Id = 13, Args = [pid, power]};
|
||||||
public static GameEvent POWER_OUT(int pid) => new(){ID = 14, Args = [pid]};
|
public static GameEvent POWER_OUT(int pid) => new(){Id = 14, Args = [pid]};
|
||||||
public static GameEvent TOGGLE_LIGHT(int pid, int camId, bool state) => new(){ID = 15, Args = [pid, camId, state ? 1 : 0]};
|
public static GameEvent TOGGLE_LIGHT(int pid, int camId, bool state) => new(){Id = 15, Args = [pid, camId, state ? 1 : 0]};
|
||||||
public static GameEvent NEKO_ANGERED(int pid, int enemyId) => new(){ID = 16, Args = [pid, enemyId]};
|
public static GameEvent NEKO_ANGERED(int pid, int enemyId) => new(){Id = 16, Args = [pid, enemyId]};
|
||||||
public static GameEvent VENT_USED() => new(){ID = 17};
|
public static GameEvent VENT_USED() => new(){Id = 17};
|
||||||
public static GameEvent NEXT_PHASE() => new(){ID = 18};
|
public static GameEvent NEXT_PHASE() => new(){Id = 18};
|
||||||
|
|
||||||
public int ID{ get; set; }
|
public int Id{ get; set; }
|
||||||
public bool Hideable => ID < 0;
|
|
||||||
public int[] Args{ get; private set; }
|
public int[] Args{ get; private set; }
|
||||||
|
|
||||||
public void Serialize(NetDataWriter writer) {
|
public void Serialize(NetDataWriter writer) {
|
||||||
writer.Put(ID);
|
writer.Put(Id);
|
||||||
writer.PutArray(Args);
|
writer.PutArray(Args);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Deserialize(NetDataReader reader) {
|
public void Deserialize(NetDataReader reader) {
|
||||||
ID = reader.GetInt();
|
Id = reader.GetInt();
|
||||||
Args = reader.GetIntArray();
|
Args = reader.GetIntArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
namespace PacketLib;
|
namespace PacketLib;
|
||||||
|
|
||||||
public class JoinAcceptPacket {
|
public class JoinAcceptPacket {
|
||||||
public PlayerState state { get; set; }
|
public PlayerState State { get; set; }
|
||||||
// public PlayerState otherPlayerState { get; set; }
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
namespace PacketLib;
|
namespace PacketLib;
|
||||||
|
|
||||||
public class JoinPacket {
|
public class JoinPacket {
|
||||||
public string username { get; set; }
|
public string Username { get; set; }
|
||||||
}
|
}
|
||||||
|
|
@ -1,13 +0,0 @@
|
||||||
using System.Xml;
|
|
||||||
using LiteNetLib.Utils;
|
|
||||||
|
|
||||||
namespace PacketLib;
|
|
||||||
|
|
||||||
public static class NetDataWriterExtensions {
|
|
||||||
public static GameEvent GetGameEvent(this NetDataReader reader) {
|
|
||||||
GameEvent gevent = new();
|
|
||||||
gevent.Deserialize(reader);
|
|
||||||
return gevent;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
namespace PacketLib;
|
namespace PacketLib;
|
||||||
|
|
||||||
public class OpponentInitPacket {
|
public class OpponentInitPacket {
|
||||||
public PlayerState state { get; set; }
|
public PlayerState State { get; set; }
|
||||||
public string username { get; set; }
|
public string Username { get; set; }
|
||||||
}
|
}
|
||||||
|
|
@ -4,22 +4,21 @@ using LiteNetLib.Utils;
|
||||||
namespace PacketLib;
|
namespace PacketLib;
|
||||||
|
|
||||||
public struct PlayerCommand : INetSerializable {
|
public struct PlayerCommand : INetSerializable {
|
||||||
public static PlayerCommand SWITCH_CAM(int id) => new(){ID = 0, Args = [id] };
|
public static PlayerCommand SWITCH_CAM(int id) => new(){Id = 0, Args = [id] };
|
||||||
public static PlayerCommand SET_MONITOR(bool state) => new(){ID = 1, Args = [state ? 1 : 0]};
|
public static PlayerCommand SET_MONITOR(bool state) => new(){Id = 1, Args = [state ? 1 : 0]};
|
||||||
public static PlayerCommand SET_DOOR_OFFICE(Direction direction, bool state) => new(){ID = 2, Args = [(int)direction, state ? 1 : 0]};
|
public static PlayerCommand SET_DOOR_OFFICE(Direction direction, bool state) => new(){Id = 2, Args = [(int)direction, state ? 1 : 0]};
|
||||||
public static PlayerCommand SET_DOOR_REMOTE((int, int) remoteDoorId, bool state) => new(){ID = 3, Args = [remoteDoorId.Item1, remoteDoorId.Item2, state ? 1 : 0]};
|
public static PlayerCommand SET_DOOR_REMOTE((int, int) remoteDoorId, bool state) => new(){Id = 3, Args = [remoteDoorId.Item1, remoteDoorId.Item2, state ? 1 : 0]};
|
||||||
public static PlayerCommand SET_LIGHT(int camId, bool state) => new(){ID = 4, Args = [camId, state ? 1 : 0]};
|
public static PlayerCommand SET_LIGHT(int camId, bool state) => new(){Id = 4, Args = [camId, state ? 1 : 0]};
|
||||||
public int ID{ get; set; }
|
public int Id{ get; set; }
|
||||||
public bool Hideable => ID < 0;
|
|
||||||
public int[] Args{ get; private set; }
|
public int[] Args{ get; private set; }
|
||||||
|
|
||||||
public void Serialize(NetDataWriter writer) {
|
public void Serialize(NetDataWriter writer) {
|
||||||
writer.Put(ID);
|
writer.Put(Id);
|
||||||
writer.PutArray(Args);
|
writer.PutArray(Args);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Deserialize(NetDataReader reader) {
|
public void Deserialize(NetDataReader reader) {
|
||||||
ID = reader.GetInt();
|
Id = reader.GetInt();
|
||||||
Args = reader.GetIntArray();
|
Args = reader.GetIntArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
namespace PacketLib;
|
namespace PacketLib;
|
||||||
|
|
||||||
public class PlayerCommandPacket {
|
public class PlayerCommandPacket {
|
||||||
public PlayerCommand[] commands { get; set; }
|
public PlayerCommand[] Commands { get; set; }
|
||||||
}
|
}
|
||||||
|
|
@ -1,40 +1,39 @@
|
||||||
using LiteNetLib;
|
using LiteNetLib.Utils;
|
||||||
using LiteNetLib.Utils;
|
|
||||||
|
|
||||||
namespace PacketLib;
|
namespace PacketLib;
|
||||||
|
|
||||||
public struct PlayerState : INetSerializable { // TODO: make a constructor
|
public struct PlayerState(int pid, int camera, bool[] doorStates, int power, bool poweredOut) : INetSerializable {
|
||||||
public int pid;
|
public int Pid = pid;
|
||||||
public int camera;
|
public int Camera = camera;
|
||||||
public bool monitorUp;
|
public bool MonitorUp;
|
||||||
|
|
||||||
public int officeTileId;
|
public int OfficeTileId;
|
||||||
public bool[] doorStates;
|
public bool[] DoorStates = doorStates;
|
||||||
public int[] neighbouringTiles; // the indexes should correspond in both arrays
|
public int[] NeighbouringTiles = []; // the indexes should correspond in both arrays
|
||||||
|
|
||||||
public int power;
|
public int Power = power;
|
||||||
public bool poweredOut;
|
public bool PoweredOut = poweredOut;
|
||||||
|
|
||||||
public void Serialize(NetDataWriter writer) {
|
public void Serialize(NetDataWriter writer) {
|
||||||
writer.Put(pid);
|
writer.Put(Pid);
|
||||||
writer.Put(camera);
|
writer.Put(Camera);
|
||||||
writer.Put(monitorUp);
|
writer.Put(MonitorUp);
|
||||||
writer.PutArray(doorStates);
|
writer.PutArray(DoorStates);
|
||||||
writer.Put(officeTileId);
|
writer.Put(OfficeTileId);
|
||||||
writer.PutArray(neighbouringTiles);
|
writer.PutArray(NeighbouringTiles);
|
||||||
writer.Put(power);
|
writer.Put(Power);
|
||||||
writer.Put(poweredOut);
|
writer.Put(PoweredOut);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Deserialize(NetDataReader reader) {
|
public void Deserialize(NetDataReader reader) {
|
||||||
pid = reader.GetInt();
|
Pid = reader.GetInt();
|
||||||
camera = reader.GetInt();
|
Camera = reader.GetInt();
|
||||||
monitorUp = reader.GetBool();
|
MonitorUp = reader.GetBool();
|
||||||
doorStates = reader.GetBoolArray();
|
DoorStates = reader.GetBoolArray();
|
||||||
officeTileId = reader.GetInt();
|
OfficeTileId = reader.GetInt();
|
||||||
neighbouringTiles = reader.GetIntArray();
|
NeighbouringTiles = reader.GetIntArray();
|
||||||
power = reader.GetInt();
|
Power = reader.GetInt();
|
||||||
poweredOut = reader.GetBool();
|
PoweredOut = reader.GetBool();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,5 @@
|
||||||
namespace PacketLib;
|
namespace PacketLib;
|
||||||
|
|
||||||
public class UpdatePlayerPacket {
|
public class UpdatePlayerPacket {
|
||||||
// public PlayerState stateP1{ get; set; }
|
public GameEvent[] Events { get; set; }
|
||||||
// public PlayerState stateP2{ get; set; }
|
|
||||||
|
|
||||||
// TODO: implement anti-desync measures by comparing server and client states
|
|
||||||
|
|
||||||
public GameEvent[] events { get; set; }
|
|
||||||
// public EventQueue eventQueue { get; set; }
|
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue