Add Modular grenades (chemnades). (#7138)
This commit is contained in:
@@ -1,32 +1,119 @@
|
||||
using System;
|
||||
using Content.Server.Explosion.Components;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Interaction.Events;
|
||||
using Content.Shared.Trigger;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Content.Shared.Verbs;
|
||||
using Robust.Shared.Player;
|
||||
|
||||
namespace Content.Server.Explosion.EntitySystems;
|
||||
|
||||
public sealed partial class TriggerSystem
|
||||
{
|
||||
[Dependency] private readonly SharedPopupSystem _popupSystem = default!;
|
||||
|
||||
private void InitializeOnUse()
|
||||
{
|
||||
SubscribeLocalEvent<OnUseTimerTriggerComponent, UseInHandEvent>(OnTimerUse);
|
||||
SubscribeLocalEvent<OnUseTimerTriggerComponent, ExaminedEvent>(OnExamined);
|
||||
SubscribeLocalEvent<OnUseTimerTriggerComponent, GetVerbsEvent<AlternativeVerb>>(OnGetAltVerbs);
|
||||
}
|
||||
|
||||
private void OnExamined(EntityUid uid, OnUseTimerTriggerComponent component, ExaminedEvent args)
|
||||
{
|
||||
if (args.IsInDetailsRange)
|
||||
args.PushText(Loc.GetString("examine-trigger-timer", ("time", component.Delay)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add an alt-click interaction that cycles through delays.
|
||||
/// </summary>
|
||||
private void OnGetAltVerbs(EntityUid uid, OnUseTimerTriggerComponent component, GetVerbsEvent<AlternativeVerb> args)
|
||||
{
|
||||
if (!args.CanInteract || !args.CanAccess)
|
||||
return;
|
||||
|
||||
if (component.DelayOptions == null || component.DelayOptions.Count == 1)
|
||||
return;
|
||||
|
||||
args.Verbs.Add(new AlternativeVerb()
|
||||
{
|
||||
Category = TimerOptions,
|
||||
Text = Loc.GetString("verb-trigger-timer-cycle"),
|
||||
Act = () => CycleDelay(component, args.User),
|
||||
Priority = 1
|
||||
});
|
||||
|
||||
foreach (var option in component.DelayOptions)
|
||||
{
|
||||
if (MathHelper.CloseTo(option, component.Delay))
|
||||
{
|
||||
args.Verbs.Add(new AlternativeVerb()
|
||||
{
|
||||
Category = TimerOptions,
|
||||
Text = Loc.GetString("verb-trigger-timer-set-current", ("time", option)),
|
||||
Disabled = true,
|
||||
Priority = (int) (-100 * option)
|
||||
});
|
||||
continue;
|
||||
}
|
||||
|
||||
args.Verbs.Add(new AlternativeVerb()
|
||||
{
|
||||
Category = TimerOptions,
|
||||
Text = Loc.GetString("verb-trigger-timer-set", ("time", option)),
|
||||
Priority = (int) (-100 * option),
|
||||
|
||||
Act = () =>
|
||||
{
|
||||
component.Delay = option;
|
||||
_popupSystem.PopupEntity(Loc.GetString("popup-trigger-timer-set", ("time", option)), args.User, Filter.Entities(args.User));
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void CycleDelay(OnUseTimerTriggerComponent component, EntityUid user)
|
||||
{
|
||||
if (component.DelayOptions == null || component.DelayOptions.Count == 1)
|
||||
return;
|
||||
|
||||
// This is somewhat inefficient, but its good enough. This is run rarely, and the lists should be short.
|
||||
|
||||
component.DelayOptions.Sort();
|
||||
|
||||
if (component.DelayOptions[^1] <= component.Delay)
|
||||
{
|
||||
component.Delay = component.DelayOptions[0];
|
||||
_popupSystem.PopupEntity(Loc.GetString("popup-trigger-timer-set", ("time", component.Delay)), user, Filter.Entities(user));
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var option in component.DelayOptions)
|
||||
{
|
||||
if (option > component.Delay)
|
||||
{
|
||||
component.Delay = option;
|
||||
_popupSystem.PopupEntity(Loc.GetString("popup-trigger-timer-set", ("time", option)), user, Filter.Entities(user));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTimerUse(EntityUid uid, OnUseTimerTriggerComponent component, UseInHandEvent args)
|
||||
{
|
||||
if (args.Handled) return;
|
||||
|
||||
Trigger(uid, args.User, component);
|
||||
HandleTimerTrigger(
|
||||
uid,
|
||||
args.User,
|
||||
component.Delay,
|
||||
component.BeepInterval,
|
||||
component.InitialBeepDelay,
|
||||
component.BeepSound,
|
||||
component.BeepParams);
|
||||
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
// TODO: Need to split this out so it's a generic "OnUseTimerTrigger" component.
|
||||
private void Trigger(EntityUid uid, EntityUid user, OnUseTimerTriggerComponent component)
|
||||
{
|
||||
if (TryComp<AppearanceComponent>(uid, out var appearance))
|
||||
appearance.SetData(TriggerVisuals.VisualState, TriggerVisualState.Primed);
|
||||
|
||||
HandleTimerTrigger(TimeSpan.FromSeconds(component.Delay), uid, user);
|
||||
}
|
||||
public static VerbCategory TimerOptions = new("verb-categories-timer", "/Textures/Interface/VerbIcons/clock.svg.192dpi.png");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user