2026-03-08 16:55:49 +01:00
|
|
|
using System.Diagnostics;
|
|
|
|
|
using FNAF_Server.Enemies;
|
2026-02-01 14:53:27 +01:00
|
|
|
using FNAF_Server.Map;
|
2026-02-14 14:35:29 +01:00
|
|
|
using GlobalClassLib;
|
2025-12-19 17:54:50 +01:00
|
|
|
using PacketLib;
|
|
|
|
|
|
|
|
|
|
namespace FNAF_Server;
|
|
|
|
|
|
|
|
|
|
public class GameLogic {
|
|
|
|
|
|
2026-02-26 16:24:55 +01:00
|
|
|
public const int START_CAMERA = 12;
|
2026-03-08 16:55:49 +01:00
|
|
|
|
|
|
|
|
private static MovementOpportunity secondCycleTimer = new(1000);
|
|
|
|
|
public static bool NSecondUpdate{ get; private set; } = false;
|
2026-02-26 16:24:55 +01:00
|
|
|
|
2026-03-08 16:55:49 +01:00
|
|
|
public static MapTile P1Office;
|
|
|
|
|
public static MapTile P2Office;
|
|
|
|
|
public static MapTile[] Offices =>[P1Office, P2Office];
|
|
|
|
|
|
2026-02-01 14:53:27 +01:00
|
|
|
public static void Init() {
|
2026-02-14 14:35:29 +01:00
|
|
|
// Create map
|
2026-02-01 14:53:27 +01:00
|
|
|
MapManager.InitMap();
|
2026-03-08 16:55:49 +01:00
|
|
|
P1Office = MapManager.Get(10);
|
|
|
|
|
P2Office = MapManager.Get(14);
|
2026-02-14 14:35:29 +01:00
|
|
|
|
|
|
|
|
//Send map to client
|
|
|
|
|
TileConnector[] connectors = MapManager.GetAllConnectors();
|
|
|
|
|
int[] connectorsConverted = new int[connectors.Length * 3];
|
|
|
|
|
for (int i = 0; i < connectors.Length; i++){
|
|
|
|
|
connectorsConverted[i * 3] = connectors[i].Tiles.tile1.Id;
|
|
|
|
|
connectorsConverted[i * 3 + 1] = connectors[i].Tiles.tile2.Id;
|
|
|
|
|
connectorsConverted[i * 3 + 2] = (int)connectors[i].Type;
|
|
|
|
|
}
|
2026-03-08 16:55:49 +01:00
|
|
|
Server.SendPacket(new MapInitPacket{Connectors = connectorsConverted, UpsideDown = false}, Server.P1.peer);
|
|
|
|
|
Server.SendPacket(new MapInitPacket{Connectors = connectorsConverted, UpsideDown = true}, Server.P2.peer);
|
|
|
|
|
|
2026-03-11 22:35:30 +01:00
|
|
|
EnemyManager.AddEnemy(new LurkEnemy(0)).Spawn(MapManager.Get(12));
|
2026-03-09 20:05:21 +01:00
|
|
|
EnemyManager.AddEnemy(new NekoEnemy(0)).Spawn(MapManager.Get(2));
|
2026-03-11 22:35:30 +01:00
|
|
|
EnemyManager.AddEnemy(new SpotEnemy(10)).Spawn(MapManager.Get(12));
|
2026-02-14 14:35:29 +01:00
|
|
|
|
2026-03-11 22:35:30 +01:00
|
|
|
Thread.Sleep(3000);
|
2026-03-08 16:55:49 +01:00
|
|
|
secondCycleTimer.Start();
|
2026-03-11 22:35:30 +01:00
|
|
|
Server.SendUpdateToAll([GameEvent.GAME_START()]);
|
2026-02-01 14:53:27 +01:00
|
|
|
}
|
2025-12-19 17:54:50 +01:00
|
|
|
public static void Update() {
|
2026-03-08 16:55:49 +01:00
|
|
|
if(secondCycleTimer.Check()) NSecondUpdate = true;
|
2025-12-19 17:54:50 +01:00
|
|
|
|
2026-03-08 16:55:49 +01:00
|
|
|
EnemyManager.Update();
|
|
|
|
|
|
|
|
|
|
NSecondUpdate = false;
|
2025-12-19 17:54:50 +01:00
|
|
|
}
|
2026-03-09 20:05:21 +01:00
|
|
|
|
|
|
|
|
public static void DeclareWinner(ServerPlayer player) {
|
|
|
|
|
Server.SendUpdateToAll([GameEvent.PLAYER_WIN(player.state.pid)]);
|
|
|
|
|
Server.Stop();
|
|
|
|
|
Console.WriteLine("Player " + player.state.pid + " won!");
|
|
|
|
|
}
|
2025-12-19 17:54:50 +01:00
|
|
|
}
|