2021-11-09 21:24:35 +01:00
using Content.Server.Construction ;
2021-09-15 03:07:37 +10:00
using Content.Server.Destructible.Thresholds ;
2021-11-09 21:24:35 +01:00
using Content.Server.Explosion.EntitySystems ;
2021-09-15 03:07:37 +10:00
using Content.Shared.Acts ;
using Content.Shared.Damage ;
2020-12-23 13:34:57 +01:00
using JetBrains.Annotations ;
2021-02-11 01:13:03 -08:00
using Robust.Server.GameObjects ;
using Robust.Shared.GameObjects ;
2020-12-23 13:34:57 +01:00
using Robust.Shared.IoC ;
2021-02-11 01:13:03 -08:00
using Robust.Shared.Random ;
2020-12-23 13:34:57 +01:00
2021-06-09 22:19:39 +02:00
namespace Content.Server.Destructible
2020-12-23 13:34:57 +01:00
{
[UsedImplicitly]
public class DestructibleSystem : EntitySystem
{
[Dependency] public readonly IRobustRandom Random = default ! ;
2021-11-09 21:24:35 +01:00
public new IEntityManager EntityManager = > base . EntityManager ;
2021-07-26 12:58:17 +02:00
[Dependency] public readonly ActSystem ActSystem = default ! ;
2021-11-09 21:24:35 +01:00
[Dependency] public readonly AudioSystem AudioSystem = default ! ;
[Dependency] public readonly ConstructionSystem ConstructionSystem = default ! ;
[Dependency] public readonly ExplosionSystem ExplosionSystem = default ! ;
2021-09-15 03:07:37 +10:00
public override void Initialize ( )
{
base . Initialize ( ) ;
SubscribeLocalEvent < DestructibleComponent , DamageChangedEvent > ( Execute ) ;
}
/// <summary>
/// Check if any thresholds were reached. if they were, execute them.
/// </summary>
public void Execute ( EntityUid uid , DestructibleComponent component , DamageChangedEvent args )
{
foreach ( var threshold in component . Thresholds )
{
if ( threshold . Reached ( args . Damageable , this ) )
{
RaiseLocalEvent ( uid , new DamageThresholdReached ( component , threshold ) ) ;
2021-11-09 12:06:00 +01:00
threshold . Execute ( uid , this , EntityManager ) ;
2021-09-15 03:07:37 +10:00
}
2022-01-18 20:48:17 +13:00
// if destruction behavior (or some other deletion effect) occurred, don't run other triggers.
if ( EntityManager . IsQueuedForDeletion ( uid ) | | Deleted ( uid ) )
return ;
2021-09-15 03:07:37 +10:00
}
}
}
// Currently only used for destructible integration tests. Unless other uses are found for this, maybe this should just be removed and the tests redone.
/// <summary>
/// Event raised when a <see cref="DamageThreshold"/> is reached.
/// </summary>
public class DamageThresholdReached : EntityEventArgs
{
public readonly DestructibleComponent Parent ;
public readonly DamageThreshold Threshold ;
public DamageThresholdReached ( DestructibleComponent parent , DamageThreshold threshold )
{
Parent = parent ;
Threshold = threshold ;
}
2020-12-23 13:34:57 +01:00
}
2021-02-05 13:41:05 +01:00
}