public DebugUnitEntry(CacheUnit entry) { SNOID = entry.SNOID; Name = entry.InternalName; ActorType = PluginActorType.Monster; UnitFlags = entry.UnitPropertyFlags.HasValue ? entry.UnitPropertyFlags.Value : UnitFlags.None; TargetType = TargetType.Unit; }
} // of overloaded constructor public UnitCluster(double p_Dist, CacheUnit unit) : base(p_Dist, unit) { ListUnits = new List <CacheUnit>(); ListUnits.Add(unit); NearestMonsterDistance = unit.CentreDistance; Info = new ClusterInfo(); Info.Update(ref unit); } // of overloaded constructor
public void UpdateUnitPointLists(ClusterConditions CC) { if (ListUnits.Count == 0) { return; } List <int> RemovalIndexList = new List <int>(); bool changeOccured = false; foreach (var item in ListUnits) { if (!item.IsStillValid() || (!CC.IgnoreNonTargetable || !item.IsTargetable.Value)) { RemovalIndexList.Add(ListUnits.IndexOf(item)); RAGUIDS.Remove(item.RAGUID); changeOccured = true; } } if (changeOccured) { RemovalIndexList.Sort(); RemovalIndexList.Reverse(); foreach (var item in RemovalIndexList) { //ListCacheObjects.RemoveAt(item); ListUnits.RemoveAt(item); ListPoints.RemoveAt(item); } if (ListUnits.Count > 1) { //Logger.DBLog.InfoFormat("Updating Cluster"); //Reset Vars Info = new ClusterInfo(); NearestMonsterDistance = -1f; //Set default using First Unit CacheUnit firstUnit = ListUnits[0]; MidPoint = firstUnit.PointPosition; RAGUIDS.Add(firstUnit.RAGUID); NearestMonsterDistance = firstUnit.CentreDistance; Info.Update(ref firstUnit); //Iterate thru the remaining for (int i = 1; i < ListUnits.Count - 1; i++) { this.UpdateProperties(ListUnits[i]); } } } }
internal CacheUnitAlloc(int maxUnitCount) { _Pool = new CacheUnit[maxUnitCount]; for (int i = 0; i < maxUnitCount; i++) { _Pool[i] = new CacheUnit(i); _UnUsedIdStack.Push(i); } }
private static QueryCache LoadCache() { string type = AppSetting.Default["App.CacheType"]; string cache = AppSetting.Default["App.Cache"]; if (string.IsNullOrWhiteSpace(type)) { type = BuffaloCacheTypes.Web; } return(CacheUnit.CreateCache(type, cache)); }
public void CheckEntry(CacheUnit entry) { var d = new DebugUnitEntry(entry); if (Units.Entries.Contains(d)) { return; } Units.Entries.Add(d); DebugData_Units.SerializeToXML(Units); }
private void UpdateProperties(CacheUnit unit) { float distance = unit.CentreDistance; if (distance < this.NearestMonsterDistance) { this.NearestMonsterDistance = distance; } Info.Update(ref unit, true); }
} // of overloaded constructor private bool ContainsUnit(CacheUnit unit) { bool u_Exists = false; if (base.RAGUIDS.Contains(unit.RAGUID)) { u_Exists = true; } return(u_Exists); }
public bool CheckCustomCombatMethod(CacheUnit unit) { foreach (Func <CacheUnit, bool> item in FcriteriaCombat.GetInvocationList()) { if (!item(unit)) { return(false); } } return(true); }
private void button1_Click(object sender, EventArgs e) { //INetFwPolicy2 firewallPolicy = (INetFwPolicy2)Activator.CreateInstance(Type.GetTypeFromProgID("HNetCfg.FwPolicy2")); //INetFwRule2 firewallRule = null; //firewallRule = firewallPolicy.Rules.Item("Bonjour 服务") as INetFwRule2; QueryCache cache = CacheUnit.CreateCache(BuffaloCacheTypes.Redis, "server=39.108.125.58:6379;throw=1;"); string key = "App.BkIP"; cache.SetValue <long>(key, 100); object cnt = cache.GetValue(key); }
public static List <UnitCluster> RunKmeans <T>(List <T> objList, double distance) where T : CacheObject { List <UnitCluster> LC_ = new List <UnitCluster>(); if (objList.Count == 0) { return(LC_); } List <CacheObject> l_ListUnits = new List <CacheObject>(objList.ToArray()); if (l_ListUnits.Count == 0) { return(LC_); } // for starters, take a point to create one cluster CacheUnit l_P1 = (CacheUnit)l_ListUnits[0]; l_ListUnits.RemoveAt(0); // so far, we have a one-point cluster LC_.Add(new UnitCluster(distance, l_P1)); #region Main Loop // the algorithm is inside this loop List <UnitCluster> l_ListAttainableClusters; UnitCluster l_c; foreach (CacheUnit p in l_ListUnits) { l_ListAttainableClusters = new List <UnitCluster>(); l_ListAttainableClusters = LC_.FindAll(x => x.IsPointReachable(p.PointPosition)); LC_.RemoveAll(x => x.IsPointReachable(p.PointPosition)); l_c = new UnitCluster(distance, p); // merge point's "reachable" clusters if (l_ListAttainableClusters.Count > 0) { l_c.AnnexCluster(l_ListAttainableClusters.Aggregate((c, x) => c = MergeClusters(x, c))); } LC_.Add(l_c); //Logger.DBLog.InfoFormat("Cluster Found: Total Points {0} with Centeroid {1}", l_c.ListPoints.Count, l_c.Centeroid.ToString()); l_ListAttainableClusters = null; l_c = null; } // of loop over candidate points //LC_=LC_.OrderByDescending(o => o.ListPoints.Count).ToList(); #endregion return(LC_); }
public void Add(CacheUnit unit) { lock (mutex) { int cnt = list.Count; for (int i = 0; i < cnt; i++) { if (list[i].deathTime >= unit.deathTime) { list.Insert(i, unit); return; } } list.Add(unit); } }
/// <summary> /// Adds point to this cluster only if it is "reachable" /// (if point is inside a circle of radius Dist of any cluster's points ) /// </summary> /// <param name="p_Point">The point to be added to this cluster</param> /// <returns>false if point can't be added (that is either already in cluster /// or it is unreachable from any of the cluster's points)</returns> internal override bool AddObject(CacheObject obj) { bool l_bSuccess = base.AddObject(obj); if (l_bSuccess) //&&Bot.Targeting.Environment.UnitRAGUIDs.Contains(unit.RAGUID)) { CacheUnit unitobj = (CacheUnit)obj; ListUnits.Add(unitobj); UpdateProperties(unitobj); } else { return(l_bSuccess = false); } return(true); } // of AddPoint()
///<summary> ///Returns a power for Combat Buffing. ///</summary> internal bool FindCombatBuffPower(CacheUnit unit, out Skill BuffAbility) { BuffAbility = null; foreach (var item in Abilities.Values.Where(A => A.IsBuff && A.UseageType.HasFlag(SkillUseage.Combat | SkillUseage.Anywhere))) { if (item.CheckPreCastConditionMethod()) { if (item.CheckCombatConditionMethod(unit: unit)) { BuffAbility = item; Skill.SetupAbilityForUse(ref BuffAbility, unit); return(true); } } } return(false); }
///<summary> ///Sets criteria based on object given. ///</summary> internal virtual Skill AbilitySelector(CacheUnit obj, bool IgnoreOutOfRange = false) { //Reset default attack can use CanUseDefaultAttack = !HotBar.HotbarPowers.Contains(DefaultAttack.Power) ? false : true; //Reset waiting for special! bWaitingForSpecial = false; ConditionCriteraTypes criterias = ConditionCriteraTypes.All; //Although the unit is a cluster exception.. we should verify it is not a clustered object. if (obj.IsClusterException && obj.BeingIgnoredDueToClusterLogic) { criterias = ConditionCriteraTypes.SingleTarget; } return(AbilitySelector(criterias, IgnoreOutOfRange)); }
internal List <Skill> ReturnAllUsableAbilities(CacheUnit obj, bool IgnoreOutOfRange = false) { //Reset default attack can use CanUseDefaultAttack = !Abilities.ContainsKey(DefaultAttack.Power) ? false : true; ConditionCriteraTypes criterias = ConditionCriteraTypes.All; //Although the unit is a cluster exception.. we should verify it is not a clustered object. if (obj.IsClusterException && obj.BeingIgnoredDueToClusterLogic) { criterias = ConditionCriteraTypes.SingleTarget; } List <Skill> UsableAbilities = new List <Skill>(); foreach (var item in SortedAbilities) { //Check precast conditions if (!item.CheckPreCastConditionMethod()) { continue; } //Check Combat Conditions! if (!item.CheckCombatConditionMethod(criterias)) { continue; } //Check if we can execute or if it requires movement if (IgnoreOutOfRange) { if (item.DestinationVector != Bot.Character.Data.Position) { continue; } } Skill ability = item; Skill.SetupAbilityForUse(ref ability); UsableAbilities.Add(ability); } return(UsableAbilities); }
public void Update(ref CacheUnit unit, bool refreshproperties = false) { UnitCounter++; if (unit.UnitMaxHitPointAverageWeight < 0) { WeakCounter++; } else if (unit.UnitMaxHitPointAverageWeight > 0) { StrongCounter++; } if (unit.IsEliteRareUnique) { ElitesCounter++; } else if (unit.IsBoss) { BossCounter++; } if (unit.IsFast) { FastCounter++; } if (unit.IsRanged) { RangedCounter++; } if (FunkyGame.Hero.Class.UsesDOTDPSAbility && unit.HasDOTdps.HasValue && unit.HasDOTdps.Value) { DOTDPSCounter++; } if (refreshproperties) { UpdateProperties(); } }
///<summary> ///Adds/Updates CacheObjects inside collection by Iteration of RactorList ///This is the method that caches all live data about an object! ///</summary> internal static bool UpdateCacheObjectCollection() { HashSet <int> hashDoneThisRactor = new HashSet <int>(); using (ZetaDia.Memory.AcquireFrame(true)) { if (!ZetaDia.IsInGame || ZetaDia.IsLoadingWorld || !ZetaDia.Me.IsValid) { return(false); } foreach (Actor thisActor in ZetaDia.Actors.RActorList) { int tmp_raGUID; DiaObject thisObj; if (!thisActor.IsValid) { continue; } //Convert to DiaObject thisObj = (DiaObject)thisActor; tmp_raGUID = thisObj.RActorGuid; // See if we've already checked this ractor, this loop if (hashDoneThisRactor.Contains(tmp_raGUID)) { continue; } hashDoneThisRactor.Add(tmp_raGUID); //Update RactorGUID and check blacklisting.. if (BlacklistCache.IsRAGUIDBlacklisted(tmp_raGUID)) { continue; } CacheObject tmp_CachedObj; if (!Objects.TryGetValue(tmp_raGUID, out tmp_CachedObj)) { Vector3 tmp_position; int tmp_acdguid; int tmp_SNOID; #region SNO //Lookup SNO try { tmp_SNOID = thisObj.ActorSNO; } catch (NullReferenceException) { //Logger.DBLog.InfoFormat("Failure to get SNO from object! RaGUID: {0}", tmp_raGUID); continue; } #endregion //check our SNO blacklist if (BlacklistCache.IsSNOIDBlacklisted(tmp_SNOID) && !CacheIDLookup.hashSummonedPets.Contains(tmp_SNOID)) { continue; } #region Position try { tmp_position = thisObj.Position; } catch (NullReferenceException) { //Logger.DBLog.InfoFormat("Failure to get position vector for RAGUID {0}", tmp_raGUID); continue; } #endregion #region AcdGUID try { tmp_acdguid = thisObj.ACDGuid; } catch (NullReferenceException) { //Logger.DBLog.InfoFormat("Failure to get ACDGUID for RAGUID {0}", tmp_raGUID); continue; } #endregion tmp_CachedObj = new CacheObject(tmp_SNOID, tmp_raGUID, tmp_acdguid, tmp_position); } else { //Reset unseen var tmp_CachedObj.LoopsUnseen = 0; } //Validate try { if (thisObj.CommonData == null || thisObj.CommonData.ACDGuid != thisObj.ACDGuid) { continue; } } catch (NullReferenceException) { continue; } //Check if this object is a summoned unit by a player... #region SummonedUnits if (tmp_CachedObj.IsSummonedPet) { // Get the summoned-by info, cached if possible if (!tmp_CachedObj.SummonerID.HasValue) { try { tmp_CachedObj.SummonerID = thisObj.CommonData.GetAttribute <int>(ActorAttributeType.SummonedByACDID); } catch (Exception ex) { //Logger.DBLog.InfoFormat("[Funky] Safely handled exception getting summoned-by info [" + tmp_CachedObj.SNOID.ToString(CultureInfo.InvariantCulture) + "]"); //Logger.DBLog.DebugFormat(ex.ToString()); continue; } } //See if this summoned unit was summoned by the bot. if (Bot.Character.Data.iMyDynamicID == tmp_CachedObj.SummonerID.Value) { //Now modify the player data pets count.. if (Bot.Character.Class.AC == ActorClass.Monk) { Bot.Character.Data.PetData.MysticAlly++; } else if (Bot.Character.Class.AC == ActorClass.DemonHunter) { if (CacheIDLookup.hashDHPets.Contains(tmp_CachedObj.SNOID)) { Bot.Character.Data.PetData.DemonHunterPet++; } else if (CacheIDLookup.hashDHSpikeTraps.Contains(tmp_CachedObj.SNOID) && tmp_CachedObj.CentreDistance <= 50f) { Bot.Character.Data.PetData.DemonHunterSpikeTraps++; } } else if (Bot.Character.Class.AC == ActorClass.Witchdoctor) { if (CacheIDLookup.hashZombie.Contains(tmp_CachedObj.SNOID)) { Bot.Character.Data.PetData.ZombieDogs++; } else if (CacheIDLookup.hashGargantuan.Contains(tmp_CachedObj.SNOID)) { Bot.Character.Data.PetData.Gargantuan++; } } else if (Bot.Character.Class.AC == ActorClass.Wizard) { //only count when range is within 45f (so we can summon a new one) if (CacheIDLookup.hashWizHydras.Contains(tmp_CachedObj.SNOID) && tmp_CachedObj.CentreDistance <= 45f) { Bot.Character.Data.PetData.WizardHydra++; } } } //We return regardless if it was summoned by us or not since this object is not anything we want to deal with.. tmp_CachedObj.NeedsRemoved = true; continue; } #endregion //Update any SNO Data. #region SNO_Cache_Update if (tmp_CachedObj.ref_DiaObject == null || tmp_CachedObj.ContainsNullValues()) { if (!tmp_CachedObj.UpdateData(thisObj, tmp_CachedObj.RAGUID)) { continue; } } else if (!tmp_CachedObj.IsFinalized) { //Finalize this data by recreating it and updating the Sno cache with a new finalized entry, this also clears our all Sno cache dictionaries since we no longer need them! cacheSnoCollection.FinalizeEntry(tmp_CachedObj.SNOID); } #endregion //Special Cache for Interactable Server Objects if (CheckTargetTypeFlag(tmp_CachedObj.targetType.Value, TargetType.ServerInteractable)) { if (!Bot.Game.Profile.InteractableObjectCache.ContainsKey(tmp_CachedObj.RAGUID)) { Bot.Game.Profile.InteractableObjectCache.Add(tmp_CachedObj.RAGUID, tmp_CachedObj); } //Do not add to main cache! continue; } //Objects with static positions already cached don't need to be updated here. if (!tmp_CachedObj.NeedsUpdate) { continue; } //Obstacles -- (Not an actual object we add to targeting.) if (CheckTargetTypeFlag(tmp_CachedObj.targetType.Value, TargetType.Avoidance) || tmp_CachedObj.IsObstacle || tmp_CachedObj.HandleAsAvoidanceObject) { #region Obstacles CacheObstacle thisObstacle; //Do we have this cached? if (!Obstacles.TryGetValue(tmp_CachedObj.RAGUID, out thisObstacle)) { AvoidanceType AvoidanceType = AvoidanceType.None; if (tmp_CachedObj.IsAvoidance) { AvoidanceType = AvoidanceCache.FindAvoidanceUsingSNOID(tmp_CachedObj.SNOID); if (AvoidanceType == AvoidanceType.None) { AvoidanceType = AvoidanceCache.FindAvoidanceUsingName(tmp_CachedObj.InternalName); if (AvoidanceType == AvoidanceType.None) { continue; } } } if (tmp_CachedObj.IsAvoidance && tmp_CachedObj.IsProjectileAvoidance) { //Ranged Projectiles require more than simple bounding points.. so we create it as avoidance zone to cache it with properties. //Check for intersection.. try { ActorMovement thisMovement = thisObj.Movement; Vector2 Direction = thisMovement.DirectionVector; Ray R = new Ray(tmp_CachedObj.Position, Direction.ToVector3()); double Speed; //Lookup Cached Speed, or add new entry. if (!dictProjectileSpeed.TryGetValue(tmp_CachedObj.SNOID, out Speed)) { Speed = thisMovement.DesiredSpeed; dictProjectileSpeed.Add(tmp_CachedObj.SNOID, Speed); } thisObstacle = new CacheAvoidance(tmp_CachedObj, AvoidanceType, R, Speed); Obstacles.Add(thisObstacle); } catch { Logger.Write(LogLevel.Cache, "Failed to create projectile avoidance with rotation and speed. {0}", tmp_CachedObj.InternalName); } } else if (tmp_CachedObj.IsAvoidance) { //Poison Gas Can Be Friendly... if (AvoidanceType == AvoidanceType.PoisonGas) { int TeamID = 0; try { TeamID = thisObj.CommonData.GetAttribute <int>(ActorAttributeType.TeamID); } catch { Logger.Write(LogLevel.Cache, "Failed to retrieve TeamID attribute for object {0}", thisObstacle.InternalName); } //ID of 1 means its non-hostile! (-1?) 2?? //if (TeamID==1||TeamID==-1) if (TeamID != 10) { //Logger.Write(LogLevel.None, "Ignoring Avoidance {0} due to Friendly TeamID match!", tmp_CachedObj.InternalName); BlacklistCache.AddObjectToBlacklist(tmp_CachedObj.RAGUID, BlacklistType.Permanent); continue; } } thisObstacle = new CacheAvoidance(tmp_CachedObj, AvoidanceType); Obstacles.Add(thisObstacle); } else { //Obstacles. thisObstacle = new CacheServerObject(tmp_CachedObj); Obstacles.Add(thisObstacle); } } continue; #endregion } if (tmp_CachedObj.ObjectShouldBeRecreated) { //Specific updates if (tmp_CachedObj.Actortype.Value == ActorType.Item) { tmp_CachedObj = new CacheItem(tmp_CachedObj); } else if (tmp_CachedObj.Actortype.Value == ActorType.Monster) { tmp_CachedObj = new CacheUnit(tmp_CachedObj); } else if (tmp_CachedObj.Actortype.Value == ActorType.Gizmo) { if (CheckTargetTypeFlag(tmp_CachedObj.targetType.Value, TargetType.Interactables)) { tmp_CachedObj = new CacheInteractable(tmp_CachedObj); } else { tmp_CachedObj = new CacheDestructable(tmp_CachedObj); } } //Update Properties tmp_CachedObj.UpdateProperties(); } if (!tmp_CachedObj.UpdateData()) { if (!tmp_CachedObj.IsStillValid()) { tmp_CachedObj.NeedsRemoved = true; } continue; } //Obstacle cache if (tmp_CachedObj.Obstacletype.Value != ObstacleType.None && (CheckTargetTypeFlag(tmp_CachedObj.targetType.Value, TargetType.ServerObjects))) { CacheObstacle thisObstacleObj; if (!Obstacles.TryGetValue(tmp_CachedObj.RAGUID, out thisObstacleObj)) { CacheServerObject newobj = new CacheServerObject(tmp_CachedObj); Obstacles.Add(tmp_CachedObj.RAGUID, newobj); //Add nearby objects to our collection (used in navblock/obstaclecheck methods to reduce queries) if (CacheIDLookup.hashSNONavigationObstacles.Contains(newobj.SNOID)) { Navigation.MGP.AddCellWeightingObstacle(newobj.SNOID, newobj.Radius); } } else { if (thisObstacleObj.targetType.Value == TargetType.Unit) { //Since units position requires updating, we update using the CacheObject thisObstacleObj.Position = tmp_CachedObj.Position; Obstacles[tmp_CachedObj.RAGUID] = thisObstacleObj; } } } //cache it if (Objects.ContainsKey(tmp_CachedObj.RAGUID)) { Objects[tmp_CachedObj.RAGUID] = tmp_CachedObj; } else { Objects.Add(tmp_CachedObj.RAGUID, tmp_CachedObj); } } //End of Loop } // End of Framelock //Tally up unseen objects. var UnseenObjects = Objects.Keys.Where(O => !hashDoneThisRactor.Contains(O)).ToList(); if (UnseenObjects.Any()) { for (int i = 0; i < UnseenObjects.Count(); i++) { Objects[UnseenObjects[i]].LoopsUnseen++; } } //Trim our collection every 5th refresh. UpdateLoopCounter++; if (UpdateLoopCounter > 4) { UpdateLoopCounter = 0; //Now flag any objects not seen for 5 loops. Gold/Globe only 1 loop. foreach (var item in Objects.Values.Where(CO => (CO.LoopsUnseen >= 5 || //5 loops max.. (CO.targetType.HasValue && (CheckTargetTypeFlag(CO.targetType.Value, TargetType.Gold | TargetType.Globe)) && CO.LoopsUnseen > 0)))) //gold/globe only 1 loop! { item.NeedsRemoved = true; } } return(true); }
internal static TargetProperties EvaluateUnitProperties(CacheUnit unit) { TargetProperties properties = TargetProperties.None; if (unit.IsBoss) { properties |= TargetProperties.Boss; } if (unit.IsBurrowableUnit) { properties |= TargetProperties.Burrowing; } if (unit.MonsterMissileDampening) { properties |= TargetProperties.MissileDampening; } if (unit.IsMissileReflecting) { properties |= TargetProperties.MissileReflecting; } if (unit.MonsterShielding) { properties |= TargetProperties.Shielding; } if (unit.IsStealthableUnit) { properties |= TargetProperties.Stealthable; } if (unit.IsSucideBomber) { properties |= TargetProperties.SucideBomber; } if (unit.IsTreasureGoblin) { properties |= TargetProperties.TreasureGoblin; } if (unit.IsFast) { properties |= TargetProperties.Fast; } if (unit.IsEliteRareUnique) { properties |= TargetProperties.RareElite; } if (unit.MonsterUnique) { properties |= TargetProperties.Unique; } if (unit.CurrentHealthPct.HasValue && unit.CurrentHealthPct.Value == 1d) { properties |= TargetProperties.FullHealth; } if (unit.UnitMaxHitPointAverageWeight < 0) { properties |= TargetProperties.Weak; } if (unit.IsRanged) { properties |= TargetProperties.Ranged; } if (unit.IsTargetableAndAttackable) { properties |= TargetProperties.TargetableAndAttackable; } if (unit.HasDOTdps.HasValue && unit.HasDOTdps.Value) { properties |= TargetProperties.DOTDPS; } if (unit.RadiusDistance < 10f) { properties |= TargetProperties.CloseDistance; } if (unit.MonsterReflectDamage) { properties |= TargetProperties.ReflectsDamage; } if (unit.MonsterElectrified) { properties |= TargetProperties.Electrified; } if (unit.MonsterNormal) { properties |= TargetProperties.Normal; } if (unit.CurrentHealthPct.HasValue && unit.CurrentHealthPct.Value < 0.25d) { properties |= TargetProperties.LowHealth; } return(properties); }
public TargetingInfo(CacheUnit unit) { _unit = unit; }
public TargetingInfo() { _unit = new CacheUnit(ObjectCache.FakeCacheObject); }
///<summary> ///Check Combat ///</summary> public bool CheckCombatConditionMethod(ConditionCriteraTypes conditions = ConditionCriteraTypes.All, CacheUnit unit = null) { //Order in which tests are conducted.. //Units in Range (Not Cluster) //Clusters //Single Target //If all are null or any of them are successful, then we test Custom Conditions //Custom Condition //Reset Last Condition LastConditionPassed = ConditionCriteraTypes.None; bool TestCustomConditions = false; bool FailedCondition = false; if (conditions.HasFlag(ConditionCriteraTypes.Cluster) && ClusterConditions.Count > 0) { foreach (var condition in ClusterConditions) { FailedCondition = false; foreach (Func <bool> item in condition.Criteria.GetInvocationList()) { if (!item()) { FailedCondition = true; break; } } //Last Condition did not fail.. (Success!) if (!FailedCondition) { LastConditionPassed = ConditionCriteraTypes.Cluster; LastClusterConditionSuccessful = condition; TestCustomConditions = true; break; } } } if ((!TestCustomConditions || FailedCondition) && conditions.HasFlag(ConditionCriteraTypes.SingleTarget) && SingleUnitCondition.Count > 0) { //We iterate each condition in the list and test the criteria. foreach (var condition in SingleUnitCondition) { FailedCondition = false; foreach (Func <CacheUnit, bool> item in condition.Criteria.GetInvocationList()) { if (!item(unit)) { FailedCondition = true; break; } } //Last Condition did not fail.. (Success!) if (!FailedCondition) { LastConditionPassed = ConditionCriteraTypes.SingleTarget; TestCustomConditions = true; break; } } } //If TestCustomCondtion failed, and FailedCondition is true.. then we tested a combat condition. //If FailedCondition is false, then we never tested a condition. if (!TestCustomConditions && !TestCustomCombatConditions) { return(false); //&&FailedCondition } foreach (Func <CacheUnit, bool> item in FcriteriaCombat.GetInvocationList()) { if (!item(unit)) { return(false); } } return(true); }
internal void Return(CacheUnit cacheUnit) { _UnUsedIdStack.Push(cacheUnit.UnitId); }
///<summary> ///Selects first Ability that is successful in precast and combat testing. ///</summary> private Skill AbilitySelector(ConditionCriteraTypes criteria = ConditionCriteraTypes.All, bool IgnoreOutOfRange = false, CacheUnit unit = null) { Skill returnAbility = DefaultAttack; foreach (var item in SortedAbilities) { //Check precast conditions if (!item.CheckPreCastConditionMethod()) { continue; } //Check Combat Conditions! if (!item.CheckCombatConditionMethod(criteria, unit)) { continue; } //Check if we can execute or if it requires movement if (IgnoreOutOfRange) { if (item.DestinationVector != FunkyGame.Hero.Position) { continue; } } returnAbility = item; break; } //Setup Ability (sets vars according to current cache) Skill.SetupAbilityForUse(ref returnAbility, unit); return(returnAbility); }
// ///<summary> ///Adds/Updates CacheObjects inside collection by Iteration of RactorList ///This is the method that caches all live data about an object! ///</summary> internal static bool UpdateCacheObjectCollection() { //Update Character (just incase it wasnt called before..) FunkyGame.Hero.Update(false, true); Obstacles.AttemptToClearEntries(); HashSet <int> hashDoneThisRactor = new HashSet <int>(); using (ZetaDia.Memory.AcquireFrame(true)) { if (!ZetaDia.IsInGame || ZetaDia.IsLoadingWorld || !ZetaDia.Me.IsValid) { return(false); } foreach (Actor thisActor in ZetaDia.Actors.RActorList) { int tmp_raGUID; DiaObject thisObj; if (!thisActor.IsValid) { continue; } //Convert to DiaObject thisObj = (DiaObject)thisActor; tmp_raGUID = thisObj.RActorGuid; // See if we've already checked this ractor, this loop if (hashDoneThisRactor.Contains(tmp_raGUID)) { continue; } hashDoneThisRactor.Add(tmp_raGUID); //Update RactorGUID and check blacklisting.. if (BlacklistCache.IsRAGUIDBlacklisted(tmp_raGUID)) { continue; } CacheObject tmp_CachedObj; if (!Objects.TryGetValue(tmp_raGUID, out tmp_CachedObj)) { ActorType Actortype; Vector3 tmp_position; int tmp_acdguid; int tmp_SNOID; #region SNO //Lookup SNO try { tmp_SNOID = thisObj.ActorSNO; } catch (Exception ex) { Logger.Write(LogLevel.Cache, "Safely handled getting SNO for {0}", tmp_raGUID); //Logger.DBLog.InfoFormat("Failure to get SNO from object! RaGUID: {0}", tmp_raGUID); continue; } #endregion //check our SNO blacklist (exclude pets?) if (BlacklistCache.IsSNOIDBlacklisted(tmp_SNOID)) { continue; } #region Position try { tmp_position = thisObj.Position; } catch (Exception ex) { Logger.Write(LogLevel.Cache, "Safely handled getting Position for {0}", tmp_SNOID); continue; } #endregion #region AcdGUID try { tmp_acdguid = thisObj.ACDGuid; } catch (Exception ex) { Logger.Write(LogLevel.Cache, "Safely handled getting ACDGuid for {0}", tmp_SNOID); continue; } #endregion tmp_CachedObj = new CacheObject(tmp_SNOID, tmp_raGUID, tmp_acdguid, tmp_position); } else { //Reset unseen var tmp_CachedObj.LoopsUnseen = 0; } ////Validate (ignore special object SNO Ids) //if (!CacheIDLookup.hashSNOSkipCommonDataCheck.Contains(tmp_CachedObj.SNOID)) //{ // try // { // if (thisObj.CommonData == null) // { // Logger.Write(LogLevel.Cache, "CommonData is no longer valid! {0}", tmp_CachedObj.DebugStringSimple); // //BlacklistCache.AddObjectToBlacklist(tmp_CachedObj.RAGUID, BlacklistType.Temporary); // continue; // } // if (thisObj.CommonData.ACDGuid != thisObj.ACDGuid) // { // Logger.Write(LogLevel.Cache, "ACDGuid Mismatched! {0}", tmp_CachedObj.DebugStringSimple); // //BlacklistCache.AddObjectToBlacklist(tmp_CachedObj.RAGUID, BlacklistType.Temporary); // continue; // } // } // catch (Exception ex) // { // //Logger.Write(LogLevel.Cache, "Object is no longer valid! (Exception) SNOID {0}", tmp_CachedObj.DebugStringSimple); // //BlacklistCache.AddObjectToBlacklist(tmp_CachedObj.RAGUID, BlacklistType.Temporary); // continue; // } //} //Update any SNO Data. #region SNO_Cache_Update if (tmp_CachedObj.ref_DiaObject == null || tmp_CachedObj.ContainsNullValues()) { if (!tmp_CachedObj.UpdateData(thisObj, tmp_CachedObj.RAGUID)) { continue; } } else if (!tmp_CachedObj.IsFinalized) { //Finalize this data by recreating it and updating the Sno cache with a new finalized entry, this also clears our all Sno cache dictionaries since we no longer need them! cacheSnoCollection.FinalizeEntry(tmp_CachedObj.SNOID); } #endregion //Check if this object is a summoned unit by a player... #region SummonedUnits if (tmp_CachedObj.IsSummonedPet && CacheIDLookup.hashSNOSkipCommonDataCheck.Contains(tmp_CachedObj.SNOID)) { PetTypes PetType = (PetTypes)TheCache.ObjectIDCache.UnitPetEntries[tmp_CachedObj.SNOID].ObjectType; if (PetType == PetTypes.WIZARD_ArcaneOrbs) { FunkyGame.Targeting.Cache.Environment.HeroPets.WizardArcaneOrbs++; tmp_CachedObj.NeedsRemoved = true; continue; } } #endregion //Special Cache for Interactable Server Objects if (CheckFlag(tmp_CachedObj.targetType.Value, TargetType.ServerInteractable)) { if (!InteractableObjectCache.ContainsKey(tmp_CachedObj.RAGUID)) { InteractableObjectCache.Add(tmp_CachedObj.RAGUID, tmp_CachedObj); //Adventure Mode -- Rifting we add Exit to LOS movement! //if (FunkyGame.AdventureMode && FunkyGame.Bounty.IsInRiftWorld && FunkyBaseExtension.Settings.AdventureMode.EnableAdventuringMode) //{ // if (tmp_CachedObj.InternalName.Contains("Exit")) // { // int index = FunkyGame.Bounty.CurrentBountyMapMarkers.Count; // FunkyGame.Bounty.CurrentBountyMapMarkers.Add(index, new BountyCache.BountyMapMarker(tmp_CachedObj.Position, FunkyGame.Hero.CurrentWorldDynamicID, index)); // } //} } //Whymsdal Portal! if (tmp_CachedObj.SNOID == 405590) { GoblinBehavior.Portal = tmp_CachedObj; } else if (tmp_CachedObj.SNOID == 393030) { GoblinBehavior.Portal = tmp_CachedObj; } //Do not add to main cache! continue; } //Objects with static positions already cached don't need to be updated here. if (!tmp_CachedObj.NeedsUpdate) { continue; } //Obstacles -- (Not an actual object we add to targeting.) if (CheckFlag(tmp_CachedObj.targetType.Value, TargetType.Avoidance) || tmp_CachedObj.IsObstacle || tmp_CachedObj.HandleAsAvoidanceObject) { #region Obstacles CacheObstacle thisObstacle; //Do we have this cached? if (!Obstacles.TryGetValue(tmp_CachedObj.RAGUID, out thisObstacle)) { AvoidanceType AvoidanceType = AvoidanceType.None; if (tmp_CachedObj.IsAvoidance) { AvoidanceType = AvoidanceCache.FindAvoidanceUsingSNOID(tmp_CachedObj.SNOID); if (AvoidanceType == AvoidanceType.None) { AvoidanceType = AvoidanceCache.FindAvoidanceUsingName(tmp_CachedObj.InternalName); if (AvoidanceType == AvoidanceType.None) { continue; } } } if (tmp_CachedObj.IsAvoidance && tmp_CachedObj.IsProjectileAvoidance) { //Ranged Projectiles require more than simple bounding points.. so we create it as avoidance zone to cache it with properties. //Check for intersection.. try { ActorMovement thisMovement = thisObj.Movement; Vector2 Direction = thisMovement.DirectionVector; Ray R = new Ray(tmp_CachedObj.Position, Direction.ToVector3()); double Speed; //Lookup Cached Speed, or add new entry. if (!dictProjectileSpeed.TryGetValue(tmp_CachedObj.SNOID, out Speed)) { Speed = thisMovement.DesiredSpeed; dictProjectileSpeed.Add(tmp_CachedObj.SNOID, Speed); } thisObstacle = new CacheAvoidance(tmp_CachedObj, AvoidanceType, R, Speed); Obstacles.Add(thisObstacle); } catch { Logger.Write(LogLevel.Cache, "Failed to create projectile avoidance with rotation and speed. {0}", tmp_CachedObj.InternalName); } } else if (tmp_CachedObj.IsAvoidance) { //Poison Gas Can Be Friendly... if (AvoidanceType == AvoidanceType.PoisonGas) { int TeamID = 0; try { TeamID = thisObj.CommonData.GetAttribute <int>(ActorAttributeType.TeamID); } catch { Logger.Write(LogLevel.Cache, "Failed to retrieve TeamID attribute for object {0}", tmp_CachedObj.InternalName); } //ID of 1 means its non-hostile! (-1?) 2?? //if (TeamID==1||TeamID==-1) if (TeamID != 10) { //Logger.Write(LogLevel.None, "Ignoring Avoidance {0} due to Friendly TeamID match!", tmp_CachedObj.InternalName); BlacklistCache.AddObjectToBlacklist(tmp_CachedObj.RAGUID, BlacklistType.Permanent); continue; } } thisObstacle = new CacheAvoidance(tmp_CachedObj, AvoidanceType); Obstacles.Add(thisObstacle); } else { //Obstacles. thisObstacle = new CacheServerObject(tmp_CachedObj); Obstacles.Add(thisObstacle); } } continue; #endregion } if (tmp_CachedObj.ObjectShouldBeRecreated) { //This is where we create the real object after its done with SNO Update. //Specific updates if (tmp_CachedObj.Actortype.Value == ActorType.Item) { tmp_CachedObj = new CacheItem(tmp_CachedObj); } else if (tmp_CachedObj.Actortype.Value == ActorType.Monster) { if (!tmp_CachedObj.IsSummonedPet) { tmp_CachedObj = new CacheUnit(tmp_CachedObj); } else { PetTypes PetType = (PetTypes)TheCache.ObjectIDCache.UnitPetEntries[tmp_CachedObj.SNOID].ObjectType; #region Summoner ID Check // Get the summoned-by info, cached if possible if (!tmp_CachedObj.SummonerID.HasValue) { try { tmp_CachedObj.SummonerID = thisObj.CommonData.GetAttribute <int>(ActorAttributeType.SummonedByACDID); } catch (Exception ex) { //Logger.DBLog.InfoFormat("[Funky] Safely handled exception getting summoned-by info [" + tmp_CachedObj.SNOID.ToString(CultureInfo.InvariantCulture) + "]"); //Logger.DBLog.DebugFormat(ex.ToString()); continue; } } if (FunkyGame.Hero.iMyDynamicID != tmp_CachedObj.SummonerID.Value) { BlacklistCache.IgnoreThisObject(tmp_CachedObj, false, false); tmp_CachedObj.NeedsRemoved = true; continue; } #endregion tmp_CachedObj = new CachePet(tmp_CachedObj, PetType); } } else if (tmp_CachedObj.Actortype.Value == ActorType.Gizmo) { if (CheckFlag(tmp_CachedObj.targetType.Value, TargetType.Interactables)) { tmp_CachedObj = new CacheInteractable(tmp_CachedObj); } else { tmp_CachedObj = new CacheDestructable(tmp_CachedObj); } } //Update Properties (currently only for units) try { tmp_CachedObj.UpdateProperties(); } catch { Logger.Write(LogLevel.Cache, "Failed to update properties for {0}", tmp_CachedObj.DebugStringSimple); } } if (!tmp_CachedObj.UpdateData()) { //Logger.Write(LogLevel.Cache, "Update Failed for {0}", tmp_CachedObj.DebugStringSimple); if (!tmp_CachedObj.IsStillValid()) { tmp_CachedObj.NeedsRemoved = true; } continue; } //Obstacle cache if (tmp_CachedObj.Obstacletype.Value != ObstacleType.None && (CheckFlag(tmp_CachedObj.targetType.Value, TargetType.ServerObjects))) { CacheObstacle thisObstacleObj; if (!Obstacles.TryGetValue(tmp_CachedObj.RAGUID, out thisObstacleObj)) { CacheServerObject newobj = new CacheServerObject(tmp_CachedObj); Obstacles.Add(tmp_CachedObj.RAGUID, newobj); //Add nearby objects to our collection (used in navblock/obstaclecheck methods to reduce queries) if (CacheIDLookup.hashSNONavigationObstacles.Contains(newobj.SNOID)) { Navigation.Navigation.MGP.AddCellWeightingObstacle(newobj.SNOID, newobj.Radius); } } else { if (thisObstacleObj.targetType.Value == TargetType.Unit) { //Since units position requires updating, we update using the CacheObject thisObstacleObj.Position = tmp_CachedObj.Position; Obstacles[tmp_CachedObj.RAGUID] = thisObstacleObj; } } } //cache it if (Objects.ContainsKey(tmp_CachedObj.RAGUID)) { Objects[tmp_CachedObj.RAGUID] = tmp_CachedObj; } else { Objects.Add(tmp_CachedObj.RAGUID, tmp_CachedObj); } } //End of Loop } // End of Framelock //Tally up unseen objects. var UnseenObjects = Objects.Keys.Where(O => !hashDoneThisRactor.Contains(O)).ToList(); if (UnseenObjects.Any()) { for (int i = 0; i < UnseenObjects.Count(); i++) { Objects[UnseenObjects[i]].LoopsUnseen++; } } //Trim our collection every 5th refresh. UpdateLoopCounter++; if (UpdateLoopCounter > 4) { UpdateLoopCounter = 0; //Now flag any objects not seen for 5 loops. Gold/Globe only 1 loop. foreach (var item in Objects.Values.Where(CO => (CO.LoopsUnseen >= 5 || //5 loops max.. (CO.targetType.HasValue && (CheckFlag(CO.targetType.Value, TargetType.Gold | TargetType.Globe)) && CO.LoopsUnseen > 0)))) //gold/globe only 1 loop! { item.NeedsRemoved = true; } } CheckForCacheRemoval(); _lastUpdatedCacheCollection = DateTime.Now; return(true); }
public override void Initialize() { base.Test = (ref CacheObject obj) => { //Final Possible Target Check if (obj != null) { if (obj.targetType.Equals(TargetType.Unit)) { //Update CurrentUnitTarget Variable. CacheUnit unitObj = (CacheUnit)obj; //Grouping Movements if (FunkyBaseExtension.Settings.Grouping.AttemptGroupingMovements && unitObj.CurrentHealthPct.Value < 1d && //only after we engaged the target. !unitObj.BeingIgnoredDueToClusterLogic && !unitObj.IsClusterException && //we only want a cluster target! DateTime.Compare(DateTime.Now, FunkyGame.Navigation.groupingSuspendedDate) > 0 && !FunkyGame.Targeting.Cache.Environment.bAnyTreasureGoblinsPresent || FunkyBaseExtension.Settings.Targeting.GoblinPriority < 2) { FunkyGame.Targeting.Cache.Clusters.UpdateGroupClusteringVariables(); if (FunkyGame.Targeting.Cache.Clusters.CurrentGroupClusters.Count > 0) { foreach (UnitCluster cluster in FunkyGame.Targeting.Cache.Clusters.CurrentGroupClusters) { //Validate the cluster is something worthy.. if (!CheckCluster(cluster)) { continue; } //Validate that our target will not intersect avoidances? CacheUnit groupUnit = cluster.GetNearestUnitToCenteroid(); if (ObjectCache.Obstacles.TestVectorAgainstAvoidanceZones(groupUnit.Position)) { groupUnit = cluster.ListUnits[0]; if (ObjectCache.Obstacles.TestVectorAgainstAvoidanceZones(groupUnit.Position)) { continue; } } Logger.Write(LogLevel.Grouping, "Starting Grouping Behavior"); //Activate Behavior FunkyGame.Navigation.groupRunningBehavior = true; FunkyGame.Navigation.groupingOrginUnit = (CacheUnit)ObjectCache.Objects[obj.RAGUID]; Logger.Write(LogLevel.Grouping, "Group Cluster Propeties {0}", cluster.Info.Properties.ToString()); //Find initial grouping target.. obj = groupUnit; FunkyGame.Navigation.groupingCurrentUnit = groupUnit; FunkyGame.Navigation.groupingUnitCluster = cluster; return(true); } } } } } return(false); }; }
public override void Initialize() { base.Test = (ref CacheObject obj) => { if (obj == null) { // Cursed Events that have had interaction with a cursed object in the last nth time frame we check for completed bounty. // Kill/Clear Events that are on the last area level we check for completed bounty. if ((FunkyGame.Bounty.CurrentBountyCacheEntry.Type == BountyTypes.CursedEvent && DateTime.Now.Subtract(FunkyGame.Targeting.Cache.lastSeenCursedShrine).TotalSeconds < 45)) //|| ((FunkyGame.Bounty.CurrentBountyCacheEntry.Type == BountyQuestTypes.Kill || FunkyGame.Bounty.CurrentBountyCacheEntry.Type == BountyQuestTypes.Clear) //&& FunkyGame.Hero.iCurrentLevelID == FunkyGame.Bounty.CurrentBountyCacheEntry.EndingLevelAreaID)) { FunkyGame.Bounty.ActiveBounty.Refresh(); //Check Current Quest State! if (FunkyGame.Bounty.ActiveBounty.State == QuestState.Completed) { Logger.DBLog.Info("Bounty Is Finished.. Reloading Profile!!!"); //Refresh Active Bounty to Verify there is no active bounty still! //FunkyGame.Bounty.UpdateActiveBounty(); //if (FunkyGame.Bounty.ActiveBounty == null) //{ // //No Active Bounty.. lets reload profile! // Zeta.Bot.ProfileManager.Load(Zeta.Bot.ProfileManager.CurrentProfile.Path); //} } } else if (FunkyGame.Bounty.CurrentBountyCacheEntry.Type == BountyTypes.Event) { FunkyGame.Bounty.RefreshBountyQuestStates(); FunkyGame.Bounty.RefreshActiveQuests(); if (FunkyGame.Bounty.BountyQuestStates[FunkyGame.Bounty.ActiveBounty.QuestSNO] == QuestState.InProgress) { //Check interactive object cache.. if (ObjectCache.InteractableObjectCache.Values.Any(o => o.targetType.HasValue && o.targetType.Value == TargetType.Interaction && o.CentreDistance < 75f)) { Logger.DBLog.Info("Quest Giver Nearby!"); var interactableObj = ObjectCache.InteractableObjectCache.Values.First(o => o.targetType.HasValue && o.targetType.Value == TargetType.Interaction && o.CentreDistance < 75f); if (!interactableObj.LineOfSight.LOSTest(FunkyGame.Hero.Position, interactableObj.BotMeleeVector)) { if (interactableObj.CentreDistance > 25f) { FunkyGame.Targeting.Cache.Environment.LoSMovementObjects.Add(interactableObj); FunkyGame.Navigation.LOSmovementObject = new CacheLineOfSight(interactableObj, interactableObj.Position); Navigation.Navigation.NP.MoveTo(FunkyGame.Navigation.LOSmovementObject.Position, "LOS", true); obj = new CacheObject(FunkyGame.Navigation.LOSmovementObject.Position, TargetType.LineOfSight, 1d, "LOS Movement", Navigation.Navigation.NP.PathPrecision); return(true); } } else if (interactableObj.CentreDistance < 25f) { CacheUnit interactableUnit = (CacheUnit)interactableObj; if (interactableUnit.IsQuestGiver) { obj = interactableObj; return(true); } } } if (FunkyGame.Bounty.CurrentBountyMapMarkers.Count > 0) { //Check map marker.. foreach (var mapmarker in FunkyGame.Bounty.CurrentBountyMapMarkers.Values) { if (mapmarker.WorldID != FunkyGame.Hero.CurrentWorldDynamicID) { continue; } //Check Distance var DistanceFromMarker = mapmarker.Position.Distance(FunkyGame.Hero.Position); if (DistanceFromMarker < 25f) { obj = new CacheObject(FunkyGame.Hero.Position, TargetType.NoMovement, 20000, "EventWait", 2f, -1); return(true); } if (DistanceFromMarker < 100f && DistanceFromMarker > 25f) { Logger.DBLog.Info("Event Marker Nearby!"); FunkyGame.Bounty.RefreshActiveQuests(); obj = new CacheObject(mapmarker.Position, TargetType.LineOfSight, 20000, "Marker", 2f, -1); return(true); } } } } else if (FunkyGame.Bounty.BountyQuestStates[FunkyGame.Bounty.ActiveBounty.QuestSNO] == QuestState.Completed) { //Bounty is Completed.. } } } return(false); }; }