Esempio n. 1
0
            public DoWhenNamedActivity(string customActivityName,
                                       IUseWhenPredicate useWhenPredicate,
                                       OrderNodeCollection nodes,
                                       bool isMovementStopRequired)
                : base(CreateActivityIdentifier(customActivityName), useWhenPredicate, isMovementStopRequired)
            {
                Contract.Requires(!string.IsNullOrEmpty(customActivityName), context => "!string.IsNullOrEmpty(customActivityName)");
                Contract.Requires(nodes != null && nodes.GetNodes().Any(), context => "nodes != null && Nodes.GetNodes().Any()");

                Nodes = nodes;
            }
Esempio n. 2
0
            protected IDoWhenActivity(string activityIdentifier,
                                      IUseWhenPredicate useWhenPredicate,
                                      bool isMovementStopRequired)
            {
                Contract.Requires(!string.IsNullOrEmpty(activityIdentifier), (context) => "activityIdentifier may not be null or empty");
                Contract.Requires(useWhenPredicate != null, (context) => "useWhenPredicate != null");

                ActivityIdentifier           = activityIdentifier;
                IsMovementStopRequired       = isMovementStopRequired;
                UseWhenPredicate             = useWhenPredicate;
                ShouldBreakWhenIndeterminate = true;
            }
Esempio n. 3
0
            public DoWhenUseItemActivity(int itemId, IUseWhenPredicate useWhenPredicate, bool isMovementStopRequired)
                : base(CreateActivityIdentifier(itemId), useWhenPredicate, isMovementStopRequired)
            {
                Contract.Requires(itemId > 0, context => "itemId > 0");

                _errorMessage_ItemNotInInventory = string.Format(
                    "For DoWhenActivity {1}, ItemId({2}) is not in our inventory.{0}"
                    + "  This is a profile problem.  To squelch this message there are two options:{0}"
                    + "  * (Preferred) Remove the corresponding DoWhen in the profile until the item is in our backpack.{0}"
                    + "  * Include a \"HasItem({2})\" term as part of the UseWhen predicate expression.",
                    Environment.NewLine, ActivityIdentifier, itemId);

                _itemToUse = Me.CarriedItems.FirstOrDefault(i => (i.Entry == itemId));
            }
Esempio n. 4
0
            public DoWhenCastSpellActivity(int spellId, IUseWhenPredicate useWhenPredicate, bool isMovementStopRequired)
                : base(CreateActivityIdentifier(spellId), useWhenPredicate, isMovementStopRequired)
            {
                Contract.Requires(spellId > 0, context => "spellId > 0");

                _errorMessage_UnknownSpell = string.Format(
                    "For DoWhenActivity {1}, SpellId({2}) is not known.{0}"
                    + "  This is a profile problem.  To squelch this message there are two options:{0}"
                    + "  * (Preferred) Remove the corresponding DoWhen in the profile until the spell is learned.{0}"
                    + "  * Include a \"HasSpell({2})\" term as part of the UseWhen predicate expression.",
                    Environment.NewLine, ActivityIdentifier, spellId);

                _wowSpell = WoWSpell.FromId(spellId);
            }
Esempio n. 5
0
        private void ActionUpdate(IUseWhenPredicate useWhenPredicate, bool isMovementStopRequired)
        {
            var activityIdentifier = FindActivityIdentifier();
            var existingActivity   = FindActivity(activityIdentifier);

            // If activity already exists, remove it...
            if (existingActivity != null)
            {
                s_persistedActivities.Remove(existingActivity);
            }

            // Install new activity...
            IDoWhenActivity doWhenActivity = null;

            if (ActivityKey_ItemId > 0)
            {
                doWhenActivity = new DoWhenUseItemActivity(ActivityKey_ItemId, useWhenPredicate, isMovementStopRequired);
            }

            else if (ActivityKey_SpellId > 0)
            {
                doWhenActivity = new DoWhenCastSpellActivity(ActivityKey_SpellId, useWhenPredicate, isMovementStopRequired);
            }

            else if (!string.IsNullOrEmpty(ActivityKey_Name))
            {
                doWhenActivity = new DoWhenNamedActivity(ActivityKey_Name, useWhenPredicate, Nodes, isMovementStopRequired);
            }

            if (doWhenActivity != null)
            {
                s_persistedActivities.Add(doWhenActivity);
                QBCLog.DeveloperInfo("DoWhenActivity '{0}' created:{1}",
                                     doWhenActivity.ActivityIdentifier,
                                     doWhenActivity.BuildDebugInfo("    "));
            }
        }
Esempio n. 6
0
        // CreateBehavior supplied by QuestBehaviorBase.
        // Instead, provide CreateMainBehavior definition.

        // Dispose provided by QuestBehaviorBase.

        // IsDone provided by QuestBehaviorBase.
        // Call the QuestBehaviorBase.BehaviorDone() method when you want to indicate your behavior is complete.

        // OnFinished provided by QuestBehaviorBase.

        public override void OnStart()
        {
            // Acquisition and checking of any sub-elements go here.
            // A common example:
            //     HuntingGrounds = HuntingGroundsType.GetOrCreate(Element, "HuntingGrounds", HuntingGroundCenter);
            //     IsAttributeProblem |= HuntingGrounds.IsAttributeProblem;

            // Let QuestBehaviorBase do basic initialization of the behavior, deal with bad or deprecated attributes,
            // capture configuration state, install BT hooks, etc.  This will also update the goal text.
            var isBehaviorShouldRun = OnStart_QuestBehaviorCore();

            // 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 (isBehaviorShouldRun)
            {
                // The BotStop handler will remove the "use when" activities...
                // Note, we only want to hook BotStopped once for this behavior.
                if (!s_persistedIsOnBotStopHooked)
                {
                    BotEvents.OnBotStopped      += BotEvents_OnBotStopped;
                    s_persistedIsOnBotStopHooked = true;
                }

                if (!s_persistedIsOnNewProfileLoadedHooked)
                {
                    BotEvents.Profile.OnNewProfileLoaded += BotEvents_OnNewProfileLoaded;
                    s_persistedIsOnNewProfileLoadedHooked = true;
                }

                switch (Command)
                {
                case CommandType.Disable:
                    ActionSetEnableState(false);
                    break;

                case CommandType.Enable:
                    ActionSetEnableState(true);
                    break;

                case CommandType.ShowActivities:
                    ActionShowActivities();
                    break;

                case CommandType.Remove:
                    ActionRemove();
                    break;

                case CommandType.Update:
                    IUseWhenPredicate useWhenPredicate =
                        (UseAtInterval > TimeSpan.Zero)
                            ? (IUseWhenPredicate) new UseWhenPredicate_TimeElapse(UseAtInterval,
                                                                                  AllowUseDuringCombat,
                                                                                  AllowUseInVehicle,
                                                                                  AllowUseWhileFlying,
                                                                                  AllowUseWhileMounted)
                            : (IUseWhenPredicate) new UseWhenPredicate_FuncEval(UseWhen,
                                                                                AllowUseDuringCombat,
                                                                                AllowUseInVehicle,
                                                                                AllowUseWhileFlying,
                                                                                AllowUseWhileMounted);

                    ActionUpdate(useWhenPredicate, StopMovingToConductActivity);
                    break;

                default:
                    QBCLog.MaintenanceError("Unhandled action type of '{0}'.", Command);
                    TreeRoot.Stop();
                    return;
                }

                // Install or remove behavior as needed...
                // We need to install the hook when its not present, AND there is something to execute.
                // We remove the hook if there is nothing left to execute.  This betters the user's experience,
                // by maximizing performance.
                // NB: We cannot simply override the methods provided by QuestBehaviorBase, because this behavior
                // is unusual.  We want these hooks to remain after this behavior terminates.  If we use the
                // QuestBehaviorBase-provide facilities (e.g., override the methods), then the hooks would be
                // cleaned up (e.g., removed) when this behavior exits.
                if (s_persistedActivities.Count > 0)
                {
                    DoWhenHookInstall();
                }

                if (s_persistedActivities.Count <= 0)
                {
                    DoWhenHookRemove();
                }

                BehaviorDone();
            }
        }