Gun refactor (#8301)

Co-authored-by: Kara <lunarautomaton6@gmail.com>
Co-authored-by: T-Stalker <le0nel_1van@hotmail.com>
Co-authored-by: T-Stalker <43253663+DogZeroX@users.noreply.github.com>
Co-authored-by: ElectroJr <leonsfriedrich@gmail.com>
Co-authored-by: metalgearsloth <metalgearsloth@gmail.com>
This commit is contained in:
metalgearsloth
2022-06-01 19:59:58 +10:00
committed by GitHub
parent 1ced3c5002
commit fb943a61dc
1051 changed files with 8230 additions and 99090 deletions

View File

@@ -0,0 +1,59 @@
using Content.Server.Power.Components;
using Content.Shared.Weapons.Ranged.Components;
namespace Content.Server.Weapon.Ranged.Systems;
public sealed partial class GunSystem
{
protected override void InitializeBattery()
{
base.InitializeBattery();
// Hitscan
SubscribeLocalEvent<HitscanBatteryAmmoProviderComponent, ComponentStartup>(OnBatteryStartup);
SubscribeLocalEvent<HitscanBatteryAmmoProviderComponent, ChargeChangedEvent>(OnBatteryChargeChange);
// Projectile
SubscribeLocalEvent<ProjectileBatteryAmmoProviderComponent, ComponentStartup>(OnBatteryStartup);
SubscribeLocalEvent<ProjectileBatteryAmmoProviderComponent, ChargeChangedEvent>(OnBatteryChargeChange);
}
private void OnBatteryStartup(EntityUid uid, BatteryAmmoProviderComponent component, ComponentStartup args)
{
UpdateShots(uid, component);
}
private void OnBatteryChargeChange(EntityUid uid, BatteryAmmoProviderComponent component, ChargeChangedEvent args)
{
UpdateShots(uid, component);
}
private void UpdateShots(EntityUid uid, BatteryAmmoProviderComponent component)
{
if (!TryComp<BatteryComponent>(uid, out var battery)) return;
UpdateShots(component, battery);
}
private void UpdateShots(BatteryAmmoProviderComponent component, BatteryComponent battery)
{
var shots = (int) (battery.CurrentCharge / component.FireCost);
var maxShots = (int) (battery.MaxCharge / component.FireCost);
if (component.Shots != shots || component.Capacity != maxShots)
{
Dirty(component);
}
component.Shots = shots;
component.Capacity = maxShots;
UpdateBatteryAppearance(component.Owner, component);
}
protected override void TakeCharge(EntityUid uid, BatteryAmmoProviderComponent component)
{
if (!TryComp<BatteryComponent>(uid, out var battery)) return;
battery.CurrentCharge -= component.FireCost;
UpdateShots(component, battery);
}
}