private bool NotStarted() { State = States.Clearing; _currentDestination = ActorFinder.FindNearestHostileUnitInRadius(_center, _radius); if (_currentDestination == Vector3.Zero && !_forceMoveAround) { State = States.Completed; return(false); } if (_forceMoveAround) { // Desperate Measures _forceClearDestinations = new ConcurrentBag <Vector3>( ExplorationHelpers.GetFourPointsInEachDirection(_center, _radius).Where(d => d != Vector3.Zero)); Core.Logger.Debug($"[ClearArea] No actors found in the area, using the desperate measures. Center={_center} Radius={_radius}"); State = States.ForceClearing; if (_forceClearDestinations.TryTake(out _currentDestination)) { return(false); } Core.Logger.Error($"[ClearArea] Couldn't get force clear destinations, ending tag. Center={_center} Radius={_radius}"); State = States.Completed; return(true); } return(false); }
//private readonly WaitTimer _newNodePickTimer = new WaitTimer(TimeSpan.FromSeconds(60)); private async Task <bool> Exploring() { if (_currentDestination == null || _currentDestination.IsVisited)// || _newNodePickTimer.IsFinished) { //_newNodePickTimer.Stop(); //_currentDestination = ExplorationHelpers.NearestWeightedUnvisitedNodeLocation(_levelAreaIds); if (_currentDestination != null) { _currentDestination.IsCurrentDestination = false; } _currentDestination = ExplorationHelpers.NearestWeightedUnvisitedNode(_levelAreaIds); if (_currentDestination != null) { _currentDestination.IsCurrentDestination = true; } //_newNodePickTimer.Reset(); } if (_currentDestination != null) { if (await NavigationCoroutine.MoveTo(_currentDestination.NavigableCenter, 3)) { _currentDestination.IsVisited = true; _currentDestination.IsCurrentDestination = false; _currentDestination = null; } return(false); } State = States.Completed; return(false); }
private void ScanForObjective() { if (_previouslyFoundLocation != Vector3.Zero && PluginTime.ReadyToUse(_returnTimeForPreviousLocation, 60000)) { _objectiveLocation = _previouslyFoundLocation; _previouslyFoundLocation = Vector3.Zero; Core.Logger.Debug("[KillUniqueMonster] Returning previous objective location."); return; } if (PluginTime.ReadyToUse(_lastScanTime, 1000)) { _lastScanTime = PluginTime.CurrentMillisecond; if (_marker != 0) { _objectiveLocation = BountyHelpers.ScanForMarkerLocation(_marker, _objectiveScanRange); } if (_objectiveLocation == Vector3.Zero && _actorId != 0) { _objectiveLocation = BountyHelpers.ScanForActorLocation(_actorId, _objectiveScanRange); } if (_objectiveLocation != Vector3.Zero) { using (new PerformanceLogger("[KillUniqueMonster] Path to Objective Check", true)) { Core.Logger.Log("[KillUniqueMonster] Found the objective at distance {0}", AdvDia.MyPosition.Distance(_objectiveLocation)); ExplorationHelpers.SetExplorationPriority(_objectiveLocation); } } } }
private bool NotStarted() { State = States.Exploring; if (_ignoreScenes != null && _ignoreScenes.Any()) { ExplorationHelpers.MarkNodesAsVisited(_ignoreScenes); } return(false); }
private void ScanForObjective() { if (_previouslyFoundLocation != Vector3.Zero && PluginTime.ReadyToUse(_returnTimeForPreviousLocation, 60000)) { _objectiveLocation = _previouslyFoundLocation; _previouslyFoundLocation = Vector3.Zero; _returnTimeForPreviousLocation = PluginTime.CurrentMillisecond; Core.Logger.Debug("Returning previous objective location."); return; } if (PluginTime.ReadyToUse(_lastScanTime, 1000)) { _lastScanTime = PluginTime.CurrentMillisecond; TrinityMarker marker = null; if (_markerHash != 0) { if (_markerHash == -1) { marker = BountyHelpers.ScanForMarker(0, _objectiveScanRange); } else { marker = BountyHelpers.ScanForMarker(_markerHash, _markerType, _objectiveScanRange); } } else if (!string.IsNullOrEmpty(_markerName)) { marker = BountyHelpers.ScanForMarker(_markerName, _objectiveScanRange); } else if (_markerType != default(WorldMarkerType)) { marker = BountyHelpers.ScanForMarker(_markerType, _objectiveScanRange); } if (marker != null && marker.Position != Vector3.Zero) { _objectiveLocation = marker.Position; Core.Logger.Log($"[MoveToMapMarker] Found the objective {marker}"); ExplorationHelpers.SetExplorationPriority(_objectiveLocation); } _objectiveLocation = marker?.Position ?? Vector3.Zero; } }
private void ScanForObjective() { if (_previouslyFoundLocation != Vector3.Zero && PluginTime.ReadyToUse(_returnTimeForPreviousLocation, 60000)) { _objectiveLocation = _previouslyFoundLocation; _previouslyFoundLocation = Vector3.Zero; Core.Logger.Debug("[MoveToScene] Returning previous objective location."); return; } if (PluginTime.ReadyToUse(_lastScanTime, 1000)) { _lastScanTime = PluginTime.CurrentMillisecond; if (!string.IsNullOrEmpty(SceneName)) { _scene = Core.Scenes.CurrentWorldScenes.OrderBy(s => s.Center.DistanceSqr(AdvDia.MyPosition.ToVector2())).FirstOrDefault(s => s.Name.ToLowerInvariant().Contains(SceneName.ToLowerInvariant()) || s.HasChild && s.SubScene.Name.ToLowerInvariant().Contains(SceneName.ToLowerInvariant())); var centerNode = _scene?.Nodes.Where(n => n.HasEnoughNavigableCells) .OrderBy(n => n.Center.DistanceSqr(_scene.Center)) .FirstOrDefault(); if (centerNode != null) { _objectiveLocation = centerNode.NavigableCenter; } } if (_objectiveLocation != Vector3.Zero && PluginTime.ReadyToUse(_lastObjectiveFoundTime, 20000)) { _lastObjectiveFoundTime = PluginTime.CurrentMillisecond; using (new PerformanceLogger("[MoveToScene] Path to Objective Check", true)) { Core.Logger.Log("[MoveToScene] Found the objective at distance {0}", AdvDia.MyPosition.Distance(_objectiveLocation)); ExplorationHelpers.SetExplorationPriority(_objectiveLocation); } } else { _objectiveLocation = Vector3.Zero; } } }
protected override void OnWorldChanged(ChangeEventArgs <SNOWorld> args) { ExplorationHelpers.ClearExplorationPriority(); PurgeOldScenes(); Update(); }
private async Task <bool> Exploring() { if (_useIgnoreRegions) { ExplorationHelpers.UpdateIgnoreRegions(); } if (_currentDestination == null || _currentDestination.IsVisited) { if (_explorationDataMaxWaitUntil != DateTime.MinValue && DateTime.UtcNow > _explorationDataMaxWaitUntil) { Core.Logger.Debug($"[Exploration] Timeout waiting for exploration data"); State = States.Completed; return(false); } if (!ExplorationGrid.Instance.WalkableNodes.Any()) { if (_explorationDataMaxWaitUntil == DateTime.MinValue) { _explorationDataMaxWaitUntil = DateTime.UtcNow + TimeSpan.FromSeconds(15); } Core.Scenes.Update(); await Coroutine.Sleep(1000); Core.Logger.Debug($"[Exploration] Patiently waiting for exploration data"); return(false); } _explorationDataMaxWaitUntil = DateTime.MinValue; if (_currentDestination != null) { _currentDestination.IsCurrentDestination = false; } var destination = ExplorationHelpers.NearestWeightedUnvisitedNode(_levelAreaIds); // Ignore marking nodes as Visited for bounties. if (destination != null && ZetaDia.Storage.Quests.ActiveBounty == null) { WorldScene destScene = destination.Scene; Vector3 destinationPos = destination.NavigableCenter; var exitPositions = destScene.ExitPositions; var connectedScenes = destScene.ConnectedScenes(); var unconnectedExits = exitPositions.Where(ep => connectedScenes.FirstOrDefault(cs => cs.Direction == ep.Key) == null); if (destinationPos.Distance(ExplorationHelpers.PriorityPosition) >= 15) { if (!unconnectedExits.Any(ep => destinationPos.Distance(ep.Value) <= 15) && ZetaDia.Minimap.IsExplored(destinationPos, AdvDia.CurrentWorldDynamicId)) { destination.IsVisited = true; destination.IsKnown = true; return(false); } } } if (destination == null) { Core.Logger.Debug($"[Exploration] No more unvisited nodes to explore, so we're done."); State = States.Completed; return(false); } if (_currentDestination != destination) { Core.Logger.Debug($"[Exploration] Destination Changed from {_currentDestination?.NavigableCenter} to {destination.NavigableCenter}"); _currentDestination = destination; } if (_currentDestination != null) { Core.Logger.Debug($"[Exploration] Current Destination {_currentDestination?.NavigableCenter}, CanRayWalk={CanRayWalkDestination} MyPosition={AdvDia.MyPosition}"); _currentDestination.IsCurrentDestination = true; } //_newNodePickTimer.Reset(); } if (_currentDestination != null) { if (await NavigationCoroutine.MoveTo(_currentDestination.NavigableCenter, 15)) { if (NavigationCoroutine.LastResult == CoroutineResult.Failure && (NavigationCoroutine.LastMoveResult == MoveResult.Failed || NavigationCoroutine.LastMoveResult == MoveResult.PathGenerationFailed)) { _currentDestination.FailedNavigationAttempts++; var canClientPathTo = await AdvDia.Navigator.CanFullyClientPathTo(_currentDestination.NavigableCenter); if (_currentDestination.FailedNavigationAttempts >= 10 && !canClientPathTo) { Core.Logger.Debug($"[Exploration] Unable to client path to {_currentDestination.NavigableCenter} and failed {_currentDestination.FailedNavigationAttempts} times; Ignoring Node."); _currentDestination.IsVisited = true; _currentDestination.IsIgnored = true; _currentDestination.IsCurrentDestination = false; _currentDestination = null; _failedNavigationAttempts++; } else if (!CanRayWalkDestination && _currentDestination.Distance < 25f && _currentDestination.FailedNavigationAttempts >= 3 || _currentDestination.FailedNavigationAttempts >= 15) { Core.Logger.Debug($"[Exploration] Failed to Navigate to {_currentDestination.NavigableCenter} {_currentDestination.FailedNavigationAttempts} times; Ignoring Node."); _currentDestination.IsVisited = true; _currentDestination.IsIgnored = true; _currentDestination.IsCurrentDestination = false; _currentDestination = null; _failedNavigationAttempts++; } } else { Core.Logger.Debug($"[Exploration] Destination Reached!"); _currentDestination.FailedNavigationAttempts = 0; _currentDestination.IsVisited = true; _currentDestination.IsCurrentDestination = false; _currentDestination = null; } if (_failedNavigationAttempts > 25) { if (_allowReExplore) { Core.Logger.Debug($"[Exploration] Exploration Resetting"); Core.Scenes.Reset(); Navigator.Clear(); _failedNavigationAttempts = 0; } else { Core.Logger.Debug($"[Exploration] too many failed navigation attempts, aborting."); State = States.Completed; return(false); } } } return(false); } Core.Logger.Debug($"[Exploration] We found no explore destination, so we're done."); Core.Scenes.Reset(); Navigator.Clear(); State = States.Completed; return(false); }
private void ScanForObjective() { //if (_previouslyFoundLocation != Vector3.Zero && PluginTime.ReadyToUse(_returnTimeForPreviousLocation, 60000)) //{ // _objectiveLocation = _previouslyFoundLocation; // _previouslyFoundLocation = Vector3.Zero; // Core.Logger.Debug("[MoveToScenePosition] Returning previous objective location."); // return; //} if (PluginTime.ReadyToUse(_lastScanTime, 1000)) { _lastScanTime = PluginTime.CurrentMillisecond; if (_sceneSnoId > 0) { var scene = Core.Scenes.CurrentWorldScenes.OrderBy(s => s.Center.DistanceSqr(AdvDia.MyPosition.ToVector2())).FirstOrDefault(s => s.SnoId == _sceneSnoId || s.HasChild && s.SubScene.SnoId == _sceneSnoId); if (scene != null) { _worldScene = scene; _objectiveLocation = _worldScene.GetWorldPosition(_position); ExplorationHelpers.SetExplorationPriority(_objectiveLocation); Core.Logger.Debug($"Scan found target scene by SnoId {_worldScene.Name} ({_worldScene.SnoId}). Pos={_objectiveLocation} Dist={_objectiveLocation.Distance(AdvDia.MyPosition)} Relative={_position}"); } } else if (!string.IsNullOrEmpty(_sceneName)) { var scene = Core.Scenes.CurrentWorldScenes.OrderBy( s => s.Center.DistanceSqr(AdvDia.MyPosition.ToVector2())) .FirstOrDefault( s => s.Name.ToLowerInvariant().Contains(_sceneName.ToLowerInvariant()) || s.SubScene != null && s.SubScene.Name.ToLowerInvariant().Contains(_sceneName.ToLowerInvariant()) ); if (scene != null) { _worldScene = scene; _objectiveLocation = _worldScene.GetWorldPosition(_position); ExplorationHelpers.SetExplorationPriority(_objectiveLocation); Core.Logger.Debug($"Scan found target scene {_worldScene.Name} ({_worldScene.SnoId}). Pos={_objectiveLocation} Dist={_objectiveLocation.Distance(AdvDia.MyPosition)} Relative={_position}"); } } if (!Core.Scenes.CurrentScene.IsConnected(_objectiveLocation)) { Core.Logger.Debug($"Unable to reach the scene, we need to uncover more intermediary scenes first"); _objectiveLocation = Vector3.Zero; } //else if (!string.IsNullOrEmpty(_tempSceneName)) //{ // var scene = Core.Scenes.CurrentWorldScenes.OrderBy(s => s.Center.DistanceSqr(AdvDia.MyPosition.ToVector2())).FirstOrDefault(s => s.Name == _tempSceneName); // if (scene != null) // { // _worldScene = scene; // _objectiveLocation = _worldScene.GetWorldPosition(_position); // } //} //if (_objectiveLocation == Vector3.Zero && _actorId != 0) //{ // _objectiveLocation = BountyHelpers.ScanForActorLocation(_actorId, _objectiveScanRange); //} //if (_objectiveLocation != Vector3.Zero) //{ // using (new PerformanceLogger("[MoveToScenePosition] Path to Objective Check", true)) // { // //if ((Navigator.GetNavigationProviderAs<Navigator>().CanFullyClientPathTo(_objectiveLocation))) // //{ // Core.Logger.Log("[MoveToScenePosition] Found the objective at distance {0}", // AdvDia.MyPosition.Distance(_objectiveLocation)); // //} // //else // //{ // // Core.Logger.Debug("[MoveToMapMarker] Found the objective at distance {0}, but cannot get a path to it.", // // AdvDia.MyPosition.Distance(_objectiveLocation)); // // _objectiveLocation = Vector3.Zero; // //} // } //} } }
private void ScanForObjective() { if (_previouslyFoundLocation != Vector3.Zero && PluginTime.ReadyToUse(_returnTimeForPreviousLocation, 60000)) { _objectiveLocation = _previouslyFoundLocation; _previouslyFoundLocation = Vector3.Zero; _returnTimeForPreviousLocation = PluginTime.CurrentMillisecond; Core.Logger.Debug("[EnterLevelArea] Returning previous objective location."); return; } if (PluginTime.ReadyToUse(_lastScanTime, 250)) { _lastScanTime = PluginTime.CurrentMillisecond; if (_portalMarker != 0) { if (_objectiveLocation == Vector3.Zero) { // Help with weighting exploration nodes even if its unreachable/unpathable. var markerlocation = BountyHelpers.ScanForMarkerLocation(_portalMarker, 5000); ExplorationHelpers.SetExplorationPriority(markerlocation); } _objectiveLocation = BountyHelpers.ScanForMarkerLocation(_portalMarker, _objectiveScanRange); if (ExplorationData.FortressLevelAreaIds.Contains(AdvDia.CurrentLevelAreaId)) { _deathGateLocation = DeathGates.GetBestGatePosition(_objectiveLocation); if (_deathGateLocation != Vector3.Zero) { if (Navigator.StuckHandler.IsStuck && _deathGateLocation.Distance(AdvDia.MyPosition) < 125f) { var nearestGate = ActorFinder.FindNearestDeathGate(); if (nearestGate != null) { Core.Logger.Warn("Found death gate location"); _objectiveLocation = nearestGate.Position; } } } } } if (_objectives != null && _objectives.Any()) { BountyHelpers.ObjectiveActor objective; _objectiveLocation = BountyHelpers.TryFindObjectivePosition(_objectives, _objectiveScanRange, out objective); if (objective != null) { _objective = objective; _portalActorId = objective.ActorId; _destinationWorldId = objective.DestWorldId; } } // Belial if (_objectiveLocation == Vector3.Zero && _portalActorId == 159574) { _objectiveLocation = BountyHelpers.ScanForActorLocation(_portalActorId, _objectiveScanRange); } //if (_objectiveLocation == Vector3.Zero && _portalActorId != 0) //{ // _objectiveLocation = BountyHelpers.ScanForActorLocation(_portalActorId, _objectiveScanRange); //} if (_objectiveLocation != Vector3.Zero) { Core.Logger.Log("[EnterLevelArea] Found the objective at distance {0}", AdvDia.MyPosition.Distance(_objectiveLocation)); ExplorationHelpers.SetExplorationPriority(_objectiveLocation); } } }
//private readonly WaitTimer _newNodePickTimer = new WaitTimer(TimeSpan.FromSeconds(60)); private async Task <bool> Exploring() { if (_useIgnoreRegions) { ExplorationHelpers.UpdateIgnoreRegions(); } if (_currentDestination == null || _currentDestination.IsVisited)// || _newNodePickTimer.IsFinished) { //_newNodePickTimer.Stop(); //_currentDestination = ExplorationHelpers.NearestWeightedUnvisitedNodeLocation(_levelAreaIds); if (_explorationDataMaxWaitUntil != DateTime.MinValue && DateTime.UtcNow > _explorationDataMaxWaitUntil) { Core.Logger.Debug($"[Exploration] Timeout waiting for exploration data"); State = States.Completed; return(false); } if (!ExplorationGrid.Instance.WalkableNodes.Any()) { if (_explorationDataMaxWaitUntil == DateTime.MinValue) { _explorationDataMaxWaitUntil = DateTime.UtcNow + TimeSpan.FromSeconds(15); } Core.Scenes.Update(); await Coroutine.Sleep(1000); Core.Logger.Debug($"[Exploration] Patiently waiting for exploration data"); return(false); } _explorationDataMaxWaitUntil = DateTime.MinValue; if (_currentDestination != null) { _currentDestination.IsCurrentDestination = false; } var destination = ExplorationHelpers.NearestWeightedUnvisitedNode(_levelAreaIds); if (destination == null) { Core.Logger.Debug($"[Exploration] No more unvisited nodes to explore, so we're done."); State = States.Completed; return(false); } if (_currentDestination != destination) { Core.Logger.Debug($"[Exploration] Destination Changed from {_currentDestination?.NavigableCenter} to {destination.NavigableCenter}"); _currentDestination = destination; } if (_currentDestination != null) { Core.Logger.Debug($"[Exploration] Current Destination {_currentDestination?.NavigableCenter}, CanRayWalk={CanRayWalkDestination} MyPosition={AdvDia.MyPosition}"); _currentDestination.IsCurrentDestination = true; } //_newNodePickTimer.Reset(); } if (_currentDestination != null) { if (await NavigationCoroutine.MoveTo(_currentDestination.NavigableCenter, 15)) { if (NavigationCoroutine.LastResult == CoroutineResult.Failure && (NavigationCoroutine.LastMoveResult == MoveResult.Failed || NavigationCoroutine.LastMoveResult == MoveResult.PathGenerationFailed)) { _currentDestination.FailedNavigationAttempts++; var canClientPathTo = await AdvDia.Navigator.CanFullyClientPathTo(_currentDestination.NavigableCenter); if (_currentDestination.FailedNavigationAttempts >= 10 && !canClientPathTo) { Core.Logger.Debug($"[Exploration] Unable to client path to {_currentDestination.NavigableCenter} and failed {_currentDestination.FailedNavigationAttempts} times; Ignoring Node."); _currentDestination.IsVisited = true; _currentDestination.IsIgnored = true; _currentDestination.IsCurrentDestination = false; _currentDestination = null; _failedNavigationAttempts++; } else if (!CanRayWalkDestination && _currentDestination.Distance < 25f && _currentDestination.FailedNavigationAttempts >= 3 || _currentDestination.FailedNavigationAttempts >= 15) { Core.Logger.Debug($"[Exploration] Failed to Navigate to {_currentDestination.NavigableCenter} {_currentDestination.FailedNavigationAttempts} times; Ignoring Node."); _currentDestination.IsVisited = true; _currentDestination.IsIgnored = true; _currentDestination.IsCurrentDestination = false; _currentDestination = null; _failedNavigationAttempts++; } } else { Core.Logger.Debug($"[Exploration] Destination Reached!"); _currentDestination.FailedNavigationAttempts = 0; _currentDestination.IsVisited = true; _currentDestination.IsCurrentDestination = false; _currentDestination = null; } if (_failedNavigationAttempts > 25) { if (_allowReExplore) { Core.Logger.Debug($"[Exploration] Exploration Resetting"); Core.Scenes.Reset(); Navigator.Clear(); _failedNavigationAttempts = 0; } else { Core.Logger.Debug($"[Exploration] too many failed navigation attempts, aborting."); State = States.Completed; return(false); } } } return(false); } Core.Logger.Debug($"[Exploration] We found no explore destination, so we're done."); Core.Scenes.Reset(); Navigator.Clear(); State = States.Completed; return(false); }