public GPArea(Vector3 startingLocation) { //Creation and Cache base centerGPRect=new GPRectangle(startingLocation, 3); GPRectangle centerClone=centerGPRect.Clone(); //Get all valid points (besides current point) from our current location GPR GridPoint[] SearchPoints=centerGPRect.Points.Keys.Where(gp => !gp.Ignored).ToArray(); gridpointrectangles_=new List<GPRectangle>(); if (SearchPoints.Length>1) { //we should check our surrounding points to see if we can even move into any of them first! for (int i=1; i<SearchPoints.Length-1; i++) { GridPoint curGP=SearchPoints[i]; Vector3 thisV3=(Vector3)curGP; thisV3.Z+=(Bot.Character.fCharacterRadius/2f); //Its a valid point for direction testing! float DirectionDegrees=Navigation.FindDirection(Bot.NavigationCache.LastSearchVector, thisV3, false); DirectionPoint P=new DirectionPoint((Vector3)curGP, DirectionDegrees, 125f); if (P.Range>5f) { gridpointrectangles_.Add(new GPRectangle(P, centerGPRect)); } } gridpointrectangles_.Add(centerClone); gridpointrectangles_=gridpointrectangles_.OrderByDescending(gpr => gpr.Count).ToList(); } }
private void iterateGPRectsSafeSpot(Vector3 CurrentPosition, out Vector3 safespot, Vector3 LOS, bool kiting=false) { safespot=Vector3.Zero; for (int i=lastGPRectIndexUsed; i<gridpointrectangles_.Count-1; i++) { GPRectangle item=gridpointrectangles_[i]; item.UpdateObjectCount(AllGPRectsFailed); if (item.Weight>Bot.NavigationCache.CurrentLocationGPRect.Weight) continue; if (item.TryFindSafeSpot(CurrentPosition, out safespot, LOS, kiting, false, AllGPRectsFailed)) { this.lastUsedGPRect=gridpointrectangles_[i]; return; } } lastGPRectIndexUsed=0; }
public GPRectangle(GPRectangle clone) : base(clone) { base.CornerPoints=clone.CornerPoints; this.Quadrant=clone.Quadrant; this.CreationVector=clone.CreationVector; this.searchablepoints_=clone.searchablepoints_; }
///<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 this.LastNavigationBlockedPoints=new List<GridPoint>(); //Create Local GPRect! if (this.LastUsedBlockCheckGPRect==null||this.LastUsedBlockCheckGPRect.centerpoint!=(GridPoint)location) { //Clear lists LastObjectblockCounter.Clear(); LastObjectOccupiedGridPoints.Clear(); this.LastUsedBlockCheckGPRect=new GPRectangle(location); } if (this.LastUsedBlockCheckGPRect.Count==0) { Logging.WriteDiagnostic("Current Location GP Rect has no valid Grid Points!"); return false; } GridPoint[] CurrentLocationGridPoints=this.LastUsedBlockCheckGPRect.Keys.ToArray(); List<GridPoint> SurroundingPoints=new List<GridPoint>(); int SurroundingMaxCount=this.LastUsedBlockCheckGPRect.Count>=8?8:this.LastUsedBlockCheckGPRect.Count; for (int i=0; i<SurroundingMaxCount; i++) { GridPoint gp=CurrentLocationGridPoints[i]; if (!gp.Ignored) SurroundingPoints.Add(gp); else this.LastNavigationBlockedPoints.Add(gp); } List<int> NearbyObjectRAGUIDs=new List<int>(); List<CacheServerObject> NearbyObjects=Bot.Combat.NearbyObstacleObjects.Where(obj => obj.RadiusDistance<=5f).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(); if (Bot.SettingsFunky.LogSafeMovementOutput) Logging.WriteVerbose("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) { this.LastNavigationBlockedPoints.AddRange(item); } //Update Surrounding Points SurroundingPoints=SurroundingPoints.Except(this.LastNavigationBlockedPoints).ToList(); if (SurroundingPoints.Count==0) { if (Bot.SettingsFunky.LogSafeMovementOutput) Logging.WriteVerbose("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) { if (Bot.SettingsFunky.LogSafeMovementOutput) Logging.WriteVerbose("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.SettingsFunky.LogSafeMovementOutput) Logging.WriteVerbose("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); } this.LastNavigationBlockedPoints.Add(item); } } //Update Surrounding Points SurroundingPoints=SurroundingPoints.Except(this.LastNavigationBlockedPoints).ToList(); if (Bot.SettingsFunky.LogSafeMovementOutput) Logging.WriteVerbose("Current Location Point has {0} usable points", SurroundingPoints.Count); return (SurroundingPoints.Count==0); }
///<summary> ///Used to recreate from temp into obstacle object. ///</summary> public CacheObject(CacheObject parent) : base(parent) { this.AcdGuid=parent.AcdGuid; this.BlacklistFlag=parent.BlacklistFlag; this.BlacklistLoops_=parent.BlacklistLoops_; this.gprect_=parent.gprect_; this.InteractionAttempts=parent.InteractionAttempts; this.LastLOSCheck=parent.LastLOSCheck; this.LoopsUnseen_=parent.LoopsUnseen_; this.losv3_=parent.losv3_; this.LosSearchRetryMilliseconds_=parent.LosSearchRetryMilliseconds_; this.NeedsRemoved=parent.NeedsRemoved; this.NeedsUpdate=parent.NeedsUpdate; this.PrioritizedDate=parent.PrioritizedDate; this.PriorityCounter=parent.PriorityCounter; this.position_=parent.Position; this.radius_=parent.Radius; this.RAGUID=parent.RAGUID; this.ref_DiaObject=parent.ref_DiaObject; this.removal_=parent.removal_; this.RequiresLOSCheck=parent.RequiresLOSCheck; this.SummonerID=parent.SummonerID; this.weight_=parent.Weight; this.HandleAsAvoidanceObject=parent.HandleAsAvoidanceObject; }