support Huge integers

This commit is contained in:
oc 2018-04-17 23:04:47 +08:00
parent ece78a0c9f
commit 85d45d0147
6 changed files with 55 additions and 57 deletions

View File

@ -249,7 +249,7 @@ enemys.prototype.calDamage = function (monster, hero_hp, hero_atk, hero_def, her
// 如果有神圣盾免疫吸血等可以在这里写
if (core.hasFlag("shield5")) vampireDamage = 0; // 存在神圣盾吸血伤害为0
vampireDamage = parseInt(vampireDamage);
vampireDamage = Math.floor(vampireDamage) || 0;
// 加到自身
if (monster.add) // 如果加到自身
mon_hp += vampireDamage;

View File

@ -946,7 +946,7 @@ control.prototype.updateCheckBlock = function() {
core.status.checkBlock.betweenAttack[13*x+y]=true;
var leftHp = core.status.hero.hp - core.status.checkBlock.damage[13*x+y];
if (leftHp>1)
core.status.checkBlock.damage[13*x+y] += parseInt((leftHp+(core.flags.betweenAttackCeil?0:1))/2);
core.status.checkBlock.damage[13*x+y] += Math.floor((leftHp+(core.flags.betweenAttackCeil?0:1))/2);
}
}
}
@ -2088,9 +2088,7 @@ control.prototype.updateStatusBar = function () {
var statusList = ['hpmax', 'hp', 'atk', 'def', 'mdef', 'money', 'experience'];
statusList.forEach(function (item) {
var val = core.getStatus(item);
if (val>=10000000) val = parseInt(val/10000) + "W";
core.statusBar[item].innerHTML = val;
core.statusBar[item].innerHTML = core.formatBigNumber(core.getStatus(item));
});
// 进阶

View File

@ -84,11 +84,11 @@ enemys.prototype.getSpecialHint = function (enemy, special) {
case 4: return "2连击怪物每回合攻击2次";
case 5: return "3连击怪物每回合攻击3次";
case 6: return (enemy.n||4)+"连击: 怪物每回合攻击"+(enemy.n||4)+"次";
case 7: return "破甲:战斗前,怪物附加角色防御的"+parseInt(100*core.values.breakArmor||0)+"%作为伤害";
case 8: return "反击:战斗时,怪物每回合附加角色攻击的"+parseInt(100*core.values.counterAttack||0)+"%作为伤害,无视角色防御";
case 7: return "破甲:战斗前,怪物附加角色防御的"+Math.floor(100*core.values.breakArmor||0)+"%作为伤害";
case 8: return "反击:战斗时,怪物每回合附加角色攻击的"+Math.floor(100*core.values.counterAttack||0)+"%作为伤害,无视角色防御";
case 9: return "净化:战斗前,怪物附加勇士魔防的"+core.values.purify+"倍作为伤害";
case 10: return "模仿:怪物的攻防和勇士攻防相等";
case 11: return "吸血:战斗前,怪物首先吸取角色的"+parseInt(100*enemy.value||0)+"%生命作为伤害"+(enemy.add?",并把伤害数值加到自身生命上":"");
case 11: return "吸血:战斗前,怪物首先吸取角色的"+Math.floor(100*enemy.value||0)+"%生命作为伤害"+(enemy.add?",并把伤害数值加到自身生命上":"");
case 12: return "中毒:战斗后,勇士陷入中毒状态,每一步损失生命"+core.values.poisonDamage+"点";
case 13: return "衰弱:战斗后,勇士陷入衰弱状态,攻防暂时下降"+core.values.weakValue+"点";
case 14: return "诅咒:战斗后,勇士陷入诅咒状态,战斗无法获得金币和经验";
@ -138,7 +138,7 @@ enemys.prototype.getCritical = function (monsterId) {
// 坚固、模仿怪物没有临界!
if (this.hasSpecial(monster.special, 3) || this.hasSpecial(monster.special, 10)) return "???";
if (monster.def + monster.hp/2 <= 10000) {
if (monster.def + monster.hp/2 <= 0) {
var last = this.calDamage(monster, core.status.hero.hp, core.status.hero.atk, core.status.hero.def, core.status.hero.mdef);
@ -157,23 +157,22 @@ enemys.prototype.getCritical = function (monsterId) {
}
else {
var info = this.getDamageInfo(monster, 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) 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<=0) return '???';
var nextTurn = turn - 1; // 怪物攻击次数少1
// turn 是勇士攻击次数
if (turn<=1) return 0; // 攻杀
// 每回合最小伤害 = ⎡怪物生命/勇士攻击次数⎤
var nextAtk = parseInt((mon_hp - 1)/(nextTurn+1)) + 1 + mon_def;
var nextAtk = Math.ceil(mon_hp/(turn-1)) + mon_def;
if (nextAtk <= hero_atk) return '???';
return core.formatBigNumber(nextAtk - hero_atk);
if (nextAtk <= hero_atk) return 0;
return nextAtk - hero_atk;
}
}
@ -187,7 +186,7 @@ enemys.prototype.getCriticalDamage = function (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 core.formatBigNumber(last - now);
return last - now;
}
////// 1防减伤计算 //////
@ -196,7 +195,7 @@ enemys.prototype.getDefDamage = function (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);
if (nowDamage == null || nextDamage ==null) return "???";
return core.formatBigNumber(nowDamage - nextDamage);
return nowDamage - nextDamage;
}
////// 获得战斗伤害信息 //////
@ -219,7 +218,7 @@ enemys.prototype.getDamageInfo = function(monster, hero_hp, hero_atk, hero_def,
// 如果有神圣盾免疫吸血等可以在这里写
vampireDamage = parseInt(vampireDamage) || 0;
vampireDamage = Math.floor(vampireDamage) || 0;
// 加到自身
if (monster.add) // 如果加到自身
mon_hp += vampireDamage;
@ -248,7 +247,7 @@ enemys.prototype.getDamageInfo = function(monster, hero_hp, hero_atk, hero_def,
var counterDamage = 0;
// 反击
if (this.hasSpecial(mon_special, 8)) counterDamage += parseInt(core.values.counterAttack * hero_atk);
if (this.hasSpecial(mon_special, 8)) counterDamage += Math.floor(core.values.counterAttack * hero_atk);
// 先攻
if (this.hasSpecial(mon_special, 1))
@ -256,14 +255,15 @@ enemys.prototype.getDamageInfo = function(monster, hero_hp, hero_atk, hero_def,
// 破甲
if (this.hasSpecial(mon_special, 7))
initDamage += parseInt(core.values.breakArmor * hero_def);
initDamage += Math.floor(core.values.breakArmor * hero_def);
// 净化
if (this.hasSpecial(mon_special, 9))
initDamage += parseInt(core.values.purify * hero_mdef);
initDamage += Math.floor(core.values.purify * hero_mdef);
var turn = parseInt((mon_hp - 1) / (hero_atk - mon_def));
var ans = initDamage + turn * per_damage + (turn + 1) * counterDamage;
// turn: 勇士攻击回合数
var turn = Math.ceil(mon_hp / (hero_atk - mon_def));
var ans = initDamage + (turn - 1) * per_damage + turn * counterDamage;
ans -= hero_mdef;
if (!core.flags.enableNegativeDamage)
@ -275,8 +275,7 @@ enemys.prototype.getDamageInfo = function(monster, hero_hp, hero_atk, hero_def,
"hero_mdef": hero_mdef,
"mon_hp": mon_hp,
"mon_atk": mon_atk,
"mod_def": mon_def,
"mon_mdef": mon_mdef,
"mon_def": mon_def,
"per_damage": per_damage,
"initDamage": initDamage,
"turn": turn,

View File

@ -488,7 +488,7 @@ events.prototype.doAction = function() {
var value=core.calValue(data.value);
// 属性
if (data.name.indexOf("status:")==0) {
value=parseInt(value);
value=parseFloat(value);
core.setStatus(data.name.substring(7), value);
}
// 道具

View File

@ -787,7 +787,7 @@ ui.prototype.drawBattleAnimate = function(monsterId, callback) {
// 如果有神圣盾免疫吸血等可以在这里写
vampireDamage = parseInt(vampireDamage);
vampireDamage = Math.floor(vampireDamage);
// 加到自身
if (monster.add) // 如果加到自身
mon_hp += vampireDamage;
@ -815,8 +815,8 @@ ui.prototype.drawBattleAnimate = function(monsterId, callback) {
if (core.enemys.hasSpecial(mon_special, 6)) turns=1+(monster.n||4);
// 初始伤害
if (core.enemys.hasSpecial(mon_special, 7)) initDamage+=parseInt(core.values.breakArmor * hero_def);
if (core.enemys.hasSpecial(mon_special, 9)) initDamage+=parseInt(core.values.purify * hero_mdef);
if (core.enemys.hasSpecial(mon_special, 7)) initDamage+=Math.floor(core.values.breakArmor * hero_def);
if (core.enemys.hasSpecial(mon_special, 9)) initDamage+=Math.floor(core.values.purify * hero_mdef);
hero_mdef-=initDamage;
if (hero_mdef<0) {
hero_hp+=hero_mdef;
@ -1001,7 +1001,7 @@ ui.prototype.drawBattleAnimate = function(monsterId, callback) {
// 反击
if (core.enemys.hasSpecial(mon_special, 8)) {
hero_mdef -= parseInt(core.values.counterAttack * hero_atk);
hero_mdef -= Math.floor(core.values.counterAttack * hero_atk);
if (hero_mdef<0) {
hero_hp+=hero_mdef;
@ -1247,16 +1247,16 @@ ui.prototype.drawBook = function (index) {
}
core.canvas.ui.textAlign = "left";
core.fillText('ui', '生命', 165, 62 * i + 32, '#DDDDDD', '13px Verdana');
core.fillText('ui', enemy.hp, 195, 62 * i + 32, '#DDDDDD', 'bold 13px Verdana');
core.fillText('ui', core.formatBigNumber(enemy.hp), 195, 62 * i + 32, '#DDDDDD', 'bold 13px Verdana');
core.fillText('ui', '攻击', 255, 62 * i + 32, '#DDDDDD', '13px Verdana');
core.fillText('ui', enemy.atk, 285, 62 * i + 32, '#DDDDDD', 'bold 13px Verdana');
core.fillText('ui', core.formatBigNumber(enemy.atk), 285, 62 * i + 32, '#DDDDDD', 'bold 13px Verdana');
core.fillText('ui', '防御', 335, 62 * i + 32, '#DDDDDD', '13px Verdana');
core.fillText('ui', enemy.def, 365, 62 * i + 32, '#DDDDDD', 'bold 13px Verdana');
core.fillText('ui', core.formatBigNumber(enemy.def), 365, 62 * i + 32, '#DDDDDD', 'bold 13px Verdana');
var expOffset = 165, line_cnt=0;
if (core.flags.enableMoney) {
core.fillText('ui', '金币', 165, 62 * i + 50, '#DDDDDD', '13px Verdana');
core.fillText('ui', enemy.money, 195, 62 * i + 50, '#DDDDDD', 'bold 13px Verdana');
core.fillText('ui', core.formatBigNumber(enemy.money), 195, 62 * i + 50, '#DDDDDD', 'bold 13px Verdana');
expOffset = 255;
line_cnt++;
}
@ -1265,7 +1265,7 @@ ui.prototype.drawBook = function (index) {
if (core.flags.enableAddPoint) {
core.canvas.ui.textAlign = "left";
core.fillText('ui', '加点', expOffset, 62 * i + 50, '#DDDDDD', '13px Verdana');
core.fillText('ui', enemy.point, expOffset + 30, 62 * i + 50, '#DDDDDD', 'bold 13px Verdana');
core.fillText('ui', core.formatBigNumber(enemy.point), expOffset + 30, 62 * i + 50, '#DDDDDD', 'bold 13px Verdana');
expOffset = 255;
line_cnt++;
}
@ -1273,7 +1273,7 @@ ui.prototype.drawBook = function (index) {
if (core.flags.enableExperience && line_cnt<2) {
core.canvas.ui.textAlign = "left";
core.fillText('ui', '经验', expOffset, 62 * i + 50, '#DDDDDD', '13px Verdana');
core.fillText('ui', enemy.experience, expOffset + 30, 62 * i + 50, '#DDDDDD', 'bold 13px Verdana');
core.fillText('ui', core.formatBigNumber(enemy.experience), expOffset + 30, 62 * i + 50, '#DDDDDD', 'bold 13px Verdana');
line_cnt++;
}
@ -1281,15 +1281,6 @@ ui.prototype.drawBook = function (index) {
if (line_cnt==1) damageOffset=326;
if (line_cnt==2) damageOffset=361;
/*
var damageOffet = 281;
if (core.flags.enableMoney && core.flags.enableExperience)
damageOffet = 361;
else if (core.flags.enableMoney || core.flags.enableExperience)
damageOffet = 326;
*/
core.canvas.ui.textAlign = "center";
var damage = enemy.damage;
@ -1303,18 +1294,17 @@ ui.prototype.drawBook = function (index) {
if (damage<=0) color = '#00FF00';
damage = core.formatBigNumber(damage);
}
core.fillText('ui', damage, damageOffset, 62 * i + 50, color, 'bold 13px Verdana');
core.canvas.ui.textAlign = "left";
core.fillText('ui', '临界', 165, 62 * i + 68, '#DDDDDD', '13px Verdana');
core.fillText('ui', enemy.critical, 195, 62 * i + 68, '#DDDDDD', 'bold 13px Verdana');
core.fillText('ui', core.formatBigNumber(enemy.critical), 195, 62 * i + 68, '#DDDDDD', 'bold 13px Verdana');
core.fillText('ui', '减伤', 255, 62 * i + 68, '#DDDDDD', '13px Verdana');
core.fillText('ui', enemy.criticalDamage, 285, 62 * i + 68, '#DDDDDD', 'bold 13px Verdana');
core.fillText('ui', core.formatBigNumber(enemy.criticalDamage), 285, 62 * i + 68, '#DDDDDD', 'bold 13px Verdana');
core.fillText('ui', '1防', 335, 62 * i + 68, '#DDDDDD', '13px Verdana');
core.fillText('ui', enemy.defDamage, 365, 62 * i + 68, '#DDDDDD', 'bold 13px Verdana');
core.fillText('ui', core.formatBigNumber(enemy.defDamage), 365, 62 * i + 68, '#DDDDDD', 'bold 13px Verdana');
if (index == start+i) {
core.strokeRect('ui', 10, 62 * i + 13, 416-10*2, 62, '#FFD700');

View File

@ -146,13 +146,24 @@ utils.prototype.setTwoDigits = function (x) {
}
utils.prototype.formatBigNumber = function (x) {
x = parseInt(x);
if (!core.isset(x)) return x;
x = parseFloat(x);
if (!core.isset(x)) return '???';
if (x>=1e17) return (x / 1e16).toFixed(1) + "j";
else if (x>=1e13) return (x / 1e12).toFixed(1) + "z";
else if (x>=1e9) return (x / 1e8).toFixed(1) + "e";
else if (x>=1e5) return (x / 1e4).toFixed(1) + "w";
var all = [
{"val": 10e20, "char": "g"},
{"val": 10e16, "char": "j"},
{"val": 10e12, "char": "z"},
{"val": 10e8, "char": "e"},
{"val": 10e4, "char": "w"},
]
for (var i=0;i<all.length;i++) {
var one = all[i];
if (x>=10*one.val) {
var v = x/one.val;
return v.toFixed(Math.max(0, Math.floor(4-Math.log10(v)))) + one.char;
}
}
return x;
}