protected override Composite CreateBehavior() { return(new PrioritySelector( new Decorator(ret => ZetaDia.IsLoadingWorld, new Action() ), new Decorator(ret => ZetaDia.IsInTown && !DataDictionary.ForceTownPortalLevelAreaIds.Contains(Player.LevelAreaId), new Action(ret => { ForceClearArea = false; AreaClearTimer.Reset(); _isDone = true; }) ), new Decorator(ret => !ZetaDia.IsInTown && !ZetaDia.Me.CanUseTownPortal(), new Action(ret => { ForceClearArea = false; AreaClearTimer.Reset(); _isDone = true; }) ), new Decorator(ret => ZetaDia.Me.HitpointsCurrent < _startHealth, new Action(ret => { _startHealth = ZetaDia.Me.HitpointsCurrent; AreaClearTimer.Restart(); ForceClearArea = true; }) ), new Decorator(ret => AreaClearTimer.IsRunning, new PrioritySelector( new Decorator(ret => AreaClearTimer.ElapsedMilliseconds <= WaitTime, new Action(ret => ForceClearArea = true) // returns RunStatus.Success ), new Decorator(ret => AreaClearTimer.ElapsedMilliseconds > WaitTime, new Action(ret => { Logger.Log("Town Portal timer finished"); ForceClearArea = false; AreaClearTimer.Reset(); }) ) ) ), new Decorator(ret => !ForceClearArea, new PrioritySelector( new Decorator(ret => ZetaDia.Me.Movement.IsMoving, new Sequence( CommonBehaviors.MoveStop(), new Sleep(1000) ) ), new Decorator(ret => PortalCastTimer.IsRunning && PortalCastTimer.ElapsedMilliseconds >= 7000, new Sequence( new Action(ret => { Logger.Log("Stuck casting town portal, moving a little"); Navigator.MoveTo(Navigator.StuckHandler.GetUnstuckPos(), "Unstuck Position"); PortalCastTimer.Reset(); }) ) ), new Decorator(ret => PortalCastTimer.IsRunning && ZetaDia.Me.LoopingAnimationEndTime > 0, // Already casting, just wait new Action(ret => RunStatus.Success) ), new Sequence( new Action(ret => { PortalCastTimer.Restart(); GameEvents.FireWorldTransferStart(); ZetaDia.Me.UseTownPortal(); }), new WaitContinue(3, ret => ZetaDia.Me != null && ZetaDia.Me.LoopingAnimationEndTime > 0, new Sleep(100) ) ) ) ) )); }
/// <summary> /// Main MoveToMapMarker Behavior /// </summary> /// <returns></returns> protected override Composite CreateBehavior() { return (new Sequence( new DecoratorContinue(ret => ZetaDia.Me.IsDead || ZetaDia.IsLoadingWorld, new Sequence( new Action(ret => Logger.Log("IsDead={0} IsLoadingWorld={1}", ZetaDia.Me.IsDead, ZetaDia.IsLoadingWorld)), new Action(ret => RunStatus.Failure) ) ), CheckTimeout(), new Action(ret => FindMiniMapMarker()), new DecoratorContinue(ret => _miniMapMarker != null, new Action(ret => RefreshActorInfo()) ), //new DecoratorContinue(ret => _interactObject == null && _miniMapMarker == null && Position == Vector3.Zero, // new Sequence( // new Action(ret => _miniMapMarker = GetRiftExitMarker()) // ) //), new DecoratorContinue(ret => _interactObject == null && _miniMapMarker == null && Position == Vector3.Zero, new Sequence( new Action(ret => Logger.Debug("Error: Could not find MiniMapMarker nor PortalObject nor Position {0}", Status())), new Action(ret => _isDone = true) ) ), new DecoratorContinue(ret => _lastMoveResult == MoveResult.ReachedDestination && _interactObject == null, new Sequence( new Action(ret => Logger.Log("ReachedDestination, no object found - finished!")), new Action(ret => _isDone = true), new Action(ret => RunStatus.Failure) ) ), new Sequence( new Action(ret => GameUI.SafeClickUIButtons()), new PrioritySelector( new Decorator(ret => GameUI.IsPartyDialogVisible, new Action(ret => Logger.Log("Party Dialog is visible")) ), new Decorator(ret => GameUI.IsElementVisible(GameUI.GenericOK), new Action(ret => Logger.Log("Generic OK is visible")) ), new Decorator(ret => DestinationWorldId == -1 && ZetaDia.CurrentWorldId != _startWorldId, new Sequence( new Action(ret => Logger.Log("World changed ({0} to {1}), destinationWorlId={2}, finished {3}", _startWorldId, ZetaDia.CurrentWorldId, DestinationWorldId, Status())), new Action(ret => _isDone = true) ) ), new Decorator(ret => DestinationWorldId != 0 && ZetaDia.CurrentWorldId == DestinationWorldId, new Sequence( new Action(ret => Logger.Log("DestinationWorlId matched, finished {0}", Status())), new Action(ret => _isDone = true) ) ), new Decorator(ret => _completedInteractAttempts > 1 && _lastPosition.Distance(ZetaDia.Me.Position) > 4f && DestinationWorldId != _startWorldId, new Sequence( new Action(ret => _isDone = true), new Action(ret => Logger.Log("Moved {0:0} yards after interaction, finished {1}", _lastPosition.Distance(ZetaDia.Me.Position), Status())) ) ), new Decorator(ret => _interactObject != null && _interactObject.IsValid, new PrioritySelector( new Decorator(ret => _lastMoveResult != MoveResult.ReachedDestination, new Sequence( new Action(ret => Logger.Debug("Moving to actor {0} {1}", _interactObject.ActorSNO, Status())), new Action(ret => _lastMoveResult = Navigator.MoveTo(_interactObject.Position)) ) ), new Decorator(ret => _lastMoveResult == MoveResult.ReachedDestination && _interactObject.Distance > InteractRange, new Sequence( new Action(ret => Logger.Log("ReachedDestination but not within InteractRange, finished")), new Action(ret => _isDone = true) ) ), new Decorator(ret => ZetaDia.Me.Movement.IsMoving, new Action(ret => CommonBehaviors.MoveStop())), new Sequence( new Action(ret => _lastPosition = ZetaDia.Me.Position), new Action(ret => _interactObject.Interact()), new Action(ret => _completedInteractAttempts++), new Action(ret => Logger.Debug("Interacting with portal object {0}, result: {1}", _interactObject.ActorSNO, Status())), new Sleep(500), new Action(ret => GameEvents.FireWorldTransferStart()) ) ) ), new Decorator(ret => _miniMapMarker != null && _interactObject == null, new PrioritySelector( new Decorator(ret => _miniMapMarker != null && _miniMapMarker.Position.Distance(ZetaDia.Me.Position) > PathPrecision, new Sequence( new Action(ret => Logger.Debug("Moving to Map Marker {0}, {1}", _miniMapMarker.NameHash, Status())), new Action(ret => _lastMoveResult = Navigator.MoveTo(_miniMapMarker.Position)) ) ), new Decorator(ret => _miniMapMarker != null && _miniMapMarker.Position.Distance(ZetaDia.Me.Position) < PathPrecision, new Sequence( new Action(ret => Logger.Debug("Successfully Moved to Map Marker {0}, {1}", _miniMapMarker.NameHash, Status())), new Action(ret => _isDone = true) ) ) ) ), new Decorator(ret => _miniMapMarker == null && Position != Vector3.Zero, new Sequence( new Action(ret => _lastMoveResult = Navigator.MoveTo(Position)), new DecoratorContinue(ret => _lastMoveResult == MoveResult.ReachedDestination, new Sequence( new Action(ret => Logger.Log("ReachedDestination of Position, finished.")), new Action(ret => _isDone = true) ) ) ) ), new Action(ret => Logger.LogError("MoveToMapMarker Error: marker={0} actor={1}/{2} completedInteracts={3} isPortal={4} dist={5} interactRange={6}", _miniMapMarker != null, _interactObject != null, (_interactObject != null && _interactObject.IsValid), _completedInteractAttempts, IsPortal, (_interactObject != null ? _interactObject.Position.Distance(ZetaDia.Me.Position) : 0f), InteractRange)) ) ) )); }
protected override Composite CreateBehavior() { return(new PrioritySelector( new Decorator(ret => ZetaDia.IsLoadingWorld, new Action() ), new Decorator(ret => Bot.Character.Data.bIsInTown && ZetaDia.CurrentLevelAreaId != 55313, new Action(ret => { ForceClearArea = false; AreaClearTimer.Reset(); _IsDone = true; //Logger.Logger.DBLog.InfoFormat("[TrinityTownPortal] In Town"); }) ), new Decorator(ret => !Bot.Character.Data.bIsInTown && !TownPortalBehavior.CanCastTP(), new Action(ret => { ForceClearArea = false; AreaClearTimer.Reset(); _IsDone = true; //Logger.Logger.DBLog.InfoFormat("[TrinityTownPortal] Unable to use TownPortal!"); }) ), new Decorator(ret => Bot.Character.Data.dCurrentHealthPct < _StartHealth, new Action(ret => { _StartHealth = Bot.Character.Data.dCurrentHealthPct; AreaClearTimer.Restart(); ForceClearArea = true; }) ), new Decorator(ret => AreaClearTimer.IsRunning, new PrioritySelector( new Decorator(ret => AreaClearTimer.ElapsedMilliseconds <= WaitTime, new Action(ret => ForceClearArea = true) // returns RunStatus.Success ), new Decorator(ret => AreaClearTimer.ElapsedMilliseconds > WaitTime, new Action(ret => { Logger.DBLog.DebugFormat("TownRun timer finished"); ForceClearArea = false; AreaClearTimer.Reset(); }) ) ) ), new Decorator(ret => !ForceClearArea, new PrioritySelector( new Decorator(ret => Bot.NavigationCache.IsMoving, new Sequence( CommonBehaviors.MoveStop(), new Sleep(1000) ) ), new Sequence( // Already casting, just wait new DecoratorContinue(ret => TownPortalBehavior.CastingRecall(), new Action() ), new Action(ret => { GameEvents.FireWorldTransferStart(); ZetaDia.Me.UseTownPortal(); }) ) ) ) )); }
/// <summary> /// Main MoveToObjective Behavior /// </summary> /// <returns></returns> protected override Composite CreateBehavior() { return (new Sequence( new DecoratorContinue(ret => ZetaDia.Me.IsDead || ZetaDia.IsLoadingWorld, new Sequence( new Action(ret => Logger.Log("IsDead={0} IsLoadingWorld={1}", ZetaDia.Me.IsDead, ZetaDia.IsLoadingWorld)), new Action(ret => RunStatus.Failure) ) ), new DecoratorContinue(ret => _lastMoveResult == MoveResult.ReachedDestination && _objectiveObject == null, new Sequence( new Action(ret => Logger.Log("ReachedDestination, no Objective found - finished!")), new Action(ret => _isDone = true), new Action(ret => RunStatus.Failure) ) ), new Action(ret => FindObjectiveMarker()), new DecoratorContinue(ret => _mapMarkerLastPosition != Vector3.Zero, new Action(ret => RefreshActorInfo()) ), new DecoratorContinue(ret => _objectiveObject == null && _miniMapMarker == null && Position == Vector3.Zero, new Sequence( new Action(ret => Logger.Log("Error: Could not find Objective Marker! {0}", Status())), new Action(ret => _isDone = true) ) ), new Sequence( new PrioritySelector( new Decorator(ret => ZetaDia.CurrentWorldId != _startWorldId, new Sequence( new Action(ret => Logger.Log("World changed from {0} to {1}, finished {2}", _startWorldId, ZetaDia.CurrentWorldId, Status())), new Action(ret => _isDone = true) ) ), new Decorator(ret => IsValidObjective() && _objectiveObject is DiaUnit && _objectiveObject.Position.Distance(ZetaDia.Me.Position) <= PathPrecision, new Sequence( new Action(ret => Logger.Log("We found the objective and its a monster, ending tag so we can kill it. {0}", Status())), new Action(ret => _isDone = true) ) ), new Decorator(ret => _objectiveObject != null && _objectiveObject.IsValid, new PrioritySelector( new Decorator(ret => _lastMoveResult != MoveResult.ReachedDestination, new Sequence( new Action(ret => Logger.Debug("Moving to actor {0} {1}", _objectiveObject.ActorSNO, Status())), new Action(ret => _lastMoveResult = Navigator.MoveTo(_objectiveObject.Position)) ) ), new Decorator(ret => _objectiveObject is GizmoPortal, new PrioritySelector( new Decorator(ret => _lastMoveResult == MoveResult.ReachedDestination && _objectiveObject.Distance > InteractRange, new Sequence( new Action(ret => Logger.Log("ReachedDestination but not within InteractRange, finished")), new Action(ret => _isDone = true) ) ), new Decorator(ret => ZetaDia.Me.Movement.IsMoving, new Action(ret => CommonBehaviors.MoveStop())), new Sequence( new Action(ret => _objectiveObject.Interact()), new Action(ret => _completedInteractAttempts++), new Action(ret => Logger.Debug("Interacting with portal object {0}, result: {1}", _objectiveObject.ActorSNO, Status())), new Sleep(500), new Action(ret => GameEvents.FireWorldTransferStart()) ) ) ) ) ), new Decorator(ret => _miniMapMarker != null && _objectiveObject == null, new PrioritySelector( new Decorator(ret => _miniMapMarker != null && _miniMapMarker.Position.Distance(ZetaDia.Me.Position) > PathPrecision, new Sequence( new Action(ret => Logger.Debug("Moving to Objective Marker {0}, {1}", _miniMapMarker.NameHash, Status())), new Action(ret => _lastMoveResult = Navigator.MoveTo(_miniMapMarker.Position)) ) ), new Decorator(ret => _miniMapMarker != null && _miniMapMarker.Position.Distance(ZetaDia.Me.Position) < PathPrecision, new Sequence( new Action(ret => Logger.Debug("Successfully Moved to Objective Marker {0}, {1}", _miniMapMarker.NameHash, Status())), new Action(ret => _isDone = true) ) ) ) ), new Decorator(ret => _miniMapMarker == null && Position != Vector3.Zero && Position.Distance(ZetaDia.Me.Position) > PathPrecision, new Sequence( new Action(ret => _lastMoveResult = Navigator.MoveTo(Position)), new DecoratorContinue(ret => _lastMoveResult == MoveResult.ReachedDestination, new Sequence( new Action(ret => Logger.Log("ReachedDestination of Position, finished.")), new Action(ret => _isDone = true) ) ) ) ), new Action(ret => Logger.LogError("MoveToObjective Error: marker={0} actor={1}/{2} completedInteracts={3} isPortal={4} dist={5} interactRange={6}", _miniMapMarker != null, _objectiveObject != null, (_objectiveObject != null && _objectiveObject.IsValid), _completedInteractAttempts, IsPortal, (_objectiveObject != null && _objectiveObject.IsValid ? _objectiveObject.Position.Distance(ZetaDia.Me.Position) : 0f), InteractRange) ) ) ) )); }
protected async Task <bool> MoveToObjectiveRoutine() { if (ZetaDia.Me.IsDead || ZetaDia.IsLoadingWorld) { Logger.Log("IsDead={0} IsLoadingWorld={1}", ZetaDia.Me.IsDead, ZetaDia.IsLoadingWorld); return(false); } SceneSegmentation.Update(); if (_route.Any() || _currentRouteDestination != Vector3.Zero) { return(MoveAlongRoute(_route)); } // If the bot has failed to run directly towards the objective marker too many times // We'll blacklist it for 30 seconds to allow adjacent scenes to be explored. if (FailedAttempts >= FailedAttemptMax) { Logger.Log("Blacklisting Objective Marker for 60 seconds"); BlacklistMarkerExpires = DateTime.UtcNow.AddSeconds(60); FailedAttempts = 0; _route = CreateRouteToUnexploredScene(); return(false); } // While the bot is currently blacklisted from directly running at the objective // Generate a route to go through some nearby scenes if (DateTime.UtcNow < BlacklistMarkerExpires) { _route = CreateRouteToObjective(); return(false); } // 'ReachedDestination' is returned when finding a path to destination has failed. if (_lastMoveResult == MoveResult.ReachedDestination && _objectiveObject == null) { if (_miniMapMarker != null && _miniMapMarker.IsValid && _miniMapMarker.IsPointOfInterest) { var distance = ZetaDia.Me.Position.Distance(_miniMapMarker.Position); if (distance > 100) { FailedAttempts++; Logger.Log("Direct Pathfinding failed towards Objective Marker. Attempts={0}/{1}", FailedAttempts, FailedAttemptMax); } else if (distance < 30) { Logger.Log("ReachedDestination no Objective found - finished!"); _isDone = true; return(true); } } } // Find the objective minimap marker FindObjectiveMarker(); // If the marker is found or was previously found, find a nearby actor if (_mapMarkerLastPosition != Vector3.Zero) { RefreshActorInfo(); } if (_objectiveObject == null && _miniMapMarker == null && Position == Vector3.Zero) { Logger.Log("Error: Could not find Objective Marker! {0}", Status()); _isDone = true; return(true); } // Finish if World Changed if (ZetaDia.CurrentWorldId != _startWorldId) { Logger.Log("World changed from {0} to {1}, finished {2}", _startWorldId, ZetaDia.CurrentWorldId, Status()); _isDone = true; return(true); } // Finish because Objective Found if (IsValidObjective() && _objectiveObject is DiaUnit && _objectiveObject.Position.Distance(ZetaDia.Me.Position) <= PathPrecision) { Logger.Log("We found the objective and its a monster, ending tag so we can kill it. {0}", Status()); _isDone = true; return(true); } // Objective Object is available if (_objectiveObject != null && _objectiveObject.IsFullyValid()) { // Move Closer to Objective Object if (_lastMoveResult != MoveResult.ReachedDestination) { Logger.Debug("Moving to actor {0} {1}", _objectiveObject.ActorSNO, Status()); _lastMoveResult = await CommonCoroutines.MoveTo(_objectiveObject.Position); return(true); } if (_objectiveObject is GizmoPortal) { if (_lastMoveResult == MoveResult.ReachedDestination && _objectiveObject.Distance > InteractRange) { Logger.Log("ReachedDestination but not within InteractRange, finished"); _isDone = true; return(true); } if (GameUI.PartyLeaderBossAccept.IsVisible || GameUI.PartyFollowerBossAccept.IsVisible) { Logger.Debug("Party Boss Button visible"); return(true); } if (ZetaDia.Me.Movement.IsMoving) { await CommonBehaviors.MoveStop().ExecuteCoroutine(); } _objectiveObject.Interact(); _completedInteractAttempts++; Logger.Debug("Interacting with portal object {0}, result: {1}", _objectiveObject.ActorSNO, Status()); await Coroutine.Sleep(500); GameEvents.FireWorldTransferStart(); return(true); } } if (_miniMapMarker != null && ObjectiveObjectIsNullOrInvalid()) { if (_miniMapMarker != null && _miniMapMarker.Position.Distance(ZetaDia.Me.Position) > PathPrecision) { Logger.Debug("Moving to Objective Marker {0}, {1}", _miniMapMarker.NameHash, Status()); _lastMoveResult = await CommonCoroutines.MoveTo(_miniMapMarker.Position); return(true); } if (_miniMapMarker != null && _miniMapMarker.Position.Distance(ZetaDia.Me.Position) < PathPrecision) { Logger.Debug("Successfully Moved to Objective Marker {0}, {1}", _miniMapMarker.NameHash, Status()); _isDone = true; return(true); } } if (_miniMapMarker == null && Position != Vector3.Zero && Position.Distance(ZetaDia.Me.Position) > PathPrecision) { _lastMoveResult = CommonCoroutines.MoveTo(Position).Result; if (_lastMoveResult == MoveResult.ReachedDestination) { Logger.Log("ReachedDestination of Position, minimap marker not found, finished."); _isDone = true; return(true); } } Logger.Error("MoveToObjective Error: marker={0} actorNull={1} actorValid={2} completedInteracts={3} isPortal={4} dist={5} interactRange={6}", _miniMapMarker != null, _objectiveObject != null, (_objectiveObject != null && _objectiveObject.IsFullyValid()), _completedInteractAttempts, IsPortal, (_objectiveObject != null && _objectiveObject.IsFullyValid() ? _objectiveObject.Position.Distance(ZetaDia.Me.Position) : 0f), InteractRange); return(false); }