Files
tbd-station-14/Content.Shared/Xenoarchaeology/Artifact/XAE/XAEDamageInAreaSystem.cs
Hannah Giovanna Dawson cdbe92d37d Update DamageableSystem to modern standards (#39417)
* Update DamageableSystem to modern standards

* DamageContainerId -> DamageContainerID with lint flag

* Replace strings with protoids

* Make CVar subscription declarations all consistently whitespaced

* ChangeDamage -> TryChangeDamage, cope with C# jank

* Revert event signature changes

* Restore a comment

* Re-add two queries

* Init the queries

* Use appearanceQuery in DamageChanged

* Use damageableQuery in TryChangeDamage

* Use damageableQuery in SetDamageModifierSetId

* Final cleanup, fix sandboxing

* Rectify ExplosionSystem:::ProcessEntity's call to TryChangeDamage

* Re-organize DamageableSystem

* first big fuck you breaking change.

* THATS A LOT OF DAMAGE!!!

* Fix test fails

* test fixes 2

* push it

---------

Co-authored-by: Princess Cheeseballs <66055347+Pronana@users.noreply.github.com>
2025-10-27 19:53:04 +00:00

45 lines
1.7 KiB
C#

using Content.Shared.Damage;
using Content.Shared.Damage.Systems;
using Content.Shared.Whitelist;
using Content.Shared.Xenoarchaeology.Artifact.XAE.Components;
using Robust.Shared.Random;
using Robust.Shared.Timing;
namespace Content.Shared.Xenoarchaeology.Artifact.XAE;
/// <summary>
/// System for xeno artifact effect that damages entities from whitelist in area.
/// </summary>
public sealed class XAEDamageInAreaSystem : BaseXAESystem<XAEDamageInAreaComponent>
{
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly EntityLookupSystem _lookup = default!;
[Dependency] private readonly DamageableSystem _damageable = default!;
[Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!;
[Dependency] private readonly IGameTiming _timing = default!;
/// <summary> Pre-allocated and re-used collection.</summary>
private readonly HashSet<EntityUid> _entitiesInRange = new();
/// <inheritdoc />
protected override void OnActivated(Entity<XAEDamageInAreaComponent> ent, ref XenoArtifactNodeActivatedEvent args)
{
if (!_timing.IsFirstTimePredicted)
return;
var damageInAreaComponent = ent.Comp;
_entitiesInRange.Clear();
_lookup.GetEntitiesInRange(ent.Owner, damageInAreaComponent.Radius, _entitiesInRange);
foreach (var entityInRange in _entitiesInRange)
{
if (!_random.Prob(damageInAreaComponent.DamageChance))
continue;
if (_whitelistSystem.IsWhitelistFail(damageInAreaComponent.Whitelist, entityInRange))
continue;
_damageable.TryChangeDamage(entityInRange, damageInAreaComponent.Damage, damageInAreaComponent.IgnoreResistances);
}
}
}