From 217de108c52191afa7d68f58b0a3bada65c73f67 Mon Sep 17 00:00:00 2001 From: Kaan Soral Date: Wed, 17 Aug 2016 03:23:08 +0300 Subject: [PATCH] Update runner_functions.js New functions: buy, upgrade, heal, get_player --- runner_functions.js | 41 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/runner_functions.js b/runner_functions.js index 639e5e9..ca2fbcf 100644 --- a/runner_functions.js +++ b/runner_functions.js @@ -1,3 +1,4 @@ +//#NOTE: If you want to see a new function/feature, just request it at: https://github.com/kaansoral/adventureland/issues var character=parent.character; function get_socket() @@ -31,13 +32,13 @@ function change_target(target) parent.ctarget=target; } -function in_attack_range(target) +function in_attack_range(target) // also works for priests/heal { if(parent.distance(character,target)<=character.range) return true; return false; } -function can_attack(target) +function can_attack(target) // also works for priests/heal { if(in_attack_range(target) && new Date()>=parent.next_attack) return true; return false; @@ -45,12 +46,34 @@ function can_attack(target) function attack(target) { - parent.socket.emit('click',{'type':'monster','id':target.server_id,'button':'right'}); + parent.monster_attack.call(target); +} + +function heal(target) +{ + parent.player_heal.call(target); +} + +function buy(name,quantity) //item names can be spotted from show_json(character.items) - they can be bought only if an NPC sells them +{ + parent.buy(name,quantity); +} + +function sell(num,quantity) //sell an item from character.items by it's order - 0 to N-1 +{ + parent.sell(num,quantity); +} + +function upgrade(item_num,scroll_num) //number of the item and scroll on the show_json(character.items) array - 0 to N-1 +{ + parent.u_item=item_num; + parent.u_scroll=scroll_num; + parent.upgrade(); } function move(x,y) { - var map=parent.map,move=parent.calculate_move(character.real_x,character.real_y,x,y); + var map=parent.map,move=parent.calculate_move(parent.M,character.real_x,character.real_y,x,y); character.from_x=character.real_x; character.from_y=character.real_y; character.going_x=move.x; @@ -61,11 +84,19 @@ function move(x,y) parent.socket.emit("move",{x:character.real_x,y:character.real_y,going_x:character.going_x,going_y:character.going_y}); } -function show_json(e) +function show_json(e) // renders the object as json inside the game { parent.show_json(parent.game_stringify(e,2)); } +function get_player(name) // returns the player by name, if the player is within the vision area +{ + var target=null,entities=parent.entities; + if(name==character.name) target=character; + for(i in entities) if(entities[i].type=="character" && entities[i].name==name) target=entities[i]; + return target; +} + function get_nearest_monster(args) { var min_d=999999,target=null;