Exemplo n.º 1
0
    public WeightedRandomCollection <T> WeightedBag <T>(T[] values, float[] initalWeights)
    {
        var result = new WeightedRandomCollection <T>(this);

        for (var n = 0; n < values.Length; ++n)
        {
            result.Add(values[n], initalWeights[n]);
        }

        return(result);
    }
Exemplo n.º 2
0
    public static WeightedRandomCollection <T> CreateWeightedBag <T>(T[] values, float initalWeight, IRandomGenerator randomGenerator = null)
    {
        var result = new WeightedRandomCollection <T>(randomGenerator);

        foreach (var n in values)
        {
            result.Add(n, initalWeight);
        }

        return(result);
    }
Exemplo n.º 3
0
    //
    public WeightedRandomCollection <T> WeightedBag <T>(T[] values, float initalWeight)
    {
        var result = new WeightedRandomCollection <T>(this);

        foreach (var n in values)
        {
            result.Add(n, initalWeight);
        }

        return(result);
    }
Exemplo n.º 4
0
        public static void Initialize(LootConfig lootConfig)
        {
            Config = lootConfig;

            var random = new System.Random();

            _weightedDropCountTable   = new WeightedRandomCollection <int[]>(random);
            _weightedLootTable        = new WeightedRandomCollection <LootDrop>(random);
            _weightedEffectTable      = new WeightedRandomCollection <MagicItemEffectDefinition>(random);
            _weightedEffectCountTable = new WeightedRandomCollection <KeyValuePair <int, int> >(random);
            _weightedRarityTable      = new WeightedRandomCollection <KeyValuePair <ItemRarity, int> >(random);

            LootTables.Clear();
            AddItemSets(lootConfig.ItemSets);
            AddLootTables(lootConfig.LootTables);
        }
Exemplo n.º 5
0
    //
    public static WeightedRandomCollection <T> CreateWeightedBag <T>(IEnumerable <T> values, IEnumerable <float> initalWeights, IRandomGenerator randomGenerator = null)
    {
        var result = new WeightedRandomCollection <T>(randomGenerator);

        using (var valueEnumerator = values.GetEnumerator())
            using (var weightEnumerator = initalWeights.GetEnumerator())
            {
                while (valueEnumerator.MoveNext() && weightEnumerator.MoveNext())
                {
                    result.Add(valueEnumerator.Current, weightEnumerator.Current);
                }
            }


        return(result);
    }
Exemplo n.º 6
0
        public static void Initialize(LootConfig lootConfig)
        {
            Config = lootConfig;

            var random = new System.Random();

            _weightedDropCountTable   = new WeightedRandomCollection <int[]>(random);
            _weightedLootTable        = new WeightedRandomCollection <LootDrop>(random);
            _weightedEffectTable      = new WeightedRandomCollection <MagicItemEffectDefinition>(random);
            _weightedEffectCountTable = new WeightedRandomCollection <KeyValuePair <int, int> >(random);
            _weightedRarityTable      = new WeightedRandomCollection <KeyValuePair <ItemRarity, int> >(random);

            ItemSets.Clear();
            LootTables.Clear();
            if (Config == null)
            {
                EpicLoot.LogWarning("Initialized LootRoller with null");
                return;
            }

            AddItemSets(lootConfig.ItemSets);
            AddLootTables(lootConfig.LootTables);
        }
Exemplo n.º 7
0
        public static void MagicItem(Console __instance, string[] args)
        {
            var rarityArg   = args.Length >= 2 ? args[1] : "random";
            var itemArg     = args.Length >= 3 ? args[2] : "random";
            var count       = args.Length >= 4 ? int.Parse(args[3]) : 1;
            var effectCount = args.Length >= 5 ? int.Parse(args[4]) : -1;

            __instance.AddString($"magicitem - rarity:{rarityArg}, item:{itemArg}, count:{count}");

            var allItemNames = ObjectDB.instance.m_items
                               .Where(x => EpicLoot.CanBeMagicItem(x.GetComponent <ItemDrop>().m_itemData))
                               .Where(x => x.name != "HelmetDverger" && x.name != "BeltStrength" && x.name != "Wishbone")
                               .Select(x => x.name)
                               .ToList();

            if (Player.m_localPlayer == null)
            {
                return;
            }

            LootRoller.CheatEffectCount = effectCount;
            for (var i = 0; i < count; i++)
            {
                int[] rarityTable = GetRarityTable(rarityArg);

                var item = itemArg;
                if (item == "random")
                {
                    var weightedRandomTable = new WeightedRandomCollection <string>(_random, allItemNames, x => 1);
                    item = weightedRandomTable.Roll();
                }

                if (ObjectDB.instance.GetItemPrefab(item) == null)
                {
                    __instance.AddString($"> Could not find item: {item}");
                    break;
                }

                __instance.AddString($">  {i + 1} - rarity: [{string.Join(", ", rarityTable)}], item: {item}");

                var loot = new LootTable()
                {
                    Object = "Console",
                    Drops  = new[] { new[] { 1, 1 } },
                    Loot   = new[]
                    {
                        new LootDrop()
                        {
                            Item   = item,
                            Rarity = rarityTable,
                            Weight = 1
                        }
                    }
                };

                var randomOffset = UnityEngine.Random.insideUnitSphere;
                var dropPoint    = Player.m_localPlayer.transform.position + Player.m_localPlayer.transform.forward * 3 + Vector3.up * 1.5f + randomOffset;
                LootRoller.RollLootTableAndSpawnObjects(loot, 1, loot.Object, dropPoint);
            }
            LootRoller.CheatEffectCount = -1;
        }
Exemplo n.º 8
0
        public static void MagicItem(Console __instance, string[] args)
        {
            var rarityArg = args.Length >= 2 ? args[1] : "random";
            var itemArg   = args.Length >= 3 ? args[2] : "random";
            var count     = args.Length >= 4 ? int.Parse(args[3]) : 1;

            __instance.AddString($"magicitem - rarity:{rarityArg}, item:{itemArg}, count:{count}");

            var items        = new List <GameObject>();
            var allItemNames = ObjectDB.instance.m_items
                               .Where(x => EpicLoot.CanBeMagicItem(x.GetComponent <ItemDrop>().m_itemData))
                               .Select(x => x.name)
                               .ToList();

            if (Player.m_localPlayer == null)
            {
                return;
            }

            for (var i = 0; i < count; i++)
            {
                var rarityTable = new[] { 1, 1, 1, 1 };
                switch (rarityArg.ToLowerInvariant())
                {
                case "magic":
                    rarityTable = new[] { 1, 0, 0, 0, };
                    break;

                case "rare":
                    rarityTable = new[] { 0, 1, 0, 0, };
                    break;

                case "epic":
                    rarityTable = new[] { 0, 0, 1, 0, };
                    break;

                case "legendary":
                    rarityTable = new[] { 0, 0, 0, 1, };
                    break;
                }

                var item = itemArg;
                if (item == "random")
                {
                    var weightedRandomTable = new WeightedRandomCollection <string>(_random, allItemNames, x => 1);
                    item = weightedRandomTable.Roll();
                }

                if (ObjectDB.instance.GetItemPrefab(item) == null)
                {
                    __instance.AddString($"> Could not find item: {item}");
                    break;
                }

                __instance.AddString($"  {i + 1} - rarity: [{string.Join(", ", rarityTable)}], item: {item}");

                var loot = new LootTable()
                {
                    Object = "Console",
                    Drops  = new[] { new[] { 1, 1 } },
                    Loot   = new[]
                    {
                        new LootDrop()
                        {
                            Item   = item,
                            Rarity = rarityTable
                        }
                    }
                };

                var randomOffset = UnityEngine.Random.insideUnitSphere;
                var dropPoint    = Player.m_localPlayer.transform.position + Player.m_localPlayer.transform.forward * 3 + Vector3.up * 1.5f + randomOffset;
                items.AddRange(LootRoller.RollLootTableAndSpawnObjects(loot, loot.Object, dropPoint));
            }
        }
Exemplo n.º 9
0
        //Get a block that meets certain requirements.
        LevelBlock GetPossibleLevelBlock(LevelBlockRequirements requirements)
        {
            WeightedRandomCollection<LevelBlock> possibleLevelBlocks = new WeightedRandomCollection<LevelBlock>();

            //Check all level blocks and see which ones would meet the requirements.
            foreach (LevelBlock levelBlock in levelBlocks)
            {
                if (levelBlock.MeetsRequirements(requirements))
                    possibleLevelBlocks.Add(levelBlock, levelBlock.AppearancePreference);
            }

            //If we've not found anything, return null.
            if (possibleLevelBlocks.IsWriteOnly)
                return null;

            //Then return one.
            return possibleLevelBlocks.Get();
        }