2023-07-08 06:32:31 +03:00
|
|
|
using Content.Server.Chemistry.EntitySystems;
|
2022-06-11 21:20:03 -04:00
|
|
|
using Content.Server.Power.Components;
|
2023-07-08 06:32:31 +03:00
|
|
|
using Content.Server.Power.EntitySystems;
|
2022-02-19 22:16:49 +03:00
|
|
|
using Content.Server.Power.Events;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Server.Stunnable.Components;
|
2021-06-05 00:20:52 -07:00
|
|
|
using Content.Shared.Audio;
|
2022-11-09 07:34:07 +11:00
|
|
|
using Content.Shared.Damage.Events;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Examine;
|
2022-03-13 01:33:23 +13:00
|
|
|
using Content.Shared.Interaction.Events;
|
2021-12-30 22:56:10 +01:00
|
|
|
using Content.Shared.Item;
|
2021-12-05 21:02:04 +01:00
|
|
|
using Content.Shared.Popups;
|
2023-08-08 23:19:31 +03:00
|
|
|
using Content.Shared.Stunnable;
|
2022-07-24 23:39:21 +12:00
|
|
|
using Content.Shared.Toggleable;
|
2021-06-05 00:20:52 -07:00
|
|
|
using Robust.Shared.Audio;
|
|
|
|
|
using Robust.Shared.Player;
|
|
|
|
|
|
2022-07-06 18:06:12 +10:00
|
|
|
namespace Content.Server.Stunnable.Systems
|
2021-06-05 00:20:52 -07:00
|
|
|
{
|
2023-08-08 23:19:31 +03:00
|
|
|
public sealed class StunbatonSystem : SharedStunbatonSystem
|
2021-06-05 00:20:52 -07:00
|
|
|
{
|
2022-07-27 03:53:47 -07:00
|
|
|
[Dependency] private readonly SharedItemSystem _item = default!;
|
2023-02-02 17:34:53 +01:00
|
|
|
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
2023-07-08 06:32:31 +03:00
|
|
|
[Dependency] private readonly RiggableSystem _riggableSystem = default!;
|
2022-07-27 03:53:47 -07:00
|
|
|
|
2021-06-05 00:20:52 -07:00
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
|
|
|
|
SubscribeLocalEvent<StunbatonComponent, UseInHandEvent>(OnUseInHand);
|
|
|
|
|
SubscribeLocalEvent<StunbatonComponent, ExaminedEvent>(OnExamined);
|
2023-07-08 06:32:31 +03:00
|
|
|
SubscribeLocalEvent<StunbatonComponent, SolutionChangedEvent>(OnSolutionChange);
|
2022-07-06 18:06:12 +10:00
|
|
|
SubscribeLocalEvent<StunbatonComponent, StaminaDamageOnHitAttemptEvent>(OnStaminaHitAttempt);
|
|
|
|
|
}
|
2021-06-05 00:20:52 -07:00
|
|
|
|
2022-07-06 18:06:12 +10:00
|
|
|
private void OnStaminaHitAttempt(EntityUid uid, StunbatonComponent component, ref StaminaDamageOnHitAttemptEvent args)
|
|
|
|
|
{
|
|
|
|
|
if (!component.Activated ||
|
|
|
|
|
!TryComp<BatteryComponent>(uid, out var battery) || !battery.TryUseCharge(component.EnergyPerUse))
|
2021-06-05 00:20:52 -07:00
|
|
|
{
|
2022-07-06 18:06:12 +10:00
|
|
|
args.Cancelled = true;
|
|
|
|
|
return;
|
2021-06-05 00:20:52 -07:00
|
|
|
}
|
|
|
|
|
|
2022-07-06 18:06:12 +10:00
|
|
|
if (battery.CurrentCharge < component.EnergyPerUse)
|
|
|
|
|
{
|
|
|
|
|
SoundSystem.Play(component.SparksSound.GetSound(), Filter.Pvs(component.Owner, entityManager: EntityManager), uid, AudioHelpers.WithVariation(0.25f));
|
2023-02-02 17:34:53 +01:00
|
|
|
TurnOff(uid, component);
|
2022-07-06 18:06:12 +10:00
|
|
|
}
|
2021-06-05 00:20:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnUseInHand(EntityUid uid, StunbatonComponent comp, UseInHandEvent args)
|
|
|
|
|
{
|
|
|
|
|
if (comp.Activated)
|
|
|
|
|
{
|
2023-02-02 17:34:53 +01:00
|
|
|
TurnOff(uid, comp);
|
2021-06-05 00:20:52 -07:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2023-02-02 17:34:53 +01:00
|
|
|
TurnOn(uid, comp, args.User);
|
2021-06-05 00:20:52 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnExamined(EntityUid uid, StunbatonComponent comp, ExaminedEvent args)
|
|
|
|
|
{
|
|
|
|
|
var msg = comp.Activated
|
|
|
|
|
? Loc.GetString("comp-stunbaton-examined-on")
|
|
|
|
|
: Loc.GetString("comp-stunbaton-examined-off");
|
2021-09-15 16:58:15 +02:00
|
|
|
args.PushMarkup(msg);
|
2022-06-11 21:20:03 -04:00
|
|
|
if(TryComp<BatteryComponent>(uid, out var battery))
|
|
|
|
|
args.PushMarkup(Loc.GetString("stunbaton-component-on-examine-charge",
|
|
|
|
|
("charge", (int)((battery.CurrentCharge/battery.MaxCharge) * 100))));
|
2021-06-05 00:20:52 -07:00
|
|
|
}
|
|
|
|
|
|
2023-02-02 17:34:53 +01:00
|
|
|
private void TurnOff(EntityUid uid, StunbatonComponent comp)
|
2021-06-05 00:20:52 -07:00
|
|
|
{
|
|
|
|
|
if (!comp.Activated)
|
|
|
|
|
return;
|
|
|
|
|
|
2022-07-27 03:53:47 -07:00
|
|
|
if (TryComp<AppearanceComponent>(comp.Owner, out var appearance) &&
|
|
|
|
|
TryComp<ItemComponent>(comp.Owner, out var item))
|
|
|
|
|
{
|
|
|
|
|
_item.SetHeldPrefix(comp.Owner, "off", item);
|
2023-02-02 17:34:53 +01:00
|
|
|
_appearance.SetData(uid, ToggleVisuals.Toggled, false, appearance);
|
2022-07-27 03:53:47 -07:00
|
|
|
}
|
2021-06-05 00:20:52 -07:00
|
|
|
|
2022-06-12 19:45:47 -04:00
|
|
|
SoundSystem.Play(comp.SparksSound.GetSound(), Filter.Pvs(comp.Owner), comp.Owner, AudioHelpers.WithVariation(0.25f));
|
2022-06-27 17:51:38 +10:00
|
|
|
|
2021-06-05 00:20:52 -07:00
|
|
|
comp.Activated = false;
|
2023-08-08 23:19:31 +03:00
|
|
|
Dirty(comp);
|
2021-06-05 00:20:52 -07:00
|
|
|
}
|
|
|
|
|
|
2023-02-02 17:34:53 +01:00
|
|
|
private void TurnOn(EntityUid uid, StunbatonComponent comp, EntityUid user)
|
2021-06-05 00:20:52 -07:00
|
|
|
{
|
2023-07-08 06:32:31 +03:00
|
|
|
|
2021-06-05 00:20:52 -07:00
|
|
|
if (comp.Activated)
|
|
|
|
|
return;
|
|
|
|
|
|
2022-06-27 17:51:38 +10:00
|
|
|
var playerFilter = Filter.Pvs(comp.Owner, entityManager: EntityManager);
|
2022-06-11 21:20:03 -04:00
|
|
|
if (!TryComp<BatteryComponent>(comp.Owner, out var battery) || battery.CurrentCharge < comp.EnergyPerUse)
|
2021-06-05 00:20:52 -07:00
|
|
|
{
|
2023-07-08 06:32:31 +03:00
|
|
|
|
2022-06-12 19:45:47 -04:00
|
|
|
SoundSystem.Play(comp.TurnOnFailSound.GetSound(), playerFilter, comp.Owner, AudioHelpers.WithVariation(0.25f));
|
2022-06-11 21:20:03 -04:00
|
|
|
user.PopupMessage(Loc.GetString("stunbaton-component-low-charge"));
|
2021-06-05 00:20:52 -07:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-08 06:32:31 +03:00
|
|
|
if (TryComp<RiggableComponent>(uid, out var rig) && rig.IsRigged)
|
|
|
|
|
{
|
|
|
|
|
_riggableSystem.Explode(uid, battery, user);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2022-07-27 03:53:47 -07:00
|
|
|
if (EntityManager.TryGetComponent<AppearanceComponent>(comp.Owner, out var appearance) &&
|
|
|
|
|
EntityManager.TryGetComponent<ItemComponent>(comp.Owner, out var item))
|
|
|
|
|
{
|
|
|
|
|
_item.SetHeldPrefix(comp.Owner, "on", item);
|
2023-02-02 17:34:53 +01:00
|
|
|
_appearance.SetData(uid, ToggleVisuals.Toggled, true, appearance);
|
2022-07-27 03:53:47 -07:00
|
|
|
}
|
2022-07-06 18:06:12 +10:00
|
|
|
|
|
|
|
|
SoundSystem.Play(comp.SparksSound.GetSound(), playerFilter, comp.Owner, AudioHelpers.WithVariation(0.25f));
|
|
|
|
|
comp.Activated = true;
|
2023-08-08 23:19:31 +03:00
|
|
|
Dirty(comp);
|
2021-06-05 00:20:52 -07:00
|
|
|
}
|
2022-02-19 22:16:49 +03:00
|
|
|
|
2023-07-08 06:32:31 +03:00
|
|
|
// https://github.com/space-wizards/space-station-14/pull/17288#discussion_r1241213341
|
|
|
|
|
private void OnSolutionChange(EntityUid uid, StunbatonComponent component, SolutionChangedEvent args)
|
|
|
|
|
{
|
|
|
|
|
// Explode if baton is activated and rigged.
|
|
|
|
|
if (TryComp<RiggableComponent>(uid, out var riggable))
|
|
|
|
|
if (TryComp<BatteryComponent>(uid, out var battery))
|
|
|
|
|
if (component.Activated && riggable.IsRigged)
|
|
|
|
|
_riggableSystem.Explode(uid, battery);
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-19 22:16:49 +03:00
|
|
|
private void SendPowerPulse(EntityUid target, EntityUid? user, EntityUid used)
|
|
|
|
|
{
|
|
|
|
|
RaiseLocalEvent(target, new PowerPulseEvent()
|
|
|
|
|
{
|
|
|
|
|
Used = used,
|
|
|
|
|
User = user
|
|
|
|
|
}, false);
|
|
|
|
|
}
|
2021-06-05 00:20:52 -07:00
|
|
|
}
|
|
|
|
|
}
|