Revolver fixes (#12697)

This commit is contained in:
metalgearsloth
2022-12-07 10:38:10 +11:00
committed by GitHub
parent 94240c41ec
commit b4688bc682
15 changed files with 133 additions and 194 deletions

View File

@@ -0,0 +1,12 @@
using Robust.Shared.GameStates;
namespace Content.Shared.Weapons.Ranged.Components;
/// <summary>
/// Allows this entity to bulk change revolver ammo.
/// </summary>
[RegisterComponent, NetworkedComponent]
public sealed class SpeedLoaderComponent : Component
{
}

View File

@@ -78,85 +78,92 @@ public partial class SharedGunSystem
if (component.Whitelist?.IsValid(uid, EntityManager) == false)
return false;
if (EntityManager.HasComponent<BallisticAmmoProviderComponent>(uid)) // Checks if the thing that's being used to reload the revolver is a quickloader
// If it's a speedloader try to get ammo from it.
if (EntityManager.HasComponent<SpeedLoaderComponent>(uid))
{
var ammoComp = EntityManager.GetComponent<BallisticAmmoProviderComponent>(uid);
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.
}
var loadedBullet = false; // Used later
var freeSlots = 0;
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#!!!
if (component.AmmoSlots[i] != null || component.Chambers[i] != null)
continue;
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<TransformComponent>(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);
freeSlots++;
}
if (!loadedBullet) // Used now, if true, do funny sound + do popup, otherwise do popup to say that the revolver is full
if (freeSlots == 0)
{
Popup(Loc.GetString("gun-revolver-full"), component.Owner, user);
return false;
}
else
var xformQuery = GetEntityQuery<TransformComponent>();
var xform = xformQuery.GetComponent(uid);
var ammo = new List<IShootable>(freeSlots);
var ev = new TakeAmmoEvent(freeSlots, ammo, xform.Coordinates, user);
RaiseLocalEvent(uid, ev);
if (ev.Ammo.Count == 0)
{
Audio.PlayPredicted(component.SoundInsert, component.Owner, user);
Popup(Loc.GetString("gun-revolver-insert"), component.Owner, user);
return true;
Popup(Loc.GetString("gun-speedloader-empty"), component.Owner, user);
return false;
}
}
else
{
for (var i = 0; i < component.Capacity; i++)
for (var i = Math.Min(ev.Ammo.Count - 1, component.Capacity - 1); i >= 0; i--)
{
var index = (component.CurrentIndex + i) % component.Capacity;
if (component.AmmoSlots[index] != null ||
component.Chambers[index] != null) continue;
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;
var ent = ev.Ammo.Last();
ev.Ammo.RemoveAt(ev.Ammo.Count - 1);
if (ent is not AmmoComponent ammoComp)
{
Sawmill.Error($"Tried to load hitscan into a revolver which is unsupported");
continue;
}
component.AmmoSlots[index] = ammoComp.Owner;
component.AmmoContainer.Insert(ammoComp.Owner, EntityManager);
if (ev.Ammo.Count == 0)
break;
}
Popup(Loc.GetString("gun-revolver-full"), component.Owner, user);
return false;
DebugTools.Assert(ammo.Count == 0);
UpdateRevolverAppearance(component);
UpdateAmmoCount(uid);
Dirty(component);
Audio.PlayPredicted(component.SoundInsert, component.Owner, user);
Popup(Loc.GetString("gun-revolver-insert"), component.Owner, user);
return true;
}
// Try to insert the entity directly.
for (var i = 0; i < component.Capacity; i++)
{
var index = (component.CurrentIndex + i) % component.Capacity;
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<Verb> args)

View File

@@ -91,10 +91,10 @@
# Magnum
- type: entity
name: box of .40 Lamia magazines
name: box of Lamia magazines
parent: BoxCardboard
id: BoxMagazineMagnum
description: A box full of .40 Lamia magazines.
description: A box full of Lamia magazines.
components:
- type: StorageFill
contents:
@@ -102,10 +102,10 @@
amount: 6
- type: entity
name: box of .40 Lamia (high-velocity) magazines
name: box of Lamia (high-velocity) magazines
parent: BoxCardboard
id: BoxMagazineMagnumHighVelocity
description: A box full of .40 Lamia (high-velocity) magazines.
description: A box full of Lamia (high-velocity) magazines.
components:
- type: StorageFill
contents:
@@ -113,10 +113,10 @@
amount: 6
- type: entity
name: box of .40 Lamia (practice) magazines
name: box of Lamia (practice) magazines
parent: BoxCardboard
id: BoxMagazineMagnumPractice
description: A box full of .40 Lamia (practice) magazines.
description: A box full of Lamia (practice) magazines.
components:
- type: StorageFill
contents:
@@ -124,10 +124,10 @@
amount: 6
- type: entity
name: box of .40 Vector magazines
name: box of Vector magazines
parent: BoxCardboard
id: BoxMagazineMagnumSubMachineGun
description: A box full of .40 Vector magazines.
description: A box full of Vector magazines.
components:
- type: StorageFill
contents:
@@ -135,10 +135,10 @@
amount: 3
- type: entity
name: box of .40 Vector (high-velocity) magazines
name: box of Vector (high-velocity) magazines
parent: BoxCardboard
id: BoxMagazineMagnumSubMachineGunHighVelocity
description: A box full of .40 Vector (high-velocity) magazines.
description: A box full of Vector (high-velocity) magazines.
components:
- type: StorageFill
contents:
@@ -146,10 +146,10 @@
amount: 3
- type: entity
name: box of .40 Vector (practice) magazines
name: box of Vector (practice) magazines
parent: BoxCardboard
id: BoxMagazineMagnumSubMachineGunPractice
description: A box full of .40 Vector (practice) magazines.
description: A box full of Vector (practice) magazines.
components:
- type: StorageFill
contents:
@@ -157,10 +157,10 @@
amount: 3
- type: entity
name: box of .40 Vector (rubber) magazines
name: box of Vector (rubber) magazines
parent: BoxCardboard
id: BoxMagazineMagnumSubMachineGunRubber
description: A box full of .40 Vector (rubber) magazines.
description: A box full of Vector (rubber) magazines.
components:
- type: StorageFill
contents:

View File

@@ -27,7 +27,7 @@
- type: entity
parent: BaseMagazineBoxMagnum
id: MagazineBoxMagnum
name: ammunition box (.40 magnum)
name: ammunition box (.45 magnum)
components:
- type: BallisticAmmoProvider
proto: CartridgeMagnum
@@ -41,7 +41,7 @@
- type: entity
parent: BaseMagazineBoxMagnum
id: MagazineBoxMagnumHighVelocity
name: ammunition box (.40 magnum high-velocity)
name: ammunition box (.45 magnum high-velocity)
components:
- type: BallisticAmmoProvider
proto: CartridgeMagnumHighVelocity
@@ -56,7 +56,7 @@
- type: entity
parent: BaseMagazineBoxMagnum
id: MagazineBoxMagnumPractice
name: ammunition box (.40 magnum practice)
name: ammunition box (.45 magnum practice)
components:
- type: BallisticAmmoProvider
proto: CartridgeMagnumPractice
@@ -71,7 +71,7 @@
- type: entity
parent: BaseMagazineBoxMagnum
id: MagazineBoxMagnumRubber
name: ammunition box (.40 magnum rubber)
name: ammunition box (.45 magnum rubber)
components:
- type: BallisticAmmoProvider
proto: CartridgeMagnumRubber

View File

@@ -1,6 +1,6 @@
- type: entity
id: BaseCartridgeMagnum
name: cartridge (.40 magnum)
name: cartridge (.45 magnum)
parent: BaseCartridge
abstract: true
components:
@@ -23,7 +23,7 @@
- type: entity
id: CartridgeMagnum
name: cartridge (.40 magnum)
name: cartridge (.45 magnum)
parent: BaseCartridgeMagnum
components:
- type: CartridgeAmmo
@@ -31,31 +31,15 @@
- type: entity
id: CartridgeMagnumHighVelocity
name: cartridge (.40 magnum high-velocity)
name: cartridge (.45 magnum high-velocity)
parent: BaseCartridgeMagnum
components:
- type: CartridgeAmmo
proto: BulletMagnumHighVelocity
- type: entity
id: CartridgeMagnumHC
name: cartridge (.45 magnum)
parent: BaseCartridgeMagnum
components:
- type: CartridgeAmmo
proto: BulletMagnumHC
- type: entity
id: CartridgeMagnumHCHighVelocity
name: cartridge (.45 magnum high-velocity)
parent: BaseCartridgeMagnum
components:
- type: CartridgeAmmo
proto: BulletMagnumHCHighVelocity
- type: entity
id: CartridgeMagnumPractice
name: cartridge (.40 magnum practice)
name: cartridge (.45 magnum practice)
parent: BaseCartridgeMagnum
components:
- type: CartridgeAmmo
@@ -63,7 +47,7 @@
- type: entity
id: CartridgeMagnumRubber
name: cartridge (.40 magnum rubber)
name: cartridge (.45 magnum rubber)
parent: BaseCartridgeMagnum
components:
- type: CartridgeAmmo

View File

@@ -1,6 +1,6 @@
- type: entity
id: BaseMagazineMagnum
name: "Lamia magazine (.40 magnum)"
name: "Lamia magazine (.45 magnum)"
parent: BaseItem
abstract: true
components:
@@ -33,7 +33,7 @@
- type: entity
id: BaseMagazineMagnumSubMachineGun
name: "Vector magazine (.40 magnum)"
name: "Vector magazine (.45 magnum)"
parent: BaseItem
abstract: true
components:
@@ -66,7 +66,7 @@
- type: entity
id: MagazineMagnum
name: "Lamia magazine (.40 magnum)"
name: "Lamia magazine (.45 magnum)"
parent: BaseMagazineMagnum
components:
- type: BallisticAmmoProvider
@@ -80,7 +80,7 @@
- type: entity
id: MagazineMagnumHighVelocity
name: "Lamia magazine (.40 magnum high-velocity)"
name: "Lamia magazine (.45 magnum high-velocity)"
parent: BaseMagazineMagnum
components:
- type: BallisticAmmoProvider
@@ -94,7 +94,7 @@
- type: entity
id: MagazineMagnumPractice
name: "Lamia magazine (.40 magnum practice)"
name: "Lamia magazine (.45 magnum practice)"
parent: BaseMagazineMagnum
components:
- type: BallisticAmmoProvider
@@ -108,7 +108,7 @@
- type: entity
id: MagazineMagnumRubber
name: "Lamia magazine (.40 magnum rubber)"
name: "Lamia magazine (.45 magnum rubber)"
parent: BaseMagazineMagnum
components:
- type: BallisticAmmoProvider
@@ -122,7 +122,7 @@
- type: entity
id: MagazineMagnumSubMachineGun
name: "Vector magazine (.40 magnum)"
name: "Vector magazine (.45 magnum)"
parent: BaseMagazineMagnumSubMachineGun
components:
- type: BallisticAmmoProvider
@@ -136,7 +136,7 @@
- type: entity
id: MagazineMagnumSubMachineGunHighVelocity
name: "Vector magazine (.40 magnum High-Velocity)"
name: "Vector magazine (.45 magnum High-Velocity)"
parent: BaseMagazineMagnumSubMachineGun
components:
- type: BallisticAmmoProvider
@@ -150,7 +150,7 @@
- type: entity
id: MagazineMagnumSubMachineGunPractice
name: "Vector magazine (.40 magnum practice)"
name: "Vector magazine (.45 magnum practice)"
parent: BaseMagazineMagnumSubMachineGun
components:
- type: BallisticAmmoProvider
@@ -164,7 +164,7 @@
- type: entity
id: MagazineMagnumSubMachineGunRubber
name: "Vector magazine (.40 magnum rubber)"
name: "Vector magazine (.45 magnum rubber)"
parent: BaseMagazineMagnumSubMachineGun
components:
- type: BallisticAmmoProvider

View File

@@ -1,6 +1,6 @@
- type: entity
id: BulletMagnum
name: bullet (.40 magnum)
name: bullet (.45 magnum)
parent: BaseBullet
noSpawn: true
components:
@@ -11,7 +11,7 @@
- type: entity
id: BulletMagnumHighVelocity
name: bullet (.40 magnum high-velocity)
name: bullet (.45 magnum high-velocity)
parent: BaseBulletHighVelocity
noSpawn: true
components:
@@ -20,31 +20,9 @@
types:
Piercing: 24
- type: entity
id: BulletMagnumHC
name: bullet (.45 magnum)
parent: BaseBullet
noSpawn: true
components:
- type: Projectile
damage:
types:
Piercing: 34
- type: entity
id: BulletMagnumHCHighVelocity
name: bullet (.45 magnum high-velocity)
parent: BaseBulletHighVelocity
noSpawn: true
components:
- type: Projectile
damage:
types:
Piercing: 36
- type: entity
id: BulletMagnumPractice
name: bullet (.40 magnum practice)
name: bullet (.45 magnum practice)
parent: BaseBulletPractice
noSpawn: true
components:
@@ -55,7 +33,7 @@
- type: entity
id: BulletMagnumRubber
name: bullet (.40 magnum rubber)
name: bullet (.45 magnum rubber)
parent: BaseBulletRubber
noSpawn: true
components:

View File

@@ -1,12 +1,13 @@
- type: entity
id: BaseSpeedLoaderMagnum
name: "speed loader (.40 magnum)"
name: "speed loader (.45 magnum)"
parent: BaseItem
abstract: true
components:
- type: Tag
tags:
- SpeedLoaderMagnum
- type: SpeedLoader
- type: BallisticAmmoProvider
whitelist:
tags:
@@ -21,7 +22,7 @@
- type: entity
id: SpeedLoaderMagnum
name: "speed loader (.40 magnum)"
name: "speed loader (.45 magnum)"
parent: BaseSpeedLoaderMagnum
components:
- type: BallisticAmmoProvider
@@ -41,7 +42,7 @@
- type: entity
id: SpeedLoaderMagnumHighVelocity
name: "speed loader (.40 magnum high-velocity)"
name: "speed loader (.45 magnum high-velocity)"
parent: BaseSpeedLoaderMagnum
components:
- type: BallisticAmmoProvider
@@ -59,49 +60,9 @@
zeroVisible: false
- type: Appearance
- type: entity
id: SpeedLoaderMagnumHC
name: "speed loader (.45 magnum)"
parent: BaseSpeedLoaderMagnum
components:
- type: BallisticAmmoProvider
proto: BulletMagnumHC
- type: Sprite
sprite: Objects/Weapons/Guns/Ammunition/SpeedLoaders/Magnum/magnum_speed_loader.rsi
layers:
- state: base
map: [ "enum.GunVisualLayers.Base" ]
- state: base-6
map: [ "enum.GunVisualLayers.Mag" ]
- type: MagazineVisuals
magState: base
steps: 7
zeroVisible: false
- type: Appearance
- type: entity
id: SpeedLoaderMagnumHCHighVelocity
name: "speed loader (.45 magnum high-velocity)"
parent: BaseSpeedLoaderMagnum
components:
- type: BallisticAmmoProvider
proto: BulletMagnumHCHighVelocity
- type: Sprite
sprite: Objects/Weapons/Guns/Ammunition/SpeedLoaders/Magnum/magnum_speed_loader.rsi
layers:
- state: base
map: [ "enum.GunVisualLayers.Base" ]
- state: high-velocity-6
map: [ "enum.GunVisualLayers.Mag" ]
- type: MagazineVisuals
magState: high-velocity
steps: 7
zeroVisible: false
- type: Appearance
- type: entity
id: SpeedLoaderMagnumPractice
name: "speed loader (.40 magnum practice)"
name: "speed loader (.45 magnum practice)"
parent: BaseSpeedLoaderMagnum
components:
- type: BallisticAmmoProvider
@@ -121,7 +82,7 @@
- type: entity
id: SpeedLoaderMagnumRubber
name: "speed loader (.40 magnum rubber)"
name: "speed loader (.45 magnum rubber)"
parent: BaseSpeedLoaderMagnum
components:
- type: BallisticAmmoProvider

View File

@@ -7,6 +7,7 @@
- type: Tag
tags:
- SpeedLoaderPistol
- type: SpeedLoader
- type: BallisticAmmoProvider
whitelist:
tags:

View File

@@ -6,6 +6,7 @@
- type: Tag
tags:
- SpeedLoaderRifle
- type: SpeedLoader
- type: BallisticAmmoProvider
whitelist:
tags:

View File

@@ -7,6 +7,7 @@
- type: Tag
tags:
- SpeedLoaderCap
- type: SpeedLoader
- type: BallisticAmmoProvider
whitelist:
tags:

View File

@@ -29,9 +29,9 @@
- type: RevolverAmmoProvider
whitelist:
tags:
- CartridgeMagnumHC
- SpeedLoaderMagnumHC
proto: CartridgeMagnumHC
- CartridgeMagnum
- SpeedLoaderMagnum
proto: CartridgeMagnum
capacity: 7
chambers: [ True, True, True, True, True, True, True ]
ammoSlots: [ null, null, null, null, null, null, null ]

View File

@@ -105,7 +105,7 @@
name: Vector
parent: BaseWeaponSubMachineGun
id: WeaponSubMachineGunVector
description: An excellent fully automatic Heavy SMG. Uses .40 magnum ammo.
description: An excellent fully automatic Heavy SMG. Uses .45 magnum ammo.
components:
- type: Sprite
sprite: Objects/Weapons/Guns/SMGs/vector.rsi
@@ -205,7 +205,7 @@
name: Vector
parent: WeaponSubMachineGunVector
id: WeaponSubMachineGunVectorRubber
description: An excellent fully automatic Heavy SMG. Uses .40 magnum ammo.
description: An excellent fully automatic Heavy SMG. Uses .45 magnum ammo.
suffix: Non-Lethal
components:
- type: ItemSlots

View File

@@ -109,9 +109,9 @@
- type: RevolverAmmoProvider
whitelist:
tags:
- CartridgeMagnumHC
- SpeedLoaderMagnumHC
proto: CartridgeMagnumHC
- CartridgeMagnum
- SpeedLoaderMagnum
proto: CartridgeMagnum
capacity: 7
chambers: [ True, True, True, True, True, True, True ]
ammoSlots: [ null, null, null, null, null, null, null ]

View File

@@ -96,9 +96,6 @@
- type: Tag
id: CartridgeMagnum
- type: Tag
id: CartridgeMagnumHC
- type: Tag
id: CartridgePistol
@@ -519,9 +516,6 @@
- type: Tag
id: SpeedLoaderMagnum
- type: Tag
id: SpeedLoaderMagnumHC
- type: Tag
id: SpeedLoaderPistol