dd
This commit is contained in:
18
assets/script/game/core/EntityFactory.ts
Normal file
18
assets/script/game/core/EntityFactory.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
export class EntityFactory {
|
||||
static createHero(config: HeroConfig): ecs.Entity {
|
||||
const hero = ecs.Entity.create();
|
||||
|
||||
// 基础组件
|
||||
hero.add(HeroModel).init(config);
|
||||
hero.add(HeroView).loadModel(config.prefabPath);
|
||||
hero.add(Movement).init(config.speed);
|
||||
hero.add(Combat).init(config.baseAttack, config.attackRange);
|
||||
|
||||
// 技能系统
|
||||
config.skills.forEach(skill => {
|
||||
hero.add(Skill).registerSkill(skill);
|
||||
});
|
||||
|
||||
return hero;
|
||||
}
|
||||
}
|
||||
9
assets/script/game/core/EntityFactory.ts.meta
Normal file
9
assets/script/game/core/EntityFactory.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "d29e9c6d-1fbc-439e-b674-0a5fdf1d929a",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
18
assets/script/game/core/GameEvents.ts
Normal file
18
assets/script/game/core/GameEvents.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
export class CombatEvent {
|
||||
static readonly type = 'CombatEvent';
|
||||
constructor(
|
||||
public readonly attacker: ecs.Entity,
|
||||
public readonly target: ecs.Entity,
|
||||
public readonly damage: number
|
||||
) {}
|
||||
}
|
||||
|
||||
// 事件监听示例
|
||||
oops.message.on(CombatEvent.type, (event: CombatEvent) => {
|
||||
const targetModel = event.target.get(HeroModel);
|
||||
targetModel.hp = Math.max(targetModel.hp - event.damage, 0);
|
||||
|
||||
if (targetModel.hp <= 0) {
|
||||
event.target.add(Status).setDead();
|
||||
}
|
||||
});
|
||||
9
assets/script/game/core/GameEvents.ts.meta
Normal file
9
assets/script/game/core/GameEvents.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "45c6bedf-311f-4ad5-9e0e-92542a7655c4",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
Reference in New Issue
Block a user