diff --git a/runner_functions.js b/runner_functions.js index c26777f..4cf6be2 100644 --- a/runner_functions.js +++ b/runner_functions.js @@ -31,9 +31,9 @@ game={ platform:parent.is_electron&&"electron"||"web", // "electron" for Steam, Mac clients, "web" for https://adventure.land graphics:!parent.no_graphics, // if game.graphics is false, don't draw stuff to the game in your Code html:!parent.no_html, // if game.html is false, this character is loaded in [CODE] mode + cli:parent.is_cli, }; character.bot=parent.is_bot; -character.cli=parent.is_cli; //#NOTE: Most new features are experimental - for #feedback + suggestions: https://discord.gg/X4MpntA [05/01/18] @@ -137,30 +137,23 @@ function bank_withdraw(gold) parent.socket.emit("bank",{operation:"withdraw",amount:gold}); } -/** - * Store an item in the Bank. - * - * `bank_store(0)` - Stores the first item in inventory in the first/best spot in bank. - * `bank_store(0, "items0", 41)` - Stores the first item in inventory in the last spot in "items0". - * - * @param {number} inventory_slot Inventory slot number (0-41). - * @param {string} [pack] Bank pack (one of "items0"-"items7"). - * @param {number} [pack_slot=-1] Pack slot number (0-41; default: first available). - */ -function bank_store(inventory_slot, pack, pack_slot) +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[inventory_slot]) return game_log("No item in that spot"); - if(!(pack_slot >= 0)) pack_slot=-1; // the server interprets -1 as first slot available + if(!character.items[num]) return game_log("No item in that spot"); + if(pack_num===undefined) pack_num=-1; // the server interprets -1 as first slot available if(!pack) { - var cp=undefined; + var cp=undefined,cs=undefined; for(var cpack in bank_packs) { if(pack || bank_packs[cpack][0]!=character.map || !character.bank[cpack]) continue; - for(var i=0;i 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_slot]) return game_log("No item in that spot"); - if(!(inventory_slot>=0)) inventory_slot=-1; // the server interprets -1 as first slot available - - parent.socket.emit("bank",{operation:"swap",pack:pack,str:pack_slot,inv:inventory_slot}); + if(!character.bank[pack] || !character.bank[pack][pack_num]) return game_log("No item in that spot"); + 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}); } function swap(a,b) // inventory move/swap @@ -367,6 +349,11 @@ function is_in_range(target,skill) if(!target || !target.visible) return false; // When a target leaves your viewpoint, .visible becomes false and the object reference is never updated again var range_multiplier=1,range_bonus=0; + if(G.skills[skill] && G.skills[skill].range) + { + if(distance(character,target)<=G.skills[skill].range) return true; + return false; + } if(G.skills[skill] && G.skills[skill].range_multiplier) range_multiplier=G.skills[skill].range_multiplier; if(G.skills[skill] && G.skills[skill].range_bonus) range_bonus=G.skills[skill].range_bonus; if(distance(character,target)<=character.range*range_multiplier+range_bonus) return true; @@ -375,6 +362,7 @@ function is_in_range(target,skill) function is_on_cooldown(skill) { + if(G.skills[skill] && G.skills[skill].share) return is_on_cooldown(G.skills[skill].share); if(parent.next_skill[skill] && new Date() to see slot options @@ -469,39 +458,27 @@ function unequip(slot) // show_json(character.slots) => to see slot options parent.socket.emit("unequip",{slot:slot}); } -/** - * Open Merchant stand. - * - * @param {number} [num=0] Inventory slot containing merchant stand. - */ -function open_stand(num) -{ - num = num || 0; - if(!character.items[num]) return; - if(G.items[character.items[num].name].type !== "stand") { - parent.d_text("CAN'T OPEN", character); - return; - } - parent.open_merchant(num); -} - -/** - * Close Merchant stand. - */ -function close_stand() -{ - parent.close_merchant(); -} - 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); } -function trade_buy(target,trade_slot) // target needs to be an actual player +function trade_buy(target,trade_slot,quantity) { - parent.trade_buy(trade_slot,target.id,target.slots[trade_slot].rid); // the .rid changes when the item in the slot changes, it prevents swap-based frauds [22/11/16] + // 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] +} + +function trade_sell(target,trade_slot,quantity) +{ + // sells an item to a target's buy listing by slot name + // 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] } function upgrade(item_num,scroll_num,offering_num) // number of the item and scroll on the show_json(character.items) array - 0 to N-1 @@ -542,12 +519,17 @@ function exchange(item_num) function say(message) // please use MORE responsibly, thank you! :) { - parent.say(message,1); + parent.say(message,safeties); } -function pm(name,message) // please use responsibly, thank you! :) +function party_say(message) { - parent.private_say(name,message,0) + parent.party_say(message,safeties); +} + +function pm(name,message) +{ + parent.private_say(name,message,safeties); } function move(x,y) @@ -558,6 +540,7 @@ function move(x,y) function cruise(speed) { + // to revert, just cruise(500) - since it just sets an upper cap for speed parent.socket.emit("cruise",speed); } @@ -687,13 +670,14 @@ function get_nearest_hostile(args) // mainly as an example [08/02/17] function use_hp_or_mp() { if(safeties && mssince(last_potion)200) + if(!activity.heartbeat[character.name] || mssince(new Date(activity.heartbeat[character.name]))>320) { activity.heartbeat[character.name]=(new Date()).toString(); - localStorage.setItem("activity",JSON.stringify(activity)); + localStorage.setItem("activity"+(game.cli&&character.name||""),JSON.stringify(activity)); } - - for (var key in localStorage) - { - if(key.startsWith("cm_"+character.name+"_")) + var keys=Object.keys(localStorage); + if(game.cli) keys=localStorage._keys; + keys.forEach(function(key){ // 2x faster than for(key in localStorage) { - var data=localStorage.getItem(key); - localStorage.removeItem(key); - data=JSON.parse(data); - data[2]=new Date(data[2]); - messages.push(data); + if(key.startsWith("cm_"+character.name+"_")) + { + var data=localStorage.getItem(key); + localStorage.removeItem(key); + data=JSON.parse(data); + data[2]=new Date(data[2]); + messages.push(data); + } } - } + }); messages.sort(function(a,b){ if(!(a[2]-b[2])) @@ -1160,24 +1173,31 @@ setInterval(function(){ return a[2]-b[2]; }); - if(messages.length) console.log(messages); - messages.forEach(function(cm){ - character.trigger("cm",{name:cm[0],message:cm[1],date:cm[2],local:true}); + try{ + character.trigger("cm",{name:cm[0],message:cm[1],date:cm[2],local:true}); + }catch(e){ + game_log("CM Error, From: "+cm[0]); + log(e); + log(e.stack); + } }); -},10); + setTimeout(local_cm_logic,min(120,max(16,mssince(start)*10))); +} +setTimeout(local_cm_logic,10); var local_m_num=0; function send_local_cm(name,data) { - localStorage.setItem("cm_"+name+"_"+randomStr(20),JSON.stringify([character.name,data,new Date(),++local_m_num])); + if(game.cli) parent.CLI_OUT.push({"type":"cm","to":name,"data":[character.name,data,new Date(),++local_m_num]}); + else localStorage.setItem("cm_"+name+"_"+randomStr(20),JSON.stringify([character.name,data,new Date(),++local_m_num])); } function is_character_local(name) { - var activity=localStorage.getItem("activity"); + var activity=localStorage.getItem("activity"+(game.cli&&name||"")); activity=activity&&JSON.parse(activity)||{}; - if(activity.heartbeat && activity.heartbeat[name] && mssince(new Date(activity.heartbeat[name]))<2400) + if(activity.heartbeat && activity.heartbeat[name] && mssince(new Date(activity.heartbeat[name]))<2880) return true; return false; } @@ -1264,6 +1284,31 @@ function require_code(name) return module.exports; } +function upload_code(slot_number,slot_name,code_string) +{ + // Some players use the code slots to persist data across platforms, but please use it sparingly :) [04/08/20] + return api_call("save_code",{code:code_string,slot:slot_number,name:slot_name,auto:true,electron:true},{promise:true}); +} + +var active_code_slot=parent.code_slot||""; +function get_active_code_slot() +{ + return active_code_slot; +} + +function get_edited_code_slot() +{ + // Current slot on the CODE Editor + return parent.code_slot; +} + +function disconnect() +{ + // Forces a limitdc + for(var i=0;i<300;i++) + parent.socket.emit("cruise"); +} + var smart={ moving:false, map:"main",x:0,y:0, @@ -1523,7 +1568,7 @@ function start_pathfinding() smart.start_x=character.real_x; smart.start_y=character.real_y; queue=[],visited={},start=0,best=null; - if(character.cli) + if(game.cli) { parent.CLI_OUT.push({"type":"smart_move",G:G,start_x:smart.start_x,start_y:smart.start_y,start_map:character.map,x:smart.x,y:smart.y,map:smart.map}); } @@ -1562,7 +1607,7 @@ function smart_move_logic() { start_pathfinding(); } - else if(!smart.found && character.cli) { /* Just wait */ } + else if(!smart.found && game.cli) { /* Just wait */ } else if(!smart.found) { if(Math.random()<0.1) @@ -1660,4 +1705,9 @@ function code_draw() else requestAnimationFrame(code_draw); } +if(parent.is_cli) +{ + if(parent.ls_emulation) window._localStorage=parent.ls_emulation; + window.cli_require=parent.cli_require; +} code_draw();