2022-07-23 20:32:10 +00:00
|
|
|
|
import lodash from 'lodash'
|
2022-10-06 22:20:46 +00:00
|
|
|
|
import { autoRefresh } from './ProfileCommon.js'
|
2022-08-18 10:13:42 +00:00
|
|
|
|
import { Common, Format, Profile } from '../../components/index.js'
|
2022-11-23 20:26:07 +00:00
|
|
|
|
import { MysApi, Avatar, ProfileRank, ProfileArtis } from '../../models/index.js'
|
2022-06-25 23:45:43 +00:00
|
|
|
|
|
2022-08-24 01:07:06 +00:00
|
|
|
|
export async function renderProfile (e, char, mode = 'profile', params = {}) {
|
2022-09-20 11:50:27 +00:00
|
|
|
|
let selfUser = await MysApi.initUser(e)
|
2022-06-25 23:45:43 +00:00
|
|
|
|
|
2022-09-27 02:25:31 +00:00
|
|
|
|
if (!selfUser) {
|
|
|
|
|
e.reply('尚未绑定UID')
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-23 20:32:10 +00:00
|
|
|
|
let { uid } = e
|
2022-06-25 23:45:43 +00:00
|
|
|
|
|
2022-06-29 23:05:31 +00:00
|
|
|
|
if (char.isCustom) {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
e.reply(`暂不支持自定义角色${char.name}的面板信息查看`)
|
|
|
|
|
return true
|
2022-06-29 23:05:31 +00:00
|
|
|
|
}
|
2022-06-25 23:45:43 +00:00
|
|
|
|
|
2022-11-26 08:12:32 +00:00
|
|
|
|
let profile = e._profile || Profile.get(uid, char.id)
|
|
|
|
|
|
2022-06-25 23:45:43 +00:00
|
|
|
|
let refresh = async () => {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
let refreshRet = await autoRefresh(e)
|
2022-06-25 23:45:43 +00:00
|
|
|
|
if (refreshRet) {
|
2022-08-24 01:07:06 +00:00
|
|
|
|
await renderProfile(e, char, mode, params)
|
2022-06-25 23:45:43 +00:00
|
|
|
|
}
|
2022-07-23 20:32:10 +00:00
|
|
|
|
return refreshRet
|
2022-06-25 23:45:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-09-10 19:59:45 +00:00
|
|
|
|
if (!profile || !profile.hasData) {
|
2022-06-25 23:45:43 +00:00
|
|
|
|
if (await refresh()) {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
return true
|
2022-06-25 23:45:43 +00:00
|
|
|
|
} else {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
e.reply(`请确认${char.name}已展示在【游戏内】的角色展柜中,并打开了“显示角色详情”。然后请使用 #更新面板\n命令来获取${char.name}的面板详情`)
|
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-09-24 12:19:59 +00:00
|
|
|
|
let avatar = new Avatar(profile)
|
2022-09-04 04:02:51 +00:00
|
|
|
|
char = profile.char || char
|
2022-07-23 20:32:10 +00:00
|
|
|
|
let a = profile.attr
|
|
|
|
|
let c = Format.comma
|
|
|
|
|
let p = Format.pct
|
2022-06-25 23:45:43 +00:00
|
|
|
|
let attr = {
|
|
|
|
|
hp: c(a.hp),
|
|
|
|
|
hpPlus: c(a.hp - a.hpBase),
|
|
|
|
|
atk: c(a.atk),
|
|
|
|
|
atkPlus: c(a.atk - a.atkBase),
|
|
|
|
|
def: c(a.def),
|
|
|
|
|
defPlus: c(a.def - a.defBase),
|
2022-08-18 10:13:42 +00:00
|
|
|
|
cpct: p(a.cpct),
|
|
|
|
|
cdmg: p(a.cdmg),
|
2022-06-25 23:45:43 +00:00
|
|
|
|
mastery: c(a.mastery),
|
|
|
|
|
recharge: p(a.recharge),
|
2022-08-18 10:13:42 +00:00
|
|
|
|
dmg: p(Math.max(a.dmg * 1 || 0, a.phy * 1 || 0))
|
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 enemyLv = await selfUser.getCfg('char.enemyLv', 91)
|
|
|
|
|
let dmgMsg = []
|
|
|
|
|
let dmgData = []
|
2022-08-18 10:13:42 +00:00
|
|
|
|
let dmgCalc = await profile.calcDmg({
|
2022-06-25 23:45:43 +00:00
|
|
|
|
enemyLv,
|
|
|
|
|
mode,
|
|
|
|
|
...params
|
2022-07-23 20:32:10 +00:00
|
|
|
|
})
|
2022-06-25 23:45:43 +00:00
|
|
|
|
if (dmgCalc && dmgCalc.ret) {
|
|
|
|
|
lodash.forEach(dmgCalc.ret, (ds) => {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
ds.dmg = Format.comma(ds.dmg, 0)
|
|
|
|
|
ds.avg = Format.comma(ds.avg, 0)
|
|
|
|
|
dmgData.push(ds)
|
2022-06-25 23:45:43 +00:00
|
|
|
|
})
|
|
|
|
|
lodash.forEach(dmgCalc.msg, (msg) => {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
msg.replace(':', ':')
|
|
|
|
|
dmgMsg.push(msg.split(':'))
|
2022-06-25 23:45:43 +00:00
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-08 21:16:37 +00:00
|
|
|
|
if (mode === 'dmg' && dmgCalc.dmgRet) {
|
|
|
|
|
let basic = dmgCalc?.dmgCfg?.basicRet
|
2022-06-25 23:45:43 +00:00
|
|
|
|
lodash.forEach(dmgCalc.dmgRet, (row) => {
|
|
|
|
|
lodash.forEach(row, (ds) => {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
ds.val = (ds.avg > basic.avg ? '+' : '') + Format.comma(ds.avg - basic.avg)
|
|
|
|
|
ds.dmg = Format.comma(ds.dmg, 0)
|
|
|
|
|
ds.avg = Format.comma(ds.avg, 0)
|
2022-06-25 23:45:43 +00:00
|
|
|
|
})
|
2022-07-23 20:32:10 +00:00
|
|
|
|
})
|
|
|
|
|
basic.dmg = Format.comma(basic.dmg)
|
|
|
|
|
basic.avg = Format.comma(basic.avg)
|
2022-06-25 23:45:43 +00:00
|
|
|
|
}
|
2022-11-07 20:16:30 +00:00
|
|
|
|
let rank = false
|
2022-11-26 08:12:32 +00:00
|
|
|
|
if (e.group_id && !e._profile) {
|
2022-11-07 20:16:30 +00:00
|
|
|
|
rank = await ProfileRank.create({ group: e.group_id, uid, qq: e.user_id })
|
|
|
|
|
await rank.getRank(profile, true)
|
|
|
|
|
}
|
2022-11-23 20:26:07 +00:00
|
|
|
|
|
|
|
|
|
let artisDetail = profile.getArtisMark()
|
|
|
|
|
let artisKeyTitle = ProfileArtis.getArtisKeyTitle()
|
2022-11-29 19:44:09 +00:00
|
|
|
|
let imgs = char.getImgs(profile.costume)
|
2022-07-23 20:32:10 +00:00
|
|
|
|
// 渲染图像
|
2022-12-03 19:45:50 +00:00
|
|
|
|
let msgRes = await Common.render('character/profile-detail', {
|
2022-06-25 23:45:43 +00:00
|
|
|
|
save_id: uid,
|
2022-07-23 20:32:10 +00:00
|
|
|
|
uid,
|
2022-11-24 16:31:36 +00:00
|
|
|
|
data: avatar.getData('name,abbr,cons,level,weapon,talent,dataSource,updateTime,_attrCalc'),
|
2022-06-25 23:45:43 +00:00
|
|
|
|
attr,
|
|
|
|
|
elem: char.elem,
|
|
|
|
|
dmgData,
|
|
|
|
|
dmgMsg,
|
2022-08-08 21:16:37 +00:00
|
|
|
|
dmgRet: dmgCalc.dmgRet || false,
|
|
|
|
|
dmgCfg: dmgCalc.dmgCfg || false,
|
2022-11-23 20:26:07 +00:00
|
|
|
|
artisDetail,
|
|
|
|
|
artisKeyTitle,
|
2022-06-25 23:45:43 +00:00
|
|
|
|
enemyLv,
|
2022-11-29 19:44:09 +00:00
|
|
|
|
imgs,
|
2022-07-23 20:32:10 +00:00
|
|
|
|
enemyName: dmgCalc.enemyName || '小宝',
|
|
|
|
|
talentMap: { a: '普攻', e: '战技', q: '爆发' },
|
2022-09-10 19:59:45 +00:00
|
|
|
|
bodyClass: `char-${char.name}`,
|
2022-11-26 08:12:32 +00:00
|
|
|
|
mode,
|
|
|
|
|
changeProfile: e._profileMsg
|
2022-12-03 19:45:50 +00:00
|
|
|
|
}, { e, scale: 1.6,retMsgId: true })
|
|
|
|
|
if (msgRes && msgRes.message_id) {
|
|
|
|
|
// 如果消息发送成功,就将message_id和图片路径存起来,3小时过期
|
|
|
|
|
await redis.set(`miao:original-picture:${msgRes.message_id}`, imgs.splash0, { EX: 3600 * 3 })
|
|
|
|
|
}
|
|
|
|
|
return true
|
2022-07-23 20:32:10 +00:00
|
|
|
|
}
|