public static int NewBelt(CLRScriptBase script, int maxValue)
 {
     List<int> selectableAbilities = new List<int>();
     foreach (KeyValuePair<int, int> prop in PrimaryAmuletAbility)
     {
         if (prop.Value <= maxValue)
         {
             selectableAbilities.Add(prop.Key);
         }
     }
     if (selectableAbilities.Count == 0)
     {
         return 0;
     }
     int selectedAbility = selectableAbilities[Generation.rand.Next(selectableAbilities.Count)];
     uint belt = script.CreateItemOnObject("zitem_belt", script.OBJECT_SELF, 1, "", FALSE);
     switch (selectedAbility)
     {
         #region Belt of Shielding
         case ITEM_PROPERTY_AC_BONUS:
             {
                 if (maxValue >= 50000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyACBonus(5), belt, 0.0f);
                     script.SetFirstName(belt, "Belt of Shielding +5");
                     Pricing.CalculatePrice(script, belt);
                     return 50000;
                 }
                 else if (maxValue >= 32000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyACBonus(4), belt, 0.0f);
                     script.SetFirstName(belt, "Belt of Shielding +4");
                     Pricing.CalculatePrice(script, belt);
                     return 32000;
                 }
                 else if (maxValue >= 18000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyACBonus(3), belt, 0.0f);
                     script.SetFirstName(belt, "Belt of Shielding +3");
                     Pricing.CalculatePrice(script, belt);
                     return 18000;
                 }
                 else if (maxValue >= 8000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyACBonus(2), belt, 0.0f);
                     script.SetFirstName(belt, "Belt of Shielding +2");
                     Pricing.CalculatePrice(script, belt);
                     return 8000;
                 }
                 else if (maxValue >= 2000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyACBonus(1), belt, 0.0f);
                     script.SetFirstName(belt, "Belt of Shielding +1");
                     Pricing.CalculatePrice(script, belt);
                     return 2000;
                 }
                 else
                 {
                     return 0;
                 }
             }
         #endregion
         #region Ability Bonus
         case ITEM_PROPERTY_ABILITY_BONUS:
             {
                 int ability = AbilityScores[Generation.rand.Next(AbilityScores.Count)];
                 if (maxValue >= 36000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyAbilityBonus(ability, 6), belt, 0.0f);
                     script.SetFirstName(belt, AbilityScoreNames[ability] + " +6");
                     Pricing.CalculatePrice(script, belt);
                     return 36000;
                 }
                 else if (maxValue >= 25000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyAbilityBonus(ability, 5), belt, 0.0f);
                     script.SetFirstName(belt, AbilityScoreNames[ability] + " +5");
                     Pricing.CalculatePrice(script, belt);
                     return 25000;
                 }
                 else if (maxValue >= 16000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyAbilityBonus(ability, 4), belt, 0.0f);
                     script.SetFirstName(belt, AbilityScoreNames[ability] + " +4");
                     Pricing.CalculatePrice(script, belt);
                     return 16000;
                 }
                 else if (maxValue >= 9000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyAbilityBonus(ability, 3), belt, 0.0f);
                     script.SetFirstName(belt, AbilityScoreNames[ability] + " +3");
                     Pricing.CalculatePrice(script, belt);
                     return 9000;
                 }
                 else if (maxValue >= 4000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyAbilityBonus(ability, 2), belt, 0.0f);
                     script.SetFirstName(belt, AbilityScoreNames[ability] + " +2");
                     Pricing.CalculatePrice(script, belt);
                     return 4000;
                 }
                 else if (maxValue >= 1000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyAbilityBonus(ability, 1), belt, 0.0f);
                     script.SetFirstName(belt, AbilityScoreNames[ability] + " +1");
                     Pricing.CalculatePrice(script, belt);
                     return 1000;
                 }
                 else
                 {
                     return 0;
                 }
             }
         #endregion
         #region Immunities
         case ITEM_PROPERTY_IMMUNITY_MISCELLANEOUS:
             {
                 List<int> possibleImmunities = new List<int>();
                 foreach (KeyValuePair<int, int> immunity in AvailableImmunities)
                 {
                     if (immunity.Value <= maxValue)
                     {
                         possibleImmunities.Add(immunity.Key);
                     }
                 }
                 if (possibleImmunities.Count == 0)
                 {
                     return 0;
                 }
                 int selectedImmunity = possibleImmunities[Generation.rand.Next(possibleImmunities.Count)];
                 script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyImmunityMisc(selectedImmunity), belt, 0.0f);
                 script.SetFirstName(belt, ImmunityNames[selectedImmunity]);
                 Pricing.CalculatePrice(script, belt);
                 return AvailableImmunities[selectedImmunity];
             }
         #endregion
         #region Skill Bonuses
         case ITEM_PROPERTY_SKILL_BONUS:
             {
                 int skillBonus = AvailableSkills[Generation.rand.Next(AvailableSkills.Count)];
                 script.SetFirstName(belt, SkillNames[skillBonus]);
                 if (maxValue >= 10000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertySkillBonus(skillBonus, 10), belt, 0.0f);
                     script.SetFirstName(belt, script.GetName(belt) + " +10");
                     Pricing.CalculatePrice(script, belt);
                     return 10000;
                 }
                 else if (maxValue >= 8100)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertySkillBonus(skillBonus, 9), belt, 0.0f);
                     script.SetFirstName(belt, script.GetName(belt) + " +9");
                     Pricing.CalculatePrice(script, belt);
                     return 8100;
                 }
                 else if (maxValue >= 6400)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertySkillBonus(skillBonus, 8), belt, 0.0f);
                     script.SetFirstName(belt, script.GetName(belt) + " +8");
                     Pricing.CalculatePrice(script, belt);
                     return 6400;
                 }
                 else if (maxValue >= 4900)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertySkillBonus(skillBonus, 7), belt, 0.0f);
                     script.SetFirstName(belt, script.GetName(belt) + " +7");
                     Pricing.CalculatePrice(script, belt);
                     return 4900;
                 }
                 else if (maxValue >= 3600)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertySkillBonus(skillBonus, 6), belt, 0.0f);
                     script.SetFirstName(belt, script.GetName(belt) + " +6");
                     Pricing.CalculatePrice(script, belt);
                     return 3600;
                 }
                 else if (maxValue >= 2500)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertySkillBonus(skillBonus, 5), belt, 0.0f);
                     script.SetFirstName(belt, script.GetName(belt) + " +5");
                     Pricing.CalculatePrice(script, belt);
                     return 2500;
                 }
                 else if (maxValue >= 1600)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertySkillBonus(skillBonus, 4), belt, 0.0f);
                     script.SetFirstName(belt, script.GetName(belt) + " +4");
                     Pricing.CalculatePrice(script, belt);
                     return 1600;
                 }
                 else if (maxValue >= 900)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertySkillBonus(skillBonus, 3), belt, 0.0f);
                     script.SetFirstName(belt, script.GetName(belt) + " +3");
                     Pricing.CalculatePrice(script, belt);
                     return 900;
                 }
                 else if (maxValue >= 400)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertySkillBonus(skillBonus, 2), belt, 0.0f);
                     script.SetFirstName(belt, script.GetName(belt) + " +2");
                     Pricing.CalculatePrice(script, belt);
                     return 400;
                 }
                 else if (maxValue >= 100)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertySkillBonus(skillBonus, 1), belt, 0.0f);
                     script.SetFirstName(belt, script.GetName(belt) + " +1");
                     Pricing.CalculatePrice(script, belt);
                     return 100;
                 }
                 break;
             }
         #endregion
     }
     script.DestroyObject(belt, 0.0f, FALSE);
     return 0;
 }
 public static int NewBoots(CLRScriptBase script, int maxValue)
 {
     List<int> potentialAbilities = new List<int>();
     foreach (KeyValuePair<int, int> ability in AvailableAbilities)
     {
         if (ability.Value <= maxValue)
         {
             potentialAbilities.Add(ability.Key);
         }
     }
     if (potentialAbilities.Count == 0)
     {
         return 0;
     }
     int selectedAbility = potentialAbilities[Generation.rand.Next(potentialAbilities.Count)];
     uint Boots = script.CreateItemOnObject("zitem_boot2", script.OBJECT_SELF, 1, "", FALSE);
     switch (selectedAbility)
     {
         #region Boots of Ability Boosts
         case ITEM_PROPERTY_ABILITY_BONUS:
             {
                 int abilityScore = AvailableAbilityScores[Generation.rand.Next(AvailableAbilityScores.Count)];
                 string name = AbilityScoreNames[abilityScore];
                 if (maxValue >= 36000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyAbilityBonus(abilityScore, 6), Boots, 0.0f);
                     script.SetFirstName(Boots, name + " +6");
                     Pricing.CalculatePrice(script, Boots);
                     return 36000;
                 }
                 else if (maxValue >= 25000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyAbilityBonus(abilityScore, 5), Boots, 0.0f);
                     script.SetFirstName(Boots, name + " +5");
                     Pricing.CalculatePrice(script, Boots);
                     return 25000;
                 }
                 else if (maxValue >= 16000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyAbilityBonus(abilityScore, 4), Boots, 0.0f);
                     script.SetFirstName(Boots, name + " +4");
                     Pricing.CalculatePrice(script, Boots);
                     return 16000;
                 }
                 else if (maxValue >= 9000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyAbilityBonus(abilityScore, 3), Boots, 0.0f);
                     script.SetFirstName(Boots, name + " +3");
                     Pricing.CalculatePrice(script, Boots);
                     return 9000;
                 }
                 else if (maxValue >= 4000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyAbilityBonus(abilityScore, 2), Boots, 0.0f);
                     script.SetFirstName(Boots, name + " +2");
                     Pricing.CalculatePrice(script, Boots);
                     return 4000;
                 }
                 else if (maxValue >= 1000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyAbilityBonus(abilityScore, 1), Boots, 0.0f);
                     script.SetFirstName(Boots, name + " +1");
                     Pricing.CalculatePrice(script, Boots);
                     return 1000;
                 }
                 else
                 {
                     return 0;
                 }
             }
         #endregion
         #region Freedom of Movement
         case ITEM_PROPERTY_FREEDOM_OF_MOVEMENT:
             {
                 script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyFreeAction(), Boots, 0.0f);
                 script.SetFirstName(Boots, "Boots of Freedom");
                 Pricing.CalculatePrice(script, Boots);
                 return 40000;
             }
         #endregion
         #region Immunities
         case ITEM_PROPERTY_IMMUNITY_MISCELLANEOUS:
             {
                 List<int> possibleImmunities = new List<int>();
                 foreach (KeyValuePair<int, int> immunity in AvailableImmunities)
                 {
                     if (immunity.Value <= maxValue)
                     {
                         possibleImmunities.Add(immunity.Key);
                     }
                 }
                 if (possibleImmunities.Count == 0)
                 {
                     return 0;
                 }
                 int selectedImmunity = possibleImmunities[Generation.rand.Next(possibleImmunities.Count)];
                 script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyImmunityMisc(selectedImmunity), Boots, 0.0f);
                 script.SetFirstName(Boots, ImmunityNames[selectedImmunity]);
                 Pricing.CalculatePrice(script, Boots);
                 return AvailableImmunities[selectedImmunity];
             }
         #endregion
         #region Skill Bonus
         case ITEM_PROPERTY_SKILL_BONUS:
             {
                 int skillBonus = AvailableSkills[Generation.rand.Next(AvailableSkills.Count)];
                 script.SetFirstName(Boots, SkillNames[skillBonus]);
                 if (maxValue >= 10000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertySkillBonus(skillBonus, 10), Boots, 0.0f);
                     script.SetFirstName(Boots, script.GetName(Boots) + " +10");
                     Pricing.CalculatePrice(script, Boots);
                     return 10000;
                 }
                 else if (maxValue >= 8100)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertySkillBonus(skillBonus, 9), Boots, 0.0f);
                     script.SetFirstName(Boots, script.GetName(Boots) + " +9");
                     Pricing.CalculatePrice(script, Boots);
                     return 8100;
                 }
                 else if (maxValue >= 6400)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertySkillBonus(skillBonus, 8), Boots, 0.0f);
                     script.SetFirstName(Boots, script.GetName(Boots) + " +8");
                     Pricing.CalculatePrice(script, Boots);
                     return 6400;
                 }
                 else if (maxValue >= 4900)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertySkillBonus(skillBonus, 7), Boots, 0.0f);
                     script.SetFirstName(Boots, script.GetName(Boots) + " +7");
                     Pricing.CalculatePrice(script, Boots);
                     return 4900;
                 }
                 else if (maxValue >= 3600)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertySkillBonus(skillBonus, 6), Boots, 0.0f);
                     script.SetFirstName(Boots, script.GetName(Boots) + " +6");
                     Pricing.CalculatePrice(script, Boots);
                     return 3600;
                 }
                 else if (maxValue >= 2500)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertySkillBonus(skillBonus, 5), Boots, 0.0f);
                     script.SetFirstName(Boots, script.GetName(Boots) + " +5");
                     Pricing.CalculatePrice(script, Boots);
                     return 2500;
                 }
                 else if (maxValue >= 1600)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertySkillBonus(skillBonus, 4), Boots, 0.0f);
                     script.SetFirstName(Boots, script.GetName(Boots) + " +4");
                     Pricing.CalculatePrice(script, Boots);
                     return 1600;
                 }
                 else if (maxValue >= 900)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertySkillBonus(skillBonus, 3), Boots, 0.0f);
                     script.SetFirstName(Boots, script.GetName(Boots) + " +3");
                     Pricing.CalculatePrice(script, Boots);
                     return 900;
                 }
                 else if (maxValue >= 400)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertySkillBonus(skillBonus, 2), Boots, 0.0f);
                     script.SetFirstName(Boots, script.GetName(Boots) + " +2");
                     Pricing.CalculatePrice(script, Boots);
                     return 400;
                 }
                 else if (maxValue >= 100)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertySkillBonus(skillBonus, 1), Boots, 0.0f);
                     script.SetFirstName(Boots, script.GetName(Boots) + " +1");
                     Pricing.CalculatePrice(script, Boots);
                     return 100;
                 }
                 else
                 {
                     return 0;
                 }
             }
         #endregion
     }
     script.DestroyObject(Boots, 0.0f, FALSE);
     return 0;
 }
 public static int NewRing(CLRScriptBase script, int maxValue)
 {
     List<int> potentialAbilities = new List<int>();
     foreach (KeyValuePair<int, int> ability in AvailableAbilities)
     {
         if (ability.Value <= maxValue)
         {
             potentialAbilities.Add(ability.Key);
         }
     }
     if (potentialAbilities.Count == 0)
     {
         return 0;
     }
     int selectedAbility = potentialAbilities[Generation.rand.Next(potentialAbilities.Count)];
     uint ring = script.CreateItemOnObject("nw_it_mring021", script.OBJECT_SELF, 1, "", FALSE);
     switch (selectedAbility)
     {
         #region Rings of Deflection
         case ITEM_PROPERTY_AC_BONUS:
             {
                 string name = AbilityNames[selectedAbility];
                 if (maxValue >= 50000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyACBonus(5), ring, 0.0f);
                     script.SetFirstName(ring, name + " +5");
                     Pricing.CalculatePrice(script, ring);
                     return 50000;
                 }
                 else if (maxValue >= 32000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyACBonus(4), ring, 0.0f);
                     script.SetFirstName(ring, name + " +4");
                     Pricing.CalculatePrice(script, ring);
                     return 32000;
                 }
                 else if (maxValue >= 18000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyACBonus(3), ring, 0.0f);
                     script.SetFirstName(ring, name + " +3");
                     Pricing.CalculatePrice(script, ring);
                     return 18000;
                 }
                 else if (maxValue >= 8000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyACBonus(2), ring, 0.0f);
                     script.SetFirstName(ring, name + " +2");
                     Pricing.CalculatePrice(script, ring);
                     return 8000;
                 }
                 else if (maxValue >= 2000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyACBonus(1), ring, 0.0f);
                     script.SetFirstName(ring, name + " +1");
                     Pricing.CalculatePrice(script, ring);
                     return 2000;
                 }
                 else
                 {
                     return 0;
                 }
             }
         #endregion
         #region Rings of Ability Scores
         case ITEM_PROPERTY_ABILITY_BONUS:
             {
                 int abilityScore = AvailableAbilityScores[Generation.rand.Next(AvailableAbilityScores.Count)];
                 string name = AbilityScoreNames[abilityScore];
                 if (maxValue >= 36000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyAbilityBonus(abilityScore, 6), ring, 0.0f);
                     script.SetFirstName(ring, name + " +6");
                     Pricing.CalculatePrice(script, ring);
                     return 36000;
                 }
                 else if (maxValue >= 25000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyAbilityBonus(abilityScore, 5), ring, 0.0f);
                     script.SetFirstName(ring, name + " +5");
                     Pricing.CalculatePrice(script, ring);
                     return 25000;
                 }
                 else if (maxValue >= 16000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyAbilityBonus(abilityScore, 4), ring, 0.0f);
                     script.SetFirstName(ring, name + " +4");
                     Pricing.CalculatePrice(script, ring);
                     return 16000;
                 }
                 else if (maxValue >= 9000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyAbilityBonus(abilityScore, 3), ring, 0.0f);
                     script.SetFirstName(ring, name + " +3");
                     Pricing.CalculatePrice(script, ring);
                     return 9000;
                 }
                 else if (maxValue >= 4000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyAbilityBonus(abilityScore, 2), ring, 0.0f);
                     script.SetFirstName(ring, name + " +2");
                     Pricing.CalculatePrice(script, ring);
                     return 4000;
                 }
                 else if (maxValue >= 1000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyAbilityBonus(abilityScore, 1), ring, 0.0f);
                     script.SetFirstName(ring, name + " +1");
                     Pricing.CalculatePrice(script, ring);
                     return 1000;
                 }
                 else
                 {
                     return 0;
                 }
             }
         #endregion
         #region Rings with Bonus Feats
         case ITEM_PROPERTY_BONUS_FEAT:
             {
                 List<int> possibleFeats = new List<int>();
                 foreach (KeyValuePair<int, int> feat in AvailableFeats)
                 {
                     if (feat.Value <= maxValue)
                     {
                         possibleFeats.Add(feat.Key);
                     }
                 }
                 if (possibleFeats.Count == 0)
                 {
                     return 0;
                 }
                 int selectedFeat = possibleFeats[Generation.rand.Next(possibleFeats.Count)];
                 script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusFeat(selectedFeat), ring, 0.0f);
                 script.SetFirstName(ring, FeatNames[selectedFeat]);
                 Pricing.CalculatePrice(script, ring);
                 return AvailableFeats[selectedFeat];
             }
         #endregion
         #region Bonus Spell Slots
         case ITEM_PROPERTY_BONUS_SPELL_SLOT_OF_LEVEL_N:
             {
                 int bonusType = AvailableBonusSpells[Generation.rand.Next(AvailableBonusSpells.Count)];
                 string name = BonusSpellNames[bonusType];
                 if (maxValue >= 81000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusLevelSpell(bonusType, IP_CONST_SPELLLEVEL_9), ring, 0.0f);
                     script.SetFirstName(ring, name + " IX");
                     Pricing.CalculatePrice(script, ring);
                     return 81000;
                 }
                 else if (maxValue >= 64000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusLevelSpell(bonusType, IP_CONST_SPELLLEVEL_8), ring, 0.0f);
                     script.SetFirstName(ring, name + " VIII");
                     Pricing.CalculatePrice(script, ring);
                     return 64000;
                 }
                 else if (maxValue >= 49000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusLevelSpell(bonusType, IP_CONST_SPELLLEVEL_7), ring, 0.0f);
                     script.SetFirstName(ring, name + " VII");
                     Pricing.CalculatePrice(script, ring);
                     return 49000;
                 }
                 else if (maxValue >= 36000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusLevelSpell(bonusType, IP_CONST_SPELLLEVEL_6), ring, 0.0f);
                     script.SetFirstName(ring, name + " VI");
                     Pricing.CalculatePrice(script, ring);
                     return 36000;
                 }
                 else if (maxValue >= 25000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusLevelSpell(bonusType, IP_CONST_SPELLLEVEL_5), ring, 0.0f);
                     script.SetFirstName(ring, name + " V");
                     Pricing.CalculatePrice(script, ring);
                     return 25000;
                 }
                 else if (maxValue >= 16000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusLevelSpell(bonusType, IP_CONST_SPELLLEVEL_4), ring, 0.0f);
                     script.SetFirstName(ring, name + " IV");
                     Pricing.CalculatePrice(script, ring);
                     return 16000;
                 }
                 else if (maxValue >= 9000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusLevelSpell(bonusType, IP_CONST_SPELLLEVEL_3), ring, 0.0f);
                     script.SetFirstName(ring, name + " III");
                     Pricing.CalculatePrice(script, ring);
                     return 9000;
                 }
                 else if (maxValue >= 4000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusLevelSpell(bonusType, IP_CONST_SPELLLEVEL_2), ring, 0.0f);
                     script.SetFirstName(ring, name + " II");
                     Pricing.CalculatePrice(script, ring);
                     return 4000;
                 }
                 else if (maxValue >= 1000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusLevelSpell(bonusType, IP_CONST_SPELLLEVEL_1), ring, 0.0f);
                     script.SetFirstName(ring, name + " I");
                     Pricing.CalculatePrice(script, ring);
                     return 1000;
                 }
                 else if (maxValue >= 500)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusLevelSpell(bonusType, IP_CONST_SPELLLEVEL_0), ring, 0.0f);
                     script.SetFirstName(ring, name + " 0");
                     Pricing.CalculatePrice(script, ring);
                     return 500;
                 }
                 else
                 {
                     return 0;
                 }
             }
         #endregion
         #region Damage Resistance
         case ITEM_PROPERTY_DAMAGE_RESISTANCE:
             {
                 int damageResistType = DamageResistances[Generation.rand.Next(DamageResistances.Count)];
                 if (damageResistType == IP_CONST_DAMAGETYPE_NEGATIVE &&
                     maxValue < 6000)
                 {
                     int attempts = 0;
                     while (damageResistType == IP_CONST_DAMAGETYPE_NEGATIVE)
                     {
                         damageResistType = DamageResistances[Generation.rand.Next(DamageResistances.Count)];
                         attempts++;
                         if (attempts == 10)
                         {
                             // something is wrong. Break out and just go with fire or something.
                             damageResistType = IP_CONST_DAMAGETYPE_FIRE;
                             break;
                         }
                     }
                 }
                 if (damageResistType == IP_CONST_DAMAGETYPE_NEGATIVE)
                 {
                     if (maxValue >= 66000)
                     {
                         script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyDamageResistance(damageResistType, IP_CONST_DAMAGERESIST_30), ring, 0.0f);
                         script.SetFirstName(ring, DamageResistanceNames[damageResistType] + ", 30");
                         Pricing.CalculatePrice(script, ring);
                         return 66000;
                     }
                     else if (maxValue >= 54000)
                     {
                         script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyDamageResistance(damageResistType, IP_CONST_DAMAGERESIST_25), ring, 0.0f);
                         script.SetFirstName(ring, DamageResistanceNames[damageResistType] + ", 25");
                         Pricing.CalculatePrice(script, ring);
                         return 54000;
                     }
                     else if (maxValue >= 42000)
                     {
                         script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyDamageResistance(damageResistType, IP_CONST_DAMAGERESIST_20), ring, 0.0f);
                         script.SetFirstName(ring, DamageResistanceNames[damageResistType] + ", 20");
                         Pricing.CalculatePrice(script, ring);
                         return 42000;
                     }
                     else if (maxValue >= 30000)
                     {
                         script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyDamageResistance(damageResistType, IP_CONST_DAMAGERESIST_15), ring, 0.0f);
                         script.SetFirstName(ring, DamageResistanceNames[damageResistType] + ", 15");
                         Pricing.CalculatePrice(script, ring);
                         return 30000;
                     }
                     else if (maxValue >= 18000)
                     {
                         script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyDamageResistance(damageResistType, IP_CONST_DAMAGERESIST_10), ring, 0.0f);
                         script.SetFirstName(ring, DamageResistanceNames[damageResistType] + ", 10");
                         Pricing.CalculatePrice(script, ring);
                         return 18000;
                     }
                     else if (maxValue >= 6000)
                     {
                         script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyDamageResistance(damageResistType, IP_CONST_DAMAGERESIST_5), ring, 0.0f);
                         script.SetFirstName(ring, DamageResistanceNames[damageResistType] + ", 5");
                         Pricing.CalculatePrice(script, ring);
                         return 6000;
                     }
                 }
                 else
                 {
                     if (maxValue >= 44000)
                     {
                         script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyDamageResistance(damageResistType, IP_CONST_DAMAGERESIST_30), ring, 0.0f);
                         script.SetFirstName(ring, DamageResistanceNames[damageResistType] + ", 30");
                         Pricing.CalculatePrice(script, ring);
                         return 44000;
                     }
                     else if (maxValue >= 36000)
                     {
                         script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyDamageResistance(damageResistType, IP_CONST_DAMAGERESIST_25), ring, 0.0f);
                         script.SetFirstName(ring, DamageResistanceNames[damageResistType] + ", 25");
                         Pricing.CalculatePrice(script, ring);
                         return 36000;
                     }
                     else if (maxValue >= 28000)
                     {
                         script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyDamageResistance(damageResistType, IP_CONST_DAMAGERESIST_20), ring, 0.0f);
                         script.SetFirstName(ring, DamageResistanceNames[damageResistType] + ", 20");
                         Pricing.CalculatePrice(script, ring);
                         return 28000;
                     }
                     else if (maxValue >= 20000)
                     {
                         script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyDamageResistance(damageResistType, IP_CONST_DAMAGERESIST_15), ring, 0.0f);
                         script.SetFirstName(ring, DamageResistanceNames[damageResistType] + ", 15");
                         Pricing.CalculatePrice(script, ring);
                         return 20000;
                     }
                     else if (maxValue >= 12000)
                     {
                         script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyDamageResistance(damageResistType, IP_CONST_DAMAGERESIST_10), ring, 0.0f);
                         script.SetFirstName(ring, DamageResistanceNames[damageResistType] + ", 10");
                         Pricing.CalculatePrice(script, ring);
                         return 12000;
                     }
                     else if (maxValue >= 4000)
                     {
                         script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyDamageResistance(damageResistType, IP_CONST_DAMAGERESIST_5), ring, 0.0f);
                         script.SetFirstName(ring, DamageResistanceNames[damageResistType] + ", 5");
                         Pricing.CalculatePrice(script, ring);
                         return 4000;
                     }
                 }
                 break;
             }
         #endregion
         #region Freedom of Movement
         case ITEM_PROPERTY_FREEDOM_OF_MOVEMENT:
             {
                 script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyFreeAction(), ring, 0.0f);
                 script.SetFirstName(ring, "Ring of Freedom");
                 Pricing.CalculatePrice(script, ring);
                 return 40000;
             }
         #endregion
         #region Immunities
         case ITEM_PROPERTY_IMMUNITY_MISCELLANEOUS:
             {
                 List<int> possibleImmunities = new List<int>();
                 foreach (KeyValuePair<int, int> immunity in AvailableImmunities)
                 {
                     if (immunity.Value <= maxValue)
                     {
                         possibleImmunities.Add(immunity.Key);
                     }
                 }
                 if (possibleImmunities.Count == 0)
                 {
                     return 0;
                 }
                 int selectedImmunity = possibleImmunities[Generation.rand.Next(possibleImmunities.Count)];
                 script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyImmunityMisc(selectedImmunity), ring, 0.0f);
                 script.SetFirstName(ring, ImmunityNames[selectedImmunity]);
                 Pricing.CalculatePrice(script, ring);
                 return AvailableImmunities[selectedImmunity];
             }
         #endregion
         #region Light
         case ITEM_PROPERTY_LIGHT:
             {
                 int lightColor = LightColors[Generation.rand.Next(LightColors.Count)]; ;
                 script.SetFirstName(ring, AbilityNames[selectedAbility]);
                 if (maxValue >= 400)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyLight(IP_CONST_LIGHTBRIGHTNESS_BRIGHT, lightColor), ring, 0.0f);
                     Pricing.CalculatePrice(script, ring);
                     return 400;
                 }
                 else if (maxValue >= 300)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyLight(IP_CONST_LIGHTBRIGHTNESS_NORMAL, lightColor), ring, 0.0f);
                     Pricing.CalculatePrice(script, ring);
                     return 300;
                 }
                 else if (maxValue >= 200)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyLight(IP_CONST_LIGHTBRIGHTNESS_LOW, lightColor), ring, 0.0f);
                     Pricing.CalculatePrice(script, ring);
                     return 200;
                 }
                 else if (maxValue >= 100)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyLight(IP_CONST_LIGHTBRIGHTNESS_DIM, lightColor), ring, 0.0f);
                     Pricing.CalculatePrice(script, ring);
                     return 100;
                 }
                 else
                 {
                     return 0;
                 }
             }
         #endregion
         #region Saving Throws
         case ITEM_PROPERTY_SAVING_THROW_BONUS:
             {
                 if (maxValue >= 25000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSavingThrowVsX(IP_CONST_SAVEVS_UNIVERSAL, 5), ring, 0.0f);
                     script.SetFirstName(ring, "Ring of Resistance +5");
                     Pricing.CalculatePrice(script, ring);
                     return 25000;
                 }
                 else if (maxValue >= 16000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSavingThrowVsX(IP_CONST_SAVEVS_UNIVERSAL, 4), ring, 0.0f);
                     script.SetFirstName(ring, "Ring of Resistance +4");
                     Pricing.CalculatePrice(script, ring);
                     return 16000;
                 }
                 else if (maxValue >= 9000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSavingThrowVsX(IP_CONST_SAVEVS_UNIVERSAL, 3), ring, 0.0f);
                     script.SetFirstName(ring, "Ring of Resistance +3");
                     Pricing.CalculatePrice(script, ring);
                     return 9000;
                 }
                 else if (maxValue >= 4000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSavingThrowVsX(IP_CONST_SAVEVS_UNIVERSAL, 2), ring, 0.0f);
                     script.SetFirstName(ring, "Ring of Resistance +2");
                     Pricing.CalculatePrice(script, ring);
                     return 4000;
                 }
                 else if (maxValue >= 1000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSavingThrowVsX(IP_CONST_SAVEVS_UNIVERSAL, 1), ring, 0.0f);
                     script.SetFirstName(ring, "Ring of Resistance +1");
                     Pricing.CalculatePrice(script, ring);
                     return 1000;
                 }
                 else
                 {
                     return 0;
                 }
             }
         #endregion
         #region Saving Throws vs. Specific
         case ITEM_PROPERTY_SAVING_THROW_BONUS_SPECIFIC:
             {
                 int saveType = AvailableSaveTypes[Generation.rand.Next(AvailableSaveTypes.Count)];
                 script.SetFirstName(ring, SaveTypeNames[saveType]);
                 if (maxValue >= 6250)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSavingThrowVsX(saveType, 5), ring, 0.0f);
                     script.SetFirstName(ring, String.Format("{0} +5", script.GetName(ring)));
                     Pricing.CalculatePrice(script, ring);
                     return 6250;
                 }
                 else if (maxValue >= 4000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSavingThrowVsX(saveType, 4), ring, 0.0f);
                     script.SetFirstName(ring, String.Format("{0} +4", script.GetName(ring)));
                     Pricing.CalculatePrice(script, ring);
                     return 4000;
                 }
                 else if (maxValue >= 2250)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSavingThrowVsX(saveType, 3), ring, 0.0f);
                     script.SetFirstName(ring, String.Format("{0} +3", script.GetName(ring)));
                     Pricing.CalculatePrice(script, ring);
                     return 2250;
                 }
                 else if (maxValue >= 1000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSavingThrowVsX(saveType, 2), ring, 0.0f);
                     script.SetFirstName(ring, String.Format("{0} +2", script.GetName(ring)));
                     Pricing.CalculatePrice(script, ring);
                     return 1000;
                 }
                 else if (maxValue >= 250)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSavingThrowVsX(saveType, 1), ring, 0.0f);
                     script.SetFirstName(ring, String.Format("{0} +1", script.GetName(ring)));
                     Pricing.CalculatePrice(script, ring);
                     return 250;
                 }
                 break;
             }
         #endregion
         #region Skill Bonus
         case ITEM_PROPERTY_SKILL_BONUS:
             {
                 int skillBonus = AvailableSkills[Generation.rand.Next(AvailableSkills.Count)];
                 script.SetFirstName(ring, SkillNames[skillBonus]);
                 if (maxValue >= 10000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertySkillBonus(skillBonus, 10), ring, 0.0f);
                     script.SetFirstName(ring, script.GetName(ring) + " +10");
                     Pricing.CalculatePrice(script, ring);
                     return 10000;
                 }
                 else if (maxValue >= 8100)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertySkillBonus(skillBonus, 9), ring, 0.0f);
                     script.SetFirstName(ring, script.GetName(ring) + " +9");
                     Pricing.CalculatePrice(script, ring);
                     return 8100;
                 }
                 else if (maxValue >= 6400)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertySkillBonus(skillBonus, 8), ring, 0.0f);
                     script.SetFirstName(ring, script.GetName(ring) + " +8");
                     Pricing.CalculatePrice(script, ring);
                     return 6400;
                 }
                 else if (maxValue >= 4900)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertySkillBonus(skillBonus, 7), ring, 0.0f);
                     script.SetFirstName(ring, script.GetName(ring) + " +7");
                     Pricing.CalculatePrice(script, ring);
                     return 4900;
                 }
                 else if (maxValue >= 3600)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertySkillBonus(skillBonus, 6), ring, 0.0f);
                     script.SetFirstName(ring, script.GetName(ring) + " +6");
                     Pricing.CalculatePrice(script, ring);
                     return 3600;
                 }
                 else if (maxValue >= 2500)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertySkillBonus(skillBonus, 5), ring, 0.0f);
                     script.SetFirstName(ring, script.GetName(ring) + " +5");
                     Pricing.CalculatePrice(script, ring);
                     return 2500;
                 }
                 else if (maxValue >= 1600)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertySkillBonus(skillBonus, 4), ring, 0.0f);
                     script.SetFirstName(ring, script.GetName(ring) + " +4");
                     Pricing.CalculatePrice(script, ring);
                     return 1600;
                 }
                 else if (maxValue >= 900)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertySkillBonus(skillBonus, 3), ring, 0.0f);
                     script.SetFirstName(ring, script.GetName(ring) + " +3");
                     Pricing.CalculatePrice(script, ring);
                     return 900;
                 }
                 else if (maxValue >= 400)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertySkillBonus(skillBonus, 2), ring, 0.0f);
                     script.SetFirstName(ring, script.GetName(ring) + " +2");
                     Pricing.CalculatePrice(script, ring);
                     return 400;
                 }
                 else if (maxValue >= 100)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertySkillBonus(skillBonus, 1), ring, 0.0f);
                     script.SetFirstName(ring, script.GetName(ring) + " +1");
                     Pricing.CalculatePrice(script, ring);
                     return 100;
                 }
                 else
                 {
                     return 0;
                 }
             }
         #endregion
         #region Spell Resistance
         case ITEM_PROPERTY_SPELL_RESISTANCE:
             {
                 if (maxValue >= 140000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSpellResistance(IP_CONST_SPELLRESISTANCEBONUS_26), ring, 0.0f);
                     script.SetFirstName(ring, "Ring of Spell Resistance, 26");
                     Pricing.CalculatePrice(script, ring);
                     return 140000;
                 }
                 else if (maxValue >= 120000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSpellResistance(IP_CONST_SPELLRESISTANCEBONUS_24), ring, 0.0f);
                     script.SetFirstName(ring, "Ring of Spell Resistance, 24");
                     Pricing.CalculatePrice(script, ring);
                     return 120000;
                 }
                 else if (maxValue >= 100000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSpellResistance(IP_CONST_SPELLRESISTANCEBONUS_22), ring, 0.0f);
                     script.SetFirstName(ring, "Ring of Spell Resistance, 22");
                     Pricing.CalculatePrice(script, ring);
                     return 100000;
                 }
                 else if (maxValue >= 80000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSpellResistance(IP_CONST_SPELLRESISTANCEBONUS_20), ring, 0.0f);
                     script.SetFirstName(ring, "Ring of Spell Resistance, 20");
                     Pricing.CalculatePrice(script, ring);
                     return 80000;
                 }
                 else if (maxValue >= 60000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSpellResistance(IP_CONST_SPELLRESISTANCEBONUS_18), ring, 0.0f);
                     script.SetFirstName(ring, "Ring of Spell Resistance, 18");
                     Pricing.CalculatePrice(script, ring);
                     return 60000;
                 }
                 else if (maxValue >= 40000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSpellResistance(IP_CONST_SPELLRESISTANCEBONUS_16), ring, 0.0f);
                     script.SetFirstName(ring, "Ring of Spell Resistance, 16");
                     Pricing.CalculatePrice(script, ring);
                     return 40000;
                 }
                 else if (maxValue >= 20000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSpellResistance(IP_CONST_SPELLRESISTANCEBONUS_14), ring, 0.0f);
                     script.SetFirstName(ring, "Ring of Spell Resistance, 14");
                     Pricing.CalculatePrice(script, ring);
                     return 20000;
                 }
                 else if (maxValue >= 10000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSpellResistance(IP_CONST_SPELLRESISTANCEBONUS_12), ring, 0.0f);
                     script.SetFirstName(ring, "Ring of Spell Resistance, 12");
                     Pricing.CalculatePrice(script, ring);
                     return 10000;
                 }
                 else if (maxValue >= 6000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSpellResistance(IP_CONST_SPELLRESISTANCEBONUS_10), ring, 0.0f);
                     script.SetFirstName(ring, "Ring of Spell Resistance, 10");
                     Pricing.CalculatePrice(script, ring);
                     return 6000;
                 }
                 else
                 {
                     return 0;
                 }
             }
         #endregion
     }
     script.DestroyObject(ring, 0.0f, FALSE);
     return 0;
 }
 public static int NewHelmet(CLRScriptBase script, int maxValue)
 {
     List<int> potentialAbilities = new List<int>();
     foreach (KeyValuePair<int, int> ability in AvailableAbilities)
     {
         if (ability.Value <= maxValue)
         {
             potentialAbilities.Add(ability.Key);
         }
     }
     if (potentialAbilities.Count == 0)
     {
         return 0;
     }
     int selectedAbility = potentialAbilities[Generation.rand.Next(potentialAbilities.Count)];
     uint helmet = script.CreateItemOnObject("zitem_helm2", script.OBJECT_SELF, 1, "", FALSE);
     switch (selectedAbility)
     {
         #region Helmets of Ability Scores
         case ITEM_PROPERTY_ABILITY_BONUS:
             {
                 int abilityScore = AvailableAbilityScores[Generation.rand.Next(AvailableAbilityScores.Count)];
                 string name = AbilityScoreNames[abilityScore];
                 if (maxValue >= 36000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyAbilityBonus(abilityScore, 6), helmet, 0.0f);
                     script.SetFirstName(helmet, name + " +6");
                     Pricing.CalculatePrice(script, helmet);
                     return 36000;
                 }
                 else if (maxValue >= 25000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyAbilityBonus(abilityScore, 5), helmet, 0.0f);
                     script.SetFirstName(helmet, name + " +5");
                     Pricing.CalculatePrice(script, helmet);
                     return 25000;
                 }
                 else if (maxValue >= 16000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyAbilityBonus(abilityScore, 4), helmet, 0.0f);
                     script.SetFirstName(helmet, name + " +4");
                     Pricing.CalculatePrice(script, helmet);
                     return 16000;
                 }
                 else if (maxValue >= 9000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyAbilityBonus(abilityScore, 3), helmet, 0.0f);
                     script.SetFirstName(helmet, name + " +3");
                     Pricing.CalculatePrice(script, helmet);
                     return 9000;
                 }
                 else if (maxValue >= 4000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyAbilityBonus(abilityScore, 2), helmet, 0.0f);
                     script.SetFirstName(helmet, name + " +2");
                     Pricing.CalculatePrice(script, helmet);
                     return 4000;
                 }
                 else if (maxValue >= 1000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyAbilityBonus(abilityScore, 1), helmet, 0.0f);
                     script.SetFirstName(helmet, name + " +1");
                     Pricing.CalculatePrice(script, helmet);
                     return 1000;
                 }
                 else
                 {
                     return 0;
                 }
             }
         #endregion
         #region Helmets with Bonus Feats
         case ITEM_PROPERTY_BONUS_FEAT:
             {
                 List<int> possibleFeats = new List<int>();
                 foreach (KeyValuePair<int, int> feat in AvailableFeats)
                 {
                     if (feat.Value <= maxValue)
                     {
                         possibleFeats.Add(feat.Key);
                     }
                 }
                 if (possibleFeats.Count == 0)
                 {
                     return 0;
                 }
                 int selectedFeat = possibleFeats[Generation.rand.Next(possibleFeats.Count)];
                 script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusFeat(selectedFeat), helmet, 0.0f);
                 script.SetFirstName(helmet, FeatNames[selectedFeat]);
                 Pricing.CalculatePrice(script, helmet);
                 return AvailableFeats[selectedFeat];
             }
         #endregion
         #region Bonus Spell Slots
         case ITEM_PROPERTY_BONUS_SPELL_SLOT_OF_LEVEL_N:
             {
                 int bonusType = AvailableBonusSpells[Generation.rand.Next(AvailableBonusSpells.Count)];
                 string name = BonusSpellNames[bonusType];
                 if (maxValue >= 81000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusLevelSpell(bonusType, IP_CONST_SPELLLEVEL_9), helmet, 0.0f);
                     script.SetFirstName(helmet, name + " IX");
                     Pricing.CalculatePrice(script, helmet);
                     return 81000;
                 }
                 else if (maxValue >= 64000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusLevelSpell(bonusType, IP_CONST_SPELLLEVEL_8), helmet, 0.0f);
                     script.SetFirstName(helmet, name + " VIII");
                     Pricing.CalculatePrice(script, helmet);
                     return 64000;
                 }
                 else if (maxValue >= 49000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusLevelSpell(bonusType, IP_CONST_SPELLLEVEL_7), helmet, 0.0f);
                     script.SetFirstName(helmet, name + " VII");
                     Pricing.CalculatePrice(script, helmet);
                     return 49000;
                 }
                 else if (maxValue >= 36000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusLevelSpell(bonusType, IP_CONST_SPELLLEVEL_6), helmet, 0.0f);
                     script.SetFirstName(helmet, name + " VI");
                     Pricing.CalculatePrice(script, helmet);
                     return 36000;
                 }
                 else if (maxValue >= 25000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusLevelSpell(bonusType, IP_CONST_SPELLLEVEL_5), helmet, 0.0f);
                     script.SetFirstName(helmet, name + " V");
                     Pricing.CalculatePrice(script, helmet);
                     return 25000;
                 }
                 else if (maxValue >= 16000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusLevelSpell(bonusType, IP_CONST_SPELLLEVEL_4), helmet, 0.0f);
                     script.SetFirstName(helmet, name + " IV");
                     Pricing.CalculatePrice(script, helmet);
                     return 16000;
                 }
                 else if (maxValue >= 9000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusLevelSpell(bonusType, IP_CONST_SPELLLEVEL_3), helmet, 0.0f);
                     script.SetFirstName(helmet, name + " III");
                     Pricing.CalculatePrice(script, helmet);
                     return 9000;
                 }
                 else if (maxValue >= 4000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusLevelSpell(bonusType, IP_CONST_SPELLLEVEL_2), helmet, 0.0f);
                     script.SetFirstName(helmet, name + " II");
                     Pricing.CalculatePrice(script, helmet);
                     return 4000;
                 }
                 else if (maxValue >= 1000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusLevelSpell(bonusType, IP_CONST_SPELLLEVEL_1), helmet, 0.0f);
                     script.SetFirstName(helmet, name + " I");
                     Pricing.CalculatePrice(script, helmet);
                     return 1000;
                 }
                 else if (maxValue >= 500)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusLevelSpell(bonusType, IP_CONST_SPELLLEVEL_0), helmet, 0.0f);
                     script.SetFirstName(helmet, name + " 0");
                     Pricing.CalculatePrice(script, helmet);
                     return 500;
                 }
                 else
                 {
                     return 0;
                 }
             }
         #endregion
         #region Immunities
         case ITEM_PROPERTY_IMMUNITY_MISCELLANEOUS:
             {
                 List<int> possibleImmunities = new List<int>();
                 foreach (KeyValuePair<int, int> immunity in AvailableImmunities)
                 {
                     if (immunity.Value <= maxValue)
                     {
                         possibleImmunities.Add(immunity.Key);
                     }
                 }
                 if (possibleImmunities.Count == 0)
                 {
                     return 0;
                 }
                 int selectedImmunity = possibleImmunities[Generation.rand.Next(possibleImmunities.Count)];
                 script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyImmunityMisc(selectedImmunity), helmet, 0.0f);
                 script.SetFirstName(helmet, ImmunityNames[selectedImmunity]);
                 Pricing.CalculatePrice(script, helmet);
                 return AvailableImmunities[selectedImmunity];
             }
         #endregion
         #region Saving Throws vs. Specific
         case ITEM_PROPERTY_SAVING_THROW_BONUS_SPECIFIC:
             {
                 int saveType = AvailableSaveTypes[Generation.rand.Next(AvailableSaveTypes.Count)];
                 script.SetFirstName(helmet, SaveTypeNames[saveType]);
                 if (maxValue >= 6250)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSavingThrowVsX(saveType, 5), helmet, 0.0f);
                     script.SetFirstName(helmet, String.Format("{0} +5", script.GetName(helmet)));
                     Pricing.CalculatePrice(script, helmet);
                     return 6250;
                 }
                 else if (maxValue >= 4000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSavingThrowVsX(saveType, 4), helmet, 0.0f);
                     script.SetFirstName(helmet, String.Format("{0} +4", script.GetName(helmet)));
                     Pricing.CalculatePrice(script, helmet);
                     return 4000;
                 }
                 else if (maxValue >= 2250)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSavingThrowVsX(saveType, 3), helmet, 0.0f);
                     script.SetFirstName(helmet, String.Format("{0} +3", script.GetName(helmet)));
                     Pricing.CalculatePrice(script, helmet);
                     return 2250;
                 }
                 else if (maxValue >= 1000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSavingThrowVsX(saveType, 2), helmet, 0.0f);
                     script.SetFirstName(helmet, String.Format("{0} +2", script.GetName(helmet)));
                     Pricing.CalculatePrice(script, helmet);
                     return 1000;
                 }
                 else if (maxValue >= 250)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSavingThrowVsX(saveType, 1), helmet, 0.0f);
                     script.SetFirstName(helmet, String.Format("{0} +1", script.GetName(helmet)));
                     Pricing.CalculatePrice(script, helmet);
                     return 250;
                 }
                 break;
             }
         #endregion
         #region Skill Bonus
         case ITEM_PROPERTY_SKILL_BONUS:
             {
                 int skillBonus = AvailableSkills[Generation.rand.Next(AvailableSkills.Count)];
                 script.SetFirstName(helmet, SkillNames[skillBonus]);
                 if (maxValue >= 10000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertySkillBonus(skillBonus, 10), helmet, 0.0f);
                     script.SetFirstName(helmet, script.GetName(helmet) + " +10");
                     Pricing.CalculatePrice(script, helmet);
                     return 10000;
                 }
                 else if (maxValue >= 8100)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertySkillBonus(skillBonus, 9), helmet, 0.0f);
                     script.SetFirstName(helmet, script.GetName(helmet) + " +9");
                     Pricing.CalculatePrice(script, helmet);
                     return 8100;
                 }
                 else if (maxValue >= 6400)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertySkillBonus(skillBonus, 8), helmet, 0.0f);
                     script.SetFirstName(helmet, script.GetName(helmet) + " +8");
                     Pricing.CalculatePrice(script, helmet);
                     return 6400;
                 }
                 else if (maxValue >= 4900)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertySkillBonus(skillBonus, 7), helmet, 0.0f);
                     script.SetFirstName(helmet, script.GetName(helmet) + " +7");
                     Pricing.CalculatePrice(script, helmet);
                     return 4900;
                 }
                 else if (maxValue >= 3600)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertySkillBonus(skillBonus, 6), helmet, 0.0f);
                     script.SetFirstName(helmet, script.GetName(helmet) + " +6");
                     Pricing.CalculatePrice(script, helmet);
                     return 3600;
                 }
                 else if (maxValue >= 2500)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertySkillBonus(skillBonus, 5), helmet, 0.0f);
                     script.SetFirstName(helmet, script.GetName(helmet) + " +5");
                     Pricing.CalculatePrice(script, helmet);
                     return 2500;
                 }
                 else if (maxValue >= 1600)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertySkillBonus(skillBonus, 4), helmet, 0.0f);
                     script.SetFirstName(helmet, script.GetName(helmet) + " +4");
                     Pricing.CalculatePrice(script, helmet);
                     return 1600;
                 }
                 else if (maxValue >= 900)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertySkillBonus(skillBonus, 3), helmet, 0.0f);
                     script.SetFirstName(helmet, script.GetName(helmet) + " +3");
                     Pricing.CalculatePrice(script, helmet);
                     return 900;
                 }
                 else if (maxValue >= 400)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertySkillBonus(skillBonus, 2), helmet, 0.0f);
                     script.SetFirstName(helmet, script.GetName(helmet) + " +2");
                     Pricing.CalculatePrice(script, helmet);
                     return 400;
                 }
                 else if (maxValue >= 100)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertySkillBonus(skillBonus, 1), helmet, 0.0f);
                     script.SetFirstName(helmet, script.GetName(helmet) + " +1");
                     Pricing.CalculatePrice(script, helmet);
                     return 100;
                 }
                 else
                 {
                     return 0;
                 }
             }
         #endregion
     }
     script.DestroyObject(helmet, 0.0f, FALSE);
     return 0;
 }
 public static int NewCloak(CLRScriptBase script, int maxValue)
 {
     List<int> potentialAbilities = new List<int>();
     foreach (KeyValuePair<int, int> ability in AvailableAbilities)
     {
         if (ability.Value <= maxValue)
         {
             potentialAbilities.Add(ability.Key);
         }
     }
     if (potentialAbilities.Count == 0)
     {
         return 0;
     }
     int selectedAbility = potentialAbilities[Generation.rand.Next(potentialAbilities.Count)];
     uint cloak = script.CreateItemOnObject("zitem_cloak", script.OBJECT_SELF, 1, "", FALSE);
     switch (selectedAbility)
     {
         #region Cloaks of Deflection
         case ITEM_PROPERTY_AC_BONUS:
             {
                 string name = AbilityNames[selectedAbility];
                 if (maxValue >= 50000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyACBonus(5), cloak, 0.0f);
                     script.SetFirstName(cloak, name + " +5");
                     Pricing.CalculatePrice(script, cloak);
                     return 50000;
                 }
                 else if (maxValue >= 32000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyACBonus(4), cloak, 0.0f);
                     script.SetFirstName(cloak, name + " +4");
                     Pricing.CalculatePrice(script, cloak);
                     return 32000;
                 }
                 else if (maxValue >= 18000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyACBonus(3), cloak, 0.0f);
                     script.SetFirstName(cloak, name + " +3");
                     Pricing.CalculatePrice(script, cloak);
                     return 18000;
                 }
                 else if (maxValue >= 8000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyACBonus(2), cloak, 0.0f);
                     script.SetFirstName(cloak, name + " +2");
                     Pricing.CalculatePrice(script, cloak);
                     return 8000;
                 }
                 else if (maxValue >= 2000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyACBonus(1), cloak, 0.0f);
                     script.SetFirstName(cloak, name + " +1");
                     Pricing.CalculatePrice(script, cloak);
                     return 2000;
                 }
                 else
                 {
                     return 0;
                 }
             }
         #endregion
         #region Cloaks of Ability Scores
         case ITEM_PROPERTY_ABILITY_BONUS:
             {
                 int abilityScore = AvailableAbilityScores[Generation.rand.Next(AvailableAbilityScores.Count)];
                 string name = AbilityScoreNames[abilityScore];
                 if (maxValue >= 36000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyAbilityBonus(abilityScore, 6), cloak, 0.0f);
                     script.SetFirstName(cloak, name + " +6");
                     Pricing.CalculatePrice(script, cloak);
                     return 36000;
                 }
                 else if (maxValue >= 25000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyAbilityBonus(abilityScore, 5), cloak, 0.0f);
                     script.SetFirstName(cloak, name + " +5");
                     Pricing.CalculatePrice(script, cloak);
                     return 25000;
                 }
                 else if (maxValue >= 16000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyAbilityBonus(abilityScore, 4), cloak, 0.0f);
                     script.SetFirstName(cloak, name + " +4");
                     Pricing.CalculatePrice(script, cloak);
                     return 16000;
                 }
                 else if (maxValue >= 9000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyAbilityBonus(abilityScore, 3), cloak, 0.0f);
                     script.SetFirstName(cloak, name + " +3");
                     Pricing.CalculatePrice(script, cloak);
                     return 9000;
                 }
                 else if (maxValue >= 4000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyAbilityBonus(abilityScore, 2), cloak, 0.0f);
                     script.SetFirstName(cloak, name + " +2");
                     Pricing.CalculatePrice(script, cloak);
                     return 4000;
                 }
                 else if (maxValue >= 1000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyAbilityBonus(abilityScore, 1), cloak, 0.0f);
                     script.SetFirstName(cloak, name + " +1");
                     Pricing.CalculatePrice(script, cloak);
                     return 1000;
                 }
                 else
                 {
                     return 0;
                 }
             }
         #endregion
         #region Damage Resistance
         case ITEM_PROPERTY_DAMAGE_RESISTANCE:
             {
                 int damageResistType = DamageResistances[Generation.rand.Next(DamageResistances.Count)];
                 if (damageResistType == IP_CONST_DAMAGETYPE_NEGATIVE &&
                     maxValue < 6000)
                 {
                     int attempts = 0;
                     while (damageResistType == IP_CONST_DAMAGETYPE_NEGATIVE)
                     {
                         damageResistType = DamageResistances[Generation.rand.Next(DamageResistances.Count)];
                         attempts++;
                         if (attempts == 10)
                         {
                             // something is wrong. Break out and just go with fire or something.
                             damageResistType = IP_CONST_DAMAGETYPE_FIRE;
                             break;
                         }
                     }
                 }
                 if (damageResistType == IP_CONST_DAMAGETYPE_NEGATIVE)
                 {
                     if (maxValue >= 66000)
                     {
                         script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyDamageResistance(damageResistType, IP_CONST_DAMAGERESIST_30), cloak, 0.0f);
                         script.SetFirstName(cloak, DamageResistanceNames[damageResistType] + ", 30");
                         Pricing.CalculatePrice(script, cloak);
                         return 66000;
                     }
                     else if (maxValue >= 54000)
                     {
                         script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyDamageResistance(damageResistType, IP_CONST_DAMAGERESIST_25), cloak, 0.0f);
                         script.SetFirstName(cloak, DamageResistanceNames[damageResistType] + ", 25");
                         Pricing.CalculatePrice(script, cloak);
                         return 54000;
                     }
                     else if (maxValue >= 42000)
                     {
                         script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyDamageResistance(damageResistType, IP_CONST_DAMAGERESIST_20), cloak, 0.0f);
                         script.SetFirstName(cloak, DamageResistanceNames[damageResistType] + ", 20");
                         Pricing.CalculatePrice(script, cloak);
                         return 42000;
                     }
                     else if (maxValue >= 30000)
                     {
                         script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyDamageResistance(damageResistType, IP_CONST_DAMAGERESIST_15), cloak, 0.0f);
                         script.SetFirstName(cloak, DamageResistanceNames[damageResistType] + ", 15");
                         Pricing.CalculatePrice(script, cloak);
                         return 30000;
                     }
                     else if (maxValue >= 18000)
                     {
                         script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyDamageResistance(damageResistType, IP_CONST_DAMAGERESIST_10), cloak, 0.0f);
                         script.SetFirstName(cloak, DamageResistanceNames[damageResistType] + ", 10");
                         Pricing.CalculatePrice(script, cloak);
                         return 18000;
                     }
                     else if (maxValue >= 6000)
                     {
                         script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyDamageResistance(damageResistType, IP_CONST_DAMAGERESIST_5), cloak, 0.0f);
                         script.SetFirstName(cloak, DamageResistanceNames[damageResistType] + ", 5");
                         Pricing.CalculatePrice(script, cloak);
                         return 6000;
                     }
                 }
                 else
                 {
                     if (maxValue >= 44000)
                     {
                         script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyDamageResistance(damageResistType, IP_CONST_DAMAGERESIST_30), cloak, 0.0f);
                         script.SetFirstName(cloak, DamageResistanceNames[damageResistType] + ", 30");
                         Pricing.CalculatePrice(script, cloak);
                         return 44000;
                     }
                     else if (maxValue >= 36000)
                     {
                         script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyDamageResistance(damageResistType, IP_CONST_DAMAGERESIST_25), cloak, 0.0f);
                         script.SetFirstName(cloak, DamageResistanceNames[damageResistType] + ", 25");
                         Pricing.CalculatePrice(script, cloak);
                         return 36000;
                     }
                     else if (maxValue >= 28000)
                     {
                         script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyDamageResistance(damageResistType, IP_CONST_DAMAGERESIST_20), cloak, 0.0f);
                         script.SetFirstName(cloak, DamageResistanceNames[damageResistType] + ", 20");
                         Pricing.CalculatePrice(script, cloak);
                         return 28000;
                     }
                     else if (maxValue >= 20000)
                     {
                         script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyDamageResistance(damageResistType, IP_CONST_DAMAGERESIST_15), cloak, 0.0f);
                         script.SetFirstName(cloak, DamageResistanceNames[damageResistType] + ", 15");
                         Pricing.CalculatePrice(script, cloak);
                         return 20000;
                     }
                     else if (maxValue >= 12000)
                     {
                         script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyDamageResistance(damageResistType, IP_CONST_DAMAGERESIST_10), cloak, 0.0f);
                         script.SetFirstName(cloak, DamageResistanceNames[damageResistType] + ", 10");
                         Pricing.CalculatePrice(script, cloak);
                         return 12000;
                     }
                     else if (maxValue >= 4000)
                     {
                         script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyDamageResistance(damageResistType, IP_CONST_DAMAGERESIST_5), cloak, 0.0f);
                         script.SetFirstName(cloak, DamageResistanceNames[damageResistType] + ", 5");
                         Pricing.CalculatePrice(script, cloak);
                         return 4000;
                     }
                 }
                 break;
             }
         #endregion
         #region Immunities
         case ITEM_PROPERTY_IMMUNITY_MISCELLANEOUS:
             {
                 List<int> possibleImmunities = new List<int>();
                 foreach (KeyValuePair<int, int> immunity in AvailableImmunities)
                 {
                     if (immunity.Value <= maxValue)
                     {
                         possibleImmunities.Add(immunity.Key);
                     }
                 }
                 if (possibleImmunities.Count == 0)
                 {
                     return 0;
                 }
                 int selectedImmunity = possibleImmunities[Generation.rand.Next(possibleImmunities.Count)];
                 script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyImmunityMisc(selectedImmunity), cloak, 0.0f);
                 script.SetFirstName(cloak, ImmunityNames[selectedImmunity]);
                 Pricing.CalculatePrice(script, cloak);
                 return AvailableImmunities[selectedImmunity];
             }
         #endregion
         #region Saving Throws
         case ITEM_PROPERTY_SAVING_THROW_BONUS:
             {
                 if (maxValue >= 25000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSavingThrowVsX(IP_CONST_SAVEVS_UNIVERSAL, 5), cloak, 0.0f);
                     script.SetFirstName(cloak, "Cloak of Resistance +5");
                     Pricing.CalculatePrice(script, cloak);
                     return 25000;
                 }
                 else if (maxValue >= 16000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSavingThrowVsX(IP_CONST_SAVEVS_UNIVERSAL, 4), cloak, 0.0f);
                     script.SetFirstName(cloak, "Cloak of Resistance +4");
                     Pricing.CalculatePrice(script, cloak);
                     return 16000;
                 }
                 else if (maxValue >= 9000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSavingThrowVsX(IP_CONST_SAVEVS_UNIVERSAL, 3), cloak, 0.0f);
                     script.SetFirstName(cloak, "Cloak of Resistance +3");
                     Pricing.CalculatePrice(script, cloak);
                     return 9000;
                 }
                 else if (maxValue >= 4000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSavingThrowVsX(IP_CONST_SAVEVS_UNIVERSAL, 2), cloak, 0.0f);
                     script.SetFirstName(cloak, "Cloak of Resistance +2");
                     Pricing.CalculatePrice(script, cloak);
                     return 4000;
                 }
                 else if (maxValue >= 1000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSavingThrowVsX(IP_CONST_SAVEVS_UNIVERSAL, 1), cloak, 0.0f);
                     script.SetFirstName(cloak, "Cloak of Resistance +1");
                     Pricing.CalculatePrice(script, cloak);
                     return 1000;
                 }
                 else
                 {
                     return 0;
                 }
             }
         #endregion
         #region Saving Throws vs. Specific
         case ITEM_PROPERTY_SAVING_THROW_BONUS_SPECIFIC:
             {
                 int saveType = AvailableSaveTypes[Generation.rand.Next(AvailableSaveTypes.Count)];
                 script.SetFirstName(cloak, SaveTypeNames[saveType]);
                 if (maxValue >= 6250)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSavingThrowVsX(saveType, 5), cloak, 0.0f);
                     script.SetFirstName(cloak, String.Format("{0} +5", script.GetName(cloak)));
                     Pricing.CalculatePrice(script, cloak);
                     return 6250;
                 }
                 else if (maxValue >= 4000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSavingThrowVsX(saveType, 4), cloak, 0.0f);
                     script.SetFirstName(cloak, String.Format("{0} +4", script.GetName(cloak)));
                     Pricing.CalculatePrice(script, cloak);
                     return 4000;
                 }
                 else if (maxValue >= 2250)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSavingThrowVsX(saveType, 3), cloak, 0.0f);
                     script.SetFirstName(cloak, String.Format("{0} +3", script.GetName(cloak)));
                     Pricing.CalculatePrice(script, cloak);
                     return 2250;
                 }
                 else if (maxValue >= 1000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSavingThrowVsX(saveType, 2), cloak, 0.0f);
                     script.SetFirstName(cloak, String.Format("{0} +2", script.GetName(cloak)));
                     Pricing.CalculatePrice(script, cloak);
                     return 1000;
                 }
                 else if (maxValue >= 250)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSavingThrowVsX(saveType, 1), cloak, 0.0f);
                     script.SetFirstName(cloak, String.Format("{0} +1", script.GetName(cloak)));
                     Pricing.CalculatePrice(script, cloak);
                     return 250;
                 }
                 break;
             }
         #endregion
         #region Skill Bonus
         case ITEM_PROPERTY_SKILL_BONUS:
             {
                 int skillBonus = AvailableSkills[Generation.rand.Next(AvailableSkills.Count)];
                 script.SetFirstName(cloak, SkillNames[skillBonus]);
                 if (maxValue >= 10000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertySkillBonus(skillBonus, 10), cloak, 0.0f);
                     script.SetFirstName(cloak, script.GetName(cloak) + " +10");
                     Pricing.CalculatePrice(script, cloak);
                     return 10000;
                 }
                 else if (maxValue >= 8100)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertySkillBonus(skillBonus, 9), cloak, 0.0f);
                     script.SetFirstName(cloak, script.GetName(cloak) + " +9");
                     Pricing.CalculatePrice(script, cloak);
                     return 8100;
                 }
                 else if (maxValue >= 6400)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertySkillBonus(skillBonus, 8), cloak, 0.0f);
                     script.SetFirstName(cloak, script.GetName(cloak) + " +8");
                     Pricing.CalculatePrice(script, cloak);
                     return 6400;
                 }
                 else if (maxValue >= 4900)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertySkillBonus(skillBonus, 7), cloak, 0.0f);
                     script.SetFirstName(cloak, script.GetName(cloak) + " +7");
                     Pricing.CalculatePrice(script, cloak);
                     return 4900;
                 }
                 else if (maxValue >= 3600)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertySkillBonus(skillBonus, 6), cloak, 0.0f);
                     script.SetFirstName(cloak, script.GetName(cloak) + " +6");
                     Pricing.CalculatePrice(script, cloak);
                     return 3600;
                 }
                 else if (maxValue >= 2500)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertySkillBonus(skillBonus, 5), cloak, 0.0f);
                     script.SetFirstName(cloak, script.GetName(cloak) + " +5");
                     Pricing.CalculatePrice(script, cloak);
                     return 2500;
                 }
                 else if (maxValue >= 1600)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertySkillBonus(skillBonus, 4), cloak, 0.0f);
                     script.SetFirstName(cloak, script.GetName(cloak) + " +4");
                     Pricing.CalculatePrice(script, cloak);
                     return 1600;
                 }
                 else if (maxValue >= 900)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertySkillBonus(skillBonus, 3), cloak, 0.0f);
                     script.SetFirstName(cloak, script.GetName(cloak) + " +3");
                     Pricing.CalculatePrice(script, cloak);
                     return 900;
                 }
                 else if (maxValue >= 400)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertySkillBonus(skillBonus, 2), cloak, 0.0f);
                     script.SetFirstName(cloak, script.GetName(cloak) + " +2");
                     Pricing.CalculatePrice(script, cloak);
                     return 400;
                 }
                 else if (maxValue >= 100)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertySkillBonus(skillBonus, 1), cloak, 0.0f);
                     script.SetFirstName(cloak, script.GetName(cloak) + " +1");
                     Pricing.CalculatePrice(script, cloak);
                     return 100;
                 }
                 else
                 {
                     return 0;
                 }
             }
         #endregion
         #region Spell Resistance
         case ITEM_PROPERTY_SPELL_RESISTANCE:
             {
                 if (maxValue >= 140000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSpellResistance(IP_CONST_SPELLRESISTANCEBONUS_26), cloak, 0.0f);
                     script.SetFirstName(cloak, "Cloak of Spell Resistance, 26");
                     Pricing.CalculatePrice(script, cloak);
                     return 140000;
                 }
                 else if (maxValue >= 120000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSpellResistance(IP_CONST_SPELLRESISTANCEBONUS_24), cloak, 0.0f);
                     script.SetFirstName(cloak, "Cloak of Spell Resistance, 24");
                     Pricing.CalculatePrice(script, cloak);
                     return 120000;
                 }
                 else if (maxValue >= 100000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSpellResistance(IP_CONST_SPELLRESISTANCEBONUS_22), cloak, 0.0f);
                     script.SetFirstName(cloak, "Cloak of Spell Resistance, 22");
                     Pricing.CalculatePrice(script, cloak);
                     return 100000;
                 }
                 else if (maxValue >= 80000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSpellResistance(IP_CONST_SPELLRESISTANCEBONUS_20), cloak, 0.0f);
                     script.SetFirstName(cloak, "Cloak of Spell Resistance, 20");
                     Pricing.CalculatePrice(script, cloak);
                     return 80000;
                 }
                 else if (maxValue >= 60000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSpellResistance(IP_CONST_SPELLRESISTANCEBONUS_18), cloak, 0.0f);
                     script.SetFirstName(cloak, "Cloak of Spell Resistance, 18");
                     Pricing.CalculatePrice(script, cloak);
                     return 60000;
                 }
                 else if (maxValue >= 40000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSpellResistance(IP_CONST_SPELLRESISTANCEBONUS_16), cloak, 0.0f);
                     script.SetFirstName(cloak, "Cloak of Spell Resistance, 16");
                     Pricing.CalculatePrice(script, cloak);
                     return 40000;
                 }
                 else if (maxValue >= 20000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSpellResistance(IP_CONST_SPELLRESISTANCEBONUS_14), cloak, 0.0f);
                     script.SetFirstName(cloak, "Cloak of Spell Resistance, 14");
                     Pricing.CalculatePrice(script, cloak);
                     return 20000;
                 }
                 else if (maxValue >= 10000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSpellResistance(IP_CONST_SPELLRESISTANCEBONUS_12), cloak, 0.0f);
                     script.SetFirstName(cloak, "Cloak of Spell Resistance, 12");
                     Pricing.CalculatePrice(script, cloak);
                     return 10000;
                 }
                 else if (maxValue >= 6000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSpellResistance(IP_CONST_SPELLRESISTANCEBONUS_10), cloak, 0.0f);
                     script.SetFirstName(cloak, "Cloak of Spell Resistance, 10");
                     Pricing.CalculatePrice(script, cloak);
                     return 6000;
                 }
                 else
                 {
                     return 0;
                 }
             }
         #endregion
     }
     script.DestroyObject(cloak, 0.0f, FALSE);
     return 0;
 }
 public static int NewAmulet(CLRScriptBase script, int maxValue)
 {
     List<int> potentialAbilities = new List<int>();
     foreach (KeyValuePair<int, int> ability in PrimaryAmuletAbility)
     {
         if (ability.Value <= maxValue)
         {
             potentialAbilities.Add(ability.Key);
         }
     }
     if (potentialAbilities.Count == 0)
     {
         return 0;
     }
     int selectedAbility = potentialAbilities[Generation.rand.Next(potentialAbilities.Count)];
     uint amulet = script.CreateItemOnObject("nw_it_mneck020", script.OBJECT_SELF, 1, "", FALSE);
     switch (selectedAbility)
     {
         #region Amulets of Natural Armor
         case ITEM_PROPERTY_AC_BONUS:
             {
                 if (maxValue >= 50000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyACBonus(5), amulet, 0.0f);
                     script.SetFirstName(amulet, "Amulet of Natural Armor +5");
                     Pricing.CalculatePrice(script, amulet);
                     return 50000;
                 }
                 else if (maxValue >= 32000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyACBonus(4), amulet, 0.0f);
                     script.SetFirstName(amulet, "Amulet of Natural Armor +4");
                     Pricing.CalculatePrice(script, amulet);
                     return 32000;
                 }
                 else if (maxValue >= 18000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyACBonus(3), amulet, 0.0f);
                     script.SetFirstName(amulet, "Amulet of Natural Armor +3");
                     Pricing.CalculatePrice(script, amulet);
                     return 18000;
                 }
                 else if (maxValue >= 8000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyACBonus(2), amulet, 0.0f);
                     script.SetFirstName(amulet, "Amulet of Natural Armor +2");
                     Pricing.CalculatePrice(script, amulet);
                     return 8000;
                 }
                 else if (maxValue >= 2000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyACBonus(1), amulet, 0.0f);
                     script.SetFirstName(amulet, "Amulet of Natural Armor +1");
                     Pricing.CalculatePrice(script, amulet);
                     return 2000;
                 }
                 else
                 {
                     return 0;
                 }
             }
         #endregion
         #region Amulets of Health and Wisdom
         case ITEM_PROPERTY_ABILITY_BONUS:
             {
                 int abilityScore = IP_CONST_ABILITY_CON;
                 string name = "Amulet of Health";
                 if (script.d2(1) == 1)
                 {
                     abilityScore = IP_CONST_ABILITY_WIS;
                     name = "Amulet of Wisdom";
                 }
                 if (maxValue >= 36000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyAbilityBonus(abilityScore, 6), amulet, 0.0f);
                     script.SetFirstName(amulet, name + " +6");
                     Pricing.CalculatePrice(script, amulet);
                     return 36000;
                 }
                 else if (maxValue >= 25000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyAbilityBonus(abilityScore, 5), amulet, 0.0f);
                     script.SetFirstName(amulet, name + " +5");
                     Pricing.CalculatePrice(script, amulet);
                     return 25000;
                 }
                 else if (maxValue >= 16000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyAbilityBonus(abilityScore, 4), amulet, 0.0f);
                     script.SetFirstName(amulet, name + " +4");
                     Pricing.CalculatePrice(script, amulet);
                     return 16000;
                 }
                 else if (maxValue >= 9000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyAbilityBonus(abilityScore, 3), amulet, 0.0f);
                     script.SetFirstName(amulet, name + " +3");
                     Pricing.CalculatePrice(script, amulet);
                     return 9000;
                 }
                 else if (maxValue >= 4000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyAbilityBonus(abilityScore, 2), amulet, 0.0f);
                     script.SetFirstName(amulet, name + " +2");
                     Pricing.CalculatePrice(script, amulet);
                     return 4000;
                 }
                 else if (maxValue >= 1000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyAbilityBonus(abilityScore, 1), amulet, 0.0f);
                     script.SetFirstName(amulet, name + " +1");
                     Pricing.CalculatePrice(script, amulet);
                     return 1000;
                 }
                 else
                 {
                     return 0;
                 }
             }
         #endregion
         #region Amulets with Bonus Feats
         case ITEM_PROPERTY_BONUS_FEAT:
             {
                 List<int> possibleFeats = new List<int>();
                 foreach (KeyValuePair<int, int> feat in AvailableFeats)
                 {
                     if (feat.Value <= maxValue)
                     {
                         possibleFeats.Add(feat.Key);
                     }
                 }
                 if (possibleFeats.Count == 0)
                 {
                     return 0;
                 }
                 int selectedFeat = possibleFeats[Generation.rand.Next(possibleFeats.Count)];
                 script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusFeat(selectedFeat), amulet, 0.0f);
                 switch (selectedFeat)
                 {
                     case IP_CONST_FEAT_COMBAT_CASTING:
                         script.SetFirstName(amulet, "Amulet of the Battlemage");
                         break;
                     case IP_CONST_FEAT_EXTRA_TURNING:
                         script.SetFirstName(amulet, "Amulet of Turning");
                         break;
                     case IP_CONST_FEAT_DARKVISION:
                         script.SetFirstName(amulet, "Amulet of Darkvision");
                         break;
                 }
                 Pricing.CalculatePrice(script, amulet);
                 return AvailableFeats[selectedFeat];
             }
         #endregion
         #region Damage Resistance
         case ITEM_PROPERTY_DAMAGE_RESISTANCE:
             {
                 int damageResistType = DamageResistances[Generation.rand.Next(DamageResistances.Count)];
                 if (damageResistType == IP_CONST_DAMAGETYPE_NEGATIVE &&
                     maxValue < 6000)
                 {
                     int attempts = 0;
                     while (damageResistType == IP_CONST_DAMAGETYPE_NEGATIVE)
                     {
                         damageResistType = DamageResistances[Generation.rand.Next(DamageResistances.Count)];
                         attempts++;
                         if (attempts == 10)
                         {
                             // something is wrong. Break out and just go with fire or something.
                             damageResistType = IP_CONST_DAMAGETYPE_FIRE;
                             break;
                         }
                     }
                 }
                 if (damageResistType == IP_CONST_DAMAGETYPE_NEGATIVE)
                 {
                     if (maxValue >= 66000)
                     {
                         script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyDamageResistance(damageResistType, IP_CONST_DAMAGERESIST_30), amulet, 0.0f);
                         script.SetFirstName(amulet, DamageResistanceNames[damageResistType] + ", 30");
                         Pricing.CalculatePrice(script, amulet);
                         return 66000;
                     }
                     else if (maxValue >= 54000)
                     {
                         script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyDamageResistance(damageResistType, IP_CONST_DAMAGERESIST_25), amulet, 0.0f);
                         script.SetFirstName(amulet, DamageResistanceNames[damageResistType] + ", 25");
                         Pricing.CalculatePrice(script, amulet);
                         return 54000;
                     }
                     else if (maxValue >= 42000)
                     {
                         script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyDamageResistance(damageResistType, IP_CONST_DAMAGERESIST_20), amulet, 0.0f);
                         script.SetFirstName(amulet, DamageResistanceNames[damageResistType] + ", 20");
                         Pricing.CalculatePrice(script, amulet);
                         return 42000;
                     }
                     else if (maxValue >= 30000)
                     {
                         script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyDamageResistance(damageResistType, IP_CONST_DAMAGERESIST_15), amulet, 0.0f);
                         script.SetFirstName(amulet, DamageResistanceNames[damageResistType] + ", 15");
                         Pricing.CalculatePrice(script, amulet);
                         return 30000;
                     }
                     else if (maxValue >= 18000)
                     {
                         script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyDamageResistance(damageResistType, IP_CONST_DAMAGERESIST_10), amulet, 0.0f);
                         script.SetFirstName(amulet, DamageResistanceNames[damageResistType] + ", 10");
                         Pricing.CalculatePrice(script, amulet);
                         return 18000;
                     }
                     else if (maxValue >= 6000)
                     {
                         script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyDamageResistance(damageResistType, IP_CONST_DAMAGERESIST_5), amulet, 0.0f);
                         script.SetFirstName(amulet, DamageResistanceNames[damageResistType] + ", 5");
                         Pricing.CalculatePrice(script, amulet);
                         return 6000;
                     }
                 }
                 else
                 {
                     if (maxValue >= 44000)
                     {
                         script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyDamageResistance(damageResistType, IP_CONST_DAMAGERESIST_30), amulet, 0.0f);
                         script.SetFirstName(amulet, DamageResistanceNames[damageResistType] + ", 30");
                         Pricing.CalculatePrice(script, amulet);
                         return 44000;
                     }
                     else if (maxValue >= 36000)
                     {
                         script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyDamageResistance(damageResistType, IP_CONST_DAMAGERESIST_25), amulet, 0.0f);
                         script.SetFirstName(amulet, DamageResistanceNames[damageResistType] + ", 25");
                         Pricing.CalculatePrice(script, amulet);
                         return 36000;
                     }
                     else if (maxValue >= 28000)
                     {
                         script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyDamageResistance(damageResistType, IP_CONST_DAMAGERESIST_20), amulet, 0.0f);
                         script.SetFirstName(amulet, DamageResistanceNames[damageResistType] + ", 20");
                         Pricing.CalculatePrice(script, amulet);
                         return 28000;
                     }
                     else if (maxValue >= 20000)
                     {
                         script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyDamageResistance(damageResistType, IP_CONST_DAMAGERESIST_15), amulet, 0.0f);
                         script.SetFirstName(amulet, DamageResistanceNames[damageResistType] + ", 15");
                         Pricing.CalculatePrice(script, amulet);
                         return 20000;
                     }
                     else if (maxValue >= 12000)
                     {
                         script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyDamageResistance(damageResistType, IP_CONST_DAMAGERESIST_10), amulet, 0.0f);
                         script.SetFirstName(amulet, DamageResistanceNames[damageResistType] + ", 10");
                         Pricing.CalculatePrice(script, amulet);
                         return 12000;
                     }
                     else if (maxValue >= 4000)
                     {
                         script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyDamageResistance(damageResistType, IP_CONST_DAMAGERESIST_5), amulet, 0.0f);
                         script.SetFirstName(amulet, DamageResistanceNames[damageResistType] + ", 5");
                         Pricing.CalculatePrice(script, amulet);
                         return 4000;
                     }
                 }
                 break;
             }
         #endregion
         #region Freedom of Movement
         case ITEM_PROPERTY_FREEDOM_OF_MOVEMENT:
             {
                 script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyFreeAction(), amulet, 0.0f);
                 script.SetFirstName(amulet, "Amulet of Freedom");
                 Pricing.CalculatePrice(script, amulet);
                 return 40000;
             }
         #endregion
         #region Immunities
         case ITEM_PROPERTY_IMMUNITY_MISCELLANEOUS:
             {
                 List<int> possibleImmunities = new List<int>();
                 foreach (KeyValuePair<int, int> immunity in AvailableImmunities)
                 {
                     if (immunity.Value <= maxValue)
                     {
                         possibleImmunities.Add(immunity.Key);
                     }
                 }
                 if (possibleImmunities.Count == 0)
                 {
                     return 0;
                 }
                 int selectedImmunity = possibleImmunities[Generation.rand.Next(possibleImmunities.Count)];
                 script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyImmunityMisc(selectedImmunity), amulet, 0.0f);
                 switch (selectedImmunity)
                 {
                     case IP_CONST_IMMUNITYMISC_DEATH_MAGIC:
                         script.SetFirstName(amulet, "Amulet of Lifeshielding");
                         break;
                     case IP_CONST_IMMUNITYMISC_DISEASE:
                         script.SetFirstName(amulet, "Amulet of Good Health");
                         break;
                     case IP_CONST_IMMUNITYMISC_FEAR:
                         script.SetFirstName(amulet, "Amulet of Fearlessness");
                         break;
                     case IP_CONST_IMMUNITYMISC_KNOCKDOWN:
                         script.SetFirstName(amulet, "Amulet of Stability");
                         break;
                     case IP_CONST_IMMUNITYMISC_LEVEL_ABIL_DRAIN:
                         script.SetFirstName(amulet, "Amulet of Undeath's Deflection");
                         break;
                     case IP_CONST_IMMUNITYMISC_PARALYSIS:
                         script.SetFirstName(amulet, "Amulet of Mobility");
                         break;
                     case IP_CONST_IMMUNITYMISC_POISON:
                         script.SetFirstName(amulet, "Amulet of Antivenom");
                         break;
                 }
                 Pricing.CalculatePrice(script, amulet);
                 return AvailableImmunities[selectedImmunity];
             }
         #endregion
         #region Saving Throws
         case ITEM_PROPERTY_SAVING_THROW_BONUS:
             {
                 if (maxValue >= 25000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSavingThrowVsX(IP_CONST_SAVEVS_UNIVERSAL, 5), amulet, 0.0f);
                     script.SetFirstName(amulet, "Amulet of Resistance +5");
                     Pricing.CalculatePrice(script, amulet);
                     return 25000;
                 }
                 else if (maxValue >= 16000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSavingThrowVsX(IP_CONST_SAVEVS_UNIVERSAL, 4), amulet, 0.0f);
                     script.SetFirstName(amulet, "Amulet of Resistance +4");
                     Pricing.CalculatePrice(script, amulet);
                     return 16000;
                 }
                 else if (maxValue >= 9000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSavingThrowVsX(IP_CONST_SAVEVS_UNIVERSAL, 3), amulet, 0.0f);
                     script.SetFirstName(amulet, "Amulet of Resistance +3");
                     Pricing.CalculatePrice(script, amulet);
                     return 9000;
                 }
                 else if (maxValue >= 4000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSavingThrowVsX(IP_CONST_SAVEVS_UNIVERSAL, 2), amulet, 0.0f);
                     script.SetFirstName(amulet, "Amulet of Resistance +2");
                     Pricing.CalculatePrice(script, amulet);
                     return 4000;
                 }
                 else if (maxValue >= 1000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSavingThrowVsX(IP_CONST_SAVEVS_UNIVERSAL, 1), amulet, 0.0f);
                     script.SetFirstName(amulet, "Amulet of Resistance +1");
                     Pricing.CalculatePrice(script, amulet);
                     return 1000;
                 }
                 else
                 {
                     return 0;
                 }
             }
         #endregion
         #region Saving Throws vs. Specific
         case ITEM_PROPERTY_SAVING_THROW_BONUS_SPECIFIC:
             {
                 int saveType = AvailableSaveTypes[Generation.rand.Next(AvailableSaveTypes.Count)];
                 script.SetFirstName(amulet, SaveTypeNames[saveType]);
                 if (maxValue >= 6250)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSavingThrowVsX(saveType, 5), amulet, 0.0f);
                     script.SetFirstName(amulet, String.Format("{0} +5", script.GetName(amulet)));
                     Pricing.CalculatePrice(script, amulet);
                     return 6250;
                 }
                 else if (maxValue >= 4000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSavingThrowVsX(saveType, 4), amulet, 0.0f);
                     script.SetFirstName(amulet, String.Format("{0} +4", script.GetName(amulet)));
                     Pricing.CalculatePrice(script, amulet);
                     return 4000;
                 }
                 else if (maxValue >= 2250)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSavingThrowVsX(saveType, 3), amulet, 0.0f);
                     script.SetFirstName(amulet, String.Format("{0} +3", script.GetName(amulet)));
                     Pricing.CalculatePrice(script, amulet);
                     return 2250;
                 }
                 else if (maxValue >= 1000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSavingThrowVsX(saveType, 2), amulet, 0.0f);
                     script.SetFirstName(amulet, String.Format("{0} +2", script.GetName(amulet)));
                     Pricing.CalculatePrice(script, amulet);
                     return 1000;
                 }
                 else if (maxValue >= 250)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSavingThrowVsX(saveType, 1), amulet, 0.0f);
                     script.SetFirstName(amulet, String.Format("{0} +1", script.GetName(amulet)));
                     Pricing.CalculatePrice(script, amulet);
                     return 250;
                 }
                 break;
             }
         #endregion
         #region Skill Bonus
         case ITEM_PROPERTY_SKILL_BONUS:
             {
                 int skillBonus = AvailableSkills[Generation.rand.Next(AvailableSkills.Count)];
                 script.SetFirstName(amulet, SkillNames[skillBonus]);
                 if (maxValue >= 10000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertySkillBonus(skillBonus, 10), amulet, 0.0f);
                     script.SetFirstName(amulet, script.GetName(amulet) + " +10");
                     Pricing.CalculatePrice(script, amulet);
                     return 10000;
                 }
                 else if (maxValue >= 8100)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertySkillBonus(skillBonus, 9), amulet, 0.0f);
                     script.SetFirstName(amulet, script.GetName(amulet) + " +9");
                     Pricing.CalculatePrice(script, amulet);
                     return 8100;
                 }
                 else if (maxValue >= 6400)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertySkillBonus(skillBonus, 8), amulet, 0.0f);
                     script.SetFirstName(amulet, script.GetName(amulet) + " +8");
                     Pricing.CalculatePrice(script, amulet);
                     return 6400;
                 }
                 else if (maxValue >= 4900)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertySkillBonus(skillBonus, 7), amulet, 0.0f);
                     script.SetFirstName(amulet, script.GetName(amulet) + " +7");
                     Pricing.CalculatePrice(script, amulet);
                     return 4900;
                 }
                 else if (maxValue >= 3600)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertySkillBonus(skillBonus, 6), amulet, 0.0f);
                     script.SetFirstName(amulet, script.GetName(amulet) + " +6");
                     Pricing.CalculatePrice(script, amulet);
                     return 3600;
                 }
                 else if (maxValue >= 2500)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertySkillBonus(skillBonus, 5), amulet, 0.0f);
                     script.SetFirstName(amulet, script.GetName(amulet) + " +5");
                     Pricing.CalculatePrice(script, amulet);
                     return 2500;
                 }
                 else if (maxValue >= 1600)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertySkillBonus(skillBonus, 4), amulet, 0.0f);
                     script.SetFirstName(amulet, script.GetName(amulet) + " +4");
                     Pricing.CalculatePrice(script, amulet);
                     return 1600;
                 }
                 else if (maxValue >= 900)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertySkillBonus(skillBonus, 3), amulet, 0.0f);
                     script.SetFirstName(amulet, script.GetName(amulet) + " +3");
                     Pricing.CalculatePrice(script, amulet);
                     return 900;
                 }
                 else if (maxValue >= 400)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertySkillBonus(skillBonus, 2), amulet, 0.0f);
                     script.SetFirstName(amulet, script.GetName(amulet) + " +2");
                     Pricing.CalculatePrice(script, amulet);
                     return 400;
                 }
                 else if (maxValue >= 100)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertySkillBonus(skillBonus, 1), amulet, 0.0f);
                     script.SetFirstName(amulet, script.GetName(amulet) + " +1");
                     Pricing.CalculatePrice(script, amulet);
                     return 100;
                 }
                 else
                 {
                     return 0;
                 }
             }
         #endregion
         #region Spell Resistance
         case ITEM_PROPERTY_SPELL_RESISTANCE:
             {
                 if (maxValue >= 140000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSpellResistance(IP_CONST_SPELLRESISTANCEBONUS_26), amulet, 0.0f);
                     script.SetFirstName(amulet, "Amulet of Spell Resistance, 26");
                     Pricing.CalculatePrice(script, amulet);
                     return 140000;
                 }
                 else if (maxValue >= 120000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSpellResistance(IP_CONST_SPELLRESISTANCEBONUS_24), amulet, 0.0f);
                     script.SetFirstName(amulet, "Amulet of Spell Resistance, 24");
                     Pricing.CalculatePrice(script, amulet);
                     return 120000;
                 }
                 else if (maxValue >= 100000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSpellResistance(IP_CONST_SPELLRESISTANCEBONUS_22), amulet, 0.0f);
                     script.SetFirstName(amulet, "Amulet of Spell Resistance, 22");
                     Pricing.CalculatePrice(script, amulet);
                     return 100000;
                 }
                 else if (maxValue >= 80000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSpellResistance(IP_CONST_SPELLRESISTANCEBONUS_20), amulet, 0.0f);
                     script.SetFirstName(amulet, "Amulet of Spell Resistance, 20");
                     Pricing.CalculatePrice(script, amulet);
                     return 80000;
                 }
                 else if (maxValue >= 60000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSpellResistance(IP_CONST_SPELLRESISTANCEBONUS_18), amulet, 0.0f);
                     script.SetFirstName(amulet, "Amulet of Spell Resistance, 18");
                     Pricing.CalculatePrice(script, amulet);
                     return 60000;
                 }
                 else if (maxValue >= 40000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSpellResistance(IP_CONST_SPELLRESISTANCEBONUS_16), amulet, 0.0f);
                     script.SetFirstName(amulet, "Amulet of Spell Resistance, 16");
                     Pricing.CalculatePrice(script, amulet);
                     return 40000;
                 }
                 else if (maxValue >= 20000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSpellResistance(IP_CONST_SPELLRESISTANCEBONUS_14), amulet, 0.0f);
                     script.SetFirstName(amulet, "Amulet of Spell Resistance, 14");
                     Pricing.CalculatePrice(script, amulet);
                     return 20000;
                 }
                 else if (maxValue >= 10000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSpellResistance(IP_CONST_SPELLRESISTANCEBONUS_12), amulet, 0.0f);
                     script.SetFirstName(amulet, "Amulet of Spell Resistance, 12");
                     Pricing.CalculatePrice(script, amulet);
                     return 10000;
                 }
                 else if (maxValue >= 6000)
                 {
                     script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyBonusSpellResistance(IP_CONST_SPELLRESISTANCEBONUS_10), amulet, 0.0f);
                     script.SetFirstName(amulet, "Amulet of Spell Resistance, 10");
                     Pricing.CalculatePrice(script, amulet);
                     return 6000;
                 }
                 else
                 {
                     return 0;
                 }
             }
         #endregion
     }
     // Something has gone wrong. Nuke that amulet before it spreads the plague.
     script.DestroyObject(amulet, 0.0f, FALSE);
     return 0;
 }