private void ExecuteEnemyTurn() { // One last check that the current combatant is an enemy Debug.Assert(CurrCombatant.Allegiance == Allegiance.ENEMY); EnemyController enemy = (EnemyController)CurrCombatant; // Carry out the enemy's turn enemy.DoTurn(); // If the next turn is an enemy too, recursively execute their turn CombatantTurnQueue.Dequeue(); if (CurrCombatant.Allegiance == Allegiance.ENEMY) { ExecuteEnemyTurn(); } else { // The next combatant is player controlled, so let's wait for // PlayerMenuController to execute the turn State = BattleState.PLAYERCHOICE; } }
private void GenerateNewTurnEntry() { bool turnAssigned = false; while (!turnAssigned) { // First check if any combatants' clocks are already below zero List <Tuple <int, int> > subZeroClockIDs = new List <Tuple <int, int> >(); for (int i = 0; i < CombatantTurnClocks.Count; ++i) { // If the combatant is dead, don't consider them if (!IsCombatantAlive(i)) { continue; } if (CombatantTurnClocks[i] <= 0) { subZeroClockIDs.Add(new Tuple <int, int>(i, CombatantTurnClocks[i])); } } if (subZeroClockIDs.Count > 0) { // If there are combatants below zero on their clocks, one of them will // have the next turn // Find which ID has precedence subZeroClockIDs.Sort(CompareIDTurnClockPair); int idOfNextTurnTaker = subZeroClockIDs[0].Item1; // Set their turn clock appropriately for how much they've overspilled CombatantTurnClocks[idOfNextTurnTaker] = turnClockStartVal + CombatantTurnClocks[idOfNextTurnTaker] + Combatants[idOfNextTurnTaker].Agility; // Add them to the turn queue CombatantTurnQueue.Enqueue(idOfNextTurnTaker); // Store the turn clocks at this turn TurnClocksAtGivenTurn[TurnClocksAtGivenTurn.Keys.Count] = new List <int>(CombatantTurnClocks); // A turn has been assigned - we can exit the loop turnAssigned = true; } else { // If there aren't any combatants below zero on their clocks, // subtract agilities and check again for (int i = 0; i < CombatantTurnClocks.Count; ++i) { // If the combatant is dead, don't consider them if (!IsCombatantAlive(i)) { continue; } CombatantTurnClocks[i] -= Combatants[i].Agility; } // We'll need to run the loop again to check if anyone's clock // has hit zero turnAssigned = false; } } }
private void Update() { // If the combatant is involved in an animation currently, we have to // wait for that to finish if (!ResolvedAurasThisTurn) { if (CurrCombatant.Allegiance == Allegiance.ENEMY) { if (currentlyAnimatingCombatants.Count > 0) { return; } } else { if (currentlyAnimatingCombatants.Contains(CurrCombatantID)) { return; } } } // Resolve all auras affecting the current combatant if (!ResolvedAurasThisTurn) { Debug.Log("~~~~~~~~~~~"); Debug.Log(CurrCombatant.Name + "[" + CurrCombatantID + "]'s turn!"); CurrCombatant.ResolveAuras(); ResolvedAurasThisTurn = true; } if (CurrCombatant.Allegiance == Allegiance.ENEMY) { // For enemies, execute their turn straight away ((EnemyController)CurrCombatant).DoTurn(); } else { // For players, we've got to wait until PlayerMenuController takes // the player turn // // This is pretty grim (why are we running update cycles if nothing's // happening?) but whatever, sue me if (WaitingOnPlayerTurn) { return; } } // The turn has been executed; prepare for the next one CombatantTurnQueue.Dequeue(); ++TurnNum; if (CurrCombatant.Allegiance == Allegiance.PLAYER) { State = BattleState.PLAYERCHOICE; WaitingOnPlayerTurn = true; } else { State = BattleState.ENEMYCHOICE; WaitingOnPlayerTurn = false; } ResolvedAurasThisTurn = false; GenerateNewTurnEntry(); }