move ninja objectives code into generic antag system (#20186)
Co-authored-by: deltanedas <@deltanedas:kde.org>
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
using Content.Server.GameTicking.Rules;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List;
|
||||
|
||||
namespace Content.Server.GameTicking.Rules.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Gamerule for simple antagonists that have fixed objectives.
|
||||
/// </summary>
|
||||
[RegisterComponent, Access(typeof(GenericAntagRuleSystem))]
|
||||
public sealed partial class GenericAntagRuleComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// All antag minds that are using this rule.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public List<EntityUid> Minds = new();
|
||||
|
||||
/// <summary>
|
||||
/// Locale id for the name of the antag used by the roundend summary.
|
||||
/// </summary>
|
||||
[DataField(required: true), ViewVariables(VVAccess.ReadWrite)]
|
||||
public string AgentName = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// List of objective entity prototypes to add to the antag when a mind is added.
|
||||
/// </summary>
|
||||
[DataField(required: true)]
|
||||
public List<EntProtoId> Objectives = new();
|
||||
}
|
||||
@@ -1,36 +1,25 @@
|
||||
using Content.Server.Ninja.Systems;
|
||||
using Content.Shared.Communications;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List;
|
||||
|
||||
namespace Content.Server.GameTicking.Rules.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Stores some configuration used by the ninja system.
|
||||
/// Objectives and roundend summary are handled by <see cref="GenericAntagRuleComponent/">.
|
||||
/// </summary>
|
||||
[RegisterComponent, Access(typeof(SpaceNinjaSystem))]
|
||||
public sealed partial class NinjaRuleComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// All ninja minds that are using this rule.
|
||||
/// Their SpaceNinjaComponent Rule field should point back to this rule.
|
||||
/// </summary>
|
||||
[DataField("minds")]
|
||||
public List<EntityUid> Minds = new();
|
||||
|
||||
/// <summary>
|
||||
/// List of objective entity prototypes to add
|
||||
/// </summary>
|
||||
[DataField("objectives", required: true, customTypeSerializer: typeof(PrototypeIdListSerializer<EntityPrototype>))]
|
||||
public List<string> Objectives = new();
|
||||
|
||||
/// <summary>
|
||||
/// List of threats that can be called in. Copied onto <see cref="CommsHackerComponent"/> when gloves are enabled.
|
||||
/// </summary>
|
||||
[DataField("threats", required: true)]
|
||||
[DataField(required: true)]
|
||||
public List<Threat> Threats = new();
|
||||
|
||||
/// <summary>
|
||||
/// Sound played when making the player a ninja via antag control or ghost role
|
||||
/// </summary>
|
||||
[DataField("greetingSound", customTypeSerializer: typeof(SoundSpecifierTypeSerializer))]
|
||||
[DataField]
|
||||
public SoundSpecifier? GreetingSound = new SoundPathSpecifier("/Audio/Misc/ninja_greeting.ogg");
|
||||
}
|
||||
|
||||
53
Content.Server/GameTicking/Rules/GenericAntagRuleSystem.cs
Normal file
53
Content.Server/GameTicking/Rules/GenericAntagRuleSystem.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using Content.Server.GameTicking.Rules.Components;
|
||||
using Content.Server.Objectives;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Content.Server.GameTicking.Rules;
|
||||
|
||||
/// <summary>
|
||||
/// Handles round end text for simple antags.
|
||||
/// Adding objectives is handled in its own system.
|
||||
/// </summary>
|
||||
public sealed class GenericAntagRuleSystem : GameRuleSystem<GenericAntagRuleComponent>
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<GenericAntagRuleComponent, ObjectivesTextGetInfoEvent>(OnObjectivesTextGetInfo);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Start a simple antag's game rule.
|
||||
/// If it is invalid the rule is deleted and null is returned.
|
||||
/// </summary>
|
||||
public bool StartRule(string rule, EntityUid mindId, [NotNullWhen(true)] out EntityUid? ruleId, [NotNullWhen(true)] out GenericAntagRuleComponent? comp)
|
||||
{
|
||||
ruleId = GameTicker.AddGameRule(rule);
|
||||
if (!TryComp<GenericAntagRuleComponent>(ruleId, out comp))
|
||||
{
|
||||
Log.Error($"Simple antag rule prototype {rule} is invalid, deleting it.");
|
||||
Del(ruleId);
|
||||
ruleId = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!GameTicker.StartGameRule(ruleId.Value))
|
||||
{
|
||||
Log.Error($"Simple antag rule prototype {rule} failed to start, deleting it.");
|
||||
Del(ruleId);
|
||||
ruleId = null;
|
||||
comp = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
comp.Minds.Add(mindId);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void OnObjectivesTextGetInfo(EntityUid uid, GenericAntagRuleComponent comp, ref ObjectivesTextGetInfoEvent args)
|
||||
{
|
||||
args.Minds = comp.Minds;
|
||||
args.AgentName = Loc.GetString(comp.AgentName);
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
using Content.Server.GameTicking.Rules.Components;
|
||||
using Content.Server.Objectives;
|
||||
|
||||
namespace Content.Server.GameTicking.Rules;
|
||||
|
||||
/// <summary>
|
||||
/// Only handles round end text for ninja.
|
||||
/// </summary>
|
||||
public sealed class NinjaRuleSystem : GameRuleSystem<NinjaRuleComponent>
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<NinjaRuleComponent, ObjectivesTextGetInfoEvent>(OnObjectivesTextGetInfo);
|
||||
}
|
||||
|
||||
private void OnObjectivesTextGetInfo(EntityUid uid, NinjaRuleComponent comp, ref ObjectivesTextGetInfoEvent args)
|
||||
{
|
||||
args.Minds = comp.Minds;
|
||||
args.AgentName = Loc.GetString("ninja-round-end-agent-name");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user