fix: 捕捉

This commit is contained in:
unanmed 2024-03-03 10:37:01 +08:00
parent b1a28b6b3d
commit 0084dafaf0
7 changed files with 55 additions and 53 deletions

View File

@ -2833,6 +2833,9 @@ events.prototype._action_function = function (data, x, y, prefix) {
if (typeof func == 'string' && func.indexOf('function') == 0) { if (typeof func == 'string' && func.indexOf('function') == 0) {
eval('(' + func + ')()'); eval('(' + func + ')()');
} }
if (typeof func === 'function') {
func();
}
} catch (e) { } catch (e) {
console.error(e); console.error(e);
} }

View File

@ -1,6 +1,6 @@
var enemys_fcae963b_31c9_42b4_b48c_bb48d09f3f80 = var enemys_fcae963b_31c9_42b4_b48c_bb48d09f3f80 =
{ {
"greenSlime": {"name":"绿头怪","hp":0,"atk":0,"def":0,"money":0,"exp":0,"point":0,"special":[]}, "greenSlime": {"name":"绿头怪","hp":0,"atk":0,"def":0,"money":0,"exp":0,"point":0,"special":[27]},
"redSlime": {"name":"红头怪","hp":0,"atk":0,"def":0,"money":0,"exp":0,"point":0,"special":[16,18],"value":10}, "redSlime": {"name":"红头怪","hp":0,"atk":0,"def":0,"money":0,"exp":0,"point":0,"special":[16,18],"value":10},
"blackSlime": {"name":"青头怪","hp":0,"atk":0,"def":0,"money":0,"exp":0,"point":0,"special":[]}, "blackSlime": {"name":"青头怪","hp":0,"atk":0,"def":0,"money":0,"exp":0,"point":0,"special":[]},
"slimelord": {"name":"怪王","hp":100,"atk":120,"def":0,"money":10,"exp":0,"point":0,"special":[1,9]}, "slimelord": {"name":"怪王","hp":100,"atk":120,"def":0,"money":10,"exp":0,"point":0,"special":[1,9]},

View File

@ -30,7 +30,7 @@ main.floors.sample1=
[ 0, 0, 0,151, 0, 0, 0,152,152,221, 0,221,153], [ 0, 0, 0,151, 0, 0, 0,152,152,221, 0,221,153],
[ 0, 0, 0,151, 0, 0, 0,121, 0, 0, 0, 0,153], [ 0, 0, 0,151, 0, 0, 0,121, 0, 0, 0, 0,153],
[151, 0,151,151, 0,153,153,153,153,153,153,153,153], [151, 0,151,151, 0,153,153,153,153,153,153,153,153],
[ 0, 0, 0, 0, 0, 0, 0,164, 0, 0,163, 0, 0], [ 0, 0, 0, 0,201, 0, 0,164, 0, 0,163, 0, 0],
[ 1, 1, 1, 1, 0, 20, 0, 0, 0,162, 0,161, 0], [ 1, 1, 1, 1, 0, 20, 0, 0, 0,162, 0,161, 0],
[ 1, 0,123, 1, 0, 20,124, 0,121, 0,122, 0,126], [ 1, 0,123, 1, 0, 20,124, 0,121, 0,122, 0,126],
[ 1, 0, 0, 1, 88, 20, 0, 0, 0, 0, 0, 0, 0] [ 1, 0, 0, 1, 88, 20, 0, 0, 0, 0, 0, 0, 0]
@ -626,5 +626,12 @@ main.floors.sample1=
}, },
"width": 13, "width": 13,
"height": 13, "height": 13,
"beforeBattle": {} "beforeBattle": {},
"cannotMoveIn": {},
"bg2map": [
],
"fg2map": [
]
} }

View File

@ -1059,15 +1059,11 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = {
let x = this.x; let x = this.x;
let y = this.y; let y = this.y;
const { x: dx, y: dy } = core.utils.scan[dir]; const { x: dx, y: dy } = core.utils.scan[dir];
this.col.list.forEach(v => {
if (v.x === x + dx * 2 && v.y === y + dy * 2) {
const loc = `${x + dx},${y + dy}`; const loc = `${x + dx},${y + dy}`;
this.setMapDamage(damage, loc, 0); this.setMapDamage(damage, loc, 0);
damage[loc].ambush = damage[loc].ambush ?? []; damage[loc].ambush = damage[loc].ambush ?? [];
damage[loc].ambush.push(this); damage[loc].ambush.push(this);
} }
});
}
} }
return damage; return damage;
@ -1307,10 +1303,9 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = {
for (const enemy of info.ambush) { for (const enemy of info.ambush) {
actions.push({ actions.push({
type: 'function', type: 'function',
function: function: () => {
'function() { ' + core.battle(enemy, void 0, true, core.doAction);
`core.battle(${enemy.x}, ${enemy.y}, true, core.doAction); ` + },
'}',
async: true async: true
}); });
} }

View File

@ -23,25 +23,37 @@ export function getEnemy(
function init() { function init() {
core.enemys.canBattle = function canBattle( core.enemys.canBattle = function canBattle(
x: number, x: number | DamageEnemy,
y: number, y: number,
floorId: FloorIds = core.status.floorId floorId: FloorIds = core.status.floorId
) { ) {
const enemy = getEnemy(x, y, floorId); const enemy = typeof x === 'number' ? getEnemy(x, y, floorId) : x;
const { damage } = enemy!.calDamage(); if (!enemy) {
throw new Error(
`Cannot get enemy on x:${x}, y:${y}, floor: ${floorId}`
);
}
const { damage } = enemy.calDamage();
return damage < core.status.hero.hp; return damage < core.status.hero.hp;
}; };
core.events.battle = function battle( core.events.battle = function battle(
x: number, x: number | DamageEnemy,
y: number, y: number,
force: boolean = false, force: boolean = false,
callback?: () => void callback?: () => void
) { ) {
core.saveAndStopAutomaticRoute(); core.saveAndStopAutomaticRoute();
const enemy = getEnemy(x, y); const isLoc = typeof x === 'number';
const enemy = isLoc ? getEnemy(x, y) : x;
if (!enemy) {
throw new Error(
`Cannot battle with enemy since no enemy on ${x},${y}`
);
}
// 非强制战斗 // 非强制战斗
// @ts-ignore
if (!core.canBattle(x, y) && !force && !core.status.event.id) { if (!core.canBattle(x, y) && !force && !core.status.event.id) {
core.stopSound(); core.stopSound();
core.playSound('操作失败'); core.playSound('操作失败');
@ -52,7 +64,7 @@ function init() {
if (!core.status.event.id) core.autosave(true); if (!core.status.event.id) core.autosave(true);
// 战前事件 // 战前事件
// 战后事件 // 战后事件
core.afterBattle(enemy, x, y); core.afterBattle(enemy, isLoc ? x : enemy.x, y);
callback?.(); callback?.();
}; };
@ -149,5 +161,22 @@ loading.once('coreInit', init);
declare global { declare global {
interface Enemys { interface Enemys {
getCurrentEnemys(floorId: FloorIds): CurrentEnemy[]; getCurrentEnemys(floorId: FloorIds): CurrentEnemy[];
canBattle(enemy: DamageEnemy, _?: number, floorId?: FloorIds): boolean;
canBattle(x: number, y: number, floorId?: FloorIds): boolean;
}
interface Events {
battle(
enemy: DamageEnemy,
_?: number,
force?: boolean,
callback?: () => void
): void;
battle(
x: number,
y?: number,
force?: boolean,
callback?: () => void
): void;
} }
} }

16
src/types/enemy.d.ts vendored
View File

@ -253,22 +253,6 @@ interface Enemys {
getEnemys(): { getEnemys(): {
[P in EnemyIds]: Enemy<P>; [P in EnemyIds]: Enemy<P>;
}; };
/**
*
* @example core.canBattle('greenSlime',0,0,'MT0') // 能否打败主塔0层左上角的绿头怪假设有
* @param enemy id或敌人对象
* @param x
* @param y
* @param floorId
* @returns true表示可以打败false表示无法打败
*/
canBattle(
x: number,
y: number,
floorId?: FloorIds,
dir?: Dir | 'none' | (Dir | 'none')[]
): boolean;
} }
declare const enemys: new () => Enemys; declare const enemys: new () => Enemys;

16
src/types/event.d.ts vendored
View File

@ -99,22 +99,6 @@ interface Events extends EventData {
*/ */
trigger(x: number, y: number, callback?: () => void): void; trigger(x: number, y: number, callback?: () => void): void;
/**
*
* @example core.battle('greenSlime'); // 和从天而降的绿头怪战斗(如果打得过)
* @param id id
* @param x
* @param y
* @param force true表示强制战斗
* @param callback
*/
battle(
x: number,
y: number,
force: boolean = false,
callback?: () => void
): void;
/** /**
* *
* @example core.openDoor(0, 0, true, core.jumpHero); // 打开左上角的门,需要钥匙,然后主角原地跳跃半秒 * @example core.openDoor(0, 0, true, core.jumpHero); // 打开左上角的门,需要钥匙,然后主角原地跳跃半秒