diff --git a/Content.Server/Power/Components/BatteryComponent.cs b/Content.Server/Power/Components/BatteryComponent.cs index b3039d0e13..42d56b1d2b 100644 --- a/Content.Server/Power/Components/BatteryComponent.cs +++ b/Content.Server/Power/Components/BatteryComponent.cs @@ -34,7 +34,7 @@ namespace Content.Server.Power.Components /// public virtual bool TryUseCharge(float chargeToUse) { - if (chargeToUse >= CurrentCharge) + if (chargeToUse > CurrentCharge) { return false; } diff --git a/Content.Server/Stunnable/StunbatonSystem.cs b/Content.Server/Stunnable/StunbatonSystem.cs index 57c6913af2..a868f1c7fd 100644 --- a/Content.Server/Stunnable/StunbatonSystem.cs +++ b/Content.Server/Stunnable/StunbatonSystem.cs @@ -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(OnMeleeHit); SubscribeLocalEvent(OnUseInHand); SubscribeLocalEvent(OnThrowCollide); - SubscribeLocalEvent(OnPowerCellChanged); SubscribeLocalEvent(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(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(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(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(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(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; } diff --git a/Resources/Locale/en-US/stunnable/components/stunbaton-component.ftl b/Resources/Locale/en-US/stunnable/components/stunbaton-component.ftl index a20e5ecd69..8c6f09d098 100644 --- a/Resources/Locale/en-US/stunnable/components/stunbaton-component.ftl +++ b/Resources/Locale/en-US/stunnable/components/stunbaton-component.ftl @@ -7,9 +7,8 @@ comp-stunbaton-examined-off = The light is currently [color=darkred]off[/color] ## Used when activating the stunbaton, depending on the state of its cell. -comp-stunbaton-activated-dead-cell = Dead cell... -comp-stunbaton-activated-missing-cell = Missing cell... +comp-stunbaton-activated-low-charge = Insufficient charge... -stunbaton-component-no-cell = Cell missing... -stunbaton-component-dead-cell = Dead cell... -stunbaton-component-on-examine = The light is currently [color=darkgreen]on[/color]. \ No newline at end of file +stunbaton-component-low-charge = Insufficient charge... +stunbaton-component-on-examine = The light is currently [color=darkgreen]on[/color]. +stunbaton-component-on-examine-charge = The charge indicator reads {$charge} % \ No newline at end of file diff --git a/Resources/Prototypes/Entities/Objects/Weapons/security.yml b/Resources/Prototypes/Entities/Objects/Weapons/security.yml index c31595ec92..1bac5df766 100644 --- a/Resources/Prototypes/Entities/Objects/Weapons/security.yml +++ b/Resources/Prototypes/Entities/Objects/Weapons/security.yml @@ -8,6 +8,7 @@ sprite: Objects/Weapons/Melee/stunbaton.rsi state: stunbaton_off - type: Stunbaton + energyPerUse: 100 - type: MeleeWeapon damage: types: @@ -15,10 +16,9 @@ range: 1.5 arcwidth: 60 arc: default - - type: PowerCellSlot - slotSize: Medium - cellSlot: - startingItem: PowerCellMediumHigh + - type: Battery + maxCharge: 1000 + startingCharge: 1000 - type: ItemCooldown - type: Clothing sprite: Objects/Weapons/Melee/stunbaton.rsi diff --git a/Resources/Prototypes/Entities/Structures/Power/chargers.yml b/Resources/Prototypes/Entities/Structures/Power/chargers.yml index 3785b0fcca..0dbbc9c6a0 100644 --- a/Resources/Prototypes/Entities/Structures/Power/chargers.yml +++ b/Resources/Prototypes/Entities/Structures/Power/chargers.yml @@ -53,6 +53,7 @@ components: - HitscanBatteryAmmoProvider - ProjectileBatteryAmmoProvider + - Stunbaton - type: entity name: wall recharger