Skip to content

Instantly share code, notes, and snippets.

@Ricket
Created April 6, 2011 21:23
Show Gist options
  • Save Ricket/906557 to your computer and use it in GitHub Desktop.
Save Ricket/906557 to your computer and use it in GitHub Desktop.
Greasemonkey script to cheat at Vanthia, the beta version in mid-July 2009
// ==UserScript==
// @name VanthiaBot
// @namespace http://richardcarter.org/
// @include http://87.239.219.99/
// ==/UserScript==
var allMonstersDead = function () {
var actionbar = unsafeWindow.document.getElementById("actionbar");
return (actionbar.style.display == "none");
}
var getCombatStats = function () {
var hudtop = unsafeWindow.document.getElementById("hud_top");
var string_hp = hudtop.getElementById("string_hp").textContent;
var string_mp = hudtop.getElementById("string_mp").textContent;
var h_p = parseInt(string_hp.substring(0,string_hp.indexOf(' / ')));
var m_axhp = parseInt(string_hp.substring(string_hp.indexOf(' / ')+3));
var m_p = parseInt(string_mp.substring(0,string_mp.indexOf(' / ')));
var m_axmp = parseInt(string_mp.substring(string_mp.indexOf(' / ')+3));
return {hp:h_p, maxhp:m_axhp, mp:m_p, maxmp:m_axmp};
}
var getCombatTurns = function () {
return parseInt(document.getElementById("turns").textContent);
}
var getIcon = function (id) {
var actionbar = document.getElementById("actionbar");
var currId = -1;
for(var i=0;i<actionbar.childNodes.length;i++) {
var icon = actionbar.childNodes[i];
if(icon.nodeName == "A" && icon.className.indexOf("icon") > -1) {
currId += 1;
if(currId == id)
return icon;
}
}
return null;
}
var isCoolingDown = function (abilityId) {
var icon = getIcon(abilityId);
if(!icon) {
console.log("isCoolingDown: !icon id "+abilityId);
return true;
} else {
return (icon.className.indexOf("oncooldown") > -1);
}
}
var isDisabled = function (abilityId) {
var icon = getIcon(abilityId);
if(!icon) {
console.log("isDisabled: !icon id "+abilityId);
return true;
} else {
return (icon.className.indexOf("blackout") > -1);
}
}
var botStop = true;
var vanthiaBotStart = function (fia) {
var VANTHIA = unsafeWindow.VANTHIA;
fightInArea = fia;
if(!botStop) {
alert("Bot already running");
return false;
}
if(!VANTHIA.loggedIn()) {
alert("Not logged in!");
return false;
}
if(combatOnly) {
botStop = false;
mapIdx = -1;
mapSubIdx = 1;
foughtBoss = false;
setTimeout(vanthiaBotTick, 100);
return true;
} else {
if(VANTHIA.combat.inCombat()) {
alert("Finish the combat before starting the bot");
return false;
} else {
botStop = false;
mapIdx = -1;
mapSubIdx = 1;
foughtBoss = false;
if(window.confirm("Teleport to beginning?")) {
VANTHIA.ajax('world::spell',{spell:'portal'});
} else {
mapIdx = parseInt(window.prompt("which map are you on? (0-2 where 0 is the first part of the cave)","0"));
if(mapIdx < 0 || mapIdx > 2)
botStop = true;
}
setTimeout(vanthiaBotTick, 100);
return true;
}
}
}
var vanthiaBotStop = function () {
botStop = true;
}
var mapIdx = -1;
var mapSubIdx = 1;
var foughtBoss = false;
var thePath = [
[ [18,1], [20,1], [20,14], [19,14], [19,17], [13,17], [13,26], [14,26] ],
[ [12,2], [12,5], [8,5], [8,8], [5,8], [5,18], [10,18], [10,25], [5,25], [5,35], [8,35], [8,44], [17,44] ],
[ [6, 20], [6,26], [16,26], [16,20], [29,20] ]
];
var combatOnly = false;
var fightInArea = false;
var bound1 = [0,0];
var bound2 = [0,0];
var waitToHeal = true;
var tempHealMP = false;
var vanthiaBotTick = function () {
var VANTHIA = unsafeWindow.VANTHIA;
if(VANTHIA.ajax.processing) {
setTimeout(vanthiaBotTick, 50);
return;
}
if(botStop) return;
if(VANTHIA.loggedIn()) {
if(VANTHIA.combat.inCombat()) {
if(allMonstersDead()) {
VANTHIA.ajax('combat::lootAll');
afterLootAll();
return;
} else {
var combatStats = getCombatStats();
if(!isCoolingDown(7) && combatStats.mp < 23) {
VANTHIA.combat.use(7);
} else if(!isCoolingDown(6) && combatStats.mp >= 23 && combatStats.hp < combatStats.maxhp-46) {
VANTHIA.combat.use(6);
} else if(getCombatTurns() > 2) {
if(!isDisabled(2) && !isCoolingDown(2) && combatStats.mp >= 8) {
VANTHIA.combat.use(2);
} else if(!isCoolingDown(1) && combatStats.mp >= 5) {
VANTHIA.combat.use(1);
} else {
VANTHIA.combat.use(0);
}
}
setTimeout(vanthiaBotTick, 100);
return;
}
} else {
if(combatOnly) {
setTimeout(vanthiaBotTick, 100);
return;
}
var combatStats = getCombatStats();
if(combatStats.mp == combatStats.maxmp)
tempHealMP = false;
if(tempHealMP || combatStats.mp < 80) {
// wait to heal mp
tempHealMP = true;
} else if((waitToHeal || foughtBoss) && (combatStats.hp < combatStats.maxhp || combatStats.mp < combatStats.maxmp)) {
// wait to heal
} else if(VANTHIA.hud.onCooldown()) {
// wait for cooldown to finish
} else {
// move to next position
var x = VANTHIA.map.getPlayerX();
var y = VANTHIA.map.getPlayerY();
if(fightInArea) {
var mapnum = mapIdx+2;
if(bound1[0]==bound2[0] && bound1[1]==bound2[1]) {
VANTHIA.ajax("map::move", {map:mapnum, path:42});
} else {
var dest = [x,y];
var areaLowerBound = [Math.min(bound1[0],bound2[0]),Math.min(bound1[1],bound2[1])];
var areaUpperBound = [Math.max(bound1[0],bound2[0]),Math.max(bound1[1],bound2[1])];
while(dest[0]==x && dest[1]==y) {
var destX = areaLowerBound[0] + Math.floor(Math.random()*(areaUpperBound[0]-areaLowerBound[0]+1));
var destY = areaLowerBound[1] + Math.floor(Math.random()*(areaUpperBound[1]-areaLowerBound[1]+1));
dest = [destX,destY];
}
var strPath = '';
for(var i=0;i<(x - dest[0]);i++)
strPath += "2";
for(var i=0;i<(dest[0] - x);i++)
strPath += "4";
for(var i=0;i<(y - dest[1]);i++)
strPath += "3";
for(var i=0;i<(dest[1] - y);i++)
strPath += "1";
VANTHIA.ajax("map::move", {map:mapnum,path:strPath});
}
} else {
if(x==22 && y==18 && mapIdx == thePath.length) {
mapIdx = -1;
mapSubIdx = 1;
foughtBoss = false;
}
if(mapIdx == -1) {
if(x==22&&y==18) {
// teleport spot
//moveTo(25,18);
VANTHIA.ajax("map::move", {map:1, path:'444'});
setTimeout(vanthiaBotTick, 100);
return;
} else if(x==25 && y==18) {
VANTHIA.ajax("trade::sellall",{npc:'olind'});
setTimeout(afterSellAll, 100);
return;
}
} else if(mapIdx == thePath.length && foughtBoss) {
// restart
VANTHIA.ajax('world::spell',{spell:'portal'});
setTimeout(vanthiaBotTick, 100);
return;
} else if(mapIdx == thePath.length && !foughtBoss) {
// prepare, and fight the boss
VANTHIA.ajax('eq::switch',{from:'47',to:'trash'});
VANTHIA.ajax('combat::boss');
foughtBoss = true;
setTimeout(vanthiaBotTick, 100);
return;
} else {
// move along the path
var currPath = thePath[mapIdx];
var dest = currPath[mapSubIdx];
if(mapIdx < (thePath.length-1) && mapSubIdx == currPath.length - 1) {
if(x == thePath[mapIdx+1][0][0] && y == thePath[mapIdx+1][0][1]) {
mapIdx++;
mapSubIdx = 1;
currPath = thePath[mapIdx];
dest = currPath[mapSubIdx];
}
} else if(x == dest[0] && y == dest[1]) {
// we reached a destination! increment...
mapSubIdx++;
if(mapSubIdx == currPath.length) {
mapIdx++;
mapSubIdx = 0;
if(mapIdx == thePath.length) {
setTimeout(vanthiaBotTick, 100);
return;
} else {
currPath = thePath[mapIdx];
}
}
currPath = thePath[mapIdx];
dest = currPath[mapSubIdx];
}
var strPath = "";
for(var i=0;i<(x - dest[0]);i++)
strPath += "2";
for(var i=0;i<(dest[0] - x);i++)
strPath += "4";
for(var i=0;i<(y - dest[1]);i++)
strPath += "3";
for(var i=0;i<(dest[1] - y);i++)
strPath += "1";
// mapIdx+2
var mapnum = mapIdx+2;
VANTHIA.ajax("map::move",{map:mapnum,path:strPath});
setTimeout(vanthiaBotTick, 100);
return;
}
}
}
setTimeout(vanthiaBotTick, 100);
return;
}
setTimeout(vanthiaBotTick, 100);
return;
} else {
alert("Not logged in! (bot stopped)");
}
}
var afterSellAll = function () {
var VANTHIA = unsafeWindow.VANTHIA;
if(VANTHIA.ajax.processing) {
setTimeout(afterSellAll, 50);
return;
}
// now detect remaining items and sell them
var dragframe = unsafeWindow.document.getElementById("game");
var slotsToSell = [];
for(var i=0;i<dragframe.childNodes.length;i++) {
var item = dragframe.childNodes[i];
if(item.nodeName == "SPAN" && item.className == "item") {
if(item.slot > 2 && item.slot < 48) {
slotsToSell.push(item.slot);
}
}
}
for(var i=0;i<slotsToSell.length;i++) {
VANTHIA.ajax("trade::sell",{npc:'olind',slot:(''+slotsToSell[i])});
}
setTimeout(afterSellAll2, 50);
}
var afterSellAll2 = function () {
var VANTHIA = unsafeWindow.VANTHIA;
if(VANTHIA.ajax.processing) {
setTimeout(afterSellAll2, 50);
return;
}
VANTHIA.ajax("map::move", {map:1, path:'43444444'});
mapIdx = 0;
setTimeout(vanthiaBotTick, 50);
}
var afterLootAll = function () {
var VANTHIA = unsafeWindow.VANTHIA;
if(VANTHIA.ajax.processing) {
setTimeout(afterLootAll, 50);
return;
}
if(VANTHIA.combat.inCombat())
VANTHIA.ajax('combat::end');
setTimeout(vanthiaBotTick, 50);
}
unsafeWindow.gpc = function () {
return [unsafeWindow.VANTHIA.map.getPlayerX(), unsafeWindow.VANTHIA.map.getPlayerY()];
}
window.addEventListener("load", function(e) {
//window.vanthiaBotTick();
var body = unsafeWindow.document.getElementsByTagName("body")[0];
var buttonDiv = unsafeWindow.document.createElement("div");
//buttonDiv.style.textAlign = "center";
//buttonDiv.style.width = "608px";
buttonDiv.style.backgroundColor = "#880000";
//buttonDiv.style.display = "inline";
buttonDiv.style.position = "absolute";
buttonDiv.style.top = "0px";
buttonDiv.style.left = "20px";
buttonDiv.style.zIndex = "10000";
var btnStart = unsafeWindow.document.createElement("input");
btnStart.type = "button";
btnStart.value = "Start bot";
btnStart.style.fontSize = "10px";
btnStart.addEventListener("click", function(e) {
if(btnStart.value == "Start bot") {
if(vanthiaBotStart(false)) {
btnStart.value = "Stop bot";
btnFightInArea.disabled = true;
}
} else {
btnStart.value = "Start bot";
btnFightInArea.disabled = false;
vanthiaBotStop();
}
}, false);
var btnToggle = unsafeWindow.document.createElement("input");
btnToggle.type = "button";
btnToggle.value = "Enable combat-only";
btnToggle.style.fontSize = "10px";
btnToggle.addEventListener("click", function(e) {
if(btnToggle.value == "Enable combat-only") {
btnToggle.value = "Disable combat-only (and stop bot)";
combatOnly = true;
} else {
btnToggle.value = "Enable combat-only";
btnStart.value = "Start bot";
btnFightInArea.disabled = false;
vanthiaBotStop();
combatOnly = false;
}
}, false);
var btnFightInArea = unsafeWindow.document.createElement("input");
btnFightInArea.type = "button";
btnFightInArea.value = "Fight in area";
btnFightInArea.style.fontSize = "10px";
btnFightInArea.addEventListener("click", function(e) {
if(btnFightInArea.value == "Fight in area") {
if(vanthiaBotStart(true)) {
btnFightInArea.value = "Stop fighting";
btnStart.disabled = true;
btnToggle.disabled = true;
btnFightOnBridge.disabled = true;
}
} else {
btnFightInArea.value = "Fight in area";
btnStart.disabled = false;
btnToggle.disabled = false;
btnFightOnBridge.disabled = true;
vanthiaBotStop();
}
}, false);
var btnFightOnBridge = unsafeWindow.document.createElement("input");
btnFightOnBridge.type = "button";
btnFightOnBridge.value = "Fight on bridge";
btnFightOnBridge.style.fontSize = "10px";
btnFightOnBridge.addEventListener("click", function(e) {
if(btnFightOnBridge.value == "Fight on bridge") {
bound1 = [0,0];
bound2 = [0,0];
if(vanthiaBotStart(true)) {
btnFightOnBridge.value = "Stop fighting";
btnStart.disabled = true;
btnToggle.disabled = true;
btnFightInArea.disabled = true;
}
} else {
btnFightOnBridge.value = "Fight on bridge";
btnStart.disabled = false;
btnToggle.disabled = false;
btnFightInArea.disabled = false;
vanthiaBotStop();
}
}, false);
var btnSetBound1 = unsafeWindow.document.createElement("input");
btnSetBound1.type = "button";
btnSetBound1.value = "Set bound 1";
btnSetBound1.style.fontSize = "10px";
btnSetBound1.addEventListener("click", function(e) {
var x = unsafeWindow.VANTHIA.map.getPlayerX();
var y = unsafeWindow.VANTHIA.map.getPlayerY();
bound1[0] = x;
bound1[1] = y;
}, false);
var btnSetBound2 = unsafeWindow.document.createElement("input");
btnSetBound2.type = "button";
btnSetBound2.value = "Set bound 2";
btnSetBound2.style.fontSize = "10px";
btnSetBound2.addEventListener("click", function(e) {
var x = unsafeWindow.VANTHIA.map.getPlayerX();
var y = unsafeWindow.VANTHIA.map.getPlayerY();
bound2[0] = x;
bound2[1] = y;
}, false);
var btnHealWait = unsafeWindow.document.createElement("input");
btnHealWait.type = "button";
btnHealWait.value = "Disable heal-wait";
btnHealWait.style.fontSize = "10px";
btnHealWait.addEventListener("click", function(e) {
if(btnHealWait.value == "Enable heal-wait") {
btnHealWait.value = "Disable heal-wait";
waitToHeal = true;
} else {
btnHealWait.value = "Enable heal-wait";
waitToHeal = false;
}
}, false);
var btnResize = unsafeWindow.document.createElement("input");
btnResize.type = "button";
btnResize.value = "Resize";
btnResize.style.fontSize = "10px";
btnResize.addEventListener("click", function(e) {
var w = unsafeWindow.innerWidth;
var h = unsafeWindow.innerHeight;
unsafeWindow.document.getElementById("gameframe").style.width=w+"px";
unsafeWindow.document.getElementById("game").style.width=w+"px";
unsafeWindow.document.getElementById("hud_map").style.width=w+"px";
unsafeWindow.document.getElementById("hud_preloader").style.width=w+"px";
unsafeWindow.document.getElementById("gameframe").style.height=(h)+"px";
unsafeWindow.document.getElementById("game").style.height=h+"px";
unsafeWindow.document.getElementById("hud").style.height=h+"px";
unsafeWindow.document.getElementById("hud_map").style.height=(h)+"px";
unsafeWindow.document.getElementById("hud_preloader").style.height=(h)+"px";
unsafeWindow.document.getElementById("hud_bottom").style.opacity=".5";
unsafeWindow.document.getElementById("hud_minitabs").style.opacity=".5";
unsafeWindow.$$('.item').set({
'styles': {'opacity':'.5'}
});
//unsafeWindow.document.getElementById("hud_bottom").style.top="";
//unsafeWindow.document.getElementById("hud_bottom").style.bottom="169px";
//buttonDiv.style.width = unsafeWindow.innerWidth+"px";
}, false);
buttonDiv.appendChild(btnStart);
buttonDiv.appendChild(btnToggle);
buttonDiv.appendChild(btnFightInArea);
buttonDiv.appendChild(btnSetBound1);
buttonDiv.appendChild(btnSetBound2);
buttonDiv.appendChild(btnFightOnBridge);
buttonDiv.appendChild(btnHealWait);
buttonDiv.appendChild(btnResize);
body.appendChild(buttonDiv);
}, false);
//GM_registerMenuCommand("Start bot", vanthiaBotStart);
//GM_registerMenuCommand("Stop bot", vanthiaBotStop);
//GM_registerMenuCommand("Toggle combat only", function () {combatOnly = !combatOnly;});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment