コード例 #1
0
    public void MoveUnitTo(MazeUnit unit, Vector2Int pos)
    {
        if (IsPosOutOfBounds(pos))
        {
            Debug.LogError(unit.name + ": Trying to move out of bounds");
        }

        CellData cellData = mazeData[pos.x, pos.y];

        if (cellData.occupant != null && cellData.occupant != unit)
        {
            Debug.LogError(unit.name + ": Trying to move unit to occupied space");
            return;
        }

        mazeData[unit.GetMovement().GetMazePos().x, unit.GetMovement().GetMazePos().y].occupant = null;
        cellData.occupant = unit;
    }
コード例 #2
0
    public override IEnumerator TakeTurn()
    {
        DidAction = false;

        if (turnsSinceLastMove != -1)
        {
            turnsSinceLastMove++;
        }

        // Still lock on targets even if we can't move right now
        if (!target)
        {
            target = VisionUtils.FindVisibleEnemy(transform, visionRange, enemyLayers, visionBlockingLayers);
        }

        if (turnsSinceLastMove != -1 && turnsSinceLastMove < turnsPerMove)
        {
            yield break;
        }

        if (target)
        {
            List <Vector2Int> path = AStar.FindPath(
                Maze.Instance,
                unit.GetMovement().GetMazePos(),
                target.GetMovement().GetMazePos(),
                Maze.Instance.GetValidNeighbourCoords(target.GetMovement().GetMazePos()));

            if (path.Count > pursuitSteps)
            {
                target = null;
                yield break;
            }

            if (path.Count >= 1 && unit.GetMovement().AttemptMoveToPos(path[1]))
            {
                turnsSinceLastMove = 0;
                DidAction          = true;
            }
        }

        yield break;
    }