2023-02-08 20:55:54 +00:00
|
|
|
|
/**
|
|
|
|
|
* 面板圣遗物
|
|
|
|
|
*/
|
|
|
|
|
import lodash from 'lodash'
|
|
|
|
|
import Base from './Base.js'
|
|
|
|
|
import { Artifact, ArtifactSet } from './index.js'
|
2023-03-07 17:52:11 +00:00
|
|
|
|
import { Format, Data } from '#miao'
|
2023-02-13 19:47:22 +00:00
|
|
|
|
import ArtisMark from './profile/ArtisMark.js'
|
2023-02-08 20:55:54 +00:00
|
|
|
|
|
|
|
|
|
export default class AvatarArtis extends Base {
|
2023-05-16 05:04:43 +00:00
|
|
|
|
constructor (charid = 0, game = 'gs') {
|
2023-02-08 20:55:54 +00:00
|
|
|
|
super()
|
2023-05-16 05:04:43 +00:00
|
|
|
|
this.game = game
|
2023-02-08 20:55:54 +00:00
|
|
|
|
this.charid = charid
|
|
|
|
|
this.artis = {}
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-11 19:51:50 +00:00
|
|
|
|
get sets () {
|
|
|
|
|
return this.getSetData().sets || {}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get names () {
|
|
|
|
|
return this.getSetData().names || []
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get hasArtis () {
|
|
|
|
|
return !lodash.isEmpty(this.artis)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get hasAttr () {
|
2023-05-14 20:19:33 +00:00
|
|
|
|
if (this.isSr) {
|
|
|
|
|
return true
|
|
|
|
|
}
|
2023-02-11 19:51:50 +00:00
|
|
|
|
return ArtisMark.hasAttr(this.artis)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static _eachArtisSet (sets, fn) {
|
|
|
|
|
lodash.forEach(sets || [], (v, k) => {
|
|
|
|
|
let artisSet = ArtifactSet.get(k)
|
|
|
|
|
if (artisSet) {
|
|
|
|
|
if (v >= 4) {
|
|
|
|
|
fn(artisSet, 2)
|
|
|
|
|
}
|
|
|
|
|
fn(artisSet, v)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-18 20:23:19 +00:00
|
|
|
|
static getArtisKeyTitle (game = 'gs') {
|
|
|
|
|
return ArtisMark.getKeyTitleMap(game)
|
2023-02-11 19:51:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-16 05:04:43 +00:00
|
|
|
|
setArtisData (ds = {}, isProfile = false) {
|
|
|
|
|
if (!isProfile || (isProfile && ArtisMark.hasAttr(ds))) {
|
|
|
|
|
for (let idx = 1; idx <= (this.isGs ? 5 : 6); idx++) {
|
2023-02-11 07:24:44 +00:00
|
|
|
|
if (ds[idx] || ds[`arti${idx}`]) {
|
2023-05-16 05:04:43 +00:00
|
|
|
|
this.setArtis(idx, ds[idx] || ds[`arti${idx}`], isProfile)
|
2023-02-08 20:55:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-16 05:04:43 +00:00
|
|
|
|
setArtis (idx = 1, ds = {}, isProfile = false) {
|
2023-02-08 20:55:54 +00:00
|
|
|
|
idx = idx.toString().replace('arti', '')
|
2023-02-11 07:24:44 +00:00
|
|
|
|
this.artis[idx] = this.artis[idx] || {}
|
|
|
|
|
let arti = this.artis[idx]
|
2023-05-16 05:04:43 +00:00
|
|
|
|
let artiObj
|
|
|
|
|
if (this.isSr) {
|
|
|
|
|
artiObj = Artifact.get(ds.id, this.game)
|
|
|
|
|
if (!artiObj) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
arti.id = artiObj.id || ds.id || arti.id || ''
|
|
|
|
|
arti.name = artiObj.name || arti.name || ''
|
|
|
|
|
arti.set = artiObj.setName || arti.set || ''
|
|
|
|
|
arti.level = ds.level || arti.level || 1
|
|
|
|
|
arti.star = artiObj.getStarById(ds.id) || arti.star || 5
|
|
|
|
|
|
|
|
|
|
if (ds.mainId && ds.attrs) {
|
2023-05-18 20:23:19 +00:00
|
|
|
|
let attr = artiObj.getAttrData(ds.mainId, ds.attrs, arti.level, arti.star, idx)
|
2023-05-16 05:04:43 +00:00
|
|
|
|
if (attr) {
|
|
|
|
|
arti.mainId = ds.mainId
|
|
|
|
|
arti.main = attr.main || arti.main || {}
|
|
|
|
|
arti.attrs = attr.attrs || arti.attrs || {}
|
|
|
|
|
} else {
|
|
|
|
|
console.log('attr id error', ds.main, arti.level, arti.star)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
} else {
|
|
|
|
|
if (isProfile) {
|
|
|
|
|
arti.name = ds._name || ds.name || arti.name || ''
|
|
|
|
|
arti.set = ds._set || Artifact.getSetNameByArti(arti._name) || ds.set || ''
|
|
|
|
|
arti.level = ds._level || ds.level || 1
|
|
|
|
|
arti.star = ds._star || ds.star || 5
|
|
|
|
|
arti.main = ds.main
|
|
|
|
|
arti.attrs = ds.attrs
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
arti.name = ds.name || arti.name || ''
|
|
|
|
|
arti.set = ds.set || Artifact.getSetNameByArti(arti.name) || ''
|
|
|
|
|
arti.level = ds.level || 1
|
|
|
|
|
arti.star = ds.star || 5
|
|
|
|
|
|
|
|
|
|
if (ds.mainId || ds.main) {
|
|
|
|
|
arti._name = ds._name || ds.name || arti._name || arti.name
|
|
|
|
|
arti._set = ds._set || Artifact.getSetNameByArti(arti._name) || arti._set || ''
|
|
|
|
|
arti._level = ds._level || ds.level || arti._level || arti.level
|
|
|
|
|
arti._star = ds._star || ds.star || arti._star || arti.star || 5
|
|
|
|
|
}
|
2023-02-11 19:51:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 存在面板数据,更新面板数据
|
|
|
|
|
if (ds.mainId && ds.attrIds) {
|
|
|
|
|
arti.mainId = ds.mainId
|
|
|
|
|
arti.attrIds = ds.attrIds
|
|
|
|
|
arti.main = Artifact.getMainById(ds.mainId, arti._level, arti._star)
|
2023-02-12 11:56:47 +00:00
|
|
|
|
arti.attrs = Artifact.getAttrsByIds(ds.attrIds, arti._star)
|
2023-02-11 19:51:50 +00:00
|
|
|
|
} else if (ds.main && ds.attrs) {
|
2023-02-11 07:24:44 +00:00
|
|
|
|
arti.main = ArtisMark.formatAttr(ds.main || {})
|
|
|
|
|
arti.attrs = []
|
2023-02-08 20:55:54 +00:00
|
|
|
|
for (let attrIdx in ds.attrs || []) {
|
|
|
|
|
if (ds.attrs[attrIdx]) {
|
2023-02-11 07:24:44 +00:00
|
|
|
|
arti.attrs.push(ArtisMark.formatAttr(ds.attrs[attrIdx]))
|
2023-02-08 20:55:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
forEach (fn) {
|
|
|
|
|
lodash.forEach(this.artis, (ds, idx) => {
|
|
|
|
|
if (ds.name) {
|
|
|
|
|
fn(ds, idx)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_get (key) {
|
|
|
|
|
let artis = this.artis
|
|
|
|
|
switch (key) {
|
|
|
|
|
case 'length':
|
|
|
|
|
return lodash.keys(artis).length
|
|
|
|
|
}
|
|
|
|
|
if (artis[key]) {
|
|
|
|
|
return artis[key]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
toJSON () {
|
|
|
|
|
let ret = {}
|
2023-05-16 05:04:43 +00:00
|
|
|
|
for (let idx = 1; idx <= (this.isGs ? 5 : 6); idx++) {
|
2023-02-08 20:55:54 +00:00
|
|
|
|
let ds = this.artis[idx]
|
2023-05-16 05:04:43 +00:00
|
|
|
|
if (!ds) {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
let tmp = {
|
|
|
|
|
level: ds.level || 1,
|
|
|
|
|
star: ds.star || 5
|
|
|
|
|
}
|
2023-05-16 19:15:00 +00:00
|
|
|
|
|
2023-05-16 05:04:43 +00:00
|
|
|
|
if (this.isSr) {
|
|
|
|
|
tmp.id = ds.id
|
|
|
|
|
tmp.mainId = ds.main?.id
|
|
|
|
|
tmp.attrs = []
|
|
|
|
|
lodash.forEach(ds.attrs, (as) => {
|
|
|
|
|
tmp.attrs.push({
|
|
|
|
|
id: as?.id,
|
|
|
|
|
count: as?.count,
|
|
|
|
|
step: as?.step
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
} else {
|
|
|
|
|
tmp.name = ds.name || ''
|
2023-02-11 19:51:50 +00:00
|
|
|
|
if ((ds.mainId && ds.attrIds) || (ds.main && ds.attrs)) {
|
|
|
|
|
if ((ds._name && ds._name !== ds.name) || (ds._level && ds._level !== ds.level) || (ds._star && ds._star !== ds.star)) {
|
|
|
|
|
tmp._name = ds._name || null
|
|
|
|
|
tmp._level = ds._level || null
|
|
|
|
|
tmp._star = ds._star || null
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (ds.mainId && ds.attrIds) {
|
|
|
|
|
tmp.mainId = ds.mainId || null
|
|
|
|
|
tmp.attrIds = ds.attrIds
|
|
|
|
|
} else if (ds.main && ds.attrs) {
|
2023-02-08 20:55:54 +00:00
|
|
|
|
tmp.main = ds.main || null
|
|
|
|
|
tmp.attrs = []
|
|
|
|
|
for (let attrIdx in ds.attrs || []) {
|
|
|
|
|
if (ds.attrs[attrIdx]) {
|
|
|
|
|
tmp.attrs.push(ArtisMark.formatAttr(ds.attrs[attrIdx]))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-05-16 05:04:43 +00:00
|
|
|
|
ret[idx] = tmp
|
2023-02-08 20:55:54 +00:00
|
|
|
|
}
|
|
|
|
|
return ret
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-11 07:24:44 +00:00
|
|
|
|
getDetail (profile = false) {
|
2023-02-08 20:55:54 +00:00
|
|
|
|
let ret = {}
|
|
|
|
|
for (let idx = 1; idx <= 5; idx++) {
|
|
|
|
|
let ds = this.artis[idx]
|
|
|
|
|
if (ds) {
|
2023-02-11 07:24:44 +00:00
|
|
|
|
let artis = Artifact.get(profile ? ds._name : ds.name)
|
2023-02-08 20:55:54 +00:00
|
|
|
|
let tmp = {
|
|
|
|
|
...artis?.getData('img,name,set'),
|
2023-02-11 07:24:44 +00:00
|
|
|
|
level: (profile ? ds._level : ds.level) || 1
|
2023-02-08 20:55:54 +00:00
|
|
|
|
}
|
|
|
|
|
if (ds.main && ds.attrs) {
|
|
|
|
|
tmp.main = ds.main || null
|
|
|
|
|
tmp.attrs = []
|
|
|
|
|
for (let attrIdx in ds.attrs || []) {
|
|
|
|
|
if (ds.attrs[attrIdx]) {
|
|
|
|
|
tmp.attrs.push(ArtisMark.formatAttr(ds.attrs[attrIdx]))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ret[idx] = tmp
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ret
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mainAttr (idx = '') {
|
|
|
|
|
if (!idx) {
|
|
|
|
|
let ret = {}
|
|
|
|
|
for (let i = 1; i <= 5; i++) {
|
|
|
|
|
ret[i] = this.mainAttr(i)
|
|
|
|
|
}
|
|
|
|
|
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 = '3,4,5') {
|
|
|
|
|
let mainAttr = this.mainAttr()
|
|
|
|
|
let check = true
|
|
|
|
|
Data.eachStr(pos.toString(), (p) => {
|
|
|
|
|
let attrs = attr.split(',')
|
|
|
|
|
if (!attrs.includes(mainAttr[p]) && (p === '4' && !attrs.includes('dmg') && Format.isElem(mainAttr[p]))) {
|
|
|
|
|
check = false
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
return check
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取圣遗物套装数据
|
|
|
|
|
* @returns {*|{imgs: *[], names: *[], sets: {}, abbrs: *[], sName: string, name: (string|*)}}
|
|
|
|
|
* sets: 套装名:2/4
|
|
|
|
|
* names: [套装名]
|
|
|
|
|
* imgs: [img]
|
|
|
|
|
* abbrs:[别名]
|
|
|
|
|
* name: '组合名字', 若为4件套会使用套装完整名
|
|
|
|
|
* sName: '简写名字',若为4件套也会使用简写
|
|
|
|
|
*/
|
2023-02-11 07:24:44 +00:00
|
|
|
|
getSetData (profile = false) {
|
2023-02-08 20:55:54 +00:00
|
|
|
|
let setCount = {}
|
|
|
|
|
this.forEach((arti, idx) => {
|
2023-02-11 07:24:44 +00:00
|
|
|
|
setCount[profile ? arti._set : arti.set] = (setCount[profile ? arti._set : arti.set] || 0) + 1
|
2023-02-08 20:55:54 +00:00
|
|
|
|
})
|
|
|
|
|
let sets = {}
|
|
|
|
|
let names = []
|
|
|
|
|
let imgs = []
|
|
|
|
|
let abbrs = []
|
|
|
|
|
let abbrs2 = []
|
|
|
|
|
for (let set in setCount) {
|
|
|
|
|
if (setCount[set] >= 2) {
|
|
|
|
|
let count = setCount[set] >= 4 ? 4 : 2
|
|
|
|
|
sets[set] = count
|
|
|
|
|
let artiSet = ArtifactSet.get(set)
|
|
|
|
|
names.push(artiSet.name)
|
|
|
|
|
imgs.push(artiSet.img)
|
|
|
|
|
abbrs.push(artiSet.abbr + count)
|
|
|
|
|
abbrs2.push(artiSet.name + count)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return {
|
|
|
|
|
sets,
|
|
|
|
|
names,
|
|
|
|
|
imgs,
|
|
|
|
|
abbrs: [...abbrs, ...abbrs2],
|
|
|
|
|
name: (abbrs.length > 1 || abbrs2[0]?.length > 7) ? abbrs.join('+') : abbrs2[0],
|
|
|
|
|
sName: abbrs.join('+')
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
eachArtisSet (fn) {
|
|
|
|
|
AvatarArtis._eachArtisSet(this.sets, fn)
|
|
|
|
|
}
|
|
|
|
|
}
|