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
|
|
|
|
|
|
|
|
|
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/3和1/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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获得所有被标记的怪物
|
|
|
|
|
*/
|
|
|
|
|
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;
|
|
|
|
|
const n = core.nextCriticals(id, 1)[0]?.[0];
|
|
|
|
|
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);
|
|
|
|
|
const damage = core.getDamageInfo(v)?.damage ?? -1;
|
|
|
|
|
if (damage === -1) return;
|
|
|
|
|
const info = enemyDamageInfo[v]!;
|
|
|
|
|
const name = core.material.enemys[v].name;
|
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
|
|
|
|
}
|
|
|
|
|
info[1] = true;
|
|
|
|
|
info[2] = true;
|
|
|
|
|
info[3] = true;
|
|
|
|
|
} 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
|
|
|
|
}
|
|
|
|
|
info[1] = true;
|
|
|
|
|
info[2] = true;
|
|
|
|
|
info[3] = false;
|
|
|
|
|
} 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
|
|
|
|
}
|
|
|
|
|
info[1] = true;
|
|
|
|
|
info[2] = false;
|
|
|
|
|
info[3] = false;
|
2022-12-29 00:38:42 +08:00
|
|
|
|
} else {
|
|
|
|
|
info[1] = false;
|
|
|
|
|
info[2] = false;
|
|
|
|
|
info[3] = false;
|
2022-12-29 00:26:12 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const checkMarkedStatus = ref(false);
|
|
|
|
|
|
|
|
|
|
export default function init() {
|
|
|
|
|
return { checkMarkedEnemy, checkStatus: checkMarkedStatus };
|
|
|
|
|
}
|