Pardus Building Class

Building class used by Pardus Trader Autopilot

目前为 2023-06-09 提交的版本。查看 最新版本

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

  1. // ==UserScript==
  2. // @name Pardus Building Class
  3. // @namespace fear.math@gmail.com
  4. // @version 2.0.0
  5. // @description Building class used by Pardus Trader Autopilot
  6. // @author Math (Orion)
  7. // ==/UserScript==
  8.  
  9. class Building {
  10. // Credit to Taised (tiziano.m@infinito.it) who hosts the original version of this data at
  11. // 'http://www.fantamondi.it/pardus/common/building_data.js
  12. static buildingData = [
  13. { type: "Energy Well", tier: 0, resources: { "food": -1, "water": -1, "energy": 6 } },
  14. { type: "Nebula Plant", tier: 0, resources: { "food": -2, "water": -2, "ematter": -3, "energy": 35, "gas": 4 } },
  15. { type: "Space Farm", tier: 0, resources: { "energy": -4, "embryos": -5, "food": 8, "water": 2, "biowaste": 1 } },
  16.  
  17. { type: "Asteroid Mine", tier: 1, resources: { "food": -1, "energy": -1, "water": -1, "ore": 9, "gems": 2 } },
  18. { type: "Chemical Laboratory", tier: 1, resources: { "food": -1, "energy": -3, "water": -1, "chems": 9 } },
  19. { type: "Gas Collector", tier: 1, resources: { "food": -2, "energy": -2, "water": -2, "gas": 20 } },
  20. { type: "Radiation Collector", tier: 1, resources: { "food": -1, "energy": -3, "water": -1, "cells": 6 } },
  21.  
  22. { type: "Alliance Command Station", tier: 2, resources: { "energy": -6, "cells": -2 } },
  23. { type: "Brewery", tier: 2, resources: { "food": -2, "energy": -2, "water": -2, "chems": -4, "liquor": 4 } },
  24. { type: "Clod Generator", tier: 2, resources: { "biowaste": -18, "energy": -4, "chems": -4, "clod": 5 } },
  25. { type: "Fuel Collector", tier: 2, resources: { "energy": -4, "chems": -1, "fuel": 30 } },
  26. { type: "Medical Laboratory", tier: 2, resources: { "food": -2, "energy": -2, "water": -2, "gas": -7, "medics": 4 } },
  27. { type: "Military Outpost", tier: 2, resources: { "energy": -5, "fuel": -5 } },
  28. { type: "Optics Research Center", tier: 2, resources: { "food": -1, "energy": -3, "water": -1, "gems": -2, "optics": 10 } },
  29. { type: "Plastics Facility", tier: 2, resources: { "food": -2, "energy": -2, "water": -2, "chems": -3, "gas": -3, "plastics": 6 } },
  30. { type: "Recyclotron", tier: 2, resources: { "biowaste": -5, "energy": -3, "chems": -1, "food": 7, "water": 5 } },
  31. { type: "Smelting Facility", tier: 2, resources: { "food": -2, "energy": -2, "water": -2, "ore": -6, "metal": 12 } },
  32.  
  33. { type: "Electronics Facility", tier: 3, resources: { "food": -1, "energy": -4, "water": -1, "plastics": -2, "metal": -3, "electronics": 6 } },
  34. { type: "Leech Nursery", tier: 3, resources: { "food": -2, "energy": -6, "water": -10, "cells": -6, "clod": -40, "leech": 1, "biowaste": 3 } },
  35. { type: "Neural Laboratory", tier: 3, resources: { "food": -2, "water": -2, "energy": -2, "embryos": -12, "medics": -2, "tissue": 16 } },
  36. { type: "Slave Camp", tier: 3, resources: { "food": -3, "energy": -1, "water": -3, "liquor": -2, "medics": -2, "slaves": 3 } },
  37.  
  38. { type: "Battleweapons Factory", tier: 4, resources: { "food": -1, "energy": -2, "water": -1, "metal": -3, "optics": -4, "electronics": -3, "bwps": 2 } },
  39. { type: "Dark Dome", tier: 4, resources: { "slaves": -3, "energy": -1, "bodyparts": 12, "biowaste": 4 } },
  40. // { type: "Dark Dome (TSS)", tier: 4, resources: { "slaves": -2, "energy": -1, "bodyparts": 12, "biowaste": 4 } },
  41. { type: "Drug Station", tier: 4, resources: { "food": -3, "energy": -1, "water": -3, "slaves": -4, "ematter": -3, "drugs": 1 } },
  42. // { type: "Drug Station (TSS)", tier: 4, resources: { "food": -3, "energy": -1, "water": -3, "slaves": -3, "ematter": -3, "drugs": 1 } },
  43. { type: "Handweapons Factory", tier: 4, resources: { "food": -1, "energy": -2, "water": -1, "plastics": -3, "optics": -3, "electronics": -3, "hws": 2 } },
  44. { type: "Robots Factory", tier: 4, resources: { "food": -2, "energy": -2, "water": -2, "metal": -1, "optics": -2, "electronics": -4, "bots": 3 } },
  45. { type: "Stim Chip Mill", tier: 4, resources: { "food": -3, "water": -3, "ematter": -2, "tissue": -44, "electronics": -2, "stims": 2 } },
  46.  
  47. { type: "Droid Assembly Complex", tier: 5, resources: {"food": -1, "energy": -3, "water": -1, "cells": -3, "bots": -2, "droids": 1} }
  48. ];
  49.  
  50. constructor(type, sector, x, y, level = 8, stock = {}, lastViewed) {
  51. this.type = type;
  52. this.sector = sector;
  53. this.x = x;
  54. this.y = y;
  55. this.level = level;
  56. this.stock = stock;
  57. this.lastViewed = lastViewed;
  58. }
  59.  
  60. get coords() {
  61. return `[${this.x},${this.y}]`;
  62. }
  63.  
  64. // Setters for level, stock, and lastViewed
  65. setLevel(level) {
  66. this.level = level;
  67. }
  68.  
  69. setStock(stock) {
  70. this.stock = stock;
  71. }
  72.  
  73. setLastViewed(lastViewed) {
  74. this.lastViewed = lastViewed;
  75. }
  76.  
  77. // Calculate the guessed current stock based on lastViewed time and building characteristics
  78. guessCurrentStock() {
  79. const ticksPassed = this.calculateTicksPassed();
  80. const productionConsumption = this.calculateProductionConsumption();
  81. const guessedStock = {};
  82.  
  83. // Calculate the guessed stock for each commodity
  84. for (const commodity in productionConsumption) {
  85. if (productionConsumption.hasOwnProperty(commodity)) {
  86. const lastStock = this.stock[commodity] || 0;
  87. const change = productionConsumption[commodity] * ticksPassed;
  88. guessedStock[commodity] = lastStock + change;
  89. }
  90. }
  91.  
  92. return guessedStock;
  93. }
  94.  
  95. // Calculate the number of building ticks that have passed since lastViewed
  96. calculateTicksPassed() {
  97. const millisecondsPerTick = 6 * 60 * 60 * 1000; // Milliseconds per tick
  98.  
  99. const now = new Date();
  100. const lastViewed = new Date(this.lastViewed);
  101.  
  102. // Adjust the last viewed time forward to the nearest tick time (1:25 GMT and every 6 hours)
  103. lastViewed.setUTCMinutes(Math.round(Math.ceil((lastViewed.getUTCMinutes() - 25) / 60) * 60 + 25));
  104. lastViewed.setUTCHours(Math.round(Math.ceil((lastViewed.getUTCHours() - 1) / 6) * 6 + 1));
  105.  
  106. // Calculate the time difference in milliseconds
  107. const timeDiff = now - lastViewed;
  108.  
  109. // Calculate the number of ticks passed
  110. const ticksPassed = Math.ceil(timeDiff / millisecondsPerTick);
  111.  
  112. return ticksPassed;
  113. }
  114.  
  115. // Calculate the production and consumption rates based on the building type and level
  116. calculateProduction() {
  117. const buildingData = Building.buildingData.find(building => building.type === this.type);
  118.  
  119. if (!buildingData) {
  120. console.log(`Building data not found for building type: ${this.type}`);
  121. return;
  122. }
  123.  
  124. const { resources } = buildingData;
  125. const production = {};
  126.  
  127. for (const resource in resources) {
  128. const value = resources[resource];
  129.  
  130. if (value > 0) {
  131. production[resource] = Math.round(value * (1 + 0.5 * (this.level - 1)));
  132. } else if (value < 0) {
  133. production[resource] = Math.round(value * (1 + 0.4 * (this.level - 1)));
  134. }
  135. }
  136.  
  137. return production;
  138. }
  139. }