CatStation/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.BasicEntity.cs
Samuka e927a6d1c4
Oil gun (#44389)
* xenoborg oil

* xenoborg oil vial

* oil gun

* minor fix to all welders

* make it more flammable

* turn into a ampoule

* update the proto

* don't declare the anchors again

* rename state

* its now a proper item

* make it spill from hitting something, but not from the hand

* fix description

* AmmoVisuals.IsFull

* make reloading animation

* update sprite

* oil gun module

* add todo comment

* less fire stacks per direct hit

* increase evaporation speed

* make it darker and not recognizable

* make oil color darker on the sprite

* add a crystal

* make it slower

* add fire sprite

* oil gun now comes with a tiny fire

* some description

* make gun glow a little

* have to be ignited

* fix

* update sprite

* flame in separate layer

* ops

* make the bullets slower

* fix the angle

* ops, it was uppercase

* comment

* typo

* empty commit

* overkill behavior is now automatic

* fix xenoborg ampoule

* oil gun custom ammo sprites

* remove glass thing

* alphabetical

* fix ampoule proto

* use localizedLabel

* update ammo counter sprite
2026-08-03 06:54:53 +00:00

85 lines
2.9 KiB
C#

using Content.Shared.Weapons.Ranged.Components;
using Content.Shared.Weapons.Ranged.Events;
namespace Content.Shared.Weapons.Ranged.Systems;
public abstract partial class SharedGunSystem
{
protected virtual void InitializeBasicEntity()
{
SubscribeLocalEvent<BasicEntityAmmoProviderComponent, MapInitEvent>(OnBasicEntityMapInit);
SubscribeLocalEvent<BasicEntityAmmoProviderComponent, TakeAmmoEvent>(OnBasicEntityTakeAmmo);
SubscribeLocalEvent<BasicEntityAmmoProviderComponent, GetAmmoCountEvent>(OnBasicEntityAmmoCount);
}
private void OnBasicEntityMapInit(Entity<BasicEntityAmmoProviderComponent> ent, ref MapInitEvent args)
{
if (ent.Comp.Count is null)
{
ent.Comp.Count = ent.Comp.Capacity;
Dirty(ent);
}
UpdateBasicEntityAppearance(ent);
}
private void OnBasicEntityTakeAmmo(Entity<BasicEntityAmmoProviderComponent> ent, ref TakeAmmoEvent args)
{
for (var i = 0; i < args.Shots; i++)
{
if (ent.Comp.Count <= 0)
return;
if (ent.Comp.Count != null)
ent.Comp.Count--;
var ammoEnt = SpawnAtPosition(ent.Comp.Proto, args.Coordinates);
args.Ammo.Add((ammoEnt, EnsureShootable(ammoEnt)));
}
_recharge.Reset(ent.Owner);
UpdateBasicEntityAppearance(ent);
Dirty(ent);
}
private void OnBasicEntityAmmoCount(Entity<BasicEntityAmmoProviderComponent> ent, ref GetAmmoCountEvent args)
{
args.Capacity = ent.Comp.Capacity ?? int.MaxValue;
args.Count = ent.Comp.Count ?? int.MaxValue;
}
private void UpdateBasicEntityAppearance(Entity<BasicEntityAmmoProviderComponent> ent)
{
if (!Timing.IsFirstTimePredicted || !TryComp<AppearanceComponent>(ent, out var appearance))
return;
Appearance.SetData(ent, AmmoVisuals.HasAmmo, ent.Comp.Count != 0, appearance);
Appearance.SetData(ent, AmmoVisuals.IsFull, ent.Comp.Count == ent.Comp.Capacity, appearance);
Appearance.SetData(ent, AmmoVisuals.AmmoCount, ent.Comp.Count ?? int.MaxValue, appearance);
Appearance.SetData(ent, AmmoVisuals.AmmoMax, ent.Comp.Capacity ?? int.MaxValue, appearance);
}
#region Public API
public bool ChangeBasicEntityAmmoCount(Entity<BasicEntityAmmoProviderComponent?> ent, int delta)
{
if (!Resolve(ent, ref ent.Comp, false) || ent.Comp.Count == null)
return false;
return UpdateBasicEntityAmmoCount((ent.Owner, ent.Comp), ent.Comp.Count.Value + delta);
}
public bool UpdateBasicEntityAmmoCount(Entity<BasicEntityAmmoProviderComponent?> ent, int count)
{
if (!Resolve(ent, ref ent.Comp, false) || count > ent.Comp.Capacity)
return false;
ent.Comp.Count = count;
UpdateBasicEntityAppearance((ent.Owner, ent.Comp));
UpdateAmmoCount(ent);
Dirty(ent);
return true;
}
#endregion
}