// Attacks a piece on the map public void AttackPiece(GamePiece attackingPiece, GamePiece targetPiece) { // Return if either piece is null if (attackingPiece == null || targetPiece == null) { return; } // Return if both pieces belong to same player if (attackingPiece.GetPlayerId() == targetPiece.GetPlayerId()) { return; } // Return if out of range int distance = Hex.GetDistanceHexes(attackingPiece.gameHex, targetPiece.gameHex); if (distance > attackingPiece.range) { return; } int damageGiven = attackingPiece.AttackPiece(targetPiece); attackingPiece.player.SetSelectedPiece(null); // Target piece dies if (targetPiece.currentHealth == 0) { targetPiece.gameHex.piece = null; C.Destroy(targetPiece.gameObject); } }
// Attack piece private void AttackPiece(Vector3Int targetTileCoords) { // Get targeted piece and player object GamePiece targetPiece = gameMap.GetHexPieceFromHexCoords(Hex.TileToHexCoords(targetTileCoords)); PlayerObject playerObject = gameManagerObject.GetPlayerObject(targetPiece.GetPlayerId()); // Attack piece GamePiece attackingPiece = player.selectedPiece; attackingPiece.AttackPiece(targetPiece); // Update the targeted piece lifebar playerObject.UpdateGamePieceObjectLifebar(targetPiece); // Set attacking piece as disabled GamePieceObject gamePieceObject = gamePieceObjects[attackingPiece]; gamePieceObject.ShowPieceDisabled(); // Update maps player.UpdateMaps(gameMap); PaintPlayerMaps(); }