chip-gameV3/Assets/Scripts/Common/GameFSM/BotThinkingState.cs
sega 8a6d23b77d Реорг Scripts
Разделено на 4 модуля
- Menu
- Gameplay
- Settings
- Common
2026-07-15 10:49:55 +03:00

139 lines
4.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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.GetMovesCount();
currentPreset = currentPreset.GetPreset(movesMade);
//Debug.Log("Ходов: " + movesMade + " Пресет: " + currentPreset.Description);
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<Animator>();
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)
{
//нужно запустить анимацию подброса и дождаться ее окончания
//Debug.Log("Throw из botthink");
animator.SetTrigger("Throw");
startAnimTime = Time.time;
animationStarted = true;
}
if (animationStarted && Time.time - startAnimTime > animLength)
{
//ставим фишку в расчитанную колонку (подготовка к следующему состоянию)
GameManager.instance.currentColumnIndex = calculatedColumn;
float targetY = GameManager.instance.startY + 5;
float targetX = GameManager.instance.slotLeftTop.position.x +
GameManager.instance.currentColumnIndex *
GameManager.instance.stepX;
GameManager.instance.currentChip.transform.position = new Vector2(targetX, targetY);
//GameManager.instance.currentChip.SetActive(true);
GameManager.instance.stateMachine.ChangeState(new ChipFallingState(0));
}
}
}
void calc()
{
//calculatedColumn = Solver.FindBestMove(GameManager.fieldModel.fieldArr, GameManager.instance.currentPlayer);
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);
//NeedSuperPreset = true;
//Debug.Log($"Использовать суперсложность: {NeedSuperPreset}\nСейчас босс: {OnBossByScore}\nСложная сложность: {IsHardCommonDifficulty}\nВключен режим заработка: {IsUpperCashDifficulty}\n");
if (NeedSuperPreset)
{
calculatedColumn = SolverV2.FindBestMove(GameManager.fieldModel.FieldArray, GameManager.instance.currentPlayer);
}
else
{
calculatedColumn = Solver.FindBestMove(GameManager.fieldModel.FieldArray, GameManager.instance.currentPlayer);
}
}
}