Skip to content

Instantly share code, notes, and snippets.

@davidcraig
Last active October 18, 2020 15:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidcraig/36c324839f20ce03103ecd2825a1bcc3 to your computer and use it in GitHub Desktop.
Save davidcraig/36c324839f20ce03103ecd2825a1bcc3 to your computer and use it in GitHub Desktop.
Kittens Game script
if (!window.speed) speed = 1;
if (!game.realUpdateModel) game.realUpdateModel = game.updateModel;
game.updateModel = () => {
for (var i = 0; i < speed; i++) {
if (i !== 0) {
game.calendar.tick();
}
game.realUpdateModel();
}
}
setSpeed = spd => {
if (spd >= 1) {
speed = spd;
updateSpeedText();
}
}
speedUp = () => setSpeed(speed * 2);
slowDown = () => setSpeed(speed / 2);
$("#timeSetting").remove();
$('#gamePageContainer').append($('<div id="timeSetting" style="position: absolute; top: 50px; right: 10px;" onclick="event.preventDefault(); speedUp();" oncontextmenu="event.preventDefault(); slowDown();">'));
updateSpeedText = () => $("#timeSetting").html("Speed: " + speed + "x" + (speed > 30 ? " <br />(right click<br />to lower)" : ""));
updateSpeedText();
const SniperAutoPlay = function() {
var origTab = gamePage.activeTabId
// Auto Catnip
const autoCatnip = () => {
const catnip = gamePage.resPool.get('catnip')
const calendar = gamePage.calendar
if (catnip.perTickUI < 0) { return; }
if (catnip.value / catnip.maxValue < 0.95) { return; }
// Only run if positive catnip and not in last half of Autumn and not Winter
if ((calendar.season == 2 && calendar.day > 50) || calendar.season == 3) { return; }
if (window.craft_wood === true) {
gamePage.craftAll('wood')
}
}
const getCraft = (r) => {
try {
return gamePage.workshop.getCraft(r)
} catch (err) {
console.error(err)
}
}
const craftIfUnlocked = (resource, reagents) => {
const res = getCraft(resource)
if (!res) {
console.log(`!gamePage.workshop.getCraft(resource) ${resource}`)
return
}
reagents.forEach(r => {
if (r == "minerals" || r == "coal" || r == "iron" || r == "unobtanium" || r == "oil" || r == "uranium") {
// Skip these
} else {
try {
const craft = getCraft(r)
if (!craft) {
console.warn(`${r} does not have a craft`)
}
if (craft && !craft.unlocked) {
console.log(`!gamePage.workshop.getCraft(r).unlocked: ${r}`)
return
}
} catch (err) {
console.error(err)
return
}
}
})
if (gamePage.workshop.getCraft(resource).unlocked) {
if (window[`craft_${resource}`] === true) {
try {
gamePage.craftAll(resource)
}
catch(err) {
console.error(err)
}
}
}
}
const autoHunt = () => {
var catpower = gamePage.resPool.get('manpower')
if (catpower.value / catpower.maxValue > 0.95) {
if (window.send_hunters === true) {
$("a:contains('Send hunters')")[0].click();
}
}
}
autoCatnip();
autoHunt();
const autoCraft = () => {
if (window.auto_craft !== true) {
return;
}
var resources = [
[ ["wood"], "beam" ],
[ ["minerals"], "slab" ],
[ ["beam"], "scaffold" ],
[ ["coal"], "steel" ],
[ ["iron"], "plate" ],
[ ["iron"], "steel" ],
[ ["steel"], "alloy" ],
[ ["steel"], "gear" ],
[ ["oil"], "kerosene" ],
[ ["uranium"], "thorium" ],
[ ["steel", "slab"], "concrate" ], // "Concrete"
[ ["unobtanium"], "eludium" ]
];
for (var i = 0; i < resources.length; i++) {
craftIfUnlocked(resources[i][1], resources[i][0])
}
if (gamePage.workshop.getCraft('parchment').unlocked) { gamePage.craftAll('parchment'); }
if (window.craft_manuscript === true && gamePage.workshop.getCraft('manuscript').unlocked) { gamePage.craftAll('manuscript'); }
if (window.craft_compendium === true && gamePage.workshop.getCraft('compedium').unlocked) { gamePage.craftAll('compedium'); }
if (window.craft_blueprint === true && gamePage.workshop.getCraft('blueprint').unlocked) { gamePage.craftAll('blueprint'); }
//if (window.craft_concrete === true) { gamePage.craftAll('concrate'); }
}
autoCraft();
const faith = gamePage.resPool.get('faith')
// Auto Praise
if (faith.value / faith.maxValue > 0.95 && window.auto_pray === true) {
gamePage.activeTabId = 'Religion'; gamePage.render();
$(".btnContent:contains('Praise the sun')").click();
gamePage.activeTabId = origTab; gamePage.render();
}
}
autoPlay = setInterval(SniperAutoPlay, 3000);
window.auto_craft = true;
window.send_hunters = true;
window.craft_steel = true;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment