Predict base and damage examines of cartridge ammo. (#39401)
* commit * requested changes +
This commit is contained in:
@@ -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"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user