Esempio n. 1
0
        public static ItemRarity RollItemRarity(LootDrop lootDrop, float luckFactor)
        {
            if (lootDrop.Rarity == null || lootDrop.Rarity.Length == 0)
            {
                return(ItemRarity.Magic);
            }

            var rarityWeights = GetRarityWeights(lootDrop.Rarity, luckFactor);

            _weightedRarityTable.Setup(rarityWeights, x => x.Value);
            return(_weightedRarityTable.Roll().Key);
        }
Esempio n. 2
0
        private static LootDrop ResolveLootDrop(LootDrop lootDrop)
        {
            var result = new LootDrop {
                Item = lootDrop.Item, Rarity = ArrayUtils.Copy(lootDrop.Rarity), Weight = lootDrop.Weight
            };
            var needsResolve = true;

            while (needsResolve)
            {
                if (ItemSets.TryGetValue(result.Item, out var itemSet))
                {
                    if (itemSet.Loot.Length == 0)
                    {
                        EpicLoot.LogError($"Tried to roll using ItemSet ({itemSet.Name}) but its loot list was empty!");
                    }
                    _weightedLootTable.Setup(itemSet.Loot, x => x.Weight);
                    var itemSetResult = _weightedLootTable.Roll();
                    result.Item   = itemSetResult.Item;
                    result.Weight = itemSetResult.Weight;
                    if (ArrayUtils.IsNullOrEmpty(result.Rarity))
                    {
                        result.Rarity = ArrayUtils.Copy(itemSetResult.Rarity);
                    }
                }
                else if (IsLootTableRefence(result.Item, out var lootList))
                {
                    if (lootList.Length == 0)
                    {
                        EpicLoot.LogError($"Tried to roll using loot table reference ({result.Item}) but its loot list was empty!");
                    }
                    _weightedLootTable.Setup(lootList, x => x.Weight);
                    var referenceResult = _weightedLootTable.Roll();
                    result.Item   = referenceResult.Item;
                    result.Weight = referenceResult.Weight;
                    if (ArrayUtils.IsNullOrEmpty(result.Rarity))
                    {
                        result.Rarity = ArrayUtils.Copy(referenceResult.Rarity);
                    }
                }
                else
                {
                    needsResolve = false;
                }
            }

            return(result);
        }
Esempio n. 3
0
        private static LootDrop ResolveLootDrop(LootDrop lootDrop, int[] rarityOverride)
        {
            var result = new LootDrop {
                Item = lootDrop.Item, Rarity = lootDrop.Rarity, Weight = lootDrop.Weight
            };
            var needsResolve = true;

            while (needsResolve)
            {
                if (ItemSets.TryGetValue(result.Item, out LootItemSet itemSet))
                {
                    if (itemSet.Loot.Length == 0)
                    {
                        Debug.LogError($"Tried to roll using ItemSet ({itemSet.Name}) but its loot list was empty!");
                    }
                    _weightedLootTable.Setup(itemSet.Loot, x => x.Weight);
                    result = _weightedLootTable.Roll();
                    if (!ArrayUtils.IsNullOrEmpty(rarityOverride))
                    {
                        result.Rarity = rarityOverride;
                    }
                }
                else if (IsLootTableRefence(result.Item, out LootDrop[] lootList))
Esempio n. 4
0
        private static ItemRarity GetItemRarity(LootDrop lootDrop)
        {
            var roll       = Random.Range(0.0f, 1.0f);
            var lowerRange = 0.0f;

            if (roll >= lowerRange && roll <= lootDrop.PercentMagic)
            {
                return(ItemRarity.Magic);
            }
            lowerRange += lootDrop.PercentMagic;

            if (roll > lowerRange && roll <= lowerRange + lootDrop.PercentRare)
            {
                return(ItemRarity.Rare);
            }
            lowerRange += lootDrop.PercentRare;

            if (roll > lowerRange && roll <= lowerRange + lootDrop.PercentEpic)
            {
                return(ItemRarity.Epic);
            }

            return(ItemRarity.Legendary);
        }
Esempio n. 5
0
        public static MagicItem RollMagicItem(LootDrop lootDrop, ExtendedItemData baseItem, float luckFactor)
        {
            var rarity = RollItemRarity(lootDrop, luckFactor);

            return(RollMagicItem(rarity, baseItem, luckFactor));
        }