Files
crystall-punk-14/Content.Shared/Damage/Systems/PassiveDamageSystem.cs
Ed e79b046c4a Magic redesign (#594)
* water spell textures

* water creation spell

* mana consume, and mana glove

* remove mana transfer ring

* Update migration.yml

* copy Wizden loadout PR

* add sprite component to all spells

* spell dummy loadouts

* delete spell traits

* really give spells from loadouts

* update crates fill and demiplane spawners

* beer creation spell, fix passivedamage

* Update PassiveDamageSystem.cs
2024-11-20 00:23:44 +03:00

74 lines
2.5 KiB
C#

using Content.Shared.Damage.Components;
using Content.Shared.Mobs.Systems;
using Content.Shared.Mobs.Components;
using Content.Shared.FixedPoint;
using Robust.Shared.Timing;
namespace Content.Shared.Damage;
public sealed class PassiveDamageSystem : EntitySystem
{
[Dependency] private readonly DamageableSystem _damageable = default!;
[Dependency] private readonly IGameTiming _timing = default!;
private EntityQuery<MobStateComponent> _mobStateQuery; //CP14
public override void Initialize()
{
base.Initialize();
_mobStateQuery = GetEntityQuery<MobStateComponent>(); //CP14
SubscribeLocalEvent<PassiveDamageComponent, MapInitEvent>(OnPendingMapInit);
}
private void OnPendingMapInit(EntityUid uid, PassiveDamageComponent component, MapInitEvent args)
{
component.NextDamage = _timing.CurTime + TimeSpan.FromSeconds(1f);
}
// Every tick, attempt to damage entities
public override void Update(float frameTime)
{
base.Update(frameTime);
var curTime = _timing.CurTime;
// Go through every entity with the component
var query = EntityQueryEnumerator<PassiveDamageComponent, DamageableComponent /*, MobStateComponent*/>();
while (query.MoveNext(out var uid, out var comp, out var damage /*, out var mobState*/))
{
// Make sure they're up for a damage tick
if (comp.NextDamage > curTime)
continue;
if (comp.DamageCap != 0 && damage.TotalDamage >= comp.DamageCap)
continue;
// Set the next time they can take damage
comp.NextDamage = curTime + TimeSpan.FromSeconds(1f);
//CP14 logic replacement
//
//// Damage them
//foreach (var allowedState in comp.AllowedStates)
//{
// if(allowedState == mobState.CurrentState)
// _damageable.TryChangeDamage(uid, comp.Damage, true, false, damage);
//}
if (comp.AllowedStates.Count > 0 && _mobStateQuery.TryComp(uid, out var mobState))
{
foreach (var allowedState in comp.AllowedStates)
{
if(allowedState == mobState.CurrentState)
_damageable.TryChangeDamage(uid, comp.Damage, true, false, damage);
}
}
else
{
_damageable.TryChangeDamage(uid, comp.Damage, true, false, damage);
}
//CP14 logic replacement end
}
}
}