miao-plugin/models/serv/api/EnkaData.js

107 lines
2.5 KiB
JavaScript
Raw Normal View History

2023-02-09 16:57:25 +00:00
import lodash from 'lodash'
2023-11-07 21:01:31 +00:00
import { Character, Artifact, Weapon } from '#miao.models'
const artisIdxMap = {
EQUIP_BRACER: 1,
EQUIP_NECKLACE: 2,
EQUIP_SHOES: 3,
EQUIP_RING: 4,
EQUIP_DRESS: 5,
生之花: 1,
死之羽: 2,
时之沙: 3,
空之杯: 4,
理之冠: 5
}
2023-02-09 16:57:25 +00:00
let EnkaData = {
setAvatar (player, data, dataSource = 'enka') {
2023-02-09 16:57:25 +00:00
let char = Character.get(data.avatarId)
if (!char) {
return
}
let avatar = player.getAvatar(char.id, true)
2023-02-09 16:57:25 +00:00
let talentRet = EnkaData.getTalent(char.id, data.skillLevelMap)
avatar.setAvatar({
level: data.propMap['4001'].val * 1,
promote: data.propMap['1002'].val * 1,
cons: data.talentIdList ? data.talentIdList.length : 0,
fetter: data.fetterInfo.expLevel,
costume: char.checkCostume(data.costumeId) ? data.costumeId : 0,
elem: talentRet.elem,
weapon: EnkaData.getWeapon(data.equipList),
talent: talentRet.talent,
artis: EnkaData.getArtifact(data.equipList)
}, dataSource)
2023-02-09 16:57:25 +00:00
return avatar
},
getWeapon (data) {
let ds = {}
lodash.forEach(data, (temp) => {
if (temp.flat && temp.flat.itemType === 'ITEM_WEAPON') {
ds = temp
return false
}
})
2023-02-27 19:20:43 +00:00
let { weapon } = ds
let w = Weapon.get(ds.itemId)
2023-02-09 16:57:25 +00:00
return {
2023-02-27 19:20:43 +00:00
name: w ? w.name : '',
2023-02-09 16:57:25 +00:00
level: weapon.level,
promote: weapon.promoteLevel,
affix: (lodash.values(weapon.affixMap)[0] || 0) + 1
}
},
getTalent (charid, ds = {}) {
let char = Character.get(charid)
let { talentId = {}, talentElem = {} } = char.meta
2023-02-09 16:57:25 +00:00
let elem = ''
let idx = 0
let ret = {}
lodash.forEach(ds, (lv, id) => {
let key
if (talentId[id]) {
let key = talentId[id]
elem = elem || talentElem[id]
2023-02-09 16:57:25 +00:00
ret[key] = lv
} else {
key = ['a', 'e', 'q'][idx++]
ret[key] = ret[key] || lv
}
})
return {
elem: elem,
talent: ret
}
},
getArtifact (data) {
let ret = {}
lodash.forEach(data, (ds) => {
let flat = ds.flat || {}
let re = ds.reliquary
let idx = artisIdxMap[flat.equipType]
if (!idx) {
return
}
2023-11-07 21:01:31 +00:00
let arti = Artifact.get(ds.itemId)
if (!arti) {
return true
}
ret[idx] = {
2023-11-07 21:01:31 +00:00
name: arti.name,
level: Math.min(20, ((re.level) || 1) - 1),
star: flat.rankLevel || 5,
mainId: re.mainPropId,
attrIds: re.appendPropIdList
}
})
return ret
2023-02-09 16:57:25 +00:00
}
}
export default EnkaData