HumanBreak/packages-user/legacy-plugin-data/src/hook.ts

66 lines
2.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { hook } from '@user/data-base';
const potionItems: AllIdsOf<'items'>[] = [
'redPotion',
'bluePotion',
'yellowPotion',
'greenPotion',
'I482',
'I484',
'I487',
'I491'
];
export function createHook() {
hook.on('afterGetItem', (itemId, x, y, isGentleClick) => {
// 获得一个道具后触发的事件
// itemId获得的道具IDx和y是该道具所在的坐标
// isGentleClick是否是轻按触发的
if (potionItems.includes(itemId)) core.playSound('回血');
else core.playSound('获得道具');
const todo: any[] = [];
// 检查该点的获得道具后事件。
if (core.status.floorId == null) return;
const event =
core.floors[core.status.floorId].afterGetItem[`${x},${y}`];
if (
event &&
(event instanceof Array ||
!isGentleClick ||
!event.disableOnGentleClick)
) {
core.unshift(todo, event as any[]);
}
if (core.hasFlag('spring')) {
if (!core.hasFlag('springCount')) core.setFlag('springCount', 0);
if (potionItems.includes(itemId)) {
core.addFlag('springCount', 1);
}
if (core.getFlag<number>('springCount', 0) === 50) {
core.setFlag('springCount', 0);
core.status.hero.hpmax += core.getNakedStatus('hpmax') * 0.1;
}
core.updateStatusBar();
}
if (todo.length > 0) core.insertAction(todo, x, y);
});
hook.on('afterOpenDoor', (doorId, x, y) => {
// 开一个门后触发的事件
const todo: any[] = [];
// 检查该点的获得开门后事件。
if (core.status.floorId == null) return;
const event =
core.floors[core.status.floorId].afterOpenDoor[`${x},${y}`];
if (event) core.unshift(todo, event as any[]);
if (todo.length > 0) core.insertAction(todo, x, y);
if (core.status.event.id == null) core.continueAutomaticRoute();
else core.clearContinueAutomaticRoute();
});
}