From 98137082c445166a9b9195e7172c99004e597a50 Mon Sep 17 00:00:00 2001 From: oc Date: Tue, 22 May 2018 14:27:32 +0800 Subject: [PATCH] criticals --- docs/api.md | 24 +++++------ libs/control.js | 4 +- libs/enemys.js | 112 ++++++++++++++++++++---------------------------- libs/events.js | 18 +++++--- libs/ui.js | 6 ++- 5 files changed, 77 insertions(+), 87 deletions(-) diff --git a/docs/api.md b/docs/api.md index 179774bf..92bc289b 100644 --- a/docs/api.md +++ b/docs/api.md @@ -313,27 +313,21 @@ core.enemys.getExtraDamage(enemyId) core.enemys.nextCriticals(enemyId, number) -返回接下来number个该怪物的临界。列表每一项类似 "x:y" 表示临界值为x,该临界减伤为y。 +返回一个列表,为接下来number(可忽略,默认为1)个该怪物的临界值和临界减伤。 +列表每一项类似 [x,y] 表示临界值为x,且临界减伤为y。 +如果无临界值,则返回空列表。 -core.enemys.getCritical(enemyId) -返回怪物的下一个临界值。无临界(如坚固、魔防等)返回'???'。 +core.enemys.getDefDamage(enemyId, k) +获得k(可忽略,默认为1)防减伤值。 -core.enemys.getCriticalDamage(enemyId) -获得怪物的下一个临界减伤。 - - -core.enemys.getDefDamage(enemyId) -获得一防减伤值。 - - -core.enemys.getDamageInfo(enemyId, hero_hp, hero_atk, hero_def, hero_mdef) +core.enemys.getDamageInfo(enemy, hero_hp, hero_atk, hero_def, hero_mdef) 获得实际战斗信息,比如伤害,回合数,每回合伤害等等。 此函数是实际战斗过程的计算。 -core.enemys.calDamage(enemyId, hero_hp, hero_atk, hero_def, hero_mdef) +core.enemys.calDamage(enemy, hero_hp, hero_atk, hero_def, hero_mdef) 计算战斗伤害;实际返回的是上面getDamageInfo中伤害的数值。 @@ -372,6 +366,10 @@ core.events.canUseQuickShop(shopId) 当前能否使用某个快捷商店 +core.events.setHeroIcon(name) +设置勇士行走图 + + ========== core.items.XXX 和道具相关的函数 ========== items.js将处理和道具相关的内容,比如道具的使用,获取和删除等等。 diff --git a/libs/control.js b/libs/control.js index 48437c91..429b9af7 100644 --- a/libs/control.js +++ b/libs/control.js @@ -1331,7 +1331,9 @@ control.prototype.updateFg = function () { // 临界显伤 if (core.flags.displayCritical) { - var critical = core.formatBigNumber(core.enemys.getCritical(id)); + var critical = core.enemys.nextCriticals(id); + if (critical.length>0) critical=critical[0]; + critical = core.formatBigNumber(critical[0]); if (critical == '???') critical = '?'; core.setFillStyle('fg', '#000000'); core.canvas.fg.fillText(critical, 32 * x + 2, 32 * (y + 1) - 2 - 10); diff --git a/libs/enemys.js b/libs/enemys.js index 1b4158ff..bdc5e7a0 100644 --- a/libs/enemys.js +++ b/libs/enemys.js @@ -132,92 +132,63 @@ enemys.prototype.getExtraDamage = function (monster) { return extra_damage; } -////// 接下来若干个临界值计算 ///// +////// 接下来N个临界值和临界减伤计算 ////// enemys.prototype.nextCriticals = function (monsterId, number) { - number = number||1; + var useTurn = true; // 是否使用回合法计算临界值;如果要用循环法,则直接改为false。 + number = number||1; var monster = core.material.enemys[monsterId]; // 坚固、模仿怪物没有临界! if (this.hasSpecial(monster.special, 3) || this.hasSpecial(monster.special, 10)) return []; - var info = this.getDamageInfo(monster, core.status.hero.hp, core.status.hero.atk, core.status.hero.def, core.status.hero.mdef); if (info == null) { if (core.status.hero.atk<=monster.def) { - return [(monster.def+1-core.status.hero.atk)+":?"]; + return [[monster.def+1-core.status.hero.atk,'?']]; } return []; } - if (info.damage <= 0) return []; - - var mon_hp = info.mon_hp, hero_atk = core.status.hero.atk, mon_def = monster.def, turn = info.turn; - - if (turn<=1) return []; var list = [], pre = null; + var mon_hp = info.mon_hp, hero_atk = core.status.hero.atk, mon_def = monster.def, turn = info.turn; - for (var t = turn-1;t>=1;t--) { - var nextAtk = Math.ceil(mon_hp/t) + mon_def; - if (nextAtk<=hero_atk) break; - if (nextAtk!=pre) { - var nextInfo = this.getDamageInfo(monster, core.status.hero.hp, nextAtk, core.status.hero.def, core.status.hero.mdef); - if (nextInfo==null) break; - list.push((nextAtk-hero_atk)+":"+(info.damage-nextInfo.damage)); - if (nextInfo.damage<=0) break; - pre = nextAtk; + if (useTurn) { // 回合数计算法 + for (var t = turn-1;t>=1;t--) { + var nextAtk = Math.ceil(mon_hp/t) + mon_def; + if (nextAtk<=hero_atk) break; + if (nextAtk!=pre) { + var nextInfo = this.getDamageInfo(monster, core.status.hero.hp, nextAtk, core.status.hero.def, core.status.hero.mdef); + if (nextInfo==null) break; + list.push([nextAtk-hero_atk,info.damage-nextInfo.damage]); + pre = nextAtk; + } + if (list.length>=number) + break; } - if (list.length>=number) - break; } + else { // 暴力for循环法 + pre = info.damage; + for (var atk=hero_atk+1;atk<=mon_hp+mon_def;atk++) { + var nextInfo = this.getDamageInfo(monster, core.status.hero.hp, atk, core.status.hero.def, core.status.hero.mdef); + if (nextInfo==null) break; + if (pre>nextInfo.damage) { + pre = nextInfo.damage; + list.push([atk-hero_atk, info.damage-nextInfo.damage]); + if (list.length>=number) break; + } + } + } + if (list.length==0) list.push([0,0]); return list; } -////// 临界值计算 ////// -enemys.prototype.getCritical = function (monsterId) { - var monster = core.material.enemys[monsterId]; - // 坚固、模仿怪物没有临界! - if (this.hasSpecial(monster.special, 3) || this.hasSpecial(monster.special, 10)) return "???"; - - var info = this.getDamageInfo(monster, core.status.hero.hp, core.status.hero.atk, core.status.hero.def, core.status.hero.mdef); - - if (info == null) { - if (core.status.hero.atk<=monster.def) - return monster.def+1-core.status.hero.atk; - return '???'; - } - if (info.damage <= 0) return 0; - - var mon_hp = info.mon_hp, hero_atk = core.status.hero.atk, mon_def = monster.def, turn = info.turn; - - // turn 是勇士攻击次数 - if (turn<=1) return 0; // 攻杀 - - // 每回合最小伤害 = ⎡怪物生命/勇士攻击次数⎤ - var nextAtk = Math.ceil(mon_hp/(turn-1)) + mon_def; - - if (nextAtk <= hero_atk) return 0; - return nextAtk - hero_atk; - -} - -////// 临界减伤计算 ////// -enemys.prototype.getCriticalDamage = function (monsterId) { - var c = this.getCritical(monsterId); - if (c == '???') return '???'; - if (c <= 0) return 0; - var monster = core.material.enemys[monsterId]; - var last = this.calDamage(monster, core.status.hero.hp, core.status.hero.atk, core.status.hero.def, core.status.hero.mdef); - var now = this.calDamage(monster, core.status.hero.hp, core.status.hero.atk+c, core.status.hero.def, core.status.hero.mdef); - if (last == null || now==null) return '???'; - return last - now; -} - -////// 1防减伤计算 ////// -enemys.prototype.getDefDamage = function (monsterId) { +////// N防减伤计算 ////// +enemys.prototype.getDefDamage = function (monsterId, k) { + k = k || 1; var monster = core.material.enemys[monsterId]; var nowDamage = this.calDamage(monster, core.status.hero.hp, core.status.hero.atk, core.status.hero.def, core.status.hero.mdef); - var nextDamage = this.calDamage(monster, core.status.hero.hp, core.status.hero.atk, core.status.hero.def + 1, core.status.hero.mdef); + var nextDamage = this.calDamage(monster, core.status.hero.hp, core.status.hero.atk, core.status.hero.def + k, core.status.hero.mdef); if (nowDamage == null || nextDamage ==null) return "???"; return nowDamage - nextDamage; } @@ -225,6 +196,10 @@ enemys.prototype.getDefDamage = function (monsterId) { ////// 获得战斗伤害信息 ////// enemys.prototype.getDamageInfo = function(monster, hero_hp, hero_atk, hero_def, hero_mdef) { + if (typeof monster == 'string') { + monster = core.material.enemys[monster]; + } + var mon_hp = monster.hp, mon_atk = monster.atk, mon_def = monster.def, mon_special = monster.special; hero_hp=Math.max(0, hero_hp); hero_atk=Math.max(0, hero_atk); @@ -310,6 +285,10 @@ enemys.prototype.getDamageInfo = function(monster, hero_hp, hero_atk, hero_def, ////// 具体的伤害计算公式 ////// enemys.prototype.calDamage = function (monster, hero_hp, hero_atk, hero_def, hero_mdef) { + if (typeof monster == 'string') { + monster = core.material.enemys[monsterId]; + } + var info = this.getDamageInfo(monster, hero_hp, hero_atk, hero_def, hero_mdef); if (info == null) return null; return info.damage; @@ -341,6 +320,9 @@ enemys.prototype.getCurrentEnemys = function (floorId) { if (specialText.length>=3) specialText = "多属性..."; else specialText = specialText.join(" "); + var critical = this.nextCriticals(monsterId); + if (critical.length>0) critical=critical[0]; + enemys.push({ 'id': monsterId, 'name': monster.name, @@ -352,8 +334,8 @@ enemys.prototype.getCurrentEnemys = function (floorId) { 'point': monster.point||0, // 加点 'special': specialText, 'damage': this.getDamage(monsterId), - 'critical': this.getCritical(monsterId), - 'criticalDamage': this.getCriticalDamage(monsterId), + 'critical': critical[0], + 'criticalDamage': critical[1], 'defDamage': this.getDefDamage(monsterId) }); diff --git a/libs/events.js b/libs/events.js index 09da3f66..b8f2f1b4 100644 --- a/libs/events.js +++ b/libs/events.js @@ -643,13 +643,7 @@ events.prototype.doAction = function() { break; case "setHeroIcon": { - var name = "hero.png"; - if (core.isset(core.material.images.images[data.name]) && core.material.images.images[data.name].width==128) - name = data.name; - core.setFlag("heroIcon", name); - core.material.images.hero.src = core.material.images.images[name].src; - core.material.icons.hero.height = core.material.images.images[name].height/4; - core.drawHero(); + this.setHeroIcon(data.name); this.doAction(); break; } @@ -1256,6 +1250,16 @@ events.prototype.canUseQuickShop = function(shopId) { return null; } +////// 设置角色行走图 ////// +events.prototype.setHeroIcon = function (name) { + if (core.isset(core.material.images.images[name]) && core.material.images.images[name].width==128) { + core.setFlag("heroIcon", name); + core.material.images.hero.src = core.material.images.images[name].src; + core.material.icons.hero.height = core.material.images.images[name].height/4; + core.drawHero(); + } +} + ////// 检查升级事件 ////// events.prototype.checkLvUp = function () { if (!core.flags.enableLevelUp || core.status.hero.lv>=core.firstData.levelUp.length) return; diff --git a/libs/ui.js b/libs/ui.js index 0d42b692..1520a02c 100644 --- a/libs/ui.js +++ b/libs/ui.js @@ -1341,7 +1341,11 @@ ui.prototype.drawBookDetail = function (index) { hints.push("该怪物无特殊属性。"); hints.push(""); - hints.push("临界表:"+JSON.stringify(core.enemys.nextCriticals(enemyId,10))) + var criticals = core.enemys.nextCriticals(enemyId, 10).map(function (v) { + return v[0]+":"+v[1]; + }); + while (criticals[0]=='0:0') criticals.shift(); + hints.push("临界表:"+JSON.stringify(criticals)) var content=hints.join("\n");