NPCs/HostileNPC.cs

namespace Opium.AI;

public partial class HostileNPC : Agent
{
	/// <summary>
	/// Actors what have done damage to us so we hate them
	/// </summary>
	private List<Actor> HostileActors = new();

	public override void OnDamage( in Sandbox.DamageInfo damage )
	{
		base.OnDamage( damage );

		// These don't ever seem to work?
		if ( damage.Hitbox?.Tags.Has( "head" ) ?? false )
			Health = 0;

		var attackerActor = damage.Attacker.Components.Get<Actor>( FindMode.EverythingInSelfAndAncestors );

		if ( attackerActor == null ) return;
		if ( HostileActors.Contains( attackerActor ) ) return;

		HostileActors.Add( attackerActor );
	}

	public override bool Hates( Actor other )
	{
		if ( Relationship.GetFriendState( this, other ) != Relationship.FriendState.Friend )
		{
			return true;
		}

		if ( HostileActors.Contains( other ) )
			return true;

		return false;
	}
}