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;
/**
*
*
* @param locator
*/
getDamageWithoutCheck(

View File

@ -7,6 +7,7 @@ import {
ITileLocator
} from '@motajs/common';
import { FaceDirection } from './types';
import { IFaceHandler } from './faceManager';
//#region 对象移动
@ -278,6 +279,14 @@ export abstract class ObjectMover<T extends IObjectMovable>
/** 是否调用了 `IMoverController.stop` 接口 */
private shouldStop: boolean = false;
/** 朝向处理 */
private readonly faceHandler: IFaceHandler<FaceDirection>;
constructor(faceHandler: IFaceHandler<FaceDirection>) {
super();
this.faceHandler = faceHandler;
}
protected createController(
hook: Partial<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
@ -397,7 +378,7 @@ export abstract class ObjectMover<T extends IObjectMovable>
case ObjectMoveStepType.Special: {
const dir = this.getCurrentDirection();
if (step.direction === ObjectSpecialStep.Backward) {
const opposite = this.getOppositeDirection(dir);
const opposite = this.faceHandler.opposite(dir);
this.moveDirection = opposite;
this.faceDirection = opposite;
} else {

View File

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