Files
wwdpublic/Content.Shared/Damage/Systems/DamageContactsSystem.cs
Abigail 86add98bef Fix Tendons Damage (#1835)
<!--
This is a semi-strict format, you can add/remove sections as needed but
the order/format should be kept the same
Remove these comments before submitting
-->

# Description
This PR fixes the contact damage used by Tendons.
Fix originally made in space-wizards/space-station-14/pull/31494

---

# Changelog

<!--
You can add an author after the `🆑` to change the name that appears
in the changelog (ex: `🆑 Death`)
Leaving it blank will default to your GitHub display name
This includes all available types for the changelog
-->

🆑
- fix: Fixed tendons not causing damage! Careful!

(cherry picked from commit 2cb054e0e873ea1b56150cf9464db7c2d84c7700)
2025-02-28 16:29:01 +03:00

75 lines
2.4 KiB
C#

using Content.Shared.Damage.Components;
using Content.Shared.Whitelist;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Events;
using Robust.Shared.Physics.Systems;
using Robust.Shared.Timing;
namespace Content.Shared.Damage.Systems;
public sealed class DamageContactsSystem : EntitySystem
{
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly DamageableSystem _damageable = default!;
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
[Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<DamageContactsComponent, StartCollideEvent>(OnEntityEnter);
SubscribeLocalEvent<DamageContactsComponent, EndCollideEvent>(OnEntityExit);
}
public override void Update(float frameTime)
{
base.Update(frameTime);
var query = EntityQueryEnumerator<DamagedByContactComponent>();
while (query.MoveNext(out var ent, out var damaged))
{
if (_timing.CurTime < damaged.NextSecond)
continue;
damaged.NextSecond = _timing.CurTime + TimeSpan.FromSeconds(1);
if (damaged.Damage != null)
_damageable.TryChangeDamage(ent, damaged.Damage, interruptsDoAfters: false);
}
}
private void OnEntityExit(EntityUid uid, DamageContactsComponent component, ref EndCollideEvent args)
{
var otherUid = args.OtherEntity;
if (!TryComp<PhysicsComponent>(uid, out var body))
return;
var damageQuery = GetEntityQuery<DamageContactsComponent>();
foreach (var ent in _physics.GetContactingEntities(uid, body))
{
if (ent == uid)
continue;
if (damageQuery.HasComponent(ent))
return;
}
RemComp<DamagedByContactComponent>(otherUid);
}
private void OnEntityEnter(EntityUid uid, DamageContactsComponent component, ref StartCollideEvent args)
{
var otherUid = args.OtherEntity;
if (HasComp<DamagedByContactComponent>(otherUid))
return;
if (_whitelistSystem.IsWhitelistPass(component.IgnoreWhitelist, otherUid))
return;
var damagedByContact = EnsureComp<DamagedByContactComponent>(otherUid);
damagedByContact.Damage = component.Damage;
}
}