///<summary> ///Searches for a safespot ///</summary> public bool AttemptFindSafeSpot(out Vector3 safespot, Vector3 LOS, PointCheckingFlags flags) { safespot = vlastSafeSpot; Vector3 BotPosition = FunkyGame.Hero.Position; //Recreate the entire area? if (!CurrentAreaValid()) { CurrentGPArea = new GPArea(BotPosition); } //Check Bot Navigationally blocked RefreshNavigationBlocked(); if (BotIsNavigationallyBlocked) { return(false); } //Recreate Bot Current rect? //if (CurrentLocationGPrect == null || CurrentLocationGPrect.centerpoint != FunkyGame.Hero.PointPosition) //{ // FunkyGame.Navigation.CurrentLocationGPrect = new GPRectangle(BotPosition); // //Refresh boundary (blocked directions) // currentLocationBoundary = new AreaBoundary(BotPosition); // UpdateLocationsBlocked(); //} // FunkyGame.Navigation.CurrentLocationGPRect.UpdateObjectCount(); safespot = CurrentGPArea.AttemptFindSafeSpot(BotPosition, LOS, flags); return(safespot != Vector3.Zero); }
///<summary> ///Searches for a safespot ///</summary> public bool AttemptFindSafeSpot(out Vector3 safespot, Vector3 LOS, PointCheckingFlags flags) { safespot = vlastSafeSpot; Vector3 BotPosition = Bot.Character.Data.Position; //Recreate the entire area? if (Bot.NavigationCache.CurrentGPArea == null || Bot.NavigationCache.CurrentGPArea.AllGPRectsFailed && !Bot.NavigationCache.CurrentGPArea.centerGPRect.Contains(BotPosition) || !Bot.NavigationCache.CurrentGPArea.GridPointContained(BotPosition)) { Bot.NavigationCache.CurrentGPArea = new GPArea(BotPosition); } //Check Bot Navigationally blocked RefreshNavigationBlocked(); if (BotIsNavigationallyBlocked) { return(false); } //Recreate Bot Current rect? if (Bot.NavigationCache.CurrentLocationGPrect == null || Bot.NavigationCache.CurrentLocationGPrect.centerpoint != Bot.Character.Data.PointPosition) { Bot.NavigationCache.CurrentLocationGPrect = new GPRectangle(BotPosition); //Refresh boundary (blocked directions) currentLocationBoundary = new AreaBoundary(BotPosition); UpdateLocationsBlocked(); } // Bot.NavigationCache.CurrentLocationGPRect.UpdateObjectCount(); safespot = Bot.NavigationCache.CurrentGPArea.AttemptFindSafeSpot(BotPosition, LOS, flags); return(safespot != Vector3.Zero); }
///<summary> ///Searches for a safespot! ///</summary> public Vector3 AttemptFindSafeSpot(Vector3 CurrentPosition, Vector3 LOS, PointCheckingFlags Flags) { if (AllGPRectsFailed && Bot.NavigationCache.CurrentGPArea.BlacklistedGridpoints.Count > 0) { //Reset all blacklist to retry again. AllGPRectsFailed = false; //Clear Blacklisted Bot.NavigationCache.CurrentGPArea.BlacklistedGridpoints.Clear(); } Vector3 safespot; //Check if we actually created any surrounding GPCs.. if (gridpointrectangles_.Count > 0) { iterateGPRectsSafeSpot(CurrentPosition, out safespot, LOS, Flags); //If still failed to find a safe spot.. set the timer before we try again. if (safespot == Vector3.Zero) { Logger.DBLog.InfoFormat("All GPCs failed to find a valid location to move!"); AllGPRectsFailed = true; return safespot; } //Cache it and set timer Bot.NavigationCache.lastFoundSafeSpot = DateTime.Now; Bot.NavigationCache.vlastSafeSpot = safespot; } //Logger.DBLog.InfoFormat("Safespot location {0} distance from {1} is {2}", safespot.ToString(), LastSearchVector.ToString(), safespot.Distance2D(LastSearchVector)); return Bot.NavigationCache.vlastSafeSpot; }
///<summary> ///Searches for a safespot! ///</summary> public Vector3 AttemptFindSafeSpot(Vector3 CurrentPosition, Vector3 LOS, PointCheckingFlags Flags) { if (AllGPRectsFailed && FunkyGame.Navigation.CurrentGPArea.BlacklistedGridpoints.Count > 0) { //Reset all blacklist to retry again. AllGPRectsFailed = false; //Clear Blacklisted FunkyGame.Navigation.CurrentGPArea.BlacklistedGridpoints.Clear(); } Vector3 safespot; //Check if we actually created any surrounding GPCs.. if (gridpointrectangles_.Count > 0) { iterateGPRectsSafeSpot(CurrentPosition, out safespot, LOS, Flags); DateSearchSafeSpots = DateTime.Now; //If still failed to find a safe spot.. set the timer before we try again. if (safespot == Vector3.Zero) { Logger.DBLog.InfoFormat("All GPCs failed to find a valid location to move!"); AllGPRectsFailed = true; return(safespot); } //Cache it and set timer FunkyGame.Navigation.lastFoundSafeSpot = DateTime.Now; FunkyGame.Navigation.vlastSafeSpot = safespot; } //Logger.DBLog.InfoFormat("Safespot location {0} distance from {1} is {2}", safespot.ToString(), LastSearchVector.ToString(), safespot.Distance2D(LastSearchVector)); return(FunkyGame.Navigation.vlastSafeSpot); }
public override void Initialize() { base.Test = (ref CacheObject obj) => { if (Bot.Settings.Debug.FunkyLogFlags.HasFlag(LogLevel.Movement)) { string avoidances = ""; Bot.Targeting.Cache.Environment.TriggeringAvoidances.ForEach(a => avoidances = avoidances + a.AvoidanceType.ToString() + ", "); Logger.Write(LogLevel.Movement, "Avoidances Triggering: {0}", avoidances); } //Reuse the last generated safe spot... if (DateTime.Now.Subtract(Bot.Targeting.Cache.LastAvoidanceMovement).TotalSeconds < this.iSecondsAvoidMoveFor) { Vector3 reuseV3 = Bot.NavigationCache.AttemptToReuseLastLocationFound(); if (reuseV3 != Vector3.Zero) { if (!ObjectCache.Obstacles.IsPositionWithinAvoidanceArea(reuseV3)) { obj = new CacheObject(reuseV3, TargetType.Avoidance, 20000f, "SafeReuseAvoid", 2.5f, -1); return(true); } } } Vector3 vAnySafePoint; //Check if we have any movement abilities we can cast.. if so lets not check avoidance intersections. PointCheckingFlags flags = Bot.Settings.Plugin.AvoidanceFlags; if (Bot.Character.Class.HasCastableMovementAbility()) { flags &= ~(PointCheckingFlags.AvoidanceIntersection | PointCheckingFlags.BlockedDirection); } if (Bot.NavigationCache.AttemptFindSafeSpot(out vAnySafePoint, Vector3.Zero, flags)) { float distance = vAnySafePoint.Distance(Bot.Character.Data.Position); Logger.DBLog.DebugFormat("Avoid Movement found AT {0} with {1} Distance", vAnySafePoint.ToString(), distance); //setup avoidance target obj = new CacheObject(vAnySafePoint, TargetType.Avoidance, 20000f, "SafeAvoid", 2.5f, -1); //Estimate time we will be reusing this movement vector3 this.iSecondsAvoidMoveFor = 1 + (int)(distance / 5f); return(true); } else { //Failed to find any location.. //Set the future date we must wait for to retry.. AvoidRetryDate = DateTime.Now.AddMilliseconds(Bot.Settings.Avoidance.FailureRetryMilliseconds); } return(false); }; }
public SettingPlugin() { GoldInactivityTimeoutSeconds = 180; //default of 3 minutes CacheObjectRefreshRate = 150; UnusedSNORemovalRate = 180000; MovementNonMovementCount = 50; OutofCombatMaxDistance = 50; CreateMuleOnStashFull = true; AvoidanceFlags = PointCheckingFlags.AvoidanceIntersection | PointCheckingFlags.AvoidanceOverlap | PointCheckingFlags.ObstacleOverlap | PointCheckingFlags.BlockedDirection; FleeingFlags = PointCheckingFlags.AvoidanceIntersection | PointCheckingFlags.AvoidanceOverlap | PointCheckingFlags.ObstacleOverlap | PointCheckingFlags.Raycast | PointCheckingFlags.MonsterOverlap | PointCheckingFlags.BlockedDirection; }
//Static Methods #region Static Movement Methods public static bool CheckVectorFlags(Vector3 currentPos, Vector3 targetPos, PointCheckingFlags flags) { //Avoidance Check (Any Avoidance) if (flags.HasFlag(PointCheckingFlags.AvoidanceOverlap)) { if (ObjectCache.Obstacles.IsPositionWithinAvoidanceArea(targetPos)) { return(false); } } //Kiting Check //if (flags.HasFlag(PointCheckingFlags.MonsterOverlap)) //{ // if (ObjectCache.Objects.OfType<CacheUnit>().Any(m => m.ShouldFlee && m.IsPositionWithinRange(targetPos, FunkyBaseExtension.Settings.Fleeing.FleeMaxMonsterDistance))) return false; //} //Avoidance Intersection Check if (flags.HasFlag(PointCheckingFlags.AvoidanceIntersection)) { if (ObjectCache.Obstacles.TestVectorAgainstAvoidanceZones(currentPos, targetPos)) { return(false); } } Vector3 botcurpos = FunkyGame.Hero.Position; if (flags.HasFlag(PointCheckingFlags.Raycast)) { if (!Navigation.CanRayCast(currentPos, targetPos)) { return(false); } } if (flags.HasFlag(PointCheckingFlags.RaycastWalkable)) { if (!Navigation.CanRayCast(currentPos, targetPos, NavCellFlags.AllowWalk)) { return(false); } } if (flags.HasFlag(PointCheckingFlags.RaycastNavProvider)) { if (!Navigation.CanRayCast(currentPos, targetPos, UseSearchGridProvider: true)) { return(false); } } return(true); }
public override void Initialize() { this.Test = (ref CacheObject obj) => { //Resuse last safespot until timer expires! if (DateTime.Now.Subtract(FunkyGame.Targeting.Cache.LastFleeAction).TotalSeconds < this.iSecondsFleeMoveFor) { Vector3 reuseV3 = FunkyGame.Navigation.AttemptToReuseLastLocationFound(); if (reuseV3 != Vector3.Zero) { if (!ObjectCache.Objects.IsPointNearbyMonsters(reuseV3, FunkyBaseExtension.Settings.Fleeing.FleeMaxMonsterDistance) && !ObjectCache.Obstacles.IsPositionWithinAvoidanceArea(reuseV3)) { obj = new CacheObject(reuseV3, TargetType.Fleeing, 20000f, "ReuseFleeSpot", 2.5f, -1); return(true); } } } Vector3 vAnySafePoint; //Setup Line of Sight for last target if its a unit and still valid.. Vector3 LineOfSight = FunkyGame.Targeting.Cache.LastCachedTarget.targetType.HasValue && FunkyGame.Targeting.Cache.LastCachedTarget.targetType.Value == TargetType.Unit && FunkyGame.Targeting.Cache.LastCachedTarget.ObjectIsValidForTargeting ? FunkyGame.Targeting.Cache.LastCachedTarget.Position : Vector3.Zero; PointCheckingFlags flags = FunkyBaseExtension.Settings.Plugin.FleeingFlags; if (FunkyGame.Hero.Class.HasCastableMovementAbility()) { flags &= ~(PointCheckingFlags.AvoidanceIntersection | PointCheckingFlags.BlockedDirection); } if (FunkyGame.Navigation.AttemptFindSafeSpot(out vAnySafePoint, LineOfSight, flags)) { float distance = vAnySafePoint.Distance(FunkyGame.Hero.Position); Logger.DBLog.DebugFormat("Flee Movement found AT {0} with {1} Distance", vAnySafePoint.ToString(), distance.ToString()); obj = new CacheObject(vAnySafePoint, TargetType.Fleeing, 20000f, "FleeSpot", 2.5f, -1); this.iSecondsFleeMoveFor = 1 + (int)(distance / 5f); return(true); } else { //Failed to find any location.. //Set the future date we must wait for to retry.. FleeRetryDate = DateTime.Now.AddMilliseconds(FunkyBaseExtension.Settings.Fleeing.FailureRetryMilliseconds); } return(false); }; }
///<summary> ///Searches through the contained GridPoints and preforms multiple tests to return a successful point for navigation. ///</summary> public bool FindSafeSpot(Vector3 CurrentLocation, out Vector3 safespot, Vector3 LoSCheckV3, PointCheckingFlags Flags, List <GridPoint> BlacklistedPoints) { bool PassedPointNonLOS = false; bool CheckingLOSV3 = LoSCheckV3 != Vector3.Zero; for (int curIndex = LastIndexUsed; curIndex < ContainedPoints.Count - 1; curIndex++) { GridPoint gp = ContainedPoints[curIndex]; if (BlacklistedPoints.Contains(gp)) { continue; } if (!CheckPoint(gp, LoSCheckV3, Flags)) { continue; } //LOS Check if (CheckingLOSV3) { if (!Navigation.CanRayCast(LastSafespotFound, LoSCheckV3, UseSearchGridProvider: true)) { LastIndexUsed = curIndex; PassedPointNonLOS = true; continue; } } //PointChecker passed! LastIndexUsed = curIndex; safespot = LastSafespotFound; return(true); } //Did we find a valid point that didn't pass LOS? if (PassedPointNonLOS) { safespot = LastSafespotFound; return(true); } LastSafespotFound = Vector3.Zero; safespot = LastSafespotFound; LastIndexUsed = 0; return(false); }
private void iterateGPRectsSafeSpot(Vector3 CurrentPosition, out Vector3 safespot, Vector3 LOS, PointCheckingFlags Flags) { //blacklisted a point?.. we advance to next index! if (BlacklistedPoint) { lastGPRectIndexUsed++; BlacklistedPoint = false; } GPRectangle PositionRect = GetGPRectContainingPoint(CurrentPosition); if (PositionRect != null) { PositionRect.UpdateObjectCount(); } GPQuadrant PositionQuadrant = PositionRect.GetQuadrantContainingPoint(CurrentPosition); double CompareWeight = PositionQuadrant != null ? PositionQuadrant.ThisWeight : PositionRect != null ? PositionRect.Weight : 0; safespot = Vector3.Zero; Dictionary <Vector3, int> safespotsFound = new Dictionary <Vector3, int>(); for (int i = lastGPRectIndexUsed; i < gridpointrectangles_.Count - 1; i++) { GPRectangle item = gridpointrectangles_[i]; item.UpdateObjectCount(AllGPRectsFailed); Vector3 safespotRect; if (item.TryFindSafeSpot(CurrentPosition, out safespotRect, LOS, Flags, BlacklistedGridpoints, AllGPRectsFailed, CompareWeight)) { safespotsFound.Add(safespotRect, i); BlacklistedGridpoints.Add(safespotRect); } } if (safespotsFound.Count > 0) { lastfoundsafespots.Clear(); Logger.DBLog.InfoFormat("Found a total of {0} possible safe spots!", safespotsFound.Count); List <Vector3> safeVectors = new List <Vector3>(safespotsFound.Keys.OrderBy(o => o.Distance(FunkyGame.Hero.Position)).ToList()); lastfoundsafespots.AddRange(safeVectors); safespot = lastfoundsafespots.First(); lastUsedGPRect = gridpointrectangles_[safespotsFound[safespot]]; } lastGPRectIndexUsed = 0; }
private void iterateGPRectsSafeSpot(Vector3 CurrentPosition, out Vector3 safespot, Vector3 LOS, PointCheckingFlags Flags) { //blacklisted a point?.. we advance to next index! if (BlacklistedPoint) { lastGPRectIndexUsed++; BlacklistedPoint = false; } GPRectangle PositionRect = GetGPRectContainingPoint(CurrentPosition); if (PositionRect != null) { PositionRect.UpdateObjectCount(); } GPQuadrant PositionQuadrant = PositionRect.GetQuadrantContainingPoint(CurrentPosition); double CompareWeight = PositionQuadrant != null ? PositionQuadrant.ThisWeight : PositionRect != null ? PositionRect.Weight : 0; safespot = Vector3.Zero; for (int i = lastGPRectIndexUsed; i < gridpointrectangles_.Count - 1; i++) { GPRectangle item = gridpointrectangles_[i]; item.UpdateObjectCount(AllGPRectsFailed); if (item.TryFindSafeSpot(CurrentPosition, out safespot, LOS, Flags, BlacklistedGridpoints, AllGPRectsFailed, CompareWeight)) { lastUsedGPRect = gridpointrectangles_[i]; return; } } lastGPRectIndexUsed = 0; }
///<summary> ///Searches through the contained GridPoints and preforms multiple tests to return a successful point for navigation. ///</summary> public bool FindSafeSpot(Vector3 CurrentLocation, out Vector3 safespot, Vector3 LoSCheckV3, PointCheckingFlags Flags, List<GridPoint> BlacklistedPoints) { bool PassedPointNonLOS = false; bool CheckingLOSV3 = LoSCheckV3 != Vector3.Zero; for (int curIndex = LastIndexUsed; curIndex < ContainedPoints.Count - 1; curIndex++) { GridPoint gp = ContainedPoints[curIndex]; if (BlacklistedPoints.Contains(gp)) continue; if (!CheckPoint(gp, LoSCheckV3, Flags)) continue; //LOS Check if (CheckingLOSV3) { if (!Navigation.CheckVectorFlags((Vector3)gp, LoSCheckV3, PointCheckingFlags.AvoidanceOverlap | PointCheckingFlags.RaycastNavProvider)) { LastIndexUsed = curIndex; PassedPointNonLOS = true; continue; } } //PointChecker passed! LastIndexUsed = curIndex; safespot = LastSafespotFound; return true; } //Did we find a valid point that didn't pass LOS? if (PassedPointNonLOS) { safespot = LastSafespotFound; return true; } LastSafespotFound = Vector3.Zero; safespot = LastSafespotFound; LastIndexUsed = 0; return false; }
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 (FunkyGame.Navigation.CheckPointAgainstBlockedDirection(point)) return false; } //Create Vector3 Vector3 pointVectorReturn = (Vector3)point; Vector3 pointVector = pointVectorReturn; Vector3 botcurpos = FunkyGame.Hero.Position; //2D Obstacle Navigation Check bool ZCheck = false; if (this.AreaIsFlat) { if (flags.HasFlag(PointCheckingFlags.ObstacleOverlap)) { if (ObjectCache.Obstacles.Values.OfType<CacheServerObject>().Any(obj => ObjectCache.CheckFlag(ObstacleType.Navigation, obj.Obstacletype.Value) && obj.PointInside(point))) return false; } if (flags.HasFlag(PointCheckingFlags.ObstacleIntersection)) { if (ObjectCache.Obstacles.Values.OfType<CacheServerObject>().Any(obj => ObjectCache.CheckFlag(ObstacleType.Navigation, 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 => ObjectCache.CheckFlag(ObstacleType.Navigation, obj.Obstacletype.Value) && obj.PointInside(pointVector))) return false; } if (flags.HasFlag(PointCheckingFlags.ObstacleIntersection)) { if (ObjectCache.Obstacles.Values.OfType<CacheServerObject>().Any(obj => ObjectCache.CheckFlag(ObstacleType.Navigation, obj.Obstacletype.Value) && obj.TestIntersection(botcurpos, pointVector))) return false; } } if (!Navigation.CheckVectorFlags(botcurpos, pointVector, flags)) return false; LastSafespotFound = pointVectorReturn; LastSafeGridPointFound = point.Clone(); return true; }
private void iterateGPRectsSafeSpot(Vector3 CurrentPosition, out Vector3 safespot, Vector3 LOS, PointCheckingFlags Flags) { //blacklisted a point?.. we advance to next index! if (BlacklistedPoint) { lastGPRectIndexUsed++; BlacklistedPoint = false; } GPRectangle PositionRect = GetGPRectContainingPoint(CurrentPosition); if (PositionRect != null) PositionRect.UpdateObjectCount(); GPQuadrant PositionQuadrant = PositionRect.GetQuadrantContainingPoint(CurrentPosition); double CompareWeight = PositionQuadrant != null ? PositionQuadrant.ThisWeight : PositionRect != null ? PositionRect.Weight : 0; safespot = Vector3.Zero; Dictionary<Vector3, int> safespotsFound = new Dictionary<Vector3, int>(); for (int i = lastGPRectIndexUsed; i < gridpointrectangles_.Count - 1; i++) { GPRectangle item = gridpointrectangles_[i]; item.UpdateObjectCount(AllGPRectsFailed); Vector3 safespotRect; if (item.TryFindSafeSpot(CurrentPosition, out safespotRect, LOS, Flags, BlacklistedGridpoints, AllGPRectsFailed, CompareWeight)) { safespotsFound.Add(safespotRect, i); BlacklistedGridpoints.Add(safespotRect); } } if (safespotsFound.Count>0) { lastfoundsafespots.Clear(); Logger.DBLog.InfoFormat("Found a total of {0} possible safe spots!", safespotsFound.Count); List<Vector3> safeVectors=new List<Vector3>(safespotsFound.Keys.OrderBy(o => o.Distance(FunkyGame.Hero.Position)).ToList()); lastfoundsafespots.AddRange(safeVectors); safespot = lastfoundsafespots.First(); lastUsedGPRect = gridpointrectangles_[safespotsFound[safespot]]; } lastGPRectIndexUsed = 0; }
public bool TryFindSafeSpot(Vector3 CurrentPosition, out Vector3 safespot, Vector3 los, PointCheckingFlags Flags, List<GridPoint> BlacklistedPoints, bool expandOnFailure = false, double CurrentWeight = 0) { lastUsedQuadrant = null; safespot = Vector3.Zero; //Do not continue search if all sectors failed recently. if (AllQuadrantsFailed) return false; bool CheckingWeight = (CurrentWeight > 0); foreach (var item in Quadrant.Values) { if (item == null) continue; if (CheckingWeight && item.ThisWeight > CurrentWeight) continue; if (item.FindSafeSpot(CurrentPosition, out safespot, los, Flags, BlacklistedPoints)) { lastUsedQuadrant = item; return true; } } AllQuadrantsFailed = true; if (expandOnFailure && CanExpandFurther) { //Logger.DBLog.InfoFormat("Expanding GPC due to failure to find a location!"); this.FullyExpand(); this.UpdateQuadrants(); this.UpdateObjectCount(); } return false; }
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 static bool CheckVectorFlags(Vector3 currentPos, Vector3 targetPos, PointCheckingFlags flags) { //Avoidance Check (Any Avoidance) if (flags.HasFlag(PointCheckingFlags.AvoidanceOverlap)) { if (ObjectCache.Obstacles.IsPositionWithinAvoidanceArea(targetPos)) return false; } //Kiting Check //if (flags.HasFlag(PointCheckingFlags.MonsterOverlap)) //{ // if (ObjectCache.Objects.OfType<CacheUnit>().Any(m => m.ShouldFlee && m.IsPositionWithinRange(targetPos, FunkyBaseExtension.Settings.Fleeing.FleeMaxMonsterDistance))) return false; //} //Avoidance Intersection Check if (flags.HasFlag(PointCheckingFlags.AvoidanceIntersection)) { if (ObjectCache.Obstacles.TestVectorAgainstAvoidanceZones(currentPos, targetPos)) return false; } Vector3 botcurpos = FunkyGame.Hero.Position; if (flags.HasFlag(PointCheckingFlags.Raycast)) { if (!Navigation.CanRayCast(currentPos, targetPos)) return false; } if (flags.HasFlag(PointCheckingFlags.RaycastWalkable)) { if (!Navigation.CanRayCast(currentPos, targetPos, NavCellFlags.AllowWalk)) return false; } if (flags.HasFlag(PointCheckingFlags.RaycastNavProvider)) { if (!Navigation.CanRayCast(currentPos, targetPos, UseSearchGridProvider: true)) return false; } return true; }
///<summary> ///Searches for a safespot ///</summary> public bool AttemptFindSafeSpot(out Vector3 safespot, Vector3 LOS, PointCheckingFlags flags) { safespot = vlastSafeSpot; Vector3 BotPosition = FunkyGame.Hero.Position; //Recreate the entire area? if (!CurrentAreaValid()) CurrentGPArea = new GPArea(BotPosition); //Check Bot Navigationally blocked RefreshNavigationBlocked(); if (BotIsNavigationallyBlocked) { return false; } //Recreate Bot Current rect? //if (CurrentLocationGPrect == null || CurrentLocationGPrect.centerpoint != FunkyGame.Hero.PointPosition) //{ // FunkyGame.Navigation.CurrentLocationGPrect = new GPRectangle(BotPosition); // //Refresh boundary (blocked directions) // currentLocationBoundary = new AreaBoundary(BotPosition); // UpdateLocationsBlocked(); //} // FunkyGame.Navigation.CurrentLocationGPRect.UpdateObjectCount(); safespot = CurrentGPArea.AttemptFindSafeSpot(BotPosition, LOS, flags); return (safespot != Vector3.Zero); }
public bool TryFindSafeSpot(Vector3 CurrentPosition, out Vector3 safespot, Vector3 los, PointCheckingFlags Flags, List <GridPoint> BlacklistedPoints, bool expandOnFailure = false, double CurrentWeight = 0) { lastUsedQuadrant = null; safespot = Vector3.Zero; //Do not continue search if all sectors failed recently. if (AllQuadrantsFailed) { return(false); } bool CheckingWeight = (CurrentWeight > 0); foreach (var item in Quadrant.Values) { if (item == null) { continue; } if (CheckingWeight && item.ThisWeight > CurrentWeight) { continue; } if (item.FindSafeSpot(CurrentPosition, out safespot, los, Flags, BlacklistedPoints)) { lastUsedQuadrant = item; return(true); } } AllQuadrantsFailed = true; if (expandOnFailure && CanExpandFurther) { //Logger.DBLog.InfoFormat("Expanding GPC due to failure to find a location!"); this.FullyExpand(); this.UpdateQuadrants(); this.UpdateObjectCount(); } return(false); }
private void iterateGPRectsSafeSpot(Vector3 CurrentPosition, out Vector3 safespot, Vector3 LOS, PointCheckingFlags Flags) { //blacklisted a point?.. we advance to next index! if (BlacklistedPoint) { lastGPRectIndexUsed++; BlacklistedPoint = false; } GPRectangle PositionRect = GetGPRectContainingPoint(CurrentPosition); if (PositionRect != null) PositionRect.UpdateObjectCount(); GPQuadrant PositionQuadrant = PositionRect.GetQuadrantContainingPoint(CurrentPosition); double CompareWeight = PositionQuadrant != null ? PositionQuadrant.ThisWeight : PositionRect != null ? PositionRect.Weight : 0; safespot = Vector3.Zero; for (int i = lastGPRectIndexUsed; i < gridpointrectangles_.Count - 1; i++) { GPRectangle item = gridpointrectangles_[i]; item.UpdateObjectCount(AllGPRectsFailed); if (item.TryFindSafeSpot(CurrentPosition, out safespot, LOS, Flags, BlacklistedGridpoints, AllGPRectsFailed, CompareWeight)) { lastUsedGPRect = gridpointrectangles_[i]; return; } } lastGPRectIndexUsed = 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 (FunkyGame.Navigation.CheckPointAgainstBlockedDirection(point)) { return(false); } } //Create Vector3 Vector3 pointVectorReturn = (Vector3)point; Vector3 pointVector = pointVectorReturn; Vector3 botcurpos = FunkyGame.Hero.Position; //2D Obstacle Navigation Check bool ZCheck = false; if (this.AreaIsFlat) { if (flags.HasFlag(PointCheckingFlags.ObstacleOverlap)) { if (ObjectCache.Obstacles.Values.OfType <CacheServerObject>().Any(obj => ObjectCache.CheckFlag(ObstacleType.Navigation, obj.Obstacletype.Value) && obj.PointInside(point))) { return(false); } } if (flags.HasFlag(PointCheckingFlags.ObstacleIntersection)) { if (ObjectCache.Obstacles.Values.OfType <CacheServerObject>().Any(obj => ObjectCache.CheckFlag(ObstacleType.Navigation, 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 => ObjectCache.CheckFlag(ObstacleType.Navigation, obj.Obstacletype.Value) && obj.PointInside(pointVector))) { return(false); } } if (flags.HasFlag(PointCheckingFlags.ObstacleIntersection)) { if (ObjectCache.Obstacles.Values.OfType <CacheServerObject>().Any(obj => ObjectCache.CheckFlag(ObstacleType.Navigation, obj.Obstacletype.Value) && obj.TestIntersection(botcurpos, pointVector))) { return(false); } } } if (!Navigation.CheckVectorFlags(botcurpos, pointVector, flags)) { return(false); } LastSafespotFound = pointVectorReturn; LastSafeGridPointFound = point.Clone(); return(true); }
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); }
///<summary> ///Searches for a safespot ///</summary> public bool AttemptFindSafeSpot(out Vector3 safespot, Vector3 LOS, PointCheckingFlags flags) { safespot = vlastSafeSpot; Vector3 BotPosition = Bot.Character.Data.Position; //Recreate the entire area? if (Bot.NavigationCache.CurrentGPArea == null || Bot.NavigationCache.CurrentGPArea.AllGPRectsFailed && !Bot.NavigationCache.CurrentGPArea.centerGPRect.Contains(BotPosition) || !Bot.NavigationCache.CurrentGPArea.GridPointContained(BotPosition)) Bot.NavigationCache.CurrentGPArea = new GPArea(BotPosition); //Check Bot Navigationally blocked RefreshNavigationBlocked(); if (BotIsNavigationallyBlocked) { return false; } //Recreate Bot Current rect? if (Bot.NavigationCache.CurrentLocationGPrect == null || Bot.NavigationCache.CurrentLocationGPrect.centerpoint != Bot.Character.Data.PointPosition) { Bot.NavigationCache.CurrentLocationGPrect = new GPRectangle(BotPosition); //Refresh boundary (blocked directions) currentLocationBoundary = new AreaBoundary(BotPosition); UpdateLocationsBlocked(); } // Bot.NavigationCache.CurrentLocationGPRect.UpdateObjectCount(); safespot = Bot.NavigationCache.CurrentGPArea.AttemptFindSafeSpot(BotPosition, LOS, flags); return (safespot != Vector3.Zero); }