From 63f2724341344a76ebb7a3fef350b6056b7c795d Mon Sep 17 00:00:00 2001 From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Thu, 25 Jun 2020 01:29:40 +1000 Subject: [PATCH] Add default ammo for guns (#1207) * Add default ammo types * Add revolver and bolt action default pro support Co-authored-by: Metal Gear Sloth --- .../Barrels/BoltActionBarrelComponent.cs | 9 ++++++- .../Ranged/Barrels/RevolverBarrelComponent.cs | 27 ++++++++++++++++--- .../Barrels/ServerMagazineBarrelComponent.cs | 15 +++++++++-- .../Prototypes/Entities/Weapons/LMGs/lmgs.yml | 2 ++ .../Entities/Weapons/Launchers/launchers.yml | 2 ++ .../Entities/Weapons/Pistols/pistols.yml | 4 +++ .../Entities/Weapons/Revolvers/revolvers.yml | 3 +++ .../Entities/Weapons/Rifles/rifles.yml | 5 ++++ .../Prototypes/Entities/Weapons/SMGs/smgs.yml | 4 +++ .../Entities/Weapons/Shotguns/shotguns.yml | 4 +++ .../Entities/Weapons/Snipers/snipers.yml | 2 ++ 11 files changed, 71 insertions(+), 6 deletions(-) diff --git a/Content.Server/GameObjects/Components/Weapon/Ranged/Barrels/BoltActionBarrelComponent.cs b/Content.Server/GameObjects/Components/Weapon/Ranged/Barrels/BoltActionBarrelComponent.cs index a5bfbbe7a3..bd97e4f742 100644 --- a/Content.Server/GameObjects/Components/Weapon/Ranged/Barrels/BoltActionBarrelComponent.cs +++ b/Content.Server/GameObjects/Components/Weapon/Ranged/Barrels/BoltActionBarrelComponent.cs @@ -110,7 +110,13 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels { if (_fillPrototype != null) { - _unspawnedCount += Capacity - 1; + _unspawnedCount += Capacity; + if (_unspawnedCount > 0) + { + _unspawnedCount--; + var chamberEntity = Owner.EntityManager.SpawnEntity(_fillPrototype, Owner.Transform.GridPosition); + _chamberContainer.Insert(chamberEntity); + } } UpdateAppearance(); } @@ -139,6 +145,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels } _appearanceComponent?.SetData(MagazineBarrelVisuals.MagLoaded, true); + Dirty(); UpdateAppearance(); } diff --git a/Content.Server/GameObjects/Components/Weapon/Ranged/Barrels/RevolverBarrelComponent.cs b/Content.Server/GameObjects/Components/Weapon/Ranged/Barrels/RevolverBarrelComponent.cs index d5f5540f28..74333c1e6d 100644 --- a/Content.Server/GameObjects/Components/Weapon/Ranged/Barrels/RevolverBarrelComponent.cs +++ b/Content.Server/GameObjects/Components/Weapon/Ranged/Barrels/RevolverBarrelComponent.cs @@ -32,6 +32,8 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels public override int ShotsLeft => _ammoContainer.ContainedEntities.Count; private AppearanceComponent _appearanceComponent; + private string _fillPrototype; + private int _unspawnedCount; // Sounds private string _soundEject; @@ -50,7 +52,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels } // TODO: Writing? - + serializer.DataField(ref _fillPrototype, "fillPrototype", null); // Sounds serializer.DataField(ref _soundEject, "soundEject", "/Audio/Guns/MagOut/revolver_magout.ogg"); @@ -61,13 +63,32 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels public override void Initialize() { base.Initialize(); - _ammoContainer = ContainerManagerComponent.Ensure($"{Name}-ammoContainer", Owner); + _unspawnedCount = Capacity; + int idx = 0; + _ammoContainer = ContainerManagerComponent.Ensure($"{Name}-ammoContainer", Owner, out var existing); + if (existing) + { + foreach (var entity in _ammoContainer.ContainedEntities) + { + _unspawnedCount--; + _ammoSlots[idx] = entity; + idx++; + } + } + + for (var i = 0; i < _unspawnedCount; i++) + { + var entity = Owner.EntityManager.SpawnEntity(_fillPrototype, Owner.Transform.GridPosition); + _ammoSlots[idx] = entity; + _ammoContainer.Insert(entity); + idx++; + } if (Owner.TryGetComponent(out AppearanceComponent appearanceComponent)) { _appearanceComponent = appearanceComponent; } - + _appearanceComponent?.SetData(MagazineBarrelVisuals.MagLoaded, true); } diff --git a/Content.Server/GameObjects/Components/Weapon/Ranged/Barrels/ServerMagazineBarrelComponent.cs b/Content.Server/GameObjects/Components/Weapon/Ranged/Barrels/ServerMagazineBarrelComponent.cs index d4863587a7..73ad1c3c38 100644 --- a/Content.Server/GameObjects/Components/Weapon/Ranged/Barrels/ServerMagazineBarrelComponent.cs +++ b/Content.Server/GameObjects/Components/Weapon/Ranged/Barrels/ServerMagazineBarrelComponent.cs @@ -14,7 +14,6 @@ using Robust.Shared.Containers; using Robust.Shared.GameObjects; using Robust.Shared.GameObjects.Systems; using Robust.Shared.Interfaces.GameObjects; -using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Serialization; using Robust.Shared.ViewVariables; @@ -72,6 +71,8 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels } } + private string _magFillPrototype; + public bool BoltOpen { get; private set; } = true; private bool _autoEjectMag; // If the bolt needs to be open before we can insert / remove the mag (i.e. for LMGs) @@ -100,6 +101,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels } } serializer.DataField(ref _caliber, "caliber", BallisticCaliber.Unspecified); + serializer.DataField(ref _magFillPrototype, "magFillPrototype", null); serializer.DataField(ref _autoEjectMag, "autoEjectMag", false); serializer.DataField(ref _magNeedsOpenBolt, "magNeedsOpenBolt", false); serializer.DataField(ref _soundBoltOpen, "soundBoltOpen", null); @@ -136,7 +138,16 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels } _chamberContainer = ContainerManagerComponent.Ensure($"{Name}-chamber", Owner); - _magazineContainer = ContainerManagerComponent.Ensure($"{Name}-magazine", Owner); + _magazineContainer = ContainerManagerComponent.Ensure($"{Name}-magazine", Owner, out var existing); + + if (!existing && _magFillPrototype != null) + { + var magEntity = Owner.EntityManager.SpawnEntity(_magFillPrototype, Owner.Transform.GridPosition); + _magazineContainer.Insert(magEntity); + } + + Dirty(); + UpdateAppearance(); } public void ToggleBolt() diff --git a/Resources/Prototypes/Entities/Weapons/LMGs/lmgs.yml b/Resources/Prototypes/Entities/Weapons/LMGs/lmgs.yml index 9985f9780d..e81a103849 100644 --- a/Resources/Prototypes/Entities/Weapons/LMGs/lmgs.yml +++ b/Resources/Prototypes/Entities/Weapons/LMGs/lmgs.yml @@ -56,6 +56,7 @@ sprite: Objects/Guns/LMGs/l6.rsi - type: RangedWeapon - type: MagazineBarrel + magFillPrototype: MagazineLRifleBox fireRate: 5 minAngle: 0 maxAngle: 45 @@ -91,6 +92,7 @@ sprite: Objects/Guns/LMGs/pk.rsi - type: RangedWeapon - type: MagazineBarrel + magFillPrototype: MagazineLRiflePkBox fireRate: 5 minAngle: 0 maxAngle: 45 diff --git a/Resources/Prototypes/Entities/Weapons/Launchers/launchers.yml b/Resources/Prototypes/Entities/Weapons/Launchers/launchers.yml index a7544c1923..62950fff8b 100644 --- a/Resources/Prototypes/Entities/Weapons/Launchers/launchers.yml +++ b/Resources/Prototypes/Entities/Weapons/Launchers/launchers.yml @@ -37,6 +37,7 @@ currentSelector: Single allSelectors: - Single + fillPrototype: GrenadeFrag fireRate: 1 capacity: 3 soundEmpty: /Audio/Guns/Empty/empty.ogg @@ -70,6 +71,7 @@ currentSelector: Single allSelectors: - Single + fillPrototype: RocketAmmo fireRate: 0.5 capacity: 1 soundEmpty: /Audio/Guns/Empty/empty.ogg diff --git a/Resources/Prototypes/Entities/Weapons/Pistols/pistols.yml b/Resources/Prototypes/Entities/Weapons/Pistols/pistols.yml index fba5f1f820..8774592200 100644 --- a/Resources/Prototypes/Entities/Weapons/Pistols/pistols.yml +++ b/Resources/Prototypes/Entities/Weapons/Pistols/pistols.yml @@ -31,6 +31,7 @@ maxAngle: 60 angleIncrease: 10 angleDecay: 60 + magFillPrototype: MagazinePistol soundGunshot: /Audio/Guns/Gunshots/pistol.ogg soundEmpty: /Audio/Guns/Empty/empty.ogg soundRack: /Audio/Guns/Cock/pistol_cock.ogg @@ -193,6 +194,7 @@ caliber: Magnum magazineTypes: - Pistol + magFillPrototype: MagazineMagnum autoEjectMag: true fireRate: 5 minAngle: 0 @@ -236,6 +238,7 @@ caliber: ClRifle magazineTypes: - Pistol + magFillPrototype: MagazineClRiflePistol autoEjectMag: true canMuzzleFlash: false # Dat in-built suppressor minAngle: 0 @@ -330,6 +333,7 @@ magazineTypes: - HCPistol - Smg + magFillPrototype: MagazinePistolSmg autoEjectMag: true fireRate: 6 minAngle: 0 diff --git a/Resources/Prototypes/Entities/Weapons/Revolvers/revolvers.yml b/Resources/Prototypes/Entities/Weapons/Revolvers/revolvers.yml index e16849f322..8e21794ba9 100644 --- a/Resources/Prototypes/Entities/Weapons/Revolvers/revolvers.yml +++ b/Resources/Prototypes/Entities/Weapons/Revolvers/revolvers.yml @@ -37,6 +37,7 @@ currentSelector: Single allSelectors: - Single + fillPrototype: CartridgeMagnum caliber: Magnum capacity: 5 autoCycle: true @@ -69,6 +70,7 @@ currentSelector: Single allSelectors: - Single + fillPrototype: CartridgeMagnum caliber: Magnum capacity: 7 soundEmpty: /Audio/Guns/Empty/empty.ogg @@ -94,6 +96,7 @@ currentSelector: Single allSelectors: - Single + fillPrototype: CartridgeMagnum caliber: Magnum capacity: 7 soundEmpty: /Audio/Guns/Empty/empty.ogg diff --git a/Resources/Prototypes/Entities/Weapons/Rifles/rifles.yml b/Resources/Prototypes/Entities/Weapons/Rifles/rifles.yml index 8ec39ca798..fb53c8bfc6 100644 --- a/Resources/Prototypes/Entities/Weapons/Rifles/rifles.yml +++ b/Resources/Prototypes/Entities/Weapons/Rifles/rifles.yml @@ -16,6 +16,7 @@ currentSelector: Automatic allSelectors: - Automatic + magFillPrototype: MagazineLRifle fireRate: 5 minAngle: 0 maxAngle: 45 @@ -132,6 +133,7 @@ caliber: SRifle magazineTypes: - Rifle + magFillPrototype: MagazineSRifle fireRate: 5 minAngle: 0 maxAngle: 45 @@ -172,6 +174,7 @@ caliber: ClRifle magazineTypes: - Rifle + magFillPrototype: MagazineClRifle10x24 fireRate: 8 minAngle: 10 maxAngle: 60 @@ -255,6 +258,7 @@ caliber: SRifle magazineTypes: - Rifle + magFillPrototype: MagazineSRifle fireRate: 5 minAngle: 0 maxAngle: 45 @@ -293,6 +297,7 @@ caliber: SRifle magazineTypes: - Rifle + magFillPrototype: MagazineSRifle autoEjectMag: true fireRate: 5 minAngle: 0 diff --git a/Resources/Prototypes/Entities/Weapons/SMGs/smgs.yml b/Resources/Prototypes/Entities/Weapons/SMGs/smgs.yml index acbb218e9e..7088d4f227 100644 --- a/Resources/Prototypes/Entities/Weapons/SMGs/smgs.yml +++ b/Resources/Prototypes/Entities/Weapons/SMGs/smgs.yml @@ -25,6 +25,7 @@ maxAngle: 60 angleIncrease: 10 angleDecay: 60 + magFillPrototype: MagazinePistolSmg soundGunshot: /Audio/Guns/Gunshots/smg.ogg soundEmpty: /Audio/Guns/Empty/empty.ogg soundRack: /Audio/Guns/Cock/smg_cock.ogg @@ -146,6 +147,7 @@ caliber: Magnum magazineTypes: - Smg + magFillPrototype: MagazineMagnumSmg minAngle: 5 maxAngle: 60 angleIncrease: 12 @@ -229,6 +231,7 @@ caliber: Pistol magazineTypes: - SmgTopMounted + magFillPrototype: MagazinePistolSmgTopMounted - type: Appearance visuals: - type: MagVisualizer2D @@ -265,6 +268,7 @@ caliber: Magnum magazineTypes: - Smg + magFillPrototype: MagazineMagnumSmg - type: Appearance visuals: - type: BarrelBoltVisualizer2D diff --git a/Resources/Prototypes/Entities/Weapons/Shotguns/shotguns.yml b/Resources/Prototypes/Entities/Weapons/Shotguns/shotguns.yml index f74118a9fe..f311f652e4 100644 --- a/Resources/Prototypes/Entities/Weapons/Shotguns/shotguns.yml +++ b/Resources/Prototypes/Entities/Weapons/Shotguns/shotguns.yml @@ -16,6 +16,7 @@ currentSelector: Single allSelectors: - Single + fillPrototype: ShellShotgun caliber: Shotgun capacity: 7 fireRate: 2.0 @@ -57,6 +58,7 @@ caliber: Shotgun magazineTypes: - Rifle + magFillPrototype: MagazineShotgun soundGunshot: /Audio/Guns/Gunshots/shotgun.ogg soundEmpty: /Audio/Guns/Empty/empty.ogg soundRack: /Audio/Guns/Cock/smg_cock.ogg @@ -98,6 +100,7 @@ currentSelector: Single allSelectors: - Single + fillPrototype: ShellShotgun capacity: 2 fireRate: 8.0 minAngle: 10 @@ -221,6 +224,7 @@ currentSelector: Single allSelectors: - Single + fillPrototype: ShellShotgun capacity: 2 fireRate: 8.0 minAngle: 10 diff --git a/Resources/Prototypes/Entities/Weapons/Snipers/snipers.yml b/Resources/Prototypes/Entities/Weapons/Snipers/snipers.yml index 61eadb9802..d72097857f 100644 --- a/Resources/Prototypes/Entities/Weapons/Snipers/snipers.yml +++ b/Resources/Prototypes/Entities/Weapons/Snipers/snipers.yml @@ -20,6 +20,7 @@ currentSelector: Single allSelectors: - Single + fillPrototype: CartridgeLRifle caliber: LRifle capacity: 10 fireRate: 1.0 @@ -79,6 +80,7 @@ - type: BoltActionBarrel caliber: AntiMaterial capacity: 1 + fillPrototype: CartridgeAntiMaterial - type: Appearance visuals: - type: BarrelBoltVisualizer2D