HumanBreak/public/project/plugin/remainEnemy.js

73 lines
1.8 KiB
JavaScript
Raw Normal View History

2023-02-28 18:21:29 +08:00
///<reference path="../../../src/types/core.d.ts" />
2023-02-28 17:49:34 +08:00
2023-04-16 17:05:47 +08:00
/**
* 检查漏怪
* @param {FloorIds[]} floorIds
*/
export function checkRemainEnemy(floorIds) {
2023-02-28 17:49:34 +08:00
/**
2023-04-16 17:05:47 +08:00
* @type {Record<FloorIds, {loc: LocArr, id: EnemyIds}[]>}
2023-02-28 17:49:34 +08:00
*/
2023-04-16 17:05:47 +08:00
const enemy = {};
floorIds.forEach(v => {
core.extractBlocks(v);
const blocks = core.status.maps[v].blocks;
blocks.forEach(block => {
if (!block.event.cls.startsWith('enemy') || block.disable) return;
/**
* @type {EnemyIds}
*/
const id = block.event.id;
enemy[v] ??= [];
const info = enemy[v];
info.push({ loc: [block.x, block.y], id });
});
});
return enemy;
}
/**
* 获取剩余怪物字符串
* @param {FloorIds[]} floorIds
*/
export function getRemainEnemyString(floorIds) {
const enemy = checkRemainEnemy(floorIds);
const str = [];
let now = [];
for (const floor in enemy) {
2023-02-28 17:49:34 +08:00
/**
2023-04-16 17:05:47 +08:00
* @type {{loc: LocArr, id: EnemyIds}[]}
2023-02-28 17:49:34 +08:00
*/
2023-04-16 17:05:47 +08:00
const all = enemy[floor];
/**
* @type {Record<EnemyIds, number>}
*/
const remain = {};
all.forEach(v => {
const id = v.id;
remain[id] ??= 0;
remain[id]++;
2023-02-28 17:49:34 +08:00
});
2023-04-16 17:05:47 +08:00
const title = core.status.maps[floor].title;
for (const id in remain) {
const name = core.material.enemys[id].name;
now.push(`${title}(${floor}): ${name} * ${remain[id]}`);
if (now.length === 10) {
str.push(now.join('\n'));
now = [];
2023-02-28 17:49:34 +08:00
}
}
}
2023-04-16 17:05:47 +08:00
if (now.length > 0) {
str.push(now.join('\n'));
str[0] = `当前剩余怪物:\n${str[0]}`;
}
return str;
}
2023-02-28 17:49:34 +08:00
2023-04-16 17:05:47 +08:00
core.plugin.remainEnemy = {
checkRemainEnemy,
getRemainEnemyString
};