Exemplo n.º 1
0
        public static void Apply(ControllerOptions controller, string profile)
        {
            int rpos = profile.IndexOf(_seedID);

            if (rpos == -1)
            {
                throw new ArgumentException(string.Format("Missing {0} separator in profile string.", _seedID));
            }
            if (rpos == 0 || rpos == profile.Length - 1)
            {
                throw new ArgumentException("Invalid separator position in profile string.");
            }

            string randoElements = profile.Substring(0, rpos);
            string seedElements  = profile.Substring(rpos + 1); //skip the first seed separator

            List <int> seeds = new List <int>();

            foreach (string seedString in seedElements.Split(_seedID))
            {
                seeds.Add(FromBase(seedString, _seedBase));
            }

            bool randomizeLevelSequencing = false, randomizeUnarmedLevels = false, randomizeAmmolessLevels = false,
                 randomizeSecretRewards = false, randomizeSunsets = false, randomizeAudioTracks = false,
                 randomizeItems = false, randomizeSecrets = false, randomizeEnemies = false, randomizeTextures = false;

            int levelSequencingSeed = -1, unarmledSeed = -1, ammolessSeed = -1,
                secretRewardsSeed = -1, sunsetsSeed = -1, tracksSeed = -1,
                itemsSeed = -1, secretsSeed = -1, enemiesSeed = -1, texturesSeed = -1;

            int unarmedLevelCount = -1, ammolessLevelCount = -1, sunsetCount = -1;

            bool blankTracks = false, includeKeyItems = false, hardSecrets = false;

            for (int i = 0; i < randoElements.Length; i++)
            {
                char randoID = randoElements[i];
                switch (randoID)
                {
                case _levelSeqID:
                    randomizeLevelSequencing = true;
                    break;

                case _unarmedID:
                    randomizeUnarmedLevels = true;
                    break;

                case _ammolessID:
                    randomizeAmmolessLevels = true;
                    break;

                case _rewardsID:
                    randomizeSecretRewards = true;
                    break;

                case _sunsetsID:
                    randomizeSunsets = true;
                    break;

                case _tracksID:
                    randomizeAudioTracks = true;
                    break;

                case _itemsID:
                    randomizeItems = true;
                    break;

                case _enemiesID:
                    randomizeEnemies = true;
                    break;

                case _secretsID:
                    randomizeSecrets = true;
                    break;

                case _texturesID:
                    randomizeTextures = true;
                    break;

                default:
                    continue;
                }

                if (i == randoElements.Length - 1)
                {
                    throw new ArgumentException("Invalid profile string - unexpected EOF.");
                }

                string seedString = randoElements[++i].ToString();
                int    seedIndex  = FromBase(seedString, _intBase);
                if (seedIndex < 0 || seedIndex > seeds.Count - 1)
                {
                    throw new ArgumentException(string.Format("Invalid seed index ({0}).", seedString));
                }

                switch (randoID)
                {
                case _levelSeqID:
                    levelSequencingSeed = seeds[seedIndex];
                    break;

                case _unarmedID:
                    unarmledSeed = seeds[seedIndex];
                    break;

                case _ammolessID:
                    ammolessSeed = seeds[seedIndex];
                    break;

                case _rewardsID:
                    secretRewardsSeed = seeds[seedIndex];
                    break;

                case _sunsetsID:
                    sunsetsSeed = seeds[seedIndex];
                    break;

                case _tracksID:
                    tracksSeed = seeds[seedIndex];
                    break;

                case _itemsID:
                    itemsSeed = seeds[seedIndex];
                    break;

                case _enemiesID:
                    enemiesSeed = seeds[seedIndex];
                    break;

                case _secretsID:
                    secretsSeed = seeds[seedIndex];
                    break;

                case _texturesID:
                    texturesSeed = seeds[seedIndex];
                    break;

                default:
                    continue;
                }

                if (i < randoElements.Length - 2 && !_allIDs.Contains(randoElements[i + 1]))
                {
                    char c = randoElements[++i];
                    switch (randoID)
                    {
                    case _unarmedID:
                        unarmedLevelCount = FromBase(c.ToString(), _intBase);
                        break;

                    case _ammolessID:
                        ammolessLevelCount = FromBase(c.ToString(), _intBase);
                        break;

                    case _sunsetsID:
                        sunsetCount = FromBase(c.ToString(), _intBase);
                        break;

                    case _tracksID:
                        blankTracks = c == _boolID;
                        break;

                    case _secretsID:
                        hardSecrets = c == _boolID;
                        break;

                    case _itemsID:
                        includeKeyItems = c == _boolID;
                        break;
                    }
                }
            }

            controller.RandomizeLevelSequencing = randomizeLevelSequencing;
            controller.RandomizeUnarmedLevels   = randomizeUnarmedLevels;
            controller.RandomizeAmmolessLevels  = randomizeAmmolessLevels;
            controller.RandomizeSecretRewards   = randomizeSecretRewards;
            controller.RandomizeSunsets         = randomizeSunsets;
            controller.RandomizeAudioTracks     = randomizeAudioTracks;
            controller.RandomizeItems           = randomizeItems;
            controller.RandomizeEnemies         = randomizeEnemies;
            controller.RandomizeSecrets         = randomizeSecrets;
            controller.RandomizeTextures        = randomizeTextures;

            if (levelSequencingSeed != -1)
            {
                controller.LevelSequencingSeed = levelSequencingSeed;
            }
            if (unarmledSeed != -1)
            {
                controller.UnarmedLevelsSeed = unarmledSeed;
            }
            if (ammolessSeed != -1)
            {
                controller.AmmolessLevelsSeed = ammolessSeed;
            }
            if (secretRewardsSeed != -1)
            {
                controller.SecretRewardSeed = secretRewardsSeed;
            }
            if (sunsetsSeed != -1)
            {
                controller.SunsetsSeed = sunsetsSeed;
            }
            if (tracksSeed != -1)
            {
                controller.AudioTracksSeed = tracksSeed;
            }
            if (itemsSeed != -1)
            {
                controller.ItemSeed = itemsSeed;
            }
            if (enemiesSeed != -1)
            {
                controller.EnemySeed = enemiesSeed;
            }
            if (secretsSeed != -1)
            {
                controller.SecretSeed = secretsSeed;
            }
            if (texturesSeed != -1)
            {
                controller.TextureSeed = texturesSeed;
            }

            if (unarmedLevelCount > 0)
            {
                controller.UnarmedLevelCount = (uint)unarmedLevelCount;
            }
            if (ammolessLevelCount > 0)
            {
                controller.AmmolessLevelCount = (uint)ammolessLevelCount;
            }
            if (sunsetCount > 0)
            {
                controller.SunsetCount = (uint)sunsetCount;
            }

            controller.RandomAudioTracksIncludeBlank = blankTracks;
            controller.HardSecrets     = hardSecrets;
            controller.IncludeKeyItems = includeKeyItems;
        }