新增柏妮思伤害计算等

This commit is contained in:
UCPr 2025-01-14 21:42:23 +08:00
parent 6573f1d600
commit b51acca73e
19 changed files with 1053 additions and 164 deletions

View file

@ -1,5 +1,4 @@
import { aliasToID } from '../../lib/convert/char.js';
import config from '../../../../lib/config/config.js';
import { BuffManager } from './BuffManager.js';
import { pluginPath } from '../../lib/path.js';
import { elementEnum } from './BuffManager.js';
@ -15,7 +14,15 @@ const calcFnc = {
set: {}
};
async function init() {
const isWatch = config.bot.log_level === 'debug'; // debug模式下监听文件变化
// debug模式下监听文件变化
const isWatch = await (async () => {
try {
return (await import('../../../../lib/config/config.js')).default.bot.log_level === 'debug';
}
catch {
return false;
}
})();
await Promise.all(fs.readdirSync(path.join(damagePath, 'character')).filter(v => v !== '模板').map(v => importChar(v, isWatch)));
for (const type of ['weapon', 'set']) {
await Promise.all(fs.readdirSync(path.join(damagePath, type)).filter(v => v !== '模板.js' && !v.endsWith('_user.js') && v.endsWith('.js'))
@ -43,11 +50,14 @@ async function importChar(charName, isWatch = false) {
const calcFile = fs.existsSync(path.join(dir, 'calc_user.js')) ? 'calc_user.js' : 'calc.js';
const dataPath = path.join(dir, (fs.existsSync(path.join(dir, 'data_user.json')) ? 'data_user.json' : 'data.json'));
try {
const calcFilePath = path.join(dir, calcFile);
if (isWatch) {
watchFile(path.join(dir, calcFile), () => importChar(charName));
watchFile(calcFilePath, () => importChar(charName));
watchFile(dataPath, () => charData[id] = JSON.parse(fs.readFileSync(dataPath, 'utf8')));
}
charData[id] = JSON.parse(fs.readFileSync(dataPath, 'utf8'));
if (!fs.existsSync(calcFilePath))
return;
const m = await import(`./character/${charName}/${calcFile}?${Date.now()}`);
if (!m.calc && (!m.buffs || !m.skills))
throw new Error('伤害计算文件格式错误');