Пример #1
0
        protected override Composite CreateBehavior()
        {
            var turnIn = new ActionRunCoroutine(r => TurnInLeve(NpcId));
            var update = new Action(r => done = true);

            return(new PrioritySelector(turnIn, update));
        }
Пример #2
0
        protected override Composite CreateBehavior()
        {
            var turnIn = new ActionRunCoroutine(r => TurnInLeve(NpcId));
            var update = new Action(r => done = true);

            return new PrioritySelector(turnIn, update);
        }
Пример #3
0
        private void RemoveHook()
        {
            if (s_hook == null)
            {
                return;
            }
            TreeHooks.Instance.RemoveHook("Combat_Main", s_hook);
            Navigator.NavigationProvider = s_prevNavigator;

            // Make sure maps for the previous navigator are up-to-date
            var meshNav = Navigator.NavigationProvider as MeshNavigator;

            if (meshNav != null)
            {
                meshNav.UpdateMaps();
            }

            s_prevNavigator = null;
            s_hook          = null;
            foreach (var kv in s_avoidDictionary)
            {
                AvoidanceManager.RemoveAvoid(kv.Value);
                QBCLog.DeveloperInfo("Removed the \"{0}\" avoidance definition", kv.Key);
            }
            s_avoidDictionary.Clear();
            BotEvents.OnPulse      -= BotEvents_OnPulse;
            BotEvents.OnBotStopped -= BotEvents_OnBotStopped;
            BotEvents.Profile.OnNewOuterProfileLoaded  -= Profile_OnNewOuterProfileLoaded;
            LootTargeting.Instance.RemoveTargetsFilter -= Instance_RemoveTargetsFilter;
            QBCLog.Info("Uninstalled avoidance system");
        }
Пример #4
0
        private void InstallHook()
        {
            s_prevNavigator = Navigator.NavigationProvider;
            var avoidNavigator = new AvoidanceNavigationProvider();;

            Navigator.NavigationProvider = avoidNavigator;
            avoidNavigator.UpdateMaps();
            s_hook = new ActionRunCoroutine(ctx => HookHelpers.ExecuteHook(this, HookHandler));
            TreeHooks.Instance.InsertHook("Combat_Main", 0, s_hook);
            BotEvents.OnPulse      += BotEvents_OnPulse;
            BotEvents.OnBotStopped += BotEvents_OnBotStopped;
            BotEvents.Profile.OnNewOuterProfileLoaded  += Profile_OnNewOuterProfileLoaded;
            LootTargeting.Instance.RemoveTargetsFilter += Instance_RemoveTargetsFilter;
            QBCLog.Info("Installed avoidance system");
        }
Пример #5
0
        private static Composite CreateBehaviour()
        {
            var setCombatPoi = new ActionRunCoroutine(coroutine => SetCombatPoi.Main());
            var setFatePoi   = new ActionRunCoroutine(coroutine => SetFatePoi.Main());
            var setWaitPoi   = new ActionRunCoroutine(coroutine => SetWaitPoi.Main());

            Composite[] composites =
            {
                new HookExecutor("SetDeathPoi"),
                new HookExecutor("SetCombatPoi",                                                                                     "A hook to help defend the character when their Chocobo is under attack.",  setCombatPoi),
                new Decorator(check => !OracleFateManager.PausePoiSetting,
                              new HookExecutor("SetFatePoi",
                                               "A hook that selects a viable FATE based in user settings and assigns it as the Poi.",
                                               setFatePoi)),
                new Decorator(check => !OracleFateManager.PausePoiSetting,
                              new HookExecutor("SetWaitPoi",                                                                         "A hook that sets the correct wait Poi based on user settings.",            setWaitPoi))
            };

            return(new PrioritySelector(composites));
        }
Пример #6
0
        protected async override Task Run()
        {
            try
            {
                if (!SubRoutineComposite.GetSubRoutineMyName(SubRoutineName, out _sub))
                {
                    PBLog.Warn("{0}: {1}.", ProfessionbuddyBot.Instance.Strings["Error_SubroutineNotFound"], SubRoutineName);
                    return;
                }

                _treeHookStub = new ActionRunCoroutine(ctx => SubRoutineExecutor());
                TreeHooks.Instance.InsertHook(TreeHookName, 0, _treeHookStub);
                BotEvents.Profile.OnNewOuterProfileLoaded += ProfileOnOnNewOuterProfileLoaded;
                BotEvents.OnBotStopped += BotEvents_OnBotStopped;
                PBLog.Debug("Attached the '{0}' SubRoutine to the {1} TreeHook", SubRoutineName, TreeHookName);
            }
            finally
            {
                _ranonce = true;
            }
        }
Пример #7
0
        private void rehookavoid(object sender, EventArgs e)
        {
            s_hook = new ActionRunCoroutine(async ctx =>
            {
                var supportsCapabilities = RoutineManager.Current.SupportedCapabilities != CapabilityFlags.None;

                if (AvoidanceManager.IsRunningOutOfAvoid && Core.Me.IsCasting)
                {
                    ActionManager.StopCasting();
                    return(true);
                }

                if (AvoidanceManager.IsRunningOutOfAvoid && !supportsCapabilities)
                {
                    return(true);
                }
                var poiType = Poi.Current.Type;

                // taken from HB
                // Special case: Bot will do a lot of fast stop n go when avoiding a mob that moves slowly and trying to
                // do something near the mob. To fix, a delay is added to slow down the 'Stop n go' behavior
                if (poiType == PoiType.Collect || poiType == PoiType.Gather || poiType == PoiType.Hotspot)
                {
                    if (Core.Me.InCombat && AvoidanceManager.Avoids.Any(o => o.IsPointInAvoid(Poi.Current.Location)))
                    {
                        TreeRoot.StatusText = "Waiting for 'avoid' to move before attempting to interact " +
                                              Poi.Current.Name;
                        var randomWaitTime = (new Random()).Next(3000, 8000);
                        await Coroutine.Wait(randomWaitTime,
                                             () => Core.Me.InCombat ||
                                             !AvoidanceManager.Avoids.Any(o => o.IsPointInAvoid(Poi.Current.Location)));
                    }
                }
                return(false);
            });

            TreeHooks.Instance.InsertHook("TreeStart", 0, s_hook);
        }
        public static Composite GetComposite(WoWClass wowClass, WoWSpec spec, BehaviorType behavior, WoWContext context, out int behaviourCount, bool silent = false)
        {
            if (context == WoWContext.None)
            {
                // None is an invalid context, but rather than stopping bot wait it out with donothing logic
                Logger.Write(LogColor.Hilite, "No Active Context -{0}{1} for{2} set to DoNothingBehavior temporarily", wowClass.ToString().CamelToSpaced(), behavior.ToString().CamelToSpaced(), spec.ToString().CamelToSpaced());
                behaviourCount = 1;
                return(NoContextAvailable.CreateDoNothingBehavior());
            }

            SilentBehaviorCreation = silent;
            behaviourCount         = 0;
            var matchedMethods = new Dictionary <BehaviorAttribute, Composite>();

            foreach (MethodInfo mi in _methods)
            {
                // If the behavior is set as ignore. Don't use it? Duh?
                if (mi.GetCustomAttributes(typeof(IgnoreBehaviorCountAttribute), false).Any())
                {
                    continue;
                }

                // If there's no behavior attrib, then move along.
                foreach (var a in mi.GetCustomAttributes(typeof(BehaviorAttribute), false))
                {
                    var attribute = a as BehaviorAttribute;
                    if (attribute == null)
                    {
                        continue;
                    }

                    // Check if our behavior matches with what we want. If not, don't add it!
                    if (IsMatchingMethod(attribute, wowClass, spec, behavior, context))
                    {
                        if (!silent)
                        {
                            Logger.WriteFile("{0} {1} {2}", attribute.PriorityLevel.ToString().AlignRight(4), behavior.ToString().AlignLeft(15), mi.Name);
                        }

                        CurrentBehaviorType     = behavior;
                        CurrentBehaviorPriority = attribute.PriorityLevel;
                        CurrentBehaviorName     = mi.Name;

                        // if it blows up here, you defined a method with the exact same attribute and priority as one already found

                        Composite comp;
                        if (typeof(Composite).IsAssignableFrom(mi.ReturnType))
                        {
                            comp = mi.Invoke(null, null) as Composite;
                        }
                        else
                        {
                            Beta.Assert(mi.ReturnType == typeof(Task <bool>));
                            comp = new ActionRunCoroutine(o => mi.Invoke(null, null) as Task <bool>);
                        }

                        string name = behavior + "." + mi.Name + "." + attribute.PriorityLevel;

                        if (SingularSettings.Trace)
                        {
                            comp = new CallTrace(name, comp);
                        }

                        if (matchedMethods.ContainsKey(attribute))
                        {
                            Logger.Write(LogColor.Hilite, "Internal Error:  method '{0}' has attribute that already exists", name);
                            Logger.WriteDiagnostic(" ");
                            Logger.WriteDiagnostic("Dump Methods");
                            Logger.WriteDiagnostic("===========================");
                            foreach (var v in matchedMethods)
                            {
                                Logger.WriteDiagnostic("{0} {1} {2} {3}", v.Key.SpecificClass, v.Key.SpecificSpec, v.Key.SpecificContext, v.Key.PriorityLevel);
                            }
                            Logger.WriteDiagnostic("===========================");
                            Logger.WriteDiagnostic("{0} {1} {2} {3}  == add  attempt for {4}", attribute.SpecificClass, attribute.SpecificSpec, attribute.SpecificContext, attribute.PriorityLevel, name);
                            Logger.WriteDiagnostic(" ");
                        }

                        matchedMethods.Add(attribute, comp);

                        CurrentBehaviorType     = 0;
                        CurrentBehaviorPriority = 0;
                        CurrentBehaviorName     = string.Empty;
                    }
                }
            }
            // If we found no methods, rofls!
            if (matchedMethods.Count <= 0)
            {
                return(null);
            }

            var result = new PrioritySelector();

            foreach (var kvp in matchedMethods.OrderByDescending(mm => mm.Key.PriorityLevel))
            {
                result.AddChild(kvp.Value);
                behaviourCount++;
            }

            return(result);
        }