mirror of
https://github.com/gooba42/adventureland.git
synced 2026-10-14 18:39:27 -05:00
Update runner_functions.js
This commit is contained in:
+123
-25
@@ -1,7 +1,22 @@
|
|||||||
// #NOTE: If you want to see a new function/feature, just request it at: https://github.com/kaansoral/adventureland/issues
|
// #NOTE: If you want to see a new function/feature, just request it at: https://github.com/kaansoral/adventureland/issues
|
||||||
var character=parent.character;
|
// Or at #feedback in Discord: https://discord.gg/4SXJGU
|
||||||
var G=parent.G; // Game data
|
|
||||||
var safeties=true;
|
var character={
|
||||||
|
// This object proxies the real parent.character
|
||||||
|
// Normal entities have normal coordinates, their {x,y}'s are equal to their {real_x,real_y}'s
|
||||||
|
// The character object is special, it's always in the middle of the screen, so it has static {x,y}'s
|
||||||
|
// Added this wrapper so instead of using .real_x and .real_y on all entities, .x and .y's can be used uniformly
|
||||||
|
"note":"This is a proxy object, the real character is in parent.character",
|
||||||
|
"properties":["x","y"],
|
||||||
|
}
|
||||||
|
|
||||||
|
Object.defineProperty(character,'x',{get:function(){return parent.character.real_x;},set:function(){game_log("You can't set coordinates manually, use the move(x,y) function!");}});
|
||||||
|
Object.defineProperty(character,'y',{get:function(){return parent.character.real_y;},set:function(){game_log("You can't set coordinates manually, use the move(x,y) function!");}});
|
||||||
|
for(var p in parent.character) proxy(p); // Not all properties are sadly available right away, new properties are captured imperfectly
|
||||||
|
// var character=parent.character; // Old [25/06/2018]
|
||||||
|
|
||||||
|
var G=parent.G; // Game Data - Use show_json(Object.keys(G)); and inspect individual data with show_json(G.skills) and alike
|
||||||
|
var safeties=true; // Prevents common delay based issues that cause many requests to be sent to the server in a burst that triggers the server to disconnect the character
|
||||||
|
|
||||||
server={
|
server={
|
||||||
mode:parent.gameplay, // "normal", "hardcore", "test"
|
mode:parent.gameplay, // "normal", "hardcore", "test"
|
||||||
@@ -97,6 +112,7 @@ function use(name,target) // a multi-purpose use function, works for skills too
|
|||||||
|
|
||||||
function use_skill(name,target)
|
function use_skill(name,target)
|
||||||
{
|
{
|
||||||
|
// for blink: use_skill("blink",[x,y])
|
||||||
if(!target) target=get_target();
|
if(!target) target=get_target();
|
||||||
parent.use_skill(name,target);
|
parent.use_skill(name,target);
|
||||||
}
|
}
|
||||||
@@ -204,7 +220,7 @@ function change_target(target,public)
|
|||||||
function can_move_to(x,y)
|
function can_move_to(x,y)
|
||||||
{
|
{
|
||||||
if(is_object(x)) y=x.real_y,x=x.real_x;
|
if(is_object(x)) y=x.real_y,x=x.real_x;
|
||||||
return can_move({map:character.map,x:character.real_x,y:character.real_y,going_x:x,going_y:y});
|
return can_move({map:character.map,x:character.real_x,y:character.real_y,going_x:x,going_y:y,base:character.base});
|
||||||
}
|
}
|
||||||
|
|
||||||
function xmove(x,y)
|
function xmove(x,y)
|
||||||
@@ -326,12 +342,12 @@ function exchange(item_num)
|
|||||||
parent.exchange(1);
|
parent.exchange(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
function say(message) // please use responsibly, thank you! :)
|
function say(message) // please use MORE responsibly, thank you! :)
|
||||||
{
|
{
|
||||||
parent.say(message,1);
|
parent.say(message,1);
|
||||||
}
|
}
|
||||||
|
|
||||||
function pm(name,message) // please use MORE responsibly, thank you! :)
|
function pm(name,message) // please use responsibly, thank you! :)
|
||||||
{
|
{
|
||||||
parent.private_say(name,message,0)
|
parent.private_say(name,message,0)
|
||||||
}
|
}
|
||||||
@@ -339,15 +355,7 @@ function pm(name,message) // please use MORE responsibly, thank you! :)
|
|||||||
function move(x,y)
|
function move(x,y)
|
||||||
{
|
{
|
||||||
if(!can_walk(character)) return;
|
if(!can_walk(character)) return;
|
||||||
var map=parent.map,move=parent.calculate_move(parent.M,character.real_x,character.real_y,parseFloat(x)||0,parseFloat(y)||0);
|
parent.move(x,y);
|
||||||
character.from_x=character.real_x;
|
|
||||||
character.from_y=character.real_y;
|
|
||||||
character.going_x=move.x;
|
|
||||||
character.going_y=move.y;
|
|
||||||
character.moving=true;
|
|
||||||
parent.calculate_vxy(character);
|
|
||||||
// parent.console.log("engaged move "+character.angle);
|
|
||||||
parent.socket.emit("move",{x:character.real_x,y:character.real_y,going_x:character.going_x,going_y:character.going_y,m:character.m});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function show_json(e) // renders the object as json inside the game
|
function show_json(e) // renders the object as json inside the game
|
||||||
@@ -376,6 +384,7 @@ function get_nearest_monster(args)
|
|||||||
|
|
||||||
if(!args) args={};
|
if(!args) args={};
|
||||||
if(args && args.target && args.target.name) args.target=args.target.name;
|
if(args && args.target && args.target.name) args.target=args.target.name;
|
||||||
|
if(args && args.type=="monster") game_log("You used monster.type, which is always 'monster', use monster.mtype instead");
|
||||||
|
|
||||||
for(id in parent.entities)
|
for(id in parent.entities)
|
||||||
{
|
{
|
||||||
@@ -438,8 +447,9 @@ function loot(commander)
|
|||||||
var chest=parent.chests[id];
|
var chest=parent.chests[id];
|
||||||
if(safeties && (chest.items>character.esize || chest.last_loot && mssince(chest.last_loot)<1600)) continue;
|
if(safeties && (chest.items>character.esize || chest.last_loot && mssince(chest.last_loot)<1600)) continue;
|
||||||
chest.last_loot=last_loot;
|
chest.last_loot=last_loot;
|
||||||
if(commander) parent.parent.socket.emit("open_chest",{id:id});
|
if(commander) parent.parent.open_chest(id);
|
||||||
else parent.socket.emit("open_chest",{id:id});
|
else parent.open_chest(id);
|
||||||
|
// parent.socket.emit("open_chest",{id:id}); old version [02/07/18]
|
||||||
looted++;
|
looted++;
|
||||||
if(looted==2) break;
|
if(looted==2) break;
|
||||||
}
|
}
|
||||||
@@ -570,6 +580,7 @@ var buttons=parent.code_buttons;
|
|||||||
function draw_line(x,y,x2,y2,size,color)
|
function draw_line(x,y,x2,y2,size,color)
|
||||||
{
|
{
|
||||||
// keep in mind that drawings could significantly slow redraws, especially if you don't .destroy() them
|
// keep in mind that drawings could significantly slow redraws, especially if you don't .destroy() them
|
||||||
|
if(!game.graphics) return;
|
||||||
if(!color) color=0xF38D00;
|
if(!color) color=0xF38D00;
|
||||||
if(!size) size=1;
|
if(!size) size=1;
|
||||||
e=new PIXI.Graphics();
|
e=new PIXI.Graphics();
|
||||||
@@ -585,6 +596,7 @@ function draw_line(x,y,x2,y2,size,color)
|
|||||||
// Example: draw_circle(character.real_x,character.real_y,character.range) :) [22/10/16]
|
// Example: draw_circle(character.real_x,character.real_y,character.range) :) [22/10/16]
|
||||||
function draw_circle(x,y,radius,size,color)
|
function draw_circle(x,y,radius,size,color)
|
||||||
{
|
{
|
||||||
|
if(!game.graphics) return;
|
||||||
if(!color) color=0x00F33E;
|
if(!color) color=0x00F33E;
|
||||||
if(!size) size=1;
|
if(!size) size=1;
|
||||||
e=new PIXI.Graphics();
|
e=new PIXI.Graphics();
|
||||||
@@ -732,6 +744,55 @@ function preview_item(def,args)
|
|||||||
parent.prop_cache={};
|
parent.prop_cache={};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function set_skillbar() // example: set_skillbar("1","2","3","4","R") or set_skillbar(["1","2","3","4","R"])
|
||||||
|
{
|
||||||
|
var arr=["1"];
|
||||||
|
if(is_array(arguments[0])) arr=arguments[0];
|
||||||
|
else
|
||||||
|
{
|
||||||
|
arr=[];
|
||||||
|
for(var i=0;i<arguments.length;i++) arr.push(arguments[i]);
|
||||||
|
}
|
||||||
|
parent.set_setting(parent.real_id,"skillbar",arr);
|
||||||
|
parent.skillbar=arr;
|
||||||
|
parent.render_skills(); parent.render_skills();
|
||||||
|
}
|
||||||
|
|
||||||
|
function set_keymap(keymap) // example: {"1":{"name":"use_mp"},"2":{"name":"use_hp"}}
|
||||||
|
{
|
||||||
|
parent.set_setting(parent.real_id,"keymap",keymap);
|
||||||
|
parent.keymap=keymap;
|
||||||
|
parent.render_skills(); parent.render_skills();
|
||||||
|
}
|
||||||
|
|
||||||
|
function map_key(key,skill,code) // example: map_key("1","use_hp") or map_key("2","snippet","say('OMG')") or map_key("1","esc") or map_key("ESC","up")
|
||||||
|
{
|
||||||
|
var settings=parent.get_settings(parent.real_id);
|
||||||
|
var keymap=settings.keymap||parent.keymap;
|
||||||
|
if(is_string(skill)) keymap[key]={"name":skill};
|
||||||
|
else keymap[key]=skill;
|
||||||
|
if(code) keymap[key].code=code;
|
||||||
|
if(keymap[key].keycode) parent.K[keymap[key].keycode]=key;
|
||||||
|
set_keymap(keymap);
|
||||||
|
}
|
||||||
|
|
||||||
|
function unmap_key(key)
|
||||||
|
{
|
||||||
|
var settings=parent.get_settings(parent.real_id);
|
||||||
|
var keymap=settings.keymap||parent.keymap;
|
||||||
|
delete keymap[key];
|
||||||
|
set_keymap(keymap);
|
||||||
|
}
|
||||||
|
|
||||||
|
function reset_mappings()
|
||||||
|
{
|
||||||
|
parent.keymap={};
|
||||||
|
parent.skillbar=[];
|
||||||
|
parent.map_keys_and_skills();
|
||||||
|
set_keymap(parent.keymap);
|
||||||
|
set_skillbar(parent.skillbar);
|
||||||
|
}
|
||||||
|
|
||||||
function load_code(name,onerror) // onerror can be a function that will be executed if load_code fails
|
function load_code(name,onerror) // onerror can be a function that will be executed if load_code fails
|
||||||
{
|
{
|
||||||
if(!onerror) onerror=function(){ game_log("load_code: Failed to load","#E13758"); }
|
if(!onerror) onerror=function(){ game_log("load_code: Failed to load","#E13758"); }
|
||||||
@@ -763,6 +824,7 @@ function smart_move(destination,on_done) // despite the name, smart_move isn't v
|
|||||||
{
|
{
|
||||||
smart.map="";
|
smart.map="";
|
||||||
if(is_string(destination)) destination={to:destination};
|
if(is_string(destination)) destination={to:destination};
|
||||||
|
if(is_number(destination)) destination={x:destination,y:on_done},on_done=null;
|
||||||
if("x" in destination)
|
if("x" in destination)
|
||||||
{
|
{
|
||||||
smart.map=destination.map||character.map;
|
smart.map=destination.map||character.map;
|
||||||
@@ -827,12 +889,23 @@ function smart_move(destination,on_done) // despite the name, smart_move isn't v
|
|||||||
console.log(smart.map+" "+smart.x+" "+smart.y);
|
console.log(smart.map+" "+smart.x+" "+smart.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
function stop()
|
function stop(action)
|
||||||
|
{
|
||||||
|
if(!action || action=="move")
|
||||||
{
|
{
|
||||||
if(smart.moving) smart.on_done(false);
|
if(smart.moving) smart.on_done(false);
|
||||||
smart.moving=false;
|
smart.moving=false;
|
||||||
move(character.real_x,character.real_y);
|
move(character.real_x,character.real_y);
|
||||||
}
|
}
|
||||||
|
else if(action=="invis")
|
||||||
|
{
|
||||||
|
parent.socket.emit("stop",{action:"invis"});
|
||||||
|
}
|
||||||
|
else if(action=="teleport")
|
||||||
|
{
|
||||||
|
parent.socket.emit("stop",{action:"teleport"});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var queue=[],visited={},start=0,best=null;
|
var queue=[],visited={},start=0,best=null;
|
||||||
var moves=[[0,15],[0,-15],[15,0],[-15,0]];
|
var moves=[[0,15],[0,-15],[15,0],[-15,0]];
|
||||||
@@ -862,8 +935,9 @@ function smooth_path()
|
|||||||
// Assume the path ahead is [i] [i+1] [i+2] - This routine checks whether [i+1] could be skipped
|
// Assume the path ahead is [i] [i+1] [i+2] - This routine checks whether [i+1] could be skipped
|
||||||
// The resulting path is smooth rather than rectangular and bumpy
|
// The resulting path is smooth rather than rectangular and bumpy
|
||||||
// Try adding "function smooth_path(){}" or "smart.prune.smooth=false;" to your Code
|
// Try adding "function smooth_path(){}" or "smart.prune.smooth=false;" to your Code
|
||||||
while(i+2<smart.plot.length && smart.plot[i].map==smart.plot[i+1].map && smart.plot[i].map==smart.plot[i+1].map &&
|
// [06/07/18]: (!smart.plot[i+2] || !smart.plot[i+2].transport) - without this condition, in "winterland", move(-160,-660), smart_move("main") fails
|
||||||
can_move({map:smart.plot[i].map,x:smart.plot[i].x,y:smart.plot[i].y,going_x:smart.plot[i+2].x,going_y:smart.plot[i+2].y}))
|
while(i+2<smart.plot.length && smart.plot[i].map==smart.plot[i+1].map && smart.plot[i].map==smart.plot[i+1].map && (!smart.plot[i+2] || !smart.plot[i+2].transport) &&
|
||||||
|
can_move({map:smart.plot[i].map,x:smart.plot[i].x,y:smart.plot[i].y,going_x:smart.plot[i+2].x,going_y:smart.plot[i+2].y,base:character.base}))
|
||||||
smart.plot.splice(i+1,1);
|
smart.plot.splice(i+1,1);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
@@ -876,6 +950,7 @@ function bfs()
|
|||||||
while(start<queue.length)
|
while(start<queue.length)
|
||||||
{
|
{
|
||||||
var current=queue[start];
|
var current=queue[start];
|
||||||
|
var map=G.maps[current.map];
|
||||||
if(current.map==smart.map)
|
if(current.map==smart.map)
|
||||||
{
|
{
|
||||||
smart.flags.map=true;
|
smart.flags.map=true;
|
||||||
@@ -892,11 +967,11 @@ function bfs()
|
|||||||
else if(current.map!=smart.map)
|
else if(current.map!=smart.map)
|
||||||
{
|
{
|
||||||
if(smart.prune.map && smart.flags.map) {start++; continue;}
|
if(smart.prune.map && smart.flags.map) {start++; continue;}
|
||||||
G.maps[current.map].doors.forEach(function(door){
|
map.doors.forEach(function(door){
|
||||||
if(simple_distance({x:door[0]+door[2]/2,y:door[1]+door[3]/2},{x:current.x,y:current.y})<45)
|
if(simple_distance({x:map.spawns[door[6]][0],y:map.spawns[door[6]][1]},{x:current.x,y:current.y})<30)
|
||||||
qpush({map:door[4],x:G.maps[door[4]].spawns[door[5]||0][0],y:G.maps[door[4]].spawns[door[5]||0][1],transport:true,s:door[5]||0});
|
qpush({map:door[4],x:G.maps[door[4]].spawns[door[5]||0][0],y:G.maps[door[4]].spawns[door[5]||0][1],transport:true,s:door[5]||0});
|
||||||
});
|
});
|
||||||
G.maps[current.map].npcs.forEach(function(npc){
|
map.npcs.forEach(function(npc){
|
||||||
if(npc.id=="transporter" && simple_distance({x:npc.position[0],y:npc.position[1]},{x:current.x,y:current.y})<75)
|
if(npc.id=="transporter" && simple_distance({x:npc.position[0],y:npc.position[1]},{x:current.x,y:current.y})<75)
|
||||||
{
|
{
|
||||||
for(var place in G.npcs.transporter.places)
|
for(var place in G.npcs.transporter.places)
|
||||||
@@ -907,13 +982,13 @@ function bfs()
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if(smart.use_town) qpush({map:current.map,x:G.maps[current.map].spawns[0][0],y:G.maps[current.map].spawns[0][1],town:true}); // "town"
|
if(smart.use_town) qpush({map:current.map,x:map.spawns[0][0],y:map.spawns[0][1],town:true}); // "town"
|
||||||
|
|
||||||
shuffle(moves);
|
shuffle(moves);
|
||||||
moves.forEach(function(m){
|
moves.forEach(function(m){
|
||||||
var new_x=parseInt(current.x+m[0]),new_y=parseInt(current.y+m[1]);
|
var new_x=parseInt(current.x+m[0]),new_y=parseInt(current.y+m[1]);
|
||||||
// utilise can_move - game itself uses can_move too - smart_move is slow as can_move checks all the lines at each step
|
// utilise can_move - game itself uses can_move too - smart_move is slow as can_move checks all the lines at each step
|
||||||
if(can_move({map:current.map,x:current.x,y:current.y,going_x:new_x,going_y:new_y}))
|
if(can_move({map:current.map,x:current.x,y:current.y,going_x:new_x,going_y:new_y,base:character.base}))
|
||||||
qpush({map:current.map,x:new_x,y:new_y});
|
qpush({map:current.map,x:new_x,y:new_y});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1004,6 +1079,29 @@ function smart_move_logic()
|
|||||||
|
|
||||||
setInterval(function(){smart_move_logic();},80);
|
setInterval(function(){smart_move_logic();},80);
|
||||||
|
|
||||||
|
function proxy(name)
|
||||||
|
{
|
||||||
|
if(in_arr(name,character.properties)) return;
|
||||||
|
character.properties.push(name);
|
||||||
|
Object.defineProperty(character,name,{get:function(){return parent.character[name];},set:function(value){delete this[name]; parent.character[name]=value;}});
|
||||||
|
}
|
||||||
|
|
||||||
|
["bank","user","code","angle","direction","target","from_x","from_y","going_x","going_y","moving","vx","vy","move_num"].forEach(function(p){proxy(p)});
|
||||||
|
setInterval(function(){ for(var p in parent.character) proxy(p); },50); // bottom of the barrel
|
||||||
|
|
||||||
|
function eval_s(code) // this is how snippets are eval'ed if they include "output="/"json_output=" - so if they include these, the scope of eval isn't global - doesn't matter much [13/07/18]
|
||||||
|
{
|
||||||
|
var output=undefined,json_output=undefined;
|
||||||
|
eval(code);
|
||||||
|
if(output!==undefined) parent.show_modal("<pre>"+output+"</pre>");
|
||||||
|
if(json_output!==undefined) parent.show_json(json_output);
|
||||||
|
}
|
||||||
|
|
||||||
|
function performance_trick()
|
||||||
|
{
|
||||||
|
parent.performance_trick(); // Just plays an empty sound file, so browsers don't throttle JS, only way to prevent it, interesting cheat [05/07/18]
|
||||||
|
}
|
||||||
|
|
||||||
function doneify(fn,s_event,f_event)
|
function doneify(fn,s_event,f_event)
|
||||||
{
|
{
|
||||||
return function(a,b,c,d,e,f){
|
return function(a,b,c,d,e,f){
|
||||||
|
|||||||
Reference in New Issue
Block a user