HumanBreak/src/plugin/mark.ts

151 lines
4.1 KiB
TypeScript
Raw Normal View History

2022-12-29 00:26:12 +08:00
import { reactive, ref } from 'vue';
2022-12-29 12:02:48 +08:00
import { tip } from './utils';
2022-12-29 00:26:12 +08:00
2023-01-04 11:59:50 +08:00
export const showMarkedEnemy = ref(false);
2022-12-29 00:26:12 +08:00
const markedEnemy = reactive<EnemyIds[]>([]);
interface MarkInfo {
nextCritical: number;
}
const markInfo: Partial<Record<EnemyIds, MarkInfo>> = {};
const criticalReached: Partial<Record<EnemyIds, Record<number, boolean>>> = {};
const enemyDamageInfo: Partial<Record<EnemyIds, Record<number, boolean>>> = {};
/**
* 2/31/3
* @param id id
*/
export function markEnemy(id: EnemyIds) {
if (hasMarkedEnemy(id)) return;
markedEnemy.push(id);
markInfo[id] = {
nextCritical:
core.nextCriticals(id, 1)[0]?.[0] ?? 0 + core.status.hero.atk
};
criticalReached[id] = { 0: true };
enemyDamageInfo[id] = { 1: false, 2: false, 3: false };
2022-12-29 00:28:47 +08:00
getMarkInfo(id, true);
checkMarkedEnemy(true);
2022-12-29 00:26:12 +08:00
}
/**
*
*/
export function hasMarkedEnemy(id: EnemyIds) {
return markedEnemy.includes(id);
}
/**
*
*/
export function unmarkEnemy(id: EnemyIds) {
const index = markedEnemy.indexOf(id);
if (index === -1) return;
markedEnemy.splice(index, 1);
checkMarkedEnemy();
}
2023-02-20 20:34:42 +08:00
export function unmarkAll() {
markedEnemy.splice(0);
checkMarkedEnemy();
}
2022-12-29 00:26:12 +08:00
/**
*
*/
export function getMarkedEnemy() {
return markedEnemy;
}
/**
*
* @param id id
*/
2022-12-29 00:28:47 +08:00
export function getMarkInfo(id: EnemyIds, noMessage: boolean = false) {
2022-12-29 00:26:12 +08:00
const reached = criticalReached[id]!;
const info = markInfo[id]!;
if (core.status.hero.atk >= info.nextCritical) {
2022-12-29 00:28:47 +08:00
if (!reached[info.nextCritical] && !noMessage) {
2022-12-29 12:02:48 +08:00
tip('success', `踩到了${core.material.enemys[id].name}的临界!`);
2022-12-29 00:26:12 +08:00
}
reached[info.nextCritical] = true;
2023-01-16 22:32:04 +08:00
const n = core.nextCriticals(id, 1, void 0, void 0, 'empty')[0]?.[0];
2022-12-29 00:26:12 +08:00
const next = (n ?? 0) + core.status.hero.atk;
info.nextCritical = next;
}
}
/**
*
*/
2022-12-29 00:28:47 +08:00
export function checkMarkedEnemy(noMessage: boolean = false) {
2022-12-29 00:26:12 +08:00
checkMarkedStatus.value = !checkMarkedStatus.value;
const hp = core.status.hero.hp;
getMarkedEnemy().forEach(v => {
getMarkInfo(v);
2023-01-16 22:32:04 +08:00
const damage =
core.getDamageInfo(v, void 0, void 0, void 0, 'empty')?.damage ??
-1;
2022-12-29 00:26:12 +08:00
if (damage === -1) return;
const info = enemyDamageInfo[v]!;
const name = core.material.enemys[v].name;
2023-01-16 22:32:04 +08:00
let res = 0;
2022-12-29 12:02:48 +08:00
if (damage <= 0) {
if (!noMessage) tip('success', `${name}已经零伤了!`);
2022-12-29 00:38:42 +08:00
} else if (damage < hp / 3) {
2022-12-29 00:28:47 +08:00
if (!info[3] && !noMessage) {
2022-12-29 12:02:48 +08:00
tip('success', `${name}的伤害已降至勇士生命值的1/3`);
2022-12-29 00:26:12 +08:00
}
2023-01-16 22:32:04 +08:00
res = 0b111;
2022-12-29 00:26:12 +08:00
} else if (damage < (hp / 3) * 2) {
2022-12-29 00:28:47 +08:00
if (!info[2] && !noMessage) {
2022-12-29 12:02:48 +08:00
tip('success', `${name}的伤害已降至勇士生命值的2/3`);
2022-12-29 00:26:12 +08:00
}
2023-01-16 22:32:04 +08:00
res = 0b110;
2022-12-29 00:26:12 +08:00
} else if (damage < hp) {
2022-12-29 00:28:47 +08:00
if (!info[1] && !noMessage) {
2022-12-29 12:02:48 +08:00
tip('success', `你已经能打过${name}了!`);
2022-12-29 00:26:12 +08:00
}
2023-01-16 22:32:04 +08:00
res = 0b100;
}
info[1] = info[2] = info[3] = false;
if (res & 0b100) {
2022-12-29 00:26:12 +08:00
info[1] = true;
2023-01-16 22:32:04 +08:00
}
if (res & 0b010) {
info[2] = true;
}
if (res & 0b001) {
info[3] = true;
2022-12-29 00:26:12 +08:00
}
});
}
export const checkMarkedStatus = ref(false);
export default function init() {
2022-12-30 11:06:46 +08:00
// 鼠标移动时进行监听按下M时进行快速标记
core.registerAction(
'onmove',
'mark',
(x, y) => {
if (core.isPlaying()) {
flags.mouseLoc = [x, y];
}
return false;
},
150
);
return {
checkMarkedEnemy,
checkStatus: checkMarkedStatus,
markEnemy,
hasMarkedEnemy,
2023-01-04 11:59:50 +08:00
unmarkEnemy,
2023-02-20 20:34:42 +08:00
showMarkedEnemy,
unmarkAll
2022-12-30 11:06:46 +08:00
};
2022-12-29 00:26:12 +08:00
}