2022-09-18 20:54:01 +00:00
|
|
|
/*
|
2022-09-25 13:56:10 +00:00
|
|
|
* 用户角色封装
|
|
|
|
* 兼容处理面板 Profile Data 及 Mys Avatar 数据
|
2022-09-18 20:54:01 +00:00
|
|
|
* */
|
|
|
|
import Base from './Base.js'
|
|
|
|
import lodash from 'lodash'
|
2022-09-20 19:15:22 +00:00
|
|
|
import { Profile } from '../components/index.js'
|
2022-09-24 12:19:59 +00:00
|
|
|
import { Artifact, Character, Weapon, ArtifactSet } from './index.js'
|
2022-09-18 20:54:01 +00:00
|
|
|
import moment from 'moment'
|
|
|
|
|
2022-09-24 21:05:22 +00:00
|
|
|
const charKey = 'name,abbr,sName,star,imgs,face,side,gacha,weaponType,elem'.split(',')
|
2022-09-18 20:54:01 +00:00
|
|
|
|
|
|
|
export default class Avatar extends Base {
|
2022-09-20 19:15:22 +00:00
|
|
|
constructor (data = {}, pd = false, hasCk = true) {
|
2022-09-18 20:54:01 +00:00
|
|
|
super()
|
|
|
|
if (!data.name) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
let char = Character.get(data.name)
|
|
|
|
if (!char || char.isCustom) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
this.meta = data
|
|
|
|
this.char = char
|
2022-09-20 19:15:22 +00:00
|
|
|
let isProfile = data.isProfile
|
|
|
|
this.dataType = isProfile ? 'profile' : 'avatar'
|
|
|
|
this.hasCk = hasCk
|
|
|
|
let profile
|
|
|
|
let uid
|
|
|
|
if (isProfile) {
|
|
|
|
profile = data
|
|
|
|
} else if (pd) {
|
|
|
|
if (pd.isProfile) {
|
|
|
|
profile = pd
|
|
|
|
} else if (/\d{9}/.test(pd)) {
|
|
|
|
uid = pd
|
|
|
|
profile = Profile.get(pd, char.id, true)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (profile && profile.isProfile && profile.hasData) {
|
|
|
|
this.profile = profile
|
|
|
|
}
|
2022-09-21 03:06:33 +00:00
|
|
|
this.elem = ((profile && profile.elem) || data.element || data.elem || char.elem || 'anemo').toLowerCase()
|
2022-09-20 19:15:22 +00:00
|
|
|
if (char.isTraveler) {
|
|
|
|
this.char = Character.get({ id: data.id || char.id, elem: this.elem })
|
|
|
|
uid && char.setTraveler(uid)
|
|
|
|
}
|
2022-09-18 20:54:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_get (key) {
|
|
|
|
if (charKey.includes(key)) {
|
|
|
|
return this.char[key]
|
|
|
|
}
|
|
|
|
return this.meta[key]
|
|
|
|
}
|
|
|
|
|
|
|
|
get dataSourceName () {
|
2022-09-20 19:15:22 +00:00
|
|
|
if (!this.hasCk && this.profile) {
|
|
|
|
return this.profile.dataSourceName
|
|
|
|
}
|
2022-09-19 19:16:00 +00:00
|
|
|
return this.meta.dataSourceName || '米游社'
|
2022-09-18 20:54:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get updateTime () {
|
2022-09-20 19:15:22 +00:00
|
|
|
if ((!this.hasCk || this.isProfile) && this.profile) {
|
|
|
|
return this.profile.updateTime
|
|
|
|
}
|
|
|
|
return moment(new Date()).format('MM-DD HH:mm')
|
2022-09-18 20:54:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get isProfile () {
|
|
|
|
return this.dataType === 'profile'
|
|
|
|
}
|
|
|
|
|
|
|
|
get isAvatar () {
|
|
|
|
return this.dataType === 'avatar'
|
|
|
|
}
|
|
|
|
|
|
|
|
get artis () {
|
|
|
|
let ret = {}
|
2022-09-20 19:15:22 +00:00
|
|
|
if (!this.isProfile) {
|
|
|
|
lodash.forEach(this.meta.reliquaries, (ds) => {
|
2022-09-24 12:19:59 +00:00
|
|
|
let arti = Artifact.get(ds.name)
|
|
|
|
ret[arti.idx] = {
|
|
|
|
name: arti.name,
|
|
|
|
set: arti.setName,
|
|
|
|
img: arti.img,
|
2022-09-20 19:15:22 +00:00
|
|
|
level: ds.level
|
|
|
|
}
|
|
|
|
})
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
if (this.profile && this.profile?.artis) {
|
2022-09-24 12:19:59 +00:00
|
|
|
return this.profile.artis.getArtisData()
|
2022-09-20 19:15:22 +00:00
|
|
|
}
|
|
|
|
return false
|
2022-09-18 20:54:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get cons () {
|
|
|
|
let data = this.meta
|
2022-09-20 19:15:22 +00:00
|
|
|
let profile = this.profile
|
2022-09-21 03:06:33 +00:00
|
|
|
return data?.cons || data?.actived_constellation_num || profile?.cons || 0
|
2022-09-18 20:54:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get weapon () {
|
2022-09-20 19:15:22 +00:00
|
|
|
let wd = this.meta?.weapon || this.profile?.weapon
|
2022-09-18 20:54:01 +00:00
|
|
|
if (!wd || !wd.name) {
|
|
|
|
return {}
|
|
|
|
}
|
|
|
|
let weapon = Weapon.get(wd.name)
|
|
|
|
return {
|
|
|
|
name: wd.name,
|
|
|
|
abbr: weapon.abbr,
|
|
|
|
star: weapon.star,
|
|
|
|
level: wd.level || 1,
|
|
|
|
affix: wd.affix || wd.affix_level || 0,
|
|
|
|
type: weapon.type,
|
|
|
|
img: weapon.img
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-20 19:15:22 +00:00
|
|
|
async getTalent (mys) {
|
|
|
|
if (!this.isProfile && mys && mys.isSelfCookie) {
|
|
|
|
let char = this.char
|
|
|
|
let id = char.id
|
|
|
|
let talent = {}
|
|
|
|
let talentRes = await mys.getDetail(id)
|
|
|
|
let avatar = this.meta
|
|
|
|
if (!char || !avatar) {
|
2022-10-06 19:36:24 +00:00
|
|
|
return false
|
2022-09-20 19:15:22 +00:00
|
|
|
}
|
|
|
|
if (talentRes && talentRes.skill_list) {
|
|
|
|
let talentList = lodash.orderBy(talentRes.skill_list, ['id'], ['asc'])
|
|
|
|
for (let val of talentList) {
|
|
|
|
let { max_level: maxLv, level_current: lv } = val
|
|
|
|
if (val.name.includes('普通攻击')) {
|
|
|
|
talent.a = lv
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if (maxLv >= 10 && !talent.e) {
|
|
|
|
talent.e = lv
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if (maxLv >= 10 && !talent.q) {
|
|
|
|
talent.q = lv
|
|
|
|
continue
|
|
|
|
}
|
2022-09-18 20:54:01 +00:00
|
|
|
}
|
|
|
|
}
|
2022-09-23 21:59:30 +00:00
|
|
|
let ret = char.getAvatarTalent(talent, this.cons, 'original')
|
2022-10-07 13:13:46 +00:00
|
|
|
if (ret) {
|
|
|
|
ret.id = id
|
|
|
|
}
|
2022-09-20 19:15:22 +00:00
|
|
|
return ret
|
|
|
|
}
|
|
|
|
if (this.profile) {
|
|
|
|
let profile = this.profile
|
|
|
|
let talent = profile.talent
|
|
|
|
talent.id = profile.id
|
|
|
|
return talent
|
2022-09-18 20:54:01 +00:00
|
|
|
}
|
2022-09-20 19:15:22 +00:00
|
|
|
return false
|
2022-09-18 20:54:01 +00:00
|
|
|
}
|
2022-09-19 19:16:00 +00:00
|
|
|
|
|
|
|
get artisSet () {
|
|
|
|
if (this._artisSet) {
|
|
|
|
return this._artisSet
|
|
|
|
}
|
2022-09-20 19:15:22 +00:00
|
|
|
this._artisSet = false
|
|
|
|
if (!this.isProfile) {
|
|
|
|
let artis = this.artis
|
|
|
|
let setCount = {}
|
|
|
|
lodash.forEach(artis, (arti, idx) => {
|
2022-09-24 12:19:59 +00:00
|
|
|
let set = arti?.set
|
2022-09-20 19:15:22 +00:00
|
|
|
if (set) {
|
|
|
|
setCount[set] = (setCount[set] || 0) + 1
|
|
|
|
}
|
|
|
|
})
|
|
|
|
let sets = {}
|
|
|
|
let names = []
|
|
|
|
let abbrs = []
|
|
|
|
let abbrs2 = []
|
2022-09-24 12:19:59 +00:00
|
|
|
let imgs = []
|
2022-09-20 19:15:22 +00:00
|
|
|
for (let set in setCount) {
|
|
|
|
if (setCount[set] >= 2) {
|
2022-09-24 12:19:59 +00:00
|
|
|
let value = setCount[set] >= 4 ? 4 : 2
|
|
|
|
sets[set] = value
|
|
|
|
let artiSet = ArtifactSet.get(set)
|
|
|
|
names.push(artiSet.name)
|
|
|
|
abbrs.push(artiSet.abbr + value)
|
|
|
|
abbrs2.push(artiSet.name + value)
|
|
|
|
imgs.push(artiSet.img)
|
2022-09-20 19:15:22 +00:00
|
|
|
}
|
2022-09-19 19:16:00 +00:00
|
|
|
}
|
2022-09-20 19:15:22 +00:00
|
|
|
this._artisSet = {
|
|
|
|
sets,
|
|
|
|
names,
|
|
|
|
abbrs: [...abbrs, ...abbrs2],
|
2022-09-24 12:19:59 +00:00
|
|
|
imgs,
|
2022-09-20 19:15:22 +00:00
|
|
|
name: abbrs.length > 1 ? abbrs.join('+') : abbrs2[0]
|
2022-09-19 19:16:00 +00:00
|
|
|
}
|
|
|
|
}
|
2022-09-20 19:15:22 +00:00
|
|
|
if (this.profile) {
|
|
|
|
let profile = this.profile
|
|
|
|
this._artisSet = profile.artis ? profile.artis.getSetData() : false
|
|
|
|
}
|
|
|
|
return this._artisSet || {}
|
2022-09-19 19:16:00 +00:00
|
|
|
}
|
2022-09-20 19:15:22 +00:00
|
|
|
}
|