This commit is contained in:
2025-04-27 16:57:46 +08:00
parent ff172c7f72
commit 32f3c75241
2 changed files with 82 additions and 12 deletions

View File

@@ -1,10 +1,11 @@
import { _decorator, Label, ProgressBar, resources, Sprite, SpriteAtlas, v3, Vec3 } 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 { SkillSet } from "../common/config/SkillSet";
import { CdType, SkillSet } from "../common/config/SkillSet";
import { BoxSet } from "../common/config/BoxSet";
import { smc } from "../common/SingletonModuleComp";
import { Skill } from "../skills/Skill";
import { GameEvent } from "../common/config/GameEvent";
const { ccclass, property } = _decorator;
@@ -12,35 +13,103 @@ const { ccclass, property } = _decorator;
@ccclass('MSkillComp')
@ecs.register('MSkillComp', false)
export class MSkillComp extends CCComp {
/** 视图层逻辑代码分离演示 */
/** 技能队列 */
private skillQueue: Array<{
uuid: number,
startPos: Vec3,
targetPos: Vec3,
group: number,
count: number,
cd: number,
cdTimer: number // 改用累计时间计时器
}> = [];
/** 常驻技能 */
MSkill:any={
uuid:0,
CdType:0,
cd:0,
count:0,
cdTimer:0
}
/** 技能队列 */
protected onLoad(): void {
this.on(GameEvent.MissionSkill, this.skill_event, this);
}
start() {
}
init(){
}
protected update(dt: number): void {
if(!smc.mission.play||smc.mission.pause){
return
if (!smc.mission.play || smc.mission.pause) {
return;
}
// 处理技能队列
this.processSkillQueue(dt);
}
skill_event(e: any) {
// 技能加入队列
const { uuid, startPos, targetPos, group, count = 1, cd = 0 } = e;
this.skillQueue.push({
uuid,
startPos,
targetPos,
group,
count,
cd,
cdTimer: 0 // 初始化计时器为0
});
}
private processSkillQueue(dt: number) {
// 遍历技能队列
for (let i = this.skillQueue.length - 1; i >= 0; i--) {
const skill = this.skillQueue[i];
// 累加计时器
skill.cdTimer += dt;
// 检查CD (将cd从毫秒转换为秒进行比较)
if (skill.cdTimer < skill.cd * 0.001) {
continue;
}
// 释放技能
this.doSkill(
skill.uuid,
skill.startPos,
skill.targetPos,
skill.group
);
// 重置CD计时器
skill.cdTimer = 0;
// 减少技能次数
skill.count--;
// 如果技能次数用完,从队列中移除
if (skill.count <= 0) {
this.skillQueue.splice(i, 1);
}
}
}
private doSkill(config: typeof SkillSet[keyof typeof SkillSet]) {
private doSkill(uuid: number, start_pos: Vec3, target_pos: Vec3, group: number) {
const skillEntity = ecs.getEntity<Skill>(Skill);
const start_pos=v3(0,0)
const target_pos=v3(0,0)
skillEntity.load(
start_pos, // 起始位置
BoxSet.HERO, // 阵营
group, // 阵营
this.node.parent, // 父节点
config.uuid, // 技能ID
uuid, // 技能ID
target_pos, // 目标位置
);
}
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
reset() {
// 清空技能队列
this.skillQueue = [];
}
}