miao-plugin/apps/character/profile-detail.js

112 lines
3.1 KiB
JavaScript
Raw Normal View History

2022-07-23 20:32:10 +00:00
import lodash from 'lodash'
import { autoRefresh } from './profile-common.js'
2022-08-18 10:13:42 +00:00
import { Common, Format, Profile } from '../../components/index.js'
export async function renderProfile (e, char, mode = 'profile', params = {}) {
let selfUser = await e.checkAuth({
2022-07-23 20:32:10 +00:00
auth: 'self'
})
2022-07-23 20:32:10 +00:00
let { uid } = e
if (char.isCustom) {
2022-07-23 20:32:10 +00:00
e.reply(`暂不支持自定义角色${char.name}的面板信息查看`)
return true
}
let refresh = async () => {
2022-07-23 20:32:10 +00:00
let refreshRet = await autoRefresh(e)
if (refreshRet) {
await renderProfile(e, char, mode, params)
}
2022-07-23 20:32:10 +00:00
return refreshRet
}
2022-08-18 10:13:42 +00:00
let profile = Profile.get(uid, char.id)
2022-09-10 19:59:45 +00:00
if (!profile || !profile.hasData) {
if (await refresh()) {
2022-07-23 20:32:10 +00:00
return true
} else {
2022-07-23 20:32:10 +00:00
e.reply(`请确认${char.name}已展示在【游戏内】的角色展柜中,并打开了“显示角色详情”。然后请使用 #更新面板\n命令来获取${char.name}的面板详情`)
}
2022-07-23 20:32:10 +00:00
return true
}
char = profile.char || char
2022-07-23 20:32:10 +00:00
let a = profile.attr
let c = Format.comma
let p = Format.pct
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),
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
}
let { artis, mark: totalMark, markClass: totalMarkClass, usefulMark, classTitle } = profile.getArtisMark()
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({
enemyLv,
mode,
...params
2022-07-23 20:32:10 +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)
})
lodash.forEach(dmgCalc.msg, (msg) => {
2022-07-23 20:32:10 +00:00
msg.replace(':', '')
dmgMsg.push(msg.split(''))
})
}
if (mode === 'dmg' && dmgCalc.dmgRet) {
let basic = dmgCalc?.dmgCfg?.basicRet
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-07-23 20:32:10 +00:00
})
basic.dmg = Format.comma(basic.dmg)
basic.avg = Format.comma(basic.avg)
}
2022-07-23 20:32:10 +00:00
// 渲染图像
return await Common.render('character/profile-detail', {
save_id: uid,
2022-07-23 20:32:10 +00:00
uid,
data: profile.getData('cons,level,weapon,dataSource,updateTime'),
attr,
name: char.name,
elem: char.elem,
talent: char.getAvatarTalent(profile.talent, profile.cons),
dmgData,
dmgMsg,
dmgRet: dmgCalc.dmgRet || false,
dmgCfg: dmgCalc.dmgCfg || false,
artis,
enemyLv,
imgs: char.getImgs(profile.costume),
2022-07-23 20:32:10 +00:00
enemyName: dmgCalc.enemyName || '小宝',
totalMark: c(totalMark, 1),
totalMarkClass,
classTitle,
usefulMark,
2022-07-23 20:32:10 +00:00
talentMap: { a: '普攻', e: '战技', q: '爆发' },
2022-09-10 19:59:45 +00:00
bodyClass: `char-${char.name}`,
2022-07-23 20:32:10 +00:00
mode
}, { e, scale: 1.6 })
2022-07-23 20:32:10 +00:00
}