/// <summary>
/// Indicates that this gun requires wielding to be useable.
/// </summary>
-[RegisterComponent, NetworkedComponent, Access(typeof(WieldableSystem))]
+[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
+[Access(typeof(WieldableSystem))]
public sealed partial class GunRequiresWieldComponent : Component
{
+ [DataField, AutoNetworkedField]
+ public TimeSpan LastPopup;
+ [DataField, AutoNetworkedField]
+ public TimeSpan PopupCooldown = TimeSpan.FromSeconds(1);
}
using Content.Shared.Weapons.Ranged.Systems;
using Content.Shared.Wieldable.Components;
using Robust.Shared.Audio.Systems;
-using Robust.Shared.Player;
+using Robust.Shared.Timing;
namespace Content.Shared.Wieldable;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly UseDelaySystem _delay = default!;
[Dependency] private readonly SharedGunSystem _gun = default!;
+ [Dependency] private readonly IGameTiming _timing = default!;
public override void Initialize()
{
SubscribeLocalEvent<WieldableComponent, GetVerbsEvent<InteractionVerb>>(AddToggleWieldVerb);
SubscribeLocalEvent<MeleeRequiresWieldComponent, AttemptMeleeEvent>(OnMeleeAttempt);
- SubscribeLocalEvent<GunRequiresWieldComponent, AttemptShootEvent>(OnShootAttempt);
+ SubscribeLocalEvent<GunRequiresWieldComponent, ShotAttemptedEvent>(OnShootAttempt);
SubscribeLocalEvent<GunWieldBonusComponent, ItemWieldedEvent>(OnGunWielded);
SubscribeLocalEvent<GunWieldBonusComponent, ItemUnwieldedEvent>(OnGunUnwielded);
SubscribeLocalEvent<GunWieldBonusComponent, GunRefreshModifiersEvent>(OnGunRefreshModifiers);
}
}
- private void OnShootAttempt(EntityUid uid, GunRequiresWieldComponent component, ref AttemptShootEvent args)
+ private void OnShootAttempt(EntityUid uid, GunRequiresWieldComponent component, ref ShotAttemptedEvent args)
{
if (TryComp<WieldableComponent>(uid, out var wieldable) &&
!wieldable.Wielded)
{
- args.Cancelled = true;
+ args.Cancel();
- if (!HasComp<MeleeWeaponComponent>(uid) && !HasComp<MeleeRequiresWieldComponent>(uid))
+ var time = _timing.CurTime;
+ if (time > component.LastPopup + component.PopupCooldown &&
+ !HasComp<MeleeWeaponComponent>(uid) &&
+ !HasComp<MeleeRequiresWieldComponent>(uid))
{
- args.Message = Loc.GetString("wieldable-component-requires", ("item", uid));
+ component.LastPopup = time;
+ var message = Loc.GetString("wieldable-component-requires", ("item", uid));
+ _popupSystem.PopupClient(message, args.Used, args.User);
}
}
}