Allow direct transfer between specific BallisticAmmoProviders. (#12964)
This commit is contained in:
parent
da1de51202
commit
7575c0944b
|
|
@ -45,4 +45,10 @@ public sealed class BallisticAmmoProviderComponent : Component
|
|||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite), DataField("cycled")]
|
||||
public bool Cycled = true;
|
||||
|
||||
/// <summary>
|
||||
/// Is it okay for this entity to directly transfer its valid ammunition into another provider?
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite), DataField("mayTransfer")]
|
||||
public bool MayTransfer = false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ public abstract partial class SharedGunSystem
|
|||
SubscribeLocalEvent<BallisticAmmoProviderComponent, ExaminedEvent>(OnBallisticExamine);
|
||||
SubscribeLocalEvent<BallisticAmmoProviderComponent, GetVerbsEvent<Verb>>(OnBallisticVerb);
|
||||
SubscribeLocalEvent<BallisticAmmoProviderComponent, InteractUsingEvent>(OnBallisticInteractUsing);
|
||||
SubscribeLocalEvent<BallisticAmmoProviderComponent, AfterInteractEvent>(OnBallisticAfterInteract);
|
||||
SubscribeLocalEvent<BallisticAmmoProviderComponent, UseInHandEvent>(OnBallisticUse);
|
||||
}
|
||||
|
||||
|
|
@ -50,6 +51,81 @@ public abstract partial class SharedGunSystem
|
|||
Dirty(component);
|
||||
}
|
||||
|
||||
private void OnBallisticAfterInteract(EntityUid uid, BallisticAmmoProviderComponent component, AfterInteractEvent args)
|
||||
{
|
||||
if (args.Handled ||
|
||||
!component.MayTransfer ||
|
||||
!Timing.IsFirstTimePredicted ||
|
||||
args.Target == null ||
|
||||
args.Used == args.Target ||
|
||||
Deleted(args.Target) ||
|
||||
!TryComp(args.Target, out BallisticAmmoProviderComponent? targetComponent) ||
|
||||
targetComponent.Whitelist == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
args.Handled = true;
|
||||
|
||||
if (targetComponent.Entities.Count + targetComponent.UnspawnedCount == targetComponent.Capacity)
|
||||
{
|
||||
Popup(
|
||||
Loc.GetString("gun-ballistic-transfer-target-full",
|
||||
("entity", args.Target)),
|
||||
args.Target,
|
||||
args.User);
|
||||
return;
|
||||
}
|
||||
|
||||
if (component.Entities.Count + component.UnspawnedCount == 0)
|
||||
{
|
||||
Popup(
|
||||
Loc.GetString("gun-ballistic-transfer-empty",
|
||||
("entity", args.Used)),
|
||||
args.Used,
|
||||
args.User);
|
||||
return;
|
||||
}
|
||||
|
||||
void SimulateInsertAmmo(EntityUid ammo, EntityUid ammoProvider, EntityCoordinates coordinates)
|
||||
{
|
||||
var evInsert = new InteractUsingEvent(args.User, ammo, ammoProvider, coordinates);
|
||||
RaiseLocalEvent(ammoProvider, evInsert);
|
||||
}
|
||||
|
||||
List<IShootable> ammo = new();
|
||||
var evTakeAmmo = new TakeAmmoEvent(1, ammo, Transform(args.Used).Coordinates, args.User);
|
||||
RaiseLocalEvent(args.Used, evTakeAmmo);
|
||||
|
||||
foreach (var shot in ammo)
|
||||
{
|
||||
if (shot is not AmmoComponent cast)
|
||||
continue;
|
||||
|
||||
if (!targetComponent.Whitelist.IsValid(cast.Owner))
|
||||
{
|
||||
Popup(
|
||||
Loc.GetString("gun-ballistic-transfer-invalid",
|
||||
("ammoEntity", cast.Owner),
|
||||
("targetEntity", args.Target.Value)),
|
||||
args.Used,
|
||||
args.User);
|
||||
|
||||
// TODO: For better or worse, this will play a sound, but it's the
|
||||
// more future-proof thing to do than copying the same code
|
||||
// that OnBallisticInteractUsing has, sans sound.
|
||||
SimulateInsertAmmo(cast.Owner, args.Used, Transform(args.Used).Coordinates);
|
||||
}
|
||||
else
|
||||
{
|
||||
SimulateInsertAmmo(cast.Owner, args.Target.Value, Transform(args.Target.Value).Coordinates);
|
||||
}
|
||||
|
||||
if (cast.Owner.IsClientSide())
|
||||
Del(cast.Owner);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnBallisticVerb(EntityUid uid, BallisticAmmoProviderComponent component, GetVerbsEvent<Verb> args)
|
||||
{
|
||||
if (!args.CanAccess || !args.CanInteract || args.Hands == null) return;
|
||||
|
|
|
|||
|
|
@ -15,6 +15,9 @@ gun-FullAuto = full-auto
|
|||
gun-ballistic-cycle = Cycle
|
||||
gun-ballistic-cycled = Cycled
|
||||
gun-ballistic-cycled-empty = Cycled (empty)
|
||||
gun-ballistic-transfer-invalid = {CAPITALIZE(THE($ammoEntity))} won't fit inside {THE($targetEntity)}!
|
||||
gun-ballistic-transfer-empty = {CAPITALIZE(THE($entity))} is empty.
|
||||
gun-ballistic-transfer-target-full = {CAPITALIZE(THE($entity))} is already fully loaded.
|
||||
|
||||
# CartridgeAmmo
|
||||
gun-cartridge-spent = It is [color=red]spent[/color].
|
||||
|
|
@ -32,4 +35,4 @@ gun-revolver-full = Revolver full
|
|||
gun-revolver-insert = Inserted
|
||||
gun-revolver-spin = Spin revolver
|
||||
gun-revolver-spun = Spun
|
||||
gun-speedloader-empty = Speedloader empty
|
||||
gun-speedloader-empty = Speedloader empty
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
name: ammunition box (.60 anti-material)
|
||||
components:
|
||||
- type: BallisticAmmoProvider
|
||||
mayTransfer: true
|
||||
capacity: 30
|
||||
proto: CartridgeAntiMaterial
|
||||
- type: Sprite
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
name: ammunition box (.25 caseless)
|
||||
components:
|
||||
- type: BallisticAmmoProvider
|
||||
mayTransfer: true
|
||||
whitelist:
|
||||
tags:
|
||||
- CartridgeCaselessRifle
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
name: ammunition box (.30 rifle)
|
||||
components:
|
||||
- type: BallisticAmmoProvider
|
||||
mayTransfer: true
|
||||
whitelist:
|
||||
tags:
|
||||
- CartridgeLightRifle
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
id: BaseMagazineBoxMagnum
|
||||
components:
|
||||
- type: BallisticAmmoProvider
|
||||
mayTransfer: true
|
||||
whitelist:
|
||||
tags:
|
||||
- CartridgeMagnum
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
name: ammunition box (.35 auto)
|
||||
components:
|
||||
- type: BallisticAmmoProvider
|
||||
mayTransfer: true
|
||||
whitelist:
|
||||
tags:
|
||||
- CartridgePistol
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
id: BaseMagazineBoxRifle
|
||||
components:
|
||||
- type: BallisticAmmoProvider
|
||||
mayTransfer: true
|
||||
whitelist:
|
||||
tags:
|
||||
- CartridgeRifle
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
name: foamdart box
|
||||
components:
|
||||
- type: BallisticAmmoProvider
|
||||
mayTransfer: true
|
||||
capacity: 30
|
||||
- type: Sprite
|
||||
netsync: false
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
tags:
|
||||
- MagazineCaselessRifle
|
||||
- type: BallisticAmmoProvider
|
||||
mayTransfer: true
|
||||
whitelist:
|
||||
tags:
|
||||
- CartridgeCaselessRifle
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
- type: Item
|
||||
size: 10
|
||||
- type: BallisticAmmoProvider
|
||||
mayTransfer: true
|
||||
capacity: 100
|
||||
- type: ContainerContainer
|
||||
containers:
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
tags:
|
||||
- MagazineLightRifle
|
||||
- type: BallisticAmmoProvider
|
||||
mayTransfer: true
|
||||
whitelist:
|
||||
tags:
|
||||
- CartridgeLightRifle
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
tags:
|
||||
- MagazineMagnum
|
||||
- type: BallisticAmmoProvider
|
||||
mayTransfer: true
|
||||
whitelist:
|
||||
tags:
|
||||
- CartridgeMagnum
|
||||
|
|
@ -41,6 +42,7 @@
|
|||
tags:
|
||||
- MagazineMagnumSubMachineGun
|
||||
- type: BallisticAmmoProvider
|
||||
mayTransfer: true
|
||||
whitelist:
|
||||
tags:
|
||||
- CartridgeMagnum
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
tags:
|
||||
- MagazinePistol
|
||||
- type: BallisticAmmoProvider
|
||||
mayTransfer: true
|
||||
whitelist:
|
||||
tags:
|
||||
- CartridgePistol
|
||||
|
|
@ -41,6 +42,7 @@
|
|||
tags:
|
||||
- MagazinePistolHighCapacity
|
||||
- type: BallisticAmmoProvider
|
||||
mayTransfer: true
|
||||
whitelist:
|
||||
tags:
|
||||
- CartridgePistol
|
||||
|
|
@ -74,6 +76,7 @@
|
|||
tags:
|
||||
- MagazinePistolSubMachineGun
|
||||
- type: BallisticAmmoProvider
|
||||
mayTransfer: true
|
||||
whitelist:
|
||||
tags:
|
||||
- CartridgePistol
|
||||
|
|
@ -106,6 +109,7 @@
|
|||
tags:
|
||||
- MagazinePistolSubMachineGunTopMounted
|
||||
- type: BallisticAmmoProvider
|
||||
mayTransfer: true
|
||||
proto: CartridgePistol
|
||||
whitelist:
|
||||
tags:
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
- type: Item
|
||||
size: 5
|
||||
- type: BallisticAmmoProvider
|
||||
mayTransfer: true
|
||||
whitelist:
|
||||
tags:
|
||||
- CartridgeRifle
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
tags:
|
||||
- MagazineShotgun
|
||||
- type: BallisticAmmoProvider
|
||||
mayTransfer: true
|
||||
whitelist:
|
||||
tags:
|
||||
- ShellShotgun
|
||||
|
|
|
|||
Loading…
Reference in New Issue