140 lines
4.6 KiB
C#
140 lines
4.6 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
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 (GameManager.instance.dummyBots)
|
||
currentPreset = GameManager.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 (GameManager.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);
|
||
|
||
Debug.Log($"Использовать суперсложность: {NeedSuperPreset}\nСейчас босс: {OnBossByScore}\nСложная сложность: {IsHardCommonDifficulty}\nВключен режим заработка: {IsUpperCashDifficulty}\n");
|
||
|
||
|
||
|
||
if (NeedSuperPreset)
|
||
{
|
||
calculatedColumn = SolverV2.FindBestMove(GameManager.fieldModel.fieldArr, GameManager.instance.currentPlayer);
|
||
}
|
||
else
|
||
{
|
||
calculatedColumn = Solver.FindBestMove(GameManager.fieldModel.fieldArr, GameManager.instance.currentPlayer);
|
||
}
|
||
|
||
}
|
||
}
|