Skip to content

Instantly share code, notes, and snippets.

@sehrgut
Last active November 6, 2023 21:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sehrgut/290e99f4438d48c4eda42fea39aaf46e to your computer and use it in GitHub Desktop.
Save sehrgut/290e99f4438d48c4eda42fea39aaf46e to your computer and use it in GitHub Desktop.
Sandcastle Builder autobot: kitten clicking, and ninja-safe sand clicking
// ==UserScript==
// @name castlebot
// @namespace http://alphahelical.com/
// @version 0.4
// @description Sandcastle Builder autobot: kitten clicking, and ninja-safe sand clicking
// @author sehrgut
// @match http://castle.chirpingmustard.com/castle.html
// @grant GM_info
// @grant unsafeWindow
// @grant GM_log
// ==/UserScript==
/*
todo: gui control window
todo: configurable intervals
todo: pause clicking but not watchdog/kittens
todo: persistent configuration
todo: switch various features on/off
todo: pause clicking at ASHF
todo: detect occasional failure to create window.bot in userscript
*/
(function () {
var state = {
click_beach: false,
click_kittens: true,
iv_watchdog: null,
iv_fastclick: null,
verbose: true
};
function is_userscript() {
return (typeof GM_info !== 'undefined') && GM_info.version;
}
function get_mNP_remaining() {
return Math.floor((1000 - Molpy.ONGelapsed / Molpy.NPlength)*Molpy.NPlength/Molpy.mNPlength);
}
var logHeader = is_userscript() ?
'[' + GM_info.script.name + '/' + GM_info.script.version + ']: ' :
'[' + castlebot + ']: ';
function log(msg, important) {
if (state.verbose || important) {
msg = logHeader + msg;
if (is_userscript()) {
GM_log(msg);
} else {
console.log(msg);
}
}
}
function findAndClickKitten() {
// http://pastebin.com/HSUJVBiE doesn't work anymore
var els = null;
if ( (els = Molpy.Redacted.divElement) ) {
var btn = els[0].querySelectorAll('input')[0];
if (btn) {
log('KITTEN!');
btn.click();
}
}
}
function ninjaTime() {
var prod = Molpy.CastleToolsById[0].getProduction();
var parts = prod.split('<br>');
var timeParts = parts[1] ? parts[1].split(': ') : null;
var timeString = timeParts && timeParts[1] ? timeParts[1] : "0";
return Number(timeString);
}
function startWatchdog() {
if (state.iv_watchdog)
return;
log('Watchdog watching.');
function watchdog() {
var rt = get_mNP_remaining();
if (state.click_kittens)
findAndClickKitten();
if (state.click_beach) {
if (rt <= 5) {
stopClick();
log('Waiting to click.... like a ninja.');
}
} else {
if (rt <= 5) {// remain paused
log('Remaining paused for ' + rt.toString() + 'mNP');
return;
}
if (!ninjaTime()) { // no activated NPBs to be ninja'd
log('Clicking all ninjalike!');
startClick();
}
}
}
state.iv_watchdog = setInterval(watchdog, 5000);
watchdog();
}
function startClick() {
if (state.click_beach)
return;
state.click_beach = true;
if (!state.iv_fastclick)
state.iv_fastclick = setInterval(Molpy.ClickBeach, 5);
log('Starting to click.');
}
function stopClick() {
state.click_beach = false;
clearInterval(state.iv_fastclick);
state.iv_fastclick = null;
log('No moar clicky.');
}
function stopWatchdog() {
clearInterval(state.iv_watchdog);
state.iv_watchdog = null;
log('Watchdog no longer watching.');
}
function stopAll() {
log('Stopping the presses.');
stopWatchdog();
stopClick();
}
function quiet() {
log('Hushing up.');
state.verbose = false;
}
function loud() {
state.verbose = true;
log('Loudmouth.');
}
function status() {
log(JSON.stringify(state, null, ' '), true);
}
var bot_interface = {
start: startWatchdog,
stop: stopAll,
quiet: quiet,
loud: loud,
status: status
};
// init
var realNotify = Molpy.Notify;
Molpy.Notify = function (text, importance) {
if (Molpy.bp.indexOf(text) > -1) // no one needs bag puns
return;
if (!importance || importance < 2)
log('[Molpy]: ' + text);
realNotify(text, importance);
};
if (is_userscript()) {
unsafeWindow.bot = bot_interface;
} else {
window.bot = bot_interface;
}
log('Loaded castlebot');
log('Environment: ' + (is_userscript() ? 'userscript' : 'console'));
startWatchdog();
})();
@unknownxus1er
Copy link

how do you use it once its in your terminal

@sehrgut
Copy link
Author

sehrgut commented Nov 6, 2023

window.bot.start

Though I would be surprised if this still works. I haven't updated it since I wrote it, and the original game likely has been updated since then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment