Update runner_functions.js

This commit is contained in:
Kaan Soral
2018-10-16 16:41:41 +03:00
committed by GitHub
parent 82cdb9975e
commit c49ba4fd22
+39 -11
View File
@@ -72,11 +72,11 @@ function is_monster(entity)
if(entity && entity.type=="monster") return true;
}
function is_player(entity)
function is_character(entity)
{
if(entity && entity.type=="character" && !entity.npc) return true;
}
function is_character(e){return is_player(e);}
function is_player(e){return is_character(e);} // backwards-compatibility
function activate(num) // activates an item, likely a booster, in the num-th inventory slot
{
@@ -91,9 +91,10 @@ function shift(num,name) // shifts an item, likely a booster, in the num-th inve
parent.shift(num,name);
}
function can_use(name) // work in progress, can be used to check cooldowns of class skills [02/02/17]
function can_use(name)
{
return parent.can_use(name);
if(G.skills[name] && G.skills[name].class && !in_arr(character.ctype,G.skills[name].class)) return false; // checks the class
return parent.can_use(name); // checks the cooldown
}
function use(name,target) // a multi-purpose use function, works for skills too
@@ -117,6 +118,11 @@ function use_skill(name,target)
parent.use_skill(name,target);
}
function transport(map,spawn)
{
parent.socket.emit("transport",{to:map,s:spawn});
}
function item_properties(item) // example: item_properties(character.items[0])
{
if(!item || !item.name) return null;
@@ -246,7 +252,7 @@ function can_attack(target) // also works for priests/heal
function can_heal(t)
{
if(is_monster(t)) return false;
if(is_monster(t)) return false; // ?? :D [11/10/18]
return can_attack(t);
}
@@ -286,14 +292,24 @@ function buy(name,quantity) //item names can be spotted from show_json(character
parent.buy(name,quantity);
}
function buy_with_gold(name,quantity)
{
parent.buy_with_gold(name,quantity);
}
function buy_with_shells(name,quantity)
{
parent.buy_with_shells(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 equip(num)
function equip(num,slot) // slot is optional
{
parent.socket.emit("equip",{num:num});
parent.socket.emit("equip",{num:num,slot:slot});
}
function unequip(slot) // show_json(character.slots) => to see slot options
@@ -301,9 +317,10 @@ function unequip(slot) // show_json(character.slots) => to see slot options
parent.socket.emit("unequip",{slot:slot});
}
function trade(num,trade_slot,price) // where trade_slot is 1 to 16 - example, trade(0,4,1000) puts the first item in inventory to the 4th trade slot for 1000 gold [27/10/16]
function trade(num,trade_slot,price,quantity) // where trade_slot is 1 to 16 - example, trade(0,4,1000) puts the first item in inventory to the 4th trade slot for 1000 gold [27/10/16]
{
parent.trade("trade"+trade_slot,num,price);
if(!is_string(trade_slot) || !trade_slot.startsWith("trade")) trade_slot="trade"+trade_slot;
parent.trade(trade_slot,num,price,quantity||1);
}
function trade_buy(target,trade_slot) // target needs to be an actual player
@@ -358,6 +375,11 @@ function move(x,y)
parent.move(x,y);
}
function cruise(speed)
{
parent.socket.emit("cruise",speed);
}
function show_json(e) // renders the object as json inside the game
{
parent.show_json(parent.game_stringify(e,2));
@@ -436,9 +458,9 @@ function use_hp_or_mp()
if(used) last_potion=new Date();
}
// loot(true) allows code characters to make their commanders' loot instead, extremely useful [14/01/18]
function loot(commander)
{
// loot(true) allows code characters to make their commanders' loot instead, extremely useful [14/01/18]
var looted=0;
if(safeties && mssince(last_loot)<200) return;
last_loot=new Date();
@@ -494,6 +516,11 @@ function accept_party_request(name)
parent.socket.emit('party',{event:'raccept',name:name});
}
function unfriend(name) // instead of a name, an owner id also works, this is currently the only way to unfriend someone [20/08/18]
{
parent.socket.emit('friend',{event:'unfriend',name:name});
}
function respawn()
{
parent.socket.emit('respawn');
@@ -968,7 +995,8 @@ function bfs()
{
if(smart.prune.map && smart.flags.map) {start++; continue;}
map.doors.forEach(function(door){
if(simple_distance({x:map.spawns[door[6]][0],y:map.spawns[door[6]][1]},{x:current.x,y:current.y})<30)
// if(simple_distance({x:map.spawns[door[6]][0],y:map.spawns[door[6]][1]},{x:current.x,y:current.y})<30)
if(is_door_close(current.map,door,current.x,current.y) && can_use_door(current.map,door,current.x,current.y))
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});
});
map.npcs.forEach(function(npc){