zinsho / incremental_musings

Idle musings of an incremental gamer
0 stars 0 forks source link

When using all three current userscripts together in TamperMonkey, Intellishatter does not operate #1

Closed kaeroku closed 6 years ago

kaeroku commented 6 years ago

Full Code Below:

// ==UserScript==
// @name         Zisho's Kitten Mods
// @namespace    https://zinsho.github.io/incremental_musings/
// @version      1.0
// @description  UI and Automation improvements for KG
// @include     *bloodrizer.ru/games/kittens/*
// @author       Zinsho
// ==/UserScript==

(function() {
    'use strict';

    // OFFLINE PROGRESS MODULE
function runOfflineUpdate () {
    game.opts.enableRedshift = true
    game.time.calculateRedshift()
    game.opts.enableRedshift = false
}

// Run function every X hours
var offlineHours = 8;
var hours = 60*60*1000;
var getOfflineProduction = setInterval(runOfflineUpdate, offlineHours*hours);

//Disable with
// clearInterval(getOfflineProduction)

    // End OFFLINE PROGRESS module

    // KEYBINDS MODULE update key, shift,alt,ctrl as desired but key must be capital letter for it to ensure it maps
var keybinds = [
    {
        name: 'Bonfire',
        key: 'B',
        shift: true,
        alt: false,
        control: false
    },
    {
        name: 'Village',
        key: 'V',
        shift: true,
        alt: false,
        control: false
    },
    {
        name: "Science",
        key: 'S',
        shift: true,
        alt: false,
        control: false
    },
    {
        name: 'Workshop',
        key: 'W',
        shift: true,
        alt: false,
        control: false
    },
    {
        name: 'Trade',
        key: 'T',
        shift: true,
        alt: false,
        control: false
    },
    {
        name: 'Religion',
        key: 'R',
        shift: true,
        alt: false,
        control: false
    },
    {
        name: 'Space',
        key: 'P',
        shift: true,
        alt: false,
        control: false
    },
    {
        name: 'Time',
        key: 'I',
        shift: true,
        alt: false,
        control: false
    },
    {
        name: "Close Options",
        key: "Escape",
        shift: false,
        alt: false,
        control: false,
        action: () => { $('div.dialog:visible').last().hide() }
    },
    {
        name: "Send Hunters",
        key: "h",
        shift: false,
        alt: false,
        control: false,
        action: () => { $("a:contains('Send hunters')").click() }
    },
    {
        name: "Praise the Sun",
        key: "p",
        shift: false,
        alt: false,
        control: false,
        action: () => { $("a:contains('Praise the sun')").click() }
    },
    {
        name: "Observe",
        key: "o",
        shift: false,
        alt: false,
        control: false,
        action: () => {
            var starChart = $('#observeBtn')
            if (starChart[0]) {
                starChart.click()
            }
        }
    },
]

function callKeybind(event) {
    var keybind = keybinds.find(x =>
        x.key === event.key &&
        x.shift == event.shiftKey &&
        x.alt == event.altKey &&
        x.control == event.ctrlKey)
    if (keybind && keybind.name != game.ui.activeTabId) {
        if (keybind.action) {
            keybind.action()
        } else {
            console.log('Switching to: ' + keybind.name)
            game.ui.activeTabId = keybind.name
            game.ui.render()
        }
    }
}

window.addEventListener('keyup', callKeybind)

    // END KEYBIND MODULE

    // CRYSTAL SHATTER MODULE
var shatterPerTick = false
var shatterPadding = 0 // Additional seconds to delay shatter

function getTimePer10Heat() {
    return Math.ceil(Math.abs(10 / ((shatterPerTick ? 1 : 5) *
                                    game.getEffect('heatPerTick')))) +
        (shatterPadding * (shatterPerTick ? 5 : 1))
}

function createShatterWidget () {
    var shatterWidget = new classes.ui.ChronoforgeWgt(game),
        shatterButton = shatterWidget.children.find(
            button => button.opts.name === 'Combust TC'
        );

    shatterButton.model = Object.assign({},shatterButton.opts);
    shatterButton.model.options = Object.assign({},shatterButton.opts)
    shatterButton.model.enabled = true;
    return shatterButton
}

var shatterButton = createShatterWidget()

var counter = 1 // Start at 1 for increment
function shatterTCTime () {
    if (counter % getTimePer10Heat() == 0) {
        shatterButton.controller.doShatterAmt(
            shatterButton.model, false, () => { }, 1
        )
        counter = 1
    } else {
        counter++
    }
}

// ** Alicorns
// Load religion buttons into memory
game.religionTab.render()
var alicornButton = game.religionTab.sacrificeAlicornsBtn

function sacrificeAlicorns () {
    alicornButton.controller.sacrificeAll(
        alicornButton.model, false, () => { }
    )
}

// ** Leviathans
function tradeLeviathans () {
    var leviRace = game.diplomacy.races.find(
        race => race.name === 'leviathans'
    )
    game.diplomacy.tradeAll(leviRace)
}

// ** Timer
function automateShatter () {
    sacrificeAlicorns()
    tradeLeviathans()
    shatterTCTime()
}

if (gamePage.resPool.get('timeCrystal').unlocked) {
    var shatterInterval = setInterval(automateShatter,
                                      shatterPerTick ? 250 : 1000)
} else {
    console.log("Time Crystals not available")
}
// clearInterval(shatterInterval)

    //END CRYSTAL SHATTER MODULE

})();
zinsho commented 6 years ago

Change top and bottom:

// ==/UserScript==

function run () {
    'use strict';

...

//END CRYSTAL SHATTER MODULE

}

function start () {
    if (typeof gamePage != 'undefined') {
        run()
    } else {
        setTimeout(start, 1000)
    }
}

setTimeout(start,1000)