Пример #1
0
        public static async Task <bool> Execute()
        {
            if (!ZetaDia.IsInTown)
            {
                Core.Logger.Verbose("[SalvageItems] Need to be in town to salvage items");
                return(false);
            }

            var salvageItems = Core.Inventory.Backpack.Where(ShouldSalvage).ToList();

            if (!salvageItems.Any())
            {
                Core.Logger.Verbose("[SalvageItems] Nothing to salvage");
                return(false);
            }

            Core.Logger.Verbose("[SalvageItems] Starting salvage for {0} items", salvageItems.Count);
            salvageItems.ForEach(i => Core.Logger.Debug($"[SalvageItems] Salvaging: {i.Name} ({i.ActorSnoId}) InternalName={i.InternalName} Ancient={i.IsAncient} Ann={i.AnnId}"));

            GameUI.CloseVendorWindow();

            var blacksmith = TownInfo.BlacksmithSalvage;

            if (blacksmith == null)
            {
                Core.Logger.Error("[SalvageItems] Unable to find a blacksmith info for this area :(");
                return(false);
            }

            if (!UIElements.SalvageWindow.IsVisible)
            {
                var blacksmithNpc = TownInfo.Blacksmith;
                if (blacksmithNpc != null)
                {
                    Core.DBGridProvider.AddCellWeightingObstacle(blacksmithNpc.ActorId, 4);
                }

                if (!await MoveTo.Execute(blacksmith.InteractPosition))
                {
                    Core.Logger.Error($"[SalvageItems] Failed to move to blacksmith interact position ({blacksmith.Name}) to salvage items :(");
                    return(false);
                }
                ;

                if (!await MoveToAndInteract.Execute(blacksmith, 10f))
                {
                    Core.Logger.Error($"[SalvageItems] Failed to move to blacksmith ({blacksmith.Name}) to salvage items :(");
                    return(false);
                }
                ;
                await Coroutine.Sleep(Rnd.Next(750, 1250));
            }

            if (UIElements.SalvageWindow.IsVisible)
            {
                if (ZetaDia.Me.Level >= 70 && UIElements.SalvageAllWrapper.IsVisible)
                {
                    var items = Core.Inventory.Backpack.Where(i => Combat.TrinityCombat.Loot.ShouldSalvage(i)).ToList();

                    var normals = items.Where(i => NormalQualityLevels.Contains(i.ItemQualityLevel)).ToList();
                    if (normals.Count > 0)
                    {
                        Core.Logger.Verbose($"[SalvageItems] Bulk Salvaging {normals.Count} Normal");
                        if (InventoryManager.SalvageItemsOfRarity(SalvageRarity.Normal))
                        {
                            normals.ForEach(ItemEvents.FireItemSalvaged);
                        }
                    }

                    var magic = items.Where(i => MagicQualityLevels.Contains(i.ItemQualityLevel)).ToList();
                    if (magic.Count > 0)
                    {
                        Core.Logger.Verbose($"[SalvageItems] Bulk Salvaging {magic.Count} Magic");
                        if (InventoryManager.SalvageItemsOfRarity(SalvageRarity.Magic))
                        {
                            magic.ForEach(ItemEvents.FireItemSalvaged);
                        }
                    }

                    var rares = items.Where(i => RareQualityLevels.Contains(i.ItemQualityLevel)).ToList();
                    if (rares.Count > 0)
                    {
                        Core.Logger.Verbose($"[SalvageItems] Bulk Salvaging {rares.Count} Rare");
                        if (InventoryManager.SalvageItemsOfRarity(SalvageRarity.Rare))
                        {
                            rares.ForEach(ItemEvents.FireItemSalvaged);
                        }
                    }
                }

                await Coroutine.Sleep(500);

                await Coroutine.Yield();

                var timeout = DateTime.UtcNow.Add(TimeSpan.FromSeconds(30));
                while (DateTime.UtcNow < timeout)
                {
                    if (!UIElements.SalvageWindow.IsVisible)
                    {
                        break;
                    }

                    await Coroutine.Sleep(Rnd.Next(200, 300));

                    Core.Actors.Update();

                    var freshItems = Core.Inventory.Backpack.Where(i => ShouldSalvage(i) && !Core.Inventory.InvalidAnnIds.Contains(i.AnnId)).ToList();
                    if (!freshItems.Any())
                    {
                        break;
                    }

                    var item = freshItems.First();

                    if (ZetaDia.Actors.GetACDByAnnId(item.AnnId) == null)
                    {
                        Core.Logger.Log("AnnId doesn't exist, skipping salvage");
                        Core.Inventory.InvalidAnnIds.Add(item.AnnId);
                        continue;
                    }

                    if (!Core.Actors.IsAnnIdValid(item.AnnId))
                    {
                        Core.Logger.Log("AnnId test failed, skipping salvage to prevent disconnect");
                        Core.Inventory.InvalidAnnIds.Add(item.AnnId);
                        continue;
                    }

                    Core.Logger.Log($"Salvaging: {item.Name} ({item.ActorSnoId}) Ancient={item.IsAncient}");
                    InventoryManager.SalvageItem(item.AnnId);
                    Core.Inventory.InvalidAnnIds.Add(item.AnnId);
                    ItemEvents.FireItemSalvaged(item);
                }

                await Coroutine.Sleep(Rnd.Next(750, 1250));

                await RepairItems.Execute();

                return(true);
            }

            Core.Logger.Error($"[SalvageItems] Failed to salvage items");
            return(false);
        }
Пример #2
0
        public static async Task <bool> Execute()
        {
            if (!ZetaDia.IsInTown)
            {
                Core.Logger.Verbose("[SalvageItems] Need to be in town to salvage items");
                return(false);
            }

            var salvageItems = Core.Inventory.Backpack.Where(ShouldSalvage).ToList();

            if (!salvageItems.Any())
            {
                Core.Logger.Verbose("[SalvageItems] Nothing to salvage");
                return(false);
            }

            Core.Logger.Verbose("[SalvageItems] Starting salvage for {0} items", salvageItems.Count);
            salvageItems.ForEach(i => Core.Logger.Debug($"[SalvageItems] Salvaging: {i.Name} ({i.ActorSnoId}) InternalName={i.InternalName} Ancient={i.IsAncient} Ann={i.AnnId}"));

            GameUI.CloseVendorWindow();

            if (!await EnsureSalvageWindow())
            {
                Core.Logger.Error($"[SalvageItems] Failed to salvage items");
                return(false);
            }

            if (ZetaDia.Me.Level >= 70 && UIElements.SalvageAllWrapper.IsVisible)
            {
                var items = Core.Inventory.Backpack.Where(i => Combat.TrinityCombat.Loot.ShouldSalvage(i)).ToList();

                var normals = items.Where(i => NormalQualityLevels.Contains(i.ItemQualityLevel)).ToList();
                if (normals.Count > 0)
                {
                    Core.Logger.Verbose($"[SalvageItems] Bulk Salvaging {normals.Count} Normal");
                    if (InventoryManager.SalvageItemsOfRarity(SalvageRarity.Normal))
                    {
                        normals.ForEach(ItemEvents.FireItemSalvaged);
                    }
                }

                var magic = items.Where(i => MagicQualityLevels.Contains(i.ItemQualityLevel)).ToList();
                if (magic.Count > 0)
                {
                    Core.Logger.Verbose($"[SalvageItems] Bulk Salvaging {magic.Count} Magic");
                    if (InventoryManager.SalvageItemsOfRarity(SalvageRarity.Magic))
                    {
                        magic.ForEach(ItemEvents.FireItemSalvaged);
                    }
                }

                var rares = items.Where(i => RareQualityLevels.Contains(i.ItemQualityLevel)).ToList();
                if (rares.Count > 0)
                {
                    Core.Logger.Verbose($"[SalvageItems] Bulk Salvaging {rares.Count} Rare");
                    if (InventoryManager.SalvageItemsOfRarity(SalvageRarity.Rare))
                    {
                        rares.ForEach(ItemEvents.FireItemSalvaged);
                    }
                }
            }
            else
            {
                var timeout = DateTime.UtcNow.Add(TimeSpan.FromSeconds(30));
                while (DateTime.UtcNow < timeout)
                {
                    if (!UIElements.SalvageWindow.IsVisible)
                    {
                        break;
                    }

                    await Coroutine.Yield();

                    Core.Actors.Update();

                    var freshItems = Core.Inventory.Backpack.Where(i => ShouldSalvage(i) && !Core.Inventory.InvalidAnnIds.Contains(i.AnnId)).ToList();
                    if (!freshItems.Any())
                    {
                        break;
                    }

                    var item = freshItems.First();

                    if (ZetaDia.Actors.GetACDByAnnId(item.AnnId) == null)
                    {
                        Core.Logger.Log("AnnId doesn't exist, skipping salvage");
                        Core.Inventory.InvalidAnnIds.Add(item.AnnId);
                        continue;
                    }

                    if (!Core.Actors.IsAnnIdValid(item.AnnId))
                    {
                        Core.Logger.Log("AnnId test failed, skipping salvage to prevent disconnect");
                        Core.Inventory.InvalidAnnIds.Add(item.AnnId);
                        continue;
                    }

                    Core.Logger.Log($"Salvaging: {item.Name} ({item.ActorSnoId}) Ancient={item.IsAncient}");
                    InventoryManager.SalvageItem(item.AnnId);
                    Core.Inventory.InvalidAnnIds.Add(item.AnnId);
                    ItemEvents.FireItemSalvaged(item);
                }
            }

            await Coroutine.Yield();

            await RepairItems.Execute();

            return(true);
        }