You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
2.9 KiB
76 lines
2.9 KiB
|
3 weeks ago
|
import type { IBattleBuffEffectContext, IBattleBuffEffectHandler, IBattleBuffInstantResult } from './BattleBuffEffectTypes';
|
||
|
|
import { BattleBuffVigourEffectHandler } from './handlers/BattleBuffVigourEffectHandler';
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Battlebuff 效果统一注册与分发(按 functiontype 路由)。
|
||
|
|
* 新增类型:实现 IBattleBuffEffectHandler 并在 _registerBuiltins 中注册。
|
||
|
|
*/
|
||
|
|
export class BattleBuffEffectRegistry {
|
||
|
|
private static _handlers: IBattleBuffEffectHandler[] = [];
|
||
|
|
private static _inited = false;
|
||
|
|
|
||
|
|
/** 注册效果处理器 */
|
||
|
|
static register(handler: IBattleBuffEffectHandler): void {
|
||
|
|
if (!handler) return;
|
||
|
|
for (let i = 0; i < this._handlers.length; i++) {
|
||
|
|
if (this._handlers[i].functionType === handler.functionType) {
|
||
|
|
console.log('[BattleBuffEffectRegistry] 重复注册 functiontype', handler.functionType);
|
||
|
|
this._handlers[i] = handler;
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
this._handlers.push(handler);
|
||
|
|
}
|
||
|
|
|
||
|
|
/** 是否抽中即生效(type=3 自动,由 handler 判定是否支持) */
|
||
|
|
static isInstant(row: ITableBattlebuff | null | undefined): boolean {
|
||
|
|
if (!row) return false;
|
||
|
|
this._ensureInit();
|
||
|
|
const handler = this._findHandler(Number(row.functiontype) || 0);
|
||
|
|
return handler != null && handler.isInstant(row);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 执行即时效果
|
||
|
|
* @returns 是否已成功应用
|
||
|
|
*/
|
||
|
|
static applyInstant(row: ITableBattlebuff | null | undefined, ctx: IBattleBuffEffectContext): IBattleBuffInstantResult {
|
||
|
|
if (!row) return { applied: false };
|
||
|
|
this._ensureInit();
|
||
|
|
const ft = Number(row.functiontype) || 0;
|
||
|
|
const handler = this._findHandler(ft);
|
||
|
|
if (!handler) {
|
||
|
|
console.log('[BattleBuffEffectRegistry] 未注册 functiontype', ft, 'id=', row.id);
|
||
|
|
return { applied: false };
|
||
|
|
}
|
||
|
|
if (!handler.isInstant(row)) {
|
||
|
|
console.log('[BattleBuffEffectRegistry] 非即时 buff 不可 applyInstant', row.id, ft);
|
||
|
|
return { applied: false };
|
||
|
|
}
|
||
|
|
return handler.applyInstant(row, ctx);
|
||
|
|
}
|
||
|
|
|
||
|
|
/** 按 functiontype 查找处理器 */
|
||
|
|
static getHandler(functionType: number): IBattleBuffEffectHandler | null {
|
||
|
|
this._ensureInit();
|
||
|
|
return this._findHandler(functionType);
|
||
|
|
}
|
||
|
|
|
||
|
|
private static _ensureInit(): void {
|
||
|
|
if (this._inited) return;
|
||
|
|
this._inited = true;
|
||
|
|
this._registerBuiltins();
|
||
|
|
}
|
||
|
|
|
||
|
|
private static _registerBuiltins(): void {
|
||
|
|
this.register(new BattleBuffVigourEffectHandler());
|
||
|
|
}
|
||
|
|
|
||
|
|
private static _findHandler(functionType: number): IBattleBuffEffectHandler | null {
|
||
|
|
for (let i = 0; i < this._handlers.length; i++) {
|
||
|
|
if (this._handlers[i].functionType === functionType) return this._handlers[i];
|
||
|
|
}
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
}
|