using System.Collections.Generic; using Content.Shared.GameObjects.Components.Damage; using Robust.Server.GameObjects.EntitySystems; using Robust.Shared.GameObjects; using Robust.Shared.GameObjects.Systems; using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Serialization; namespace Content.Server.GameObjects.Components.Damage { /// /// When attached to an , allows it to take damage and /// "ruins" or "destroys" it after enough damage is taken. /// [ComponentReference(typeof(IDamageableComponent))] public abstract class RuinableComponent : DamageableComponent { private DamageState _currentDamageState; /// /// Sound played upon destruction. /// protected string DestroySound { get; private set; } public override List SupportedDamageStates => new List {DamageState.Alive, DamageState.Dead}; public override DamageState CurrentDamageState => _currentDamageState; public override void ExposeData(ObjectSerializer serializer) { base.ExposeData(serializer); serializer.DataReadWriteFunction( "deadThreshold", 100, t => DeadThreshold = t , () => DeadThreshold ?? -1); serializer.DataField(this, ruinable => ruinable.DestroySound, "destroySound", string.Empty); } protected override void EnterState(DamageState state) { base.EnterState(state); if (state == DamageState.Dead) { PerformDestruction(); } } /// /// Destroys the Owner , setting /// to /// /// protected void PerformDestruction() { _currentDamageState = DamageState.Dead; if (!Owner.Deleted && DestroySound != string.Empty) { var pos = Owner.Transform.Coordinates; EntitySystem.Get().PlayAtCoords(DestroySound, pos); } DestructionBehavior(); } protected abstract void DestructionBehavior(); } }