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

View File

@ -847,7 +847,7 @@ export interface IEnemyContext<TAttr> {
* *
* @param system * @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 { loadState(data: IStateSaveData): void {
this.hero.removeAllFollowers(); this.hero.removeAllFollowers();
data?.followers.forEach(v => { data.followers.forEach(v => {
this.hero.addFollower(v.num, v.identifier); this.hero.addFollower(v.num, v.identifier);
}); });
} }

View File

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