refactor: 伤害计算

This commit is contained in:
AncTe committed 2026-04-17 17:49:24 +08:00
1 parent 4d9c6720aa
commit 79d06c31df
7 files changed
+249 -9

No files matched your search

+34 -1
View File
@@ -11,6 +11,7 @@ import {
IReadonlyEnemy
} from './types';
import { IHeroAttribute, IReadonlyHeroAttribute } from '../hero';
import { clamp } from 'lodash-es';
interface ICriticalSearchResult {
/** 此临界点的属性值 */
@@ -84,6 +85,37 @@ export class DamageSystem<TAttr, THero> implements IDamageSystem<TAttr, THero> {
return info;
}
getDamageInfoByComputed(
enemy: IReadonlyEnemy<TAttr>
): IEnemyDamageInfo | null {
if (!this.heroStatus) {
logger.warn(107);
return null;
}
if (!this.calculator) {
logger.warn(106);
return null;
}
const hero = this.heroStatus;
if (!hero) return null;
const view = this.context.getViewByComputed(enemy);
if (!view) return null;
const locator = this.context.getEnemyLocatorByView(view);
if (!locator) return null;
const cached = this.cache.get(view);
if (cached) {
return cached;
}
const handler = this.createReadonlyHandler(enemy, locator, hero);
const info = this.calculator.calculate(handler);
this.cache.set(view, info);
return info;
}
markDirty(enemy: IEnemyView<TAttr>): void {
this.cache.delete(enemy);
}
@@ -127,7 +159,8 @@ export class DamageSystem<TAttr, THero> implements IDamageSystem<TAttr, THero> {
if (currentValue >= upperLimit) return;
const maxIterations = Math.max(0, Math.floor(precision));
// 超过 64 位的精度没有意义,所以最高设置为 64
const maxIterations = clamp(Math.floor(precision), 4, 64);
let baseValue = currentValue;
let baseInfo = currentInfo;
@@ -650,6 +650,14 @@ export interface IDamageSystem<TAttr, THero> {
*/
getDamageInfo(enemy: IEnemyView<TAttr>): IEnemyDamageInfo | null;
/**
* 根据怪物对象获取战斗伤害信息
* @param enemy 怪物对象
*/
getDamageInfoByComputed(
enemy: IReadonlyEnemy<TAttr>
): IEnemyDamageInfo | null;
/**
* 将指定的怪物标记为脏
* @param enemy 怪物视图