using PrizeSystem; using UnityEngine; public static class EndOfTurnHandler { private static GameManager gm; private static CheckResult result; public static void NormalHandling() { result = GameManager.fieldModel.Check(GameManager.instance.currentPlayer); gm = GameManager.instance; gm.lastResult = result; bool swipeToNextRightNow = false; IState nextState; //pvp решение победа в раунде или в игре bool endround = result.End && !result.Draw; bool endgame = false; // подсчет очков if (result.End)//Раунд окончен. Считаем очки и ставим стейт показ победителя { if (gm.gameMode == GameMode.pvp && !result.Draw) { //победил p1 if (gm.currentPlayer == CellState.Player1) { gm.player1score += 1; gm.Player1Scale.SetMedalsCount(gm.player1score); } else//победил p2 { gm.player2score += 1; gm.Player2Scale.SetMedalsCount(gm.player2score); } if (gm.player1score == 5 || gm.player2score == 5) endgame = true; if (endgame) AvatarEventBus.Instance.OnEndGame?.Invoke(gm.currentPlayer); else if (endround) AvatarEventBus.Instance.OnEndRound?.Invoke(gm.currentPlayer); } else if (gm.gameMode == GameMode.pve && !result.Draw) //конец раунда с ботом { //НЕ НИЧЬЯ VictoryScale botScale = gm.botScale; if (gm.currentPlayer == CellState.Player1)//[ПОБЕДА ИГРОКА] { if (CharacterController.CurrentCharacter.HasPrize) { PrizeSystemManager.GivePrize(CharacterController.CurrentCharacter.prize); CharacterController.CurrentCharacter.HasPrize = false; } DifficultyManager.instance.IncreaseDifficulty(); gm.vsBotScore += 1; CharacterEventBus.Instance.OnPlayerWin?.Invoke(); LightUtility.Win(); CharacterController.CurrentCharacter.Animator.SetTrigger("Lose"); swipeToNextRightNow = true; } else//Бот победил { LightUtility.Lose(); CharacterController.CurrentCharacter.GetComponent().SetTrigger("Win"); DifficultyManager.instance.DecreaseDifficulty(); if (gm.vsBotScore != 0) gm.vsBotScore -= 1; CharacterEventBus.Instance.OnBotWin?.Invoke(); } botScale.SetMedalsCount(gm.vsBotScore); } else if (gm.gameMode == GameMode.pve && result.Draw) { CharacterEventBus.Instance.OnDraw?.Invoke(); } nextState = new ShowWinnerState(result); } else { gm.SwitchPlayer(); nextState = new StartTurnState(); } if (gm.gameMode == GameMode.pve && gm.vsBotScore == gm.botsAmount) gm.upgradeFeeshkaDifficulty(); //конец игры - призовое состояние if (TotalWin()) { nextState = new PrizeState(); ClearAllScales(); } else if (swipeToNextRightNow) { ShowWinnerState showWinner = new ShowWinnerState(result); showWinner.subState = ShowWinnerState.ShowWinnerSubstates.ExitByTime; showWinner.timeRest = 4; nextState = showWinner; } gm.stateMachine.ChangeState(nextState); } private static bool TotalWin() => gm.player1score == 5 || gm.player2score == 5 || gm.vsBotScore == gm.botsAmount; public static void WinByTimerHandling() { //При победе по таймеру: //PVP проиграл тот, кто не успел кинуть фишку //PVE - прогрывает человек result = new CheckResult(true, false, null); IState nextState; if (gm.gameMode == GameMode.pvp) { //p2 не успел if (gm.currentPlayer == CellState.Player2) { gm.player1score += 1; gm.Player1Scale.SetMedalsCount(gm.player1score); } else//p1 не успел { gm.player2score += 1; gm.Player2Scale.SetMedalsCount(gm.player2score); } } else if (gm.gameMode == GameMode.pve)//время вышло при игре с ботом - бот победил { LightUtility.Lose(); CharacterController.CurrentCharacter.GetComponent().SetTrigger("Win"); //НЕ НИЧЬЯ VictoryScale vsBotScale = gm.botScale; DifficultyManager.instance.DecreaseDifficulty(); CharacterEventBus.Instance.OnBotWin?.Invoke(); if (gm.vsBotScore != 0) gm.vsBotScore -= 1; vsBotScale.SetMedalsCount(gm.vsBotScore); } nextState = new ShowWinnerState(result); //конец игры - призовое состояние if (TotalWin()) { nextState = new PrizeState(); ClearAllScales(); } gm.stateMachine.ChangeState(nextState); } private static void ClearAllScales() { if (gm.botScale.isActiveAndEnabled) gm.botScale.ClearScale(); if (gm.Player1Scale.isActiveAndEnabled) gm.Player1Scale.ClearScale(); if (gm.Player2Scale.isActiveAndEnabled) gm.Player2Scale.ClearScale(); } }