From a3f4d8ad6c6e89946e64c1feceb5f00b654a05cd Mon Sep 17 00:00:00 2001
From: deltanedas <@deltanedas:kde.org>
Date: Fri, 1 Mar 2024 01:37:11 +0000
Subject: [PATCH 1/8] add SubGamemodes comp/sys
---
.../Rules/Components/SubGamemodesComponent.cs | 20 +++++++++++++++++++
.../GameTicking/Rules/SubGamemodesSystem.cs | 17 ++++++++++++++++
2 files changed, 37 insertions(+)
create mode 100644 Content.Server/GameTicking/Rules/Components/SubGamemodesComponent.cs
create mode 100644 Content.Server/GameTicking/Rules/SubGamemodesSystem.cs
diff --git a/Content.Server/GameTicking/Rules/Components/SubGamemodesComponent.cs b/Content.Server/GameTicking/Rules/Components/SubGamemodesComponent.cs
new file mode 100644
index 000000000000..76ee6103d9f2
--- /dev/null
+++ b/Content.Server/GameTicking/Rules/Components/SubGamemodesComponent.cs
@@ -0,0 +1,20 @@
+using Content.Server.GameTicking.Rules;
+using Content.Shared.Storage;
+
+namespace Content.Server.GameTicking.Rules.Components;
+
+///
+/// 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.
+///
+[RegisterComponent, Access(typeof(SubGamemodesSystem))]
+public sealed partial class SubGamemodesComponent : Component
+{
+ ///
+ /// Spawn entries for each gamerule prototype.
+ /// Use orGroups if you want to limit rules.
+ ///
+ [DataField(required: true)]
+ public List Rules = new();
+}
diff --git a/Content.Server/GameTicking/Rules/SubGamemodesSystem.cs b/Content.Server/GameTicking/Rules/SubGamemodesSystem.cs
new file mode 100644
index 000000000000..42e7e82335c4
--- /dev/null
+++ b/Content.Server/GameTicking/Rules/SubGamemodesSystem.cs
@@ -0,0 +1,17 @@
+using Content.Server.GameTicking.Rules.Components;
+using Content.Shared.Storage;
+
+namespace Content.Server.GameTicking.Rules;
+
+public sealed class SubGamemodesSystem : GameRuleSystem
+{
+ 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);
+ }
+ }
+}
From 8b54b74e983d10ccd18d7c00c9a8f26673c373a7 Mon Sep 17 00:00:00 2001
From: deltanedas <@deltanedas:kde.org>
Date: Fri, 1 Mar 2024 01:51:15 +0000
Subject: [PATCH 2/8] remove RuleChance from thief rule
---
.../GameTicking/Rules/Components/ThiefRuleComponent.cs | 6 ------
Content.Server/GameTicking/Rules/ThiefRuleSystem.cs | 4 ----
2 files changed, 10 deletions(-)
diff --git a/Content.Server/GameTicking/Rules/Components/ThiefRuleComponent.cs b/Content.Server/GameTicking/Rules/Components/ThiefRuleComponent.cs
index 3b0158dcd1ec..9dfd6e6627cc 100644
--- a/Content.Server/GameTicking/Rules/Components/ThiefRuleComponent.cs
+++ b/Content.Server/GameTicking/Rules/Components/ThiefRuleComponent.cs
@@ -29,12 +29,6 @@ public sealed partial class ThiefRuleComponent : Component
[DataField]
public bool PacifistThieves = true;
- ///
- /// A chance for this mode to be added to the game.
- ///
- [DataField]
- public float RuleChance = 1f;
-
[DataField]
public ProtoId ThiefPrototypeId = "Thief";
diff --git a/Content.Server/GameTicking/Rules/ThiefRuleSystem.cs b/Content.Server/GameTicking/Rules/ThiefRuleSystem.cs
index 32f6de608cf3..f050a5b4abc0 100644
--- a/Content.Server/GameTicking/Rules/ThiefRuleSystem.cs
+++ b/Content.Server/GameTicking/Rules/ThiefRuleSystem.cs
@@ -39,10 +39,6 @@ private void OnPlayersSpawned(RulePlayerJobsAssignedEvent ev)
var query = QueryActiveRules();
while (query.MoveNext(out _, out var comp, out _))
{
- //Chance to not launch the game rule
- if (!_random.Prob(comp.RuleChance))
- continue;
-
//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 >:)
var eligiblePlayers = _antagSelection.GetEligiblePlayers(ev.Players, comp.ThiefPrototypeId, acceptableAntags: AntagAcceptability.All, allowNonHumanoids: true);
From 0ade4e77a6fc39a6df5d0dc641174daf5afa5973 Mon Sep 17 00:00:00 2001
From: deltanedas <@deltanedas:kde.org>
Date: Fri, 1 Mar 2024 01:51:24 +0000
Subject: [PATCH 3/8] use SubGamemodes for adding thief rule instead of adding
ThiefRule component to random gamemodes
---
Resources/Prototypes/GameRules/roundstart.yml | 23 +++++++++++--------
1 file changed, 14 insertions(+), 9 deletions(-)
diff --git a/Resources/Prototypes/GameRules/roundstart.yml b/Resources/Prototypes/GameRules/roundstart.yml
index a3ef4a7f0b33..2482dff0d550 100644
--- a/Resources/Prototypes/GameRules/roundstart.yml
+++ b/Resources/Prototypes/GameRules/roundstart.yml
@@ -5,6 +5,17 @@
components:
- type: GameRule
+# a rule that has common subgamemode rules, roundstart is fairly normal so there is time for them to play out
+- type: entity
+ abstract: true
+ parent: BaseGameRule
+ id: BaseSubGamemodesRule
+ components:
+ - type: SubGamemodes
+ rules:
+ - id: Thief
+ prob: 0.5
+
- type: entity
id: DeathMatch31
parent: BaseGameRule
@@ -55,15 +66,13 @@
- type: entity
id: Nukeops
- parent: BaseGameRule
+ parent: BaseSubGamemodesRule
noSpawn: true
components:
- type: GameRule
minPlayers: 20
- type: NukeopsRule
faction: Syndicate
- - type: ThiefRule #the thieves come as an extension of another gamemode
- ruleChance: 0.5
- type: entity
id: Pirates
@@ -74,21 +83,17 @@
- type: entity
id: Traitor
- parent: BaseGameRule
+ parent: BaseSubGamemodesRule
noSpawn: true
components:
- type: TraitorRule
- - type: ThiefRule #the thieves come as an extension of another gamemode
- ruleChance: 0.5
- type: entity
id: Revolutionary
- parent: BaseGameRule
+ parent: BaseSubGamemodesRule
noSpawn: true
components:
- type: RevolutionaryRule
- - type: ThiefRule #the thieves come as an extension of another gamemode
- ruleChance: 0.5
- type: entity
id: Sandbox
From c68abab3cbe065586adf82ab6a8022ae7f455e5e Mon Sep 17 00:00:00 2001
From: deltanedas <@deltanedas:kde.org>
Date: Fri, 1 Mar 2024 01:51:40 +0000
Subject: [PATCH 4/8] clean up thief rule prototype
---
Resources/Prototypes/GameRules/midround.yml | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/Resources/Prototypes/GameRules/midround.yml b/Resources/Prototypes/GameRules/midround.yml
index 28767e2c1808..37fc4b44cde2 100644
--- a/Resources/Prototypes/GameRules/midround.yml
+++ b/Resources/Prototypes/GameRules/midround.yml
@@ -28,13 +28,12 @@
- CarpRiftsObjective
- DragonSurviveObjective
-# need for admin panel antag create (because the rule doesn't have a roundstart entity like TraitorRule)
- type: entity
- id: Thief
- parent: BaseGameRule
noSpawn: true
+ parent: BaseGameRule
+ id: Thief
components:
- - type: ThiefRule
+ - type: ThiefRule
- type: entity
noSpawn: true
From 190d0c701860103a70d46c151fa8709d47b9a8a0 Mon Sep 17 00:00:00 2001
From: deltanedas <@deltanedas:kde.org>
Date: Fri, 1 Mar 2024 02:14:25 +0000
Subject: [PATCH 5/8] add better logging + end rule if it fails to start
---
Content.Server/GameTicking/Rules/ThiefRuleSystem.cs | 6 +++++-
Resources/Prototypes/GameRules/roundstart.yml | 2 ++
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/Content.Server/GameTicking/Rules/ThiefRuleSystem.cs b/Content.Server/GameTicking/Rules/ThiefRuleSystem.cs
index f050a5b4abc0..32f9040f89f9 100644
--- a/Content.Server/GameTicking/Rules/ThiefRuleSystem.cs
+++ b/Content.Server/GameTicking/Rules/ThiefRuleSystem.cs
@@ -37,7 +37,7 @@ public override void Initialize()
private void OnPlayersSpawned(RulePlayerJobsAssignedEvent ev)
{
var query = QueryActiveRules();
- while (query.MoveNext(out _, out var comp, out _))
+ while (query.MoveNext(out var uid, out _, out var comp, out var gameRule))
{
//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 >:)
@@ -45,7 +45,11 @@ private void OnPlayersSpawned(RulePlayerJobsAssignedEvent ev)
//Abort if there are none
if (eligiblePlayers.Count == 0)
+ {
+ Log.Warning($"No eligible thieves found, ending game rule {ToPrettyString(uid):rule}");
+ GameTicker.EndGameRule(uid, gameRule);
continue;
+ }
//Calculate number of thieves to choose
var thiefCount = _random.Next(1, comp.MaxAllowThief + 1);
diff --git a/Resources/Prototypes/GameRules/roundstart.yml b/Resources/Prototypes/GameRules/roundstart.yml
index 2482dff0d550..1609a02cc4c0 100644
--- a/Resources/Prototypes/GameRules/roundstart.yml
+++ b/Resources/Prototypes/GameRules/roundstart.yml
@@ -86,6 +86,8 @@
parent: BaseSubGamemodesRule
noSpawn: true
components:
+ - type: GameRule
+ minPlayers: 1
- type: TraitorRule
- type: entity
From acbd4e067306d2011f8a34381fedf128eda2f57d Mon Sep 17 00:00:00 2001
From: deltanedas <@deltanedas:kde.org>
Date: Fri, 1 Mar 2024 02:15:54 +0000
Subject: [PATCH 6/8] march 1st incident
---
Resources/Prototypes/GameRules/roundstart.yml | 2 --
1 file changed, 2 deletions(-)
diff --git a/Resources/Prototypes/GameRules/roundstart.yml b/Resources/Prototypes/GameRules/roundstart.yml
index 1609a02cc4c0..2482dff0d550 100644
--- a/Resources/Prototypes/GameRules/roundstart.yml
+++ b/Resources/Prototypes/GameRules/roundstart.yml
@@ -86,8 +86,6 @@
parent: BaseSubGamemodesRule
noSpawn: true
components:
- - type: GameRule
- minPlayers: 1
- type: TraitorRule
- type: entity
From fdcc494dc5916a86e2b5a23f5c93549737782f55 Mon Sep 17 00:00:00 2001
From: deltanedas <@deltanedas:kde.org>
Date: Sat, 2 Mar 2024 15:12:53 +0000
Subject: [PATCH 7/8] preset ops
---
Resources/Prototypes/GameRules/roundstart.yml | 11 +++++------
Resources/Prototypes/game_presets.yml | 3 +++
2 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/Resources/Prototypes/GameRules/roundstart.yml b/Resources/Prototypes/GameRules/roundstart.yml
index 2482dff0d550..a836faf500c7 100644
--- a/Resources/Prototypes/GameRules/roundstart.yml
+++ b/Resources/Prototypes/GameRules/roundstart.yml
@@ -5,11 +5,10 @@
components:
- type: GameRule
-# a rule that has common subgamemode rules, roundstart is fairly normal so there is time for them to play out
- type: entity
- abstract: true
+ noSpawn: true
parent: BaseGameRule
- id: BaseSubGamemodesRule
+ id: SubGamemodesRule
components:
- type: SubGamemodes
rules:
@@ -66,7 +65,7 @@
- type: entity
id: Nukeops
- parent: BaseSubGamemodesRule
+ parent: BaseGameRule
noSpawn: true
components:
- type: GameRule
@@ -83,14 +82,14 @@
- type: entity
id: Traitor
- parent: BaseSubGamemodesRule
+ parent: BaseGameRule
noSpawn: true
components:
- type: TraitorRule
- type: entity
id: Revolutionary
- parent: BaseSubGamemodesRule
+ parent: BaseGameRule
noSpawn: true
components:
- type: RevolutionaryRule
diff --git a/Resources/Prototypes/game_presets.yml b/Resources/Prototypes/game_presets.yml
index f1f16ab9b8a2..885b6197975f 100644
--- a/Resources/Prototypes/game_presets.yml
+++ b/Resources/Prototypes/game_presets.yml
@@ -93,6 +93,7 @@
showInVote: false
rules:
- Traitor
+ - SubGamemodes
- BasicStationEventScheduler
- BasicRoundstartVariation
@@ -118,6 +119,7 @@
showInVote: false
rules:
- Nukeops
+ - SubGamemodes
- BasicStationEventScheduler
- BasicRoundstartVariation
@@ -132,6 +134,7 @@
showInVote: false
rules:
- Revolutionary
+ - SubGamemodes
- BasicStationEventScheduler
- BasicRoundstartVariation
From 743228f544feb6cd13e33afbc78c7ad569d475cf Mon Sep 17 00:00:00 2001
From: deltanedas <39013340+deltanedas@users.noreply.github.com>
Date: Sat, 2 Mar 2024 15:36:45 +0000
Subject: [PATCH 8/8] the dreaded
---
Resources/Prototypes/game_presets.yml | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/Resources/Prototypes/game_presets.yml b/Resources/Prototypes/game_presets.yml
index 885b6197975f..a5b20a3db68e 100644
--- a/Resources/Prototypes/game_presets.yml
+++ b/Resources/Prototypes/game_presets.yml
@@ -93,7 +93,7 @@
showInVote: false
rules:
- Traitor
- - SubGamemodes
+ - SubGamemodesRule
- BasicStationEventScheduler
- BasicRoundstartVariation
@@ -119,7 +119,7 @@
showInVote: false
rules:
- Nukeops
- - SubGamemodes
+ - SubGamemodesRule
- BasicStationEventScheduler
- BasicRoundstartVariation
@@ -134,7 +134,7 @@
showInVote: false
rules:
- Revolutionary
- - SubGamemodes
+ - SubGamemodesRule
- BasicStationEventScheduler
- BasicRoundstartVariation