Combat/FactionTag.cs

A small component that tags a GameObject with a faction string, defaulting to "lizard", plus a static helper to look up the tag on itself or its ancestors. NPCs use it to decide how to treat things.

/// <summary>
/// Which side something appears to be on. NPCs read this to decide how to treat it; wearing a
/// skin changes the lizard's faction to the skin's.
/// </summary>
[Title( "Faction Tag" ), Category( "Combat" ), Icon( "flag" )]
public sealed class FactionTag : Component
{
	public const string Lizard = "lizard";
	public const string Owners = "owners";

	[Property] public string Faction { get; set; } = Lizard;

	/// <summary>The faction of an object (looking up its parents too), or null if it has none.</summary>
	public static string Of( GameObject go ) =>
		go.IsValid() ? go.Components.Get<FactionTag>( FindMode.EverythingInSelfAndAncestors )?.Faction : null;
}