// ==UserScript== // @name KittenManager // @namespace http://inithello.net/ // @version 1.1 // @description Manage resources in bloodrizer's kittens game. // @author InitHello // @license CC-BY-NC-SA-4.0 // @supportURL https://github.com/InitHello/greasemonkey/issues // @match http://bloodrizer.ru/games/kittens/ // @require https://code.jquery.com/jquery-3.3.1.min.js#sha256=FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8= // @grant none // @downloadURL https://update.greasyfork.icu/scripts/373285/KittenManager.user.js // @updateURL https://update.greasyfork.icu/scripts/373285/KittenManager.meta.js // ==/UserScript== /* jshint esversion: 6 */ class KittenManagement { constructor() { this.resources = {}; this.capless_resources = ['hunters', 'astronomers', 'log', 'furs'] this.managed_resources = ['faith', 'science', 'culture', 'catnip', 'wood', 'minerals', 'coal', 'iron']; this.loadConfig(); window.setTimeout(this.mainTick.bind(null, this), 2500); } checkResources() { let products = {catnip: ['wood'], wood: ['beam'], minerals: ['slab'], iron: ['steel', 'plate'], coal: ['steel'], culture: ['manuscript'], science: ['compendium', 'blueprint']}; for (let resource in products) { let over = this.overThreshold(resource); if (over) { try { var resname = products[resource]; this.game.craft(game.resPool.get(resname).name, 1); } catch (err) { console.log(`Error crafting ${resname} (${typeof(resname)}): ${err}`); } } } try { let furs = this.game.resPool.get('furs'); if (furs.value >= 175 && this.config.resource_management.furs.manage) { this.game.craft(game.resPool.get('parchment').name, 1); } } catch (err) { console.log(`Error checking furs: ${err}`); } let faith = this.game.resPool.get('faith'); let faithcap = faith.maxValue * 0.95; if (faith.value >= faithcap) { this.game.religion.praise(); } } getCap(resource) { let threshold = 1000; try { threshold = this.config.resource_management[resource.name].threshold; } catch (err) { console.log(`Error getting cap for ${resource}: ${err}`); } return threshold == 0 ? 0 : threshold / 100; } initialStartup() { let tab = [' | ', 'Tools'].join(''); let tabRow = $('#gameContainerId').find('div.tabsContainer'); tabRow.append($(tab)); $('#KittenManager').on('click', () => { this.showConfig(); }); let css = $([''].join('')); $(document.body).append(css); } loadConfig() { if (localStorage.getItem('KittenManager') !== null) { this.config = JSON.parse(localStorage.getItem('KittenManager')); } else { this.config = {logLevel: 0, resource_management: {}}; for (let resource in this.capless_resources) { this.config.resource_management[this.capless_resources[resource]] = {manage: false}; } for (let resource in this.managed_resources) { this.config.resource_management[this.managed_resources[resource]] = {manage: false, threshold: 80}; } this.saveConfig(); } } mainTick(self) { self.game = window.game; let child = $('#KittenManager'); if (!child.length) { self.initialStartup(); } let controller = $('#KittenManager'); let hunters = self.config.resource_management.hunters.manage; let astro = self.config.resource_management.astronomers.manage; let log = self.config.resource_management.log.manage; self.checkResources(); if (hunters && self.game.resPool.get('manpower').value >= 100) { self.game.village.huntAll(); } if (astro && self.game.calendar.observeRemainingTime && !game.workshop.get("seti").researched) { self.game.calendar.observeHandler(); } if (log) { $('#clearLogHref').click(); } window.setTimeout(self.mainTick.bind(null, self), self.config.heartbeat); } managing(resource) { if (!this.config.resource_management.hasOwnProperty(resource.name)) { this.config.resource_management[resource.name] = {manage: false, threshold: 80}; this.saveConfig(); } return this.config.resource_management[resource.name].manage; } overThreshold(material) { let resource = this.game.resPool.get(material); let adj = 0; if (!this.managing(resource)) { return false; } let cap = this.getCap(resource); try { adj = resource.maxValue * cap; } catch (err) { console.log(`Error checking cap for ${resource.name}: ${err}`); return false; } if (resource.value >= adj) { return true; } return false } saveConfig() { localStorage.removeItem('KittenManager'); localStorage.setItem('KittenManager', JSON.stringify(this.config)); } setCap(resource, cap) { if (this.config.resource_management.hasOwnProperty(resource)) { if (this.config.resource_management[resource].hasOwnProperty('threshold')) { this.config.resource_management[resource].threshold = cap; this.saveConfig(); } else { this.config.resource_management[resource] = {manage: false, threshold: cap}; } } } showConfig() { let tab_contents = ['