全局商店优化

This commit is contained in:
ckcz123 2021-08-30 17:28:49 +08:00
parent 5c2caf7556
commit 4081d7a3e7
5 changed files with 47 additions and 18 deletions

View File

@ -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();
}

View File

@ -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) {

View File

@ -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);

View File

@ -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"
}
]
}
]

View File

@ -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;