Skip to content

Instantly share code, notes, and snippets.

@Neui
Created July 17, 2019 18:16
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 Neui/31bb23f50f8fba95a2c2e791da83fc75 to your computer and use it in GitHub Desktop.
Save Neui/31bb23f50f8fba95a2c2e791da83fc75 to your computer and use it in GitHub Desktop.
Personal script for a bot in Omnia Regna
/* Omnia Regna script --- Created by Neui
* This is NOT the original version, which IIRC used chained setTimeouts,
* but has been modified since then to this worker-like version.
* Unfortunately, due du spectre and other timing attacks, firefox has made
* the timings be at least one second.
*
* How to use: Copy this script, open omniaregna.com, F12, Console, paste, enter.
* Then you can call one of the functions defined at the end to "execute" an "ai".
*/
bot = {}
bot.queue = []
bot.keymap = {'s': 83, 'w': 87, 'd': 68, 'a': 65}
bot.queueSleep = 0
bot.queueLastTime = (new Date()).getTime()
bot.act = {}
bot.act.move = function(d) {
let e = document.getElementsByTagName('body')[0];
let dir = d.dir
ev = {bubbles: true, cancelable: true, key: dir, keyCode: bot.keymap[dir]}
e.dispatchEvent(new KeyboardEvent('keydown', ev))
if (d.up)
setTimeout(() => e.dispatchEvent(new KeyboardEvent('keyup', ev)), d.up)
}
bot.act.sleep = function(d) { bot.queueSleep = d.sleep }
bot.move = function(dir, up) {
this.queue.push({func: bot.act.move, dir: dir, up: up})
}
bot.sleep = function(sleep) {
this.queue.push({func: bot.act.sleep, sleep: sleep})
}
if (typeof queueWorkerId !== 'undefined')
clearInterval(queueWorkerId);
queueWorkerId = setInterval(function(bot) {
if (bot.queueSleep > 0) {
let diffTime = (new Date()).getTime() - bot.queueLastTime
// console.log("sleeping")
bot.queueSleep -= diffTime;
// if (document.hidden) console.log(diffTime, bot.queueSleep)
}
if (bot.queueSleep <= 0) {
let action = bot.queue.shift()
if (!action) return;
// console.log("executing")
// console.log(action)
action.func(action)
}
bot.queueLastTime = (new Date()).getTime()
}, 1000, bot);
d = 15
movement = 's'.repeat(d) + 'a'.repeat(d) + 'w'.repeat(d) + 'd'.repeat(d)
movement = 'sawd'
movement = Array.from(movement)
moveInCircle = function() {
for (let e in movement) {
bot.move(movement[e]);
bot.sleep(5000)
}
}
moveInCircleInfinitly = function() {
moveInCircle()
bot.queue.push({func: moveInCircleInfinitly})
}
moveRandomly = function() {
bot.move(('wasd')[Math.floor(Math.random() * 4)]);
bot.sleep(250 + Math.floor(Math.random() * 150))
}
moveRandomlyInfinitly = function() {
moveRandomly()
bot.queue.push({func: moveRandomlyInfinitly})
}
bot.lastMovement = 'w'
moveSomewhatRandomly = function() {
let moves = Array.from('wasd')
let lastMoveIndex = moves.findIndex((e) => e == bot.lastMovement)
if (lastMoveIndex) moves.splice(lastMoveIndex, 1)
bot.lastMovement = moves[Math.floor(Math.random() * moves.length)]
bot.move(bot.lastMovement);
bot.sleep(250 + Math.floor(Math.random() * 150 * 0))
}
moveSomewhatRandomlyInfinitly = function() {
moveSomewhatRandomly()
bot.queue.push({func: moveSomewhatRandomlyInfinitly})
}
moveUpDownInfinitly = function() {
bot.move('w');
bot.sleep(1000);
bot.move('s');
bot.sleep(1000);
bot.queue.push({func: moveUpDownInfinitly})
}
moveRightInfinitly = function() {
bot.move('d');
bot.sleep(1000);
bot.queue.push({func: moveUpDownInfinitly})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment