コード例 #1
0
ファイル: TrinityTownRun.cs プロジェクト: galou12345/Trinity
        public static bool CanTownRun()
        {
            if (!ZetaDia.Me.CanUseTownPortal(out var cantUseTPreason) && !ZetaDia.IsInTown)
            {
                Core.Logger.Verbose("Can't townrun because '{0}'", cantUseTPreason);
                DontAttemptTownRunUntil = DateTime.UtcNow + TimeSpan.FromSeconds(10);
                return(false);
            }

            if (Core.Player.IsDead)
            {
                return(false);
            }

            if (!RepairItems.EquipmentNeedsRepair())
            {
                if (Core.Player.IsInventoryLockedForGreaterRift)
                {
                    Core.Logger.Verbose("Can't townrun while in greater rift!");
                    DontAttemptTownRunUntil = DateTime.UtcNow + TimeSpan.FromSeconds(5);
                    return(false);
                }

                // Close Greater rift before doing a town run.
                if (!Core.Settings.Items.KeepLegendaryUnid && Core.Player.ParticipatingInTieredLootRun)
                {
                    return(false);
                }
            }

            if (ErrorDialog.IsVisible)
            {
                Core.Logger.Log("Can't townrun with an error dialog present!");
                DontAttemptTownRunUntil = DateTime.UtcNow + TimeSpan.FromSeconds(10);
                return(false);
            }

            if (Core.Player.WorldSnoId == 71150 && ZetaDia.CurrentQuest.QuestSnoId == 87700 && ZetaDia.CurrentQuest.StepId == -1)
            {
                Core.Logger.Debug("Can't townrun with the current quest (A1 New Game) !");
                DontAttemptTownRunUntil = DateTime.UtcNow + TimeSpan.FromSeconds(30);
                return(false);
            }

            if (GameData.BossLevelAreaIDs.Contains(Core.Player.LevelAreaId))
            {
                Core.Logger.Debug("Unable to Town Portal - Boss Area!");
                DontAttemptTownRunUntil = DateTime.UtcNow + TimeSpan.FromSeconds(10);
                return(false);
            }

            if (GameData.NeverTownPortalLevelAreaIds.Contains(Core.Player.LevelAreaId))
            {
                Core.Logger.Log("Unable to Town Portal in this area!");
                DontAttemptTownRunUntil = DateTime.UtcNow + TimeSpan.FromSeconds(10);
                return(false);
            }

            return(true);
        }
コード例 #2
0
ファイル: TrinityTownRun.cs プロジェクト: ysj1995/Trinity
        private static bool ShouldStartTownRun()
        {
            if (ZetaDia.IsInTown && BrainBehavior.IsVendoring)
            {
                return(!IsInTownVendoring);
            }

            if (!CanTownRun())
            {
                return(false);
            }

            if (IsWantingTownRun)
            {
                Core.Logger.Debug("Is wanting to town run.");
                return(true);
            }

            // Close Normal rift before doing a town run.
            if (ZetaDia.IsInTown && !StartedOutOfTown && ZetaDia.Storage.RiftCompleted && ZetaDia.Storage.RiftStarted)
            {
                var orek = TownInfo.Orek?.GetActor() as DiaUnit;
                if (orek != null && orek.IsQuestGiver)
                {
                    return(false);
                }
            }

            var validLocation = DefaultLootProvider.FindBackpackLocation(true, false);

            if (validLocation.X < 0 || validLocation.Y < 0)
            {
                Core.Logger.Log("No more space to pickup a 2-slot item, now running town-run routine. (TownRun)");
                return(true);
            }

            var needRepair = RepairItems.EquipmentNeedsRepair();

            if (needRepair)
            {
                Core.Logger.Debug("Townrun for repair.");
                return(true);
            }

            return(BrainBehavior.IsVendoring);
        }
コード例 #3
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);
        }
コード例 #4
0
ファイル: TrinityTownRun.cs プロジェクト: agraellee/Trinity
        public static async Task <bool> Execute()
        {
            try
            {
                if (!ZetaDia.IsInGame)
                {
                    return(false);
                }

                if (await ClearArea.Execute())
                {
                    Core.Logger.Debug("Clearing");
                    return(false);
                }

                CheckForDBVendoringBug();

                if (DateTime.UtcNow < DontAttemptTownRunUntil)
                {
                    IsVendoring = false;
                    return(false);
                }

                // Fix for Campaign quest start of ACT1
                if (ZetaDia.CurrentQuest.QuestSnoId == 87700)
                {
                    return(false);
                }

                if (Core.CastStatus.StoneOfRecall.LastResult == CastResult.Casting)
                {
                    Core.Logger.Verbose(LogCategory.GlobalHandler, "Casting");
                    return(true);
                }

                if (!ShouldStartTownRun())
                {
                    IsVendoring = false;
                    return(false);
                }

                IsWantingTownRun = true;

                Core.Logger.Debug("Town run started");

                if (ZetaDia.Globals.IsLoadingWorld)
                {
                    return(true);
                }

                if (!ZetaDia.IsInTown)
                {
                    if (ZetaDia.Me.IsInCombat && !ClearArea.IsClearing && ZetaDia.Actors.GetActorsOfType <DiaUnit>().Any(u => u?.CommonData != null && u.CommonData.IsValid && u.IsAlive && u.IsHostile && u.Distance < 16f))
                    {
                        ClearArea.Start();
                    }

                    await GoToTown();

                    if (!ZetaDia.IsInTown)
                    {
                        if (Core.CastStatus.StoneOfRecall.LastResult == CastResult.Failed)
                        {
                            Core.Logger.Debug("Setting Town Run Cooldown because of cast failure");
                            DontAttemptTownRunUntil = DateTime.UtcNow.AddSeconds(5);
                        }
                        return(true);
                    }
                }

                Core.Logger.Verbose($"Starting Townrun");

                IsInTownVendoring = true;

                while (DateTime.UtcNow.Subtract(ChangeEvents.WorldId.LastChanged).TotalMilliseconds < 2000 || ZetaDia.Globals.IsLoadingWorld || ZetaDia.Globals.WorldSnoId <= 0)
                {
                    await Coroutine.Yield();
                }

                await Coroutine.Wait(8000, () => Core.Actors.Inventory.Any());

                await Coroutine.Yield();

                Core.Actors.Update();
                Core.Player.Update();
                await Coroutine.Sleep(1000);

                Core.Logger.Debug("Started Town Run Loop");

                var checkCycles = 2;

                while (!Core.Player.IsInventoryLockedForGreaterRift)
                {
                    Core.Inventory.Backpack.ForEach(i => Core.Logger.Debug($"Backpack Item: {i.Name} ({i.ActorSnoId} / {i.InternalName}) RawItemType={i.RawItemType} TrinityItemType={i.TrinityItemType}"));

                    await Coroutine.Yield();

                    GameUI.CloseVendorWindow();
                    await IdentifyItems.Execute();

                    if (!ZetaDia.IsInGame)
                    {
                        StartedOutOfTown  = false;
                        IsWantingTownRun  = false;
                        IsInTownVendoring = false;
                        IsVendoring       = false;
                        return(false);
                    }

                    if (!await ExtractLegendaryPowers.Execute())
                    {
                        continue;
                    }

                    if (!await Gamble.Execute())
                    {
                        continue;
                    }

                    if (!await CubeRaresToLegendary.Execute())
                    {
                        continue;
                    }

                    if (!await CubeItemsToMaterials.Execute())
                    {
                        continue;
                    }

                    if (await Any(
                            DropItems.Execute,
                            () => StashItems.Execute(true),
                            SellItems.Execute,
                            SalvageItems.Execute))
                    {
                        continue;
                    }

                    checkCycles--;
                    if (checkCycles == 0)
                    {
                        break;
                    }
                }

                await StashItems.Execute();

                await RepairItems.Execute();

                Core.Logger.Log("Finished Town Run woo!");
                DontAttemptTownRunUntil = DateTime.UtcNow + TimeSpan.FromSeconds(15);

                if (StartedOutOfTown)
                {
                    StartedOutOfTown = false;
                    await TakeReturnPortal();
                }
            }
            finally
            {
                IsWantingTownRun  = false;
                IsInTownVendoring = false;
                IsVendoring       = false;
            }
            return(false);
        }
コード例 #5
0
ファイル: SalvageItems.cs プロジェクト: ysj1995/Trinity
        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);
        }
コード例 #6
0
ファイル: StashItems.cs プロジェクト: galou12345/Trinity
        public static async Task <bool> Execute(bool dontStashCraftingMaterials = false)
        {
            if (!ZetaDia.IsInTown)
            {
                Core.Logger.Verbose("[StashItems] Need to be in town to stash items");
                return(false);
            }

            var stashItems = Core.Inventory.Backpack.Where(ShouldStash).Where(i => AllowedToStash(dontStashCraftingMaterials, i)).ToList();

            if (!stashItems.Any())
            {
                Core.Logger.Verbose($"[StashItems] Nothing to stash");
                return(false);
            }

            Core.Logger.Verbose($"[StashItems] Now to stash {stashItems.Count} items");
            stashItems.ForEach(i => Core.Logger.Debug($"[StashItems] Stashing: {i.Name} ({i.ActorSnoId}) InternalName={i.InternalName} Ancient={i.IsAncient} Ann={i.AnnId}"));

            GameUI.CloseVendorWindow();

            await MoveToStash();

            if (!UIElements.StashWindow.IsVisible)
            {
                var stash = ZetaDia.Actors.GetActorsOfType <GizmoPlayerSharedStash>().FirstOrDefault();
                if (stash == null)
                {
                    return(false);
                }

                if (!await MoveTo.Execute(stash.Position))
                {
                    Core.Logger.Error($"[SalvageItems] Failed to move to stash interact position ({stash.Name}) to stash items :(");
                    return(false);
                }
                ;
                Navigator.PlayerMover.MoveTowards(stash.Position);
                if (!await MoveToAndInteract.Execute(stash, 5f))
                {
                    Core.Logger.Error($"[SalvageItems] Failed to move to stash ({stash.Name}) to stash items :(");
                    return(false);
                }
                ;
                await Coroutine.Yield();

                stash.Interact();
            }

            if (UIElements.StashWindow.IsVisible)
            {
                if (Core.Settings.Items.BuyStashTabs && StashPagesAvailableToPurchase)
                {
                    Core.Logger.Error("[StashItems] Attempting to buy stash pages");
                    InventoryManager.BuySharedStashSlots();
                }

                await StackRamaladnisGift();
                await StackCraftingMaterials();

                var isStashFull = false;

                // Get items again to make sure they are valid and current this tick
                var freshItems = Core.Inventory.Backpack.Where(ShouldStash).Where(i => AllowedToStash(dontStashCraftingMaterials, i)).ToList();
                if (!freshItems.Any())
                {
                    Core.Logger.Verbose($"[StashItems] No items to stash");
                }
                else
                {
                    foreach (var item in freshItems)
                    {
                        try
                        {
                            item.OnUpdated(); // make sure wrong col/row/location is not cached after a move.

                            var page = GetBestStashLocation(item, out var col, out var row);
                            if (page == -1)
                            {
                                Core.Logger.Verbose($"[StashItems] No place to put item, stash is probably full ({item.Name} [{col},{row}] Page={page})");
                                HandleFullStash();
                                isStashFull = true;
                                continue;
                            }

                            if (page != InventoryManager.CurrentStashPage)
                            {
                                Core.Logger.Verbose($"[StashItems] Changing to stash page: {page}");
                                InventoryManager.SwitchStashPage(page);
                                await Coroutine.Yield();
                            }

                            Core.Logger.Debug($"[StashItems] Stashing: {item.Name} ({item.ActorSnoId}) [{item.InventoryColumn},{item.InventoryRow} {item.InventorySlot}] Quality={item.ItemQualityLevel} IsAncient={item.IsAncient} InternalName={item.InternalName} StashPage={page}");
                            InventoryManager.MoveItem(item.AnnId, Core.Player.MyDynamicID, InventorySlot.SharedStash, col, row);
                            await Coroutine.Yield();

                            Core.Actors.Update();

                            await Coroutine.Wait(5000, () => !item.IsValid || item.InventoryRow == row && item.InventoryColumn == col);

                            ItemEvents.FireItemStashed(item);
                        }
                        catch (Exception ex)
                        {
                            Core.Logger.Log($"Exception Stashing Item: {ex}");
                        }
                    }
                }

                await Coroutine.Yield();

                await RepairItems.Execute();

                if (isStashFull)
                {
                    return(false);
                }

                return(true);
            }

            Core.Logger.Error($"[StashItems] Failed to stash items");
            return(false);
        }
コード例 #7
0
ファイル: SalvageItems.cs プロジェクト: galou12345/Trinity
        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);
        }