miao-plugin/models/profile-lib/ArtisMark.js

233 lines
5.8 KiB
JavaScript
Raw Normal View History

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 = {
// 根据Key获取标题
getKeyByTitle (title, dmg = false) {
if (/元素伤害加成/.test(title)) {
2022-11-24 15:27:03 +00:00
let elem = Format.matchElem(title)
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) => {
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 {
key: ArtisMark.getKeyByTitle(ds[0]),
2022-08-18 10:13:42 +00:00
value: ds[1]
}
}
if (!ds.value) {
return {}
}
return {
key: ds.key || ArtisMark.getKeyByTitle(ds.title || ds.name || ds.key || ds.id || ''),
2022-08-18 10:13:42 +00:00
value: ds.value || ''
}
},
/**
* 格式化圣遗物词条
* @param ds
* @param markCfg
* @param isMain
* @returns {{title: *, value: string}|*[]}
*/
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 = []
let totalUpNum = 0
let ltArr = []
2022-08-18 10:13:42 +00:00
lodash.forEach(ds, (d) => {
let arti = ArtisMark.formatArti(d, charAttrCfg)
totalUpNum += arti.upNum
if (arti.hasLt) {
ltArr.push(arti)
}
ret.push(arti)
delete arti.hasLt
delete arti.hasGt
2022-08-18 10:13:42 +00:00
})
ltArr = lodash.sortBy(ltArr, 'upNum').reverse()
for (let arti of ltArr) {
if (totalUpNum > 9) {
arti.upNum = arti.upNum - 1
totalUpNum--
} else {
break
}
}
2022-08-18 10:13:42 +00:00
return ret
}
let key = ds.key
2022-08-18 10:13:42 +00:00
let title = ds.title || ds[0]
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]
let value = val
2022-08-18 10:13:42 +00:00
let num = ds.value || ds[1]
if (!key || key === 'undefined') {
return {}
2022-08-18 10:13:42 +00:00
}
let arrCfg = attrMap[isDmg ? 'dmg' : key]
2022-08-18 10:13:42 +00:00
val = Format[arrCfg.format](val, 1)
2022-08-18 10:13:42 +00:00
let ret = {
key,
value: val
}
if (!isMain) {
let incRet = ArtisMark.getIncNum(key, value)
ret.upNum = incRet.num
ret.hasGt = incRet.hasGt
ret.hasLt = incRet.hasLt
}
2022-08-18 10:13:42 +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
ret.key = key
2022-08-18 10:13:42 +00:00
}
ret.mark = Format.comma(mark || 0)
ret._mark = mark || 0
}
return ret
},
// 获取升级次数
getIncNum (key, value) {
let cfg = attrMap[key]
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-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]
}
}
},
// 获取位置分数
getMark (charCfg, posIdx, mainAttr, subAttr, elem = '') {
2022-08-18 10:13:42 +00:00
let ret = 0
let { attrs, posMaxMark } = charCfg
let key = mainAttr?.key
2022-08-18 10:13:42 +00:00
let fixPct = 1
posIdx = posIdx * 1
2022-08-18 10:13:42 +00:00
if (posIdx >= 3) {
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])))
}
ret += (attrs[mainKey]?.mark || 0) * (mainAttr.value || 0) / 4
2022-08-18 10:13:42 +00:00
}
lodash.forEach(subAttr, (ds) => {
ret += (attrs[ds.key]?.mark || 0) * (ds.value || 0)
2022-08-18 10:13:42 +00:00
})
return ret * (1 + fixPct) / 2 / posMaxMark[posIdx] * 66
2022-08-18 10:13:42 +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) {
mAttr = ArtisMark.getMaxAttr(attrs, mainAttr[idx])[0]
mMark = attrs[mAttr].fixWeight
totalMark += attrs[mAttr].fixWeight * 2
2022-08-18 10:13:42 +00:00
}
let sAttr = ArtisMark.getMaxAttr(attrs, subAttr, 4, mAttr)
2022-08-18 10:13:42 +00:00
lodash.forEach(sAttr, (attr, aIdx) => {
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
},
// 获取最高分的属性
getMaxAttr (attrs = {}, list2 = [], maxLen = 1, banAttr = '') {
2022-08-18 10:13:42 +00:00
let tmp = []
lodash.forEach(list2, (attr) => {
if (attr === banAttr) return
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)
}
}
export default ArtisMark