/// <summary> /// Reads a data reference. /// </summary> public static T DecodeData <T>(this ByteStream Stream) where T : CsvData { int Type = Stream.ReadVInt(); if (Type > 0) { CsvTable Table = CsvFiles.Get(Type); if (Table != null) { return(Table.GetWithInstanceId(Stream.ReadVInt()) as T); } Logging.Error(typeof(StreamHelper), "ReadData() - Table " + Type + " doesn't exists."); } return(null); }
/// <summary> /// Reads a data reference. /// </summary> public static T DecodeLogicData <T>(this ByteStream Stream, int BaseType) where T : CsvData { int Id = Stream.ReadVInt(); if (Id > 0) { while (true) { CsvTable Table = CsvFiles.Get(BaseType++); if (Id <= Table.Datas.Count) { return(Table.GetWithInstanceId(Id - 1) as T); } Id -= Table.Datas.Count; } } return(null); }
/// <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); }