feat: 内置最终效果

This commit is contained in:
unanmed 2026-04-15 18:48:59 +08:00
parent 0517da5000
commit 63e1a01fab
6 changed files with 55 additions and 15 deletions

View File

@ -51,6 +51,13 @@ export class Enemy<TAttr> implements IEnemy<TAttr> {
this.attributes[key] = value; this.attributes[key] = value;
} }
addAttribute<K extends SelectKey<TAttr, number>>(
key: K,
value: number
): void {
(this.attributes[key] as number) += value;
}
getAttribute<K extends keyof TAttr>(key: K): TAttr[K] { getAttribute<K extends keyof TAttr>(key: K): TAttr[K] {
return this.attributes[key]; return this.attributes[key];
} }

View File

@ -100,6 +100,16 @@ export interface IEnemy<TAttr> extends IReadonlyEnemy<TAttr> {
*/ */
setAttribute<K extends keyof TAttr>(key: K, value: TAttr[K]): void; setAttribute<K extends keyof TAttr>(key: K, value: TAttr[K]): void;
/**
*
* @param key
* @param value
*/
addAttribute<K extends SelectKey<TAttr, number>>(
key: K,
value: number
): void;
/** /**
* *
*/ */

View File

@ -13,6 +13,7 @@ import { IEnemyAttributes } from './enemy/types';
import { import {
CommonAuraConverter, CommonAuraConverter,
GuardAuraConverter, GuardAuraConverter,
MainEnemyFinalEffect,
MainMapDamageConverter, MainMapDamageConverter,
MainMapDamageReducer MainMapDamageReducer
} from './enemy'; } from './enemy';
@ -44,6 +45,7 @@ export class CoreState implements ICoreState {
enemyContext.attachMapDamage(mapDamage); enemyContext.attachMapDamage(mapDamage);
enemyContext.registerAuraConverter(new CommonAuraConverter()); enemyContext.registerAuraConverter(new CommonAuraConverter());
enemyContext.registerAuraConverter(new GuardAuraConverter()); enemyContext.registerAuraConverter(new GuardAuraConverter());
enemyContext.registerFinalEffect(new MainEnemyFinalEffect());
enemyContext.resize(core._WIDTH_, core._HEIGHT_); enemyContext.resize(core._WIDTH_, core._HEIGHT_);
this.enemyContext = enemyContext; this.enemyContext = enemyContext;
} }

View File

@ -95,27 +95,18 @@ export class CommonAura implements IEnemyAuraView<
const { hpBuff, atkBuff, defBuff } = this.special.value; const { hpBuff, atkBuff, defBuff } = this.special.value;
if (hpBuff !== 0) { if (hpBuff !== 0) {
enemy.setAttribute( const hpValue = (baseEnemy.getAttribute('hp') * hpBuff) / 100;
'hp', enemy.addAttribute('hp', Math.floor(hpValue));
enemy.getAttribute('hp') +
Math.floor((baseEnemy.getAttribute('hp') * hpBuff) / 100)
);
} }
if (atkBuff !== 0) { if (atkBuff !== 0) {
enemy.setAttribute( const atkValue = (baseEnemy.getAttribute('atk') * atkBuff) / 100;
'atk', enemy.addAttribute('atk', Math.floor(atkValue));
enemy.getAttribute('atk') +
Math.floor((baseEnemy.getAttribute('atk') * atkBuff) / 100)
);
} }
if (defBuff !== 0) { if (defBuff !== 0) {
enemy.setAttribute( const defValue = (baseEnemy.getAttribute('def') * defBuff) / 100;
'def', enemy.addAttribute('def', Math.floor(defValue));
enemy.getAttribute('def') +
Math.floor((baseEnemy.getAttribute('def') * defBuff) / 100)
);
} }
} }

View File

@ -0,0 +1,29 @@
import { IEnemy, IEnemyFinalEffect } from '@user/data-base';
import { IEnemyAttributes } from './types';
import { ITileLocator } from '@user/types';
const HERO_STATUS_PLACEHOLDER = {
atk: 0,
def: 0
} as const;
export class MainEnemyFinalEffect implements IEnemyFinalEffect<IEnemyAttributes> {
readonly priority: number = 0;
apply(enemy: IEnemy<IEnemyAttributes>, _locator: ITileLocator): void {
if (enemy.hasSpecial(3)) {
enemy.setAttribute(
'def',
Math.max(
enemy.getAttribute('def'),
HERO_STATUS_PLACEHOLDER.atk - 1
)
);
}
if (enemy.hasSpecial(10)) {
enemy.setAttribute('atk', HERO_STATUS_PLACEHOLDER.atk);
enemy.setAttribute('def', HERO_STATUS_PLACEHOLDER.def);
}
}
}

View File

@ -1,4 +1,5 @@
export * from './aura'; export * from './aura';
export * from './damage'; export * from './damage';
export * from './final';
export * from './mapDamage'; export * from './mapDamage';
export * from './special'; export * from './special';