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