From 3541578ed674b28914a1d3efa367dda61b766bfa Mon Sep 17 00:00:00 2001 From: yoimiya-kokomi <592981798@qq.com> Date: Tue, 2 Aug 2022 05:15:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=B7=B1=E6=B8=8A=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E4=B8=AD=E5=A2=9E=E5=8A=A0=E5=A4=A9=E8=B5=8B=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- adapter/mys.js | 11 +- apps/stat.js | 7 +- components/Common.js | 7 +- components/models/Abyss.js | 22 ++-- components/models/Avatars.js | 98 +++++++++++++++++- resources/common/common.css | 14 +-- resources/common/common.less | 2 +- resources/common/tpl.css | 41 +++++++- resources/common/tpl/avatar-card.html | 15 ++- resources/common/tpl/avatar-card.less | 46 +++++++- resources/meta/character/旅行者/face.png | Bin 0 -> 83530 bytes resources/meta/character/旅行者/face_2.png | Bin 0 -> 11753 bytes resources/meta/character/旅行者/side.png | Bin 0 -> 29063 bytes resources/meta/character/旅行者/side_2.png | Bin 0 -> 3444 bytes 14 files changed, 228 insertions(+), 35 deletions(-) create mode 100644 resources/meta/character/旅行者/face.png create mode 100644 resources/meta/character/旅行者/face_2.png create mode 100644 resources/meta/character/旅行者/side.png create mode 100644 resources/meta/character/旅行者/side_2.png diff --git a/adapter/mys.js b/adapter/mys.js index e38012d4..dea36581 100644 --- a/adapter/mys.js +++ b/adapter/mys.js @@ -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) } diff --git a/apps/stat.js b/apps/stat.js index 7fd88236..9a6012a3 100644 --- a/apps/stat.js +++ b/apps/stat.js @@ -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, diff --git a/components/Common.js b/components/Common.js index 7cae0336..fba14046 100644 --- a/components/Common.js +++ b/components/Common.js @@ -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 } diff --git a/components/models/Abyss.js b/components/models/Abyss.js index 9652d718..5727f81a 100644 --- a/components/models/Abyss.js +++ b/components/models/Abyss.js @@ -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) diff --git a/components/models/Avatars.js b/components/models/Avatars.js index f69174b4..c9cbcfeb 100644 --- a/components/models/Avatars.js +++ b/components/models/Avatars.js @@ -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 + } } diff --git a/resources/common/common.css b/resources/common/common.css index 4d537dd6..94c77e8f 100644 --- a/resources/common/common.css +++ b/resources/common/common.css @@ -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"); } diff --git a/resources/common/common.less b/resources/common/common.less index 171dd044..25c96af9 100644 --- a/resources/common/common.less +++ b/resources/common/common.less @@ -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 { diff --git a/resources/common/tpl.css b/resources/common/tpl.css index b2ea9578..58c2faa4 100644 --- a/resources/common/tpl.css +++ b/resources/common/tpl.css @@ -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; diff --git a/resources/common/tpl/avatar-card.html b/resources/common/tpl/avatar-card.html index f73f57aa..00a941fb 100644 --- a/resources/common/tpl/avatar-card.html +++ b/resources/common/tpl/avatar-card.html @@ -1,8 +1,9 @@ {{set avatar = $data[0] || {} }} {{set {_res_path} = $data[1]}} {{set weapon = avatar.weapon || {} }} +{{set talentMap = ['a','e','q'] }} -