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); }