Allow direct transfer between specific BallisticAmmoProviders. (#12964)
This commit is contained in:
@@ -45,4 +45,10 @@ public sealed class BallisticAmmoProviderComponent : Component
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[ViewVariables(VVAccess.ReadWrite), DataField("cycled")]
|
[ViewVariables(VVAccess.ReadWrite), DataField("cycled")]
|
||||||
public bool Cycled = true;
|
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, ExaminedEvent>(OnBallisticExamine);
|
||||||
SubscribeLocalEvent<BallisticAmmoProviderComponent, GetVerbsEvent<Verb>>(OnBallisticVerb);
|
SubscribeLocalEvent<BallisticAmmoProviderComponent, GetVerbsEvent<Verb>>(OnBallisticVerb);
|
||||||
SubscribeLocalEvent<BallisticAmmoProviderComponent, InteractUsingEvent>(OnBallisticInteractUsing);
|
SubscribeLocalEvent<BallisticAmmoProviderComponent, InteractUsingEvent>(OnBallisticInteractUsing);
|
||||||
|
SubscribeLocalEvent<BallisticAmmoProviderComponent, AfterInteractEvent>(OnBallisticAfterInteract);
|
||||||
SubscribeLocalEvent<BallisticAmmoProviderComponent, UseInHandEvent>(OnBallisticUse);
|
SubscribeLocalEvent<BallisticAmmoProviderComponent, UseInHandEvent>(OnBallisticUse);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,6 +51,81 @@ public abstract partial class SharedGunSystem
|
|||||||
Dirty(component);
|
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)
|
private void OnBallisticVerb(EntityUid uid, BallisticAmmoProviderComponent component, GetVerbsEvent<Verb> args)
|
||||||
{
|
{
|
||||||
if (!args.CanAccess || !args.CanInteract || args.Hands == null) return;
|
if (!args.CanAccess || !args.CanInteract || args.Hands == null) return;
|
||||||
|
|||||||
@@ -15,6 +15,9 @@ gun-FullAuto = full-auto
|
|||||||
gun-ballistic-cycle = Cycle
|
gun-ballistic-cycle = Cycle
|
||||||
gun-ballistic-cycled = Cycled
|
gun-ballistic-cycled = Cycled
|
||||||
gun-ballistic-cycled-empty = Cycled (empty)
|
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
|
# CartridgeAmmo
|
||||||
gun-cartridge-spent = It is [color=red]spent[/color].
|
gun-cartridge-spent = It is [color=red]spent[/color].
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
name: ammunition box (.60 anti-material)
|
name: ammunition box (.60 anti-material)
|
||||||
components:
|
components:
|
||||||
- type: BallisticAmmoProvider
|
- type: BallisticAmmoProvider
|
||||||
|
mayTransfer: true
|
||||||
capacity: 30
|
capacity: 30
|
||||||
proto: CartridgeAntiMaterial
|
proto: CartridgeAntiMaterial
|
||||||
- type: Sprite
|
- type: Sprite
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
name: ammunition box (.25 caseless)
|
name: ammunition box (.25 caseless)
|
||||||
components:
|
components:
|
||||||
- type: BallisticAmmoProvider
|
- type: BallisticAmmoProvider
|
||||||
|
mayTransfer: true
|
||||||
whitelist:
|
whitelist:
|
||||||
tags:
|
tags:
|
||||||
- CartridgeCaselessRifle
|
- CartridgeCaselessRifle
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
name: ammunition box (.30 rifle)
|
name: ammunition box (.30 rifle)
|
||||||
components:
|
components:
|
||||||
- type: BallisticAmmoProvider
|
- type: BallisticAmmoProvider
|
||||||
|
mayTransfer: true
|
||||||
whitelist:
|
whitelist:
|
||||||
tags:
|
tags:
|
||||||
- CartridgeLightRifle
|
- CartridgeLightRifle
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
id: BaseMagazineBoxMagnum
|
id: BaseMagazineBoxMagnum
|
||||||
components:
|
components:
|
||||||
- type: BallisticAmmoProvider
|
- type: BallisticAmmoProvider
|
||||||
|
mayTransfer: true
|
||||||
whitelist:
|
whitelist:
|
||||||
tags:
|
tags:
|
||||||
- CartridgeMagnum
|
- CartridgeMagnum
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
name: ammunition box (.35 auto)
|
name: ammunition box (.35 auto)
|
||||||
components:
|
components:
|
||||||
- type: BallisticAmmoProvider
|
- type: BallisticAmmoProvider
|
||||||
|
mayTransfer: true
|
||||||
whitelist:
|
whitelist:
|
||||||
tags:
|
tags:
|
||||||
- CartridgePistol
|
- CartridgePistol
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
id: BaseMagazineBoxRifle
|
id: BaseMagazineBoxRifle
|
||||||
components:
|
components:
|
||||||
- type: BallisticAmmoProvider
|
- type: BallisticAmmoProvider
|
||||||
|
mayTransfer: true
|
||||||
whitelist:
|
whitelist:
|
||||||
tags:
|
tags:
|
||||||
- CartridgeRifle
|
- CartridgeRifle
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
name: foamdart box
|
name: foamdart box
|
||||||
components:
|
components:
|
||||||
- type: BallisticAmmoProvider
|
- type: BallisticAmmoProvider
|
||||||
|
mayTransfer: true
|
||||||
capacity: 30
|
capacity: 30
|
||||||
- type: Sprite
|
- type: Sprite
|
||||||
netsync: false
|
netsync: false
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
tags:
|
tags:
|
||||||
- MagazineCaselessRifle
|
- MagazineCaselessRifle
|
||||||
- type: BallisticAmmoProvider
|
- type: BallisticAmmoProvider
|
||||||
|
mayTransfer: true
|
||||||
whitelist:
|
whitelist:
|
||||||
tags:
|
tags:
|
||||||
- CartridgeCaselessRifle
|
- CartridgeCaselessRifle
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
- type: Item
|
- type: Item
|
||||||
size: 10
|
size: 10
|
||||||
- type: BallisticAmmoProvider
|
- type: BallisticAmmoProvider
|
||||||
|
mayTransfer: true
|
||||||
capacity: 100
|
capacity: 100
|
||||||
- type: ContainerContainer
|
- type: ContainerContainer
|
||||||
containers:
|
containers:
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
tags:
|
tags:
|
||||||
- MagazineLightRifle
|
- MagazineLightRifle
|
||||||
- type: BallisticAmmoProvider
|
- type: BallisticAmmoProvider
|
||||||
|
mayTransfer: true
|
||||||
whitelist:
|
whitelist:
|
||||||
tags:
|
tags:
|
||||||
- CartridgeLightRifle
|
- CartridgeLightRifle
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
tags:
|
tags:
|
||||||
- MagazineMagnum
|
- MagazineMagnum
|
||||||
- type: BallisticAmmoProvider
|
- type: BallisticAmmoProvider
|
||||||
|
mayTransfer: true
|
||||||
whitelist:
|
whitelist:
|
||||||
tags:
|
tags:
|
||||||
- CartridgeMagnum
|
- CartridgeMagnum
|
||||||
@@ -41,6 +42,7 @@
|
|||||||
tags:
|
tags:
|
||||||
- MagazineMagnumSubMachineGun
|
- MagazineMagnumSubMachineGun
|
||||||
- type: BallisticAmmoProvider
|
- type: BallisticAmmoProvider
|
||||||
|
mayTransfer: true
|
||||||
whitelist:
|
whitelist:
|
||||||
tags:
|
tags:
|
||||||
- CartridgeMagnum
|
- CartridgeMagnum
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
tags:
|
tags:
|
||||||
- MagazinePistol
|
- MagazinePistol
|
||||||
- type: BallisticAmmoProvider
|
- type: BallisticAmmoProvider
|
||||||
|
mayTransfer: true
|
||||||
whitelist:
|
whitelist:
|
||||||
tags:
|
tags:
|
||||||
- CartridgePistol
|
- CartridgePistol
|
||||||
@@ -41,6 +42,7 @@
|
|||||||
tags:
|
tags:
|
||||||
- MagazinePistolHighCapacity
|
- MagazinePistolHighCapacity
|
||||||
- type: BallisticAmmoProvider
|
- type: BallisticAmmoProvider
|
||||||
|
mayTransfer: true
|
||||||
whitelist:
|
whitelist:
|
||||||
tags:
|
tags:
|
||||||
- CartridgePistol
|
- CartridgePistol
|
||||||
@@ -74,6 +76,7 @@
|
|||||||
tags:
|
tags:
|
||||||
- MagazinePistolSubMachineGun
|
- MagazinePistolSubMachineGun
|
||||||
- type: BallisticAmmoProvider
|
- type: BallisticAmmoProvider
|
||||||
|
mayTransfer: true
|
||||||
whitelist:
|
whitelist:
|
||||||
tags:
|
tags:
|
||||||
- CartridgePistol
|
- CartridgePistol
|
||||||
@@ -106,6 +109,7 @@
|
|||||||
tags:
|
tags:
|
||||||
- MagazinePistolSubMachineGunTopMounted
|
- MagazinePistolSubMachineGunTopMounted
|
||||||
- type: BallisticAmmoProvider
|
- type: BallisticAmmoProvider
|
||||||
|
mayTransfer: true
|
||||||
proto: CartridgePistol
|
proto: CartridgePistol
|
||||||
whitelist:
|
whitelist:
|
||||||
tags:
|
tags:
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
- type: Item
|
- type: Item
|
||||||
size: 5
|
size: 5
|
||||||
- type: BallisticAmmoProvider
|
- type: BallisticAmmoProvider
|
||||||
|
mayTransfer: true
|
||||||
whitelist:
|
whitelist:
|
||||||
tags:
|
tags:
|
||||||
- CartridgeRifle
|
- CartridgeRifle
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
tags:
|
tags:
|
||||||
- MagazineShotgun
|
- MagazineShotgun
|
||||||
- type: BallisticAmmoProvider
|
- type: BallisticAmmoProvider
|
||||||
|
mayTransfer: true
|
||||||
whitelist:
|
whitelist:
|
||||||
tags:
|
tags:
|
||||||
- ShellShotgun
|
- ShellShotgun
|
||||||
|
|||||||
Reference in New Issue
Block a user