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>
This commit is contained in:
@@ -4,6 +4,9 @@ using Content.Server.Ninja.Systems;
|
|||||||
using Content.Shared.Communications;
|
using Content.Shared.Communications;
|
||||||
using Content.Shared.DoAfter;
|
using Content.Shared.DoAfter;
|
||||||
using Content.Shared.Interaction;
|
using Content.Shared.Interaction;
|
||||||
|
using Content.Shared.Random;
|
||||||
|
using Content.Shared.Random.Helpers;
|
||||||
|
using Robust.Shared.Prototypes;
|
||||||
using Robust.Shared.Random;
|
using Robust.Shared.Random;
|
||||||
using Robust.Shared.Serialization;
|
using Robust.Shared.Serialization;
|
||||||
|
|
||||||
@@ -13,6 +16,7 @@ public sealed class CommsHackerSystem : SharedCommsHackerSystem
|
|||||||
{
|
{
|
||||||
[Dependency] private readonly ChatSystem _chat = default!;
|
[Dependency] private readonly ChatSystem _chat = default!;
|
||||||
[Dependency] private readonly GameTicker _gameTicker = default!;
|
[Dependency] private readonly GameTicker _gameTicker = default!;
|
||||||
|
[Dependency] private readonly IPrototypeManager _proto = default!;
|
||||||
[Dependency] private readonly IRobustRandom _random = default!;
|
[Dependency] private readonly IRobustRandom _random = default!;
|
||||||
// TODO: remove when generic check event is used
|
// TODO: remove when generic check event is used
|
||||||
[Dependency] private readonly NinjaGlovesSystem _gloves = default!;
|
[Dependency] private readonly NinjaGlovesSystem _gloves = default!;
|
||||||
@@ -55,11 +59,12 @@ public sealed class CommsHackerSystem : SharedCommsHackerSystem
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void OnDoAfter(EntityUid uid, CommsHackerComponent comp, TerrorDoAfterEvent args)
|
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;
|
return;
|
||||||
|
|
||||||
var threat = _random.Pick(comp.Threats);
|
var threats = _proto.Index<WeightedRandomPrototype>(comp.Threats);
|
||||||
CallInThreat(threat);
|
var threat = threats.Pick(_random);
|
||||||
|
CallInThreat(_proto.Index<ThreatPrototype>(threat));
|
||||||
|
|
||||||
// prevent calling in multiple threats
|
// prevent calling in multiple threats
|
||||||
RemComp<CommsHackerComponent>(uid);
|
RemComp<CommsHackerComponent>(uid);
|
||||||
@@ -71,7 +76,7 @@ public sealed class CommsHackerSystem : SharedCommsHackerSystem
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Makes announcement and adds game rule of the threat.
|
/// Makes announcement and adds game rule of the threat.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void CallInThreat(Threat threat)
|
public void CallInThreat(ThreatPrototype threat)
|
||||||
{
|
{
|
||||||
_gameTicker.StartGameRule(threat.Rule, out _);
|
_gameTicker.StartGameRule(threat.Rule, out _);
|
||||||
_chat.DispatchGlobalAnnouncement(Loc.GetString(threat.Announcement), playSound: true, colorOverride: Color.Red);
|
_chat.DispatchGlobalAnnouncement(Loc.GetString(threat.Announcement), playSound: true, colorOverride: Color.Red);
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
using Content.Server.Ninja.Systems;
|
using Content.Server.Ninja.Systems;
|
||||||
using Content.Shared.Communications;
|
using Content.Shared.Communications;
|
||||||
|
using Content.Shared.Random;
|
||||||
using Robust.Shared.Audio;
|
using Robust.Shared.Audio;
|
||||||
|
using Robust.Shared.Prototypes;
|
||||||
|
|
||||||
namespace Content.Server.GameTicking.Rules.Components;
|
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 <see cref="CommsHackerComponent"/> when gloves are enabled.
|
/// List of threats that can be called in. Copied onto <see cref="CommsHackerComponent"/> when gloves are enabled.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField(required: true)]
|
[DataField(required: true)]
|
||||||
public List<Threat> Threats = new();
|
public ProtoId<WeightedRandomPrototype> Threats = string.Empty;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sound played when making the player a ninja via antag control or ghost role
|
/// Sound played when making the player a ninja via antag control or ghost role
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
|
using Content.Shared.Random;
|
||||||
using Robust.Shared.GameStates;
|
using Robust.Shared.GameStates;
|
||||||
using Robust.Shared.Prototypes;
|
using Robust.Shared.Prototypes;
|
||||||
using Robust.Shared.Serialization;
|
|
||||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
|
||||||
|
|
||||||
namespace Content.Shared.Communications;
|
namespace Content.Shared.Communications;
|
||||||
|
|
||||||
@@ -15,14 +14,14 @@ public sealed partial class CommsHackerComponent : Component
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Time taken to hack the console
|
/// Time taken to hack the console
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField("delay")]
|
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||||
public TimeSpan Delay = TimeSpan.FromSeconds(20);
|
public TimeSpan Delay = TimeSpan.FromSeconds(20);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Possible threats to choose from.
|
/// Weighted random for the possible threats to choose from.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField("threats", required: true)]
|
[DataField(required: true)]
|
||||||
public List<Threat> Threats = new();
|
public ProtoId<WeightedRandomPrototype> Threats = string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -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.
|
/// 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?
|
/// You wouldn't do that, right?
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataDefinition]
|
[Prototype("threat")]
|
||||||
public sealed partial class Threat
|
public sealed class ThreatPrototype : IPrototype
|
||||||
{
|
{
|
||||||
|
[IdDataField]
|
||||||
|
public string ID { get; private set; } = default!;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Locale id for the announcement to be made from CentCom.
|
/// Locale id for the announcement to be made from CentCom.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField("announcement")]
|
[DataField]
|
||||||
public string Announcement = default!;
|
public string Announcement = default!;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The game rule for the threat to be added, it should be able to work when added mid-round otherwise this will do nothing.
|
/// The game rule for the threat to be added, it should be able to work when added mid-round otherwise this will do nothing.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField("rule", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
|
[DataField]
|
||||||
public string Rule = default!;
|
public EntProtoId Rule = default!;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,9 +10,9 @@ namespace Content.Shared.Communications;
|
|||||||
public abstract class SharedCommsHackerSystem : EntitySystem
|
public abstract class SharedCommsHackerSystem : EntitySystem
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 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.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void SetThreats(EntityUid uid, List<Threat> threats, CommsHackerComponent? comp = null)
|
public void SetThreats(EntityUid uid, string threats, CommsHackerComponent? comp = null)
|
||||||
{
|
{
|
||||||
if (!Resolve(uid, ref comp))
|
if (!Resolve(uid, ref comp))
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -14,8 +14,4 @@
|
|||||||
- TerrorObjective
|
- TerrorObjective
|
||||||
- NinjaSurviveObjective
|
- NinjaSurviveObjective
|
||||||
- type: NinjaRule
|
- type: NinjaRule
|
||||||
threats:
|
threats: NinjaThreats
|
||||||
- announcement: terror-dragon
|
|
||||||
rule: Dragon
|
|
||||||
- announcement: terror-revenant
|
|
||||||
rule: RevenantSpawn
|
|
||||||
|
|||||||
16
Resources/Prototypes/threats.yml
Normal file
16
Resources/Prototypes/threats.yml
Normal file
@@ -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
|
||||||
Reference in New Issue
Block a user