2022-08-18 10:13:42 +00:00
|
|
|
import lodash from 'lodash'
|
|
|
|
import { Format } from '../../components/index.js'
|
2022-11-24 08:25:04 +00:00
|
|
|
import { attrNameMap, mainAttr, subAttr, attrMap } from '../../resources/meta/artifact/index.js'
|
2022-08-18 10:13:42 +00:00
|
|
|
|
|
|
|
let ArtisMark = {
|
2022-11-23 20:26:07 +00:00
|
|
|
// 根据Key获取标题
|
|
|
|
getKeyByTitle (title, dmg = false) {
|
2023-02-09 18:54:51 +00:00
|
|
|
if (/元素伤害加成/.test(title) || Format.isElem(title)) {
|
2022-11-24 15:27:03 +00:00
|
|
|
let elem = Format.matchElem(title)
|
2022-11-23 20:26:07 +00:00
|
|
|
return dmg ? 'dmg' : elem
|
|
|
|
} else if (title === '物理伤害加成') {
|
|
|
|
return 'phy'
|
|
|
|
}
|
|
|
|
return attrNameMap[title]
|
|
|
|
},
|
|
|
|
|
|
|
|
// 根据标题获取Key
|
|
|
|
getTitleByKey (key) {
|
|
|
|
// 检查是否是伤害字段
|
|
|
|
let dmg = Format.elemName(key, '')
|
|
|
|
if (dmg) {
|
|
|
|
return `${dmg}伤加成`
|
|
|
|
}
|
|
|
|
return attrMap[key].title
|
|
|
|
},
|
|
|
|
|
|
|
|
getKeyTitleMap () {
|
|
|
|
let ret = {}
|
|
|
|
lodash.forEach(attrMap, (ds, key) => {
|
|
|
|
ret[key] = ds.title
|
|
|
|
})
|
2022-11-24 15:27:03 +00:00
|
|
|
Format.eachElem((key, name) => {
|
2022-11-23 20:26:07 +00:00
|
|
|
ret[key] = `${name}伤加成`
|
|
|
|
})
|
|
|
|
return ret
|
|
|
|
},
|
|
|
|
|
2022-08-18 10:13:42 +00:00
|
|
|
formatAttr (ds) {
|
|
|
|
if (!ds) {
|
|
|
|
return {}
|
|
|
|
}
|
|
|
|
if (lodash.isArray(ds) && ds[0] && ds[1]) {
|
|
|
|
return {
|
2022-11-23 20:26:07 +00:00
|
|
|
key: ArtisMark.getKeyByTitle(ds[0]),
|
2022-08-18 10:13:42 +00:00
|
|
|
value: ds[1]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!ds.value) {
|
|
|
|
return {}
|
|
|
|
}
|
|
|
|
return {
|
2022-11-23 20:26:07 +00:00
|
|
|
key: ds.key || ArtisMark.getKeyByTitle(ds.title || ds.name || ds.key || ds.id || ''),
|
2022-08-18 10:13:42 +00:00
|
|
|
value: ds.value || ''
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2022-11-14 12:52:16 +00:00
|
|
|
/**
|
|
|
|
* 格式化圣遗物词条
|
|
|
|
* @param ds
|
|
|
|
* @param markCfg
|
|
|
|
* @param isMain
|
|
|
|
* @returns {{title: *, value: string}|*[]}
|
|
|
|
*/
|
2022-11-23 20:26:07 +00:00
|
|
|
formatArti (ds, charAttrCfg = false, isMain = false, elem = '') {
|
|
|
|
// 若为attr数组
|
|
|
|
if (ds[0] && (ds[0].title || ds[0].key)) {
|
2022-08-18 10:13:42 +00:00
|
|
|
let ret = []
|
2022-11-14 17:10:52 +00:00
|
|
|
let totalUpNum = 0
|
|
|
|
let ltArr = []
|
2023-02-11 19:51:50 +00:00
|
|
|
let isIdAttr = false
|
|
|
|
|
2022-08-18 10:13:42 +00:00
|
|
|
lodash.forEach(ds, (d) => {
|
2023-02-21 19:49:49 +00:00
|
|
|
isIdAttr = !d.isCalcNum
|
2022-11-23 20:26:07 +00:00
|
|
|
let arti = ArtisMark.formatArti(d, charAttrCfg)
|
2023-02-11 19:51:50 +00:00
|
|
|
ret.push(arti)
|
|
|
|
if (isIdAttr) {
|
|
|
|
return true
|
|
|
|
}
|
2022-11-14 17:10:52 +00:00
|
|
|
totalUpNum += arti.upNum
|
|
|
|
if (arti.hasLt) {
|
|
|
|
ltArr.push(arti)
|
|
|
|
}
|
|
|
|
delete arti.hasLt
|
|
|
|
delete arti.hasGt
|
2022-08-18 10:13:42 +00:00
|
|
|
})
|
2023-02-11 19:51:50 +00:00
|
|
|
if (!isIdAttr) {
|
|
|
|
ltArr = lodash.sortBy(ltArr, 'upNum').reverse()
|
|
|
|
for (let arti of ltArr) {
|
|
|
|
if (totalUpNum > 9) {
|
|
|
|
arti.upNum = arti.upNum - 1
|
|
|
|
totalUpNum--
|
|
|
|
} else {
|
|
|
|
break
|
|
|
|
}
|
2022-11-14 17:10:52 +00:00
|
|
|
}
|
|
|
|
}
|
2022-08-18 10:13:42 +00:00
|
|
|
return ret
|
|
|
|
}
|
2022-11-23 20:26:07 +00:00
|
|
|
|
|
|
|
let key = ds.key
|
2022-08-18 10:13:42 +00:00
|
|
|
let title = ds.title || ds[0]
|
2022-11-23 20:26:07 +00:00
|
|
|
if (!key) {
|
|
|
|
key = ArtisMark.getKeyByTitle(title)
|
|
|
|
} else if (!title) {
|
|
|
|
title = ArtisMark.getTitleByKey(key)
|
|
|
|
}
|
|
|
|
let isDmg = Format.isElem(key)
|
2022-08-18 10:13:42 +00:00
|
|
|
let val = ds.value || ds[1]
|
2022-11-14 12:52:16 +00:00
|
|
|
let value = val
|
2022-08-18 10:13:42 +00:00
|
|
|
let num = ds.value || ds[1]
|
2022-11-23 20:26:07 +00:00
|
|
|
if (!key || key === 'undefined') {
|
2022-11-14 12:52:16 +00:00
|
|
|
return {}
|
2022-08-18 10:13:42 +00:00
|
|
|
}
|
2022-11-23 20:26:07 +00:00
|
|
|
let arrCfg = attrMap[isDmg ? 'dmg' : key]
|
|
|
|
val = Format[arrCfg.format](val, 1)
|
2022-11-14 12:52:16 +00:00
|
|
|
let ret = {
|
2022-11-23 20:26:07 +00:00
|
|
|
key,
|
2023-02-21 19:49:49 +00:00
|
|
|
value: val,
|
|
|
|
upNum: ds.upNum || 0
|
2022-11-14 12:52:16 +00:00
|
|
|
}
|
2023-02-21 19:49:49 +00:00
|
|
|
if (!isMain && !ret.upNum) {
|
2022-11-23 20:26:07 +00:00
|
|
|
let incRet = ArtisMark.getIncNum(key, value)
|
2022-11-14 17:10:52 +00:00
|
|
|
ret.upNum = incRet.num
|
|
|
|
ret.hasGt = incRet.hasGt
|
|
|
|
ret.hasLt = incRet.hasLt
|
2023-02-21 19:49:49 +00:00
|
|
|
ret.isCalcNum = true
|
2022-11-14 12:52:16 +00:00
|
|
|
}
|
2022-08-18 10:13:42 +00:00
|
|
|
|
2022-11-23 20:26:07 +00:00
|
|
|
if (charAttrCfg) {
|
|
|
|
let mark = charAttrCfg[key]?.mark * num || 0
|
2022-08-18 10:13:42 +00:00
|
|
|
if (isMain) {
|
|
|
|
mark = mark / 4 + 0.01
|
2022-11-22 20:25:36 +00:00
|
|
|
ret.key = key
|
2022-08-18 10:13:42 +00:00
|
|
|
}
|
|
|
|
ret.mark = Format.comma(mark || 0)
|
|
|
|
ret._mark = mark || 0
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
},
|
|
|
|
|
2022-11-23 20:26:07 +00:00
|
|
|
// 获取升级次数
|
|
|
|
getIncNum (key, value) {
|
|
|
|
let cfg = attrMap[key]
|
2022-11-14 17:10:52 +00:00
|
|
|
if (!value || !cfg || !cfg.value || !cfg.valueMin) {
|
|
|
|
return { num: 0 }
|
|
|
|
}
|
|
|
|
let maxNum = Math.min(5, Math.floor((value / cfg.valueMin).toFixed(1) * 1))
|
|
|
|
let minNum = Math.max(1, Math.ceil((value / cfg.value).toFixed(1) * 1))
|
|
|
|
// 相等时直接返回
|
|
|
|
if (maxNum === minNum) {
|
|
|
|
return { num: minNum }
|
|
|
|
}
|
|
|
|
let avg = Math.round(value / (cfg.value + cfg.valueMin) * 2)
|
|
|
|
return {
|
|
|
|
num: avg,
|
|
|
|
hasGt: maxNum > avg,
|
|
|
|
hasLt: minNum < avg
|
2022-11-14 13:10:20 +00:00
|
|
|
}
|
2022-11-14 12:52:16 +00:00
|
|
|
},
|
|
|
|
|
2022-11-23 20:26:07 +00:00
|
|
|
// 获取评分档位
|
2022-08-18 10:13:42 +00:00
|
|
|
getMarkClass (mark) {
|
|
|
|
let pct = mark
|
2023-02-05 18:14:38 +00:00
|
|
|
let scoreMap = [['D', 10], ['C', 16.5], ['B', 23.1], ['A', 29.7], ['S', 36.3], ['SS', 42.9], ['SSS', 49.5], ['ACE', 56.1], ['ACE²', 66.1]]
|
2022-08-18 10:13:42 +00:00
|
|
|
for (let idx = 0; idx < scoreMap.length; idx++) {
|
|
|
|
if (pct < scoreMap[idx][1]) {
|
|
|
|
return scoreMap[idx][0]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2022-11-23 20:26:07 +00:00
|
|
|
// 获取位置分数
|
2022-11-22 20:25:36 +00:00
|
|
|
getMark (charCfg, posIdx, mainAttr, subAttr, elem = '') {
|
2022-08-18 10:13:42 +00:00
|
|
|
let ret = 0
|
2022-11-23 20:26:07 +00:00
|
|
|
let { attrs, posMaxMark } = charCfg
|
2023-02-09 17:17:18 +00:00
|
|
|
let key = mainAttr?.key
|
2023-02-09 17:50:52 +00:00
|
|
|
if (!key) {
|
|
|
|
return 0
|
|
|
|
}
|
2022-08-18 10:13:42 +00:00
|
|
|
let fixPct = 1
|
2022-11-23 20:26:07 +00:00
|
|
|
posIdx = posIdx * 1
|
2022-08-18 10:13:42 +00:00
|
|
|
if (posIdx >= 3) {
|
2022-11-23 20:26:07 +00:00
|
|
|
let mainKey = key
|
|
|
|
if (key !== 'recharge') {
|
|
|
|
if (posIdx === 4 && Format.isElem(key) && key === elem) {
|
|
|
|
mainKey = 'dmg'
|
|
|
|
}
|
|
|
|
fixPct = Math.max(0, Math.min(1, (attrs[mainKey]?.weight || 0) / (posMaxMark['m' + posIdx])))
|
2022-11-22 20:25:36 +00:00
|
|
|
}
|
2022-11-23 20:26:07 +00:00
|
|
|
ret += (attrs[mainKey]?.mark || 0) * (mainAttr.value || 0) / 4
|
2022-08-18 10:13:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
lodash.forEach(subAttr, (ds) => {
|
2022-11-23 20:26:07 +00:00
|
|
|
ret += (attrs[ds.key]?.mark || 0) * (ds.value || 0)
|
2022-08-18 10:13:42 +00:00
|
|
|
})
|
2022-11-23 20:26:07 +00:00
|
|
|
return ret * (1 + fixPct) / 2 / posMaxMark[posIdx] * 66
|
2022-08-18 10:13:42 +00:00
|
|
|
},
|
2022-11-23 20:26:07 +00:00
|
|
|
|
|
|
|
// 获取位置最高分
|
2022-09-14 19:31:10 +00:00
|
|
|
getMaxMark (attrs) {
|
2022-08-18 10:13:42 +00:00
|
|
|
let ret = {}
|
|
|
|
for (let idx = 1; idx <= 5; idx++) {
|
|
|
|
let totalMark = 0
|
|
|
|
let mMark = 0
|
|
|
|
let mAttr = ''
|
|
|
|
if (idx === 1) {
|
|
|
|
mAttr = 'hpPlus'
|
|
|
|
} else if (idx === 2) {
|
|
|
|
mAttr = 'atkPlus'
|
|
|
|
} else if (idx >= 3) {
|
2022-09-14 19:31:10 +00:00
|
|
|
mAttr = ArtisMark.getMaxAttr(attrs, mainAttr[idx])[0]
|
|
|
|
mMark = attrs[mAttr].fixWeight
|
|
|
|
totalMark += attrs[mAttr].fixWeight * 2
|
2022-08-18 10:13:42 +00:00
|
|
|
}
|
|
|
|
|
2022-09-14 19:31:10 +00:00
|
|
|
let sAttr = ArtisMark.getMaxAttr(attrs, subAttr, 4, mAttr)
|
2022-08-18 10:13:42 +00:00
|
|
|
lodash.forEach(sAttr, (attr, aIdx) => {
|
2022-09-14 19:31:10 +00:00
|
|
|
totalMark += attrs[attr].fixWeight * (aIdx === 0 ? 6 : 1)
|
2022-08-18 10:13:42 +00:00
|
|
|
})
|
|
|
|
ret[idx] = totalMark
|
|
|
|
ret['m' + idx] = mMark
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
},
|
2022-11-23 20:26:07 +00:00
|
|
|
|
|
|
|
// 获取最高分的属性
|
2022-09-14 19:31:10 +00:00
|
|
|
getMaxAttr (attrs = {}, list2 = [], maxLen = 1, banAttr = '') {
|
2022-08-18 10:13:42 +00:00
|
|
|
let tmp = []
|
|
|
|
lodash.forEach(list2, (attr) => {
|
|
|
|
if (attr === banAttr) return
|
2022-09-14 19:31:10 +00:00
|
|
|
if (!attrs[attr]) return
|
|
|
|
tmp.push({ attr, mark: attrs[attr].fixWeight })
|
2022-08-18 10:13:42 +00:00
|
|
|
})
|
|
|
|
tmp = lodash.sortBy(tmp, 'mark')
|
|
|
|
tmp = tmp.reverse()
|
|
|
|
let ret = []
|
|
|
|
lodash.forEach(tmp, (ds) => ret.push(ds.attr))
|
|
|
|
return ret.slice(0, maxLen)
|
2023-02-09 18:54:51 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
hasAttr (artis) {
|
|
|
|
for (let idx = 1; idx <= 5; idx++) {
|
|
|
|
let ds = artis[idx]
|
|
|
|
if (ds && (!ds.name || !ds.main || !ds.attrs || !ds?.main?.key)) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
2022-08-18 10:13:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ArtisMark
|