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>
public virtual bool TryUseCharge(float chargeToUse)
{
if (chargeToUse >= CurrentCharge)
if (chargeToUse > CurrentCharge)
{
return false;
}

View File

@@ -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;
}

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.
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-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} %

View File

@@ -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

View File

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