public override void Initialize() { base.Test = (ref CacheObject obj) => { this.bStayPutDuringAvoidance = false; //cluster update Bot.Targeting.Cache.Clusters.UpdateTargetClusteringVariables(); //Standard weighting of valid objects -- updates current target. this.WeightEvaluationObjList(ref obj); //Final Possible Target Check if (obj == null) { // No valid targets but we were told to stay put? if (this.bStayPutDuringAvoidance) { //Lets check our avoidance object list if (Bot.Targeting.Cache.objectsIgnoredDueToAvoidance.Count > 0 && DateTime.Now.Subtract(lastAvoidanceConnectSearch).TotalMilliseconds > 4000) { Logger.DBLog.InfoFormat("Preforming Avoidance Connection Search on Potential Objects"); lastAvoidanceConnectSearch = DateTime.Now; //Update or Create Bot Postion GPRect GPRectangle botrect = new GPRectangle(Bot.Character.Data.Position); Vector3 connectVector3; foreach (CacheObject testobj in Bot.Targeting.Cache.objectsIgnoredDueToAvoidance) { if (botrect.TryFindSafeSpot(Bot.Character.Data.Position, out connectVector3, testobj.Position, PointCheckingFlags.AvoidanceOverlap | PointCheckingFlags.BlockedDirection | PointCheckingFlags.MonsterOverlap | PointCheckingFlags.ObstacleOverlap | PointCheckingFlags.RaycastWalkable, new List <GridPoint>())) { obj = new CacheObject(connectVector3, TargetType.Avoidance, 20000, "Avoid Connection", 2.5f, -1); return(true); } } // } if (Bot.Targeting.Cache.Environment.TriggeringAvoidances.Count == 0) { obj = new CacheObject(Bot.Character.Data.Position, TargetType.Avoidance, 20000, "StayPutPoint", 2.5f, -1); return(true); } } } return(false); }; }
///<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 = FunkyGame.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 && FunkyBaseExtension.Settings.Debugging.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); }