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 () {
console.trace();
core.status.lockControl = true;
};

View File

@ -138,7 +138,9 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = {
core.maps.resizeMap(floorId);
// 设置勇士的位置
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.drawMap(floorId);
@ -172,6 +174,7 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = {
else core.setWeather();
checkLoopMap();
core.updateDamage();
// ...可以新增一些其他内容,比如创建个画布在右上角显示什么内容等等
},

View File

@ -97,6 +97,10 @@ export function init() {
}
}
function move(dir: Dir) {
moveDir = dir;
}
function continueAfterEnd() {
requestAnimationFrame(() => {
if (pressedArrow.size === 0 || moving) {
@ -144,7 +148,6 @@ export function init() {
if (noPass || !canMove) {
onCannotMove(canMove, callback);
if (moving) endMove();
// onMoveEnd(true);
return false;
}
return true;
@ -163,8 +166,9 @@ export function init() {
*/
function checkCanMove() {
const { nx, ny } = getNextLoc();
const { x, y } = core.status.hero.loc;
const noPass = core.noPass(nx, ny);
const canMove = core.canMoveHero(nx, ny, stepDir);
const canMove = core.canMoveHero(x, y, stepDir);
return { noPass, canMove };
}
@ -203,181 +207,15 @@ export function init() {
// ----- 勇士移动相关
control.prototype._moveAction_moving = function (callback?: () => void) {
return;
const adapter = adapters['hero-adapter'];
if (!adapter) {
onMoveEnd(callback);
return;
} else {
core.status.heroMoving = 1;
adapter
.all('readyMove')
.then(() => {
return adapter.all('move', 'forward');
})
.then(() => {
onMoveEnd(callback);
core.status.heroMoving = 0;
return adapter.all('endMove');
});
}
};
const dir8to4: Record<Dir2, Dir> = {
up: 'up',
down: 'down',
left: 'left',
right: 'right',
leftup: 'left',
leftdown: 'left',
rightup: 'right',
rightdown: 'right'
};
Mota.r(() => {
control.prototype._moveAction_moving = function (
callback?: () => void
) {};
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);
core.setHeroLoc('y', ny, true);
core.setHeroLoc('direction', nowDir, true);
core.updateFollowers();
core.status.heroMoving = 0;
core.drawHero();
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(
// function () {
// if (moveSteps.length == 0) {
// delete core.animateFrame.asyncId[animate];
// 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',
@ -401,32 +239,13 @@ export function init() {
////// 停止勇士的一切行动等待勇士行动结束后再执行callback //////
control.prototype.waitHeroToStop = function (callback?: () => void) {
var lastDirection = core.status.automaticRoute.lastDirection;
core.stopAutomaticRoute();
core.clearContinueAutomaticRoute();
if (!main.replayChecking) {
moveEnding.then(() => {
callback?.();
});
return;
}
if (callback) {
// @ts-ignore
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
);
}
};
});
return { readyMove, endMove, move };
}