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

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

View File

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

View File

@ -32,9 +32,14 @@ export const todoV3 = function (e) {
return false
}
function sleep (ms) {
return new Promise((resolve) => setTimeout(resolve, ms))
}
export default {
render,
cfg: Cfg.get,
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')
}
getDisplayAvatars () {
getAvatars () {
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) => {
let display = floor?.display || {}
lodash.forEach(display.up?.avatars || [], (id) => {
ret[id] = true
})
lodash.forEach(display.down?.avatars || [], (id) => {
ret[id] = true
let levels = floor?.levels || {}
lodash.forEach(levels, (level) => {
lodash.forEach(level.up?.avatars || [], (id) => {
ret[id] = true
})
lodash.forEach(level.down?.avatars || [], (id) => {
ret[id] = true
})
})
})
return lodash.keys(ret)

View File

@ -1,14 +1,21 @@
import Base from './Base.js'
import lodash from 'lodash'
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 {
constructor (datas) {
constructor (uid, datas = []) {
super()
if (!uid) {
return false
}
this.uid = uid
let avatars = {}
lodash.forEach(datas, (avatar) => {
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')
let artis = {}
let sets = {}
@ -37,7 +44,7 @@ export default class Avatars extends Base {
this.avatars = avatars
}
getData (ids, withTalent = false) {
getData (ids) {
let rets = {}
let avatars = this.avatars
lodash.forEach(ids, (id) => {
@ -45,4 +52,89 @@ export default class Avatars extends Base {
})
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;
}
/******** 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 {
background-image: url("./bg/talent-anemo.png");
}
@ -199,13 +206,6 @@ body {
.geo-bg {
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 {
background-image: url("./bg/talent-pyro.png");
}

View File

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

View File

@ -195,13 +195,48 @@
border-radius: 0 4px 0 0;
}
.avatar-card .avatar-talent {
height: 18px;
line-height: 18px;
height: 21px;
padding: 3px 5px 2px;
font-size: 12px;
width: 100%;
color: #222;
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 {
position: absolute;

View File

@ -1,8 +1,9 @@
{{set avatar = $data[0] || {} }}
{{set {_res_path} = $data[1]}}
{{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="avatar-face item-icon star{{avatar.star==4?4:5}}">
<span class="img"
@ -10,7 +11,17 @@
<span class="cons cons-{{avatar.cons}}">{{avatar.cons}}</span>
<div class="avatar-level">Lv{{avatar.level}}</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="item avatar-weapon">
<div class="item-icon star{{weapon.star}}">

View File

@ -61,20 +61,58 @@
left: 0;
padding: 2px 5px 2px 3px;
border-radius: 0 4px 0 0;
}
}
.avatar-talent {
height: 18px;
line-height: 18px;
height: 21px;
padding: 3px 5px 2px;
font-size: 12px;
width: 100%;
color: #222;
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 {

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