From: deltanedas <39013340+deltanedas@users.noreply.github.com> Date: Mon, 25 Sep 2023 03:16:09 +0000 (+0100) Subject: use weighted random for ninja threats (#20469) X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=91a157d7ed0e7597dd5ad0db7d288c6b2e85694c;p=space-station-14.git use weighted random for ninja threats (#20469) * change threats to be weighted random and a little cleanup * ninja rule stores weighted random id for threats * move threats out of the rule and into weighted random --------- Co-authored-by: deltanedas <@deltanedas:kde.org> --- diff --git a/Content.Server/Communications/CommsHackerSystem.cs b/Content.Server/Communications/CommsHackerSystem.cs index 95cad6eb97..851be07454 100644 --- a/Content.Server/Communications/CommsHackerSystem.cs +++ b/Content.Server/Communications/CommsHackerSystem.cs @@ -4,6 +4,9 @@ using Content.Server.Ninja.Systems; using Content.Shared.Communications; using Content.Shared.DoAfter; using Content.Shared.Interaction; +using Content.Shared.Random; +using Content.Shared.Random.Helpers; +using Robust.Shared.Prototypes; using Robust.Shared.Random; using Robust.Shared.Serialization; @@ -13,6 +16,7 @@ public sealed class CommsHackerSystem : SharedCommsHackerSystem { [Dependency] private readonly ChatSystem _chat = default!; [Dependency] private readonly GameTicker _gameTicker = default!; + [Dependency] private readonly IPrototypeManager _proto = default!; [Dependency] private readonly IRobustRandom _random = default!; // TODO: remove when generic check event is used [Dependency] private readonly NinjaGlovesSystem _gloves = default!; @@ -55,11 +59,12 @@ public sealed class CommsHackerSystem : SharedCommsHackerSystem /// private void OnDoAfter(EntityUid uid, CommsHackerComponent comp, TerrorDoAfterEvent args) { - if (args.Cancelled || args.Handled || comp.Threats.Count == 0 || args.Target == null) + if (args.Cancelled || args.Handled || args.Target == null) return; - var threat = _random.Pick(comp.Threats); - CallInThreat(threat); + var threats = _proto.Index(comp.Threats); + var threat = threats.Pick(_random); + CallInThreat(_proto.Index(threat)); // prevent calling in multiple threats RemComp(uid); @@ -71,7 +76,7 @@ public sealed class CommsHackerSystem : SharedCommsHackerSystem /// /// Makes announcement and adds game rule of the threat. /// - public void CallInThreat(Threat threat) + public void CallInThreat(ThreatPrototype threat) { _gameTicker.StartGameRule(threat.Rule, out _); _chat.DispatchGlobalAnnouncement(Loc.GetString(threat.Announcement), playSound: true, colorOverride: Color.Red); diff --git a/Content.Server/GameTicking/Rules/Components/NinjaRuleComponent.cs b/Content.Server/GameTicking/Rules/Components/NinjaRuleComponent.cs index 6a1a4a6a9b..e6966c1e37 100644 --- a/Content.Server/GameTicking/Rules/Components/NinjaRuleComponent.cs +++ b/Content.Server/GameTicking/Rules/Components/NinjaRuleComponent.cs @@ -1,6 +1,8 @@ using Content.Server.Ninja.Systems; using Content.Shared.Communications; +using Content.Shared.Random; using Robust.Shared.Audio; +using Robust.Shared.Prototypes; namespace Content.Server.GameTicking.Rules.Components; @@ -15,7 +17,7 @@ public sealed partial class NinjaRuleComponent : Component /// List of threats that can be called in. Copied onto when gloves are enabled. /// [DataField(required: true)] - public List Threats = new(); + public ProtoId Threats = string.Empty; /// /// Sound played when making the player a ninja via antag control or ghost role diff --git a/Content.Shared/Communications/CommsHackerComponent.cs b/Content.Shared/Communications/CommsHackerComponent.cs index 9116899cca..fdd1876c1d 100644 --- a/Content.Shared/Communications/CommsHackerComponent.cs +++ b/Content.Shared/Communications/CommsHackerComponent.cs @@ -1,7 +1,6 @@ +using Content.Shared.Random; using Robust.Shared.GameStates; using Robust.Shared.Prototypes; -using Robust.Shared.Serialization; -using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; namespace Content.Shared.Communications; @@ -15,14 +14,14 @@ public sealed partial class CommsHackerComponent : Component /// /// Time taken to hack the console /// - [DataField("delay")] + [DataField, ViewVariables(VVAccess.ReadWrite)] public TimeSpan Delay = TimeSpan.FromSeconds(20); /// - /// Possible threats to choose from. + /// Weighted random for the possible threats to choose from. /// - [DataField("threats", required: true)] - public List Threats = new(); + [DataField(required: true)] + public ProtoId Threats = string.Empty; } /// @@ -30,18 +29,21 @@ public sealed partial class CommsHackerComponent : Component /// Generally some kind of mid-round minor antag, though you could make it call in scrubber backflow if you wanted to. /// You wouldn't do that, right? /// -[DataDefinition] -public sealed partial class Threat +[Prototype("threat")] +public sealed class ThreatPrototype : IPrototype { + [IdDataField] + public string ID { get; private set; } = default!; + /// /// Locale id for the announcement to be made from CentCom. /// - [DataField("announcement")] + [DataField] public string Announcement = default!; /// /// The game rule for the threat to be added, it should be able to work when added mid-round otherwise this will do nothing. /// - [DataField("rule", customTypeSerializer: typeof(PrototypeIdSerializer))] - public string Rule = default!; + [DataField] + public EntProtoId Rule = default!; } diff --git a/Content.Shared/Communications/SharedCommsHackerSystem.cs b/Content.Shared/Communications/SharedCommsHackerSystem.cs index 94c530878a..c4d9c1e197 100644 --- a/Content.Shared/Communications/SharedCommsHackerSystem.cs +++ b/Content.Shared/Communications/SharedCommsHackerSystem.cs @@ -10,9 +10,9 @@ namespace Content.Shared.Communications; public abstract class SharedCommsHackerSystem : EntitySystem { /// - /// Set the list of threats to choose from when hacking a comms console. + /// Set the threats prototype to choose from when hacking a comms console. /// - public void SetThreats(EntityUid uid, List threats, CommsHackerComponent? comp = null) + public void SetThreats(EntityUid uid, string threats, CommsHackerComponent? comp = null) { if (!Resolve(uid, ref comp)) return; diff --git a/Resources/Prototypes/GameRules/midround.yml b/Resources/Prototypes/GameRules/midround.yml index 41fb9fa432..1927cde53c 100644 --- a/Resources/Prototypes/GameRules/midround.yml +++ b/Resources/Prototypes/GameRules/midround.yml @@ -14,8 +14,4 @@ - TerrorObjective - NinjaSurviveObjective - type: NinjaRule - threats: - - announcement: terror-dragon - rule: Dragon - - announcement: terror-revenant - rule: RevenantSpawn + threats: NinjaThreats diff --git a/Resources/Prototypes/threats.yml b/Resources/Prototypes/threats.yml new file mode 100644 index 0000000000..6e21cc1037 --- /dev/null +++ b/Resources/Prototypes/threats.yml @@ -0,0 +1,16 @@ +# threats called in by ninja hacking comms console +- type: weightedRandom + id: NinjaThreats + weights: + Dragon: 1 + Revenant: 1 + +- type: threat + id: Dragon + announcement: terror-dragon + rule: Dragon + +- type: threat + id: Revenant + announcement: terror-revenant + rule: RevenantSpawn