179 lines
5.7 KiB
C#
179 lines
5.7 KiB
C#
|
|
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<Animator>().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<Animator>().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();
|
|
}
|
|
}
|