diff --git a/packages-user/data-state/src/enemy/aura.ts b/packages-user/data-state/src/enemy/aura.ts index 0c23d4a..e75bdeb 100644 --- a/packages-user/data-state/src/enemy/aura.ts +++ b/packages-user/data-state/src/enemy/aura.ts @@ -32,11 +32,11 @@ export class CommonAuraConverter implements IAuraConverter { } convert( - special: ISpecial, + special: ISpecial, enemy: IReadonlyEnemy, locator: ITileLocator ): CommonAura { - return new CommonAura(enemy, special as ISpecial, locator); + return new CommonAura(enemy, special, locator); } } @@ -134,17 +134,12 @@ export class GuardAuraConverter implements IAuraConverter { } convert( - special: ISpecial, + special: ISpecial, enemy: IReadonlyEnemy, locator: ITileLocator, context: IEnemyContext ): GuardAura { - return new GuardAura( - context, - enemy, - special as ISpecial, - locator - ); + return new GuardAura(context, enemy, special, locator); } } diff --git a/packages-user/data-state/src/enemy/index.ts b/packages-user/data-state/src/enemy/index.ts index 2e7ac2f..6de8758 100644 --- a/packages-user/data-state/src/enemy/index.ts +++ b/packages-user/data-state/src/enemy/index.ts @@ -1,4 +1,4 @@ export * from './aura'; export * from './damage'; -export * from './mapSpecials'; +export * from './mapDamage'; export * from './special'; diff --git a/packages-user/data-state/src/enemy/mapSpecials.ts b/packages-user/data-state/src/enemy/mapDamage.ts similarity index 96% rename from packages-user/data-state/src/enemy/mapSpecials.ts rename to packages-user/data-state/src/enemy/mapDamage.ts index 3499691..cda0439 100644 --- a/packages-user/data-state/src/enemy/mapSpecials.ts +++ b/packages-user/data-state/src/enemy/mapDamage.ts @@ -74,20 +74,6 @@ abstract class BaseMapDamageView implements IMapDamageView { } }; } - - /** - * 判断一个点是否在上下文范围内 - * @param x 横坐标 - * @param y 纵坐标 - */ - protected isInBounds(x: number, y: number): boolean { - return ( - x >= 0 && - y >= 0 && - x < this.context.width && - y < this.context.height - ); - } } export class ZoneDamageView extends BaseMapDamageView< @@ -232,7 +218,9 @@ export class BetweenDamageView extends BaseMapDamageView { const otherX = locator.x + deltaX; const otherY = locator.y + deltaY; - if (!this.isInBounds(otherX, otherY)) { + const range = this.getRange(); + range.bindHost(this.context); + if (!range.inBound(otherX, otherY)) { return null; } diff --git a/packages/common/src/utils/range.ts b/packages/common/src/utils/range.ts index 25e5f4e..2ddecb4 100644 --- a/packages/common/src/utils/range.ts +++ b/packages/common/src/utils/range.ts @@ -20,7 +20,7 @@ export abstract class BaseRange implements IRange { * @param x 横坐标 * @param y 纵坐标 */ - protected isInBounds(x: number, y: number) { + inBound(x: number, y: number) { const { width, height } = this.host; return x >= 0 && y >= 0 && x < width && y < height; } @@ -29,7 +29,7 @@ export abstract class BaseRange implements IRange { * 判断一个坐标索引是否在宿主对象范围内 * @param index 坐标索引 */ - protected isValidIndex(index: number) { + inBoundIndex(index: number) { const { width, height } = this.host; return index >= 0 && index < width * height; } @@ -96,7 +96,7 @@ export class RectRange extends BaseRange { const ex = Math.max(param.x, param.x + param.w); const ey = Math.max(param.y, param.y + param.h); - return this.isInBounds(x, y) && x >= sx && y >= sy && x < ex && y < ey; + return this.inBound(x, y) && x >= sx && y >= sy && x < ex && y < ey; } } @@ -131,7 +131,7 @@ export class ManhattanRange extends BaseRange { param: Readonly ): boolean { return ( - this.isInBounds(x, y) && + this.inBound(x, y) && Math.abs(x - param.cx) + Math.abs(y - param.cy) <= param.radius ); } @@ -193,7 +193,7 @@ export class RayRange extends BaseRange { const { width } = this.host; const yielded = new Set(); - if (this.isInBounds(param.cx, param.cy)) { + if (this.inBound(param.cx, param.cy)) { const centerIndex = param.cy * width + param.cx; yielded.add(centerIndex); yield centerIndex; @@ -206,7 +206,7 @@ export class RayRange extends BaseRange { let x = param.cx + direction.x; let y = param.cy + direction.y; - while (this.isInBounds(x, y)) { + while (this.inBound(x, y)) { const index = y * width + x; if (!yielded.has(index)) { yielded.add(index); @@ -219,7 +219,7 @@ export class RayRange extends BaseRange { } inRange(x: number, y: number, param: Readonly): boolean { - if (!this.isInBounds(x, y)) { + if (!this.inBound(x, y)) { return false; } @@ -263,11 +263,11 @@ export class FullRange extends BaseRange { } inRange(x: number, y: number): boolean { - return this.isInBounds(x, y); + return this.inBound(x, y); } inRangeIndex(index: number): boolean { - return this.isValidIndex(index); + return this.inBoundIndex(index); } } diff --git a/packages/common/src/utils/types.ts b/packages/common/src/utils/types.ts index 3a7fd90..db01be3 100644 --- a/packages/common/src/utils/types.ts +++ b/packages/common/src/utils/types.ts @@ -87,6 +87,19 @@ export interface IRange { * @param param 传递给范围对象的参数 */ inRangeIndex(index: number, param: Readonly): boolean; + + /** + * 判断一个点是否在宿主对象矩形范围内 + * @param x 横坐标 + * @param y 纵坐标 + */ + inBound(x: number, y: number): boolean; + + /** + * 判断一个点索引是否在宿主对象矩形范围内 + * @param index 索引 + */ + inBoundIndex(index: number): boolean; } export interface IRectRangeParam {