public void InitCase(BoardItemDataSource itemDataSource, BendDataSource turnDataSource, StandDataSource standDataSource) { _spriteSmallRenderer = this.transform.FindChild("case-board-small").GetComponent <SpriteRenderer>(); _spriteLargeRenderer = this.transform.FindChild("case-board-large").GetComponent <SpriteRenderer>(); _spriteWarningRenderer = this.transform.FindChild("case-board-warning").GetComponent <SpriteRenderer>(); _spriteDangerousRenderer = this.transform.FindChild("case-board-dangerous").GetComponent <SpriteRenderer>(); _textMesh = this.transform.FindChild("case-board-text").GetComponent <TextMesh>(); this.standDataSource = standDataSource; this.itemDataSource = itemDataSource; this.bendDataSource = turnDataSource; this.SetDefaultBorder(); _spriteWarningRenderer.color = new Color(1, 0, 0, 0); _spriteDangerousRenderer.color = new Color(1, 0, 0, 0); _textMesh.text = string.Empty; }
public void InitCase(BoardItemDataSource itemDataSource, BendDataSource turnDataSource, StandDataSource standDataSource) { _spriteSmallRenderer = this.transform.FindChild("case-board-small").GetComponent<SpriteRenderer>(); _spriteLargeRenderer = this.transform.FindChild("case-board-large").GetComponent<SpriteRenderer>(); _spriteWarningRenderer = this.transform.FindChild("case-board-warning").GetComponent<SpriteRenderer>(); _spriteDangerousRenderer = this.transform.FindChild("case-board-dangerous").GetComponent<SpriteRenderer>(); _textMesh = this.transform.FindChild("case-board-text").GetComponent<TextMesh>(); this.standDataSource = standDataSource; this.itemDataSource = itemDataSource; this.bendDataSource = turnDataSource; this.SetDefaultBorder(); _spriteWarningRenderer.color = new Color(1, 0, 0, 0); _spriteDangerousRenderer.color = new Color(1, 0, 0, 0); _textMesh.text = string.Empty; }
public void EndTurn(StandDataSource standDataSource) { if (standDataSource != null) { if (standDataSource.playerIndex.HasValue && standDataSource.playerIndex.Value == _currentPlayer.index) { _currentPlayer.features.tire = 6; var blackDice = RaceEngine.Instance.BlackDice(); if (blackDice <= 10) { _currentPlayer.currentTurn.standMovement = Mathf.CeilToInt(((float)blackDice) / 2.0f); _currentPlayer.currentTurn.gear = 4; _currentPlayer.state = PlayerStateType.StandOut; } else { if (_currentPlayer.currentTurn.gear > 4) { _currentPlayer.currentTurn.gear = 4; } _currentPlayer.state = PlayerStateType.EndTurn; } } else { _currentPlayer.state = PlayerStateType.EndTurn; } } else { RaceEngine.Instance.OnClash(_currentPlayer); RaceEngine.Instance.OnBrokenEngine(_currentPlayer); _currentPlayer.state = PlayerStateType.EndTurn; } this.CheckIsDead(_currentPlayer); }
public void SelectedRoute(RouteResult candidate) { var endCase = candidate.route.Last(); StandDataSource standData = null; if (endCase.standDataSource != null) { standData = endCase.standDataSource; } FeatureEngine.Instance.ApplyRoute(_currentPlayer, candidate); bool hasNewLap = BoardEngine.Instance.ContainsFinishCase(candidate.route.Select(r => r.itemDataSource.index)); if (hasNewLap) { _currentPlayer.lap = _currentPlayer.lap + 1; } if (endCase.bendDataSource != null) { if (candidate.nbOutOfBend == 0 && _currentPlayer.state != PlayerStateType.Aspiration) { if (_currentPlayer.lastBend == endCase.bendDataSource.name) { _currentPlayer.stopBend = _currentPlayer.stopBend + 1; } else { _currentPlayer.stopBend = 1; _currentPlayer.lastBend = endCase.bendDataSource.name; } } else if (_currentPlayer.lastBend != endCase.bendDataSource.name) { _currentPlayer.stopBend = 0; _currentPlayer.lastBend = endCase.bendDataSource.name; } } else { _currentPlayer.lastBend = string.Empty; _currentPlayer.stopBend = 0; } FeatureEngine.Instance.ApplyDangerousRoute(_currentPlayer, candidate); if (_currentPlayer.state == PlayerStateType.ChoseRoute) { var turnHistories = this.GetTurnHistories(_currentPlayer); if (turnHistories.Any()) { var previousHistory = turnHistories.Last(); if (previousHistory.paths.Any()) { BoardEngine.Instance.CleanRoute(previousHistory.paths.SelectMany(p => p.Select(i => BoardEngine.Instance.GetCase(i))).ToList(), _currentPlayer.GetColor()); } } _currentPlayer.currentTurn.paths.Add(candidate.route.Select(r => r.itemDataSource.index).ToList()); _currentPlayer.currentTurn.outOfBend = candidate.nbOutOfBend; if (candidate.nbOutOfBend == 0 && standData == null && !candidate.isBadWay && this.CheckAspiration(candidate.route)) { _currentPlayer.state = PlayerStateType.Aspiration; this.CheckIsDead(_currentPlayer); } else { this.EndTurn(standData); } } else if (_currentPlayer.state == PlayerStateType.Aspiration || _currentPlayer.state == PlayerStateType.StandOut) { _currentPlayer.currentTurn.paths.Add(candidate.route.Select(r => r.itemDataSource.index).ToList()); if (standData == null && !candidate.isBadWay && this.CheckAspiration(candidate.route)) { _currentPlayer.state = PlayerStateType.Aspiration; this.CheckIsDead(_currentPlayer); } else { this.EndTurn(standData); } } if (_currentPlayer.state == PlayerStateType.EndTurn || _currentPlayer.state == PlayerStateType.Dead) { var turnHistories = this.GetTurnHistories(_currentPlayer); turnHistories.Add(_currentPlayer.currentTurn); _currentPlayer.currentTurn = null; ContextEngine.Instance.gameContext.lastTurn = DateTime.Now; if (ContextEngine.Instance.gameContext.state == GameStateType.Qualification) { if (_currentPlayer.lap > 0) { var previousHistory = turnHistories.Last(); if (previousHistory.paths.Any()) { BoardEngine.Instance.CleanRoute(previousHistory.paths.SelectMany(p => p.Select(i => BoardEngine.Instance.GetCase(i))).ToList(), _currentPlayer.GetColor()); } _currentPlayer.qualification.endDate = DateTime.UtcNow; int nbDe = _currentPlayer.qualification.turnHistories.Count - 1; var duration = _currentPlayer.qualification.endDate - _currentPlayer.qualification.startDate; int totalMin = Mathf.FloorToInt((float)duration.TotalMinutes); _currentPlayer.qualification.total = nbDe + totalMin + _currentPlayer.qualification.outOfBend; _currentPlayer.qualification.state = QualificationStateType.Completed; _currentPlayer.state = PlayerStateType.Finish; } else if (_currentPlayer.state == PlayerStateType.Dead) { _currentPlayer.qualification.endDate = DateTime.UtcNow; _currentPlayer.qualification.state = QualificationStateType.Completed; _currentPlayer.qualification.isDead = true; } } else if (_currentPlayer.lap == ContextEngine.Instance.gameContext.totalLap) { _currentPlayer.state = PlayerStateType.Finish; _currentPlayer.position = ContextEngine.Instance.gameContext.players.Where(p => p.state == PlayerStateType.Finish).Count(); } else if (_currentPlayer.state != PlayerStateType.Dead) { _currentPlayer.state = PlayerStateType.Waiting; } } }