using CharacterSystem; using System.Collections.Generic; using UnityEngine; using UnityEngine.Serialization; public class EndGameHandler : MonoBehaviour { [SerializeField, FormerlySerializedAs("winPanel")] private PveWinPanel _winPanel; [SerializeField, FormerlySerializedAs("lossPanel")] private PveLossPanel _lossPanel; [SerializeField, FormerlySerializedAs("pvpWinPanel")] private PvpWinPanel _pvpWinPanel; [SerializeField, FormerlySerializedAs("drawPanel")] private PveLossPanel _drawPanel; public void HandleEndGame(Team lastPlayer, GameMode gameMode, CheckResult lastResult) { Debug.Log("Конец игры"); GameManager.Instance.turnTracker.EnableTimer(false); if (lastResult.Draw) DrawHandler(gameMode); else WinHandler(lastPlayer, gameMode, lastResult.WinningIndexes); } private void DrawHandler(GameMode gameMode) { if (gameMode == GameMode.pve) { EventBus.TriggerEvent(GameEvent.Draw); _drawPanel.Open(GameManager.Instance.ContinueAfterPveDraw); } else { _pvpWinPanel.Open(); } } private void WinHandler(Team winner, GameMode gameMode, HashSet<(int row, int col)> winChipsCoords) { Debug.Log($"Победа {winner}; Режим {gameMode}"); PlayWinChipsAnimation(winChipsCoords); if (gameMode == GameMode.pve) { if (winner == Team.Player1) { EventBus.TriggerEvent(GameEvent.PlayerWin); _winPanel.Open(); } else { EventBus.TriggerEvent(GameEvent.BotWin); _lossPanel.Open(GameManager.Instance.ContinueAfterPveLoss); } } else { _pvpWinPanel.Open(); } } private void PlayWinChipsAnimation(HashSet<(int row, int col)> winChipsCoords) { Chip[,] grid = Board.Instance.Grid; foreach ((int row, int col) winCoord in winChipsCoords) grid[winCoord.col, winCoord.row].WinAnimation(); } }