战斗管理系统基础
This commit is contained in:
@@ -1,11 +1,43 @@
|
||||
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||
|
||||
/** 战斗状态组件 */
|
||||
@ecs.register('BattleState')
|
||||
export class BattleState extends ecs.Comp {
|
||||
isEnded: boolean = false;
|
||||
export class BattleStateComp extends ecs.Comp {
|
||||
/** 战斗阶段枚举 */
|
||||
static Phase = {
|
||||
Preparation: 0, // 准备阶段
|
||||
Fighting: 1, // 战斗中
|
||||
Victory: 2, // 胜利
|
||||
Defeat: 3 // 失败
|
||||
};
|
||||
|
||||
phase: number = BattleStateComp.Phase.Preparation;
|
||||
/** 是否结束 */
|
||||
isEnded: boolean = false;
|
||||
/** 当前关卡ID */
|
||||
missionId: number = 0;
|
||||
/** 战斗开始时间戳 */
|
||||
startTime: number = 0;
|
||||
|
||||
reset() {
|
||||
this.isEnded = false;
|
||||
this.missionId = 0;
|
||||
this.startTime = 0;
|
||||
}
|
||||
|
||||
/** 安全状态转换 */
|
||||
setPhase(newPhase: number) {
|
||||
const validTransitions = {
|
||||
[BattleStateComp.Phase.Preparation]: [BattleStateComp.Phase.Fighting],
|
||||
[BattleStateComp.Phase.Fighting]: [BattleStateComp.Phase.Victory, BattleStateComp.Phase.Defeat],
|
||||
[BattleStateComp.Phase.Victory]: [BattleStateComp.Phase.Preparation],
|
||||
[BattleStateComp.Phase.Defeat]: [BattleStateComp.Phase.Preparation]
|
||||
};
|
||||
|
||||
if (validTransitions[this.phase]?.includes(newPhase)) {
|
||||
this.phase = newPhase;
|
||||
} else {
|
||||
console.error(`Invalid phase transition from ${this.phase} to ${newPhase}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user