//корутина движенния бота private IEnumerator GoBot() { if (!isCheating) { _gameCanvas.OnOffSavedButtons(); way = _dbWork.GetWay(currentStreetPath.GetIdStreetPath(), ThinkOfWay()); bool tried = (Random.value * 100 > 95); if (tried) { GameController.aboutPlayer += "Игрок " + NickName + " пытался смухлевать \n"; if (Random.Range(0, 2) != 1) { GetCheat(); GameController.aboutPlayer += "Игрок " + NickName + " не попался \n"; alreadyCheat = true; } else { GameController.aboutPlayer += "Игрок " + NickName + " попался \n"; corutine = false; _gameCanvas.gameObject.GetComponent <GameController>().cathedPlayer(); yield break; } } } while (currentSteps < maxSteps || isCheating && way.Count > 0) { bool endFirstStep = false; int num = way.Count; NetworkStreetPath somewhere = null; for (int i = 0; i < num; i++) { if (i != 0) { somewhere = _dbWork.GetPathById(way.Dequeue()); } if (i == 0 && !endFirstStep) { somewhere = _dbWork.GetPathById(way.Dequeue()); if (currentStreetPath.isBridge && (currentStreetPath.start.Equals(somewhere.start) || currentStreetPath.start.Equals(somewhere.end))) { destination = currentStreetPath.start; angle = MapBuilder.Angle(transform.position, destination); yield return(new WaitUntil(() => transform.position == destination)); } else { destination = currentStreetPath.end; angle = MapBuilder.Angle(transform.position, destination); yield return(new WaitUntil(() => transform.position == destination)); } endFirstStep = true; i--; continue; } if (i == num - 1) { destination = MapBuilder.GetCenter(somewhere.start, somewhere.end); angle = MapBuilder.Angle(transform.position, destination); currentStreetPath = somewhere; yield return(new WaitUntil(() => transform.position == destination)); } else { if (somewhere.isBridge && transform.position.Equals(somewhere.end)) { destination = somewhere.start; angle = MapBuilder.Angle(transform.position, destination); yield return(new WaitUntil(() => transform.position == destination)); } else { destination = somewhere.end; angle = MapBuilder.Angle(transform.position, destination); yield return(new WaitUntil(() => transform.position == destination)); } } currentSteps++; } } GameController.aboutPlayer += "Игрок " + NickName + " пришел на " + currentStreetPath.namePath + "\n"; NetworkPathForBuy pathForBuy = _dbWork.GetPathForBuy(currentStreetPath.GetIdStreetPath()); if (currentStreetPath.CanBuy && pathForBuy.IdPlayer == 0 && money > pathForBuy.PriceStreetPath) { GameController.aboutPlayer += "Игрок " + NickName + " купил " + currentStreetPath.namePath + "\n"; pathForBuy.Buy(this); } corutine = false; ready = true; _gameCanvas.OnOffSavedButtons(); }
//Корутина движения private IEnumerator Go() { if (alreadyCheat) { _gameCanvas.ShowInfoAboutEvent("Вы уже мухлевали на этом ходе :("); corutine = false; yield break; } bool tried = isCheating; yield return(new WaitUntil(() => isCheating == false)); if (tried && isGonnaBeCathced) { if (Random.Range(0, 2) != 1) { NetworkGameController.aboutPlayer += "Игрок " + NickName + " не попался \n"; alreadyCheat = true; isGonnaBeCathced = false; } else { NetworkGameController.aboutPlayer += "Игрок " + NickName + " попался \n"; corutine = false; _gameCanvas.gameObject.GetComponent <NetworkGameController>().cathedPlayer(); yield break; } } else if (tried) { corutine = false; yield break; } bool endFirstStep = false; int num = way.Count; NetworkStreetPath somewhere = null; for (int i = 0; i < num; i++) { if (i != 0) { somewhere = _dbWork.GetPathById(way.Dequeue()); } if (i == 0 && !endFirstStep) { somewhere = _dbWork.GetPathById(way.Dequeue()); if (currentStreetPath.isBridge && (currentStreetPath.start.Equals(somewhere.start) || currentStreetPath.start.Equals(somewhere.end))) { destination = currentStreetPath.start; angle = MapBuilder.Angle(transform.position, destination); yield return(new WaitUntil(() => transform.position == destination)); } else { destination = currentStreetPath.end; angle = MapBuilder.Angle(transform.position, destination); yield return(new WaitUntil(() => transform.position == destination)); } endFirstStep = true; i--; continue; } if (i == num - 1) { destination = MapBuilder.GetCenter(somewhere.start, somewhere.end); angle = MapBuilder.Angle(transform.position, destination); currentStreetPath = somewhere; yield return(new WaitUntil(() => transform.position == destination)); } else { if (somewhere.isBridge && transform.position.Equals(somewhere.end)) { destination = somewhere.start; angle = MapBuilder.Angle(transform.position, destination); yield return(new WaitUntil(() => transform.position == destination)); } else { destination = somewhere.end; angle = MapBuilder.Angle(transform.position, destination); yield return(new WaitUntil(() => transform.position == destination)); } } currentSteps++; } corutine = false; _gameCanvas.OnOffSavedButtons(); if (tried && isGonnaBeCathced) { _gameCanvas.GetComponent <NetworkGameController>().nextStep(); } }