From 256ce800e73979006689015c3be4ec4163b11a1c Mon Sep 17 00:00:00 2001 From: Kaan Soral Date: Mon, 22 Aug 2022 19:46:58 +0300 Subject: [PATCH] Update runner_functions.js Every non-instant call returns a Promise now --- runner_functions.js | 107 ++++++++++++++++++++++++++++++++------------ 1 file changed, 78 insertions(+), 29 deletions(-) diff --git a/runner_functions.js b/runner_functions.js index 16c91ca..5b00ec0 100644 --- a/runner_functions.js +++ b/runner_functions.js @@ -57,25 +57,25 @@ function mode_resolve_all() */ function start_character(name,code_slot_or_name) { - return parent.start_character_runner(name,code_slot_or_name) + return parent.start_character_runner(name,code_slot_or_name); } function stop_character(name) { - parent.stop_character_runner(name) + parent.stop_character_runner(name); } function command_character(name,code_snippet) { // Commands the character in [CODE] mode - parent.character_code_eval(name,code_snippet) + parent.character_code_eval(name,code_snippet); } function get_active_characters() { // States: "self", "starting","loading", "active", "code" // Example: {"Me":"self","Protector":"loading"} - return parent.get_active_characters() + return parent.get_active_characters(); } function change_server(region,name) // change_server("EU","I") or change_server("ASIA","PVP") or change_server("US","III") @@ -83,7 +83,7 @@ function change_server(region,name) // change_server("EU","I") or change_server( parent.window.location.href="/character/"+character.name+"/in/"+region+"/"+name+"/"; } -function is_pvp() +function is_in_pvp() { return G.maps[character.map].pvp || server.pvp; } @@ -102,7 +102,6 @@ function is_character(entity) { if(entity && entity.type=="character" && !entity.npc) return true; } -function is_player(e){return is_character(e);} // backwards-compatibility function interact(name) { @@ -113,10 +112,10 @@ function interact(name) } } -function enter(place) +function enter(place,name) { // Possible places: "duelland" / "crypt" / "winter_instance" - parent.socket.emit('enter',{place:place}); + parent.socket.emit('enter',{place:place,name:name}); return parent.push_deferred("enter"); } @@ -139,7 +138,7 @@ function use_nearest_door() function activate(num) // activates an item, likely a booster, in the num-th inventory slot { - parent.activate(num); + return parent.activate(num); } function shift(num,name) // shifts an item, likely a booster, in the num-th inventory slot @@ -147,7 +146,7 @@ function shift(num,name) // shifts an item, likely a booster, in the num-th inve // shift(0,'xpbooster') // shift(0,'luckbooster') // shift(0,'goldbooster') - parent.shift(num,name); + return parent.shift(num,name); } function use_skill(name,target,extra_arg) @@ -177,14 +176,16 @@ function reduce_cooldown(name,ms) function bank_deposit(gold) { - if(!character.bank) return game_log("Not inside the bank"); + if(!character.bank) return rejecting_promise({reason:"not_in_bank"}); parent.socket.emit("bank",{operation:"deposit",amount:gold}); + return parent.push_deferred("bank"); } function bank_withdraw(gold) { - if(!character.bank) return game_log("Not inside the bank"); + if(!character.bank) return rejecting_promise({reason:"not_in_bank"}); parent.socket.emit("bank",{operation:"withdraw",amount:gold}); + return parent.push_deferred("bank"); } function bank_store(num,pack,pack_num) @@ -192,8 +193,8 @@ function bank_store(num,pack,pack_num) // bank_store(0) - Stores the first item in inventory in the first/best spot in bank // bank_store(41,"items0",41) -> stores the last item on the last spot of bank's "items0" // pack is one of "items0","items1","items2",... - if(!character.bank) return game_log("Not inside the bank"); - if(!character.items[num]) return game_log("No item in that spot"); + if(!character.bank) return rejecting_promise({reason:"not_in_bank"}); + if(!character.items[num]) return rejecting_promise({reason:"no_item"}); if(pack_num===undefined) pack_num=-1; // the server interprets -1 as first slot available if(!pack) { @@ -209,20 +210,29 @@ function bank_store(num,pack,pack_num) cp=cpack; } } - if(!pack && !cp) return game_log("Bank is full!"); + if(!pack && !cp) return rejecting_promise({reason:"bank_full"}); if(!pack) pack=cp; } parent.socket.emit("bank",{operation:"swap",pack:pack,str:pack_num,inv:num}); + return parent.push_deferred("bank"); } function bank_retrieve(pack,pack_num,num) { // bank_retrieve("items0",0) -> retrieves the first item from bank's "items0" // bank_retrieve("items0",0,12) -> you can optionally specify where to retrieve the item in inventory - if(!character.bank) return game_log("Not inside the bank"); - if(!character.bank[pack] || !character.bank[pack][pack_num]) return game_log("No item in that spot"); + if(!character.bank) return rejecting_promise({reason:"not_in_bank"}); + if(!character.bank[pack] || !character.bank[pack][pack_num]) return rejecting_promise({reason:"no_item"}); if(num===undefined) num=-1; // the server interprets -1 as first slot available parent.socket.emit("bank",{operation:"swap",pack:pack,str:pack_num,inv:num}); + return parent.push_deferred("bank"); +} + +function bank_swap(pack,a,b) +{ + // bank_swap("items0",0,1) -> swaps the first 2 items + parent.socket.emit("bank",{operation:"move",pack:pack,a:a,b:b}); + return parent.push_deferred("bank"); } function swap(a,b) // inventory move/swap @@ -399,7 +409,7 @@ function get_targeted_monster() function change_target(target) { parent.ctarget=target; - parent.send_target_logic(); + return parent.send_target_logic(); } function change_target_privately(target) @@ -407,7 +417,7 @@ function change_target_privately(target) parent.ctarget=target; if(target) parent.last_id_sent=target.id; // Marks the id as sent, so it doesn't actually get sent else parent.last_id_sent=''; - parent.send_target_logic(); + return parent.send_target_logic(); } function can_move_to(x,y) @@ -513,7 +523,8 @@ function buy_with_gold(name,quantity) function buy_with_shells(name,quantity) { - parent.buy_with_shells(name,quantity); + // returns {success:false,in_progress:true} + return parent.buy_with_shells(name,quantity); } function sell(num,quantity) //sell an item from character.items by it's order - 0 to N-1 @@ -565,10 +576,12 @@ function unlock_item(num) return parent.unlock_item(num); } -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] +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] if(!is_string(trade_slot) || !trade_slot.startsWith("trade")) trade_slot="trade"+trade_slot; - parent.trade(trade_slot,num,price,quantity||1); + return parent.trade(trade_slot,num,price,quantity||1); } function trade_buy(target,trade_slot,quantity) @@ -576,7 +589,7 @@ function trade_buy(target,trade_slot,quantity) // buys the item from a target by slot name // target needs to be an actual player object // quantity is optional - parent.trade_buy(trade_slot,target.id,target.slots[trade_slot].rid,quantity||1); // the .rid changes when the item in the slot changes, it prevents swap-based frauds [22/11/16] + return parent.trade_buy(trade_slot,target.id,target.slots[trade_slot].rid,quantity||1); // the .rid changes when the item in the slot changes, it prevents swap-based frauds [22/11/16] } function trade_sell(target,trade_slot,quantity) @@ -585,7 +598,27 @@ function trade_sell(target,trade_slot,quantity) // server automatically checks/picks the item from your inventory to sell // target needs to be an actual player object // quantity is optional - parent.trade_sell(trade_slot,target.id,target.slots[trade_slot].rid,quantity||1); // the .rid changes when the item in the slot changes, it prevents swap-based frauds [22/11/16] + return parent.trade_sell(trade_slot,target.id,target.slots[trade_slot].rid,quantity||1); // the .rid changes when the item in the slot changes, it prevents swap-based frauds [22/11/16] +} + +function wishlist(trade_slot,name,price,level,quantity) +{ + // where trade_slot is 1 to 16 + // example: trade(0,"staff",10000000,9) Wishlists an +9 Staff for 10,000,000 + if(!is_string(trade_slot) || !trade_slot.startsWith("trade")) trade_slot="trade"+trade_slot; + return parent.wishlist(trade_slot,name,price,quantity||1,level); +} + +function giveaway(slot,num,q,minutes) +{ + // example: giveaway("trade1",0,12,20) - Gives away 12X of Inventory[0] at "trade1" with a 20 minutes cooldown + return parent.giveaway(slot,num,q,minutes) +} + +function join_giveaway(name,slot,rid) +{ + // example: join_giveaway("CharacterName","trade1",get_player("CharacterName").slots.trade1.rid); + return parent.join_giveaway(slot,name,rid); } function upgrade(item_num,scroll_num,offering_num,only_calculate) // number of the item and scroll on the show_json(character.items) array - 0 to N-1 @@ -799,7 +832,7 @@ function use_hp_or_mp() { if(safeties && mssince(last_potion)