Example #1
0
        protected override NodeStates Tick(Tick tick)
        {
            NodeStates    result          = NodeStates.Failure;
            GameManager   gameManager     = Locator.Get <GameManager>();
            Entity        player          = gameManager.Player;
            CellTransform playerTransform = player.CellTransform;

            Cell playerCell = gameManager.MapManager[playerTransform.Position.x, playerTransform.Position.y];

            if
            (
                playerCell != null &&
                playerCell.Prop != null &&
                playerCell.Prop.Info != null &&
                playerCell.Prop.Info.NameId == "Stairs Exit"
            )
            {
                TrapDoor trapDoor = playerCell.Prop.GetComponent <TrapDoor>();

                if (trapDoor != null && trapDoor.IsOpen)
                {
                    result = NodeStates.Success;
                }
            }

            return(result);
        }
Example #2
0
        protected override NodeStates Tick(Tick tick)
        {
            NodeStates result    = NodeStates.Failure;
            Entity     target    = tick.Target as Entity;
            Actor      actor     = target.GetComponent <Actor>();
            Inventory  inventory = target.GetComponent <Inventory>();

            if (actor != null && inventory != null)
            {
                Item item = inventory.GetItem(InventorySlotType.Bag);

                if (item != null && item is IConsumable)
                {
                    actor.ConsumeItemInBag();
                    result = NodeStates.Success;
                }
                else
                {
                    result = NodeStates.Error;
                }
            }
            else
            {
                result = NodeStates.Error;
            }

            return(result);
        }
Example #3
0
        /// <summary>
        /// Merges the node x into the fixed target node into.
        ///
        /// Edges between these nodes, edges to x and related distance information is updated.
        ///
        /// x is marked as to be removed from the search space. If x was the start node, into
        /// will now be the start node.
        /// </summary>
        /// <returns>All neighbors of x before merging. These are the nodes that had their adjacency
        /// information changed.</returns>
        protected IEnumerable <int> MergeInto(int x, int into)
        {
            if (!NodeStates.IsFixedTarget(into))
            {
                throw new ArgumentException("Nodes can only be merged into fixed target nodes", "into");
            }

            _data.DistanceLookup.IndexToNode(into).MergeWith(_data.DistanceLookup.IndexToNode(x), _data.DistanceLookup.GetShortestPath(x, into));
            _data.DistanceLookup.MergeInto(x, into);

            EdgeSet.Remove(x, into);
            var intoNeighbors = EdgeSet.NeighborsOf(into);
            var xNeighbors    = EdgeSet.NeighborsOf(x);
            var neighbors     = intoNeighbors.Union(xNeighbors);

            foreach (var neighbor in xNeighbors)
            {
                EdgeSet.Remove(x, neighbor);
            }
            foreach (var neighbor in neighbors)
            {
                EdgeSet.Add(into, neighbor, _data.DistanceLookup[into, neighbor]);
            }

            if (StartNodeIndex == x)
            {
                _data.StartNodeIndex = into;
            }

            NodeStates.MarkNodeAsRemoved(x);

            return(xNeighbors);
        }
Example #4
0
 public void OpenNode()
 {
     if (!IsObstacle && !used)
     {
         nodeState = NodeStates.Open;
     }
 }
Example #5
0
        protected override NodeStates Tick(Tick tick)
        {
            NodeStates result = NodeStates.Failure;
            Dictionary <int2, HashSet <Entity> > memory;

            if (tick.Blackboard.TryGet(entitiesMemoryId, out memory))
            {
                var memoryEnumerator = memory.Values.GetEnumerator();

                while (result == NodeStates.Failure && memoryEnumerator.MoveNext())
                {
                    var entitiesEnumerator = memoryEnumerator.Current.GetEnumerator();

                    while (result == NodeStates.Failure && entitiesEnumerator.MoveNext())
                    {
                        if (entityMatch(entitiesEnumerator.Current))
                        {
                            int2 position = entitiesEnumerator.Current.CellTransform.Position;

                            if (mapManager[position.x, position.y].Visibility == VisibilityType.Visible)
                            {
                                result = NodeStates.Success;
                            }
                        }
                    }
                }
            }
            else
            {
                result = NodeStates.Error;
            }

            return(result);
        }
Example #6
0
        protected override NodeStates Tick(Tick tick)
        {
            NodeStates result = NodeStates.Failure;
            Dictionary <int2, HashSet <Entity> > memory;

            if (tick.Blackboard.TryGet(memoryId, out memory))
            {
                var enumerator = memory.Values.GetEnumerator();

                while (result == NodeStates.Failure && enumerator.MoveNext())
                {
                    var entitiesEnumerator = enumerator.Current.GetEnumerator();

                    while (result == NodeStates.Failure && entitiesEnumerator.MoveNext())
                    {
                        if (entitiesEnumerator.Current.Info.NameId == entityId)
                        {
                            result = NodeStates.Success;
                        }
                    }
                }
            }
            else
            {
                result = NodeStates.Error;
            }

            return(result);
        }
Example #7
0
        protected override int ExecuteTest()
        {
            if (NodeStates.FixedTargetNodeCount <= 1 || NodeStates.VariableTargetNodeCount > 0)
            {
                return(0);
            }

            var removedNodes = 0;

            var mst = new MinimalSpanningTree(NodeStates.FixedTargetNodeIndices.ToList(), DistanceLookup);

            mst.Span(StartNodeIndex);
            var maxEdgeDistance = mst.SpanningEdges.Max(e => e.Priority);

            for (var i = 0; i < SearchSpaceSize; i++)
            {
                if (NodeStates.IsTarget(i) || NodeStates.IsRemoved(i))
                {
                    continue;
                }

                // Theoretically, this can be sped up by using Voronoi partitions. The Voronoi base of i is the
                // terminal with the smallest distance to i by definition, so only the distance to that terminal
                // has to be checked.
                if (NodeStates.FixedTargetNodeIndices.All(t => DistanceLookup[i, t] >= maxEdgeDistance))
                {
                    EdgeSet.EdgesOf(i).ForEach(EdgeSet.Remove);
                    NodeStates.MarkNodeAsRemoved(i);
                    removedNodes++;
                }
            }

            return(removedNodes);
        }
Example #8
0
        protected override NodeStates Tick(Tick tick)
        {
            NodeStates result = NodeStates.Failure;
            Dictionary <int2, HashSet <Entity> > memory;

            if (tick.Blackboard.TryGet(memoryId, out memory))
            {
                var enumerator = memory.Values.GetEnumerator();

                while (result == NodeStates.Failure && enumerator.MoveNext())
                {
                    var entitiesEnumerator = enumerator.Current.GetEnumerator();

                    while (result == NodeStates.Failure && entitiesEnumerator.MoveNext())
                    {
                        if (entityMatch(entitiesEnumerator.Current))
                        {
                            tick.Blackboard.Set(destinyId, entitiesEnumerator.Current.CellTransform.Position);
                            result = NodeStates.Success;
                        }
                    }
                }
            }
            else
            {
                result = NodeStates.Error;
            }

            return(result);
        }
Example #9
0
        public override NodeStates Evaluate()
        {
            if (!condition())
            {
                return(NodeStates.FAILURE);
            }
            foreach (Node node in inputNodes)
            {
                NodeStates result = node.Evaluate();

                switch (result)
                {
                case NodeStates.FAILURE:
                    return(NodeStates.FAILURE);

                case NodeStates.RUNNING:
                    return(NodeStates.RUNNING);

                case NodeStates.SUCCESS:
                    //only at succes it moves on to the next task
                    break;

                default:
                    break;
                }
            }

            return(NodeStates.FAILURE);
        }
Example #10
0
 protected void ChangeNodeState(PointNode node, NodeStates state)
 {
     if (node != null)
     {
         Map.ChangeNodeState(node, state);
     }
 }
        public void SetState(NodeStates state)
        {
            visitedCircle.gameObject.SetActive(false);
            switch (state)
            {
            case NodeStates.Locked:
                sr.DOKill();
                sr.color = MapView.Instance.lockedColor;
                break;

            case NodeStates.Visited:
                sr.DOKill();
                sr.color = MapView.Instance.visitedColor;
                visitedCircle.gameObject.SetActive(true);
                break;

            case NodeStates.Attainable:
                // start pulsating from visited to locked color:
                sr.color = MapView.Instance.lockedColor;
                sr.DOKill();
                sr.DOColor(MapView.Instance.visitedColor, 0.5f).SetLoops(-1, LoopType.Yoyo);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(state), state, null);
            }
        }
Example #12
0
        protected override NodeStates Tick(Tick tick)
        {
            NodeStates result = NodeStates.Error;
            Entity     entity = tick.Target as Entity;

            if (entity != null)
            {
                SideManager   sideManager   = Locator.Get <SideManager>();
                SideComponent sideComponent = entity.GetComponent <SideComponent>();

                if (sideComponent != null)
                {
                    TileMap <Cell> map     = Locator.Get <MapManager>().Map;
                    List <Entity>  enemies = sideManager.GetOtherSidesActors(sideComponent.Side);
                    result = NodeStates.Failure;
                    int i = 0;

                    while (result == NodeStates.Failure && i < enemies.Count)
                    {
                        bool isEnemyInVisibleCell = map[enemies[i].CellTransform.Position].Visibility == VisibilityType.Visible;

                        if (isEnemyInVisibleCell && CanSeeEntity(entity, enemies[i]))
                        {
                            result = NodeStates.Success;
                        }

                        i++;
                    }
                }
            }

            return(result);
        }
Example #13
0
        protected override NodeStates Tick(Tick tick)
        {
            NodeStates     result = NodeStates.Success;
            TileMap <Cell> map    = Locator.Get <MapManager>().Map;

            IDTools.PlotFunction isClear = (int x, int y) =>
            {
                bool plotResult = true;
                Cell cell       = map[x, y];

                if (cell == null || cell.BreaksLineOfSight())
                {
                    plotResult = false;
                    result     = NodeStates.Failure;
                }

                return(plotResult);
            };

            Entity target = tick.Target as Entity;

            int2 actorPosition  = target.CellTransform.Position;
            int2 entityPosition = entity.CellTransform.Position;

            IDTools.Line(actorPosition.x, actorPosition.y, entityPosition.x, entityPosition.y, isClear);

            return(result);
        }
Example #14
0
        protected override NodeStates Tick(Tick tick)
        {
            NodeStates result    = NodeStates.Failure;
            Entity     target    = tick.Target as Entity;
            Inventory  inventory = target.GetComponent <Inventory>();

            if (inventory != null)
            {
                int i = 0;

                while (result == NodeStates.Failure && i < slotsToLookUp.Count)
                {
                    Item item = inventory.GetItem(slotsToLookUp[i]);

                    if (item != null && itemMatch(item))
                    {
                        result = NodeStates.Success;
                    }

                    i++;
                }
            }
            else
            {
                result = NodeStates.Error;
            }

            return(result);
        }
Example #15
0
        protected override NodeStates Tick(Tick tick)
        {
            NodeStates result = NodeStates.Error;

            HashSet <int2> threshold = null;

            if (tick.Blackboard.TryGet(thresholdId, out threshold))
            {
                Entity      target          = tick.Target as Entity;
                int2        targetPosition  = target.CellTransform.Position;
                MapManager  mapManager      = Locator.Get <MapManager>();
                List <int2> candidates      = new List <int2>();
                int         closestDistance = int.MaxValue;
                var         enumerator      = threshold.GetEnumerator();

                while (enumerator.MoveNext())
                {
                    int distance = heuristic.Evaluate(targetPosition, enumerator.Current);

                    if (distance < closestDistance)
                    {
                        closestDistance = distance;
                        candidates.Clear();
                        candidates.Add(enumerator.Current);
                    }
                    else if (distance == closestDistance)
                    {
                        candidates.Add(enumerator.Current);
                    }
                }

                if (candidates.Count > 0)
                {
                    int2 chosenDestiny = candidates[Random.Range(0, candidates.Count)];
                    int2 currentDestiny;

                    if (tick.Blackboard.TryGet(tileId, out currentDestiny))
                    {
                        int2[] path = mapManager.GetPathIgnoringActors(targetPosition, currentDestiny);
                        Cell   cell = mapManager[currentDestiny.x, currentDestiny.y];

                        if (threshold.Contains(currentDestiny) && path.Length > 0 && path.Length <= closestDistance)
                        {
                            chosenDestiny = currentDestiny;
                        }
                    }

                    tick.Blackboard.Set(tileId, chosenDestiny);
                    result = NodeStates.Success;
                }
                else
                {
                    tick.Blackboard.Remove(tileId);
                    result = NodeStates.Failure;
                }
            }

            return(result);
        }
Example #16
0
        private void comboBox_Type_SelectedIndexChanged(object sender, EventArgs e)
        {
            NodeStates ns = (NodeStates)comboBox_Type.SelectedIndex;

            PositionEnabled(ns == NodeStates.마우스_이동 || ns == NodeStates.마우스_이동_후_왼쪽클릭);
            textBox_Keyborad.Enabled   = (ns == NodeStates.키보드_키입력);
            textBox_Keyborad.BackColor = EnableColor(textBox_Keyborad.Enabled);
        }
Example #17
0
        public float score;                  //{ get; set; }

        public Node(Vector3 location, int label, NodeStates state = NodeStates.inactive)
        {
            this.location         = location;
            this.label            = label;
            this.state            = state;
            this.connections      = new List <Node>();
            this.possiblePrevious = new List <Node>();
        }
Example #18
0
 public virtual void OnBTDisable()
 {
     m_nodeState = NodeStates.OFF;
     foreach (var node in Children)
     {
         node.OnBTDisable();
     }
 }
Example #19
0
 public Node(Vector2 _position, NodeStates _state, bool _isObstacle, uint _weight)
 {
     isObstacle = _isObstacle;
     position   = _position;
     nodeState  = originalState = _state;
     used       = false;
     weight     = _weight;
 }
Example #20
0
        public static void RemoveControlState(Control control, NodeStates stateHint)
        {
            if (stateHints.TryGetValue(control, out NodeStates currentStateHint))
            {
                currentStateHint &= ~stateHint;

                stateHints[control] = currentStateHint;
            }
        }
        public GridNode[] GetAroundNodes(int X, int Y, int Offset, NodeStates StateMask)
        {
            List <GridNode> nodes = new List <GridNode>();

            GridNode node = null;

            node = GetNode(X - Offset, Y);
            if (node != null && BitwiseHelper.IsEnabled((int)StateMask, (ushort)node.State))
            {
                nodes.Add(node);
            }

            node = GetNode(X, Y - Offset);
            if (node != null && BitwiseHelper.IsEnabled((int)StateMask, (ushort)node.State))
            {
                nodes.Add(node);
            }

            node = GetNode(X + Offset, Y);
            if (node != null && BitwiseHelper.IsEnabled((int)StateMask, (ushort)node.State))
            {
                nodes.Add(node);
            }

            node = GetNode(X, Y + Offset);
            if (node != null && BitwiseHelper.IsEnabled((int)StateMask, (ushort)node.State))
            {
                nodes.Add(node);
            }

            node = GetNode(X - Offset, Y - Offset);
            if (node != null && BitwiseHelper.IsEnabled((int)StateMask, (ushort)node.State))
            {
                nodes.Add(node);
            }

            node = GetNode(X + Offset, Y - Offset);
            if (node != null && BitwiseHelper.IsEnabled((int)StateMask, (ushort)node.State))
            {
                nodes.Add(node);
            }

            node = GetNode(X - Offset, Y + Offset);
            if (node != null && BitwiseHelper.IsEnabled((int)StateMask, (ushort)node.State))
            {
                nodes.Add(node);
            }

            node = GetNode(X + Offset, Y + Offset);
            if (node != null && BitwiseHelper.IsEnabled((int)StateMask, (ushort)node.State))
            {
                nodes.Add(node);
            }

            return(nodes.ToArray());
        }
        public override IEnumerator EvaluateBehaviourTree()
        {
            UpdateBehaviourTree();

            while (GameManager.Cur.StateCtrl.CompareGameState(GameState.PLAYLEVEL))
            {
                rootNodeState = rootNode.Evaluate();
                yield return(waitTimeEvaluateDeltaTime);
            }
        }
Example #23
0
    public void OpenNode(Node n)
    {
        if (!IsObstacle && !used)
        {
            parentNode = n;
            nodeState  = NodeStates.Open;

            TotalWeight = parentNode.TotalWeight + Weight;
        }
    }
Example #24
0
 // The constructor requires the child node that this Limiter decorator wraps,
 // the max number of times that you would like the node to be evaluated
 // this node is mostly used to make sure AI does not get stuck in infinte loops
 // and what you would like the node to evaluate once the limit has reached
 public Limiter(BaseNode _node, int _numTimesEvaluate, NodeStates _StateToReturn)
 {
     m_node               = _node;
     m_StateToReturn      = _StateToReturn;
     m_numTimesToEvaluate = _numTimesEvaluate;
     if (m_numTimesToEvaluate <= 0)
     {
         m_numTimesToEvaluate = 1;
     }
 }
Example #25
0
 // Resets the node, so that the child node can be evaluated again
 // allows you to reset the amount of times you would like the child node to be evaluated
 // and what you would like the node to evaluate once the limit has reached
 public void ResetNode(int _numTimesEvaluate, NodeStates _StateToReturn)
 {
     m_numTimesHasEvaluated = 0;
     m_StateToReturn        = _StateToReturn;
     m_numTimesToEvaluate   = _numTimesEvaluate;
     if (m_numTimesToEvaluate <= 0)
     {
         m_numTimesToEvaluate = 1;
     }
 }
Example #26
0
        protected override NodeStates Tick(Tick tick)
        {
            NodeStates result = NodeStates.Failure;

            if (Locator.Get <GameManager>().GameState == GameState.GameOver)
            {
                result = NodeStates.Success;
            }

            return(result);
        }
Example #27
0
        public override NodeStates Evaluate()
        {
            NodeStates state = node.Evaluate();

            if (state == NodeStates.RUNNING)
            {
                return(NodeStates.RUNNING);
            }

            return(state == NodeStates.SUCCESS ? NodeStates.FAILURE : NodeStates.SUCCESS);
        }
Example #28
0
        protected override NodeStates Tick(Tick tick)
        {
            NodeStates result = NodeStates.Error;

            if (callback != null)
            {
                callback();
                result = NodeStates.Success;
            }

            return(result);
        }
Example #29
0
        protected override NodeStates Tick(Tick tick)
        {
            NodeStates    result        = NodeStates.Success;
            Entity        entity        = tick.Target as Entity;
            SideComponent sideComponent = entity.GetComponent <SideComponent>();
            List <Entity> enemies       = Locator.Get <SideManager>().GetOtherSidesActors(sideComponent.Side);
            Entity        target        = FindClosestEntity(enemies, entity);

            tick.Blackboard.Set(targetId, target);

            return(result);
        }
Example #30
0
        protected override NodeStates Tick(Tick tick)
        {
            NodeStates result = NodeStates.Failure;
            T          variable;

            if (tick.Blackboard.TryGet(variableId, out variable))
            {
                result = NodeStates.Success;
            }

            return(result);
        }
Example #31
0
 public virtual void Start()
 {
     State = NodeStates.InProcess;
 }