ACR_Items.GenerateArmor.NewArmor C# (CSharp) Метод

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

public static NewArmor ( CLRScriptBase script, int maxValue ) : int
script CLRScriptFramework.CLRScriptBase
maxValue int
Результат int
        public static int NewArmor(CLRScriptBase script, int maxValue)
        {
            #region Calculate Armor Type
            List<int> possibleBaseItems = new List<int>();
            foreach (int armorType in ArmorResRefs.Keys)
            {
                if (Pricing.ArmorRulesTypeValues[armorType] <= maxValue)
                {
                    possibleBaseItems.Add(armorType);
                }
            }
            if (possibleBaseItems.Count == 0)
            {
                // Can't afford any armor. What are we doing here?
                return 0;
            }
            int selectedArmorType = possibleBaseItems[Generation.rand.Next(possibleBaseItems.Count)];
            int armorValue = Pricing.ArmorRulesTypeValues[selectedArmorType];
            maxValue -= armorValue;
            uint armor = script.CreateItemOnObject(ArmorResRefs[selectedArmorType], script.OBJECT_SELF, 1, "", FALSE);
            #endregion

            #region Armor Appearance
            Generation.Theme armorTheme = Generation.GetEnchantmentTheme();
            if (script.GetBaseItemType(armor) == BASE_ITEM_ARMOR)
            {
                script.StoreCampaignObject(ACR_Items.ItemChangeDBName, ACR_Items.ModelChangeVarName, armor, script.OBJECT_SELF);
                ArmorSet set = null;
                switch (selectedArmorType)
                {
                    case ARMOR_RULES_TYPE_BANDED:
                        set = ACR_Items.ArmorSetLibrary[ACR_Items.ArmorSetTypes.Banded][Generation.rand.Next(ACR_Items.ArmorSetLibrary[ACR_Items.ArmorSetTypes.Banded].Count)];
                        break;
                    case ARMOR_RULES_TYPE_BREASTPLATE:
                        set = ACR_Items.ArmorSetLibrary[ACR_Items.ArmorSetTypes.Breastplate][Generation.rand.Next(ACR_Items.ArmorSetLibrary[ACR_Items.ArmorSetTypes.Breastplate].Count)];
                        break;
                    case ARMOR_RULES_TYPE_CHAIN_SHIRT:
                        set = ACR_Items.ArmorSetLibrary[ACR_Items.ArmorSetTypes.ChainShirt][Generation.rand.Next(ACR_Items.ArmorSetLibrary[ACR_Items.ArmorSetTypes.ChainShirt].Count)];
                        break;
                    case ARMOR_RULES_TYPE_CHAINMAIL:
                        set = ACR_Items.ArmorSetLibrary[ACR_Items.ArmorSetTypes.Chainmail][Generation.rand.Next(ACR_Items.ArmorSetLibrary[ACR_Items.ArmorSetTypes.Chainmail].Count)];
                        break;
                    case ARMOR_RULES_TYPE_CLOTH:
                        set = ACR_Items.ArmorSetLibrary[ACR_Items.ArmorSetTypes.Cloth][Generation.rand.Next(ACR_Items.ArmorSetLibrary[ACR_Items.ArmorSetTypes.Cloth].Count)];
                        break;
                    case ARMOR_RULES_TYPE_FULL_PLATE:
                        set = ACR_Items.ArmorSetLibrary[ACR_Items.ArmorSetTypes.FullPlate][Generation.rand.Next(ACR_Items.ArmorSetLibrary[ACR_Items.ArmorSetTypes.FullPlate].Count)];
                        break;
                    case ARMOR_RULES_TYPE_HALF_PLATE:
                        set = ACR_Items.ArmorSetLibrary[ACR_Items.ArmorSetTypes.HalfPlate][Generation.rand.Next(ACR_Items.ArmorSetLibrary[ACR_Items.ArmorSetTypes.HalfPlate].Count)];
                        break;
                    case ARMOR_RULES_TYPE_HIDE:
                        set = ACR_Items.ArmorSetLibrary[ACR_Items.ArmorSetTypes.Hide][Generation.rand.Next(ACR_Items.ArmorSetLibrary[ACR_Items.ArmorSetTypes.Hide].Count)];
                        break;
                    case ARMOR_RULES_TYPE_LEATHER:
                        set = ACR_Items.ArmorSetLibrary[ACR_Items.ArmorSetTypes.Leather][Generation.rand.Next(ACR_Items.ArmorSetLibrary[ACR_Items.ArmorSetTypes.Leather].Count)];
                        break;
                    case ARMOR_RULES_TYPE_PADDED:
                        set = ACR_Items.ArmorSetLibrary[ACR_Items.ArmorSetTypes.Padded][Generation.rand.Next(ACR_Items.ArmorSetLibrary[ACR_Items.ArmorSetTypes.Padded].Count)];
                        break;
                    case ARMOR_RULES_TYPE_SCALE:
                        set = ACR_Items.ArmorSetLibrary[ACR_Items.ArmorSetTypes.Scale][Generation.rand.Next(ACR_Items.ArmorSetLibrary[ACR_Items.ArmorSetTypes.Scale].Count)];
                        break;
                    case ARMOR_RULES_TYPE_STUDDED_LEATHER:
                        set = ACR_Items.ArmorSetLibrary[ACR_Items.ArmorSetTypes.StuddedLeather][Generation.rand.Next(ACR_Items.ArmorSetLibrary[ACR_Items.ArmorSetTypes.StuddedLeather].Count)];
                        break;
                }
                if (set != null)
                {
                    ItemModels.TakeArmorStyle(ALFA.Shared.Modules.InfoStore.ModifiedGff[ACR_Items.ModelChangeVarName], set);
                }
                ColorPair color = GeneratedColors.ColorPairs[armorTheme][Generation.rand.Next(GeneratedColors.ColorPairs[armorTheme].Count)];
                ItemColors.SetColorThemes(ALFA.Shared.Modules.InfoStore.ModifiedGff[ACR_Items.ModelChangeVarName], color.Primary, color.Accent);
                script.DestroyObject(armor, 0.0f, TRUE);
                armor = script.RetrieveCampaignObject(ACR_Items.ItemChangeDBName, ACR_Items.ModelChangeVarName, script.GetLocation(script.OBJECT_SELF), script.OBJECT_SELF, script.OBJECT_SELF);
            }
            #endregion

            #region See if We Want This to be Masterwork
            if (maxValue >= 150)
            {
                switch (selectedArmorType)
                {
                    case ARMOR_RULES_TYPE_BANDED:
                        script.SetArmorRulesType(armor, ARMOR_RULES_TYPE_BANDED_MASTERWORK);
                        armorValue += 150;
                        maxValue -= 150;
                        break;
                    case ARMOR_RULES_TYPE_BREASTPLATE:
                        script.SetArmorRulesType(armor, ARMOR_RULES_TYPE_BREASTPLATE_MASTERWORK);
                        armorValue += 150;
                        maxValue -= 150;
                        break;
                    case ARMOR_RULES_TYPE_CHAIN_SHIRT:
                        script.SetArmorRulesType(armor, ARMOR_RULES_TYPE_CHAIN_SHIRT_MASTERWORK);
                        armorValue += 150;
                        maxValue -= 150;
                        break;
                    case ARMOR_RULES_TYPE_CHAINMAIL:
                        script.SetArmorRulesType(armor, ARMOR_RULES_TYPE_CHAINMAIL_MASTERWORK);
                        armorValue += 150;
                        maxValue -= 150;
                        break;
                    case ARMOR_RULES_TYPE_FULL_PLATE:
                        script.SetArmorRulesType(armor, ARMOR_RULES_TYPE_FULL_PLATE_MASTERWORK);
                        armorValue += 150;
                        maxValue -= 150;
                        break;
                    case ARMOR_RULES_TYPE_HALF_PLATE:
                        script.SetArmorRulesType(armor, ARMOR_RULES_TYPE_HALF_PLATE_MASTERWORK);
                        armorValue += 150;
                        maxValue -= 150;
                        break;
                    case ARMOR_RULES_TYPE_HIDE:
                        script.SetArmorRulesType(armor, ARMOR_RULES_TYPE_HIDE_MASTERWORK);
                        armorValue += 150;
                        maxValue -= 150;
                        break;
                    case ARMOR_RULES_TYPE_LEATHER:
                        script.SetArmorRulesType(armor, ARMOR_RULES_TYPE_LEATHER_MASTERWORK);
                        armorValue += 150;
                        maxValue -= 150;
                        break;
                    case ARMOR_RULES_TYPE_PADDED:
                        script.SetArmorRulesType(armor, ARMOR_RULES_TYPE_PADDED_MASTERWORK);
                        armorValue += 150;
                        maxValue -= 150;
                        break;
                    case ARMOR_RULES_TYPE_SCALE:
                        script.SetArmorRulesType(armor, ARMOR_RULES_TYPE_SCALE_MASTERWORK);
                        armorValue += 150;
                        maxValue -= 150;
                        break;
                    case ARMOR_RULES_TYPE_SHIELD_HEAVY:
                        script.SetArmorRulesType(armor, ARMOR_RULES_TYPE_SHIELD_HEAVY_MASTERWORK);
                        armorValue += 150;
                        maxValue -= 150;
                        break;
                    case ARMOR_RULES_TYPE_SHIELD_LIGHT:
                        script.SetArmorRulesType(armor, ARMOR_RULES_TYPE_SHIELD_LIGHT_MASTERWORK);
                        armorValue += 150;
                        maxValue -= 150;
                        break;
                    case ARMOR_RULES_TYPE_SHIELD_TOWER:
                        script.SetArmorRulesType(armor, ARMOR_RULES_TYPE_SHIELD_TOWER_MASTERWORK);
                        armorValue += 150;
                        maxValue -= 150;
                        break;
                    case ARMOR_RULES_TYPE_SPLINT:
                        script.SetArmorRulesType(armor, ARMOR_RULES_TYPE_SPLINT_MASTERWORK);
                        armorValue += 150;
                        maxValue -= 150;
                        break;
                    case ARMOR_RULES_TYPE_STUDDED_LEATHER:
                        script.SetArmorRulesType(armor, ARMOR_RULES_TYPE_STUDDED_LEATHER_MASTERWORK);
                        armorValue += 150;
                        maxValue -= 150;
                        break;
                }
            }
            else
            {
                // We can't even afford masterwork. Carry on.
                return armorValue;
            }
            #endregion

            #region Calculate Effective Plus
            double effectivePlusRemaining = Math.Sqrt((double)(maxValue / 1000)); // we cast after the division because we're going to turn this into an int later.
            double currentEffectivePlus = 0.0;
            #endregion

            #region Set Base Properties
            int enhancementBonus = 0;
            if (effectivePlusRemaining >= 1.0)
            {
                enhancementBonus = 1;
                effectivePlusRemaining -= 1;
                currentEffectivePlus = 1;
                bool quirkAdded = false;
                while (effectivePlusRemaining >= 1)
                {
                    if (Generation.rand.Next(100) > 95)
                    {
                        // The remainder of the enchantment will
                        // be personality heavy.
                        break;
                    }
                    if (!quirkAdded && Generation.rand.Next(100) < 75)
                    {
                        enhancementBonus += 1;
                        effectivePlusRemaining -= 1;
                        currentEffectivePlus += 1;
                    }
                    else
                    {
                        List<EnhancementTypes> quirks = BuildBaseEnchantmentPossibilities(script.GetBaseItemType(armor), effectivePlusRemaining);
                        if (quirks.Count > 0)
                        {
                            EnhancementTypes quirk = quirks[Generation.rand.Next(quirks.Count)];
                            if (selectedArmorType == ARMOR_RULES_TYPE_CLOTH &&
                                quirk == EnhancementTypes.Twilight)
                            {
                                quirk = EnhancementTypes.SpellFocus;
                            }
                            switch (quirk)
                            {
                                case EnhancementTypes.CombatCasting:
                                    script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusFeat(IP_CONST_FEAT_COMBAT_CASTING), armor, 0.0f);
                                    script.SetFirstName(armor, String.Format("Battlemage's {0}", script.GetName(armor)));
                                    effectivePlusRemaining -= 1;
                                    currentEffectivePlus += 1;
                                    break;
                                case EnhancementTypes.DeflectArrows:
                                    script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusFeat(IP_CONST_FEAT_DEFLECT_ARROWS), armor, 0.0f);
                                    script.SetFirstName(armor, String.Format("Arrowcatching {0}", script.GetName(armor)));
                                    effectivePlusRemaining -= 2;
                                    currentEffectivePlus += 2;
                                    break;
                                case EnhancementTypes.Dodge:
                                    script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusFeat(IP_CONST_FEAT_DODGE), armor, 0.0f);
                                    script.SetFirstName(armor, String.Format("Nimble {0}", script.GetName(armor)));
                                    effectivePlusRemaining -= 1;
                                    currentEffectivePlus += 1;
                                    break;
                                case EnhancementTypes.ExtraTurning:
                                    script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusFeat(IP_CONST_FEAT_EXTRA_TURNING), armor, 0.0f);
                                    script.SetFirstName(armor, String.Format("Turning {0}", script.GetName(armor)));
                                    effectivePlusRemaining -= 1;
                                    currentEffectivePlus += 1;
                                    break;
                                case EnhancementTypes.SpellFocus:
                                    int primarySchool = Generation.SpellSchoolFocus[Generation.rand.Next(Generation.SpellSchoolFocus.Count)];
                                    script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusFeat(primarySchool), armor, 0.0f);
                                    script.SetFirstName(armor, String.Format("Mage's {0}", script.GetName(armor)));
                                    effectivePlusRemaining -= 1;
                                    currentEffectivePlus += 1;
                                    if (effectivePlusRemaining >= 0.5)
                                    {
                                        script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusFeat(Generation.SpellFocusLeft[primarySchool]), armor, 0.0f);
                                        effectivePlusRemaining -= 0.5;
                                        currentEffectivePlus += 0.5;
                                    }
                                    if (effectivePlusRemaining >= 0.5)
                                    {
                                        script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusFeat(Generation.SpellFocusRight[primarySchool]), armor, 0.0f);
                                        effectivePlusRemaining -= 0.5;
                                        currentEffectivePlus += 0.5;
                                    }
                                    break;
                                case EnhancementTypes.SpellPenetration:
                                    script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusFeat(IP_CONST_FEAT_SPELLPENETRATION), armor, 0.0f);
                                    script.SetFirstName(armor, String.Format("Mage's {0}", script.GetName(armor)));
                                    effectivePlusRemaining -= 1.5;
                                    currentEffectivePlus += 1.5;
                                    break;
                                case EnhancementTypes.SR12:
                                    script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSpellResistance(IP_CONST_SPELLRESISTANCEBONUS_12), armor, 0.0f);
                                    script.SetFirstName(armor, String.Format("Spellsoaking {0}", script.GetName(armor)));
                                    effectivePlusRemaining -= 2;
                                    currentEffectivePlus += 2;
                                    break;
                                case EnhancementTypes.SR14:
                                    script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSpellResistance(IP_CONST_SPELLRESISTANCEBONUS_14), armor, 0.0f);
                                    script.SetFirstName(armor, String.Format("Spellsoaking {0}", script.GetName(armor)));
                                    effectivePlusRemaining -= 3;
                                    currentEffectivePlus += 3;
                                    break;
                                case EnhancementTypes.SR16:
                                    script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSpellResistance(IP_CONST_SPELLRESISTANCEBONUS_16), armor, 0.0f);
                                    script.SetFirstName(armor, String.Format("Spellsoaking {0}", script.GetName(armor)));
                                    effectivePlusRemaining -= 4;
                                    currentEffectivePlus += 4;
                                    break;
                                case EnhancementTypes.SR18:
                                    script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSpellResistance(IP_CONST_SPELLRESISTANCEBONUS_18), armor, 0.0f);
                                    script.SetFirstName(armor, String.Format("Spellsoaking {0}", script.GetName(armor)));
                                    effectivePlusRemaining -= 5;
                                    currentEffectivePlus += 5;
                                    break;
                                case EnhancementTypes.Twilight:
                                    script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyArcaneSpellFailure(IP_CONST_ARCANE_SPELL_FAILURE_MINUS_10_PERCENT), armor, 0.0f);
                                    script.SetFirstName(armor, String.Format("Twilight {0}", script.GetName(armor)));
                                    effectivePlusRemaining -= 1;
                                    currentEffectivePlus += 1;
                                    break;
                            }
                        }
                        quirkAdded = true;
                    }
                }
                script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyACBonus(enhancementBonus), armor, 0.0f);
                script.SetFirstName(armor, String.Format("{0} +{1}", script.GetName(armor), enhancementBonus));
            }
            #endregion

            #region Armor Personality
            SetPersonalityProperties(script, armor, armorTheme, enhancementBonus, ref effectivePlusRemaining, ref currentEffectivePlus);
            armorValue += (int)(currentEffectivePlus * currentEffectivePlus * 1000);
            Pricing.CalculatePrice(script, armor);
            return armorValue;
            #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;
                }
            }
        }