This commit is contained in:
walkpan
2025-02-01 00:14:25 +08:00
parent c5c01c6cf4
commit bffbb9077e
91 changed files with 2067 additions and 1327 deletions

View File

@@ -21,6 +21,11 @@ import { UIID } from "../common/config/GameUIConfig";
import { CardControllerComp } from "./CardController";
import { MissionHomeComp } from "./MissionHomeComp";
import { GameEvent } from "../common/config/GameEvent";
import { HeroViewComp } from "../hero/HeroViewComp";
import { MoveToComp } from "../hero/MoveToComp";
import { HeroSkillComp } from "../hero/HeroSkillComp";
import { HeroStateComp } from "../hero/HeroStateComp";
import { instantiate } from "cc";
const { ccclass, property } = _decorator;
/** 视图层对象 */
@@ -323,17 +328,66 @@ export class MissionComp extends CCComp {
this.fight_start= true
}
/** 添加玩家 */
private addHero(uuid:number=1001,i:number=0) {
let hero = ecs.getEntity<Hero>(Hero);
let scale = 1
let pos:Vec3 = v3(HeroSet.StartPos[1]-i*10,BoxSet.GAME_LINE);
hero.load(pos,scale,uuid);
private createEntity<T extends ecs.Entity>(
entityClass: ecs.TypedConstructor<T>,
components: ecs.Comp[]
): T {
const entity = ecs.Entity.create(entityClass);
components.forEach(comp => entity.add(comp));
return entity;
}
private addMonster(uuid:number=1001,i:number=0,is_boss:boolean=false) {
let mon = ecs.getEntity<Monster>(Monster);
let scale = -1
let pos:Vec3 = v3(-1*HeroSet.StartPos[1]+i*10,BoxSet.GAME_LINE);
mon.load(pos,scale,uuid,is_boss);
private addHero(uuid: number = 1001, index: number = 0) {
// 组件初始化
const components = [
this.createHeroModel(uuid),
this.createHeroView(index),
new MoveToComp()
];
// 创建实体
const hero = this.createEntity(Hero, components);
// 初始化技能系统
hero.get(HeroSkillComp)?.initSkills();
}
private createHeroModel(uuid: number): HeroModelComp {
const model = new HeroModelComp();
model.uuid = uuid;
model.level = 1;
return model;
}
private createHeroView(index: number): HeroViewComp {
const view = new HeroViewComp();
const pos = v3(HeroSet.StartPos[1] - index * 10, BoxSet.GAME_LINE);
view.initPosition(pos, 1);
return view;
}
private addMonster(uuid: number = 2001, index: number = 0, isBoss: boolean = false) {
const components = [
this.createMonsterModel(uuid, isBoss),
this.createMonsterView(index),
new MoveToComp()
];
this.createEntity(Monster, components);
}
private createMonsterModel(uuid: number, isBoss: boolean): MonModelComp {
const model = new MonModelComp();
model.uuid = uuid;
model.isBoss = isBoss;
return model;
}
private createMonsterView(index: number): HeroViewComp {
const view = new HeroViewComp();
const pos = v3(-HeroSet.StartPos[1] + index * 10, BoxSet.GAME_LINE);
view.initPosition(pos, -1);
return view;
}
@@ -343,4 +397,36 @@ export class MissionComp extends CCComp {
reset() {
this.node.destroy();
}
private clearEntities() {
// 使用类型安全的方式销毁实体
this.destroyEntities<Hero>(ecs.allOf(HeroModelComp));
this.destroyEntities<Monster>(ecs.allOf(MonModelComp));
}
private destroyEntities<T extends ecs.Entity>(matcher: ecs.IMatcher) {
ecs.query(matcher).forEach(entity => {
const view = entity.get(HeroViewComp);
view?.destroyNode();
entity.destroy();
});
}
// 添加实体类型守卫
private isHero(entity: ecs.Entity): entity is Hero {
return entity.has(HeroModelComp);
}
private isMonster(entity: ecs.Entity): entity is Monster {
return entity.has(MonModelComp);
}
// 统一实体处理
private updateEntities() {
ecs.query(ecs.allOf(HeroModelComp)).forEach(entity => {
if (this.isHero(entity)) {
entity.HeroModel.updateState();
}
});
}
}