internal void OnQueueEmpty() { #if _GAME_DEBUG DebugLog.WriteLine("Game " + GameId + ": Action queue resolved"); #endif // Don't do anything if the game state hasn't changed // Check if one of the other players is waiting for the other one to mulligan var step = Step; if (step == Step.BEGIN_MULLIGAN) { foreach (var p in Players) { if (p.MulliganState == MulliganState.WAITING) { ActiveTriggers.Queue(TriggerType.OnMulliganWaiting, p); return; } } } // Advance game step if necessary (probably setting off new triggers) var nextStep = NextStep; // Only advance to end turn when current player chooses to #if _GAME_DEBUG if (nextStep == Step.MAIN_END && ActionQueue.IsEmpty) { DebugLog.WriteLine("Game " + GameId + ": Waiting for player to select next option"); } #endif if (nextStep != step && nextStep != Step.MAIN_END) { #if _GAME_DEBUG DebugLog.WriteLine("Game " + GameId + ": Advancing game step from " + step + " to " + nextStep); #endif Step = nextStep; } }
// Death checking phase internal void RunDeathCreationStepIfNeeded() { #if _GAME_DEBUG DebugLog.WriteLine("Game " + GameId + ": Checking for death creation step"); #endif if (_deathCheckQueue.Count == 0) { return; } // We only have to check health because ToBeDestroyed cannot be reversed without the minion leaving play var dyingEntities = _deathCheckQueue.Where( id => ((ICharacter)Entities[id]).MortallyWounded && Entities[id].Zone.Type == Brimstone.Zone.PLAY) .Select(id => (ICharacter)Entities[id]).ToList(); if (dyingEntities.Count > 0) { #if _GAME_DEBUG DebugLog.WriteLine("Game " + GameId + ": Running death creation step"); #endif PowerHistory?.Add(new BlockStart(BlockType.DEATHS, this)); } // Death Creation Step bool gameEnd = false; foreach (var e in dyingEntities) { #if _ACTIONS_DEBUG DebugLog.WriteLine("Game {0}: {1} dies", GameId, e.ShortDescription); #endif // Queue deathrattles and OnDeath triggers before moving mortally wounded minion to graveyard // (they will be executed after the zone move) // TODO: Test that each queue resolves before the next one populates. If it doesn't, we can make queue populating lazy if (e is Minion) { ActiveTriggers.Queue(TriggerType.OnDeath, e); } // NumMinionsPlayerKilledThisTurn seems to be the number of minions that died this turn // regardless of who or what killed what e.Controller.NumMinionsPlayerKilledThisTurn++; NumMinionsKilledThisTurn++; e.IsExhausted = false; // Move dead character to graveyard e.Zone = e.Controller.Graveyard; // TODO: Reset all minion tags to default if (e is Minion) { var minion = ((Minion)e); minion.Damage = 0; } // Hero death if (e is Hero) { e.Controller.PlayState = PlayState.LOSING; gameEnd = true; } } if (gameEnd) { GameWon(); } if (dyingEntities.Count > 0) { PowerHistory?.Add(new BlockEnd(BlockType.DEATHS)); } _deathCheckQueue.Clear(); }