using RimWorld;
using Verse;
using Verse.AI;

namespace SCE
{
    public class ThinkNode_ConditionalCloseToNthDutyFocus : ThinkNode_Conditional
    {
        public int focusIndex;

        public float maxDistToDutyTarget = 10f;

        public override ThinkNode DeepCopy(bool resolve = true)
        {
            ThinkNode_ConditionalCloseToNthDutyFocus result = (ThinkNode_ConditionalCloseToNthDutyFocus) base.DeepCopy(resolve);
            result.focusIndex = focusIndex;
            result.maxDistToDutyTarget = maxDistToDutyTarget;
            return result;
        }

		protected override bool Satisfied(Pawn pawn)
		{
			LocalTargetInfo target = focusIndex switch
            {
                1   => pawn.mindState.duty.focus,
                2   => pawn.mindState.duty.focusSecond,
                3   => pawn.mindState.duty.focusThird,
                _   => LocalTargetInfo.Invalid
            };

            return target.IsValid && pawn.Position.InHorDistOf(target.Cell, maxDistToDutyTarget);
		}
    }
}