Abstract base class for unit statuses. It stores references to the Unit and whether it is an Enemy or Player, tracks elapsed time and lifetime, and exposes virtual lifecycle and event hooks (Init, Update, OnHurt, OnHit, Die, etc.) for concrete status implementations to override.
using System;
using Sandbox;
public abstract class UnitStatus
{
public Unit Unit { get; protected set; }
public bool IsOnEnemy { get; set; }
public Enemy Enemy { get; set; }
public Player Player { get; set; }
public TimeSince ElapsedTime { get; set; }
public float Lifetime { get; set; }
public bool ShouldUpdate { get; protected set; }
public UnitStatus()
{
}
public virtual void Init( Unit unit )
{
Unit = unit;
if ( Unit is Enemy enemy )
{
IsOnEnemy = true;
Enemy = enemy;
}
else if ( Unit is Player player )
{
IsOnEnemy = false;
Player = player;
}
ElapsedTime = 0f;
ShouldUpdate = true;
}
public virtual void Update( float dt )
{
}
public virtual void StartDying( Player player )
{
}
public virtual void Die( Player player )
{
}
public virtual void OnRemove( bool playEffects = true )
{
}
public virtual void Refresh()
{
}
public virtual void Colliding( Thing other, float percent, float dt )
{
}
public virtual void OnHurt( float damage, Player playerSource, Enemy enemySource, DamageType damageType, bool isSelfInflicted )
{
}
public virtual void OnHit( float damage, Player playerSource, Enemy enemySource, DamageType damageType, bool isSelfInflicted )
{
}
}