From ca18576625ec149a5b9bc444b35e963653dac23d Mon Sep 17 00:00:00 2001 From: Kyle Tyo <36606155+VerinSenpai@users.noreply.github.com> Date: Wed, 6 Aug 2025 10:29:57 -0400 Subject: [PATCH] Predict base and damage examines of cartridge ammo. (#39401) * commit * requested changes + --- .../Ranged/Systems/GunSystem.Cartridges.cs | 60 ------------------- .../Ranged/Components/AmmoComponent.cs | 15 +++-- .../Systems/SharedGunSystem.Cartridges.cs | 43 ++++++++++++- 3 files changed, 52 insertions(+), 66 deletions(-) delete mode 100644 Content.Server/Weapons/Ranged/Systems/GunSystem.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 index 770bd2f7b6..0000000000 --- a/Content.Server/Weapons/Ranged/Systems/GunSystem.Cartridges.cs +++ /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(OnCartridgeExamine); - SubscribeLocalEvent(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(proto, out var entityProto)) - return null; - - if (entityProto.Components - .TryGetValue(Factory.GetComponentName(), 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")); - } - } -} diff --git a/Content.Shared/Weapons/Ranged/Components/AmmoComponent.cs b/Content.Shared/Weapons/Ranged/Components/AmmoComponent.cs index 13cee5bad6..0ba8a5faee 100644 --- a/Content.Shared/Weapons/Ranged/Components/AmmoComponent.cs +++ b/Content.Shared/Weapons/Ranged/Components/AmmoComponent.cs @@ -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)] + /// + /// Prototype of the ammo to be shot. + /// + [DataField("proto", required: true)] public EntProtoId Prototype; - [ViewVariables(VVAccess.ReadWrite), DataField] - [AutoNetworkedField] + /// + /// Is this cartridge spent? + /// + [DataField, AutoNetworkedField] public bool Spent; /// @@ -36,6 +40,9 @@ public sealed partial class CartridgeAmmoComponent : AmmoComponent [DataField] public bool DeleteOnSpawn; + /// + /// Sound the case makes when it leaves the weapon. + /// [DataField("soundEject")] public SoundSpecifier? EjectSound = new SoundCollectionSpecifier("CasingEject"); } diff --git a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Cartridges.cs b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Cartridges.cs index b28b4b7508..dcc9a5689a 100644 --- a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Cartridges.cs +++ b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Cartridges.cs @@ -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(OnCartridgeExamine); + SubscribeLocalEvent(OnCartridgeDamageExamine); + } + + private void OnCartridgeExamine(Entity 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(out var projectile, Factory)) + return null; + + if (!projectile.Damage.Empty) + return projectile.Damage * Damageable.UniversalProjectileDamageModifier; + + return null; } } -- 2.51.2