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);
}