コード例 #1
0
        protected override void OnNewSubMove(Move m, SubMove sm)
        {
            if ((sm.agent is ConnectedBlock cBlock))
            {
                if (siblings.Contains(cBlock))                //we must move with this, because we are connected.
                {
                    if (CanMoveInDir(sm.dir))
                    {
                        m.AddAgentToMove(this, sm.dir, false, sm, null, 50);                        //should relies on be a submove?
                        return;
                    }
                    else
                    {
                        sm.Invalidate();
                        return;
                    }
                }
            }
            //If this is not a chain setup (which should exit the function before this code happens).

            if (sm.destinationNode == _node)
            {
                if (CanMoveInDir(sm.dir))
                {
                    m.AddAgentToMove(this, sm.dir, false, sm, sm, 60);
                }
                else
                {
                    sm.Invalidate();
                }
            }
        }
コード例 #2
0
        protected override void OnNewSubMove(Move m, SubMove sm)
        {
            //if we are not already involved. There is absolutely a way for this recursive move tree to get bungled up by the first thing saying "yes you can move" and a second one saying "no you cannot".
            // if (!m.IsInvolved(this))
            // {
            //we check pushing because a move should be invalid if we are being pushed.
            //below, the move should only be invalid if we are forcefully sticky. (todo: rename that lol).
            //This could be cleaned up with a check where we set the criticalToMove bool to 'destination == current || forcefullysticky'. But uh, thats conceptually harder, even if this is uglier. Whatever.
            if (sm.destinationNode == _node)
            {
                if ((sm.destinationNode.cellPos - _node.cellPos).magnitude != 1)
                {
                    // Debug.Log("edge case found?");
                }

                // bool critical = sm.agent is Player;
                //a tile agent is moving to here, we need to either invalidate the move or get pushed or move out of the way or whatever.
                if (CanMoveInDir(sm.dir))
                {
                    //critical to move should be true! but only if the move that was passed to us is critical. If we are being pushed by a stickyblock, then we aren't critical....
                    m.AddAgentToMove(this, sm.dir, false, sm, sm, 19);
                }
                else
                {
                    //we are being pushed, and we cannot move. so the submove trying to push us cannot move.
                    sm.Invalidate();
                }
            }
            else
            {
                if (onlyStickToPlayer)
                {
                    if (!(sm.agent is Player))
                    {
                        return;
                    }
                }

                //we arent being pushed. Time to behave like a sticky object, getting scraped off!
                //if we are adjacent to the moving object...
                if ((_node.cellPos - sm.startingNode.cellPos).magnitude == 1)
                {
                    if (CanMoveInDir(sm.dir))
                    {
                        //we follow along. If we don't get to move, thats fine! The thing pushing us isn't a big problem, ya know?
                        m.AddAgentToMove(this, sm.dir, false, null, sm, -5);
                    }
                    else
                    {
                        //uh oh, youre stuck to us now! sucks lol.
                        if (forcefulSticky)
                        {
                            sm.Invalidate();
                        }
                    }
                }
            }
        }
コード例 #3
0
        protected override void OnNewSubMove(Move m, SubMove sm)
        {
            if (!m.IsInvolved(this))
            {
                if (sm.destinationNode == _node)//if we are being pushed.
                {
                    //a tile agent is moving to here, we need to either invalidate the move or get pushed or move out of the way or whatever.
                    if (CanMoveInDir(sm.dir))
                    {
                        //critical to
                        m.AddAgentToMove(this, sm.dir, false, sm, sm, 20);
                    }
                    else
                    {
                        //we are being pushed, and we cannot move. So the submove tr
                        sm.Invalidate();
                    }
                }
                else
                {
                    Vector3Int dir = (Vector3Int)(sm.startingNode.cellPos - _node.cellPos);
                    if ((Vector3Int)FacingDir == dir && dir.magnitude == 1)//facingDir
                    {
                        //We need to check if another agent is moving into the spot of the player.

                        SubMove otherMove = m.GetSubMoveWithDestination(sm.startingNode);
                        if (otherMove != null)
                        {
                            if (otherMove.subMovePriority < 11)//ijjj
                            {
                                //that other thing is less important.
                                otherMove.Invalidate();
                            }
                            else
                            {
                                //we can't move, a more important thing is moving.
                                return;
                            }
                        }

                        if (CanMoveInDir(dir))
                        {
                            //critical to
                            SubMove newSM = m.AddAgentToMove(this, dir, false, null, sm, 11);
                            newSM.SetExtraData((Vector2Int)sm.dir);
                        }
                    }
                }
            }
        }
コード例 #4
0
ファイル: AIBase.cs プロジェクト: hunterdyar/GridFramework
        protected IEnumerator PathfindThenTakeTurn(NavNode destination)
        {
            //Wait for pathfinder to finish its search.
            _pathfinder.Search(_node, destination);
            while (_pathfinder.Running)
            {
                yield return(null);
            }

            if (_pathfinder.PathStatus == PathStatus.success)
            {
                List <NavNode> path = _pathfinder.GetPath();               //0 is our current position, so position 1 is the next.

                if (path.Count > 1)
                {
                    NavNode    next = path[1];
                    Vector3Int dir  = next.cellPos - _node.cellPos;
                    Move       m    = new Move(puzzleManager, false);
                    m.AddAgentToMove(this, dir, true, null, null, 50);
                    puzzleManager.ExecuteAICommand(m);
                    if (m.IsValid)
                    {
                        puzzleManager.HoldPlayerForAI(this);
                    }
                }
            }
        }
コード例 #5
0
ファイル: Pusher.cs プロジェクト: hunterdyar/GridFramework
 protected override void OnGameReady()
 {
     base.OnGameReady();
     if (_node.AgentBaseHere != null)
     {
         Move m = new Move(puzzleManager, false);
         m.AddAgentToMove(_node.AgentBaseHere, (Vector3Int)pushDir, true, null, null, 50);
         puzzleManager.CommandManager.ExecuteCommand(m);
     }
 }
コード例 #6
0
        protected override void TakeTurn()
        {
            Move m = new Move(puzzleManager, false);

            m.AddAgentToMove(this, (Vector3Int)FacingDir, true, null, null, 50);
            puzzleManager.ExecuteAICommand(m);
            if (m.IsValid)
            {
                puzzleManager.HoldPlayerForAI(this);
            }
        }
コード例 #7
0
ファイル: Pusher.cs プロジェクト: hunterdyar/GridFramework
 protected override void OnPreMoveComplete(Move m)
 {
     foreach (var sm in m.GetValidSubMoves())
     {
         if (sm.destinationNode == _node)
         {
             Move am = new Move(puzzleManager, false);
             am.AddAgentToMove(sm.agent, (Vector3Int)pushDir, true, null, null, 50);
             m.RegisterAfterMove(am);
         }
     }
 }
コード例 #8
0
 protected override void OnNewSubMove(Move m, SubMove sm)
 {
     if (sm.destinationNode == _node)
     {
         //this is almost identical to the default tileAgent except for this "sm.agent is player" check. Only can be pushed by the playER
         if (CanMoveInDir(sm.dir) && sm.agent is Player)
         {
             m.AddAgentToMove(this, sm.dir, false, sm);
         }
         else
         {
             sm.Invalidate();
         }
     }
 }
コード例 #9
0
ファイル: AgentBase.cs プロジェクト: hunterdyar/GridFramework
 protected virtual void OnNewSubMove(Move m, SubMove sm)
 {
     //if we are not already involved with the move.
     if (!m.IsInvolved(this))
     {
         if (sm.destinationNode == _node)                //if we are being pushed.
         {
             //a tile agent is moving to here, we need to either invalidate the move or get pushed or move out of the way or whatever.
             if (CanMoveInDir(sm.dir))
             {
                 //critical to
                 m.AddAgentToMove(this, sm.dir, false, sm, sm, 20);
             }
             else
             {
                 //we are being pushed, and we cannot move. So the submove tryu
                 sm.Invalidate();
             }
         }
     }
 }
コード例 #10
0
        protected override void OnNewSubMove(Move m, SubMove sm)
        {
            //distance between us and the cell we would move to (the thing we are following's starting cell).
            Vector3Int dir = sm.startingNode.cellPos - _node.cellPos;

            if (dir.magnitude == 1 && dir != -sm.dir)    //we are one block away, and not being pushed.
            {
                bool agentIsPlayer = (sm.agent is Player);
                if (!(sm.agent is FollowerAgent) && !agentIsPlayer)
                {
                    return;
                }
                SubMove otherMove = m.GetSubMoveWithDestination(sm.startingNode);
                if (otherMove != null)
                {
                    if (otherMove.subMovePriority < 10)    //ijjj
                    {
                        //that other thing is less important.
                        otherMove.Invalidate();
                    }
                    else
                    {
                        //we can't move, a more important thing is moving.
                        return;
                    }
                }
                int bonus = agentIsPlayer ? 2 : 0;       //prioritize first leader in a chain
                bonus += (dir == sm.dir ? 1 : 0);        //prioritize following straight over following curved
                m.AddAgentToMove(this, dir, false, null, sm, movePriority + bonus);
            }
            else
            {
                //If we are being pushed and are one block away.
                if (sm.destinationNode == _node && dir.magnitude == 1 && dir == -sm.dir)
                {
                    //a tile agent is moving to here, we need to either invalidate the move or get pushed or move out of the way or whatever.
                    if (CanMoveInDir(sm.dir))
                    {
                        if (m.GetValidSubMove(this, out SubMove sm2))
                        {
                            sm.SetReliesOn(sm2);
                        }
                        //critical to move should be true! but only if the move that was passed to us is critical. If we are being pushed by a stickyblock, then we aren't critical....
                        //If we ARE being pushed, criticalFor should NOT be null, or the player could end up landing on the current fella in odd edge cases.
                        m.AddAgentToMove(this, sm.dir, false, sm, sm, 12);       //this needs to be lower than the follower ones, or a follower 'further back' on a chain will push those ahead of it instead of them moving to the side.
                    }
                    else
                    {
                        //If we are moving already, then lets just move on out of the way!
                        if (m.GetValidSubMove(this, out SubMove sm2))
                        {
                            sm.SetReliesOn(sm2);
                        }
                        else
                        {
                            // sm.Invalidate();//cant move in dir that sm moves in...
                            //we need to tell the system that sm MIGHT be valid if we move out of the way... but we don't yet know if that will happen.
                            sm.ReliesOnAgentMoving(this);
                        }
                    }
                }
            }
        }