Ejemplo n.º 1
0
        public ItemGenerator(List <Item> seedPool, WorldWealth wealth)
        {
            // Make a copy
            var treasurePool = seedPool.ToList();

            // Make sure we copy all the input lists so we don't modify anything static.
            List <List <Item> > tiers = new List <List <Item> >
            {
                ItemLists.UberTier.Where(item => treasurePool.Remove(item)).ToList(),
                ItemLists.LegendaryWeaponTier.Where(item => treasurePool.Remove(item)).ToList(),
                ItemLists.LegendaryArmorTier.Where(item => treasurePool.Remove(item)).ToList(),
                ItemLists.RareWeaponTier.Where(item => treasurePool.Remove(item)).ToList(),
                ItemLists.RareArmorTier.Where(item => treasurePool.Remove(item)).ToList(),
                ItemLists.CommonWeaponTier.Where(item => treasurePool.Remove(item)).ToList(),
                ItemLists.CommonArmorTier.Where(item => treasurePool.Remove(item)).ToList(),
                ItemLists.AllConsumables.Where(item => treasurePool.Remove(item)).ToList(),
                treasurePool.Where(x => x >= Item.Gold10 && x <= Item.Gold65000).ToList(),
            };

            List <int> ratios = Ratios[(int)wealth];

            System.Diagnostics.Debug.Assert(tiers.Count == ratios.Count);
            System.Diagnostics.Debug.Assert(Enum.GetValues(typeof(WorldWealth)).Length == Ratios.Length);

            // Now populate the comined pool with a weighted average of all those above lists.
            _pool = new List <List <Item> >();
            for (int i = 0; i < ratios.Count(); ++i)
            {
                for (int j = 0; j < ratios[i]; ++j)
                {
                    if (tiers[i].Any())
                    {
                        _pool.Add(tiers[i]);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public ItemShopSlot ShuffleShops(MT19337 rng, bool earlyAilments, bool randomizeWeaponsAndArmor, IEnumerable <Item> excludeItemsFromRandomShops, WorldWealth wealth)
        {
            var pointers = Get(ShopPointerOffset, ShopPointerCount * ShopPointerSize).ToUShorts();

            RepackShops(pointers);

            ShuffleShopType(ShopType.Weapon, pointers, rng, randomizeWeaponsAndArmor, excludeItemsFromRandomShops, wealth);
            ShuffleShopType(ShopType.Armor, pointers, rng, randomizeWeaponsAndArmor, excludeItemsFromRandomShops, wealth);
            ItemShopSlot result = null;

            do
            {
                result = ShuffleShopType(ShopType.Item, pointers, rng);
            } while (earlyAilments && !AilmentsCovered(pointers));
            if (result == null)
            {
                throw new InvalidOperationException("Shop Location for Bottle was not set");
            }

            Put(ShopPointerOffset, Blob.FromUShorts(pointers));
            return(result);
        }
Ejemplo n.º 3
0
        private ItemShopSlot ShuffleShopType(ShopType shopType, ushort[] pointers, MT19337 rng, bool randomize = false, IEnumerable <Item> excludeItemsFromRandomShops = null, WorldWealth wealth = WorldWealth.Normal)
        {
            var shops = GetShops(shopType, pointers);

            bool shopsBlocked;

            List <byte>[] newShops;
            do
            {
                shopsBlocked = false;
                newShops     = new List <byte> [ShopSectionSize];

                var allEntries = shops.SelectMany(list => list).ToList();
                allEntries.Shuffle(rng);

                int entry = 0;
                for (int i = 0; i < ShopSectionSize; i++)
                {
                    newShops[i] = new List <byte>();
                    if (pointers[(int)shopType + i] != ShopNullPointer)
                    {
                        newShops[i].Add(allEntries[entry++]);
                    }
                }

                while (entry < allEntries.Count)
                {
                    var eligibleShops = new List <int>();
                    for (int i = 0; i < newShops.Length; i++)
                    {
                        if (newShops[i].Count > 0 && newShops[i].Count < 5 && !newShops[i].Contains(allEntries[entry]))
                        {
                            eligibleShops.Add(i);
                        }
                    }

                    // We might be unable to place an item in any shop because they're all full, or they already have that item.  Start over.
                    if (eligibleShops.Count == 0)
                    {
                        shopsBlocked = true;
                        break;
                    }

                    int shopIndex = eligibleShops[rng.Between(0, eligibleShops.Count - 1)];
                    newShops[shopIndex].Add(allEntries[entry++]);
                }
            } while (shopsBlocked);

            if (randomize)
            {
                if (shopType == ShopType.Weapon || shopType == ShopType.Armor)
                {
                    // Shuffle up a byte array of random weapons or armor and assign them in place of the existing items.
                    var baseIndex = shopType == ShopType.Armor ? Item.Cloth : Item.WoodenNunchucks;
                    var indeces   = Enumerable.Range((int)baseIndex, 40).Select(i => (Item)i).ToList();
                    foreach (var exclusion in excludeItemsFromRandomShops ?? new List <Item>())
                    {
                        indeces.Remove(exclusion);
                    }

                    ItemGenerator generator = new ItemGenerator(indeces, wealth);
                    for (int i = 0; i < newShops.Length; i++)
                    {
                        newShops[i] = newShops[i].Select(x => (byte)generator.SpliceItem(rng)).ToList();
                    }
                }
            }
            // Zero-terminate the new shops.
            foreach (var newShop in newShops)
            {
                newShop.Add(0);
            }

            ItemShopSlot result  = null;
            var          pointer = pointers[(int)shopType];

            for (int i = 0; i < ShopSectionSize; i++)
            {
                if (newShops[i].Count > 1)
                {
                    var bottle =
                        newShops[i]
                        .Select((item, index) => new { item, index })
                        .FirstOrDefault(x => ((Item)x.item) == Item.Bottle);
                    if (bottle != null)
                    {
                        var location = ShopMapLocationsByIndex[i];
                        result = new ItemShopSlot(ShopPointerBase + pointer + bottle.index,
                                                  $"{Enum.GetName(typeof(MapLocation), location)}Shop{bottle.index + 1}",
                                                  location,
                                                  Item.Bottle);
                    }
                    Put(ShopPointerBase + pointer, newShops[i].ToArray());

                    pointers[(int)shopType + i] = pointer;
                    pointer += (ushort)newShops[i].Count;
                }
            }
            return(result);
        }