public override void OnFinished()
        {
            // NB: we don't unhook _behaviorTreeHook_Main
            // This was installed when HB created the behavior, and its up to HB to unhook it

            if (_behaviorTreeHook_CombatMain != null)
            {
                TreeHooks.Instance.RemoveHook("Combat_Main", _behaviorTreeHook_CombatMain);
                _behaviorTreeHook_CombatMain = null;
            }

            if (_behaviorTreeHook_CombatOnly != null)
            {
                TreeHooks.Instance.RemoveHook("Combat_Only", _behaviorTreeHook_CombatOnly);
                _behaviorTreeHook_CombatOnly = null;
            }

            if (_behaviorTreeHook_DeathMain != null)
            {
                TreeHooks.Instance.RemoveHook("Death_Main", _behaviorTreeHook_DeathMain);
                _behaviorTreeHook_DeathMain = null;
            }

            if (_configMemento != null)
            {
                _configMemento.Dispose();
                _configMemento = null;
            }

            BlackspotManager.RemoveBlackspots(Blackspots);
            TreeRoot.GoalText   = string.Empty;
            TreeRoot.StatusText = string.Empty;
            base.OnFinished();
        }
예제 #2
0
 public static IEnumerable <Blackspot> FindCoveringBlackspots(Vector3 location)
 {
     return
         (from blackspot in BlackspotManager.GetAllCurrentBlackspots()
          where
          (blackspot.Location.Distance2D(location) <= blackspot.Radius) &&
          (Math.Abs(blackspot.Location.Z - location.Z) <= blackspot.Height)
          select blackspot);
 }
        // 24Feb2013-08:10UTC chinajade
        public override void OnFinished()
        {
            // Defend against being called multiple times (just in case)...
            if (!IsOnFinishedRun)
            {
                if (Targeting.Instance != null)
                {
                    Targeting.Instance.IncludeTargetsFilter -= TargetFilter_IncludeTargets;
                    Targeting.Instance.RemoveTargetsFilter  -= TargetFilter_RemoveTargets;
                    Targeting.Instance.WeighTargetsFilter   -= TargetFilter_WeighTargets;
                }


                // NB: we don't unhook _behaviorTreeHook_Main
                // This was installed when HB created the behavior, and its up to HB to unhook it

                BehaviorHookRemove("Combat_Main", ref _behaviorTreeHook_CombatMain);
                BehaviorHookRemove("Combat_Only", ref _behaviorTreeHook_CombatOnly);
                BehaviorHookRemove("Death_Main", ref _behaviorTreeHook_DeathMain);
                BehaviorHookRemove("Questbot_Main", ref _behaviorTreeHook_QuestbotMain);

                // Remove temporary blackspots...
                if (_temporaryBlackspots != null)
                {
                    BlackspotManager.RemoveBlackspots(_temporaryBlackspots.GetBlackspots());
                    _temporaryBlackspots = null;
                }

                // Restore configuration...
                if (_configMemento != null)
                {
                    _configMemento.Dispose();
                    _configMemento = null;
                }

                // Make sure we don't leave stale POIs set after finishing a QB.
                // This could happen if the user used a TerminateWhen to finish it
                // for example.
                BotPoi.Clear("Finished " + GetType().Name);

                TreeRoot.GoalText   = string.Empty;
                TreeRoot.StatusText = string.Empty;

                // Report the behavior run time...
                if (_behaviorRunTimer.IsRunning)
                {
                    _behaviorRunTimer.Stop();
                    QBCLog.DeveloperInfo("Behavior completed in {0}", Utility.PrettyTime(_behaviorRunTimer.Elapsed));
                }

                base.OnFinished();
                QBCLog.BehaviorLoggingContext = null;
                IsOnFinishedRun = true;
            }
        }
        public override void OnStart()
        {
            PlayerQuest quest = StyxWoW.Me.QuestLog.GetQuestById((uint)QuestId);

            if ((QuestId != 0) && (quest == null))
            {
                QBCLog.Error("This behavior has been associated with QuestId({0}), but the quest is not in our log", QuestId);
                IsAttributeProblem = true;
            }

            // This reports problems, and stops BT processing if there was a problem with attributes...
            // We had to defer this action, as the 'profile line number' is not available during the element's
            // constructor call.
            OnStart_HandleAttributeProblem();

            // We need to move off boat after quest is complete, so we can't use "quest complete"
            // as part of the normal IsDone criteria for this behavior.  So, we explicitly check for
            // quest complete here, and set IsDone appropriately.
            if (!UtilIsProgressRequirementsMet(QuestId, QuestRequirementInLog, QuestRequirementComplete))
            {
                _isBehaviorDone = true;
            }

            // If the quest is complete, this behavior is already done...
            // So we don't want to falsely inform the user of things that will be skipped.
            if (!IsDone)
            {
                _configMemento = new ConfigMemento();

                // Disable any settings that may interfere with the escort --
                // When we escort, we don't want to be distracted by other things.
                // NOTE: these settings are restored to their normal values when the behavior completes
                // or the bot is stopped.
                CharacterSettings.Instance.HarvestHerbs    = false;
                CharacterSettings.Instance.HarvestMinerals = false;
                CharacterSettings.Instance.LootChests      = false;
                CharacterSettings.Instance.NinjaSkin       = false;
                CharacterSettings.Instance.SkinMobs        = false;

                BlackspotManager.AddBlackspots(Blackspots);

                State_MainBehavior = StateType_MainBehavior.AssigningTask;

                _behaviorTreeHook_CombatMain = CreateBehavior_CombatMain();
                TreeHooks.Instance.InsertHook("Combat_Main", 0, _behaviorTreeHook_CombatMain);
                _behaviorTreeHook_CombatOnly = CreateBehavior_CombatOnly();
                TreeHooks.Instance.InsertHook("Combat_Only", 0, _behaviorTreeHook_CombatOnly);
                _behaviorTreeHook_DeathMain = CreateBehavior_DeathMain();
                TreeHooks.Instance.InsertHook("Death_Main", 0, _behaviorTreeHook_DeathMain);

                this.UpdateGoalText(QuestId);
            }
        }
        public override void OnStart()
        {
            PlayerQuest quest = StyxWoW.Me.QuestLog.GetQuestById((uint)QuestId);

            if ((QuestId != 0) && (quest == null))
            {
                QBCLog.Error("This behavior has been associated with QuestId({0}), but the quest is not in our log", QuestId);
                IsAttributeProblem = true;
            }

            // This reports problems, and stops BT processing if there was a problem with attributes...
            // We had to defer this action, as the 'profile line number' is not available during the element's
            // constructor call.
            OnStart_HandleAttributeProblem();

            // If the quest is complete, this behavior is already done...
            // So we don't want to falsely inform the user of things that will be skipped.
            if (!IsDone)
            {
                _configMemento = new ConfigMemento();

                // Disable any settings that may interfere with the escort --
                // When we escort, we don't want to be distracted by other things.
                // NOTE: these settings are restored to their normal values when the behavior completes
                // or the bot is stopped.
                CharacterSettings.Instance.HarvestHerbs    = false;
                CharacterSettings.Instance.HarvestMinerals = false;
                CharacterSettings.Instance.LootChests      = false;
                CharacterSettings.Instance.NinjaSkin       = false;
                CharacterSettings.Instance.SkinMobs        = false;
                // CharacterSettings.Instance.PullDistance = 1;    // don't pull anything unless we absolutely must

                BlackspotManager.AddBlackspots(Blackspots);

                State_MainBehavior = StateType_MainBehavior.DroppingOffVictim;

                _behaviorTreeHook_CombatMain = CreateBehavior_CombatMain();
                TreeHooks.Instance.InsertHook("Combat_Main", 0, _behaviorTreeHook_CombatMain);
                _behaviorTreeHook_CombatOnly = CreateBehavior_CombatOnly();
                TreeHooks.Instance.InsertHook("Combat_Only", 0, _behaviorTreeHook_CombatOnly);
                _behaviorTreeHook_DeathMain = CreateBehavior_DeathMain();
                TreeHooks.Instance.InsertHook("Death_Main", 0, _behaviorTreeHook_DeathMain);

                this.UpdateGoalText(QuestId);
            }
        }
예제 #6
0
        /// <summary>
        /// <p>Returns 'true' if WOWOBJECT is located in a blackspot; otherwise, 'false'.</p>
        ///
        /// <p>Not all blackspots are created equal.  For targeting purposes, we only want to consider
        /// blackspots defined by the profile (static), or the QBcore-based behaviors (a subset of dynamic
        /// blackspots).  Other blackspots, such as those dropped by the StuckHandler (also dynamic), should not
        /// be considered for targeting purposes.  If we did, then it would be possible for say InteractWith
        /// to cause Honorbuddy to hang forever, because the StuckHandler dropped a blackspot on a unique
        /// target.</p>
        /// <p>Blackspots dropped by the StuckHandler and other sources should not be considered for
        /// targeting decisions.</p>
        /// </summary>
        /// <param name="wowObject"></param>
        /// <returns></returns>
        public static bool IsTargetInBlackspot(WoWObject wowObject)
        {
            Func <Vector3, Blackspot, bool> isInBlackspot =
                (location, blackspot) =>
            {
                return
                    ((blackspot.Location.DistanceSquared(location) <= (blackspot.Radius * blackspot.Radius)) &&
                     (location.Z >= (blackspot.Location.Z - blackspot.Height)) &&
                     (location.Z <= (blackspot.Location.Z + blackspot.Height)));
            };
            var wowObjectLocation = wowObject.Location;

            return
                // Consider profile-defined (static) blackspots...
                (BlackspotManager.GetAllCurrentBlackspots(BlackspotQueryFlags.Static)
                 .Any(b => isInBlackspot(wowObjectLocation, b))
                 ||
                 // Consider QBcore-defined (dynamic) blackspots...
                 BlackspotManager.GetAllCurrentBlackspots(BlackspotQueryFlags.Dynamic)
                 .Any(b => BlackspotType.IsQbcoreDefined(b) && isInBlackspot(wowObjectLocation, b)));
        }
        /// <summary>
        /// <para>This reports problems, and stops BT processing if there was a problem with attributes...
        /// We had to defer this action, as the 'profile line number' is not available during the element's
        /// constructor call.</para>
        /// <para>It also captures the user's configuration, and installs Behavior Tree hooks.  The items will
        /// be restored when the behavior terminates, or Honorbuddy is stopped.</para>
        /// </summary>
        /// <return>true, if the behavior should run; false, if it should not.</return>
        /// <param name="extraGoalTextDescription"></param>
        protected bool OnStart_QuestBehaviorCore(string extraGoalTextDescription = null)
        {
            // Semantic coherency / covariant dependency checks...
            UsageCheck_SemanticCoherency(Element, QuestObjectiveIndex > 0 && !VariantQuestIds.Any(),
                                         context => $"QuestObjectiveIndex of '{QuestObjectiveIndex}' specified, but no corresponding QuestId provided");

            UsageCheck_SemanticCoherency(Element,
                                         _providedQuestIdAndQuestVariantIds,
                                         context => "Cannot provide both a QuestId and VariantQuestIds at same time.");

            EvaluateUsage_SemanticCoherency(Element);

            // Deprecated attributes...
            EvaluateUsage_DeprecatedAttributes(Element);

            // This reports problems, and stops BT processing if there was a problem with attributes...
            // We had to defer this action, as the 'profile line number' is not available during the element's
            // constructor call.
            OnStart_HandleAttributeProblem();

            var questId = GetQuestId();

            // If the quest is complete, this behavior is already done...
            // So we don't want to falsely inform the user of things that will be skipped.
            // NB: Since the IsDone property may skip checking the 'progress conditions', we need to explicltly
            // check them here to see if we even need to start the behavior.
            if (!(IsDone || !UtilIsProgressRequirementsMet(questId, QuestRequirementInLog, QuestRequirementComplete)))
            {
                this.UpdateGoalText(questId, extraGoalTextDescription);

                // Start the timer to measure the behavior run time...
                _behaviorRunTimer.Restart();

                // Monitored Behaviors...
                if (QuestBehaviorCoreSettings.Instance.MonitoredBehaviors.Contains(GetType().Name))
                {
                    QBCLog.Debug("MONITORED BEHAVIOR: {0}", GetType().Name);
                    AudibleNotifyOn(true);
                }

                _configMemento = CreateConfigMemento();

                if (Targeting.Instance != null)
                {
                    Targeting.Instance.IncludeTargetsFilter += TargetFilter_IncludeTargets;
                    Targeting.Instance.RemoveTargetsFilter  += TargetFilter_RemoveTargets;
                    Targeting.Instance.WeighTargetsFilter   += TargetFilter_WeighTargets;
                }

                Query.InCompetitionReset();
                Utility.BlacklistsReset();

                _behaviorTreeHook_CombatMain   = BehaviorHookInstall("Combat_Main", CreateBehavior_CombatMain());
                _behaviorTreeHook_CombatOnly   = BehaviorHookInstall("Combat_Only", CreateBehavior_CombatOnly());
                _behaviorTreeHook_DeathMain    = BehaviorHookInstall("Death_Main", CreateBehavior_DeathMain());
                _behaviorTreeHook_QuestbotMain = BehaviorHookInstall("Questbot_Main", CreateBehavior_QuestbotMain());

                BlackspotManager.AddBlackspots(_temporaryBlackspots.GetBlackspots());

                if (_temporaryAvoidMobs != null)
                {
                    foreach (var avoidMobId in _temporaryAvoidMobs.GetAvoidMobIds())
                    {
                        // NB: ProfileManager.CurrentProfile.AvoidMobs will never be null
                        if (!ProfileManager.CurrentProfile.AvoidMobs.Contains(avoidMobId))
                        {
                            ProfileManager.CurrentProfile.AvoidMobs.Add(avoidMobId);
                        }
                    }
                }

                return(true);    // behavior should run
            }

            return(false);   // behavior should NOT run
        }