* Completely refactor how job spawning works * Remove remains of old system. * Squash the final bug, cleanup. * Attempt to fix tests * Adjusts packed's round-start crew roster, re-enables a bunch of old roles. Also adds the Central Command Official as a proper role. * pretty up ui * refactor StationSystem into the correct folder & namespace. * remove a log, make sure the lobby gets updated if a new map is spontaneously added. * re-add accidentally removed log * We do a little logging * we do a little resolving * we do a little documenting * Renamed OverflowJob to FallbackOverflowJob Allows stations to configure their own roundstart overflow job list. * narrator: it did not compile * oops * support having no overflow jobs * filescope for consistency * small fixes * Bumps a few role counts for Packed, namely engis * log moment * E * Update Resources/Prototypes/Entities/Objects/Misc/identification_cards.yml Co-authored-by: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com> * Update Content.Server/Maps/GameMapPrototype.cs Co-authored-by: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com> * factored job logic, cleanup. * e * Address reviews * Remove the concept of a "default" grid. It has no future in our new multi-station world * why was clickable using that in the first place * fix bad evil bug that almost slipped through also adds chemist * rms obsolete things from chemist * Adds a sanity fallback * address reviews * adds ability to set name * fuck * cleanup joingame
119 lines
3.6 KiB
C#
119 lines
3.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
using System.Linq;
|
|
using Content.Server.Chat.Managers;
|
|
using Content.Shared.CCVar;
|
|
using Robust.Server.Player;
|
|
using Robust.Shared.Configuration;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.Localization;
|
|
using Robust.Shared.Prototypes;
|
|
using Robust.Shared.Random;
|
|
|
|
namespace Content.Server.Maps;
|
|
|
|
public class GameMapManager : IGameMapManager
|
|
{
|
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
|
[Dependency] private readonly IConfigurationManager _configurationManager = default!;
|
|
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
|
[Dependency] private readonly IRobustRandom _random = default!;
|
|
[Dependency] private readonly IChatManager _chatManager = default!;
|
|
|
|
private GameMapPrototype _currentMap = default!;
|
|
private bool _currentMapForced;
|
|
|
|
public void Initialize()
|
|
{
|
|
_configurationManager.OnValueChanged(CCVars.GameMap, value =>
|
|
{
|
|
if (TryLookupMap(value, out var map))
|
|
_currentMap = map;
|
|
else
|
|
throw new ArgumentException($"Unknown map prototype {value} was selected!");
|
|
}, true);
|
|
_configurationManager.OnValueChanged(CCVars.GameMapForced, value => _currentMapForced = value, true);
|
|
}
|
|
|
|
public IEnumerable<GameMapPrototype> CurrentlyEligibleMaps()
|
|
{
|
|
var maps = AllVotableMaps().Where(IsMapEligible).ToArray();
|
|
|
|
return maps.Length == 0 ? AllMaps().Where(x => x.Fallback) : maps;
|
|
}
|
|
|
|
public IEnumerable<GameMapPrototype> AllVotableMaps()
|
|
{
|
|
return _prototypeManager.EnumeratePrototypes<GameMapPrototype>().Where(x => x.Votable);
|
|
}
|
|
|
|
public IEnumerable<GameMapPrototype> AllMaps()
|
|
{
|
|
return _prototypeManager.EnumeratePrototypes<GameMapPrototype>();
|
|
}
|
|
|
|
public bool TrySelectMap(string gameMap)
|
|
{
|
|
if (!TryLookupMap(gameMap, out var map) || !IsMapEligible(map)) return false;
|
|
|
|
_currentMap = map;
|
|
_currentMapForced = false;
|
|
return true;
|
|
|
|
}
|
|
|
|
public void ForceSelectMap(string gameMap)
|
|
{
|
|
if (!TryLookupMap(gameMap, out var map))
|
|
throw new ArgumentException($"The map \"{gameMap}\" is invalid!");
|
|
_currentMap = map;
|
|
_currentMapForced = true;
|
|
}
|
|
|
|
public void SelectRandomMap()
|
|
{
|
|
var maps = CurrentlyEligibleMaps().ToList();
|
|
_random.Shuffle(maps);
|
|
_currentMap = maps[0];
|
|
_currentMapForced = false;
|
|
}
|
|
|
|
public GameMapPrototype GetSelectedMap()
|
|
{
|
|
return _currentMap;
|
|
}
|
|
|
|
public GameMapPrototype GetSelectedMapChecked(bool loud = false)
|
|
{
|
|
if (!_currentMapForced && !IsMapEligible(GetSelectedMap()))
|
|
{
|
|
var oldMap = GetSelectedMap().MapName;
|
|
SelectRandomMap();
|
|
if (loud)
|
|
{
|
|
_chatManager.DispatchServerAnnouncement(
|
|
Loc.GetString("gamemap-could-not-use-map-error",
|
|
("oldMap", oldMap), ("newMap", GetSelectedMap().MapName)
|
|
));
|
|
}
|
|
}
|
|
|
|
return GetSelectedMap();
|
|
}
|
|
|
|
public bool CheckMapExists(string gameMap)
|
|
{
|
|
return TryLookupMap(gameMap, out _);
|
|
}
|
|
|
|
private bool IsMapEligible(GameMapPrototype map)
|
|
{
|
|
return map.MaxPlayers >= _playerManager.PlayerCount && map.MinPlayers <= _playerManager.PlayerCount;
|
|
}
|
|
|
|
private bool TryLookupMap(string gameMap, [NotNullWhen(true)] out GameMapPrototype? map)
|
|
{
|
|
return _prototypeManager.TryIndex(gameMap, out map);
|
|
}
|
|
} |