2023-10-18 13:19:12 +00:00
|
|
|
|
/**
|
|
|
|
|
* 面板圣遗物
|
|
|
|
|
*/
|
|
|
|
|
import lodash from 'lodash'
|
2023-10-19 16:31:35 +00:00
|
|
|
|
import { Artifact, ArtifactSet } from '#miao.models'
|
2023-10-18 13:19:12 +00:00
|
|
|
|
import { Data, Format } from '#miao'
|
2023-10-19 16:31:35 +00:00
|
|
|
|
import Base from '../Base.js'
|
2023-10-19 07:46:08 +00:00
|
|
|
|
import ArtisAttr from './ArtisAttr.js'
|
2023-10-19 16:31:35 +00:00
|
|
|
|
import ArtisSet from './ArtisSet.js'
|
|
|
|
|
import ArtisMark from './ArtisMark.js'
|
2023-10-18 13:19:12 +00:00
|
|
|
|
|
2023-10-19 16:31:35 +00:00
|
|
|
|
export default class Artis extends Base {
|
2023-10-18 17:01:11 +00:00
|
|
|
|
constructor (game = 'gs', isProfile = false) {
|
2023-10-19 16:31:35 +00:00
|
|
|
|
super()
|
|
|
|
|
this.game = game
|
|
|
|
|
this.artis = {}
|
2023-10-18 13:19:12 +00:00
|
|
|
|
this.isProfile = !!isProfile
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-19 16:31:35 +00:00
|
|
|
|
|
|
|
|
|
// 获取圣遗物套装数据
|
|
|
|
|
getSetData () {
|
|
|
|
|
return ArtisSet.getSetData(this)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get sets () {
|
|
|
|
|
return this.getSetData().sets || {}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get names () {
|
|
|
|
|
return this.getSetData().names || []
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 有圣遗物数据
|
|
|
|
|
get hasArtis () {
|
|
|
|
|
return !lodash.isEmpty(this.artis)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_get (key) {
|
|
|
|
|
let artis = this.artis
|
|
|
|
|
switch (key) {
|
|
|
|
|
case 'length':
|
|
|
|
|
return lodash.keys(artis).length
|
|
|
|
|
}
|
|
|
|
|
if (artis[key]) {
|
|
|
|
|
return artis[key]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
forEach (fn) {
|
|
|
|
|
lodash.forEach(this.artis, (ds, idx) => {
|
|
|
|
|
if (ds.name) {
|
|
|
|
|
return fn(ds, idx)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
eachIdx (fn) {
|
|
|
|
|
for (let idx = 1; idx <= (this.isGs ? 5 : 6); idx++) {
|
|
|
|
|
this.artis[idx] = this.artis[idx] || {}
|
|
|
|
|
let ret = fn(this.artis[idx], idx)
|
|
|
|
|
if (ret === false) {
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setArtisData (ds = {}) {
|
|
|
|
|
this.eachIdx((arti, idx) => {
|
|
|
|
|
this.setArtis(idx, ds[idx] || ds[`arti${idx}`] || {})
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getDetail () {
|
|
|
|
|
let ret = {}
|
|
|
|
|
for (let idx = 1; idx <= 5; idx++) {
|
|
|
|
|
let ds = this.artis[idx]
|
|
|
|
|
if (ds && (ds.name || ds.id)) {
|
|
|
|
|
let artis = Artifact.get(ds)
|
|
|
|
|
if (!artis) {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
let tmp = {
|
|
|
|
|
...artis?.getData('img,name,set'),
|
|
|
|
|
level: ds.level || 1
|
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
eachArtisSet (fn) {
|
|
|
|
|
ArtifactSet.eachSet(this.sets, fn, this.game)
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-18 13:19:12 +00:00
|
|
|
|
// 有圣遗物词条
|
|
|
|
|
get hasAttr () {
|
2023-10-19 07:46:08 +00:00
|
|
|
|
return ArtisAttr.hasAttr(this)
|
2023-10-18 13:19:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-10-19 16:31:35 +00:00
|
|
|
|
setArtisBase (idx = 1, ds = {}) {
|
|
|
|
|
this.artis[idx] = this.artis[idx] || {}
|
|
|
|
|
let arti = this.artis[idx]
|
|
|
|
|
|
|
|
|
|
if (this.isSr) {
|
|
|
|
|
let 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
|
|
|
|
|
} else {
|
|
|
|
|
arti.name = ds.name || arti.name || ''
|
|
|
|
|
arti.set = ds.set || Artifact.getSetNameByArti(arti.name) || ''
|
|
|
|
|
arti.level = ds.level || 1
|
|
|
|
|
arti.star = ds.star || 5
|
|
|
|
|
}
|
2023-10-18 13:19:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setArtis (idx = 1, ds = {}) {
|
2023-10-18 17:01:11 +00:00
|
|
|
|
idx = idx.toString().replace('arti', '') * 1 || 1
|
2023-10-19 16:31:35 +00:00
|
|
|
|
this.setArtisBase(idx, ds)
|
2023-10-18 17:01:11 +00:00
|
|
|
|
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) => {
|
2023-10-19 16:31:35 +00:00
|
|
|
|
let key = this.isGs ? 'name' : 'id'
|
|
|
|
|
let tmp = {
|
2023-10-23 02:56:47 +00:00
|
|
|
|
level: ds.level || 1
|
2023-10-19 16:31:35 +00:00
|
|
|
|
}
|
|
|
|
|
if (!ds[key]) {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
tmp[key] = ds[key]
|
2023-10-23 02:56:47 +00:00
|
|
|
|
if (this.isGs) {
|
|
|
|
|
tmp.star = ds.star || 5
|
|
|
|
|
}
|
2023-10-18 13:19:12 +00:00
|
|
|
|
// 如果不为面板数据,则不保存mainId和attrIds
|
|
|
|
|
if (!this.isProfile) {
|
2023-10-19 16:31:35 +00:00
|
|
|
|
ret[idx] = tmp
|
2023-10-18 13:19:12 +00:00
|
|
|
|
return true
|
|
|
|
|
}
|
2023-10-19 16:31:35 +00:00
|
|
|
|
if (!ds.mainId || !ds.attrIds) {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
ret[idx] = tmp
|
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
|
|
|
|
|
}
|
2023-10-18 19:53:48 +00:00
|
|
|
|
|
|
|
|
|
isSameArtis (target) {
|
|
|
|
|
let k = (ds) => [ds?.name || '', ds?.level || '', ds?.star || ''].join('|')
|
|
|
|
|
let ret = true
|
|
|
|
|
this.eachIdx((ds, idx) => {
|
2023-10-19 16:31:35 +00:00
|
|
|
|
if (k(ds) !== k(target[idx])) {
|
2023-10-18 19:53:48 +00:00
|
|
|
|
return ret = false
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
return ret
|
|
|
|
|
}
|
2023-10-18 13:19:12 +00:00
|
|
|
|
}
|