Newer
Older
Hierarchical-Task-Network-Unity-3D / Assets / Scripts / Example / Conditions / IsCostumerInTheQueue.cs
using UnityEngine;

public class IsCostumerInTheQueue : Condition
{
    public IsCostumerInTheQueue() : base("Is Customer on the Queue"){ }
    public override bool IsConditionMet(HTNPlanner planner)
    {
        //Get the payment are
        PaymentArea paymentArea = planner.WorldState.Get<PaymentArea>("PaymentArea");

        //Cast
        Customer customer = planner.Agent as Customer;

        //Checks if the cast fails
        if (customer == null) 
        {
            Debug.LogError("Cast Failed!");
            return false;
        }

        if (paymentArea != null) return paymentArea.FindCustomer(customer);

        Debug.LogError($"{nameof(PaymentArea)} is Null!");
        return false;
    }
}