using System.Threading; using UnityEngine; public class BotThinkingState : IState { Thread calcThread; int calculatedColumn = -1; float startTime; float timeToThink; Animator animator; float animLength; DifficultyPreset preset; public BotThinkingState(float timeToThink) { this.timeToThink = timeToThink; } public BotThinkingState(float timeToThink, DifficultyPreset preset) { this.timeToThink = timeToThink; this.preset = preset; } public void enter() { //Установка пресета сложности DifficultyPreset currentPreset = CharacterController.CurrentCharacter.CurrentDifficultyPreset; //Debug.Log(currentPreset.Description); if (DifficultyManager.Instance.dummyBots) currentPreset = DifficultyManager.Instance.DummyPreset; if (preset!= null) { currentPreset = preset; } int movesMade = GameManager.instance.board.MovesCount; currentPreset = currentPreset.GetPreset(movesMade); Solver.SetPreset(currentPreset); calcThread = new Thread(calc); calcThread.Start(); startTime = Time.time; if (DifficultyManager.Instance.dummyBots) timeToThink = 0; CharacterEventBus.Instance.OnBotTurn?.Invoke(); animator = CharacterController.CurrentCharacter.GetComponent(); try{ animLength = CharacterController.CurrentCharacter.chipSpawningAnim.length; } catch { } } public void exit() { } public bool displayed = false; bool animationStarted = false; float startAnimTime; public void update() { //подсчет времени if(calculatedColumn!= -1 && !displayed) { //Debug.Log($"Думал: {Time.time - startTime}"); displayed = true; } if (calculatedColumn != -1 && Time.time - startTime > timeToThink) { if (!animationStarted) { animator.SetTrigger("Throw"); startAnimTime = Time.time; animationStarted = true; } if (animationStarted && Time.time - startAnimTime > animLength) { //ставим фишку в расчитанную колонку (подготовка к следующему состоянию) Vector2 targetPosition = GameManager.instance.board.GetStickedPosition(calculatedColumn); targetPosition += Vector2.up * 5; GameManager.instance.currentChip.transform.position = targetPosition; GameManager.instance.stateMachine.ChangeState(new ChipFallingState(0, calculatedColumn)); } } } void calc() { GameManager gm = GameManager.instance; bool OnBossByScore = gm.vsBotScore == gm.botsAmount - 1; bool IsHardCommonDifficulty = SettingsManager.GetString("Difficulty", "Средняя") == "Сложная"; bool IsUpperCashDifficulty = SettingsManager.GetString("BaseBotDifficulty", "Повышенная") == "Повышенная"; bool NeedSuperPreset = OnBossByScore && (IsHardCommonDifficulty || IsUpperCashDifficulty); if (NeedSuperPreset) { calculatedColumn = SolverV2.FindBestMove(gm.board.GridToTeam(), GameManager.instance.currentPlayer); } else { calculatedColumn = Solver.FindBestMove(gm.board.GridToTeam(), GameManager.instance.currentPlayer); } } }