Example #1
0
        public override UpdateResult Update()
        {
            if (_dataProvider.InAdventureScreen)
            {
                var dungeonInfo = _dataProvider.GetDungeonInfo();
                if (dungeonInfo != null)
                {
                    for (var i = 0; i < dungeonInfo.Length; i++)
                    {
                        if (dungeonInfo[i]?.RunActive ?? false)
                        {
                            if ((_prevCards[i] == null || !dungeonInfo[i].DbfIds.SequenceEqual(_prevCards[i])) &&
                                (_prevLootChoice[i] != dungeonInfo[i].PlayerChosenLoot ||
                                 _prevTreasureChoice[i] != dungeonInfo[i].PlayerChosenTreasure))
                            {
                                _prevCards[i]          = dungeonInfo[i].DbfIds.ToList();
                                _prevLootChoice[i]     = dungeonInfo[i].PlayerChosenLoot;
                                _prevTreasureChoice[i] = dungeonInfo[i].PlayerChosenTreasure;
                                DungeonRunDeckUpdated?.Invoke(new DungeonRunDeckUpdatedEventArgs(BuildDeck(dungeonInfo[i])));
                            }
                        }
                        else
                        {
                            _prevCards[i] = null;
                        }
                    }

                    if (_prevLootChoice.All(x => x > 0))
                    {
                        return(UpdateResult.Break);
                    }
                }
                else
                {
                    _prevCards = new List <int>[] { null, null }
                };
            }
            else if (_dataProvider.InAiMatch && !string.IsNullOrEmpty(_dataProvider.OpponentHeroId))
            {
                if (Cards.All.TryGetValue(_dataProvider.OpponentHeroId, out var card))
                {
                    if (DungeonRun.IsDungeonBoss(card))
                    {
                        var newRun = _initialOpponents.Contains(_dataProvider.OpponentHeroId);
                        var deck   = newRun ? DungeonRun.GetDefaultDeck(_dataProvider.LocalPlayerClass, card.Set) : null;
                        DungeonRunMatchStarted?.Invoke(new DungeonRunMatchStartedEventArgs(newRun, deck));
                        return(UpdateResult.Break);
                    }
                }
            }

            return(UpdateResult.Continue);
        }
Example #2
0
        private static Deck CreateDungeonDeck(string playerClass)
        {
            Log.Info($"Creating new {playerClass} dungeon run deck");
            var deck = DungeonRun.GetDefaultDeck(playerClass);

            if (deck == null)
            {
                Log.Info($"Could not find default deck for {playerClass}");
                return(null);
            }
            DeckList.Instance.Decks.Add(deck);
            DeckList.Save();
            Core.MainWindow.DeckPickerList.UpdateDecks();
            Core.MainWindow.SelectDeck(deck, true);
            return(deck);
        }
Example #3
0
        private static Deck CreateDungeonDeck(string playerClass, CardSet set)
        {
            var shrine = Core.Game.Player.Board.FirstOrDefault(x => x.HasTag(GameTag.SHRINE))?.CardId;

            Log.Info($"Creating new {playerClass} dungeon run deck (CardSet={set}, Shrine={shrine})");
            var deck = DungeonRun.GetDefaultDeck(playerClass, set, shrine);

            if (deck == null)
            {
                Log.Info($"Could not find default deck for {playerClass} in card set {set} with Shrine={shrine}");
                return(null);
            }
            DeckList.Instance.Decks.Add(deck);
            DeckList.Save();
            Core.MainWindow.DeckPickerList.UpdateDecks();
            Core.MainWindow.SelectDeck(deck, true);
            return(deck);
        }
        private static Deck CreateDungeonDeck(string playerClass, CardSet set, bool isPVPDR, List <int> selectedDeck = null, Card loadout = null)
        {
            var shrine = Core.Game.Player.Board.FirstOrDefault(x => x.HasTag(GameTag.SHRINE))?.CardId;

            Log.Info($"Creating new {playerClass} dungeon run deck (CardSet={set}, Shrine={shrine}, SelectedDeck={selectedDeck != null})");
            var deck = selectedDeck == null
                                ? DungeonRun.GetDefaultDeck(playerClass, set, shrine)
                                : DungeonRun.GetDeckFromDbfIds(playerClass, set, isPVPDR, selectedDeck);

            if (deck == null)
            {
                Log.Info($"Could not find default deck for {playerClass} in card set {set} with Shrine={shrine}");
                return(null);
            }
            if (loadout != null && selectedDeck != null && !selectedDeck.Contains(loadout.DbfIf))
            {
                deck.Cards.Add(loadout);
            }
            DeckList.Instance.Decks.Add(deck);
            DeckList.Save();
            Core.MainWindow.DeckPickerList.UpdateDecks();
            Core.MainWindow.SelectDeck(deck, true);
            return(deck);
        }
        public static void UpdateDungeonRunDeck(DungeonInfo info, bool isPVPDR)
        {
            if (!Config.Instance.DungeonAutoImport)
            {
                return;
            }

            var isNewPVPDR = isPVPDR && !info.RunActive && info.SelectedLoadoutTreasureDbId > 0;

            Log.Info($"Found dungeon run deck Set={(CardSet)info.CardSet}, PVPDR={isPVPDR} (new={isNewPVPDR})");

            var allCards = info.DbfIds?.ToList() ?? new List <int>();

            // New PVPDR runs have all non-loadout cards in the DbfIds. We still add the picked loadout below.
            // So we don't want to replace allCards with baseDeck, as backDeck is empty, and we don't want to add
            // any loot or treasure, as these will be the ones from a previous run, if they exist.
            if (!isNewPVPDR)
            {
                var baseDeck = info.SelectedDeck ?? new List <int>();
                if (baseDeck.All(x => allCards.Contains(x)))
                {
                    if (info.PlayerChosenLoot > 0)
                    {
                        var loot   = new[] { info.LootA, info.LootB, info.LootC };
                        var chosen = loot[info.PlayerChosenLoot - 1];
                        for (var i = 1; i < chosen.Count; i++)
                        {
                            allCards.Add(chosen[i]);
                        }
                    }
                    if (info.PlayerChosenTreasure > 0)
                    {
                        allCards.Add(info.Treasure[info.PlayerChosenTreasure - 1]);
                    }
                }
                else
                {
                    allCards = baseDeck;
                }
            }

            var cards = allCards.GroupBy(x => x).Select(x =>
            {
                var card = Database.GetCardFromDbfId(x.Key, false);
                if (card == null)
                {
                    return(null);
                }
                card.Count = x.Count();
                return(card);
            }).Where(x => x != null).ToList();

            var loadoutCardId = info.LoadoutCardId;
            var loadout       = loadoutCardId != null?Database.GetCardFromId(loadoutCardId) : null;

            if (loadout != null && !allCards.Contains(loadout.DbfIf))
            {
                cards.Add(loadout);
            }

            if (!Config.Instance.DungeonRunIncludePassiveCards)
            {
                cards.RemoveAll(c => !c.Collectible && c.HideStats);
            }

            var cardSet = (CardSet)info.CardSet;

            string playerClass = null;

            if (cardSet == CardSet.ULDUM && loadout != null)
            {
                playerClass = DungeonRun.GetUldumHeroPlayerClass(loadout.PlayerClass);
            }
            else if (isPVPDR)
            {
                playerClass = HearthDbConverter.ConvertClass((CardClass)(info.HeroClass != 0 ? info.HeroClass : info.HeroCardClass));
            }
            else
            {
                if (allCards.Count == 10)
                {
                    playerClass = allCards.Select(x => Database.GetCardFromDbfId(x).PlayerClass).FirstOrDefault(x => x != null)?.ToUpperInvariant();
                }
                if (playerClass == null)
                {
                    playerClass = ((CardClass)info.HeroCardClass).ToString().ToUpperInvariant();
                }
            }

            var deck = DeckList.Instance.Decks.FirstOrDefault(x => (!isPVPDR && x.IsDungeonDeck || isPVPDR && x.IsDuelsDeck) && x.Class.ToUpperInvariant() == playerClass.ToUpperInvariant() &&
                                                              x.Cards.All(e => cards.Any(c => c.Id == e.Id && c.Count >= e.Count)) &&
                                                              !(x.IsDungeonRunCompleted ?? false) &&
                                                              !(x.IsDuelsRunCompleted ?? false));
            var baseDbfids = isPVPDR ? info.DbfIds : info.SelectedDeck;

            if (deck == null && (deck = CreateDungeonDeck(playerClass, cardSet, isPVPDR, baseDbfids, loadout)) == null)
            {
                Log.Info($"No existing deck - can't find default deck for {playerClass}");
                return;
            }
            if (!info.RunActive && (cardSet == CardSet.ULDUM || cardSet == CardSet.DALARAN))
            {
                Log.Info($"Inactive run for Set={cardSet.ToString()} - this is a new run");
                return;
            }
            if (cards.All(c => deck.Cards.Any(e => c.Id == e.Id && c.Count == e.Count)))
            {
                Log.Info("No new cards");
                return;
            }
            deck.Cards.Clear();
            Helper.SortCardCollection(cards, false);
            foreach (var card in cards)
            {
                deck.Cards.Add(card);
            }
            deck.LastEdited = DateTime.Now;
            DeckList.Save();
            Core.UpdatePlayerCards(true);
            Log.Info("Updated dungeon run deck");
        }
        public static void DungeonRunMatchStarted(bool newRun, CardSet set, bool isPVPDR, bool recursive = false)
        {
            if (!Config.Instance.DungeonAutoImport)
            {
                return;
            }
            Log.Info($"Dungeon run detected! New={newRun}, Recursive={recursive}");
            var boardHero = Core.Game.Player.Board.FirstOrDefault(x => x.IsHero)?.Card;

            if (boardHero == null)
            {
                return;
            }
            var playerClass = set == CardSet.ULDUM
                                ? DungeonRun.GetUldumHeroPlayerClass(boardHero.PlayerClass)
                                : boardHero.PlayerClass;

            if (playerClass == null)
            {
                return;
            }
            var revealed     = RevealedEntites;
            var existingDeck = DeckList.Instance.Decks
                               .Where(x => (isPVPDR && x.IsDuelsDeck || !isPVPDR && x.IsDungeonDeck) && x.Class == playerClass &&
                                      !((x.IsDungeonRunCompleted ?? false) || (x.IsDuelsRunCompleted ?? false)) &&
                                      (!newRun || x.Cards.Count == 10 || x.Cards.Count == 11) &&
                                      GetMissingCards(revealed, x).Count == 0)
                               .OrderByDescending(x => x.LastEdited).FirstOrDefault();

            if (existingDeck == null)
            {
                if (newRun)
                {
                    var hero = Core.Game.Opponent.PlayerEntities.FirstOrDefault(x => x.IsHero)?.CardId;
                    if (set == CardSet.DALARAN || set == CardSet.ULDUM)
                    {
                        Watchers.DungeonRunWatcher.UpdateDungeonInfo();
                        if (!recursive)
                        {
                            DungeonRunMatchStarted(newRun, set, isPVPDR, true);
                            return;
                        }
                    }
                    else
                    {
                        CreateDungeonDeck(playerClass, set, isPVPDR);
                    }
                }
                else
                {
                    Log.Info("We don't have an existing deck for this run, but it's not a new run");
                    if (DeckList.Instance.ActiveDeck != null)
                    {
                        Log.Info("Switching to no deck mode");
                        Core.MainWindow.SelectDeck(null, true);
                    }
                }
            }
            else if (!existingDeck.Equals(DeckList.Instance.ActiveDeck))
            {
                Log.Info($"Selecting existing deck: {existingDeck.Name}");
                Core.MainWindow.SelectDeck(existingDeck, true);
            }
        }
Example #7
0
        public static void UpdateDungeonRunDeck(DungeonInfo info)
        {
            if (!Config.Instance.DungeonAutoImport)
            {
                return;
            }
            Log.Info($"Found dungeon run deck Set={((CardSet)info.CardSet).ToString()}");
            var baseDeck = info.SelectedDeck ?? new List <int>();
            var allCards = info.DbfIds?.ToList() ?? new List <int>();

            if (baseDeck.All(x => allCards.Contains(x)))
            {
                if (info.PlayerChosenLoot > 0)
                {
                    var loot   = new[] { info.LootA, info.LootB, info.LootC };
                    var chosen = loot[info.PlayerChosenLoot - 1];
                    for (var i = 1; i < chosen.Count; i++)
                    {
                        allCards.Add(chosen[i]);
                    }
                }
                if (info.PlayerChosenTreasure > 0)
                {
                    allCards.Add(info.Treasure[info.PlayerChosenTreasure - 1]);
                }
            }
            else
            {
                allCards = baseDeck;
            }
            var cards = allCards.GroupBy(x => x).Select(x =>
            {
                var card = Database.GetCardFromDbfId(x.Key, false);
                if (card == null)
                {
                    return(null);
                }
                card.Count = x.Count();
                return(card);
            }).Where(x => x != null).ToList();

            var loadoutCardId = info.LoadoutCardId;
            var loadout       = loadoutCardId != null?Database.GetCardFromId(loadoutCardId) : null;

            if (loadout != null && !allCards.Contains(loadout.DbfIf))
            {
                cards.Add(loadout);
            }

            if (!Config.Instance.DungeonRunIncludePassiveCards)
            {
                cards.RemoveAll(c => !c.Collectible && c.HideStats);
            }

            var cardSet = (CardSet)info.CardSet;

            string playerClass = null;

            if (cardSet == CardSet.ULDUM && loadout != null)
            {
                playerClass = DungeonRun.GetUldumHeroPlayerClass(loadout.PlayerClass);
            }
            else
            {
                if (allCards.Count == 10)
                {
                    playerClass = allCards.Select(x => Database.GetCardFromDbfId(x).PlayerClass).FirstOrDefault(x => x != null)?.ToUpperInvariant();
                }
                if (playerClass == null)
                {
                    playerClass = ((CardClass)info.HeroCardClass).ToString().ToUpperInvariant();
                }
            }

            var deck = DeckList.Instance.Decks.FirstOrDefault(x => x.IsDungeonDeck && x.Class.ToUpperInvariant() == playerClass.ToUpperInvariant() &&
                                                              !(x.IsDungeonRunCompleted ?? false) &&
                                                              x.Cards.All(e => cards.Any(c => c.Id == e.Id && c.Count >= e.Count)));

            if (deck == null && (deck = CreateDungeonDeck(playerClass, cardSet, info.SelectedDeck, loadout)) == null)
            {
                Log.Info($"No existing deck - can't find default deck for {playerClass}");
                return;
            }
            if (!info.RunActive && (cardSet == CardSet.ULDUM || cardSet == CardSet.DALARAN))
            {
                Log.Info($"Inactive run for Set={cardSet.ToString()} - this is a new run");
                return;
            }
            if (cards.All(c => deck.Cards.Any(e => c.Id == e.Id && c.Count == e.Count)))
            {
                Log.Info("No new cards");
                return;
            }
            deck.Cards.Clear();
            Helper.SortCardCollection(cards, false);
            foreach (var card in cards)
            {
                deck.Cards.Add(card);
            }
            deck.LastEdited = DateTime.Now;
            DeckList.Save();
            Core.UpdatePlayerCards(true);
            Log.Info("Updated dungeon run deck");
        }