ACR_Items.GenerateScroll.NewScroll C# (CSharp) Метод

NewScroll() публичный статический Метод

public static NewScroll ( CLRScriptBase script, int maxValue ) : int
script CLRScriptFramework.CLRScriptBase
maxValue int
Результат int
        public static int NewScroll(CLRScriptBase script, int maxValue)
        {
            #region Early Return if No Scrolls Fit the Criteria
            if (maxValue < 12)
            {
                return 0;
            }
            #endregion

            #region Generate up to Level 9 Scrolls
            if (maxValue >= 3825)
            {
                int roll = Generation.rand.Next(512);
                if((roll & 256) == 0)
                {
                    script.CreateItemOnObject(Level0Scrolls[Generation.rand.Next(Level0Scrolls.Count)], script.OBJECT_SELF, 1, "", FALSE);
                    return 12;
                }
                else if((roll & 128) == 0)
                {
                    script.CreateItemOnObject(Level1Scrolls[Generation.rand.Next(Level1Scrolls.Count)], script.OBJECT_SELF, 1, "", FALSE);
                    return 25;
                }
                else if ((roll & 64) == 0)
                {
                    script.CreateItemOnObject(Level2Scrolls[Generation.rand.Next(Level2Scrolls.Count)], script.OBJECT_SELF, 1, "", FALSE);
                    return 150;
                }
                else if ((roll & 32) == 0)
                {
                    script.CreateItemOnObject(Level3Scrolls[Generation.rand.Next(Level3Scrolls.Count)], script.OBJECT_SELF, 1, "", FALSE);
                    return 375;
                }
                else if ((roll & 16) == 0)
                {
                    script.CreateItemOnObject(Level4Scrolls[Generation.rand.Next(Level4Scrolls.Count)], script.OBJECT_SELF, 1, "", FALSE);
                    return 700;
                }
                else if ((roll & 8) == 0)
                {
                    script.CreateItemOnObject(Level5Scrolls[Generation.rand.Next(Level5Scrolls.Count)], script.OBJECT_SELF, 1, "", FALSE);
                    return 1125;
                }
                else if ((roll & 4) == 0)
                {
                    script.CreateItemOnObject(Level6Scrolls[Generation.rand.Next(Level6Scrolls.Count)], script.OBJECT_SELF, 1, "", FALSE);
                    return 1650;
                }
                else if ((roll & 2) == 0)
                {
                    script.CreateItemOnObject(Level7Scrolls[Generation.rand.Next(Level7Scrolls.Count)], script.OBJECT_SELF, 1, "", FALSE);
                    return 2275;
                }
                else if ((roll & 1) == 0)
                {
                    script.CreateItemOnObject(Level8Scrolls[Generation.rand.Next(Level8Scrolls.Count)], script.OBJECT_SELF, 1, "", FALSE);
                    return 3000;
                }
                else
                {
                    script.CreateItemOnObject(Level9Scrolls[Generation.rand.Next(Level9Scrolls.Count)], script.OBJECT_SELF, 1, "", FALSE);
                    return 3825;
                }
            }
            #endregion

            #region Generate up to Level 8 Scrolls
            else if (maxValue > 3000)
            {
                int roll = Generation.rand.Next(256);
                if ((roll & 128) == 0)
                {
                    script.CreateItemOnObject(Level0Scrolls[Generation.rand.Next(Level0Scrolls.Count)], script.OBJECT_SELF, 1, "", FALSE);
                    return 12;
                }
                else if ((roll & 64) == 0)
                {
                    script.CreateItemOnObject(Level1Scrolls[Generation.rand.Next(Level1Scrolls.Count)], script.OBJECT_SELF, 1, "", FALSE);
                    return 25;
                }
                else if ((roll & 32) == 0)
                {
                    script.CreateItemOnObject(Level2Scrolls[Generation.rand.Next(Level2Scrolls.Count)], script.OBJECT_SELF, 1, "", FALSE);
                    return 150;
                }
                else if ((roll & 16) == 0)
                {
                    script.CreateItemOnObject(Level3Scrolls[Generation.rand.Next(Level3Scrolls.Count)], script.OBJECT_SELF, 1, "", FALSE);
                    return 375;
                }
                else if ((roll & 8) == 0)
                {
                    script.CreateItemOnObject(Level4Scrolls[Generation.rand.Next(Level4Scrolls.Count)], script.OBJECT_SELF, 1, "", FALSE);
                    return 700;
                }
                else if ((roll & 4) == 0)
                {
                    script.CreateItemOnObject(Level5Scrolls[Generation.rand.Next(Level5Scrolls.Count)], script.OBJECT_SELF, 1, "", FALSE);
                    return 1125;
                }
                else if ((roll & 2) == 0)
                {
                    script.CreateItemOnObject(Level6Scrolls[Generation.rand.Next(Level6Scrolls.Count)], script.OBJECT_SELF, 1, "", FALSE);
                    return 1650;
                }
                else if ((roll & 1) == 0)
                {
                    script.CreateItemOnObject(Level7Scrolls[Generation.rand.Next(Level7Scrolls.Count)], script.OBJECT_SELF, 1, "", FALSE);
                    return 2275;
                }
                else
                {
                    script.CreateItemOnObject(Level8Scrolls[Generation.rand.Next(Level8Scrolls.Count)], script.OBJECT_SELF, 1, "", FALSE);
                    return 3000;
                }
            }
            #endregion

            #region Generate up to Level 7 Scrolls
            else if (maxValue > 2275)
            {
                int roll = Generation.rand.Next(128);
                if ((roll & 64) == 0)
                {
                    script.CreateItemOnObject(Level0Scrolls[Generation.rand.Next(Level0Scrolls.Count)], script.OBJECT_SELF, 1, "", FALSE);
                    return 12;
                }
                else if ((roll & 32) == 0)
                {
                    script.CreateItemOnObject(Level1Scrolls[Generation.rand.Next(Level1Scrolls.Count)], script.OBJECT_SELF, 1, "", FALSE);
                    return 25;
                }
                else if ((roll & 16) == 0)
                {
                    script.CreateItemOnObject(Level2Scrolls[Generation.rand.Next(Level2Scrolls.Count)], script.OBJECT_SELF, 1, "", FALSE);
                    return 150;
                }
                else if ((roll & 8) == 0)
                {
                    script.CreateItemOnObject(Level3Scrolls[Generation.rand.Next(Level3Scrolls.Count)], script.OBJECT_SELF, 1, "", FALSE);
                    return 375;
                }
                else if ((roll & 4) == 0)
                {
                    script.CreateItemOnObject(Level4Scrolls[Generation.rand.Next(Level4Scrolls.Count)], script.OBJECT_SELF, 1, "", FALSE);
                    return 700;
                }
                else if ((roll & 2) == 0)
                {
                    script.CreateItemOnObject(Level5Scrolls[Generation.rand.Next(Level5Scrolls.Count)], script.OBJECT_SELF, 1, "", FALSE);
                    return 1125;
                }
                else if ((roll & 1) == 0)
                {
                    script.CreateItemOnObject(Level6Scrolls[Generation.rand.Next(Level6Scrolls.Count)], script.OBJECT_SELF, 1, "", FALSE);
                    return 1650;
                }
                else
                {
                    script.CreateItemOnObject(Level7Scrolls[Generation.rand.Next(Level7Scrolls.Count)], script.OBJECT_SELF, 1, "", FALSE);
                    return 2275;
                }
            }
            #endregion

            #region Generate up to Level 6 Scrolls
            else if (maxValue > 1650)
            {
                int roll = Generation.rand.Next(64);
                if ((roll & 32) == 0)
                {
                    script.CreateItemOnObject(Level0Scrolls[Generation.rand.Next(Level0Scrolls.Count)], script.OBJECT_SELF, 1, "", FALSE);
                    return 12;
                }
                else if ((roll & 16) == 0)
                {
                    script.CreateItemOnObject(Level1Scrolls[Generation.rand.Next(Level1Scrolls.Count)], script.OBJECT_SELF, 1, "", FALSE);
                    return 25;
                }
                else if ((roll & 8) == 0)
                {
                    script.CreateItemOnObject(Level2Scrolls[Generation.rand.Next(Level2Scrolls.Count)], script.OBJECT_SELF, 1, "", FALSE);
                    return 150;
                }
                else if ((roll & 4) == 0)
                {
                    script.CreateItemOnObject(Level3Scrolls[Generation.rand.Next(Level3Scrolls.Count)], script.OBJECT_SELF, 1, "", FALSE);
                    return 375;
                }
                else if ((roll & 2) == 0)
                {
                    script.CreateItemOnObject(Level4Scrolls[Generation.rand.Next(Level4Scrolls.Count)], script.OBJECT_SELF, 1, "", FALSE);
                    return 700;
                }
                else if ((roll & 1) == 0)
                {
                    script.CreateItemOnObject(Level5Scrolls[Generation.rand.Next(Level5Scrolls.Count)], script.OBJECT_SELF, 1, "", FALSE);
                    return 1125;
                }
                else
                {
                    script.CreateItemOnObject(Level6Scrolls[Generation.rand.Next(Level6Scrolls.Count)], script.OBJECT_SELF, 1, "", FALSE);
                    return 1650;
                }
            }
            #endregion

            #region Generate up to Level 5 Scrolls
            else if (maxValue > 1125)
            {
                int roll = Generation.rand.Next(32);
                if ((roll & 16) == 0)
                {
                    script.CreateItemOnObject(Level0Scrolls[Generation.rand.Next(Level0Scrolls.Count)], script.OBJECT_SELF, 1, "", FALSE);
                    return 12;
                }
                else if ((roll & 8) == 0)
                {
                    script.CreateItemOnObject(Level1Scrolls[Generation.rand.Next(Level1Scrolls.Count)], script.OBJECT_SELF, 1, "", FALSE);
                    return 25;
                }
                else if ((roll & 4) == 0)
                {
                    script.CreateItemOnObject(Level2Scrolls[Generation.rand.Next(Level2Scrolls.Count)], script.OBJECT_SELF, 1, "", FALSE);
                    return 150;
                }
                else if ((roll & 2) == 0)
                {
                    script.CreateItemOnObject(Level3Scrolls[Generation.rand.Next(Level3Scrolls.Count)], script.OBJECT_SELF, 1, "", FALSE);
                    return 375;
                }
                else if ((roll & 1) == 0)
                {
                    script.CreateItemOnObject(Level4Scrolls[Generation.rand.Next(Level4Scrolls.Count)], script.OBJECT_SELF, 1, "", FALSE);
                    return 700;
                }
                else
                {
                    script.CreateItemOnObject(Level5Scrolls[Generation.rand.Next(Level5Scrolls.Count)], script.OBJECT_SELF, 1, "", FALSE);
                    return 1125;
                }
            }
            #endregion

            #region Generate up to Level 4 Scrolls
            else if (maxValue > 700)
            {
                int roll = Generation.rand.Next(16);
                if ((roll & 8) == 0)
                {
                    script.CreateItemOnObject(Level0Scrolls[Generation.rand.Next(Level0Scrolls.Count)], script.OBJECT_SELF, 1, "", FALSE);
                    return 12;
                }
                else if ((roll & 4) == 0)
                {
                    script.CreateItemOnObject(Level1Scrolls[Generation.rand.Next(Level1Scrolls.Count)], script.OBJECT_SELF, 1, "", FALSE);
                    return 25;
                }
                else if ((roll & 2) == 0)
                {
                    script.CreateItemOnObject(Level2Scrolls[Generation.rand.Next(Level2Scrolls.Count)], script.OBJECT_SELF, 1, "", FALSE);
                    return 150;
                }
                else if ((roll & 1) == 0)
                {
                    script.CreateItemOnObject(Level3Scrolls[Generation.rand.Next(Level3Scrolls.Count)], script.OBJECT_SELF, 1, "", FALSE);
                    return 375;
                }
                else
                {
                    script.CreateItemOnObject(Level4Scrolls[Generation.rand.Next(Level4Scrolls.Count)], script.OBJECT_SELF, 1, "", FALSE);
                    return 700;
                }
            }
            #endregion

            #region Generate up to Level 3 Scrolls
            else if (maxValue > 375)
            {
                int roll = Generation.rand.Next(8);
                if ((roll & 4) == 0)
                {
                    script.CreateItemOnObject(Level0Scrolls[Generation.rand.Next(Level0Scrolls.Count)], script.OBJECT_SELF, 1, "", FALSE);
                    return 12;
                }
                else if ((roll & 2) == 0)
                {
                    script.CreateItemOnObject(Level1Scrolls[Generation.rand.Next(Level1Scrolls.Count)], script.OBJECT_SELF, 1, "", FALSE);
                    return 25;
                }
                else if ((roll & 1) == 0)
                {
                    script.CreateItemOnObject(Level2Scrolls[Generation.rand.Next(Level2Scrolls.Count)], script.OBJECT_SELF, 1, "", FALSE);
                    return 150;
                }
                else
                {
                    script.CreateItemOnObject(Level3Scrolls[Generation.rand.Next(Level3Scrolls.Count)], script.OBJECT_SELF, 1, "", FALSE);
                    return 375;
                }
            }
            #endregion

            #region Generate up to Level 2 Scrolls
            else if (maxValue > 150)
            {
                int roll = Generation.rand.Next(4);
                if ((roll & 2) == 0)
                {
                    script.CreateItemOnObject(Level0Scrolls[Generation.rand.Next(Level0Scrolls.Count)], script.OBJECT_SELF, 1, "", FALSE);
                    return 12;
                }
                else if ((roll & 1) == 0)
                {
                    script.CreateItemOnObject(Level1Scrolls[Generation.rand.Next(Level1Scrolls.Count)], script.OBJECT_SELF, 1, "", FALSE);
                    return 25;
                }
                else
                {
                    script.CreateItemOnObject(Level2Scrolls[Generation.rand.Next(Level2Scrolls.Count)], script.OBJECT_SELF, 1, "", FALSE);
                    return 150;
                }
            }
            #endregion

            #region Generate up to Level 1 Spells
            else if (maxValue > 25)
            {
                int roll = Generation.rand.Next(2);
                if ((roll & 1) == 0)
                {
                    script.CreateItemOnObject(Level0Scrolls[Generation.rand.Next(Level0Scrolls.Count)], script.OBJECT_SELF, 1, "", FALSE);
                    return 12;
                }
                else
                {
                    script.CreateItemOnObject(Level1Scrolls[Generation.rand.Next(Level1Scrolls.Count)], script.OBJECT_SELF, 1, "", FALSE);
                    return 25;
                }
            }
            #endregion

            #region Only Generate Level 0 Spells
            else
            {
                script.CreateItemOnObject(Level0Scrolls[Generation.rand.Next(Level0Scrolls.Count)], script.OBJECT_SELF, 1, "", FALSE);
                return 12;
            }
            #endregion
        }

Usage Example

Пример #1
0
        public static void GenerateLoot(CLRScriptBase script, int lootValue, int maxItemValue)
        {
            if (lootValue < 1)
            {
                return;
            }

            if (maxItemValue < 1)
            {
                maxItemValue = lootValue;
            }

            // For expensive caches, favor magic that is going to be most-commonly crafted.
            while (lootValue > 1000)
            {
                if (maxItemValue > lootValue)
                {
                    maxItemValue = lootValue;
                }
                switch (script.d10(1))
                {
                case 1:
                {
                    lootValue -= GenerateArt(script, maxItemValue);
                    break;
                }

                default:
                {
                    int roll     = script.d100(1);
                    int decrease = 0;
                    if (roll > 82)
                    {
                        decrease   = GenerateScroll.NewScroll(script, maxItemValue);       // 81-100
                        lootValue -= decrease;
                    }
                    else if (roll > 65)
                    {
                        decrease   = GeneratePotion.NewPotion(script, maxItemValue);       // 66-80
                        lootValue -= decrease;
                    }
                    else if (roll > 55)
                    {
                        decrease   = GenerateWand.NewWand(script, maxItemValue);       // 56-65
                        lootValue -= decrease;
                    }
                    else if (roll > 52)
                    {
                        decrease   = GenerateStaff.NewStaff(script, maxItemValue);       // 53-55
                        lootValue -= decrease;
                    }
                    else if (roll > 50)
                    {
                        decrease   = GenerateRod.NewRod(script, maxItemValue);       // 51-52
                        lootValue -= decrease;
                    }
                    else if (roll > 42)
                    {
                        decrease   = GenerateArmor.NewArmor(script, maxItemValue);       // 43-50
                        lootValue -= decrease;
                    }
                    else if (roll > 35)
                    {
                        decrease   = GenerateWeapon.NewWeapon(script, maxItemValue);       // 36-42
                        lootValue -= decrease;
                    }
                    else if (roll > 30)
                    {
                        decrease   = GenerateAmulet.NewAmulet(script, maxItemValue);       // 31-35
                        lootValue -= decrease;
                    }
                    else if (roll > 25)
                    {
                        decrease   = GenerateBelt.NewBelt(script, maxItemValue);       // 26-30
                        lootValue -= decrease;
                    }
                    else if (roll > 20)
                    {
                        decrease   = GenerateBoots.NewBoots(script, maxItemValue);       // 21-25
                        lootValue -= decrease;
                    }
                    else if (roll > 15)
                    {
                        decrease   = GenerateCloak.NewCloak(script, maxItemValue);       // 16-20
                        lootValue -= decrease;
                    }
                    else if (roll > 10)
                    {
                        decrease   = GenerateHelmet.NewHelmet(script, maxItemValue);       // 11-15
                        lootValue -= decrease;
                    }
                    else if (roll > 5)
                    {
                        decrease   = GenerateRing.NewRing(script, maxItemValue);       // 6-10
                        lootValue -= decrease;
                    }
                    else
                    {
                        decrease   = GenerateGloves.NewGloves(script, maxItemValue);       // 1-5
                        lootValue -= decrease;
                    }
                    break;
                }
                }
                if (lootValue < 10)
                {
                    script.CreateItemOnObject("nw_it_gold001", script.OBJECT_SELF, lootValue, "", FALSE);
                    return;
                }
                if (script.d100(1) > 95)
                {
                    script.CreateItemOnObject("nw_it_gold001", script.OBJECT_SELF, maxItemValue / 10, "", FALSE);
                    lootValue -= maxItemValue / 10;
                }
            }

            // For cheap loot or to clean up big caches, use more weapons and armor.
            while (lootValue > 0)
            {
                if (maxItemValue > lootValue)
                {
                    maxItemValue = lootValue;
                }
                switch (script.d10(1))
                {
                case 1:
                {
                    lootValue -= GenerateArt(script, maxItemValue);
                    break;
                }

                default:
                {
                    int roll     = script.d100(1);
                    int decrease = 0;
                    if (roll > 91)
                    {
                        decrease   = GenerateScroll.NewScroll(script, maxItemValue);       // 83-100
                        lootValue -= decrease;
                    }
                    else if (roll > 82)
                    {
                        decrease   = GeneratePotion.NewPotion(script, maxItemValue);       // 61-82
                        lootValue -= decrease;
                    }
                    else if (roll > 60)
                    {
                        decrease   = GenerateArmor.NewArmor(script, maxItemValue);       // 61-82
                        lootValue -= decrease;
                    }
                    else if (roll > 21)
                    {
                        decrease   = GenerateWeapon.NewWeapon(script, maxItemValue);       // 22-59
                        lootValue -= decrease;
                    }
                    else if (roll > 18)
                    {
                        decrease   = GenerateAmulet.NewAmulet(script, maxItemValue);       // 19-21
                        lootValue -= decrease;
                    }
                    else if (roll > 15)
                    {
                        decrease   = GenerateBelt.NewBelt(script, maxItemValue);       // 16-18
                        lootValue -= decrease;
                    }
                    else if (roll > 12)
                    {
                        decrease   = GenerateBoots.NewBoots(script, maxItemValue);       // 13-15
                        lootValue -= decrease;
                    }
                    else if (roll > 9)
                    {
                        decrease   = GenerateCloak.NewCloak(script, maxItemValue);       // 10-12
                        lootValue -= decrease;
                    }
                    else if (roll > 6)
                    {
                        decrease   = GenerateHelmet.NewHelmet(script, maxItemValue);       // 7-9
                        lootValue -= decrease;
                    }
                    else if (roll > 3)
                    {
                        decrease   = GenerateRing.NewRing(script, maxItemValue);       // 4-6
                        lootValue -= decrease;
                    }
                    else
                    {
                        decrease   = GenerateGloves.NewGloves(script, maxItemValue);       // 1-3
                        lootValue -= decrease;
                    }
                    break;
                }
                }
                if (lootValue < 10)
                {
                    script.CreateItemOnObject("nw_it_gold001", script.OBJECT_SELF, lootValue, "", FALSE);
                    return;
                }
                if (script.d100(1) > 95)
                {
                    script.CreateItemOnObject("nw_it_gold001", script.OBJECT_SELF, maxItemValue / 10, "", FALSE);
                    lootValue -= maxItemValue / 10;
                }
            }
        }
GenerateScroll