public bool GridPointContained(GridPoint point) { return(centerGPRect.Contains(point)); }
///<summary> ///Checks if the position is total blocked from adjacent movements either by objects or non navigation ///</summary> private bool IsVectorBlocked(Vector3 location) { //Reset Navigationally Blocked GPs LastNavigationBlockedPoints = new List <GridPoint>(); //Create Local GPRect! if (LastUsedBlockCheckGPRect == null || LastUsedBlockCheckGPRect.centerpoint != (GridPoint)location) { //Clear lists LastObjectblockCounter.Clear(); LastObjectOccupiedGridPoints.Clear(); LastUsedBlockCheckGPRect = new GPRectangle(location); } if (LastUsedBlockCheckGPRect.Count == 0) { //Logger.DBLog.DebugFormat("Current Location GP Rect has no valid Grid Points!"); return(false); } GridPoint[] CurrentLocationGridPoints = LastUsedBlockCheckGPRect.Keys.ToArray(); List <GridPoint> SurroundingPoints = new List <GridPoint>(); int SurroundingMaxCount = LastUsedBlockCheckGPRect.Count >= 8 ? 8 : LastUsedBlockCheckGPRect.Count; for (int i = 0; i < SurroundingMaxCount; i++) { GridPoint gp = CurrentLocationGridPoints[i]; if (!gp.Ignored) { SurroundingPoints.Add(gp); } else { LastNavigationBlockedPoints.Add(gp); } } List <int> NearbyObjectRAGUIDs = new List <int>(); List <CacheServerObject> NearbyObjects = Bot.Targeting.Cache.Environment.NearbyObstacleObjects.Where(obj => obj.RadiusDistance <= 6f).ToList(); //ObjectCache.Obstacles.Navigations.Where(obj => obj.RadiusDistance<=5f).ToList(); //no nearby objects passed distance check.. if (NearbyObjects.Count == 0) { //Clear list, and return pure navigational check (Zero means we are completely stuck in a non-navigable location?) LastObjectblockCounter.Clear(); LastObjectOccupiedGridPoints.Clear(); //Logger.DBLog.InfoFormat("Current Location Point has {0} usable points (NoNewObjs)", SurroundingPoints.Count); return(SurroundingPoints.Count == 0); } //Update ObjectBlockCounter Collection if (LastObjectblockCounter.Count > 0) { //Add current nearby object RAGUIDs to collection NearbyObjectRAGUIDs.AddRange((from objs in NearbyObjects select objs.RAGUID).ToArray()); //Generate Removal List for ObjectBlockCounter Collections List <int> RemovalRAGUIDList = (from raguids in LastObjectblockCounter.Keys where !NearbyObjectRAGUIDs.Contains(raguids) select raguids).ToList(); //Removal foreach (var item in RemovalRAGUIDList) { LastObjectblockCounter.Remove(item); LastObjectOccupiedGridPoints.Remove(item); } } //Check any exisiting block entries if (LastObjectblockCounter.Count > 0) { foreach (var item in LastObjectOccupiedGridPoints.Values) { LastNavigationBlockedPoints.AddRange(item); } //Update Surrounding Points SurroundingPoints = SurroundingPoints.Except(LastNavigationBlockedPoints).ToList(); if (SurroundingPoints.Count == 0) { //Logger.DBLog.InfoFormat("NavBlocked -- No available surrounding points."); return(true); } } //Generate new object list that contains objects that are not already accounted for List <CacheServerObject> NewObjects = NearbyObjects.Where(obj => !LastObjectblockCounter.ContainsKey(obj.RAGUID) || LastObjectblockCounter[obj.RAGUID] < 4).ToList(); //No new objects to test.. if (NewObjects.Count == 0) { //Logger.DBLog.InfoFormat("No new Objects Unaccounted"); return(SurroundingPoints.Count == 0); } foreach (GridPoint item in SurroundingPoints) { //Find any objects that contain this GP CacheServerObject[] ContainedObjs = NewObjects.Where(Obj => Obj.PointInside(item) && //only objects that have hit there maximum block count. (!LastObjectblockCounter.ContainsKey(Obj.RAGUID) || Math.Round(Obj.PointRadius) < LastObjectblockCounter[Obj.RAGUID])).ToArray(); if (ContainedObjs.Length > 0) { //if (ContainedObjs.Length > 1 && Bot.Settings.Debug.FunkyLogFlags.HasFlag(LogLevel.Movement)) //Logger.DBLog.InfoFormat("Multiple Objects Found Occuping Grid Point!"); CacheServerObject ThisObjBlocking = ContainedObjs[0]; int ObjRAGUID = ThisObjBlocking.RAGUID; if (LastObjectblockCounter.ContainsKey(ObjRAGUID)) { int GPCount = LastObjectOccupiedGridPoints[ObjRAGUID].Length; LastObjectblockCounter[ObjRAGUID]++; GridPoint[] newArrayGPs = new GridPoint[GPCount]; LastObjectOccupiedGridPoints[ObjRAGUID].CopyTo(newArrayGPs, 0); newArrayGPs[GPCount - 1] = item.Clone(); LastObjectOccupiedGridPoints[ObjRAGUID] = newArrayGPs; } else { LastObjectblockCounter.Add(ObjRAGUID, 1); GridPoint[] NewArrayGP = new GridPoint[1] { item.Clone() }; LastObjectOccupiedGridPoints.Add(ObjRAGUID, NewArrayGP); } LastNavigationBlockedPoints.Add(item); } } //Update Surrounding Points SurroundingPoints = SurroundingPoints.Except(LastNavigationBlockedPoints).ToList(); //Logger.DBLog.InfoFormat("Current Location Point has {0} usable points", SurroundingPoints.Count); return(SurroundingPoints.Count == 0); }
private bool CheckPoint(GridPoint point, Vector3 LoSCheckV3, PointCheckingFlags flags) { //Check blacklisted points and ignored if (point.Ignored) { return(false); } //Check if this point is in a blocked direction if (flags.HasFlag(PointCheckingFlags.BlockedDirection)) { if (Bot.NavigationCache.CheckPointAgainstBlockedDirection(point)) { return(false); } } //Create Vector3 Vector3 pointVectorReturn = (Vector3)point; Vector3 pointVector = pointVectorReturn; Vector3 botcurpos = Bot.Character.Data.Position; //2D Obstacle Navigation Check bool ZCheck = false; if (this.AreaIsFlat) { if (flags.HasFlag(PointCheckingFlags.ObstacleOverlap)) { if (ObjectCache.Obstacles.Values.OfType <CacheServerObject>().Any(obj => ObstacleType.Navigation.HasFlag(obj.Obstacletype.Value) && obj.PointInside(point))) { return(false); } } if (flags.HasFlag(PointCheckingFlags.ObstacleIntersection)) { if (ObjectCache.Obstacles.Values.OfType <CacheServerObject>().Any(obj => ObstacleType.Navigation.HasFlag(obj.Obstacletype.Value) && obj.TestIntersection(botcurpos, point))) { return(false); } } ZCheck = true; } //Check if we already within this "point". if (botcurpos.Distance2D(pointVector) < 2.5f) { return(false); } //3D Obstacle Navigation Check if (!ZCheck) { //Because Z Variance we need to check if we can raycast walk to the location. if (!Navigation.CanRayCast(botcurpos, pointVector)) { return(false); } if (!Navigation.MGP.CanStandAt(pointVector)) { return(false); } if (flags.HasFlag(PointCheckingFlags.ObstacleOverlap)) { if (ObjectCache.Obstacles.Values.OfType <CacheServerObject>().Any(obj => ObstacleType.Navigation.HasFlag(obj.Obstacletype.Value) && obj.PointInside(pointVector))) { return(false); } } if (flags.HasFlag(PointCheckingFlags.ObstacleIntersection)) { if (ObjectCache.Obstacles.Values.OfType <CacheServerObject>().Any(obj => ObstacleType.Navigation.HasFlag(obj.Obstacletype.Value) && obj.TestIntersection(botcurpos, pointVector))) { return(false); } } } //Avoidance Check (Any Avoidance) if (flags.HasFlag(PointCheckingFlags.AvoidanceOverlap)) { if (ObjectCache.Obstacles.IsPositionWithinAvoidanceArea(pointVector)) { return(false); } } //Kiting Check if (flags.HasFlag(PointCheckingFlags.MonsterOverlap)) { if (ObjectCache.Objects.OfType <CacheUnit>().Any(m => m.ShouldFlee && m.IsPositionWithinRange(pointVector, Bot.Settings.Fleeing.FleeMaxMonsterDistance))) { return(false); } } //Avoidance Intersection Check if (flags.HasFlag(PointCheckingFlags.AvoidanceIntersection)) { //if (ObjectCache.Obstacles.TestVectorAgainstAvoidanceZones(botcurpos, pointVector)) return false; } if (flags.HasFlag(PointCheckingFlags.Raycast)) { if (!Navigation.CanRayCast(botcurpos, pointVector)) { return(false); } } if (flags.HasFlag(PointCheckingFlags.RaycastWalkable)) { if (!Navigation.CanRayCast(botcurpos, pointVector, NavCellFlags.AllowWalk)) { return(false); } } if (flags.HasFlag(PointCheckingFlags.RaycastNavProvider)) { if (!Navigation.CanRayCast(botcurpos, pointVector, UseSearchGridProvider: true)) { return(false); } } LastSafespotFound = pointVectorReturn; LastSafeGridPointFound = point.Clone(); return(true); }
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) }
public void UpdateRange(Vector3 start) { StartingPoint = start; update_(start); }