diff --git a/public/libs/events.js b/public/libs/events.js index ad1a5aa..d49758a 100644 --- a/public/libs/events.js +++ b/public/libs/events.js @@ -2833,6 +2833,9 @@ events.prototype._action_function = function (data, x, y, prefix) { if (typeof func == 'string' && func.indexOf('function') == 0) { eval('(' + func + ')()'); } + if (typeof func === 'function') { + func(); + } } catch (e) { console.error(e); } diff --git a/public/project/enemys.js b/public/project/enemys.js index 0d9c8c6..0e505ca 100644 --- a/public/project/enemys.js +++ b/public/project/enemys.js @@ -1,6 +1,6 @@ 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}, "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]}, diff --git a/public/project/floors/sample1.js b/public/project/floors/sample1.js index 2d3f74a..840f27e 100644 --- a/public/project/floors/sample1.js +++ b/public/project/floors/sample1.js @@ -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,121, 0, 0, 0, 0,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, 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] @@ -626,5 +626,12 @@ main.floors.sample1= }, "width": 13, "height": 13, - "beforeBattle": {} + "beforeBattle": {}, + "cannotMoveIn": {}, + "bg2map": [ + +], + "fg2map": [ + +] } \ No newline at end of file diff --git a/public/project/plugins.js b/public/project/plugins.js index 3c9abd9..280b8ca 100644 --- a/public/project/plugins.js +++ b/public/project/plugins.js @@ -1059,14 +1059,10 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = { let x = this.x; let y = this.y; 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}`; - this.setMapDamage(damage, loc, 0); - damage[loc].ambush = damage[loc].ambush ?? []; - damage[loc].ambush.push(this); - } - }); + const loc = `${x + dx},${y + dy}`; + this.setMapDamage(damage, loc, 0); + damage[loc].ambush = damage[loc].ambush ?? []; + damage[loc].ambush.push(this); } } @@ -1307,10 +1303,9 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = { for (const enemy of info.ambush) { actions.push({ type: 'function', - function: - 'function() { ' + - `core.battle(${enemy.x}, ${enemy.y}, true, core.doAction); ` + - '}', + function: () => { + core.battle(enemy, void 0, true, core.doAction); + }, async: true }); } diff --git a/src/game/enemy/battle.ts b/src/game/enemy/battle.ts index 653de76..acfa2ec 100644 --- a/src/game/enemy/battle.ts +++ b/src/game/enemy/battle.ts @@ -23,25 +23,37 @@ export function getEnemy( function init() { core.enemys.canBattle = function canBattle( - x: number, + x: number | DamageEnemy, y: number, floorId: FloorIds = core.status.floorId ) { - const enemy = getEnemy(x, y, floorId); - const { damage } = enemy!.calDamage(); + const enemy = typeof x === 'number' ? getEnemy(x, y, floorId) : x; + 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; }; core.events.battle = function battle( - x: number, + x: number | DamageEnemy, y: number, force: boolean = false, callback?: () => void ) { 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) { core.stopSound(); core.playSound('操作失败'); @@ -52,7 +64,7 @@ function init() { if (!core.status.event.id) core.autosave(true); // 战前事件 // 战后事件 - core.afterBattle(enemy, x, y); + core.afterBattle(enemy, isLoc ? x : enemy.x, y); callback?.(); }; @@ -149,5 +161,22 @@ loading.once('coreInit', init); declare global { interface Enemys { 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; } } diff --git a/src/types/enemy.d.ts b/src/types/enemy.d.ts index 201a1d4..ddd6305 100644 --- a/src/types/enemy.d.ts +++ b/src/types/enemy.d.ts @@ -253,22 +253,6 @@ interface Enemys { getEnemys(): { [P in EnemyIds]: Enemy

; }; - - /** - * 判定主角当前能否打败某只敌人 - * @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; diff --git a/src/types/event.d.ts b/src/types/event.d.ts index f19d62b..7263ff5 100644 --- a/src/types/event.d.ts +++ b/src/types/event.d.ts @@ -99,22 +99,6 @@ interface Events extends EventData { */ 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); // 打开左上角的门,需要钥匙,然后主角原地跳跃半秒