Flight Rising Baldwin

Automatically transmutes items from your list.

目前为 2023-09-22 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Flight Rising Baldwin
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.3
  5. // @description Automatically transmutes items from your list.
  6. // @author Triggernometry
  7. // @match https://www1.flightrising.com/trading/baldwin/transmute*
  8. // @grant none
  9. // @license GNU GPLv3
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14. getState();
  15. })();
  16.  
  17. // Categories are food, mats, app, fam, other
  18.  
  19. var transmuteItems = {
  20. "food" : [],
  21. "mats" : [],
  22. "app" : [],
  23. "fam" : [],
  24. "other" : []
  25. };
  26.  
  27. // set this to true to automatically melt down all food items with a point value of 2.
  28. // the script will check the list if it doesn't find any 2-value food items, so you can still fill out the list if you use this option.
  29. var autoMeltFood = false;
  30.  
  31. async function getFood(maxPoints) {
  32. // switch to food category tab, if not already selected
  33. while(document.querySelector('#swaptabs > a[data-tab-id="food"]').className != 'generic-hoard-tab generic-hoard-tab-selected') {
  34. console.log("Swapping to food tab");
  35. let chooseCategory = document.querySelector('#swaptabs > a[data-tab-id="food"]').click();
  36. await sleep(2000);
  37. }
  38.  
  39. // get all items in category
  40. let itemList = document.querySelectorAll('#itempage > span > a');
  41.  
  42. // compare to own list of allowed items
  43. for (const node of itemList) {
  44. // get tooltip name
  45. var tooltipID = node.getAttribute('rel');
  46. // get first matching tooltip. this might fail if similar tooltips exist, like #17 and #177? need to test
  47. var tooltip = document.querySelectorAll(`${tooltipID} .foodval > strong`)[0];
  48. //console.log("Tooltip", tooltipID, "Foodval", tooltip.firstChild.data);
  49. var foodPoints = Number(tooltip.firstChild.data);
  50.  
  51. if(foodPoints <= maxPoints ) {
  52. // if allowed item found, set and break loop
  53. console.log("Found food:", node);
  54. return node;
  55. }
  56. }
  57.  
  58. //if reached end of loop without returning, no valid food found
  59. return null;
  60. }
  61.  
  62. async function getMatchingTransmutable() {
  63. for (const key of Object.keys(transmuteItems)) {
  64. let valueList = transmuteItems[key];
  65. console.log("key:", key);
  66. // switch to category tab
  67. let chooseCategory = document.querySelector(`#swaptabs > a[data-tab-id="${key}"]`).click();
  68. await sleep(2000);
  69.  
  70. // get all items in category
  71. let itemList = document.querySelectorAll('#itempage > span > a');
  72.  
  73. // compare to own list of allowed items
  74. for (const node of itemList) {
  75. if(valueList.includes(node.getAttribute('data-name'))) {
  76. // if allowed item found, return and break loops
  77. return node;
  78. }
  79. }
  80. }
  81.  
  82. //if reached end of loop without returning, no item found
  83. return null;
  84. }
  85.  
  86. function getState(){
  87.  
  88. let idle = document.querySelector('#plus-button-container');
  89. let brewing = document.querySelector('.baldwin-cauldron-brewing');
  90. let done = document.querySelector('.baldwin-cauldron-done');
  91.  
  92. if(done){
  93. collectItem();
  94. } else if (brewing){
  95. brewingWait();
  96. } else if(idle){
  97. transmute();
  98. }
  99. }
  100.  
  101. async function collectItem(){
  102. await sleep(2000);
  103. let collectDoneItem = document.querySelector('input[value="Collect!"]').click();
  104. // wait for page to load after click
  105. // await collectDoneItem.DOMContentLoaded();
  106. await sleep(2000);
  107. location.reload();
  108. }
  109.  
  110. async function brewingWait(){
  111. let brewingTime = document.querySelector('#baldwin-timer-value').getAttribute('data-seconds-left');
  112. brewingTime = parseInt(brewingTime) + 3;
  113. console.log(`Now waiting for ${brewingTime} seconds. Please Stand by.`)
  114. await sleep(brewingTime * 1000);
  115. location.reload();
  116. }
  117.  
  118. async function transmute(){
  119. let clickTransmuteButton = document.querySelector('#baldwin-transmute-btn');
  120. console.log("Click return object:", clickTransmuteButton);
  121.  
  122. // wait for item load
  123. // if Transmute button is clicked multiple times, page breaks
  124. while(!document.querySelector('#ui-id-1'))
  125. {
  126. await sleep(2000);
  127. clickTransmuteButton.click();
  128. await sleep(2000);
  129. }
  130.  
  131. var transmuteSelection;
  132.  
  133. if (autoMeltFood) {
  134. transmuteSelection = await getFood(2);
  135. }
  136.  
  137. if (!transmuteSelection) {
  138. transmuteSelection = await getMatchingTransmutable();
  139. }
  140.  
  141. // if not null, item found
  142. if(transmuteSelection) {
  143. console.log("Selected food:", transmuteSelection);
  144.  
  145. transmuteSelection.click();
  146. await sleep(1000);
  147. let transmuteStart = document.querySelector('#attch').click();
  148. await sleep(2000);
  149. let transmuteConfirm = document.querySelector('#transmute-confirm-ok').click();
  150. }
  151. // otherwise, reached end of items without findin a match. Exit.
  152. else {
  153. console.log("Reached end without finding a match. Nothing to brew.");
  154. return 0;
  155. }
  156. }
  157.  
  158. function sleep(ms) {
  159. console.log(`Sleebs ${ms} ms!`);
  160. return new Promise(resolve => setTimeout(resolve, ms));
  161. }