Pardus Building Class

Building class used by Pardus Trader Autopilot

当前为 2023-06-09 提交的版本,查看 最新版本

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.gf.qytechs.cn/scripts/468016/1202299/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, 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. // Setters for level, stock, and lastViewed
  61. setLevel(level) {
  62. this.level = level;
  63. }
  64.  
  65. setStock(stock) {
  66. this.stock = stock;
  67. }
  68.  
  69. setLastViewed(lastViewed) {
  70. this.lastViewed = lastViewed;
  71. }
  72.  
  73. // Calculate the guessed current stock based on lastViewed time and building characteristics
  74. guessCurrentStock() {
  75. const ticksPassed = this.calculateTicksPassed();
  76. const productionConsumption = this.calculateProductionConsumption();
  77. const guessedStock = {};
  78.  
  79. // Calculate the guessed stock for each commodity
  80. for (const commodity in productionConsumption) {
  81. if (productionConsumption.hasOwnProperty(commodity)) {
  82. const lastStock = this.stock[commodity] || 0;
  83. const change = productionConsumption[commodity] * ticksPassed;
  84. guessedStock[commodity] = lastStock + change;
  85. }
  86. }
  87.  
  88. return guessedStock;
  89. }
  90.  
  91. // Calculate the number of building ticks that have passed since lastViewed
  92. calculateTicksPassed() {
  93. const millisecondsPerTick = 6 * 60 * 60 * 1000; // Milliseconds per tick
  94.  
  95. const now = new Date();
  96. const lastViewed = new Date(this.lastViewed);
  97.  
  98. // Adjust the last viewed time forward to the nearest tick time (1:25 GMT and every 6 hours)
  99. lastViewed.setUTCMinutes(Math.round(Math.ceil((lastViewed.getUTCMinutes() - 25) / 60) * 60 + 25));
  100. lastViewed.setUTCHours(Math.round(Math.ceil((lastViewed.getUTCHours() - 1) / 6) * 6 + 1));
  101.  
  102. // Calculate the time difference in milliseconds
  103. const timeDiff = now - lastViewed;
  104.  
  105. // Calculate the number of ticks passed
  106. const ticksPassed = Math.ceil(timeDiff / millisecondsPerTick);
  107.  
  108. return ticksPassed;
  109. }
  110.  
  111. // Calculate the production and consumption rates based on the building type and level
  112. calculateProduction() {
  113. const buildingData = Building.buildingData.find(building => building.type === this.type);
  114.  
  115. if (!buildingData) {
  116. console.log(`Building data not found for building type: ${this.type}`);
  117. return;
  118. }
  119.  
  120. const { resources } = buildingData;
  121. const production = {};
  122.  
  123. for (const resource in resources) {
  124. const value = resources[resource];
  125.  
  126. if (value > 0) {
  127. production[resource] = Math.round(value * (1 + 0.5 * (this.level - 1)));
  128. } else if (value < 0) {
  129. production[resource] = Math.round(value * (1 + 0.4 * (this.level - 1)));
  130. }
  131. }
  132.  
  133. return production;
  134. }
  135. }

QingJ © 2025

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