using System; using System.Collections.Generic; using System.Linq; using game; using JetBrains.Annotations; public static class SequenceBuilder { private static readonly Random Random = new Random(); public static List BuildDefault() { return GameSettings.Levels.DefaultSequence as List; } public static List BuildDefaultWithTutorial() { var temp = new List(50); temp.AddRange(GameSettings.Levels.GetIDsBy(l => l.Type == EnumLevelType.TUTORIAL)); temp.AddRange(GameSettings.Levels.DefaultSequence); return temp; } public static List BuildByPattern(IList pattern) { var tutorialLevels = GameSettings.Levels.GetBy(l => l.Type == EnumLevelType.TUTORIAL); var commonLevels = GameSettings.Levels.GetBy(l => l.Type == EnumLevelType.COMMON); var bossLevels = GameSettings.Levels.GetBy(l => l.Type == EnumLevelType.BOSS); var rewardLevels = GameSettings.Levels.GetBy(l => l.Type == EnumLevelType.REWARD); var pvpLevels = GameSettings.Levels.GetBy(l => l.Type == EnumLevelType.PVP); var shuffledLevels = new List(); for (int i = 0; i < pattern.Count; i++) { switch (pattern[i]) { case EnumLevelType.TUTORIAL: AddRandomLevelToShuffle(tutorialLevels, shuffledLevels, pattern[i]); break; case EnumLevelType.COMMON: AddRandomLevelToShuffle(commonLevels, shuffledLevels, pattern[i]); break; case EnumLevelType.BOSS: AddRandomLevelToShuffle(bossLevels, shuffledLevels, pattern[i]); break; case EnumLevelType.REWARD: AddRandomLevelToShuffle(rewardLevels, shuffledLevels, pattern[i]); break; case EnumLevelType.PVP: AddRandomLevelToShuffle(pvpLevels, shuffledLevels, pattern[i]); break; default: throw new ArgumentOutOfRangeException(); } } return shuffledLevels; } private static void AddRandomLevelToShuffle(IList original, [NotNull] List shuffled, EnumLevelType levelType) { if (shuffled == null) throw new ArgumentNullException(nameof(shuffled)); if (original.IsEmpty()) original = GameSettings.Levels.GetBy(l => l.Type == levelType); var randomItem = original.ElementAt(Random.Next(0, original.Count)); shuffled.Add(randomItem.ID); original.Remove(randomItem); } }