You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
137 lines
4.2 KiB
137 lines
4.2 KiB
import { Player, Attribute } from '@/config'; |
|
import { deepCopy } from '.'; |
|
|
|
/** |
|
* 计算角色最终属性于技能 |
|
* @param player 角色 |
|
* @param rA 转生属性 |
|
*/ |
|
export const callPlayerAttribute = (player: Player, rA: any) => { |
|
const equips = [player.weapon, player.armor, player.neck, player.ring, player.jewelry, player.pants, player.shoes, player.bracers]; |
|
const curHp = player.attribute.curHp, |
|
hp = player.attribute.hp; |
|
const hpP = hp > 0 ? curHp / hp : 1; |
|
|
|
const attribute: Attribute = new Attribute(rA); |
|
const entry = new Array(); |
|
equips.forEach((equip) => { |
|
equip && Array.prototype.push.apply(entry, equip.extraEntry); |
|
equip && Array.prototype.push.apply(entry, strengthenEntry(equip)); |
|
}); |
|
|
|
entry.forEach((item) => { |
|
const key = item.type; |
|
if (key == 'dmgPercent') { |
|
attribute[key] = Math.round(callDmgPercent(attribute[key], item.value)); |
|
} else if (key == 'dmgReduc') { |
|
attribute[key] = callDmgReduc(attribute[key], item.value); |
|
} else { |
|
attribute[key] += item.value; |
|
} |
|
}); |
|
attribute.dmgReduc = Math.floor(attribute.dmgReduc * 100) / 100; //伤害减免保留两位小数 |
|
attribute.hp = Math.ceil(attribute.hp * (1 + attribute.hpPercent / 100)); |
|
attribute.curHp = Math.ceil(attribute.hp * hpP); |
|
attribute.baseAtk = attribute.atk; |
|
attribute.atk = Math.ceil(attribute.baseAtk * (1 + attribute.atkPercent / 100)); |
|
attribute.def = Math.ceil(attribute.def * (1 + attribute.defPercent / 100)); |
|
attribute.bloc = Math.ceil(attribute.bloc * (1 + attribute.blocPercent / 100)); |
|
const arr = ['hp', 'curHp', 'atk', 'def', 'bloc', 'eva']; |
|
arr.forEach((key) => { |
|
attribute[key] = Math.round(attribute[key]); |
|
}); |
|
//计算秒伤 |
|
const atk = attribute.atk, |
|
crit = (attribute.crit > 100 ? 100 : attribute.crit) / 100, // 暴击率最多100% |
|
critdmg = attribute.critDmg / 100, |
|
dmgPercent = attribute.dmgPercent / 100; |
|
attribute.dps = Math.ceil((1 - crit + crit * critdmg) * atk * (1 + dmgPercent)); |
|
//计算减伤比例 |
|
attribute.reducPercent = callReducPercent(attribute.def, player.lv); |
|
player.attribute = attribute; |
|
}; |
|
|
|
/** |
|
* 计算防御提供的减伤比例 |
|
* @param def 防御 |
|
* @returns 减伤比例 |
|
*/ |
|
export const callReducPercent = (def: number, lv: number): number => { |
|
// return def / (200 + 1.1 * def) + (0.09 * def) / (def + 200); |
|
return def / (300 + 1.05263 * def) + lv * 0.0003; |
|
}; |
|
|
|
/** |
|
* 计算新增伤害减免后的伤害减免 |
|
* @param source 已有伤害减免 |
|
* @param add 新增伤害减免 |
|
* @returns 最终伤害减免 |
|
*/ |
|
export const callDmgReduc = (has, addition) => { |
|
if (has > 100 || addition > 100) { |
|
return 100; |
|
} |
|
return 100 - (100 - has) * (1 - addition / 100); |
|
}; |
|
|
|
/** |
|
* 计算新增伤害加成后的伤害加成 |
|
* @param source 已有伤害加成 |
|
* @param add 新增伤害加成 |
|
* @returns 最终伤害加成 |
|
*/ |
|
export const callDmgPercent = (has, addition) => { |
|
return (100 + has) * (1 + addition / 100) - 100; |
|
}; |
|
|
|
/** |
|
* 计算装备强化后的基础属性 |
|
* @param equip 装备 |
|
* @returns |
|
*/ |
|
const strengthenEntry = (equip) => { |
|
const temp = deepCopy(equip.base.entry); |
|
temp.forEach((item) => { |
|
item.value = strengthenValue(item.value, equip.strengthenLv); |
|
}); |
|
return temp; |
|
}; |
|
|
|
/** |
|
* 计算基础属性强化后的值 |
|
* @param value 基础值 |
|
* @param strengthenLv 强化等级 |
|
* @returns |
|
*/ |
|
export const strengthenValue = (value, strengthenLv) => { |
|
if (strengthenLv <= 0) { |
|
return value; |
|
} |
|
const factor = 1.055 ** (strengthenLv ** 1.1); |
|
return Math.round(factor * value); |
|
}; |
|
|
|
/** |
|
* 计算角色转生可获得的转生点数 |
|
* @param playerAttribute 角色属性 |
|
* @returns |
|
*/ |
|
export const getPointsOfReborn = (playerAttribute) => { |
|
const lv = playerAttribute.lv; |
|
let points = lv >= 20 ? Math.floor((lv - 20) ** 1.1 / 2.1) : 0; |
|
|
|
const euqips = [playerAttribute.weapon, playerAttribute.armor, playerAttribute.neck, playerAttribute.ring]; |
|
euqips.forEach((equip) => { |
|
if (!equip) { |
|
return; |
|
} |
|
const wlv = equip.lv; |
|
const elv = equip.enchantlvl || 0; |
|
const q = equip.quality.qualityCoefficient; |
|
if (wlv >= 20) { |
|
points += Math.floor((((wlv - 20) / 10) ** 1.1 * (0.1 * elv ** 1.5 + 1) * q) / 3.5); |
|
} |
|
}); |
|
|
|
return Math.round(points * 1.2); |
|
};
|
|
|