mirror of
https://github.com/motajs/template.git
synced 2026-05-02 12:23:13 +08:00
32 lines
1.2 KiB
TypeScript
32 lines
1.2 KiB
TypeScript
import { IEnemyComparer, IReadonlyEnemy } from '@user/data-base';
|
|
import { IEnemyAttr } from './types';
|
|
|
|
export class MainEnemyComparer implements IEnemyComparer<IEnemyAttr> {
|
|
compare(
|
|
enemyA: IReadonlyEnemy<IEnemyAttr>,
|
|
enemyB: IReadonlyEnemy<IEnemyAttr>
|
|
): boolean {
|
|
// 比较基本属性
|
|
if (
|
|
enemyA.getAttribute('hp') !== enemyB.getAttribute('hp') ||
|
|
enemyA.getAttribute('atk') !== enemyB.getAttribute('atk') ||
|
|
enemyA.getAttribute('def') !== enemyB.getAttribute('def') ||
|
|
enemyA.getAttribute('money') !== enemyB.getAttribute('money') ||
|
|
enemyA.getAttribute('exp') !== enemyB.getAttribute('exp') ||
|
|
enemyA.getAttribute('point') !== enemyB.getAttribute('point')
|
|
) {
|
|
return false;
|
|
}
|
|
|
|
// 比较特殊属性
|
|
const specialsA = [...enemyA.iterateSpecials()];
|
|
const specialsB = [...enemyB.iterateSpecials()];
|
|
if (specialsA.length !== specialsB.length) return false;
|
|
for (const special of specialsA) {
|
|
const other = enemyB.getSpecial(special.code);
|
|
if (!other || !special.deepEqualsTo(other)) return false;
|
|
}
|
|
return true;
|
|
}
|
|
}
|