예제 #1
0
    /// <summary>
    /// Constructor for overstacking.
    /// Sets up and displays the overstack interface.
    /// </summary>
    /// <param name="attacker">The attacking piece</param>
    /// <param name="victim">The victim piece</param>
    public void Construct(PieceTower attacker, PieceTower victim)
    {
        this.attacker  = attacker;
        this.victim    = victim;
        destination    = victim.GetNode();
        attackerColour = attacker.owningColour;

        done = false;

        // Offset the piece locations
        float offset = 0f;

        for (int i = attacker.pieces.Count - 1; i >= 0; i--)
        {
            PieceData p = attacker.pieces[i];
            // Duplicate the piece onto the canvas
            GameObject dup = GameObject.Instantiate(p.getObj());
            dup.AddComponent <OverstackPieceUI>();
            dup.GetComponent <OverstackPieceUI>().Piece = p;
            dup.transform.SetParent(transform, false);

            // Position on the screen
            Vector3 newPos = new Vector3(-250f, 150f - offset, 0f);
            Vector3 newRot = new Vector3(270f, 120f, 0f);

            // Flip pieces that are not the same colour as the attacker
            if (p.colour != attacker.owningColour && p.type != PieceData.Type.Hook)
            {
                newPos.y += 25f;
                newRot    = new Vector3(-270f, 60f, 0f);
                dup.GetComponent <OverstackPieceUI>().Flipped = true;
            }

            // Set the position and angles
            dup.transform.localPosition    = newPos;
            dup.transform.localEulerAngles = newRot;

            offset += 30f;
        }

        // Offset between towers
        offset += 30f;

        for (int i = victim.pieces.Count - 1; i >= 0; i--)
        {
            PieceData p = victim.pieces[i];
            // Duplicate the piece onto the canvas
            GameObject dup = GameObject.Instantiate(p.getObj());
            dup.AddComponent <OverstackPieceUI>();
            dup.GetComponent <OverstackPieceUI>().Piece   = p;
            dup.GetComponent <OverstackPieceUI>().Flipped = true;
            dup.transform.SetParent(transform, false);

            // Position on the screen
            Vector3 newPos = new Vector3(-250f, 175f - offset, 0f);
            Vector3 newRot = new Vector3(-270f, 60f, 0f);

            // Don't flip hook pieces or pieces that are the same colour as the attacker
            if (p.type == PieceData.Type.Hook || p.colour == attacker.owningColour)
            {
                newPos.y -= 25f;
                newRot    = new Vector3(270f, 120f, 0f);
                dup.GetComponent <OverstackPieceUI>().Flipped = false;
            }

            // Set the location and angles
            dup.transform.localPosition    = newPos;
            dup.transform.localEulerAngles = newRot;

            offset += 30;
        }

        offsets          = new int[] { 0, 25, 50, 75, 100, 125 };
        consideredPieces = new LinkedList <OverstackPieceUI>();

        // Enable the backdrop and overstack button
        GameObject.Find("UICanvas").GetComponent <RawImage>().enabled = true;
        GameObject.Find("UICanvas").transform.Find("DoneOverstackBtn").gameObject.SetActive(true);

        // Overstacking for AI
        if (attacker.owningPlayer.IsAI)
        {
            StartCoroutine(((AIPlayer)attacker.owningPlayer).AIOverstack());
        }
    }
예제 #2
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);
    }
예제 #3
0
    /// <summary>
    /// Called when there is a valid finish request from the overstack button.
    /// Handles the creation of the new tower, and removes all old pieces from the game.
    /// </summary>
    /// <param name="pieces">The considered pieces that have been validated.</param>
    public void Finished(List <PieceData> pieces)
    {
        // Reference to the attacking player
        Player    player        = GameObject.Find("Taoex").GetComponent <TurnHandler>().getPlayerByColour(attacker.owningColour);
        PieceData startingPiece = null;

        HashSet <TileNode> attackerMoves = attacker.GetMoves().Destinations;

        // Remove references to the selected pieces
        attacker.RemovePieces(pieces);
        victim.RemovePieces(pieces);

        // Pick the first selected attacker piece as the starting piece
        foreach (PieceData p in pieces)
        {
            if (p.colour == player.colour)
            {
                startingPiece = p;
                break;
            }
        }

        Debug.Assert(startingPiece != null, "Starting piece was null");

        // Create the new tower
        PieceTower newTower = new PieceTower(player, startingPiece, destination);

        newTower.owningPlayer.AddTower(newTower);

        // Add rest of the pieces
        foreach (PieceData p in pieces)
        {
            if (p != startingPiece)
            {
                newTower.AddPiece(p);
            }
        }

        // Clear the UI
        foreach (Transform ga in transform)
        {
            Destroy(ga.gameObject);
        }

        // Kill off the extra pieces
        foreach (PieceData p in attacker.pieces)
        {
            // Take extra pieces for scoring
            if (!pieces.Contains(p))
            {
                player.TakePiece(p);
            }

            // Liberate the piece if it's the attacker's colour
            if (p.colour == attackerColour)
            {
                if (p.getObj().GetComponent <PlacementPiece>() != null)
                {
                    p.getObj().GetComponent <PlacementPiece>().Liberate();
                }
                else
                {
                    Debug.Log("PlacementPiece script was null, probably testing with sandbox mode");
                    Destroy(p.getObj());
                }
            }
            else if (p.type == PieceData.Type.Hook)
            {
                // Return hook
                ReturnHook(p);
            }
            else
            {
                Destroy(p.getObj());
            }
        }

        foreach (PieceData p in victim.pieces)
        {
            // Take extra pieces for scoring
            if (!pieces.Contains(p))
            {
                player.TakePiece(p);
            }

            // Liberate the piece if it's the attacker's colour
            if (p.colour == attackerColour)
            {
                if (p.getObj().GetComponent <PlacementPiece>() != null)
                {
                    p.getObj().GetComponent <PlacementPiece>().Liberate();
                }
                else
                {
                    Debug.Log("PlacementPiece script was null, probably testing with sandbox mode");
                    Destroy(p.getObj());
                }
            }
            else if (p.type == PieceData.Type.Hook)
            {
                // Return hook
                ReturnHook(p);
            }
            else
            {
                Destroy(p.getObj());
            }
        }

        attacker.Die();
        victim.Die();

        // Update player status
        newTower.GetNode().tower = newTower;
        newTower.updatePosition();
        attacker.owningPlayer.updateScore();
        victim.owningPlayer.updateScore();

        // Reset variables
        hookConsidered = false;
        consideredPieces.Clear();

        this.newTower = newTower;

        // Disable the dim effect
        GameObject.Find("UICanvas").GetComponent <RawImage>().enabled = false;

        done = true;
    }