Mission Queue

Put "Mission Commands" in the fleet notes.

当前为 2015-11-07 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Mission Queue
  3. // @namespace http://bitbucket/odahviing
  4. // @description Put "Mission Commands" in the fleet notes.
  5. // @include http://*.war-facts.com/fleet.php*
  6. // @grant GM_xmlhttpRequest
  7. // @version 2.0
  8. // ==/UserScript==
  9.  
  10. // Version 1.0, 1.1, 1.2 - Carabas Amazing Script
  11. // Version 2.0 - Cohenman - Basic support in the new user interface, many bugs still
  12.  
  13. /*
  14. To create a mission, start with the MISSION tags in the fleet notes.
  15. <MISSION step=1>
  16. </MISSION>
  17.  
  18. They must both be on seperate lines. The mission tags are there to
  19. a) let you have other notes
  20. b) give a place for the script to save the current "step".
  21.  
  22. The step=# is the current "step" of the mission queue.
  23. There are two ways to manually set the step. The first, obviously,
  24. is to edit the <MISSION> tag and press the "Take note!" button.
  25. The second, is to enter step:# into the current mission text box and press the button.
  26.  
  27. There are two mission types. They are "mission" and "trade".
  28. Basic syntax:
  29.  
  30. mission:[[restart]transfer|explore|colonize|jump];[planet|system|global|local]:[planetid|systemid|globalcoords|localcoords]
  31. trade:[buy|sell|buyall|sellall|refuel];outpost:outpostid;ship:shipid[;resource:amount[;resource:amount]etc]
  32. trade:buyall, trade:sellall and trade:refuel do not require the resource:amount.
  33.  
  34. outpost and ship are always require for resource trades, however only outpost is
  35. required for the refuel command. The resource:all syntax is also supported.
  36.  
  37. ex: trade:sell;outpost:123;ship:122456;oil:all;iron:50000;gold:all
  38.  
  39. Please pay extra attention to the syntax. Each command is made up of several
  40. field:value pairs. Each part of the pair is seperated by a colon. Each pair is
  41. seperated by a semi-colon.
  42.  
  43. Here are some examples:
  44.  
  45. Basic trade mission:
  46. <MISSION step=1>
  47. mission:transfer;planet:12234
  48. trade:buyall;outpost:123;ship:293458
  49. mission:transfer;planet:12322
  50. trade:sellall;outpost:123;ship:293458
  51. mission:restart
  52. </MISSION>
  53.  
  54. Colonize mission passing through a wormhole, refueling at a warpnet, and colonizing a planet:
  55. <MISSION step=1>
  56. mission:transfer;planet:12345
  57. mission:transfer;planet:12346
  58. mission:transfer;planet:12347
  59. mission:jump;local:85,-20,6
  60. mission:transfer;global:12234,-32468,560
  61. trade:refuel;outpost:123
  62. mission:colonize;planet:12348
  63. </MISSION>
  64. */
  65.  
  66. /* Greasemonkey 20080112 workaround */
  67. function wrap(f) {
  68. return function () {
  69. setTimeout.apply(window, [f, 0].concat([].slice.call(arguments)));
  70. };
  71. }
  72. /* End of workaround */
  73.  
  74. function main() {
  75. if (document.evaluate("//b[text()='In Transit']", document, null, XPathResult.BOOLEAN_TYPE, null).booleanValue) {
  76. return;
  77. }
  78.  
  79. var notes = document.getElementById('fleetNoteContent');
  80. //var note_submit = notes.parentNode.getElementsByTagName('input')[2];
  81. var t;
  82. var b;
  83. var s;
  84. var p;
  85. var form2;
  86. var mnum;
  87. var gets = 0;
  88.  
  89. var restypes = new Array('iron', 'copper', 'silver', 'titanium', 'gold', 'uranium', 'platinum', 'diamonds', 'oil', 'water', 'food');
  90.  
  91. var fleetid = window.location.href.match(/fleet=(\d+)/);
  92. if (fleetid) {
  93. fleetid = fleetid[1];
  94. } else {
  95. return;
  96. }
  97.  
  98. var mission_notes = notes.value.match(/<MISSION step=(\d+)>\n([\s\S]+?)\n<\/MISSION>/);
  99. if (mission_notes) {
  100. t = document.createElement('input');
  101. b = document.createElement('input');
  102. s = document.createElement('input');
  103. t.setAttribute('class', 'text');
  104. t.setAttribute('type', 'text');
  105. t.setAttribute('id', 'missionbox');
  106. t.setAttribute('size', '50');
  107. b.setAttribute('class', 'warn');
  108. b.setAttribute('type', 'button');
  109. b.setAttribute('id', 'missiondo');
  110. b.setAttribute('onclick', 'missionDo(document.getElementById("missionbox").value)');
  111. s.setAttribute('class', 'text');
  112. s.setAttribute('type', 'text');
  113. s.setAttribute('id', 'statusbox');
  114. s.setAttribute('size', '60');
  115. s.disabled = true;
  116. var fleetFrame = document.getElementById('fleetNote');
  117. form2 = fleetFrame.getElementsByClassName('highlight fullwidth padding5')[0];
  118. p = document.createElement('p');
  119. p.appendChild(t);
  120. p.appendChild(b);
  121. p.appendChild(document.createElement('br'));
  122. p.appendChild(s);
  123. form2.appendChild(p);
  124. updateMission();
  125. }
  126.  
  127. function updateMission() {
  128. var missions = mission_notes[2].split("\n");
  129. mnum = mnum != undefined ? mnum : mission_notes[1] - 1;
  130. mnum = (missions[mnum] && missions[mnum].indexOf('restart') == 8) ? 0 : mnum;
  131. var current_mission = missions[mnum] ? missions[mnum] : 'done';
  132.  
  133. if (current_mission.indexOf('done') == 0) {
  134. b.value = "Restart";
  135. } else if (current_mission.indexOf('mission') == 0) {
  136. b.value = "Launch";
  137. } else if (current_mission.indexOf('trade') == 0) {
  138. b.value = "Trade";
  139. }
  140.  
  141. t.value = current_mission;
  142. }
  143.  
  144. function missionDo(mission) {
  145. // Do Mission stuff
  146. var url = 'http://' + window.location.hostname + '/';
  147. var type;
  148. var subtype;
  149. var marray = mission.split(';');
  150.  
  151. for (var i = 0, len = marray.length; i < len; i++) {
  152. var m = marray[i].split(':');
  153.  
  154. // Step
  155. if (m[0] == 'step') {
  156. mnum = m[1] - 1;
  157. saveMission(mnum);
  158. updateMission();
  159. return;
  160. }
  161. // Done
  162. if (m[0] == 'done') {
  163. mnum = 0;
  164. updateMission();
  165. return;
  166. }
  167.  
  168. // Mission
  169. if (type == 'mission') {
  170. switch (m[0]) {
  171. case 'planet':
  172. url += '&tworld2=' + m[1];
  173. break;
  174. case 'system':
  175. url += '&tsystem=' + m[1];
  176. break;
  177. case 'colony':
  178. url += '&tcolony2=' + m[1];
  179. break;
  180. case 'global':
  181. url += '&tpos=global&rawcoords=' + encodeURIComponent(m[1]);
  182. break;
  183. case 'local':
  184. url += '&tpos=local&rawcoords=' + encodeURIComponent(m[1]);
  185. break;
  186. default:
  187. break;
  188. }
  189.  
  190. }
  191. if (m[0] == 'mission') {
  192. url += 'fleet_navigation.php?fleet=' + fleetid;
  193. switch (m[1]) {
  194. case 'transfer':
  195. case 'explore':
  196. case 'transport':
  197. case 'colonize':
  198. case 'jump':
  199. break;
  200. default:
  201. m[1] = 'transfer';
  202. }
  203. url += '&verify=1&mtype=' + m[1];
  204. type = 'mission';
  205. }
  206.  
  207. // Trade
  208. if (m[0] == 'trade') {
  209. var outpost;
  210. var colony;
  211. var ship;
  212. switch (m[1]) {
  213. case 'refuel':
  214. type = 'refuel';
  215. case 'buy':
  216. case 'buyall':
  217. case 'sell':
  218. case 'sellall':
  219. break;
  220. default:
  221. s.value = "Syntax Error!";
  222. return;
  223. }
  224. subtype = m[1];
  225. }
  226.  
  227. if ((outpost && ship) || colony) {
  228. type = 'trade';
  229. }
  230.  
  231. if (type != 'trade') {
  232. switch (m[0]) {
  233. case 'outpost':
  234. outpost = m[1];
  235. url += 'outposttrade.php?fleet=' + fleetid + '&outpost=' + m[1];
  236. outpost = 1;
  237. if (type == 'refuel') {
  238. execMission('trade', url + '&refuel=1');
  239. return;
  240. }
  241. break;
  242. case 'ship':
  243. ship = m[1];
  244. /*url += '&shipselect='+m[1]; ship=1;*/
  245. break;
  246. case 'colony':
  247. colony = m[1];
  248. break;
  249. }
  250. }
  251.  
  252. if (((outpost && ship) || colony) && subtype && subtype != 'load' && subtype != 'unload') {
  253. if (outpost) {
  254. url += 'outposttrade.php?fleet=' + fleetid + '&outpost=' + outpost + '&shipselect=' + ship;
  255. } else if (colony) {
  256. url += 'cargo_fleet.php?posted=1&fleet=' + fleetid + '&colony=' + colony;
  257. }
  258.  
  259. if (mission.indexOf('all') != -1 || mission.indexOf('%') != -1) {
  260. getResources(subtype, url, mission);
  261. return;
  262. }
  263.  
  264. switch (subtype) {
  265. case 'refuel':
  266. break;
  267. case 'sell':
  268. subtype = 'unload';
  269. break;
  270. case 'buy':
  271. subtype = 'load';
  272. break;
  273. //case 'sellall': getResources('sell',url,mission);return;
  274. //case 'buyall': getResources('buy',url,mission);return;
  275. default:
  276. s.value = 'Syntax Error!';
  277. return;
  278. }
  279. }
  280.  
  281. if (type == 'trade') {
  282. if (subtype == 'load' || subtype == 'unload') {
  283. switch (m[0]) {
  284. case 'iron':
  285. case 'copper':
  286. case 'silver':
  287. case 'titanium':
  288. case 'gold':
  289. case 'uranium':
  290. case 'platinum':
  291. case 'diamonds':
  292. case 'oil':
  293. case 'water':
  294. case 'food':
  295. break;
  296. default:
  297. s.value = 'Syntax Error!';
  298. return;
  299. }
  300.  
  301. // Grab trade URL in the background.
  302. if (outpost) {
  303. execMission(type, url + '&cargo_type=' + m[0] + '&lu' + m[0] + '=' + subtype + '&' + m[0] + '=' + m[1]);
  304. } else if (colony) {
  305. url += '&lu' + m[0] + '=' + subtype + '&' + m[0] + '=' + m[1];
  306. }
  307. }
  308. }
  309. }
  310. // Mission Stuff
  311.  
  312. // Go to mission URL
  313. execMission(type, url);
  314. }
  315. exportFunction(missionDo, unsafeWindow, {defineAs: "missionDo"});
  316.  
  317. window.saveMission = wrap(function (mnum) {
  318. mnum++;
  319. s.value += 'Saving Mission... ';
  320. var new_notes = notes.value.replace(/step=\d+/, 'step=' + mnum);
  321. var url = 'http://' + window.location.hostname + '/notemanager.php';
  322. var pars = 'type=fleet&id=' + fleetid + '&note=' + encodeURIComponent(new_notes);
  323. GM_xmlhttpRequest({
  324. method : 'POST',
  325. url : url,
  326. headers : {
  327. 'User-agent' : 'Mozilla/4.0 (compatible) Greasemonkey',
  328. 'Accept' : 'application/atom+xml,application/xml,text/xml,text/html',
  329. 'Content-Type' : 'application/x-www-form-urlencoded'
  330. },
  331. data : pars,
  332. onload : function () {
  333. s.value += 'Done.';
  334. notes.value = new_notes
  335. }
  336. });
  337. });
  338.  
  339. window.execMission = wrap(function (type, url) {
  340. if (type == 'mission') {
  341. mnum++;
  342. saveMission(mnum);
  343. /*updateMission();*/
  344. s.value = 'Launching...';
  345. window.location = url;
  346. } else if (type == 'trade') {
  347. pars = url.split('?')[1];
  348. url = url.split('?')[0];
  349. gets++;
  350. s.value = 'Background Processes: ' + gets;
  351.  
  352. GM_xmlhttpRequest({
  353. method : 'POST',
  354. url : url,
  355. data : pars,
  356. headers : {
  357. 'User-agent' : 'Mozilla/4.0 (compatible) Greasemonkey',
  358. 'Accept' : 'application/atom+xml,application/xml,text/xml,text/html',
  359. 'Content-Type' : 'application/x-www-form-urlencoded'
  360. },
  361. onload : function (responseDetails) {
  362. gets--;
  363. s.value = 'Background Processes: ' + gets;
  364. if (gets == 0) {
  365. mnum++;
  366. s.value = '';
  367. updateMission();
  368. saveMission(mnum);
  369. }
  370. }
  371. });
  372. }
  373. });
  374.  
  375. window.getResources = wrap(function (buysell, url, mission) {
  376. s.value = 'Obtaining Data...';
  377. mission = mission.replace('buyall', 'buy').replace('sellall', 'sell');
  378. var resources = new Array();
  379. var marray = mission.split(';');
  380. var new_mission = new Array();
  381. for (var i = 0, len = marray.length; i < len; i++) {
  382. var res = marray[i].split(':');
  383. if (restypes.indexOf(res[0]) != -1) {
  384. if (res[1].indexOf('%') != -1) {
  385. res[1] = res[1].replace('%', '') / 100;
  386. }
  387. resources[res[0]] = res[1];
  388. } else {
  389. new_mission.push(res[0] + ':' + res[1]);
  390. }
  391. }
  392.  
  393. mission = new_mission.join(';');
  394.  
  395. if (buysell == 'buyall' || buysell == 'sellall') {
  396. for (i in restypes) {
  397. resources[i] = 'all';
  398. }
  399. }
  400.  
  401. GM_xmlhttpRequest({
  402. method : 'GET',
  403. url : url,
  404. headers : {
  405. 'User-agent' : 'Mozilla/4.0 (compatible) Greasemonkey',
  406. 'Accept' : 'application/atom+xml,application/xml,text/xml,text/html',
  407. 'Content-Type' : 'application/x-www-form-urlencoded'
  408. },
  409. onload : function (responseDetails) {
  410. var text = responseDetails.responseText;
  411. //GM_log(text);
  412. var station = text.match(/document\.getElementById\('lo\w+'\)\.checked = true; document\.getElementById\('\w+'\)\.value = \d+/g);
  413. var cargo = text.match(/document\.getElementById\('ul\w+'\)\.checked = true; document\.getElementById\('\w+'\)\.value = \d+/g);
  414.  
  415. var res = (buysell.indexOf('buy') != -1) ? station : cargo;
  416.  
  417. if (res) {
  418. //var resources = new Array();
  419. for (var i = 0, len = res.length; i < len; i++) {
  420. var thisres = res[i].match(/document\.getElementById\('(\w+)'\)\.value = (\d+)/);
  421. if (buysell == 'buyall' || buysell == 'sellall' || resources[thisres[1]] == 'all') {
  422. resources[thisres[1]] = thisres[2];
  423. }
  424. if (resources[thisres[1]] < 1 && resources[thisres[1]] > 0) {
  425. resources[thisres[1]] = Math.round(resources[thisres[1]] * thisres[2]);
  426. }
  427. }
  428.  
  429. res = new Array();
  430. for (i in resources) {
  431. if (resources[i] > 0) {
  432. res.push(i + ':' + resources[i]);
  433. }
  434. }
  435.  
  436. if (res == '') {
  437. s.value = 'The station seems to be empty! ';
  438. mnum++;
  439. updateMission();
  440. saveMission(mnum);
  441. return;
  442. }
  443.  
  444. mission += ';' + res.join(';');
  445.  
  446. // Finally recall missionDo()
  447. window.missionDo(mission);
  448.  
  449. } else {
  450. s.value = 'Your cargo holds are empty! ';
  451. mnum++;
  452. updateMission();
  453. saveMission(mnum);
  454. return
  455. }
  456. }
  457. });
  458. });
  459. }
  460.  
  461. main();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址