예제 #1
0
        /// <summary>This will: loop assemblies,
        /// loop types,
        /// filter types that are a subclass of RotationBase and not the abstract,
        /// create an instance of a RotationBase subclass so we can interigate KeySpell within the RotationBase subclass,
        /// Check if the character has the Keyspell,
        /// Set the active rotation to the matching RotationBase subclass.</summary>
        private void QueryClassTree()
        {
            try
            {
                Type type = typeof(RotationBase);

                //no need to get ALL Assemblies, need only the executed ones
                IEnumerable <Type> types = Assembly.GetExecutingAssembly().GetTypes().Where(p => p.IsSubclassOf(type));

                //_rotations.AddRange(new TypeLoader<RotationBase>(null));

                this._rotations = new List <RotationBase>();
                foreach (Type x in types)
                {
                    ConstructorInfo constructorInfo = x.GetConstructor(new Type[] { });
                    if (constructorInfo != null)
                    {
                        var rb = constructorInfo.Invoke(new object[] { }) as RotationBase;
                        if (rb != null && SpellManager.HasSpell(rb.KeySpellId))
                        {
                            CLULogger.TroubleshootLog(" Using " + rb.Name + " rotation. Character has " + rb.KeySpell);
                            this._rotations.Add(rb);
                        }
                        else
                        {
                            if (rb != null)
                            {
                                //TroubleshootLog(" Skipping " + rb.Name + " rotation. Character is missing " + rb.KeySpell);
                            }
                        }
                    }
                }

                // If there is more than one rotation then display the selector for the user, otherwise just load the one and only.

                if (this._rotations.Count > 1)
                {
                    string value = "null";
                    if (
                        GUIHelpers.RotationSelector
                            ("[CLU] " + Version + " Rotation Selector", this._rotations,
                            "Please select your prefered rotation:", ref value) == DialogResult.OK)
                    {
                        this.SetActiveRotation(this._rotations.First(x => value != null && x.Name == value));
                    }
                }
                else
                {
                    if (this._rotations.Count == 0)
                    {
                        CLULogger.Log("Couldn't finde a rotation for you, Contact us!");
                        StopBot("Unable to find Active Rotation");
                    }
                    else
                    {
                        RotationBase r = this._rotations.FirstOrDefault();
                        if (r != null)
                        {
                            CLULogger.Log("Found rotation: " + r.Name);
                            this.SetActiveRotation(r);
                        }
                    }
                }
            }
            catch (ReflectionTypeLoadException ex)
            {
                var sb = new StringBuilder();
                foreach (Exception exSub in ex.LoaderExceptions)
                {
                    sb.AppendLine(exSub.Message);
                    if (exSub is FileNotFoundException)
                    {
                        var exFileNotFound = exSub as FileNotFoundException;
                        if (!string.IsNullOrEmpty(exFileNotFound.FusionLog))
                        {
                            sb.AppendLine("CLU Log:");
                            sb.AppendLine(exFileNotFound.FusionLog);
                        }
                    }
                    sb.AppendLine();
                }
                string errorMessage = sb.ToString();
                CLULogger.Log(" Woops, we could not set the rotation.");
                CLULogger.Log(errorMessage);
                StopBot(" Unable to find Active Rotation: " + ex);
            }
        }