Exemplo n.º 1
0
        private void LoadCraftPage(int blueprintID)
        {
            var model = _craft.GetPlayerCraftingData(GetPC());

            model.BlueprintID = blueprintID;
            SwitchConversation("CraftItem");
        }
Exemplo n.º 2
0
        private void HandleBlueprintListPageResponse(int responseID)
        {
            DialogResponse response    = GetResponseByID("BlueprintListPage", responseID);
            int            blueprintID = (int)response.CustomData;

            if (blueprintID == -1)
            {
                ChangePage("CraftCategoriesPage");
                return;
            }

            var model = _craft.GetPlayerCraftingData(GetPC());

            model.Blueprint        = _craft.GetBlueprintByID(blueprintID);
            model.BlueprintID      = blueprintID;
            model.PlayerSkillRank  = _skill.GetPCSkillRank(GetPC(), model.Blueprint.SkillID);
            model.MainMinimum      = model.Blueprint.MainMinimum;
            model.MainMaximum      = model.Blueprint.MainMaximum;
            model.SecondaryMinimum = model.Blueprint.SecondaryMinimum;
            model.SecondaryMaximum = model.Blueprint.SecondaryMaximum;
            model.TertiaryMinimum  = model.Blueprint.TertiaryMinimum;
            model.TertiaryMaximum  = model.Blueprint.TertiaryMaximum;

            string header = _craft.BuildBlueprintHeader(GetPC(), blueprintID, false);

            SetPageHeader("BlueprintDetailsPage", header);
            ChangePage("BlueprintDetailsPage");
        }
Exemplo n.º 3
0
        private void HandleBlueprintListResponse(int responseID)
        {
            DialogResponse response    = GetResponseByID("BlueprintListPage", responseID);
            int            blueprintID = (int)response.CustomData;
            var            model       = _craft.GetPlayerCraftingData(GetPC());

            model.BlueprintID = blueprintID;
            SwitchConversation("CraftItem");
        }
Exemplo n.º 4
0
        public override void Initialize()
        {
            var model  = _craft.GetPlayerCraftingData(GetPC());
            var device = GetDevice();

            // Entering the conversation for the first time from the blueprint selection menu.
            if (model.BlueprintID <= 0)
            {
                model.BlueprintID    = GetPC().GetLocalInt("CRAFT_BLUEPRINT_ID");
                model.Blueprint      = _craft.GetBlueprintByID(model.BlueprintID);
                GetDevice().IsLocked = true;
            }
            // Otherwise returning from accessing the device's inventory.
            else
            {
                model.Access = CraftingAccessType.None;

                _.SetEventScript(device.Object, EVENT_SCRIPT_PLACEABLE_ON_USED, "jvm_script_1");
                _.SetEventScript(device.Object, EVENT_SCRIPT_PLACEABLE_ON_OPEN, string.Empty);
                _.SetEventScript(device.Object, EVENT_SCRIPT_PLACEABLE_ON_CLOSED, string.Empty);
                _.SetEventScript(device.Object, EVENT_SCRIPT_PLACEABLE_ON_INVENTORYDISTURBED, string.Empty);
            }

            BuildMainPageHeader();
            BuildMainPageOptions();
        }
Exemplo n.º 5
0
        public bool Run(params object[] args)
        {
            NWPlaceable device = NWPlaceable.Wrap(Object.OBJECT_SELF);
            NWPlayer    oPC    = NWPlayer.Wrap(_.GetLastOpenedBy());
            var         model  = _craft.GetPlayerCraftingData(oPC);

            if (model.Access != CraftingAccessType.None)
            {
                NWItem        menuItem     = NWItem.Wrap(_.CreateItemOnObject("cft_confirm", device.Object));
                NWPlaceable   storage      = NWPlaceable.Wrap(_.GetObjectByTag("craft_temp_store"));
                var           storageItems = storage.InventoryItems;
                List <NWItem> list         = null;

                if (model.Access == CraftingAccessType.MainComponent)
                {
                    menuItem.Name = "Confirm Main Components";
                    list          = model.MainComponents;
                }
                else if (model.Access == CraftingAccessType.SecondaryComponent)
                {
                    menuItem.Name = "Confirm Secondary Components";
                    list          = model.SecondaryComponents;
                }
                else if (model.Access == CraftingAccessType.TertiaryComponent)
                {
                    menuItem.Name = "Confirm Tertiary Components";
                    list          = model.TertiaryComponents;
                }
                else if (model.Access == CraftingAccessType.Enhancement)
                {
                    menuItem.Name = "Confirm Enhancement Components";
                    list          = model.EnhancementComponents;
                }

                if (list == null)
                {
                    oPC.FloatingText("Error locating component list. Notify an admin.");
                    return(false);
                }

                foreach (var item in list)
                {
                    NWItem storageItem = storageItems.Single(x => x.GlobalID == item.GlobalID);
                    _.CopyItem(storageItem.Object, device.Object, TRUE);
                }

                oPC.FloatingText("Place the components inside the container and then click the item named '" + menuItem.Name + "' to continue.");
            }

            device.IsLocked = true;
            return(true);
        }
Exemplo n.º 6
0
        public bool Run(params object[] args)
        {
            // Should only fire when a player walks away from the device.
            // Clean up temporary data and return all items placed inside.
            NWPlayer    player = NWPlayer.Wrap(_.GetLastClosedBy());
            NWPlaceable device = NWPlaceable.Wrap(Object.OBJECT_SELF);
            var         model  = _craft.GetPlayerCraftingData(player);

            device.DestroyAllInventoryItems();
            device.IsLocked          = false;
            model.IsAccessingStorage = false;

            foreach (var item in model.MainComponents)
            {
                _.CopyItem(item.Object, player.Object, TRUE);
                item.Destroy();
            }
            foreach (var item in model.SecondaryComponents)
            {
                _.CopyItem(item.Object, player.Object, TRUE);
                item.Destroy();
            }
            foreach (var item in model.TertiaryComponents)
            {
                _.CopyItem(item.Object, player.Object, TRUE);
                item.Destroy();
            }
            foreach (var item in model.EnhancementComponents)
            {
                _.CopyItem(item.Object, player.Object, TRUE);
                item.Destroy();
            }

            _.SetEventScript(device.Object, EVENT_SCRIPT_PLACEABLE_ON_USED, "jvm_script_1");
            _.SetEventScript(device.Object, EVENT_SCRIPT_PLACEABLE_ON_OPEN, string.Empty);
            _.SetEventScript(device.Object, EVENT_SCRIPT_PLACEABLE_ON_CLOSED, string.Empty);
            _.SetEventScript(device.Object, EVENT_SCRIPT_PLACEABLE_ON_INVENTORYDISTURBED, string.Empty);
            player.Data.Remove("CRAFTING_MODEL");
            return(true);
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        private void HandleAddItem()
        {
            NWPlayer oPC   = NWPlayer.Wrap(_.GetLastDisturbed());
            NWItem   oItem = NWItem.Wrap(_.GetInventoryDisturbItem());

            if (oItem.Resref == "cft_confirm")
            {
                return;
            }
            var         model   = _craft.GetPlayerCraftingData(oPC);
            NWPlaceable storage = NWPlaceable.Wrap(_.GetObjectByTag("craft_temp_store"));

            List <NWItem> list          = null;
            ComponentType allowedType   = ComponentType.None;
            bool          reachedCap    = false;
            string        componentName = string.Empty;

            switch (model.Access)
            {
            case CraftingAccessType.MainComponent:
                allowedType   = (ComponentType)model.Blueprint.MainComponentTypeID;
                reachedCap    = model.Blueprint.MainMinimum * 2 < model.MainComponents.Count + 1;
                list          = model.MainComponents;
                componentName = model.Blueprint.MainComponentType.Name;
                break;

            case CraftingAccessType.SecondaryComponent:
                allowedType   = (ComponentType)model.Blueprint.SecondaryComponentTypeID;
                reachedCap    = model.Blueprint.SecondaryMinimum * 2 < model.SecondaryComponents.Count + 1;
                list          = model.SecondaryComponents;
                componentName = model.Blueprint.SecondaryComponentType.Name;
                break;

            case CraftingAccessType.TertiaryComponent:
                allowedType   = (ComponentType)model.Blueprint.TertiaryComponentTypeID;
                reachedCap    = model.Blueprint.TertiaryMinimum * 2 < model.TertiaryComponents.Count + 1;
                list          = model.TertiaryComponents;
                componentName = model.Blueprint.TertiaryComponentType.Name;
                break;

            case CraftingAccessType.Enhancement:
                allowedType   = ComponentType.Enhancement;
                reachedCap    = model.Blueprint.EnhancementSlots < model.EnhancementComponents.Count + 1;
                list          = model.EnhancementComponents;
                componentName = "Enhancement";
                break;
            }

            if (list == null)
            {
                oPC.FloatingText("There was an issue getting the item data. Notify an admin.");
                _item.ReturnItem(oPC, oItem);
                return;
            }

            if (reachedCap)
            {
                _item.ReturnItem(oPC, oItem);
                oPC.FloatingText("You cannot add any more components of that type.");
                return;
            }

            foreach (var ip in oItem.ItemProperties)
            {
                if (_.GetItemPropertyType(ip) == (int)CustomItemPropertyType.ComponentType)
                {
                    int compType = _.GetItemPropertyCostTableValue(ip);
                    if (compType == (int)allowedType)
                    {
                        NWItem copy = NWItem.Wrap(_.CopyItem(oItem.Object, storage.Object, TRUE));
                        list.Add(copy);
                        return;
                    }
                }
            }

            oPC.FloatingText("Only " + componentName + " components may be used with this component type.");
            _item.ReturnItem(oPC, oItem);
        }
Exemplo n.º 9
0
        private void HandleAddItem()
        {
            NWPlayer oPC   = (_.GetLastDisturbed());
            NWItem   oItem = (_.GetInventoryDisturbItem());

            if (oItem.Resref == "cft_confirm")
            {
                return;
            }
            if (oPC.IsBusy)
            {
                _item.ReturnItem(oPC, oItem);
                oPC.SendMessage("You are too busy right now.");
                return;
            }

            var model              = _craft.GetPlayerCraftingData(oPC);
            var mainComponent      = _data.Get <Data.Entity.ComponentType>(model.Blueprint.MainComponentTypeID);
            var secondaryComponent = _data.Get <Data.Entity.ComponentType>(model.Blueprint.SecondaryComponentTypeID);
            var tertiaryComponent  = _data.Get <Data.Entity.ComponentType>(model.Blueprint.TertiaryComponentTypeID);

            NWPlaceable storage = _.GetObjectByTag("craft_temp_store");

            List <NWItem> list                    = null;
            ComponentType allowedType             = ComponentType.None;
            bool          reachedCap              = false;
            bool          reachedEnhancementLimit = false;

            string componentName = string.Empty;

            switch (model.Access)
            {
            case CraftingAccessType.MainComponent:
                allowedType   = (ComponentType)model.Blueprint.MainComponentTypeID;
                reachedCap    = model.MainMaximum < model.MainComponents.Count + 1;
                list          = model.MainComponents;
                componentName = mainComponent.Name;
                break;

            case CraftingAccessType.SecondaryComponent:
                allowedType   = (ComponentType)model.Blueprint.SecondaryComponentTypeID;
                reachedCap    = model.SecondaryMaximum < model.SecondaryComponents.Count + 1;
                list          = model.SecondaryComponents;
                componentName = secondaryComponent.Name;
                break;

            case CraftingAccessType.TertiaryComponent:
                allowedType   = (ComponentType)model.Blueprint.TertiaryComponentTypeID;
                reachedCap    = model.TertiaryMaximum < model.TertiaryComponents.Count + 1;
                list          = model.TertiaryComponents;
                componentName = tertiaryComponent.Name;
                break;

            case CraftingAccessType.Enhancement:
                allowedType             = ComponentType.Enhancement;
                reachedCap              = model.Blueprint.EnhancementSlots < model.EnhancementComponents.Count + 1;
                reachedEnhancementLimit = model.PlayerPerkLevel / 2 <= model.EnhancementComponents.Count + 1;
                list          = model.EnhancementComponents;
                componentName = "Enhancement";
                break;
            }

            if (list == null)
            {
                _item.ReturnItem(oPC, oItem);
                oPC.FloatingText("There was an issue getting the item data. Notify an admin.");
                return;
            }

            if (reachedCap)
            {
                _item.ReturnItem(oPC, oItem);
                oPC.FloatingText("You cannot add any more components of that type.");
                return;
            }

            if (reachedEnhancementLimit)
            {
                _item.ReturnItem(oPC, oItem);
                oPC.FloatingText("Your perk level does not allow you to attach any more enhancements to this item.");
                return;
            }

            var            props            = oItem.ItemProperties.ToList();
            var            allowedItemTypes = new List <CustomItemType>();
            CustomItemType finishedItemType = _item.GetCustomItemTypeByResref(model.Blueprint.ItemResref);

            foreach (var ip in props)
            {
                if (_.GetItemPropertyType(ip) == (int)CustomItemPropertyType.ComponentItemTypeRestriction)
                {
                    int restrictionType = _.GetItemPropertyCostTableValue(ip);
                    allowedItemTypes.Add((CustomItemType)restrictionType);
                }
            }

            if (allowedItemTypes.Count > 0)
            {
                if (!allowedItemTypes.Contains(finishedItemType))
                {
                    oPC.FloatingText("This component cannot be used with this type of blueprint.");
                    _item.ReturnItem(oPC, oItem);
                    return;
                }
            }

            foreach (var ip in props)
            {
                if (_.GetItemPropertyType(ip) == (int)CustomItemPropertyType.ComponentType)
                {
                    int compType = _.GetItemPropertyCostTableValue(ip);
                    if (compType == (int)allowedType)
                    {
                        oItem.GetOrAssignGlobalID();
                        NWItem copy = (_.CopyItem(oItem.Object, storage.Object, TRUE));
                        list.Add(copy);
                        return;
                    }
                }
            }

            oPC.FloatingText("Only " + componentName + " components may be used with this component type.");
            _item.ReturnItem(oPC, oItem);
        }
Exemplo n.º 10
0
        public override void Initialize()
        {
            ToggleBackButton(false);

            var model = _craft.GetPlayerCraftingData(GetPC());
            var device = GetDevice();

            // Entering the conversation for the first time from the blueprint selection menu.
            if (!model.IsInitialized)
            {
                model.IsInitialized = true;
                model.Blueprint = _craft.GetBlueprintByID(model.BlueprintID);
                model.PlayerSkillRank = _skill.GetPCSkillRank(GetPC(), model.Blueprint.SkillID);

                switch ((SkillType)model.Blueprint.SkillID)
                {
                    case SkillType.Armorsmith:
                        model.PlayerPerkLevel = _perk.GetPCPerkLevel(GetPC(), PerkType.ArmorBlueprints);
                        model.EfficiencyLevel = _perk.GetPCPerkLevel(GetPC(), PerkType.ArmorsmithEfficiency);
                        model.OptimizationLevel = _perk.GetPCPerkLevel(GetPC(), PerkType.ArmorsmithOptimization);
                        break;
                    case SkillType.Engineering:
                        model.PlayerPerkLevel = _perk.GetPCPerkLevel(GetPC(), PerkType.EngineeringBlueprints);
                        model.EfficiencyLevel = _perk.GetPCPerkLevel(GetPC(), PerkType.EngineeringEfficiency);
                        model.OptimizationLevel = _perk.GetPCPerkLevel(GetPC(), PerkType.EngineeringOptimization);
                        break;
                    case SkillType.Weaponsmith:
                        model.PlayerPerkLevel = _perk.GetPCPerkLevel(GetPC(), PerkType.WeaponBlueprints);
                        model.EfficiencyLevel = _perk.GetPCPerkLevel(GetPC(), PerkType.WeaponsmithEfficiency);
                        model.OptimizationLevel = _perk.GetPCPerkLevel(GetPC(), PerkType.WeaponsmithOptimization);
                        break;
                    case SkillType.Fabrication:
                        model.PlayerPerkLevel = _perk.GetPCPerkLevel(GetPC(), PerkType.FabricationBlueprints);
                        model.EfficiencyLevel = _perk.GetPCPerkLevel(GetPC(), PerkType.FabricationEfficiency);
                        model.OptimizationLevel = _perk.GetPCPerkLevel(GetPC(), PerkType.FabricationOptimization);
                        break;
                    case SkillType.Medicine:
                        model.PlayerPerkLevel = _perk.GetPCPerkLevel(GetPC(), PerkType.MedicalBlueprints);
                        model.EfficiencyLevel = _perk.GetPCPerkLevel(GetPC(), PerkType.MedicineEfficiency);
                        model.OptimizationLevel = _perk.GetPCPerkLevel(GetPC(), PerkType.MedicineOptimization);
                        break;
                    default:
                        model.PlayerPerkLevel = 0;
                        break;

                }
                GetDevice().IsLocked = true;
                model.MainMinimum = model.Blueprint.MainMinimum - model.EfficiencyLevel;
                model.SecondaryMinimum = model.Blueprint.SecondaryMinimum - model.EfficiencyLevel;
                model.TertiaryMinimum = model.Blueprint.TertiaryMinimum - model.EfficiencyLevel;

                model.MainMaximum = model.Blueprint.MainMaximum + model.OptimizationLevel;
                model.SecondaryMaximum = model.Blueprint.SecondaryMaximum > 0 ? model.Blueprint.SecondaryMaximum + model.OptimizationLevel : 0;
                model.TertiaryMaximum = model.Blueprint.TertiaryMaximum > 0 ? model.Blueprint.TertiaryMaximum + model.OptimizationLevel : 0;

                if (model.MainMinimum <= 0)
                    model.MainMinimum = 1;
                if (model.SecondaryMinimum <= 0 && model.Blueprint.SecondaryMinimum > 0)
                    model.SecondaryMinimum = 1;
                if (model.TertiaryMinimum <= 0 && model.Blueprint.TertiaryMinimum > 0)
                    model.TertiaryMinimum = 1;

            }
            // Otherwise returning from accessing the device's inventory.
            else
            {
                model.Access = CraftingAccessType.None;

                _.SetEventScript(device.Object, EVENT_SCRIPT_PLACEABLE_ON_USED, "jvm_script_1");
                _.SetEventScript(device.Object, EVENT_SCRIPT_PLACEABLE_ON_OPEN, string.Empty);
                _.SetEventScript(device.Object, EVENT_SCRIPT_PLACEABLE_ON_CLOSED, string.Empty);
                _.SetEventScript(device.Object, EVENT_SCRIPT_PLACEABLE_ON_INVENTORYDISTURBED, string.Empty);
            }


            SetPageHeader("MainPage", _craft.BuildBlueprintHeader(GetPC(), model.BlueprintID, true));
            BuildMainPageOptions();
        }