From 8742f9eb5525a58bb33f0f06589f6ac7b0f2f48c Mon Sep 17 00:00:00 2001 From: Perry Date: Sun, 29 Mar 2026 18:15:32 +0200 Subject: [PATCH] =?UTF-8?q?Spr=C3=A1vn=C3=A9=20vypnut=C3=AD=20serveru=20v?= =?UTF-8?q?=20p=C5=99=C3=ADpad=C4=9B=20crashe=20z=20d=C5=AFvodu=20obsazen?= =?UTF-8?q?=C3=A9ho=20portu,=20soubor=20na=20nastaven=C3=AD=20rozli=C5=A1e?= =?UTF-8?q?n=C3=AD,=20odstran=C4=9Bn=C3=AD=20nepou=C5=BE=C3=ADvan=C3=A9=20?= =?UTF-8?q?metody=20Enemy.SilentSpawn=20a=20implementace=20metody=20SoundM?= =?UTF-8?q?anager.GetRandomisedPitchInstance?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ONDClient/GameMain.cs | 2 +- ONDClient/Net/EventProcessor.cs | 2 +- ONDClient/ONDClient.csproj | 13 ++++++------ ONDClient/Program.cs | 5 ++++- ONDClient/Sound/SoundManager.cs | 33 +++++++++++++++---------------- ONDClient/settings/resolution.txt | 8 ++++++++ ONDServer/Enemies/Enemy.cs | 6 ------ ONDServer/GameLogic.cs | 4 ---- ONDServer/Net/Server.cs | 6 ++++-- ONDServer/Program.cs | 23 ++++++--------------- 10 files changed, 46 insertions(+), 56 deletions(-) create mode 100644 ONDClient/settings/resolution.txt diff --git a/ONDClient/GameMain.cs b/ONDClient/GameMain.cs index db33396..0df1a6f 100644 --- a/ONDClient/GameMain.cs +++ b/ONDClient/GameMain.cs @@ -9,7 +9,7 @@ using ONDClient.Sound; namespace ONDClient; -public class GameMain() : Core("OND", 1280, 720, false) { +public class GameMain(int width, int height) : Core("OND", width, height, false) { protected override void Initialize() { Exiting += (_, _) => { Client.Disconnect(); diff --git a/ONDClient/Net/EventProcessor.cs b/ONDClient/Net/EventProcessor.cs index 7fc81cd..37d577d 100644 --- a/ONDClient/Net/EventProcessor.cs +++ b/ONDClient/Net/EventProcessor.cs @@ -110,7 +110,7 @@ public static class EventProcessor { 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)); + UIManager.Jumpscare(ClientEnemyManager.Get(enemyId)); SoundManager.PlayJumpscare(); } } diff --git a/ONDClient/ONDClient.csproj b/ONDClient/ONDClient.csproj index d1ad6ea..817fdd8 100644 --- a/ONDClient/ONDClient.csproj +++ b/ONDClient/ONDClient.csproj @@ -43,21 +43,20 @@ link\MonoGameLibrary.dll - - - - - - - + + + Always + Always + + \ No newline at end of file diff --git a/ONDClient/Program.cs b/ONDClient/Program.cs index 265a1de..128f8fd 100644 --- a/ONDClient/Program.cs +++ b/ONDClient/Program.cs @@ -1,5 +1,8 @@ using System; +using System.IO; +using System.Linq; -using var game = new ONDClient.GameMain(); Environment.CurrentDirectory = AppDomain.CurrentDomain.BaseDirectory; +int resMult = int.Parse(File.ReadLines("settings/resolution.txt").First()); +using var game = new ONDClient.GameMain(640 * resMult, 360 * resMult); game.Run(); \ No newline at end of file diff --git a/ONDClient/Sound/SoundManager.cs b/ONDClient/Sound/SoundManager.cs index 550d752..e5f9537 100644 --- a/ONDClient/Sound/SoundManager.cs +++ b/ONDClient/Sound/SoundManager.cs @@ -71,27 +71,27 @@ public static class SoundManager { public static void PlayDoor(bool doorState) { if (doorState){ - doorClose.Play(); + GetRandomisedPitchInstance(doorClose).Play(); } else{ - doorOpen.Play(); + GetRandomisedPitchInstance(doorOpen).Play(); } } public static void PlayDoorRemote(bool doorState) { if (doorState){ - doorCloseRemote.Play(); + GetRandomisedPitchInstance(doorCloseRemote).Play(); } else{ - doorOpenRemote.Play(); + GetRandomisedPitchInstance(doorOpenRemote).Play(); } } public static void PlayLight(bool lightState) { if (lightState){ - lightOn.Play(); + GetRandomisedPitchInstance(lightOn).Play(); } else{ - lightOff.Play(); + GetRandomisedPitchInstance(lightOff).Play(); } } @@ -99,23 +99,23 @@ public static class SoundManager { public static void PlayPowerOut() => powerOut.Play(); - public static void PlayNekoMove() => nekoMove.Play(); + public static void PlayNekoMove() => GetRandomisedPitchInstance(nekoMove).Play(); public static void PlayNekoAnger() => nekoAnger.Play(); - public static void PlaySpotActivate() => spotActivate.Play(); + public static void PlaySpotActivate() => GetRandomisedPitchInstance(spotActivate).Play(); - public static void PlaySpotMove() => spotMove.Play(); + public static void PlaySpotMove() => GetRandomisedPitchInstance(spotMove).Play(); - public static void PlayDashMove() => dashMove.Play(); + public static void PlayDashMove() => GetRandomisedPitchInstance(dashMove).Play(); - public static void PlayMareMove() => mareMove.Play(); + public static void PlayMareMove() => GetRandomisedPitchInstance(mareMove).Play(); - public static void PlayMonitorFlip() => monitorFlip.Play(); + public static void PlayMonitorFlip() => GetRandomisedPitchInstance(monitorFlip).Play(); - public static void PlayCameraSwitch() => camSwitch.Play(); + public static void PlayCameraSwitch() => GetRandomisedPitchInstance(camSwitch).Play(); - public static void PlayVentWalk() => ventWalk.Play(); + public static void PlayVentWalk() => GetRandomisedPitchInstance(ventWalk).Play(); public static void PlayBell() => bell.Play(); @@ -126,10 +126,9 @@ public static class SoundManager { } public static void StopNekoPurr() { - nekoPurrInstance.Stop(); + nekoPurrInstance?.Stop(); } - - // unused + private static SoundEffectInstance GetRandomisedPitchInstance(SoundEffect effect) { SoundEffectInstance instance = effect.CreateInstance(); instance.Pitch = (float)(random.NextDouble() - 0.5) / 5; diff --git a/ONDClient/settings/resolution.txt b/ONDClient/settings/resolution.txt new file mode 100644 index 0000000..83c7578 --- /dev/null +++ b/ONDClient/settings/resolution.txt @@ -0,0 +1,8 @@ +2 + +# 1 - 640x360 +# 2 (default) - 1280x720 +# 3 - 1920x1080 (Full HD) +# 4 - 2560x1440 (QHD) +# 5 - 3200x1800 +# 6 - 3840x2160 (4K) \ No newline at end of file diff --git a/ONDServer/Enemies/Enemy.cs b/ONDServer/Enemies/Enemy.cs index 5d37158..2e08175 100644 --- a/ONDServer/Enemies/Enemy.cs +++ b/ONDServer/Enemies/Enemy.cs @@ -16,12 +16,6 @@ public abstract class Enemy : GlobalEnemy { MovementOpportunity = new(movementInterval); SetDifficulty(difficulty); } - - // unused - public virtual void SpawnSilent(MapTile location) { - Console.WriteLine($"!!! Silent spawn not implemented for enemy {Type} ({Name}), reverting to regular spawn"); - Spawn(location); - } public override void Spawn(MapTile location) { base.Spawn(location); diff --git a/ONDServer/GameLogic.cs b/ONDServer/GameLogic.cs index 2735746..ba9a7e6 100644 --- a/ONDServer/GameLogic.cs +++ b/ONDServer/GameLogic.cs @@ -122,10 +122,6 @@ public static class GameLogic { } Thread.Sleep(1000); Server.Stop(); - - if (!Server.AutoStop){ - Program.Restart(); - } } private static (int p1Usage, int p2Usage) CalculatePowerUsage() { diff --git a/ONDServer/Net/Server.cs b/ONDServer/Net/Server.cs index 5aa8308..65906ee 100644 --- a/ONDServer/Net/Server.cs +++ b/ONDServer/Net/Server.cs @@ -12,8 +12,6 @@ public static class Server { public static readonly Dictionary Players = new(); public static ServerPlayer OtherPlayer(ServerPlayer player) => player.State.Pid == P1.State.Pid ? P2 : P1; - public static bool AutoStop{ get; set; } = true; - private static EventBasedNetListener listener; private static NetManager server; @@ -61,6 +59,10 @@ public static class Server { listener.PeerDisconnectedEvent += OnPeerDisconnected; server.Start(port); + if (!server.IsRunning){ + Stop(); + return; + } Run(); } diff --git a/ONDServer/Program.cs b/ONDServer/Program.cs index da43b22..3edb8c4 100644 --- a/ONDServer/Program.cs +++ b/ONDServer/Program.cs @@ -1,19 +1,8 @@ -using System.Diagnostics; -using ONDServer.Net; +using ONDServer.Net; -namespace ONDServer; - -public static class Program { - public static void Main(string[] args) { - if (args.Contains("--persistent")){ - Server.AutoStop = false; - } - Server.Start(9012); - } - - public static void Restart() { - Console.WriteLine("Game concluded -> restarting server"); - Process.Start(new ProcessStartInfo{ FileName = Environment.ProcessPath, UseShellExecute = false }); - Environment.Exit(0); - } +try{ + Server.Start(9012); +} +finally{ + Server.Stop(); } \ No newline at end of file