miao-plugin/models/player/HomoApi.js

110 lines
2.5 KiB
JavaScript
Raw Normal View History

2023-05-14 20:19:33 +00:00
import lodash from 'lodash'
import { Data } from '#miao'
import { Character } from '#miao.models'
export default {
id: 'homo',
name: 'Mihomo',
cfgKey: 'homoApi',
2023-05-14 20:19:33 +00:00
// 处理请求参数
async request (api) {
let params = {
headers: { 'User-Agent': this.getCfg('userAgent') }
}
return { api, params }
},
// 处理服务返回
async response (data, req) {
2023-06-08 08:45:07 +00:00
if (!data.detailInfo) {
2023-05-14 20:19:33 +00:00
return req.err('error', 60)
}
2023-06-08 08:45:07 +00:00
let ds = data.detailInfo
let ac = ds.assistAvatarDetail
2023-05-14 20:19:33 +00:00
let avatars = {}
if (ac && !lodash.isEmpty(ac)) {
avatars[ac.AvatarID] = ac
}
2023-06-08 08:45:07 +00:00
lodash.forEach(ds.avatarDetailList, (ds) => {
avatars[ds.avatarId] = ds
2023-05-14 20:19:33 +00:00
})
if (lodash.isEmpty(avatars)) {
return req.err('empty', 5 * 60)
}
data.avatars = avatars
return data
},
updatePlayer (player, data) {
try {
player.setBasicData(Data.getData(data, 'name:NickName,face:HeadIconID,level:Level,word:WorldLevel,sign:Signature'))
lodash.forEach(data.avatars, (ds, id) => {
let ret = HomoData.setAvatar(player, ds)
if (ret) {
player._update.push(ds.avatarId)
}
})
} catch (e) {
console.log(e)
}
2023-05-14 20:19:33 +00:00
},
// 获取冷却时间
cdTime (data) {
return data.ttl || 60
}
}
const HomoData = {
2023-05-14 20:19:33 +00:00
setAvatar (player, data) {
2023-06-08 08:45:07 +00:00
let char = Character.get(data.avatarId)
2023-05-14 20:19:33 +00:00
if (!char) {
return false
}
let avatar = player.getAvatar(char.id, true)
let setData = {
level: data.level,
2023-06-08 08:45:07 +00:00
promote: data.promotion,
cons: data.rank || 0,
weapon: Data.getData(data.equipment, 'id:tid,promote:promotion,level,affix:rank'),
...HomoData.getTalent(data.skillTreeList, char),
artis: HomoData.getArtis(data.relicList)
2023-05-14 20:19:33 +00:00
}
avatar.setAvatar(setData, 'homo')
2023-05-14 20:19:33 +00:00
return avatar
},
getTalent (ds, char) {
2023-05-14 20:19:33 +00:00
let talent = {}
let trees = []
2023-05-14 20:19:33 +00:00
lodash.forEach(ds, (d) => {
2023-06-08 08:45:07 +00:00
let key = char.getTalentKey(d.pointId)
2023-05-14 20:19:33 +00:00
if (key || d.Level > 1) {
2023-06-08 08:45:07 +00:00
talent[key || d.pointId] = d.level
2023-05-14 20:19:33 +00:00
} else {
2023-06-08 08:45:07 +00:00
trees.push(d.pointId)
2023-05-14 20:19:33 +00:00
}
})
return { talent, trees }
2023-05-14 20:19:33 +00:00
},
getArtis (artis) {
let ret = {}
lodash.forEach(artis, (ds) => {
let tmp = {
2023-06-08 08:45:07 +00:00
id: ds.tid,
level: ds.level || 1,
mainId: ds.mainAffixId,
attrIds: []
}
2023-06-08 08:45:07 +00:00
lodash.forEach(ds.subAffixList, (s) => {
if (!s.affixId) {
return true
}
2023-06-08 08:45:07 +00:00
tmp.attrIds.push([s.affixId, s.cnt, s.step || 0].join(','))
2023-05-14 20:19:33 +00:00
})
2023-06-10 01:25:44 +00:00
ret[ds.type] = tmp
2023-05-14 20:19:33 +00:00
})
return ret
}
}