miao-plugin/models/player/MiaoData.js

137 lines
3.0 KiB
JavaScript
Raw Normal View History

import { Character } from '../index.js'
import lodash from 'lodash'
2023-02-08 20:55:54 +00:00
2023-02-09 16:57:25 +00:00
import { attrMap, artisIdxMap } from './ProfileMeta.js'
let MiaoData = {
2023-02-08 20:55:54 +00:00
setAvatar (player, ds) {
let char = Character.get(ds.id)
let avatar = player.getAvatar(ds.id, true)
2023-02-08 20:55:54 +00:00
let talentRet = MiaoData.getTalent(char.id, ds.skill)
avatar.setAvatar({
level: ds.level,
cons: ds.constellationNum || 0,
promote: ds.promoteLevel,
fetter: ds.fetterLevel,
costume: char.checkCostume(ds.costumeID) ? ds.costumeID : 0,
2023-02-08 20:55:54 +00:00
elem: talentRet.elem,
weapon: MiaoData.getWeapon(ds.weapon),
talent: talentRet.talent,
artis: MiaoData.getArtifact(ds.reliquary)
}, 'miao')
return avatar
},
2023-02-09 16:57:25 +00:00
2023-02-19 17:08:05 +00:00
setAvatarNew (player, ds) {
let char = Character.get(ds.id)
let avatar = player.getAvatar(ds.id, true)
let talentRet = MiaoData.getTalentNew(char.id, ds.talent)
avatar.setAvatar({
...ds,
elem: talentRet.elem,
talent: talentRet.talent
2023-02-19 17:08:05 +00:00
}, 'miao')
return avatar
},
getWeapon (weapon) {
return {
name: weapon.name,
level: weapon.level,
promote: weapon.promoteLevel,
affix: (weapon.affixLevel || 0) + 1
}
},
2023-02-09 16:57:25 +00:00
2023-02-19 17:08:05 +00:00
getTalentNew (charid, data = {}) {
let char = Character.get(charid)
let { talentId = {}, talentElem = {} } = char.meta
2023-02-19 17:08:05 +00:00
let elem = ''
let idx = 0
let ret = {}
lodash.forEach(data, (level, id) => {
let key
if (talentId[id]) {
key = talentId[id]
elem = elem || talentElem[id]
2023-02-19 17:08:05 +00:00
ret[key] = level
} else {
key = ['a', 'e', 'q'][idx]
ret[key] = level
}
idx++
})
return {
talent: ret,
elem
}
},
2023-02-09 16:57:25 +00:00
getTalent (charid, data = {}) {
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(data, (ds) => {
let key
if (talentId[ds.id]) {
key = talentId[ds.id]
elem = elem || talentElem[ds.id]
2023-02-09 16:57:25 +00:00
ret[key] = {
level: ds.level
}
} else {
key = ['a', 'e', 'q'][idx++]
ret[key] = ret[key] || {
level: ds.level
}
}
})
return {
talent: ret,
elem
}
},
getArtifact (data) {
let ret = {}
let get = function (d) {
if (!d) {
return []
}
let name = d.name
name = name.replace('FIGHT_PROP_', '')
if (!attrMap[name]) {
return []
}
let value = d.value
if (value && value < 1) {
value = value * 100
}
2023-02-08 20:55:54 +00:00
return { key: attrMap[name], value }
}
lodash.forEach(data, (ds) => {
let sub = ds.appendAffix || []
2023-02-09 16:57:25 +00:00
let idx = artisIdxMap[ds.type]
if (!idx) {
return
}
2023-02-08 20:55:54 +00:00
ret[idx] = {
name: ds.name,
level: ds.level,
star: ds.rank,
main: get(ds.mainAffix),
attrs: [
get(sub[0]),
get(sub[1]),
get(sub[2]),
get(sub[3])
]
}
})
return ret
}
}
2022-08-18 10:13:42 +00:00
export default MiaoData