Tweak stun batons to use a battery instead of power cell (#8716)
* Allow baton/battery to be inserted into recharger * Revert "Allow baton/battery to be inserted into recharger" This reverts commit ccf1f3d1827bf45c49bb6ca4f5c97990d1afba6e. * Refactor stun batons to use internal batteries
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
using System.Linq;
|
||||
using Content.Server.Power.Components;
|
||||
using Content.Server.Power.Events;
|
||||
using Content.Server.PowerCell;
|
||||
using Content.Server.Speech.EntitySystems;
|
||||
using Content.Server.Stunnable.Components;
|
||||
using Content.Server.Weapon.Melee;
|
||||
@@ -10,7 +10,6 @@ using Content.Shared.Interaction.Events;
|
||||
using Content.Shared.Item;
|
||||
using Content.Shared.Jittering;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.PowerCell.Components;
|
||||
using Content.Shared.StatusEffect;
|
||||
using Content.Shared.Stunnable;
|
||||
using Content.Shared.Throwing;
|
||||
@@ -26,7 +25,6 @@ namespace Content.Server.Stunnable
|
||||
[Dependency] private readonly StunSystem _stunSystem = default!;
|
||||
[Dependency] private readonly StutteringSystem _stutteringSystem = default!;
|
||||
[Dependency] private readonly SharedJitteringSystem _jitterSystem = default!;
|
||||
[Dependency] private readonly PowerCellSystem _cellSystem = default!;
|
||||
[Dependency] private readonly IRobustRandom _robustRandom = default!;
|
||||
|
||||
public override void Initialize()
|
||||
@@ -36,7 +34,6 @@ namespace Content.Server.Stunnable
|
||||
SubscribeLocalEvent<StunbatonComponent, MeleeHitEvent>(OnMeleeHit);
|
||||
SubscribeLocalEvent<StunbatonComponent, UseInHandEvent>(OnUseInHand);
|
||||
SubscribeLocalEvent<StunbatonComponent, ThrowDoHitEvent>(OnThrowCollide);
|
||||
SubscribeLocalEvent<StunbatonComponent, PowerCellChangedEvent>(OnPowerCellChanged);
|
||||
SubscribeLocalEvent<StunbatonComponent, ExaminedEvent>(OnExamined);
|
||||
}
|
||||
|
||||
@@ -45,7 +42,7 @@ namespace Content.Server.Stunnable
|
||||
if (!comp.Activated || !args.HitEntities.Any() || args.Handled)
|
||||
return;
|
||||
|
||||
if (!_cellSystem.TryGetBatteryFromSlot(uid, out var battery) || !battery.TryUseCharge(comp.EnergyPerUse))
|
||||
if (!TryComp<BatteryComponent>(uid, out var battery) || !battery.TryUseCharge(comp.EnergyPerUse))
|
||||
return;
|
||||
|
||||
foreach (EntityUid entity in args.HitEntities)
|
||||
@@ -75,7 +72,7 @@ namespace Content.Server.Stunnable
|
||||
if (!comp.Activated)
|
||||
return;
|
||||
|
||||
if (!_cellSystem.TryGetBatteryFromSlot(uid, out var battery))
|
||||
if (!TryComp<BatteryComponent>(uid, out var battery))
|
||||
return;
|
||||
|
||||
if (_robustRandom.Prob(comp.OnThrowStunChance) && battery.TryUseCharge(comp.EnergyPerUse))
|
||||
@@ -85,25 +82,15 @@ namespace Content.Server.Stunnable
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPowerCellChanged(EntityUid uid, StunbatonComponent comp, PowerCellChangedEvent args)
|
||||
{
|
||||
if (!comp.Activated)
|
||||
return;
|
||||
|
||||
if (args.Ejected
|
||||
|| !_cellSystem.TryGetBatteryFromSlot(comp.Owner, out var battery)
|
||||
|| battery.CurrentCharge < comp.EnergyPerUse)
|
||||
{
|
||||
TurnOff(comp);
|
||||
}
|
||||
}
|
||||
|
||||
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");
|
||||
args.PushMarkup(msg);
|
||||
if(TryComp<BatteryComponent>(uid, out var battery))
|
||||
args.PushMarkup(Loc.GetString("stunbaton-component-on-examine-charge",
|
||||
("charge", (int)((battery.CurrentCharge/battery.MaxCharge) * 100))));
|
||||
}
|
||||
|
||||
private void StunEntity(EntityUid entity, StunbatonComponent comp)
|
||||
@@ -132,7 +119,7 @@ namespace Content.Server.Stunnable
|
||||
_jitterSystem.DoJitter(entity, slowdownTime, true, status:status);
|
||||
_stutteringSystem.DoStutter(entity, slowdownTime, true, status);
|
||||
|
||||
if (!_cellSystem.TryGetBatteryFromSlot(comp.Owner, out var battery) || !(battery.CurrentCharge < comp.EnergyPerUse))
|
||||
if (!TryComp<BatteryComponent>(comp.Owner, out var battery) || !(battery.CurrentCharge < comp.EnergyPerUse))
|
||||
return;
|
||||
|
||||
SoundSystem.Play(Filter.Pvs(comp.Owner), comp.SparksSound.GetSound(), comp.Owner, AudioHelpers.WithVariation(0.25f));
|
||||
@@ -168,17 +155,10 @@ namespace Content.Server.Stunnable
|
||||
return;
|
||||
|
||||
var playerFilter = Filter.Pvs(comp.Owner);
|
||||
if (!_cellSystem.TryGetBatteryFromSlot(comp.Owner, out var battery))
|
||||
if (!TryComp<BatteryComponent>(comp.Owner, out var battery) || battery.CurrentCharge < comp.EnergyPerUse)
|
||||
{
|
||||
SoundSystem.Play(playerFilter, comp.TurnOnFailSound.GetSound(), comp.Owner, AudioHelpers.WithVariation(0.25f));
|
||||
user.PopupMessage(Loc.GetString("comp-stunbaton-activated-missing-cell"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (battery.CurrentCharge < comp.EnergyPerUse)
|
||||
{
|
||||
SoundSystem.Play(playerFilter, comp.TurnOnFailSound.GetSound(), comp.Owner, AudioHelpers.WithVariation(0.25f));
|
||||
user.PopupMessage(Loc.GetString("comp-stunbaton-activated-dead-cell"));
|
||||
user.PopupMessage(Loc.GetString("stunbaton-component-low-charge"));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user