Лимиты в пуле режимов. Если доступный вариант всего один - голосования не будет. (#2630)
This commit is contained in:
parent
31b1d1e2a7
commit
2c14594a49
5 changed files with 86 additions and 39 deletions
|
|
@ -42,7 +42,7 @@ namespace Content.Server.GameTicking.Commands
|
|||
return;
|
||||
}
|
||||
|
||||
ticker.SetGamePreset(ticker.CurrentPreset, false, rounds);
|
||||
ticker.SetGamePreset(ticker.Preset, false, rounds);
|
||||
shell.WriteLine(Loc.GetString("set-game-preset-preset-set-finite", ("preset", preset.ID), ("rounds", rounds.ToString())));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -230,6 +230,14 @@ namespace Content.Server.Voting.Managers
|
|||
var presets = GetGamePresets();
|
||||
|
||||
// Sunrise-Start
|
||||
if (presets.Count == 1)
|
||||
{
|
||||
var singlePreset = presets.First();
|
||||
var ticker = _entityManager.EntitySysManager.GetEntitySystem<GameTicker>();
|
||||
ticker.SetGamePreset(singlePreset.Key);
|
||||
return;
|
||||
}
|
||||
|
||||
if (presets.Count < 1)
|
||||
return;
|
||||
// Sunrise-End
|
||||
|
|
@ -635,43 +643,54 @@ namespace Content.Server.Voting.Managers
|
|||
var excluded = ticker.ExcludedPresets.ToHashSet();
|
||||
var validPresets = new List<GamePresetPrototype>();
|
||||
var presetPoolId = _cfg.GetCVar(SunriseCCVars.GamePresetPool);
|
||||
HashSet<string>? allowedPresets = null;
|
||||
|
||||
if (_prototypeManager.TryIndex<GamePresetPoolPrototype>(presetPoolId, out var presetPoolProto))
|
||||
allowedPresets = presetPoolProto.Presets;
|
||||
foreach (var preset in _prototypeManager.EnumeratePrototypes<GamePresetPrototype>())
|
||||
{
|
||||
if (allowedPresets != null && !allowedPresets.Contains(preset.ID))
|
||||
continue;
|
||||
if (excluded.Contains(preset.ID))
|
||||
continue;
|
||||
if (!preset.ShowInVote)
|
||||
continue;
|
||||
if (_playerManager.PlayerCount < (preset.MinPlayers ?? int.MinValue))
|
||||
continue;
|
||||
if (_playerManager.PlayerCount > (preset.MaxPlayers ?? int.MaxValue))
|
||||
continue;
|
||||
validPresets.Add(preset);
|
||||
}
|
||||
if (validPresets.Count == 0 && excluded.Count > 0)
|
||||
{
|
||||
ticker.ClearExcludedPresets();
|
||||
foreach (var preset in _prototypeManager.EnumeratePrototypes<GamePresetPrototype>())
|
||||
foreach (var (presetId, limits) in presetPoolProto.Presets)
|
||||
{
|
||||
if (allowedPresets != null && !allowedPresets.Contains(preset.ID))
|
||||
if (excluded.Contains(presetId))
|
||||
continue;
|
||||
|
||||
if (!_prototypeManager.TryIndex<GamePresetPrototype>(presetId, out var preset))
|
||||
continue;
|
||||
|
||||
if (!preset.ShowInVote)
|
||||
continue;
|
||||
if (_playerManager.PlayerCount < (preset.MinPlayers ?? int.MinValue))
|
||||
continue;
|
||||
if (_playerManager.PlayerCount > (preset.MaxPlayers ?? int.MaxValue))
|
||||
|
||||
var minPlayers = limits.Length > 0 ? limits[0] : int.MinValue;
|
||||
var maxPlayers = limits.Length > 1 ? limits[1] : int.MaxValue;
|
||||
|
||||
if (_playerManager.PlayerCount < minPlayers || _playerManager.PlayerCount > maxPlayers)
|
||||
continue;
|
||||
|
||||
validPresets.Add(preset);
|
||||
}
|
||||
|
||||
if (validPresets.Count == 0 && excluded.Count > 0)
|
||||
{
|
||||
ticker.ClearExcludedPresets();
|
||||
foreach (var (presetId, limits) in presetPoolProto.Presets)
|
||||
{
|
||||
if (!_prototypeManager.TryIndex<GamePresetPrototype>(presetId, out var preset))
|
||||
continue;
|
||||
|
||||
if (!preset.ShowInVote)
|
||||
continue;
|
||||
|
||||
var minPlayers = limits.Length > 0 ? limits[0] : int.MinValue;
|
||||
var maxPlayers = limits.Length > 1 ? limits[1] : int.MaxValue;
|
||||
|
||||
if (_playerManager.PlayerCount < minPlayers || _playerManager.PlayerCount > maxPlayers)
|
||||
continue;
|
||||
|
||||
validPresets.Add(preset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (validPresets.Count == 0)
|
||||
{
|
||||
Logger.Warning("Нет подходящих игровых режимов для текущего количества игроков.");
|
||||
Logger.Warning("No suitable game modes for the current player count.");
|
||||
return presets;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
using Content.Server.GameTicking.Presets;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Set;
|
||||
|
||||
namespace Content.Server._Sunrise.Presets;
|
||||
|
||||
|
|
@ -13,8 +11,8 @@ public sealed partial class GamePresetPoolPrototype : IPrototype
|
|||
public string ID { get; private set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// Which presets are in this pool.
|
||||
/// Presets with their respective player limits.
|
||||
/// </summary>
|
||||
[DataField("presets", customTypeSerializer:typeof(PrototypeIdHashSetSerializer<GamePresetPrototype>), required: true)]
|
||||
public HashSet<string> Presets = new(0);
|
||||
[DataField("presets", required: true)]
|
||||
public Dictionary<string, int[]> Presets { get; private set; } = new();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -309,7 +309,7 @@ public sealed partial class SunriseCCVars : CVars
|
|||
CVarDef.Create("game.reset_preset_after_restart", false);
|
||||
|
||||
public static readonly CVarDef<string> GamePresetPool =
|
||||
CVarDef.Create("game.preset_pool", "DefaultPresetPool", CVar.SERVERONLY);
|
||||
CVarDef.Create("game.preset_pool", "DefaultHighPopPresetPool", CVar.SERVERONLY);
|
||||
|
||||
/*
|
||||
* Ban links.
|
||||
|
|
|
|||
|
|
@ -1,14 +1,44 @@
|
|||
# НЕ ТРОГАТЬ БЕЗ МОЕГО РАЗРЕШЕНИЯ!!! SplikZerys
|
||||
- type: gamePresetPool
|
||||
id: DefaultLowPopPresetPool
|
||||
presets:
|
||||
Greenshift: [0, 200]
|
||||
Secret: [30, 200]
|
||||
|
||||
- type: gamePresetPool
|
||||
id: DefaultPresetPool
|
||||
id: DefaultHighPopPresetPool
|
||||
presets:
|
||||
- Greenshift
|
||||
- Secret
|
||||
Greenshift: [0, 200]
|
||||
Secret: [2, 200]
|
||||
|
||||
- type: gamePresetPool
|
||||
id: MiddlePresetPool
|
||||
id: DynamicPresetPool
|
||||
presets:
|
||||
- Greenshift
|
||||
- Secret
|
||||
- Extra
|
||||
Nukeops: [30, 200]
|
||||
Traitor: [5, 200]
|
||||
Zombie: [30, 200]
|
||||
Survival: [5, 200]
|
||||
Revolutionary: [30, 200]
|
||||
Wizard: [30, 200]
|
||||
BloodCult: [30, 200]
|
||||
AssaultOps: [10, 200]
|
||||
FleshCult: [30, 200]
|
||||
|
||||
- type: gamePresetPool
|
||||
id: PeacePresetPool
|
||||
presets:
|
||||
Greenshift: [50, 100]
|
||||
Extra: [50, 100]
|
||||
|
||||
- type: gamePresetPool
|
||||
id: MiddleLowPopPresetPool
|
||||
presets:
|
||||
Greenshift: [0, 200]
|
||||
Secret: [30, 200]
|
||||
Extra: [30, 200]
|
||||
|
||||
- type: gamePresetPool
|
||||
id: MiddleHighPopPresetPool
|
||||
presets:
|
||||
Greenshift: [0, 200]
|
||||
Secret: [50, 200]
|
||||
Extra: [50, 100]
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue