BatteryWeaponPowerCell tweaks (#33500)

* BatteryWeaponPowerCell tweaks

* add update ammo ev & shuttle guns tweaks

* MilonPL requested changes

* revert changes in OnPowerCellChanged

* Add events to get charge info & change current charge

---------

Co-authored-by: Nemanja <98561806+EmoGarbage404@users.noreply.github.com>
This commit is contained in:
Kirus59
2025-04-29 04:12:25 +03:00
committed by GitHub
parent a8054c37b1
commit 8c38aa3742
9 changed files with 138 additions and 43 deletions

View File

@@ -2,9 +2,11 @@ using Content.Server.Power.Components;
using Content.Shared.Damage;
using Content.Shared.Damage.Events;
using Content.Shared.FixedPoint;
using Content.Shared.PowerCell.Components;
using Content.Shared.Projectiles;
using Content.Shared.Weapons.Ranged;
using Content.Shared.Weapons.Ranged.Components;
using Content.Shared.Weapons.Ranged.Events;
using Robust.Shared.Prototypes;
namespace Content.Server.Weapons.Ranged.Systems;
@@ -19,29 +21,36 @@ public sealed partial class GunSystem
SubscribeLocalEvent<HitscanBatteryAmmoProviderComponent, ComponentStartup>(OnBatteryStartup);
SubscribeLocalEvent<HitscanBatteryAmmoProviderComponent, ChargeChangedEvent>(OnBatteryChargeChange);
SubscribeLocalEvent<HitscanBatteryAmmoProviderComponent, DamageExamineEvent>(OnBatteryDamageExamine);
SubscribeLocalEvent<HitscanBatteryAmmoProviderComponent, PowerCellChangedEvent>(OnPowerCellChanged);
// Projectile
SubscribeLocalEvent<ProjectileBatteryAmmoProviderComponent, ComponentStartup>(OnBatteryStartup);
SubscribeLocalEvent<ProjectileBatteryAmmoProviderComponent, ChargeChangedEvent>(OnBatteryChargeChange);
SubscribeLocalEvent<ProjectileBatteryAmmoProviderComponent, DamageExamineEvent>(OnBatteryDamageExamine);
SubscribeLocalEvent<ProjectileBatteryAmmoProviderComponent, PowerCellChangedEvent>(OnPowerCellChanged);
}
private void OnBatteryStartup(EntityUid uid, BatteryAmmoProviderComponent component, ComponentStartup args)
private void OnBatteryStartup<T>(Entity<T> entity, ref ComponentStartup args) where T : BatteryAmmoProviderComponent
{
UpdateShots(uid, component);
UpdateShots(entity, entity.Comp);
}
private void OnBatteryChargeChange(EntityUid uid, BatteryAmmoProviderComponent component, ref ChargeChangedEvent args)
private void OnBatteryChargeChange<T>(Entity<T> entity, ref ChargeChangedEvent args) where T : BatteryAmmoProviderComponent
{
UpdateShots(uid, component, args.Charge, args.MaxCharge);
UpdateShots(entity, entity.Comp, args.Charge, args.MaxCharge);
}
private void OnPowerCellChanged<T>(Entity<T> entity, ref PowerCellChangedEvent args) where T : BatteryAmmoProviderComponent
{
UpdateShots(entity, entity.Comp);
}
private void UpdateShots(EntityUid uid, BatteryAmmoProviderComponent component)
{
if (!TryComp<BatteryComponent>(uid, out var battery))
return;
var ev = new GetChargeEvent();
RaiseLocalEvent(uid, ref ev);
UpdateShots(uid, component, battery.CurrentCharge, battery.MaxCharge);
UpdateShots(uid, component, ev.CurrentCharge, ev.MaxCharge);
}
private void UpdateShots(EntityUid uid, BatteryAmmoProviderComponent component, float charge, float maxCharge)
@@ -55,18 +64,24 @@ public sealed partial class GunSystem
}
component.Shots = shots;
component.Capacity = maxShots;
if (maxShots > 0)
component.Capacity = maxShots;
UpdateBatteryAppearance(uid, component);
var updateAmmoEv = new UpdateClientAmmoEvent();
RaiseLocalEvent(uid, ref updateAmmoEv);
}
private void OnBatteryDamageExamine(EntityUid uid, BatteryAmmoProviderComponent component, ref DamageExamineEvent args)
private void OnBatteryDamageExamine<T>(Entity<T> entity, ref DamageExamineEvent args) where T : BatteryAmmoProviderComponent
{
var damageSpec = GetDamage(component);
var damageSpec = GetDamage(entity.Comp);
if (damageSpec == null)
return;
var damageType = component switch
var damageType = entity.Comp switch
{
HitscanBatteryAmmoProviderComponent => Loc.GetString("damage-hitscan"),
ProjectileBatteryAmmoProviderComponent => Loc.GetString("damage-projectile"),
@@ -103,9 +118,9 @@ public sealed partial class GunSystem
return null;
}
protected override void TakeCharge(EntityUid uid, BatteryAmmoProviderComponent component)
protected override void TakeCharge(Entity<BatteryAmmoProviderComponent> entity)
{
// Will raise ChargeChangedEvent
_battery.UseCharge(uid, component.FireCost);
var ev = new ChangeChargeEvent(-entity.Comp.FireCost);
RaiseLocalEvent(entity, ref ev);
}
}

View File

@@ -22,6 +22,7 @@ using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;
using Robust.Shared.Containers;
using Content.Server.PowerCell;
namespace Content.Server.Weapons.Ranged.Systems;
@@ -34,6 +35,7 @@ public sealed partial class GunSystem : SharedGunSystem
[Dependency] private readonly SharedColorFlashEffectSystem _color = default!;
[Dependency] private readonly StaminaSystem _stamina = default!;
[Dependency] private readonly SharedContainerSystem _container = default!;
[Dependency] private readonly PowerCellSystem _powerCell = default!;
[Dependency] private readonly SharedMapSystem _map = default!;
private const float DamagePitchVariation = 0.05f;