Пример #1
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();

                    return(true);
                }

                return(false);

            default:
                return(false);
            }
        }
        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;

                    ClientPlateStation deliverStation = ComponentUtil
                                                        .GetClosestComponent <ClientPlateStation>(player.transform.position);

                    Logger.Log($"Current pos: {Logger.FormatPosition(player.transform.position)}, " +
                               $"station pos: {Logger.FormatPosition(deliverStation.transform.position)}");

                    currentAction = new PathFindAction(player, deliverStation);
                }

                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);
            }
        }
        public bool Update()
        {
            switch (state)
            {
            case 0:
                state         = 1;
                currentAction = new GetRawIngredientAction(player, ingredient);

                return(false);

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

                    currentAction = new ProcessIngredientAction(player);
                }

                return(false);

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

                    if (orderData.plate == null)
                    {
                        orderData.plate = ComponentUtil.GetClosestComponent <ClientPlate>(player.transform.position);
                    }

                    currentAction = new PlateHoldingAction(player, orderData.plate);
                }

                return(false);

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

                    return(true);
                }

                return(false);

            default:
                return(false);
            }
        }
Пример #4
0
    private IEnumerator RunAction(Action action)
    {
        action.isRunning = false;

        float waitTime = action.Run();

        if (waitTime > 0f)
        {
            while (action.isRunning)
            {
                yield return(new WaitForSeconds(waitTime));

                waitTime = action.Run();
            }
        }

        int actionEnd = action.End();

        if (actionEnd != 0)
        {
            nextActionNumber = actionEnd;
        }

        // Fix bug where actionlist would continue even if game is paused
        while (stateHandler.gameState == GameState.Paused)
        {
            yield return(new WaitForFixedUpdate());
        }

        ProcessAction(nextActionNumber);
    }
Пример #5
0
        public void Update()
        {
            if (!executing)
            {
                return;
            }

            if (currentOrder.Equals(""))
            {
                currentOrder = OrderUtil.GetNewOrder(ObjectUtil.GetFlowController());
                Logger.Log("Getting new order");
            }
            else
            {
                bool orderExists = false;
                foreach (string order in OrderUtil.GetOrders(ObjectUtil.GetFlowController()))
                {
                    if (order.Equals(currentOrder))
                    {
                        orderExists = true;
                        break;
                    }
                }

                if (!orderExists)
                {
                    if (currentAction is IPausableAction cancellableCurrentAction)
                    {
                        cancellableCurrentAction.Pause();
                    }

                    currentAction = null;

                    currentOrder = OrderUtil.GetNewOrder(ObjectUtil.GetFlowController());
                    Logger.Log("Getting new order");
                }
            }
            // We should have an order to work on
            if (currentAction == null)
            {
                currentAction = new HandleOrderAction(ObjectUtil.GetBotControls(), currentOrder);
            }

            if (currentAction.Update())
            {
                currentAction.End();
                currentAction = null;
                currentOrder  = "";
            }
        }
Пример #6
0
        public virtual bool TrySetAction(EntityAction newAction, bool locked = false)
        {
            if (Utilities.AreSameBaseType(Action, newAction)) // Don't assign an action of the same type.
            {
                return(false);
            }
            else
            {
                if (Action != null && !Action.IsActive)
                {
                    Action.End();
                }

                Action       = newAction;
                ActionLocked = locked;
                return(true);
            }
        }
Пример #7
0
        public virtual void TakeDamage(int damage, Entity attacker)
        {
            // If the entity is waiting and the action that triggered the wait can be interrupred, e.g. sleeping, playing, talking
            // then the action will be wiped so PersonBrain can asign a new one.
            // It should flee from the attacker, then it can decide to fight back or not.
            if (Action != null)
            {
                if (Action.IsInterruptible)
                {
                    ActionLocked = false;
                    Action.End();
                }
            }

            // Turn entity red temporarily to show damage taken.
            SetColor(Color.Red);
            base.OnScheduleEvent(this, new ScheduleEventArgs(1, new ResetColorAction()));
            Health  -= damage;
            Attacker = attacker;
        }
Пример #8
0
 public virtual void Exit()
 {
     actor.basicBody.SetBool(GetBoolName(), false);
     action.End();
     actor = null;
 }
Пример #9
0
        private void EndAction(Action action)
        {
            action.isRunning = false;

            ActionEnd actionEnd = action.End (this.actions);
            if (isSkipping && action.lastResult.skipAction != -10 && (action is ActionCheck || action is ActionCheckMultiple))
            {
                // When skipping an ActionCheck that has already run, revert to previous result
                actionEnd = new ActionEnd (action.lastResult);
            }
            else
            {
                action.SetLastResult (new ActionEnd (actionEnd));
                ReturnLastResultToSource (actionEnd, actions.IndexOf (action));
            }

            if (action is ActionCheck || action is ActionCheckMultiple)
            {
                if (actionEnd.resultAction == ResultAction.Skip && actionEnd.skipAction == actions.IndexOf (action))
                {
                    // Looping on itself will cause a StackOverflowException, so delay slightly
                    ProcessActionEnd (actionEnd, actions.IndexOf (action), true);
                    return;
                }
            }

            ProcessActionEnd (actionEnd, actions.IndexOf (action));
        }
Пример #10
0
 public void End()
 {
     action?.End();
 }
Пример #11
0
		private void EndAction (Action action)
		{
			action.isRunning = false;
			
			int actionEnd = 0;
			if (isSkipping && action.lastResult != -10 && (action is ActionCheck || action is ActionCheckMultiple))
			{
				// When skipping an ActionCheck that has already run, revert to previous result
				actionEnd = action.lastResult;
			}
			else
			{
				actionEnd = action.End (this.actions);
				action.lastResult = actionEnd;
			}
			if (actionEnd >= 0)
			{
				nextActionNumber = actionEnd;
			}
			
			if (action.endAction == ResultAction.RunCutscene)
			{
				if (action.isAssetFile && action.linkedAsset != null)
				{
					AdvGame.RunActionListAsset (action.linkedAsset);
				}
				else if (!action.isAssetFile && action.linkedCutscene != null && action.linkedCutscene != this)
				{
					action.linkedCutscene.SendMessage ("Interact");
				}
			}
			if (actionEnd == -1 || actionEnd == -2)
			{
				EndCutscene ();
			}
			else if (nextActionNumber >= 0)
			{
				ProcessAction (nextActionNumber);
			}
			
			if (action.endAction == ResultAction.RunCutscene && !action.isAssetFile && action.linkedCutscene != null && action.linkedCutscene == this)
			{
				action.linkedCutscene.SendMessage ("Interact");
			}
		}