* Increase all walls hp by 5 times * Increase reinforced and riveted wall hp as well * Revert "Increase reinforced and riveted wall hp as well" This reverts commit a9d95670e3f6c4d7fb2b2cf3c84503496f685e26. * Increase reinforced and riveted wall hp as well * Merge conflict fixes * Reduced wall hp slightly
87 lines
2.8 KiB
C#
87 lines
2.8 KiB
C#
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;
|
|
using Robust.Shared.ViewVariables;
|
|
|
|
namespace Content.Server.GameObjects.Components.Damage
|
|
{
|
|
/// <summary>
|
|
/// When attached to an <see cref="IEntity"/>, allows it to take damage and
|
|
/// "ruins" or "destroys" it after enough damage is taken.
|
|
/// </summary>
|
|
[ComponentReference(typeof(IDamageableComponent))]
|
|
public abstract class RuinableComponent : DamageableComponent
|
|
{
|
|
private DamageState _currentDamageState;
|
|
|
|
/// <summary>
|
|
/// How much HP this component can sustain before triggering
|
|
/// <see cref="PerformDestruction"/>.
|
|
/// </summary>
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
|
public int MaxHp { get; private set; }
|
|
|
|
/// <summary>
|
|
/// Sound played upon destruction.
|
|
/// </summary>
|
|
protected string DestroySound { get; private set; }
|
|
|
|
public override List<DamageState> SupportedDamageStates =>
|
|
new List<DamageState> {DamageState.Alive, DamageState.Dead};
|
|
|
|
public override DamageState CurrentDamageState => _currentDamageState;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
HealthChangedEvent += OnHealthChanged;
|
|
}
|
|
|
|
public override void ExposeData(ObjectSerializer serializer)
|
|
{
|
|
base.ExposeData(serializer);
|
|
|
|
serializer.DataField(this, ruinable => ruinable.MaxHp, "maxHP", 100);
|
|
serializer.DataField(this, ruinable => ruinable.DestroySound, "destroySound", string.Empty);
|
|
}
|
|
|
|
public override void OnRemove()
|
|
{
|
|
base.OnRemove();
|
|
HealthChangedEvent -= OnHealthChanged;
|
|
}
|
|
|
|
private void OnHealthChanged(HealthChangedEventArgs e)
|
|
{
|
|
if (CurrentDamageState != DamageState.Dead && TotalDamage >= MaxHp)
|
|
{
|
|
PerformDestruction();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Destroys the Owner <see cref="IEntity"/>, setting
|
|
/// <see cref="IDamageableComponent.CurrentDamageState"/> to
|
|
/// <see cref="DamageState.Dead"/>
|
|
/// </summary>
|
|
protected void PerformDestruction()
|
|
{
|
|
_currentDamageState = DamageState.Dead;
|
|
|
|
if (!Owner.Deleted && DestroySound != string.Empty)
|
|
{
|
|
var pos = Owner.Transform.GridPosition;
|
|
EntitySystem.Get<AudioSystem>().PlayAtCoords(DestroySound, pos);
|
|
}
|
|
|
|
DestructionBehavior();
|
|
}
|
|
|
|
protected abstract void DestructionBehavior();
|
|
}
|
|
}
|