Power - spotřebovává se když jsou zavřené dveře. Hráči mohou zavírat pouze dveře na svojí polovině mapy. Oprava bugu v MovementOpportunity, který způsoboval zpožďování intervalu.

This commit is contained in:
Perry 2026-03-12 22:33:35 +01:00
parent 7656707177
commit 25a62af483
22 changed files with 240 additions and 59 deletions

View file

@ -4,6 +4,9 @@ namespace FNAF_Server.Map;
public static class MapManager {
private static MapTile[,] map = new MapTile[5, 5];
private static List<TileConnector> doors = new();
private static List<TileConnector> doorsP1 = new();
private static List<TileConnector> doorsP2 = new();
public static MapTile Get((int x, int y) coords) => map[coords.x, coords.y];
public static MapTile Get(int tileId) => Get(IdToCoords(tileId));
@ -27,14 +30,14 @@ public static class MapManager {
[(3,2)] = [(4,2,1)]
};
public static void InitMap() { // TODO: make map size not hardcoded
public static void InitMap() {
for (int i = 0; i < 5; i++){
for (int j = 0; j < 2; j++){
map[i, j] = new MapTile(CoordsToId(i, j), null); // TODO: implement ownership
map[i, j] = new MapTile(CoordsToId(i, j)){Owner = Server.P1};
}
map[i, 2] = new MapTile(CoordsToId(i, 2), null);
map[i, 2] = new MapTile(CoordsToId(i, 2));
for (int j = 3; j < 5; j++){
map[i, j] = new MapTile(CoordsToId(i, j), null);
map[i, j] = new MapTile(CoordsToId(i, j)){Owner = Server.P2};
}
}
@ -44,12 +47,15 @@ public static class MapManager {
}
foreach (var con in halfConnectors){
map[con.Key.x1, con.Key.y1].AddConnectors(con.Value.Select(c => new TileConnector(map[c.x2, c.y2], c.type, c.value)).ToArray());
map[con.Key.x1, con.Key.y1].AddConnectors(con.Value.Select(c => new TileConnector(map[c.x2, c.y2], c.type, c.value){Owner = Server.P1}).ToArray());
}
foreach (var con in halfConnectors){
map[4 - con.Key.x1, 4 - con.Key.y1].AddConnectors(con.Value.Select(c => new TileConnector(map[4 - c.x2, 4 - c.y2], c.type, c.value)).ToArray());
map[4 - con.Key.x1, 4 - con.Key.y1].AddConnectors(con.Value.Select(c => new TileConnector(map[4 - c.x2, 4 - c.y2], c.type, c.value){Owner = Server.P2}).ToArray());
}
doors = GetAllConnectors().Where(c => c.Type == ConnectorType.DOOR_OFFICE || c.Type == ConnectorType.DOOR_REMOTE).ToList();
doorsP1 = doors.Where(c => c.Owner == Server.P1).ToList();
doorsP2 = doors.Where(c => c.Owner == Server.P2).ToList();
}
public static TileConnector[] GetAllConnectors() {
@ -72,4 +78,7 @@ public static class MapManager {
public const int ID_X_OFFSET = 5; // map grid height
public static int CoordsToId(int x, int y) => x * ID_X_OFFSET + y;
public static (int, int) IdToCoords(int id) => (id / ID_X_OFFSET, id % ID_X_OFFSET);
public static TileConnector[] GetDoors() => doors.ToArray();
public static TileConnector[] GetDoors(ServerPlayer player) => player == Server.P1 ? doorsP1.ToArray() : doorsP2.ToArray();
}

View file

@ -4,10 +4,9 @@ using GlobalClassLib;
namespace FNAF_Server.Map;
public class MapTile : GlobalMapTile<TileConnector, MapTile> {
public ServerPlayer Owner{ get; private set; }
public ServerPlayer? Owner{ get; set; }
public MapTile(int id, ServerPlayer owner) : base(id, MapManager.IdToCoords(id)) {
Owner = owner;
public MapTile(int id) : base(id, MapManager.IdToCoords(id)) {
}
// public int Id { get; private set; }

View file

@ -4,6 +4,7 @@ namespace FNAF_Server.Map;
public class TileConnector : GlobalTileConnector<MapTile,TileConnector> {
public int Value{ get; set; }
public ServerPlayer? Owner{ get; set; }
public TileConnector(MapTile tile1, MapTile tile2, ConnectorType type, int value) : base(tile1, tile2, type) {
Value = value;
}
@ -40,5 +41,5 @@ public class TileConnector : GlobalTileConnector<MapTile,TileConnector> {
// VENT
// }
public override TileConnector Clone() => new(Tiles.tile1, Tiles.tile2, Type, Value);
public override TileConnector Clone() => new(Tiles.tile1, Tiles.tile2, Type, Value){Owner = Owner};
}