chore: 添加必要注释

This commit is contained in:
unanmed 2026-04-16 13:30:52 +08:00
parent 39e91b241f
commit 89936416e1
4 changed files with 96 additions and 11 deletions

View File

@ -67,16 +67,19 @@ export class EnemyContext<TAttr> implements IEnemyContext<TAttr> {
this.width = width;
this.height = height;
this.indexer.setWidth(width);
this.needUpdate = true;
}
registerAuraConverter(converter: IAuraConverter<TAttr>): void {
this.auraConverter.add(converter);
this.converterStatus.set(converter, true);
this.needUpdate = true;
}
unregisterAuraConverter(converter: IAuraConverter<TAttr>): void {
this.auraConverter.delete(converter);
this.converterStatus.delete(converter);
this.needUpdate = true;
}
setAuraConverterEnabled(
@ -85,6 +88,7 @@ export class EnemyContext<TAttr> implements IEnemyContext<TAttr> {
): void {
if (!this.auraConverter.has(converter)) return;
this.converterStatus.set(converter, enabled);
this.needUpdate = true;
}
registerCommonQueryEffect(
@ -94,6 +98,7 @@ export class EnemyContext<TAttr> implements IEnemyContext<TAttr> {
const array = this.commonQueryMap.getOrInsert(code, []);
array.push(effect);
array.sort((a, b) => b.priority - a.priority);
this.needUpdate = true;
}
unregisterCommonQueryEffect(
@ -105,11 +110,13 @@ export class EnemyContext<TAttr> implements IEnemyContext<TAttr> {
const index = array.indexOf(effect);
if (index === -1) return;
array.splice(index, 1);
this.needUpdate = true;
}
registerSpecialQueryEffect(effect: IEnemySpecialQueryEffect<TAttr>): void {
const list = this.specialQueryEffects.getOrInsert(effect.priority, []);
list.push(effect);
this.needUpdate = true;
}
unregisterSpecialQueryEffect(
@ -124,11 +131,13 @@ export class EnemyContext<TAttr> implements IEnemyContext<TAttr> {
if (list.length === 0) {
this.specialQueryEffects.delete(effect.priority);
}
this.needUpdate = true;
}
registerFinalEffect(effect: IEnemyFinalEffect<TAttr>): void {
this.finalEffects.push(effect);
this.finalEffects.sort((a, b) => b.priority - a.priority);
this.needUpdate = true;
}
unregisterFinalEffect(effect: IEnemyFinalEffect<TAttr>): void {
@ -136,6 +145,7 @@ export class EnemyContext<TAttr> implements IEnemyContext<TAttr> {
if (index !== -1) {
this.finalEffects.splice(index, 1);
}
this.needUpdate = true;
}
getEnemyLocator(enemy: IEnemy<TAttr>): Readonly<ITileLocator> | null {
@ -166,6 +176,10 @@ export class EnemyContext<TAttr> implements IEnemyContext<TAttr> {
return this.computedToView.get(enemy) ?? null;
}
/**
*
* @param index
*/
private deleteEnemyAt(index: number) {
const view = this.enemyViewMap.get(index);
const enemy = this.enemyMap.get(index);
@ -201,6 +215,13 @@ export class EnemyContext<TAttr> implements IEnemyContext<TAttr> {
this.locatorViewMap.set(view, index);
this.computedToView.set(view.getComputingEnemy(), view);
if (this.mapDamage) {
this.mapDamage.markEnemyDirty(view);
}
if (this.damageSystem) {
this.damageSystem.markDirty(view);
}
this.needUpdate = true;
}
@ -209,6 +230,11 @@ export class EnemyContext<TAttr> implements IEnemyContext<TAttr> {
this.deleteEnemyAt(index);
}
/**
*
* @param range
* @param param
*/
private *internalScanRange<T>(
range: IRange<T>,
param: T
@ -257,15 +283,23 @@ export class EnemyContext<TAttr> implements IEnemyContext<TAttr> {
return this.mapDamage;
}
attachDamageSystem(system: IDamageSystem<TAttr, unknown>): void {
attachDamageSystem(system: IDamageSystem<TAttr, unknown> | null): void {
this.damageSystem = system;
system.markAllDirty();
if (system) {
system.markAllDirty();
}
}
getDamageSystem<THero>(): IDamageSystem<TAttr, THero> | null {
return this.damageSystem as IDamageSystem<TAttr, THero> | null;
}
/**
*
* @param special
* @param enemy
* @param locator
*/
private convertSpecial(
special: ISpecial<any>,
enemy: IReadonlyEnemy<TAttr>,
@ -288,6 +322,10 @@ export class EnemyContext<TAttr> implements IEnemyContext<TAttr> {
return matched.convert(special, enemy, locator, this);
}
/**
*
* @param aura
*/
private insertIntoSortedAura(aura: IAuraView<TAttr>): void {
const set = this.sortedAura.getOrInsertComputed(
aura.priority,
@ -296,6 +334,10 @@ export class EnemyContext<TAttr> implements IEnemyContext<TAttr> {
set.add(aura);
}
/**
*
* @param aura
*/
private removeFromSortedAura(aura: IAuraView<TAttr>): void {
const set = this.sortedAura.get(aura.priority);
if (set) {
@ -306,6 +348,13 @@ export class EnemyContext<TAttr> implements IEnemyContext<TAttr> {
}
}
/**
*
* @param modifier
* @param enemy
* @param locator
* @param currentPriority
*/
private processSpecialModifier(
modifier: IEnemySpecialModifier<TAttr>,
enemy: IEnemy<TAttr>,
@ -325,6 +374,7 @@ export class EnemyContext<TAttr> implements IEnemyContext<TAttr> {
for (const adding of toAdd) {
const aura = this.convertSpecial(adding, enemy, locator);
if (aura) {
// 新生成的光环只能影响之后的阶段,不能反过来影响当前优先级链。
if (import.meta.env.DEV && aura.priority > currentPriority) {
logger.warn(
99,
@ -344,6 +394,7 @@ export class EnemyContext<TAttr> implements IEnemyContext<TAttr> {
enemy.deleteSpecial(deleting);
const aura = this.convertedAura.get(deleting);
if (aura) {
// 当前阶段不允许删除同优先级或更高优先级的已生效光环。
if (import.meta.env.DEV && aura.priority >= currentPriority) {
logger.warn(
98,
@ -377,6 +428,11 @@ export class EnemyContext<TAttr> implements IEnemyContext<TAttr> {
return affectedAuras;
}
/**
*
* @param effect
* @param currentPriority
*/
private processSpecialQuery(
effect: IEnemySpecialQueryEffect<TAttr>,
currentPriority: number
@ -404,6 +460,11 @@ export class EnemyContext<TAttr> implements IEnemyContext<TAttr> {
}
}
/**
*
* @param aura
* @param currentPriority
*/
private processAuraSpecial(
aura: IAuraView<TAttr>,
currentPriority: number
@ -431,6 +492,9 @@ export class EnemyContext<TAttr> implements IEnemyContext<TAttr> {
}
}
/**
*
*/
private buildupSpecials(): void {
for (const aura of this.globalAuraList) {
this.insertIntoSortedAura(aura);
@ -450,6 +514,7 @@ export class EnemyContext<TAttr> implements IEnemyContext<TAttr> {
const processedPriorities = new Set<number>();
// 由于期间可能会产生新优先级的光环,所以要用 while (true) 而不是直接遍历
while (true) {
let maxPriority: number | null = null;
for (const priority of this.sortedAura.keys()) {
@ -488,6 +553,9 @@ export class EnemyContext<TAttr> implements IEnemyContext<TAttr> {
}
}
/**
*
*/
private buildupBase(): void {
const priorities = [...this.sortedAura.keys()].sort((a, b) => b - a);
for (const p of priorities) {
@ -505,6 +573,9 @@ export class EnemyContext<TAttr> implements IEnemyContext<TAttr> {
}
}
/**
*
*/
private buildupQuery(): void {
for (const [index, view] of this.enemyViewMap) {
const enemy = view.getComputingEnemy();
@ -527,6 +598,9 @@ export class EnemyContext<TAttr> implements IEnemyContext<TAttr> {
}
}
/**
*
*/
private buildupFinal(): void {
for (const [index, view] of this.enemyViewMap) {
const enemy = view.getComputingEnemy();
@ -575,6 +649,12 @@ export class EnemyContext<TAttr> implements IEnemyContext<TAttr> {
}
}
/**
*
* @param modifier
* @param enemy
* @param locator
*/
private refreshSpecialModifier(
modifier: IEnemySpecialModifier<TAttr>,
enemy: IEnemy<TAttr>,
@ -619,6 +699,10 @@ export class EnemyContext<TAttr> implements IEnemyContext<TAttr> {
}
}
/**
*
* @param view
*/
private refreshEnemy(view: EnemyView<TAttr>): void {
const locator = this.getEnemyLocatorByView(view);
if (!locator) return;
@ -646,6 +730,7 @@ export class EnemyContext<TAttr> implements IEnemyContext<TAttr> {
if (!aura.couldApplySpecial) continue;
const param = aura.getRangeParam();
aura.range.bindHost(this);
// 局部刷新只重新判断“这个怪物是否被该光环命中”。
const inRange = aura.range.inRange(
locator.x,
locator.y,
@ -756,7 +841,7 @@ export class EnemyContext<TAttr> implements IEnemyContext<TAttr> {
destroy(): void {
this.clear();
this.attachMapDamage(null);
this.damageSystem = null;
this.attachDamageSystem(null);
this.auraConverter.clear();
this.commonQueryMap.clear();
this.specialQueryEffects.clear();

View File

@ -847,7 +847,7 @@ export interface IEnemyContext<TAttr> {
*
* @param system
*/
attachDamageSystem(system: IDamageSystem<TAttr, unknown>): void;
attachDamageSystem(system: IDamageSystem<TAttr, unknown> | null): void;
/**
*

View File

@ -76,7 +76,7 @@ export class CoreState implements ICoreState {
loadState(data: IStateSaveData): void {
this.hero.removeAllFollowers();
data?.followers.forEach(v => {
data.followers.forEach(v => {
this.hero.addFollower(v.num, v.identifier);
});
}

View File

@ -11,16 +11,16 @@ export class MainEnemyFinalEffect implements IEnemyFinalEffect<IEnemyAttributes>
readonly priority: number = 0;
apply(enemy: IEnemy<IEnemyAttributes>, _locator: ITileLocator): void {
// 3-坚固
if (enemy.hasSpecial(3)) {
enemy.setAttribute(
'def',
Math.max(
enemy.getAttribute('def'),
HERO_STATUS_PLACEHOLDER.atk - 1
)
const target = Math.max(
enemy.getAttribute('def'),
HERO_STATUS_PLACEHOLDER.atk - 1
);
enemy.setAttribute('def', target);
}
// 10-模仿
if (enemy.hasSpecial(10)) {
enemy.setAttribute('atk', HERO_STATUS_PLACEHOLDER.atk);
enemy.setAttribute('def', HERO_STATUS_PLACEHOLDER.def);