LardaX

Legendary-Farming-Old

Oct 8th, 2016
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.51 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Legendary_Farming_Old
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Dictionary<string, int> materials = new Dictionary<string, int>();
  14.             string legendarySword = "";
  15.  
  16.             while (true)
  17.             {
  18.                 string[] materialsObtained = Console.ReadLine().ToLower().Split().ToArray();
  19.  
  20.                 bool isEnough = false;
  21.  
  22.                 for (int i = 1; i < materialsObtained.Length; i += 2)
  23.                 {
  24.                     if (!materials.ContainsKey(materialsObtained[i]))
  25.                     {
  26.                         materials.Add(materialsObtained[i], 0);
  27.                     }
  28.  
  29.                     materials[materialsObtained[i]] += int.Parse(materialsObtained[i - 1]);
  30.  
  31.                     if (materials[materialsObtained[i]] >= 250)
  32.                     {
  33.  
  34.                         if (materialsObtained[i].Equals("shards"))
  35.                         {
  36.                             legendarySword = "Shadowmourne";
  37.                             isEnough = true;
  38.                             break;
  39.                         }
  40.                         else if (materialsObtained[i].Equals("fragments"))
  41.                         {
  42.                             legendarySword = "Valanyr";
  43.                             isEnough = true;
  44.                             break;
  45.                         }
  46.                         else if (materialsObtained[i].Equals("motes"))
  47.                         {
  48.                             legendarySword = "Dragonwrath";
  49.                             isEnough = true;
  50.                             break;
  51.                         }
  52.                     }
  53.                     if (isEnough)
  54.                     {
  55.                         break;
  56.                     }
  57.                 }
  58.  
  59.                 if (isEnough)
  60.                 {
  61.                     break;
  62.                 }
  63.             }
  64.  
  65.             PrintWeapon(materials, legendarySword);
  66.  
  67.         }
  68.  
  69.         private static void PrintWeapon(Dictionary<string, int> materials, string legendarySword)
  70.         {
  71.             Console.WriteLine($"{legendarySword} obtained!");
  72.             Dictionary<string, int> legendaryMaterials = new Dictionary<string, int>();
  73.             SortedDictionary<string, int> otherMaterials = new SortedDictionary<string, int>();
  74.  
  75.             FillDictionaries(materials, legendaryMaterials, otherMaterials);
  76.  
  77.             PrintLegendaryMaterials(legendaryMaterials);
  78.             PrintOtherMaterials(otherMaterials);
  79.  
  80.         }
  81.  
  82.         private static void PrintOtherMaterials(SortedDictionary<string, int> otherMaterials)
  83.         {
  84.             foreach (KeyValuePair<string, int> material in otherMaterials)
  85.             {
  86.                 Console.WriteLine($"{material.Key}: {material.Value}");
  87.             }
  88.         }
  89.  
  90.         private static void PrintLegendaryMaterials(Dictionary<string, int> legendaryMaterials)
  91.         {
  92.             foreach (KeyValuePair<string, int> material in legendaryMaterials.OrderByDescending(x => x.Value).ThenBy(x => x.Key))
  93.             {
  94.                 Console.WriteLine($"{material.Key}: {material.Value}");
  95.             }
  96.         }
  97.  
  98.         private static void FillDictionaries(Dictionary<string, int> materials, Dictionary<string, int> legendaryMaterials, SortedDictionary<string, int> otherMaterials)
  99.         {
  100.             foreach (KeyValuePair<string, int> material in materials)
  101.             {
  102.                 if (material.Key.Equals("shards") || material.Key.Equals("fragments") || material.Key.Equals("motes"))
  103.                 {
  104.                     legendaryMaterials.Add(material.Key, material.Value);
  105.                     if (material.Value > 250)
  106.                     {
  107.                         legendaryMaterials[material.Key] -= 250;
  108.                     }
  109.                 }
  110.                 else
  111.                 {
  112.                     otherMaterials.Add(material.Key, material.Value);
  113.                 }
  114.             }
  115.             if (!legendaryMaterials.ContainsKey("fragments"))
  116.             {
  117.                 legendaryMaterials.Add("fragments", 0);
  118.             }
  119.             if (!legendaryMaterials.ContainsKey("shards"))
  120.             {
  121.                 legendaryMaterials.Add("shards", 0);
  122.             }
  123.             if (!legendaryMaterials.ContainsKey("motes"))
  124.             {
  125.                 legendaryMaterials.Add("motes", 0);
  126.             }
  127.         }
  128.     }
  129. }
Add Comment
Please, Sign In to add comment