예제 #1
0
    /// <summary>
    /// Logic for handling a way roll move along a way line
    /// </summary>
    /// <returns>The roll.</returns>
    /// <param name="node">Node.</param>
    /// <param name="tower">Tower.</param>
    /// <param name="wayLineID">Way line ID.</param>
    private IEnumerator WayRoll(TileNode node, PieceTower tower, int wayLineID)
    {
        //moves = tower.GetWayMove(9);

        // Wait for overstack to finish
        yield return(new WaitUntil(() => OverstackUI.done));

        // Create a way roll dice
        GameObject diceObj = Instantiate(Resources.Load("Prefabs/UI/WayDice")) as GameObject;

        // place the way roll dice on the UICanvas
        diceObj.transform.SetParent(GameObject.Find("UICanvas").transform, false);

        // Starts the roll
        DiceRollScript diceScript = diceObj.GetComponent <DiceRollScript>();

        StartCoroutine(diceScript.StartRoll());

        // wait until roll is complete
        yield return(new WaitUntil(() => diceScript.RollState == DiceRollScript.State.Ready));

        // if the result is -999, some how the diceroll did not reach a result.
        Debug.Assert(diceObj.GetComponent <DiceRollScript>().Result != -999);

        // Overstacking onto way cross, fix the reference for the tower
        if (tower.GetNode() == null)
        {
            // Get the new tower
            tower = GameObject.Find("Overstack").GetComponent <OverstackUI>().NewTower;

            // Clear reference from overstack interface
            GameObject.Find("Overstack").GetComponent <OverstackUI>().NewTower = null;
        }

        // get moves along the way line with the range from the result of the roll
        moves = tower.GetWayMove(diceObj.GetComponent <DiceRollScript>().Result, wayLineID).Destinations;

        // if no moves are avalible or rolled a zero
        if (moves.Count == 0)
        {
            // add move to history
            moveHistory.Add(new PieceMove(node, tower.GetMoves().GetMoveObject(node), moves));
            GameObject.Find("MoveHistoryPanel").GetComponent <MoveHistoryHandler>().addMove(moveHistory[moveHistory.Count - 1]);

            // reset selection
            state          = State.Playing;
            firstSelection = null;

            // move to next player's turn
            NextTurn();
        }
        else
        {
            // highlight the way move options
            foreach (TileNode wayTile in moves)
            {
                wayTile.highlight();
            }

            // set state to special way state
            state = State.PlayingForceWay;

            // set first selection to current position
            firstSelection = node;

            // If the player is an AI
            if (players[turnIndex].IsAI)
            {
                // AI delay before continuing
                yield return(new WaitForSeconds(AIPlayer.AIDelay));

                // Forced way move for AI
                StartCoroutine(ForcedWayAction(((AIPlayer)players[turnIndex]).ForcedWay(tower, moves).dest));
            }
        }

        // destory the dice roll ui game object
        Destroy(diceObj, 1f);
    }