From c88a31f4c39af7e34f2f4f49b78ce430a91e52c5 Mon Sep 17 00:00:00 2001 From: oc Date: Mon, 15 Jan 2018 20:56:57 +0800 Subject: [PATCH] Record & Encode route --- libs/core.js | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ libs/data.js | 4 ++-- libs/events.js | 17 +++++++++++++++-- libs/items.js | 6 ++++++ 4 files changed, 73 insertions(+), 4 deletions(-) diff --git a/libs/core.js b/libs/core.js index 72e40938..5659a75b 100644 --- a/libs/core.js +++ b/libs/core.js @@ -79,6 +79,7 @@ function core() { 'mouseOutCheck': 1, 'moveStepBeforeStop': [], 'downTime': null, + 'route': [], // 当前路线! // 勇士状态;中心对称飞行器 @@ -1411,6 +1412,7 @@ core.prototype.setHeroMoveTriggerInterval = function () { y = core.getHeroLoc('y'); var noPass = core.noPass(x + scan[direction].x, y + scan[direction].y), canMove = core.canMoveHero(); if (noPass || !canMove) { + core.status.route.push(direction); if (canMove) // 非箭头:触发 core.trigger(x + scan[direction].x, y + scan[direction].y); core.drawHero(direction, x, y, 'stop'); @@ -1443,6 +1445,7 @@ core.prototype.setHeroMoveTriggerInterval = function () { else if (core.status.heroStop) { core.drawHero(core.getHeroLoc('direction'), core.getHeroLoc('x'), core.getHeroLoc('y'), 'stop'); } + core.status.route.push(direction); core.trigger(core.getHeroLoc('x'), core.getHeroLoc('y')); clearInterval(core.interval.heroMoveInterval); core.status.heroMoving = false; @@ -3598,6 +3601,53 @@ core.prototype.loadData = function (data, callback) { }); } +////// 加密路线 ////// +core.prototype.encodeRoute = function (route) { + var ans=""; + var lastMove = "", cnt=0; + + var items=Object.keys(core.material.items).sort(); + var shops=Object.keys(core.status.shops).sort(); + route.forEach(function (t) { + if (t=='up' || t=='down' || t=='left' || t=='right') { + if (t!=lastMove && cnt>0) { + ans+=lastMove.substring(0,1).toUpperCase(); + if (cnt>1) ans+=cnt; + cnt=0; + } + lastMove=t; + cnt++; + } + else { + if (cnt>0) { + ans+=lastMove.substring(0,1).toUpperCase(); + if (cnt>1) ans+=cnt; + cnt=0; + } + if (t.indexOf('item:')==0) + ans+="I"+items.indexOf(t.substring(5)); + else if (t.indexOf('fly:')==0) + ans+="F"+core.floorIds.indexOf(t.substring(4)); + else if (t.indexOf('choices:')==0) + ans+="C"+t.substring(8); + else if (t.indexOf('shop:')==0) { + var sp=t.substring(5).split(":"); + ans+="S"+shops.indexOf(sp[0])+":"+sp[1]; + } + } + }); + if (cnt>0) { + ans+=lastMove.substring(0,1).toUpperCase(); + if (cnt>1) ans+=cnt; + } + return ans; +} + +////// 解密路线 ////// +core.prototype.decodeRoute = function (route) { + +} + ////// 设置勇士属性 ////// core.prototype.setStatus = function (statusName, statusVal) { core.status.hero[statusName] = statusVal; diff --git a/libs/data.js b/libs/data.js index 680b98b7..ae052c34 100644 --- a/libs/data.js +++ b/libs/data.js @@ -43,7 +43,7 @@ data.prototype.init = function() { { "id": "moneyShop1", // 商店唯一ID "name": "贪婪之神", // 商店名称(标题) - "icon": "blueShop", // 商店图标,blueShop为蓝色商店,pinkShop为粉色商店 + "icon": "blueShop", // 商店图标,在icons.js中的npc一项定义 "textInList": "1F金币商店", // 在快捷商店栏中显示的名称 "use": "money", // 商店所要使用的。只能是"money"或"experience"。 "need": "20+10*times*(times+1)", // 商店需要的金币/经验数值;可以是一个表达式,以times作为参数计算。 @@ -96,7 +96,7 @@ data.prototype.init = function() { // effect也允许写一个function,代表本次升级将会执行的操作 {"need": 40, "effect": function () { - core.drawText("恭喜升级!"); + core.insertAction("恭喜升级!"); core.status.hero.hp *= 2; core.status.hero.atk += 100; core.status.hero.def += 100; diff --git a/libs/events.js b/libs/events.js index 5ae76e9b..13f03c01 100644 --- a/libs/events.js +++ b/libs/events.js @@ -433,11 +433,15 @@ events.prototype.openShop = function(shopId, needVisited) { shop.visited = true; var selection = core.status.event.selection; + var actions = []; + if (core.isset(core.status.event.data) && core.isset(core.status.event.data.actions)) + actions=core.status.event.data.actions; + core.ui.closePanel(); core.lockControl(); // core.status.event = {'id': 'shop', 'data': {'id': shopId, 'shop': shop}}; core.status.event.id = 'shop'; - core.status.event.data = {'id': shopId, 'shop': shop}; + core.status.event.data = {'id': shopId, 'shop': shop, 'actions': actions}; core.status.event.selection = selection; // 拼词 @@ -774,6 +778,8 @@ events.prototype.clickAction = function (x,y) { if (x >= 5 && x <= 7) { var topIndex = 6 - parseInt((choices.length - 1) / 2); if (y>=topIndex && y0) { if (keycode==13 || keycode==32 || keycode==67) { + core.status.route.push("choices:"+core.status.event.selection); this.insertAction(choices[core.status.event.selection].action); this.doAction(); } @@ -888,6 +895,7 @@ events.prototype.clickFly = function(x,y) { var index=core.status.hero.flyRange.indexOf(core.status.floorId); var stair=core.status.event.data0) { + core.status.route.push("shop:"+core.status.event.data.id+":"+core.status.event.data.actions.join("")); + } + core.status.boxAnimateObjs = []; core.setBoxAnimate(); if (core.status.event.data.fromList) diff --git a/libs/items.js b/libs/items.js index 149fb395..1a7e9417 100644 --- a/libs/items.js +++ b/libs/items.js @@ -193,6 +193,12 @@ items.prototype.useItem = function (itemId) { core.setFlag('curse', false); } core.updateStatusBar(); + + // 记录路线 + if (itemId!='book' && itemId!='fly') { + core.status.route.push("item:"+itemId); + } + // 道具使用完毕:删除 if (itemCls=='tools') core.status.hero.items[itemCls][itemId]--;