ABM_creator.ConsumableCreator.Run C# (CSharp) Метод

Run() публичный Метод

public Run ( ) : void
Результат void
        public void Run()
        {
            System.Collections.ArrayList tradeScrollList = new System.Collections.ArrayList();

            for (int ip = 0; ip < Globals.iprp_spells2da.RowCount; ip++)
            {
                //DebugWindow.PrintDebugMessage("Looking at iprp_spells.2da row: " + ip);
                string tdaSpellId = Globals.iprp_spells2da["SpellIndex"][ip];
                string tdaCasterLevel = Globals.iprp_spells2da["CasterLvl"][ip];
                string icon = Globals.iprp_spells2da["Icon"][ip];
                bool formatOK = true;
                int spellId = -1;
                int casterLevel = -1;
                try
                {
                    spellId = Convert.ToInt32(tdaSpellId);
                    casterLevel = Convert.ToInt32(tdaCasterLevel);
                    DebugWindow.PrintDebugMessage("Creating consumables for spell id " + spellId + ", caster level " + casterLevel + " and scroll icon " + icon + ".");
                }
                catch
                {
                    DebugWindow.PrintDebugMessage("2da format error for iprp_spells.2da line " + ip + ", spell id " + tdaSpellId + ", caster level " + tdaCasterLevel + ".");
                    formatOK = false;
                }

                if (formatOK && !ipHash.Contains(tdaSpellId.ToString() + "_" + tdaCasterLevel.ToString()))
                {

                    NWN2Toolset.NWN2.Rules.CNWSpell spell = Globals.spells.GetSpell(spellId);
                    ipHash.Add(tdaSpellId.ToString() + "_" + tdaCasterLevel.ToString());

                    if (spell != null && spell.IsValid() == 1 && spell.GetSpellMasterSpell() == spellId)
                    {
                        int targets = spell.GetSpellTargetType();
                        int wizardLevel = spell.GetSpellWizardLevel();
                        int clericLevel = spell.GetSpellClericLevel();
                        int druidLevel = spell.GetSpellDruidLevel();
                        int rangerLevel = spell.GetSpellRangerLevel();
                        int paladinLevel = spell.GetSpellPaladinLevel();
                        int bardLevel = spell.GetSpellBardLevel();

                        // Find the lowest spell level.
                        int lowestSpellLevel = wizardLevel;
                        if (lowestSpellLevel > clericLevel)
                            lowestSpellLevel = clericLevel;
                        if (lowestSpellLevel > druidLevel)
                            lowestSpellLevel = druidLevel;

                        float costLevel = lowestSpellLevel;
                        if (lowestSpellLevel == 0)
                            costLevel = 0.5F;

                        if ((lowestSpellLevel < 255))
                        {
                            if ((targets & 2) != 0 && lowestSpellLevel <= 3 && spell.GetSpellHostile() != 1 && !nonpotion(spellId))
                            {
                                // Can target a creature, ie can be a potion.
                                Potion potion = new Potion(ip, spellId, lowestSpellLevel, casterLevel, spell);
                                Globals.AddBlueprint(potion.blueprint);
                                potionStore.addToPotionItems(potion.blueprint);
                            }
                            DebugWindow.PrintDebugMessage("Potion handled.");

                            if (lowestSpellLevel <= 4)
                            {
                                // Can be a wand.
                                Wand wand = new Wand(ip, spellId, lowestSpellLevel, casterLevel, spell);
                                addClassRestrictions(wand.blueprint, bardLevel, clericLevel, druidLevel, paladinLevel, rangerLevel, wizardLevel);
                                Globals.AddBlueprint(wand.blueprint);
                                wandStore.addToPotionItems(wand.blueprint);
                            }
                            DebugWindow.PrintDebugMessage("Wand handled.");

                            int lowestDivineLevel = clericLevel;
                            if (druidLevel < clericLevel)
                            {
                                lowestDivineLevel = druidLevel;
                            }
                            if (lowestDivineLevel == 255)
                            {
                                lowestDivineLevel = rangerLevel;
                                if (lowestDivineLevel > paladinLevel)
                                    lowestDivineLevel = paladinLevel;
                            }
                            if (lowestDivineLevel < 255)
                            {
                                // Can be a divine scroll.
                                Scroll scroll = new DivineScroll(ip, spellId, lowestSpellLevel, casterLevel, spell, icon);
                                addClassRestrictions(scroll.blueprint, 255, clericLevel, druidLevel, paladinLevel, rangerLevel, 255);
                                Globals.AddBlueprint(scroll.blueprint);
                                scrollStore.addToPotionItems(scroll.blueprint);
                            }
                            DebugWindow.PrintDebugMessage("Divine Scroll handled.");

                            int lowestArcaneLevel = wizardLevel;
                            if (wizardLevel == 255)
                            {
                                lowestArcaneLevel = bardLevel;
                            }

                            if (wizardLevel < 255 && !tradeScrollList.Contains(spellId))
                            {
                                // Can be a trade scroll.
                                TradeScroll tradescroll = new TradeScroll(ip, spellId, lowestSpellLevel, spell);
                                Globals.AddBlueprint(tradescroll.blueprint);
                                tradeScrollList.Add(spellId);
                            }
                            DebugWindow.PrintDebugMessage("Trade scroll handled.");

                            if (lowestArcaneLevel < 255)
                            {
                                // Can be an arcane scroll.
                                Scroll scroll = new ArcaneScroll(ip, spellId, lowestSpellLevel, casterLevel, spell, icon);
                                addClassRestrictions(scroll.blueprint, bardLevel, 255, 255, 255, 255, wizardLevel);
                                Globals.AddBlueprint(scroll.blueprint);
                                scrollStore.addToPotionItems(scroll.blueprint);
                            }
                            DebugWindow.PrintDebugMessage("Arcane scroll handled.");
                        }
                    }
                }
            }
            DebugWindow.PrintDebugMessage("Items in blueprint collection: " + Globals.items.Count);

            NotfyIconsNotFoundFor("Potions", Potion.iconsMissing);
            NotfyIconsNotFoundFor("Wand", Wand.iconsMissing);
            NotfyIconsNotFoundFor("Scroll", Scroll.iconsMissing);

            ipHash = new HashSet<String>();
        }
    }

Usage Example

        private void HandlePluginLaunch(object sender, EventArgs e)
        {
            //NWN2Toolset.NWN2.Data.Blueprints.NWN2GlobalBlueprintManager bpManager = new NWN2Toolset.NWN2.Data.Blueprints.NWN2GlobalBlueprintManager();
            //bpManager.Initialize();
            NWN2Toolset.NWN2.Data.TypedCollections.NWN2BlueprintCollection items = NWN2Toolset.NWN2.Data.Blueprints.NWN2GlobalBlueprintManager.GetBlueprintsOfType(NWN2Toolset.NWN2.Data.Templates.NWN2ObjectType.Item);
            ALFAItemBlueprint scroll;
            
            System.Windows.Forms.Form form = new System.Windows.Forms.Form();
            /*System.Windows.Forms.TextBox text = new System.Windows.Forms.TextBox();
            text.Size = new System.Drawing.Size(400, 300);
            text.Multiline = true;
            text.WordWrap = false;
            text.AcceptsReturn = true;
            text.AcceptsTab = true;
            text.ScrollBars = System.Windows.Forms.ScrollBars.Both;
            text.Text = scroll.ToString();*/
            System.Windows.Forms.ListBox listBox = new System.Windows.Forms.ListBox();
            listBox.Sorted = true;
            listBox.HorizontalScrollbar = true;
            listBox.Size = new System.Drawing.Size(400, 300);

            form.Controls.Add(listBox);
            form.Size = new System.Drawing.Size(430, 330);
            form.Show();    

            //items.Add(scroll.ItemBlueprint);
            //scroll.TemplateResRef = "TEST RESREF";
            //scroll.AddItemProperty(ALFAItemProperty.CastSpell1ChargeItemProperty(0));
            //scroll.AddItemProperty(ALFAItemProperty.WizardOnlyItemProperty());            
            //items.Add(scroll.ItemBlueprint);

            ConsumableCreator cc = new ConsumableCreator();
            cc.Run();
        }