Refactor how jobs are handed out (#5422)
* 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
This commit is contained in:
@@ -11,110 +11,109 @@ using Robust.Shared.Localization;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Random;
|
||||
|
||||
namespace Content.Server.Maps
|
||||
namespace Content.Server.Maps;
|
||||
|
||||
public class GameMapManager : IGameMapManager
|
||||
{
|
||||
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()
|
||||
{
|
||||
[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 =>
|
||||
{
|
||||
_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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,53 +1,70 @@
|
||||
using System.Collections.Generic;
|
||||
using Content.Shared.Roles;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Dictionary;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.Maps
|
||||
namespace Content.Server.Maps;
|
||||
|
||||
/// <summary>
|
||||
/// Prototype data for a game map.
|
||||
/// </summary>
|
||||
[Prototype("gameMap")]
|
||||
public class GameMapPrototype : IPrototype
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
[DataField("id", required: true)]
|
||||
public string ID { get; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// Prototype data for a game map.
|
||||
/// Minimum players for the given map.
|
||||
/// </summary>
|
||||
[Prototype("gameMap")]
|
||||
public class GameMapPrototype : IPrototype
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
[ViewVariables, DataField("id", required: true)]
|
||||
public string ID { get; } = default!;
|
||||
[DataField("minPlayers", required: true)]
|
||||
public uint MinPlayers { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Minimum players for the given map.
|
||||
/// </summary>
|
||||
[ViewVariables, DataField("minPlayers", required: true)]
|
||||
public uint MinPlayers { get; }
|
||||
/// <summary>
|
||||
/// Maximum players for the given map.
|
||||
/// </summary>
|
||||
[DataField("maxPlayers")]
|
||||
public uint MaxPlayers { get; } = uint.MaxValue;
|
||||
|
||||
/// <summary>
|
||||
/// Maximum players for the given map.
|
||||
/// </summary>
|
||||
[ViewVariables, DataField("maxPlayers")]
|
||||
public uint MaxPlayers { get; } = uint.MaxValue;
|
||||
/// <summary>
|
||||
/// Name of the given map.
|
||||
/// </summary>
|
||||
[DataField("mapName", required: true)]
|
||||
public string MapName { get; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// Name of the given map.
|
||||
/// </summary>
|
||||
[ViewVariables, DataField("mapName", required: true)]
|
||||
public string MapName { get; } = default!;
|
||||
/// <summary>
|
||||
/// Relative directory path to the given map, i.e. `Maps/saltern.yml`
|
||||
/// </summary>
|
||||
[DataField("mapPath", required: true)]
|
||||
public string MapPath { get; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// Relative directory path to the given map, i.e. `Maps/saltern.yml`
|
||||
/// </summary>
|
||||
[ViewVariables, DataField("mapPath", required: true)]
|
||||
public string MapPath { get; } = default!;
|
||||
/// <summary>
|
||||
/// Controls if the map can be used as a fallback if no maps are eligible.
|
||||
/// </summary>
|
||||
[DataField("fallback")]
|
||||
public bool Fallback { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Controls if the map can be used as a fallback if no maps are eligible.
|
||||
/// </summary>
|
||||
[ViewVariables, DataField("fallback")]
|
||||
public bool Fallback { get; }
|
||||
/// <summary>
|
||||
/// Controls if the map can be voted for.
|
||||
/// </summary>
|
||||
[DataField("votable")]
|
||||
public bool Votable { get; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Controls if the map can be voted for.
|
||||
/// </summary>
|
||||
[ViewVariables, DataField("votable")]
|
||||
public bool Votable { get; } = true;
|
||||
}
|
||||
/// <summary>
|
||||
/// Jobs used at round start should the station run out of job slots.
|
||||
/// Doesn't necessarily mean the station has infinite slots for the given jobs midround!
|
||||
/// </summary>
|
||||
[DataField("overflowJobs", required: true, customTypeSerializer:typeof(PrototypeIdListSerializer<JobPrototype>))]
|
||||
public List<string> OverflowJobs { get; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// Index of all jobs available on the station, of form
|
||||
/// jobname: [roundstart, midround]
|
||||
/// </summary>
|
||||
[DataField("availableJobs", required: true, customTypeSerializer:typeof(PrototypeIdDictionarySerializer<List<int>, JobPrototype>))]
|
||||
public Dictionary<string, List<int>> AvailableJobs { get; } = default!;
|
||||
}
|
||||
|
||||
@@ -1,68 +1,67 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Content.Server.Maps
|
||||
namespace Content.Server.Maps;
|
||||
|
||||
/// <summary>
|
||||
/// Manages which station map will be used for the next round.
|
||||
/// </summary>
|
||||
public interface IGameMapManager
|
||||
{
|
||||
void Initialize();
|
||||
|
||||
/// <summary>
|
||||
/// Manages which station map will be used for the next round.
|
||||
/// Returns all maps eligible to be played right now.
|
||||
/// </summary>
|
||||
public interface IGameMapManager
|
||||
{
|
||||
void Initialize();
|
||||
/// <returns>enumerator of map prototypes</returns>
|
||||
IEnumerable<GameMapPrototype> CurrentlyEligibleMaps();
|
||||
|
||||
/// <summary>
|
||||
/// Returns all maps eligible to be played right now.
|
||||
/// </summary>
|
||||
/// <returns>enumerator of map prototypes</returns>
|
||||
IEnumerable<GameMapPrototype> CurrentlyEligibleMaps();
|
||||
/// <summary>
|
||||
/// Returns all maps that can be voted for.
|
||||
/// </summary>
|
||||
/// <returns>enumerator of map prototypes</returns>
|
||||
IEnumerable<GameMapPrototype> AllVotableMaps();
|
||||
|
||||
/// <summary>
|
||||
/// Returns all maps that can be voted for.
|
||||
/// </summary>
|
||||
/// <returns>enumerator of map prototypes</returns>
|
||||
IEnumerable<GameMapPrototype> AllVotableMaps();
|
||||
/// <summary>
|
||||
/// Returns all maps.
|
||||
/// </summary>
|
||||
/// <returns>enumerator of map prototypes</returns>
|
||||
IEnumerable<GameMapPrototype> AllMaps();
|
||||
|
||||
/// <summary>
|
||||
/// Returns all maps.
|
||||
/// </summary>
|
||||
/// <returns>enumerator of map prototypes</returns>
|
||||
IEnumerable<GameMapPrototype> AllMaps();
|
||||
/// <summary>
|
||||
/// Attempts to select the given map.
|
||||
/// </summary>
|
||||
/// <param name="gameMap">map prototype</param>
|
||||
/// <returns>success or failure</returns>
|
||||
bool TrySelectMap(string gameMap);
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to select the given map.
|
||||
/// </summary>
|
||||
/// <param name="gameMap">map prototype</param>
|
||||
/// <returns>success or failure</returns>
|
||||
bool TrySelectMap(string gameMap);
|
||||
/// <summary>
|
||||
/// Forces the given map, making sure the game map manager won't reselect if conditions are no longer met at round restart.
|
||||
/// </summary>
|
||||
/// <param name="gameMap">map prototype</param>
|
||||
/// <returns>success or failure</returns>
|
||||
void ForceSelectMap(string gameMap);
|
||||
|
||||
/// <summary>
|
||||
/// Forces the given map, making sure the game map manager won't reselect if conditions are no longer met at round restart.
|
||||
/// </summary>
|
||||
/// <param name="gameMap">map prototype</param>
|
||||
/// <returns>success or failure</returns>
|
||||
void ForceSelectMap(string gameMap);
|
||||
/// <summary>
|
||||
/// Selects a random map.
|
||||
/// </summary>
|
||||
void SelectRandomMap();
|
||||
|
||||
/// <summary>
|
||||
/// Selects a random map.
|
||||
/// </summary>
|
||||
void SelectRandomMap();
|
||||
/// <summary>
|
||||
/// Gets the currently selected map, without double-checking if it can be used.
|
||||
/// </summary>
|
||||
/// <returns>selected map</returns>
|
||||
GameMapPrototype GetSelectedMap();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the currently selected map, without double-checking if it can be used.
|
||||
/// </summary>
|
||||
/// <returns>selected map</returns>
|
||||
GameMapPrototype GetSelectedMap();
|
||||
/// <summary>
|
||||
/// Gets the currently selected map, double-checking if it can be used.
|
||||
/// </summary>
|
||||
/// <returns>selected map</returns>
|
||||
GameMapPrototype GetSelectedMapChecked(bool loud = false);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the currently selected map, double-checking if it can be used.
|
||||
/// </summary>
|
||||
/// <returns>selected map</returns>
|
||||
GameMapPrototype GetSelectedMapChecked(bool loud = false);
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the given map exists
|
||||
/// </summary>
|
||||
/// <param name="gameMap">name of the map</param>
|
||||
/// <returns>existence</returns>
|
||||
bool CheckMapExists(string gameMap);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Checks if the given map exists
|
||||
/// </summary>
|
||||
/// <param name="gameMap">name of the map</param>
|
||||
/// <returns>existence</returns>
|
||||
bool CheckMapExists(string gameMap);
|
||||
}
|
||||
Reference in New Issue
Block a user