private void StartNextCharacterTurn(TurnCharacter ch) { int checkIndex = ActiveCharacters.IndexOf(ch) + 1; if (checkIndex >= ActiveCharacters.Count) { checkIndex = 0; } TurnCharacter lastChar = ch; // Get the next non-dead character with opposite player, pruning any dead ones. // Give up if we've cycled back to the character that just acted, or if a team is empty. Once CheckBothTeamsForActive() is called, the game will know to end. while (ActiveCharacters[checkIndex] != lastChar && TeamOneActiveChars.Count > 0 && TeamTwoActiveChars.Count > 0) { if (checkIndex < ActiveCharacters.Count) { if (ActiveCharacters[checkIndex].CurrentState != CharacterState.dead && ActiveCharacters[checkIndex].PlayerNumber != this.MovingPlayer && !ActiveCharacters[checkIndex].WentThisTurn) { StartTurnByNumber(checkIndex); break; } else if (ActiveCharacters[checkIndex].CurrentState == CharacterState.dead) // Kill character if their CurrentState is "dead" { switch (ActiveCharacters[checkIndex].PlayerNumber) { case 1: TeamOneActiveChars.Remove(ActiveCharacters[checkIndex]); break; case 2: TeamTwoActiveChars.Remove(ActiveCharacters[checkIndex]); break; } // TODO: Death animation, gravestone, etc? ActiveCharacters[checkIndex].CharGO.SetActive(false); ActiveCharacters.Remove(ActiveCharacters[checkIndex]); } else if (ActiveCharacters[checkIndex].CurrentState != CharacterState.dead && (ActiveCharacters[checkIndex].PlayerNumber == this.MovingPlayer || ActiveCharacters[checkIndex].WentThisTurn)) // Skip over the last-moving player's characters, and characters that went this turn { checkIndex++; } } if (checkIndex >= ActiveCharacters.Count) { checkIndex = 0; } } }
private void PruneDeadCharacters() { List <TurnCharacter> charsToRemove = new List <TurnCharacter>(); List <GameObject> charsGOToRemove = new List <GameObject>(); foreach (TurnCharacter dCh in ActiveCharacters) { if (dCh.CurrentState == CharacterState.dead) { switch (dCh.PlayerNumber) { case 1: TeamOneActiveChars.Remove(dCh); break; case 2: TeamTwoActiveChars.Remove(dCh); break; } // TODO: Death animation, gravestone, etc? dCh.CharGO.SetActive(false); charsToRemove.Add(dCh); charsGOToRemove.Add(dCh.CharGO); } } foreach (TurnCharacter rCh in charsToRemove) { ActiveCharacters.Remove(rCh); gridMgr.ActiveCharsGO.Remove(rCh.CharGO); // Really should move ActiveCharsGO to here probably } charsToRemove.Clear(); }