mirror of
https://github.com/unanmed/HumanBreak.git
synced 2026-11-18 13:24:30 +08:00
refactor: 循环式地图
This commit is contained in:
1 parent
2bf0fbe781
commit
48ce4a2fb7
16 files changed
+471
-291
No files matched your search
+2
-1
@@ -34,7 +34,8 @@ Mota.register('var', 'loading', loading);
|
||||
// ----- 模块注册
|
||||
Mota.register('module', 'Mechanism', {
|
||||
BluePalace: miscMechanism.BluePalace,
|
||||
NightSpecial: miscMechanism.NightSpecial
|
||||
NightSpecial: miscMechanism.NightSpecial,
|
||||
MiscData: miscMechanism.MiscData
|
||||
});
|
||||
Mota.register('module', 'State', {
|
||||
ItemState,
|
||||
|
||||
@@ -2,6 +2,14 @@ import { backDir, has } from '@/plugin/game/utils';
|
||||
import { loading } from '../game';
|
||||
import type { LayerDoorAnimate } from '@/core/render/preset/floor';
|
||||
|
||||
/**
|
||||
* 一些零散机制的数据
|
||||
*/
|
||||
export namespace MiscData {
|
||||
/** 循环式地图 */
|
||||
export const loopMaps: Set<FloorIds> = new Set(['tower6']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 永夜/极昼
|
||||
*/
|
||||
|
||||
+113
-6
@@ -1,5 +1,5 @@
|
||||
import EventEmitter from 'eventemitter3';
|
||||
import { backDir, toDir } from './utils';
|
||||
import { backDir, checkCanMoveExtended, toDir } from './utils';
|
||||
import { loading } from '../game';
|
||||
import type { RenderAdapter } from '@/core/render/adapter';
|
||||
import type { HeroRenderer } from '@/core/render/preset/hero';
|
||||
@@ -8,10 +8,11 @@ import type { HeroKeyMover } from '@/core/main/action/move';
|
||||
import type {
|
||||
FloorLayer,
|
||||
Layer,
|
||||
LayerGroup,
|
||||
LayerMovingRenderable
|
||||
} from '@/core/render/preset/layer';
|
||||
import type { LayerFloorBinder } from '@/core/render/preset/floor';
|
||||
import { BluePalace } from '../mechanism/misc';
|
||||
import { BluePalace, MiscData } from '../mechanism/misc';
|
||||
|
||||
interface MoveStepDir {
|
||||
type: 'dir';
|
||||
@@ -425,7 +426,9 @@ const enum HeroMoveCode {
|
||||
/** 不能移动,同时当前格有CannotOut,或目标格有CannotIn,不会触发前面一格的触发器 */
|
||||
CannotMove,
|
||||
/** 进入传送门 */
|
||||
Portal
|
||||
Portal,
|
||||
/** 循环式地图 */
|
||||
Loop
|
||||
}
|
||||
|
||||
export class HeroMover extends ObjectMoverBase {
|
||||
@@ -478,8 +481,10 @@ export class HeroMover extends ObjectMoverBase {
|
||||
protected async onMoveStart(controller: IMoveController): Promise<void> {
|
||||
this.beforeMoveSpeed = this.moveSpeed;
|
||||
const adapter = HeroMover.adapter;
|
||||
if (!adapter) return;
|
||||
const viewport = HeroMover.viewport;
|
||||
if (!adapter || !viewport) return;
|
||||
await adapter.all('readyMove');
|
||||
viewport.sync('startMove');
|
||||
adapter.sync('startAnimate');
|
||||
}
|
||||
|
||||
@@ -487,8 +492,10 @@ export class HeroMover extends ObjectMoverBase {
|
||||
this.moveSpeed = this.beforeMoveSpeed;
|
||||
this.onSetMoveSpeed(this.moveSpeed, controller);
|
||||
const adapter = HeroMover.adapter;
|
||||
if (!adapter) return;
|
||||
const viewport = HeroMover.viewport;
|
||||
if (!adapter || !viewport) return;
|
||||
await adapter.all('endMove');
|
||||
viewport.sync('endMove');
|
||||
adapter.sync('endAnimate');
|
||||
core.clearContinueAutomaticRoute();
|
||||
core.stopAutomaticRoute();
|
||||
@@ -536,6 +543,25 @@ export class HeroMover extends ObjectMoverBase {
|
||||
if (!canMove) return HeroMoveCode.CannotMove;
|
||||
else return HeroMoveCode.Hit;
|
||||
}
|
||||
|
||||
const floorId = core.status.floorId;
|
||||
if (MiscData.loopMaps.has(core.status.floorId)) {
|
||||
const floor = core.status.maps[floorId];
|
||||
const width = floor.width;
|
||||
if (x === 0 && dir === 'left') {
|
||||
await Promise.all([
|
||||
this.renderHeroLoop(),
|
||||
this.moveAnimate(nx, ny, showDir, dir)
|
||||
]);
|
||||
return HeroMoveCode.Loop;
|
||||
} else if (x === width - 1 && dir === 'right') {
|
||||
await Promise.all([
|
||||
this.renderHeroLoop(),
|
||||
this.moveAnimate(nx, ny, showDir, dir)
|
||||
]);
|
||||
return HeroMoveCode.Loop;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 可以移动,显示移动动画
|
||||
@@ -572,13 +598,21 @@ export class HeroMover extends ObjectMoverBase {
|
||||
}
|
||||
|
||||
// 本次移动正常完成
|
||||
if (code === HeroMoveCode.Step || code === HeroMoveCode.Portal) {
|
||||
if (
|
||||
code === HeroMoveCode.Step ||
|
||||
code === HeroMoveCode.Portal ||
|
||||
code === HeroMoveCode.Loop
|
||||
) {
|
||||
if (code === HeroMoveCode.Portal) {
|
||||
const data = this.portalData;
|
||||
if (!data) return;
|
||||
core.setHeroLoc('x', data.x);
|
||||
core.setHeroLoc('y', data.y);
|
||||
core.setHeroLoc('direction', data.dir);
|
||||
} else if (code === HeroMoveCode.Loop) {
|
||||
const map = core.status.thisMap;
|
||||
if (x === 0) core.setHeroLoc('x', map.width - 1);
|
||||
else core.setHeroLoc('x', 0);
|
||||
} else {
|
||||
core.setHeroLoc('x', nx, true);
|
||||
core.setHeroLoc('y', ny, true);
|
||||
@@ -644,6 +678,21 @@ export class HeroMover extends ObjectMoverBase {
|
||||
* @param dir 移动方向
|
||||
*/
|
||||
private checkCanMove(x: number, y: number, dir: Dir): CanMoveStatus {
|
||||
// 如果是循环式地图
|
||||
const floorId = core.status.floorId;
|
||||
if (MiscData.loopMaps.has(floorId)) {
|
||||
const floor = core.status.maps[floorId];
|
||||
const width = floor.width;
|
||||
if (x === 0 && dir === 'left') {
|
||||
const noPass = core.noPass(width - 1, y);
|
||||
const move = checkCanMoveExtended(0, y, width - 1, y, 'left');
|
||||
return { noPass, canMove: move };
|
||||
} else if (x === width - 1 && dir === 'right') {
|
||||
const noPass = core.noPass(0, y);
|
||||
const move = checkCanMoveExtended(width - 1, y, 0, y, 'right');
|
||||
return { noPass, canMove: move };
|
||||
}
|
||||
}
|
||||
const { x: nx, y: ny } = this.nextLoc(x, y, dir);
|
||||
const noPass = core.noPass(nx, ny);
|
||||
const canMove = core.canMoveHero(x, y, dir);
|
||||
@@ -777,6 +826,64 @@ export class HeroMover extends ObjectMoverBase {
|
||||
|
||||
return Promise.all(promises);
|
||||
}
|
||||
|
||||
private renderHeroLoop() {
|
||||
const adapter = HeroMover.adapter;
|
||||
const viewport = HeroMover.viewport;
|
||||
if (!adapter || !viewport) return;
|
||||
const MotaRenderer = Mota.require('module', 'Render').MotaRenderer;
|
||||
const render = MotaRenderer.get('render-main');
|
||||
const group = render?.getElementById('layer-loop') as LayerGroup;
|
||||
const layer = group?.getLayer('event');
|
||||
const mainGroup = render?.getElementById('layer-main') as LayerGroup;
|
||||
const mainLayer = mainGroup?.getLayer('event');
|
||||
const hero = mainLayer?.getExtends('floor-hero') as HeroRenderer;
|
||||
const renderable = hero?.renderable;
|
||||
if (!layer || !hero || !renderable) return;
|
||||
const { x, y } = core.status.hero.loc;
|
||||
const width = core.status.thisMap.width;
|
||||
const loopHero = { ...renderable };
|
||||
layer.moving.add(loopHero);
|
||||
|
||||
let target: number;
|
||||
let from: number;
|
||||
if (x === 0) {
|
||||
from = width;
|
||||
target = width - 1;
|
||||
} else {
|
||||
from = -1;
|
||||
target = 0;
|
||||
}
|
||||
const delta = target - from;
|
||||
loopHero.x = from;
|
||||
|
||||
layer.requestUpdateMoving();
|
||||
|
||||
const startTime = Date.now();
|
||||
return new Promise<void>(res => {
|
||||
layer.delegateTicker(
|
||||
() => {
|
||||
const progress = (Date.now() - startTime) / this.moveSpeed;
|
||||
const dx = delta * progress;
|
||||
loopHero.x = dx + from;
|
||||
layer.update(layer);
|
||||
console.log(
|
||||
loopHero.x,
|
||||
loopHero.y,
|
||||
renderable.x,
|
||||
renderable.y
|
||||
);
|
||||
},
|
||||
this.moveSpeed,
|
||||
() => {
|
||||
layer.moving.delete(loopHero);
|
||||
layer.requestUpdateMoving();
|
||||
viewport.all('setPosition', x === 0 ? width - 1 : 0, y);
|
||||
res();
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
interface HeroMoveCollection {
|
||||
|
||||
@@ -33,3 +33,75 @@ export function backDir(dir: Dir2): Dir2;
|
||||
export function backDir(dir: Dir2): Dir2 {
|
||||
return backDirMap[dir];
|
||||
}
|
||||
|
||||
export function locInMap(x: number, y: number, floorId: FloorIds) {
|
||||
const { width, height } = core.status.maps[floorId];
|
||||
return x >= 0 && y >= 0 && x < width && y < height;
|
||||
}
|
||||
|
||||
/**
|
||||
* 广义检查能否移动,指定两个点以及行走方向,返回能否执行上述移动。
|
||||
* 可以传入地图之外的点,视为可以随意移动。仅检查 cannotIn 和 cannotOut,不检查 noPass
|
||||
* @param fx 出点横坐标
|
||||
* @param fy 出点纵坐标
|
||||
* @param tx 入点横坐标
|
||||
* @param ty 入点纵坐标
|
||||
* @param dir 行走方向
|
||||
* @param fromFloorId 出点楼层id
|
||||
* @param toFloorId 入点楼层id
|
||||
*/
|
||||
export function checkCanMoveExtended(
|
||||
fx: number,
|
||||
fy: number,
|
||||
tx: number,
|
||||
ty: number,
|
||||
dir: Dir,
|
||||
fromFloorId: FloorIds = core.status.floorId,
|
||||
toFloorId: FloorIds = core.status.floorId
|
||||
) {
|
||||
const fromInMap = locInMap(fx, fy, fromFloorId);
|
||||
const toInMap = locInMap(tx, ty, toFloorId);
|
||||
const map = maps_90f36752_8815_4be8_b32b_d7fad1d0542e;
|
||||
|
||||
if (fromInMap) {
|
||||
const cannotMove = core.floors[fromFloorId].cannotMove;
|
||||
const fromIndex: LocString = `${fx},${fy}`;
|
||||
// 检查当前点是否有不可出
|
||||
if (cannotMove[fromIndex]?.includes(dir)) return false;
|
||||
const blocks = getBlockForLoc(fx, fy, fromFloorId);
|
||||
const can = blocks.some(v => {
|
||||
if (v === 0) return false;
|
||||
const out = map[v as Exclude<AllNumbers, 0>]?.cannotOut;
|
||||
return out?.includes(dir);
|
||||
});
|
||||
if (can) return false;
|
||||
}
|
||||
if (toInMap) {
|
||||
const cannotMoveIn = core.floors[toFloorId].cannotMoveIn;
|
||||
const toIndex: LocString = `${tx},${ty}`;
|
||||
const back = backDir(dir);
|
||||
// 检查目标点是否有不可入
|
||||
if (cannotMoveIn[toIndex]?.includes(back)) return false;
|
||||
const blocks = getBlockForLoc(tx, ty, toFloorId);
|
||||
const can = blocks.some(v => {
|
||||
if (v === 0) return false;
|
||||
const out = map[v as Exclude<AllNumbers, 0>]?.cannotIn;
|
||||
return out?.includes(back);
|
||||
});
|
||||
if (can) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function getBlockForLoc(x: number, y: number, floorId: FloorIds) {
|
||||
const map = core.status.maps[floorId];
|
||||
const floor = core.floors[floorId];
|
||||
return [
|
||||
floor.bgmap[y][x],
|
||||
floor.bg2map[y][x],
|
||||
map.map[y][x],
|
||||
floor.bgmap[y][x],
|
||||
floor.bg2map[y][x]
|
||||
];
|
||||
}
|
||||
+1
-2
@@ -106,13 +106,13 @@ interface ModuleInterface {
|
||||
Mechanism: {
|
||||
BluePalace: typeof misc.BluePalace;
|
||||
NightSpecial: typeof misc.NightSpecial;
|
||||
MiscData: typeof misc.MiscData;
|
||||
};
|
||||
Effect: {
|
||||
Portal: typeof portal;
|
||||
};
|
||||
Render: {
|
||||
texture: typeof texture;
|
||||
main: MotaRenderer;
|
||||
MotaRenderer: typeof MotaRenderer;
|
||||
Container: typeof Container;
|
||||
Sprite: typeof Sprite;
|
||||
@@ -161,7 +161,6 @@ interface PluginInterface {
|
||||
frag_r: typeof import('../plugin/fx/frag');
|
||||
// 游戏进程定义的插件
|
||||
utils_g: typeof import('../plugin/game/utils');
|
||||
loopMap_g: typeof import('../plugin/game/loopMap');
|
||||
shop_g: typeof import('../plugin/game/shop');
|
||||
replay_g: typeof import('../plugin/game/replay');
|
||||
skillTree_g: typeof import('../plugin/game/skillTree');
|
||||
|
||||
Reference in new issue
Block a user