Advertisement
goodwin64

HWM - parse castle buildings

May 3rd, 2024
793
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const names = [...$$('#all_buildings_list .castle_build_div_outside .castle_build_name_inside')].map(
  2.   (el) => el.innerText
  3. );
  4.  
  5. const levelsForGold = [...$$('#all_buildings_list .castle_build_div_outside')]
  6.   .map((el) =>
  7.     el.querySelector(
  8.       '.castle_cost .castle_cost_line:not(:has( img[src*="diamonds"] )) .castle_amount_icon:has(img[src*="attr_level"])'
  9.     )
  10.   )
  11.   .map((el) => el?.innerText || '')
  12.   .map((str) => str.replaceAll(',', ''))
  13.   .map(Number);
  14.  
  15. const levelsForDiamonds = [...$$('#all_buildings_list .castle_build_div_outside')]
  16.   .map((el) =>
  17.     el.querySelector(
  18.       '.castle_cost .castle_cost_line:has( img[src*="diamonds"] ) .castle_amount_icon:has(img[src*="attr_level"])'
  19.     )
  20.   )
  21.   .map((el) => el?.innerText || '')
  22.   .map((str) => str.replaceAll(',', ''))
  23.   .map(Number);
  24.  
  25. const costsGold = [...$$('#all_buildings_list .castle_build_div_outside')]
  26.   .map((el) => el.querySelector('.castle_cost .castle_amount_icon:has(img[src*="gold"])'))
  27.   .map((el) => el?.innerText || '')
  28.   .map((str) => str.replaceAll(',', ''))
  29.   .map(Number);
  30.  
  31. const costsOre = [...$$('#all_buildings_list .castle_build_div_outside')]
  32.   .map((el) => el.querySelector('.castle_cost .castle_amount_icon:has(img[src*="ore"])'))
  33.   .map((el) => el?.innerText || '')
  34.   .map((str) => str.replaceAll(',', ''))
  35.   .map(Number);
  36.  
  37. const costsWood = [...$$('#all_buildings_list .castle_build_div_outside')]
  38.   .map((el) => el.querySelector('.castle_cost .castle_amount_icon:has(img[src*="wood"])'))
  39.   .map((el) => el?.innerText || '')
  40.   .map((str) => str.replaceAll(',', ''))
  41.   .map(Number);
  42.  
  43. const costsMercury = [...$$('#all_buildings_list .castle_build_div_outside')]
  44.   .map((el) => el.querySelector('.castle_cost .castle_amount_icon:has(img[src*="mercury"])'))
  45.   .map((el) => el?.innerText || '')
  46.   .map((str) => str.replaceAll(',', ''))
  47.   .map(Number);
  48.  
  49. const costsSulfur = [...$$('#all_buildings_list .castle_build_div_outside')]
  50.   .map((el) => el.querySelector('.castle_cost .castle_amount_icon:has(img[src*="sulfur"])'))
  51.   .map((el) => el?.innerText || '')
  52.   .map((str) => str.replaceAll(',', ''))
  53.   .map(Number);
  54.  
  55. const costsCrystals = [...$$('#all_buildings_list .castle_build_div_outside')]
  56.   .map((el) => el.querySelector('.castle_cost .castle_amount_icon:has(img[src*="crystals"])'))
  57.   .map((el) => el?.innerText || '')
  58.   .map((str) => str.replaceAll(',', ''))
  59.   .map(Number);
  60.  
  61. const costsGems = [...$$('#all_buildings_list .castle_build_div_outside')]
  62.   .map((el) => el.querySelector('.castle_cost .castle_amount_icon:has(img[src*="gems"])'))
  63.   .map((el) => el?.innerText || '')
  64.   .map((str) => str.replaceAll(',', ''))
  65.   .map(Number);
  66.  
  67. const costsDiamonds = [...$$('#all_buildings_list .castle_build_div_outside')]
  68.   .map((el) => el.querySelector('.castle_cost .castle_amount_icon:has(img[src*="diamonds"])'))
  69.   .map((el) => el?.innerText || '')
  70.   .map((str) => str.replaceAll(',', ''))
  71.   .map(Number);
  72.  
  73. const buildings = names.map((name, i) => {
  74.   const result = {
  75.     name,
  76.     purchaseForGoldAndResources: {
  77.       priceGold: costsGold[i],
  78.       minRequiredLevelForGold: levelsForGold[i],
  79.     },
  80.     race: 'KNIGHT',
  81.   };
  82.  
  83.   if (costsWood[i] || costsOre[i] || costsMercury[i] || costsSulfur[i] || costsCrystals[i] || costsGems[i]) {
  84.     result.purchaseForGoldAndResources.priceResources = {};
  85.     if (costsWood[i]) result.purchaseForGoldAndResources.priceResources.WOOD = costsWood[i];
  86.     if (costsOre[i]) result.purchaseForGoldAndResources.priceResources.ORE = costsOre[i];
  87.     if (costsMercury[i]) result.purchaseForGoldAndResources.priceResources.MERCURY = costsMercury[i];
  88.     if (costsSulfur[i]) result.purchaseForGoldAndResources.priceResources.SULFUR = costsSulfur[i];
  89.     if (costsCrystals[i]) result.purchaseForGoldAndResources.priceResources.CRYSTAL = costsCrystals[i];
  90.     if (costsGems[i]) result.purchaseForGoldAndResources.priceResources.GEMS = costsGems[i];
  91.   }
  92.  
  93.   if (costsDiamonds[i]) {
  94.     result.purchaseForDiamonds = {
  95.       priceDiamonds: costsDiamonds[i],
  96.       minRequiredLevelForDiamonds: levelsForDiamonds[i],
  97.     };
  98.   }
  99.  
  100.   return result;
  101. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement