Esempio n. 1
0
 private void addEvosToList(List<Evolution> evoList, Evolution baseEvo, int baseMonsterId)
 {
     MonsterCard card = FindMonsterCard(baseEvo.EvolvesTo);
     foreach(Evolution evo in card.Evolutions)
     {
         if(!evoList.Any(e => e.EvolvesTo == evo.EvolvesTo) && baseMonsterId != evo.EvolvesTo)
         {
             Evolution newEvo = new Evolution();
             newEvo.EvolvesTo = evo.EvolvesTo;
             newEvo.Materials.AddRange(baseEvo.Materials);
             foreach(EvoMaterial mat in evo.Materials)
             {
                 if(newEvo.Materials.Any(m => m.MonsterCardId == mat.MonsterCardId))
                 {
                     newEvo.Materials.First(m => m.MonsterCardId == mat.MonsterCardId).Count += mat.Count;
                 }
                 else
                 {
                     EvoMaterial newMat = new EvoMaterial();
                     newMat.MonsterCardId = mat.MonsterCardId;
                     newMat.Count = mat.Count;
                     newEvo.Materials.Add(newMat);
                 }
             }
             evoList.Add(newEvo);
             Console.WriteLine("added evolution" + MonsterNameByID(newEvo.EvolvesTo));
             addEvosToList(evoList, newEvo, baseMonsterId);
         }
     }
 }
Esempio n. 2
0
 public void ParseEvolutions()
 {
     using (StreamReader file = File.OpenText(EvolutionFile))
     {
         
         JObject evolutionsJS = (JObject)JToken.ReadFrom(new JsonTextReader(file));
         IList<string> keys = evolutionsJS.Properties().Select(p => p.Name).ToList();
         foreach(string key in keys)
         {
             int id = 0;                    
             if(int.TryParse(key,out id))
             {
                 MonsterCard monster = FindMonsterCard(id);                        
                 foreach(JObject evolutionJS in evolutionsJS[key])
                 {
                     Evolution evolution = new Evolution();
                     evolution.EvolvesTo = (int)evolutionJS["evolves_to"];
                     List<Evolution> dupes = monster.Evolutions.FindAll(monst => monst.EvolvesTo == evolution.EvolvesTo);
                     if (dupes.Count == 0)
                     {
                         evolution.IsUltimate = bool.Parse(evolutionJS["is_ultimate"].ToString());
                         foreach (JArray material in evolutionJS["materials"])
                         {
                             EvoMaterial mat = new EvoMaterial();
                             mat.MonsterCardId = (int)material[0];
                             mat.Count = (int)material[1];
                             evolution.Materials.Add(mat);
                         }
                         monster.Evolutions.Add(evolution);
                     }
                     //Console.WriteLine(evolutionJS);
                 }
                 //evolutions.Add(evolutionEntry);                     
                 
             }
             //Console.WriteLine(key);
         }                
     }
 }