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