mirror of
https://github.com/motajs/template.git
synced 2026-11-30 02:34:30 +08:00
refactor: 寻路系统改进
This commit is contained in:
1 parent
50b8b3e651
commit
4aaea68b65
17 files changed
+251
-323
No files matched your search
@@ -12,6 +12,7 @@ import {
|
||||
IHeroLocationSave,
|
||||
IHeroMover
|
||||
} from './types';
|
||||
import { IGameMap } from '../map';
|
||||
|
||||
export class HeroLocation
|
||||
extends Hookable<IHeroLocationHooks>
|
||||
@@ -20,6 +21,7 @@ export class HeroLocation
|
||||
x: number;
|
||||
y: number;
|
||||
floorId: string | undefined = undefined;
|
||||
map: IGameMap | null = null;
|
||||
|
||||
readonly state: IDataCommon;
|
||||
readonly mover: IHeroMover<this>;
|
||||
@@ -44,9 +46,10 @@ export class HeroLocation
|
||||
return new HookController(this, hook);
|
||||
}
|
||||
|
||||
setFloor(floorId: string | undefined): void {
|
||||
this.floorId = floorId;
|
||||
this.forEachHook(hook => hook.onSetFloor?.(floorId));
|
||||
setFloor(map: IGameMap): void {
|
||||
this.floorId = map.floorId;
|
||||
this.map = map;
|
||||
this.forEachHook(hook => hook.onSetFloor?.(map));
|
||||
}
|
||||
|
||||
setPos(x: number, y: number): void {
|
||||
|
||||
@@ -18,6 +18,7 @@ import {
|
||||
IHeroMoveTopImpl
|
||||
} from './types';
|
||||
import { isNil } from 'lodash-es';
|
||||
import { IPassCheckHandler } from '../map';
|
||||
|
||||
export class HeroMover<T extends IHeroLocation>
|
||||
extends ObjectMover<T>
|
||||
@@ -196,11 +197,11 @@ export class HeroMover<T extends IHeroLocation>
|
||||
if (this.ignoreTerrain) {
|
||||
return HeroMoveCode.Step;
|
||||
} else {
|
||||
const passHandler = {
|
||||
const passHandler: IPassCheckHandler = {
|
||||
currLoc: handler.currLoc,
|
||||
nextLoc: handler.nextLoc,
|
||||
direction: handler.direction,
|
||||
floorId: handler.floorId,
|
||||
map: this.tile.map,
|
||||
state: handler.state
|
||||
};
|
||||
const predicate = this.topImpl.predicate();
|
||||
@@ -215,6 +216,12 @@ export class HeroMover<T extends IHeroLocation>
|
||||
}
|
||||
}
|
||||
|
||||
// 瞬移录像记录
|
||||
if (type === ObjectMoveType.Teleport) {
|
||||
const replay = this.state.replaySystem;
|
||||
replay.array.add(ReplayCode.Teleport, [step.x, step.y]);
|
||||
}
|
||||
|
||||
// 跳跃和瞬移
|
||||
if (type === ObjectMoveType.Jump || type === ObjectMoveType.Teleport) {
|
||||
if (this.ignoreTerrain) {
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
ISaveableContent,
|
||||
SaveCompression
|
||||
} from '@user/data-common';
|
||||
import { IPassPredicate } from '../map';
|
||||
import { IGameMap, IPassPredicate } from '../map';
|
||||
|
||||
//#region 勇士属性
|
||||
|
||||
@@ -280,9 +280,9 @@ export interface IHeroLocationHooks extends IHookBase {
|
||||
|
||||
/**
|
||||
* 当设置勇士所处楼层时触发
|
||||
* @param floorId 设置为的楼层 id,undefined 表示尚不处于任何楼层
|
||||
* @param map 设置为的楼层对象,`null` 表示不处于任何楼层
|
||||
*/
|
||||
onSetFloor?(floorId: string | undefined): void;
|
||||
onSetFloor?(map: IGameMap | null): void;
|
||||
}
|
||||
|
||||
export interface IHeroLocationSave {
|
||||
@@ -302,16 +302,18 @@ export interface IHeroLocation
|
||||
IObjectMovable,
|
||||
IHookable<IHeroLocationHooks>,
|
||||
IDataCommonExtended {
|
||||
/** 当前所在楼层 id,undefined 表示尚不处于任何楼层 */
|
||||
/** 勇士所处楼层的楼层 id,若为 `undefined` 则表示不在任何楼层 */
|
||||
readonly floorId: string | undefined;
|
||||
/** 勇士所处地图,若为 `null` 则表示不在任何楼层 */
|
||||
readonly map: IGameMap | null;
|
||||
/** 勇士的移动对象 */
|
||||
readonly mover: IHeroMover<this>;
|
||||
|
||||
/**
|
||||
* 设置勇士所在的楼层 id,注意此方法会引起数据变化,但是不会产生楼层切换动画
|
||||
* @param floorId 目标楼层 id
|
||||
* 设置勇士所在的楼层,注意此方法会引起数据变化,但是不会产生楼层切换动画
|
||||
* @param map 目标楼层对象
|
||||
*/
|
||||
setFloor(floorId: string | undefined): void;
|
||||
setFloor(map: IGameMap | null): void;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
@@ -840,7 +842,7 @@ export interface IHeroEquipment<THero>
|
||||
|
||||
export interface IHeroChangeFloorInfo {
|
||||
/** 要切换至的目标楼层 */
|
||||
readonly target: string;
|
||||
readonly target: IGameMap;
|
||||
/** 要切换至的目标位置横坐标 */
|
||||
readonly x: number;
|
||||
/** 要切换至的目标位置纵坐标 */
|
||||
|
||||
@@ -855,13 +855,13 @@ export interface IPassCheckHandler extends IDataCommonExtended {
|
||||
readonly nextLoc: ITileLocator;
|
||||
/** 移动方向 */
|
||||
readonly direction: FaceDirection;
|
||||
/** 当前楼层 id */
|
||||
readonly floorId: string | undefined;
|
||||
/** 地图对象 */
|
||||
readonly map: IGameMap | null;
|
||||
}
|
||||
|
||||
export interface IPassPredicate {
|
||||
/**
|
||||
* 检查在指定楼层中,能否从某一个移动入某一格
|
||||
* 检查在指定楼层中,能否从某一个移动入某一格,若会产生撞击,则此项应返回 `false`
|
||||
* @param handler 通行性检查信息对象
|
||||
*/
|
||||
canPass(handler: IPassCheckHandler): boolean;
|
||||
|
||||
Reference in new issue
Block a user