Example #1
0
        /// <summary>
        ///     Loot all the items stored on page X, and store them to the local database
        /// </summary>
        /// <param name="filename"></param>
        private string EmptyPageX(string filename)
        {
            Logger.InfoFormat("Looting {0}", filename);

            var pCrypto = new GDCryptoDataBuffer(DataBuffer.ReadBytesFromDisk(filename));
            var stash   = new Stash();

            if (stash.Read(pCrypto))
            {
                var lootFromIndex = GetStashToLootFrom(stash);
                var isHardcore    = GlobalPaths.IsHardcore(filename);

#if DEBUG
                if (stash.Tabs.Count < 5)
                {
                    while (stash.Tabs.Count < 5)
                    {
                        stash.Tabs.Add(new StashTab());
                    }

                    SafelyWriteStash(filename, stash);
                    Logger.Info("Upgraded stash to 5 pages.");

                    return(string.Empty);
                }
#endif

                // Update the internal listing of unlooted items (in other stash tabs)
                var unlootedLocal = new List <Item>();

                for (var idx = 0; idx < stash.Tabs.Count; idx++)
                {
                    if (idx != lootFromIndex)
                    {
                        unlootedLocal.AddRange(stash.Tabs[idx].Items);
                    }
                }

                Interlocked.Exchange(ref _unlootedItems, new ConcurrentBag <Item>(unlootedLocal));
                StashUpdated?.Invoke(null, null);

                if (stash.Tabs.Count < 2)
                {
                    Logger.WarnFormat($"File \"{filename}\" only contains {stash.Tabs.Count} pages. IA requires at least 2 stash pages to function properly.");
                    return(GlobalSettings.Language.GetTag("iatag_not_enough_stash", filename, stash.Tabs.Count));
                }

                if (stash.Tabs.Count < lootFromIndex + 1)
                {
                    Logger.Warn($"You have configured IA to loot from stash {lootFromIndex + 1} but you only have {stash.Tabs.Count} pages");
                    return(GlobalSettings.Language.GetTag("iatag_invalid_loot_stash_number", lootFromIndex + 1, stash.Tabs.Count));
                }

                if (stash.Tabs[lootFromIndex].Items.Count > 0)
                {
                    _hasLootedItemsOnceThisSession = true;

                    // Grab the items and clear the tab
                    var items = stash.Tabs[lootFromIndex].Items
                                .Where(m => m.StackCount <= 1)
                                .Where(m => !_playerItemDao.Exists(Map(m, stash.ModLabel, isHardcore, stash.IsExpansion1)))
                                .ToList();
                    var notLootedDueToStackSize = stash.Tabs[lootFromIndex].Items.Where(m => m.StackCount > 1).ToList();

                    if (notLootedDueToStackSize.Count > 0)
                    {
                        _setFeedback("Warning", GlobalSettings.Language.GetTag("iatag_feedback_stacked_not_looted", notLootedDueToStackSize.Count));
                    }

                    var notLootedDueToDuplicate = stash.Tabs[lootFromIndex].Items.ToList();

                    notLootedDueToDuplicate.RemoveAll(m => items.Contains(m) || m.StackCount > 1);

                    if (notLootedDueToDuplicate.Count > 0)
                    {
                        _setFeedback("Warning", GlobalSettings.Language.GetTag("iatag_feedback_duplicates_not_looted", notLootedDueToDuplicate.Count));
                    }

                    stash.Tabs[lootFromIndex].Items.RemoveAll(e => items.Any(m => m.Equals(e)));

                    var storedItems = StoreItemsToDatabase(items, stash.ModLabel, isHardcore, stash.IsExpansion1);
                    var message     = GlobalSettings.Language.GetTag("iatag_looted_from_stash", items.Count, lootFromIndex + 1);

                    if (storedItems != null)
                    {
                        Logger.Info(message);

                        if (!SafelyWriteStash(filename, stash))
                        {
                            _playerItemDao.Remove(storedItems);
                        }
                    }

                    _performedLootCallback();

                    return(message);
                }

                Logger.Info($"Looting of stash {lootFromIndex + 1} halted, no items available.");

                return(GlobalSettings.Language.GetTag("iatag_feedback_no_items_to_loot"));
            }

            Logger.Error("Could not load stash file.");
            Logger.Error("An update from the developer is most likely required.");

            return(string.Empty);
        }
Example #2
0
        /// <summary>
        ///     Loot all the items stored on page X, and store them to the local database
        /// </summary>
        /// <param name="filename"></param>
        private string EmptyPageX(string filename)
        {
            Logger.InfoFormat("Looting {0}", filename);

            GDCryptoDataBuffer pCrypto = new GDCryptoDataBuffer(DataBuffer.ReadBytesFromDisk(filename));

            Stash stash = new Stash();

            if (stash.Read(pCrypto))
            {
                int lootFromIndex;
                if (Settings.Default.StashToLootFrom == 0)
                {
                    lootFromIndex = stash.Tabs.Count - 1;
                }
                else
                {
                    lootFromIndex = Settings.Default.StashToLootFrom - 1;
                }

                bool isHardcore = GlobalPaths.IsHardcore(filename);

#if DEBUG
                if (stash.Tabs.Count < 5)
                {
                    while (stash.Tabs.Count < 5)
                    {
                        stash.Tabs.Add(new StashTab());
                    }
                    SafelyWriteStash(filename, stash);
                    Logger.Info("Upgraded stash to 5 pages.");
                    return(string.Empty);
                }
#endif

                // Update the internal listing of unlooted items (in other stash tabs)
                List <Item> unlootedLocal = new List <Item>();
                for (var idx = 0; idx < stash.Tabs.Count; idx++)
                {
                    if (idx != lootFromIndex)
                    {
                        unlootedLocal.AddRange(stash.Tabs[idx].Items);
                    }
                }
                Interlocked.Exchange(ref _unlootedItems, new ConcurrentBag <Item>(unlootedLocal));
                StashUpdated?.Invoke(null, null);

                if (stash.Tabs.Count < 2)
                {
                    Logger.WarnFormat(
                        "File \"{0}\" only contains {1} pages, must have at least 2 pages to function properly.",
                        filename, stash.Tabs.Count);
                    return
                        ($"File \"{filename}\" only contains {stash.Tabs.Count} pages, must have at least 2 pages to function properly.");
                }
                if (stash.Tabs.Count < lootFromIndex + 1)
                {
                    var message =
                        $"You have configured IA to loot from {lootFromIndex + 1} but you only have {stash.Tabs.Count} pages";
                    Logger.Warn(message);
                    return(message);
                }

                if (stash.Tabs[lootFromIndex].Items.Count > 0)
                {
                    //_hasLootedItemsOnceThisSession = true;

                    // Grab the items and clear the tab
                    List <Item> items = new List <Item>(stash.Tabs[lootFromIndex].Items);
                    stash.Tabs[lootFromIndex].Items.Clear();

                    List <PlayerItem> storedItems =
                        StoreItemsToDatabase(items, stash.ModLabel, isHardcore, stash.IsExpansion1);
                    if (storedItems != null)
                    {
                        Logger.Info($"Looted {items.Count} items from stash {lootFromIndex + 1}");

                        if (!SafelyWriteStash(filename, stash))
                        {
                            // TODO: Delete from DB
                            _playerItemDao.Remove(storedItems);
                        }
                    }

                    _performedLootCallback();
                    return($"Looted {items.Count} items from stash {lootFromIndex + 1}");
                }
                Logger.Info($"Looting of stash {lootFromIndex + 1} halted, no items available.");
                return(GlobalSettings.Language.GetTag("iatag_feedback_no_items_to_loot"));
            }
            Logger.Error("Could not load stash file.");
            Logger.Error("An update from the developer is most likely required.");

            return(string.Empty);
        }