public static void ApplyComponentBonus(NWItem product, ItemProperty sourceIP) { ComponentBonusType bonusType = (ComponentBonusType)_.GetItemPropertySubType(sourceIP); int amount = _.GetItemPropertyCostTableValue(sourceIP); ItemProperty prop = null; string sourceTag = string.Empty; int attackBonus = 0; // A note about the sourceTags: // It's not currently possible to create custom item properties on items. To get around this, // we look in an inaccessible container which holds the custom item properties. Then, we get the // item that has the item property we want. From there we take that item property and copy it to // the crafted item. // This is a really roundabout way to do it, but it's the only option for now. Hopefully a feature to // directly add the item properties comes in to NWNX in the future. // 2019-06-12: Directly modifying item properties is possible now but I'm not going to do a refactor until later. // Anyone interested in working on this let me know and I can point you in the right direction. - Z for (int x = 1; x <= amount; x++) { switch (bonusType) { case ComponentBonusType.ModSocketRed: sourceTag = "rslot_red"; break; case ComponentBonusType.ModSocketBlue: sourceTag = "rslot_blue"; break; case ComponentBonusType.ModSocketGreen: sourceTag = "rslot_green"; break; case ComponentBonusType.ModSocketYellow: sourceTag = "rslot_yellow"; break; case ComponentBonusType.ModSocketPrismatic: sourceTag = "rslot_prismatic"; break; case ComponentBonusType.DurabilityUp: var maxDur = DurabilityService.GetMaxDurability(product) + amount; DurabilityService.SetMaxDurability(product, maxDur); DurabilityService.SetDurability(product, maxDur); break; case ComponentBonusType.ChargesUp: product.Charges += amount; break; case ComponentBonusType.ACUp: product.CustomAC += amount; break; case ComponentBonusType.HarvestingUp: product.HarvestingBonus += amount; break; case ComponentBonusType.CooldownRecoveryUp: product.CooldownRecovery += amount; break; case ComponentBonusType.ArmorsmithUp: product.CraftBonusArmorsmith += amount; break; case ComponentBonusType.WeaponsmithUp: product.CraftBonusWeaponsmith += amount; break; case ComponentBonusType.CookingUp: product.CraftBonusCooking += amount; break; case ComponentBonusType.EngineeringUp: product.CraftBonusEngineering += amount; break; case ComponentBonusType.FabricationUp: product.CraftBonusFabrication += amount; break; case ComponentBonusType.HPUp: product.HPBonus += amount; break; case ComponentBonusType.FPUp: product.FPBonus += amount; break; case ComponentBonusType.EnmityUp: product.EnmityRate += amount; break; case ComponentBonusType.EnmityDown: product.EnmityRate -= amount; break; case ComponentBonusType.LuckUp: product.LuckBonus += amount; break; case ComponentBonusType.MeditateUp: product.MeditateBonus += amount; break; case ComponentBonusType.RestUp: product.RestBonus += amount; break; case ComponentBonusType.MedicineUp: product.MedicineBonus += amount; break; case ComponentBonusType.HPRegenUp: product.HPRegenBonus += amount; break; case ComponentBonusType.FPRegenUp: product.FPRegenBonus += amount; break; case ComponentBonusType.BaseAttackBonusUp: product.BaseAttackBonus += amount; break; case ComponentBonusType.SneakAttackUp: product.SneakAttackBonus += amount; break; case ComponentBonusType.DamageUp: product.DamageBonus += amount; break; case ComponentBonusType.StructureBonusUp: product.StructureBonus += amount; break; case ComponentBonusType.StrengthUp: product.StrengthBonus += amount; break; case ComponentBonusType.DexterityUp: product.DexterityBonus += amount; break; case ComponentBonusType.ConstitutionUp: product.ConstitutionBonus += amount; break; case ComponentBonusType.WisdomUp: product.WisdomBonus += amount; break; case ComponentBonusType.IntelligenceUp: product.IntelligenceBonus += amount; break; case ComponentBonusType.CharismaUp: product.CharismaBonus += amount; break; case ComponentBonusType.AttackBonusUp: attackBonus += amount; break; case ComponentBonusType.DurationUp: product.DurationBonus += amount; break; case ComponentBonusType.ScanningUp: product.ScanningBonus += amount; break; case ComponentBonusType.ScavengingUp: product.ScavengingBonus += amount; break; case ComponentBonusType.PilotingUp: product.PilotingBonus += amount; break; default: throw new ArgumentOutOfRangeException(); } if (!string.IsNullOrWhiteSpace(sourceTag)) { prop = ItemService.GetCustomItemPropertyByItemTag(sourceTag); } if (prop == null) { return; } BiowareXP2.IPSafeAddItemProperty(product, prop, 0.0f, AddItemPropertyPolicy.IgnoreExisting, true, true); } // Attack bonus is aggregated into one item property, ensuring that the amount doesn't go over 20. if (attackBonus > 0) { // Look for existing properties, get the value and add it. Then remove that item property. foreach (var ip in product.ItemProperties) { if (_.GetItemPropertyType(ip) == _.ITEM_PROPERTY_ATTACK_BONUS) { amount = _.GetItemPropertyCostTableValue(ip); attackBonus += amount; _.RemoveItemProperty(product, ip); } } // Clamp bonus to 20. if (attackBonus > 20) { attackBonus = 20; } // Time to add the new item property. prop = _.ItemPropertyAttackBonus(attackBonus); BiowareXP2.IPSafeAddItemProperty(product, prop, 0.0f, AddItemPropertyPolicy.ReplaceExisting, false, false); } }
public static Tuple <ItemProperty, int> GetRandomComponentBonusIP(ResourceQuality quality) { string[] commonIP = { "compbon_ac1", "compbon_arm1", "compbon_cspd1", "compbon_charges1", "compbon_charges2", "compbon_cooking1", "compbon_dmg1", "compbon_dur1", "compbon_dur2", "compbon_eng1", "compbon_enmdown1", "compbon_epup1", "compbon_epdown1", "compbon_edup1", "compbon_eddown1", "compbon_dpdown1", "compbon_dpup1", "compbon_dddown1", "compbon_ddup1", "compbon_lpdown1", "compbon_lpup1", "compbon_lddown1", "compbon_ldup1", "compbon_mpdown1", "compbon_mpup1", "compbon_mddown1", "compbon_mdup1", "compbon_harv1", "compbon_wpn1", "compbon_hp2", "compbon_fp2", "compbon_enmup1", "compbon_med1", "compbon_faid1", "compbon_fab1", "compbon_scanup1", "compbon_rest1", "compbon_ab1" }; string[] uncommonIP = { "compbon_ac2", "compbon_arm2", "compbon_cspd2", "compbon_charges3", "compbon_cooking2", "compbon_dmg2", "compbon_dur3", "compbon_eng2", "compbon_enmdown2", "compbon_epup2", "compbon_epdown2", "compbon_edup2", "compbon_eddown2", "compbon_dpdown2", "compbon_dpup2", "compbon_dddown2", "compbon_ddup2", "compbon_lpdown2", "compbon_lpup2", "compbon_lddown2", "compbon_ldup2", "compbon_mpdown2", "compbon_mpup2", "compbon_mddown2", "compbon_mdup2", "compbon_harv2", "compbon_wpn2", "compbon_hp4", "compbon_fp4", "compbon_enmup2", "compbon_luck1", "compbon_med2", "compbon_faid2", "compbon_hpregen1", "compbon_fpregen1", "compbon_snkatk1", "compbon_fab2", "compbon_scanup2", "compbon_rest2", "compbon_str1", "compbon_dex1", "compbon_con1", "compbon_wis1", "compbon_int1", "compbon_cha1", "compbon_ab2", "compbon_scavup1" }; string[] rareIP = { "compbon_ac3", "compbon_arm3", "compbon_cspd3", "compbon_cooking3", "compbon_dmg3", "compbon_eng3", "compbon_enmdown3", "compbon_epup3", "compbon_epdown3", "compbon_edup3", "compbon_eddown3", "compbon_dpdown3", "compbon_dpup3", "compbon_dddown3", "compbon_ddup3", "compbon_lpdown3", "compbon_lpup3", "compbon_lddown3", "compbon_ldup3", "compbon_mpdown3", "compbon_mpup3", "compbon_mddown3", "compbon_mdup3", "compbon_harv3", "compbon_wpn3", "compbon_hp6", "compbon_fp6", "compbon_enmup3", "compbon_luck2", "compbon_med3", "compbon_faid3", "compbon_hpregen2", "compbon_fpregen2", "compbon_snkatk2", "compbon_fab3", "compbon_scanup3", "compbon_rest3", "compbon_str2", "compbon_dex2", "compbon_con2", "compbon_wis2", "compbon_int2", "compbon_cha2", "compbon_ab3", "compbon_scavup2" }; string[] ultraRareIP = { "compbon_luck3", "compbon_hpregen3", "compbon_fpregen3", "compbon_snkatk3", "compbon_str3", "compbon_dex3", "compbon_con3", "compbon_wis3", "compbon_int3", "compbon_cha3", "compbon_fpup1", "compbon_faup1", "compbon_fdup1", "compbon_scavup3" }; // Order: Common, Uncommon, Rare, Ultra Rare int[] chance; switch (quality) { case ResourceQuality.Low: chance = new[] { 100, 0, 0, 0 }; break; case ResourceQuality.Normal: chance = new[] { 80, 20, 0, 0 }; break; case ResourceQuality.High: chance = new[] { 20, 40, 40, 0 }; break; case ResourceQuality.VeryHigh: chance = new[] { 0, 0, 70, 30 }; break; default: throw new ArgumentOutOfRangeException(nameof(quality)); } string[] setToUse = null; int index = RandomService.GetRandomWeightedIndex(chance); switch (index) { case 0: setToUse = commonIP; break; case 1: setToUse = uncommonIP; break; case 2: setToUse = rareIP; break; case 3: setToUse = ultraRareIP; break; } if (setToUse == null) { throw new NullReferenceException(nameof(setToUse)); } index = RandomService.Random(0, setToUse.Length - 1); string itemTag = setToUse[index]; return(new Tuple <ItemProperty, int>(ItemService.GetCustomItemPropertyByItemTag(itemTag), index)); }
public static Tuple <ItemProperty, int> GetRandomComponentBonusIP(ResourceQuality quality) { string[] normalIP = { "compbon_arm1", // Armorsmith 1 "compbon_cspd1", // Cooldown Recovery 1 "compbon_charges1", // Charges 1 //"compbon_cooking1", // Cooking 1 "compbon_dmg1", // Damage 1 "compbon_eng1", // Engineering 1 "compbon_enmdown1", // Enmity Down 1 "compbon_harv1", // Harvesting 1 "compbon_wpn1", // Weaponsmith 1 "compbon_hp2", // Hit Points 2 "compbon_fp2", // Force Points 2 "compbon_enmup1", // Enmity Up 1 "compbon_med1", // Meditate 1 "compbon_faid1", // Medicine 1 "compbon_fab1", // Fabrication 1 "compbon_scanup1", // Scanning 1 "compbon_rest1", // Rest 1 "compbon_ab1" // Attack Bonus 1 }; string[] highIP = { "compbon_arm2", // Armorsmith 2 "compbon_cspd2", // Cooldown Recovery 2 "compbon_charges2", // Charges 2 //"compbon_cooking2", // Cooking 2 "compbon_dmg2", // Damage 2 "compbon_eng2", // Engineering 2 "compbon_enmdown2", // Enmity Down 2 "compbon_harv2", // Harvesting 2 "compbon_wpn2", // Weaponsmith 2 "compbon_hp4", // Hit Points 4 "compbon_fp4", // Force Points 4 "compbon_enmup2", // Enmity Up 2 "compbon_luck1", // Luck 1 "compbon_med2", // Meditate 2 "compbon_faid2", // Medicine 2 "compbon_hpregen1", // HP Regen 1 "compbon_fpregen1", // FP Regen 1 "compbon_snkatk1", // Sneak Attack 1 "compbon_fab2", // Fabrication 2 "compbon_scanup2", // Scanning 2 "compbon_rest2", // Rest 2 "compbon_str1", // Strength 1 "compbon_dex1", // Dexterity 1 "compbon_con1", // Constitution 1 "compbon_wis1", // Wisdom 1 "compbon_int1", // Intelligence 1 "compbon_cha1", // Charisma 1 "compbon_ab2", // Attack Bonus 2 "compbon_scavup1" // Scavenging 1 }; string[] veryHighIP = { "compbon_arm3", // Armorsmith 3 "compbon_cspd3", // Cooldown Recovery 3 //"compbon_cooking3", // Cooking 3 "compbon_charges3", // Charges 3 "compbon_dmg3", // Damage 3 "compbon_eng3", // Engineering 3 "compbon_enmdown3", // Enmity Down 3 "compbon_harv3", // Harvesting 3 "compbon_wpn3", // Weaponsmith 3 "compbon_hp6", // Hit Points 6 "compbon_fp6", // Force Points 6 "compbon_enmup3", // Enmity Up 3 "compbon_luck2", // Luck 2 "compbon_med3", // Meditate 3 "compbon_faid3", // Medicine 3 "compbon_hpregen2", // HP Regen 2 "compbon_fpregen2", // FP Regen 2 "compbon_snkatk2", // Sneak Attack 2 "compbon_fab3", // Fabrication 3 "compbon_scanup3", // Scanning 3 "compbon_rest3", // Rest 3 "compbon_str2", // Strength 2 "compbon_dex2", // Dexterity 2 "compbon_con2", // Constitution 2 "compbon_wis2", // Wisdom 2 "compbon_int2", // Intelligence 2 "compbon_cha2", // Charisma 2 "compbon_ab3", // Attack Bonus 3 "compbon_scavup2" // Scavenging 2 }; string[] setToUse; switch (quality) { case ResourceQuality.Low: case ResourceQuality.Normal: setToUse = normalIP; break; case ResourceQuality.High: setToUse = highIP; break; case ResourceQuality.VeryHigh: setToUse = veryHighIP; break; default: throw new ArgumentOutOfRangeException(nameof(quality), quality, null); } int index = RandomService.Random(0, setToUse.Length - 1); string itemTag = setToUse[index]; return(new Tuple <ItemProperty, int>(ItemService.GetCustomItemPropertyByItemTag(itemTag), Colorize(itemTag))); }
public static void ApplyComponentBonus(NWItem product, ItemProperty sourceIP) { ComponentBonusType bonusType = (ComponentBonusType)_.GetItemPropertySubType(sourceIP); int amount = _.GetItemPropertyCostTableValue(sourceIP); ItemProperty prop = null; string sourceTag = string.Empty; // A note about the sourceTags: // It's not currently possible to create custom item properties on items. To get around this, // we look in an inaccessible container which holds the custom item properties. Then, we get the // item that has the item property we want. From there we take that item property and copy it to // the crafted item. // This is a really roundabout way to do it, but it's the only option for now. Hopefully a feature to // directly add the item properties comes in to NWNX in the future. for (int x = 1; x <= amount; x++) { switch (bonusType) { case ComponentBonusType.ModSocketRed: sourceTag = "rslot_red"; break; case ComponentBonusType.ModSocketBlue: sourceTag = "rslot_blue"; break; case ComponentBonusType.ModSocketGreen: sourceTag = "rslot_green"; break; case ComponentBonusType.ModSocketYellow: sourceTag = "rslot_yellow"; break; case ComponentBonusType.ModSocketPrismatic: sourceTag = "rslot_prismatic"; break; case ComponentBonusType.DurabilityUp: var maxDur = DurabilityService.GetMaxDurability(product) + amount; DurabilityService.SetMaxDurability(product, maxDur); DurabilityService.SetDurability(product, maxDur); break; case ComponentBonusType.ChargesUp: product.Charges += amount; break; case ComponentBonusType.ACUp: product.CustomAC += amount; break; case ComponentBonusType.HarvestingUp: product.HarvestingBonus += amount; break; case ComponentBonusType.CastingSpeedUp: product.CastingSpeed += amount; break; case ComponentBonusType.ArmorsmithUp: product.CraftBonusArmorsmith += amount; break; case ComponentBonusType.WeaponsmithUp: product.CraftBonusWeaponsmith += amount; break; case ComponentBonusType.CookingUp: product.CraftBonusCooking += amount; break; case ComponentBonusType.EngineeringUp: product.CraftBonusEngineering += amount; break; case ComponentBonusType.FabricationUp: product.CraftBonusFabrication += amount; break; case ComponentBonusType.HPUp: product.HPBonus += amount; break; case ComponentBonusType.FPUp: product.FPBonus += amount; break; case ComponentBonusType.EnmityUp: product.EnmityRate += amount; break; case ComponentBonusType.EnmityDown: product.EnmityRate -= amount; break; case ComponentBonusType.DarkPotencyUp: product.DarkPotencyBonus += amount; break; case ComponentBonusType.LightPotencyUp: product.LightPotencyBonus += amount; break; case ComponentBonusType.MindPotencyUp: product.MindPotencyBonus += amount; break; case ComponentBonusType.LuckUp: product.LuckBonus += amount; break; case ComponentBonusType.MeditateUp: product.MeditateBonus += amount; break; case ComponentBonusType.RestUp: product.RestBonus += amount; break; case ComponentBonusType.MedicineUp: product.MedicineBonus += amount; break; case ComponentBonusType.HPRegenUp: product.HPRegenBonus += amount; break; case ComponentBonusType.FPRegenUp: product.FPRegenBonus += amount; break; case ComponentBonusType.BaseAttackBonusUp: product.BaseAttackBonus += amount; break; case ComponentBonusType.SneakAttackUp: product.SneakAttackBonus += amount; break; case ComponentBonusType.DamageUp: product.DamageBonus += amount; break; case ComponentBonusType.DarkPotencyDown: product.DarkPotencyBonus -= amount; break; case ComponentBonusType.LightPotencyDown: product.LightPotencyBonus -= amount; break; case ComponentBonusType.StructureBonusUp: product.StructureBonus += amount; break; case ComponentBonusType.StrengthUp: product.StrengthBonus += amount; break; case ComponentBonusType.DexterityUp: product.DexterityBonus += amount; break; case ComponentBonusType.ConstitutionUp: product.ConstitutionBonus += amount; break; case ComponentBonusType.WisdomUp: product.WisdomBonus += amount; break; case ComponentBonusType.IntelligenceUp: product.IntelligenceBonus += amount; break; case ComponentBonusType.CharismaUp: product.CharismaBonus += amount; break; case ComponentBonusType.AttackBonusUp: prop = _.ItemPropertyAttackBonus(amount); break; case ComponentBonusType.DurationUp: product.DurationBonus += amount; break; case ComponentBonusType.ScanningUp: product.ScanningBonus += amount; break; case ComponentBonusType.ScavengingUp: product.ScavengingBonus += amount; break; case ComponentBonusType.MindPotencyDown: product.MindPotencyBonus -= amount; break; case ComponentBonusType.ElectricalPotencyUp: product.ElectricalPotencyBonus += amount; break; case ComponentBonusType.ElectricalPotencyDown: product.ElectricalPotencyBonus -= amount; break; case ComponentBonusType.ForcePotencyUp: product.ForcePotencyBonus += amount; break; case ComponentBonusType.ForcePotencyDown: product.ForcePotencyBonus -= amount; break; case ComponentBonusType.ForceAccuracyUp: product.ForceAccuracyBonus += amount; break; case ComponentBonusType.ForceAccuracyDown: product.ForceAccuracyBonus -= amount; break; case ComponentBonusType.ForceDefenseUp: product.ForceDefenseBonus += amount; break; case ComponentBonusType.ForceDefenseDown: product.ForceDefenseBonus -= amount; break; case ComponentBonusType.ElectricalDefenseUp: product.ElectricalDefenseBonus += amount; break; case ComponentBonusType.ElectricalDefenseDown: product.ElectricalDefenseBonus -= amount; break; case ComponentBonusType.MindDefenseUp: product.MindDefenseBonus += amount; break; case ComponentBonusType.MindDefenseDown: product.MindDefenseBonus -= amount; break; case ComponentBonusType.LightDefenseUp: product.LightDefenseBonus += amount; break; case ComponentBonusType.LightDefenseDown: product.LightDefenseBonus -= amount; break; case ComponentBonusType.DarkDefenseUp: product.DarkDefenseBonus += amount; break; case ComponentBonusType.DarkDefenseDown: product.DarkDefenseBonus -= amount; break; case ComponentBonusType.PilotingUp: product.PilotingBonus += amount; break; default: throw new ArgumentOutOfRangeException(); } if (!string.IsNullOrWhiteSpace(sourceTag)) { prop = ItemService.GetCustomItemPropertyByItemTag(sourceTag); } if (prop == null) { return; } BiowareXP2.IPSafeAddItemProperty(product, prop, 0.0f, AddItemPropertyPolicy.IgnoreExisting, true, true); } }