miao-plugin/models/artis/ArtisMark.js

226 lines
6.1 KiB
JavaScript
Raw Normal View History

2022-08-18 10:13:42 +00:00
import lodash from 'lodash'
import { Data, Format, Meta } from '#miao'
import ArtisMarkCfg from './ArtisMarkCfg.js'
import { Artifact } from '#miao.models'
2022-08-18 10:13:42 +00:00
let ArtisMark = {
getKeyTitleMap (game = 'gs') {
let ret = {}
let { attrMap } = Meta.getMeta(game, 'arti')
lodash.forEach(attrMap, (ds, key) => {
ret[key] = ds.title
})
2022-11-24 15:27:03 +00:00
Format.eachElem((key, name) => {
ret[key] = `${name}伤加成`
}, game)
return ret
},
2023-05-18 20:23:19 +00:00
formatAttr (ds, game = 'gs') {
2022-08-18 10:13:42 +00:00
if (!ds) {
return {}
}
if (!ds.value) {
return {}
}
return {
key: ds.key || '',
2022-08-18 10:13:42 +00:00
value: ds.value || ''
}
},
/**
* 格式化圣遗物词条
* @param ds
* @param charAttrCfg
* @param isMain
2023-05-18 20:23:19 +00:00
* @param game
* @returns {{title: *, value: string}|*[]}
*/
formatArti (ds, charAttrCfg = false, isMain = false, game = 'gs') {
// 若为attr数组
if (ds[0] && (ds[0].title || ds[0].key)) {
2022-08-18 10:13:42 +00:00
let ret = []
lodash.forEach(ds, (d) => {
let arti = ArtisMark.formatArti(d, charAttrCfg, isMain, game)
ret.push(arti)
2022-08-18 10:13:42 +00:00
})
return ret
}
let key = ds.key
let isDmg = Format.isElem(key)
2022-08-18 10:13:42 +00:00
let val = ds.value || ds[1]
let num = ds.value || ds[1]
if (!key || key === 'undefined') {
return {}
2022-08-18 10:13:42 +00:00
}
let arrCfg = Meta.getMeta(game, 'arti', 'attrMap')[isDmg ? 'dmg' : key]
val = Format[arrCfg?.format || 'comma'](val, 1)
let ret = {
key,
2023-02-21 19:49:49 +00:00
value: val,
upNum: ds.upNum || 0,
eff: ds.eff || 0
}
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
}
ret.eff = ret.eff ? Format.comma(ret.eff / (game === 'gs' ? 0.85 : 0.9), 1) : '-'
2022-08-18 10:13:42 +00:00
return ret
},
formatArtiAttrs (ds, charAttrCfg = false, game = 'gs') {
let ret = []
lodash.forEach(ds, (d) => {
let arti = ArtisMark.formatArti(d, charAttrCfg, false, game)
ret.push(arti)
})
return ret
},
// 获取评分档位
2022-08-18 10:13:42 +00:00
getMarkClass (mark) {
let pct = mark
let scoreMap = [['D', 7], ['C', 14], ['B', 21], ['A', 28], ['S', 35], ['SS', 42], ['SSS', 49], ['ACE', 56], ['MAX', 70]]
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, idx, arti, elem = '', game = 'gs' }) {
2022-08-18 10:13:42 +00:00
let ret = 0
let mAttr = arti.main
let sAttr = arti.attrs
let { attrs, posMaxMark } = charCfg
let key = mAttr?.key
if (!key) {
return 0
}
2022-08-18 10:13:42 +00:00
let fixPct = 1
idx = idx * 1
if (idx >= 3) {
let mainKey = key
if (key !== 'recharge') {
let dmgIdx = { gs: 4, sr: 5 }
if (idx === dmgIdx[game] && Format.sameElem(elem, key, game)) {
mainKey = 'dmg'
}
fixPct = Math.max(0, Math.min(1, (attrs[mainKey]?.weight || 0) / (posMaxMark['m' + idx])))
2023-10-24 19:34:36 +00:00
if (game === 'gs') {
if (['atk', 'hp', 'def'].includes(mainKey) && attrs[mainKey]?.weight >= 75) {
fixPct = 1
}
}
}
ret += (attrs[mainKey]?.mark || 0) * (mAttr.value || 0) / 4
2022-08-18 10:13:42 +00:00
}
lodash.forEach(sAttr, (ds) => {
ret += (attrs[ds.key]?.mark || 0) * (ds.value || 0)
2022-08-18 10:13:42 +00:00
})
return ret * (1 + fixPct) / 2 / posMaxMark[idx] * 66
},
// 获取位置最高分
getMaxMark (attrs, game = 'gs') {
2022-08-18 10:13:42 +00:00
let ret = {}
let { mainAttr, subAttr } = Meta.getMeta(game, 'arti')
for (let idx = 1; idx <= (game === 'gs' ? 5 : 6); idx++) {
2022-08-18 10:13:42 +00:00
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)
},
getMarkDetail (profile, withDetail = true) {
if (!profile.isProfile) {
return {}
}
let charCfg = ArtisMarkCfg.getCfg(profile)
let artisRet = {}
let setCount = {}
let totalMark = 0
let { game, artis, elem } = profile
artis.forEach((arti, idx) => {
let mark = ArtisMark.getMark({ charCfg, idx, arti, elem, game })
totalMark += mark
setCount[arti.set] = (setCount[arti.set] || 0) + 1
artisRet[idx] = {
_mark: mark,
mark: Format.comma(mark, 1),
markClass: ArtisMark.getMarkClass(mark)
}
if (withDetail) {
let artifact = Artifact.get(arti, game)
artisRet[idx] = {
...artifact.getData('name,abbr,set:setName,img'),
level: arti.level,
main: ArtisMark.formatArti(arti.main, charCfg.attrs, true, game),
attrs: ArtisMark.formatArtiAttrs(arti.attrs, charCfg.attrs, game),
...artisRet[idx]
}
}
})
let setData = artis.getSetData()
artis.mark = totalMark
artis.markClass = ArtisMark.getMarkClass(totalMark / (profile.isGs ? 5 : 6))
let ret = {
classTitle: charCfg.classTitle,
artis: artisRet,
mark: Format.comma(totalMark, 1),
_mark: artis.mark,
markClass: artis.markClass,
...Data.getData(setData, 'sets,names,imgs')
}
if (withDetail) {
ret.charWeight = lodash.mapValues(charCfg.attrs, ds => ds.weight)
}
return ret
2022-08-18 10:13:42 +00:00
}
}
export default ArtisMark