]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Predict base and damage examines of cartridge ammo. (#39401)
authorKyle Tyo <36606155+VerinSenpai@users.noreply.github.com>
Wed, 6 Aug 2025 14:29:57 +0000 (10:29 -0400)
committerGitHub <noreply@github.com>
Wed, 6 Aug 2025 14:29:57 +0000 (16:29 +0200)
* commit

* requested changes +

Content.Server/Weapons/Ranged/Systems/GunSystem.Cartridges.cs [deleted file]
Content.Shared/Weapons/Ranged/Components/AmmoComponent.cs
Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Cartridges.cs

diff --git a/Content.Server/Weapons/Ranged/Systems/GunSystem.Cartridges.cs b/Content.Server/Weapons/Ranged/Systems/GunSystem.Cartridges.cs
deleted file mode 100644 (file)
index 770bd2f..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-using Content.Shared.Damage;
-using Content.Shared.Damage.Events;
-using Content.Shared.Examine;
-using Content.Shared.FixedPoint;
-using Content.Shared.Projectiles;
-using Content.Shared.Weapons.Ranged.Components;
-using Robust.Shared.Prototypes;
-
-namespace Content.Server.Weapons.Ranged.Systems;
-
-public sealed partial class GunSystem
-{
-    protected override void InitializeCartridge()
-    {
-        base.InitializeCartridge();
-        SubscribeLocalEvent<CartridgeAmmoComponent, ExaminedEvent>(OnCartridgeExamine);
-        SubscribeLocalEvent<CartridgeAmmoComponent, DamageExamineEvent>(OnCartridgeDamageExamine);
-    }
-
-    private void OnCartridgeDamageExamine(EntityUid uid, CartridgeAmmoComponent component, ref DamageExamineEvent args)
-    {
-        var damageSpec = GetProjectileDamage(component.Prototype);
-
-        if (damageSpec == null)
-            return;
-
-        _damageExamine.AddDamageExamine(args.Message, Damageable.ApplyUniversalAllModifiers(damageSpec), Loc.GetString("damage-projectile"));
-    }
-
-    private DamageSpecifier? GetProjectileDamage(string proto)
-    {
-        if (!ProtoManager.TryIndex<EntityPrototype>(proto, out var entityProto))
-            return null;
-
-        if (entityProto.Components
-            .TryGetValue(Factory.GetComponentName<ProjectileComponent>(), out var projectile))
-        {
-            var p = (ProjectileComponent) projectile.Component;
-
-            if (!p.Damage.Empty)
-            {
-                return p.Damage * Damageable.UniversalProjectileDamageModifier;
-            }
-        }
-
-        return null;
-    }
-
-    private void OnCartridgeExamine(EntityUid uid, CartridgeAmmoComponent component, ExaminedEvent args)
-    {
-        if (component.Spent)
-        {
-            args.PushMarkup(Loc.GetString("gun-cartridge-spent"));
-        }
-        else
-        {
-            args.PushMarkup(Loc.GetString("gun-cartridge-unspent"));
-        }
-    }
-}
index 13cee5bad6f853c5c78ccb59f8b4fbef2ca80b88..0ba8a5faee0f632ef96ea8913030e8f9c64405ce 100644 (file)
@@ -1,7 +1,6 @@
 using Robust.Shared.Audio;
 using Robust.Shared.GameStates;
 using Robust.Shared.Prototypes;
-using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
 
 namespace Content.Shared.Weapons.Ranged.Components;
 
@@ -23,11 +22,16 @@ public partial class AmmoComponent : Component, IShootable
 [RegisterComponent, NetworkedComponent, AutoGenerateComponentState(fieldDeltas: true)]
 public sealed partial class CartridgeAmmoComponent : AmmoComponent
 {
-    [ViewVariables(VVAccess.ReadWrite), DataField("proto", required: true)]
+    /// <summary>
+    /// Prototype of the ammo to be shot.
+    /// </summary>
+    [DataField("proto", required: true)]
     public EntProtoId Prototype;
 
-    [ViewVariables(VVAccess.ReadWrite), DataField]
-    [AutoNetworkedField]
+    /// <summary>
+    /// Is this cartridge spent?
+    /// </summary>
+    [DataField, AutoNetworkedField]
     public bool Spent;
 
     /// <summary>
@@ -36,6 +40,9 @@ public sealed partial class CartridgeAmmoComponent : AmmoComponent
     [DataField]
     public bool DeleteOnSpawn;
 
+    /// <summary>
+    /// Sound the case makes when it leaves the weapon.
+    /// </summary>
     [DataField("soundEject")]
     public SoundSpecifier? EjectSound = new SoundCollectionSpecifier("CasingEject");
 }
index b28b4b7508e2c78bcb54a2dab804974f9c29e893..dcc9a5689a2dd9bb63042031da4063393e959d20 100644 (file)
@@ -1,13 +1,52 @@
+using Content.Shared.Damage;
+using Content.Shared.Damage.Events;
+using Content.Shared.Damage.Systems;
+using Content.Shared.Examine;
+using Content.Shared.Projectiles;
 using Content.Shared.Weapons.Ranged.Components;
-using Robust.Shared.GameStates;
-using Robust.Shared.Serialization;
+using Robust.Shared.Prototypes;
 
 namespace Content.Shared.Weapons.Ranged.Systems;
 
 public abstract partial class SharedGunSystem
 {
+    [Dependency] private readonly DamageExamineSystem _damageExamine = default!;
+
     // needed for server system
     protected virtual void InitializeCartridge()
     {
+        SubscribeLocalEvent<CartridgeAmmoComponent, ExaminedEvent>(OnCartridgeExamine);
+        SubscribeLocalEvent<CartridgeAmmoComponent, DamageExamineEvent>(OnCartridgeDamageExamine);
+    }
+
+    private void OnCartridgeExamine(Entity<CartridgeAmmoComponent> ent, ref ExaminedEvent args)
+    {
+        args.PushMarkup(ent.Comp.Spent
+            ? Loc.GetString("gun-cartridge-spent")
+            : Loc.GetString("gun-cartridge-unspent"));
+    }
+
+    private void OnCartridgeDamageExamine(EntityUid uid, CartridgeAmmoComponent component, ref DamageExamineEvent args)
+    {
+        var damageSpec = GetProjectileDamage(component.Prototype);
+
+        if (damageSpec == null)
+            return;
+
+        _damageExamine.AddDamageExamine(args.Message, Damageable.ApplyUniversalAllModifiers(damageSpec), Loc.GetString("damage-projectile"));
+    }
+
+    private DamageSpecifier? GetProjectileDamage(EntProtoId proto)
+    {
+        if (!ProtoManager.TryIndex(proto, out var entityProto))
+            return null;
+
+        if (!entityProto.TryGetComponent<ProjectileComponent>(out var projectile, Factory))
+            return null;
+
+        if (!projectile.Damage.Empty)
+            return projectile.Damage * Damageable.UniversalProjectileDamageModifier;
+
+        return null;
     }
 }