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;
}
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] {
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;
/**
*
* @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 {
CommonAuraConverter,
GuardAuraConverter,
MainEnemyFinalEffect,
MainMapDamageConverter,
MainMapDamageReducer
} from './enemy';
@ -44,6 +45,7 @@ export class CoreState implements ICoreState {
enemyContext.attachMapDamage(mapDamage);
enemyContext.registerAuraConverter(new CommonAuraConverter());
enemyContext.registerAuraConverter(new GuardAuraConverter());
enemyContext.registerFinalEffect(new MainEnemyFinalEffect());
enemyContext.resize(core._WIDTH_, core._HEIGHT_);
this.enemyContext = enemyContext;
}

View File

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

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 './damage';
export * from './final';
export * from './mapDamage';
export * from './special';