Files
wwdpublic/Content.Shared/Damage/Systems/SharedDamageOtherOnHitSystem.cs
Skubman a665f310a9 Throwing Mini-Update 1 (#1434)
# Description

Bug fixes:

- Re-enable damage examine for embeddable passive damage after the
Wizmerge for Station AI wiped it
(https://github.com/Simple-Station/Einstein-Engines/pull/1351)
- Fixed a bug where emags did not have embed passive damage (due to
`DamageOtherOnHitStartupEvent` only raising when `MeleeWeaponComponent`
exists on the entity)

Tweaks:

- Added a stamina cost to spears, 6 stamina, and removed spears dealing
damage to itself when thrown
- Floor tiles will now break when thrown 10 times instead of 4 times
- Added the MetalThud sound effect for structures when thrown, and
increased the base thrown damage of structures slightly from 8 to 9

Damage examine is now sorted properly. From top to bottom:
- Gun damage
- Melee weapon damage
- Throwing weapon damage
- Embed passive damage

## Media

**Laser rifle sorted damage examine**

![image](https://github.com/user-attachments/assets/6fe2a47b-b354-415a-8835-8f0e33c6da00)

**Spear sorted damage examine**

![image](https://github.com/user-attachments/assets/0c93c125-08ce-4e5b-9af9-5c5ceddcd3b1)

**Emag stats**

![image](https://github.com/user-attachments/assets/ac9b1073-b209-4a44-badf-8f8ec9f8514a)

## Changelog

🆑 Skubman
- fix: Fixed embeddable damage over time not showing when examining an
item's damage values.
- fix: Fixed the emag not dealing passive damage when embedded on a
target.
- tweak: Examining an item's damage values now shows values in a sorted
order. From top to bottom: gun damage, melee damage, throwing damage,
embedded damage.
- tweak: Spears now have a 6 stamina cost when thrown, and they no
longer break when thrown enough times.
- tweak: Floor tiles now break when thrown 10 times instead of 4 times.
- tweak: Closets, lockers and crates now play the proper sound effect
when thrown (by Space Wind).

(cherry picked from commit 6c70875882cb9435a6172ef103660e0fcf1d27fd)
2025-01-14 01:26:24 +03:00

202 lines
9.0 KiB
C#

using Content.Shared.Administration.Logs;
using Content.Shared.Camera;
using Content.Shared.Contests;
using Content.Shared.Damage;
using Content.Shared.Damage.Components;
using Content.Shared.Damage.Events;
using Content.Shared.Database;
using Content.Shared.Effects;
using Content.Shared.Item.ItemToggle.Components;
using Content.Shared.Mobs.Components;
using Content.Shared.Projectiles;
using Content.Shared.Popups;
using Content.Shared.Throwing;
using Content.Shared.Weapons.Melee;
using Robust.Shared.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Systems;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;
namespace Content.Shared.Damage.Systems
{
public abstract partial class SharedDamageOtherOnHitSystem : EntitySystem
{
[Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
[Dependency] private readonly DamageableSystem _damageable = default!;
[Dependency] private readonly SharedCameraRecoilSystem _sharedCameraRecoil = default!;
[Dependency] private readonly SharedColorFlashEffectSystem _color = default!;
[Dependency] private readonly ThrownItemSystem _thrownItem = default!;
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
[Dependency] private readonly MeleeSoundSystem _meleeSound = default!;
[Dependency] private readonly IPrototypeManager _protoManager = default!;
[Dependency] private readonly ContestsSystem _contests = default!;
public override void Initialize()
{
SubscribeLocalEvent<DamageOtherOnHitComponent, MapInitEvent>(OnMapInit);
SubscribeLocalEvent<DamageOtherOnHitComponent, ThrowDoHitEvent>(OnDoHit);
SubscribeLocalEvent<DamageOtherOnHitComponent, ThrownEvent>(OnThrown);
SubscribeLocalEvent<ItemToggleDamageOtherOnHitComponent, MapInitEvent>(OnItemToggleMapInit);
SubscribeLocalEvent<DamageOtherOnHitComponent, ItemToggledEvent>(OnItemToggle);
}
/// <summary>
/// Inherit stats from MeleeWeapon.
/// </summary>
private void OnMapInit(EntityUid uid, DamageOtherOnHitComponent component, MapInitEvent args)
{
if (TryComp<MeleeWeaponComponent>(uid, out var melee))
{
if (component.Damage.Empty)
component.Damage = melee.Damage * component.MeleeDamageMultiplier;
if (component.SoundHit == null)
component.SoundHit = melee.SoundHit;
if (component.SoundNoDamage == null)
{
if (melee.SoundNoDamage != null)
component.SoundNoDamage = melee.SoundNoDamage;
else
component.SoundNoDamage = new SoundCollectionSpecifier("WeakHit");
}
}
RaiseLocalEvent(uid, new DamageOtherOnHitStartupEvent((uid, component)));
}
/// <summary>
/// Inherit stats from ItemToggleMeleeWeaponComponent.
/// </summary>
private void OnItemToggleMapInit(EntityUid uid, ItemToggleDamageOtherOnHitComponent component, MapInitEvent args)
{
if (!TryComp<ItemToggleMeleeWeaponComponent>(uid, out var itemToggleMelee) ||
!TryComp<DamageOtherOnHitComponent>(uid, out var damage))
return;
if (component.ActivatedDamage == null && itemToggleMelee.ActivatedDamage is {} activatedDamage)
component.ActivatedDamage = activatedDamage * damage.MeleeDamageMultiplier;
if (component.ActivatedSoundHit == null)
component.ActivatedSoundHit = itemToggleMelee.ActivatedSoundOnHit;
if (component.ActivatedSoundNoDamage == null && itemToggleMelee.ActivatedSoundOnHitNoDamage is {} activatedSoundOnHitNoDamage)
component.ActivatedSoundNoDamage = activatedSoundOnHitNoDamage;
RaiseLocalEvent(uid, new ItemToggleDamageOtherOnHitStartupEvent((uid, component)));
}
private void OnDoHit(EntityUid uid, DamageOtherOnHitComponent component, ThrowDoHitEvent args)
{
if (component.HitQuantity >= component.MaxHitQuantity)
return;
var modifiedDamage = _damageable.TryChangeDamage(args.Target, GetDamage(uid, component, args.Component.Thrower),
component.IgnoreResistances, origin: args.Component.Thrower, targetPart: args.TargetPart);
// Log damage only for mobs. Useful for when people throw spears at each other, but also avoids log-spam when explosions send glass shards flying.
if (modifiedDamage != null)
{
if (HasComp<MobStateComponent>(args.Target))
_adminLogger.Add(LogType.ThrowHit, $"{ToPrettyString(args.Target):target} received {modifiedDamage.GetTotal():damage} damage from collision");
_meleeSound.PlayHitSound(args.Target, null, SharedMeleeWeaponSystem.GetHighestDamageSound(modifiedDamage, _protoManager), null,
component.SoundHit, component.SoundNoDamage);
}
if (modifiedDamage is { Empty: false })
_color.RaiseEffect(Color.Red, new List<EntityUid>() { args.Target }, Filter.Pvs(args.Target, entityManager: EntityManager));
if (TryComp<PhysicsComponent>(uid, out var body) && body.LinearVelocity.LengthSquared() > 0f)
{
var direction = body.LinearVelocity.Normalized();
_sharedCameraRecoil.KickCamera(args.Target, direction);
}
// TODO: If more stuff touches this then handle it after.
if (TryComp<PhysicsComponent>(uid, out var physics))
{
_thrownItem.LandComponent(args.Thrown, args.Component, physics, false);
if (!HasComp<EmbeddableProjectileComponent>(args.Thrown))
{
var newVelocity = physics.LinearVelocity;
newVelocity.X = -newVelocity.X / 4;
newVelocity.Y = -newVelocity.Y / 4;
_physics.SetLinearVelocity(uid, newVelocity, body: physics);
}
}
component.HitQuantity += 1;
}
/// <summary>
/// Used to update the DamageOtherOnHit component on item toggle.
/// </summary>
private void OnItemToggle(EntityUid uid, DamageOtherOnHitComponent component, ItemToggledEvent args)
{
if (!TryComp<ItemToggleDamageOtherOnHitComponent>(uid, out var itemToggle))
return;
if (args.Activated)
{
if (itemToggle.ActivatedDamage is {} activatedDamage)
{
itemToggle.DeactivatedDamage ??= component.Damage;
component.Damage = activatedDamage * component.MeleeDamageMultiplier;
}
if (itemToggle.ActivatedStaminaCost is {} activatedStaminaCost)
{
itemToggle.DeactivatedStaminaCost ??= component.StaminaCost;
component.StaminaCost = activatedStaminaCost;
}
itemToggle.DeactivatedSoundHit ??= component.SoundHit;
component.SoundHit = itemToggle.ActivatedSoundHit;
if (itemToggle.ActivatedSoundNoDamage is {} activatedSoundNoDamage)
{
itemToggle.DeactivatedSoundNoDamage ??= component.SoundNoDamage;
component.SoundNoDamage = activatedSoundNoDamage;
}
}
else
{
if (itemToggle.DeactivatedDamage is {} deactivatedDamage)
component.Damage = deactivatedDamage;
if (itemToggle.DeactivatedStaminaCost is {} deactivatedStaminaCost)
component.StaminaCost = deactivatedStaminaCost;
component.SoundHit = itemToggle.DeactivatedSoundHit;
if (itemToggle.DeactivatedSoundNoDamage is {} deactivatedSoundNoDamage)
component.SoundNoDamage = deactivatedSoundNoDamage;
}
}
private void OnThrown(EntityUid uid, DamageOtherOnHitComponent component, ThrownEvent args)
{
component.HitQuantity = 0;
}
/// <summary>
/// Gets the total damage a throwing weapon does.
/// </summary>
public DamageSpecifier GetDamage(EntityUid uid, DamageOtherOnHitComponent? component = null, EntityUid? user = null)
{
if (!Resolve(uid, ref component, false))
return new DamageSpecifier();
var ev = new GetThrowingDamageEvent(uid, component.Damage, new(), user);
RaiseLocalEvent(uid, ref ev);
if (component.ContestArgs is not null && user is EntityUid userUid)
ev.Damage *= _contests.ContestConstructor(userUid, component.ContestArgs);
return DamageSpecifier.ApplyModifierSets(ev.Damage, ev.Modifiers);
}
}
}