Kitten Extrapolation

A script for outputting information about kitten survival (Other features may come later)

当前为 2019-05-13 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Kitten Extrapolation
  3. // @namespace https://greasyfork.org/en/scripts/10234-kitten-extrapolation
  4. // @version 0.7.4
  5. // @description A script for outputting information about kitten survival (Other features may come later)
  6. // @author Yuriy
  7. // @match http://bloodrizer.ru/games/kittens/*
  8. // @match https://bloodrizer.ru/games/kittens/*
  9. // @exclude http://bloodrizer.ru/games/kittens/wiki*
  10. // @exclude https://bloodrizer.ru/games/kittens/wiki*
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. var KE_seasons = {
  15. "Spring": 1.5,
  16. "Summer": 1,
  17. "Autumn": 1,
  18. "Winter": 0.25
  19. };
  20.  
  21. var KE_weathers = {
  22. "Warm": 0.15,
  23. "Norm": 0.0,
  24. "Cold": -0.15
  25. };
  26.  
  27. var KE_seasons_reverse_Lookup = {
  28. 0 : "Spring",
  29. 1 : "Summer",
  30. 2 : "Autumn",
  31. 3 : "Winter"
  32. };
  33.  
  34. function KE_calcTitaniumChance()
  35. {
  36. if(0.35*gamePage.resPool.get("ship").value+15>100){
  37. return 100;
  38. }else{
  39. return 0.35*gamePage.resPool.get("ship").value+15;
  40. }
  41. }
  42.  
  43. var KE_seasonal_trading = {
  44. "Lizards" : {
  45. "wood" : {
  46. "Spring": "<font color=red>↓↓</font>",
  47. "Summer": "<font color=limegreen>↑↑</font>",
  48. "Autumn": "<font color=limegreen>↑</font>",
  49. "Winter": "<font color=red>↓</font>",
  50. "Best": "Summer",
  51. "Chance": 100
  52. }
  53. },
  54. "Sharks" : {
  55. "catnip" : {
  56. "Spring": "<font color=limegreen>↑</font>",
  57. "Summer": "<font color=red>↓↓</font>",
  58. "Autumn": "<font color=red>↓</font>",
  59. "Winter": "<font color=limegreen>↑↑</font>",
  60. "Best": "Winter",
  61. "Chance": 100
  62. }
  63. },
  64. "Griffins" : {
  65. "iron" : {
  66. "Spring": "<font color=red>↓↓</font>",
  67. "Summer": "<font color=limegreen>↑</font>",
  68. "Autumn": "<font color=limegreen>↑↑</font>",
  69. "Winter": "<font color=red>↓</font>",
  70. "Best": "Autumn",
  71. "Chance": 100
  72. }
  73. },
  74. "Nagas" : {
  75. "minerals" : {
  76. "Spring": "<font color=limegreen>↑↑</font>",
  77. "Summer": "<font color=limegreen>↑</font>",
  78. "Autumn": "<font color=red>↓↓</font>",
  79. "Winter": "<font color=red>↓</font>",
  80. "Best": "Spring",
  81. "Chance": 100
  82. }
  83. },
  84. "Zebras" : {
  85. "iron" : {
  86. "Spring": "<font color=limegreen>↑</font>",
  87. "Summer": "<font color=limegreen>↑↑</font>",
  88. "Autumn": "<font color=red>↓</font>",
  89. "Winter": "<font color=red>↓↓</font>",
  90. "Best": "Summer",
  91. "Chance": 100
  92. },
  93. "plate" : {
  94. "Spring": "<font color=yellow>=</font>",
  95. "Summer": "<font color=red>↓↓</font>",
  96. "Autumn": "<font color=yellow>=</font>",
  97. "Winter": "<font color=limegreen>↑↑</font>",
  98. "Best": "Winter",
  99. "Chance": 65
  100. },
  101. "titanium" : {
  102. "Chance": KE_calcTitaniumChance
  103. }
  104. },
  105. "Spiders" : {
  106. "coal" : {
  107. "Spring": "<font color=red>↓</font>",
  108. "Summer": "<font color=limegreen>↑</font>",
  109. "Autumn": "<font color=limegreen>↑↑</font>",
  110. "Winter": "<font color=red>↓↓</font>",
  111. "Best": "Autumn",
  112. "Chance": 100
  113. }
  114. },
  115. "Dragons" : {
  116. "uranium" : {
  117. // "Spring": "<font color=red>↓</font>",
  118. // "Summer": "<font color=limegreen>↑</font>",
  119. // "Autumn": "<font color=limegreen>↑↑</font>",
  120. // "Winter": "<font color=red>↓↓</font>",
  121. // "Best": "Autumn",
  122. "Chance": 95
  123. }
  124. }
  125. };
  126.  
  127. function KE_generate_food_table_cell(tag="", contents = "", colspan = 1){
  128. var cell = document.createElement("td");
  129. if(tag != ""){
  130. cell.setAttribute("id",tag);
  131. }
  132. cell.style.textAlign="text-align:center";
  133. cell.append(contents)
  134. if(colspan != 1){
  135. cell.setAttribute("colspan","4")
  136. }
  137. return cell;
  138. }
  139.  
  140. function KE_generate_food_table_line(line_name, line_tag) {
  141. var line = document.createElement("tr");
  142. var cell = document.createElement("td");
  143. cell.style.textAlign="text-align:center";
  144. cell.append(line_name);
  145. line.append(cell);
  146. line.append(KE_generate_food_table_cell(line_tag+'Sp'));
  147. line.append(KE_generate_food_table_cell(line_tag+'Su'));
  148. line.append(KE_generate_food_table_cell(line_tag+'A'));
  149. line.append(KE_generate_food_table_cell(line_tag+'W'));
  150. return line;
  151. }
  152.  
  153. function KE_generate_food_table() {
  154. //Creating the enclosing div for the table
  155. var enclosing_div = document.createElement("div");
  156. enclosing_div.setAttribute("width","340px");
  157. //Making the table itself
  158. var table = document.createElement("table");
  159. table.setAttribute("id","food_table_season");
  160. table.setAttribute("table-layout","fixed");
  161. //create/define the columns in the tables
  162. var column = document.createElement("col");
  163. column.setAttribute("width",60);
  164. table.append(column);
  165. for (var i = 0; i < 4; i++) {
  166. var column2 = document.createElement("col");
  167. column2.setAttribute("width",70);
  168. table.append(column2);
  169. }
  170. //create the top line of the table
  171. var topline = document.createElement("tr");
  172. topline.append(KE_generate_food_table_cell("cycle_warning"));
  173. topline.append(KE_generate_food_table_cell("","Food during seasons (/season)",4));
  174. table.append(topline);
  175. //Create second line of table
  176. var line2 = document.createElement("tr");
  177. line2.append(KE_generate_food_table_cell("","Weather"));
  178. line2.append(KE_generate_food_table_cell("KE_Spring","Spring"));
  179. line2.append(KE_generate_food_table_cell("KE_Summer","Summer"));
  180. line2.append(KE_generate_food_table_cell("KE_Autumn","Autumn"));
  181. line2.append(KE_generate_food_table_cell("KE_Winter","Winter"));
  182. table.append(line2);
  183. //Create the table's main cells/liens
  184. table.append(KE_generate_food_table_line('Warm', 'WS'));
  185. table.append(KE_generate_food_table_line('Norm', 'NS'));
  186. table.append(KE_generate_food_table_line('Cold', 'CS'));
  187. //append the table to the enclosing div
  188. enclosing_div.append(table);
  189. //Yearly food production calculation
  190. var yearly_food_produced = document.createElement("p");
  191. yearly_food_produced.setAttribute("id","yearly_food_produced");
  192. yearly_food_produced.style.marginBlockStart="2px";
  193. yearly_food_produced.style.marginBlockEnd="2px";
  194. enclosing_div.append(yearly_food_produced);
  195. return enclosing_div;
  196. }
  197.  
  198. //Calculates the reasource production for a season other then the current one.
  199. function KE_calcResourcePerTick_NCW(resName, season, weather)
  200. {
  201. if(resName == "catnip"){
  202. //Get data for the current weather
  203. var realWeatherMod = gamePage.calendar.getWeatherMod();
  204. //invert it
  205. var realWeatherModInverse = 0-realWeatherMod;
  206. //get the effective season+weather
  207. var mockSeasonWeatherMod = KE_seasons[season]+KE_weathers[weather];
  208. //Apply the inveser of the real weather to it to counter that it is going to be applied in the function
  209. mockSeasonWeatherMod = mockSeasonWeatherMod + realWeatherModInverse;
  210. return (gamePage.calcResourcePerTick(resName,{"modifiers" : {"catnip" : mockSeasonWeatherMod}})-gamePage.getResourcePerTickConvertion(resName));
  211. } else{
  212. return gamePage.calcResourcePerTick(resName)-gamePage.getResourcePerTickConvertion(resName);
  213. }
  214. }
  215.  
  216. function KE_update_food_table_cell(lable, season, weather)
  217. {
  218. var element_to_update = document.getElementById(lable);
  219. //Clear labeled element
  220. element_to_update.innerHTML = ""
  221. var updated_text = document.createElement("font");
  222. //Bold the current season/weather combo
  223. if(season == KE_seasons_reverse_Lookup[gamePage.calendar.season] && ((weather=="Norm" && gamePage.calendar.weather == null) || weather.toLowerCase() == gamePage.calendar.weather)){
  224. updated_text.setAttribute("class","msg type_date");
  225. updated_text.style.fontWeight = "bold";
  226. updated_text.style.borderBottomWidth = "0px";
  227. updated_text.style.fontSize = "14px";
  228. }
  229. //Get updated value
  230. updated_text.append(gamePage.getDisplayValueExt(KE_calcResourcePerTick_NCW("catnip",season,weather)*1000,true));
  231. //Close out font
  232. element_to_update.append(updated_text);
  233. return true;
  234. }
  235.  
  236. function KE_update_trade_screen()
  237. {
  238.  
  239. ///////////////////////////////////////////////////
  240. //Adding trade calculations, purely experimental //
  241. ///////////////////////////////////////////////////
  242. //Panel container is the class of all trade containers
  243. var trade_containers = document.getElementsByClassName("panelContainer")
  244. //Cycle through all trade containers
  245. for (var i = 0; i < trade_containers.length; i++) {
  246. //for every container
  247. if(typeof(trade_containers[i]) === 'object' && trade_containers[i].getElementsByClassName("title").length > 0)
  248. {
  249. try
  250. {
  251. var trade_partner = trade_containers[i].getElementsByClassName("title")[0].childNodes[0].nodeValue.trim()
  252. //////////////////////////////////////
  253. //Chance of success/bonus for trades//
  254. //////////////////////////////////////
  255. for (var j = 0; j<gamePage.diplomacy.races.length; j++){
  256. if(gamePage.diplomacy.races[j]["title"] == trade_partner){
  257. if(gamePage.diplomacy.races[j]["attitude"] != "neutral")
  258. {
  259. var standingRatio = gamePage.getEffect("standingRatio");
  260. standingRatio = standingRatio ? standingRatio : 0;
  261.  
  262. if (gamePage.prestige.getPerk("diplomacy").researched){
  263. standingRatio += 10;
  264. }
  265.  
  266. if(gamePage.diplomacy.races[j]["attitude"] == "friendly")
  267. {
  268. standingRatio = standingRatio/2;
  269. }
  270.  
  271. standingRatio += gamePage.diplomacy.races[j]["standing"]*100
  272. if (standingRatio > 100){
  273. standingRatio = 100;
  274. }
  275.  
  276. var append_string = "";
  277.  
  278. if(gamePage.diplomacy.races[j]["attitude"] == "friendly")
  279. {
  280. append_string = "(+"+gamePage.getDisplayValueExt(standingRatio)+"%)";
  281. }
  282.  
  283. if(gamePage.diplomacy.races[j]["attitude"] == "hostile")
  284. {
  285. append_string = "(-"+gamePage.getDisplayValueExt(100-standingRatio)+"%)";
  286. }
  287.  
  288. //Add standing info to the trade window.
  289. if(trade_containers[i].getElementsByClassName("title")[0].getElementsByClassName("attitude")[0].getElementsByClassName("trade-seasonal-appeal").length == 0){
  290. //If the block does not exist yet
  291. var appendnode = document.createElement("span");
  292. appendnode.setAttribute("class", "trade-seasonal-appeal");
  293. trade_containers[i].getElementsByClassName("title")[0].getElementsByClassName("attitude")[0].appendChild(appendnode);
  294. }
  295.  
  296. trade_containers[i].getElementsByClassName("title")[0].getElementsByClassName("attitude")[0].getElementsByClassName("trade-seasonal-appeal")[0].innerHTML = append_string;
  297. }
  298.  
  299. break;
  300. }
  301. }
  302.  
  303. //////////////////////////////////////////////
  304. //Colored arrows for race season prefrences.//
  305. //Should probobly be redone using the game's//
  306. //internal code //
  307. //////////////////////////////////////////////
  308. //Check if the trade partner is in seasonal_trading
  309. if(Object.keys(KE_seasonal_trading).indexOf(trade_partner) != -1){
  310. //get the list of all reasources for trade
  311. var reasource_containers = trade_containers[i].getElementsByClassName("trade-race")[0].getElementsByClassName("left")[0].children
  312. //cycle through them
  313. for (var j = 0; j < reasource_containers.length; j++) {
  314. //if this is a 'sell' type container (as opposed to the 'buy' containers)
  315. if(reasource_containers[j].getElementsByClassName("sells").length > 0)
  316. {
  317. //find out if this is a reasource that the race being looked at has a variable deal on based on seasons
  318. var trade_reasource = reasource_containers[j].childNodes[1].nodeValue.trim();
  319. if(Object.keys(KE_seasonal_trading[trade_partner]).indexOf(trade_reasource) != -1)
  320. {
  321. //Add the addjustment appearence to it.
  322. if(reasource_containers[j].getElementsByClassName("trade-seasonal").length == 0){
  323. //If the block does not exist yet
  324. var appendnode = document.createElement("span");
  325. appendnode.setAttribute("class", "trade-seasonal");
  326. reasource_containers[j].appendChild(appendnode);
  327. }
  328. var append_string = "";
  329. if(KE_seasonal_trading[trade_partner][trade_reasource]["Chance"]!=100){
  330. var string_add = document.createElement("span")
  331. if(typeof(KE_seasonal_trading[trade_partner][trade_reasource]["Chance"]) != 'function'){
  332. string_add.innerHTML = gamePage.getDisplayValueExt(KE_seasonal_trading[trade_partner][trade_reasource]["Chance"]) + "%";
  333. }else{
  334. string_add.innerHTML = gamePage.getDisplayValueExt(KE_seasonal_trading[trade_partner][trade_reasource]["Chance"]()) + "%";
  335. }
  336. string_add.setAttribute("class", "ammount");
  337. append_string += string_add.outerHTML;
  338. }
  339. if(KE_seasonal_trading[trade_partner][trade_reasource][KE_seasons_reverse_Lookup[gamePage.calendar.season]])
  340. {
  341. append_string += KE_seasonal_trading[trade_partner][trade_reasource][KE_seasons_reverse_Lookup[gamePage.calendar.season]];
  342. if(KE_seasons_reverse_Lookup[gamePage.calendar.season] != KE_seasonal_trading[trade_partner][trade_reasource]["Best"]){
  343. append_string += " (+" + KE_seasonal_trading[trade_partner][trade_reasource]["Best"] + ")";
  344. }
  345. }
  346. reasource_containers[j].getElementsByClassName("trade-seasonal")[0].innerHTML = append_string;
  347. }
  348. }
  349. }
  350. }
  351. }
  352. catch(err) {
  353. console.error("Error in adding trade container. ",err.message);
  354. }
  355. }else{
  356. console.log(typeof(trade_containers[i]), trade_containers[i]);
  357. }
  358.  
  359.  
  360. }
  361. }
  362.  
  363. function KE_update(){
  364. //Update all the food cells
  365. KE_update_food_table_cell("WSSp", "Spring", "Warm");
  366. KE_update_food_table_cell("WSSu", "Summer", "Warm");
  367. KE_update_food_table_cell("WSA", "Autumn", "Warm");
  368. KE_update_food_table_cell("WSW", "Winter", "Warm");
  369. KE_update_food_table_cell("NSSp", "Spring", "Norm");
  370. KE_update_food_table_cell("NSSu", "Summer", "Norm");
  371. KE_update_food_table_cell("NSA", "Autumn", "Norm");
  372. KE_update_food_table_cell("NSW", "Winter", "Norm");
  373. KE_update_food_table_cell("CSSp", "Spring", "Cold");
  374. KE_update_food_table_cell("CSSu", "Summer", "Cold");
  375. KE_update_food_table_cell("CSA", "Autumn", "Cold");
  376. KE_update_food_table_cell("CSW", "Winter", "Cold");
  377.  
  378. //Yearly production
  379. document.getElementById('yearly_food_produced').innerHTML = "Yearly food balance (avg): " + gamePage.getDisplayValueExt((KE_calcResourcePerTick_NCW("catnip", "Spring", "Norm")*1000) + (KE_calcResourcePerTick_NCW("catnip", "Summer", "Norm")*1000) + (KE_calcResourcePerTick_NCW("catnip", "Autumn", "Norm")*1000) + (KE_calcResourcePerTick_NCW("catnip", "Winter", "Norm")*1000), true);
  380.  
  381. var cycle = gamePage.calendar.cycles[gamePage.calendar.cycle];
  382. var element_to_update;
  383. element_to_update = document.getElementById("cycle_warning");
  384. if(cycle["name"]=="piscine"){
  385. element_to_update.innerHTML = '<font color="red">↑Piscine</font>'
  386. }else{
  387. element_to_update.innerHTML = ""
  388. }
  389.  
  390. //
  391.  
  392. //Trading
  393. KE_update_trade_screen();
  394.  
  395. //console.log(trade_reasource, Object.keys(seasonal_trading[trade_partner]).indexOf(trade_reasource));
  396.  
  397. return true;
  398. }
  399.  
  400. function KE_initiate_script() {
  401. var data_out = document.createElement('div');
  402. data_out.id = 'kitten_extrapolation_container';
  403. data_out.style.width = '100%';
  404. data_out.style.bottom = '0px';
  405. data_out.style.verticalAlign = 'bottom';
  406. data_out.innerHTML = "";
  407. data_out.append(KE_generate_food_table());
  408. var right_col = document.getElementById('rightColumn')
  409. right_col.style.width = '360px';
  410. var before_child = document.getElementsByClassName("right-tab-header")[0];
  411. right_col.insertBefore(data_out, before_child);
  412. setInterval(KE_update, 500);
  413. return true;
  414. }
  415.  
  416. function KE_initiate() {
  417. if (typeof gamePage == "object") {
  418. if (!document.getElementById('kitten_extrapolation_container')) {
  419. KE_initiate_script();
  420. }
  421. } else if(typeof gamePage == "undefined") {
  422. setTimeout(function(){
  423. KE_initiate();
  424. }, 100);
  425. }else{
  426. window.alert("Error E1 occured in Kitten Extrapolation! \nThis is most likely to occure if the game's code has been radically changed and Kitten Extrapolation needs updating or if the script is run on something other then the Kittens game.");
  427. }
  428. }
  429.  
  430. KE_initiate();
  431.  
  432. //Function for trimming strings.
  433. //Credit: David Andres (https://stackoverflow.com/questions/1418050/string-strip-for-javascript)
  434. if(typeof(String.prototype.trim) === "undefined")
  435. {
  436. String.prototype.trim = function()
  437. {
  438. return String(this).replace(/^\s+|\s+$/g, '');
  439. };
  440. }