Example #1
0
        public static void ResetEverythingNewGame()
        {
            // In-thread stuff
            V.ValidateLoad();

            // Out of thread Async stuff
            BeginInvoke(() =>
            {
                Logger.Log("New Game - resetting everything");

                TrinityItemManager.ResetBackPackCheck();
                WantToTownRun      = false;
                ForceVendorRunASAP = false;
                TownRun.TownRunCheckTimer.Reset();
                TownRun.SendEmailNotification();
                TownRun.PreTownRunPosition = Vector3.Zero;
                TownRun.PreTownRunWorldId  = -1;
                TownRun.WasVendoring       = false;

                CacheData.AbilityLastUsed.Clear();
                SpellHistory.History.Clear();

                DeathsThisRun = 0;
                LastDeathTime = DateTime.UtcNow;
                ItemDropStats._hashsetItemStatsLookedAt    = new HashSet <string>();
                ItemDropStats._hashsetItemPicksLookedAt    = new HashSet <string>();
                ItemDropStats._hashsetItemFollowersIgnored = new HashSet <string>();

                Blacklist60Seconds = new HashSet <int>();
                Blacklist90Seconds = new HashSet <int>();
                Blacklist15Seconds = new HashSet <int>();

                PlayerMover.TotalAntiStuckAttempts     = 1;
                PlayerMover.vSafeMovementLocation      = Vector3.Zero;
                PlayerMover.LastPosition               = Vector3.Zero;
                PlayerMover.TimesReachedStuckPoint     = 0;
                PlayerMover.TimeLastRecordedPosition   = DateTime.MinValue;
                PlayerMover.LastGeneratedStuckPosition = DateTime.MinValue;
                PlayerMover.TimesReachedMaxUnstucks    = 0;
                PlayerMover.CancelUnstuckerForSeconds  = 0;
                PlayerMover.LastCancelledUnstucker     = DateTime.MinValue;
                NavHelper.UsedStuckSpots               = new List <GridPoint>();

                CacheData.FullClear();

                // Reset all the caches
                ProfileHistory = new List <string>();
                CurrentProfile = "";
                FirstProfile   = "";

                Logger.Log("New Game, resetting Gold Inactivity Timer");
                GoldInactivity.Instance.ResetCheckGold();

                CombatBase.IsQuestingMode = false;

                GenericCache.ClearCache();
                GenericBlacklist.ClearBlacklist();
            });
        }
Example #2
0
        public static CachedACDItem GetCachedItem(ACDItem item)
        {
            try
            {
                if (!item.IsValid)
                {
                    return(default(CachedACDItem));
                }

                CachedACDItem cItem = new CachedACDItem(item.Stats)
                {
                    AcdItem           = item,
                    InternalName      = item.InternalName,
                    RealName          = item.Name,
                    Level             = item.Level,
                    Quality           = item.GetItemQuality(),
                    GoldAmount        = item.Gold,
                    BalanceID         = item.GameBalanceId,
                    DynamicID         = item.DynamicId,
                    ActorSNO          = item.ActorSNO,
                    OneHanded         = item.IsOneHand,
                    TwoHanded         = item.IsTwoHand,
                    DyeType           = item.DyeType,
                    DBItemType        = item.ItemType,
                    DBBaseType        = item.ItemBaseType,
                    FollowerType      = item.FollowerSpecialType,
                    IsUnidentified    = item.IsUnidentified,
                    ItemStackQuantity = item.ItemStackQuantity,
                    Row             = item.InventoryRow,
                    Column          = item.InventoryColumn,
                    ItemLink        = item.ItemLink,
                    GameBalanceId   = item.GameBalanceId,
                    TrinityItemType = TrinityItemManager.DetermineItemType(item.InternalName, item.ItemType, item.FollowerSpecialType),
                    IsAncient       = item.GetAttribute <int>(ActorAttributeType.AncientRank) > 0,
                };
                TrinityItemBaseType trinityItemBaseType = TrinityItemManager.DetermineBaseType(TrinityItemManager.DetermineItemType(item.InternalName, item.ItemType, item.FollowerSpecialType));
                cItem.TrinityItemBaseType = trinityItemBaseType;
                cItem.IsEquipment         = GetIsEquipment(trinityItemBaseType);
                cItem.IsSalvageable       = GetIsSalvageable(cItem);

                return(cItem);
            }
            catch (Exception ex)
            {
                Logger.LogError("Error getting CachedItem {0}", ex.Message);
                return(default(CachedACDItem));
            }
        }
Example #3
0
        private static void TrinityOnDeath(object src, EventArgs mea)
        {
            if (DateTime.UtcNow.Subtract(LastDeathTime).TotalSeconds > 10)
            {
                LastDeathTime = DateTime.UtcNow;
                TotalDeaths++;
                DeathsThisRun++;
                CacheData.AbilityLastUsed          = new Dictionary <SNOPower, DateTime>(DataDictionary.LastUseAbilityTimeDefaults);
                PlayerMover.TotalAntiStuckAttempts = 1;
                PlayerMover.vSafeMovementLocation  = Vector3.Zero;

                // Reset pre-townrun position if we die
                TownRun.PreTownRunPosition          = Vector3.Zero;
                TownRun.PreTownRunWorldId           = -1;
                TownRun.LastCheckBackpackDurability = DateTime.MinValue;
                SpellHistory.History.Clear();
                TrinityItemManager.ResetBackPackCheck();
            }
        }
        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;
            }
            }
        }
Example #5
0
        /// <summary>
        /// This is wired up by Plugin.OnEnabled, and called when the bot is started
        /// </summary>
        /// <param name="bot"></param>
        private static void TrinityBotStart(IBot bot)
        {
            Logger.Log("Bot Starting");
            DateTime timeBotStart = DateTime.UtcNow;

            V.ValidateLoad();

            // Recording of all the XML's in use this run
            try
            {
                string sThisProfile = GlobalSettings.Instance.LastProfile;
                if (sThisProfile != CurrentProfile)
                {
                    ProfileHistory.Add(sThisProfile);
                    CurrentProfile = sThisProfile;
                    if (FirstProfile == "")
                    {
                        FirstProfile = sThisProfile;
                    }
                }

                DebugUtil.LogSystemInformation();
            }
            catch
            {
            }

            if (!ItemDropStats.MaintainStatTracking)
            {
                ItemDropStats.ItemStatsWhenStartedBot   = DateTime.UtcNow;
                ItemDropStats.ItemStatsLastPostedReport = DateTime.UtcNow;
                ItemDropStats.MaintainStatTracking      = true;
            }
            else
            {
                Logger.Log(TrinityLogLevel.Info, LogCategory.UserInformation,
                           "Note: Maintaining item stats from previous run. To reset stats fully, please restart DB.");
            }

            TrinityItemManager.ResetBackPackCheck();

            BeginInvoke(UsedProfileManager.RefreshProfileBlacklists);
            UsedProfileManager.SetProfileInWindowTitle();

            BotManager.ReplaceTreeHooks();
            TreeHooks.Instance.OnHooksCleared += BotManager.InstanceOnOnHooksCleared;


            PlayerMover.TimeLastRecordedPosition = DateTime.UtcNow;
            PlayerMover.LastRestartedGame        = DateTime.UtcNow;
            Logger.Log("Bot Starting, Resetting Gold Inactivity Timer");
            GoldInactivity.Instance.ResetCheckGold();
            XpInactivity.Instance.ResetCheckXp();

            if (CharacterSettings.Instance.KillRadius < 20)
            {
                Logger.Log("WARNING: Low Kill Radius detected, currently set to: {0} (you can change this through Demonbuddy bot settings)",
                           CharacterSettings.Instance.KillRadius);
            }

            if (CharacterSettings.Instance.LootRadius < 50)
            {
                Logger.Log("WARNING: Low Gold Loot Radius detected, currently set to: {0} (you can change this through Demonbuddy bot settings)",
                           CharacterSettings.Instance.LootRadius);
            }

            if (Settings.Loot.ItemFilterMode == ItemFilterMode.TrinityWithItemRules)
            {
                try
                {
                    if (StashRule == null)
                    {
                        StashRule = new Interpreter();
                    }
                }
                catch (Exception ex)
                {
                    Logger.LogError("Error configuring ItemRules Interpreter: " + ex);
                }
            }

            Logger.LogDebug("Trinity BotStart took {0:0}ms", DateTime.UtcNow.Subtract(timeBotStart).TotalMilliseconds);
        }
Example #6
0
 static void GameEvents_OnWorldChanged(object sender, EventArgs e)
 {
     CacheData.WorldChangedClear();
     TrinityItemManager.ResetBackPackCheck();
 }
Example #7
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);
            }
        }
Example #8
0
        private static bool RefreshItem()
        {
            using (new PerformanceLogger("RefreshItem"))
            {
                bool logNewItem;
                bool AddToCache;

                var diaItem = c_diaObject as DiaItem;

                if (diaItem == null)
                {
                    return(false);
                }

                if (diaItem.CommonData == null)
                {
                    return(false);
                }

                if (!diaItem.IsValid)
                {
                    return(false);
                }

                if (!diaItem.CommonData.IsValid)
                {
                    return(false);
                }

                c_ItemQuality = diaItem.CommonData.ItemQualityLevel;
                ((DiaItem)c_diaObject).CommonData.GetAttribute <int>(ActorAttributeType.ItemQualityLevelIdentified);
                c_ItemDisplayName = diaItem.CommonData.Name;

                CurrentCacheObject.DynamicID     = c_diaObject.CommonData.DynamicId;
                CurrentCacheObject.GameBalanceID = c_diaObject.CommonData.GameBalanceId;

                c_ItemLevel          = diaItem.CommonData.Level;
                c_DBItemBaseType     = diaItem.CommonData.ItemBaseType;
                c_DBItemType         = diaItem.CommonData.ItemType;
                c_IsOneHandedItem    = diaItem.CommonData.IsOneHand;
                c_IsTwoHandedItem    = diaItem.CommonData.IsTwoHand;
                c_item_tFollowerType = diaItem.CommonData.FollowerSpecialType;

                // Calculate item type
                if (_cItemTinityItemType == TrinityItemType.Unknown)
                {
                    _cItemTinityItemType = TrinityItemManager.DetermineItemType(CurrentCacheObject.InternalName, c_DBItemType, c_item_tFollowerType);
                }

                // And temporarily store the base type
                TrinityItemBaseType itemBaseType = TrinityItemManager.DetermineBaseType(_cItemTinityItemType);

                // Compute item quality from item link
                if (!CacheData.ItemLinkQuality.TryGetValue(CurrentCacheObject.ACDGuid, out c_ItemQuality))
                {
                    c_ItemQuality = diaItem.CommonData.GetItemQuality();
                    CacheData.ItemLinkQuality.Add(CurrentCacheObject.ACDGuid, c_ItemQuality);
                }

                if (itemBaseType == TrinityItemBaseType.Gem)
                {
                    c_ItemLevel = (int)diaItem.CommonData.GemQuality;
                }

                CurrentCacheObject.ObjectHash = HashGenerator.GenerateItemHash(
                    CurrentCacheObject.Position,
                    CurrentCacheObject.ActorSNO,
                    CurrentCacheObject.InternalName,
                    Player.WorldID,
                    c_ItemQuality,
                    c_ItemLevel);

                try
                {
                    c_IsAncient = c_ItemQuality == ItemQuality.Legendary && diaItem.CommonData.GetAttribute <int>(ActorAttributeType.AncientRank) > 0;
                }
                catch {}

                float range = 0f;

                // no range check on Legendaries
                if (c_ItemQuality < ItemQuality.Legendary || _cItemTinityItemType == TrinityItemType.ProgressionGlobe || _cItemTinityItemType == TrinityItemType.HoradricRelic)
                {
                    if (c_ItemQuality >= ItemQuality.Rare4)
                    {
                        range = CurrentBotLootRange;
                    }

                    if (_keepLootRadiusExtendedForSeconds > 0)
                    {
                        range += 90f;
                    }

                    if (CurrentCacheObject.Distance > (CurrentBotLootRange + range))
                    {
                        c_IgnoreSubStep = "OutOfRange";
                        // return here to save CPU on reading unncessary attributes for out of range items;
                        return(false);
                    }
                }

                var pickupItem = new PickupItem
                {
                    Name             = c_ItemDisplayName,
                    InternalName     = CurrentCacheObject.InternalName,
                    Level            = c_ItemLevel,
                    Quality          = c_ItemQuality,
                    BalanceID        = CurrentCacheObject.GameBalanceID,
                    DBBaseType       = c_DBItemBaseType,
                    DBItemType       = c_DBItemType,
                    TBaseType        = itemBaseType,
                    TType            = _cItemTinityItemType,
                    IsOneHand        = c_IsOneHandedItem,
                    IsTwoHand        = c_IsTwoHandedItem,
                    ItemFollowerType = c_item_tFollowerType,
                    DynamicID        = CurrentCacheObject.DynamicID,
                    Position         = CurrentCacheObject.Position,
                    ActorSNO         = CurrentCacheObject.ActorSNO,
                    ACDGuid          = CurrentCacheObject.ACDGuid,
                    RActorGUID       = CurrentCacheObject.RActorGuid,
                };

                // Blood Shards == HoradricRelic
                if (_cItemTinityItemType == TrinityItemType.HoradricRelic && ZetaDia.CPlayer.BloodshardCount >= Player.MaxBloodShards)
                {
                    return(false);
                }

                // Treat all globes as a yes
                if (_cItemTinityItemType == TrinityItemType.HealthGlobe)
                {
                    CurrentCacheObject.Type = TrinityObjectType.HealthGlobe;
                    return(true);
                }

                // Treat all globes as a yes
                if (_cItemTinityItemType == TrinityItemType.PowerGlobe)
                {
                    CurrentCacheObject.Type = TrinityObjectType.PowerGlobe;
                    return(true);
                }

                // Treat all globes as a yes
                if (_cItemTinityItemType == TrinityItemType.ProgressionGlobe)
                {
                    CurrentCacheObject.Type = TrinityObjectType.ProgressionGlobe;
                    return(true);
                }

                // Item stats
                logNewItem = RefreshItemStats(itemBaseType);

                // Get whether or not we want this item, cached if possible
                if (!CacheData.PickupItem.TryGetValue(CurrentCacheObject.RActorGuid, out AddToCache))
                {
                    if (pickupItem.IsTwoHand && Settings.Loot.Pickup.IgnoreTwoHandedWeapons && c_ItemQuality < ItemQuality.Legendary)
                    {
                        AddToCache = false;
                    }
                    else if (Settings.Loot.ItemFilterMode == ItemFilterMode.DemonBuddy)
                    {
                        AddToCache = ItemManager.Current.ShouldPickUpItem((ACDItem)c_diaObject.CommonData);
                    }
                    else if (Settings.Loot.ItemFilterMode == ItemFilterMode.TrinityWithItemRules)
                    {
                        AddToCache = TrinityItemManager.ItemRulesPickupValidation(pickupItem);
                    }
                    else // Trinity Scoring Only
                    {
                        AddToCache = TrinityItemManager.PickupItemValidation(pickupItem);
                    }

                    // Pickup low level enabled, and we're a low level
                    if (!AddToCache && Settings.Loot.Pickup.PickupLowLevel && Player.Level <= 10)
                    {
                        AddToCache = TrinityItemManager.PickupItemValidation(pickupItem);
                    }

                    // Ignore if item has existed before in this location
                    if (Settings.Loot.TownRun.DropLegendaryInTown)
                    {
                        if (!CacheData.DroppedItems.Any(i => i.Equals(pickupItem)))
                        {
                            CacheData.DroppedItems.Add(pickupItem);
                            AddToCache = true;
                        }
                        else
                        {
                            Logger.LogDebug("Ignoring Dropped Item = ItemPosition={0} Hashcode={1} DynId={2}", pickupItem.Position, pickupItem.GetHashCode(), pickupItem.DynamicID);
                            AddToCache = false;
                        }
                    }

                    CacheData.PickupItem.Add(CurrentCacheObject.RActorGuid, AddToCache);
                }

                if (AddToCache && ForceVendorRunASAP)
                {
                    c_IgnoreSubStep = "ForcedVendoring";
                }

                // Didn't pass pickup rules, so ignore it
                if (!AddToCache && c_IgnoreSubStep == String.Empty)
                {
                    c_IgnoreSubStep = "NoMatchingRule";
                }

                if (Settings.Advanced.LogDroppedItems && logNewItem && _cItemTinityItemType != TrinityItemType.HealthGlobe && _cItemTinityItemType != TrinityItemType.HealthPotion && _cItemTinityItemType != TrinityItemType.PowerGlobe && _cItemTinityItemType != TrinityItemType.ProgressionGlobe)
                {
                    //LogDroppedItem();
                    ItemDroppedAppender.Instance.AppendDroppedItem(pickupItem);
                }

                return(AddToCache);
            }
        }
Example #9
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,
                    });
                }
            }
        }