public void DeregisterUnitFromPlayer(Unit unit) { //Checking if the unit that has to be destroyed is the same that has the current turn, in that case the game automatically skips to the next player bool skipAfterDestroy = false; if (_currentPlayer.CurrentUnit == unit) { skipAfterDestroy = true; } CustomHumanPlayer player = _cellGrid.Players.Find(p => p.PlayerNumber.Equals(unit.PlayerNumber)) as CustomHumanPlayer; Debug.Assert(player != null, "Error in retriving the player"); if (player != null) { player.PlayerUnits = new Queue <Unit>(player.PlayerUnits.Where(u => u != unit)); if (player.PlayerUnits.Count == 0) { GameOver(unit.PlayerNumber); } else if (skipAfterDestroy) { CustomUnit cUnit = unit as CustomUnit; if (cUnit) { _cellGrid.EndTurn(cUnit); Debug.Log("Turnskip by destruction called by " + unit.name); } } } }
private void ChangeCurrentPlayer() { _currentPlayer = _cellGrid.CurrentPlayer as CustomHumanPlayer; _uiController.ForEach(ui => { ui.SetButtonsInteractable(ui.PlayerNumber == _cellGrid.CurrentPlayerNumber); if (ui.PlayerNumber == _cellGrid.CurrentPlayerNumber) { CustomUnit unit = _currentPlayer.PlayerUnits.Peek() as CustomUnit; if (unit != null) { ui.SetAbilityCost(unit.GetAbilityCost()); } } }); }