2022-11-20 20:45:27 +00:00
|
|
|
/**
|
|
|
|
* 面板属性计算
|
|
|
|
* @type {{}}
|
|
|
|
*/
|
|
|
|
|
2022-11-23 20:26:07 +00:00
|
|
|
import { Weapon, ProfileAttr } from '../index.js'
|
|
|
|
import { Format } from '../../components/index.js'
|
2022-11-21 21:26:06 +00:00
|
|
|
import { calc as artisBuffs } from '../../resources/meta/artifact/index.js'
|
|
|
|
import { calc as weaponBuffs } from '../../resources/meta/weapon/index.js'
|
2022-11-20 20:45:27 +00:00
|
|
|
import lodash from 'lodash'
|
|
|
|
|
|
|
|
class AttrCalc {
|
|
|
|
constructor (profile) {
|
|
|
|
this.profile = profile
|
|
|
|
this.char = profile.char
|
|
|
|
}
|
|
|
|
|
2022-11-21 21:26:06 +00:00
|
|
|
/**
|
|
|
|
* 静态调用入口
|
|
|
|
* @param profile
|
2022-11-24 16:31:36 +00:00
|
|
|
* @returns {AttrCalc}
|
2022-11-21 21:26:06 +00:00
|
|
|
*/
|
2022-11-24 16:31:36 +00:00
|
|
|
static create (profile) {
|
|
|
|
return new AttrCalc(profile)
|
2022-11-20 20:45:27 +00:00
|
|
|
}
|
|
|
|
|
2022-11-21 21:26:06 +00:00
|
|
|
/**
|
2022-11-24 16:31:36 +00:00
|
|
|
* 面板属性计算
|
|
|
|
* @returns {{}}
|
2022-11-21 21:26:06 +00:00
|
|
|
*/
|
2022-11-24 16:31:36 +00:00
|
|
|
calc () {
|
|
|
|
this.attr = ProfileAttr.create({
|
2022-11-21 21:26:06 +00:00
|
|
|
recharge: 100,
|
|
|
|
cpct: 5,
|
|
|
|
cdmg: 50
|
|
|
|
})
|
2022-11-24 16:31:36 +00:00
|
|
|
this.setCharAttr()
|
2022-11-20 20:45:27 +00:00
|
|
|
this.setWeaponAttr()
|
|
|
|
this.setArtisAttr()
|
2022-11-22 20:25:36 +00:00
|
|
|
if (process.argv.includes('web-debug')) {
|
2022-11-24 16:31:36 +00:00
|
|
|
// console.log(this.attr, this.attr.getAttr())
|
2022-11-22 20:25:36 +00:00
|
|
|
}
|
|
|
|
return this.attr.getAttr()
|
2022-11-20 20:45:27 +00:00
|
|
|
}
|
|
|
|
|
2022-11-21 21:26:06 +00:00
|
|
|
addAttr (key, val) {
|
|
|
|
this.attr.addAttr(key, val)
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 计算角色属性
|
|
|
|
* @param affix
|
|
|
|
*/
|
2022-11-24 16:31:36 +00:00
|
|
|
setCharAttr (affix = '') {
|
2022-11-22 20:25:36 +00:00
|
|
|
let { char, level, promote } = this.profile
|
2022-11-20 20:45:27 +00:00
|
|
|
let metaAttr = char.detail?.attr || {}
|
2022-11-21 21:26:06 +00:00
|
|
|
let { keys = {}, details = {} } = metaAttr
|
2022-11-20 20:45:27 +00:00
|
|
|
let lvLeft = 0
|
|
|
|
let lvRight = 0
|
2022-11-22 20:25:36 +00:00
|
|
|
let lvStep = [1, 20, 40, 50, 60, 70, 80, 90]
|
|
|
|
let currPromote = 0
|
2022-11-20 20:45:27 +00:00
|
|
|
for (let idx = 0; idx < lvStep.length - 1; idx++) {
|
2022-11-22 20:25:36 +00:00
|
|
|
if (currPromote === promote) {
|
|
|
|
if (level >= lvStep[idx] && level <= lvStep[idx + 1]) {
|
|
|
|
lvLeft = lvStep[idx]
|
|
|
|
lvRight = lvStep[idx + 1]
|
|
|
|
break
|
|
|
|
}
|
2022-11-20 20:45:27 +00:00
|
|
|
}
|
2022-11-22 20:25:36 +00:00
|
|
|
currPromote++
|
2022-11-20 20:45:27 +00:00
|
|
|
}
|
2022-11-21 21:26:06 +00:00
|
|
|
let detailLeft = details[lvLeft + '+'] || details[lvLeft] || {}
|
|
|
|
let detailRight = details[lvRight] || {}
|
2022-11-20 20:45:27 +00:00
|
|
|
|
2022-11-22 20:25:36 +00:00
|
|
|
let getLvData = (idx, step = false) => {
|
2022-11-20 20:45:27 +00:00
|
|
|
let valueLeft = detailLeft[idx]
|
|
|
|
let valueRight = detailRight[idx]
|
2022-11-22 20:25:36 +00:00
|
|
|
if (!step) {
|
|
|
|
return valueLeft * 1 + ((valueRight - valueLeft) * (level - lvLeft) / (lvRight - lvLeft))
|
|
|
|
} else {
|
|
|
|
return valueLeft * 1 + ((valueRight - valueLeft) * Math.floor((level - lvLeft) / 5) / Math.round(((lvRight - lvLeft) / 5)))
|
|
|
|
}
|
2022-11-20 20:45:27 +00:00
|
|
|
}
|
2022-11-21 21:26:06 +00:00
|
|
|
this.addAttr('hpBase', getLvData(0))
|
|
|
|
this.addAttr('atkBase', getLvData(1))
|
|
|
|
this.addAttr('defBase', getLvData(2))
|
2022-11-22 20:25:36 +00:00
|
|
|
this.addAttr(keys[3], getLvData(3, true))
|
|
|
|
|
2022-11-24 16:31:36 +00:00
|
|
|
let charBuffs = char.getCalcRule()
|
2022-11-22 20:25:36 +00:00
|
|
|
lodash.forEach(charBuffs.buffs, (buff) => {
|
|
|
|
if (!buff.isStatic) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
if (buff) {
|
|
|
|
lodash.forEach(buff.data, (val, key) => {
|
|
|
|
this.addAttr(key, val)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
2022-11-20 20:45:27 +00:00
|
|
|
}
|
|
|
|
|
2022-11-21 21:26:06 +00:00
|
|
|
/**
|
|
|
|
* 计算武器属性
|
|
|
|
*/
|
2022-11-20 20:45:27 +00:00
|
|
|
setWeaponAttr () {
|
|
|
|
let wData = this.profile?.weapon
|
|
|
|
let weapon = Weapon.get(wData?.name)
|
|
|
|
let level = wData.level
|
2022-11-22 20:25:36 +00:00
|
|
|
let promote = lodash.isUndefined(wData.promote) ? -1 : wData.promote
|
|
|
|
let lvLeft = 1
|
|
|
|
let lvRight = 20
|
2022-11-20 20:45:27 +00:00
|
|
|
let lvStep = [1, 20, 40, 50, 60, 70, 80, 90]
|
2022-11-22 20:25:36 +00:00
|
|
|
let currPromote = 0
|
2022-11-20 20:45:27 +00:00
|
|
|
for (let idx = 0; idx < lvStep.length - 1; idx++) {
|
2022-11-22 20:25:36 +00:00
|
|
|
if (promote === -1 || (currPromote === promote)) {
|
|
|
|
if (level >= lvStep[idx] && level <= lvStep[idx + 1]) {
|
|
|
|
lvLeft = lvStep[idx]
|
|
|
|
lvRight = lvStep[idx + 1]
|
|
|
|
break
|
|
|
|
}
|
2022-11-20 20:45:27 +00:00
|
|
|
}
|
2022-11-22 20:25:36 +00:00
|
|
|
currPromote++
|
2022-11-20 20:45:27 +00:00
|
|
|
}
|
2022-11-22 20:25:36 +00:00
|
|
|
let wAttr = weapon?.detail?.attr || {}
|
|
|
|
let wAtk = wAttr.atk || {}
|
|
|
|
let valueLeft = wAtk[lvLeft + '+'] || wAtk[lvLeft] || {}
|
|
|
|
let valueRight = wAtk[lvRight] || {}
|
2022-11-21 21:26:06 +00:00
|
|
|
this.addAttr('atkBase', valueLeft * 1 + ((valueRight - valueLeft) * (level - lvLeft) / (lvRight - lvLeft)))
|
2022-11-22 20:25:36 +00:00
|
|
|
let wBonus = wAttr.bonusData || {}
|
2022-11-20 20:45:27 +00:00
|
|
|
valueLeft = wBonus[lvLeft + '+'] || wBonus[lvLeft]
|
|
|
|
valueRight = wBonus[lvRight]
|
2022-11-22 20:25:36 +00:00
|
|
|
let stepCount = Math.ceil((lvRight - lvLeft) / 5)
|
|
|
|
let valueStep = (valueRight - valueLeft) / stepCount
|
|
|
|
let add = valueLeft + (stepCount - Math.ceil((lvRight - level) / 5)) * valueStep
|
2022-11-21 21:26:06 +00:00
|
|
|
this.addAttr(wAttr.bonusKey, add)
|
|
|
|
|
|
|
|
let wBuffs = weaponBuffs[weapon.name] || []
|
|
|
|
if (lodash.isPlainObject(wBuffs)) {
|
|
|
|
wBuffs = [wBuffs]
|
|
|
|
}
|
|
|
|
let affix = wData.affix || 1
|
|
|
|
lodash.forEach(wBuffs, (buff) => {
|
|
|
|
if (!buff.isStatic) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
if (buff) {
|
|
|
|
lodash.forEach(buff.refine, (r, key) => {
|
|
|
|
this.addAttr(key, r[affix - 1] * (buff.buffCount || 1))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
2022-11-20 20:45:27 +00:00
|
|
|
}
|
|
|
|
|
2022-11-21 21:26:06 +00:00
|
|
|
/**
|
|
|
|
* 计算圣遗物属性
|
|
|
|
*/
|
2022-11-20 20:45:27 +00:00
|
|
|
setArtisAttr () {
|
|
|
|
let artis = this.profile?.artis
|
2022-11-21 21:26:06 +00:00
|
|
|
// 计算圣遗物词条
|
2022-11-20 20:45:27 +00:00
|
|
|
artis.forEach((arti) => {
|
2022-11-22 20:25:36 +00:00
|
|
|
this.calcArtisAttr(arti.main, this.char)
|
2022-11-20 20:45:27 +00:00
|
|
|
lodash.forEach(arti.attrs, (ds) => {
|
|
|
|
this.calcArtisAttr(ds)
|
|
|
|
})
|
|
|
|
})
|
2022-11-21 21:26:06 +00:00
|
|
|
// 计算圣遗物静态加成
|
|
|
|
artis.eachArtisSet((set, num) => {
|
|
|
|
let buff = artisBuffs[set.name] && artisBuffs[set.name][num]
|
2022-11-22 20:25:36 +00:00
|
|
|
if (!buff || !buff.isStatic) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
if (buff.elem && !this.char.isElem(buff.elem)) {
|
2022-11-21 21:26:06 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
lodash.forEach(buff.data, (val, key) => {
|
|
|
|
this.addAttr(key, val)
|
|
|
|
})
|
|
|
|
})
|
2022-11-20 20:45:27 +00:00
|
|
|
}
|
|
|
|
|
2022-11-21 21:26:06 +00:00
|
|
|
/**
|
|
|
|
* 计算单条圣遗物词缀
|
|
|
|
* @param ds
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2022-11-22 20:25:36 +00:00
|
|
|
calcArtisAttr (ds, char) {
|
2022-11-23 20:26:07 +00:00
|
|
|
let key = ds.key
|
|
|
|
if (Format.isElem(key) && char.elem === key) {
|
2022-11-20 20:45:27 +00:00
|
|
|
key = 'dmg'
|
2022-11-22 20:25:36 +00:00
|
|
|
}
|
2022-11-20 20:45:27 +00:00
|
|
|
if (!key) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if (['atk', 'hp', 'def'].includes(key)) {
|
|
|
|
key = key + 'Pct'
|
|
|
|
}
|
2022-11-21 21:26:06 +00:00
|
|
|
this.attr.addAttr(key, ds.value * 1)
|
2022-11-20 20:45:27 +00:00
|
|
|
}
|
|
|
|
|
2022-11-22 20:25:36 +00:00
|
|
|
static calcPromote (lv) {
|
|
|
|
if (lv === 20) {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
if (lv === 90) {
|
|
|
|
return 6
|
|
|
|
}
|
|
|
|
let lvs = [1, 20, 40, 50, 60, 70, 80, 90]
|
|
|
|
let promote = 0
|
|
|
|
for (let idx = 0; idx < lvs.length - 1; idx++) {
|
|
|
|
if (lv >= lvs[idx] && lv <= lvs[idx + 1]) {
|
|
|
|
return promote
|
|
|
|
}
|
|
|
|
promote++
|
|
|
|
}
|
2022-11-20 20:45:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default AttrCalc
|