private void CheckEventQueue() { lock (EventQueue) { // Dequeue next ability if none is in progress if (ActiveAbility == null) { if (EventQueue.Count > 0) { BattleEvent activeEvent = EventQueue.Dequeue(); if (activeEvent != null) { activeEvent.Begin(); ActiveAbility = activeEvent; #if DEBUG Console.WriteLine("Event has begun:" + ActiveAbility.ToString()); #endif } } } // If the current ability is done, clear it if (ActiveAbility != null) { bool isDone = ActiveAbility.RunIteration(); if (isDone) { #if DEBUG Console.WriteLine("Event has completed:" + ActiveAbility.ToString()); #endif // if (ActiveAbility.Performer is Ally) // { // LastPartyAction = (AbilityState)ActiveAbility.Clone(); // } if (ActiveAbility == _victoryEvent) { int exp = 0; int ap = 0; int gil = 0; List <IInventoryItem> items = new List <IInventoryItem>(); foreach (Enemy enemy in DeadEnemies) { exp += enemy.Exp; ap += enemy.AP; gil += enemy.Gil; IInventoryItem item = enemy.WinItem(); if (item != null) { items.Add(item); } } Seven.EndBattle(exp, ap, gil, items); } if (ActiveAbility == _lossEvent) { Seven.LoseGame(); } ActiveAbility = null; CheckForDeadEnemies(); // We need to prune all events from a source who cannot act. // We must do the whole queue at once. We can't just look at // the head of the queue. // Example. You attack with a character -- an event goes in the // queue, possibly behind many other events. Then that ally is // paralyzed. Then that ally is attacked, and it reaches its // limit break. Then that character is cured by, say, one of // Aeris's limit breaks (all of these things went in the queue // before said ally's attack). Then you use that ally's limit // break immediately upon regaining control of it. // In theory, the attack event could still happen AFTER the limit // break. It needs to come out of the queue NOW if the ally // cannot act. EventQueue.PruneEvents(x => x.Source.CannotAct, "source cannot act"); } } } }