Exemplo n.º 1
0
        /// <summary>
        /// TownRunCheckOverlord - determine if we should do a town-run or not
        /// </summary>
        /// <param name="ret"></param>
        /// <returns></returns>
        internal static bool TownRunCanRun(object ret)
        {
            try
            {
                using (new PerformanceLogger("TownRunOverlord"))
                {
                    if (ZetaDia.Me == null || !ZetaDia.Me.IsValid)
                    {
                        return(false);
                    }

                    Trinity.IsReadyToTownRun = false;

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

                    var a5hubMaxRangePoint = new Vector3(441.0972f, 519.0328f, 7.718145f);
                    var a5waypoint         = new Vector3(556.9158f, 524.3738f, 2.796464f);
                    var a5hubRange         = a5waypoint.Distance2D(a5hubMaxRangePoint);
                    if (Trinity.Player.LevelAreaId == 270011 && Trinity.Player.Position.Distance2D(a5waypoint) >= a5hubRange)
                    {
                        return(false);
                    }

                    // Check if we should be forcing a town-run
                    if (!Trinity.Player.IsInTown && Trinity.ForceVendorRunASAP || BrainBehavior.IsVendoring)
                    {
                        if (!LastTownRunCheckResult)
                        {
                            if (BrainBehavior.IsVendoring)
                            {
                                Logger.Log(TrinityLogLevel.Info, LogCategory.UserInformation, "Looks like we are being asked to force a town-run by a profile/plugin/new DB feature, now doing so.");
                            }
                        }
                        SetPreTownRunPosition();
                        Trinity.IsReadyToTownRun = true;
                    }

                    // Time safety switch for more advanced town-run checking to prevent CPU spam
                    if (DateTime.UtcNow.Subtract(LastCheckBackpackDurability).TotalSeconds > 6)
                    {
                        LastCheckBackpackDurability = DateTime.UtcNow;

                        // Check for no space in backpack
                        Vector2 validLocation = TrinityItemManager.FindValidBackpackLocation(true);
                        if (validLocation.X < 0 || validLocation.Y < 0)
                        {
                            Logger.Log(TrinityLogLevel.Info, LogCategory.UserInformation, "No more space to pickup a 2-slot item, now running town-run routine. (TownRun)");
                            if (!LastTownRunCheckResult)
                            {
                                LastTownRunCheckResult = true;
                            }
                            Trinity.IsReadyToTownRun = true;

                            Trinity.ForceVendorRunASAP = true;
                            // Record the first position when we run out of bag space, so we can return later
                            SetPreTownRunPosition();
                        }

                        if (ZetaDia.Me.IsValid)
                        {
                            var equippedItems = ZetaDia.Me.Inventory.Equipped.Where(i => i.DurabilityCurrent != i.DurabilityMax).ToList();
                            if (equippedItems.Any())
                            {
                                double min = equippedItems.Min(i => i.DurabilityPercent);

                                float threshold   = Trinity.Player.IsInTown ? 0.50f : Zeta.Bot.Settings.CharacterSettings.Instance.RepairWhenDurabilityBelow;
                                bool  needsRepair = min <= threshold;

                                if (needsRepair)
                                {
                                    Logger.Log(TrinityLogLevel.Info, LogCategory.UserInformation, "Items may need repair, now running town-run routine.");

                                    Trinity.IsReadyToTownRun   = true;
                                    Trinity.ForceVendorRunASAP = true;
                                    SetPreTownRunPosition();
                                }
                            }
                        }
                    }

                    if (ErrorDialog.IsVisible)
                    {
                        Trinity.IsReadyToTownRun = false;
                    }

                    LastTownRunCheckResult = Trinity.IsReadyToTownRun;

                    // Clear blacklists to triple check any potential targets
                    if (Trinity.IsReadyToTownRun)
                    {
                        Trinity.Blacklist3Seconds  = new HashSet <int>();
                        Trinity.Blacklist15Seconds = new HashSet <int>();
                        Trinity.Blacklist60Seconds = new HashSet <int>();
                        Trinity.Blacklist90Seconds = new HashSet <int>();
                    }

                    // Fix for A1 new game with bags full
                    if (Trinity.Player.LevelAreaId == 19947 && ZetaDia.CurrentQuest.QuestSNO == 87700 && (ZetaDia.CurrentQuest.StepId == -1 || ZetaDia.CurrentQuest.StepId == 42))
                    {
                        Logger.Log(TrinityLogLevel.Verbose, LogCategory.UserInformation, "Can't townrun with the current quest!");
                        Trinity.IsReadyToTownRun = false;
                    }

                    if (Trinity.IsReadyToTownRun && !(BrainBehavior.IsVendoring || Trinity.Player.IsInTown))
                    {
                        string cantUseTPreason;
                        if (!ZetaDia.Me.CanUseTownPortal(out cantUseTPreason) && !ZetaDia.IsInTown)
                        {
                            Logger.Log(TrinityLogLevel.Verbose, LogCategory.UserInformation, "It appears we need to town run but can't: {0}", cantUseTPreason);
                            Trinity.IsReadyToTownRun = false;
                        }
                    }


                    if (Trinity.IsReadyToTownRun && DataDictionary.BossLevelAreaIDs.Contains(Trinity.Player.LevelAreaId))
                    {
                        Logger.Log(TrinityLogLevel.Debug, LogCategory.GlobalHandler, "Unable to Town Portal - Boss Area!");
                        return(false);
                    }
                    if (Trinity.IsReadyToTownRun && ZetaDia.IsInTown && DbProvider.DeathHandler.EquipmentNeedsEmergencyRepair())
                    {
                        Logger.Log(TrinityLogLevel.Debug, LogCategory.GlobalHandler, "EquipmentNeedsEmergencyRepair!");
                        return(true);
                    }
                    if (Trinity.IsReadyToTownRun && Trinity.CurrentTarget != null)
                    {
                        TownRunCheckTimer.Restart();
                        Logger.Log(TrinityLogLevel.Debug, LogCategory.GlobalHandler, "Restarting TownRunCheckTimer, we have a target!");
                        return(false);
                    }

                    if (Trinity.IsReadyToTownRun && DataDictionary.NeverTownPortalLevelAreaIds.Contains(Trinity.Player.LevelAreaId))
                    {
                        Logger.Log(TrinityLogLevel.Debug, LogCategory.GlobalHandler, "Unable to Town Portal in this area!");
                        return(false);
                    }
                    if (Trinity.IsReadyToTownRun && (TownRunTimerFinished() || BrainBehavior.IsVendoring))
                    {
                        //Logger.Log(TrinityLogLevel.Verbose, LogCategory.UserInformation, "Town run timer finished {0} or in town {1} or is vendoring {2} (TownRun)",
                        //    TownRunTimerFinished(), Trinity.Player.IsInTown, BrainBehavior.IsVendoring);
                        Trinity.IsReadyToTownRun = false;
                        return(true);
                    }
                    if (Trinity.IsReadyToTownRun && !TownRunCheckTimer.IsRunning)
                    {
                        Logger.Log(TrinityLogLevel.Verbose, LogCategory.UserInformation, "Starting town run timer");
                        TownRunCheckTimer.Start();
                        _loggedAnythingThisStash = false;
                        _loggedJunkThisStash     = false;
                    }
                    return(false);
                }
            }
            catch (Exception ex)
            {
                Logger.LogError("Error Getting TownRun {0}", ex.Message);
                return(false);
            }
        }
Exemplo n.º 2
0
        private static void RefreshStepMainObjectType(ref bool AddToCache)
        {
            // Now do stuff specific to object types
            switch (CurrentCacheObject.Type)
            {
            case GObjectType.Player:
            {
                AddToCache = RefreshUnit();
                break;
            }

            // Handle Unit-type Objects
            case GObjectType.Unit:
            {
                // Not allowed to kill monsters due to profile settings
                if (!Combat.Abilities.CombatBase.IsCombatAllowed)
                {
                    AddToCache      = false;
                    c_IgnoreSubStep = "CombatDisabled";
                    break;
                }

                AddToCache = RefreshUnit();
                break;
            }

            // Handle Item-type Objects
            case GObjectType.Item:
            {
                // Not allowed to loot due to profile settings
                // rrrix disabled this since noobs can't figure out their profile is broken... looting is always enabled now
                //if (!LootTargeting.Instance.AllowedToLoot || LootTargeting.Instance.DisableLooting)
                //{
                //    AddToCache = false;
                //    c_IgnoreSubStep = "LootingDisabled";
                //    break;
                //}

                if (TrinityItemManager.FindValidBackpackLocation(true) == new Vector2(-1, -1))
                {
                    AddToCache      = false;
                    c_IgnoreSubStep = "NoFreeSlots";
                    break;
                }
                AddToCache = RefreshItem();
                break;
            }

            // Handle Gold
            case GObjectType.Gold:
            {
                // Not allowed to loot due to profile settings
                //if (!LootTargeting.Instance.AllowedToLoot || LootTargeting.Instance.DisableLooting)
                //{
                //    AddToCache = false;
                //    c_IgnoreSubStep = "LootingDisabled";
                //    break;
                //}
                AddToCache = RefreshGold(AddToCache);
                break;
            }

            case GObjectType.PowerGlobe:
            case GObjectType.HealthGlobe:
            {
                // Ignore it if it's not in range yet
                if (CurrentCacheObject.Distance > CurrentBotLootRange || CurrentCacheObject.Distance > 60f)
                {
                    c_IgnoreSubStep = "GlobeOutOfRange";
                    AddToCache      = false;
                }
                AddToCache = true;
                break;
            }

            // Handle Avoidance Objects
            case GObjectType.Avoidance:
            {
                AddToCache = RefreshAvoidance(AddToCache);
                if (!AddToCache)
                {
                    c_IgnoreSubStep = "RefreshAvoidance";
                }

                break;
            }

            // Handle Other-type Objects
            case GObjectType.Destructible:
            case GObjectType.Door:
            case GObjectType.Barricade:
            case GObjectType.Container:
            case GObjectType.Shrine:
            case GObjectType.Interactable:
            case GObjectType.HealthWell:
            case GObjectType.CursedChest:
            case GObjectType.CursedShrine:
            {
                AddToCache = RefreshGizmo(AddToCache);
                break;
            }

            // Object switch on type (to seperate shrines, destructibles, barricades etc.)
            case GObjectType.Unknown:
            default:
            {
                c_IgnoreSubStep = "Unknown." + c_diaObject.ActorType.ToString();
                AddToCache      = false;
                break;
            }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Adds Legendary & Set Minimap Markers to ObjectCache
        /// </summary>
        private static void RefreshCacheMarkers()
        {
            const int setItemMarkerTexture       = 404424;
            const int legendaryItemMarkerTexture = 275968;

            if (!BrainBehavior.IsVendoring && !WantToTownRun && !ForceVendorRunASAP && Settings.Loot.Pickup.PickupLegendaries)
            {
                var legendaryItemMarkers = ZetaDia.Minimap.Markers.CurrentWorldMarkers.Where(m => m.IsValid &&
                                                                                             m.Position.Distance2D(Player.Position) >= 45f && m.Position.Distance2D(Player.Position) < 300f &&
                                                                                             (m.MinimapTexture == setItemMarkerTexture || m.MinimapTexture == legendaryItemMarkerTexture) && !Blacklist60Seconds.Contains(m.NameHash)).ToList();

                foreach (var marker in legendaryItemMarkers)
                {
                    var name = (marker.MinimapTexture == setItemMarkerTexture ? "Set Item" : "Legendary Item") + " Minimap Marker";

                    var cacheObject = new TrinityCacheObject
                    {
                        Position     = new Vector3((float)Math.Floor(marker.Position.X), (float)Math.Floor(marker.Position.Y), (float)Math.Floor(marker.Position.Z)),
                        InternalName = name,
                        ActorSNO     = marker.NameHash,
                        RActorGuid   = marker.MinimapTexture,
                        Distance     = marker.Position.Distance(Player.Position),
                        ActorType    = ActorType.Item,
                        Type         = TrinityObjectType.Item,
                        ItemQuality  = ItemQuality.Legendary,
                        Radius       = 2f,
                        Weight       = 50,
                        IsMarker     = true
                    };
                    cacheObject.ObjectHash = HashGenerator.GenerateItemHash(cacheObject);

                    if (GenericBlacklist.ContainsKey(cacheObject.ObjectHash))
                    {
                        Logger.LogDebug(LogCategory.CacheManagement, "Ignoring Marker because it's blacklisted {0} {1} at {2} distance {3}", name, marker.MinimapTexture, marker.Position, marker.Position.Distance(Player.Position));
                        continue;
                    }

                    Logger.LogDebug(LogCategory.CacheManagement, "Adding {0} {1} at {2} distance {3}", name, marker.MinimapTexture, marker.Position, marker.Position.Distance(Player.Position));
                    ObjectCache.Add(cacheObject);
                }

                if (legendaryItemMarkers.Any() && TrinityItemManager.FindValidBackpackLocation(true) != new Vector2(-1, -1))
                {
                    var legendaryItems = ZetaDia.Actors.GetActorsOfType <DiaItem>().Where(i => i.IsValid && i.IsACDBased && i.Position.Distance2D(ZetaDia.Me.Position) < 5f &&
                                                                                          legendaryItemMarkers.Any(im => i.Position.Distance2D(i.Position) < 2f));

                    foreach (var diaItem in legendaryItems)
                    {
                        Logger.LogDebug(LogCategory.CacheManagement, "Adding Legendary Item from Marker {0} dist={1} ActorSNO={2} ACD={3} RActor={4}",
                                        diaItem.Name, diaItem.Distance, diaItem.ActorSNO, diaItem.ACDGuid, diaItem.RActorGuid);

                        ObjectCache.Add(new TrinityCacheObject()
                        {
                            Position         = diaItem.Position,
                            InternalName     = diaItem.Name,
                            RActorGuid       = diaItem.RActorGuid,
                            ActorSNO         = diaItem.ActorSNO,
                            ACDGuid          = diaItem.ACDGuid,
                            HasBeenNavigable = true,
                            HasBeenInLoS     = true,
                            Distance         = diaItem.Distance,
                            ActorType        = ActorType.Item,
                            Type             = TrinityObjectType.Item,
                            Radius           = 2f,
                            Weight           = 50,
                            ItemQuality      = ItemQuality.Legendary,
                        });
                    }
                }
            }

            bool isRiftGuardianQuestStep = ZetaDia.CurrentQuest.QuestSNO == 337492 && ZetaDia.CurrentQuest.StepId == 16;

            if (isRiftGuardianQuestStep)
            {
                // Add Rift Guardian POI's or Markers to ObjectCache
                const int riftGuardianMarkerTexture = 81058;
                Func <MinimapMarker, bool> riftGuardianMarkerFunc = m => m.IsValid && (m.IsPointOfInterest || m.MinimapTexture == riftGuardianMarkerTexture) &&
                                                                    !Blacklist60Seconds.Contains(m.NameHash);

                foreach (var marker in ZetaDia.Minimap.Markers.CurrentWorldMarkers.Where(riftGuardianMarkerFunc))
                {
                    Logger.LogDebug(LogCategory.CacheManagement, "Adding Rift Guardian POI, distance {0}", marker.Position.Distance2D(Player.Position));
                    ObjectCache.Add(new TrinityCacheObject()
                    {
                        Position     = marker.Position,
                        InternalName = "Rift Guardian",
                        Distance     = marker.Position.Distance(Player.Position),
                        RActorGuid   = marker.NameHash,
                        ActorType    = ActorType.Monster,
                        Type         = TrinityObjectType.Unit,
                        Radius       = 10f,
                        Weight       = 5000,
                    });
                }
            }

            if (isRiftGuardianQuestStep || Player.ParticipatingInTieredLootRun) // X1_LR_DungeonFinder
            {
                foreach (var marker in ZetaDia.Minimap.Markers.CurrentWorldMarkers.Where(m => m.IsPointOfInterest && !Blacklist60Seconds.Contains(m.NameHash)))
                {
                    ObjectCache.Add(new TrinityCacheObject()
                    {
                        Position     = marker.Position,
                        InternalName = "Rift Guardian",
                        Distance     = marker.Position.Distance(Player.Position),
                        RActorGuid   = marker.NameHash,
                        ActorType    = ActorType.Monster,
                        Type         = TrinityObjectType.Unit,
                        Radius       = 10f,
                        Weight       = 5000,
                    });
                }
            }
        }