hellbound/Assets/Scripts/Game/Save/SequenceBuilder.cs

74 lines
2.7 KiB
C#

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<uint> BuildDefault()
{
return GameSettings.Levels.DefaultSequence as List<uint>;
}
public static List<uint> BuildDefaultWithTutorial()
{
var temp = new List<uint>(50);
temp.AddRange(GameSettings.Levels.GetIDsBy(l => l.Type == EnumLevelType.TUTORIAL));
temp.AddRange(GameSettings.Levels.DefaultSequence);
return temp;
}
public static List<uint> BuildByPattern(IList<EnumLevelType> 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<uint>();
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<LevelData> original, [NotNull] List<uint> 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);
}
}