示例#1
0
        public static async Task <CoroutineResult> SellItems()
        {
            if (!ZetaDia.IsInTown)
            {
                return(CoroutineResult.NoAction);
            }

            var sellItem = InventoryManager.Backpack
                           .FirstOrDefault(i => ShouldSell(i) &&
                                           InventoryManager.CanSellItem(i));

            if (sellItem == null)
            {
                if (await RepairItems() == CoroutineResult.Running)
                {
                    return(CoroutineResult.Running);
                }

                GameUI.CloseVendorWindow();
                return(CoroutineResult.Done);
            }

            if (!UIElements.VendorWindow.IsVisible)
            {
                var merchant = TownInfo.NearestMerchant;
                if (merchant == null)
                {
                    s_logger.Error($"[{nameof(SellItems)}] Unable to find merchant info for this area :(");
                    return(CoroutineResult.Failed);
                }

                if (await CommonCoroutines.MoveAndInteract(
                        merchant.GetActor(),
                        () => UIElements.VendorWindow.IsVisible) == CoroutineResult.Running)
                {
                    return(CoroutineResult.Running);
                }
            }

            if (!sellItem.IsValid || sellItem.IsUnidentified)
            {
                s_logger.Debug($"[{nameof(SellItems)}] Invalid Items Detected: IsValid={sellItem.IsValid} IsUnidentified={sellItem.IsUnidentified}");
                return(CoroutineResult.Failed);
            }

            s_logger.Debug($"[{nameof(SellItems)}] Selling: {sellItem.Name} ({sellItem.ActorSnoId}) Quality={sellItem.ItemQualityLevel} IsAncient={sellItem.Stats.IsAncient} Name={sellItem.InternalName}");
            ItemEvents.FireItemSold(sellItem);
            InventoryManager.SellItem(sellItem);
            Core.Inventory.InvalidAnnIds.Add(sellItem.AnnId);
            return(CoroutineResult.Running);
        }
示例#2
0
        public async static Task <bool> Execute()
        {
            if (!ZetaDia.IsInTown)
            {
                Core.Logger.Verbose("[SellItems] Need to be in town to sell items");
                return(false);
            }

            var sellItems = Core.Inventory.Backpack.Where(ShouldSell).ToList();

            if (!sellItems.Any())
            {
                await RepairItems.Execute();

                Core.Logger.Verbose("[SellItems] Nothing to sell");
                return(false);
            }

            Core.Logger.Verbose("[SellItems] Now to sell {0} items", sellItems.Count);
            sellItems.ForEach(i => Core.Logger.Debug($"[SellItems] Selling: {i.Name} ({i.ActorSnoId}) InternalName={i.InternalName} Ancient={i.IsAncient} Ann={i.AnnId}"));

            await Coroutine.Sleep(Randomizer.Fudge(150));

            GameUI.CloseVendorWindow();

            var merchant = TownInfo.NearestMerchant;

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

            if (!UIElements.VendorWindow.IsVisible)
            {
                if (!await MoveToAndInteract.Execute(merchant))
                {
                    Core.Logger.Error($"[SellItems] Failed to move to merchant ({merchant.Name}) to sell items :(");
                    return(false);
                }
                await Coroutine.Sleep(Randomizer.Fudge(1000));
            }

            if (UIElements.VendorWindow.IsVisible)
            {
                await Coroutine.Sleep(Randomizer.Fudge(1500));

                var freshItems = Core.Inventory.Backpack.Where(ShouldSell);
                foreach (var item in freshItems)
                {
                    if (InventoryManager.CanSellItem(item.ToAcdItem()))
                    {
                        if (!item.IsValid || item.IsUnidentified)
                        {
                            Core.Logger.Verbose($"[SellItems] Invalid Items Detected: IsValid={item.IsValid} IsUnidentified={item.IsUnidentified}");
                            continue;
                        }

                        await Coroutine.Sleep(Randomizer.Fudge(100));

                        Core.Logger.Verbose($"[SellItems] Selling: {item.Name} ({item.ActorSnoId}) Quality={item.ItemQualityLevel} IsAncient={item.IsAncient} Name={item.InternalName}");
                        InventoryManager.SellItem(item.ToAcdItem());
                        ItemEvents.FireItemSold(item);
                        Core.Inventory.InvalidAnnIds.Add(item.AnnId);
                    }
                }

                await Coroutine.Sleep(Randomizer.Fudge(1000));

                await RepairItems.Execute();

                return(true);
            }

            Core.Logger.Error($"[SellItems] Failed to sell items");
            return(false);
        }