Ejemplo n.º 1
0
        public bool Update()
        {
            if (!hasCurrentAction)
            {
                if (i == path.Count - 1)
                {
                    currentAction = new MoveTargetAction(player, target);
                }
                else
                {
                    currentAction = new MoveAction(player, path[i]);
                }

                i++;

                hasCurrentAction = true;
            }
            else
            {
                if (currentAction.Update())
                {
                    currentAction.End();
                    hasCurrentAction = false;

                    if (i == path.Count)
                    {
                        Logger.Log($"PathFindAction to {target.name} done");
                        return(true);
                    }
                }
            }

            return(false);
        }
Ejemplo n.º 2
0
        public bool Update()
        {
            switch (state)
            {
            case 0:
                if (currentAction.Update())
                {
                    currentAction.End();
                    state         = 1;
                    currentAction = new PickDropAction(player);
                }

                return(false);

            case 1:
                if (currentAction.Update())
                {
                    currentAction.End();
                    state         = 2;
                    currentAction = new ChopAction(player, workstation);
                }

                return(false);

            case 2:
                if (currentAction.Update())
                {
                    currentAction.End();
                    state         = 3;
                    currentAction = new PickDropAction(player);
                }

                return(false);

            case 3:
                if (currentAction.Update())
                {
                    currentAction.End();

                    return(true);
                }

                return(false);

            default:
                return(false);
            }
        }
Ejemplo n.º 3
0
        public static void Update()
        {
            if (walkingPath)
            {
                if (currentAction != null && currentAction.Update())
                {
                    currentAction.End();

                    if (pathIteration < path.Count - 1)
                    {
                        currentAction = new MoveAction(ObjectUtil.GetBotControls(), path[++pathIteration]);
                    }
                    else
                    {
                        currentAction = null;
                        walkingPath   = false;
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public bool Update()
        {
            switch (state)
            {
            case 0:
                if (currentAction.Update())
                {
                    currentAction.End();
                    state         = 1;
                    currentAction = new PickDropAction(player);
                }

                return(false);

            case 1:
                if (currentAction.Update())
                {
                    currentAction.End();

                    cookingStation = ComponentUtil.GetClosestComponent <ClientCookingStation>(player.transform.position);

                    if (IsCookableOnStation(cookableContainer, cookingStation))
                    {
                        state = 5;
                    }
                    else
                    {
                        state = 2;

                        currentAction = new PickDropAction(player);
                    }
                }

                return(false);

            case 2:
                if (currentAction.Update())
                {
                    currentAction.End();
                    state = 3;

                    currentAction =
                        new PathFindAction(
                            player,
                            cookingStation
                            );
                }

                return(false);

            case 3:
                if (currentAction.Update())
                {
                    currentAction.End();
                    state = 4;

                    currentAction = new PickDropAction(player);
                }

                return(false);

            case 4:
                if (currentAction.Update())
                {
                    currentAction.End();

                    state = 5;
                }

                return(false);

            case 5:
                if (cookableContainer.GetCookingHandler().GetCookingProgress() >=
                    cookableContainer.GetCookingHandler().AccessCookingTime)
                {
                    state = 6;

                    currentAction =
                        new PathFindAction(
                            player,
                            cookingStation
                            );
                }

                return(false);

            case 6:
                if (currentAction.Update())
                {
                    currentAction.End();

                    state = 7;

                    currentAction = new PickDropAction(player);
                }

                return(false);

            case 7:
                if (currentAction.Update())
                {
                    currentAction.End();

                    return(true);
                }

                return(false);

            default:
                return(false);
            }
        }
Ejemplo n.º 5
0
        public bool Update()
        {
            // Check if we have sequential actions that are no longer idle
            foreach (ISequentialAction sequentialAction in idleActionIngredients.Keys)
            {
                if (!sequentialAction.IsIdle())
                {
                    Logger.Log("Sequential action no longer idle");
                    // Sequential action is not idle anymore, resume it as soon as possible
                    if (currentAction is IPausableAction pausableAction)
                    {
                        if (pausableAction.Pause())
                        {
                            Logger.Log("Pausing current action");
                            // Action can be paused
                            pausedActionIngredients.Add(pausableAction, currentIngredient);

                            Logger.Log("Resuming non-idle sequential action after PausableAction");
                            currentIngredient = idleActionIngredients[sequentialAction];
                            currentAction     = sequentialAction;

                            idleActionIngredients.Remove(sequentialAction);

                            state = 1;
                        }
                        else
                        {
                            Logger.Log("Can not currently pause PausableAction");
                        }
                    }
                    else if (currentAction == null)
                    {
                        Logger.Log("Resuming non-idle sequential action after null action");
                        currentIngredient = idleActionIngredients[sequentialAction];
                        currentAction     = sequentialAction;

                        idleActionIngredients.Remove(sequentialAction);

                        state = 1;
                    }
                    else
                    {
                        Logger.Log("Current action is not PausableAction");
                    }

                    break;
                }
            }

            switch (state)
            {
            case 0:
                // If we have any actions that are paused, resume one of them
                foreach (Action pausedAction in pausedActionIngredients.Keys)
                {
                    Logger.Log("Found action that was paused, resuming instead of getting new ingredient");
                    currentIngredient = pausedActionIngredients[pausedAction];
                    currentAction     = pausedAction;

                    pausedActionIngredients.Remove(pausedAction);

                    state = 1;

                    return(false);
                }

                // Make a list of ingredients that are we do not need to start making
                List <string> possibleIngredients = new List <string>(orderData.ingredientsDone);

                // Add the ingredients of the sequential actions
                possibleIngredients.AddRange(idleActionIngredients.Values);

                // Query a possible ingredient to start on
                currentIngredient = OrderUtil.GetRemainingIngredientFromOrder(
                    orderData.orderName,
                    possibleIngredients
                    );

                // If no more ingredients to do
                if (currentIngredient.Equals(""))
                {
                    // If we have no idle actions remaining
                    if (idleActionIngredients.Count == 0)
                    {
                        Logger.Log("No new ingredients");
                        // No ingredients left, we are done
                        state = 2;

                        currentAction = new DeliverPlateAction(player, orderData.plate);

                        return(false);
                    }

                    state = -1;
                    return(false);
                }

                Logger.Log($"New ingredient found: {currentIngredient}");

                state = 1;

                currentAction = new HandleIngredientAction(player, currentIngredient, orderData);

                return(false);

            case 1:
                // If we have a sequential action that is idle
                if (currentAction is ISequentialAction sequentialAction)
                {
                    if (sequentialAction.IsIdle())
                    {
                        Logger.Log("Sequential action is idle");
                        List <string> ingredientsDone =
                            new List <string>(orderData.ingredientsDone);
                        ingredientsDone.Add(currentIngredient);

                        string newCurrentIngredient =
                            OrderUtil.GetRemainingIngredientFromOrder(orderData.orderName, ingredientsDone);

                        // If there are other ingredients to work on in the mean time
                        if (!newCurrentIngredient.Equals(""))
                        {
                            Logger.Log($"Other ingredient found to work on: {newCurrentIngredient}");
                            // Store this action and go work on other ingredient
                            idleActionIngredients.Add(sequentialAction, currentIngredient);

                            currentIngredient = newCurrentIngredient;
                            currentAction     = new HandleIngredientAction(player, newCurrentIngredient, orderData);
                        }
                    }
                }

                if (currentAction.Update())
                {
                    currentAction.End();
                    currentAction = null;

                    state = 0;

                    orderData.ingredientsDone.Add(currentIngredient);
                }

                return(false);

            case 2:
                if (currentAction.Update())
                {
                    currentAction.End();

                    return(true);
                }

                return(false);

            default:
                return(false);
            }
        }
Ejemplo n.º 6
0
        public bool Update()
        {
            switch (state)
            {
            case 0:
                if (currentAction.Update())
                {
                    currentAction.End();
                    state         = 1;
                    currentAction = new PickDropAction(player, true);
                }

                return(false);

            case 1:
                if (currentAction.Update())
                {
                    currentAction.End();

                    if (!PlayerUtil.IsCarrying(player))
                    {
                        return(true);
                    }
                    // Still holding something, for instance a pan or pot
                    Logger.Log("Still holding something after plating");
                    state = 2;

                    ClientAttachStation clientAttachStation =
                        ComponentUtil.GetClosestMatchingComponent <ClientAttachStation>(
                            player.transform.position, IsAttachStationEmptyAndClean);

                    currentAction =
                        new PathFindAction(
                            player,
                            clientAttachStation
                            );
                }

                return(false);

            case 2:
                if (currentAction.Update())
                {
                    currentAction.End();

                    state = 3;

                    currentAction = new PickDropAction(player);
                }

                return(false);

            case 3:
                if (currentAction.Update())
                {
                    currentAction.End();

                    return(true);
                }

                return(false);

            default:
                return(false);
            }
        }