criticals

This commit is contained in:
oc 2018-05-22 14:27:32 +08:00
parent 609552e013
commit 98137082c4
5 changed files with 77 additions and 87 deletions

View File

@ -313,27 +313,21 @@ core.enemys.getExtraDamage(enemyId)
core.enemys.nextCriticals(enemyId, number) 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.getDamageInfo(enemy, hero_hp, hero_atk, hero_def, hero_mdef)
获得怪物的下一个临界减伤。
core.enemys.getDefDamage(enemyId)
获得一防减伤值。
core.enemys.getDamageInfo(enemyId, 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中伤害的数值。 计算战斗伤害实际返回的是上面getDamageInfo中伤害的数值。
@ -372,6 +366,10 @@ core.events.canUseQuickShop(shopId)
当前能否使用某个快捷商店 当前能否使用某个快捷商店
core.events.setHeroIcon(name)
设置勇士行走图
========== core.items.XXX 和道具相关的函数 ========== ========== core.items.XXX 和道具相关的函数 ==========
items.js将处理和道具相关的内容比如道具的使用获取和删除等等。 items.js将处理和道具相关的内容比如道具的使用获取和删除等等。

View File

@ -1331,7 +1331,9 @@ control.prototype.updateFg = function () {
// 临界显伤 // 临界显伤
if (core.flags.displayCritical) { 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 = '?'; if (critical == '???') critical = '?';
core.setFillStyle('fg', '#000000'); core.setFillStyle('fg', '#000000');
core.canvas.fg.fillText(critical, 32 * x + 2, 32 * (y + 1) - 2 - 10); core.canvas.fg.fillText(critical, 32 * x + 2, 32 * (y + 1) - 2 - 10);

View File

@ -132,92 +132,63 @@ enemys.prototype.getExtraDamage = function (monster) {
return extra_damage; return extra_damage;
} }
////// 接下来若干个临界值计算 ///// ////// 接下来N个临界值和临界减伤计算 //////
enemys.prototype.nextCriticals = function (monsterId, number) { enemys.prototype.nextCriticals = function (monsterId, number) {
number = number||1; var useTurn = true; // 是否使用回合法计算临界值如果要用循环法则直接改为false。
number = number||1;
var monster = core.material.enemys[monsterId]; var monster = core.material.enemys[monsterId];
// 坚固、模仿怪物没有临界! // 坚固、模仿怪物没有临界!
if (this.hasSpecial(monster.special, 3) || this.hasSpecial(monster.special, 10)) return []; 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); 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 (info == null) {
if (core.status.hero.atk<=monster.def) { if (core.status.hero.atk<=monster.def) {
return [(monster.def+1-core.status.hero.atk)+":?"]; return [[monster.def+1-core.status.hero.atk,'?']];
} }
return []; 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 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--) { if (useTurn) { // 回合数计算法
var nextAtk = Math.ceil(mon_hp/t) + mon_def; for (var t = turn-1;t>=1;t--) {
if (nextAtk<=hero_atk) break; var nextAtk = Math.ceil(mon_hp/t) + mon_def;
if (nextAtk!=pre) { if (nextAtk<=hero_atk) break;
var nextInfo = this.getDamageInfo(monster, core.status.hero.hp, nextAtk, core.status.hero.def, core.status.hero.mdef); if (nextAtk!=pre) {
if (nextInfo==null) break; var nextInfo = this.getDamageInfo(monster, core.status.hero.hp, nextAtk, core.status.hero.def, core.status.hero.mdef);
list.push((nextAtk-hero_atk)+":"+(info.damage-nextInfo.damage)); if (nextInfo==null) break;
if (nextInfo.damage<=0) break; list.push([nextAtk-hero_atk,info.damage-nextInfo.damage]);
pre = nextAtk; 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; return list;
} }
////// 临界值计算 ////// ////// N防减伤计算 //////
enemys.prototype.getCritical = function (monsterId) { enemys.prototype.getDefDamage = function (monsterId, k) {
var monster = core.material.enemys[monsterId]; k = k || 1;
// 坚固、模仿怪物没有临界!
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) {
var monster = core.material.enemys[monsterId]; 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 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 "???"; if (nowDamage == null || nextDamage ==null) return "???";
return nowDamage - nextDamage; 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) { 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; 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_hp=Math.max(0, hero_hp);
hero_atk=Math.max(0, hero_atk); 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) { 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); var info = this.getDamageInfo(monster, hero_hp, hero_atk, hero_def, hero_mdef);
if (info == null) return null; if (info == null) return null;
return info.damage; return info.damage;
@ -341,6 +320,9 @@ enemys.prototype.getCurrentEnemys = function (floorId) {
if (specialText.length>=3) specialText = "多属性..."; if (specialText.length>=3) specialText = "多属性...";
else specialText = specialText.join(" "); else specialText = specialText.join(" ");
var critical = this.nextCriticals(monsterId);
if (critical.length>0) critical=critical[0];
enemys.push({ enemys.push({
'id': monsterId, 'id': monsterId,
'name': monster.name, 'name': monster.name,
@ -352,8 +334,8 @@ enemys.prototype.getCurrentEnemys = function (floorId) {
'point': monster.point||0, // 加点 'point': monster.point||0, // 加点
'special': specialText, 'special': specialText,
'damage': this.getDamage(monsterId), 'damage': this.getDamage(monsterId),
'critical': this.getCritical(monsterId), 'critical': critical[0],
'criticalDamage': this.getCriticalDamage(monsterId), 'criticalDamage': critical[1],
'defDamage': this.getDefDamage(monsterId) 'defDamage': this.getDefDamage(monsterId)
}); });

View File

@ -643,13 +643,7 @@ events.prototype.doAction = function() {
break; break;
case "setHeroIcon": case "setHeroIcon":
{ {
var name = "hero.png"; this.setHeroIcon(data.name);
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.doAction(); this.doAction();
break; break;
} }
@ -1256,6 +1250,16 @@ events.prototype.canUseQuickShop = function(shopId) {
return null; 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 () { events.prototype.checkLvUp = function () {
if (!core.flags.enableLevelUp || core.status.hero.lv>=core.firstData.levelUp.length) return; if (!core.flags.enableLevelUp || core.status.hero.lv>=core.firstData.levelUp.length) return;

View File

@ -1341,7 +1341,11 @@ ui.prototype.drawBookDetail = function (index) {
hints.push("该怪物无特殊属性。"); hints.push("该怪物无特殊属性。");
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"); var content=hints.join("\n");