/// <summary> Query if 'acd' is valid a ACD. </summary> /// <param name="unit"> The unit. </param> /// <returns> true if valid acd, false if not. </returns> public static bool IsAttackable(this DiaUnit unit) { ACD acd = unit.CommonData; if (!unit.IsValid || acd == null || unit.ACDGuid == -1) { return(false); } if (unit.IsFriendly) { return(false); } AnimationState animationState = GetAnimationStateForACD(acd); if (animationState == AnimationState.Dead) { return(false); } bool isAttackble = !unit.IsUntargetable && !unit.IsSlowdownImmune && !unit.IsStunImmune && !unit.IsUninterruptible && !unit.IsRootImmune && !unit.IsBurrowed && !unit.IsHidden && !unit.IsDead; return(isAttackble); }
private float GetDistance(DiaUnit u, int dynamicId) { if (!_distanceCache.ContainsKey(dynamicId)) { _distanceCache.Add(dynamicId, u.Position.DistanceSqr(_playerCurrentPosition)); } return(_distanceCache[dynamicId]); }
private bool IsValidMonsterType(DiaUnit u) { MonsterType currentMt = GetMonsterType(u); return(currentMt != MonsterType.Ally && currentMt != MonsterType.Scenery && currentMt != MonsterType.Helper && currentMt != MonsterType.Team); }
private MonsterType GetMonsterType(DiaUnit u) { int sno = u.ActorSNO; if (!_monsterTypeCache.ContainsKey(sno)) { _monsterTypeCache.Add(sno, u.MonsterInfo.MonsterType); } return(_monsterTypeCache[sno]); }
private bool IsTownVendor(DiaUnit u) { int sno = u.ActorSNO; if (!_isTownVendorCache.ContainsKey(sno)) { _isTownVendorCache.Add(sno, u.IsTownVendor); } return(_isTownVendorCache[sno]); }
public static MonsterSize GetMonsterSize(this DiaUnit u) { int sno = u.ActorSNO; if (!_monsterSizeCache.ContainsKey(sno)) { _monsterSizeCache.Add(sno, u.MonsterInfo.MonsterSize); } return(_monsterSizeCache[sno]); }
public static float GetMonsterDistanceModifier(this DiaUnit u) { int sno = u.ActorSNO; if (!_monsterDistanceModifierCache.ContainsKey(sno)) { _monsterDistanceModifierCache.Add(sno, u.CollisionSphere.Radius); } return(_monsterDistanceModifierCache[sno]); }
internal static RunStatus GamblingMovement(object ret) { if (FunkyGame.GameIsInvalid) { ActionsChecked = false; FunkyTownRunPlugin.DBLog.InfoFormat("[Funky] Town Run Behavior Failed! (Not In Game/Invalid Actor/misc)"); return(RunStatus.Failure); } BotMain.StatusText = "Town run: Gambling Movement"; DiaUnit objGamblingNPC = ZetaDia.Actors.GetActorsOfType <DiaUnit>(true).FirstOrDefault <DiaUnit>(u => u.Name.StartsWith("X1_RandomItemNPC")); Vector3 vectorPlayerPosition = ZetaDia.Me.Position; Vector3 vectorGamblingPosition = Vector3.Zero; if (objGamblingNPC == null || objGamblingNPC.Distance > 50f) { vectorGamblingPosition = SafetyGambleLocation; } else { vectorGamblingPosition = objGamblingNPC.Position; } //Wait until we are not moving if (FunkyGame.GameIsInvalid) { return(RunStatus.Running); } float fDistance = Vector3.Distance(vectorPlayerPosition, vectorGamblingPosition); //Out-Of-Range... if (objGamblingNPC == null || fDistance > 12f) //|| !GilesCanRayCast(vectorPlayerPosition, vectorSalvageLocation, Zeta.Internals.SNO.NavCellFlags.AllowWalk)) { Navigator.PlayerMover.MoveTowards(vectorGamblingPosition); return(RunStatus.Running); } UIElement uie = UI.Game.BloodShardVendorMainDialog; if (!(uie != null && uie.IsValid && uie.IsVisible)) { objGamblingNPC.Interact(); return(RunStatus.Running); } //Now we need to update our item list so we can get the DynamicIDs. UpdateGambleItemList(); return(RunStatus.Success); }
private bool IsStaticDataValid(DiaUnit u) { int key = u.ActorSNO; if (!_staticDataValidCache.ContainsKey(key)) { _staticDataValidCache.Add(key, !ActorBlackList.Contains(key) && !IsTownVendor(u) && IsValidMonsterType(u)); } return(_staticDataValidCache[key] && !_blacklistedActorsFromProfile.Contains(key)); }
/// <summary> /// Will only update actor if found (useful for some portals which tend to disappear when you stand next to them) /// </summary> private void SafeUpdateActor() { DiaObject newActor = null; DiaUnit newUnit = null; // Find closest actor if we have a position and MaxSearchDistance (only actors within radius MaxSearchDistance from Position) if (Position != Vector3.Zero && MaxSearchDistance > 0) { newActor = ZetaDia.Actors.GetActorsOfType <DiaObject>(true, false) .Where(o => o.ActorSNO == ActorId && o.Position.Distance(Position) <= MaxSearchDistance) .OrderBy(o => Position.Distance(o.Position)).FirstOrDefault(); } // Otherwise just OrderBy distance from Position (any actor found) else if (Position != Vector3.Zero) { newActor = ZetaDia.Actors.GetActorsOfType <DiaObject>(true, false) .Where(o => o.ActorSNO == ActorId) .OrderBy(o => Position.Distance(o.Position)).FirstOrDefault(); } // If all else fails, get first matching Actor closest to Player else { newActor = ZetaDia.Actors.GetActorsOfType <DiaObject>(true, false) .Where(o => o.ActorSNO == ActorId) .OrderBy(o => o.Distance).FirstOrDefault(); } if (newActor != null && newActor.IsValid && newActor.Position != Vector3.Zero) { Position = newActor.Position; actor = newActor; switch (newActor.ActorType) { case Zeta.Internals.SNO.ActorType.Unit: { newUnit = (DiaUnit)newActor; if (!newUnit.IsDead) { actor = newActor; } else { actor = null; } break; } } } else { actor = null; } }
private static bool RefreshUnitAttributes(bool AddToCache = true, DiaUnit unit = null) { if (!DataDictionary.IgnoreUntargettableAttribute.Contains(CurrentCacheObject.ActorSNO) && unit.IsUntargetable) { AddToCache = false; c_IgnoreSubStep = "IsUntargetable"; return(AddToCache); } // don't check for invulnerability on shielded and boss units, they are treated seperately if (!c_unit_HasShieldAffix && unit.IsInvulnerable) { AddToCache = false; c_IgnoreSubStep = "IsInvulnerable"; return(AddToCache); } bool isBurrowed = false; if (!CacheData.UnitIsBurrowed.TryGetValue(CurrentCacheObject.RActorGuid, out isBurrowed)) { isBurrowed = unit.IsBurrowed; // if the unit is NOT burrowed - we can attack them, add to cache (as IsAttackable) if (!isBurrowed) { CacheData.UnitIsBurrowed.Add(CurrentCacheObject.RActorGuid, isBurrowed); } } if (isBurrowed) { AddToCache = false; c_IgnoreSubStep = "IsBurrowed"; return(AddToCache); } // only check for DotDPS/Bleeding in certain conditions to save CPU for everyone else // barbs with rend // All WD's // Monks with Way of the Hundred Fists + Fists of Fury if (AddToCache && ((Player.ActorClass == ActorClass.Barbarian && Hotbar.Contains(SNOPower.Barbarian_Rend)) || Player.ActorClass == ActorClass.Witchdoctor || (Player.ActorClass == ActorClass.Monk && HotbarSkills.AssignedSkills.Any(s => s.Power == SNOPower.Monk_WayOfTheHundredFists && s.RuneIndex == 0))) ) { ////bool hasdotDPS = CurrentCacheObject.CommonData.GetAttribute<int>(ActorAttributeType.DOTDPS) != 0; //bool isBleeding = CurrentCacheObject.CommonData.GetAttribute<int>(ActorAttributeType.Bleeding) != 0; //c_HasDotDPS = hasdotDPS && isBleeding; bool hasdotDPS = CurrentCacheObject.CommonData.GetAttribute <int>(ActorAttributeType.DOTDPS) != 0; c_HasDotDPS = hasdotDPS; } return(AddToCache); }
private static bool UpdateCurrentTarget() { // Return true if we need to refresh objects and get a new target bool forceUpdate = false; try { Player.Position = ZetaDia.Me.Position; Player.CurrentHealthPct = ZetaDia.Me.HitpointsCurrentPct; if (CurrentTarget != null && CurrentTarget.IsUnit && CurrentTarget.Unit != null && CurrentTarget.Unit.IsValid) { try { DiaUnit unit = CurrentTarget.Unit; //if (unit.HitpointsCurrent <= 0d) //{ // Logger.Log(TrinityLogLevel.Debug, LogCategory.Behavior, "CurrentTarget is dead, setting null"); // CurrentTarget = null; // forceUpdate = true; //} //else //{ CurrentTarget.Position = unit.Position; CurrentTarget.HitPointsPct = unit.HitpointsCurrentPct; CurrentTarget.HitPoints = unit.HitpointsCurrent; Logger.Log(TrinityLogLevel.Debug, LogCategory.Behavior, "Updated CurrentTarget HitPoints={0:0.00} & Position={1}", CurrentTarget.HitPointsPct, CurrentTarget.Position); //} } catch (Exception) { Logger.Log(TrinityLogLevel.Debug, LogCategory.Behavior, "Error updating current target information"); CurrentTarget = null; forceUpdate = true; } } else if (CurrentTarget != null && CurrentTarget.IsUnit) { Logger.Log(TrinityLogLevel.Debug, LogCategory.Behavior, "CurrentTarget is invalid, setting null"); CurrentTarget = null; forceUpdate = true; } } catch { Logger.Log(TrinityLogLevel.Debug, LogCategory.Behavior, "Error updating current target information"); CurrentTarget = null; forceUpdate = true; } return(forceUpdate); }
private bool IsConsidered(DiaUnit u) { if (u != null && u.IsValid && IsStaticDataValid(u) && u.IsACDBased) { ACD commonData = u.CommonData; int key = commonData.DynamicId; if (!_isConsideredCache.ContainsKey(key)) { _isConsideredCache.Add(key, GetDistance(u, key) <= _killRadiusSqr && IsValid(commonData) && u.InLineOfSight); } return(_isConsideredCache[key]); } return(false); }
private float GetWeight(DiaUnit u) { ACD commonData = u.CommonData; int key = commonData.DynamicId; if (!_weightCache.ContainsKey(key)) { float weight = GetPredeterminedWeight(u); float distPct = 1 - ((1 / (_killRadiusSqr)) * GetDistance(u, key)); weight *= distPct; weight *= commonData.GetAttribute <float>(ActorAttributeType.HitpointsMaxTotal) / commonData.GetAttribute <float>(ActorAttributeType.HitpointsCur); _weightCache.Add(key, weight); } return(_weightCache[key]); }
public static int GetClusterCount(DiaUnit target, IEnumerable<DiaObject> otherUnits, ClusterType type, float clusterRange) { if (otherUnits.Count() == 0) return 0; switch (type) { case ClusterType.Radius: return GetRadiusClusterCount(target, otherUnits, clusterRange); case ClusterType.Chained: return GetChainedClusterCount(target, otherUnits, clusterRange); //case ClusterType.Cone: // return GetConeClusterCount(target, otherUnits, clusterRange); default: throw new ArgumentOutOfRangeException("type"); } }
public static int GetClusterCount(DiaUnit target, CombatContext context, ClusterType type, float clusterRange) { using (new PerformanceLogger(BelphegorSettings.Instance.Debug.IsDebugClusterLoggingActive, "GetClusterCount")) { int count; if (BelphegorSettings.Instance.EnableClusterCounts) { count = EvaluateClusterSize(target.Position, context.UnitPositions, type, clusterRange); } else { count = -1; } return(count); } }
private static bool IsValidHosileUnit(DiaUnit unit) { try { if (unit != null && unit.IsAlive && unit.IsAttackable && unit.Distance <= 12f && unit.IsHostile) { return(true); } else { return(false); } } catch { return(false); } }
private static bool IsValidMFRareUnit(DiaUnit unit) { try { if (unit != null && unit.IsValid && unit.CommonData != null && unit.CommonData.IsValid && unit.IsHostile && unit.Distance < 70f && unit.HitpointsCurrentPct < ((double)Plugin.MagicFindPerc / 100) && ((unit.CommonData.IsRare) || (unit.CommonData.IsUnique) || (unit.ActorSNO == 5984) || (unit.ActorSNO == 5985) || (unit.ActorSNO == 5987) || (unit.ActorSNO == 5987))) { return(true); } else { return(false); } } catch { return(false); } }
private static bool IsValidMFEliteUnit(DiaUnit unit) { try { if (unit != null && unit.IsValid && unit.CommonData != null && unit.CommonData.IsValid && unit.IsHostile && unit.Distance < 70f && unit.CommonData.IsElite && unit.HitpointsCurrentPct < ((double)Plugin.MagicFindPerc / 100)) { return(true); } else { return(false); } } catch { return(false); } }
private static bool IsValidElite(DiaUnit unit) { try { if (unit != null && unit.IsValid && unit.CommonData != null && unit.CommonData.IsValid && unit.IsHostile && unit.Distance < 70f && unit.CommonData.IsElite) { return(true); } else { return(false); } } catch { return(false); } }
/// <summary> /// Checks if the mob is Elite or Rare /// </summary> /// <param name="unit">DiaUnit</param> /// <returns>True if Current unit is Elite</returns> public static bool IsElite(this DiaUnit unit) { ACD commonData = unit.CommonData; if (unit.IsValid && commonData != null) { int key = commonData.DynamicId; if (!IsEliteCache.ContainsKey(key)) { MonsterAffixes affixes = commonData.MonsterAffixes; IsEliteCache.Add(key, affixes.HasFlag(MonsterAffixes.Elite) || affixes.HasFlag(MonsterAffixes.Rare) || affixes.HasFlag(MonsterAffixes.Unique) || TreasureGoblin.Contains(unit.ActorSNO)); } return(IsEliteCache[key]); } return(false); }
/// <summary> Gets a monster type for the provided unit. </summary> /// <param name="unit"> The unit. </param> /// <returns> The monster type. </returns> private MonsterType GetMonsterType(DiaUnit unit) { int actorSNO = unit.ActorSNO; MonsterType type; if (!MonsterTypeCache.TryGetValue(actorSNO, out type)) { SNORecordMonster monsterInfo = unit.MonsterInfo; if (monsterInfo != null) { type = monsterInfo.MonsterType; } MonsterTypeCache.Add(actorSNO, type); } return(type); }
private static bool UpdateCurrentTarget() { // Return true if we need to refresh objects and get a new target bool forceUpdate = false; try { PlayerStatus.CurrentPosition = ZetaDia.Me.Position; PlayerStatus.CurrentHealthPct = ZetaDia.Me.HitpointsCurrentPct; if (CurrentTarget != null && CurrentTarget.Type == GObjectType.Unit && CurrentTarget.Unit != null && CurrentTarget.Unit.IsValid) { DiaUnit unit = CurrentTarget.Unit; if (unit.IsDead) { DbHelper.Log(TrinityLogLevel.Debug, LogCategory.Behavior, "CurrentTarget is dead, setting null"); CurrentTarget = null; forceUpdate = true; } else { CurrentTarget.Position = unit.Position; CurrentTarget.HitPointsPct = unit.HitpointsCurrentPct; CurrentTarget.HitPoints = unit.HitpointsCurrent; DbHelper.Log(TrinityLogLevel.Debug, LogCategory.Behavior, "Updated CurrentTarget HitPoints={0:0.00} & Position={1}", CurrentTarget.HitPointsPct, CurrentTarget.Position); } } else if (CurrentTarget != null && CurrentTarget.Type == GObjectType.Unit) { DbHelper.Log(TrinityLogLevel.Debug, LogCategory.Behavior, "CurrentTarget is invalid, setting null"); CurrentTarget = null; forceUpdate = true; } } catch { DbHelper.Log(TrinityLogLevel.Debug, LogCategory.Behavior, "Error updating current target information"); CurrentTarget = null; forceUpdate = true; } return(forceUpdate); }
private MonsterSize GetMonsterSize(DiaUnit unit) { int actorSNO = unit.ActorSNO; MonsterSize size; if (MonsterSizeCache.TryGetValue(actorSNO, out size)) { return(size); } SNORecordMonster monsterInfo = unit.MonsterInfo; if (monsterInfo != null) { size = monsterInfo.MonsterSize; } MonsterSizeCache.Add(actorSNO, size); return(size); }
private static bool MinionCheck(Pet minion, DiaUnit unit) { switch (minion) { case Pet.MysticAlly: return(MysticAlly.Contains(unit.ActorSNO)); case Pet.Hydra: return(Hydra.Contains(unit.ActorSNO)); case Pet.DH_Caltrops: return(DH_Caltrops.Contains(unit.ActorSNO)); case Pet.DH_Companion: return(DH_Companion.Contains(unit.ActorSNO)); case Pet.DH_Sentry: return(DH_Sentry.Contains(unit.ActorSNO)); case Pet.DH_SpikeTrap: return(DH_SpikeTrap.Contains(unit.ActorSNO)); case Pet.Gargantuan: return(Gargantuan.Contains(unit.ActorSNO)); case Pet.ZombieDogs: return(ZombieDogs.Contains(unit.ActorSNO)); case Pet.Enchantress: return(unit.ActorSNO == 4482); case Pet.Templer: return(unit.ActorSNO == 52693); case Pet.Scoundrel: return(unit.ActorSNO == 52694); default: return(false); } }
private float GetSizeWeight(DiaUnit u) { float sizeWeight = 1f; MonsterSize ms = u.GetMonsterSize(); switch (ms) { case MonsterSize.Boss: sizeWeight = 1.5f; break; case MonsterSize.Swarm: sizeWeight = 1.4f; break; case MonsterSize.Ranged: sizeWeight = 1.3f; break; } return(sizeWeight); }
public CachedUnit(DiaUnit dunit) { try{ if (dunit == null) { CachingFailed = true; return; } var teamId = dunit.CommonData.GetAttribute<int>(ActorAttributeType.TeamID); Hostile = BotManager.UnitManager.IsTeamHostile(teamId); if (Hostile) MonsterAffixes = dunit.CommonData.MonsterAffixEntries.ToArray(); base.BaseInit(dunit); } catch (Exception e) { CachingFailed = true; return; } }
private float GetPredeterminedWeight(DiaUnit u) { ACD commonData = u.CommonData; int dynId = commonData.DynamicId; if (!_predeterminedWeightCache.ContainsKey(dynId)) { float weight = 1f; weight *= u.IsElite() ? 1.5f : 0.5f; weight *= GetSizeWeight(u); float prioMulti = ProfileManager.CurrentProfile.TargetPriorities.Where(prio => prio.ActorId == u.ActorSNO).Select( prio => prio.Multiplier).FirstOrDefault(); if (prioMulti != 0f) { weight *= prioMulti; } _predeterminedWeightCache.Add(dynId, weight); } return(_predeterminedWeightCache[dynId]); }
/// <summary> Gets a weight for unit. </summary> /// <param name="unit"> The unit. </param> /// <param name="priorities"> </param> /// <returns> The weight for unit. </returns> private double GetWeightForUnit(DiaUnit unit, IEnumerable <TargetPriority> priorities) { double weight = 0d; weight += (int)GetMonsterSize(unit) * 20; weight -= unit.HitpointsCurrentPct * 100; weight += IsSummoner(unit) ? 100 : 0; weight += IsTreasureGoblin(unit) ? 200 : 0; weight += IsElite(unit.CommonData) ? 300 : 0; // Heavily score invulnerable units but don't remove them. weight -= unit.IsInvulnerable ? 10000 : 0; TargetPriority multiplier = priorities.FirstOrDefault(m => m.ActorId == unit.ActorSNO); if (multiplier != null) { weight *= multiplier.Multiplier; } return(weight); }
public static Vector3 FindNearestHostileUnitInRadius(Vector3 center, float radius) { using (new PerformanceLogger("FindNearestHostileUnitInRadius")) { try { DiaUnit actor = ZetaDia.Actors.GetActorsOfType <DiaUnit>(true).Where( u => u.IsValid && u.CommonData != null && u.CommonData.IsValid && center.Distance(u.Position) <= radius && AdvDia.MyPosition.Distance(u.Position) > CharacterSettings.Instance.KillRadius && u.IsHostile && !u.IsDead && u.HitpointsCurrent > 1 && !u.IsInvulnerable && u.CommonData.GetAttribute <int>(ActorAttributeType.Invulnerable) <= 0 && u.CommonData.GetAttribute <int>(ActorAttributeType.Untargetable) <= 0 && !u.Name.Contains("bloodSpring") && !u.Name.Contains("firewall") && !u.Name.Contains("FireGrate") ) .OrderBy(u => center.Distance(u.Position)) .FirstOrDefault(); if (actor != null) { return(actor.Position); } } catch (Exception) { return(Vector3.Zero); } return(Vector3.Zero); } }
/// <summary> Query if 'unit' is a valid actor. </summary> /// <param name="unit">The unit. </param> /// <param name="blacklist"> The blacklist. </param> /// <returns> true if a valid actor, false if not. </returns> public bool IsValidActor(DiaUnit unit, HashSet <int> blacklist) { if (unit.ACDGuid == -1) { return(false); } int actorSNO = unit.ActorSNO; // Blacklisted units if (blacklist.Contains(actorSNO)) { return(false); } if (!IsValidMonsterType(unit)) { return(false); } if (unit.ZDiff > 20f) { return(false); } if (!unit.IsAttackable()) { return(false); } Vector3 raycastTo = unit.Position; Vector3 raycastFrom = ZetaDia.Me.Position; raycastFrom.Z += 2.0f; raycastTo.Z += 2.0f; return(ZetaDia.Physics.Raycast(raycastFrom, raycastTo, NavCellFlags.AllowWalk)); }
public static bool IsUnitInteractable(DiaUnit unit) { if (!unit.IsFullyValid()) { return(false); } if ((unit.CommonData.MinimapVisibilityFlags & 0x80) != 0) { return(true); } if (unit.CommonData.GetAttribute <int>(ActorAttributeType.MinimapActive) == 1) { return(true); } if (unit.MarkerType != MarkerType.Invalid && unit.MarkerType != MarkerType.None && unit.MarkerType != MarkerType.Asterisk) { return(true); } if (InteractWhitelist.Contains(unit.ActorSnoId)) { return(true); } return(false); }
private static bool RefreshUnitAttributes(bool AddToCache = true, DiaUnit unit = null) { if (!DataDictionary.IgnoreUntargettableAttribute.Contains(CurrentCacheObject.ActorSNO) && unit.IsUntargetable) { AddToCache = false; c_IgnoreSubStep = "IsUntargetable"; return AddToCache; } // don't check for invulnerability on shielded and boss units, they are treated seperately if (!c_unit_HasShieldAffix && unit.IsInvulnerable) { AddToCache = false; c_IgnoreSubStep = "IsInvulnerable"; return AddToCache; } bool isBurrowed; if (!CacheData.UnitIsBurrowed.TryGetValue(CurrentCacheObject.RActorGuid, out isBurrowed)) { isBurrowed = unit.IsBurrowed; // if the unit is NOT burrowed - we can attack them, add to cache (as IsAttackable) if (!isBurrowed) { CacheData.UnitIsBurrowed.Add(CurrentCacheObject.RActorGuid, isBurrowed); } } if (isBurrowed) { AddToCache = false; c_IgnoreSubStep = "IsBurrowed"; return AddToCache; } // only check for DotDPS/Bleeding in certain conditions to save CPU for everyone else // barbs with rend // All WD's // Monks with Way of the Hundred Fists + Fists of Fury if (AddToCache && ((Player.ActorClass == ActorClass.Barbarian && Hotbar.Contains(SNOPower.Barbarian_Rend)) || Player.ActorClass == ActorClass.Witchdoctor || (Player.ActorClass == ActorClass.Monk && CacheData.Hotbar.ActiveSkills.Any(s => s.Power == SNOPower.Monk_WayOfTheHundredFists && s.RuneIndex == 0))) ) { bool hasdotDPS = CacheObjectHasDOTDPS(); c_HasDotDPS = hasdotDPS; } return AddToCache; }