2023-03-07 17:52:11 +00:00
|
|
|
import { Data } from '#miao'
|
2022-11-23 20:26:07 +00:00
|
|
|
import lodash from 'lodash'
|
2023-10-24 19:34:36 +00:00
|
|
|
import fs from 'node:fs'
|
2024-05-21 18:05:37 +00:00
|
|
|
import { miaoPath } from '#miao.path'
|
2022-11-24 16:31:36 +00:00
|
|
|
|
|
|
|
let cfgMap = {
|
|
|
|
char: {},
|
2024-06-21 22:28:47 +00:00
|
|
|
game: 'gs',
|
|
|
|
async init (game = 'gs') {
|
|
|
|
this.game = game
|
|
|
|
let chars = fs.readdirSync(`${miaoPath}/resources/meta-${game}/character`)
|
2022-11-24 16:31:36 +00:00
|
|
|
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) {
|
2024-06-21 22:28:47 +00:00
|
|
|
return fs.existsSync(`${miaoPath}/resources/meta-${this.game}/character/${char}/${file}.js`)
|
2022-11-24 16:31:36 +00:00
|
|
|
},
|
|
|
|
async getCfg (char, file, module = '') {
|
2024-06-21 22:28:47 +00:00
|
|
|
let cfg = await Data.importModule(`resources/meta-${this.game}/character/${char}/${file}.js`, 'miao')
|
2022-11-24 16:31:36 +00:00
|
|
|
if (module) {
|
|
|
|
return cfg[module]
|
|
|
|
}
|
|
|
|
return cfg
|
|
|
|
}
|
|
|
|
}
|
2024-06-21 22:28:47 +00:00
|
|
|
await cfgMap.init('gs')
|
|
|
|
let cfgMapGs = { ...cfgMap }
|
|
|
|
await cfgMap.init('sr')
|
|
|
|
let cfgMapSr = { ...cfgMap }
|
2022-11-23 20:26:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 角色相关配置
|
|
|
|
*/
|
|
|
|
let CharCfg = {
|
|
|
|
// 获取角色伤害计算相关配置
|
2022-11-24 16:31:36 +00:00
|
|
|
getCalcRule (char) {
|
2023-11-13 08:37:07 +00:00
|
|
|
let cfg = cfgMap.char[char.isTraveler ? `旅行者/${char.elem}` : char.name]?.calc
|
2022-11-24 16:31:36 +00:00
|
|
|
if (!cfg || lodash.isEmpty(cfg)) {
|
2022-11-23 20:26:07 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
details: cfg.details || false, // 计算详情
|
|
|
|
buffs: cfg.buffs || [], // 角色buff
|
|
|
|
defParams: cfg.defParams || {}, // 默认参数,一般为空
|
|
|
|
defDmgIdx: cfg.defDmgIdx || -1, // 默认详情index
|
|
|
|
defDmgKey: cfg.defDmgKey || '',
|
|
|
|
mainAttr: cfg.mainAttr || 'atk,cpct,cdmg', // 伤害属性
|
|
|
|
enemyName: cfg.enemyName || '小宝' // 敌人名称
|
|
|
|
}
|
2022-11-24 16:31:36 +00:00
|
|
|
},
|
|
|
|
getArtisCfg (char) {
|
2024-06-21 22:28:47 +00:00
|
|
|
if (char.game !== 'sr') {
|
|
|
|
let charName = char.isTraveler ? `旅行者/${char.elem}` : char.name
|
|
|
|
return cfgMapGs.char[charName]?.artis || false
|
|
|
|
} else {
|
|
|
|
return cfgMapSr.char[char.name]?.artis || false
|
|
|
|
}
|
2022-11-23 20:26:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
export default CharCfg
|