コード例 #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;
            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);
                            }
                        }
                    }
                }
            }
        }