public string CanApply(NWPlayer player, NWItem target, params string[] args) { var maxDurability = _durability.GetMaxDurability(target); if (maxDurability >= 100) { return("You cannot improve that item's maximum durability any further."); } return(null); }
public string IsValidTarget(NWCreature user, NWItem item, NWObject target, Location targetLocation) { NWItem targetItem = target.Object; float maxDurability = _durability.GetMaxDurability(targetItem); float durability = _durability.GetDurability(targetItem); if (target.ObjectType != NWScript.OBJECT_TYPE_ITEM) { return("Only items may be targeted by repair kits."); } if (targetItem.CustomItemType != (CustomItemType)item.GetLocalInt("REPAIR_CUSTOM_ITEM_TYPE_ID")) { return("You cannot repair that item with this repair kit."); } if (maxDurability <= 0.0f || durability >= maxDurability) { return("That item does not need to be repaired."); } if (durability <= 0.0f) { return("That item is broken and cannot be repaired."); } if (maxDurability <= 0.1f) { return("You cannot repair that item any more."); } SkillType skillType = GetSkillType(item); int techLevel = item.GetLocalInt("TECH_LEVEL"); if (skillType == SkillType.Armorsmith) { if (_perk.GetPCPerkLevel(user.Object, PerkType.ArmorRepair) < techLevel) { return("Your level in the 'Armor Repair' perk is too low to use this repair kit."); } } else if (skillType == SkillType.Weaponsmith) { if (_perk.GetPCPerkLevel(user.Object, PerkType.WeaponRepair) < techLevel) { return("Your level in the 'Weapon Repair' perk is too low to use this repair kit."); } } else if (skillType == SkillType.Engineering) { if (_perk.GetPCPerkLevel(user.Object, PerkType.ElectronicRepair) < techLevel) { return("Your level in the 'Electronic Repair' perk is too low to use this repair kit."); } } return(null); }
private void RunSearchCycle(NWPlayer oPC, NWPlaceable oChest, int iDC) { int lootTable = oChest.GetLocalInt(SearchSiteLootTableVariableName); int skill = _.GetSkillRank(NWScript.SKILL_SEARCH, oPC.Object); if (skill > 10) { skill = 10; } else if (skill < 0) { skill = 0; } int roll = _random.Random(20) + 1; int combinedRoll = roll + skill; if (roll + skill >= iDC) { oPC.FloatingText(_color.SkillCheck("Search: *success*: (" + roll + " + " + skill + " = " + combinedRoll + " vs. DC: " + iDC + ")")); ItemVO spawnItem = PickResultItem(lootTable); if (!string.IsNullOrWhiteSpace(spawnItem.Resref) && spawnItem.Quantity > 0) { NWItem foundItem = (_.CreateItemOnObject(spawnItem.Resref, oChest.Object, spawnItem.Quantity, "")); float maxDurability = _durability.GetMaxDurability(foundItem); if (maxDurability > -1) { _durability.SetDurability(foundItem, _random.RandomFloat() * maxDurability + 1); } } } else { oPC.FloatingText(_color.SkillCheck("Search: *failure*: (" + roll + " + " + skill + " = " + combinedRoll + " vs. DC: " + iDC + ")")); } }
public string IsValidTarget(NWCreature user, NWItem item, NWObject target, Location targetLocation) { NWItem targetItem = target.Object; float maxDurability = _durability.GetMaxDurability(targetItem); float durability = _durability.GetDurability(targetItem); if (target.ObjectType != OBJECT_TYPE_ITEM) { return("Only items may be targeted by repair kits."); } if (targetItem.CustomItemType != (CustomItemType)item.GetLocalInt("REPAIR_CUSTOM_ITEM_TYPE_ID")) { return("You cannot repair that item with this repair kit."); } if (maxDurability <= 0.0f || durability >= maxDurability) { return("That item does not need to be repaired."); } if (durability <= 0.0f) { return("That item is broken and cannot be repaired."); } if (maxDurability <= 0.1f) { return("You cannot repair that item any more."); } SkillType skillType = GetSkillType(item); int techLevel = item.GetLocalInt("TECH_LEVEL"); return(null); }
private void RunCreateItem(NWPlayer player) { var model = _craft.GetPlayerCraftingData(player); CraftBlueprint blueprint = _data.Single <CraftBlueprint>(x => x.ID == model.BlueprintID); BaseStructure baseStructure = blueprint.BaseStructureID == null ? null : _data.Get <BaseStructure>(blueprint.BaseStructureID); PCSkill pcSkill = _skill.GetPCSkill(player, blueprint.SkillID); int pcEffectiveLevel = _craft.CalculatePCEffectiveLevel(player, pcSkill.Rank, (SkillType)blueprint.SkillID); int itemLevel = model.AdjustedLevel; float chance = CalculateBaseChanceToAddProperty(pcEffectiveLevel, itemLevel); float equipmentBonus = CalculateEquipmentBonus(player, (SkillType)blueprint.SkillID); if (chance <= 1.0f) { player.FloatingText(_color.Red("Critical failure! You don't have enough skill to create that item. All components were lost.")); _craft.ClearPlayerCraftingData(player, true); return; } int luckyBonus = _perk.GetPCPerkLevel(player, PerkType.Lucky); var craftedItems = new List <NWItem>(); NWItem craftedItem = (_.CreateItemOnObject(blueprint.ItemResref, player.Object, blueprint.Quantity)); craftedItem.IsIdentified = true; craftedItems.Add(craftedItem); // If item isn't stackable, loop through and create as many as necessary. if (craftedItem.StackSize < blueprint.Quantity) { for (int x = 2; x <= blueprint.Quantity; x++) { craftedItem = (_.CreateItemOnObject(blueprint.ItemResref, player.Object)); craftedItem.IsIdentified = true; craftedItems.Add(craftedItem); } } // Recommended level gets set regardless if all item properties make it on the final product. // Also mark who crafted the item. This is later used for display on the item's examination event. foreach (var item in craftedItems) { item.RecommendedLevel = itemLevel < 0 ? 0 : itemLevel; item.SetLocalString("CRAFTER_PLAYER_ID", player.GlobalID.ToString()); _base.ApplyCraftedItemLocalVariables(item, baseStructure); } if (_random.Random(1, 100) <= luckyBonus) { chance += _random.Random(1, luckyBonus); } int successAmount = 0; foreach (var component in model.MainComponents) { var result = RunComponentBonusAttempt(player, component, equipmentBonus, chance, craftedItems); successAmount += result.Item1; chance = result.Item2; } foreach (var component in model.SecondaryComponents) { var result = RunComponentBonusAttempt(player, component, equipmentBonus, chance, craftedItems); successAmount += result.Item1; chance = result.Item2; } foreach (var component in model.TertiaryComponents) { var result = RunComponentBonusAttempt(player, component, equipmentBonus, chance, craftedItems); successAmount += result.Item1; chance = result.Item2; } foreach (var component in model.EnhancementComponents) { var result = RunComponentBonusAttempt(player, component, equipmentBonus, chance, craftedItems); successAmount += result.Item1; chance = result.Item2; } // Structures gain increased durability based on the blueprint if (baseStructure != null) { foreach (var item in craftedItems) { var maxDur = _durability.GetMaxDurability(item); maxDur += (float)baseStructure.Durability; _durability.SetMaxDurability(item, maxDur); _durability.SetDurability(item, maxDur); } } player.SendMessage("You created " + blueprint.Quantity + "x " + blueprint.ItemName + "!"); int baseXP = 250 + successAmount * _random.Random(1, 50); float xp = _skill.CalculateRegisteredSkillLevelAdjustedXP(baseXP, model.AdjustedLevel, pcSkill.Rank); var pcCraftedBlueprint = _data.SingleOrDefault <PCCraftedBlueprint>(x => x.PlayerID == player.GlobalID && x.CraftBlueprintID == blueprint.ID); if (pcCraftedBlueprint == null) { xp = xp * 1.25f; player.SendMessage("You receive an XP bonus for crafting this item for the first time."); pcCraftedBlueprint = new PCCraftedBlueprint { CraftBlueprintID = blueprint.ID, DateFirstCrafted = DateTime.UtcNow, PlayerID = player.GlobalID }; _data.SubmitDataChange(pcCraftedBlueprint, DatabaseActionType.Insert); } _skill.GiveSkillXP(player, blueprint.SkillID, (int)xp); _craft.ClearPlayerCraftingData(player, true); }
public 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 = _durability.GetMaxDurability(product) + amount; _durability.SetMaxDurability(product, maxDur); _durability.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.DarkAbilityUp: product.DarkAbilityBonus += amount; break; case ComponentBonusType.LightAbilityUp: product.LightAbilityBonus += 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.DarkAbilityDown: product.DarkAbilityBonus -= amount; break; case ComponentBonusType.LightAbilityDown: product.LightAbilityBonus -= 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; default: throw new ArgumentOutOfRangeException(); } if (!string.IsNullOrWhiteSpace(sourceTag)) { prop = _item.GetCustomItemPropertyByItemTag(sourceTag); } if (prop == null) { return; } _biowareXP2.IPSafeAddItemProperty(product, prop, 0.0f, AddItemPropertyPolicy.IgnoreExisting, true, true); } }