mirror of
https://github.com/motajs/template.git
synced 2026-05-02 12:23:13 +08:00
feat: 内置最终效果
This commit is contained in:
parent
0517da5000
commit
63e1a01fab
@ -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];
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
||||
/**
|
||||
* 深拷贝此怪物对象
|
||||
*/
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
29
packages-user/data-state/src/enemy/final.ts
Normal file
29
packages-user/data-state/src/enemy/final.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,5 @@
|
||||
export * from './aura';
|
||||
export * from './damage';
|
||||
export * from './final';
|
||||
export * from './mapDamage';
|
||||
export * from './special';
|
||||
|
||||
Loading…
Reference in New Issue
Block a user