Správné vypnutí serveru v případě crashe z důvodu obsazeného portu, soubor na nastavení rozlišení, odstranění nepoužívané metody Enemy.SilentSpawn a implementace metody SoundManager.GetRandomisedPitchInstance

This commit is contained in:
Perry 2026-03-29 18:15:32 +02:00
parent 243f071a43
commit 8742f9eb55
10 changed files with 46 additions and 56 deletions

View file

@ -9,7 +9,7 @@ using ONDClient.Sound;
namespace ONDClient; 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() { protected override void Initialize() {
Exiting += (_, _) => { Exiting += (_, _) => {
Client.Disconnect(); Client.Disconnect();

View file

@ -110,7 +110,7 @@ public static class EventProcessor {
private static void EnemyAttack(int enemyId, int pid) { private static void EnemyAttack(int enemyId, int pid) {
Console.WriteLine($"E: Enemy {enemyId} attacked player {pid}"); Console.WriteLine($"E: Enemy {enemyId} attacked player {pid}");
if (pid == Client.Player.State.Pid) { if (pid == Client.Player.State.Pid) {
UIManager.Jumpscare(ClientEnemyManager.Get(pid)); UIManager.Jumpscare(ClientEnemyManager.Get(enemyId));
SoundManager.PlayJumpscare(); SoundManager.PlayJumpscare();
} }
} }

View file

@ -43,21 +43,20 @@
<Reference Include="MonoGameLibrary"> <Reference Include="MonoGameLibrary">
<HintPath>link\MonoGameLibrary.dll</HintPath> <HintPath>link\MonoGameLibrary.dll</HintPath>
</Reference> </Reference>
<!-- <Reference Include="FNAF_Server">-->
<!-- <HintPath>link\FNAF_Server.dll</HintPath>-->
<!-- </Reference>-->
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\GlobalClassLib\GlobalClassLib.csproj" /> <ProjectReference Include="..\GlobalClassLib\GlobalClassLib.csproj" />
<ProjectReference Include="..\PacketLib\PacketLib.csproj" /> <ProjectReference Include="..\PacketLib\PacketLib.csproj" />
<!-- <ProjectReference Include="..\FNAF_Server\FNAF_Server.csproj" />-->
</ItemGroup> </ItemGroup>
<ItemGroup>
<Compile Remove="Input\**" />
</ItemGroup>
<Target Name="RestoreDotnetTools" BeforeTargets="CollectPackageReferences"> <Target Name="RestoreDotnetTools" BeforeTargets="CollectPackageReferences">
<Message Text="Restoring dotnet tools (this might take a while depending on your internet speed and should only happen upon building your project for the first time, or after upgrading MonoGame, or clearing your nuget cache)" Importance="High"/> <Message Text="Restoring dotnet tools (this might take a while depending on your internet speed and should only happen upon building your project for the first time, or after upgrading MonoGame, or clearing your nuget cache)" Importance="High"/>
<Exec Command="dotnet tool restore"/> <Exec Command="dotnet tool restore"/>
</Target> </Target>
<ItemGroup>
<Content Include="settings\*">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<CopyToPublishDirectory>Always</CopyToPublishDirectory>
</Content>
</ItemGroup>
</Project> </Project>

View file

@ -1,5 +1,8 @@
using System; using System;
using System.IO;
using System.Linq;
using var game = new ONDClient.GameMain();
Environment.CurrentDirectory = AppDomain.CurrentDomain.BaseDirectory; 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(); game.Run();

View file

@ -71,27 +71,27 @@ public static class SoundManager {
public static void PlayDoor(bool doorState) { public static void PlayDoor(bool doorState) {
if (doorState){ if (doorState){
doorClose.Play(); GetRandomisedPitchInstance(doorClose).Play();
} }
else{ else{
doorOpen.Play(); GetRandomisedPitchInstance(doorOpen).Play();
} }
} }
public static void PlayDoorRemote(bool doorState) { public static void PlayDoorRemote(bool doorState) {
if (doorState){ if (doorState){
doorCloseRemote.Play(); GetRandomisedPitchInstance(doorCloseRemote).Play();
} }
else{ else{
doorOpenRemote.Play(); GetRandomisedPitchInstance(doorOpenRemote).Play();
} }
} }
public static void PlayLight(bool lightState) { public static void PlayLight(bool lightState) {
if (lightState){ if (lightState){
lightOn.Play(); GetRandomisedPitchInstance(lightOn).Play();
} }
else{ else{
lightOff.Play(); GetRandomisedPitchInstance(lightOff).Play();
} }
} }
@ -99,23 +99,23 @@ public static class SoundManager {
public static void PlayPowerOut() => powerOut.Play(); 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 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(); public static void PlayBell() => bell.Play();
@ -126,10 +126,9 @@ public static class SoundManager {
} }
public static void StopNekoPurr() { public static void StopNekoPurr() {
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;

View file

@ -0,0 +1,8 @@
2
# 1 - 640x360
# 2 (default) - 1280x720
# 3 - 1920x1080 (Full HD)
# 4 - 2560x1440 (QHD)
# 5 - 3200x1800
# 6 - 3840x2160 (4K)

View file

@ -17,12 +17,6 @@ public abstract class Enemy : GlobalEnemy<MapTile, TileConnector> {
SetDifficulty(difficulty); 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) { public override void Spawn(MapTile location) {
base.Spawn(location); base.Spawn(location);
Spawned = true; Spawned = true;

View file

@ -122,10 +122,6 @@ public static class GameLogic {
} }
Thread.Sleep(1000); Thread.Sleep(1000);
Server.Stop(); Server.Stop();
if (!Server.AutoStop){
Program.Restart();
}
} }
private static (int p1Usage, int p2Usage) CalculatePowerUsage() { private static (int p1Usage, int p2Usage) CalculatePowerUsage() {

View file

@ -12,8 +12,6 @@ public static class Server {
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;
private static EventBasedNetListener listener; private static EventBasedNetListener listener;
private static NetManager server; private static NetManager server;
@ -61,6 +59,10 @@ public static class Server {
listener.PeerDisconnectedEvent += OnPeerDisconnected; listener.PeerDisconnectedEvent += OnPeerDisconnected;
server.Start(port); server.Start(port);
if (!server.IsRunning){
Stop();
return;
}
Run(); Run();
} }

View file

@ -1,19 +1,8 @@
using System.Diagnostics; using ONDServer.Net;
using ONDServer.Net;
namespace ONDServer; try{
Server.Start(9012);
public static class Program { }
public static void Main(string[] args) { finally{
if (args.Contains("--persistent")){ Server.Stop();
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);
}
} }