fix: 楼层转换

This commit is contained in:
unanmed 2024-08-21 22:22:21 +08:00
parent b4159159a7
commit 529968a7a1
3 changed files with 44 additions and 223 deletions

View File

@ -3022,7 +3022,6 @@ control.prototype.removeSwitch = function (x, y, floorId, name) {
////// 锁定状态栏,常常用于事件处理 ////// ////// 锁定状态栏,常常用于事件处理 //////
control.prototype.lockControl = function () { control.prototype.lockControl = function () {
console.trace();
core.status.lockControl = true; core.status.lockControl = true;
}; };

View File

@ -138,7 +138,9 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = {
core.maps.resizeMap(floorId); core.maps.resizeMap(floorId);
// 设置勇士的位置 // 设置勇士的位置
heroLoc.direction = core.turnDirection(heroLoc.direction); heroLoc.direction = core.turnDirection(heroLoc.direction);
core.status.hero.loc = heroLoc; core.setHeroLoc('x', heroLoc.x);
core.setHeroLoc('y', heroLoc.y);
core.setHeroLoc('direction', heroLoc.direction);
// ---------- 重绘新地图这一步将会设置core.status.floorId ---------- // // ---------- 重绘新地图这一步将会设置core.status.floorId ---------- //
core.drawMap(floorId); core.drawMap(floorId);
@ -172,6 +174,7 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = {
else core.setWeather(); else core.setWeather();
checkLoopMap(); checkLoopMap();
core.updateDamage();
// ...可以新增一些其他内容,比如创建个画布在右上角显示什么内容等等 // ...可以新增一些其他内容,比如创建个画布在右上角显示什么内容等等
}, },

View File

@ -97,6 +97,10 @@ export function init() {
} }
} }
function move(dir: Dir) {
moveDir = dir;
}
function continueAfterEnd() { function continueAfterEnd() {
requestAnimationFrame(() => { requestAnimationFrame(() => {
if (pressedArrow.size === 0 || moving) { if (pressedArrow.size === 0 || moving) {
@ -144,7 +148,6 @@ export function init() {
if (noPass || !canMove) { if (noPass || !canMove) {
onCannotMove(canMove, callback); onCannotMove(canMove, callback);
if (moving) endMove(); if (moving) endMove();
// onMoveEnd(true);
return false; return false;
} }
return true; return true;
@ -163,8 +166,9 @@ export function init() {
*/ */
function checkCanMove() { function checkCanMove() {
const { nx, ny } = getNextLoc(); const { nx, ny } = getNextLoc();
const { x, y } = core.status.hero.loc;
const noPass = core.noPass(nx, ny); const noPass = core.noPass(nx, ny);
const canMove = core.canMoveHero(nx, ny, stepDir); const canMove = core.canMoveHero(x, y, stepDir);
return { noPass, canMove }; return { noPass, canMove };
} }
@ -203,230 +207,45 @@ export function init() {
// ----- 勇士移动相关 // ----- 勇士移动相关
control.prototype._moveAction_moving = function (callback?: () => void) { Mota.r(() => {
return; control.prototype._moveAction_moving = function (
const adapter = adapters['hero-adapter']; callback?: () => void
if (!adapter) { ) {};
onMoveEnd(callback); events.prototype.eventMoveHero = async function (
return; steps: string[],
} else { time?: number,
core.status.heroMoving = 1; callback?: () => void
) {};
adapter control.prototype.setHeroLoc = function (
.all('readyMove') name: 'x' | 'y' | 'direction',
.then(() => { value: number | Dir,
return adapter.all('move', 'forward'); noGather?: boolean
}) ) {
.then(() => { if (!core.status.hero) return;
onMoveEnd(callback); // @ts-ignore
core.status.heroMoving = 0; core.status.hero.loc[name] = value;
return adapter.all('endMove'); if ((name === 'x' || name === 'y') && !noGather) {
}); this.gatherFollowers();
}
};
const dir8to4: Record<Dir2, Dir> = {
up: 'up',
down: 'down',
left: 'left',
right: 'right',
leftup: 'left',
leftdown: 'left',
rightup: 'right',
rightdown: 'right'
};
events.prototype.eventMoveHero = async function (
steps: string[],
time?: number,
callback?: () => void
) {
return;
time = time || core.values.moveSpeed;
// const render = Mota.require('module', 'Render').heroRender;
var step = 0,
moveSteps = (steps || [])
.map(function (t) {
return [t.split(':')[0], parseInt(t.split(':')[1] || '1')];
})
.filter(function (t) {
return (
[
'up',
'down',
'left',
'right',
'forward',
'backward',
'leftup',
'leftdown',
'rightup',
'rightdown',
'speed'
// @ts-ignore
].indexOf(t[0]) >= 0 && !(t[0] == 'speed' && t[1] < 16)
);
});
if (main.replayChecking) {
// 录像验证中,直接算出来最终位置瞬移过去即可
const steps = moveSteps;
let { x: nx, y: ny, direction: nowDir } = core.status.hero.loc;
while (steps.length > 0) {
const [dir, count] = steps.shift()! as [string, number];
if (dir === 'speed') continue;
let resolved: Dir2;
if (dir === 'forward' || dir === 'backward') resolved = nowDir;
else resolved = dir as Dir2;
nowDir = dir8to4[resolved];
const { x, y } = core.utils.scan2[resolved];
nx += x * count;
ny += y * count;
} }
core.setHeroLoc('x', nx, true); if (name === 'direction') {
core.setHeroLoc('y', ny, true); adapters['hero-adapter']?.sync('turn', value);
core.setHeroLoc('direction', nowDir, true); } else if (name === 'x') {
core.updateFollowers(); adapters['hero-adapter']?.sync('setHeroLoc', value);
core.status.heroMoving = 0; } else {
core.drawHero(); adapters['hero-adapter']?.sync('setHeroLoc', void 0, value);
callback?.();
} else {
const adapter = adapters['hero-adapter'];
if (!adapter) return;
const steps: string[] = [];
moveSteps.forEach(([dir, count]) => {
if (dir === 'speed') {
steps.push(`speed:${count}`);
} else {
steps.push(...Array(count as number).fill(dir as string));
}
});
await adapter.all('readyMove');
core.status.heroMoving = 1;
for (const dir of steps) {
if (dir.startsWith('speed')) {
const speed = parseInt(dir.slice(6));
await adapter.all('setMoveSpeed', speed);
} else {
await adapter.all('move', dir as Move2);
}
} }
await adapter.all('endMove'); };
core.status.heroMoving = 0;
core.drawHero();
callback?.();
}
// core.status.heroMoving = -1;
// // render.move(false);
// var _run = function () {
// var cb = function () {
// core.status.heroMoving = 0;
// // render.move(false);
// core.drawHero();
// if (callback) callback();
// };
// var animate = window.setInterval( ////// 停止勇士的一切行动等待勇士行动结束后再执行callback //////
// function () { control.prototype.waitHeroToStop = function (callback?: () => void) {
// if (moveSteps.length == 0) { core.stopAutomaticRoute();
// delete core.animateFrame.asyncId[animate]; core.clearContinueAutomaticRoute();
// clearInterval(animate);
// cb();
// } else {
// if (
// step == 0 &&
// moveSteps[0][0] == 'speed' &&
// moveSteps[0][1] >= 16
// ) {
// time = moveSteps[0][1];
// moveSteps.shift();
// clearInterval(animate);
// delete core.animateFrame.asyncId[animate];
// _run();
// } else if (
// core.events._eventMoveHero_moving(++step, moveSteps)
// )
// step = 0;
// }
// },
// core.status.replay.speed == 24
// ? 1
// : time / 8 / core.status.replay.speed
// );
// core.animateFrame.lastAsyncId = animate;
// core.animateFrame.asyncId[animate] = cb;
// };
// _run();
};
control.prototype.turnHero = function (direction?: Dir) {
if (direction) {
core.setHeroLoc('direction', direction);
core.drawHero();
core.status.route.push('turn:' + direction);
return;
}
core.setHeroLoc('direction', core.turnDirection(':right') as Dir);
core.drawHero();
core.status.route.push('turn');
core.checkRouteFolding();
if (!main.replayChecking) {
// adapters['hero-adapter']?.sync('turn', direction);
}
};
control.prototype.setHeroLoc = function (
name: 'x' | 'y' | 'direction',
value: number | Dir,
noGather?: boolean
) {
if (!core.status.hero) return;
// @ts-ignore
core.status.hero.loc[name] = value;
if ((name === 'x' || name === 'y') && !noGather) {
this.gatherFollowers();
}
if (name === 'direction') {
adapters['hero-adapter']?.sync('turn', value);
} else if (name === 'x') {
adapters['hero-adapter']?.sync('setHeroLoc', value);
} else {
adapters['hero-adapter']?.sync('setHeroLoc', void 0, value);
}
};
////// 停止勇士的一切行动等待勇士行动结束后再执行callback //////
control.prototype.waitHeroToStop = function (callback?: () => void) {
var lastDirection = core.status.automaticRoute.lastDirection;
core.stopAutomaticRoute();
core.clearContinueAutomaticRoute();
if (!main.replayChecking) {
moveEnding.then(() => { moveEnding.then(() => {
callback?.(); callback?.();
}); });
return; };
} });
if (callback) {
// @ts-ignore return { readyMove, endMove, move };
core.status.replay.animate = true;
core.lockControl();
// @ts-ignore
core.status.automaticRoute.moveDirectly = false;
setTimeout(
function () {
// @ts-ignore
core.status.replay.animate = false;
if (core.isset(lastDirection))
core.setHeroLoc('direction', lastDirection);
core.drawHero();
callback();
},
core.status.replay.speed == 24 ? 1 : 30
);
}
};
} }