Files
RobustToolbox/SS14.Client/GameObjects/Component/Damageable/DamageableComponent.cs
2017-07-07 00:17:24 +02:00

46 lines
1.1 KiB
C#

using SS14.Shared.GameObjects;
using SS14.Shared.GameObjects.Components.Damageable;
using SS14.Shared.IoC;
using System;
namespace SS14.Client.GameObjects
{
/// <summary>
/// Basic damageable component only tracks whether its dead or not
/// </summary>
public class DamageableComponent : ClientComponent
{
public override string Name => "Damageable";
//Used for things that are binary. Either broken or not broken. (windows?)
protected bool IsDead;
public DamageableComponent()
{
Family = ComponentFamily.Damageable;
}
public override Type StateType
{
get { return typeof(DamageableComponentState); }
}
protected virtual void Die()
{
if (IsDead) return;
IsDead = true;
Owner.SendMessage(this, ComponentMessageType.Die);
}
public override void HandleComponentState(dynamic state)
{
dynamic newIsDeadState = state.IsDead;
if (newIsDeadState && !IsDead)
{
Die();
}
}
}
}