Example #1
0
 private void ProcessGameEntity(Entity entity)
 {
     foreach (var tag in entity.Tags)
     {
         GameTag gameTag = GameTagConverter.ParseEnum <GameTag>(tag.EnumId.ToString());
         if (gameTag == GameTag.TURN)
         {
             int value = tag.Value;
             Turns = value;
         }
     }
 }
Example #2
0
        private void ProcessUserEntity(Entity entity)
        {
            User.EntityId = entity.EntityId;
            User.Name     = entity.Name;

            foreach (var tag in entity.Tags)
            {
                GameTag gameTag = GameTagConverter.ParseEnum <GameTag>(tag.EnumId.ToString());

                switch (gameTag)
                {
                case GameTag.PLAYSTATE:
                    string value = Enum.GetName(typeof(PlayState), tag.Value);
                    User.Result = value;
                    break;

                case GameTag.NUM_RESOURCES_SPENT_THIS_GAME:
                    int mana = tag.Value;
                    User.ManaUsedThisGame = mana;
                    break;

                case GameTag.NUM_FRIENDLY_MINIONS_THAT_DIED_THIS_GAME:
                    int died = tag.Value;
                    User.MinionsDiedThisGame = died;
                    break;

                case GameTag.NUM_TIMES_HERO_POWER_USED_THIS_GAME:
                    int hero = tag.Value;
                    User.NumberOfHeroPowerUsesThisGame = hero;
                    break;

                case GameTag.FIRST_PLAYER:
                    User.Coin     = false;
                    Opponent.Coin = true;
                    break;
                }
            }
        }
Example #3
0
        public static void ImportDecksFromHearthstone()
        {
            var decks = HearthMirror.Reflection.GetDecks();
            List <HearthDb.Deckstrings.Deck> convertedDecks = new List <Deck>();
            int success   = 0;
            int attempted = 0;

            if (decks != null)
            {
                foreach (var deck in decks)
                {
                    if (CurrentDecks.All(x => x.Name != deck.Name))
                    {
                        if (deck.Cards.Count > 0)
                        {
                            HearthDb.Deckstrings.Deck convertedDeck = new Deck
                            {
                                Name      = deck.Name,
                                Format    = GameTagConverter.ParseEnum <FormatType>(deck.Type.ToString()),
                                HeroDbfId = Cards.GetCardFromId(deck.Hero).DbfId
                            };
                            foreach (var card in deck.Cards)
                            {
                                convertedDeck.CardDbfIds.Add(Cards.GetCardFromId(card.Id).DbfId, card.Count);
                            }

                            Log.Info($"Imported deck '{deck.Name}' from Hearthstone Application");
                            success += 1;
                            convertedDecks.Add(convertedDeck);
                        }
                        else
                        {
                            attempted += 1;
                            Log.Error($"Unable to import deck '{deck.Name}' due to cards not being loaded in memory.");
                        }
                    }
                }

                CurrentDecks.AddRange(convertedDecks);

                if (success == 0)
                {
                    MessageBox.Show(
                        $"Unable to import decks from Hearthstone, ensure that you have opened the decks in-game before you attempt to import.",
                        "Unable to import decks", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else if (success > 0 && attempted > 0)
                {
                    MessageBox.Show(
                        $"{convertedDecks.Count} Decks have been successfully imported from the Hearthstone Application, however {attempted} decks were unable to be imported due to issues finding card information in memory.",
                        "Success with warning.", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else if (success > 0)
                {
                    MessageBox.Show(
                        $"{convertedDecks.Count} Decks have been successfully imported from the Hearthstone Application.",
                        "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            else
            {
                MessageBox.Show("You must have Hearthstone running in order to import the decks from your collection",
                                "Hearthstone Not Running", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #4
0
        public void Handle(LogEntry entry)
        {
            if (LogEntryRegex.GameEntityRegex.IsMatch(entry.Line))
            {
                Match match = LogEntryRegex.GameEntityRegex.Match(entry.Line);
                int   id    = int.Parse(match.Groups["id"].Value);
                if (!CheckIfEntityExists(id))
                {
                    CreateEntity(id, "GameEntity");
                }
                Database.CurrentGame.CurrentEntityId = id;
            }
            else if (LogEntryRegex.PlayerEntityRegex.IsMatch(entry.Line))
            {
                Match match = LogEntryRegex.PlayerEntityRegex.Match(entry.Line);
                int   id    = int.Parse(match.Groups["id"].Value);
                if (!CheckIfEntityExists(id))
                {
                    CreateEntity(id);
                }
                Database.CurrentGame.CurrentEntityId = id;
            }
            else if (LogEntryRegex.TagChangeRegex.IsMatch(entry.Line))
            {
                Match   match       = LogEntryRegex.TagChangeRegex.Match(entry.Line);
                string  entityValue = match.Groups["entity"].Value;
                GameTag tag         = GameTagConverter.ParseEnum <GameTag>(match.Groups["tag"].Value);
                int     value       = GameTagConverter.ParseTag(tag, match.Groups["value"].Value);
                if (entityValue.StartsWith("[") && LogEntryRegex.EntityRegex.IsMatch(entityValue))                 //Find the ID in the nested entity.
                {
                    //[entityName=UNKNOWN ENTITY [cardType=INVALID] id=30 zone=DECK zonePos=0 cardId= player=1]
                    Match nestedEntity = LogEntryRegex.EntityRegex.Match(entityValue);
                    int   entityId     = int.Parse(nestedEntity.Groups["id"].Value);

                    if (!CheckIfEntityExists(entityId))
                    {
                        CreateEntity(entityId);
                    }

                    UpdateEntity(entityId, tag, value);
                }
                else if (int.TryParse(entityValue, out int entityId))                 //Try and find the ID.
                {
                    if (!CheckIfEntityExists(entityId))
                    {
                        CreateEntity(entityId);
                    }

                    UpdateEntity(entityId, tag, value);
                }
                else                 //This is if we dont have the ID of the entity.
                {
                    Entity entity = Database.CurrentGame.Entities.FirstOrDefault(x => x.Value.Name == entityValue).Value;

                    if (entity == null)
                    {
                        var unnamedPlayers = Database.CurrentGame.Entities
                                             .Where(x => x.Value.Tags.Any(y => y.EnumId == (int)GameTag.PLAYER_ID) &&
                                                    string.IsNullOrWhiteSpace(x.Value.Name)).ToList();
                        Entity tempEntity;

                        if (!CheckIfTempEntityExists(entityValue))
                        {
                            tempEntity = CreateTempEntity(entityValue);
                        }
                        else
                        {
                            tempEntity = _tempEntities.First(x => x.Name == entityValue);
                        }

                        if (unnamedPlayers.Count == 1)
                        {
                            entity = unnamedPlayers.Single().Value;
                        }
                        else if (unnamedPlayers.Count == 2 && tag == GameTag.CURRENT_PLAYER && value == 0)
                        {
                            entity = Database.CurrentGame.Entities
                                     .FirstOrDefault(x => x.Value.Tags.Any(y => y.EnumId == (int)GameTag.CURRENT_PLAYER)).Value;
                        }
                        if (entity != null)
                        {
                            entity.Name = tempEntity.Name;
                            entity.Tags = tempEntity.Tags;
                            _tempEntities.Remove(tempEntity);
                            UpdateEntity(entity.EntityId, tag, value);
                        }
                        if (_tempEntities.Contains(tempEntity))
                        {
                            tempEntity.Tags.Add(new Tag {
                                EnumId = (int)tag, Value = value
                            });
                            Player player = null;
                            if (tempEntity.Name == Database.CurrentGame.User.Name)
                            {
                                player = Database.CurrentGame.User;
                            }
                            else if (tempEntity.Name == Database.CurrentGame.Opponent.Name)
                            {
                                player = Database.CurrentGame.Opponent;
                            }
                            if (player != null)
                            {
                                Entity playerEntity = Database.CurrentGame.Entities
                                                      .FirstOrDefault(x => x.Value.Tags.Any(y => y.EnumId == (int)GameTag.PLAYER_ID)).Value;
                                if (playerEntity != null)
                                {
                                    playerEntity.Name = tempEntity.Name;
                                    playerEntity.Tags = tempEntity.Tags;
                                    _tempEntities.Remove(tempEntity);
                                }
                            }
                        }
                    }
                    else
                    {
                        UpdateEntity(entity.EntityId, tag, value);
                    }
                }
            }
            else if (LogEntryRegex.CreationRegexUpdating.IsMatch(entry.Line))
            {
                Match  match  = LogEntryRegex.CreationRegexUpdating.Match(entry.Line);
                int    id     = int.Parse(match.Groups[2].Value);
                string cardId = match.Groups[5].Value;
                Zone   zone   = GameTagConverter.ParseEnum <Zone>(match.Groups["zone"].Value);

                if (!CheckIfEntityExists(id))
                {
                    Database.CurrentGame.Entities.Add(id, new Entity {
                        EntityId = id, CardId = cardId
                    });
                }
                else
                {
                    Database.CurrentGame.Entities[id].CardId = cardId;
                }

                Database.CurrentGame.CurrentEntityId = id;
            }
            else if (LogEntryRegex.UpdatingEntityRegex.IsMatch(entry.Line))
            {
                Match  match  = LogEntryRegex.UpdatingEntityRegex.Match(entry.Line);
                string cardId = match.Groups["cardId"].Value;
                string entity = match.Groups["entity"].Value;
                string type   = match.Groups["type"].Value;
                int    entityId;

                if (entity.StartsWith("[") && LogEntryRegex.EntityRegex.IsMatch(entity))
                {
                    Match nestedMatch = LogEntryRegex.EntityRegex.Match(entry.Line);
                    entityId = int.Parse(nestedMatch.Groups["id"].Value);
                }
                else if (!int.TryParse(entity, out entityId))
                {
                    entityId = -1;
                }

                if (entityId != -1)
                {
                    if (!CheckIfEntityExists(entityId))
                    {
                        CreateEntity(entityId);
                    }
                    if (type != "CHANGE_ENTITY" || string.IsNullOrWhiteSpace(Database.CurrentGame.Entities[entityId].CardId))                 //If the cardId has been revealed to us!
                    {
                        Database.CurrentGame.Entities[entityId].CardId = cardId;
                    }

                    Database.CurrentGame.CurrentEntityId = entityId;
                }
            }
            else if (LogEntryRegex.CreationTagRegex.IsMatch(entry.Line) && !entry.Line.Contains("HIDE_ENTITY"))
            {
                Match   match = LogEntryRegex.CreationTagRegex.Match(entry.Line);
                GameTag tag   = GameTagConverter.ParseEnum <GameTag>(match.Groups["tag"].Value);
                int     value = GameTagConverter.ParseTag(tag, match.Groups["value"].Value);

                //D 12:05:41.2181993 GameState.DebugPrintPower() -         tag=CARDTYPE value=GAME

                UpdateEntity(Database.CurrentGame.CurrentEntityId, tag, value);
                //TagChangeActions.TagChange(Database.CurrentGame.CurrentEntityId, tag, value);
            }
            else if (LogEntryRegex.CreationRegexCreating.IsMatch(entry.Line))
            {
                Match  match  = LogEntryRegex.CreationRegexCreating.Match(entry.Line);
                int    id     = int.Parse(match.Groups[1].Value);
                string cardId = match.Groups[2].Value;

                if (!CheckIfEntityExists(id))
                {
                    CreateCardEntity(id, cardId);
                }

                Database.CurrentGame.CurrentEntityId = id;
            }

            if (Database.CurrentGame.Info == null)
            {
                Database.CurrentGame.Info = HearthMirror.Reflection.GetMatchInfo();
            }
        }