VGA Bot-Core

Library of functions for NU bot library

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.cn-greasyfork.org/scripts/47367/762362/VGA%20Bot-Core.js

  1. // ==UserScript==
  2. // @name VGA Bot-Core
  3. // @namespace daunting/bot
  4. // @version 0.1
  5. // @date 2018-04-01
  6. // @author Daunting
  7. // @description Library of functions for NU bot library
  8. // @include http://planets.nu/*
  9. // @include http://play.planets.nu/*
  10. // @include http://test.planets.nu/*
  11. // @include userscript
  12. // @resource userscript https://greasyfork.org/en/scripts/35354-planets-nu-build-plan-plugin
  13. // @homepage http://planets.nu
  14. // ==/UserScript==
  15. function wrapper () { // wrapper for injection
  16. if (vgap.version < 3.0)
  17. {
  18. console.log("VGABot-Core plugin requires at least NU version 3.0. Plugin disabled." );
  19. return;
  20. }
  21. var plugin_version = 0.1;
  22. console.log("VGABot-Core plugin version: v" + plugin_version );
  23. /**
  24. * Specify your plugin
  25. * You need to have all those methods defined or errors will be thrown.
  26. * I inserted the print-outs in order to demonstrate when each method is
  27. * being called. Just comment them out once you know your way around.
  28. *
  29. * For any access to plugin class variables and methods,
  30. * "vgap.plugins["vgaBot"].my_variable" has to be used
  31. * instead of "this.my_variable".
  32. */
  33. var vgaBotCore =
  34. {
  35.  
  36. /**
  37. * processload: executed whenever a turn is loaded: either the current turn or
  38. * an older turn through time machine
  39. */
  40. processload: function()
  41. {
  42. console.log("ProcessLoad: plugin called.");
  43. },
  44. /**
  45. * loaddashboard: executed to rebuild the dashboard content after a turn is loaded
  46. */
  47. loaddashboard: function()
  48. {
  49. console.log("LoadDashboard: plugin called.");
  50. },
  51.  
  52. /**
  53. * showdashboard: executed when switching from starmap to dashboard
  54. */
  55. showdashboard: function()
  56. {
  57. console.log("ShowDashboard: plugin called.");
  58. },
  59. /**
  60. * showsummary: executed when returning to the main screen of the dashboard
  61. */
  62. showsummary: function()
  63. {
  64. console.log("ShowSummary: plugin called.");
  65. },
  66. /**
  67. * loadmap: executed after the first turn has been loaded to create the map
  68. * as far as I can tell not executed again when using time machine
  69. */
  70. loadmap: function()
  71. {
  72. console.log("LoadMap: plugin called.");
  73. },
  74. /**
  75. * showmap: executed when switching from dashboard to starmap
  76. */
  77. showmap: function()
  78. {
  79. console.log("ShowMap: plugin called.");
  80. },
  81. /**
  82. * draw: executed on any click or drag on the starmap
  83. */
  84. draw: function()
  85. {
  86. console.log("Draw: plugin called.");
  87. },
  88. /**
  89. * loadplanet: executed a planet is selected on dashboard or starmap
  90. */
  91. loadplanet: function()
  92. {
  93. console.log("LoadPlanet: plugin called.");
  94. },
  95. /**
  96. * loadstarbase: executed a planet is selected on dashboard or starmap
  97. */
  98. loadstarbase: function()
  99. {
  100. console.log("LoadStarbase: plugin called.");
  101. },
  102. /**
  103. * loadship: executed a planet is selected on dashboard or starmap
  104. */
  105. loadship: function()
  106. {
  107. console.log("LoadShip: plugin called.");
  108. },
  109. /***************************************************************************************
  110. * Custom plugin variables
  111. ***************************************************************************************/
  112. missionEnum: {
  113. EXPLORATION: 0,
  114. HISS: 8,
  115. CLOAK: 9,
  116. BEAMFUEL: 10,
  117. BEAMDUR: 11,
  118. BEAMTRIT: 12,
  119. BEAMMOLY: 13,
  120. BEAMSUP: 14
  121. },
  122. /*****************************
  123. * Unload freighters
  124. ******************************/
  125. unloadToPlanet: function(ship, planet)
  126. {
  127. vgap.plugins["vgaBotCore"].transferClans(ship, planet, ship.clans);
  128. vgap.plugins["vgaBotCore"].transferSupplies(ship, planet, ship.supplies);
  129. vgap.plugins["vgaBotCore"].transferDur(ship, planet, ship.duranium);
  130. vgap.plugins["vgaBotCore"].transferTrit(ship, planet, ship.tritanium);
  131. vgap.plugins["vgaBotCore"].transferMoly(ship, planet, ship.molybdenum);
  132. vgap.plugins["vgaBotCore"].transferCredits(ship, planet, ship.megacredits);
  133. },
  134. transferClans: function(src, dest, nClans)
  135. {
  136. if (src.clans >= nClans)
  137. {
  138. if (dest.ownerid == src.ownerid)
  139. {
  140. dest.clans += nClans;
  141. dest.changed = 1;
  142. }
  143. else
  144. {
  145. src.transferclans += nClans;
  146. vgap.plugins["vgaBotCore"].setTransferTarget(src, dest);
  147. }
  148. src.clans -= nClans;
  149. src.changed = 1;
  150. }
  151. },
  152. transferSupplies: function(src, dest, nSupplies)
  153. {
  154. if (src.supplies >= nSupplies)
  155. {
  156. if (dest.ownerid == src.ownerid)
  157. {
  158. dest.supplies += nSupplies;
  159. dest.changed = 1;
  160. }
  161. else
  162. {
  163. src.transfersupplies += nSupplies;
  164. vgap.plugins["vgaBotCore"].setTransferTarget(src, dest);
  165. }
  166. src.supplies -= nSupplies;
  167. src.changed = 1;
  168. }
  169. },
  170. transferDur: function(src, dest, nDur)
  171. {
  172. if (src.duranium >= nDur)
  173. {
  174. if (dest.ownerid == src.ownerid)
  175. {
  176. dest.duranium += nDur;
  177. dest.changed = 1;
  178. }
  179. else
  180. {
  181. src.transferduranium += nDur;
  182. vgap.plugins["vgaBotCore"].setTransferTarget(src, dest);
  183. }
  184. src.duranium -= nDur;
  185. src.changed = 1;
  186. }
  187. },
  188. transferTrit: function(src, dest, nTrit)
  189. {
  190. if (src.tritanium >= nTrit)
  191. {
  192. if (dest.ownerid == src.ownerid)
  193. {
  194. dest.tritanium += nTrit;
  195. dest.changed = 1;
  196. }
  197. else
  198. {
  199. src.transfertritanium += nTrit;
  200. vgap.plugins["vgaBotCore"].setTransferTarget(src, dest);
  201. }
  202. src.tritanium -= nTrit;
  203. src.changed = 1;
  204. }
  205. },
  206. transferMoly: function(src, dest, nMoly)
  207. {
  208. if (src.molybdenum >= nMoly)
  209. {
  210. if (dest.ownerid == src.ownerid)
  211. {
  212. dest.molybdenum += nMoly;
  213. dest.changed = 1;
  214. }
  215. else
  216. {
  217. src.transfermolybdenum += nMoly;
  218. vgap.plugins["vgaBotCore"].setTransferTarget(src, dest);
  219. }
  220. src.molybdenum -= nMoly;
  221. src.changed = 1;
  222. }
  223. },
  224. transferCredits: function(src, dest, nCredits)
  225. {
  226. if (src.megacredits >= nCredits && dest.ownerid == src.ownerid)
  227. {
  228. dest.megacredits += nCredits;
  229. src.megacredits -= nCredits;
  230. src.changed = 1;
  231. dest.changed = 1;
  232. }
  233. },
  234. setTransferTarget: function(src, dest)
  235. {
  236. src.transfertargetid = dest.id;
  237. if (dest.isPlanet)
  238. src.transfertargettype = 1;
  239. else if (dest.isShip)
  240. src.transfertargettype = 0;
  241. },
  242. /*****************************
  243. * Move Ships
  244. ******************************/
  245. findNearestStarbase: function(target)
  246. {
  247. var min = 100000;
  248. var ret = null;
  249. for (var i=0; i<vgap.planets.length; i++)
  250. {
  251. var planet = vgap.planets[i];
  252. if ( planet.ownerid == vgap.player.id && planet.isbase)
  253. {
  254. var distance = vgap.plugins["vgaBotCore"].calcDistance(planet, target);
  255. if (distance < min)
  256. {
  257. min = distance;
  258. ret = planet;
  259. }
  260. }
  261. }
  262. return ret;
  263. },
  264. orbittingPlanet: function(ship)
  265. {
  266. for (var i=0; i<vgap.planets.length; i++)
  267. {
  268. var planet = vgap.planets[i];
  269. if ( (ship.x == planet.x && ship.y == planet.y) )
  270. return planet;
  271. }
  272. return null;
  273. },
  274. /**
  275. * TODO: Need to make sure ships don't go to the same planet.
  276. */
  277. findNearestUnownedPlanet: function(thing)
  278. {
  279. var min = 100000;
  280. var ret = null;
  281. for (var i=0; i<vgap.planets.length; i++)
  282. {
  283. var planet = vgap.planets[i];
  284. if ( (thing.x != planet.x || thing.y != planet.y) && planet.ownerid == 0)
  285. {
  286. var distance = vgap.plugins["vgaBotCore"].calcDistance(planet, thing);
  287. if (distance < min)
  288. {
  289. min = distance;
  290. ret = planet;
  291. }
  292. }
  293. }
  294. return ret;
  295. },
  296. findNearestEnemyPlanet: function(thing)
  297. {
  298. var min = 100000;
  299. var ret = null;
  300. for (var i=0; i<vgap.planets.length; i++)
  301. {
  302. var planet = vgap.planets[i];
  303. if ( (thing.x != planet.x || thing.y != planet.y) && planet.ownerid != 0 && planet.ownerid != vgap.player.id)
  304. {
  305. var distance = vgap.plugins["vgaBotCore"].calcDistance(planet, thing);
  306. if (distance < min)
  307. {
  308. min = distance;
  309. ret = planet;
  310. }
  311. }
  312. }
  313. return ret;
  314. },
  315.  
  316. calcDistance: function(a, b)
  317. {
  318. return Math.sqrt(Math.pow(a.x-b.x,2) + Math.pow(a.y-b.y,2));
  319. },
  320. createWaypoint: function(ship, dest)
  321. {
  322. var waypoint = {id:ship.id, x1:ship.x, y1:ship.y, x2:dest.x, y2:dest.y, color:"#009900", dasharray:null};
  323. ship.lastwaypoint=waypoint;
  324. //vgap.waypoints.push(waypoint);
  325. ship.targetx = dest.x;
  326. ship.targety = dest.y;
  327. ship.target = dest;
  328. ship.warp = ship.engineid;
  329. ship.changed = 1;
  330. },
  331. clearWaypoint: function(ship)
  332. {
  333. ship.lastwaypoint=null;
  334. ship.targetx = ship.x;
  335. ship.targety = ship.y;
  336. ship.target = null;
  337. ship.changed = 1;
  338. },
  339. loadFuel: function(ship)
  340. {
  341. var fuelAvailable = vgap.plugins["vgaBotCore"].getFuelAvailable(ship);
  342. var planet = vgap.plugins["vgaBotCore"].orbittingPlanet(ship);
  343. var sbPlanet = vgap.plugins["vgaBotCore"].findNearestStarbase(ship.target);
  344. var returnFuel = vgap.plugins["vgaBotCore"].calcFuelConsumption(ship, ship.target, sbPlanet, false);
  345. var needed = vgap.plugins["vgaBotCore"].calcFuelConsumption(ship, ship, ship.target, true) + returnFuel;
  346. var added = 0;
  347. console.log("Ship " + ship.id + ": Needed: " + needed + " Ship: " + ship.neutronium + " Available: " + fuelAvailable + " Return: " + returnFuel);
  348. while (needed > ship.neutronium && needed < fuelAvailable)
  349. {
  350. if (needed > ship.neutronium)
  351. {
  352. if (planet != null && planet.ownerid == vgap.player.id)
  353. {
  354. var adding = needed - ship.neutronium;
  355. added += adding;
  356. planet.neutronium -= adding;
  357. ship.neutronium += adding;
  358. }
  359. }
  360. needed = vgap.plugins["vgaBotCore"].calcFuelConsumption(ship, ship, ship.target, true) + returnFuel;
  361. }
  362. if (ship.neutronium < needed && added > 0)
  363. {
  364. ship.neutronium -= added;
  365. planet.neutronium += added;
  366. }
  367. else if (planet != null && planet.neutronium > 0 && planet.ownerid == vgap.player.id)
  368. {
  369. planet.neutronium -= 1;
  370. ship.neutronium += 1;
  371. }
  372. console.log("Added fuel: " + added);
  373. return ship.neutronium >= needed;
  374. },
  375. calcFuelConsumption: function(ship, start, dest, includeCargo)
  376. {
  377. var fuelFactor = vgap.plugins["vgaBotCore"].getFuelFactor(ship);
  378. var mass = vgap.plugins["vgaBotCore"].getMass(ship, includeCargo);
  379. var distance = vgap.plugins["vgaBotCore"].calcDistance(start, dest);
  380. var cloakFuel = 0;
  381. if (ship.mission == vgap.plugins["vgaBotCore"].missionEnum.CLOAK)
  382. {
  383. var turns = Math.ceil(distance / Math.pow(ship.engineid,2));
  384. var hull = vgap.getHull(ship.hullid);
  385. cloakFuel = Math.ceil(hull.mass / 20) * turns;
  386. }
  387. console.log("mass: " + mass + " cloakFuel: " + cloakFuel + " distance: " + distance + " factor: " + fuelFactor);
  388. return Math.truncate(fuelFactor * Math.truncate(mass / 10) * Math.truncate(distance / Math.pow(ship.engineid,2)) / 10000) + cloakFuel;
  389. },
  390. getFuelFactor: function(ship)
  391. {
  392. var engine = vgap.getEngine(ship.engineid);
  393. return engine.warps[ship.engineid-1];
  394. },
  395.  
  396. getMass: function(ship, includeCargo)
  397. {
  398. var mass = 0;
  399. var hull = vgap.getHull(ship.hullid);
  400. mass += hull.mass;
  401. if (ship.torpedoid != 0)
  402. {
  403. var torps = vgap.getTorpedo(ship.torpedoid);
  404. mass += torps.mass * ship.torps;
  405. }
  406. if (ship.beamid != 0)
  407. {
  408. var beam = vgap.getBeam(ship.beamid);
  409. mass += beam.mass * ship.beams;
  410. }
  411. //Will still have ammo
  412. mass += ship.ammo;
  413. if (includeCargo)
  414. {
  415. mass += ship.duranium + ship.tritanium + ship.molybdenum + ship.supplies + ship.clans +
  416. ship.neutronium;
  417. }
  418. return mass;
  419. },
  420. getFuelAvailable: function(ship)
  421. {
  422. var planet = vgap.plugins["vgaBotCore"].orbittingPlanet(ship);
  423. var fuel = ship.neutronium;
  424. if (planet != null && planet.ownerid == ship.ownerid)
  425. fuel += planet.neutronium;
  426. return fuel;
  427. },
  428.  
  429. /****************************
  430. * Intel
  431. *****************************/
  432. hasOrbitingShip: function(planet)
  433. {
  434. var ret = false;
  435. for (var i=0; i<vgap.myships.length; i++)
  436. {
  437. var ship = vgap.myships[i];
  438. if (ship.x == planet.x && ship.y == planet.y)
  439. ret = true;
  440. }
  441. return ret;
  442. },
  443. shouldCloak: function(ship)
  444. {
  445. var cloak = true;
  446. var hull = vgap.getHull(ship.hullid);
  447. //Can it cloak?
  448. if (!hull.cancloak)
  449. cloak = false;
  450. //Is it moving (currently only cloaking when moving ...)?
  451. //TODO: Put in tactical decision to cloak on friendly planets or in space.
  452. if (cloak)
  453. {
  454. if (ship.target == null)
  455. cloak = false;
  456. }
  457. //Target a friendly planet?
  458. if (cloak)
  459. {
  460. if (ship.target.isPlanet && ship.target.ownerid == ship.ownerid)
  461. cloak = false;
  462. }
  463. return cloak;
  464. },
  465.  
  466. /****************************
  467. * Build Ships
  468. *****************************/
  469. calcShipCredits: function(shipAssembly, base)
  470. {
  471. console.log("Ship hull name: " + shipAssembly.hull.name);
  472. var credits = shipAssembly.hull.cost +
  473. shipAssembly.hull.engines * shipAssembly.engine.cost;
  474. if (shipAssembly.hull.launchers != 0 && shipAssembly.torp != null)
  475. credits += shipAssembly.hull.launchers * shipAssembly.torp.launchercost;
  476. if (shipAssembly.hull.beams != 0 && shipAssembly.beam != null)
  477. credits += shipAssembly.hull.beams * shipAssembly.beam.cost;
  478. credits += vgap.plugins["vgaBotCore"].calcTechCost(base.hulltechlevel, shipAssembly.hull.techlevel);
  479. credits += vgap.plugins["vgaBotCore"].calcTechCost(base.enginetechlevel, shipAssembly.engine.techlevel);
  480. credits += vgap.plugins["vgaBotCore"].calcTechCost(base.torptechlevel, shipAssembly.torp.techlevel);
  481. credits += vgap.plugins["vgaBotCore"].calcTechCost(base.beamtechlevel, shipAssembly.beam.techlevel);
  482. return credits;
  483. },
  484. calcTechCost: function(baseTech, shipTech)
  485. {
  486. var cost = 0;
  487. if (baseTech < shipTech)
  488. {
  489. for (i=baseTech; i<shipTech; i++)
  490. cost += i*100;
  491. }
  492. //Have we upgraded to level 9 (i.e. 10)
  493. if (shipTech == 9 && cost > 0)
  494. cost += 900;
  495. if (cost > 0)
  496. {
  497. console.log("Tech Cost: " + cost);
  498. console.log("Upgrade from " + baseTech + " to " + shipTech);
  499. }
  500. return cost;
  501. },
  502. calcShipDur: function(shipAssembly)
  503. {
  504. var dur = shipAssembly.hull.duranium +
  505. shipAssembly.hull.engines * shipAssembly.engine.duranium;
  506. if (shipAssembly.hull.launchers != 0 && shipAssembly.torp != null)
  507. dur += shipAssembly.hull.launchers * shipAssembly.torp.duranium;
  508. if (shipAssembly.hull.beams != 0 && shipAssembly.beam != null)
  509. dur += shipAssembly.hull.beams * shipAssembly.beam.duranium;
  510. return dur;
  511. },
  512. calcShipTrit: function(shipAssembly)
  513. {
  514. var trit = shipAssembly.hull.tritanium +
  515. shipAssembly.hull.engines * shipAssembly.engine.tritanium;
  516. if (shipAssembly.hull.launchers != 0 && shipAssembly.torp != null)
  517. trit += shipAssembly.hull.launchers * shipAssembly.torp.tritanium;
  518. if (shipAssembly.hull.beams != 0 && shipAssembly.beam != null)
  519. trit += shipAssembly.hull.beams * shipAssembly.beam.tritanium;
  520. return trit;
  521. },
  522. calcShipMoly: function(shipAssembly)
  523. {
  524. var moly = shipAssembly.hull.molybdenum +
  525. shipAssembly.hull.engines * shipAssembly.engine.molybdenum;
  526. if (shipAssembly.hull.launchers != 0 && shipAssembly.torp != null)
  527. moly += shipAssembly.hull.launchers * shipAssembly.torp.molybdenum;
  528. if (shipAssembly.hull.beams != 0 && shipAssembly.beam != null)
  529. moly += shipAssembly.hull.beams * shipAssembly.beam.molybdenum;
  530. return moly;
  531. },
  532. findHullNamed: function(hullName)
  533. {
  534. var ret = null;
  535. for (var i=0; i<vgap.hulls.length; i++)
  536. {
  537. if (vgap.hulls[i].name == hullName)
  538. ret = vgap.hulls[i];
  539. }
  540. return ret;
  541. },
  542. assembleShip: function(base, shipAssembly)
  543. {
  544. var planet = vgap.getPlanet(base.planetid);
  545. //Pay for the ship
  546. var credits = vgap.plugins["vgaBotCore"].calcShipCredits(shipAssembly, base);
  547. var dur = vgap.plugins["vgaBotCore"].calcShipDur(shipAssembly);
  548. var trit = vgap.plugins["vgaBotCore"].calcShipTrit(shipAssembly);
  549. var moly = vgap.plugins["vgaBotCore"].calcShipMoly(shipAssembly);
  550. planet.duranium -= dur;
  551. planet.tritanium -= trit;
  552. planet.molybdenum -= moly;
  553. vgap.plugins["vgaBotCore"].payForStructure(planet, 0, credits);
  554. //Upgrade all tech needed
  555. if (base.beamtechlevel < shipAssembly.beam.techlevel)
  556. {
  557. base.beamtechup = shipAssembly.beam.techlevel - base.beamtechlevel;
  558. base.beamtechlevel = shipAssembly.beam.techlevel;
  559. }
  560. if (base.hulltechlevel < shipAssembly.hull.techlevel)
  561. {
  562. base.hulltechup = shipAssembly.hull.techlevel - base.hulltechlevel;
  563. base.hulltechlevel = shipAssembly.hull.techlevel;
  564. }
  565. if (base.enginetechlevel < shipAssembly.engine.techlevel)
  566. {
  567. base.enginetechup = shipAssembly.engine.techlevel - base.enginetechlevel;
  568. base.enginetechlevel = shipAssembly.engine.techlevel;
  569. }
  570. if (base.torptechlevel < shipAssembly.torp.techlevel)
  571. {
  572. base.torptechup = shipAssembly.torp.techlevel - base.torptechlevel;
  573. base.torptechlevel = shipAssembly.torp.techlevel;
  574. }
  575. //Assemble the ship
  576. base.buildbeamcount = shipAssembly.hull.beams;
  577. base.buildbeamid = shipAssembly.beam.id;
  578. var stockitem = vgap.getStock(base.id, 3, shipAssembly.beam.id);
  579. stockitem.builtamount += shipAssembly.hull.beams;
  580. stockitem.amount += shipAssembly.hull.beams;
  581. stockitem.changed = 1;
  582. base.buildengineid = shipAssembly.engine.id;
  583. stockitem = vgap.getStock(base.id, 2, shipAssembly.engine.id);
  584. stockitem.builtamount += shipAssembly.hull.engines;
  585. stockitem.amount += shipAssembly.hull.engines;
  586. stockitem.changed = 1;
  587. base.buildhullid = shipAssembly.hull.id;
  588. stockitem = vgap.getStock(base.id, 1, shipAssembly.hull.id);
  589. stockitem.builtamount += 1;
  590. stockitem.amount += 1;
  591. stockitem.changed = 1;
  592. base.buildtorpcount = shipAssembly.hull.launchers;
  593. base.buildtorpedoid = shipAssembly.torp.id;
  594. stockitem = vgap.getStock(base.id, 4, shipAssembly.torp.id);
  595. stockitem.builtamount += shipAssembly.hull.launchers;
  596. stockitem.amount += shipAssembly.hull.launchers;
  597. stockitem.changed = 1;
  598. base.isbuilding = true;
  599. base.changed = 1;
  600. planet.changed = 1;
  601. },
  602. /*****************************
  603. * Build Structures
  604. ******************************/
  605. calcMaxFactories: function(planet)
  606. {
  607. var nFactories;
  608. if (planet.clans <= 100)
  609. nFactories = planet.clans;
  610. else
  611. nFactories = Math.truncate(100 + Math.sqrt( planet.clans - 100));
  612. return nFactories;
  613. },
  614. calcMaxMines: function(planet)
  615. {
  616. var nMines;
  617. if (planet.clans <= 200)
  618. nMines = planet.clans;
  619. else
  620. nMines = Math.truncate(200 + Math.sqrt( planet.clans - 200));
  621. return nMines;
  622. },
  623. calcMaxDefense: function(planet)
  624. {
  625. var nDefense;
  626. if (planet.clans <= 50)
  627. nDefense = planet.clans;
  628. else
  629. nDefense = Math.truncate(50 + Math.sqrt( planet.clans - 50));
  630. return nDefense;
  631. },
  632. calcDesiredDefense: function(planet)
  633. {
  634. return Math.min(20, vgap.plugins["vgaBotCore"].calcMaxDefense(planet));
  635. },
  636. buildFactories: function(planet, max)
  637. {
  638. while(planet.factories < max && vgap.plugins["vgaBotCore"].payForStructure(planet, 1, 3))
  639. {
  640. planet.factories += 1;
  641. planet.builtfactories += 1;
  642. }
  643. return planet.factories >= max;
  644. },
  645. buildMines: function(planet, max)
  646. {
  647. while(planet.mines < max && vgap.plugins["vgaBotCore"].payForStructure(planet, 1, 4))
  648. {
  649. planet.mines += 1;
  650. planet.builtmines += 1;
  651. }
  652. return planet.mines >= max;
  653. },
  654. buildDefense: function(planet, max)
  655. {
  656. while(planet.defense < max && vgap.plugins["vgaBotCore"].payForStructure(planet, 1, 10))
  657. {
  658. planet.defense += 1;
  659. planet.builtdefense += 1;
  660. }
  661. return planet.defense >= max;
  662. },
  663. payForStructure: function(planet, nSupplies, nCredits)
  664. {
  665. var bought = false;
  666. //Check if we can afford this
  667. if (planet.supplies >= nSupplies && ((planet.supplies + planet.megacredits) > (nSupplies + nCredits)) )
  668. {
  669. bought = true;
  670. planet.supplies -= nSupplies;
  671. var nCreditsSpend = Math.min(planet.megacredits, nCredits);
  672. planet.megacredits -= nCreditsSpend;
  673. nCredits -= nCreditsSpend;
  674. if (nCredits > 0)
  675. {
  676. vgap.plugins["vgaBotCore"].sellSupplies(planet, nCredits);
  677. planet.megacredits -= nCredits;
  678. }
  679. }
  680. return bought;
  681. },
  682. sellSupplies: function(planet, nSupplies)
  683. {
  684. planet.suppliessold += nSupplies;
  685. planet.supplies -= nSupplies;
  686. planet.megacredits += nSupplies;
  687. },
  688. /*****************************
  689. * Tax
  690. ******************************/
  691. }; //End plugin
  692. // register your plugin with NU
  693. vgap.registerPlugin(vgaBot, "vgaBotCore");
  694. } //wrapper for injection
  695.  
  696. var script = document.createElement("script");
  697. script.type = "application/javascript";
  698. script.textContent = "(" + wrapper + ")();";
  699.  
  700. document.body.appendChild(script);
  701. document.body.removeChild(script);