Files
wwdpublic/Content.Server/Weapons/Ranged/Systems/GunSystem.Battery.cs
RedFoxIV 0536fc8645 Fuselage rust stage 2 (#629)
* the definition of insanity

* the definition of insanity

* the definition of insanity

* we have hullrot at home

* maybe the real hullrot was the friends we made along the way

* john hullrot

* i am going to hullroooooot

* it's hullrotver

* we're so hullback

* we're rotting the hull with this one

* hullmerge

* the hullrot is leaking

* never gonna rot you up

* hullfresh

* john starsector

* god i wish we had grid collision damage

* you can tell I am very tired because I stopped forcing a hullrot joke into every commit message

* hr

* this is a surprise sprite that will help us later

* motherfucker

* i have nothing good to say

* still nothing

* brb

* random letter random letter random letter dash random number random number random number

* ass

* blast

* ffs

* fcuk

* RE: ffs

* RE: RE: ffs

* гнида жестяная

* continue

* i hate tests

* i love tests

* slide to the right

* i hate tests again

* what the fuck

* ты шиз?

* ??

* bbgun
2025-06-28 11:31:07 +03:00

169 lines
7.2 KiB
C#

using Content.Server.Power.Components;
using Content.Server.Power.EntitySystems;
using Content.Server.Temperature.Components;
using Content.Server.Temperature.Systems;
using Content.Shared._White.Guns;
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 Robust.Shared.Containers;
using Robust.Shared.Prototypes;
namespace Content.Server.Weapons.Ranged.Systems;
public sealed partial class GunSystem
{
[Dependency] private readonly TemperatureSystem _temp = default!; // WWDP EDIT
protected override void InitializeBattery()
{
base.InitializeBattery();
// Hitscan
SubscribeLocalEvent<HitscanBatteryAmmoProviderComponent, ComponentStartup>(OnBatteryStartup);
SubscribeLocalEvent<HitscanBatteryAmmoProviderComponent, ChargeChangedEvent>(OnBatteryChargeChange);
SubscribeLocalEvent<HitscanBatteryAmmoProviderComponent, DamageExamineEvent>(OnBatteryDamageExamine);
// Projectile
SubscribeLocalEvent<ProjectileBatteryAmmoProviderComponent, ComponentStartup>(OnBatteryStartup);
SubscribeLocalEvent<ProjectileBatteryAmmoProviderComponent, ChargeChangedEvent>(OnBatteryChargeChange);
SubscribeLocalEvent<ProjectileBatteryAmmoProviderComponent, DamageExamineEvent>(OnBatteryDamageExamine);
//// WWDP EDIT START
SubscribeLocalEvent<ProjectileContainerBatteryAmmoProviderComponent, ComponentStartup>(OnBatteryStartup);
SubscribeLocalEvent<ProjectileContainerBatteryAmmoProviderComponent, EntGotInsertedIntoContainerMessage>(OnContainerBatteryInserted);
SubscribeLocalEvent<ProjectileContainerBatteryAmmoProviderComponent, EntGotRemovedFromContainerMessage>(OnContainerBatteryRemoved);
SubscribeLocalEvent<ProjectileContainerBatteryAmmoProviderComponent, DamageExamineEvent>(OnBatteryDamageExamine);
SubscribeLocalEvent<ContainerBatteryAmmoTrackerComponent, ChargeChangedEvent>(OnBatteryChargeChangeTracker);
SubscribeLocalEvent<HitscanContainerBatteryAmmoProviderComponent, ComponentStartup>(OnBatteryStartup);
SubscribeLocalEvent<HitscanContainerBatteryAmmoProviderComponent, EntGotInsertedIntoContainerMessage>(OnContainerBatteryInserted);
SubscribeLocalEvent<HitscanContainerBatteryAmmoProviderComponent, EntGotRemovedFromContainerMessage>(OnContainerBatteryRemoved);
SubscribeLocalEvent<HitscanContainerBatteryAmmoProviderComponent, DamageExamineEvent>(OnBatteryDamageExamine);
//// WWDP EDIT END
}
private void OnBatteryStartup(EntityUid uid, BatteryAmmoProviderComponent component, ComponentStartup args)
{
UpdateShots(uid, component);
}
private void OnBatteryChargeChange(EntityUid uid, BatteryAmmoProviderComponent component, ref ChargeChangedEvent args)
{
UpdateShots(uid, component, args.Charge, args.MaxCharge);
}
public void UpdateShots(EntityUid uid, BatteryAmmoProviderComponent component) // WWDP EDIT - private -> public
{
var batteryUid = component is ContainerBatteryAmmoProviderComponent ? Transform(uid).ParentUid : uid; // WWDP EDIT
if (!TryComp<BatteryComponent>(batteryUid, out var battery)) // WWDP EDIT
return;
UpdateShots(uid, component, battery.CurrentCharge, battery.MaxCharge);
}
private void UpdateShots(EntityUid uid, BatteryAmmoProviderComponent component, float charge, float maxCharge)
{
var shots = (int) (charge / component.FireCost);
var maxShots = (int) (maxCharge / component.FireCost);
if (component.Shots != shots || component.Capacity != maxShots)
{
Dirty(uid, component);
}
component.Shots = shots;
component.Capacity = maxShots;
UpdateBatteryAppearance(uid, component);
}
private void OnBatteryDamageExamine(EntityUid uid, BatteryAmmoProviderComponent component, ref DamageExamineEvent args)
{
var damageSpec = GetDamage(component);
if (damageSpec == null)
return;
var damageType = component switch
{
HitscanBatteryAmmoProviderComponent => Loc.GetString("damage-hitscan"),
ProjectileBatteryAmmoProviderComponent => Loc.GetString("damage-projectile"),
_ => throw new ArgumentOutOfRangeException(),
};
_damageExamine.AddDamageExamine(args.Message, damageSpec, damageType);
}
private DamageSpecifier? GetDamage(BatteryAmmoProviderComponent component)
{
if (component is ProjectileBatteryAmmoProviderComponent battery)
{
if (ProtoManager.Index<EntityPrototype>(battery.Prototype).Components
.TryGetValue(_factory.GetComponentName(typeof(ProjectileComponent)), out var projectile))
{
var p = (ProjectileComponent) projectile.Component;
if (!p.Damage.Empty)
{
return p.Damage;
}
}
return null;
}
if (component is HitscanBatteryAmmoProviderComponent hitscan)
{
return ProtoManager.Index<HitscanPrototype>(hitscan.Prototype).Damage;
}
return null;
}
protected override void TakeCharge(EntityUid uid, BatteryAmmoProviderComponent component)
{
if(component is ContainerBatteryAmmoProviderComponent comp)
{
uid = comp.Linked!.Value; // the validity of this should be enforced by EntGotInserted/Removed event handlers below.
}
// Will raise ChargeChangedEvent
_battery.UseCharge(uid, component.FireCost);
}
// WWDP EDIT START
private void OnContainerBatteryInserted(EntityUid uid, ContainerBatteryAmmoProviderComponent comp, EntGotInsertedIntoContainerMessage args)
{
var contUid = args.Container.Owner;
var tracker = EnsureComp<ContainerBatteryAmmoTrackerComponent>(contUid);
tracker.Linked.Add(uid);
comp.Linked = contUid;
UpdateShots(uid, comp);
}
private void OnContainerBatteryRemoved(EntityUid uid, ContainerBatteryAmmoProviderComponent comp, EntGotRemovedFromContainerMessage args)
{
var contUid = args.Container.Owner;
var tracker = Comp<ContainerBatteryAmmoTrackerComponent>(contUid); // intended to throw on failure, should not happen
tracker.Linked.Remove(uid);
comp.Linked = null;
if (tracker.Linked.Count == 0)
RemComp(contUid, tracker);
UpdateShots(uid, comp, 0, 0);
}
private void OnBatteryChargeChangeTracker(EntityUid uid, ContainerBatteryAmmoTrackerComponent comp, ref ChargeChangedEvent args)
{
foreach (var gunUid in comp.Linked)
{
if(TryComp<ProjectileContainerBatteryAmmoProviderComponent>(gunUid, out var projectileAmmoProvider))
UpdateShots(gunUid, projectileAmmoProvider, args.Charge, args.MaxCharge);
else if(TryComp<HitscanContainerBatteryAmmoProviderComponent>(gunUid, out var hitscanAmmoProvider))
UpdateShots(gunUid, hitscanAmmoProvider, args.Charge, args.MaxCharge);
}
}
// WWDP EDIT END
}