public double UpdateWeight(out int monstercount, out int avoidcount, ref List <int> UsedRAGUIDs, bool ResetIndex = false) { monstercount = 0; avoidcount = 0; if (ResetIndex) { LastIndexUsed = 0; } OccupiedObjects.Clear(); Vector3 sectorCenter = this.Center; //Get the Diagonal Length between start and end, multiply by 2.5 since each point represents an area of 5f than Divide the total by 2 for the radius range. double range = GridPoint.GetDistanceBetweenPoints(this.StartPoint, this.CornerPoint); int TotalGridPoints = this.ContainedPoints.Count; this.ThisWeight = 0d; //We use 2D Distance and subtract the obstacles radius IEnumerable <CacheObstacle> obstaclesContained = ObjectCache.Obstacles.Values .Where(obs => Math.Max(0f, sectorCenter.Distance2D(obs.Position) - obs.Radius) <= range); double maxaverage = ObjectCache.Objects.MaximumHitPointAverage; if (obstaclesContained.Any()) { //reset weight this.ThisWeight = 0; //copy SectorPoints //GridPoint[] SectorPoints=new GridPoint[this.ContainedPoints.Count]; //this.ContainedPoints.CopyTo(SectorPoints); List <GridPoint> NonNavPoints = new List <GridPoint>(); foreach (CacheObstacle item in obstaclesContained) { OccupiedObjects.Add(item.RAGUID); if (item is CacheServerObject) { //Monsters should add 10% of its weight //if (item.Obstacletype.Value==ObstacleType.Monster) //{ // if (Bot.Settings.Fleeing.EnableFleeingBehavior&& Bot.Targeting.Environment.FleeTrigeringRAGUIDs.Contains(item.RAGUID)) // { // } //} if (item.Obstacletype.Value == ObstacleType.ServerObject) { //give +1 to weight this.ThisWeight++; } } else if (item is CacheAvoidance) { if (!UsedRAGUIDs.Contains(item.RAGUID)) { AvoidanceType thisAvoidanceType = ((CacheAvoidance)item).AvoidanceType; if (AvoidanceCache.IgnoringAvoidanceType(thisAvoidanceType)) { continue; } AvoidanceValue AV = Bot.Settings.Avoidance.Avoidances[(int)thisAvoidanceType]; avoidcount++; float BaseWeight = AV.Weight; //if ((AvoidanceType.ArcaneSentry|AvoidanceType.Dececrator|AvoidanceType.MoltenCore|AvoidanceType.TreeSpore).HasFlag(thisAvoidanceType)) // BaseWeight=1f; //else // BaseWeight=0.5f; this.ThisWeight += (BaseWeight / Bot.Character.Data.dCurrentHealthPct); UsedRAGUIDs.Add(item.RAGUID); } } } ////Now add a base score for non-nav points. (25 being 100% non-navigable) //int PointMultiplier=(25/TotalGridPoints); //int RemainingPoints=SectorPoints.Length; //this.ThisWeight+=25-(RemainingPoints*PointMultiplier); //Logger.DBLog.InfoFormat("Weight assigned to this sector {0}. \r\n" //+"Total Points {1} with {2} Remaining points Valid!", this.ThisWeight, this.ContainedPoints.Count, SectorPoints.Length); } return(this.ThisWeight); //(Total Points / Non-Navigable Points Ratio) }
///<summary> ///Updates SNO Cache Values ///</summary> public virtual bool UpdateData(DiaObject thisObj, int raguid) { bool failureDuringUpdate = false; if (InternalName == null) { try { InternalName = thisObj.Name; } catch { Logger.Write(LogLevel.Cache, "Failure to get internal name on object, SNO {0}", SNOID); return(false); } } if (!Actortype.HasValue) { #region ActorType try { Actortype = thisObj.ActorType; } catch { Logger.Write(LogLevel.Cache, "Failure to get actorType for object, SNO: {0}", SNOID); return(false); } #endregion } //Ignored actor types.. if (BlacklistCache.IgnoredActorTypes.Contains(Actortype.Value)) //||!LootBehaviorEnabled&&this.Actortype.Value==ActorType.Item) { BlacklistCache.IgnoreThisObject(this, raguid); return(false); } if (!targetType.HasValue) { #region EvaluateTargetType try { //Evaluate Target Type.. // See if it's an avoidance first from the SNO if (IsAvoidance || IsObstacle) { targetType = TargetType.None; if (IsAvoidance) { if (IsProjectileAvoidance) { Obstacletype = ObstacleType.MovingAvoidance; } else { Obstacletype = ObstacleType.StaticAvoidance; } AvoidanceType AT = AvoidanceCache.FindAvoidanceUsingSNOID(SNOID); //Check if avoidance is enabled or if the avoidance type is set to 0 if (!Bot.Settings.Avoidance.AttemptAvoidanceMovements || AT != AvoidanceType.None && AvoidanceCache.IgnoringAvoidanceType(AT)) { BlacklistCache.AddObjectToBlacklist(raguid, BlacklistType.Temporary); return(false); } // Avoidance isn't disabled, so set this object type to avoidance targetType = TargetType.Avoidance; } else { Obstacletype = ObstacleType.ServerObject; } } else { // Calculate the object type of this object if (Actortype.Value == ActorType.Monster || CacheIDLookup.hashActorSNOForceTargetUnit.Contains(SNOID)) { targetType = TargetType.Unit; Obstacletype = ObstacleType.Monster; if (CacheIDLookup.hashActorSNOForceTargetUnit.Contains(SNOID)) { //Fill in monster data? Actortype = ActorType.Monster; } } else if (Actortype.Value == ActorType.Item || CacheIDLookup.hashForceSNOToItemList.Contains(SNOID)) { string testname = InternalName.ToLower(); //Check if this item is gold/globe.. if (testname.StartsWith("gold")) { targetType = TargetType.Gold; } else if (testname.StartsWith("healthglobe")) { targetType = TargetType.Globe; } else if (testname.StartsWith("console_powerglobe")) { targetType = TargetType.PowerGlobe; } else { targetType = TargetType.Item; } //Gold/Globe? } else if (Actortype.Value == ActorType.Gizmo) { GizmoType thisGizmoType; try { thisGizmoType = thisObj.ActorInfo.GizmoType; } catch { Logger.Write(LogLevel.Cache, "Failure to get actor Gizmo Type!"); return(false); } if (thisGizmoType == GizmoType.DestroyableObject || thisGizmoType == GizmoType.BreakableChest) { targetType = TargetType.Destructible; } else if (thisGizmoType == GizmoType.PowerUp || thisGizmoType == GizmoType.HealingWell || thisGizmoType == GizmoType.PoolOfReflection) { targetType = TargetType.Shrine; } else if (thisGizmoType == GizmoType.Chest) { targetType = TargetType.Container; } else if (thisGizmoType == GizmoType.BreakableDoor) { targetType = TargetType.Barricade; } else if (thisGizmoType == GizmoType.Door) { targetType = TargetType.Door; } else if (thisGizmoType == GizmoType.Waypoint || thisGizmoType == GizmoType.Portal || thisGizmoType == GizmoType.DungeonPortal || thisGizmoType == GizmoType.BossPortal) { //Special Interactive Object -- Add to special cache! targetType = TargetType.ServerInteractable; } else if (thisGizmoType == GizmoType.Switch) { targetType = TargetType.CursedShrine; } else { //All other gizmos should be ignored! BlacklistCache.IgnoreThisObject(this, raguid); return(false); } if (targetType.HasValue) { if (targetType.Value == TargetType.Destructible || targetType.Value == TargetType.Barricade || targetType.Value == TargetType.Door) { Obstacletype = ObstacleType.Destructable; } else if (targetType.Value == TargetType.Shrine || IsChestContainer) { Obstacletype = ObstacleType.ServerObject; } } if (!Gizmotype.HasValue) { Gizmotype = thisGizmoType; } } else if (CacheIDLookup.hashSNOInteractWhitelist.Contains(SNOID)) { targetType = TargetType.Interactable; } else if (Actortype.Value == ActorType.ServerProp) { string TestString = InternalName.ToLower(); //Server props with Base in name are the destructibles "remains" which is considered an obstacle! if (TestString.Contains("base") || TestString.Contains("fence")) { //Add this to the obstacle navigation cache if (!IsObstacle) { CacheIDLookup.hashSNONavigationObstacles.Add(SNOID); } Obstacletype = ObstacleType.ServerObject; //Use unknown since we lookup SNO ID for server prop related objects. targetType = TargetType.None; } else if (TestString.StartsWith("monsteraffix_")) { AvoidanceType T = AvoidanceCache.FindAvoidanceUsingName(TestString); if (T == AvoidanceType.Wall) { //Add this to the obstacle navigation cache if (!IsObstacle) { CacheIDLookup.hashSNONavigationObstacles.Add(SNOID); } Obstacletype = ObstacleType.ServerObject; //Use unknown since we lookup SNO ID for server prop related objects. targetType = TargetType.None; } //else if (Bot.AvoidancesHealth.ContainsKey(T)) //{ // Logger.DBLog.InfoFormat("Found Avoidance not recongized by SNO! Name {0} SNO {1}", TestString, this.SNOID); // CacheIDLookup.hashAvoidanceSNOList.Add(this.SNOID); // this.targetType=TargetType.Avoidance; //} else { //Blacklist all other monster affixes BlacklistCache.IgnoreThisObject(this, raguid); return(false); } } else { BlacklistCache.IgnoreThisObject(this, raguid); return(false); } } else { //Misc?? Ignore it! BlacklistCache.IgnoreThisObject(this, raguid); return(false); } } } catch { Logger.Write(LogLevel.Cache, "Failure to get actorType for object, SNO: {0}", SNOID); return(false); } #endregion } if (!Obstacletype.HasValue) { Obstacletype = ObstacleType.None; } if (ObjectCache.CheckTargetTypeFlag(targetType.Value, TargetType.Unit)) { SNORecordMonster monsterInfo; try { monsterInfo = thisObj.CommonData.MonsterInfo; } catch { Logger.Write(LogLevel.Cache, "Safely Handled MonsterInfo Exception for Object {0}", InternalName); return(false); } if (!Monstertype.HasValue || ShouldRefreshMonsterType) { #region MonsterType try { Monstertype = monsterInfo.MonsterType; } catch { Logger.Write(LogLevel.Cache, "Failure to get MonsterType for SNO: {0}", SNOID); failureDuringUpdate = true; } #endregion } if (!Monstersize.HasValue) { #region MonsterSize try { Monstersize = monsterInfo.MonsterSize; } catch { Logger.Write(LogLevel.Cache, "Failure to get MonsterSize for SNO: {0}", SNOID); failureDuringUpdate = true; } #endregion } } if (Actortype.HasValue && targetType.HasValue && (Actortype.Value != ActorType.Item && targetType.Value != TargetType.Avoidance && targetType.Value != TargetType.ServerInteractable)) { //Validate sphere info Sphere sphereInfo = thisObj.CollisionSphere; if (!CollisionRadius.HasValue) { #region CollisionRadius try { CollisionRadius = sphereInfo.Radius; } catch { Logger.Write(LogLevel.Cache, "Failure to get CollisionRadius for SNO: {0}", SNOID); failureDuringUpdate = true; } #endregion if (CacheIDLookup.dictFixedCollisionRadius.ContainsKey(SNOID)) { //Override The Default Collision Sphere Value CollisionRadius = CacheIDLookup.dictFixedCollisionRadius[SNOID]; } } if (!ActorSphereRadius.HasValue) { #region ActorSphereRadius try { ActorSphereRadius = thisObj.ActorInfo.Sphere.Radius; } catch { Logger.Write(LogLevel.Cache, "Safely handled getting attribute Sphere radius for gizmo {0}", InternalName); failureDuringUpdate = true; } #endregion } #region GizmoProperties if (ObjectCache.CheckTargetTypeFlag(targetType.Value, TargetType.Destructible | TargetType.Interactable)) { //No Loot if (!DropsNoLoot.HasValue) { #region DropsNoLoot try { DropsNoLoot = thisObj.CommonData.GetAttribute <float>(ActorAttributeType.DropsNoLoot) <= 0; } catch { Logger.Write(LogLevel.Cache, "Safely handled reading DropsNoLoot for gizmo {0}", InternalName); failureDuringUpdate = true; } #endregion } //No XP if (!GrantsNoXP.HasValue) { #region GrantsNoXP try { GrantsNoXP = thisObj.CommonData.GetAttribute <float>(ActorAttributeType.GrantsNoXP) <= 0; } catch { Logger.Write(LogLevel.Cache, "Safely handled reading GrantsNoXp for gizmo {0}", InternalName); failureDuringUpdate = true; } #endregion } //Barricade flag if (!IsBarricade.HasValue) { #region Barricade try { IsBarricade = ((DiaGizmo)thisObj).IsBarricade; } catch { Logger.Write(LogLevel.Cache, "Safely handled getting attribute IsBarricade for gizmo {0}", InternalName); failureDuringUpdate = true; } #endregion } } #endregion } return(!failureDuringUpdate); }