From 3975a0a09df7bd8c7057fc0dcb81e0d66bc1559c Mon Sep 17 00:00:00 2001 From: ckcz123 Date: Thu, 12 Aug 2021 21:14:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BD=95=E5=83=8F=E5=A4=B1=E8=B4=A5=20&=20?= =?UTF-8?q?=E6=9C=AA=E7=A0=B4=E9=98=B2=E4=B8=B4=E7=95=8C=20&=20replaceText?= =?UTF-8?q?=E6=A0=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _server/editor_blockly.js | 8 +++++++ libs/control.js | 6 +++-- libs/enemys.js | 50 +++++++++++++++++++++++++++++---------- libs/events.js | 1 + libs/utils.js | 15 +++++++++--- 5 files changed, 62 insertions(+), 18 deletions(-) diff --git a/_server/editor_blockly.js b/_server/editor_blockly.js index 3950d437..af5b87bc 100644 --- a/_server/editor_blockly.js +++ b/_server/editor_blockly.js @@ -235,6 +235,14 @@ editor_blockly = function () { } } } + if (one.type == 'wait') { + var list = one.data; + if (list instanceof Array) { + for (var j = 0; j < list.length; j++) { + if (this.checkAsync(list[j].action)) return true; + } + } + } if (one.type == 'previewUI' && this.checkAsync(one.action)) return true; if (one.async && one.type != 'animate' && one.type != 'function') hasAsync = true; if (one.type == 'waitAsync') hasAsync = false; diff --git a/libs/control.js b/libs/control.js index d217ad50..e8bd6979 100644 --- a/libs/control.js +++ b/libs/control.js @@ -1637,7 +1637,7 @@ control.prototype._replay_save = function () { } } -control.prototype._replay_error = function (action) { +control.prototype._replay_error = function (action, callback) { core.ui.closePanel(); core.status.replay.replaying = false; var len = core.status.replay.toReplay.length; @@ -1655,12 +1655,14 @@ control.prototype._replay_error = function (action) { } else { core.playSound('操作失败'); - core.drawTip("无法回到上一个节点"); core.stopReplay(true); + core.drawTip("无法回到上一个节点"); + if (callback) callback(); } }, function () { core.ui.closePanel(); core.stopReplay(true); + if (callback) callback(); }); } diff --git a/libs/enemys.js b/libs/enemys.js index aba7a43b..06a97b4f 100644 --- a/libs/enemys.js +++ b/libs/enemys.js @@ -224,19 +224,22 @@ enemys.prototype.nextCriticals = function (enemy, number, x, y, floorId) { if (typeof enemy == 'string') enemy = core.material.enemys[enemy]; number = number || 1; - if (this.hasSpecial(enemy.special, 10)) return []; // 模仿怪物临界 + var specialCriticals = this._nextCriticals_special(enemy, number, x, y, floorId); + if (specialCriticals != null) return specialCriticals; var info = this.getDamageInfo(enemy, null, x, y, floorId); - if (info == null || this.hasSpecial(enemy.special, 3)) { // 未破防,或是坚固怪 - info = this.getEnemyInfo(enemy, null, x, y, floorId); - if (core.status.hero.atk <= info.def) { - return [[info.def + 1 - core.status.hero.atk, '?']]; - } - return []; + if (info == null) { // 如果未破防... + var enemyInfo = this.getEnemyInfo(enemy, null, x, y, floorId); + if (enemyInfo.def == null || enemyInfo.def < core.status.hero.atk) return []; + // 再次尝试获得破防后伤害 + info = this.getDamageInfo(enemy, {atk: enemyInfo.def + 1}, x, y, floorId); + if (info == null || info.mon_def != enemyInfo.def) return []; + info.__over__ = true; + info.__overAtk__ = info.mon_def + 1 - core.status.hero.atk; } - // getDamageInfo直接返回数字;0伤且无负伤 - if (typeof info == 'number' || (info.damage <= 0 && !core.flags.enableNegativeDamage)) { - return [[0, 0]]; + if (typeof info == 'number') return [[0,0]]; + if (info.damage <= 0 && !core.flags.enableNegativeDamage) { + return [[info.__overAtk__ || 0, 0]]; } if (core.flags.useLoop) { @@ -253,10 +256,21 @@ enemys.prototype.nextCriticals = function (enemy, number, x, y, floorId) { } } +enemys.prototype._nextCriticals_special = function (enemy, number, x, y, floorId) { + if (this.hasSpecial(enemy.special, 10) || this.hasSpecial(enemy.special, 3)) + return []; // 模仿or坚固临界 + return null; +} + enemys.prototype._nextCriticals_useLoop = function (enemy, info, number, x, y, floorId) { var mon_hp = info.mon_hp, hero_atk = core.status.hero.atk, mon_def = info.mon_def, pre = info.damage; var list = []; - for (var atk = hero_atk + 1; atk <= mon_hp + mon_def; atk++) { + var start_atk = hero_atk; + if (info.__over__) { + start_atk = mon_def + 1; + list.push([info.__overAtk__, -info.damage]); + } + for (var atk = start_atk + 1; atk <= mon_hp + mon_def; atk++) { var nextInfo = this.getDamageInfo(enemy, {"atk": atk}, x, y, floorId); if (nextInfo == null || (typeof nextInfo == 'number')) break; if (pre > nextInfo.damage) { @@ -273,6 +287,11 @@ enemys.prototype._nextCriticals_useLoop = function (enemy, info, number, x, y, f enemys.prototype._nextCriticals_useBinarySearch = function (enemy, info, number, x, y, floorId) { var mon_hp = info.mon_hp, hero_atk = core.status.hero.atk, mon_def = info.mon_def, pre = info.damage; var list = []; + var start_atk = hero_atk; + if (info.__over__) { + start_atk = mon_def + 1; + list.push([info.__overAtk__, -info.damage]); + } var calNext = function (currAtk, maxAtk) { var start = Math.floor(currAtk), end = Math.floor(maxAtk); if (start > end) return null; @@ -288,7 +307,7 @@ enemys.prototype._nextCriticals_useBinarySearch = function (enemy, info, number, var nextInfo = core.enemys.getDamageInfo(enemy, {"atk": start}, x, y, floorId); return nextInfo == null || (typeof nextInfo == 'number') || nextInfo.damage >= pre ? null : [start, nextInfo.damage]; } - var currAtk = hero_atk; + var currAtk = start_atk; while (true) { var next = calNext(currAtk + 1, mon_hp + mon_def, pre); if (next == null) break; @@ -310,11 +329,16 @@ enemys.prototype._nextCriticals_useTurn = function (enemy, info, number, x, y, f return this._nextCriticals_useBinarySearch(enemy, info, number, x, y, floorId); } var list = [], pre = null; + var start_atk = hero_atk; + if (info.__over__) { + start_atk = mon_def + 1; + list.push([info.__overAtk__, -info.damage]); + } for (var t = turn - 1; t >= 1; t--) { var nextAtk = Math.ceil(mon_hp / t) + mon_def; // 装备提升比例的计算临界 nextAtk = Math.ceil(nextAtk / core.getBuff('atk')); - if (nextAtk <= hero_atk) break; + if (nextAtk <= start_atk) break; if (nextAtk != pre) { var nextInfo = this.getDamageInfo(enemy, {"atk": nextAtk}, x, y, floorId); if (nextInfo == null || (typeof nextInfo == 'number')) break; diff --git a/libs/events.js b/libs/events.js index 9cb59ab7..cca91444 100644 --- a/libs/events.js +++ b/libs/events.js @@ -118,6 +118,7 @@ events.prototype.win = function (reason, norank, noexit) { ////// 游戏失败事件 ////// events.prototype.lose = function (reason) { + if (core.isReplaying()) return core.control._replay_error(reason, function () { core.lose(reason); }); core.status.gameOver = true; return this.eventdata.lose(reason); } diff --git a/libs/utils.js b/libs/utils.js index d8798860..7e04871e 100644 --- a/libs/utils.js +++ b/libs/utils.js @@ -96,9 +96,18 @@ utils.prototype._init = function () { ////// 将文字中的${和}(表达式)进行替换 ////// utils.prototype.replaceText = function (text, prefix) { if (typeof text != 'string') return text; - return text.replace(/\${(.*?)}/g, function (word, value) { - return core.calValue(value, prefix); - }); + var index = text.indexOf("${"); + if (index < 0) return text; + var cnt = 0, curr = index; + while (++curr < text.length) { + if (text.charAt(curr) == '{') cnt++; + if (text.charAt(curr) == '}') cnt--; + if (cnt == 0) break; + } + if (cnt != 0) return text; + var value = core.calValue(text.substring(index+2, curr), prefix); + if (value == null) value = ""; + return text.substring(0, index) + value + core.replaceText(text.substring(curr + 1), prefix); } utils.prototype.replaceValue = function (value) {