From 78e874aa6370a33cf863bdee4bdaf1d50657e6ee Mon Sep 17 00:00:00 2001 From: Kokomi <592981798@qq.com> Date: Thu, 2 Jun 2022 18:25:09 +0800 Subject: [PATCH] =?UTF-8?q?*=20`#=E6=9B=B4=E6=96=B0=E5=85=A8=E9=83=A8?= =?UTF-8?q?=E9=9D=A2=E6=9D=BF`=20=E5=8A=9F=E8=83=BD=E6=9A=82=E6=97=B6?= =?UTF-8?q?=E6=81=A2=E5=A4=8D=20=20=20*=20=E7=9B=AE=E5=89=8D=E5=8F=AF?= =?UTF-8?q?=E7=9B=B4=E6=8E=A5=E4=BD=BF=E7=94=A8=EF=BC=8C=E6=97=A0=E9=9C=80?= =?UTF-8?q?token=20=20=20*=20=E9=83=A8=E5=88=86=E7=BD=91=E7=BB=9C=E5=8F=AF?= =?UTF-8?q?=E8=83=BD=E6=97=A0=E6=B3=95=E8=AF=B7=E6=B1=82=EF=BC=8C=E7=AD=89?= =?UTF-8?q?=E5=BE=85=E5=90=8E=E7=BB=AD=E6=9C=8D=E5=8A=A1=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=20=20=20*=20=E7=94=B1=E4=BA=8E=E6=9C=8D=E5=8A=A1=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E4=B8=8E=E4=B9=8B=E5=89=8D=E6=95=B0=E6=8D=AE=E4=B8=8D?= =?UTF-8?q?=E4=B8=80=E8=87=B4=EF=BC=8C=E9=83=A8=E5=88=86=E8=A7=92=E8=89=B2?= =?UTF-8?q?=E7=9A=84=E5=B1=9E=E6=80=A7=E5=8F=8A=E4=BC=A4=E5=AE=B3=E8=AE=A1?= =?UTF-8?q?=E7=AE=97=E5=8F=AF=E8=83=BD=E4=BC=9A=E4=B8=8D=E5=87=86=E7=A1=AE?= =?UTF-8?q?=EF=BC=8C=E5=A6=82=E6=9C=89=E5=8F=91=E7=8E=B0=E8=AF=B7=E5=8F=8D?= =?UTF-8?q?=E9=A6=88=E7=BB=99=E5=96=B5=E5=96=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 11 +- components/Calc.js | 2 + components/Profile.js | 213 +++++++++++++++++- components/models/Reliquaries.js | 3 +- resources/meta/character/夜兰/calc.js | 6 +- resources/meta/character/雷电将军/calc.js | 6 +- .../meta/reliquaries/reliquaries-mark.js | 1 + 7 files changed, 226 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 33492347..90bd16d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,14 @@ -# 1.6.3 +# 1.6.4 -* 增加`#录入夜兰面板` 命令,可手工录入角色面板信息,用于伤害计算及角色展示。具体可参见`#角色面板帮助` -* `关于面板更新服务`:由于2.7版本底层数据架构变更,角色面板服务受到影响。预计可能会花费较长时间升级适配,请见谅 (ಥ_ಥ) +* `#更新全部面板` 功能暂时恢复 + * 目前可直接使用,无需token + * 部分网络可能无法请求,等待后续服务更新 + * 由于服务逻辑与之前数据不一致,部分角色的属性及伤害计算可能会不准确,如有发现请反馈给喵喵 -# 1.6.1 ~ 1.6.2 +# 1.6.1 ~ 1.6.3 * 增加`#喵喵面板设置`命令,可更精细的设置是否允许好友/临时对话/群使用面板功能 +* 增加`#录入夜兰面板` 命令,可在更新服务不可用时手工录入角色面板信息 * `#喵喵日历` 优化 * 对角色、武器UP的日历展示做合并优化 * 增强从活动详情解析日期的能力,使一些活动日期更加准确 diff --git a/components/Calc.js b/components/Calc.js index fb149ad6..cd2a9060 100644 --- a/components/Calc.js +++ b/components/Calc.js @@ -58,6 +58,8 @@ let Calc = { let ret = {}, { attr } = profile; + ret.dataSource = profile.dataSource || "miao"; + // 基础属性 lodash.forEach("atk,def,hp".split(","), (key) => { ret[key] = { diff --git a/components/Profile.js b/components/Profile.js index 7e3e8dcd..40236e4a 100644 --- a/components/Profile.js +++ b/components/Profile.js @@ -156,7 +156,7 @@ let Data = { }; lodash.forEach(attrKey, (cfg, key) => { if (typeof (cfg) === "string") { - cfg = { title: cfg }; + cfg = {title: cfg}; } let val = data[cfg.title] || ""; if (cfg.pct) { @@ -232,8 +232,203 @@ let Data = { } } +let Data2 = { + getData(uid, data) { + + let ret = { + uid, + chars: {} + } + + lodash.forEach({ + name: "nickname", + avatar: "profilePicture.avatarId", + lv: "level" + }, (src, key) => { + ret[key] = lodash.get(data.playerInfo, src, ""); + }) + + lodash.forEach(data.avatarInfoList, (ds) => { + let char = Data2.getAvatar(ds); + ret.chars[char.id] = char; + }) + + return ret; + + }, + getAvatar(data) { + let char = Character.get(data.avatarId); + return { + id: data["avatarId"], + name: char ? char.name : "", + dataSource: "shin", + lv: data.propMap['4001'].val * 1, + attr: Data2.getAttr(data.fightPropMap), + // weapon: Data.getWeapon(data), + artis: Data2.getArtifact(data.equipList), + //cons: data["命之座数量"] * 1 || 0, + //talent: Data.getTalent(data) + }; + }, + getAttr(data) { + let ret = {}; + let attrKey = { + // atk: 2001, + atkBase: 4, + def: 2002, + defBase: 7, + hp: 2000, + hpBase: 1, + mastery: 28, + cRate: { + src: 20, + pct: true + }, + cDmg: { + src: 22, + pct: true + }, + hInc: { + src: 26, + pct: true + }, + recharge: { + src: 23, + pct: true + } + }; + lodash.forEach(attrKey, (cfg, key) => { + if (!lodash.isObject(cfg)) { + cfg = {src: cfg}; + } + let val = data[cfg.src] || 0; + if (cfg.pct) { + val = val * 100 + } + ret[key] = val; + }); + ret.atk = data['4'] * (1 + data['6']) + data['5']; + let maxDmg = 0; + // 火40 水42 风44 岩45 冰46 雷46 + // 41 雷 + lodash.forEach("40,41,42,43,44,45,45,46".split(","), (key) => { + maxDmg = Math.max(data[key] * 1, maxDmg); + }); + // phy 30 + ret.dmgBonus = maxDmg * 100; + ret.phyBonus = data['30'] * 100; + + return ret; + }, + + getArtifact(data) { + let ret = {}; + + let artiIdx = { + EQUIP_BRACER: 1, + EQUIP_NECKLACE: 2, + EQUIP_SHOES: 3, + EQUIP_RING: 4, + EQUIP_DRESS: 5 + } + let attrMap = { + HP: "小生命", + HP_PERCENT: "大生命", + ATTACK: "小攻击", + ATTACK_PERCENT: "大攻击", + DEFENSE: "小防御", + DEFENSE_PERCENT: "大防御", + FIRE_ADD_HURT: "火元素伤害加成", + ICE_ADD_HURT: "冰元素伤害加成", + ROCK_ADD_HURT: "岩元素伤害加成", + ELEC_ADD_HURT: "雷元素伤害加成", + WIND_ADD_HURT: "风元素伤害加成", + WATER_ADD_HURT: "水元素伤害加成", + PHYSICAL_ADD_HURT: "物理伤害加成", + HEAL_ADD: "治疗加成", + ELEMENT_MASTERY: "元素精通", + CRITICAL: "暴击率", + CRITICAL_HURT: "暴击伤害", + CHARGE_EFFICIENCY: "充能效率", + } + + let get = function (d) { + if (!d) { + return []; + } + let id = d.appendPropId || d.mainPropId || ""; + id = id.replace("FIGHT_PROP_", ""); + if (!attrMap[id]) { + return []; + } + return [attrMap[id], d.statValue]; + + } + lodash.forEach(data, (ds) => { + let flat = ds.flat || {}, sub = flat.reliquarySubstats || []; + let idx = artiIdx[flat.equipType]; + if (!idx) { + return; + } + + ret[`arti${idx}`] = { + name: "", + id: ds.itemId, + main: get(flat.reliquaryMainstat), + attrs: [ + get(sub[0]), + get(sub[1]), + get(sub[2]), + get(sub[3]) + ] + } + }) + return ret; + }, +}; + let Profile = { async request(uid, e) { + let api = `https://enka.shinshin.moe/u/${uid}/__data.json`; + let inCd = await redis.get(`miao:role-all:${uid}`); + if (inCd === 'loading') { + e.reply("请求过快,请稍后重试.."); + return false; + } else if (inCd === 'pending') { + e.reply("距上次请求刷新成功间隔小于2分钟,请稍后重试.."); + return false; + } + await redis.set(`miao:role-all:${uid}`, 'loading', {EX: 20}); + e.reply("开始获取数据,可能会需要一定时间~"); + await sleep(1000); + let data; + try { + let req = await fetch(api); + data = await req.json(); + if (!data.playerInfo) { + e.reply(`请求失败:${data.msg || "请求错误,请稍后重试"}`); + return false; + } + let details = data.avatarInfoList; + if (!details || details.length === 0 || !details[0].propMap) { + e.reply(`请打开角色展柜的显示详情`); + return false; + } + } catch (err) { + e.reply(`请求失败`); + } + // 请求成功Bot侧对该uid冷却10分钟 + // 请勿将时间改短,10分钟之内若发起请求会命中服务侧的uid缓存,返回之前的数据,并导致服务侧重新计时 + await redis.set(`miao:role-all:${uid}`, 'pending', {EX: 120}); + + let userData = {}; + userData = Profile.save(uid, data, true) + + userData.leftCount = 99; + return userData; + + }, + async request_bak(uid, e) { let cfg = config.miaoApi || {}; if (!cfg.api) { e.reply("该功能为小范围非公开功能,需具备Token才可使用~"); @@ -251,7 +446,7 @@ let Profile = { e.reply("距上次请求刷新成功间隔小于10分钟,请稍后重试.."); return false; } - await redis.set(`miao:role-all:${uid}`, 'loading', { EX: 20 }); + await redis.set(`miao:role-all:${uid}`, 'loading', {EX: 20}); e.reply("开始获取数据,可能会需要一定时间~"); await sleep(1000); @@ -268,7 +463,7 @@ let Profile = { } // 请求成功Bot侧对该uid冷却10分钟 // 请勿将时间改短,10分钟之内若发起请求会命中服务侧的uid缓存,返回之前的数据,并导致服务侧重新计时 - await redis.set(`miao:role-all:${uid}`, 'pending', { EX: 600 }); + await redis.set(`miao:role-all:${uid}`, 'pending', {EX: 600}); let leftCount = data.leftCount; data = data.data; let userData = {}; @@ -279,13 +474,19 @@ let Profile = { return userData; }, - save(uid, ds) { + save(uid, ds, isNewFormat = false) { let userData = {}; const userFile = `${userPath}/${uid}.json`; if (fs.existsSync(userFile)) { userData = JSON.parse(fs.readFileSync(userFile, "utf8")) || {}; } - let data = Data.getData(uid, ds); + let data; + if (isNewFormat) { + data = Data2.getData(uid, ds); + } else { + data = Data.getData(uid, ds); + } + lodash.assignIn(userData, lodash.pick(data, "uid,name,lv,avatar".split(","))); userData.chars = userData.chars || {}; lodash.forEach(data.chars, (char, charId) => { @@ -400,7 +601,7 @@ let Profile = { }, inputProfile(uid, e) { - let { avatar, inputData } = e; + let {avatar, inputData} = e; inputData = inputData.replace("#", ""); inputData = inputData.replace(/,|;|、|\n|\t/g, ","); let attr = {}; diff --git a/components/models/Reliquaries.js b/components/models/Reliquaries.js index 932e3644..2c47a0b4 100644 --- a/components/models/Reliquaries.js +++ b/components/models/Reliquaries.js @@ -1,4 +1,4 @@ -import { attrMark, maxMark, attrMap, usefulAttr } from "../../resources/meta/reliquaries/reliquaries-mark.js"; +import {attrMark, maxMark, attrMap, usefulAttr} from "../../resources/meta/reliquaries/reliquaries-mark.js"; import lodash from "lodash"; let Reliquaries = { @@ -48,6 +48,7 @@ let Reliquaries = { let total = 0; let markMap = Reliquaries.getUseful(char).mark; lodash.forEach(data, (ret) => { + ret = ret || []; let title = ret[0], val = ret[1]; if (title && val) { if (markMap[title]) { diff --git a/resources/meta/character/夜兰/calc.js b/resources/meta/character/夜兰/calc.js index 96f44cdf..cbd82e85 100644 --- a/resources/meta/character/夜兰/calc.js +++ b/resources/meta/character/夜兰/calc.js @@ -7,12 +7,12 @@ export const details = [{ dmg: ({ talent, attr, calc }, { basic }) => basic(calc(attr.hp) * talent.e['技能伤害'] / 100, 'e') }, { - title: "Q协同攻击伤害", + title: "Q协同单段伤害", dmg: ({ talent, attr, calc, cons }, { basic }) => - basic(calc(attr.hp) * (talent.q['玄掷玲珑伤害'] / 100), 'q') + basic(calc(attr.hp) * (talent.q['玄掷玲珑伤害'] / 3 / 100), 'q') }]; -export const mainAttr = "hp,atk,cpct,cdmg"; +export const mainAttr = "hp,cpct,cdmg"; export const buffs = [{ title: "夜兰被动:有4个不同元素类型角色时,夜兰生命值上限提高30%", diff --git a/resources/meta/character/雷电将军/calc.js b/resources/meta/character/雷电将军/calc.js index eeae60a2..6357b88c 100644 --- a/resources/meta/character/雷电将军/calc.js +++ b/resources/meta/character/雷电将军/calc.js @@ -47,8 +47,10 @@ export const buffs = [ "qIgnore": 60 } }, { - title: "雷神被动:基于元素充能获得[dmg]%雷伤加成", + title: "雷神被动:基于元素充能获得[_dmg]%雷伤加成", data: { - dmg: ({ attr }) => Math.max(attr.recharge.base + attr.recharge.plus - 100, 0) * 0.4 + _dmg: ({ attr }) => Math.max(attr.recharge.base + attr.recharge.plus - 100, 0) * 0.4, + dmg: ({ attr }) => + attr.dataSource === "shin" ? 0 :Math.max(attr.recharge.base + attr.recharge.plus - 100, 0) * 0.4 } }]; \ No newline at end of file diff --git a/resources/meta/reliquaries/reliquaries-mark.js b/resources/meta/reliquaries/reliquaries-mark.js index e73548e0..06efef80 100644 --- a/resources/meta/reliquaries/reliquaries-mark.js +++ b/resources/meta/reliquaries/reliquaries-mark.js @@ -105,4 +105,5 @@ export const usefulAttr = { "辛焱": "atk,cRate,cDmg", "砂糖": "mastery,recharge", "雷泽": "atk,cRate,cDmg", + "夜兰": "hp,cRate,cDmg,recharge", } \ No newline at end of file