You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
77 lines
2.1 KiB
77 lines
2.1 KiB
import type { Player } from '../game/Player';
|
|
import { createBattleRuntime, type ProjectBattleHandle } from './runtime/BattleRuntime';
|
|
import { TableBattleConfigProvider } from './config/TableBattleConfigProvider';
|
|
import { BattleUiPauseGate } from './BattleUiPauseGate';
|
|
import { installAtkDebugHooks } from './debug/AtkDebugLog';
|
|
import type { IBattleService } from './IBattleService';
|
|
import type {
|
|
BattleDeployParams,
|
|
BattleStartParams,
|
|
IBattleRuntimeHandle,
|
|
} from './types/ProjectBattleTypes';
|
|
|
|
/** 战斗模块实现:对局生命周期,由 gg.battle 持有单实例 */
|
|
export class BattleService implements IBattleService {
|
|
readonly config = new TableBattleConfigProvider();
|
|
|
|
private _match: ProjectBattleHandle | null = null;
|
|
|
|
get match(): IBattleRuntimeHandle | null {
|
|
return this._match;
|
|
}
|
|
|
|
get localPlayer() {
|
|
return this._match?.player;
|
|
}
|
|
|
|
get players(): readonly Player[] {
|
|
return this._match?.players ?? [];
|
|
}
|
|
|
|
get remotePlayer() {
|
|
return this._match?.remotePlayer;
|
|
}
|
|
|
|
init(): void {
|
|
this.config.loadStaticTables();
|
|
installAtkDebugHooks();
|
|
}
|
|
|
|
start(params: BattleStartParams): IBattleRuntimeHandle | null {
|
|
installAtkDebugHooks();
|
|
this.end();
|
|
const runtime = createBattleRuntime(params);
|
|
if (!runtime) {
|
|
console.error(`[BattleService] start failed level=${params.levelId} rank=${params.playerRankId} opp=${params.opponentRankId}`);
|
|
return null;
|
|
}
|
|
this._match = runtime;
|
|
return runtime;
|
|
}
|
|
|
|
end(): void {
|
|
BattleUiPauseGate.clear();
|
|
const levelId = this._match?.levelId;
|
|
this._match?.destroy();
|
|
this._match = null;
|
|
if (levelId) {
|
|
this.config.releaseBattleSession(levelId);
|
|
}
|
|
}
|
|
|
|
tick(dt: number): void {
|
|
this._match?.tick(dt);
|
|
}
|
|
|
|
deploy(params: BattleDeployParams): boolean {
|
|
return this._match?.deploy(params) ?? false;
|
|
}
|
|
|
|
startCombat(): void {
|
|
this._match?.startCombat();
|
|
}
|
|
|
|
startPrep(): void {
|
|
this._match?.startPrep();
|
|
}
|
|
}
|
|
|