2022-08-18 10:13:42 +00:00
|
|
|
|
import { Artifact, Character } from '../../models/index.js'
|
2022-07-23 20:32:10 +00:00
|
|
|
|
import { Cfg, Data, Common, Profile } from '../../components/index.js'
|
|
|
|
|
import lodash from 'lodash'
|
|
|
|
|
import { segment } from 'oicq'
|
2022-06-25 23:45:43 +00:00
|
|
|
|
|
2022-07-23 20:32:10 +00:00
|
|
|
|
// 角色昵称
|
2022-06-25 23:45:43 +00:00
|
|
|
|
|
2022-07-23 20:32:10 +00:00
|
|
|
|
let abbr = Character.getAbbr()
|
2022-06-25 23:45:43 +00:00
|
|
|
|
|
2022-07-23 20:32:10 +00:00
|
|
|
|
export async function renderAvatar (e, avatar, render, renderType = 'card') {
|
2022-06-25 23:45:43 +00:00
|
|
|
|
// 如果传递的是名字,则获取
|
2022-07-23 20:32:10 +00:00
|
|
|
|
if (typeof (avatar) === 'string') {
|
|
|
|
|
let char = Character.get(avatar)
|
2022-06-25 23:45:43 +00:00
|
|
|
|
if (!char) {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
return false
|
2022-06-25 23:45:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let MysApi = await e.getMysApi({
|
2022-07-23 20:32:10 +00:00
|
|
|
|
auth: 'all',
|
|
|
|
|
targetType: Cfg.get('char.queryOther', true) ? 'all' : 'self',
|
|
|
|
|
cookieType: 'all',
|
|
|
|
|
actionName: '查询信息'
|
|
|
|
|
})
|
2022-06-29 20:40:06 +00:00
|
|
|
|
|
2022-07-23 20:32:10 +00:00
|
|
|
|
if (!MysApi) return true
|
2022-06-25 23:45:43 +00:00
|
|
|
|
|
2022-07-23 20:32:10 +00:00
|
|
|
|
let uid = MysApi.targetUser.uid
|
2022-06-25 23:45:43 +00:00
|
|
|
|
|
2022-06-29 23:05:31 +00:00
|
|
|
|
if (char.isCustom) {
|
|
|
|
|
avatar = { id: char.id, name: char.name, detail: false }
|
2022-06-29 20:40:06 +00:00
|
|
|
|
} else {
|
2022-08-18 10:13:42 +00:00
|
|
|
|
let profile = Profile.get(uid, char.id, true)
|
2022-06-29 23:05:31 +00:00
|
|
|
|
if (profile) {
|
|
|
|
|
// 优先使用Profile数据
|
2022-07-23 20:32:10 +00:00
|
|
|
|
avatar = profile
|
2022-06-29 23:05:31 +00:00
|
|
|
|
} else {
|
|
|
|
|
// 使用Mys数据兜底
|
2022-07-23 20:32:10 +00:00
|
|
|
|
let charData = await MysApi.getCharacter()
|
|
|
|
|
if (!charData) return true
|
|
|
|
|
|
|
|
|
|
let avatars = charData.avatars
|
|
|
|
|
char.checkAvatars(avatars)
|
|
|
|
|
avatars = lodash.keyBy(avatars, 'id')
|
|
|
|
|
avatar = avatars[char.id] || { id: char.id, name: char.name, detail: false }
|
2022-06-29 23:05:31 +00:00
|
|
|
|
}
|
2022-06-25 23:45:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-07-23 20:32:10 +00:00
|
|
|
|
return await renderCard(e, avatar, render, renderType)
|
2022-06-25 23:45:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 渲染角色卡片
|
2022-07-23 20:32:10 +00:00
|
|
|
|
async function renderCard (e, avatar, render, renderType = 'card') {
|
|
|
|
|
let char = Character.get(avatar)
|
2022-06-25 23:45:43 +00:00
|
|
|
|
|
|
|
|
|
if (!char) {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
return false
|
2022-06-25 23:45:43 +00:00
|
|
|
|
}
|
2022-07-23 20:32:10 +00:00
|
|
|
|
let uid = e.uid || (e.targetUser && e.targetUser.uid)
|
2022-06-25 23:45:43 +00:00
|
|
|
|
|
2022-07-23 20:32:10 +00:00
|
|
|
|
let crownNum = 0;
|
|
|
|
|
let talent = {}
|
2022-06-29 23:05:31 +00:00
|
|
|
|
if (!char.isCustom) {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
talent = await getTalent(e, avatar)
|
2022-06-29 23:05:31 +00:00
|
|
|
|
// 计算皇冠个数
|
2022-07-23 20:32:10 +00:00
|
|
|
|
crownNum = lodash.filter(lodash.map(talent, (d) => d.original), (d) => d >= 10).length
|
2022-06-29 23:05:31 +00:00
|
|
|
|
}
|
2022-07-23 20:32:10 +00:00
|
|
|
|
let bg = char.getCardImg(Cfg.get('char.se', false))
|
|
|
|
|
if (renderType === 'photo') {
|
|
|
|
|
e.reply(segment.image(process.cwd() + '/plugins/miao-plugin/resources/' + bg.img))
|
2022-06-25 23:45:43 +00:00
|
|
|
|
} else {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
// 渲染图像
|
|
|
|
|
let msgRes = await Common.render('character/card', {
|
2022-06-25 23:45:43 +00:00
|
|
|
|
save_id: uid,
|
|
|
|
|
uid,
|
|
|
|
|
talent,
|
|
|
|
|
crownNum,
|
2022-07-23 20:32:10 +00:00
|
|
|
|
talentMap: { a: '普攻', e: '战技', q: '爆发' },
|
2022-06-25 23:45:43 +00:00
|
|
|
|
bg,
|
2022-06-29 23:05:31 +00:00
|
|
|
|
custom: char.isCustom,
|
2022-06-25 23:45:43 +00:00
|
|
|
|
...getCharacterData(avatar),
|
2022-07-23 20:32:10 +00:00
|
|
|
|
ds: char.getData('name,id,title,desc')
|
2022-07-30 21:06:00 +00:00
|
|
|
|
}, { e, render, scale: 1.6, retMsgId: true })
|
2022-06-25 23:45:43 +00:00
|
|
|
|
if (msgRes && msgRes.message_id) {
|
|
|
|
|
// 如果消息发送成功,就将message_id和图片路径存起来,1小时过期
|
2022-07-23 20:32:10 +00:00
|
|
|
|
await redis.set(`miao:original-picture:${msgRes.message_id}`, bg.img, { EX: 3600 })
|
2022-06-25 23:45:43 +00:00
|
|
|
|
}
|
2022-07-23 20:32:10 +00:00
|
|
|
|
return true
|
2022-06-25 23:45:43 +00:00
|
|
|
|
}
|
2022-07-23 20:32:10 +00:00
|
|
|
|
return true
|
2022-06-25 23:45:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-23 20:32:10 +00:00
|
|
|
|
// 获取角色技能数据
|
|
|
|
|
async function getTalent (e, avatars) {
|
|
|
|
|
let talent = {};
|
|
|
|
|
let cons = 0;
|
|
|
|
|
let char = Character.get(avatars.id);
|
|
|
|
|
let mode = 'level'
|
2022-06-29 23:05:31 +00:00
|
|
|
|
if (char.isCustom) {
|
|
|
|
|
return {}
|
|
|
|
|
}
|
2022-06-29 20:40:06 +00:00
|
|
|
|
if (avatars.dataSource && avatars.talent) {
|
|
|
|
|
// profile模式
|
2022-07-23 20:32:10 +00:00
|
|
|
|
talent = avatars.talent || {}
|
|
|
|
|
cons = avatars.cons || 0
|
2022-06-29 20:40:06 +00:00
|
|
|
|
} else {
|
|
|
|
|
let MysApi = await e.getMysApi({
|
2022-07-23 20:32:10 +00:00
|
|
|
|
auth: 'all',
|
|
|
|
|
targetType: Cfg.get('char.queryOther', true) ? 'all' : 'self',
|
|
|
|
|
cookieType: 'all',
|
|
|
|
|
actionName: '查询信息'
|
|
|
|
|
})
|
|
|
|
|
if (!MysApi && !MysApi.isSelfCookie) return {}
|
|
|
|
|
let skillRes = await MysApi.getAvatar(avatars.id)
|
2022-06-29 20:40:06 +00:00
|
|
|
|
cons = avatars.actived_constellation_num
|
2022-07-23 20:32:10 +00:00
|
|
|
|
mode = 'original'
|
2022-06-29 20:40:06 +00:00
|
|
|
|
if (skillRes && skillRes.skill_list) {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
let skillList = lodash.orderBy(skillRes.skill_list, ['id'], ['asc'])
|
|
|
|
|
for (let val of skillList) {
|
|
|
|
|
if (val.name.includes('普通攻击')) {
|
|
|
|
|
talent.a = val
|
|
|
|
|
continue
|
2022-06-29 20:40:06 +00:00
|
|
|
|
}
|
|
|
|
|
if (val.max_level >= 10 && !talent.e) {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
talent.e = val
|
|
|
|
|
continue
|
2022-06-29 20:40:06 +00:00
|
|
|
|
}
|
|
|
|
|
if (val.max_level >= 10 && !talent.q) {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
talent.q = val
|
2022-06-29 20:40:06 +00:00
|
|
|
|
}
|
2022-06-25 23:45:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-06-29 23:05:31 +00:00
|
|
|
|
|
2022-07-23 20:32:10 +00:00
|
|
|
|
return char.getAvatarTalent(talent, cons, mode)
|
2022-06-25 23:45:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 获取角色数据
|
|
|
|
|
* */
|
2022-07-23 20:32:10 +00:00
|
|
|
|
function getCharacterData (avatars) {
|
|
|
|
|
let list = []
|
|
|
|
|
let set = {}
|
|
|
|
|
let artiEffect = []
|
|
|
|
|
let w = avatars.weapon || {}
|
2022-06-25 23:45:43 +00:00
|
|
|
|
let weapon = {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
type: 'weapon',
|
|
|
|
|
name: w.name || '',
|
|
|
|
|
showName: abbr[w.name] || w.name || '',
|
2022-06-29 20:40:06 +00:00
|
|
|
|
level: w.level || 1,
|
|
|
|
|
affix: w.affix || w.affix_level || 0
|
|
|
|
|
}
|
2022-06-25 23:45:43 +00:00
|
|
|
|
|
2022-08-18 21:04:31 +00:00
|
|
|
|
let artis = avatars?.artis?.artis || avatars.reliquaries
|
2022-06-25 23:45:43 +00:00
|
|
|
|
|
2022-06-29 20:40:06 +00:00
|
|
|
|
if (artis) {
|
|
|
|
|
lodash.forEach(artis, (val) => {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
let setCfg = Artifact.getSetByArti(val.name)
|
2022-06-29 20:40:06 +00:00
|
|
|
|
if (!setCfg) {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
return
|
2022-06-29 20:40:06 +00:00
|
|
|
|
}
|
2022-07-23 20:32:10 +00:00
|
|
|
|
let setName = setCfg.name
|
2022-06-29 20:40:06 +00:00
|
|
|
|
if (set[setName]) {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
set[setName]++
|
2022-06-29 20:40:06 +00:00
|
|
|
|
if (set[setName] === 2) {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
artiEffect.push('2件套:' + setCfg.effect['2'])
|
2022-06-25 23:45:43 +00:00
|
|
|
|
}
|
2022-06-29 20:40:06 +00:00
|
|
|
|
if (set[setName] === 4) {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
artiEffect.push('4件套:' + setCfg.name)
|
2022-06-29 20:40:06 +00:00
|
|
|
|
}
|
|
|
|
|
} else {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
set[setName] = 1
|
2022-06-25 23:45:43 +00:00
|
|
|
|
}
|
2022-06-29 20:40:06 +00:00
|
|
|
|
})
|
2022-06-25 23:45:43 +00:00
|
|
|
|
|
2022-06-29 20:40:06 +00:00
|
|
|
|
if (artiEffect.length === 0) {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
artiEffect = ['无套装效果']
|
2022-06-25 23:45:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-23 20:32:10 +00:00
|
|
|
|
if (avatars.id == '10000005') {
|
|
|
|
|
avatars.name = '空'
|
|
|
|
|
} else if (avatars.id == '10000007') {
|
|
|
|
|
avatars.name = '荧'
|
2022-06-25 23:45:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-23 20:32:10 +00:00
|
|
|
|
let reliquaries = list[0]
|
2022-06-25 23:45:43 +00:00
|
|
|
|
return {
|
|
|
|
|
name: avatars.name,
|
2022-07-23 20:32:10 +00:00
|
|
|
|
showName: abbr[avatars.name] ? abbr[avatars.name] : avatars.name,
|
2022-06-30 18:53:05 +00:00
|
|
|
|
level: Data.def(avatars.lv, avatars.level),
|
2022-06-25 23:45:43 +00:00
|
|
|
|
fetter: avatars.fetter,
|
2022-06-30 18:53:05 +00:00
|
|
|
|
cons: Data.def(avatars.cons, avatars.actived_constellation_num),
|
2022-06-25 23:45:43 +00:00
|
|
|
|
weapon,
|
2022-06-29 20:40:06 +00:00
|
|
|
|
artiEffect,
|
|
|
|
|
reliquaries
|
2022-07-23 20:32:10 +00:00
|
|
|
|
}
|
2022-06-25 23:45:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-23 20:32:10 +00:00
|
|
|
|
export async function getAvatarList (e, type, MysApi) {
|
|
|
|
|
let data = await MysApi.getCharacter()
|
|
|
|
|
if (!data) return false
|
2022-06-25 23:45:43 +00:00
|
|
|
|
|
2022-07-23 20:32:10 +00:00
|
|
|
|
let avatars = data.avatars
|
2022-06-25 23:45:43 +00:00
|
|
|
|
|
|
|
|
|
if (avatars.length <= 0) {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
return false
|
2022-06-25 23:45:43 +00:00
|
|
|
|
}
|
2022-07-23 20:32:10 +00:00
|
|
|
|
let list = []
|
2022-06-25 23:45:43 +00:00
|
|
|
|
for (let val of avatars) {
|
|
|
|
|
if (type !== false) {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
if (!Character.checkWifeType(val.id, type)) {
|
|
|
|
|
continue
|
2022-06-25 23:45:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (val.rarity > 5) {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
val.rarity = 5
|
2022-06-25 23:45:43 +00:00
|
|
|
|
}
|
2022-07-23 20:32:10 +00:00
|
|
|
|
list.push(val)
|
2022-06-25 23:45:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (list.length <= 0) {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
return false
|
2022-06-25 23:45:43 +00:00
|
|
|
|
}
|
2022-07-23 20:32:10 +00:00
|
|
|
|
let sortKey = 'level,fetter,weapon_level,rarity,weapon_rarity,cons,weapon_affix_level'
|
|
|
|
|
list = lodash.orderBy(list, sortKey, lodash.repeat('desc,', sortKey.length).split(','))
|
|
|
|
|
return list
|
2022-06-25 23:45:43 +00:00
|
|
|
|
}
|