/// <summary> /// Hides the indicator. /// </summary> private void HideIndicator() { gameObject.GetComponent <MeshRenderer>().material.color = originalColour; GetComponent <SmoothMovement>().rate = 0.2f; GetComponent <SmoothMovement>().MoveTo(BasePosition); if (tower != null) { tower.updatePosition(); } }
/// <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; }