コード例 #1
0
        private void ReceivedAction()
        {
            switch (_actionRequest.Exception)
            {
            case null:
                break;

            default:
                Logger.FatalS("ai", _actionRequest.Exception.ToString());
                throw _actionRequest.Exception;
            }
            var action = _actionRequest.Result;

            _actionRequest = null;
            // Actions with lower scores should be implicitly dumped by GetAction
            // If we're not allowed to replace the action with an action of the same type then dump.
            if (action == null || !action.CanOverride && CurrentAction?.GetType() == action.GetType())
            {
                return;
            }

            var currentOp = CurrentAction?.ActionOperators.Peek();

            if (currentOp != null && currentOp.HasStartup)
            {
                currentOp.Shutdown(Outcome.Failed);
            }

            CurrentAction = action;
            action.SetupOperators(_blackboard);
        }
コード例 #2
0
 /// <summary>
 /// Gets the action from the Available action list.
 /// </summary>
 /// <param name="a_Action">an action.</param>
 /// <returns></returns>
 public CS_GOAPAction GetAction(Type a_Action)
 {
     foreach (CS_GOAPAction CurrentAction in AvailableActions)
     {
         if (CurrentAction.GetType().Equals(a_Action))
         {
             return(CurrentAction);
         }
     }
     return(null);
 }
コード例 #3
0
        private void ReceivedAction()
        {
            var action = _actionRequest.Result;

            _actionRequest = null;
            // Actions with lower scores should be implicitly dumped by GetAction
            // If we're not allowed to replace the action with an action of the same type then dump.
            if (action == null || !action.CanOverride && CurrentAction?.GetType() == action.GetType())
            {
                return;
            }

            CurrentAction = action;
            action.SetupOperators(_blackboard);
        }
コード例 #4
0
        protected override void Update()
        {
            switch (CurrentState)
            {
            case ActionState.HealPerson:

                //ideally should find the closest building on fire
                if (CurrentAction == null || CurrentAction.GetType() != typeof(Actions.HealPerson))
                {
                    //print (true);
                    //CurrentAction = new CatchCriminal(gameObject, );
                }

                break;
            }

            base.Update();
        }
コード例 #5
0
        public bool Tick(bool autopilotEnabled)
        {
            if (ExecuteUntil > DateTime.UtcNow && CurrentAction != null)
            {
                CurrentAction.Execute();
                return(true);
            }

            if (LastActionExecuted + Cooldown <= DateTime.UtcNow)
            {
                IEnumerable <IIdleAction> filteredActions = IdleActions.Where(e => (!e.AutopilotOnly || autopilotEnabled) && !LastActions.Any(e => e.Value == e.GetType()) || LastActions.Where(x => x.Value == e.GetType() && (DateTime.UtcNow - x.Key).TotalMilliseconds > Rnd.Next(CurrentAction.MinCooldown, CurrentAction.MaxCooldown)).Any());

                if (filteredActions.Any())
                {
                    CurrentAction = filteredActions.ElementAtOrDefault(Rnd.Next(0, filteredActions.Count()));

                    if (CurrentAction != null && CurrentAction.Enter())
                    {
                        LastActionExecuted = DateTime.UtcNow;
                        Cooldown           = TimeSpan.FromMilliseconds(Rnd.Next(MinCooldown, MaxCooldown));
                        ExecuteUntil       = LastActionExecuted + TimeSpan.FromMilliseconds(Rnd.Next(CurrentAction.MinDuration, CurrentAction.MaxDuration));

                        LastActions.Add(new KeyValuePair <DateTime, Type>(LastActionExecuted, CurrentAction.GetType()));

                        CurrentAction.Execute();
                        return(true);
                    }
                }
            }

            return(false);
        }