public void TagChange(IHsGameState gameState, string rawTag, int id, string rawValue, IGame game, bool isRecursive = false) { GAME_TAG tag; if (!Enum.TryParse(rawTag, out tag)) { int tmp; if (int.TryParse(rawTag, out tmp) && Enum.IsDefined(typeof(GAME_TAG), tmp)) { tag = (GAME_TAG)tmp; } } var value = LogReaderHelper.ParseTagValue(tag, rawValue); TagChange(gameState, tag, id, value, game, isRecursive); }
public void TagChange(IHsGameState gameState, string rawTag, int id, string rawValue, IGame game, bool isRecursive = false) { if (gameState.LastId != id) { //game.SecondToLastUsedId = gameState.LastId; if (gameState.ProposedKeyPoint != null) { ReplayMaker.Generate(gameState.ProposedKeyPoint.Type, gameState.ProposedKeyPoint.Id, gameState.ProposedKeyPoint.Player, game); gameState.ProposedKeyPoint = null; } } gameState.LastId = id; if (id > gameState.MaxId) { gameState.MaxId = id; } if (!game.Entities.ContainsKey(id)) { game.Entities.Add(id, new Entity(id)); } GAME_TAG tag; if (!Enum.TryParse(rawTag, out tag)) { int tmp; if (int.TryParse(rawTag, out tmp) && Enum.IsDefined(typeof(GAME_TAG), tmp)) { tag = (GAME_TAG)tmp; } } var value = LogReaderHelper.ParseTagValue(tag, rawValue); var prevValue = game.Entities[id].GetTag(tag); game.Entities[id].SetTag(tag, value); if (tag == CONTROLLER && gameState.WaitForController != null && game.Player.Id == -1) { var p1 = game.Entities.FirstOrDefault(e => e.Value.GetTag(PLAYER_ID) == 1).Value; var p2 = game.Entities.FirstOrDefault(e => e.Value.GetTag(PLAYER_ID) == 2).Value; if (gameState.CurrentEntityHasCardId) { if (p1 != null) { p1.IsPlayer = value == 1; } if (p2 != null) { p2.IsPlayer = value != 1; } game.Player.Id = value; game.Opponent.Id = value % 2 + 1; } else { if (p1 != null) { p1.IsPlayer = value != 1; } if (p2 != null) { p2.IsPlayer = value == 1; } game.Player.Id = value % 2 + 1; game.Opponent.Id = value; } } var controller = game.Entities[id].GetTag(CONTROLLER); var cardId = game.Entities[id].CardId; if (tag == ZONE) { if (((TAG_ZONE)value == HAND || ((TAG_ZONE)value == PLAY || (TAG_ZONE)value == DECK) && game.IsMulliganDone) && gameState.WaitForController == null) { if (!game.IsMulliganDone) { prevValue = (int)DECK; } if (controller == 0) { game.Entities[id].SetTag(ZONE, prevValue); gameState.WaitForController = new { Tag = rawTag, Id = id, Value = rawValue }; return; } } switch ((TAG_ZONE)prevValue) { case DECK: switch ((TAG_ZONE)value) { case HAND: if (controller == game.Player.Id) { gameState.GameHandler.HandlePlayerDraw(game.Entities[id], cardId, gameState.GetTurnNumber()); gameState.ProposeKeyPoint(Draw, id, ActivePlayer.Player); } else if (controller == game.Opponent.Id) { if (!string.IsNullOrEmpty(game.Entities[id].CardId)) { #if DEBUG Log.Debug($"Opponent Draw (EntityID={id}) already has a CardID. Removing. Blizzard Pls."); #endif game.Entities[id].CardId = string.Empty; } gameState.GameHandler.HandleOpponentDraw(game.Entities[id], gameState.GetTurnNumber()); gameState.ProposeKeyPoint(Draw, id, ActivePlayer.Opponent); } break; case SETASIDE: case REMOVEDFROMGAME: if (controller == game.Player.Id) { if (gameState.JoustReveals > 0) { gameState.JoustReveals--; break; } gameState.GameHandler.HandlePlayerRemoveFromDeck(game.Entities[id], gameState.GetTurnNumber()); } else if (controller == game.Opponent.Id) { if (gameState.JoustReveals > 0) { gameState.JoustReveals--; break; } gameState.GameHandler.HandleOpponentRemoveFromDeck(game.Entities[id], gameState.GetTurnNumber()); } break; case GRAVEYARD: if (controller == game.Player.Id) { gameState.GameHandler.HandlePlayerDeckDiscard(game.Entities[id], cardId, gameState.GetTurnNumber()); gameState.ProposeKeyPoint(DeckDiscard, id, ActivePlayer.Player); } else if (controller == game.Opponent.Id) { gameState.GameHandler.HandleOpponentDeckDiscard(game.Entities[id], cardId, gameState.GetTurnNumber()); gameState.ProposeKeyPoint(DeckDiscard, id, ActivePlayer.Opponent); } break; case PLAY: if (controller == game.Player.Id) { gameState.GameHandler.HandlePlayerDeckToPlay(game.Entities[id], cardId, gameState.GetTurnNumber()); gameState.ProposeKeyPoint(DeckDiscard, id, ActivePlayer.Player); } else if (controller == game.Opponent.Id) { gameState.GameHandler.HandleOpponentDeckToPlay(game.Entities[id], cardId, gameState.GetTurnNumber()); gameState.ProposeKeyPoint(DeckDiscard, id, ActivePlayer.Opponent); } break; case TAG_ZONE.SECRET: if (controller == game.Player.Id) { gameState.GameHandler.HandlePlayerSecretPlayed(game.Entities[id], cardId, gameState.GetTurnNumber(), true); gameState.ProposeKeyPoint(SecretPlayed, id, ActivePlayer.Player); } else if (controller == game.Opponent.Id) { gameState.GameHandler.HandleOpponentSecretPlayed(game.Entities[id], cardId, -1, gameState.GetTurnNumber(), true, id); gameState.ProposeKeyPoint(SecretPlayed, id, ActivePlayer.Player); } break; default: Log.Warn($"unhandled zone change (id={id}): {prevValue} -> {value}"); break; } break; case HAND: switch ((TAG_ZONE)value) { case PLAY: if (controller == game.Player.Id) { gameState.GameHandler.HandlePlayerPlay(game.Entities[id], cardId, gameState.GetTurnNumber()); gameState.ProposeKeyPoint(Play, id, ActivePlayer.Player); } else if (controller == game.Opponent.Id) { gameState.GameHandler.HandleOpponentPlay(game.Entities[id], cardId, game.Entities[id].GetTag(ZONE_POSITION), gameState.GetTurnNumber()); gameState.ProposeKeyPoint(Play, id, ActivePlayer.Opponent); } break; case REMOVEDFROMGAME: case SETASIDE: case GRAVEYARD: if (controller == game.Player.Id) { gameState.GameHandler.HandlePlayerHandDiscard(game.Entities[id], cardId, gameState.GetTurnNumber()); gameState.ProposeKeyPoint(HandDiscard, id, ActivePlayer.Player); } else if (controller == game.Opponent.Id) { gameState.GameHandler.HandleOpponentHandDiscard(game.Entities[id], cardId, game.Entities[id].GetTag(ZONE_POSITION), gameState.GetTurnNumber()); gameState.ProposeKeyPoint(HandDiscard, id, ActivePlayer.Opponent); } break; case TAG_ZONE.SECRET: if (controller == game.Player.Id) { gameState.GameHandler.HandlePlayerSecretPlayed(game.Entities[id], cardId, gameState.GetTurnNumber(), false); gameState.ProposeKeyPoint(SecretPlayed, id, ActivePlayer.Player); } else if (controller == game.Opponent.Id) { gameState.GameHandler.HandleOpponentSecretPlayed(game.Entities[id], cardId, game.Entities[id].GetTag(ZONE_POSITION), gameState.GetTurnNumber(), false, id); gameState.ProposeKeyPoint(SecretPlayed, id, ActivePlayer.Opponent); } break; case DECK: if (controller == game.Player.Id) { gameState.GameHandler.HandlePlayerMulligan(game.Entities[id], cardId); gameState.ProposeKeyPoint(Mulligan, id, ActivePlayer.Player); } else if (controller == game.Opponent.Id) { gameState.GameHandler.HandleOpponentMulligan(game.Entities[id], game.Entities[id].GetTag(ZONE_POSITION)); gameState.ProposeKeyPoint(Mulligan, id, ActivePlayer.Opponent); } break; default: Log.Warn($"unhandled zone change (id={id}): {prevValue} -> {value}"); break; } break; case PLAY: switch ((TAG_ZONE)value) { case HAND: if (controller == game.Player.Id) { gameState.GameHandler.HandlePlayerBackToHand(game.Entities[id], cardId, gameState.GetTurnNumber()); gameState.ProposeKeyPoint(PlayToHand, id, ActivePlayer.Player); } else if (controller == game.Opponent.Id) { gameState.GameHandler.HandleOpponentPlayToHand(game.Entities[id], cardId, gameState.GetTurnNumber(), id); gameState.ProposeKeyPoint(PlayToHand, id, ActivePlayer.Opponent); } break; case DECK: if (controller == game.Player.Id) { gameState.GameHandler.HandlePlayerPlayToDeck(game.Entities[id], cardId, gameState.GetTurnNumber()); gameState.ProposeKeyPoint(PlayToDeck, id, ActivePlayer.Player); } else if (controller == game.Opponent.Id) { gameState.GameHandler.HandleOpponentPlayToDeck(game.Entities[id], cardId, gameState.GetTurnNumber()); gameState.ProposeKeyPoint(PlayToDeck, id, ActivePlayer.Opponent); } break; case REMOVEDFROMGAME: case SETASIDE: case GRAVEYARD: if (controller == game.Player.Id) { gameState.GameHandler.HandlePlayerPlayToGraveyard(game.Entities[id], cardId, gameState.GetTurnNumber()); if (game.Entities[id].HasTag(HEALTH)) { gameState.ProposeKeyPoint(Death, id, ActivePlayer.Player); } } else if (controller == game.Opponent.Id) { gameState.GameHandler.HandleOpponentPlayToGraveyard(game.Entities[id], cardId, gameState.GetTurnNumber(), gameState.PlayersTurn()); if (game.Entities[id].HasTag(HEALTH)) { gameState.ProposeKeyPoint(Death, id, ActivePlayer.Opponent); } } break; default: Log.Warn($"unhandled zone change (id={id}): {prevValue} -> {value}"); break; } break; case TAG_ZONE.SECRET: switch ((TAG_ZONE)value) { case TAG_ZONE.SECRET: case GRAVEYARD: if (controller == game.Player.Id) { gameState.ProposeKeyPoint(SecretTriggered, id, ActivePlayer.Player); } if (controller == game.Opponent.Id) { gameState.GameHandler.HandleOpponentSecretTrigger(game.Entities[id], cardId, gameState.GetTurnNumber(), id); gameState.ProposeKeyPoint(SecretTriggered, id, ActivePlayer.Opponent); } break; default: Log.Warn($"unhandled zone change (id={id}): {prevValue} -> {value}"); break; } break; case GRAVEYARD: case SETASIDE: case CREATED: case TAG_ZONE.INVALID: case REMOVEDFROMGAME: switch ((TAG_ZONE)value) { case PLAY: if (controller == game.Player.Id) { gameState.GameHandler.HandlePlayerCreateInPlay(game.Entities[id], cardId, gameState.GetTurnNumber()); gameState.ProposeKeyPoint(Summon, id, ActivePlayer.Player); } if (controller == game.Opponent.Id) { gameState.GameHandler.HandleOpponentCreateInPlay(game.Entities[id], cardId, gameState.GetTurnNumber()); gameState.ProposeKeyPoint(Summon, id, ActivePlayer.Opponent); } break; case DECK: if (controller == game.Player.Id) { if (gameState.JoustReveals > 0) { break; } gameState.GameHandler.HandlePlayerGetToDeck(game.Entities[id], cardId, gameState.GetTurnNumber()); gameState.ProposeKeyPoint(CreateToDeck, id, ActivePlayer.Player); } if (controller == game.Opponent.Id) { if (gameState.JoustReveals > 0) { break; } gameState.GameHandler.HandleOpponentGetToDeck(game.Entities[id], gameState.GetTurnNumber()); gameState.ProposeKeyPoint(CreateToDeck, id, ActivePlayer.Opponent); } break; case HAND: if (controller == game.Player.Id) { gameState.GameHandler.HandlePlayerGet(game.Entities[id], cardId, gameState.GetTurnNumber()); gameState.ProposeKeyPoint(Obtain, id, ActivePlayer.Player); } else if (controller == game.Opponent.Id) { gameState.GameHandler.HandleOpponentGet(game.Entities[id], gameState.GetTurnNumber(), id); gameState.ProposeKeyPoint(Obtain, id, ActivePlayer.Opponent); } break; default: Log.Warn($"unhandled zone change (id={id}): {prevValue} -> {value}"); break; } break; default: Log.Warn($"unhandled zone change (id={id}): {prevValue} -> {value}"); break; } } else if (tag == PLAYSTATE) { if (value == (int)CONCEDED) { gameState.GameHandler.HandleConcede(); } if (!gameState.GameEnded) { if (game.Entities[id].IsPlayer) { switch ((TAG_PLAYSTATE)value) { case WON: gameState.GameEndKeyPoint(true, id); gameState.GameHandler.HandleWin(); gameState.GameHandler.HandleGameEnd(); gameState.GameEnded = true; break; case LOST: gameState.GameEndKeyPoint(false, id); gameState.GameHandler.HandleLoss(); gameState.GameHandler.HandleGameEnd(); gameState.GameEnded = true; break; case TIED: gameState.GameEndKeyPoint(false, id); gameState.GameHandler.HandleTied(); gameState.GameHandler.HandleGameEnd(); break; } } } } else if (tag == CARDTYPE && value == (int)TAG_CARDTYPE.HERO) { SetHeroAsync(id, game, gameState); } else if (tag == CURRENT_PLAYER && value == 1) { var activePlayer = game.Entities[id].IsPlayer ? ActivePlayer.Player : ActivePlayer.Opponent; gameState.GameHandler.TurnStart(activePlayer, gameState.GetTurnNumber()); if (activePlayer == ActivePlayer.Player) { gameState.PlayerUsedHeroPower = false; } else { gameState.OpponentUsedHeroPower = false; } } else if (tag == LAST_CARD_PLAYED) { gameState.LastCardPlayed = value; } else if (tag == DEFENDING) { if (controller == game.Opponent.Id) { gameState.GameHandler.HandleDefendingEntity(value == 1 ? game.Entities[id] : null); } } else if (tag == ATTACKING) { if (controller == game.Player.Id) { gameState.GameHandler.HandleAttackingEntity(value == 1 ? game.Entities[id] : null); } } else if (tag == PROPOSED_DEFENDER) { game.OpponentSecrets.ProposedDefenderEntityId = value; } else if (tag == PROPOSED_ATTACKER) { game.OpponentSecrets.ProposedAttackerEntityId = value; } else if (tag == NUM_MINIONS_PLAYED_THIS_TURN && value > 0) { if (gameState.PlayersTurn()) { gameState.GameHandler.HandlePlayerMinionPlayed(); } } else if (tag == PREDAMAGE && value > 0) { if (gameState.PlayersTurn()) { gameState.GameHandler.HandleOpponentDamage(game.Entities[id]); } } else if (tag == NUM_TURNS_IN_PLAY && value > 0) { if (!gameState.PlayersTurn()) { gameState.GameHandler.HandleOpponentTurnStart(game.Entities[id]); } } else if (tag == NUM_ATTACKS_THIS_TURN && value > 0) { if (controller == game.Player.Id) { gameState.ProposeKeyPoint(Attack, id, ActivePlayer.Player); } else if (controller == game.Opponent.Id) { gameState.ProposeKeyPoint(Attack, id, ActivePlayer.Opponent); } } else if (tag == ZONE_POSITION) { var entity = game.Entities[id]; var zone = entity.GetTag(ZONE); if (zone == (int)HAND) { if (controller == game.Player.Id) { ReplayMaker.Generate(HandPos, id, ActivePlayer.Player, game); gameState.GameHandler.HandleZonePositionUpdate(ActivePlayer.Player, entity, HAND, gameState.GetTurnNumber()); } else if (controller == game.Opponent.Id) { ReplayMaker.Generate(HandPos, id, ActivePlayer.Opponent, game); gameState.GameHandler.HandleZonePositionUpdate(ActivePlayer.Opponent, entity, HAND, gameState.GetTurnNumber()); } } else if (zone == (int)PLAY) { if (controller == game.Player.Id) { ReplayMaker.Generate(BoardPos, id, ActivePlayer.Player, game); gameState.GameHandler.HandleZonePositionUpdate(ActivePlayer.Player, entity, PLAY, gameState.GetTurnNumber()); } else if (controller == game.Opponent.Id) { ReplayMaker.Generate(BoardPos, id, ActivePlayer.Opponent, game); gameState.GameHandler.HandleZonePositionUpdate(ActivePlayer.Opponent, entity, PLAY, gameState.GetTurnNumber()); } } } else if (tag == CARD_TARGET && value > 0) { if (controller == game.Player.Id) { gameState.ProposeKeyPoint(PlaySpell, id, ActivePlayer.Player); } else if (controller == game.Opponent.Id) { gameState.ProposeKeyPoint(PlaySpell, id, ActivePlayer.Opponent); } } else if (tag == EQUIPPED_WEAPON && value == 0) { if (controller == game.Player.Id) { gameState.ProposeKeyPoint(WeaponDestroyed, id, ActivePlayer.Player); } else if (controller == game.Opponent.Id) { gameState.ProposeKeyPoint(WeaponDestroyed, id, ActivePlayer.Opponent); } } else if (tag == EXHAUSTED && value > 0) { if (game.Entities[id].GetTag(CARDTYPE) == (int)TAG_CARDTYPE.HERO_POWER) { if (controller == game.Player.Id) { gameState.ProposeKeyPoint(HeroPower, id, ActivePlayer.Player); } else if (controller == game.Opponent.Id) { gameState.ProposeKeyPoint(HeroPower, id, ActivePlayer.Opponent); } } } else if (tag == CONTROLLER && prevValue > 0) { if (value == game.Player.Id) { if (game.Entities[id].IsInZone(TAG_ZONE.SECRET)) { gameState.GameHandler.HandleOpponentStolen(game.Entities[id], cardId, gameState.GetTurnNumber()); gameState.ProposeKeyPoint(SecretStolen, id, ActivePlayer.Player); } else if (game.Entities[id].IsInZone(PLAY)) { gameState.GameHandler.HandleOpponentStolen(game.Entities[id], cardId, gameState.GetTurnNumber()); } } else if (value == game.Opponent.Id) { if (game.Entities[id].IsInZone(TAG_ZONE.SECRET)) { gameState.GameHandler.HandleOpponentStolen(game.Entities[id], cardId, gameState.GetTurnNumber()); gameState.ProposeKeyPoint(SecretStolen, id, ActivePlayer.Player); } else if (game.Entities[id].IsInZone(PLAY)) { gameState.GameHandler.HandlePlayerStolen(game.Entities[id], cardId, gameState.GetTurnNumber()); } } } else if (tag == FATIGUE) { if (controller == game.Player.Id) { gameState.GameHandler.HandlePlayerFatigue(Convert.ToInt32(rawValue)); } else if (controller == game.Opponent.Id) { gameState.GameHandler.HandleOpponentFatigue(Convert.ToInt32(rawValue)); } } if (gameState.WaitForController != null) { if (!isRecursive) { TagChange(gameState, (string)gameState.WaitForController.Tag, (int)gameState.WaitForController.Id, (string)gameState.WaitForController.Value, game, true); gameState.WaitForController = null; } } }
public void Handle(string logLine, IHsGameState gameState, IGame game) { if (logLine.Contains("CREATE_GAME")) { gameState.GameHandler.HandleGameStart(); gameState.GameEnded = false; gameState.AddToTurn = -1; gameState.GameLoaded = true; gameState.LastGameStart = DateTime.Now; } else if (GameEntityRegex.IsMatch(logLine)) { gameState.GameHandler.HandleGameStart(); gameState.GameEnded = false; gameState.AddToTurn = -1; var match = GameEntityRegex.Match(logLine); var id = int.Parse(match.Groups["id"].Value); if (!game.Entities.ContainsKey(id)) { game.Entities.Add(id, new Entity(id)); } gameState.CurrentEntityId = id; } else if (PlayerEntityRegex.IsMatch(logLine)) { var match = PlayerEntityRegex.Match(logLine); var id = int.Parse(match.Groups["id"].Value); if (!game.Entities.ContainsKey(id)) { game.Entities.Add(id, new Entity(id)); } gameState.CurrentEntityId = id; } else if (TagChangeRegex.IsMatch(logLine)) { var match = TagChangeRegex.Match(logLine); var rawEntity = match.Groups["entity"].Value.Replace("UNKNOWN ENTITY ", ""); int entityId; if (rawEntity.StartsWith("[") && EntityRegex.IsMatch(rawEntity)) { var entity = EntityRegex.Match(rawEntity); var id = int.Parse(entity.Groups["id"].Value); _tagChangeHandler.TagChange(gameState, match.Groups["tag"].Value, id, match.Groups["value"].Value, game); } else if (int.TryParse(rawEntity, out entityId)) { _tagChangeHandler.TagChange(gameState, match.Groups["tag"].Value, entityId, match.Groups["value"].Value, game); } else { var entity = game.Entities.FirstOrDefault(x => x.Value.Name == rawEntity); if (entity.Value == null) { entity = game.Entities.FirstOrDefault(x => x.Value.Name == "UNKNOWN HUMAN PLAYER"); if (entity.Value != null) { entity.Value.Name = rawEntity; } } if (entity.Value == null) { //while the id is unknown, store in tmp entities var tmpEntity = _tmpEntities.FirstOrDefault(x => x.Name == rawEntity); if (tmpEntity == null) { tmpEntity = new Entity(_tmpEntities.Count + 1) { Name = rawEntity }; _tmpEntities.Add(tmpEntity); } GAME_TAG tag; Enum.TryParse(match.Groups["tag"].Value, out tag); var value = LogReaderHelper.ParseTagValue(tag, match.Groups["value"].Value); tmpEntity.SetTag(tag, value); if (tmpEntity.HasTag(GAME_TAG.ENTITY_ID)) { var id = tmpEntity.GetTag(GAME_TAG.ENTITY_ID); if (game.Entities.ContainsKey(id)) { game.Entities[id].Name = tmpEntity.Name; foreach (var t in tmpEntity.Tags) { game.Entities[id].SetTag(t.Key, t.Value); } _tmpEntities.Remove(tmpEntity); //Logger.WriteLine("COPIED TMP ENTITY (" + rawEntity + ")"); } else { Logger.WriteLine("TMP ENTITY (" + rawEntity + ") NOW HAS A KEY, BUT GAME.ENTITIES DOES NOT CONTAIN THIS KEY", "LogReader"); } } } else { _tagChangeHandler.TagChange(gameState, match.Groups["tag"].Value, entity.Key, match.Groups["value"].Value, game); } } if (EntityNameRegex.IsMatch(logLine)) { match = EntityNameRegex.Match(logLine); var name = match.Groups["name"].Value; var player = int.Parse(match.Groups["value"].Value); if (player == game.Player.Id) { game.Player.Name = name; } else if (player == game.Opponent.Id) { game.Opponent.Name = name; } } } else if (CreationRegex.IsMatch(logLine)) { var match = CreationRegex.Match(logLine); var id = int.Parse(match.Groups["id"].Value); var cardId = match.Groups["cardId"].Value; if (!game.Entities.ContainsKey(id)) { if (string.IsNullOrEmpty(cardId)) { if (gameState.KnownCardIds.TryGetValue(id, out cardId)) { Logger.WriteLine($"Found known cardId for entity {id}: {cardId}"); gameState.KnownCardIds.Remove(id); } } game.Entities.Add(id, new Entity(id) { CardId = cardId }); } gameState.CurrentEntityId = id; gameState.CurrentEntityHasCardId = !string.IsNullOrEmpty(cardId); } else if (UpdatingEntityRegex.IsMatch(logLine)) { var match = UpdatingEntityRegex.Match(logLine); var cardId = match.Groups["cardId"].Value; var rawEntity = match.Groups["entity"].Value; int entityId; if (rawEntity.StartsWith("[") && EntityRegex.IsMatch(rawEntity)) { var entity = EntityRegex.Match(rawEntity); entityId = int.Parse(entity.Groups["id"].Value); } else if (!int.TryParse(rawEntity, out entityId)) { entityId = -1; } if (entityId != -1) { gameState.CurrentEntityId = entityId; if (!game.Entities.ContainsKey(entityId)) { game.Entities.Add(entityId, new Entity(entityId)); } game.Entities[entityId].CardId = cardId; } if (gameState.JoustReveals > 0) { Entity currentEntity; if (game.Entities.TryGetValue(entityId, out currentEntity)) { if (currentEntity.IsControlledBy(game.Opponent.Id)) { gameState.GameHandler.HandleOpponentJoust(currentEntity, cardId, gameState.GetTurnNumber()); } else if (currentEntity.IsControlledBy(game.Player.Id)) { gameState.GameHandler.HandlePlayerJoust(currentEntity, cardId, gameState.GetTurnNumber()); } } //gameState.JoustReveals--; } } else if (CreationTagRegex.IsMatch(logLine) && !logLine.Contains("HIDE_ENTITY")) { var match = CreationTagRegex.Match(logLine); _tagChangeHandler.TagChange(gameState, match.Groups["tag"].Value, gameState.CurrentEntityId, match.Groups["value"].Value, game); } else if ((logLine.Contains("Begin Spectating") || logLine.Contains("Start Spectator")) && game.IsInMenu) { gameState.GameHandler.SetGameMode(GameMode.Spectator); } else if (logLine.Contains("End Spectator")) { gameState.GameHandler.SetGameMode(GameMode.Spectator); gameState.GameHandler.HandleGameEnd(); } else if (ActionStartRegex.IsMatch(logLine)) { Entity actionEntity; var playerEntity = game.Entities.FirstOrDefault(e => e.Value.HasTag(GAME_TAG.PLAYER_ID) && e.Value.GetTag(GAME_TAG.PLAYER_ID) == game.Player.Id); var opponentEntity = game.Entities.FirstOrDefault(e => e.Value.HasTag(GAME_TAG.PLAYER_ID) && e.Value.GetTag(GAME_TAG.PLAYER_ID) == game.Opponent.Id); var match = ActionStartRegex.Match(logLine); var actionStartingCardId = match.Groups["cardId"].Value.Trim(); var actionStartingEntityId = int.Parse(match.Groups["id"].Value); if (string.IsNullOrEmpty(actionStartingCardId)) { if (game.Entities.TryGetValue(actionStartingEntityId, out actionEntity)) { actionStartingCardId = actionEntity.CardId; } } if (game.Entities.TryGetValue(actionStartingEntityId, out actionEntity)) { // spell owned by the player if (actionEntity.HasTag(GAME_TAG.CONTROLLER) && actionEntity.GetTag(GAME_TAG.CONTROLLER) == game.Player.Id && actionEntity.GetTag(GAME_TAG.CARDTYPE) == (int)TAG_CARDTYPE.SPELL) { int targetEntityId = actionEntity.GetTag(GAME_TAG.CARD_TARGET); Entity targetEntity; var targetsMinion = game.Entities.TryGetValue(targetEntityId, out targetEntity) && targetEntity.IsMinion; gameState.GameHandler.HandlePlayerSpellPlayed(targetsMinion); } } if (string.IsNullOrEmpty(actionStartingCardId)) { return; } if (match.Groups["type"].Value == "TRIGGER") { switch (actionStartingCardId) { case Collectible.Rogue.TradePrinceGallywix: AddKnownCardId(gameState, game, game.Entities[gameState.LastCardPlayed].CardId); AddKnownCardId(gameState, game, NonCollectible.Neutral.GallywixsCoinToken); break; } } else //POWER { switch (actionStartingCardId) { case Collectible.Rogue.GangUp: AddTargetAsKnownCardId(gameState, game, match, 3); break; case Collectible.Rogue.BeneathTheGrounds: AddKnownCardId(gameState, game, NonCollectible.Rogue.AmbushToken, 3); break; case Collectible.Warrior.IronJuggernaut: AddKnownCardId(gameState, game, NonCollectible.Warrior.BurrowingMineToken); break; case Collectible.Druid.Recycle: AddTargetAsKnownCardId(gameState, game, match); break; case Collectible.Mage.ForgottenTorch: AddKnownCardId(gameState, game, NonCollectible.Mage.RoaringTorchToken); break; case Collectible.Warlock.CurseOfRafaam: AddKnownCardId(gameState, game, NonCollectible.Warlock.CursedToken); break; case Collectible.Neutral.AncientShade: AddKnownCardId(gameState, game, NonCollectible.Neutral.AncientCurseToken); break; case Collectible.Priest.ExcavatedEvil: AddKnownCardId(gameState, game, Collectible.Priest.ExcavatedEvil); break; case Collectible.Neutral.EliseStarseeker: AddKnownCardId(gameState, game, NonCollectible.Neutral.MapToTheGoldenMonkeyToken); break; case NonCollectible.Neutral.MapToTheGoldenMonkeyToken: AddKnownCardId(gameState, game, NonCollectible.Neutral.GoldenMonkeyToken); break; default: if (playerEntity.Value != null && playerEntity.Value.GetTag(GAME_TAG.CURRENT_PLAYER) == 1 && !gameState.PlayerUsedHeroPower || opponentEntity.Value != null && opponentEntity.Value.GetTag(GAME_TAG.CURRENT_PLAYER) == 1 && !gameState.OpponentUsedHeroPower) { var card = Database.GetCardFromId(actionStartingCardId); if (card.Type == "Hero Power") { if (playerEntity.Value != null && playerEntity.Value.GetTag(GAME_TAG.CURRENT_PLAYER) == 1) { gameState.GameHandler.HandlePlayerHeroPower(actionStartingCardId, gameState.GetTurnNumber()); gameState.PlayerUsedHeroPower = true; } else if (opponentEntity.Value != null) { gameState.GameHandler.HandleOpponentHeroPower(actionStartingCardId, gameState.GetTurnNumber()); gameState.OpponentUsedHeroPower = true; } } } break; } } } else if (logLine.Contains("BlockType=JOUST")) { gameState.JoustReveals = 2; } }
public void TagChange(IHsGameState gameState, string rawTag, int id, string rawValue, IGame game, bool isRecursive = false) { if (gameState.LastId != id) { //game.SecondToLastUsedId = gameState.LastId; if (gameState.ProposedKeyPoint != null) { ReplayMaker.Generate(gameState.ProposedKeyPoint.Type, gameState.ProposedKeyPoint.Id, gameState.ProposedKeyPoint.Player, game); gameState.ProposedKeyPoint = null; } } gameState.LastId = id; if (id > gameState.MaxId) { gameState.MaxId = id; } if (!game.Entities.ContainsKey(id)) { game.Entities.Add(id, new Entity(id)); } GAME_TAG tag; if (!Enum.TryParse(rawTag, out tag)) { int tmp; if (int.TryParse(rawTag, out tmp) && Enum.IsDefined(typeof(GAME_TAG), tmp)) { tag = (GAME_TAG)tmp; } } var value = LogReaderHelper.ParseTagValue(tag, rawValue); var prevValue = game.Entities[id].GetTag(tag); game.Entities[id].SetTag(tag, value); if (tag == CONTROLLER && gameState.WaitForController != null && game.Player.Id == -1) { DeterminePlayers(gameState, game, value); } var controller = game.Entities[id].GetTag(CONTROLLER); var cardId = game.Entities[id].CardId; switch (tag) { case ZONE: if (((TAG_ZONE)value == HAND || ((TAG_ZONE)value == PLAY || (TAG_ZONE)value == DECK) && game.IsMulliganDone) && gameState.WaitForController == null) { if (!game.IsMulliganDone) { prevValue = (int)DECK; } if (controller == 0) { game.Entities[id].SetTag(ZONE, prevValue); gameState.WaitForController = new { Tag = rawTag, Id = id, Value = rawValue }; return; } } ZoneChange(gameState, id, game, value, prevValue, controller, cardId); break; case PLAYSTATE: PlaystateChange(gameState, id, game, value); break; case CARDTYPE: CardTypeChange(gameState, id, game, value); break; case CURRENT_PLAYER: CurrentPlayerChange(gameState, id, game, value); break; case LAST_CARD_PLAYED: LastCardPlayedChange(gameState, value); break; case DEFENDING: DefendingChange(gameState, id, game, controller, value); break; case ATTACKING: AttackingChange(gameState, id, game, controller, value); break; case PROPOSED_DEFENDER: ProposedDefenderChange(game, value); break; case PROPOSED_ATTACKER: ProposedAttackerChange(game, value); break; case NUM_MINIONS_PLAYED_THIS_TURN: NumMinionsPlayedThisTurnChange(gameState, value); break; case PREDAMAGE: PredamageChange(gameState, id, game, value); break; case NUM_TURNS_IN_PLAY: NumTurnsInPlayChange(gameState, id, game, value); break; case NUM_ATTACKS_THIS_TURN: NumAttacksThisTurnChange(gameState, id, game, value, controller); break; case ZONE_POSITION: ZonePositionChange(gameState, id, game, controller); break; case CARD_TARGET: CardTargetChange(gameState, id, game, value, controller); break; case EQUIPPED_WEAPON: EquippedWeaponChange(gameState, id, game, value, controller); break; case EXHAUSTED: ExhaustedChange(gameState, id, game, value, controller); break; case CONTROLLER: ControllerChange(gameState, id, game, prevValue, value, cardId); break; case FATIGUE: FatigueChange(gameState, rawValue, game, controller); break; } if (gameState.WaitForController != null && !isRecursive) { TagChange(gameState, (string)gameState.WaitForController.Tag, (int)gameState.WaitForController.Id, (string)gameState.WaitForController.Value, game, true); gameState.WaitForController = null; } }