diff --git a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Revolver.cs b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Revolver.cs index 0a8d973e9a..ef933c7de2 100644 --- a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Revolver.cs +++ b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Revolver.cs @@ -6,6 +6,8 @@ using Robust.Shared.Containers; using Robust.Shared.GameStates; using Robust.Shared.Serialization; using Robust.Shared.Utility; +using System; +using System.Linq; namespace Content.Shared.Weapons.Ranged.Systems; @@ -73,27 +75,88 @@ public partial class SharedGunSystem public bool TryRevolverInsert(RevolverAmmoProviderComponent component, EntityUid uid, EntityUid? user) { - if (component.Whitelist?.IsValid(uid, EntityManager) == false) return false; + if (component.Whitelist?.IsValid(uid, EntityManager) == false) + return false; - for (var i = 0; i < component.Capacity; i++) + if (EntityManager.HasComponent(uid)) // Checks if the thing that's being used to reload the revolver is a quickloader { - var index = (component.CurrentIndex + i) % component.Capacity; + var ammoComp = EntityManager.GetComponent(uid); - if (component.AmmoSlots[index] != null || - component.Chambers[index] != null) continue; + if (ammoComp.UnspawnedCount + ammoComp.Entities.Count == 0) // Checks if there's no ammo left in the speedloader + { + Popup(Loc.GetString("gun-speedloader-empty"), component.Owner, user); // Tell the user that the speedloader is empty + return false; // Don't try to insert anything into the revolver. + } - component.AmmoSlots[index] = uid; - component.AmmoContainer.Insert(uid); - Audio.PlayPredicted(component.SoundInsert, component.Owner, user); - Popup(Loc.GetString("gun-revolver-insert"), component.Owner, user); - UpdateRevolverAppearance(component); - UpdateAmmoCount(uid); - Dirty(component); - return true; + var loadedBullet = false; // Used later + + for (var i = 0; i < component.Capacity; i++) + { + if (ammoComp.UnspawnedCount + ammoComp.Entities.Count == 0) // Checks if there's any ammo left in the speedloader in the loop + continue; // The loop doesn't continue, this is a fucking lie! I HATE C#!!! + + var index = (component.CurrentIndex + i) % component.Capacity; + + if (component.AmmoSlots[index] != null || + component.Chambers[index] != null) continue; + + loadedBullet = true; // Used later + + var xform = EntityManager.GetComponent(uid); + EntityUid bullet; // empty var that is guarenteed to be filled + + if (ammoComp.Container.ContainedEntities.Count == 0) // If the entity doesn't have any spawned bullets + { + ammoComp.UnspawnedCount -= 1; + bullet = Spawn(ammoComp.FillProto, xform.MapPosition); // Spawn it in + } + else + { + bullet = ammoComp.Container.ContainedEntities.FirstOrNull()!.Value; + ammoComp.Entities.Remove(bullet); // Remove the bullet from the container, ensures no bugs happen with the quickloader. + } + + // Loads the bullet into the chamber of the revolver + component.AmmoSlots[index] = bullet; + component.AmmoContainer.Insert(bullet); + UpdateBallisticAppearance(ammoComp); + UpdateRevolverAppearance(component); + UpdateAmmoCount(bullet); + Dirty(component); + } + if (!loadedBullet) // Used now, if true, do funny sound + do popup, otherwise do popup to say that the revolver is full + { + Popup(Loc.GetString("gun-revolver-full"), component.Owner, user); + return false; + } + else + { + Audio.PlayPredicted(component.SoundInsert, component.Owner, user); + Popup(Loc.GetString("gun-revolver-insert"), component.Owner, user); + return true; + } } + else + { + for (var i = 0; i < component.Capacity; i++) + { + var index = (component.CurrentIndex + i) % component.Capacity; - Popup(Loc.GetString("gun-revolver-full"), component.Owner, user); - return false; + if (component.AmmoSlots[index] != null || + component.Chambers[index] != null) continue; + + component.AmmoSlots[index] = uid; + component.AmmoContainer.Insert(uid); + Audio.PlayPredicted(component.SoundInsert, component.Owner, user); + Popup(Loc.GetString("gun-revolver-insert"), component.Owner, user); + UpdateRevolverAppearance(component); + UpdateAmmoCount(uid); + Dirty(component); + return true; + } + Popup(Loc.GetString("gun-revolver-full"), component.Owner, user); + return false; + } } private void OnRevolverVerbs(EntityUid uid, RevolverAmmoProviderComponent component, GetVerbsEvent args) diff --git a/Resources/Locale/en-US/weapons/ranged/gun.ftl b/Resources/Locale/en-US/weapons/ranged/gun.ftl index 574f8e6450..2dd840e25d 100644 --- a/Resources/Locale/en-US/weapons/ranged/gun.ftl +++ b/Resources/Locale/en-US/weapons/ranged/gun.ftl @@ -32,3 +32,4 @@ gun-revolver-full = Revolver full gun-revolver-insert = Inserted gun-revolver-spin = Spin revolver gun-revolver-spun = Spun +gun-speedloader-empty = Speedloader empty \ No newline at end of file diff --git a/Resources/Prototypes/Entities/Objects/Fun/toys.yml b/Resources/Prototypes/Entities/Objects/Fun/toys.yml index e5ac73fcdd..9eded76445 100644 --- a/Resources/Prototypes/Entities/Objects/Fun/toys.yml +++ b/Resources/Prototypes/Entities/Objects/Fun/toys.yml @@ -566,6 +566,7 @@ whitelist: tags: - CartridgeCap + - SpeedLoaderCap proto: CartridgeCap capacity: 6 chambers: [ True, True, True, True, True, True ] diff --git a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/SpeedLoaders/magnum.yml b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/SpeedLoaders/magnum.yml index 89e915f376..5abb3761a5 100644 --- a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/SpeedLoaders/magnum.yml +++ b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/SpeedLoaders/magnum.yml @@ -4,6 +4,9 @@ parent: BaseItem abstract: true components: + - type: Tag + tags: + - SpeedLoaderMagnum - type: BallisticAmmoProvider whitelist: tags: diff --git a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/SpeedLoaders/pistol.yml b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/SpeedLoaders/pistol.yml index 8e3841ad8c..6117f74b7b 100644 --- a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/SpeedLoaders/pistol.yml +++ b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/SpeedLoaders/pistol.yml @@ -4,6 +4,9 @@ parent: BaseItem abstract: true components: + - type: Tag + tags: + - SpeedLoaderPistol - type: BallisticAmmoProvider whitelist: tags: diff --git a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/SpeedLoaders/rifle_light.yml b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/SpeedLoaders/rifle_light.yml index 846c79da90..ddaab0cdcc 100644 --- a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/SpeedLoaders/rifle_light.yml +++ b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/SpeedLoaders/rifle_light.yml @@ -3,6 +3,9 @@ name: "speed loader (.30 rifle)" parent: BaseItem components: + - type: Tag + tags: + - SpeedLoaderRifle - type: BallisticAmmoProvider whitelist: tags: diff --git a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/SpeedLoaders/toy.yml b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/SpeedLoaders/toy.yml index e6fb23a304..5387b8eb8c 100644 --- a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/SpeedLoaders/toy.yml +++ b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/SpeedLoaders/toy.yml @@ -4,6 +4,9 @@ parent: BaseItem abstract: true components: + - type: Tag + tags: + - SpeedLoaderCap - type: BallisticAmmoProvider whitelist: tags: diff --git a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Revolvers/revolvers.yml b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Revolvers/revolvers.yml index 09a0449933..3d76916e56 100644 --- a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Revolvers/revolvers.yml +++ b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Revolvers/revolvers.yml @@ -30,6 +30,7 @@ whitelist: tags: - CartridgeMagnum + - SpeedLoaderMagnum proto: CartridgeMagnum capacity: 7 chambers: [ True, True, True, True, True, True, True ] diff --git a/Resources/Prototypes/tags.yml b/Resources/Prototypes/tags.yml index c86b500c5b..93d90b889f 100644 --- a/Resources/Prototypes/tags.yml +++ b/Resources/Prototypes/tags.yml @@ -377,6 +377,9 @@ - type: Tag id: NoSpinOnThrow +- type: Tag + id: NoBlockAnchoring + - type: Tag id: NukeOpsUplink @@ -492,6 +495,18 @@ - type: Tag id: Spear +- type: Tag + id: SpeedLoaderCap + +- type: Tag + id: SpeedLoaderMagnum + +- type: Tag + id: SpeedLoaderPistol + +- type: Tag + id: SpeedLoaderRifle + - type: Tag id: StringInstrument