GameRuleOnTrigger (#39845)
* Gaming * commit --------- Co-authored-by: iaada <iaada@users.noreply.github.com>
This commit is contained in:
44
Content.Server/Trigger/Systems/GameRuleTriggerSystem.cs
Normal file
44
Content.Server/Trigger/Systems/GameRuleTriggerSystem.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using Content.Server.Administration.Logs;
|
||||
using Content.Server.GameTicking;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.Trigger;
|
||||
using Content.Shared.Trigger.Components.Effects;
|
||||
|
||||
namespace Content.Server.Trigger.Systems;
|
||||
|
||||
/// <summary>
|
||||
/// Trigger system for game rules.
|
||||
/// </summary>
|
||||
public sealed class GameRuleTriggerSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly GameTicker _ticker = default!;
|
||||
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<AddGameRuleOnTriggerComponent, TriggerEvent>(AddRuleOnTrigger);
|
||||
}
|
||||
|
||||
private void AddRuleOnTrigger(Entity<AddGameRuleOnTriggerComponent> ent, ref TriggerEvent args)
|
||||
{
|
||||
if (args.Key != null && !ent.Comp.KeysIn.Contains(args.Key))
|
||||
return;
|
||||
|
||||
var rule = _ticker.AddGameRule(ent.Comp.GameRule);
|
||||
|
||||
_adminLogger.Add(LogType.EventStarted,
|
||||
$"{ToPrettyString(args.User):entity} added a game rule [{ent.Comp.GameRule}]" +
|
||||
$" via a trigger on {ToPrettyString(ent.Owner):entity}.");
|
||||
|
||||
if (ent.Comp.StartRule && _ticker.RunLevel == GameRunLevel.InRound)
|
||||
{
|
||||
_ticker.StartGameRule(rule);
|
||||
_adminLogger.Add(LogType.EventStarted, $"{ToPrettyString(args.User):entity} started game rule [{ent.Comp.GameRule}].");
|
||||
}
|
||||
|
||||
args.Handled = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using Content.Shared.GameTicking.Components;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Shared.Trigger.Components.Effects;
|
||||
|
||||
/// <summary>
|
||||
/// Adds and starts a new game rule on a trigger.
|
||||
/// The user is always logged alongside the game rule and this entity.
|
||||
/// </summary>
|
||||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
|
||||
public sealed partial class AddGameRuleOnTriggerComponent : BaseXOnTriggerComponent
|
||||
{
|
||||
/// <summary>
|
||||
/// The game rule that will be added. Entity requires <see cref="GameRuleComponent"/>.
|
||||
/// </summary>
|
||||
[DataField(required: true), AutoNetworkedField]
|
||||
public EntProtoId<GameRuleComponent> GameRule;
|
||||
|
||||
/// <summary>
|
||||
/// Whether to also start the game rule when adding it.
|
||||
/// You almost always want this to be true.
|
||||
/// </summary>
|
||||
[DataField, AutoNetworkedField]
|
||||
public bool StartRule = true;
|
||||
}
|
||||
Reference in New Issue
Block a user