public void EndTurn(TurnCharacter ch) // take in a character and find a character on the opposite team to activate { PruneDeadCharacters(); // Check for characters that haven't gone this turn bool allCharsWent = true; foreach (TurnCharacter wCh in ActiveCharacters) { if (!wCh.WentThisTurn) { allCharsWent = false; } } if (allCharsWent) // Start a new turn! (may add more here later) { // As this is a new turn, set all chars' WentThisTurn to false foreach (TurnCharacter tCh in ActiveCharacters) { tCh.WentThisTurn = false; } } StartNextCharacterTurn(ch); CheckBothTeamsForActive(); }
public void IdentifyMovableNodes(TurnCharacter ch) { CharacterGridMovement gm = ch.CharGO.GetComponent <CharacterGridMovement>(); GridMovableNode currentN = gm.CurrentNode; gm.MovableNodes.Add(currentN); foreach (GridMovableNode n in currentN.AllNeighborNodes) { if (!CheckIfNodeOccupied(n)) { if (!gm.MovableNodes.Contains(n)) { gm.MovableNodes.Add(n); } for (int i = 1; i < this.moveDistance; i++) { foreach (GridMovableNode ni in n.AllNeighborNodes) { if (!gm.MovableNodes.Contains(ni)) { gm.MovableNodes.Add(ni); } } } } } AssignNodeMatsFromCharacter(gm); }
public void UpdateTurn(Piece nextActor) { turnCharacters.QueueFreeChildren(); bool shouldAdd = false; foreach (Piece actor in Global.battle.actors) { if (nextActor == actor) { shouldAdd = true; TurnCharacter nextTurnActor = TurnCharacter.Create(actor); nextTurnActor.Grow(); turnCharacters.AddChild(nextTurnActor); } else if (shouldAdd) { turnCharacters.AddChild(TurnCharacter.Create(actor)); } } foreach (Piece actor in Global.battle.actors) { if (nextActor == actor) { return; } turnCharacters.AddChild(TurnCharacter.Create(actor)); } }
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; } } }
public void UpdateFocusedPlayer() { foreach (TurnCharacter ch in turnMgr.ActiveCharacters) { if (ch.CurrentState == CharacterState.active) { activeChar = ch; activeCharSliceMov = ch.CharGO.GetComponent <CharacterSliceMovement>(); break; } } }
private void Die() { TurnCharacter dataChar = this.gameObject.GetComponent <UnityCharacterTurnInfo>().DataCharacter; // If the character dying is the active character, in case they died without firing, set the turn time to 7 seconds if (dataChar.CurrentState == CharacterState.active) { TurnTimer t = TurnTimer.Instance; t.SetTurnTime(7f); } dataChar.Die(); // At the end of the turn, the character will be set inactive since its state is now "dead" }
public TurnCharacter CreateActiveCharacter(int pNum, GameObject go) { TurnCharacter ch = new TurnCharacter(pNum, go); ActiveCharacters.Add(ch); switch (pNum) { case 1: TeamOneActiveChars.Add(ch); break; case 2: TeamTwoActiveChars.Add(ch); break; } return(ch); }
public void EndTurnOfActiveCharacter() { bool foundActive = false; foreach (TurnCharacter ch in ActiveCharacters) { if (ch.CurrentState == CharacterState.active) { foundActive = true; ch.EndTurn(); break; } } // This probably means whatever character was meant to be active has died if (!foundActive) { // Keep this outside foreach to avoid collection change during enumeration TurnCharacter dCh = null; foreach (TurnCharacter ch in ActiveCharacters) { // This could result in the incorrect character ending its turn if two characters have died in the same turn if (ch.CurrentState == CharacterState.dead) { dCh = ch; break; } } // End the dead character's turn (this will leave them dead, but still proceed to the next character) if (dCh != null) { dCh.EndTurn(); } } }
public string MonsterTurnAttack() { if (ListCharacters.Count <= 0) //check if character party is already dead { EndGame(); return("EndGame"); //send endgame function to the battle page } else if (ListMonsters.Count <= 0) //checks if monsters already dead { //NEWRound // RoundRefreshPage(); ResetTurns(); EndRound(); return("refresh"); //await Navigation.PushModalAsync(new ItemDropPage(_viewModel.Pool)); } if (TurnCharacter == null) { TurnCharacter = ListCharacters[0]; //highest hp later } if (TurnMonster == null) { TurnMonster = ListMonsters[0]; //fastest on list next } MonsterAttacks(TurnCharacter, TurnMonster); EndTurn(); if (TurnCharacter.IsLiving()) { MonsterMessageOutput(TurnMonster.Name + " attacks " + TurnCharacter.Name + MonsterAttack + " HP Remaining: " + TurnCharacter.CurrentHealth); return(""); } else { MonsterMessageOutput(TurnMonster.Name + " attacks " + TurnCharacter.Name + MonsterAttack + " Character Died"); //OutputMonster.IsVisible = true; foreach (var data in TurnCharacter.DropAllItems()) { _viewModel.Pool.Add(data); } //make this a quick function _viewModel.battleInstance.score.CharacterAtDeathList += TurnCharacter.CharacterAtDeath(); _viewModel.DatasetCharacter.Remove(TurnCharacter); ListCharacters.Remove(TurnCharacter); TurnCharacter = null; turncheckCharacter += 1; //adds a turn to symbolize that a character has died numbercharacterdead = numbercharacterdead + 1; //adds to turn if (ListCharacters.Count == 0) { return("EndGame"); } //reloadEntities(); return("reload"); } }