Exemplo n.º 1
0
    public bool TraversedAlertTile()
    {
        List <CursorController.Coordinate> listToCheck = new List <CursorController.Coordinate>(_path);

        CursorController.Coordinate newTile = new CursorController.Coordinate();
        newTile.x = _unit.xPos;
        newTile.z = _unit.zPos;
        listToCheck.Add(newTile);
        return(listToCheck.Where((p) => Helpers.GetTile(p.x, p.z).alarm).Count() > 0);
    }
Exemplo n.º 2
0
    public void SetPath(int x, int z)
    {
        List <int[]> path = Helpers.DeriveShortestPath(x, z, Unit.current.xPos, Unit.current.zPos, Unit.current);

        CursorController.moveEnabled = false;
        CursorController.Coordinate[] coordinates = new CursorController.Coordinate[path.Count];
        int c = 0;

        foreach (int[] array in path)
        {
            CursorController.Coordinate coordinate = new CursorController.Coordinate();
            coordinate.x         = array[0];
            coordinate.z         = array[1];
            coordinate.counter   = array[2];
            coordinate.elevation = array[3];
            coordinates[c]       = coordinate;
            c++;
        }
        Unit.current.SetPath(coordinates);
        CmdSetPathOnServer(coordinates, Player.player.playerIndex, Unit.current.stanceIndex);
    }
Exemplo n.º 3
0
    public void ForceWalk(int tilesToMove, int directionX, int directionZ)
    {
        int    actualMoveTiles = tilesToMove;
        Cursor destination;

        //first, can they actually move there?

        while (actualMoveTiles > 0)
        {
            List <Cursor> tiles = Helpers.GetRadialTiles(_unit.xPos, _unit.zPos, actualMoveTiles, _unit.JumpHeight(), false, 1, false, true);
            print("tiles " + tiles.Count);
            Cursor projectedCursor = Helpers.GetTile(
                _unit.xPos + (actualMoveTiles * directionX),
                _unit.zPos + (actualMoveTiles * directionZ));

            if (projectedCursor && tiles.Contains(projectedCursor))
            {
                destination = projectedCursor;
                break;
            }

            actualMoveTiles--;
        }

        print("actualMoveTiles " + actualMoveTiles);

        if (actualMoveTiles == 0)
        {
            //no possible movement, so exit
            return;
        }

        int newX = _unit.xPos + (actualMoveTiles * directionX);
        int newZ = _unit.zPos + (actualMoveTiles * directionZ);

        //second, let's get the path for that tile

        List <int[]> path = Helpers.DeriveShortestPath(
            newX, newZ, _unit.xPos, _unit.zPos, _unit
            );

        //now let's go there!

        print("walking " + path.Count);

        CursorController.Coordinate[] coordinates = new CursorController.Coordinate[path.Count];
        int c = 0;

        foreach (int[] array in path)
        {
            CursorController.Coordinate coordinate = new CursorController.Coordinate();
            coordinate.x         = array[0];
            coordinate.z         = array[1];
            coordinate.counter   = array[2];
            coordinate.elevation = array[3];
            coordinates[c]       = coordinate;
            c++;
        }

        MoveAlongPath(coordinates, false);
    }
Exemplo n.º 4
0
    private void PickNext()
    {
        if (_canWalkPath)
        {
            Vector3 direction;

            if (_pathIndex >= _path.Count)
            {
                return;
            }

            CursorController.Coordinate nextStep = _path[_pathIndex];

            _pathIndex++;
            if (_pathIndex >= _path.Count)
            {
                _resetPath   = true;
                _canWalkPath = false;
                _pathIndex   = 0;
            }

            int newY = nextStep.elevation - _unit.yPos;
            _jumpHeight = nextStep.elevation - _unit.yPos;
            _unit.yPos  = _unit.yPos + newY;

            if (nextStep.x > _currentxPos)
            {
                print("going x");
                direction = new Vector3(1, newY, 0);
                _currentxPos++;
            }
            else if (nextStep.x < _currentxPos)
            {
                direction = new Vector3(-1, newY, 0);
                _currentxPos--;
            }
            else if (nextStep.z > _currentzPos)
            {
                direction = new Vector3(0, newY, 1);
                _currentzPos++;
            }
            else if (nextStep.z < _currentzPos)
            {
                direction = new Vector3(0, newY, -1);
                _currentzPos--;
            }
            else
            {
                print("return case");
                return;
            }

            _unit.lookDirection = new Vector3(direction.x, 0, direction.z);

            _goal = VoxelController.Grid().WorldToGrid(transform.position) + direction;

            _goal     = VoxelController.Grid().GridToWorld(_goal);
            _isMoving = true;

            if (newY > 0)
            {
                _isMovingUp = true;
            }
            if (newY < 0)
            {
                _isMovingDown = true;
            }
        }
    }