/**
* HitReportPolicy
* 爆弾被弾報告の送信可否を判定するポリシー
* 同一爆弾IDの重複送信を抑止する
*/
/** 被弾判定結果の最小表現型 */
export type HitEvaluationResult = "duplicate" | "missing-local-player" | "no-hit" | "hit";
/** 爆弾被弾報告の送信可否を管理する */
export class HitReportPolicy {
private readonly reportedBombHitIds = new Set<string>();
/** 被弾報告を送信すべき場合に true を返す */
public shouldSendReport(result: HitEvaluationResult | undefined, bombId: string): boolean {
if (result !== "hit") {
return false;
}
if (this.reportedBombHitIds.has(bombId)) {
return false;
}
this.reportedBombHitIds.add(bombId);
return true;
}
/** 判定済みIDをすべて破棄する */
public clear(): void {
this.reportedBombHitIds.clear();
}
}