diff --git a/libs/utils.js b/libs/utils.js index 08eb5c1d..eb3a6eea 100644 --- a/libs/utils.js +++ b/libs/utils.js @@ -397,15 +397,48 @@ utils.prototype.arrayToRGBA = function (color) { return "rgba("+nowR+","+nowG+","+nowB+","+nowA+")"; } +utils.prototype._encodeRoute_id2number = function (id) { + var number = core.maps.getNumberById(id); + return number==0?id:number; +} + +utils.prototype._encodeRoute_encodeOne = function (t) { + if (t.indexOf('item:')==0) + return "I"+this._encodeRoute_id2number(t.substring(5))+":"; + else if (t.indexOf('unEquip:')==0) + return "u"+t.substring(8); + else if (t.indexOf('equip:')==0) + return "e"+this._encodeRoute_id2number(t.substring(6))+":"; + else if (t.indexOf('fly:')==0) + return "F"+t.substring(4)+":"; + else if (t.indexOf('choices:')==0) + return "C"+t.substring(8); + else if (t.indexOf('shop:')==0) + return "S"+t.substring(5); + else if (t=='turn') + return 'T'; + else if (t.indexOf('turn:')==0) + return "t"+t.substring(5).substring(0,1).toUpperCase()+":"; + else if (t=='getNext') + return 'G'; + else if (t.indexOf('input:')==0) + return "P"+t.substring(6); + else if (t.indexOf('input2:')==0) + return "Q"+t.substring(7)+":"; + else if (t=='no') + return 'N'; + else if (t.indexOf('move:')==0) + return "M"+t.substring(5); + else if (t.indexOf('key:')==0) + return 'K'+t.substring(4); + else if (t.indexOf('random:')==0) + return 'X'+t.substring(7); + return ''; +} + ////// 加密路线 ////// utils.prototype.encodeRoute = function (route) { - var ans=""; - var lastMove = "", cnt=0; - - var id2number = function (id) { - var number = core.maps.getNumberById(id); - return number==0?id:number; - } + var ans="", lastMove = "", cnt=0; route.forEach(function (t) { if (t=='up' || t=='down' || t=='left' || t=='right') { @@ -423,50 +456,70 @@ utils.prototype.encodeRoute = function (route) { if (cnt>1) ans+=cnt; cnt=0; } - if (t.indexOf('item:')==0) - ans+="I"+id2number(t.substring(5))+":"; - else if (t.indexOf('unEquip:')==0) - ans+="u"+t.substring(8); - else if (t.indexOf('equip:')==0) - ans+="e"+id2number(t.substring(6))+":"; - else if (t.indexOf('fly:')==0) - ans+="F"+t.substring(4)+":"; - else if (t.indexOf('choices:')==0) - ans+="C"+t.substring(8); - else if (t.indexOf('shop:')==0) - ans+="S"+t.substring(5); - else if (t=='turn') - ans+='T'; - else if (t.indexOf('turn:')==0) - ans+="t"+t.substring(5).substring(0,1).toUpperCase()+":"; - else if (t=='getNext') - ans+='G'; - else if (t.indexOf('input:')==0) - ans+="P"+t.substring(6); - else if (t.indexOf('input2:')==0) - ans+="Q"+t.substring(7)+":"; - else if (t=='no') - ans+='N'; - else if (t.indexOf('move:')==0) - ans+="M"+t.substring(5); - else if (t.indexOf('key:')==0) - ans+='K'+t.substring(4); - else if (t.indexOf('random:')==0) - ans+='X'+t.substring(7); + ans += core.utils._encodeRoute_encodeOne(t); } }); if (cnt>0) { ans+=lastMove.substring(0,1).toUpperCase(); if (cnt>1) ans+=cnt; } - // return ans; - // 压缩 return LZString.compressToBase64(ans); } +utils.prototype._decodeRoute_getNumber = function (decodeObj, noparse) { + var num=""; + while (decodeObj.index