上传深渊数据中增加天赋信息展示

This commit is contained in:
yoimiya-kokomi 2022-08-02 05:15:37 +08:00
parent 6df4736a63
commit 3541578ed6
14 changed files with 228 additions and 35 deletions

View File

@ -41,6 +41,7 @@ class Mys {
this.MysApi = MysApi this.MysApi = MysApi
e.targetUser = this.targetUser e.targetUser = this.targetUser
e.selfUser = this.selfUser e.selfUser = this.selfUser
e.isSelfCookie = true
} }
async getData (api, data) { async getData (api, data) {
@ -98,14 +99,18 @@ export async function getMysApi (e, cfg) {
/* 检查user ck */ /* 检查user ck */
let isCookieUser = await MysInfo.checkUidBing(uid) let isCookieUser = await MysInfo.checkUidBing(uid)
if (auth === 'cookie' && !isCookieUser) { if (auth === 'cookie') {
e.reply('尚未绑定Cookie...') if (!isCookieUser) {
return false e.reply('尚未绑定Cookie...')
return false
}
e.isSelfCookie = true
} }
let MysApi = await MysInfo.init(e, 'roleIndex') let MysApi = await MysInfo.init(e, 'roleIndex')
if (!MysApi) { if (!MysApi) {
return false return false
} }
MysApi.isSelfCookie = !!e.isSelfCookie
return new Mys(e, uid, MysApi) return new Mys(e, uid, MysApi)
} }

View File

@ -431,8 +431,8 @@ export async function uploadData (e, { render }) {
return true return true
} }
let abyss = new Abyss(resAbyss) let abyss = new Abyss(resAbyss)
let avatars = new Avatars(resDetail.avatars) let avatars = new Avatars(uid, resDetail.avatars)
let avatarIds = abyss.getDisplayAvatars() let avatarIds = abyss.getAvatars()
let addMsg = function (title, ds) { let addMsg = function (title, ds) {
let tmp = {} let tmp = {}
if (!ds && !ds.avatarId && !ds.percent) { if (!ds && !ds.avatarId && !ds.percent) {
@ -441,7 +441,6 @@ export async function uploadData (e, { render }) {
let char = Character.get(ds.avatarId) let char = Character.get(ds.avatarId)
tmp.title = title tmp.title = title
tmp.id = char.id tmp.id = char.id
avatarIds.push(char.id)
tmp.value = `${(ds.value / 10000).toFixed(1)}W` tmp.value = `${(ds.value / 10000).toFixed(1)}W`
let msg = [] let msg = []
tmp.msg = msg tmp.msg = msg
@ -466,7 +465,7 @@ export async function uploadData (e, { render }) {
} }
addMsg('最强一击', ret.data.damage || {}) addMsg('最强一击', ret.data.damage || {})
addMsg('最高承伤', ret.data.takeDamage || {}) addMsg('最高承伤', ret.data.takeDamage || {})
let avatarData = avatars.getData(avatarIds, true) let avatarData = await avatars.getTalentData(avatarIds, MysApi)
return await Common.render('stat/abyss-summary', { return await Common.render('stat/abyss-summary', {
abyss: abyss.getData(), abyss: abyss.getData(),
avatars: avatarData, avatars: avatarData,

View File

@ -32,9 +32,14 @@ export const todoV3 = function (e) {
return false return false
} }
function sleep (ms) {
return new Promise((resolve) => setTimeout(resolve, ms))
}
export default { export default {
render, render,
cfg: Cfg.get, cfg: Cfg.get,
isDisable: Cfg.isDisable, isDisable: Cfg.isDisable,
todoV3 todoV3,
sleep
} }

View File

@ -59,15 +59,23 @@ export default class Abyss extends Base {
return Data.getData(this, 'reveral,stat,floors') return Data.getData(this, 'reveral,stat,floors')
} }
getDisplayAvatars () { getAvatars () {
let ret = {} let ret = {}
lodash.forEach(this.reveral, (ds) => {
ret[ds.id] = true
})
lodash.forEach(this.stat, (ds) => {
ret[ds.id] = true
})
lodash.forEach(this.floors, (floor) => { lodash.forEach(this.floors, (floor) => {
let display = floor?.display || {} let levels = floor?.levels || {}
lodash.forEach(display.up?.avatars || [], (id) => { lodash.forEach(levels, (level) => {
ret[id] = true lodash.forEach(level.up?.avatars || [], (id) => {
}) ret[id] = true
lodash.forEach(display.down?.avatars || [], (id) => { })
ret[id] = true lodash.forEach(level.down?.avatars || [], (id) => {
ret[id] = true
})
}) })
}) })
return lodash.keys(ret) return lodash.keys(ret)

View File

@ -1,14 +1,21 @@
import Base from './Base.js' import Base from './Base.js'
import lodash from 'lodash' import lodash from 'lodash'
import Data from '../Data.js' import Data from '../Data.js'
import Artifact from './Artifact.js'; import Artifact from './Artifact.js'
import Character from './Character.js'
import Common from '../Common.js'
export default class Avatars extends Base { export default class Avatars extends Base {
constructor (datas) { constructor (uid, datas = []) {
super() super()
if (!uid) {
return false
}
this.uid = uid
let avatars = {} let avatars = {}
lodash.forEach(datas, (avatar) => { lodash.forEach(datas, (avatar) => {
let data = Data.getData(avatar, 'id,name,level,star:rarity,cons:actived_constellation_num,fetter') let data = Data.getData(avatar, 'id,name,level,star:rarity,cons:actived_constellation_num,fetter')
data.elem = (avatar.element || '').toLowerCase() || 'hydro'
data.weapon = Data.getData(avatar.weapon, 'name,affix:affix_level,level,star:rarity') data.weapon = Data.getData(avatar.weapon, 'name,affix:affix_level,level,star:rarity')
let artis = {} let artis = {}
let sets = {} let sets = {}
@ -37,7 +44,7 @@ export default class Avatars extends Base {
this.avatars = avatars this.avatars = avatars
} }
getData (ids, withTalent = false) { getData (ids) {
let rets = {} let rets = {}
let avatars = this.avatars let avatars = this.avatars
lodash.forEach(ids, (id) => { lodash.forEach(ids, (id) => {
@ -45,4 +52,89 @@ export default class Avatars extends Base {
}) })
return rets return rets
} }
async getTalentData (ids, MysApi = false) {
let avatarTalent = {}
let talentCache = await redis.get(`genshin:avatar-talent:${this.uid}`)
if (talentCache) {
avatarTalent = JSON.parse(talentCache)
}
let needReq = {}
lodash.forEach(ids, (id) => {
if (!avatarTalent[id]) {
needReq[id] = true
}
})
let needReqIds = lodash.keys(needReq)
if (needReqIds.length > 0 && MysApi && MysApi.isSelfCookie) {
let num = 10
let ms = 100
let skillRet = []
let avatarArr = lodash.chunk(needReqIds, num)
for (let val of avatarArr) {
for (let id of val) {
skillRet.push(this.getAvatarTalent(id, MysApi))
}
skillRet = await Promise.all(skillRet)
skillRet = skillRet.filter(item => item.id)
await Common.sleep(ms)
}
lodash.forEach(skillRet, (talent) => {
avatarTalent[talent.id] = talent
})
await redis.set(`genshin:avatar-talent:${this.uid}`, JSON.stringify(avatarTalent), { EX: 3600 * 2 })
}
let ret = this.getData(ids)
lodash.forEach(ret, (avatar, id) => {
avatar.talent = avatarTalent[id] || { a: {}, e: {}, q: {} }
})
return ret
}
async getAvatarTalent (id, MysApi) {
let talent = { id, a: {}, e: {}, q: {} }
let talentRes = await MysApi.getDetail(id)
let char = Character.get(id)
let avatar = this.avatars[id]
if (!char || !avatar) {
return talent
}
let consTalent = char.getConsTalent()
if (talentRes && talentRes.skill_list) {
talent.id = id
let talentList = lodash.orderBy(talentRes.skill_list, ['id'], ['asc'])
for (let val of talentList) {
let { max_level: maxLv, level_current: lv } = val
let ds = {
current: lv,
original: lv,
crown: lv === maxLv
}
if (val.name.includes('普通攻击')) {
talent.a = ds
continue
}
if (maxLv >= 10 && !talent.e?.current) {
talent.e = ds
continue
}
if (maxLv >= 10 && !talent.q?.current) {
talent.q = ds
continue
}
}
lodash.forEach([3, 5], (c) => {
if (avatar.cons >= c) {
if (consTalent.e === c) {
talent.e.current += 3
talent.e.plus = true
} else if (consTalent.q === c) {
talent.q.current += 3
talent.q.plus = true
}
}
})
}
return talent
}
} }

View File

@ -171,6 +171,13 @@ body {
color: #fff; color: #fff;
} }
/******** ELEM ********/ /******** ELEM ********/
.elem-hydro .talent-icon {
background-image: url("./bg/talent-hydro.png");
}
.elem-hydro .elem-bg,
.hydro-bg {
background-image: url("./bg/bg-hydro.jpg");
}
.elem-anemo .talent-icon { .elem-anemo .talent-icon {
background-image: url("./bg/talent-anemo.png"); background-image: url("./bg/talent-anemo.png");
} }
@ -199,13 +206,6 @@ body {
.geo-bg { .geo-bg {
background-image: url("./bg/bg-geo.jpg"); background-image: url("./bg/bg-geo.jpg");
} }
.elem-hydro .talent-icon {
background-image: url("./bg/talent-hydro.png");
}
.elem-hydro .elem-bg,
.hydro-bg {
background-image: url("./bg/bg-hydro.jpg");
}
.elem-pyro .talent-icon { .elem-pyro .talent-icon {
background-image: url("./bg/talent-pyro.png"); background-image: url("./bg/talent-pyro.png");
} }

View File

@ -162,7 +162,7 @@ body {
/******** ELEM ********/ /******** ELEM ********/
@elems: anemo, cryo, electro, geo, hydro, pyro, dendro; @elems: hydro, anemo, cryo, electro, geo, pyro, dendro;
each(@elems, { each(@elems, {
.elem-@{value} .talent-icon { .elem-@{value} .talent-icon {

View File

@ -195,13 +195,48 @@
border-radius: 0 4px 0 0; border-radius: 0 4px 0 0;
} }
.avatar-card .avatar-talent { .avatar-card .avatar-talent {
height: 18px; height: 21px;
line-height: 18px; padding: 3px 5px 2px;
font-size: 12px; font-size: 12px;
width: 100%; width: 100%;
color: #222; color: #222;
text-align: center; text-align: center;
display: none; display: flex;
}
.avatar-card .avatar-talent .talent-item {
width: 20px;
height: 16px;
line-height: 17px;
margin: 0 2px;
text-align: center;
display: block;
background-size: contain;
opacity: 0.8;
position: relative;
border-radius: 3px;
box-shadow: 0 0 1px 0 rgba(0, 0, 0, 0.5);
/*
&.talent-crown:before {
content: "";
display: block;
width: 10px;
height: 10px;
position: absolute;
left: 0;
top: 0;
background: url("../character/imgs/crown.png") center no-repeat;
background-size: contain;
}
*/
}
.avatar-card .avatar-talent .talent-item.talent-plus {
font-weight: bold;
color: #0284b9;
}
.avatar-card .avatar-talent .talent-item.talent-crown {
background: #d3bc8e;
color: #3a2702;
box-shadow: 0 0 2px 0 #000;
} }
.avatar-card .cons { .avatar-card .cons {
position: absolute; position: absolute;

View File

@ -1,8 +1,9 @@
{{set avatar = $data[0] || {} }} {{set avatar = $data[0] || {} }}
{{set {_res_path} = $data[1]}} {{set {_res_path} = $data[1]}}
{{set weapon = avatar.weapon || {} }} {{set weapon = avatar.weapon || {} }}
{{set talentMap = ['a','e','q'] }}
<div class="avatar-card"> <div class="avatar-card elem-{{avatar.elem}} avatar-{{avatar.name}}">
<div class="card"> <div class="card">
<div class="avatar-face item-icon star{{avatar.star==4?4:5}}"> <div class="avatar-face item-icon star{{avatar.star==4?4:5}}">
<span class="img" <span class="img"
@ -10,7 +11,17 @@
<span class="cons cons-{{avatar.cons}}">{{avatar.cons}}</span> <span class="cons cons-{{avatar.cons}}">{{avatar.cons}}</span>
<div class="avatar-level">Lv{{avatar.level}}</div> <div class="avatar-level">Lv{{avatar.level}}</div>
</div> </div>
<div class="avatar-talent">10-13-13</div> {{set talent = avatar.talent || {} }}
{{if talent.a && talent.a.current }}
<div class="avatar-talent">
{{each talentMap k}}
{{set t = talent[k] || {} }}
<span class="talent-item talent-{{k}} talent-{{t.crown?'crown':'none'}} talent-{{t.plus?'plus':'none'}}">{{t.current}}</span>
{{/each}}
</div>
{{else}}
<div class="avatar-talent"> -</div>
{{/if}}
<div class="avatar-detail"> <div class="avatar-detail">
<div class="item avatar-weapon"> <div class="item avatar-weapon">
<div class="item-icon star{{weapon.star}}"> <div class="item-icon star{{weapon.star}}">

View File

@ -61,20 +61,58 @@
left: 0; left: 0;
padding: 2px 5px 2px 3px; padding: 2px 5px 2px 3px;
border-radius: 0 4px 0 0; border-radius: 0 4px 0 0;
} }
} }
.avatar-talent { .avatar-talent {
height: 18px; height: 21px;
line-height: 18px; padding: 3px 5px 2px;
font-size: 12px; font-size: 12px;
width: 100%; width: 100%;
color: #222; color: #222;
text-align: center; text-align: center;
display: none; display: flex;
.talent-item {
width: 20px;
height: 16px;
line-height: 17px;
margin: 0 2px;
text-align: center;
display: block;
background-size: contain;
opacity: 0.8;
position: relative;
border-radius: 3px;
box-shadow: 0 0 1px 0 rgba(0, 0, 0, 0.5);
/*
&.talent-crown:before {
content: "";
display: block;
width: 10px;
height: 10px;
position: absolute;
left: 0;
top: 0;
background: url("../character/imgs/crown.png") center no-repeat;
background-size: contain;
}
*/
&.talent-plus {
font-weight: bold;
color: #0284b9;
}
&.talent-crown {
background: #d3bc8e;
color: #3a2702;
box-shadow: 0 0 2px 0 #000;
}
}
} }
.cons { .cons {

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB