|
| 1 | +```js |
| 2 | +function (enemy, hero, x, y, floorId) { |
| 3 | + // 获得战斗伤害信息(实际伤害计算函数) |
| 4 | + // |
| 5 | + // 参数说明: |
| 6 | + // enemy:该怪物信息 |
| 7 | + // hero:勇士的当前数据;如果对应项不存在则会从core.status.hero中取。 |
| 8 | + // x,y:该怪物的坐标(查看手册和强制战斗时为undefined) |
| 9 | + // floorId:该怪物所在的楼层 |
| 10 | + // 后面三个参数主要是可以在光环等效果上可以适用 |
| 11 | + floorId = floorId || core.status.floorId; |
| 12 | + |
| 13 | + var hero_hp = core.getRealStatusOrDefault(hero, 'hp'), |
| 14 | + hero_atk = core.getRealStatusOrDefault(hero, 'atk'), |
| 15 | + hero_def = core.getRealStatusOrDefault(hero, 'def'), |
| 16 | + hero_mdef = core.getRealStatusOrDefault(hero, 'mdef'), |
| 17 | + origin_hero_hp = core.getStatusOrDefault(hero, 'hp'), |
| 18 | + origin_hero_atk = core.getStatusOrDefault(hero, 'atk'), |
| 19 | + origin_hero_def = core.getStatusOrDefault(hero, 'def'); |
| 20 | + |
| 21 | + // 勇士的负属性都按0计算 |
| 22 | + hero_hp = Math.max(0, hero_hp); |
| 23 | + hero_atk = Math.max(0, hero_atk); |
| 24 | + hero_def = Math.max(0, hero_def); |
| 25 | + hero_mdef = Math.max(0, hero_mdef); |
| 26 | + |
| 27 | + // 怪物的各项数据 |
| 28 | + // 对坚固模仿等处理扔到了脚本编辑-getEnemyInfo之中 |
| 29 | + var enemyInfo = core.enemys.getEnemyInfo(enemy, hero, x, y, floorId); |
| 30 | + var mon_hp = enemyInfo.hp, |
| 31 | + mon_atk = enemyInfo.atk, |
| 32 | + mon_def = enemyInfo.def, |
| 33 | + mon_special = enemyInfo.special; |
| 34 | + |
| 35 | + // 混乱(编号39):战斗中,勇士攻防互换。 |
| 36 | + if (core.hasSpecial(mon_special, 39)) { |
| 37 | + var temp = hero_atk; |
| 38 | + hero_atk = hero_def; |
| 39 | + hero_def = temp; |
| 40 | + } |
| 41 | + |
| 42 | + // 残暴斩杀(编号35):战斗开始时,如果角色血量不大于怪物血量的200%,则直接暴毙。 |
| 43 | + if (core.hasSpecial(mon_special, 35) && hero_hp < mon_hp * 2) { |
| 44 | + return null; |
| 45 | + } |
| 46 | + |
| 47 | + // 窥血为攻(编号36):战斗开始时,自身攻击力变为角色当前生命值的10%,向下取整。 |
| 48 | + if (core.hasSpecial(mon_special, 36)) { |
| 49 | + mon_atk = Math.floor(hero_hp / 10); |
| 50 | + } |
| 51 | + |
| 52 | + // 技能3:角色攻击在战斗时减少`flag:x3`,防御力增加`flag:x3`。 |
| 53 | + if (core.getFlag('skill', 0) == 3) { |
| 54 | + // 注意这里直接改变的面板攻击力(经过装备增幅后的)而不是基础攻击力。 |
| 55 | + hero_atk -= core.getFlag('x3', 0); |
| 56 | + hero_def += core.getFlag('x3', 0); |
| 57 | + } |
| 58 | + |
| 59 | + // 技能4:角色无视怪物的`flag:x4`%的防御力。(如,`flag:x4`是10时,无视怪物的10%防御力) |
| 60 | + if (core.getFlag('skill', 0) == 4) { |
| 61 | + mon_def -= Math.floor(core.getFlag('x4', 0) / 100); |
| 62 | + } |
| 63 | + |
| 64 | + // 如果是无敌属性,且勇士未持有十字架 |
| 65 | + if (core.hasSpecial(mon_special, 20) && !core.hasItem("cross")) |
| 66 | + return null; // 不可战斗 |
| 67 | + |
| 68 | + // 战前造成的额外伤害(可被护盾抵消) |
| 69 | + var init_damage = 0; |
| 70 | + |
| 71 | + // 吸血 |
| 72 | + if (core.hasSpecial(mon_special, 11)) { |
| 73 | + var vampire_damage = hero_hp * enemy.value; |
| 74 | + |
| 75 | + // 如果有神圣盾免疫吸血等可以在这里写 |
| 76 | + // 也可以用hasItem和hasEquip来判定装备 |
| 77 | + // if (core.hasFlag('shield5')) vampire_damage = 0; |
| 78 | + |
| 79 | + vampire_damage = Math.floor(vampire_damage) || 0; |
| 80 | + // 加到自身 |
| 81 | + if (enemy.add) // 如果加到自身 |
| 82 | + mon_hp += vampire_damage; |
| 83 | + |
| 84 | + init_damage += vampire_damage; |
| 85 | + } |
| 86 | + |
| 87 | + // 每回合怪物对勇士造成的战斗伤害 |
| 88 | + var per_damage = mon_atk - hero_def; |
| 89 | + // 魔攻:战斗伤害就是怪物攻击力 |
| 90 | + if (core.hasSpecial(mon_special, 2)) per_damage = mon_atk; |
| 91 | + // 穿刺(编号32):无视角色70%防御力。 |
| 92 | + if (core.hasSpecial(mon_special, 32)) per_damage = Math.floor(mon_atk - 0.3 * hero_def); |
| 93 | + // 战斗伤害不能为负值 |
| 94 | + if (per_damage < 0) per_damage = 0; |
| 95 | + |
| 96 | + // 中子束(编号34):每回合普攻两次,魔攻一次。 |
| 97 | + if (core.hasSpecial(mon_special, 34)) { |
| 98 | + per_damage *= 2; |
| 99 | + per_damage += mon_atk; |
| 100 | + } |
| 101 | + |
| 102 | + // 崩甲(编号38):怪物每回合附加勇士战斗开始时的护盾数值的0.1倍作为伤害。 |
| 103 | + if (core.hasSpecial(mon_special, 38)) { |
| 104 | + per_damage += Math.floor(hero_mdef * 0.1); |
| 105 | + } |
| 106 | + |
| 107 | + // 2连击 & 3连击 & N连击 |
| 108 | + if (core.hasSpecial(mon_special, 4)) per_damage *= 2; |
| 109 | + if (core.hasSpecial(mon_special, 5)) per_damage *= 3; |
| 110 | + if (core.hasSpecial(mon_special, 6)) per_damage *= (enemy.n || 4); |
| 111 | + |
| 112 | + // 每回合的反击伤害;反击是按照勇士的攻击次数来计算回合 |
| 113 | + var counterDamage = 0; |
| 114 | + if (core.hasSpecial(mon_special, 8)) |
| 115 | + counterDamage += Math.floor((enemy.atkValue || core.values.counterAttack) * hero_atk); |
| 116 | + |
| 117 | + // 先攻 |
| 118 | + if (core.hasSpecial(mon_special, 1)) init_damage += per_damage; |
| 119 | + |
| 120 | + // 破甲 |
| 121 | + if (core.hasSpecial(mon_special, 7)) |
| 122 | + init_damage += Math.floor((enemy.defValue || core.values.breakArmor) * hero_def); |
| 123 | + |
| 124 | + // 净化 |
| 125 | + if (core.hasSpecial(mon_special, 9)) |
| 126 | + init_damage += Math.floor((enemy.n || core.values.purify) * hero_mdef); |
| 127 | + |
| 128 | + // 冰冻(编号33):怪物首先冰冻角色3回合,冰冻期间每回合额外造成角色护盾的20%伤害。 |
| 129 | + if (core.hasSpecial(mon_special, 33)) { |
| 130 | + init_damage += Math.floor(3 * (per_damage + 0.2 * hero_mdef)); |
| 131 | + } |
| 132 | + |
| 133 | + // 勇士每回合对怪物造成的伤害 |
| 134 | + var hero_per_damage = Math.max(hero_atk - mon_def, 0); |
| 135 | + |
| 136 | + // 技能2:角色每回合造成和受到的伤害均提升`flag:x2`%。(如,`flag:x2`为10时,每回合造成和受到伤害都提升10%) |
| 137 | + if (core.getFlag("skill", 0) == 2) { |
| 138 | + per_damage += Math.floor(per_damage * core.getFlag('x2', 0) / 100); |
| 139 | + hero_per_damage += Math.floor(hero_per_damage * core.getFlag('x2', 0) / 100); |
| 140 | + } |
| 141 | + |
| 142 | + // 闪避(编号31):受到伤害降低40%。 |
| 143 | + if (core.hasSpecial(mon_special, 31)) { |
| 144 | + hero_per_damage = Math.floor(hero_per_damage * 0.6); |
| 145 | + } |
| 146 | + |
| 147 | + // 如果没有破防,则不可战斗 |
| 148 | + if (hero_per_damage <= 0) return null; |
| 149 | + |
| 150 | + // 技能5:角色额外抢攻`flag:x5`回合。 |
| 151 | + if (core.getFlag("skill", 0) == 5) { |
| 152 | + mon_hp -= core.getFlag('x5', 0) * hero_per_damage; |
| 153 | + // 判定是否已经秒杀 -> 注意mon_hp不能小于等于0否则回合计算会出问题 |
| 154 | + if (mon_hp <= 0) mon_hp = 1; |
| 155 | + } |
| 156 | + |
| 157 | + // 暗影庇护(编号41):处于无敌状态,但每回合损耗自身2%的最大生命值。 |
| 158 | + if (core.hasSpecial(mon_special, 41)) { |
| 159 | + hero_per_damage = Math.floor(mon_hp * 0.02); |
| 160 | + } |
| 161 | + |
| 162 | + // 强击(编号40):怪物第一回合三倍攻击。 |
| 163 | + // 注意:需要判定角色是否秒杀怪物 |
| 164 | + if (core.hasSpecial(mon_special, 40) && hero_per_damage < mon_hp) { |
| 165 | + init_damage += 2 * mon_atk; |
| 166 | + } |
| 167 | + |
| 168 | + |
| 169 | + // 勇士的攻击回合数;为怪物生命除以每回合伤害向上取整 |
| 170 | + var turn = Math.ceil(mon_hp / hero_per_damage); |
| 171 | + |
| 172 | + // ------ 支援 ----- // |
| 173 | + // 这个递归最好想明白为什么,flag:__extraTurn__是怎么用的 |
| 174 | + var guards = core.getFlag("__guards__" + x + "_" + y, enemyInfo.guards); |
| 175 | + var guard_before_current_enemy = false; // ------ 支援怪是先打(true)还是后打(false)? |
| 176 | + turn += core.getFlag("__extraTurn__", 0); |
| 177 | + if (guards.length > 0) { |
| 178 | + if (!guard_before_current_enemy) { // --- 先打当前怪物,记录当前回合数 |
| 179 | + core.setFlag("__extraTurn__", turn); |
| 180 | + } |
| 181 | + // 获得那些怪物组成小队战斗 |
| 182 | + for (var i = 0; i < guards.length; i++) { |
| 183 | + var gx = guards[i][0], |
| 184 | + gy = guards[i][1], |
| 185 | + gid = guards[i][2]; |
| 186 | + // 递归计算支援怪伤害信息,这里不传x,y保证不会重复调用 |
| 187 | + // 这里的mdef传0,因为护盾应该只会被计算一次 |
| 188 | + var info = core.enemys.getDamageInfo(core.material.enemys[gid], { hp: origin_hero_hp, atk: origin_hero_atk, def: origin_hero_def, mdef: 0 }); |
| 189 | + if (info == null) { // 小队中任何一个怪物不可战斗,直接返回null |
| 190 | + core.removeFlag("__extraTurn__"); |
| 191 | + return null; |
| 192 | + } |
| 193 | + // 已经进行的回合数 |
| 194 | + core.setFlag("__extraTurn__", info.turn); |
| 195 | + init_damage += info.damage; |
| 196 | + } |
| 197 | + if (guard_before_current_enemy) { // --- 先打支援怪物,增加当前回合数 |
| 198 | + turn += core.getFlag("__extraTurn__", 0); |
| 199 | + } |
| 200 | + } |
| 201 | + core.removeFlag("__extraTurn__"); |
| 202 | + // ------ 支援END ------ // |
| 203 | + |
| 204 | + // 最终伤害:初始伤害 + 怪物对勇士造成的伤害 + 反击伤害 |
| 205 | + var damage = init_damage + (turn - 1) * per_damage + turn * counterDamage; |
| 206 | + // 再扣去护盾 |
| 207 | + damage -= hero_mdef; |
| 208 | + |
| 209 | + // 匙之力(编号37):角色身上每存在一把黄钥匙,最终伤害提升5%;蓝钥匙视为三把黄钥匙,红钥匙视为九把黄钥匙,线性叠加。 |
| 210 | + // 需要判定是否负伤 |
| 211 | + if (core.hasSpecial(mon_special, 37) && damage > 0) { |
| 212 | + var cnt = core.itemCount("yellowKey") + 3 * core.itemCount("blueKey") + 9 * core.itemCount("redKey"); |
| 213 | + damage += Math.floor(damage * 0.05 * cnt); |
| 214 | + } |
| 215 | + |
| 216 | + // 检查是否允许负伤 |
| 217 | + if (!core.flags.enableNegativeDamage) |
| 218 | + damage = Math.max(0, damage); |
| 219 | + |
| 220 | + // 最后处理仇恨和固伤(因为这两个不能被护盾减伤) |
| 221 | + if (core.hasSpecial(mon_special, 17)) { // 仇恨 |
| 222 | + damage += core.getFlag('hatred', 0); |
| 223 | + } |
| 224 | + if (core.hasSpecial(mon_special, 22)) { // 固伤 |
| 225 | + damage += enemy.damage || 0; |
| 226 | + } |
| 227 | + |
| 228 | + // 技能1:角色每回合回复`flag:x1`%倍护盾的生命值。(如,`flag:x1`是10时,每回合回复10%护盾值的生命) |
| 229 | + if (core.getFlag("skill", 0) == 1) { |
| 230 | + damage -= Math.floor(core.getFlag('x1', 0) / 100 * hero_mdef * turn); |
| 231 | + } |
| 232 | + |
| 233 | + return { |
| 234 | + "mon_hp": Math.floor(mon_hp), |
| 235 | + "mon_atk": Math.floor(mon_atk), |
| 236 | + "mon_def": Math.floor(mon_def), |
| 237 | + "init_damage": Math.floor(init_damage), |
| 238 | + "per_damage": Math.floor(per_damage), |
| 239 | + "hero_per_damage": Math.floor(hero_per_damage), |
| 240 | + "turn": Math.floor(turn), |
| 241 | + "damage": Math.floor(damage) |
| 242 | + }; |
| 243 | +} |
| 244 | +``` |
0 commit comments