private static void HotSpotManager() { while (true) { try { Thread.Sleep(hotSpotRefreshRate); if (hotSpotList == null) { hotSpotList = new HashSet <HotSpot>(); } lock (hotSpotList) { var hotSpots = hotSpotList; foreach (var hotspot in hotSpots.Where(hotspot => DateTime.UtcNow.Subtract(hotspot.ExpirationTime).TotalMilliseconds > 0).ToList()) { hotSpotList.Remove(hotspot); } } } catch (Exception ex) { Logger.LogNormal("Exception in HotSpotManager: {0}", ex.ToString()); } } }
/// <summary> /// Loads the specified filename to IDictionary. /// </summary> /// <typeparam name="K"></typeparam> /// <typeparam name="T"></typeparam> /// <param name="filename">The filename.</param> /// <param name="name">The name.</param> /// <param name="keyName">Name of the key.</param> /// <param name="valueName">Name of the value.</param> /// <returns></returns> private static IDictionary <K, T> Load <K, T>(string filename, string name, string keyName, string valueName) { using (new PerformanceLogger("FileManager.Load")) { Logger.Log(TrinityLogLevel.Info, LogCategory.Configuration, "Loading Dictionary file={0} name={1} keys={2} values={3}", filename, name, keyName, valueName); IDictionary <K, T> ret = new Dictionary <K, T>(); try { if (File.Exists(filename)) { XElement xElem = XElement.Load(filename); xElem = xElem.Descendants("Dictionary").FirstOrDefault(elem => elem.Attribute("Name").Value == name); if (xElem != null) { List <KeyValuePair <K, T> > lst = (from e in xElem.Descendants("Entry") where e.Attribute(keyName) != null && e.Attribute(keyName).Value != null where e.Attribute(valueName) != null && e.Attribute(valueName).Value != null select new KeyValuePair <K, T>( typeof(K).IsEnum ? (K)Enum.Parse(typeof(K), e.Attribute(keyName).Value, true) : (K)Convert.ChangeType(e.Attribute(keyName).Value, typeof(K), CultureInfo.InvariantCulture), typeof(T).IsEnum ? (T)Enum.Parse(typeof(T), e.Attribute(valueName).Value, true) : (T)Convert.ChangeType(e.Attribute(valueName).Value, typeof(T), CultureInfo.InvariantCulture)) ).ToList(); foreach (KeyValuePair <K, T> item in lst) { Logger.Log(TrinityLogLevel.Debug, LogCategory.Configuration, "Found dictionary item {0} = {1}", item.Key, item.Value); ret.Add(item); } } } else { throw new FileNotFoundException("Could not load {0}", filename); } if (ret.Count > 0) { Logger.Log(TrinityLogLevel.Info, LogCategory.Configuration, "Loaded Dictionary name={0} key={1} value={2} with {3} values", name, keyName, valueName, ret.Count); } else { Logger.Log(TrinityLogLevel.Info, LogCategory.Configuration, "Attempted to load Dictionary name={0} key={1} value={2} but 0 values found!", name, keyName, valueName, ret.Count); } } catch (Exception ex) { Logger.LogNormal("{0}", ex); } return(ret); } }
private static void RefreshSetKiting(ref Vector3 vKitePointAvoid, bool NeedToKite) { using (new PerformanceLogger("RefreshDiaObjectCache.Kiting")) { bool TryToKite = false; List <TrinityCacheObject> kiteMonsterList = new List <TrinityCacheObject>(); if (CurrentTarget != null && CurrentTarget.IsUnit) { switch (CombatBase.KiteMode) { case KiteMode.Never: break; case KiteMode.Elites: kiteMonsterList = (from m in ObjectCache where m.IsUnit && m.RadiusDistance > 0 && m.RadiusDistance <= CombatBase.KiteDistance && m.IsBossOrEliteRareUnique select m).ToList(); break; case KiteMode.Bosses: kiteMonsterList = (from m in ObjectCache where m.IsUnit && m.RadiusDistance > 0 && m.RadiusDistance <= CombatBase.KiteDistance && m.IsBoss select m).ToList(); break; case KiteMode.Always: kiteMonsterList = (from m in ObjectCache where m.IsUnit && m.Weight > 0 && m.RadiusDistance > 0 && m.RadiusDistance <= CombatBase.KiteDistance && (m.IsBossOrEliteRareUnique || ((m.HitPointsPct >= .15 || m.MonsterSize != MonsterSize.Swarm) && !m.IsBossOrEliteRareUnique)) select m).ToList(); break; } } if (kiteMonsterList.Any()) { TryToKite = true; vKitePointAvoid = Player.Position; } if (CombatBase.KiteDistance > 0 && kiteMonsterList.Count() > 0 && IsWizardShouldKite()) { TryToKite = true; vKitePointAvoid = Player.Position; } // Avoid Death if (Settings.Combat.Misc.AvoidDeath && Player.CurrentHealthPct <= CombatBase.EmergencyHealthPotionLimit && // health is lower than potion limit !SNOPowerUseTimer(SNOPower.DrinkHealthPotion) && // we can't use a potion anymore TargetUtil.AnyMobsInRange(90f, false)) { Logger.LogNormal("Attempting to avoid death!"); NeedToKite = true; kiteMonsterList = (from m in ObjectCache where m.IsUnit select m).ToList(); } // Note that if treasure goblin level is set to kamikaze, even avoidance moves are disabled to reach the goblin! bool shouldKamikazeTreasureGoblins = (!AnyTreasureGoblinsPresent || Settings.Combat.Misc.GoblinPriority <= GoblinPriority.Prioritize); double msCancelledEmergency = DateTime.UtcNow.Subtract(timeCancelledEmergencyMove).TotalMilliseconds; bool shouldEmergencyMove = msCancelledEmergency >= cancelledEmergencyMoveForMilliseconds && NeedToKite; double msCancelledKite = DateTime.UtcNow.Subtract(timeCancelledKiteMove).TotalMilliseconds; bool shouldKite = msCancelledKite >= cancelledKiteMoveForMilliseconds && TryToKite; if (shouldKamikazeTreasureGoblins && (shouldEmergencyMove || shouldKite)) { Vector3 vAnySafePoint = NavHelper.FindSafeZone(false, 1, vKitePointAvoid, true, kiteMonsterList, shouldEmergencyMove); if (LastKitePosition == null) { LastKitePosition = new KitePosition() { PositionFoundTime = DateTime.UtcNow, Position = vAnySafePoint, Distance = vAnySafePoint.Distance(Player.Position) }; } if (vAnySafePoint != Vector3.Zero && vAnySafePoint.Distance(Player.Position) >= 1) { if ((DateTime.UtcNow.Subtract(LastKitePosition.PositionFoundTime).TotalMilliseconds > 3000 && LastKitePosition.Position == vAnySafePoint) || (CurrentTarget != null && DateTime.UtcNow.Subtract(lastGlobalCooldownUse).TotalMilliseconds > 1500 && TryToKite)) { timeCancelledKiteMove = DateTime.UtcNow; cancelledKiteMoveForMilliseconds = 1500; Logger.Log(TrinityLogLevel.Debug, LogCategory.UserInformation, "Kite movement failed, cancelling for {0:0}ms", cancelledKiteMoveForMilliseconds); return; } else { LastKitePosition = new KitePosition() { PositionFoundTime = DateTime.UtcNow, Position = vAnySafePoint, Distance = vAnySafePoint.Distance(Player.Position) }; } if (Settings.Advanced.LogCategories.HasFlag(LogCategory.Movement)) { Logger.Log(TrinityLogLevel.Verbose, LogCategory.Movement, "Kiting to: {0} Distance: {1:0} Direction: {2:0}, Health%={3:0.00}, KiteDistance: {4:0}, Nearby Monsters: {5:0} NeedToKite: {6} TryToKite: {7}", vAnySafePoint, vAnySafePoint.Distance(Player.Position), MathUtil.GetHeading(MathUtil.FindDirectionDegree(Me.Position, vAnySafePoint)), Player.CurrentHealthPct, CombatBase.KiteDistance, kiteMonsterList.Count(), NeedToKite, TryToKite); } CurrentTarget = new TrinityCacheObject() { Position = vAnySafePoint, Type = TrinityObjectType.Avoidance, Weight = 90000, Distance = Vector3.Distance(Player.Position, vAnySafePoint), Radius = 2f, InternalName = "KitePoint" }; } } else if (!shouldEmergencyMove && NeedToKite) { Logger.Log(TrinityLogLevel.Debug, LogCategory.UserInformation, "Emergency movement cancelled for {0:0}ms", DateTime.UtcNow.Subtract(timeCancelledEmergencyMove).TotalMilliseconds - cancelledKiteMoveForMilliseconds); } else if (!shouldKite && TryToKite) { Logger.Log(TrinityLogLevel.Debug, LogCategory.UserInformation, "Kite movement cancelled for {0:0}ms", DateTime.UtcNow.Subtract(timeCancelledKiteMove).TotalMilliseconds - cancelledKiteMoveForMilliseconds); } } }