mirror of
https://github.com/gooba42/adventureland.git
synced 2026-10-14 18:39:27 -05:00
86 lines
1.9 KiB
JavaScript
86 lines
1.9 KiB
JavaScript
function get_character()
|
|
{
|
|
return parent.character;
|
|
}
|
|
var character=get_character();
|
|
|
|
function set_message(text)
|
|
{
|
|
$('#gg').html(text);
|
|
}
|
|
|
|
function get_targeted_monster()
|
|
{
|
|
if(parent.ctarget && !parent.ctarget.dead && parent.ctarget.type=='monster') return parent.ctarget;
|
|
return null;
|
|
}
|
|
|
|
function change_target(target)
|
|
{
|
|
parent.ctarget=target;
|
|
}
|
|
|
|
function in_attack_range(target)
|
|
{
|
|
if(parent.distance(character,target)<=character.range) return true;
|
|
return false;
|
|
}
|
|
|
|
function can_attack(target)
|
|
{
|
|
if(in_attack_range(target) && new Date()>=parent.next_attack) return true;
|
|
return false;
|
|
}
|
|
|
|
function attack(target)
|
|
{
|
|
parent.socket.emit('click',{'type':'monster','id':target.server_id,'button':'right'});
|
|
}
|
|
|
|
function move(x,y)
|
|
{
|
|
var map=parent.map,move=parent.calculate_move(map.real_x,map.real_y,x,y);
|
|
map.speed=character.speed;
|
|
map.going_x=move.x;
|
|
map.going_y=move.y;
|
|
map.from_x=map.real_x;
|
|
map.from_y=map.real_y;
|
|
map.going=true;
|
|
parent.calculate_vxyc(map,character);
|
|
parent.socket.emit("move",{x:map.real_x,y:map.real_y,going_x:map.going_x,going_y:map.going_y});
|
|
}
|
|
|
|
function get_nearest_monster(args)
|
|
{
|
|
var min_d=999999,target=null;
|
|
for(id in parent.entities)
|
|
{
|
|
var current=parent.entities[id];
|
|
if(current.type!="monster" || args.min_xp && current.xp<args.min_xp || args.max_att && current.attack>args.max_att) continue;
|
|
var c_dist=parent.distance(character,current);
|
|
if(c_dist<min_d) min_d=c_dist,target=current;
|
|
}
|
|
return target;
|
|
}
|
|
|
|
function target(element)
|
|
{
|
|
parent.ctarget=element;
|
|
}
|
|
|
|
function use_hp_or_mp()
|
|
{
|
|
if(new Date()<parent.next_pot) return;
|
|
if(character.mp/character.max_mp<0.2) parent.use('mp');
|
|
else if(character.hp/character.max_hp<0.7) parent.use('hp');
|
|
else if(character.mp/character.max_mp<0.8) parent.use('mp');
|
|
else if(character.hp<character.max_hp) parent.use('hp');
|
|
else if(character.mp<character.max_mp) parent.use('mp');
|
|
}
|
|
|
|
function loot()
|
|
{
|
|
for(id in parent.chests)
|
|
parent.socket.emit("open_chest",{id:id});
|
|
}
|