战斗管理系统基础
This commit is contained in:
@@ -1,76 +1,46 @@
|
||||
import { oops } from "db://oops-framework/core/Oops";
|
||||
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||
import { BattleState } from "./BattleStateComp";
|
||||
import { smc } from "../common/SingletonModuleComp";
|
||||
import { GameEvent } from "../common/config/GameEvent";
|
||||
|
||||
@ecs.register('BattleManager')
|
||||
export class BattleManager extends ecs.Entity {
|
||||
private static _instance: BattleManager;
|
||||
|
||||
static get instance(): BattleManager {
|
||||
if (!this._instance) {
|
||||
this._instance = new BattleManager();
|
||||
this._instance.add(BattleState);
|
||||
}
|
||||
return this._instance;
|
||||
import { BattleEntity } from "./BattleEntity";
|
||||
import { BattleStateComp } from "./BattleStateComp";
|
||||
import { UIID } from "../common/config/GameUIConfig";
|
||||
import { oops } from "db://oops-framework/core/Oops";
|
||||
|
||||
export class BattleManager {
|
||||
/** 获取战斗实体实例 */
|
||||
static get instance(): ecs.Entity {
|
||||
return ecs.query(ecs.allOf(BattleStateComp))[0];
|
||||
}
|
||||
|
||||
/** 外部调用入口:开始新战斗 */
|
||||
startBattle(missionId: number) {
|
||||
this.get(BattleState).isEnded = false;
|
||||
// 加载关卡配置、生成敌人等
|
||||
smc.mission.load(missionId);
|
||||
/** 启动战斗 */
|
||||
static startBattle(missionId: number) {
|
||||
const entity = ecs.getEntity(BattleEntity);
|
||||
entity.get(BattleStateComp).missionId = missionId;
|
||||
}
|
||||
|
||||
/** 外部调用入口:结束战斗 */
|
||||
endBattle() {
|
||||
this.get(BattleState).isEnded = true;
|
||||
}
|
||||
|
||||
private initEvents() {
|
||||
oops.message.on("HeroDead", this.onHeroDead, this);
|
||||
oops.message.on("AllEnemyDead", this.onAllEnemyDead, this);
|
||||
oops.message.on(GameEvent.MissionEnd, this.endBattle, this);
|
||||
oops.message.on("BattleEndCheck", this.onBattleEndCheck, this);
|
||||
}
|
||||
|
||||
private onHeroDead() {
|
||||
this.endBattle();
|
||||
}
|
||||
|
||||
private onAllEnemyDead() {
|
||||
this.endBattle();
|
||||
}
|
||||
|
||||
private onBattleEndCheck() {
|
||||
// 留空或添加实际需要的检测逻辑
|
||||
}
|
||||
}
|
||||
|
||||
@ecs.register('BattleManagerComp')
|
||||
export class BattleManagerComp extends ecs.Comp {
|
||||
reset() {
|
||||
// 初始化战斗状态
|
||||
}
|
||||
}
|
||||
|
||||
export class BattleManagerSystem extends ecs.ComblockSystem {
|
||||
filter(): ecs.IMatcher {
|
||||
return ecs.allOf(BattleManagerComp);
|
||||
}
|
||||
|
||||
update(e: ecs.Entity) {
|
||||
const state = e.get(BattleState);
|
||||
if (state.isEnded) {
|
||||
// 处理战斗结束逻辑
|
||||
this.onBattleEnd(e);
|
||||
/** 结束战斗 */
|
||||
static endBattle() {
|
||||
const entity = ecs.query(ecs.allOf(BattleStateComp))[0];
|
||||
if (entity) {
|
||||
entity.get(BattleStateComp).isEnded = true;
|
||||
}
|
||||
}
|
||||
|
||||
private onBattleEnd(entity: ecs.Entity) {
|
||||
// 发放奖励、保存进度等
|
||||
entity.destroy();
|
||||
/** 扩展:带UI管理的战斗启动 */
|
||||
static startBattleWithUI(missionId: number) {
|
||||
// 关闭主界面
|
||||
// oops.gui.remove(UIID.MainMenu);
|
||||
// // 显示战斗HUD
|
||||
// oops.gui.open(UIID.BattleHUD);
|
||||
// 启动战斗
|
||||
this.startBattle(missionId);
|
||||
}
|
||||
|
||||
/** 扩展:带UI管理的战斗结束 */
|
||||
static endBattleWithUI(isVictory: boolean) {
|
||||
// 关闭战斗HUD
|
||||
// oops.gui.remove(UIID.BattleHUD);
|
||||
// 显示结算界面
|
||||
// oops.gui.open(isVictory ? UIID.Victory : UIID.Defeat);
|
||||
// 结束战斗
|
||||
this.endBattle();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user