public void ReturnHook(PieceData piece) { // Refernece to the board TaoexBoard tb = GameObject.Find("Taoex").GetComponent <TaoexBoard>(); TileNode[] wayCrossTiles = tb.WayCrossTiles; // Closest tile information float closestDistance = float.MaxValue; TileNode closestTile = null; for (int i = 0; i < 6; i++) { // Find empty way crosses if (wayCrossTiles[i].tower != null) { continue; } // Get the closest way cross float distance = Vector3.Distance(piece.getObj().transform.position, wayCrossTiles[i].transform.position); if (distance < closestDistance) { Debug.Log(i + " : " + distance); closestDistance = distance; closestTile = wayCrossTiles[i]; } } // If there is no available way cross, try the center if (closestTile == null && (tb.GetTiles()[13, 11].tower == null || tb.GetTiles()[13, 11].tower == attacker)) { closestTile = tb.GetTiles()[13, 11]; } if (closestTile != null) { // Return the hook closestTile.tower = new PieceTower(tb.HookPlayer, piece, closestTile); //piece.MoveTo(closestTile.transform.position); } else { Destroy(piece.getObj()); Debug.Log("Couldn't find a tile to put the hook back onto"); } }
/// <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()); } }