From 4db79dec3fe19edc9600c3256e07295eeb640a2a Mon Sep 17 00:00:00 2001 From: ckcz123 Date: Tue, 4 Dec 2018 18:16:19 +0800 Subject: [PATCH] Equipment percentage for each --- _server/data.comment.js | 14 ---------- docs/element.md | 26 +++++------------- libs/enemys.js | 13 ++++----- libs/items.js | 26 ++++++++++-------- libs/ui.js | 61 +++++++++++++++++++++++------------------ project/data.js | 1 - project/functions.js | 23 ++++++---------- 7 files changed, 70 insertions(+), 94 deletions(-) diff --git a/_server/data.comment.js b/_server/data.comment.js index 300a5fc0..7370b25f 100644 --- a/_server/data.comment.js +++ b/_server/data.comment.js @@ -522,20 +522,6 @@ var data_comment_c456ea59_6018_45ef_8bcc_211a24c627dc = "_bool": "bool", "_data": "状态栏的装备按钮。若此项为true则将状态栏中的楼层转换器按钮换为装备栏按钮" }, - "equipPercentage": { - "_leaf": true, - "_type": "checkbox", - "_bool": "bool", - "_data": "装备增加百分比属性。如果此项为true,则装备属性全部按照百分比进行计算,比如\"atk\": 20意味着攻击增加20%。\n如果多个装备百分比增加同一个属性的,按加算处理。(即一个10%一个20%总共是30%而不是32%)" - }, - /* - "enableDeleteItem": { - "_leaf": true, - "_type": "checkbox", - "_bool": "bool", - "_data": "是否允许删除(丢弃)道具" - }, - */ "enableAddPoint": { "_leaf": true, "_type": "checkbox", diff --git a/docs/element.md b/docs/element.md index 254f8ad9..5a7189a3 100644 --- a/docs/element.md +++ b/docs/element.md @@ -47,8 +47,9 @@ 如果要将一个道具设置为装备,首先需要将其`cls`设为`equips`。 然后在图块属性的`equip`一项中设置装备的具体属性。该项写法如下: + ``` js -{"type": 0, "atk": 0, "def": 0, "mdef":0, "animate": "hand"} +{"type": 0, "atk": 0, "def": 0, "mdef":0, "animate": "hand", "percentage": true} ``` type为该装备的类型,必填,和上面装备栏一一对应。例如,0就是武器,2就是首饰等等。 @@ -57,35 +58,22 @@ atk/def/mdef为该装备分别增加的攻防魔防数值(支持负数); animate为该装备的攻击动画,仅对type为0时有效。具体可参见[动画和天气系统](#动画和天气系统)。 +percentage为该装备是否按比例增加属性。 + 下面是几个写法例子。 ``` js {"type": 0, "atk": 10} // 装备类型是武器,效果是攻击+10,使用默认的攻击动画 {"type": 0, "atk": 40, "animate": "sword"} // 装备类型为武器,效果是攻击+10,攻击动画是sword -{"type": 1, "def": 40} // 装备类型是防具,效果是防御+40 +{"type": 1, "def": 40, "percentage": true} // 装备类型是防具,效果是防御提升40% {"type": 1, "def": 100, "mdef": 100} // 装备类型是防具,效果是防御和魔防各+100 {"type": 3, "atk": -20, "def": 50, "mdef": 50} // 装备类型是魔杖,效果是攻击-20,防御和魔防各+50 -``` - -### 装备按比例增加属性 - -从V2.4.2开始,装备可以选择按照比例来增加属性。 - -在全塔属性中有个`equipPercentage`开关,如果将其打开,则会所有值都按照比例计算。(也就是类似Buff一样) - -例如,上面的例子就变成了: - -``` js -{"type": 0, "atk": 10} // 装备类型是武器,效果是攻击提升10%,使用默认的攻击动画 -{"type": 0, "atk": 40, "animate": "sword"} // 装备类型为武器,效果是攻击提升40%,攻击动画是sword -{"type": 1, "def": 40} // 装备类型是防具,效果是防御提升40% -{"type": 1, "def": 100, "mdef": 100} // 装备类型是防具,效果是防御和魔防各提升100% -{"type": 3, "atk": -20, "def": 50, "mdef": 50} // 装备类型是魔杖,效果是攻击下降20%,防御和魔防各提升50% +{"type": 2, "atk": -20, "def": 50, "mdef": 50, "percentage": true} // 装备类型是魔杖,效果是攻击下降20%,防御和魔防各提升50% ``` 所有取值全部向下取整。 -值得注意的是:多装备增加同一属性使用加法计算;也就是比如武器增加30%攻击,防具增加10%攻击,最终合起来增加的是40%而不是43%的属性。 +值得注意的是,如果多个装备同时按比例增加属性,使用加法计算。比如武器增加30%攻击,防具增加10%攻击,最终合起来增加的是40%而不是43%的属性。 ### 检测是否存在装备 diff --git a/libs/enemys.js b/libs/enemys.js index c6dd1311..a3097af3 100644 --- a/libs/enemys.js +++ b/libs/enemys.js @@ -164,9 +164,7 @@ enemys.prototype.nextCriticals = function (enemy, number, x, y, floorId) { for (var t = turn-1;t>=1;t--) { var nextAtk = Math.ceil(mon_hp/t) + mon_def; // 装备提升比例的计算临界 - if (core.flags.equipPercentage) { - nextAtk = Math.ceil(nextAtk / core.getFlag('equip_atk_buff', 1)); - } + nextAtk = Math.ceil(nextAtk / core.getFlag('equip_atk_buff', 1)); if (nextAtk<=hero_atk) break; if (nextAtk!=pre) { var nextInfo = this.getDamageInfo(enemy, core.status.hero.hp, nextAtk, core.status.hero.def, core.status.hero.mdef, x, y, floorId); @@ -257,11 +255,10 @@ enemys.prototype.getCurrentEnemys = function (floorId) { var mon_hp = enemy.hp, mon_atk = enemy.atk, mon_def = enemy.def; var hero_atk = core.status.hero.atk, hero_def = core.status.hero.def, hero_mdef = core.status.hero.mdef; - if (core.flags.equipPercentage) { - hero_atk = Math.floor(core.getFlag('equip_atk_buff',1)*hero_atk); - hero_def = Math.floor(core.getFlag('equip_def_buff',1)*hero_def); - hero_mdef = Math.floor(core.getFlag('equip_mdef_buff',1)*hero_mdef); - } + hero_atk = Math.floor(core.getFlag('equip_atk_buff',1)*hero_atk); + hero_def = Math.floor(core.getFlag('equip_def_buff',1)*hero_def); + hero_mdef = Math.floor(core.getFlag('equip_mdef_buff',1)*hero_mdef); + var enemyInfo = this.getEnemyInfo(enemy, core.status.hero.hp, hero_atk, hero_def, hero_mdef, null, null, floorId); var specialText = core.enemys.getSpecialText(enemyId); diff --git a/libs/items.js b/libs/items.js index 1453b562..fcba3daa 100644 --- a/libs/items.js +++ b/libs/items.js @@ -199,8 +199,8 @@ items.prototype.loadEquip = function (equipId, callback) { if (!core.isset(core.status.hero.equipment)) core.status.hero.equipment = []; - var loadEquip = core.material.items[equipId]; - if (!core.isset(loadEquip)) { + var loadEquip = core.material.items[equipId]||{}; + if (!core.isset(loadEquip.equip)) { if (core.isset(callback)) callback(); return; } @@ -223,11 +223,21 @@ items.prototype.loadEquip = function (equipId, callback) { var loadEquipType = loadEquip.equip.type; var unloadEquipId = core.status.hero.equipment[loadEquipType]; + var unloadEquip = core.material.items[unloadEquipId] || {}; + + // ------ 如果当前装备和目标装备的模式不同(一个百分比一个数值),则需要先脱再穿 ------ // + if (core.isset(unloadEquip.equip) && (unloadEquip.equip.percentage||false) != (loadEquip.equip.percentage||false)) { + this.unloadEquip(loadEquipType); + this.loadEquip(equipId); + if (core.isset(callback)) callback(); + return; + } + // 下面保证了两者的模式是相同的 // 比较能力值 var result = core.compareEquipment(equipId,unloadEquipId); - if (core.flags.equipPercentage) { + if (loadEquip.equip.percentage) { core.setFlag('equip_atk_buff', core.getFlag('equip_atk_buff',1)+result.atk/100); core.setFlag('equip_def_buff', core.getFlag('equip_def_buff',1)+result.def/100); core.setFlag('equip_mdef_buff', core.getFlag('equip_mdef_buff',1)+result.mdef/100); @@ -242,9 +252,6 @@ items.prototype.loadEquip = function (equipId, callback) { core.status.hero.equipment[loadEquipType] = equipId; core.updateStatusBar(); - // 记录路线 - // core.status.route.push("equip:"+equipId); - // 装备更换完毕:删除换上的装备 core.removeItem(equipId); @@ -269,10 +276,10 @@ items.prototype.unloadEquip = function (equipType, callback) { if (core.isset(callback)) callback(); return; } - var unloadEquip = core.material.items[unloadEquipId]; + var unloadEquip = core.material.items[unloadEquipId] || {}; // 处理能力值改变 - if (core.flags.equipPercentage) { + if (unloadEquip.equip.percentage) { core.setFlag('equip_atk_buff', core.getFlag('equip_atk_buff',1)-(unloadEquip.equip.atk||0)/100); core.setFlag('equip_def_buff', core.getFlag('equip_def_buff',1)-(unloadEquip.equip.def||0)/100); core.setFlag('equip_mdef_buff', core.getFlag('equip_mdef_buff',1)-(unloadEquip.equip.mdef||0)/100); @@ -287,9 +294,6 @@ items.prototype.unloadEquip = function (equipType, callback) { core.status.hero.equipment[equipType] = null; core.updateStatusBar(); - - // 记录路线 - // core.status.route.push("unEquip:"+equipType); // 装备更换完毕:增加卸下的装备 core.addItem(unloadEquipId, 1); diff --git a/libs/ui.js b/libs/ui.js index 635d0221..c6067779 100644 --- a/libs/ui.js +++ b/libs/ui.js @@ -966,11 +966,9 @@ ui.prototype.drawBattleAnimate = function(monsterId, callback) { hero_def=Math.max(0, hero_def); hero_mdef=Math.max(0, hero_mdef); - if (core.flags.equipPercentage) { - hero_atk = Math.floor(core.getFlag('equip_atk_buff',1)*hero_atk); - hero_def = Math.floor(core.getFlag('equip_def_buff',1)*hero_def); - hero_mdef = Math.floor(core.getFlag('equip_mdef_buff',1)*hero_mdef); - } + hero_atk = Math.floor(core.getFlag('equip_atk_buff',1)*hero_atk); + hero_def = Math.floor(core.getFlag('equip_def_buff',1)*hero_def); + hero_mdef = Math.floor(core.getFlag('equip_mdef_buff',1)*hero_mdef); var enemy = core.material.enemys[monsterId]; var enemyInfo = core.enemys.getEnemyInfo(enemy, hero_hp, hero_atk, hero_def, hero_mdef); @@ -2034,30 +2032,41 @@ ui.prototype.drawEquipbox = function(index) { // 比较属性 if (lines.length==1) { - var compare; + var compare, differentMode = false; if (index<12) compare = core.compareEquipment(null, selectId); else { - compare = core.compareEquipment(selectId, equipEquipment[equip.equip.type]); - } - var drawOffset = 10; - - [['攻击','atk'], ['防御','def'], ['魔防','mdef']].forEach(function (t) { - var title = t[0], name = t[1]; - if (!core.isset(compare[name]) || compare[name]==0) return; - var color = '#00FF00'; - if (compare[name]<0) color = '#FF0000'; - var nowValue = core.getStatus(name), newValue = nowValue + compare[name]; - if (core.flags.equipPercentage) { - var nowBuff = core.getFlag('equip_'+name+"_buff",1), newBuff = nowBuff+compare[name]/100; - nowValue = Math.floor(nowBuff*core.getStatus(name)); - newValue = Math.floor(newBuff*core.getStatus(name)); + var last = core.material.items[equipEquipment[equipType]]||{}; + // 检查是不是数值模式和比例模式之间的切换 + if (core.isset(last.equip) && (last.equip.percentage||false) != (equip.equip.percentage||false)) { + differentMode = true; } - var content = title + ' ' + nowValue + '->'; - core.fillText('ui', content, drawOffset, 89, '#CCCCCC', 'bold 14px '+globalFont); - drawOffset += core.canvas.ui.measureText(content).width; - core.fillText('ui', newValue, drawOffset, 89, color); - drawOffset += core.canvas.ui.measureText(newValue).width + 15; - }) + else { + compare = core.compareEquipment(selectId, equipEquipment[equipType]); + } + } + if (differentMode) { + core.fillText('ui', '<数值和比例模式之间的切换不显示属性变化>', 10, 89, '#CCCCCC', '14px '+globalFont); + } + else { + var drawOffset = 10; + [['攻击','atk'], ['防御','def'], ['魔防','mdef']].forEach(function (t) { + var title = t[0], name = t[1]; + if (!core.isset(compare[name]) || compare[name]==0) return; + var color = '#00FF00'; + if (compare[name]<0) color = '#FF0000'; + var nowValue = core.getStatus(name), newValue = nowValue + compare[name]; + if (equip.equip.percentage) { + var nowBuff = core.getFlag('equip_'+name+"_buff",1), newBuff = nowBuff+compare[name]/100; + nowValue = Math.floor(nowBuff*core.getStatus(name)); + newValue = Math.floor(newBuff*core.getStatus(name)); + } + var content = title + ' ' + nowValue + '->'; + core.fillText('ui', content, drawOffset, 89, '#CCCCCC', 'bold 14px '+globalFont); + drawOffset += core.canvas.ui.measureText(content).width; + core.fillText('ui', newValue, drawOffset, 89, color); + drawOffset += core.canvas.ui.measureText(newValue).width + 15; + }) + } } else { var leftText = text.substring(lines[0].length); diff --git a/project/data.js b/project/data.js index 9b4ac12e..41c36ba7 100644 --- a/project/data.js +++ b/project/data.js @@ -362,7 +362,6 @@ var data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d = "bigKeyIsBox": false, "equipment": false, "equipboxButton": false, - "equipPercentage": false, "enableAddPoint": false, "enableNegativeDamage": false, "hatredDecrease": true, diff --git a/project/functions.js b/project/functions.js index ef3be11d..62ad87d6 100644 --- a/project/functions.js +++ b/project/functions.js @@ -484,12 +484,10 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = hero_def=Math.max(0, hero_def); hero_mdef=Math.max(0, hero_mdef); - // 装备按比例增加属性 - if (core.flags.equipPercentage) { - hero_atk = Math.floor(core.getFlag('equip_atk_buff',1)*hero_atk); - hero_def = Math.floor(core.getFlag('equip_def_buff',1)*hero_def); - hero_mdef = Math.floor(core.getFlag('equip_mdef_buff',1)*hero_mdef); - } + // 计算装备按比例增加属性后的数值 + hero_atk = Math.floor(core.getFlag('equip_atk_buff',1)*hero_atk); + hero_def = Math.floor(core.getFlag('equip_def_buff',1)*hero_def); + hero_mdef = Math.floor(core.getFlag('equip_mdef_buff',1)*hero_mdef); // 怪物的各项数据 // 对坚固模仿等处理扔到了脚本编辑-getEnemyInfo之中 @@ -809,16 +807,11 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = // 向下取整 if (core.isset(core.status.hero[item])) core.status.hero[item] = Math.floor(core.status.hero[item]); - // 大数据格式化 - core.statusBar[item].innerHTML = core.formatBigNumber(core.getStatus(item)); + // 装备按比例增加属性 + var value = Math.floor(core.getStatus(item)*core.getFlag('equip_'+item+'_buff',1)); + // 大数据格式化; + core.statusBar[item].innerHTML = core.formatBigNumber(value); }); - - // 装备按比例增加属性 - if (core.flags.equipPercentage) { - core.statusBar.atk.innerHTML = core.formatBigNumber(Math.floor(core.getFlag('equip_atk_buff',1)*core.getStatus('atk'))); - core.statusBar.def.innerHTML = core.formatBigNumber(Math.floor(core.getFlag('equip_def_buff',1)*core.getStatus('def'))); - core.statusBar.mdef.innerHTML = core.formatBigNumber(Math.floor(core.getFlag('equip_mdef_buff',1)*core.getStatus('mdef'))); - } // 设置魔力值 if (core.flags.enableMana) {