战斗系统也去掉,直接用脚本进行控制就好
This commit is contained in:
@@ -1,34 +0,0 @@
|
||||
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||
import { BattleStateComp } from "./BattleStateComp";
|
||||
import { HeroViewComp } from "../hero/HeroViewComp";
|
||||
import { HeroSkillsComp } from "../skill/heroSkillsComp";
|
||||
import { HCardComp } from "../map/HCardComp";
|
||||
|
||||
@ecs.register('BattleEndSystem')
|
||||
export class BattleEndSystem extends ecs.ComblockSystem {
|
||||
filter(): ecs.IMatcher {
|
||||
return ecs.allOf(BattleStateComp);
|
||||
}
|
||||
|
||||
update(e: ecs.Entity) {
|
||||
const state = e.get(BattleStateComp);
|
||||
if (state.isEnded) {
|
||||
// 清理战斗残留组件
|
||||
this.cleanComponents();
|
||||
|
||||
// 重置状态
|
||||
state.reset();
|
||||
console.log(`战斗结束,持续时间: ${Date.now() - state.startTime}ms`);
|
||||
}
|
||||
}
|
||||
|
||||
private cleanComponents() {
|
||||
console.log("cleanComponents");
|
||||
console.log("HCardComp",ecs.query(ecs.allOf(HCardComp)));
|
||||
console.log("HeroSkillsComp",ecs.query(ecs.allOf(HeroSkillsComp)));
|
||||
console.log("HeroViewComp",ecs.query(ecs.allOf(HeroViewComp)));
|
||||
ecs.query(ecs.allOf(HCardComp)).forEach(entity => entity.remove(HCardComp));
|
||||
ecs.query(ecs.allOf(HeroSkillsComp)).forEach(entity => entity.remove(HeroSkillsComp));
|
||||
ecs.query(ecs.allOf(HeroViewComp)).forEach(entity => entity.remove(HeroViewComp));
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "8454cfbc-f83d-45e9-a8c5-5bb4c830ada8",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||
import { BattleStateComp } from "./BattleStateComp";
|
||||
import { BattleManagerComp } from "./BattleManagerComp";
|
||||
|
||||
/** 战斗实体 */
|
||||
export class BattleEntity extends ecs.Entity {
|
||||
BattleState!: BattleStateComp;
|
||||
BattleManager!: BattleManagerComp;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
protected init() {
|
||||
this.addComponents<ecs.Comp>(BattleStateComp, BattleManagerComp);
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "12e09b78-0059-421e-bab8-1677760401d1",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||
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];
|
||||
}
|
||||
|
||||
/** 启动战斗 */
|
||||
static startBattle(missionId: number) {
|
||||
const entity = ecs.getEntity(BattleEntity);
|
||||
entity.get(BattleStateComp).missionId = missionId;
|
||||
}
|
||||
|
||||
/** 结束战斗 */
|
||||
static endBattle() {
|
||||
const entity = ecs.query(ecs.allOf(BattleStateComp))[0];
|
||||
if (entity) {
|
||||
entity.get(BattleStateComp).isEnded = true;
|
||||
}
|
||||
}
|
||||
|
||||
/** 扩展:带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();
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "0e6e9aa4-1bc4-49e7-a327-19d2318ac59b",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||
|
||||
/** 战斗管理组件 */
|
||||
@ecs.register('BattleManager')
|
||||
export class BattleManagerComp extends ecs.Comp {
|
||||
/** 单例实例 */
|
||||
static instance: ecs.Entity;
|
||||
|
||||
reset() {
|
||||
BattleManagerComp.instance = this.ent;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "7ab0451e-efe7-4ec3-9d54-d7027a96e005",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||
import { BattleStateComp } from "./BattleStateComp";
|
||||
import { BattleManager } from "./BattleManager";
|
||||
|
||||
@ecs.register('BattlePhaseSystem')
|
||||
export class BattlePhaseSystem extends ecs.ComblockSystem {
|
||||
filter(): ecs.IMatcher {
|
||||
return ecs.allOf(BattleStateComp);
|
||||
|
||||
}
|
||||
|
||||
update(e: ecs.Entity) {
|
||||
const state = e.get(BattleStateComp);
|
||||
|
||||
switch(state.phase) {
|
||||
case BattleStateComp.Phase.Preparation:
|
||||
this.handlePreparation(state);
|
||||
break;
|
||||
case BattleStateComp.Phase.Fighting:
|
||||
this.handleFighting(state);
|
||||
break;
|
||||
case BattleStateComp.Phase.Victory:
|
||||
this.handleVictory(state);
|
||||
break;
|
||||
case BattleStateComp.Phase.Defeat:
|
||||
this.handleDefeat(state);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private handlePreparation(state: BattleStateComp) {
|
||||
// 准备阶段逻辑:角色选择、装备检查等
|
||||
if (state.startTime > 0) {
|
||||
state.setPhase(BattleStateComp.Phase.Fighting);
|
||||
}
|
||||
}
|
||||
|
||||
private handleFighting(state: BattleStateComp) {
|
||||
// 实时战斗逻辑:由其他系统处理
|
||||
}
|
||||
|
||||
private handleVictory(state: BattleStateComp) {
|
||||
// 胜利结算逻辑
|
||||
BattleManager.endBattleWithUI(true);
|
||||
state.setPhase(BattleStateComp.Phase.Preparation);
|
||||
}
|
||||
|
||||
private handleDefeat(state: BattleStateComp) {
|
||||
// 失败结算逻辑
|
||||
BattleManager.endBattleWithUI(false);
|
||||
state.setPhase(BattleStateComp.Phase.Preparation);
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "60eca3c6-1b6b-4090-a7f9-ca98a3f3c05d",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||
import { BattleStateComp } from "./BattleStateComp";
|
||||
import { smc } from "../common/SingletonModuleComp";
|
||||
|
||||
@ecs.register('BattleStartSystem')
|
||||
export class BattleStartSystem extends ecs.ComblockSystem {
|
||||
filter(): ecs.IMatcher {
|
||||
return ecs.allOf(BattleStateComp);
|
||||
}
|
||||
|
||||
update(e: ecs.Entity) {
|
||||
const state = e.get(BattleStateComp);
|
||||
if (state.startTime === 0) {
|
||||
// 初始化战斗逻辑
|
||||
state.startTime = Date.now();
|
||||
|
||||
console.log(`战斗开始,关卡ID: ${state.missionId}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "7a7dfd93-aebc-4f85-b9b9-f1e355f23285",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||
|
||||
/** 战斗状态组件 */
|
||||
@ecs.register('BattleState')
|
||||
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}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "9676b38a-0a44-491b-8107-1cd1a46b61e0",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -1,15 +1,9 @@
|
||||
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||
import { HeroSkillSystem } from "./HeroSkillSystem";
|
||||
import { BattleEndSystem } from "../battle/BattleEndSystem";
|
||||
import { BattleStartSystem } from "../battle/BattleStartSystem";
|
||||
import { BattlePhaseSystem } from "../battle/BattlePhaseSystem";
|
||||
export class EcsSkillSystem extends ecs.System {
|
||||
constructor() {
|
||||
super();
|
||||
this.add(new HeroSkillSystem());
|
||||
this.add(new BattleStartSystem());
|
||||
this.add(new BattlePhaseSystem());
|
||||
this.add(new BattleEndSystem());
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user