Advertisement
ShadowEmbrace

Legendary Farming

Nov 12th, 2018
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.40 KB | None | 0 0
  1. <?php
  2.  
  3. $legendary = [
  4.     'fragments' => [0, 'Valanyr'],
  5.     'motes' => [0, 'Dragonwrath'],
  6.     'shards' => [0, 'Shadowmourne']
  7. ];
  8. $junk = [];
  9. $grind = true;
  10.  
  11. while ($grind) {
  12.     $items = array_map('strtolower', explode(' ', readline()));
  13.  
  14.     for ($i = 0; $i < count($items); $i += 2) {
  15.         $quantity = intval($items[$i]);
  16.         $material = $items[$i + 1];
  17.  
  18.         if ($material === 'fragments' || $material === 'motes' || $material === 'shards') {
  19.             $legendary[$material][0] += $quantity;
  20.             if ($legendary[$material][0] >= 250) {
  21.                 echo $legendary[$material][1] . " obtained!" . PHP_EOL;
  22.                 $legendary[$material][0] -= 250;
  23.                 $grind = false;
  24.                 break;
  25.             }
  26.         } else {
  27.             if (!key_exists($material, $junk)) {
  28.                 $junk[$material] = 0;
  29.             }
  30.             $junk[$material] += $quantity;
  31.         }
  32.     }
  33. }
  34.  
  35. uksort($legendary, function ($key1, $key2) use ($legendary) {
  36.     if ($legendary[$key1][0] === $legendary[$key2][0]) {
  37.         return $key1 <=> $key2;
  38.     } else {
  39.         return $legendary[$key2][0] <=> $legendary[$key1][0];
  40.     }
  41. });
  42. ksort($junk);
  43.  
  44. foreach ($legendary as $item => $quantityLeft) {
  45.     echo $item . ': ' . $legendary[$item][0] . PHP_EOL;
  46. }
  47. foreach ($junk as $item => $quantityJunk) {
  48.     echo $item . ': ' . $junk[$item] . PHP_EOL;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement