private void HandleMainPageResponses(int responseID) { var model = _craft.GetPlayerCraftingData(GetPC()); NWPlaceable device = GetDevice(); switch (responseID) { case 1: // Examine Base Item CraftBlueprint entity = _craft.GetBlueprintByID(model.BlueprintID); NWPlaceable tempContainer = (_.GetObjectByTag("craft_temp_store")); NWItem examineItem = (_.CreateItemOnObject(entity.ItemResref, tempContainer.Object)); GetPC().AssignCommand(() => _.ActionExamine(examineItem.Object)); examineItem.Destroy(0.1f); break; case 2: // Create item if (!model.CanBuildItem) { GetPC().FloatingText("You are missing some required components."); return; } int effectiveLevel = _craft.CalculatePCEffectiveLevel(GetPC(), model.PlayerSkillRank, (SkillType)model.Blueprint.SkillID); int difficulty = effectiveLevel - model.AdjustedLevel; if(difficulty <= -5) { GetPC().FloatingText("It's impossible to make this item because its level is too high. Use lower-level components to reduce the level and difficulty."); return; } _craft.CraftItem(GetPC(), device); model.IsAccessingStorage = true; EndConversation(); break; case 3: // Select main components model.Access = CraftingAccessType.MainComponent; OpenDeviceInventory(); break; case 4: // Select secondary components model.Access = CraftingAccessType.SecondaryComponent; OpenDeviceInventory(); break; case 5: // Select tertiary components model.Access = CraftingAccessType.TertiaryComponent; OpenDeviceInventory(); break; case 6: // Select enhancement components model.Access = CraftingAccessType.Enhancement; OpenDeviceInventory(); break; case 7: // Back (return to blueprint selection) _craft.ClearPlayerCraftingData(GetPC()); SwitchConversation("CraftingDevice"); break; } }
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); }