refactor: 激光地图伤害换用新 IFaceManager 接口

This commit is contained in:
unanmed 2026-05-12 19:59:10 +08:00
parent 43ad3fd83e
commit 93b5349248
3 changed files with 24 additions and 41 deletions

View File

@ -245,7 +245,7 @@ export interface IMapDamageView<T = any> {
getDamageAt(locator: ITileLocator): Readonly<IMapDamageInfo> | null; getDamageAt(locator: ITileLocator): Readonly<IMapDamageInfo> | null;
/** /**
* *
* @param locator * @param locator
*/ */
getDamageWithoutCheck( getDamageWithoutCheck(

View File

@ -7,6 +7,7 @@ import {
ITileLocator ITileLocator
} from '@motajs/common'; } from '@motajs/common';
import { FaceDirection } from './types'; import { FaceDirection } from './types';
import { IFaceHandler } from './faceManager';
//#region 对象移动 //#region 对象移动
@ -278,6 +279,14 @@ export abstract class ObjectMover<T extends IObjectMovable>
/** 是否调用了 `IMoverController.stop` 接口 */ /** 是否调用了 `IMoverController.stop` 接口 */
private shouldStop: boolean = false; private shouldStop: boolean = false;
/** 朝向处理 */
private readonly faceHandler: IFaceHandler<FaceDirection>;
constructor(faceHandler: IFaceHandler<FaceDirection>) {
super();
this.faceHandler = faceHandler;
}
protected createController( protected createController(
hook: Partial<IObjectMoverHooks<T>> hook: Partial<IObjectMoverHooks<T>>
): IHookController<IObjectMoverHooks<T>> { ): IHookController<IObjectMoverHooks<T>> {
@ -349,34 +358,6 @@ export abstract class ObjectMover<T extends IObjectMovable>
} }
} }
// TODO: 需要做一个朝向系统以解决朝向难以处理的问题
/**
*
* @param dir
*/
private getOppositeDirection(dir: FaceDirection): FaceDirection {
switch (dir) {
case FaceDirection.Left:
return FaceDirection.Right;
case FaceDirection.Up:
return FaceDirection.Down;
case FaceDirection.Right:
return FaceDirection.Left;
case FaceDirection.Down:
return FaceDirection.Up;
case FaceDirection.LeftUp:
return FaceDirection.RightDown;
case FaceDirection.RightUp:
return FaceDirection.LeftDown;
case FaceDirection.LeftDown:
return FaceDirection.RightUp;
case FaceDirection.RightDown:
return FaceDirection.LeftUp;
case FaceDirection.Unknown:
return FaceDirection.Unknown;
}
}
/** /**
* *
* @param step * @param step
@ -397,7 +378,7 @@ export abstract class ObjectMover<T extends IObjectMovable>
case ObjectMoveStepType.Special: { case ObjectMoveStepType.Special: {
const dir = this.getCurrentDirection(); const dir = this.getCurrentDirection();
if (step.direction === ObjectSpecialStep.Backward) { if (step.direction === ObjectSpecialStep.Backward) {
const opposite = this.getOppositeDirection(dir); const opposite = this.faceHandler.opposite(dir);
this.moveDirection = opposite; this.moveDirection = opposite;
this.faceDirection = opposite; this.faceDirection = opposite;
} else { } else {

View File

@ -1,7 +1,4 @@
import { import {
DirectionMapper,
IDirectionDescriptor,
InternalDirectionGroup,
IManhattanRangeParam, IManhattanRangeParam,
IRange, IRange,
IRayRangeParam, IRayRangeParam,
@ -9,7 +6,8 @@ import {
ManhattanRange, ManhattanRange,
RayRange, RayRange,
RectRange, RectRange,
ITileLocator ITileLocator,
IDirectionDescriptor
} from '@motajs/common'; } from '@motajs/common';
import { import {
IEnemyContext, IEnemyContext,
@ -21,7 +19,9 @@ import {
ISpecial, ISpecial,
IMapDamageView, IMapDamageView,
IReadonlyHeroAttribute, IReadonlyHeroAttribute,
IReadonlyEnemy IReadonlyEnemy,
IFaceHandler,
InternalFaceGroup
} from '@user/data-base'; } from '@user/data-base';
import { IZoneValue } from './special'; import { IZoneValue } from './special';
import { IEnemyAttr, MapDamageType } from './types'; import { IEnemyAttr, MapDamageType } from './types';
@ -31,9 +31,6 @@ const RECT_RANGE = new RectRange();
const MANHATTAN_RANGE = new ManhattanRange(); const MANHATTAN_RANGE = new ManhattanRange();
const RAY_RANGE = new RayRange(); const RAY_RANGE = new RayRange();
const DIRECTION_MAPPER = new DirectionMapper();
const DIR4 = [...DIRECTION_MAPPER.map(InternalDirectionGroup.Dir4)];
//#region 地图伤害 //#region 地图伤害
abstract class BaseMapDamageView<T> implements IMapDamageView<T> { abstract class BaseMapDamageView<T> implements IMapDamageView<T> {
@ -154,13 +151,17 @@ export class RepulseDamageView extends BaseMapDamageView<IManhattanRangeParam> {
} }
export class LaserDamageView extends BaseMapDamageView<IRayRangeParam> { export class LaserDamageView extends BaseMapDamageView<IRayRangeParam> {
/** 激光方向列表 */
private readonly dirs: IDirectionDescriptor[];
constructor( constructor(
context: IEnemyContext<IEnemyAttr, IHeroAttr>, context: IEnemyContext<IEnemyAttr, IHeroAttr>,
private readonly locator: Readonly<ITileLocator>, private readonly locator: Readonly<ITileLocator>,
private readonly special: Readonly<ISpecial<number>>, private readonly special: Readonly<ISpecial<number>>,
private readonly dir: IDirectionDescriptor[] = DIR4 dir: IFaceHandler<number>
) { ) {
super(context); super(context);
this.dirs = [...dir.mapMovement()].map(v => v[1]);
} }
getRange(): IRange<IRayRangeParam> { getRange(): IRange<IRayRangeParam> {
@ -171,7 +172,7 @@ export class LaserDamageView extends BaseMapDamageView<IRayRangeParam> {
return { return {
cx: this.locator.x, cx: this.locator.x,
cy: this.locator.y, cy: this.locator.y,
dir: this.dir dir: this.dirs
}; };
} }
@ -309,7 +310,8 @@ export class MainMapDamageConverter implements IMapDamageConverter<
const laser = enemy.getSpecial<number>(24); const laser = enemy.getSpecial<number>(24);
if (laser) { if (laser) {
views.push(new LaserDamageView(context, locator, laser)); const face = handler.data.faceManager.get(InternalFaceGroup.Dir4)!;
views.push(new LaserDamageView(context, locator, laser, face));
} }
if (enemy.hasSpecial(27)) { if (enemy.hasSpecial(27)) {