]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Mosin be tested, Verin be breaded. (#40957)
authorKyle Tyo <36606155+VerinSenpai@users.noreply.github.com>
Tue, 21 Oct 2025 15:40:41 +0000 (11:40 -0400)
committerGitHub <noreply@github.com>
Tue, 21 Oct 2025 15:40:41 +0000 (15:40 +0000)
* Create WeaponSniperTests.cs

* Update SharedGunSystem.cs

* requested changes.

* Update WeaponTests.cs

* rerun tests

* Update WeaponTests.cs

* Update WeaponTests.cs

* Update Content.IntegrationTests/Tests/Weapons/WeaponTests.cs

---------

Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
Content.IntegrationTests/Tests/Weapons/WeaponTests.cs [new file with mode: 0644]
Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.cs

diff --git a/Content.IntegrationTests/Tests/Weapons/WeaponTests.cs b/Content.IntegrationTests/Tests/Weapons/WeaponTests.cs
new file mode 100644 (file)
index 0000000..bf240ba
--- /dev/null
@@ -0,0 +1,63 @@
+using Content.IntegrationTests.Tests.Interaction;
+using Content.Shared.Damage;
+using Content.Shared.Weapons.Ranged.Components;
+using Content.Shared.Weapons.Ranged.Systems;
+using Content.Shared.Wieldable.Components;
+using Robust.Shared.Prototypes;
+
+namespace Content.IntegrationTests.Tests.Weapons;
+
+public sealed class WeaponTests : InteractionTest
+{
+    protected override string PlayerPrototype => "MobHuman"; // The default test mob only has one hand
+    private static readonly EntProtoId MobHuman = "MobHuman";
+    private static readonly EntProtoId SniperMosin = "WeaponSniperMosin";
+
+    [Test]
+    public async Task GunRequiresWieldTest()
+    {
+        var gunSystem = SEntMan.System<SharedGunSystem>();
+
+        await AddAtmosphere(); // prevent the Urist from suffocating
+
+        var urist = await SpawnTarget(MobHuman);
+        var damageComp = Comp<DamageableComponent>(urist);
+
+        var mosinNet = await PlaceInHands(SniperMosin);
+        var mosinEnt = ToServer(mosinNet);
+
+        await Pair.RunSeconds(2f); // Guns have a cooldown when picking them up.
+
+        Assert.That(HasComp<GunRequiresWieldComponent>(mosinNet),
+            "Looks like you've removed the 'GunRequiresWield' component from the mosin sniper." +
+            "If this was intentional, please update WeaponTests.cs to reflect this change!");
+
+        var startAmmo = gunSystem.GetAmmoCount(mosinEnt);
+        var wieldComp = Comp<WieldableComponent>(mosinNet);
+
+        Assert.That(startAmmo, Is.GreaterThan(0), "Mosin was spawned with no ammo!");
+        Assert.That(wieldComp.Wielded, Is.False, "Mosin was spawned wielded!");
+
+        await AttemptShoot(urist, false); // should fail due to not being wielded
+        var updatedAmmo = gunSystem.GetAmmoCount(mosinEnt);
+
+        Assert.That(updatedAmmo,
+            Is.EqualTo(startAmmo),
+            "Mosin discharged ammo when the weapon should not have fired!");
+        Assert.That(damageComp.TotalDamage.Value,
+            Is.EqualTo(0),
+            "Urist took damage when the weapon should not have fired!");
+
+        await UseInHand();
+
+        Assert.That(wieldComp.Wielded, Is.True, "Mosin failed to wield when interacted with!");
+
+        await AttemptShoot(urist);
+        updatedAmmo = gunSystem.GetAmmoCount(mosinEnt);
+
+        Assert.That(updatedAmmo, Is.EqualTo(startAmmo - 1), "Mosin failed to discharge appropriate amount of ammo!");
+        Assert.That(damageComp.TotalDamage.Value,
+            Is.GreaterThan(0),
+            "Mosin was fired but urist sustained no damage!");
+    }
+}
index bbfd4a051eba76396b83abd32e8a214837c0d31b..1b7bf4bae84668e92fdf9767dc02df177c797b22 100644 (file)
@@ -628,6 +628,26 @@ public abstract partial class SharedGunSystem : EntitySystem
     {
         public List<(NetCoordinates coordinates, Angle angle, SpriteSpecifier Sprite, float Distance)> Sprites = new();
     }
+
+    /// <summary>
+    /// Get the ammo count for a given EntityUid. Can be a firearm or magazine.
+    /// </summary>
+    public int GetAmmoCount(EntityUid uid)
+    {
+        var ammoEv = new GetAmmoCountEvent();
+        RaiseLocalEvent(uid, ref ammoEv);
+        return ammoEv.Count;
+    }
+
+    /// <summary>
+    /// Get the ammo capacity for a given EntityUid. Can be a firearm or magazine.
+    /// </summary>
+    public int GetAmmoCapacity(EntityUid uid)
+    {
+        var ammoEv = new GetAmmoCountEvent();
+        RaiseLocalEvent(uid, ref ammoEv);
+        return ammoEv.Capacity;
+    }
 }
 
 /// <summary>