Esempio n. 1
0
    // Sets the next action based on the person's state
    private bool SetAction()
    {
        int personLoc = PersonLocFromPosition();

        switch (state)
        {
        case PersonState.TARGET_SET:
            goto case PersonState.WANDER_SET;

        // Finds a path to the goal
        case PersonState.WANDER_SET:
            path = Pathfinder.FindPathToHouse(personLoc, goalIndex);
            return(true);

        // Finds a path to a random goal if there are houses and available space, otherwise changes to wander
        case PersonState.TARGET_RANDOM:
            if (HouseManager.houses.Count == 0 || !HouseManager.AnyStallSpaceAnywhere())
            {
                state = PersonState.WANDER;
                goto default;
            }
            else
            {
                goalIndex = HouseManager.GetRandomHouse();
                path      = Pathfinder.FindPathToHouse(personLoc, goalIndex);
            }
            return(true);

        // Finds a path to a random not burning house if there are houses that aren't burning, otherwise changes to wander
        case PersonState.TARGET_RANDOM_NOTBURNING:
            if (HouseManager.houses.Count == 0 || !HouseManager.AnyHousesNotBurning())
            {
                state = PersonState.WANDER;
                goto default;
            }
            else
            {
                goalIndex = HouseManager.GetRandomNotBurningHouse();
                path      = Pathfinder.FindPathToHouse(personLoc, goalIndex);
            }
            return(true);

        // Stalls
        case PersonState.STALL:
            StopAllCoroutines();
            StartCoroutine(Stall());
            return(false);

        // Attacks
        case PersonState.ATTACK:
            StopAllCoroutines();
            Attack();
            return(false);

        // Finds a path to an exit
        default:
            path = Pathfinder.FindPath(state, personLoc);
            return(true);
        }
    }
Esempio n. 2
0
 public override void Execute()
 {
     targetHouse = houseManager?.GetRandomHouse();
     if (targetHouse == null)
     {
         OnTargetNotFound?.Invoke();
     }
     else
     {
         OnTargetFound?.Invoke();
     }
 }