Remove Ammo component references (#19537)
This commit is contained in:
@@ -34,13 +34,13 @@ public sealed partial class GunSystem
|
||||
component.Entities.RemoveAt(component.Entities.Count - 1);
|
||||
|
||||
component.Container.Remove(existing);
|
||||
EnsureComp<AmmoComponent>(existing);
|
||||
EnsureShootable(existing);
|
||||
}
|
||||
else if (component.UnspawnedCount > 0)
|
||||
{
|
||||
component.UnspawnedCount--;
|
||||
ent = Spawn(component.FillProto, coordinates);
|
||||
EnsureComp<AmmoComponent>(ent.Value);
|
||||
EnsureShootable(ent.Value);
|
||||
}
|
||||
|
||||
if (ent != null && ent.Value.IsClientSide())
|
||||
|
||||
@@ -191,7 +191,7 @@ public sealed partial class GunSystem : SharedGunSystem
|
||||
if (ent!.Value.IsClientSide())
|
||||
Del(ent.Value);
|
||||
else
|
||||
RemComp<AmmoComponent>(ent.Value);
|
||||
RemoveShootable(ent.Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -225,7 +225,7 @@ public sealed partial class GunSystem : SharedGunSystem
|
||||
if (ent!.Value.IsClientSide())
|
||||
Del(ent.Value);
|
||||
else
|
||||
RemComp<AmmoComponent>(ent.Value);
|
||||
RemoveShootable(ent.Value);
|
||||
break;
|
||||
case HitscanPrototype:
|
||||
Audio.PlayPredicted(gun.SoundGunshot, gunUid, user);
|
||||
|
||||
@@ -17,13 +17,13 @@ public sealed partial class GunSystem
|
||||
component.Entities.RemoveAt(component.Entities.Count - 1);
|
||||
|
||||
component.Container.Remove(existing);
|
||||
EnsureComp<AmmoComponent>(existing);
|
||||
EnsureShootable(existing);
|
||||
}
|
||||
else if (component.UnspawnedCount > 0)
|
||||
{
|
||||
component.UnspawnedCount--;
|
||||
ent = Spawn(component.FillProto, coordinates);
|
||||
EnsureComp<AmmoComponent>(ent.Value);
|
||||
EnsureShootable(ent.Value);
|
||||
}
|
||||
|
||||
if (ent != null)
|
||||
|
||||
@@ -283,7 +283,7 @@ public sealed partial class GunSystem : SharedGunSystem
|
||||
// Do a throw
|
||||
if (!HasComp<ProjectileComponent>(uid))
|
||||
{
|
||||
RemComp<AmmoComponent>(uid);
|
||||
RemoveShootable(uid);
|
||||
// TODO: Someone can probably yeet this a billion miles so need to pre-validate input somewhere up the call stack.
|
||||
ThrowingSystem.TryThrow(uid, mapDirection, gun.ProjectileSpeed, user);
|
||||
return;
|
||||
|
||||
@@ -20,7 +20,7 @@ public partial class AmmoComponent : Component, IShootable
|
||||
/// <summary>
|
||||
/// Spawns another prototype to be shot instead of itself.
|
||||
/// </summary>
|
||||
[RegisterComponent, NetworkedComponent, ComponentReference(typeof(AmmoComponent)), AutoGenerateComponentState]
|
||||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
|
||||
public sealed partial class CartridgeAmmoComponent : AmmoComponent
|
||||
{
|
||||
[ViewVariables(VVAccess.ReadWrite), DataField("proto", required: true, customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
|
||||
|
||||
@@ -216,7 +216,7 @@ public abstract partial class SharedGunSystem
|
||||
{
|
||||
entity = component.Entities[^1];
|
||||
|
||||
args.Ammo.Add((entity, EnsureComp<AmmoComponent>(entity)));
|
||||
args.Ammo.Add((entity, EnsureShootable(entity)));
|
||||
component.Entities.RemoveAt(component.Entities.Count - 1);
|
||||
component.Container.Remove(entity);
|
||||
}
|
||||
@@ -224,7 +224,7 @@ public abstract partial class SharedGunSystem
|
||||
{
|
||||
component.UnspawnedCount--;
|
||||
entity = Spawn(component.FillProto, args.Coordinates);
|
||||
args.Ammo.Add((entity, EnsureComp<AmmoComponent>(entity)));
|
||||
args.Ammo.Add((entity, EnsureShootable(entity)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ public abstract partial class SharedGunSystem
|
||||
}
|
||||
|
||||
var ent = Spawn(component.Proto, args.Coordinates);
|
||||
args.Ammo.Add((ent, EnsureComp<AmmoComponent>(ent)));
|
||||
args.Ammo.Add((ent, EnsureShootable(ent)));
|
||||
}
|
||||
|
||||
_recharge.Reset(uid);
|
||||
|
||||
@@ -98,7 +98,7 @@ public abstract partial class SharedGunSystem
|
||||
{
|
||||
case ProjectileBatteryAmmoProviderComponent proj:
|
||||
var ent = Spawn(proj.Prototype, coordinates);
|
||||
return (ent, EnsureComp<AmmoComponent>(ent));
|
||||
return (ent, EnsureShootable(ent));
|
||||
case HitscanBatteryAmmoProviderComponent hitscan:
|
||||
return (null, ProtoManager.Index<HitscanPrototype>(hitscan.Prototype));
|
||||
default:
|
||||
|
||||
@@ -352,7 +352,7 @@ public abstract partial class SharedGunSystem
|
||||
{
|
||||
if (TryTakeChamberEntity(uid, out chamberEnt))
|
||||
{
|
||||
args.Ammo.Add((chamberEnt.Value, EnsureComp<AmmoComponent>(chamberEnt.Value)));
|
||||
args.Ammo.Add((chamberEnt.Value, EnsureShootable(chamberEnt.Value)));
|
||||
}
|
||||
// No ammo returned.
|
||||
else
|
||||
@@ -406,7 +406,7 @@ public abstract partial class SharedGunSystem
|
||||
{
|
||||
// Shooting code won't eject it if it's still contained.
|
||||
chamberEnt = slot.ContainedEntity;
|
||||
args.Ammo.Add((chamberEnt.Value, EnsureComp<AmmoComponent>(chamberEnt.Value)));
|
||||
args.Ammo.Add((chamberEnt.Value, EnsureShootable(chamberEnt.Value)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ public partial class SharedGunSystem
|
||||
if (_netManager.IsServer)
|
||||
container.Remove(ent);
|
||||
|
||||
args.Ammo.Add((ent, EnsureComp<AmmoComponent>(ent)));
|
||||
args.Ammo.Add((ent, EnsureShootable(ent)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -342,13 +342,13 @@ public partial class SharedGunSystem
|
||||
component.Chambers[index] = false;
|
||||
SetCartridgeSpent(ent, cartridge, true);
|
||||
var spawned = Spawn(cartridge.Prototype, args.Coordinates);
|
||||
args.Ammo.Add((spawned, EnsureComp<AmmoComponent>(spawned)));
|
||||
args.Ammo.Add((spawned, EnsureShootable(spawned)));
|
||||
Del(ent);
|
||||
continue;
|
||||
}
|
||||
|
||||
component.Chambers[i] = null;
|
||||
args.Ammo.Add((ent, EnsureComp<AmmoComponent>(ent)));
|
||||
args.Ammo.Add((ent, EnsureShootable(ent)));
|
||||
}
|
||||
}
|
||||
else if (component.AmmoSlots[index] != null)
|
||||
@@ -362,13 +362,13 @@ public partial class SharedGunSystem
|
||||
|
||||
SetCartridgeSpent(ent.Value, cartridge, true);
|
||||
var spawned = Spawn(cartridge.Prototype, args.Coordinates);
|
||||
args.Ammo.Add((spawned, EnsureComp<AmmoComponent>(spawned)));
|
||||
args.Ammo.Add((spawned, EnsureShootable(spawned)));
|
||||
continue;
|
||||
}
|
||||
|
||||
component.AmmoContainer.Remove(ent.Value);
|
||||
component.AmmoSlots[index] = null;
|
||||
args.Ammo.Add((ent.Value, EnsureComp<AmmoComponent>(ent.Value)));
|
||||
args.Ammo.Add((ent.Value, EnsureShootable(ent.Value)));
|
||||
TransformSystem.SetCoordinates(ent.Value, args.Coordinates);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ public partial class SharedGunSystem
|
||||
protected virtual (EntityUid Entity, IShootable) GetSolutionShot(EntityUid uid, SolutionAmmoProviderComponent component, EntityCoordinates position)
|
||||
{
|
||||
var ent = Spawn(component.Prototype, position);
|
||||
return (ent, EnsureComp<AmmoComponent>(ent));
|
||||
return (ent, EnsureShootable(ent));
|
||||
}
|
||||
|
||||
protected void UpdateSolutionAppearance(EntityUid uid, SolutionAmmoProviderComponent component)
|
||||
|
||||
@@ -350,7 +350,7 @@ public abstract partial class SharedGunSystem : EntitySystem
|
||||
EntityUid? user = null,
|
||||
bool throwItems = false)
|
||||
{
|
||||
var shootable = EnsureComp<AmmoComponent>(ammo);
|
||||
var shootable = EnsureShootable(ammo);
|
||||
Shoot(gunUid, gun, new List<(EntityUid? Entity, IShootable Shootable)>(1) { (ammo, shootable) }, fromCoordinates, toCoordinates, out userImpulse, user, throwItems);
|
||||
}
|
||||
|
||||
@@ -411,6 +411,20 @@ public abstract partial class SharedGunSystem : EntitySystem
|
||||
}
|
||||
}
|
||||
|
||||
protected IShootable EnsureShootable(EntityUid uid)
|
||||
{
|
||||
if (TryComp<CartridgeAmmoComponent>(uid, out var cartridge))
|
||||
return cartridge;
|
||||
|
||||
return EnsureComp<AmmoComponent>(uid);
|
||||
}
|
||||
|
||||
protected void RemoveShootable(EntityUid uid)
|
||||
{
|
||||
RemCompDeferred<CartridgeAmmoComponent>(uid);
|
||||
RemCompDeferred<AmmoComponent>(uid);
|
||||
}
|
||||
|
||||
protected void MuzzleFlash(EntityUid gun, AmmoComponent component, EntityUid? user = null)
|
||||
{
|
||||
var sprite = component.MuzzleFlash;
|
||||
|
||||
Reference in New Issue
Block a user