コード例 #1
0
ファイル: GOAPNode.cs プロジェクト: Audaxxy/Blight
 /// <summary>
 /// Crears all values.
 /// </summary>
 private void Clear()
 {
     this._parent      = null;
     this._runningCost = 0;
     this._weight      = 0;
     this._state       = null;
     this._action      = null;
 }
コード例 #2
0
ファイル: GOAPNode.cs プロジェクト: Audaxxy/Blight
 /// <summary>
 /// Reinitializes node with new values.
 /// </summary>
 public void Reinitialize(GOAPNode parent, float runningCost, float weight, Dictionary <string, bool> state,
                          GOAPAction action)
 {
     Clear();
     this._parent      = parent;
     this._runningCost = runningCost;
     this._weight      = weight;
     this._state       = state;
     this._action      = action;
 }
コード例 #3
0
ファイル: GOAPPlanner.cs プロジェクト: Audaxxy/Blight
        /// <summary>
        /// Creates a subset of the actions excluding the actionToRemove. Creates a new set.
        /// </summary>
        /// <param name="actions">Usuable actions</param>
        /// <param name="actionToRemove">Action to exclude from this branch</param>
        private HashSet <GOAPAction> ActionSubset(HashSet <GOAPAction> actions, GOAPAction actionToRemove)
        {
            HashSet <GOAPAction> subset = GOAPPlannerHelper.GetFreeActionSet();

            foreach (GOAPAction action in actions)
            {
                if (!action.Equals(actionToRemove))
                {
                    subset.Add(action);
                }
            }

            return(subset);
        }
コード例 #4
0
ファイル: GOAPAgent.cs プロジェクト: Audaxxy/Blight
        /// <summary>
        /// Creates performActionState for the FSM. This state is used to make the AI Agent perform an action.
        /// </summary>
        private void CreatePerformActionState()
        {
            _performActionState = (fsm, obj) =>
            {
                if (!HasActionPlan())
                {
                    _AIAgent.ActionsFinished();

                    fsm.ClearState();
                    fsm.PushState(_idleState);
                    return;
                }

                GOAPAction action = _currentActions.Peek();
                if (action.IsDone())
                {
                    // If action is done, remove it to perform the next one.
                    _currentActions.Dequeue();
                }

                if (HasActionPlan())
                {
                    action = _currentActions.Peek();
                    bool inRange = action.RequiresInRange() ? action.IsInRange() : true;

                    if (inRange)
                    {
                        bool success = action.Perform(obj, _AIAgent.DataHolder);
                        if (!success)
                        {
                            _AIAgent.PlanAborted(action);

                            fsm.ClearState();
                            fsm.PushState(_idleState);
                        }
                    }
                    else
                    {
                        fsm.PushState(_moveToState);
                    }
                }
                else
                {
                    _AIAgent.ActionsFinished();

                    fsm.ClearState();
                    fsm.PushState(_idleState);
                }
            };
        }
コード例 #5
0
ファイル: GOAPPlannerHelper.cs プロジェクト: Audaxxy/Blight
        /// <summary>
        /// Reinitializes free node, turns it into used one and returns it. If there is not enough free nodes, creates a new one.
        /// </summary>
        public static GOAPNode GetFreeNode(GOAPNode parent, float runningCost, float weight, Dictionary <string, bool> state,
                                           GOAPAction action)
        {
            GOAPNode free = null;

            if (_freeNodes.Count <= 0)
            {
                free = new GOAPNode(parent, runningCost, weight, state, action);
            }
            else
            {
                free = _freeNodes.Pop();
                free.Reinitialize(parent, runningCost, weight, state, action);
            }

            _usedNodes.Push(free);
            return(free);
        }
コード例 #6
0
ファイル: EnemyBase.cs プロジェクト: Audaxxy/Blight
        public bool MoveAgent(GOAPAction nextAction)
        {
            NavMeshAgent.SetDestination(nextAction._target.transform.position);

            // Check if we've reached the destination
            if (!NavMeshAgent.pathPending)
            {
                if (NavMeshAgent.remainingDistance <= NavMeshAgent.stoppingDistance)
                {
                    if (!NavMeshAgent.hasPath || NavMeshAgent.velocity.sqrMagnitude == 0f)
                    {
                        nextAction.SetInRange(true);
                        return(true);
                    }
                }
            }

            return(false);
        }
コード例 #7
0
ファイル: GOAPAgent.cs プロジェクト: Audaxxy/Blight
        /// <summary>
        /// Creates moveToState for the FSM. This state is used to move the Ai Agent to its destination.
        /// </summary>
        private void CreateMoveToState()
        {
            _moveToState = (fsm, gameObject) =>
            {
                GOAPAction action = _currentActions.Peek();

                if (action.RequiresInRange() && action._target == null)
                {
                    fsm.ClearState();
                    fsm.PushState(_idleState);
                    return;
                }

                if (_AIAgent.MoveAgent(action))
                {
                    fsm.PopState();
                }
            };
        }
コード例 #8
0
ファイル: EnemyBase.cs プロジェクト: Audaxxy/Blight
 public void PlanAborted(GOAPAction aborter)
 {
     // For debugging.
 }
コード例 #9
0
ファイル: GOAPNode.cs プロジェクト: Audaxxy/Blight
 /// <summary>
 /// Constructor.
 /// </summary>
 public GOAPNode(GOAPNode parent, float runningCost, float weight, Dictionary <string, bool> state,
                 GOAPAction action)
 {
     _ID = MaxID++;
     Reinitialize(parent, runningCost, weight, state, action);
 }
コード例 #10
0
ファイル: GOAPAgent.cs プロジェクト: Audaxxy/Blight
 public void AddAction(GOAPAction action)
 {
     _availableActions.Add(action);
 }
コード例 #11
0
ファイル: GOAPAgent.cs プロジェクト: Audaxxy/Blight
 public void RemoveAction(GOAPAction action)
 {
     _availableActions.Remove(action);
 }