make thief a subgamemode (#25740)

* add SubGamemodes comp/sys

* remove RuleChance from thief rule

* use SubGamemodes for adding thief rule instead of adding ThiefRule component to random gamemodes

* clean up thief rule prototype

* add better logging + end rule if it fails to start

* march 1st incident

* preset ops

* the dreaded

---------

Co-authored-by: deltanedas <@deltanedas:kde.org>
This commit is contained in:
deltanedas
2024-03-02 16:33:24 +00:00
committed by GitHub
parent 709881f912
commit 7f060eb129
7 changed files with 58 additions and 21 deletions

View File

@@ -0,0 +1,20 @@
using Content.Server.GameTicking.Rules;
using Content.Shared.Storage;
namespace Content.Server.GameTicking.Rules.Components;
/// <summary>
/// When this gamerule is added it has a chance of adding other gamerules.
/// Since it's done when added and not when started you can still use normal start logic.
/// Used for starting subgamemodes in game presets.
/// </summary>
[RegisterComponent, Access(typeof(SubGamemodesSystem))]
public sealed partial class SubGamemodesComponent : Component
{
/// <summary>
/// Spawn entries for each gamerule prototype.
/// Use orGroups if you want to limit rules.
/// </summary>
[DataField(required: true)]
public List<EntitySpawnEntry> Rules = new();
}

View File

@@ -29,12 +29,6 @@ public sealed partial class ThiefRuleComponent : Component
[DataField] [DataField]
public bool PacifistThieves = true; public bool PacifistThieves = true;
/// <summary>
/// A chance for this mode to be added to the game.
/// </summary>
[DataField]
public float RuleChance = 1f;
[DataField] [DataField]
public ProtoId<AntagPrototype> ThiefPrototypeId = "Thief"; public ProtoId<AntagPrototype> ThiefPrototypeId = "Thief";

View File

@@ -0,0 +1,17 @@
using Content.Server.GameTicking.Rules.Components;
using Content.Shared.Storage;
namespace Content.Server.GameTicking.Rules;
public sealed class SubGamemodesSystem : GameRuleSystem<SubGamemodesComponent>
{
protected override void Added(EntityUid uid, SubGamemodesComponent comp, GameRuleComponent rule, GameRuleAddedEvent args)
{
var picked = EntitySpawnCollection.GetSpawns(comp.Rules, RobustRandom);
foreach (var id in picked)
{
Log.Info($"Starting gamerule {id} as a subgamemode of {ToPrettyString(uid):rule}");
GameTicker.AddGameRule(id);
}
}
}

View File

@@ -37,19 +37,19 @@ public sealed class ThiefRuleSystem : GameRuleSystem<ThiefRuleComponent>
private void OnPlayersSpawned(RulePlayerJobsAssignedEvent ev) private void OnPlayersSpawned(RulePlayerJobsAssignedEvent ev)
{ {
var query = QueryActiveRules(); var query = QueryActiveRules();
while (query.MoveNext(out _, out var comp, out _)) while (query.MoveNext(out var uid, out _, out var comp, out var gameRule))
{ {
//Chance to not launch the game rule
if (!_random.Prob(comp.RuleChance))
continue;
//Get all players eligible for this role, allow selecting existing antags //Get all players eligible for this role, allow selecting existing antags
//TO DO: When voxes specifies are added, increase their chance of becoming a thief by 4 times >:) //TO DO: When voxes specifies are added, increase their chance of becoming a thief by 4 times >:)
var eligiblePlayers = _antagSelection.GetEligiblePlayers(ev.Players, comp.ThiefPrototypeId, acceptableAntags: AntagAcceptability.All, allowNonHumanoids: true); var eligiblePlayers = _antagSelection.GetEligiblePlayers(ev.Players, comp.ThiefPrototypeId, acceptableAntags: AntagAcceptability.All, allowNonHumanoids: true);
//Abort if there are none //Abort if there are none
if (eligiblePlayers.Count == 0) if (eligiblePlayers.Count == 0)
{
Log.Warning($"No eligible thieves found, ending game rule {ToPrettyString(uid):rule}");
GameTicker.EndGameRule(uid, gameRule);
continue; continue;
}
//Calculate number of thieves to choose //Calculate number of thieves to choose
var thiefCount = _random.Next(1, comp.MaxAllowThief + 1); var thiefCount = _random.Next(1, comp.MaxAllowThief + 1);

View File

@@ -28,13 +28,12 @@
- CarpRiftsObjective - CarpRiftsObjective
- DragonSurviveObjective - DragonSurviveObjective
# need for admin panel antag create (because the rule doesn't have a roundstart entity like TraitorRule)
- type: entity - type: entity
id: Thief
parent: BaseGameRule
noSpawn: true noSpawn: true
parent: BaseGameRule
id: Thief
components: components:
- type: ThiefRule - type: ThiefRule
- type: entity - type: entity
noSpawn: true noSpawn: true

View File

@@ -5,6 +5,16 @@
components: components:
- type: GameRule - type: GameRule
- type: entity
noSpawn: true
parent: BaseGameRule
id: SubGamemodesRule
components:
- type: SubGamemodes
rules:
- id: Thief
prob: 0.5
- type: entity - type: entity
id: DeathMatch31 id: DeathMatch31
parent: BaseGameRule parent: BaseGameRule
@@ -62,8 +72,6 @@
minPlayers: 20 minPlayers: 20
- type: NukeopsRule - type: NukeopsRule
faction: Syndicate faction: Syndicate
- type: ThiefRule #the thieves come as an extension of another gamemode
ruleChance: 0.5
- type: entity - type: entity
id: Pirates id: Pirates
@@ -78,8 +86,6 @@
noSpawn: true noSpawn: true
components: components:
- type: TraitorRule - type: TraitorRule
- type: ThiefRule #the thieves come as an extension of another gamemode
ruleChance: 0.5
- type: entity - type: entity
id: Revolutionary id: Revolutionary
@@ -87,8 +93,6 @@
noSpawn: true noSpawn: true
components: components:
- type: RevolutionaryRule - type: RevolutionaryRule
- type: ThiefRule #the thieves come as an extension of another gamemode
ruleChance: 0.5
- type: entity - type: entity
id: Sandbox id: Sandbox

View File

@@ -93,6 +93,7 @@
showInVote: false showInVote: false
rules: rules:
- Traitor - Traitor
- SubGamemodesRule
- BasicStationEventScheduler - BasicStationEventScheduler
- BasicRoundstartVariation - BasicRoundstartVariation
@@ -118,6 +119,7 @@
showInVote: false showInVote: false
rules: rules:
- Nukeops - Nukeops
- SubGamemodesRule
- BasicStationEventScheduler - BasicStationEventScheduler
- BasicRoundstartVariation - BasicRoundstartVariation
@@ -132,6 +134,7 @@
showInVote: false showInVote: false
rules: rules:
- Revolutionary - Revolutionary
- SubGamemodesRule
- BasicStationEventScheduler - BasicStationEventScheduler
- BasicRoundstartVariation - BasicRoundstartVariation