2023-10-18 13:19:12 +00:00
|
|
|
|
/**
|
|
|
|
|
* 面板圣遗物
|
|
|
|
|
*/
|
|
|
|
|
import lodash from 'lodash'
|
|
|
|
|
import { Artifact, ArtifactSet, Character } from '#miao.models'
|
|
|
|
|
import { Data, Format } from '#miao'
|
|
|
|
|
import ArtisMark from './ArtisMark.js'
|
|
|
|
|
import { attrMap as attrMapGS } from '../../resources/meta/artifact/index.js'
|
|
|
|
|
import { attrMap as attrMapSR } from '../../resources/meta-sr/artifact/index.js'
|
2023-10-18 17:01:11 +00:00
|
|
|
|
import ArtisMarkCfg from './ArtisMarkCfg.js'
|
2023-10-18 13:19:12 +00:00
|
|
|
|
import ArtisBase from './ArtisBase.js'
|
|
|
|
|
|
|
|
|
|
export default class Artis extends ArtisBase {
|
2023-10-18 17:01:11 +00:00
|
|
|
|
constructor (game = 'gs', isProfile = false) {
|
2023-10-18 13:19:12 +00:00
|
|
|
|
super(game)
|
|
|
|
|
this.isProfile = !!isProfile
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 有圣遗物词条
|
|
|
|
|
get hasAttr () {
|
|
|
|
|
if (this.isSr) {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
return ArtisMark.hasAttr(this.artis)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取角色配置
|
|
|
|
|
* @returns {{classTitle: *, weight: *, posMaxMark: {}, mark: {}, attrs: {}}}
|
|
|
|
|
*/
|
|
|
|
|
getCharCfg () {
|
|
|
|
|
let char = Character.get(this.charid)
|
|
|
|
|
let { game, isGs } = char
|
2023-10-18 17:01:11 +00:00
|
|
|
|
let { attrWeight, title } = ArtisMarkCfg.getCharArtisCfg(char, this.profile, this)
|
2023-10-18 13:19:12 +00:00
|
|
|
|
let attrs = {}
|
|
|
|
|
let baseAttr = char.baseAttr || { hp: 14000, atk: 230, def: 700 }
|
|
|
|
|
let attrMap = isGs ? attrMapGS : attrMapSR
|
|
|
|
|
lodash.forEach(attrMap, (attr, key) => {
|
|
|
|
|
let k = attr.base || ''
|
|
|
|
|
let weight = attrWeight[k || key]
|
|
|
|
|
if (!weight || weight * 1 === 0) {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
let ret = {
|
|
|
|
|
...attr, weight, fixWeight: weight, mark: weight / attr.value
|
|
|
|
|
}
|
|
|
|
|
if (!k) {
|
|
|
|
|
ret.mark = weight / attr.value
|
|
|
|
|
} else {
|
|
|
|
|
let plus = k === 'atk' ? 520 : 0
|
|
|
|
|
ret.mark = weight / attrMap[k].value / (baseAttr[k] + plus) * 100
|
|
|
|
|
ret.fixWeight = weight * attr.value / attrMap[k].value / (baseAttr[k] + plus) * 100
|
|
|
|
|
}
|
|
|
|
|
attrs[key] = ret
|
|
|
|
|
})
|
|
|
|
|
let posMaxMark = ArtisMark.getMaxMark(attrs, game)
|
|
|
|
|
// 返回内容待梳理简化
|
|
|
|
|
return {
|
|
|
|
|
attrs, classTitle: title, posMaxMark
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getMarkDetail (withDetail = true) {
|
|
|
|
|
let charCfg = this.getCharCfg()
|
|
|
|
|
let artis = {}
|
|
|
|
|
let setCount = {}
|
|
|
|
|
let totalMark = 0
|
|
|
|
|
let self = this
|
|
|
|
|
this.forEach((arti, idx) => {
|
|
|
|
|
let mark = ArtisMark.getMark({
|
|
|
|
|
charCfg, idx, arti, elem: this.elem, game: self.game
|
|
|
|
|
})
|
|
|
|
|
totalMark += mark
|
|
|
|
|
setCount[arti.set] = (setCount[arti.set] || 0) + 1
|
|
|
|
|
if (!withDetail) {
|
|
|
|
|
artis[idx] = {
|
|
|
|
|
_mark: mark, mark: Format.comma(mark, 1), markClass: ArtisMark.getMarkClass(mark)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
let artifact = Artifact.get(arti.name, this.game)
|
|
|
|
|
artis[idx] = {
|
|
|
|
|
name: artifact.name,
|
|
|
|
|
abbr: artifact.abbr,
|
|
|
|
|
set: artifact.setName,
|
|
|
|
|
img: artifact.img,
|
|
|
|
|
level: arti.level,
|
|
|
|
|
_mark: mark,
|
|
|
|
|
mark: Format.comma(mark, 1),
|
|
|
|
|
markClass: ArtisMark.getMarkClass(mark),
|
|
|
|
|
main: ArtisMark.formatArti(arti.main, charCfg.attrs, true, this.game),
|
|
|
|
|
attrs: ArtisMark.formatArti(arti.attrs, charCfg.attrs, false, this.game)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
let sets = {}
|
|
|
|
|
let names = []
|
|
|
|
|
let imgs = []
|
|
|
|
|
for (let set in setCount) {
|
|
|
|
|
if (setCount[set] >= 2) {
|
|
|
|
|
sets[set] = setCount[set] >= 4 ? 4 : 2
|
|
|
|
|
let artiSet = ArtifactSet.get(set)
|
|
|
|
|
imgs.push(artiSet.img)
|
|
|
|
|
names.push(artiSet.name)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
this.mark = totalMark
|
|
|
|
|
this.markClass = ArtisMark.getMarkClass(totalMark / 5)
|
|
|
|
|
let ret = {
|
|
|
|
|
mark: Format.comma(totalMark, 1),
|
|
|
|
|
_mark: totalMark,
|
|
|
|
|
markClass: ArtisMark.getMarkClass(totalMark / 5),
|
|
|
|
|
artis,
|
|
|
|
|
sets,
|
|
|
|
|
names,
|
|
|
|
|
imgs,
|
|
|
|
|
classTitle: charCfg.classTitle
|
|
|
|
|
}
|
|
|
|
|
if (withDetail) {
|
|
|
|
|
ret.charWeight = lodash.mapValues(charCfg.attrs, ds => ds.weight)
|
|
|
|
|
}
|
|
|
|
|
return ret
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setArtis (idx = 1, ds = {}) {
|
2023-10-18 17:01:11 +00:00
|
|
|
|
idx = idx.toString().replace('arti', '') * 1 || 1
|
|
|
|
|
super.setArtis(idx, ds)
|
|
|
|
|
if (!this.isProfile) {
|
|
|
|
|
return
|
|
|
|
|
}
|
2023-10-18 13:19:12 +00:00
|
|
|
|
let arti = this.artis[idx]
|
|
|
|
|
if (!ds.attrIds || !ds.mainId) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
arti.mainId = ds.mainId
|
|
|
|
|
arti.attrIds = ds.attrIds
|
2023-10-18 17:01:11 +00:00
|
|
|
|
let artiObj = Artifact.get(arti.id || arti.name, this.game)
|
2023-10-18 13:19:12 +00:00
|
|
|
|
if (!artiObj) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
2023-10-18 17:01:11 +00:00
|
|
|
|
let attr = artiObj.getAttrData(arti, idx, this.game)
|
2023-10-18 13:19:12 +00:00
|
|
|
|
if (!attr) {
|
|
|
|
|
console.log('attr id error', ds.main, ds.mainId, idx, arti.level, arti.star)
|
|
|
|
|
return false
|
|
|
|
|
}
|
2023-10-18 17:01:11 +00:00
|
|
|
|
arti.main = attr.main
|
|
|
|
|
arti.attrs = attr.attrs
|
2023-10-18 13:19:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取保存数据
|
|
|
|
|
toJSON () {
|
|
|
|
|
let ret = {}
|
|
|
|
|
this.eachIdx((ds, idx) => {
|
|
|
|
|
let tmp = this.isGs ? { name: ds.name } : { id: ds.id }
|
|
|
|
|
tmp.level = ds.level || 1
|
|
|
|
|
tmp.star = ds.star || 5
|
|
|
|
|
ret[idx] = tmp
|
|
|
|
|
// 如果不为面板数据,则不保存mainId和attrIds
|
|
|
|
|
if (!this.isProfile) {
|
|
|
|
|
return true
|
|
|
|
|
}
|
2023-10-18 17:01:11 +00:00
|
|
|
|
tmp.mainId = ds.mainId || ds.main?.id
|
2023-10-18 13:19:12 +00:00
|
|
|
|
if (this.isSr) {
|
|
|
|
|
tmp.attrIds = []
|
|
|
|
|
lodash.forEach(ds.attrs, (as) => {
|
|
|
|
|
tmp.attrIds.push([as?.id || '', as?.count || 1, as?.step || 0].join(','))
|
|
|
|
|
})
|
|
|
|
|
} else {
|
|
|
|
|
tmp.attrIds = ds.attrIds
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
return ret
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取指定idx的主词条
|
|
|
|
|
getMainAttr (idx = '') {
|
|
|
|
|
if (!idx) {
|
|
|
|
|
let ret = {}
|
|
|
|
|
this.eachIdx((arti, idx) => {
|
|
|
|
|
ret[idx] = this.getMainAttr(idx)
|
|
|
|
|
})
|
|
|
|
|
return ret
|
|
|
|
|
}
|
|
|
|
|
let main = this.artis[idx]?.main
|
|
|
|
|
if (!main) {
|
|
|
|
|
return ''
|
|
|
|
|
}
|
|
|
|
|
return main.key || ''
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
is (check, pos = '') {
|
|
|
|
|
if (pos) {
|
|
|
|
|
return this.isAttr(check, pos)
|
|
|
|
|
}
|
|
|
|
|
let sets = this.getSetData()?.abbrs || []
|
|
|
|
|
let ret = false
|
|
|
|
|
Data.eachStr(check, (s) => {
|
|
|
|
|
if (sets.includes(s)) {
|
|
|
|
|
ret = true
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
return ret
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
isAttr (attr, pos = '') {
|
|
|
|
|
let mainAttr = this.getMainAttr()
|
|
|
|
|
let check = true
|
|
|
|
|
pos = pos || this.isGs ? '3,4,5' : '3,4,5,6'
|
|
|
|
|
let dmgIdx = this.isGs ? 4 : 5
|
|
|
|
|
Data.eachStr(pos.toString(), (p) => {
|
|
|
|
|
let attrs = attr.split(',')
|
|
|
|
|
if (!attrs.includes(mainAttr[p]) && (p === dmgIdx && !attrs.includes('dmg') && Format.isElem(mainAttr[p]))) {
|
|
|
|
|
check = false
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
return check
|
|
|
|
|
}
|
|
|
|
|
}
|