mirror of
https://github.com/DeltaV-Station/Delta-v.git
synced 2026-09-29 23:57:29 +00:00
* Pass 1. * i'm FREE * Prevent hangups. * okay fine here's an attribute for settings, will polish later and prolly remove the overridable thing. * sigh. * fix singular trigger bug so LatheTest doesn't flake. * Remove SystemAttribute usage. * Poke * I used the shotgun. You know why? Cause the shot gun doesn’t miss, and unlike the shitty hybrid taser it stops a criminal in their tracks in two hits. Bang, bang, and they’re fucking done. I use four shots just to make damn sure. Because, once again, I’m not there to coddle a buncha criminal scum sucking f------, I’m there to 1) Survive the fucking round. 2) Guard the armory. So you can absolutely get fucked. If I get unbanned, which I won’t, you can guarantee I will continue to use the shotgun to apprehend criminals. Because it’s quick, clean and effective as fuck. Why in the seven hells would I fuck around with the disabler shots, which take half a clip just to bring someone down, or with the tazer bolts which are slow as balls, impossible to aim and do about next to jack shit, fuck all. The shotgun is the superior law enforcement weapon. Because it stops crime. And it stops crime by reducing the number of criminals roaming the fucking halls. * Change the faulty store test into two tests, one of which is ignored for failing.
198 lines
7.4 KiB
C#
198 lines
7.4 KiB
C#
using Content.Shared.Administration.Logs;
|
|
using Content.Shared.Database;
|
|
using Content.Shared.DeviceLinking;
|
|
using Content.Shared.EntityTable;
|
|
using Content.Shared.Item.ItemToggle;
|
|
using Content.Shared.Mind;
|
|
using Content.Shared.Popups;
|
|
using Content.Shared.Roles;
|
|
using Content.Shared.Timing;
|
|
using Content.Shared.Trigger.Components;
|
|
using Content.Shared.Whitelist;
|
|
using Robust.Shared.Network;
|
|
using Robust.Shared.Physics.Systems;
|
|
using Robust.Shared.Timing;
|
|
using Robust.Shared.Random;
|
|
using Robust.Shared.Audio.Systems;
|
|
|
|
|
|
namespace Content.Shared.Trigger.Systems;
|
|
|
|
/// <summary>
|
|
/// System containing the basic trigger API.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// If you add a custom trigger subscription or effect then don't put them here.
|
|
/// Put them into a separate system so we don't end up with a giant list of imports.
|
|
/// </remarks>
|
|
public sealed partial class TriggerSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly IGameTiming _timing = default!;
|
|
[Dependency] private readonly SharedTransformSystem _transform = default!;
|
|
[Dependency] private readonly SharedPopupSystem _popup = default!;
|
|
[Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
|
|
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
|
|
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
|
[Dependency] private readonly FixtureSystem _fixture = default!;
|
|
[Dependency] private readonly INetManager _net = default!;
|
|
[Dependency] private readonly IRobustRandom _random = default!;
|
|
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
|
[Dependency] private readonly UseDelaySystem _useDelay = default!;
|
|
[Dependency] private readonly EntityWhitelistSystem _whitelist = default!;
|
|
[Dependency] private readonly ItemToggleSystem _itemToggle = default!;
|
|
[Dependency] private readonly SharedDeviceLinkSystem _deviceLink = default!;
|
|
[Dependency] private readonly SharedRoleSystem _role = default!;
|
|
[Dependency] private readonly SharedMindSystem _mind = default!;
|
|
[Dependency] private readonly EntityTableSystem _entityTable = default!;
|
|
|
|
public const string DefaultTriggerKey = "trigger";
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
InitializeCollide();
|
|
InitializeCondition();
|
|
InitializeInteraction();
|
|
InitializeProximity();
|
|
InitializeSignal();
|
|
InitializeTimer();
|
|
InitializeSpawn();
|
|
InitializeVoice();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Trigger the given entity.
|
|
/// </summary>
|
|
/// <param name="trigger">The entity that has the components that should be triggered.</param>
|
|
/// <param name="user">The user of the trigger. Some effects may target the user instead of the trigger entity.</param>
|
|
/// <param name="key">A key string to allow multiple, independent triggers on the same entity. If null then all triggers will activate.</param>
|
|
/// <param name="predicted">Whether or not this trigger is being predicted</param>
|
|
/// <returns>Whether or not the trigger has sucessfully activated an effect.</returns>
|
|
public bool Trigger(EntityUid trigger, EntityUid? user = null, string? key = null, bool predicted = true)
|
|
{
|
|
var attemptTriggerEvent = new AttemptTriggerEvent(user, key);
|
|
RaiseLocalEvent(trigger, ref attemptTriggerEvent);
|
|
if (attemptTriggerEvent.Cancelled)
|
|
return false;
|
|
|
|
var triggerEvent = new TriggerEvent(user, key, predicted);
|
|
RaiseLocalEvent(trigger, ref triggerEvent, true);
|
|
return triggerEvent.Handled;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Activate a timer trigger on an entity with <see cref="TimerTriggerComponent"/>.
|
|
/// </summary>
|
|
/// <returns>Whether or not a timer was activated.</returns>
|
|
public bool ActivateTimerTrigger(Entity<TimerTriggerComponent?> ent, EntityUid? user = null)
|
|
{
|
|
if (!Resolve(ent, ref ent.Comp))
|
|
return false;
|
|
|
|
if (Terminating(ent))
|
|
return false; // Stop trying to resurrect a dead horse.
|
|
|
|
if (HasComp<ActiveTimerTriggerComponent>(ent))
|
|
return false; // already activated
|
|
|
|
if (user != null)
|
|
{
|
|
_adminLogger.Add(LogType.Trigger,
|
|
$"{ToPrettyString(user.Value):user} started a {ent.Comp.Delay} second timer trigger on entity {ToPrettyString(ent.Owner):timer}");
|
|
}
|
|
else
|
|
{
|
|
_adminLogger.Add(LogType.Trigger,
|
|
$"{ent.Comp.Delay} second timer trigger started on entity {ToPrettyString(ent.Owner):timer}");
|
|
}
|
|
|
|
if (ent.Comp.Popup != null)
|
|
_popup.PopupPredicted(Loc.GetString(ent.Comp.Popup.Value, ("device", ent.Owner)), ent.Owner, user);
|
|
|
|
AddComp<ActiveTimerTriggerComponent>(ent);
|
|
var curTime = _timing.CurTime;
|
|
ent.Comp.NextTrigger = curTime + ent.Comp.Delay;
|
|
var delay = ent.Comp.InitialBeepDelay ?? ent.Comp.BeepInterval;
|
|
ent.Comp.NextBeep = curTime + delay;
|
|
ent.Comp.User = user;
|
|
Dirty(ent);
|
|
|
|
var ev = new ActiveTimerTriggerEvent(user);
|
|
RaiseLocalEvent(ent.Owner, ref ev);
|
|
|
|
if (TryComp<AppearanceComponent>(ent, out var appearance))
|
|
_appearance.SetData(ent.Owner, TriggerVisuals.VisualState, TriggerVisualState.Primed, appearance);
|
|
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Stop a timer trigger on an entity with <see cref="TimerTriggerComponent"/>.
|
|
/// </summary>
|
|
/// <returns>Whether or not a timer was stopped.</returns>
|
|
public bool StopTimerTrigger(Entity<TimerTriggerComponent?> ent)
|
|
{
|
|
if (!Resolve(ent, ref ent.Comp))
|
|
return false;
|
|
|
|
if (!HasComp<ActiveTimerTriggerComponent>(ent))
|
|
return false; // the timer is not active
|
|
|
|
RemComp<ActiveTimerTriggerComponent>(ent);
|
|
if (TryComp<AppearanceComponent>(ent.Owner, out var appearance))
|
|
_appearance.SetData(ent.Owner, TriggerVisuals.VisualState, TriggerVisualState.Unprimed, appearance);
|
|
|
|
_adminLogger.Add(LogType.Trigger, $"A timer trigger was stopped before triggering on entity {ToPrettyString(ent.Owner):timer}");
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Delay an active timer trigger.
|
|
/// Returns false if not active.
|
|
/// </summary>
|
|
/// <param name="amount">The time to add.</param>
|
|
public bool TryDelay(Entity<TimerTriggerComponent?> ent, TimeSpan amount)
|
|
{
|
|
if (!Resolve(ent, ref ent.Comp, false) || !HasComp<ActiveTimerTriggerComponent>(ent))
|
|
return false;
|
|
|
|
ent.Comp.NextTrigger += amount;
|
|
Dirty(ent);
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Setter for the Delay datafield.
|
|
/// </summary>
|
|
public void SetDelay(Entity<TimerTriggerComponent?> ent, TimeSpan delay)
|
|
{
|
|
if (!Resolve(ent, ref ent.Comp))
|
|
return;
|
|
|
|
ent.Comp.Delay = delay;
|
|
Dirty(ent);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the remaining time until the trigger will activate.
|
|
/// Returns null if the trigger is not currently active.
|
|
/// </summary>
|
|
public TimeSpan? GetRemainingTime(Entity<TimerTriggerComponent?> ent)
|
|
{
|
|
if (!Resolve(ent, ref ent.Comp, false) || !HasComp<ActiveTimerTriggerComponent>(ent))
|
|
return null; // not a timer or not currently active
|
|
|
|
return ent.Comp.NextTrigger - _timing.CurTime;
|
|
}
|
|
public override void Update(float frameTime)
|
|
{
|
|
base.Update(frameTime);
|
|
|
|
UpdateTimer();
|
|
UpdateRepeat();
|
|
UpdateProximity();
|
|
UpdateTimedCollide();
|
|
}
|
|
}
|