From 1a9245616686cd239f28af973c0c698ae5f9ae1d Mon Sep 17 00:00:00 2001 From: Kokomi <102026640+yoimiya-kokomi@users.noreply.github.com> Date: Fri, 25 Nov 2022 00:31:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=9D=A2=E6=9D=BF=E8=AE=A1?= =?UTF-8?q?=E7=AE=97=E9=80=BB=E8=BE=91=E5=BC=80=E5=85=B3=EF=BC=8C=E5=90=AF?= =?UTF-8?q?=E7=94=A8=E5=90=8E=E5=8F=AF=E4=BD=BF=E7=94=A8=E9=9D=A2=E6=9D=BF?= =?UTF-8?q?=E8=AE=A1=E7=AE=97=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 2 +- apps/character/ProfileDetail.js | 2 +- config/system/cfg_system.js | 22 +++++++----- models/Character.js | 11 ++++-- models/ProfileAttr.js | 10 +++--- models/ProfileData.js | 17 +++++++--- models/character-lib/CharCfg.js | 45 +++++++++++++++++++++++-- models/profile-lib/AttrCalc.js | 24 ++++++------- models/profile-lib/CharArtis.js | 21 +----------- resources/character/profile-detail.html | 2 +- tools/profile-calc-test.js | 11 +++--- 11 files changed, 103 insertions(+), 64 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 23664894..d6c59aa6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ # 2.1.1 * 部分底层结构升级 - * 底层增加面板计算逻辑,供后续功能使用 + * 底层增加面板计算逻辑,默认不启用,具体应用待后续升级 * 圣遗物数据底层存储格式与处理逻辑初步升级 * 圣遗物主词条评分规则微调,可能会影响部分角色评分 * 元素杯属性不符会触发主词缀评分惩罚 diff --git a/apps/character/ProfileDetail.js b/apps/character/ProfileDetail.js index e92b2617..5a847854 100644 --- a/apps/character/ProfileDetail.js +++ b/apps/character/ProfileDetail.js @@ -100,7 +100,7 @@ export async function renderProfile (e, char, mode = 'profile', params = {}) { return await Common.render('character/profile-detail', { save_id: uid, uid, - data: avatar.getData('name,abbr,cons,level,weapon,talent,dataSource,updateTime'), + data: avatar.getData('name,abbr,cons,level,weapon,talent,dataSource,updateTime,_attrCalc'), attr, elem: char.elem, dmgData, diff --git a/config/system/cfg_system.js b/config/system/cfg_system.js index ec69aed3..c284c3ef 100644 --- a/config/system/cfg_system.js +++ b/config/system/cfg_system.js @@ -47,14 +47,7 @@ export const cfgSchema = { key: '戳一戳', def: true, oldCfgKey: 'char.poke' - }, - commaGroup: { - title: '数字逗号分组', - key: '逗号', - def: 3, - type: 'num', - desc: '根据语言习惯设置数字分组,如千位组设为 3,万位组设为 4。(暂不支持欧洲样式)' - }, + } } }, wiki: { @@ -108,6 +101,19 @@ export const cfgSchema = { def: false, oldCfgKey: 'sys.help', desc: '开启后将使用喵喵版帮助作为Yunzai的默认帮助,默认关闭' + }, + commaGroup: { + title: '数字逗号分组', + key: '逗号', + def: 3, + type: 'num', + desc: '根据语言习惯设置数字分组,如千位组设为3,万位组设为4' + }, + attrCalc: { + title: '面板计算属性', + key: '计算', + def: false, + desc: '实验特性:#雷神面板 使用面板计算属性取代展柜属性' } } } diff --git a/models/Character.js b/models/Character.js index 4f716aa0..5e102b60 100644 --- a/models/Character.js +++ b/models/Character.js @@ -316,12 +316,19 @@ class Character extends Base { } // 获取伤害计算配置 - async getCalcRule () { + getCalcRule () { if (!this._calcRule && this._calcRule !== false) { - this._calcRule = await CharCfg.getCalcRule(this) + this._calcRule = CharCfg.getCalcRule(this) } return this._calcRule } + + getArtisCfg () { + if (!this._artisRule && this._artisRule !== false) { + this._artisRule = CharCfg.getArtisCfg(this) + } + return this._artisRule + } } Character.CharId = CharId diff --git a/models/ProfileAttr.js b/models/ProfileAttr.js index 3cfc7fa1..19dcfc26 100644 --- a/models/ProfileAttr.js +++ b/models/ProfileAttr.js @@ -1,7 +1,5 @@ import lodash from 'lodash' import Base from './Base.js' -import DmgMastery from './profile-lib/DmgMastery.js' -import { Format } from '../components/index.js' const baseAttr = 'atk,def,hp,mastery,recharge,cpct,cdmg,dmg,phy,heal,shield'.split(',') let attrReg = new RegExp(`^(${baseAttr.join('|')})(Base|Plus|Pct|Inc)$`) @@ -9,10 +7,10 @@ let attrReg = new RegExp(`^(${baseAttr.join('|')})(Base|Plus|Pct|Inc)$`) class ProfileAttr extends Base { constructor (data = null) { super() - this._init(data) + this.init(data) } - _init (data) { + init (data) { // 基础属性 this._attr = {} let attr = this._attr @@ -28,7 +26,7 @@ class ProfileAttr extends Base { } } - static init (data = null) { + static create (data = null) { return new ProfileAttr(data) } @@ -71,6 +69,7 @@ class ProfileAttr extends Base { if (testRet && testRet[1] && testRet[2]) { let key = testRet[1] let key2 = testRet[2].toLowerCase() + attr[key][key2] = attr[key][key2] || 0 attr[key][key2] += val * 1 return true } @@ -105,6 +104,7 @@ class ProfileAttr extends Base { ret[`${key}Base`] = this[`${key}Base`] } }) + ret._calc = true return ret } } diff --git a/models/ProfileData.js b/models/ProfileData.js index 5eaf2fe5..7f3f09df 100644 --- a/models/ProfileData.js +++ b/models/ProfileData.js @@ -1,7 +1,7 @@ import lodash from 'lodash' import Base from './Base.js' import moment from 'moment' -import { Data } from '../components/index.js' +import { Data, Cfg } from '../components/index.js' import { Character, ProfileArtis, ProfileDmg } from './index.js' import AttrCalc from './profile-lib/AttrCalc.js' @@ -15,18 +15,27 @@ export default class ProfileData extends Base { this.id = char.id this.char = char this.uid = uid || '' - this.setBasic(ds) ds.attr && this.setAttr(ds.attr) ds.weapon && this.setWeapon(ds.weapon) ds.talent && this.setTalent(ds.talent) this.artis = new ProfileArtis(this.id, this.elem) ds.artis && this.setArtis(ds.artis) - if (process.argv.includes('web-debug')) { - AttrCalc.getAttr(this) + if (Cfg.get('attrCalc')) { + this._attr = AttrCalc.create(this) + this.attr = this._attr.calc() + this._attrCalc = true } } + static create (ds, uid) { + let profile = new ProfileData(ds, uid) + if (!profile) { + return false + } + return profile + } + setBasic (ds = {}) { this.level = ds.lv || ds.level || 1 this.cons = ds.cons || 0 diff --git a/models/character-lib/CharCfg.js b/models/character-lib/CharCfg.js index dad82954..1800312a 100644 --- a/models/character-lib/CharCfg.js +++ b/models/character-lib/CharCfg.js @@ -1,14 +1,50 @@ import { Data } from '../../components/index.js' import lodash from 'lodash' +import fs from 'fs' + +const charPath = process.cwd() + '/plugins/miao-plugin/resources/meta/character' +let cfgMap = { + char: {}, + async init () { + let chars = fs.readdirSync(charPath) + for (let char of chars) { + cfgMap.char[char] = {} + let curr = cfgMap.char[char] + // 评分规则 + if (cfgMap.exists(char, 'artis_user')) { + curr.artis = await cfgMap.getCfg(char, 'artis_user', 'default') + } else if (cfgMap.exists(char, 'artis')) { + curr.artis = await cfgMap.getCfg(char, 'artis', 'default') + } + // 伤害计算 + if (cfgMap.exists(char, 'calc_user')) { + curr.calc = await cfgMap.getCfg(char, 'calc_user') + } else if (cfgMap.exists(char, 'calc')) { + curr.calc = await cfgMap.getCfg(char, 'calc') + } + } + }, + exists (char, file) { + return fs.existsSync(`${charPath}/${char}/${file}.js`) + }, + async getCfg (char, file, module = '') { + let cfg = await Data.importModule(`resources/meta/character/${char}/${file}.js`) + if (module) { + return cfg[module] + } + return cfg + } +} +await cfgMap.init() /** * 角色相关配置 */ let CharCfg = { // 获取角色伤害计算相关配置 - async getCalcRule (char) { - let cfg = await Data.importModule(`resources/meta/character/${char.name}/calc.js`) - if (lodash.isEmpty(cfg)) { + getCalcRule (char) { + let cfg = cfgMap.char[char.name]?.calc + if (!cfg || lodash.isEmpty(cfg)) { return false } return { @@ -20,6 +56,9 @@ let CharCfg = { mainAttr: cfg.mainAttr || 'atk,cpct,cdmg', // 伤害属性 enemyName: cfg.enemyName || '小宝' // 敌人名称 } + }, + getArtisCfg (char) { + return cfgMap.char[char.name]?.artis || false } } export default CharCfg diff --git a/models/profile-lib/AttrCalc.js b/models/profile-lib/AttrCalc.js index 25f06737..bf0f369a 100644 --- a/models/profile-lib/AttrCalc.js +++ b/models/profile-lib/AttrCalc.js @@ -18,28 +18,27 @@ class AttrCalc { /** * 静态调用入口 * @param profile - * @returns {boolean|void} + * @returns {AttrCalc} */ - static async getAttr (profile) { - let attr = new AttrCalc(profile) - return await attr.calc() + static create (profile) { + return new AttrCalc(profile) } /** - * 实例调用入口 - * @param profile + * 面板属性计算 + * @returns {{}} */ - async calc (profile) { - this.attr = ProfileAttr.init({ + calc () { + this.attr = ProfileAttr.create({ recharge: 100, cpct: 5, cdmg: 50 }) - await this.setCharAttr() + this.setCharAttr() this.setWeaponAttr() this.setArtisAttr() if (process.argv.includes('web-debug')) { - // console.log(this.attr, this.attr.getAttr()) + // console.log(this.attr, this.attr.getAttr()) } return this.attr.getAttr() } @@ -52,7 +51,7 @@ class AttrCalc { * 计算角色属性 * @param affix */ - async setCharAttr (affix = '') { + setCharAttr (affix = '') { let { char, level, promote } = this.profile let metaAttr = char.detail?.attr || {} let { keys = {}, details = {} } = metaAttr @@ -87,7 +86,7 @@ class AttrCalc { this.addAttr('defBase', getLvData(2)) this.addAttr(keys[3], getLvData(3, true)) - let charBuffs = await char.getCalcRule() + let charBuffs = char.getCalcRule() lodash.forEach(charBuffs.buffs, (buff) => { if (!buff.isStatic) { return true @@ -189,7 +188,6 @@ class AttrCalc { if (Format.isElem(key) && char.elem === key) { key = 'dmg' } - if (!key) { return false } diff --git a/models/profile-lib/CharArtis.js b/models/profile-lib/CharArtis.js index 87573f97..e013b571 100644 --- a/models/profile-lib/CharArtis.js +++ b/models/profile-lib/CharArtis.js @@ -1,24 +1,5 @@ import { usefulAttr } from '../../resources/meta/artifact/artis-mark.js' -import { Data } from '../../components/index.js' import lodash from 'lodash' -import fs from 'fs' - -let charCfg = {} - -async function init () { - let charPath = process.cwd() + '/plugins/miao-plugin/resources/meta/character' - let chars = fs.readdirSync(charPath) - for (let char of chars) { - // 允许自定义配置文件,会覆盖喵喵版评分规则 - if (fs.existsSync(`${charPath}/${char}/artis_user.js`)) { - charCfg[char] = await Data.importModule(`resources/meta/character/${char}/artis_user.js`) - } else if (fs.existsSync(`${charPath}/${char}/artis.js`)) { - charCfg[char] = await Data.importModule(`resources/meta/character/${char}/artis.js`) - } - } -} - -await init() const CharArtis = { @@ -88,7 +69,7 @@ const CharArtis = { } } - let charRule = charCfg[char.name]?.default || function ({ def }) { + let charRule = char.getArtisCfg() || function ({ def }) { return def(usefulAttr[char.name] || { atk: 75, cpct: 100, cdmg: 100 }) } diff --git a/resources/character/profile-detail.html b/resources/character/profile-detail.html index 492f2443..437736f1 100644 --- a/resources/character/profile-detail.html +++ b/resources/character/profile-detail.html @@ -42,7 +42,7 @@