public static void Disable(CLRScriptBase s, ALFA.Shared.ActiveTrap trap, uint disabler)
 {
     if (trap.Disabler == 0)
     {
         // no one is currently working on this trap.
         s.SendMessageToPC(disabler, "<c=#98FFFF>You begin to disable the trap...</c>");
         trap.Disabler = disabler;
         trap.Helpers = new List<uint>();
     }
     else
     {
         if (trap.Disabler == disabler)
         {
             s.SendMessageToPC(disabler, "<c=#98FFFF>Error: You are already disabling this device.</c>");
         }
         else if (trap.Helpers.Contains(disabler))
         {
             s.SendMessageToPC(disabler, "<c=#98FFFF>Disable Device: * Failure * You have already given aid to this attempt.</c>");
             return;
         }
         else
         {
             trap.Helpers.Add(disabler);
             if (IsDisableSuccessful(s, trap, 10, disabler) == DisableResult.Success)
             {
                 s.SendMessageToPC(disabler, String.Format("<c=#98FFFF>Disable Device: You grant {0} useful assistance with the trap.</c>", s.GetName(trap.Disabler)));
                 trap.TotalHelp += 2;
                 return;
             }
             else
             {
                 s.SendMessageToPC(disabler, String.Format("<c=#98FFFF>Disable Device: You are unable to grant {0} useful assistance with the trap.</c>", s.GetName(trap.Disabler)));
                 return;
             }
         }
     }
     if (s.GetIsDM(disabler) == TRUE && s.GetIsDMPossessed(disabler) == FALSE)
     {
         RemoveTrap(s, trap);
         s.SendMessageToPC(disabler, String.Format("<c=#98FFFF>Removing trap {0}</c>", trap.Tag));
         return;
     }
     float neededTime = s.d4(2) * 6.0f;
     NWLocation oldLoc = s.GetLocation(disabler);
     s.DelayCommand(2.0f, delegate { StallForTime(s, trap, disabler, neededTime, oldLoc); });
 }
        public static void MountHorse(CLRScriptBase script, uint Character, uint Horse)
        {
            if (!isWarhorse.ContainsKey(Character)) isWarhorse.Add(Character, true);

            string cloakResRef;
            switch(script.GetTag(Horse))
            {
                case "abr_cr_an_horse01":
                    cloakResRef = "acr_ooc_horse01";
                    isWarhorse[Character] = true;
                    break;
                case "abr_cr_an_horse02":
                    cloakResRef = "acr_ooc_horse02";
                    isWarhorse[Character] = true;
                    break;
                case "abr_cr_an_horse03":
                    cloakResRef = "acr_ooc_horse03";
                    isWarhorse[Character] = true;
                    break;
                default:
                    cloakResRef = "acr_ooc_horse03";
                    isWarhorse[Character] = true;
                    break;
            }
            
            uint horseCloak = script.CreateItemOnObject(cloakResRef, Character, 1, "", CLRScriptBase.FALSE);
            if (script.GetLocalInt(Horse, ACR_IS_WARHORSE) == 1)
            {
                script.RemoveHenchman(Character, Horse);
                script.SetLocalInt(horseCloak, ACR_IS_WARHORSE, 1);
            }
            script.SetLocalInt(horseCloak, ACR_HORSE_ID, script.GetLocalInt(Horse, ACR_HORSE_ID));
            script.SetLocalInt(horseCloak, ACR_HORSE_HP, script.GetCurrentHitPoints(Horse));

            uint equippedCloak = script.GetItemInSlot(CLRScriptBase.INVENTORY_SLOT_CLOAK, Character);
            
            if (script.GetIsObjectValid(equippedCloak) == CLRScriptBase.TRUE)
            {
                foreach (NWItemProperty prop in script.GetItemPropertiesOnItem(equippedCloak))
                {
                    // copying property duration type prevents us from turning temporary properties into
                    // permanent ones. But because we don't know how long the non-permanent ones have left,
                    // we pretty much have to assign them with the expectation that they immediately expire.
                    script.AddItemProperty(script.GetItemPropertyDurationType(prop), prop, horseCloak, 0.0f);
                }
                script.SetFirstName(horseCloak, script.GetName(equippedCloak) + "(( Horse Appearance ))");
                script.AddItemProperty(CLRScriptBase.DURATION_TYPE_PERMANENT, script.ItemPropertyWeightReduction(CLRScriptBase.IP_CONST_REDUCEDWEIGHT_80_PERCENT), horseCloak, 0.0f);
            }
            script.SetPlotFlag(horseCloak, CLRScriptBase.TRUE);
            script.SetPlotFlag(Horse, CLRScriptBase.FALSE);
            
            script.AssignCommand(Horse, delegate { script.SetIsDestroyable(CLRScriptBase.TRUE, CLRScriptBase.FALSE, CLRScriptBase.FALSE); });
            script.AssignCommand(Horse, delegate { script.DestroyObject(Horse, 0.0f, CLRScriptBase.FALSE); });
            script.AssignCommand(Character, delegate { script.ActionEquipItem(horseCloak, CLRScriptBase.INVENTORY_SLOT_CLOAK); });

            if (!isWarhorse[Character]) script.DelayCommand(6.0f, delegate { RidingHeartbeat(script, Character); });
        }
        public static void GenericDamage(CLRScriptBase script, NWLocation location, TriggerArea triggerArea, int effectArea, float effectSize, int damageType, int diceNumber, int diceType, int saveDC, int attackBonus, int numberOfShots, uint trapOrigin, int targetAlignment, int targetRace, int minimumToTrigger, int detectDC, int disarmDC, string description)
        {
            string tag = uniqueTrapTag();
            string detectTag = tag + detectSuffix();
            
            script.ApplyEffectAtLocation(DURATION_TYPE_PERMANENT,
                script.SupernaturalEffect(script.EffectAreaOfEffect(triggerAreaToAreaOfEffect(triggerArea), "acr_traponenter", "****", "acr_traponexit", tag)),
                location,
                0.0f);

            script.ApplyEffectAtLocation(DURATION_TYPE_PERMANENT,
                script.SupernaturalEffect(script.EffectAreaOfEffect(triggerAreaToDetectArea(triggerArea), "acr_trapdtctenter", "****", "acr_trapdtctexit", detectTag)),
                location,
                0.0f);

            ALFA.Shared.ActiveTrap createdTrap = new ALFA.Shared.ActiveTrap();
            createdTrap.AreaName = script.GetName(script.GetAreaFromLocation(location));
            createdTrap.AttackBonus = attackBonus;
            createdTrap.ChallengeRating = 0.0f;
            createdTrap.DamageType = damageType;
            createdTrap.DetectTag = detectTag;
            createdTrap.DiceNumber = diceNumber;
            createdTrap.DiceType = diceType;
            createdTrap.EffectArea = effectArea;
            createdTrap.EffectSize = effectSize;
            createdTrap.Location = location;
            createdTrap.MinimumToTrigger = minimumToTrigger;
            createdTrap.NumberOfShots = numberOfShots;
            createdTrap.SaveDC = saveDC;
            createdTrap.SpellTrap = false;
            createdTrap.Tag = tag;
            createdTrap.TargetAlignment = targetAlignment;
            createdTrap.TargetRace = targetRace;
            createdTrap.TrapTriggerVFX = triggerAreaToTrapVFX(triggerArea);
            createdTrap.DetectDC = detectDC;
            createdTrap.DisarmDC = disarmDC;
            createdTrap.Detected = false;
            createdTrap.Disabler = 0;
            createdTrap.Helpers = new List<uint>();
            createdTrap.TotalHelp = 0;
            createdTrap.IsFiring = false;
            createdTrap.Description = description;
            createdTrap.ConfigureDisplayName();
            createdTrap.CalculateCR();

            createdTrap.TrapOrigin = GetNearestTrapEmitter(script, location);

            ALFA.Shared.Modules.InfoStore.SpawnedTrapDetect.Add(detectTag, createdTrap);
            ALFA.Shared.Modules.InfoStore.SpawnedTrapTriggers.Add(tag, createdTrap);

            script.SetLocalString(script.GetModule(), "ACR_TRAPS_LAST_TAG", tag);
        }
示例#4
0
 public static void LoadAreas(CLRScriptBase s)
 {
     if (!ACR_Candlekeep.ArchivesInstance.WaitForResourcesLoaded(false))
     {
         s.DelayCommand(6.0f, delegate { LoadAreas(s); });
         return;
     }
     ALFA.Shared.Modules.InfoStore.ActiveAreas = new Dictionary<uint, ALFA.Shared.ActiveArea>();
     List<uint> areas = new List<uint>();
     foreach (uint area in s.GetAreas())
     {
         ALFA.Shared.ActiveArea activeArea = new ALFA.Shared.ActiveArea();
         activeArea.Id = area;
         activeArea.Name = s.GetName(area).Trim();
         activeArea.Tag = s.GetTag(area);
         activeArea.GlobalQuests.Add("Infestation", s.GetLocalInt(area, "ACR_QST_MAX_INFESTATION"));
         ALFA.Shared.Modules.InfoStore.ActiveAreas.Add(area, activeArea);
         areas.Add(area);
     }
     int count = 0;
     foreach(KeyValuePair<string, string> keyValue in ALFA.Shared.Modules.InfoStore.AreaNames)
     {
         ALFA.Shared.Modules.InfoStore.ActiveAreas[areas[count]].LocalizedName = keyValue.Value;
         ALFA.Shared.Modules.InfoStore.ActiveAreas[areas[count]].ConfigureDisplayName();
         s.SetLocalString(areas[count], "ACR_AREA_RESREF", keyValue.Key);
         count++;
     }
     foreach (ALFA.Shared.ActiveArea activeArea in ALFA.Shared.Modules.InfoStore.ActiveAreas.Values)
     {
         foreach (uint thing in s.GetObjectsInArea(activeArea.Id))
         {
             uint target = s.GetTransitionTarget(thing);
             if (s.GetIsObjectValid(target) != FALSE)
             {
                 ALFA.Shared.ActiveTransition activeTransition = new ALFA.Shared.ActiveTransition();
                 activeTransition.AreaTarget = ALFA.Shared.Modules.InfoStore.ActiveAreas[s.GetArea(target)];
                 activeTransition.Id = thing;
                 activeTransition.Target = target;
                 activeArea.ExitTransitions.Add(activeTransition, activeTransition.AreaTarget);
             }
         }
     }
 }
        public static void CalculatePrice(CLRScriptBase script, uint target)
        {
            #region Reject to Price Objects Which Can't or Shouldn't be Priced
            if (script.GetObjectType(target) != OBJECT_TYPE_ITEM)
            {
                return;
            }

            int itemType = script.GetBaseItemType(target);
            if (GetIsOOCItem(itemType))
            {
                return;
            }
            #endregion

            #region Find out What the Item Should be Worth
            int targetValue = 0;
            if (GetIsWeapon(itemType) || GetIsAmmunition(itemType))
            {
                targetValue = GetWeaponPrice(script, target);
            }
            else if (GetIsArmor(itemType))
            {
                targetValue = GetArmorPrice(script, target);
            }
            else
            {
                targetValue = GetWonderousPrice(script, target);
            }
            #endregion

            #region Early Return for Illegal and Custom-Scripted Items
            if (targetValue == -1)
            {
                // We can't price this item, because it's illegal.
                script.SetFirstName(target, "(Illegal) " + script.GetName(target));
                return;
            }
            else if (targetValue == -2)
            {
                return;
            }
            #endregion

            #region Determine if the Item Requires Adjustment, and Adjust if Necessary
            bool isPlot = false;
            bool isUnidentified = false;
            if (script.GetLocalInt(target, localVarName) == pricingVersion)
            {
                // We've already used this logic to price this item. We have nothing to add.
                return;
            }
            if (script.GetPlotFlag(target) == TRUE)
            {
                script.SetPlotFlag(target, FALSE);
                isPlot = true;
            }
            if (script.GetIdentified(target) == FALSE)
            {
                script.SetIdentified(target, TRUE);
                isUnidentified = true;
            }
            int currentValue = script.GetGoldPieceValue(target);
            if (script.GetItemStackSize(target) > 1)
            {
                currentValue /= script.GetItemStackSize(target);
            }
            if (currentValue != targetValue)
            {
                script.StoreCampaignObject(ItemChangeDBName, PriceChangeVarName, target, script.OBJECT_SELF);
                if (ALFA.Shared.Modules.InfoStore.ModifiedGff.Keys.Contains(PriceChangeVarName))
                {
                    if (ALFA.Shared.Modules.InfoStore.ModifiedGff[PriceChangeVarName].TopLevelStruct["ModifyCost"].ValueInt == 0 ||
                        targetValue > currentValue ||
                        script.GetLocalInt(target, localVarName) != 0)
                    {
                        // We only want to adjust the price if either a) no effort to control the item's price has been made or
                        // b) the item is actually less valuable than the current price reads. Artificial inflations of price are
                        // legal in ALFA.

                        // Also, if this item was priced automatically, we want to be able to correct it.
                        script.SetLocalInt(target, localVarName, pricingVersion);
                        AdjustPrice(script, target, targetValue - currentValue);
                    }
                }
            }
            if (isPlot)
            {
                script.SetPlotFlag(target, TRUE);
            }
            if (isUnidentified)
            {
                script.SetIdentified(target, FALSE);
            }
            #endregion
        }
 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;
 }
        private static NWEffect GetTrapEffect(CLRScriptBase s, ALFA.Shared.ActiveTrap trap, uint target)
        {
            int damage = 0;
            for (int count = 0; count < trap.DiceNumber; count++)
            {
                damage += s.Random(trap.DiceType) + 1;
            }
            if (trap.SaveDC > -1)
            {
                if (s.ReflexSave(target, trap.SaveDC, SAVING_THROW_TYPE_TRAP, s.GetObjectByTag(trap.Tag, 0)) != TRUE)
                {
                    if (s.GetHasFeat(FEAT_IMPROVED_EVASION, target, TRUE) == TRUE)
                        damage /= 2;
                }
                else
                {
                    if (s.GetHasFeat(FEAT_EVASION, target, TRUE) == TRUE)
                        damage = 0;
                    else damage /= 2;
                }
            }
            else
            {
                int roll = new Random().Next(20) + 1;
                int final = roll + trap.AttackBonus;
                string hitormiss = " *hit* ";
                if (final < s.GetAC(target, FALSE) && roll != 20)
                {
                    hitormiss = " *miss* ";
                    damage = 0;
                }
                s.SendMessageToPC(target, "<C=DarkViolet>Trap</C><C=DarkOrange> attacks " + s.GetName(target) + ":" + hitormiss + ": " + roll + " + " + trap.AttackBonus + " = " + final);
            }

            NWEffect eVis = s.EffectVisualEffect(VFX_COM_HIT_DIVINE, FALSE);

            List<int> damageTypes = new List<int>();
            if ((trap.DamageType & DAMAGE_TYPE_ACID) == DAMAGE_TYPE_ACID)
            {
                damageTypes.Add(DAMAGE_TYPE_ACID);
                eVis = s.EffectVisualEffect(VFX_COM_HIT_ACID, FALSE);
            }
            if ((trap.DamageType & DAMAGE_TYPE_BLUDGEONING) == DAMAGE_TYPE_BLUDGEONING)
            {
                damageTypes.Add(DAMAGE_TYPE_BLUDGEONING);
                eVis = s.EffectVisualEffect(VFX_COM_BLOOD_CRT_RED, FALSE);
            }
            if ((trap.DamageType & DAMAGE_TYPE_COLD) == DAMAGE_TYPE_COLD)
            {
                damageTypes.Add(DAMAGE_TYPE_COLD);
                eVis = s.EffectVisualEffect(VFX_COM_HIT_FROST, FALSE);
            }
            if ((trap.DamageType & DAMAGE_TYPE_DIVINE) == DAMAGE_TYPE_DIVINE)
            {
                damageTypes.Add(DAMAGE_TYPE_DIVINE);
                eVis = s.EffectVisualEffect(VFX_COM_HIT_DIVINE, FALSE);
            }
            if ((trap.DamageType & DAMAGE_TYPE_ELECTRICAL) == DAMAGE_TYPE_ELECTRICAL)
            {
                damageTypes.Add(DAMAGE_TYPE_ELECTRICAL);
                eVis = s.EffectVisualEffect(VFX_COM_HIT_ELECTRICAL, FALSE);
            }
            if ((trap.DamageType & DAMAGE_TYPE_FIRE) == DAMAGE_TYPE_FIRE)
            {
                damageTypes.Add(DAMAGE_TYPE_FIRE);
                eVis = s.EffectVisualEffect(VFX_COM_HIT_FIRE, FALSE);
            }
            if ((trap.DamageType & DAMAGE_TYPE_MAGICAL) == DAMAGE_TYPE_MAGICAL)
            {
                damageTypes.Add(DAMAGE_TYPE_MAGICAL);
                eVis = s.EffectVisualEffect(VFX_COM_HIT_DIVINE, FALSE);
            }
            if ((trap.DamageType & DAMAGE_TYPE_NEGATIVE) == DAMAGE_TYPE_NEGATIVE)
            {
                damageTypes.Add(DAMAGE_TYPE_NEGATIVE);
                eVis = s.EffectVisualEffect(VFX_COM_HIT_NEGATIVE, FALSE);
            }
            if ((trap.DamageType & DAMAGE_TYPE_PIERCING) == DAMAGE_TYPE_PIERCING)
            {
                damageTypes.Add(DAMAGE_TYPE_PIERCING);
                eVis = s.EffectVisualEffect(VFX_COM_BLOOD_CRT_RED, FALSE);
            }
            if ((trap.DamageType & DAMAGE_TYPE_POSITIVE) == DAMAGE_TYPE_POSITIVE)
            {
                damageTypes.Add(DAMAGE_TYPE_POSITIVE);
                eVis = s.EffectVisualEffect(VFX_COM_HIT_DIVINE, FALSE);
            }
            if ((trap.DamageType & DAMAGE_TYPE_SLASHING) == DAMAGE_TYPE_SLASHING)
            {
                damageTypes.Add(DAMAGE_TYPE_SLASHING);
                eVis = s.EffectVisualEffect(VFX_COM_BLOOD_CRT_RED, FALSE);
            }
            if ((trap.DamageType & DAMAGE_TYPE_SONIC) == DAMAGE_TYPE_SONIC)
            {
                damageTypes.Add(DAMAGE_TYPE_SONIC);
                eVis = s.EffectVisualEffect(VFX_COM_HIT_SONIC, FALSE);
            }

            if (damage == 0)
            {
                return eVis;
            }

            NWEffect eDam = eVis;
            damage /= damageTypes.Count;
            if (damage < 1) damage = 1;
            foreach (int dmgType in damageTypes)
            {
                eDam = s.EffectLinkEffects(eDam, s.EffectDamage(damage, dmgType, DAMAGE_POWER_NORMAL, FALSE));
            }

            return eDam;
        }
 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 NewArmor(CLRScriptBase script, int maxValue)
        {
            #region Calculate Armor Type
            List<int> possibleBaseItems = new List<int>();
            foreach (int armorType in ArmorResRefs.Keys)
            {
                if (Pricing.ArmorRulesTypeValues[armorType] <= maxValue)
                {
                    possibleBaseItems.Add(armorType);
                }
            }
            if (possibleBaseItems.Count == 0)
            {
                // Can't afford any armor. What are we doing here?
                return 0;
            }
            int selectedArmorType = possibleBaseItems[Generation.rand.Next(possibleBaseItems.Count)];
            int armorValue = Pricing.ArmorRulesTypeValues[selectedArmorType];
            maxValue -= armorValue;
            uint armor = script.CreateItemOnObject(ArmorResRefs[selectedArmorType], script.OBJECT_SELF, 1, "", FALSE);
            #endregion

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

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

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

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

            #region Armor Personality
            SetPersonalityProperties(script, armor, armorTheme, enhancementBonus, ref effectivePlusRemaining, ref currentEffectivePlus);
            armorValue += (int)(currentEffectivePlus * currentEffectivePlus * 1000);
            Pricing.CalculatePrice(script, armor);
            return armorValue;
            #endregion
        }
示例#11
0
        public static uint _SpawnObject(string sResRef, int nObjectType, uint oWP, NWLocation lLoc, int nFlags, int nAlternate, CLRScriptBase s)
        {
            // if the object is not being spawned at it's waypoint location, we need to make sure
            // the actual spawn-in location isn't violating the "in PC sight" guidelines.
            if ((nAlternate != CLRScriptBase.FALSE) && ((nFlags & _SPAWN_FLAGS_IN_PC_SIGHT) == 0))
            {
                uint oNeighbor = s.GetNearestCreatureToLocation(CLRScriptBase.CREATURE_TYPE_PLAYER_CHAR, CLRScriptBase.PLAYER_CHAR_IS_PC, lLoc, 1, -1, -1, -1, -1);
                if (s.GetIsObjectValid(oNeighbor) == CLRScriptBase.FALSE && (s.GetDistanceBetweenLocations(lLoc, s.GetLocation(oNeighbor)) <= PC_PERCEPTION_RANGE))
                { // ACR_GetPCVisualRange() )) {
                    return CLRScriptBase.OBJECT_INVALID;
                }
                if (GetPrespawnPrediction(s) == CLRScriptBase.FALSE)
                {
                    uint oTestWP = s.GetNearestObjectToLocation(CLRScriptBase.OBJECT_TYPE_WAYPOINT, lLoc, 1);
                    int nWP_Index = 1;
                    while ((oTestWP != CLRScriptBase.OBJECT_INVALID) && (s.GetDistanceBetweenLocations(lLoc, s.GetLocation(oTestWP)) <= PC_PERCEPTION_RANGE))
                    { // ACR_GetPC_VisualRange() )) {
                        if (s.GetTag(oTestWP) == "ACR_SA_WP")
                        {
                            return CLRScriptBase.OBJECT_INVALID;
                        }
                        else
                        {
                            nWP_Index = nWP_Index + 1;
                            oTestWP = s.GetNearestObjectToLocation(CLRScriptBase.OBJECT_TYPE_WAYPOINT, lLoc, nWP_Index);
                        }
                    }
                }
            }

            uint oSpawned = s.CreateObject(nObjectType, sResRef, lLoc, nFlags & _SPAWN_FLAGS_WITH_ANIMATION, "");

            // Check to make sure it spawned ok, print an error and exit if not.
            if (s.GetIsObjectValid(oSpawned) == CLRScriptBase.FALSE)
            {
                return CLRScriptBase.OBJECT_INVALID;
            }

            // If it should be in stealth mode, place it there.
            if ((nFlags & _SPAWN_IN_STEALTH) == _SPAWN_IN_STEALTH)
            {
                s.SetActionMode(oSpawned, CLRScriptBase.ACTION_MODE_STEALTH, 1);
            }

            // If it should be in detect mode, place it there.
            if ((nFlags & _SPAWN_IN_DETECT) == _SPAWN_IN_DETECT)
            {
                s.SetActionMode(oSpawned, CLRScriptBase.ACTION_MODE_DETECT, 1);
            }

            // If this creature should buff himself, do it.
            if ((nFlags & _SPAWN_BUFFED) == _SPAWN_BUFFED)
            {
                ActivateLongTermBuffs(oSpawned, s);
            }

            // Play the spawn animation.
            s.PlayAnimation(s.GetLocalInt(oWP, _WP_SPAWN_ANIMATION), 1.0f, 0.0f);

            // Play the spawn in VFX.
            s.ApplyEffectAtLocation(CLRScriptBase.DURATION_TYPE_INSTANT, s.EffectVisualEffect(s.GetLocalInt(oWP, _WP_SPAWN_IN_VFX), CLRScriptBase.FALSE), s.GetLocation(oSpawned), 0.0f);

            // Play the spawn in SFX.
            s.AssignCommand(oSpawned, delegate { s.PlaySound(s.GetLocalString(oWP, _WP_SPAWN_IN_SFX), CLRScriptBase.FALSE); });

            // Determine facing.
            if ((nFlags & _SPAWN_FLAGS_RANDOM_FACING) == _SPAWN_FLAGS_RANDOM_FACING)
            {
                // Spawn facing is random.
                s.AssignCommand(oSpawned, delegate { s.SetFacing(new Random().Next() * 360.0f, CLRScriptBase.FALSE); });
            }

            // Colorize name if needed.
            if (s.GetLocalString(oSpawned, ACR_COLOR_NAME) != "")
            {
                s.SetFirstName(oSpawned, "<C='" + s.GetLocalString(oSpawned, ACR_COLOR_NAME) + "'>" + s.GetName(oSpawned) + "</C>");
                s.SetLastName(oSpawned, "");
            }

            // Run the spawn-in scripts, if any.
            int i = 1;
            while (true)
            {
                string sScript = s.GetLocalString(oWP, _WP_SPAWN_IN_SCRIPT_ARRAY + s.IntToString(i));
                if (sScript == "")
                {
                    break;
                }
                s.ExecuteScript(sScript, oSpawned);
                i++;
            }

            _AddObjectToSpawnPoint(oWP, oSpawned, s);

            return oSpawned;
        }
        public static int NewWeapon(CLRScriptBase script, int maxValue)
        {
            int itemType = SelectWeaponType(ref maxValue);
            int weaponValue = Pricing.BaseItemValues[itemType];
            maxValue -= weaponValue;
            generateId++;
            uint weapon = script.CreateItemOnObject(WeaponResrefs[itemType], script.OBJECT_SELF, 1, WeaponResrefs[itemType]+generateId.ToString(), FALSE);

            #region About +1.4 weapons
            if (maxValue > 4220)
            {
                if (Generation.rand.Next(10) > 0)
                {
                    if (Pricing.GetIsAmmunition(itemType))
                    {
                        if (itemType == BASE_ITEM_BULLET)
                        {
                            script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyDamageBonus(IP_CONST_DAMAGETYPE_BLUDGEONING, 1), weapon, 0.0f);
                        }
                        else
                        {
                            script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyDamageBonus(IP_CONST_DAMAGETYPE_PIERCING, 1), weapon, 0.0f);
                        }
                    }
                    else
                    {
                        script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyEnhancementBonus(1), weapon, 0.0f);
                    }
                    switch (Generation.rand.Next(7))
                    {
                        case 0:
                            script.SetFirstName(weapon, "Flametouched " + script.GetName(weapon) + " +1");
                            script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyDamageBonus(IP_CONST_DAMAGETYPE_FIRE, 1), weapon, 0.0f);
                            if (Pricing.GetIsAmmunition(itemType))
                            {
                                weaponValue += 1600;
                            }
                            else
                            {
                                weaponValue += 4220;
                            }
                            break;
                        case 1:
                            script.SetFirstName(weapon, "Frosttouched " + script.GetName(weapon) + " +1");
                            script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyDamageBonus(IP_CONST_DAMAGETYPE_COLD, 1), weapon, 0.0f);
                            if (Pricing.GetIsAmmunition(itemType))
                            {
                                weaponValue += 1600;
                            }
                            else
                            {
                                weaponValue += 4220;
                            }
                            break;
                        case 3:
                            script.SetFirstName(weapon, "Acidtouched " + script.GetName(weapon) + " +1");
                            script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyDamageBonus(IP_CONST_DAMAGETYPE_ACID, 1), weapon, 0.0f);
                            if (Pricing.GetIsAmmunition(itemType))
                            {
                                weaponValue += 1600;
                            }
                            else
                            {
                                weaponValue += 4220;
                            }
                            break;
                        case 4:
                            script.SetFirstName(weapon, "Sparktouched " + script.GetName(weapon) + " +1");
                            script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyDamageBonus(IP_CONST_DAMAGETYPE_ELECTRICAL, 1), weapon, 0.0f);
                            if (Pricing.GetIsAmmunition(itemType))
                            {
                                weaponValue += 1600;
                            }
                            else
                            {
                                weaponValue += 4220;
                            }
                            break;
                        case 5:
                            script.SetFirstName(weapon, "Humming " + script.GetName(weapon) + " +1");
                            script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyDamageBonus(IP_CONST_DAMAGETYPE_SONIC, 1), weapon, 0.0f);
                            if (Pricing.GetIsAmmunition(itemType))
                            {
                                weaponValue += 1600;
                            }
                            else
                            {
                                weaponValue += 4220;
                            }
                            break;
                        case 6:
                            script.SetFirstName(weapon, "Blessed " + script.GetName(weapon) + " +1");
                            script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyDamageBonusVsAlign(IP_CONST_ALIGNMENTGROUP_EVIL, IP_CONST_DAMAGETYPE_MAGICAL, 1), weapon, 0.0f);
                            if (Pricing.GetIsAmmunition(itemType))
                            {
                                weaponValue += 1500;
                            }
                            else
                            {
                                weaponValue += 3945;
                            }
                            break;
                    }
                }
                else
                {
                    script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyEnhancementBonus(1), weapon, 0.0f);
                    script.SetFirstName(weapon, script.GetName(weapon) + " +1");
                    weaponValue += 2300;
                }
            }
            #endregion

            #region Simple Enchantment, +1
            else if (maxValue > 2300)
            {
                if (Generation.rand.Next(10) > 0)
                {
                    script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyEnhancementBonus(1), weapon, 0.0f);
                    script.SetFirstName(weapon, script.GetName(weapon) + " +1");
                    weaponValue += 2300;
                }
                else
                {
                    script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyAttackBonus(1), weapon, 0.0f);
                    script.SetFirstName(weapon, "Masterwork " + script.GetName(weapon));
                    weaponValue += 300;
                }
            }
            #endregion

            #region Simple Bonus Damage, < +1 equiv
            else if (maxValue > 1100)
            {
                if (Generation.rand.Next(10) > 0)
                {
                    script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyAttackBonus(1), weapon, 0.0f);
                    switch (Generation.rand.Next(7))
                    {
                        case 0:
                            script.SetFirstName(weapon, "Flametouched " + script.GetName(weapon));
                            script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyDamageBonus(IP_CONST_DAMAGETYPE_FIRE, 1), weapon, 0.0f);
                            weaponValue += 1100;
                            break;
                        case 1:
                            script.SetFirstName(weapon, "Frosttouched " + script.GetName(weapon));
                            script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyDamageBonus(IP_CONST_DAMAGETYPE_COLD, 1), weapon, 0.0f);
                            weaponValue += 1100;
                            break;
                        case 3:
                            script.SetFirstName(weapon, "Acidtouched " + script.GetName(weapon));
                            script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyDamageBonus(IP_CONST_DAMAGETYPE_ACID, 1), weapon, 0.0f);
                            weaponValue += 1100;
                            break;
                        case 4:
                            script.SetFirstName(weapon, "Sparktouched " + script.GetName(weapon));
                            script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyDamageBonus(IP_CONST_DAMAGETYPE_ELECTRICAL, 1), weapon, 0.0f);
                            weaponValue += 1100;
                            break;
                        case 5:
                            script.SetFirstName(weapon, "Humming " + script.GetName(weapon));
                            script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyDamageBonus(IP_CONST_DAMAGETYPE_SONIC, 1), weapon, 0.0f);
                            weaponValue += 1100;
                            break;
                        case 6:
                            script.SetFirstName(weapon, "Blessed " + script.GetName(weapon));
                            script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyDamageBonusVsAlign(IP_CONST_ALIGNMENTGROUP_EVIL, IP_CONST_DAMAGETYPE_MAGICAL, 1), weapon, 0.0f);
                            weaponValue += 1000;
                            break;
                    }
                }
                else
                {
                    script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyAttackBonus(1), weapon, 0.0f);
                    script.SetFirstName(weapon, "Masterwork " + script.GetName(weapon));
                    weaponValue += 300;
                }

            }
            #endregion

            #region Masterwork Only
            else if (maxValue > 300)
            {
                if (Generation.rand.Next(10) > 0)
                {
                    script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyAttackBonus(1), weapon, 0.0f);
                    script.SetFirstName(weapon, "Masterwork " + script.GetName(weapon));
                    weaponValue += 300;
                }
            }
            #endregion

            if (Pricing.GetIsAmmunition(itemType))
            {
                script.SetItemStackSize(weapon, 50, FALSE);
                weaponValue /= 2;
            }
            Pricing.CalculatePrice(script, weapon);

            return weaponValue;
        }
        public static void DrawObjects(CLRScriptBase script, User currentUser, uint currentArea)
        {
            float fDelay = 0.1f;
            List<uint> ChooserAoEs = new List<uint>();
            List<uint> ChooserCreatures = new List<uint>();
            List<uint> ChooserDoors = new List<uint>();
            List<uint> ChooserItems = new List<uint>();
            List<uint> ChooserLights = new List<uint>();
            List<uint> ChooserPlaceables = new List<uint>();
            List<uint> ChooserPlacedEffects = new List<uint>();
            List<uint> ChooserStores = new List<uint>();
            List<uint> ChooserTriggers = new List<uint>();
            List<uint> ChooserWaypoints = new List<uint>();
            script.DelayCommand(fDelay, delegate
            {
                foreach (uint thing in script.GetObjectsInArea(currentArea))
                {
                    int objectType = script.GetObjectType(thing);
                    switch (objectType)
                    {
                        case OBJECT_TYPE_AREA_OF_EFFECT:
                            ChooserAoEs.Add(thing);
                            break;
                        case OBJECT_TYPE_CREATURE:
                            ChooserCreatures.Add(thing);
                            break;
                        case OBJECT_TYPE_DOOR:
                            ChooserDoors.Add(thing);
                            break;
                        case OBJECT_TYPE_ITEM:
                            ChooserItems.Add(thing);
                            break;
                        case OBJECT_TYPE_LIGHT:
                            ChooserLights.Add(thing);
                            break;
                        case OBJECT_TYPE_PLACEABLE:
                            ChooserPlaceables.Add(thing);
                            break;
                        case OBJECT_TYPE_PLACED_EFFECT:
                            ChooserPlacedEffects.Add(thing);
                            break;
                        case OBJECT_TYPE_STORE:
                            ChooserStores.Add(thing);
                            break;
                        case OBJECT_TYPE_TRIGGER:
                            ChooserTriggers.Add(thing);
                            break;
                        case OBJECT_TYPE_WAYPOINT:
                            ChooserWaypoints.Add(thing);
                            break;
                    }
                }
                script.ClearListBox(currentUser.Id, "SCREEN_DMC_CHOOSER", "LISTBOX_ACR_CHOOSER_OBJECTS");
                if (ChooserAoEs.Count > 0 && currentUser.ChooserShowAOE)
                {
                    fDelay += 0.1f;
                    script.DelayCommand(fDelay, delegate
                    {
                        foreach (uint thing in ChooserAoEs)
                        {
                            script.AddListBoxRow(currentUser.Id, "SCREEN_DMC_CHOOSER", "LISTBOX_ACR_CHOOSER_OBJECTS", thing.ToString(), "LISTBOX_ITEM_TEXT=  " + script.GetTag(thing), "LISTBOX_ITEM_ICON=trap.tga", "5="+thing.ToString(), "");
                        }
                    });
                }
                if (ChooserCreatures.Count > 0 && currentUser.ChooserShowCreature)
                {
                    fDelay += 0.1f;
                    script.DelayCommand(fDelay, delegate
                    {
                        foreach (uint thing in ChooserCreatures)
                        {
                            script.AddListBoxRow(currentUser.Id, "SCREEN_DMC_CHOOSER", "LISTBOX_ACR_CHOOSER_OBJECTS", thing.ToString(), "LISTBOX_ITEM_TEXT=  " + script.GetName(thing), "LISTBOX_ITEM_ICON=creature.tga", "5=" + thing.ToString(), "");
                        }
                    });
                }
                if (ChooserDoors.Count > 0 && currentUser.ChooserShowDoor)
                {
                    fDelay += 0.1f;
                    script.DelayCommand(fDelay, delegate
                    {
                        foreach (uint thing in ChooserDoors)
                        {
                            script.AddListBoxRow(currentUser.Id, "SCREEN_DMC_CHOOSER", "LISTBOX_ACR_CHOOSER_OBJECTS", thing.ToString(), "LISTBOX_ITEM_TEXT=  " + script.GetName(thing), "LISTBOX_ITEM_ICON=door.tga", "5=" + thing.ToString(), "");
                        }
                    });
                }
                if (ChooserItems.Count > 0 && currentUser.ChooserShowItem)
                {
                    fDelay += 0.1f;
                    script.DelayCommand(fDelay, delegate
                    {
                        foreach (uint thing in ChooserItems)
                        {
                            script.AddListBoxRow(currentUser.Id, "SCREEN_DMC_CHOOSER", "LISTBOX_ACR_CHOOSER_OBJECTS", thing.ToString(), "LISTBOX_ITEM_TEXT=  " + script.GetName(thing), "LISTBOX_ITEM_ICON=item.tga", "5=" + thing.ToString(), "");
                        }
                    });
                }
                if (ChooserLights.Count > 0 && currentUser.ChooserShowLight)
                {
                    fDelay += 0.1f;
                    script.DelayCommand(fDelay, delegate
                    {
                        foreach (uint thing in ChooserLights)
                        {
                            script.AddListBoxRow(currentUser.Id, "SCREEN_DMC_CHOOSER", "LISTBOX_ACR_CHOOSER_OBJECTS", thing.ToString(), "LISTBOX_ITEM_TEXT=  " + script.GetName(thing) + ";LISTBOX_ITEM_TEXT2= Light", "LISTBOX_ITEM_ICON=light.tga", "5=" + thing.ToString(), "");
                        }
                    });
                }
                if (ChooserPlaceables.Count > 0 && currentUser.ChooserShowPlaceable)
                {
                    fDelay += 0.1f;
                    script.DelayCommand(fDelay, delegate
                    {
                        foreach (uint thing in ChooserPlaceables)
                        {

                            script.AddListBoxRow(currentUser.Id, "SCREEN_DMC_CHOOSER", "LISTBOX_ACR_CHOOSER_OBJECTS", thing.ToString(), "LISTBOX_ITEM_TEXT=  " + script.GetName(thing) + ";LISTBOX_ITEM_TEXT2= Placeable", "LISTBOX_ITEM_ICON=placeable.tga", "5=" + thing.ToString(), "");
                        }
                    });
                }
                if (ChooserPlacedEffects.Count > 0 && currentUser.ChooserShowPlacedEffect)
                {
                    fDelay += 0.1f;
                    script.DelayCommand(fDelay, delegate
                    {
                        foreach (uint thing in ChooserPlacedEffects)
                        {
                            script.AddListBoxRow(currentUser.Id, "SCREEN_DMC_CHOOSER", "LISTBOX_ACR_CHOOSER_OBJECTS", thing.ToString(), "LISTBOX_ITEM_TEXT=  " + script.GetName(thing) + ";LISTBOX_ITEM_TEXT2= Placed Effect", "LISTBOX_ITEM_ICON=vfx.tga", "5=" + thing.ToString(), "");
                        }
                    });
                }
                if (ChooserStores.Count > 0 && currentUser.ChooserShowStore)
                {
                    fDelay += 0.1f;
                    script.DelayCommand(fDelay, delegate
                    {
                        foreach (uint thing in ChooserStores)
                        {
                            script.AddListBoxRow(currentUser.Id, "SCREEN_DMC_CHOOSER", "LISTBOX_ACR_CHOOSER_OBJECTS", thing.ToString(), "LISTBOX_ITEM_TEXT=  " + script.GetName(thing) + ";LISTBOX_ITEM_TEXT2= Store", "LISTBOX_ITEM_ICON=store.tga", "5=" + thing.ToString(), "");
                        }
                    });
                }
                if (ChooserTriggers.Count > 0 && currentUser.ChooserShowTrigger)
                {
                    fDelay += 0.1f;
                    script.DelayCommand(fDelay, delegate
                    {
                        foreach (uint thing in ChooserTriggers)
                        {
                            script.AddListBoxRow(currentUser.Id, "SCREEN_DMC_CHOOSER", "LISTBOX_ACR_CHOOSER_OBJECTS", thing.ToString(), "LISTBOX_ITEM_TEXT=  " + script.GetName(thing) + ";LISTBOX_ITEM_TEXT2= Trigger", "LISTBOX_ITEM_ICON=trigger.tga", "5=" + thing.ToString(), "");
                        }
                    });
                }
                if (ChooserWaypoints.Count > 0 && currentUser.ChooserShowWaypoint)
                {
                    fDelay += 0.1f;
                    script.DelayCommand(fDelay, delegate
                    {
                        foreach (uint thing in ChooserWaypoints)
                        {
                            script.AddListBoxRow(currentUser.Id, "SCREEN_DMC_CHOOSER", "LISTBOX_ACR_CHOOSER_OBJECTS", thing.ToString(), "LISTBOX_ITEM_TEXT=  " + script.GetName(thing) + ";LISTBOX_ITEM_TEXT2=  Waypoint", "LISTBOX_ITEM_ICON=waypoint.tga", "5=" + thing.ToString(), "");
                        }
                    });
                }
            });
        }
 public static void DrawLimbo(CLRScriptBase script, User currentUser)
 {
     script.ClearListBox(currentUser.Id, "SCREEN_DMC_CHOOSER", "LISTBOX_ACR_LIMBO_OBJECTS");
     int max = script.GetLimboCreatureCount();
     int count = 0;
     while (count < max)
     {
         uint thing = script.GetCreatureInLimbo(count);
         if (script.GetIsObjectValid(thing) == TRUE)
         {
             script.AddListBoxRow(currentUser.Id, "SCREEN_DMC_CHOOSER", "LISTBOX_ACR_LIMBO_OBJECTS", thing.ToString(), "LISTBOX_ITEM_TEXT=  " + script.GetName(thing), "LISTBOX_ITEM_ICON=creature.tga", "5=" + thing.ToString(), "");
         }
         count++;
     }
 }
 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 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;
 }
 private static void SetPersonalityProperties(CLRScriptBase script, uint armor, Generation.Theme theme, int baseEnhancement, ref double effectivePlusRemaining, ref double currentEffectivePlus)
 {
     switch (theme)
     {
         case Generation.Theme.Acid:
         case Generation.Theme.Cold:
         case Generation.Theme.Fire:
         case Generation.Theme.Electricity:
         case Generation.Theme.Sound:
             {
                 if (effectivePlusRemaining >= (1.0 / 3.0))
                 {
                     int vsElementalAC = 0;
                     if (effectivePlusRemaining >= (4.0 / 3.0))
                     {
                         vsElementalAC = baseEnhancement + 4;
                     }
                     else if (effectivePlusRemaining >= 1.0)
                     {
                         vsElementalAC = baseEnhancement + 3;
                     }
                     else if (effectivePlusRemaining >= (2.0 / 3.0))
                     {
                         vsElementalAC = baseEnhancement + 2;
                     }
                     else
                     {
                         vsElementalAC = baseEnhancement + 1;
                     }
                     if (vsElementalAC > 5) vsElementalAC = 5;
                     if (vsElementalAC > baseEnhancement)
                     {
                         script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyACBonusVsRace(IP_CONST_RACIALTYPE_ELEMENTAL, vsElementalAC), armor, 0.0f);
                         script.SetFirstName(armor, String.Format("{0} of Elementalwarding", script.GetName(armor)));
                         effectivePlusRemaining -= ((double)(vsElementalAC - baseEnhancement)) / 3.0;
                         currentEffectivePlus += ((double)(vsElementalAC - baseEnhancement)) / 3.0;
                         return;
                     }
                 }
                 return;
             }
         case Generation.Theme.ConstructSlaying:
             {
                 if (effectivePlusRemaining >= (1.0 / 3.0))
                 {
                     int vsConstructAC = 0;
                     if (effectivePlusRemaining >= (4.0 / 3.0))
                     {
                         vsConstructAC = baseEnhancement + 4;
                     }
                     else if (effectivePlusRemaining >= 1.0)
                     {
                         vsConstructAC = baseEnhancement + 3;
                     }
                     else if (effectivePlusRemaining >= (2.0 / 3.0))
                     {
                         vsConstructAC = baseEnhancement + 2;
                     }
                     else
                     {
                         vsConstructAC = baseEnhancement + 1;
                     }
                     if (vsConstructAC > 5) vsConstructAC = 5;
                     if (vsConstructAC > baseEnhancement)
                     {
                         script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyACBonusVsRace(IP_CONST_RACIALTYPE_CONSTRUCT, vsConstructAC), armor, 0.0f);
                         script.SetFirstName(armor, String.Format("{0} of Golemwarding", script.GetName(armor)));
                         effectivePlusRemaining -= ((double)(vsConstructAC - baseEnhancement)) / 3.0;
                         currentEffectivePlus += ((double)(vsConstructAC - baseEnhancement)) / 3.0;
                         return;
                     }
                 }
                 return;
             }
         case Generation.Theme.DemonSlaying:
         case Generation.Theme.DevilSlaying:
             {
                 if (effectivePlusRemaining >= (1.0 / 3.0))
                 {
                     int vsOutsiderAC = 0;
                     if (effectivePlusRemaining >= (4.0 / 3.0))
                     {
                         vsOutsiderAC = baseEnhancement + 4;
                     }
                     else if (effectivePlusRemaining >= 1.0)
                     {
                         vsOutsiderAC = baseEnhancement + 3;
                     }
                     else if (effectivePlusRemaining >= (2.0 / 3.0))
                     {
                         vsOutsiderAC = baseEnhancement + 2;
                     }
                     else
                     {
                         vsOutsiderAC = baseEnhancement + 1;
                     }
                     if (vsOutsiderAC > 5) vsOutsiderAC = 5;
                     if (vsOutsiderAC > baseEnhancement)
                     {
                         script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyACBonusVsRace(IP_CONST_RACIALTYPE_OUTSIDER, vsOutsiderAC), armor, 0.0f);
                         script.SetFirstName(armor, String.Format("{0} of Fiendwarding", script.GetName(armor)));
                         effectivePlusRemaining -= ((double)(vsOutsiderAC - baseEnhancement)) / 3.0;
                         currentEffectivePlus += ((double)(vsOutsiderAC - baseEnhancement)) / 3.0;
                         return;
                     }
                 }
                 return;
             }
         case Generation.Theme.DragonSlaying:
             {
                 if (effectivePlusRemaining >= (1.0 / 3.0))
                 {
                     int vsDragonAC = 0;
                     if (effectivePlusRemaining >= (4.0 / 3.0))
                     {
                         vsDragonAC = baseEnhancement + 4;
                     }
                     else if (effectivePlusRemaining >= 1.0)
                     {
                         vsDragonAC = baseEnhancement + 3;
                     }
                     else if (effectivePlusRemaining >= (2.0 / 3.0))
                     {
                         vsDragonAC = baseEnhancement + 2;
                     }
                     else
                     {
                         vsDragonAC = baseEnhancement + 1;
                     }
                     if (vsDragonAC > 5) vsDragonAC = 5;
                     if (vsDragonAC > baseEnhancement)
                     {
                         script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyACBonusVsRace(IP_CONST_RACIALTYPE_DRAGON, vsDragonAC), armor, 0.0f);
                         script.SetFirstName(armor, String.Format("{0} of Dragonwarding", script.GetName(armor)));
                         effectivePlusRemaining -= ((double)(vsDragonAC - baseEnhancement)) / 3.0;
                         currentEffectivePlus += ((double)(vsDragonAC - baseEnhancement)) / 3.0;
                         return;
                     }
                 }
                 return;
             }
         case Generation.Theme.FeySlaying:
             {
                 if (effectivePlusRemaining >= (1.0 / 3.0))
                 {
                     int vsFeyAC = 0;
                     if (effectivePlusRemaining >= (4.0 / 3.0))
                     {
                         vsFeyAC = baseEnhancement + 4;
                     }
                     else if (effectivePlusRemaining >= 1.0)
                     {
                         vsFeyAC = baseEnhancement + 3;
                     }
                     else if (effectivePlusRemaining >= (2.0 / 3.0))
                     {
                         vsFeyAC = baseEnhancement + 2;
                     }
                     else
                     {
                         vsFeyAC = baseEnhancement + 1;
                     }
                     if (vsFeyAC > 5) vsFeyAC = 5;
                     if (vsFeyAC > baseEnhancement)
                     {
                         script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyACBonusVsRace(IP_CONST_RACIALTYPE_FEY, vsFeyAC), armor, 0.0f);
                         script.SetFirstName(armor, String.Format("{0} of Feywarding", script.GetName(armor)));
                         effectivePlusRemaining -= ((double)(vsFeyAC - baseEnhancement)) / 3.0;
                         currentEffectivePlus += ((double)(vsFeyAC - baseEnhancement)) / 3.0;
                         return;
                     }
                 }
                 return;
             }
         case Generation.Theme.GiantSlaying:
             {
                 if (effectivePlusRemaining >= (1.0 / 3.0))
                 {
                     int vsGiantAC = 0;
                     if (effectivePlusRemaining >= (4.0 / 3.0))
                     {
                         vsGiantAC = baseEnhancement + 4;
                     }
                     else if (effectivePlusRemaining >= 1.0)
                     {
                         vsGiantAC = baseEnhancement + 3;
                     }
                     else if (effectivePlusRemaining >= (2.0 / 3.0))
                     {
                         vsGiantAC = baseEnhancement + 2;
                     }
                     else
                     {
                         vsGiantAC = baseEnhancement + 1;
                     }
                     if (vsGiantAC > 5) vsGiantAC = 5;
                     if (vsGiantAC > baseEnhancement)
                     {
                         script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyACBonusVsRace(IP_CONST_RACIALTYPE_GIANT, vsGiantAC), armor, 0.0f);
                         script.SetFirstName(armor, String.Format("{0} of Giantwarding", script.GetName(armor)));
                         effectivePlusRemaining -= ((double)(vsGiantAC - baseEnhancement)) / 3.0;
                         currentEffectivePlus += ((double)(vsGiantAC - baseEnhancement)) / 3.0;
                         return;
                     }
                 }
                 return;
             }
         case Generation.Theme.Holy:
             {
                 if (effectivePlusRemaining >= 0.5)
                 {
                     int vsEvilAC = 0;
                     if (effectivePlusRemaining >= 2.0)
                     {
                         vsEvilAC = baseEnhancement + 4;
                     }
                     else if (effectivePlusRemaining >= 1.5)
                     {
                         vsEvilAC = baseEnhancement + 3;
                     }
                     else if (effectivePlusRemaining >= 1.0)
                     {
                         vsEvilAC = baseEnhancement + 2;
                     }
                     else if (effectivePlusRemaining >= 0.5)
                     {
                         vsEvilAC = baseEnhancement + 1;
                     }
                     if (vsEvilAC > 5) vsEvilAC = 5;
                     if (vsEvilAC > baseEnhancement)
                     {
                         script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyACBonusVsAlign(IP_CONST_ALIGNMENTGROUP_EVIL, vsEvilAC), armor, 0.0f);
                         script.SetFirstName(armor, String.Format("Holy {0}", script.GetName(armor)));
                         effectivePlusRemaining -= ((double)(vsEvilAC - baseEnhancement)) / 2.0;
                         currentEffectivePlus += ((double)(vsEvilAC - baseEnhancement)) / 2.0;
                         return;
                     }
                 }
                 return;
             }
         case Generation.Theme.Themeless:
             {
                 // Not much we can do with no theme. Return a less-than-max-value item
                 return;
             }
         case Generation.Theme.UndeadSlaying:
             {
                 if (effectivePlusRemaining >= (1.0 / 3.0))
                 {
                     int vsUndeadAC = 0;
                     if (effectivePlusRemaining >= (4.0 / 3.0))
                     {
                         vsUndeadAC = baseEnhancement + 4;
                     }
                     else if (effectivePlusRemaining >= 1.0)
                     {
                         vsUndeadAC = baseEnhancement + 3;
                     }
                     else if (effectivePlusRemaining >= (2.0 / 3.0))
                     {
                         vsUndeadAC = baseEnhancement + 2;
                     }
                     else
                     {
                         vsUndeadAC = baseEnhancement + 1;
                     }
                     if (vsUndeadAC > 5) vsUndeadAC = 5;
                     if (vsUndeadAC > baseEnhancement)
                     {
                         script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyACBonusVsRace(IP_CONST_RACIALTYPE_UNDEAD, vsUndeadAC), armor, 0.0f);
                         script.SetFirstName(armor, String.Format("{0} of Undeadwarding", script.GetName(armor)));
                         effectivePlusRemaining -= ((double)(vsUndeadAC - baseEnhancement)) / 3.0;
                         currentEffectivePlus += ((double)(vsUndeadAC - baseEnhancement)) / 3.0;
                         return;
                     }
                 }
                 return;
             }
         case Generation.Theme.Unholy:
             {
                 if (effectivePlusRemaining >= 0.5)
                 {
                     int vsGoodAC = 0;
                     if (effectivePlusRemaining >= 1.6)
                     {
                         vsGoodAC = baseEnhancement + 4;
                     }
                     else if (effectivePlusRemaining >= 1.2)
                     {
                         vsGoodAC = baseEnhancement + 3;
                     }
                     else if (effectivePlusRemaining >= 0.8)
                     {
                         vsGoodAC = baseEnhancement + 2;
                     }
                     else if (effectivePlusRemaining >= 0.4)
                     {
                         vsGoodAC = baseEnhancement + 1;
                     }
                     if (vsGoodAC > 5) vsGoodAC = 5;
                     if (vsGoodAC > baseEnhancement)
                     {
                         script.AddItemProperty(DURATION_TYPE_PERMANENT, script.ItemPropertyACBonusVsAlign(IP_CONST_ALIGNMENTGROUP_GOOD, vsGoodAC), armor, 0.0f);
                         script.SetFirstName(armor, String.Format("Unholy {0}", script.GetName(armor)));
                         effectivePlusRemaining -= ((double)(vsGoodAC - baseEnhancement)) * 2.0 / 5.0;
                         currentEffectivePlus += ((double)(vsGoodAC - baseEnhancement)) * 2.0 / 5.0;
                         return;
                     }
                 }
                 return;
             }
     }
 }
 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;
 }