文章编辑人员:雪舞
内容测试时间:2023-6-13 19:07:10
测试环境:node 18.16.0 LTS
测试版本:Windows 10 64bit
在Node.js中使用 iconv-lite 模块处理GBK编码,你需要首先安装这个模块,可以通过运行npm install iconv-lite来安装。
const fs = require('fs');
const iconv = require('iconv-lite');
function loadFile(filename) {
const buffer = fs.readFileSync(filename);
const data = iconv.decode(buffer, 'GBK');
const lines = data.split('\n').filter(line => line.trim() !== '' && !line.trim().startsWith('#') && line.includes('\t'));
return lines.map(line => line.split('\t'));
}
function createDict(data, keyCol, valCol) {
const dict = {};
data.forEach(row => {
dict[row[keyCol]] = row[valCol];
});
return dict;
}
const monsterDrops = loadFile('MonsterDropBoxs.txt');
const dropBoxContents = loadFile('DropBoxContent.txt');
const monsterAttrs = loadFile('MonsterAttrExTable.txt');
const commonItems = loadFile('CommonItem.txt');
const equipBases = loadFile('EquipBase.txt');
const gemInfos = loadFile('GemInfo.txt');
const monsterDict = createDict(monsterAttrs, 0, 1);
const commonItemDict = createDict(commonItems, 0, 6);
const equipBaseDict = createDict(equipBases, 0, 10);
const gemInfoDict = createDict(gemInfos, 0, 7);
const monsterDropsDict = {};
monsterDrops.forEach(drop => {
const monsterId = drop[0];
const monsterName = monsterDict[monsterId] || 'Unknown';
const dropBoxes = drop.slice(3);
dropBoxes.forEach(boxId => {
if (boxId === '-1') return;
const boxContents = dropBoxContents.find(content => content[0] === boxId);
if (!boxContents) return;
const items = boxContents.slice(4);
items.forEach(itemId => {
if (itemId === '-1') return;
const itemName = commonItemDict[itemId] || equipBaseDict[itemId] || gemInfoDict[itemId];
if (itemName) {
if (!monsterDropsDict[monsterName]) {
monsterDropsDict[monsterName] = new Set();
}
monsterDropsDict[monsterName].add(itemName);
}
});
});
});
for (let monster in monsterDropsDict) {
console.log(`Monster: ${monster}, Drops: ${Array.from(monsterDropsDict[monster]).join(', ')}`);
}
|