Ejemplo n.º 1
0
        public void StockShopShelf(PlayerGPS.DiscoveredBuilding buildingData)
        {
            stockedDate = CreateStockedDate(DaggerfallUnity.Instance.WorldTime.Now);
            items.Clear();

            DFLocation.BuildingTypes buildingType = buildingData.buildingType;
            int shopQuality = buildingData.quality;

            Game.Entity.PlayerEntity playerEntity = GameManager.Instance.PlayerEntity;
            ItemHelper itemHelper = DaggerfallUnity.Instance.ItemHelper;

            byte[] itemGroups = { 0 };

            switch (buildingType)
            {
            case DFLocation.BuildingTypes.Alchemist:
                itemGroups = DaggerfallLootDataTables.itemGroupsAlchemist;
                RandomlyAddPotionRecipe(25, items);
                break;

            case DFLocation.BuildingTypes.Armorer:
                itemGroups = DaggerfallLootDataTables.itemGroupsArmorer;
                break;

            case DFLocation.BuildingTypes.Bookseller:
                itemGroups = DaggerfallLootDataTables.itemGroupsBookseller;
                break;

            case DFLocation.BuildingTypes.ClothingStore:
                itemGroups = DaggerfallLootDataTables.itemGroupsClothingStore;
                break;

            case DFLocation.BuildingTypes.GemStore:
                itemGroups = DaggerfallLootDataTables.itemGroupsGemStore;
                break;

            case DFLocation.BuildingTypes.GeneralStore:
                itemGroups = DaggerfallLootDataTables.itemGroupsGeneralStore;
                items.AddItem(ItemBuilder.CreateItem(ItemGroups.Transportation, (int)Transportation.Horse));
                items.AddItem(ItemBuilder.CreateItem(ItemGroups.Transportation, (int)Transportation.Small_cart));
                break;

            case DFLocation.BuildingTypes.PawnShop:
                itemGroups = DaggerfallLootDataTables.itemGroupsPawnShop;
                break;

            case DFLocation.BuildingTypes.WeaponSmith:
                itemGroups = DaggerfallLootDataTables.itemGroupsWeaponSmith;
                break;
            }

            for (int i = 0; i < itemGroups.Length; i += 2)
            {
                ItemGroups itemGroup = (ItemGroups)itemGroups[i];
                int        chanceMod = itemGroups[i + 1];
                if (itemGroup == ItemGroups.MensClothing && playerEntity.Gender == Game.Entity.Genders.Female)
                {
                    itemGroup = ItemGroups.WomensClothing;
                }
                if (itemGroup == ItemGroups.WomensClothing && playerEntity.Gender == Game.Entity.Genders.Male)
                {
                    itemGroup = ItemGroups.MensClothing;
                }

                if (itemGroup != ItemGroups.Furniture && itemGroup != ItemGroups.UselessItems1)
                {
                    if (itemGroup == ItemGroups.Books)
                    {
                        int qualityMod = (shopQuality + 3) / 5;
                        if (qualityMod >= 4)
                        {
                            --qualityMod;
                        }
                        qualityMod++;
                        for (int j = 0; j <= qualityMod; ++j)
                        {
                            items.AddItem(ItemBuilder.CreateRandomBook());
                        }
                    }
                    else
                    {
                        System.Array enumArray = itemHelper.GetEnumArray(itemGroup);
                        for (int j = 0; j < enumArray.Length; ++j)
                        {
                            ItemTemplate itemTemplate = itemHelper.GetItemTemplate(itemGroup, j);
                            if (itemTemplate.rarity <= shopQuality)
                            {
                                int stockChance = chanceMod * 5 * (21 - itemTemplate.rarity) / 100;
                                if (Dice100.SuccessRoll(stockChance))
                                {
                                    DaggerfallUnityItem item = null;
                                    if (itemGroup == ItemGroups.Weapons)
                                    {
                                        item = ItemBuilder.CreateWeapon(j + Weapons.Dagger, FormulaHelper.RandomMaterial(playerEntity.Level));
                                    }
                                    else if (itemGroup == ItemGroups.Armor)
                                    {
                                        item = ItemBuilder.CreateArmor(playerEntity.Gender, playerEntity.Race, j + Armor.Cuirass, FormulaHelper.RandomArmorMaterial(playerEntity.Level));
                                    }
                                    else if (itemGroup == ItemGroups.MensClothing)
                                    {
                                        item          = ItemBuilder.CreateMensClothing(j + MensClothing.Straps, playerEntity.Race);
                                        item.dyeColor = ItemBuilder.RandomClothingDye();
                                    }
                                    else if (itemGroup == ItemGroups.WomensClothing)
                                    {
                                        item          = ItemBuilder.CreateWomensClothing(j + WomensClothing.Brassier, playerEntity.Race);
                                        item.dyeColor = ItemBuilder.RandomClothingDye();
                                    }
                                    else if (itemGroup == ItemGroups.MagicItems)
                                    {
                                        item = ItemBuilder.CreateRandomMagicItem(playerEntity.Level, playerEntity.Gender, playerEntity.Race);
                                    }
                                    else
                                    {
                                        item = new DaggerfallUnityItem(itemGroup, j);
                                        if (DaggerfallUnity.Settings.PlayerTorchFromItems && item.IsOfTemplate(ItemGroups.UselessItems2, (int)UselessItems2.Oil))
                                        {
                                            item.stackCount = Random.Range(5, 20 + 1);  // Shops stock 5-20 bottles
                                        }
                                    }
                                    items.AddItem(item);
                                }
                            }
                        }
                        // Add any modded items registered in applicable groups
                        int[] customItemTemplates = itemHelper.GetCustomItemsForGroup(itemGroup);
                        for (int j = 0; j < customItemTemplates.Length; j++)
                        {
                            ItemTemplate itemTemplate = itemHelper.GetItemTemplate(itemGroup, customItemTemplates[j]);
                            if (itemTemplate.rarity <= shopQuality)
                            {
                                int stockChance = chanceMod * 5 * (21 - itemTemplate.rarity) / 100;
                                if (Dice100.SuccessRoll(stockChance))
                                {
                                    DaggerfallUnityItem item = ItemBuilder.CreateItem(itemGroup, customItemTemplates[j]);

                                    // Setup specific group stats
                                    if (itemGroup == ItemGroups.Weapons)
                                    {
                                        WeaponMaterialTypes material = FormulaHelper.RandomMaterial(playerEntity.Level);
                                        ItemBuilder.ApplyWeaponMaterial(item, material);
                                    }
                                    else if (itemGroup == ItemGroups.Armor)
                                    {
                                        ArmorMaterialTypes material = FormulaHelper.RandomArmorMaterial(playerEntity.Level);
                                        ItemBuilder.ApplyArmorSettings(item, playerEntity.Gender, playerEntity.Race, material);
                                    }

                                    items.AddItem(item);
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public static void CustomArmorService(IUserInterfaceWindow window)
        {
            Debug.Log("Custom Armor service.");

            PlayerEntity playerEntity = GameManager.Instance.PlayerEntity;
            ItemHelper   itemHelper   = DaggerfallUnity.Instance.ItemHelper;

            if (playerEntity.Level < 9)
            {
                DaggerfallUI.MessageBox("Sorry I have not yet sourced enough rare materials to make you armor.");
                return;
            }
            ItemCollection armorItems = new ItemCollection();
            Array          armorTypes = itemHelper.GetEnumArray(ItemGroups.Armor);

            foreach (ArmorMaterialTypes material in customArmorMaterials)
            {
                if (playerEntity.Level < 9 ||
                    (playerEntity.Level < 12 && material >= ArmorMaterialTypes.Adamantium) ||
                    (playerEntity.Level < 15 && material >= ArmorMaterialTypes.Orcish) ||
                    (playerEntity.Level < 18 && material >= ArmorMaterialTypes.Daedric))
                {
                    break;
                }

                for (int i = 0; i < armorTypes.Length; i++)
                {
                    Armor        armorType    = (Armor)armorTypes.GetValue(i);
                    ItemTemplate itemTemplate = itemHelper.GetItemTemplate(ItemGroups.Armor, i);
                    int          vs           = 0;
                    int          vf           = 0;
                    switch (armorType)
                    {
                    case Armor.Cuirass:
                    case Armor.Left_Pauldron:
                    case Armor.Right_Pauldron:
                        vs = 1;
                        vf = 3;
                        break;

                    case Armor.Greaves:
                        vs = 2;
                        vf = 5;
                        break;

                    case Armor.Gauntlets:
                        vs = 1;
                        vf = 1;
                        break;

                    case Armor.Boots:
                    case Armor.Helm:
                        vs = 1;
                        vf = itemTemplate.variants - 1;
                        break;

                    default:
                        continue;
                    }
                    for (int v = vs; v <= vf; v++)
                    {
                        armorItems.AddItem(ItemBuilder.CreateArmor(playerEntity.Gender, playerEntity.Race, armorType, material, v));
                    }
                }
                int[] customItemTemplates = itemHelper.GetCustomItemsForGroup(ItemGroups.Armor);
                for (int i = 0; i < customItemTemplates.Length; i++)
                {
                    DaggerfallUnityItem item = ItemBuilder.CreateItem(ItemGroups.Armor, customItemTemplates[i]);
                    ItemBuilder.ApplyArmorSettings(item, playerEntity.Gender, playerEntity.Race, material);
                    armorItems.AddItem(item);
                }
            }

            DaggerfallTradeWindow tradeWindow = (DaggerfallTradeWindow)
                                                UIWindowFactory.GetInstanceWithArgs(UIWindowType.Trade, new object[] { DaggerfallUI.UIManager, null, DaggerfallTradeWindow.WindowModes.Buy, null });

            tradeWindow.MerchantItems = armorItems;
            DaggerfallUI.UIManager.PushWindow(tradeWindow);
        }
Ejemplo n.º 3
0
        public void StockShopShelf(PlayerGPS.DiscoveredBuilding buildingData)
        {
            stockedDate = CreateStockedDate(DaggerfallUnity.Instance.WorldTime.Now);
            items.Clear();

            DFLocation.BuildingTypes buildingType = buildingData.buildingType;
            int shopQuality = buildingData.quality;

            Game.Entity.PlayerEntity playerEntity = GameManager.Instance.PlayerEntity;
            int        playerLuck = playerEntity.Stats.LiveLuck;
            ItemHelper itemHelper = DaggerfallUnity.Instance.ItemHelper;

            byte[] itemGroups   = { 0 };
            int[]  discrimItems = new int[] { };

            switch (buildingType)
            {
            case DFLocation.BuildingTypes.Alchemist:
                float alchChance    = 60;
                float alchChanceMod = 0.75f;
                while (Dice100.SuccessRoll((int)alchChance))
                {
                    RandomlyAddPotion(100, items);
                    alchChance *= alchChanceMod;
                }
                alchChance = 40;
                while (Dice100.SuccessRoll((int)alchChance))
                {
                    RandomlyAddPotionRecipe(100, items);
                    alchChance *= alchChanceMod;
                }
                itemGroups = DaggerfallLootDataTables.itemGroupsAlchemist;
                break;

            case DFLocation.BuildingTypes.Armorer:
                itemGroups   = DaggerfallLootDataTables.itemGroupsArmorer;
                discrimItems = new int[] { (int)Repair_Tools.Charging_Powder, (int)Repair_Tools.Epoxy_Glue, (int)Repair_Tools.Whetstone };
                break;

            case DFLocation.BuildingTypes.Bookseller:
                itemGroups = DaggerfallLootDataTables.itemGroupsBookseller;
                break;

            case DFLocation.BuildingTypes.ClothingStore:
                itemGroups = DaggerfallLootDataTables.itemGroupsClothingStore;
                break;

            case DFLocation.BuildingTypes.GemStore:
                itemGroups = DaggerfallLootDataTables.itemGroupsGemStore;
                break;

            case DFLocation.BuildingTypes.GeneralStore:
                if (Dice100.SuccessRoll(20))
                {
                    items.AddItem(ItemBuilder.CreateItem(ItemGroups.Transportation, (int)Transportation.Horse));
                }
                if (Dice100.SuccessRoll(30))
                {
                    items.AddItem(ItemBuilder.CreateItem(ItemGroups.Transportation, (int)Transportation.Small_cart));
                }
                itemGroups   = DaggerfallLootDataTables.itemGroupsGeneralStore;
                discrimItems = new int[] { (int)Containers.Barrel, (int)Containers.Lockbox, (int)Liquid_Containers.Gem_Encrusted_Gold_Goblet, (int)Liquid_Containers.Gem_Encrusted_Silver_Goblet, (int)Liquid_Containers.Gold_Goblet, (int)Liquid_Containers.Silver_Goblet };
                break;

            case DFLocation.BuildingTypes.PawnShop:
                itemGroups   = DaggerfallLootDataTables.itemGroupsPawnShop;
                discrimItems = new int[] { (int)Containers.Barrel, (int)Containers.Bucket, (int)Containers.Urn, (int)Containers.Urn, (int)Containers.Snuff_Box, (int)Containers.Quiver, (int)Liquid_Containers.Empty_Bottle, (int)Liquid_Containers.Wooden_Cup, (int)Liquid_Containers.Tin_Goblet };
                break;

            case DFLocation.BuildingTypes.WeaponSmith:
                itemGroups   = DaggerfallLootDataTables.itemGroupsWeaponSmith;
                discrimItems = new int[] { (int)Repair_Tools.Charging_Powder, (int)Repair_Tools.Armorers_Hammer, (int)Repair_Tools.Jewelers_Pliers, (int)Repair_Tools.Sewing_Kit };
                break;
            }

            for (int i = 0; i < itemGroups.Length; i += 2) // Alright, that makes more sense to me now at least, from what it seems at least. Odd values are the itemGroup, Even are the chance for that itemGroup, makes much more sense.
            {
                ItemGroups itemGroup = (ItemGroups)itemGroups[i];
                float      chance    = itemGroups[i + 1];
                float      chanceMod = 0.45f;

                if (itemGroup != ItemGroups.Furniture && itemGroup != ItemGroups.UselessItems1)
                {
                    while (Dice100.SuccessRoll((int)chance))                      // I think order will be, roll if item of group is generated, then actually pick the item of said group randomly and then continue from there until loop roll fails.
                    {
                        DaggerfallUnityItem item = null;                          // Don't forget to have weapons and armor and such have variable condition values depending on the quality of the store they were bought/generated in.
                        chanceMod = Mathf.Clamp(chanceMod + 0.05f, 0.10f, 0.85f); // Will likely have to tweak this around and see how the results are. Possibly have shop quality modify these chance values as well.
                        if (itemGroup == ItemGroups.Weapons)
                        {
                            item = ItemBuilder.CreateWeapon((Weapons)Random.Range((int)Weapons.Dagger, (int)Weapons.Arrow + 1), FormulaHelper.RandomMaterial(-1, shopQuality, playerLuck)); // May rework and give weapons different rarity values later.
                        }
                        else if (itemGroup == ItemGroups.Armor)
                        {
                            item = ItemBuilder.CreateArmor(playerEntity.Gender, playerEntity.Race, (Armor)Random.Range((int)Armor.Cuirass, (int)Armor.Tower_Shield + 1), FormulaHelper.RandomArmorMaterial(-1, shopQuality, playerLuck));
                        }
                        else if (itemGroup == ItemGroups.MensClothing)
                        {
                            item          = ItemBuilder.CreateMensClothing((MensClothing)Random.Range((int)MensClothing.Straps, (int)MensClothing.Champion_straps + 1), playerEntity.Race);
                            item.dyeColor = ItemBuilder.RandomClothingDye();
                        }
                        else if (itemGroup == ItemGroups.WomensClothing)
                        {
                            item          = ItemBuilder.CreateWomensClothing((WomensClothing)Random.Range((int)WomensClothing.Brassier, (int)WomensClothing.Vest + 1), playerEntity.Race);
                            item.dyeColor = ItemBuilder.RandomClothingDye();
                        }
                        else if (itemGroup == ItemGroups.Books)
                        {
                            item = ItemBuilder.CreateRandomBookOfRandomSubject(-1, shopQuality, playerLuck);
                        }
                        else if (itemGroup == ItemGroups.MagicItems)
                        {
                            item = ItemBuilder.CreateRandomMagicItem(playerEntity.Gender, playerEntity.Race, -1, shopQuality, playerLuck);
                        }
                        else if ((int)itemGroup == (int)ItemGroups.Jewellery || ((int)itemGroup >= (int)ItemGroups.Tiara_Jewelry && (int)itemGroup <= (int)ItemGroups.Bracelet_Jewelry))
                        {
                            item = ItemBuilder.CreateRandomJewelryOfRandomSlot(-1, shopQuality, playerLuck, discrimItems);
                        }
                        else
                        {
                            item = ItemBuilder.CreateRandomItemOfItemgroup(itemGroup, -1, shopQuality, playerLuck, discrimItems); // For filter could make a method to populate the discrimItem para values and just change them based on shop types, maybe.
                            if (item != null && DaggerfallUnity.Settings.PlayerTorchFromItems && item.IsOfTemplate(ItemGroups.UselessItems2, (int)UselessItems2.Oil))
                            {
                                item.stackCount = Random.Range(5, 20 + 1);  // Shops stock 5-20 bottles
                            }
                        }
                        items.AddItem(item);

                        chance *= chanceMod; // Likely determine chanceMod by the itemGroup being currently ran.
                    }

                    // Add any modded items registered in applicable groups
                    int[] customItemTemplates = itemHelper.GetCustomItemsForGroup(itemGroup);
                    for (int j = 0; j < customItemTemplates.Length; j++)
                    {
                        ItemTemplate itemTemplate = itemHelper.GetItemTemplate(itemGroup, customItemTemplates[j]);
                        if (itemTemplate.rarity <= shopQuality)
                        {
                            int stockChance = (int)Mathf.Round(chance * 5 * (21 - itemTemplate.rarity) / 100);
                            if (Dice100.SuccessRoll(stockChance))
                            {
                                DaggerfallUnityItem item = ItemBuilder.CreateItem(itemGroup, customItemTemplates[j]);

                                // Setup specific group stats
                                if (itemGroup == ItemGroups.Weapons)
                                {
                                    WeaponMaterialTypes material = FormulaHelper.RandomMaterial(-1, shopQuality, playerLuck);
                                    ItemBuilder.ApplyWeaponMaterial(item, material);
                                }
                                else if (itemGroup == ItemGroups.Armor)
                                {
                                    ArmorMaterialTypes material = FormulaHelper.RandomArmorMaterial(-1, shopQuality, playerLuck);
                                    ItemBuilder.ApplyArmorSettings(item, playerEntity.Gender, playerEntity.Race, material);
                                }
                                else if (item.TemplateIndex == 810)
                                {
                                    WeaponMaterialTypes material = FormulaHelper.RandomMaterial(-1, shopQuality, playerLuck);
                                    ItemBuilder.ApplyIngotMaterial(item, material);
                                }

                                items.AddItem(item);
                            }
                        }
                    }
                }
            }
        }