mirror of
https://github.com/motajs/template.git
synced 2026-07-17 09:21:09 +08:00
feat: 勇士默认撞击行为
This commit is contained in:
parent
c4bcecdf8a
commit
1ce0283743
@ -212,7 +212,7 @@ export interface IHeroLocation
|
||||
/** 当前所在楼层 id,undefined 表示尚不处于任何楼层 */
|
||||
readonly floorId: string | undefined;
|
||||
/** 勇士的移动对象 */
|
||||
readonly mover: IObjectMover<this>;
|
||||
readonly mover: IHeroMover<this>;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
|
||||
@ -66,6 +66,8 @@ import { ILoadProgressTotal, LoadProgressTotal } from '@motajs/loader';
|
||||
import { isNil } from 'lodash-es';
|
||||
import { logger } from '@motajs/common';
|
||||
import { ISaveSystem, SaveSystem } from './save';
|
||||
import { DefaultPassChecker } from './hero';
|
||||
import { DefaultHitAction } from './hero/hitAction';
|
||||
|
||||
export class CoreState implements ICoreState {
|
||||
// Layer 0 公共层,最底层的接口,不会依赖任何其他内容,一般是工具性接口及不需要存档的数据
|
||||
@ -208,6 +210,16 @@ export class CoreState implements ICoreState {
|
||||
);
|
||||
});
|
||||
|
||||
// 勇士顶层初始化
|
||||
const passChecker = new DefaultPassChecker(this.maps);
|
||||
const hitAction = new DefaultHitAction(
|
||||
this.maps,
|
||||
this.triggerCollector,
|
||||
this
|
||||
);
|
||||
this.hero.location.mover.useTerrainChecker(passChecker);
|
||||
this.hero.location.mover.useHitAction(hitAction);
|
||||
|
||||
//#endregion
|
||||
}
|
||||
|
||||
|
||||
37
packages-user/data-state/src/hero/hitAction.ts
Normal file
37
packages-user/data-state/src/hero/hitAction.ts
Normal file
@ -0,0 +1,37 @@
|
||||
import {
|
||||
IHeroHitAction,
|
||||
IHeroHitHandler,
|
||||
IMapStore,
|
||||
IStateBase
|
||||
} from '@user/data-base';
|
||||
import { ITriggerCollector, ITriggerHandler } from '@user/data-system';
|
||||
import { isNil } from 'lodash-es';
|
||||
|
||||
export class DefaultHitAction implements IHeroHitAction {
|
||||
constructor(
|
||||
readonly maps: IMapStore,
|
||||
readonly collector: ITriggerCollector,
|
||||
readonly state: IStateBase
|
||||
) {}
|
||||
|
||||
async hit(handler: IHeroHitHandler): Promise<void> {
|
||||
if (isNil(handler.floorId)) return;
|
||||
|
||||
const map = this.maps.getLayerState(handler.floorId);
|
||||
if (!map) return;
|
||||
const event = map.eventLayer;
|
||||
if (!event) return;
|
||||
|
||||
const { x, y } = handler.nextLoc;
|
||||
const triggers = this.collector.collect(x, y, event);
|
||||
|
||||
const triggerHandler: ITriggerHandler = {
|
||||
state: this.state,
|
||||
layer: map,
|
||||
mapLayer: event,
|
||||
locator: handler.nextLoc
|
||||
};
|
||||
|
||||
return triggers.trigger(triggerHandler);
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,5 @@
|
||||
import { FaceDirection, PassBit } from '@user/data-common';
|
||||
import {
|
||||
IHeroState,
|
||||
IMapStore,
|
||||
IPassCheckerHandler,
|
||||
ITerrainPassChecker
|
||||
@ -8,10 +7,7 @@ import {
|
||||
import { isNil } from 'lodash-es';
|
||||
|
||||
export class DefaultPassChecker implements ITerrainPassChecker {
|
||||
constructor(
|
||||
readonly maps: IMapStore,
|
||||
readonly hero: IHeroState<unknown>
|
||||
) {}
|
||||
constructor(readonly maps: IMapStore) {}
|
||||
|
||||
/**
|
||||
* 将朝向转换为对应的通行性位掩码。
|
||||
@ -54,10 +50,10 @@ export class DefaultPassChecker implements ITerrainPassChecker {
|
||||
return true;
|
||||
}
|
||||
|
||||
const layerState = this.maps.getLayerState(floorId);
|
||||
if (!layerState) return false;
|
||||
const eventLayer = layerState.eventLayer;
|
||||
if (!eventLayer) return false;
|
||||
const map = this.maps.getLayerState(floorId);
|
||||
if (!map) return false;
|
||||
const event = map.eventLayer;
|
||||
if (!event) return false;
|
||||
|
||||
const { x, y } = currLoc;
|
||||
const { x: nx, y: ny } = nextLoc;
|
||||
@ -70,8 +66,8 @@ export class DefaultPassChecker implements ITerrainPassChecker {
|
||||
let canEnter = true;
|
||||
|
||||
// 判断事件层
|
||||
const curr = eventLayer.getLocationData(x, y);
|
||||
const next = eventLayer.getLocationData(nx, ny);
|
||||
const curr = event.getLocationData(x, y);
|
||||
const next = event.getLocationData(nx, ny);
|
||||
if (curr && curr.raw) {
|
||||
canLeave = !!(leaveMask & curr.raw.pass.outPass);
|
||||
}
|
||||
@ -82,8 +78,8 @@ export class DefaultPassChecker implements ITerrainPassChecker {
|
||||
if (!canLeave || !canEnter) return false;
|
||||
|
||||
// 判断其他层
|
||||
for (const layer of layerState.layerList) {
|
||||
if (layer === eventLayer) continue;
|
||||
for (const layer of map.layerList) {
|
||||
if (layer === event) continue;
|
||||
const curr = layer.getLocationData(x, y);
|
||||
const next = layer.getLocationData(nx, ny);
|
||||
let canLeave = true;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user