伤害系统 + 战斗管理系统
This commit is contained in:
@@ -8,6 +8,9 @@ import { smc } from './game/common/SingletonModuleComp';
|
||||
import { Initialize } from './game/initialize/Initialize';
|
||||
import { EcsPositionSystem } from './game/common/ecs/position/EcsPositionSystem';
|
||||
import { EcsSkillSystem } from './game/skill/EcsSkillSystem';
|
||||
import { DamageSystem } from './game/damage/DamageSystem';
|
||||
import { DamageShowSystem } from './game/damage/DamageShowSystem';
|
||||
import { BattleEndSystem } from './game/battle/BattleEndSystem';
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@@ -18,6 +21,12 @@ export class Main extends Root {
|
||||
protected async run() {
|
||||
smc.initialize = ecs.getEntity<Initialize>(Initialize);
|
||||
smc.vmAdd()
|
||||
ecs.System.init(
|
||||
DamageSystem,
|
||||
DamageShowSystem,
|
||||
BattleEndSystem,
|
||||
// ...其他系统...
|
||||
);
|
||||
}
|
||||
protected initGui() {
|
||||
oops.gui.init(UIConfigData);
|
||||
|
||||
9
assets/script/game/battle.meta
Normal file
9
assets/script/game/battle.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "98ac6b4e-90c9-4719-bae3-a65982701915",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
9
assets/script/game/battle/BattleEndSystem.ts.meta
Normal file
9
assets/script/game/battle/BattleEndSystem.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "8454cfbc-f83d-45e9-a8c5-5bb4c830ada8",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
83
assets/script/game/battle/BattleManager.ts
Normal file
83
assets/script/game/battle/BattleManager.ts
Normal file
@@ -0,0 +1,83 @@
|
||||
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";
|
||||
import { DamageResult } from "../damage/DamageComp";
|
||||
|
||||
@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;
|
||||
|
||||
}
|
||||
|
||||
/** 外部调用入口:开始新战斗 */
|
||||
startBattle(missionId: number) {
|
||||
this.get(BattleState).isEnded = false;
|
||||
// 加载关卡配置、生成敌人等
|
||||
smc.mission.load(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);
|
||||
}
|
||||
}
|
||||
|
||||
private onBattleEnd(entity: ecs.Entity) {
|
||||
// 发放奖励、保存进度等
|
||||
const state = entity.get(BattleState); // 清理所有残留伤害组件
|
||||
ecs.query(ecs.allOf(DamageResult)).forEach(entity => {
|
||||
entity.remove(DamageResult);
|
||||
});
|
||||
// 重置战斗状态
|
||||
state.isEnded = false;
|
||||
entity.destroy();
|
||||
}
|
||||
}
|
||||
9
assets/script/game/battle/BattleManager.ts.meta
Normal file
9
assets/script/game/battle/BattleManager.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "0e6e9aa4-1bc4-49e7-a327-19d2318ac59b",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
11
assets/script/game/battle/BattleStateComp.ts
Normal file
11
assets/script/game/battle/BattleStateComp.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||
|
||||
@ecs.register('BattleState')
|
||||
export class BattleState extends ecs.Comp {
|
||||
isEnded: boolean = false;
|
||||
|
||||
|
||||
reset() {
|
||||
this.isEnded = false;
|
||||
}
|
||||
}
|
||||
9
assets/script/game/battle/BattleStateComp.ts.meta
Normal file
9
assets/script/game/battle/BattleStateComp.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "9676b38a-0a44-491b-8107-1cd1a46b61e0",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
9
assets/script/game/damage.meta
Normal file
9
assets/script/game/damage.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "d2e9b2e7-c86a-4c47-b030-bb7ae1d38fad",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
9
assets/script/game/damage/DamageComp.ts.meta
Normal file
9
assets/script/game/damage/DamageComp.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "5dc13d0b-967b-4378-89d0-35322998b506",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
21
assets/script/game/damage/DamageShowSystem.ts
Normal file
21
assets/script/game/damage/DamageShowSystem.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||
import { HeroViewComp } from "../hero/HeroViewComp";
|
||||
import { DamageResult } from "./DamageComp";
|
||||
|
||||
@ecs.register('DamageShowSystem')
|
||||
export class DamageShowSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate {
|
||||
filter(): ecs.IMatcher {
|
||||
return ecs.allOf(DamageResult, HeroViewComp);
|
||||
}
|
||||
|
||||
update(e: ecs.Entity) {
|
||||
const res = e.get(DamageResult);
|
||||
const view = e.get(HeroViewComp);
|
||||
|
||||
// 显示伤害数字
|
||||
view.showDamage(res.finalDamage, res.isCrit);
|
||||
|
||||
// 移除已处理的伤害结果组件
|
||||
e.remove(DamageResult);
|
||||
}
|
||||
}
|
||||
9
assets/script/game/damage/DamageShowSystem.ts.meta
Normal file
9
assets/script/game/damage/DamageShowSystem.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "a9a6c37c-d5c7-4811-bc7a-471c8ed7b022",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
9
assets/script/game/damage/DamageSystem.ts.meta
Normal file
9
assets/script/game/damage/DamageSystem.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "5e0fcfaa-f9b3-43b6-8584-5a55940c89e0",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Vec3, _decorator , v3,Collider2D,Contact2DType,Label ,Node,Prefab,instantiate,ProgressBar, Component, Material, Sprite, math, clamp, Game, tween} from "cc";
|
||||
import { Vec3, _decorator , v3,Collider2D,Contact2DType,Label ,Node,Prefab,instantiate,ProgressBar, Component, Material, Sprite, math, clamp, Game, tween, Color} from "cc";
|
||||
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
|
||||
import { HeroSpine } from "./HeroSpine";
|
||||
@@ -571,4 +571,13 @@ export class HeroViewComp extends CCComp {
|
||||
const skills = this.ent.get(HeroSkillsComp);
|
||||
skills.resetAllCooldowns();
|
||||
}
|
||||
|
||||
/** 显示伤害数字 */
|
||||
showDamage(damage: number, isCrit: boolean) {
|
||||
if(isCrit){
|
||||
this.BUFFCOMP.tooltip(4,damage.toFixed(0),damage)
|
||||
}else{
|
||||
this.BUFFCOMP.tooltip(1,damage.toFixed(0),damage)
|
||||
}
|
||||
}
|
||||
}
|
||||
26
assets/script/game/map/MapView.ts
Normal file
26
assets/script/game/map/MapView.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
// 开始战斗
|
||||
function startBattle() {
|
||||
const battle = new BattleManager();
|
||||
battle.add(BattleManagerComp);
|
||||
oops.message.dispatchEvent("BattleStart");
|
||||
}
|
||||
|
||||
// 结束战斗
|
||||
function endBattle() {
|
||||
const battle = ecs.query(ecs.allOf(BattleManager))[0];
|
||||
if (battle) {
|
||||
battle.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
// 点击开始战斗按钮
|
||||
function onBattleStartClick(missionId: number) {
|
||||
BattleManager.instance.startBattle(missionId);
|
||||
}
|
||||
|
||||
// 角色死亡时检测
|
||||
function checkHeroDeath() {
|
||||
if (heroView.hp <= 0) {
|
||||
BattleManager.instance.endBattle();
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import { UIID } from "../common/config/GameUIConfig";
|
||||
import { CardControllerComp } from "./CardController";
|
||||
import { MissionHomeComp } from "./MissionHomeComp";
|
||||
import { GameEvent } from "../common/config/GameEvent";
|
||||
import { BattleState } from "../battle/BattleStateComp";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
/** 视图层对象 */
|
||||
@@ -102,10 +103,10 @@ export class MissionComp extends CCComp {
|
||||
monsters[i].HeroView.reset()
|
||||
monsters[i].HeroView.ent.destroy()
|
||||
}
|
||||
|
||||
// this.to_mission_home()
|
||||
this.open_victory()
|
||||
}
|
||||
|
||||
open_victory(){
|
||||
this.node.getChildByName("victory").active=true
|
||||
this.node.getChildByName("victory").getComponent(VictoryComp).open()
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||
import { HeroSkillSystem } from "./HeroSkillSystem";
|
||||
import { DamageSystem } from "../damage/DamageSystem";
|
||||
export class EcsSkillSystem extends ecs.System {
|
||||
constructor() {
|
||||
super();
|
||||
this.add(new HeroSkillSystem());
|
||||
this.add(new DamageSystem());
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user