// ==UserScript==
// @name         RPGBot
// @namespace    http://whatever.com/
// @version      1.337
// @description  rpgmo bot... click [Bot] in top right to turn on/off. type "/enemy " to add enemies to the list
// @author       Frank Wolf
// @match        http://rpg.mo.ee/
// @grant        none
// @run-at       document-end
// ==/UserScript==
var btn = document.createElement("span");
btn.id = 'bot';
btn.innerText = '[ Bot ] ';
btn.style.color = 'red';
btn.onclick = function(){ toggle(); }
document.getElementById('toolbar_padding_holder').appendChild(btn);
//document.getElementById('toolbar_padding_holder').innerHTML += " [Bot]  ";
//document.getElementById('bot').setAttribute('onclick', "if (this.style.color == 'lime') {this.style.color = 'red';} else {this.style.color = 'lime';} startingPos.x = players[0].i; startingPos.y = players[0].j;");
Chat.client_commands['/en'] = function(a){ window.newEnemy = a.join(' '); };
Chat.client_commands['/scan'] = function(){
	for (var x=0; x<100; x++) {
		for (var y=0; y<100; y++) {
			if (!obj_g(on_map[current_map][x][y]).name) continue;
			if (obj_g(on_map[current_map][x][y]).name.toLowerCase().includes('[rare]')) {
				alert(x +' '+ y);
			}
		}
	}
};
function scan() { // can every so often for a rare
	for (var x=0; x<100; x++) {
		for (var y=0; y<100; y++) {
			if (!obj_g(on_map[current_map][x][y]).name) continue;
			if (obj_g(on_map[current_map][x][y]).name.toLowerCase().includes('[rare]')) alert(x +' '+ y);
			else console.log('nothing found');
		}
	}
}
function toggle() { // change color of [Bot], save position
	if (document.getElementById('bot').style.color == 'lime') {document.getElementById('bot').style.color = 'red';}
	else {document.getElementById('bot').style.color = 'lime';}
	startingPos.x = players[0].i;
	startingPos.y = players[0].j;
}
function target(enemy) {
	Socket.send("set_target", { target: enemy.id });
	players[0].path = enemy.path;
}
var startingPos = {}; // no starting position before starting the bot
var delay = 0; // dynamic delay
var enemies =   ['nothing',
                 'sapphire dragon']; // 69 27
setInterval(scan, 120000); // scan for rares every so often
setTimeout(erobot, 10000); // first run
function erobot() {
	setTimeout(erobot, 2000 + delay); // put this below any events that would cause extra delay
	var offset =  6; // 6; // max spots in any direction
	var maxView = 13; // 13; // width height of board. 17 should be good in fullscreen mode
	var coordX, coordY;
	var tempPath; // placeholder for shortest plath
	var enemy = {};
    enemy.path = new Array(100); // primed with long path. trying to find the smallest path
	delay = 0; // reset any additional delay for this loop
    updateEnemies(); // what even is this?
    if (document.getElementById('bot').style.color == 'red') {return;} // bots off
	if (inAFight) {return;} // exit if were in a fight
	if (players[0].path.length > 0) {return;} // exit if already walking somewhere
	if (skills[0].health.current*1.4 < players[0].params.health) {fatso(); return;} // eat if were low on health
	if (document.getElementById("captcha_menu").style.display == "block") {Music.sound_effect("notification"); return;} // exit if captchas up
	if (document.getElementById('penalty_points_bonus').innerText < 0) {return;} // exit if he have -1 captcha points
	if (document.getElementById("captcha_bonus_assign_form").style.display == "block") {return;} // exit if captchas up
	for (var z=0; z 6) range.x = 6;
		if (range.y > 6) range.y = 6;
		for (var x=0; x 0) {
					players[0].path = path;
					return;
				}
			}
		}
	}
}
// the effort of life would be worth it if there was an ultimate goal
function updateEnemies() { // what is this even?
    if (!window.newEnemy) return;
    else if (enemies.indexOf(window.newEnemy) == -1) {
        enemies.push(window.newEnemy);
        window.newEnemy = ''; console.log(enemies);
    }
    else {
        enemies.splice(enemies.indexOf(window.newEnemy), 1);
        window.newEnemy = ''; console.log(enemies);
    }
}
function fatso() { // this part works, but greasyfork wont let me post with it. assholes
	if (inAFight) {return;} // exit if were in a fight
	var tempItem;
	var lowestHeal;
	var lowestHealIndex;
	var count = 0;
	for (var i=0; i highestDmg) { // havent set first heal item, or found lower one
			highestDmg = tempItem.params.power;
			highestDmgIndex = i;
		}
	}
	if (!highestDmgIndex) return; // nothing to eat was found
	console.log(highestDmgIndex);
	inventoryClick(highestDmgIndex);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////// Proper Fishing //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
var drops = [
	{"id":127,"name":"cage"},
	{"id":78,"name":"lionfish"},
	{"id":14,"name":"salmon"},
	{"id":16,"name":"bass"},
	{"id":1370,"name":"eel"},
	{"id":86,"name":"angel"},
	{"id":100,"name":"shark"},
	{"id":98,"name":"manta"},
	{"id":1368,"name":"frog"},
	{"id":72,"name":"sardine"},
	{"id":10,"name":"trout"},
	{"id":8,"name":"perch"},
	{id:33, name:'tin'},
	//{id:185, name:'silver'},
	{id:186, name:'coal'},
	//{id:184, name:'gold'},
	{id:4, name:'sword'},
	{id:272, name:'bones'},
	//{id:484, name:'Wgold'}
];
var action = {i:30, j:90};
function toggleDrop(id, name) {
	for(var i=0; i";
			break
		}
	}
}
// make transaction item clicky
Market.client_transaction_offers= function(a) {
    for (var b = 0, d = a.length; b < d; b++)
        a[b].available = parseInt(a[b].available),
            a[b].classes = b % 2 ? "row even" : "row";
    market_transaction_offers = a;
    document.getElementById("market_transaction_offers").innerHTML = Market.client_transaction_offers_template()({
        results: a
    });
    var listings = document.getElementById("market_transaction_offers").getElementsByClassName('row');
    for (var i=0; i