Remove gun .Owners (#14585)

This commit is contained in:
metalgearsloth
2023-03-11 20:08:22 +11:00
committed by GitHub
parent 19f5c403b5
commit 330bb7bb14
18 changed files with 333 additions and 280 deletions

View File

@@ -27,7 +27,7 @@ public abstract partial class SharedGunSystem
if (!args.IsInDetailsRange)
return;
var (count, _) = GetChamberMagazineCountCapacity(component);
var (count, _) = GetChamberMagazineCountCapacity(uid, component);
args.PushMarkup(Loc.GetString("gun-magazine-examine", ("color", AmmoExamineColor), ("count", count)));
}
@@ -41,7 +41,9 @@ public abstract partial class SharedGunSystem
}
entity = slot.ContainedEntity;
if (entity == null) return false;
if (entity == null)
return false;
container.Remove(entity.Value);
return true;
}
@@ -57,10 +59,10 @@ public abstract partial class SharedGunSystem
return slot.ContainedEntity;
}
protected (int, int) GetChamberMagazineCountCapacity(ChamberMagazineAmmoProviderComponent component)
protected (int, int) GetChamberMagazineCountCapacity(EntityUid uid, ChamberMagazineAmmoProviderComponent component)
{
var count = GetChamberEntity(component.Owner) != null ? 1 : 0;
var (magCount, magCapacity) = GetMagazineCountCapacity(component);
var count = GetChamberEntity(uid) != null ? 1 : 0;
var (magCount, magCapacity) = GetMagazineCountCapacity(uid, component);
return (count + magCount, magCapacity);
}
@@ -81,7 +83,7 @@ public abstract partial class SharedGunSystem
if (TryTakeChamberEntity(uid, out var chamberEnt))
{
args.Ammo.Add(EnsureComp<AmmoComponent>(chamberEnt.Value));
args.Ammo.Add((chamberEnt.Value, EnsureComp<AmmoComponent>(chamberEnt.Value)));
}
var magEnt = GetMagazineEntity(uid);
@@ -90,15 +92,15 @@ public abstract partial class SharedGunSystem
if (magEnt != null)
{
// We pass in Shots not Shots - 1 as we'll take the last entity and move it into the chamber.
var relayedArgs = new TakeAmmoEvent(args.Shots, new List<IShootable>(), args.Coordinates, args.User);
RaiseLocalEvent(magEnt.Value, relayedArgs, false);
var relayedArgs = new TakeAmmoEvent(args.Shots, new List<(EntityUid? Entity, IShootable Shootable)>(), args.Coordinates, args.User);
RaiseLocalEvent(magEnt.Value, relayedArgs);
// Put in the nth slot back into the chamber
// Rest of the ammo gets shot
if (relayedArgs.Ammo.Count > 0)
{
var newChamberEnt = ((AmmoComponent) relayedArgs.Ammo[^1]).Owner;
TryInsertChamber(uid, newChamberEnt);
var newChamberEnt = relayedArgs.Ammo[^1].Entity;
TryInsertChamber(uid, newChamberEnt!.Value);
}
// Anything above the chamber-refill amount gets fired.
@@ -117,7 +119,7 @@ public abstract partial class SharedGunSystem
const int capacity = 1;
var ammoEv = new GetAmmoCountEvent();
RaiseLocalEvent(magEnt.Value, ref ammoEv, false);
RaiseLocalEvent(magEnt.Value, ref ammoEv);
FinaliseMagazineTakeAmmo(uid, component, args, count + ammoEv.Count, capacity + ammoEv.Capacity, appearance);
}