mirror of
https://github.com/motajs/template.git
synced 2026-11-15 16:34:32 +08:00
refactor: 怪物基本属性改为泛型
This commit is contained in:
1 parent
057d5ab813
commit
a24911400f
12 files changed
+405
-286
No files matched your search
@@ -1,12 +1,13 @@
|
||||
import { EnemyManager, IEnemyManager } from '@user/data-base';
|
||||
import { IEnemyAttributes } from './enemy/types';
|
||||
import { IGameDataState } from './types';
|
||||
import { registerSpecials } from './enemy';
|
||||
|
||||
export class GameDataState implements IGameDataState {
|
||||
readonly enemyManager: IEnemyManager;
|
||||
readonly enemyManager: IEnemyManager<IEnemyAttributes>;
|
||||
|
||||
constructor() {
|
||||
this.enemyManager = new EnemyManager();
|
||||
this.enemyManager = new EnemyManager<IEnemyAttributes>();
|
||||
registerSpecials(this.enemyManager);
|
||||
}
|
||||
}
|
||||
@@ -9,13 +9,16 @@ import {
|
||||
import {
|
||||
IAuraConverter,
|
||||
IEnemyAuraView,
|
||||
IEnemyContext,
|
||||
IEnemySpecialModifier,
|
||||
IEnemyView,
|
||||
IReadonlyEnemy,
|
||||
ISpecial,
|
||||
IEnemy
|
||||
} from '@user/data-base';
|
||||
import { IHaloValue } from './special';
|
||||
import { ITileLocator } from '@user/types';
|
||||
import { IEnemyAttributes } from './types';
|
||||
|
||||
const FULL_RANGE = new FullRange();
|
||||
const RECT_RANGE = new RectRange();
|
||||
@@ -23,32 +26,32 @@ const MANHATTAN_RANGE = new ManhattanRange();
|
||||
|
||||
//#region 25-光环
|
||||
|
||||
export class CommonAuraConverter implements IAuraConverter {
|
||||
export class CommonAuraConverter implements IAuraConverter<IEnemyAttributes> {
|
||||
shouldConvert(special: ISpecial<any>): boolean {
|
||||
return special.code === 25;
|
||||
}
|
||||
|
||||
convert(
|
||||
special: ISpecial<any>,
|
||||
enemy: IReadonlyEnemy,
|
||||
enemy: IReadonlyEnemy<IEnemyAttributes>,
|
||||
locator: ITileLocator
|
||||
): IEnemyAuraView<any, any> {
|
||||
): CommonAura {
|
||||
return new CommonAura(enemy, special as ISpecial<IHaloValue>, locator);
|
||||
}
|
||||
}
|
||||
|
||||
export class CommonAura implements IEnemyAuraView<
|
||||
IEnemyAttributes,
|
||||
IRectRangeParam | IManhattanRangeParam | void,
|
||||
IHaloValue
|
||||
> {
|
||||
readonly priority: number = 25;
|
||||
readonly couldApplyBase: boolean = true;
|
||||
readonly couldApplySpecial: boolean = false;
|
||||
|
||||
readonly range: IRange<IRectRangeParam | IManhattanRangeParam | void>;
|
||||
|
||||
constructor(
|
||||
readonly enemy: IReadonlyEnemy,
|
||||
readonly enemy: IReadonlyEnemy<IEnemyAttributes>,
|
||||
readonly special: ISpecial<IHaloValue>,
|
||||
readonly locator: ITileLocator
|
||||
) {
|
||||
@@ -85,7 +88,10 @@ export class CommonAura implements IEnemyAuraView<
|
||||
};
|
||||
}
|
||||
|
||||
apply(enemy: IEnemy, baseEnemy: IReadonlyEnemy): void {
|
||||
apply(
|
||||
enemy: IEnemy<IEnemyAttributes>,
|
||||
baseEnemy: IReadonlyEnemy<IEnemyAttributes>
|
||||
): void {
|
||||
const { hpBuff, atkBuff, defBuff } = this.special.value;
|
||||
|
||||
if (hpBuff !== 0) {
|
||||
@@ -113,7 +119,78 @@ export class CommonAura implements IEnemyAuraView<
|
||||
}
|
||||
}
|
||||
|
||||
applySpecial(): IEnemySpecialModifier | null {
|
||||
applySpecial(): IEnemySpecialModifier<IEnemyAttributes> | null {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
//#endregion
|
||||
|
||||
//#region 26-支援
|
||||
|
||||
export class GuardAuraConverter implements IAuraConverter<IEnemyAttributes> {
|
||||
shouldConvert(special: ISpecial<any>): boolean {
|
||||
return special.code === 26;
|
||||
}
|
||||
|
||||
convert(
|
||||
special: ISpecial<any>,
|
||||
enemy: IReadonlyEnemy<IEnemyAttributes>,
|
||||
locator: ITileLocator,
|
||||
context: IEnemyContext<IEnemyAttributes>
|
||||
): GuardAura {
|
||||
return new GuardAura(
|
||||
context,
|
||||
enemy,
|
||||
special as ISpecial<void>,
|
||||
locator
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export class GuardAura implements IEnemyAuraView<
|
||||
IEnemyAttributes,
|
||||
IRectRangeParam,
|
||||
void
|
||||
> {
|
||||
readonly priority: number = 26;
|
||||
readonly couldApplyBase: boolean = true;
|
||||
readonly couldApplySpecial: boolean = false;
|
||||
readonly range: IRange<IRectRangeParam> = RECT_RANGE;
|
||||
|
||||
private readonly sourceView: IEnemyView<IEnemyAttributes> | null;
|
||||
|
||||
constructor(
|
||||
context: IEnemyContext<IEnemyAttributes>,
|
||||
readonly enemy: IReadonlyEnemy<IEnemyAttributes>,
|
||||
readonly special: ISpecial<void>,
|
||||
readonly locator: ITileLocator
|
||||
) {
|
||||
this.sourceView = context.getViewByComputed(enemy);
|
||||
}
|
||||
|
||||
getRangeParam(): IRectRangeParam {
|
||||
return {
|
||||
x: this.locator.x - 1,
|
||||
y: this.locator.y - 1,
|
||||
w: 3,
|
||||
h: 3
|
||||
};
|
||||
}
|
||||
|
||||
apply(
|
||||
enemy: IEnemy<IEnemyAttributes>,
|
||||
_baseEnemy: IReadonlyEnemy<IEnemyAttributes>,
|
||||
locator: ITileLocator
|
||||
): void {
|
||||
if (!this.sourceView) return;
|
||||
if (locator.x === this.locator.x && locator.y === this.locator.y) {
|
||||
return;
|
||||
}
|
||||
enemy.getAttribute('guard').add(this.sourceView);
|
||||
}
|
||||
|
||||
applySpecial(): IEnemySpecialModifier<IEnemyAttributes> | null {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ import {
|
||||
IMapDamageView
|
||||
} from '@user/data-base';
|
||||
import { IZoneValue } from './special';
|
||||
import { MapDamageType } from './types';
|
||||
import { IEnemyAttributes, MapDamageType } from './types';
|
||||
|
||||
const RECT_RANGE = new RectRange();
|
||||
const MANHATTAN_RANGE = new ManhattanRange();
|
||||
@@ -33,7 +33,7 @@ const DIR4 = [...DIRECTION_MAPPER.map(InternalDirectionGroup.Dir4)];
|
||||
//#region 地图伤害
|
||||
|
||||
abstract class BaseMapDamageView<T> implements IMapDamageView<T> {
|
||||
constructor(protected readonly context: IEnemyContext) {}
|
||||
constructor(protected readonly context: IEnemyContext<IEnemyAttributes>) {}
|
||||
|
||||
abstract getRange(): IRange<T>;
|
||||
|
||||
@@ -94,7 +94,7 @@ export class ZoneDamageView extends BaseMapDamageView<
|
||||
IRectRangeParam | IManhattanRangeParam
|
||||
> {
|
||||
constructor(
|
||||
context: IEnemyContext,
|
||||
context: IEnemyContext<IEnemyAttributes>,
|
||||
private readonly locator: Readonly<ITileLocator>,
|
||||
private readonly special: Readonly<ISpecial<IZoneValue>>
|
||||
) {
|
||||
@@ -131,7 +131,7 @@ export class ZoneDamageView extends BaseMapDamageView<
|
||||
|
||||
export class RepulseDamageView extends BaseMapDamageView<IManhattanRangeParam> {
|
||||
constructor(
|
||||
context: IEnemyContext,
|
||||
context: IEnemyContext<IEnemyAttributes>,
|
||||
private readonly locator: Readonly<ITileLocator>,
|
||||
private readonly special: Readonly<ISpecial<number>>
|
||||
) {
|
||||
@@ -165,7 +165,7 @@ export class RepulseDamageView extends BaseMapDamageView<IManhattanRangeParam> {
|
||||
|
||||
export class LaserDamageView extends BaseMapDamageView<IRayRangeParam> {
|
||||
constructor(
|
||||
context: IEnemyContext,
|
||||
context: IEnemyContext<IEnemyAttributes>,
|
||||
private readonly locator: Readonly<ITileLocator>,
|
||||
private readonly special: Readonly<ISpecial<number>>,
|
||||
private readonly dir: IDirectionDescriptor[] = DIR4
|
||||
@@ -200,7 +200,7 @@ export class BetweenDamageView extends BaseMapDamageView<IManhattanRangeParam> {
|
||||
private static readonly DAMAGE = 1;
|
||||
|
||||
constructor(
|
||||
context: IEnemyContext,
|
||||
context: IEnemyContext<IEnemyAttributes>,
|
||||
private readonly locator: Readonly<ITileLocator>
|
||||
) {
|
||||
super(context);
|
||||
@@ -250,7 +250,7 @@ export class BetweenDamageView extends BaseMapDamageView<IManhattanRangeParam> {
|
||||
|
||||
export class AmbushDamageView extends BaseMapDamageView<IManhattanRangeParam> {
|
||||
constructor(
|
||||
context: IEnemyContext,
|
||||
context: IEnemyContext<IEnemyAttributes>,
|
||||
private readonly locator: Readonly<ITileLocator>
|
||||
) {
|
||||
super(context);
|
||||
@@ -285,11 +285,11 @@ export class AmbushDamageView extends BaseMapDamageView<IManhattanRangeParam> {
|
||||
|
||||
//#region 转换器
|
||||
|
||||
export class MainMapDamageConverter implements IMapDamageConverter {
|
||||
export class MainMapDamageConverter implements IMapDamageConverter<IEnemyAttributes> {
|
||||
convert(
|
||||
enemy: IReadonlyEnemy,
|
||||
enemy: IReadonlyEnemy<IEnemyAttributes>,
|
||||
locator: ITileLocator,
|
||||
context: IEnemyContext
|
||||
context: IEnemyContext<IEnemyAttributes>
|
||||
): IMapDamageView<any>[] {
|
||||
const views: IMapDamageView<any>[] = [];
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
IEnemyManager
|
||||
} from '@user/data-base';
|
||||
import { getHeroStatusOn } from '../legacy/hero';
|
||||
import { IEnemyAttributes } from './types';
|
||||
|
||||
//#region 复合属性值类型
|
||||
|
||||
@@ -47,7 +48,11 @@ export interface IHaloValue {
|
||||
* 8. 重生属性:还在脚本编辑的 changingFloor
|
||||
* 9. 阻击 | 捕捉 的每步效果:packages-user/legacy-plugin-data/src/enemy/checkblock.ts
|
||||
*/
|
||||
export function registerSpecials(manager: IEnemyManager): void {
|
||||
export function registerSpecials(
|
||||
manager: IEnemyManager<IEnemyAttributes>
|
||||
): void {
|
||||
manager.registerAttribute('guard', new Set());
|
||||
|
||||
// 0 - 空
|
||||
manager.registerSpecial(
|
||||
0,
|
||||
|
||||
@@ -1,3 +1,22 @@
|
||||
import { IEnemyView } from '@user/data-base';
|
||||
|
||||
export interface IEnemyAttributes {
|
||||
/** 怪物生命值 */
|
||||
hp: number;
|
||||
/** 怪物攻击力 */
|
||||
atk: number;
|
||||
/** 怪物防御力 */
|
||||
def: number;
|
||||
/** 怪物金币 */
|
||||
money: number;
|
||||
/** 怪物经验值 */
|
||||
exp: number;
|
||||
/** 怪物加点量 */
|
||||
point: number;
|
||||
/** 支援来源怪物视图列表 */
|
||||
guard: Set<IEnemyView<IEnemyAttributes>>;
|
||||
}
|
||||
|
||||
export const enum MapDamageType {
|
||||
/** 未知伤害 */
|
||||
Unknown,
|
||||
|
||||
@@ -2,10 +2,11 @@ import { ILayerState } from './map';
|
||||
import { IHeroFollower, IHeroState } from './hero';
|
||||
import { IRoleFaceBinder } from './common';
|
||||
import { IEnemyManager } from '@user/data-base';
|
||||
import { IEnemyAttributes } from './enemy/types';
|
||||
|
||||
export interface IGameDataState {
|
||||
/** 怪物管理器 */
|
||||
readonly enemyManager: IEnemyManager;
|
||||
readonly enemyManager: IEnemyManager<IEnemyAttributes>;
|
||||
}
|
||||
|
||||
export interface IStateSaveData {
|
||||
|
||||
Reference in new issue
Block a user