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

65 lines
1.3 KiB
JavaScript
Raw Normal View History

2023-10-19 09:48:52 +00:00
import { Character } from '#miao.models'
import lodash from 'lodash'
2023-02-08 20:55:54 +00:00
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)
if (!char) {
return false
}
if (player.isSr) {
avatar.setAvatar({
...ds,
...MiaoData.getTalentSR(char, ds.talent)
}, 'miao')
} else {
let talentRet = MiaoData.getTalent(char, ds.talent)
avatar.setAvatar({
...ds,
elem: talentRet.elem,
talent: talentRet.talent
}, 'miao')
}
return avatar
},
2023-02-09 16:57:25 +00:00
getTalent (char, data = {}) {
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
}
},
getTalentSR (char, data) {
let talent = {}
let trees = []
lodash.forEach(data, (lv, id) => {
let key = char.getTalentKey(id)
if (key || lv > 1) {
talent[key || id] = lv
2023-02-09 16:57:25 +00:00
} else {
trees.push(id)
}
})
return { talent, trees }
}
}
2022-08-18 10:13:42 +00:00
export default MiaoData