2026-02-14 14:35:29 +01:00
|
|
|
using GlobalClassLib;
|
|
|
|
|
|
2026-02-01 14:53:27 +01:00
|
|
|
namespace FNAF_Server.Map;
|
|
|
|
|
|
|
|
|
|
public static class MapManager {
|
|
|
|
|
private static MapTile[,] map = new MapTile[5, 5];
|
2026-02-21 18:42:44 +01:00
|
|
|
|
|
|
|
|
public static MapTile Get((int x, int y) coords) => map[coords.x, coords.y];
|
|
|
|
|
public static MapTile Get(int tileId) => Get(MapTile.IdToCoords(tileId));
|
|
|
|
|
|
2026-02-01 14:53:27 +01:00
|
|
|
|
2026-02-14 14:35:29 +01:00
|
|
|
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)],
|
|
|
|
|
[(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)],
|
|
|
|
|
[(4, 0)] =[(4, 1, 1, ConnectorType.DOOR_REMOTE)],
|
|
|
|
|
[(0, 1)] =[(1, 1, 1, ConnectorType.HALL)],
|
|
|
|
|
[(1, 1)] =[(1, 2, 1, ConnectorType.DOOR_REMOTE)],
|
|
|
|
|
[(2, 1)] =[(2, 2, 1, ConnectorType.HALL), (2, 0, 1, ConnectorType.DOOR_OFFICE)],
|
|
|
|
|
[(3, 1)] =[(3, 2, 1, ConnectorType.DOOR_REMOTE), (4, 1, 1, ConnectorType.HALL)]
|
2026-02-01 14:53:27 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private static Dictionary<(int x1, int y1), (int x2, int y2, int value)[]> mainHallwayConnectors = new(){
|
|
|
|
|
[(0,2)] = [(1,2,1)],
|
|
|
|
|
[(1,2)] = [(2,2,1)],
|
|
|
|
|
[(2,2)] = [(3,2,1)],
|
|
|
|
|
[(3,2)] = [(4,2,1)]
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public static void InitMap() { // TODO: make map size not hardcoded
|
|
|
|
|
for (int i = 0; i < 5; i++){
|
|
|
|
|
for (int j = 0; j < 2; j++){
|
2026-02-14 14:35:29 +01:00
|
|
|
map[i, j] = new MapTile(MapTile.CoordsToId(i, j), null); // TODO: implement ownership
|
2026-02-01 14:53:27 +01:00
|
|
|
}
|
2026-02-14 14:35:29 +01:00
|
|
|
map[i, 2] = new MapTile(MapTile.CoordsToId(i, 2), null);
|
2026-02-01 14:53:27 +01:00
|
|
|
for (int j = 3; j < 5; j++){
|
2026-02-14 14:35:29 +01:00
|
|
|
map[i, j] = new MapTile(MapTile.CoordsToId(i, j), null);
|
2026-02-01 14:53:27 +01:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var con in mainHallwayConnectors){
|
2026-02-14 14:35:29 +01:00
|
|
|
map[con.Key.x1, con.Key.y1].AddConnectors(con.Value.Select(c => new TileConnector(map[c.x2, c.y2], ConnectorType.HALL, c.value)).ToArray());
|
2026-02-01 14:53:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var con in halfConnectors){
|
2026-02-14 14:35:29 +01:00
|
|
|
map[con.Key.x1, con.Key.y1].AddConnectors(con.Value.Select(c => new TileConnector(map[c.x2, c.y2], c.type, c.value)).ToArray());
|
2026-02-01 14:53:27 +01:00
|
|
|
}
|
|
|
|
|
foreach (var con in halfConnectors){
|
2026-02-14 14:35:29 +01:00
|
|
|
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());
|
2026-02-01 14:53:27 +01:00
|
|
|
}
|
2026-02-14 14:35:29 +01:00
|
|
|
|
2026-02-01 14:53:27 +01:00
|
|
|
}
|
2026-02-14 14:35:29 +01:00
|
|
|
|
|
|
|
|
public static TileConnector[] GetAllConnectors() {
|
|
|
|
|
List<TileConnector> connectors = new();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 5; i++){
|
|
|
|
|
for (int j = 0; j < 5; j++){
|
2026-02-21 18:42:44 +01:00
|
|
|
MapTile tile = map[i, j];
|
|
|
|
|
Array.ForEach(tile.GetAllConnectors(), c => {
|
|
|
|
|
if(tile.Id < c.OtherTile(tile).Id)
|
2026-02-14 14:35:29 +01:00
|
|
|
connectors.Add(c);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return connectors.ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2026-02-01 14:53:27 +01:00
|
|
|
}
|