装备添加
This commit is contained in:
@@ -1,115 +0,0 @@
|
||||
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 { 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;
|
||||
|
||||
/** 视图层对象 */
|
||||
@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;
|
||||
}
|
||||
|
||||
// 处理技能队列
|
||||
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(uuid: number, start_pos: Vec3, target_pos: Vec3, group: number) {
|
||||
const skillEntity = ecs.getEntity<Skill>(Skill);
|
||||
skillEntity.load(
|
||||
start_pos, // 起始位置
|
||||
group, // 阵营
|
||||
this.node.parent, // 父节点
|
||||
uuid, // 技能ID
|
||||
target_pos, // 目标位置
|
||||
);
|
||||
}
|
||||
|
||||
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
||||
reset() {
|
||||
// 清空技能队列
|
||||
this.skillQueue = [];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user