Example #1
0
        public override void Randomize(BackgroundWorker backgroundWorker)
        {
            Dictionary <Character, int> plando = main.runSpeedPlando1.GetRunSpeeds();

            if (Flags.Other.RunSpeed)
            {
                Flags.Other.RunSpeed.SetRand();
                StatValues runSpeeds = new StatValues(6);

                Tuple <int, int>[] bounds = runSpeeds.GetVarianceBounds(Flags.Other.RunSpeed.Range.Value);
                for (int i = 0; i < 6; i++)
                {
                    if (plando.ContainsKey((Character)i))
                    {
                        bounds[i] = new Tuple <int, int>(plando[(Character)i] * 100 / 0x60, plando[(Character)i] * 100 / 0x60);
                        characters[GetID((Character)i)].RunSpeed = (byte)plando[(Character)i];
                    }
                }

                runSpeeds.Randomize(bounds, bounds.Where(b => b.Item1 != b.Item2).Count() * Flags.Other.RunSpeed.Range.Value);
                for (int i = 0; i < 6; i++)
                {
                    if (!plando.ContainsKey((Character)i))
                    {
                        characters[GetID((Character)i)].RunSpeed = (byte)Math.Round(0x60 * runSpeeds[i] / 100f);
                    }
                }
                RandomNum.ClearRand();
            }

            if (Tweaks.Boosts.RunSpeedMultiplier)
            {
                for (int i = 0; i < 6; i++)
                {
                    if (!Flags.Other.RunSpeed || !plando.ContainsKey((Character)i))
                    {
                        characters[GetID((Character)i)].RunSpeed = (byte)Math.Round(characters[GetID((Character)i)].RunSpeed * (100 + Tweaks.Boosts.RunSpeedMultiplier.Range.Value) / 100f);
                    }
                }
            }
        }
Example #2
0
        public override void Randomize(BackgroundWorker backgroundWorker)
        {
            Dictionary <Enemy, int[]> plandoStats = main.enemyStatsPlando1.GetStats();
            Dictionary <Enemy, Tuple <Item, Item> > plandoDrops = main.enemyDropPlando1.GetDrops();
            Dictionary <Enemy, Dictionary <Element, ElementalRes> > plandoElementResists = main.enemyElementResistPlando1.GetElementResists();
            Dictionary <Enemy, Dictionary <Debuff, int> >           plandoDebuffResists  = main.enemyDebuffResistPlando1.GetDebuffResists();

            int completed = 0;
            List <DataStoreEnemy> enemyList = Enemies.enemies.Select(eID => enemies[eID.ID]).ToList();

            Enemies.enemies.ForEach(eID =>
            {
                DataStoreEnemy e = enemies[eID];
                byte[] idBytes   = bytes.SubArray(completed * 0x20 + 0x90, 0x10);
                string id        = Encoding.UTF8.GetString(idBytes).Replace("\0", "");

                double hpBase     = 1.1;
                double strMagBase = 1.03;
                double cpBase     = 1.3;

                if (Tweaks.Challenges.BoostLevel)
                {
                    int boost  = Tweaks.Challenges.BoostLevel.Range.Value;
                    e.HP       = (uint)Math.Max(10, e.HP * Math.Pow(hpBase, RandoExtensions.CubeRoot(boost)));
                    e.Strength = (ushort)Math.Max(1, e.Strength * Math.Pow(strMagBase, RandoExtensions.CubeRoot(boost)));
                    e.Magic    = (ushort)Math.Max(1, e.Magic * Math.Pow(strMagBase, RandoExtensions.CubeRoot(boost)));
                }

                if (Flags.EnemyFlags.RandLevel)
                {
                    Flags.EnemyFlags.RandLevel.SetRand();
                    int variance = Flags.EnemyFlags.RandLevel.Range.Value;
                    bool lv0     = e.Level == 0;
                    int level    = lv0 ? 10 : e.Level;
                    if (e.Level < 50)
                    {
                        e.Level = (byte)RandomNum.RandInt(Math.Max(1, e.Level - variance), Math.Min(49, e.Level + variance));
                    }
                    else if (e.Level > 50)
                    {
                        e.Level = (byte)RandomNum.RandInt(Math.Max(51, e.Level - variance), Math.Min(99, e.Level + variance));
                    }
                    if (plandoStats.ContainsKey(eID) && plandoStats[eID][0] > -1)
                    {
                        e.Level = (byte)plandoStats[eID][0];
                    }
                    if (plandoStats.ContainsKey(eID) && plandoStats[eID][6] > -1)
                    {
                        e.CP = (uint)plandoStats[eID][6];
                    }
                    int levelDiff = e.Level - level;

                    e.HP       = (uint)Math.Max(10, e.HP * Math.Pow(hpBase, RandoExtensions.CubeRoot(levelDiff)));
                    e.Strength = (ushort)Math.Max(1, e.Strength * Math.Pow(strMagBase, RandoExtensions.CubeRoot(levelDiff)));
                    e.Magic    = (ushort)Math.Max(1, e.Magic * Math.Pow(strMagBase, RandoExtensions.CubeRoot(levelDiff)));

                    if (e.CP > 0 && (!plandoStats.ContainsKey(eID) || plandoStats[eID][6] == -1))
                    {
                        e.CP = (uint)Math.Max(1, e.CP * Math.Pow(cpBase, RandoExtensions.CubeRoot(levelDiff)));
                    }
                    if (lv0 && (!plandoStats.ContainsKey(eID) || plandoStats[eID][0] == -1))
                    {
                        e.Level = 0;
                    }
                    RandomNum.ClearRand();
                }

                if (Flags.ItemFlags.Drops)
                {
                    if (eID.ParentData != null)
                    {
                        e.CommonDropID = enemies[eID.ParentData].CommonDropID;
                        e.RareDropID   = enemies[eID.ParentData].RareDropID;
                    }
                    else
                    {
                        Flags.ItemFlags.Drops.SetRand();
                        do
                        {
                            RandomizeDrop(e, eID, true, plandoDrops);
                            RandomizeDrop(e, eID, false, plandoDrops);
                        } while (!AreDropsValid(e, eID, plandoDrops));
                        RandomNum.ClearRand();
                    }
                }

                int resistanceModifier = 100, debuffModifier = 100;
                if (Flags.EnemyFlags.RandStats)
                {
                    Flags.EnemyFlags.RandStats.SetRand();
                    StatValues stats = new StatValues(5 + (Flags.EnemyFlags.Resistances ? 1 : 0) + (Flags.EnemyFlags.Debuffs ? 1 : 0));
                    int variance     = Flags.EnemyFlags.RandStats.Range.Value;

                    Tuple <int, int>[] bounds = stats.GetVarianceBounds(variance);
                    if (e.StaggerPoint == 1000)
                    {
                        bounds[4] = new Tuple <int, int>(1000, 1000);
                    }
                    if (plandoStats.ContainsKey(eID))
                    {
                        if (plandoStats[eID][1] > -1)
                        {
                            bounds[0] = new Tuple <int, int>((int)(plandoStats[eID][1] * 100 / Math.Max((int)e.HP, 1)), (int)(plandoStats[eID][1] * 100 / Math.Max((int)e.HP, 1)));
                        }
                        if (plandoStats[eID][2] > -1)
                        {
                            bounds[1] = new Tuple <int, int>((int)(plandoStats[eID][2] * 100 / Math.Max((int)e.Strength, 1)), (int)(plandoStats[eID][2] * 100 / Math.Max((int)e.Strength, 1)));
                        }
                        if (plandoStats[eID][3] > -1)
                        {
                            bounds[2] = new Tuple <int, int>((int)(plandoStats[eID][3] * 100 / Math.Max((int)e.Magic, 1)), (int)(plandoStats[eID][3] * 100 / Math.Max((int)e.Magic, 1)));
                        }
                        if (plandoStats[eID][4] > -1)
                        {
                            bounds[3] = new Tuple <int, int>((int)(plandoStats[eID][4] * 100 / Math.Max((int)e.ChainRes, 1)), (int)(plandoStats[eID][4] * 100 / Math.Max((int)e.ChainRes, 1)));
                        }
                        if (plandoStats[eID][5] > -1)
                        {
                            bounds[4] = new Tuple <int, int>((int)(plandoStats[eID][5] * 100 / Math.Max((int)e.StaggerPoint, 1)), (int)(plandoStats[eID][5] * 100 / Math.Max((int)e.StaggerPoint, 1)));
                        }
                    }

                    if (Flags.EnemyFlags.Resistances && plandoElementResists.ContainsKey(eID) && plandoElementResists[eID].Count == 8)
                    {
                        bounds[5] = new Tuple <int, int>(100, 100);
                    }

                    if (Flags.EnemyFlags.Debuffs && plandoDebuffResists.ContainsKey(eID) && plandoDebuffResists[eID].Count == 11)
                    {
                        bounds[5 + (Flags.EnemyFlags.Resistances ? 1 : 0)] = new Tuple <int, int>(100, 100);
                    }

                    stats.Randomize(bounds, bounds.Where(b => b.Item1 != b.Item2).Count() * variance);
                    e.HP       = (uint)Math.Max(1, e.HP * stats[0] / 100f);
                    e.Strength = (ushort)Math.Max(1, e.Strength * stats[1] / 100f);
                    e.Magic    = (ushort)Math.Max(1, e.Magic * stats[2] / 100f);
                    e.ChainRes = (uint)Math.Min(100, Math.Max(0, Math.Sqrt(Math.Pow(e.ChainRes + 1, 2f) * stats[3] / 100f) - 1));
                    if (bounds[4].Item1 == 1000)
                    {
                        e.StaggerPoint = 1000;
                    }
                    else
                    {
                        e.StaggerPoint = (ushort)Math.Min(999, Math.Max(101, (e.StaggerPoint - 100) * stats[4] / 100f + 100));
                    }
                    RandomNum.ClearRand();
                    if (Flags.EnemyFlags.Resistances)
                    {
                        resistanceModifier = stats[5];
                    }
                    if (Flags.EnemyFlags.Debuffs)
                    {
                        debuffModifier = stats[5 + (Flags.EnemyFlags.Resistances ? 1 : 0)];
                    }
                }

                if (plandoStats.ContainsKey(eID))
                {
                    if (Flags.EnemyFlags.RandStats || Flags.EnemyFlags.RandLevel)
                    {
                        if (plandoStats[eID][1] > -1)
                        {
                            e.HP = (uint)plandoStats[eID][1];
                        }
                        if (plandoStats[eID][2] > -1)
                        {
                            e.Strength = (ushort)plandoStats[eID][2];
                        }
                        if (plandoStats[eID][3] > -1)
                        {
                            e.Magic = (ushort)plandoStats[eID][3];
                        }
                    }
                    if (Flags.EnemyFlags.RandStats)
                    {
                        if (plandoStats[eID][4] > -1)
                        {
                            e.ChainRes = (uint)plandoStats[eID][4];
                        }
                        if (plandoStats[eID][5] > -1)
                        {
                            e.StaggerPoint = (ushort)plandoStats[eID][5];
                        }
                    }
                }

                if (Flags.EnemyFlags.Resistances)
                {
                    Flags.EnemyFlags.Resistances.SetRand();
                    RandomizeElements(e, eID, resistanceModifier, plandoElementResists);
                    RandomNum.ClearRand();
                }

                if (Flags.EnemyFlags.Debuffs)
                {
                    Flags.EnemyFlags.Debuffs.SetRand();
                    RandomizeDebuffs(e, eID, debuffModifier, plandoDebuffResists);
                    RandomNum.ClearRand();
                }

                completed++;
                backgroundWorker.ReportProgress(completed * 100 / enemies.DataList.Count);
            });


            if (Flags.ItemFlags.ShopLocations)
            {
                Flags.ItemFlags.ShopLocations.SetRand();
                List <int> list = scene.IndexesOf(Encoding.UTF8.GetBytes("key_shop_"));

                List <string> shops = list.Select(i => Encoding.UTF8.GetString(scene.SubArray(i, 11))).ToList();
                for (int i = 0; i < shops.Count; i++)
                {
                    shops[i] = randomizers.Get <RandoTreasure>("Treasures").ShopMappings[shops[i]];
                }

                for (int i = 0; i < list.Count; i++)
                {
                    scene.SetSubArray(list[i], Encoding.UTF8.GetBytes(shops[i]));
                }
                RandomNum.ClearRand();
            }
        }