diff --git a/libs/actions.js b/libs/actions.js index 34a4d68d..3e967d99 100644 --- a/libs/actions.js +++ b/libs/actions.js @@ -1084,7 +1084,12 @@ actions.prototype._clickAction = function (x, y, px, py) { var timeout = Math.max(0, core.status.event.timeout - new Date().getTime()) || 0; delete core.status.event.timeout; core.setFlag('timeout', timeout); - core.status.route.push("choices:" + (100 * timeout + y - topIndex)); + // 对全局商店特殊处理 + var index = y - topIndex; + if (index == choices.length - 1 && core.hasFlag('@temp@shop')) { + index = -1; + } + core.status.route.push("choices:" + (100 * timeout + index)); core.insertAction(choice.action); core.doAction(); } diff --git a/libs/events.js b/libs/events.js index ccac7a3b..57ffff6c 100644 --- a/libs/events.js +++ b/libs/events.js @@ -2037,9 +2037,7 @@ events.prototype._action_choices = function (data, x, y, prefix) { var action = core.status.replay.toReplay.shift(); if (action.indexOf('choices:') == 0 && !(action == 'choices:none' && !data.timeout)) { var index = action.substring(8); - if (index == 'none' || ((index = parseInt(index)) >= 0) && index % 100 < data.choices.length) { - this.__action_choices_replaying(data, index); - } else { + if (!this.__action_choices_replaying(data, index)) { core.control._replay_error(action); return; } @@ -2057,7 +2055,7 @@ events.prototype._action_choices = function (data, x, y, prefix) { return; } if (action != 'choices:none') core.status.replay.toReplay.unshift(action); // 首先归还刚才读出的下一步操作 - core.events.__action_choices_replaying(data, core.clamp(parseInt(value), 0, data.choices.length - 1)) + core.events.__action_choices_replaying(data, ((parseInt(value) || 0) + data.choices.length) % data.choices.length); }); } } @@ -2080,17 +2078,24 @@ events.prototype._action_choices = function (data, x, y, prefix) { } events.prototype.__action_choices_replaying = function (data, index) { + var selection = index; if (index != 'none') { - var timeout = Math.floor(index / 100) || 0; + selection = parseInt(index); + if (isNaN(selection)) return false; + if (selection < 0) selection += data.choices.length; + if (selection < 0) return false; + if (selection % 100 > 50) selection += data.choices.length; + if (selection % 100 > data.choices.length) return false; + var timeout = Math.floor(selection / 100) || 0; core.setFlag('timeout', timeout); - index %= 100; + selection %= 100; } else core.setFlag('timeout', 0); - core.status.event.selection = index; + core.status.event.selection = selection; setTimeout(function () { core.status.route.push("choices:"+index); - if (index != 'none') { + if (selection != 'none') { // 检查 - var choice = data.choices[index]; + var choice = data.choices[selection]; if (choice.need != null && choice.need != '' && !core.calValue(choice.need)) { // 无法选择此项 core.control._replay_error("无法选择项:"+index); @@ -2101,6 +2106,7 @@ events.prototype.__action_choices_replaying = function (data, index) { } core.doAction(); }, core.status.replay.speed == 24 ? 1 : 750 / Math.max(1, core.status.replay.speed)); + return true; } events.prototype._precompile_choices = function (data) { diff --git a/libs/utils.js b/libs/utils.js index 9b707cbc..b02b874f 100644 --- a/libs/utils.js +++ b/libs/utils.js @@ -677,8 +677,14 @@ utils.prototype.decodeRoute = function (route) { utils.prototype._decodeRoute_getNumber = function (decodeObj, noparse) { var num = ""; - while (decodeObj.index < decodeObj.route.length && !isNaN(decodeObj.route.charAt(decodeObj.index))) { - num += decodeObj.route.charAt(decodeObj.index++); + var first = true; + while (true) { + var ch = decodeObj.route.charAt(decodeObj.index); + if (ch >= '0' && ch <= '9') num += ch; + else if (ch == '-' && first) num += ch; + else break; + first = false; + decodeObj.index++; } if (num.length == 0) num = "1"; return noparse ? num : parseInt(num); diff --git a/project/floors/sample1.js b/project/floors/sample1.js index be0af792..a9280e0b 100644 --- a/project/floors/sample1.js +++ b/project/floors/sample1.js @@ -441,7 +441,10 @@ main.floors.sample1= } ], "false": [ - "\t[老人,trader]你的金钱不足!" + "\t[老人,trader]你的金钱不足!", + { + "type": "continue" + } ] } ] @@ -464,13 +467,13 @@ main.floors.sample1= "name": "item:blueKey", "operator": "+=", "value": "1" - }, - { - "type": "continue" } ], "false": [ - "\t[老人,trader]你的金钱不足!" + "\t[老人,trader]你的金钱不足!", + { + "type": "continue" + } ] } ] diff --git a/project/plugins.js b/project/plugins.js index 6c5de0b1..f4a00cc2 100644 --- a/project/plugins.js +++ b/project/plugins.js @@ -112,6 +112,8 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = return; } + _shouldProcessKeyUp = true; + // Step 4: 执行标准公共商店 core.insertAction(this._convertShop(shop)); return true; @@ -221,9 +223,16 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = return null; } + var _shouldProcessKeyUp = true; + /// 允许商店X键退出 core.registerAction('keyUp', 'shops', function (keycode) { if (!core.status.lockControl || !core.hasFlag("@temp@shop") || core.status.event.id != 'action') return false; + if ((keycode == 13 || keycode == 32) && !_shouldProcessKeyUp) { + _shouldProcessKeyUp = true; + return true; + } + if (core.status.event.data.type != 'choices') return false; var data = core.status.event.data.current; var choices = data.choices; @@ -232,7 +241,6 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = core.actions._clickAction(core.actions.HSIZE, topIndex + choices.length - 1); return true; } - if (keycode == 13 || keycode == 32) return true; return false; }, 60); @@ -245,6 +253,7 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = var topIndex = core.actions._getChoicesTopIndex(choices.length); if (keycode == 13 || keycode == 32) { // Space, Enter core.actions._clickAction(core.actions.HSIZE, topIndex + core.status.event.selection); + _shouldProcessKeyUp = false; return true; } return false;