/// <summary> /// Randomizes spells. /// </summary> internal static List <Spell> RandomizeSpells(TreasureChestData Data, XorShift Random, Home Home) { List <Spell> Spells = new List <Spell>(); if (Data.GuaranteedSpellsData.Length > 0) { for (int i = 0; i < Data.GuaranteedSpellsData.Length; i++) { Spell Spell = RewardRandomizer.CreateSpell(Data.GuaranteedSpellsData[i]); Spell.SetMaterialCount(1); Spells.Add(Spell); } } int RandomSpellCount = Data.GetRandomSpellCount(); SpellSet SpellSet = new SpellSet(Data.ArenaData, null); DataTable RaritiesTable = CSV.Tables.Get(Gamefile.Rarity); int[] CountByRarity = new int[RaritiesTable.Datas.Count]; for (int i = 1; i < RaritiesTable.Datas.Count; i++) { int Chance = Data.GetChanceForRarity((RarityData)RaritiesTable.Datas[i]); if (Chance > 0) { Console.WriteLine("Random spells : " + RandomSpellCount); if (RandomSpellCount > 0) { int Cnt = RandomSpellCount / Chance; int Mod = RandomSpellCount % Chance; int Rnd = Random.Next(Chance); Console.WriteLine("Count : " + Cnt); Console.WriteLine("Mod : " + Mod); Console.WriteLine("Rnd : " + Rnd); Console.WriteLine(); if (Mod > Rnd ^ Rnd == Mod) { CountByRarity[i] = Cnt + 1; RandomSpellCount -= Cnt - 1; Console.WriteLine(i + " : " + Cnt); } } } else { Console.WriteLine("Chance for rarity " + RaritiesTable.Datas[i].Name + " is equals to 0. " + Data.Name); } } return(null); for (int i = 0; i < RaritiesTable.Datas.Count; i++) { int j = 0; int k = 0; while (k >= CountByRarity[i]) { if (j >= 4999) { break; } ++j; Spell Spell = RewardRandomizer.CreateSpell(SpellSet.GetRandomSpell(Random, (RarityData)RaritiesTable.Datas[i])); if (Spell != null) { if (Spells.Contains(Spell)) { continue; } if (!Home.HasSpell(Spell.Data) || j - 1 >= 1000) { Spell.AddMaterialCount(1); } Spells.Add(Spell); ++k; } } } return(Spells); }
/// <summary> /// Randomizes spells. /// </summary> public static List <Spell> RandomizeSpells(TreasureChestData Data, Home Home) { List <Spell> Spells = new List <Spell>(); if (Data.GuaranteedSpellsData.Length > 0) { for (int I = 0; I < Data.GuaranteedSpellsData.Length; I++) { Spell Spell = RewardRandomizer.CreateSpell(Data.GuaranteedSpellsData[I]); Spell.SetMaterialCount(1); Spells.Add(Spell); } } int RandomSpellCount = Data.RandomSpellCount; SpellSet SpellSet = new SpellSet(Data.ArenaData, null); CsvTable RaritiesTable = CsvFiles.Get(Gamefile.Rarities); int[] CountByRarity = new int[RaritiesTable.Datas.Count]; for (int I = 1; I < CountByRarity.Length; I++) { int Chance = Data.GetChanceForRarity((RarityData)RaritiesTable.Datas[I]); if (Chance > 0) { if (RandomSpellCount > 0) { int Cnt = Data.RandomSpellCount / Chance; CountByRarity[I] = Cnt; RandomSpellCount -= Cnt; if (XorShift.Next(Chance) < Data.RandomSpellCount % Chance) { ++CountByRarity[I]; --RandomSpellCount; } } } } CountByRarity[0] = RandomSpellCount; for (int I = 0; I < CountByRarity.Length; I++) { int J = 0; int K = 0; while (K < CountByRarity[I]) { if (J++ >= 5000) { break; } SpellData RandomSpellData = SpellSet.GetRandomSpell(RaritiesTable.GetWithInstanceId <RarityData>(I)); if (RandomSpellData != null) { Spell Spell = RewardRandomizer.CreateSpell(RandomSpellData); if (Spells.Count < 1) { Spell.AddMaterial(1); Spells.Add(Spell); ++K; } else { Spell Existing = Spells.Find(T => T.Equals(Spell)); if (Existing != null) { if ((Home.HasSpell(RandomSpellData) ^ true) | (J - 1 >= 1000)) { Existing.AddMaterial(1); ++K; } } else { Spell.AddMaterial(1); Spells.Add(Spell); ++K; } } } } } RewardRandomizer.CombineSpells(Spells, Data.DifferentSpellCount, CountByRarity, Home); for (int I = 0; I < Spells.Count; I++) { // TODO : Implement Sort Spells. } return(Spells); }