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:
themias
2022-06-11 21:20:03 -04:00
committed by GitHub
parent 093d65e92a
commit 1e02a97451
5 changed files with 19 additions and 39 deletions

View File

@@ -34,7 +34,7 @@ namespace Content.Server.Power.Components
/// </summary> /// </summary>
public virtual bool TryUseCharge(float chargeToUse) public virtual bool TryUseCharge(float chargeToUse)
{ {
if (chargeToUse >= CurrentCharge) if (chargeToUse > CurrentCharge)
{ {
return false; return false;
} }

View File

@@ -1,6 +1,6 @@
using System.Linq; using System.Linq;
using Content.Server.Power.Components;
using Content.Server.Power.Events; using Content.Server.Power.Events;
using Content.Server.PowerCell;
using Content.Server.Speech.EntitySystems; using Content.Server.Speech.EntitySystems;
using Content.Server.Stunnable.Components; using Content.Server.Stunnable.Components;
using Content.Server.Weapon.Melee; using Content.Server.Weapon.Melee;
@@ -10,7 +10,6 @@ using Content.Shared.Interaction.Events;
using Content.Shared.Item; using Content.Shared.Item;
using Content.Shared.Jittering; using Content.Shared.Jittering;
using Content.Shared.Popups; using Content.Shared.Popups;
using Content.Shared.PowerCell.Components;
using Content.Shared.StatusEffect; using Content.Shared.StatusEffect;
using Content.Shared.Stunnable; using Content.Shared.Stunnable;
using Content.Shared.Throwing; using Content.Shared.Throwing;
@@ -26,7 +25,6 @@ namespace Content.Server.Stunnable
[Dependency] private readonly StunSystem _stunSystem = default!; [Dependency] private readonly StunSystem _stunSystem = default!;
[Dependency] private readonly StutteringSystem _stutteringSystem = default!; [Dependency] private readonly StutteringSystem _stutteringSystem = default!;
[Dependency] private readonly SharedJitteringSystem _jitterSystem = default!; [Dependency] private readonly SharedJitteringSystem _jitterSystem = default!;
[Dependency] private readonly PowerCellSystem _cellSystem = default!;
[Dependency] private readonly IRobustRandom _robustRandom = default!; [Dependency] private readonly IRobustRandom _robustRandom = default!;
public override void Initialize() public override void Initialize()
@@ -36,7 +34,6 @@ namespace Content.Server.Stunnable
SubscribeLocalEvent<StunbatonComponent, MeleeHitEvent>(OnMeleeHit); SubscribeLocalEvent<StunbatonComponent, MeleeHitEvent>(OnMeleeHit);
SubscribeLocalEvent<StunbatonComponent, UseInHandEvent>(OnUseInHand); SubscribeLocalEvent<StunbatonComponent, UseInHandEvent>(OnUseInHand);
SubscribeLocalEvent<StunbatonComponent, ThrowDoHitEvent>(OnThrowCollide); SubscribeLocalEvent<StunbatonComponent, ThrowDoHitEvent>(OnThrowCollide);
SubscribeLocalEvent<StunbatonComponent, PowerCellChangedEvent>(OnPowerCellChanged);
SubscribeLocalEvent<StunbatonComponent, ExaminedEvent>(OnExamined); SubscribeLocalEvent<StunbatonComponent, ExaminedEvent>(OnExamined);
} }
@@ -45,7 +42,7 @@ namespace Content.Server.Stunnable
if (!comp.Activated || !args.HitEntities.Any() || args.Handled) if (!comp.Activated || !args.HitEntities.Any() || args.Handled)
return; return;
if (!_cellSystem.TryGetBatteryFromSlot(uid, out var battery) || !battery.TryUseCharge(comp.EnergyPerUse)) if (!TryComp<BatteryComponent>(uid, out var battery) || !battery.TryUseCharge(comp.EnergyPerUse))
return; return;
foreach (EntityUid entity in args.HitEntities) foreach (EntityUid entity in args.HitEntities)
@@ -75,7 +72,7 @@ namespace Content.Server.Stunnable
if (!comp.Activated) if (!comp.Activated)
return; return;
if (!_cellSystem.TryGetBatteryFromSlot(uid, out var battery)) if (!TryComp<BatteryComponent>(uid, out var battery))
return; return;
if (_robustRandom.Prob(comp.OnThrowStunChance) && battery.TryUseCharge(comp.EnergyPerUse)) 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) private void OnExamined(EntityUid uid, StunbatonComponent comp, ExaminedEvent args)
{ {
var msg = comp.Activated var msg = comp.Activated
? Loc.GetString("comp-stunbaton-examined-on") ? Loc.GetString("comp-stunbaton-examined-on")
: Loc.GetString("comp-stunbaton-examined-off"); : Loc.GetString("comp-stunbaton-examined-off");
args.PushMarkup(msg); 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) private void StunEntity(EntityUid entity, StunbatonComponent comp)
@@ -132,7 +119,7 @@ namespace Content.Server.Stunnable
_jitterSystem.DoJitter(entity, slowdownTime, true, status:status); _jitterSystem.DoJitter(entity, slowdownTime, true, status:status);
_stutteringSystem.DoStutter(entity, slowdownTime, true, 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; return;
SoundSystem.Play(Filter.Pvs(comp.Owner), comp.SparksSound.GetSound(), comp.Owner, AudioHelpers.WithVariation(0.25f)); SoundSystem.Play(Filter.Pvs(comp.Owner), comp.SparksSound.GetSound(), comp.Owner, AudioHelpers.WithVariation(0.25f));
@@ -168,17 +155,10 @@ namespace Content.Server.Stunnable
return; return;
var playerFilter = Filter.Pvs(comp.Owner); 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)); SoundSystem.Play(playerFilter, comp.TurnOnFailSound.GetSound(), comp.Owner, AudioHelpers.WithVariation(0.25f));
user.PopupMessage(Loc.GetString("comp-stunbaton-activated-missing-cell")); user.PopupMessage(Loc.GetString("stunbaton-component-low-charge"));
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"));
return; return;
} }

View File

@@ -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. ## Used when activating the stunbaton, depending on the state of its cell.
comp-stunbaton-activated-dead-cell = Dead cell... comp-stunbaton-activated-low-charge = Insufficient charge...
comp-stunbaton-activated-missing-cell = Missing cell...
stunbaton-component-no-cell = Cell missing... stunbaton-component-low-charge = Insufficient charge...
stunbaton-component-dead-cell = Dead cell... stunbaton-component-on-examine = The light is currently [color=darkgreen]on[/color].
stunbaton-component-on-examine = The light is currently [color=darkgreen]on[/color]. stunbaton-component-on-examine-charge = The charge indicator reads {$charge} %

View File

@@ -8,6 +8,7 @@
sprite: Objects/Weapons/Melee/stunbaton.rsi sprite: Objects/Weapons/Melee/stunbaton.rsi
state: stunbaton_off state: stunbaton_off
- type: Stunbaton - type: Stunbaton
energyPerUse: 100
- type: MeleeWeapon - type: MeleeWeapon
damage: damage:
types: types:
@@ -15,10 +16,9 @@
range: 1.5 range: 1.5
arcwidth: 60 arcwidth: 60
arc: default arc: default
- type: PowerCellSlot - type: Battery
slotSize: Medium maxCharge: 1000
cellSlot: startingCharge: 1000
startingItem: PowerCellMediumHigh
- type: ItemCooldown - type: ItemCooldown
- type: Clothing - type: Clothing
sprite: Objects/Weapons/Melee/stunbaton.rsi sprite: Objects/Weapons/Melee/stunbaton.rsi

View File

@@ -53,6 +53,7 @@
components: components:
- HitscanBatteryAmmoProvider - HitscanBatteryAmmoProvider
- ProjectileBatteryAmmoProvider - ProjectileBatteryAmmoProvider
- Stunbaton
- type: entity - type: entity
name: wall recharger name: wall recharger