diff --git a/public/libs/actions.js b/public/libs/actions.js index df4107c..247af90 100644 --- a/public/libs/actions.js +++ b/public/libs/actions.js @@ -2746,11 +2746,8 @@ actions.prototype._clickReplay = function (x, y) { actions.prototype._clickReplay_fromBeginning = function () { core.ui.closePanel(); - core.startGame( - core.status.hard, - core.getFlag('__seed__'), - core.cloneArray(core.status.route) - ); + const route = core.status.route.slice(); + core.startGame(core.status.hard, core.getFlag('__seed__'), route); }; actions.prototype._clickReplay_fromLoad = function () { diff --git a/src/core/render/renderer/use.ts b/src/core/render/renderer/use.ts index a892c1e..d8eb248 100644 --- a/src/core/render/renderer/use.ts +++ b/src/core/render/renderer/use.ts @@ -46,12 +46,17 @@ type KeyUsing = [Hotkey, symbol]; /** * 在组件中定义按键操作 + * @param noScope 是否不创建新作用域 */ -export function useKey(): KeyUsing { - const sym = Symbol(); - gameKey.use(sym); - onUnmounted(() => { - gameKey.dispose(); - }); - return [gameKey, sym]; +export function useKey(noScope: boolean = false): KeyUsing { + if (noScope) { + return [gameKey, gameKey.scope]; + } else { + const sym = Symbol(); + gameKey.use(sym); + onUnmounted(() => { + gameKey.dispose(); + }); + return [gameKey, sym]; + } } diff --git a/src/plugin/game/replay.ts b/src/plugin/game/replay.ts index 5d18ffa..705532a 100644 --- a/src/plugin/game/replay.ts +++ b/src/plugin/game/replay.ts @@ -152,7 +152,10 @@ export function init() { !core.status.floorId.startsWith('tower') && HeroSkill.learnedSkill(HeroSkill.Jump) ) { - Mota.Plugin.require('skill_g').jumpSkill(); + const success = Mota.Plugin.require('skill_g').jumpSkill(); + core.status.route.push(`useSkill:${toEmit}`); + if (!success) core.replay(); + return true; } else { if (core.hasItem('pickaxe')) { core.useItem('pickaxe'); diff --git a/src/plugin/game/skill.ts b/src/plugin/game/skill.ts index ad79dea..bf8407f 100644 --- a/src/plugin/game/skill.ts +++ b/src/plugin/game/skill.ts @@ -51,14 +51,21 @@ export const jumpIgnoreFloor: Set = new Set([ 'MT93' ]); // 跳跃 -export function jumpSkill() { +export function jumpSkill(callback?: () => void) { if (core.status.floorId.startsWith('tower')) { - return core.drawTip('当前无法使用该技能'); + callback?.(); + core.drawTip('当前无法使用该技能'); + return false; } if (jumpIgnoreFloor.has(core.status.floorId) || flags.onChase) { - return core.drawTip('当前楼层无法使用该技能'); + callback?.(); + core.drawTip('当前楼层无法使用该技能'); + return false; + } + if (!HeroSkill.learnedSkill(HeroSkill.Jump)) { + callback?.(); + return false; } - if (!HeroSkill.learnedSkill(HeroSkill.Jump)) return; if (!flags['jump_' + core.status.floorId]) flags['jump_' + core.status.floorId] = 0; if (core.status.floorId == 'MT14') { @@ -67,11 +74,16 @@ export function jumpSkill() { flags.MT14Jump = true; } if (flags.jump_MT14 === 2 && !flags.MT14Jump) { - return core.drawTip('该地图还有一个必跳的地方,你还没有跳'); + callback?.(); + core.drawTip('该地图还有一个必跳的地方,你还没有跳'); + return false; } } - if (flags['jump_' + core.status.floorId] >= 3) - return core.drawTip('当前地图使用次数已用完'); + if (flags['jump_' + core.status.floorId] >= 3) { + callback?.(); + core.drawTip('当前地图使用次数已用完'); + return false; + } var direction = core.status.hero.loc.direction; var loc = core.status.hero.loc; var checkLoc = {}; @@ -106,13 +118,19 @@ export function jumpSkill() { cls == 'items' || (id.startsWith('X') && !ignoreInJump.event.includes(id)) || (bgId.startsWith('X') && !ignoreInJump.bg.includes(bgId)) - ) - return core.drawTip('当前无法使用技能'); + ) { + callback?.(); + core.drawTip('当前无法使用技能'); + return false; + } // debugger; // 不是怪物且不可以通行 if (noPass && !(cls == 'enemys' || cls == 'enemy48')) { var toLoc = checkNoPass(direction, checkLoc.x, checkLoc.y, true); - if (!toLoc) return; + if (!toLoc) { + callback?.(); + return false; + } core.autosave(); if (flags.chapter <= 1) core.status.hero.hp -= 200 * flags.hard; core.updateStatusBar(); @@ -121,16 +139,25 @@ export function jumpSkill() { core.status.hero.hp = 0; core.updateStatusBar(); core.events.lose('你跳死了'); + callback?.(); + return false; } core.playSound('015-Jump01.ogg'); - core.insertAction([ - { type: 'jumpHero', loc: [toLoc.x, toLoc.y], time: 500 } - ]); + core.insertAction( + [{ type: 'jumpHero', loc: [toLoc.x, toLoc.y], time: 500 }], + void 0, + void 0, + callback + ); + return true; } // 是怪物 if (cls == 'enemys' || cls == 'enemy48') { var firstNoPass = checkNoPass(direction, checkLoc.x, checkLoc.y, false); - if (!firstNoPass) return; + if (!firstNoPass) { + callback?.(); + return false; + } core.autosave(); if (flags.chapter <= 1) core.status.hero.hp -= 200 * flags.hard; core.updateStatusBar(); @@ -139,18 +166,27 @@ export function jumpSkill() { core.status.hero.hp = 0; core.updateStatusBar(); core.events.lose('你跳死了'); + callback?.(); + return false; } core.playSound('015-Jump01.ogg'); - core.insertAction([ - { - type: 'jump', - from: [checkLoc.x, checkLoc.y], - to: [firstNoPass.x, firstNoPass.y], - time: 500, - keep: true - } - ]); + core.insertAction( + [ + { + type: 'jump', + from: [checkLoc.x, checkLoc.y], + to: [firstNoPass.x, firstNoPass.y], + time: 500, + keep: true + } + ], + void 0, + void 0, + callback + ); + return true; } + return false; // 检查一条线上的不可通过 function checkNoPass(direction, x, y, startNo) { @@ -174,8 +210,9 @@ export function jumpSkill() { y > core.status.thisMap.height - 1 || x < 0 || y < 0 - ) + ) { return core.drawTip('当前无法使用技能'); + } var id = core.getBlockId(x, y) || ''; if (core.getBgNumber(x, y)) var bgId =