This commit is contained in:
2025-04-27 16:08:39 +08:00
parent d75cce01d7
commit ff172c7f72
4 changed files with 29 additions and 87 deletions

View File

@@ -1,9 +1,10 @@
import { _decorator, Label, ProgressBar, resources, Sprite, SpriteAtlas } from "cc";
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 { BoxSet } from "../common/config/BoxSet";
import { smc } from "../common/SingletonModuleComp";
import { Skill } from "../skills/Skill";
const { ccclass, property } = _decorator;
@@ -11,53 +12,35 @@ const { ccclass, property } = _decorator;
@ccclass('MSkillComp')
@ecs.register('MSkillComp', false)
export class MSkillComp extends CCComp {
s_uuid: number = 0;
group: number = 0;
lv:number = 0;
skill_on:boolean = false;
cd:number = 0;
/** 视图层逻辑代码分离演示 */
start() {
}
init(){
this.lv=0
console.log("MSkillComp init s_uuid:",this.s_uuid,this.group);
this.node.getChildByName("lv").getComponent(Label).string=this.lv.toString()
if(SkillSet[this.s_uuid]==undefined){this.skill_on=false; return}
this.cd=SkillSet[this.s_uuid].cd;
this.s_uuid=smc.mission.mskill
if(this.group == BoxSet.MONSTER){
this.s_uuid=smc.mission.mmskill
}
var icon_path = "game/skills/skill_icon"
resources.load(icon_path, SpriteAtlas, (err: any, atlas) => {
const sprite = this.node.getChildByName("icon").getComponent(Sprite);
sprite.spriteFrame = atlas.getSpriteFrame(SkillSet[this.s_uuid].path);
});
this.skill_on=true
}
protected update(dt: number): void {
if(!this.skill_on) return
this.doing_cd(dt)
}
doing_cd(dt: number){
this.cd-=dt
this.node.getChildByName("cd").getComponent(ProgressBar).progress=this.cd/SkillSet[this.s_uuid].cd
if(this.cd<=0){
console.log("cd<=0")
this.cd=SkillSet[this.s_uuid].cd
if(!smc.mission.play||smc.mission.pause){
return
}
}
lvup(){
this.lv++
this.node.getChildByName("lv").getComponent(Label).string=this.lv.toString()
private doSkill(config: typeof SkillSet[keyof typeof SkillSet]) {
const skillEntity = ecs.getEntity<Skill>(Skill);
const start_pos=v3(0,0)
const target_pos=v3(0,0)
skillEntity.load(
start_pos, // 起始位置
BoxSet.HERO, // 阵营
this.node.parent, // 父节点
config.uuid, // 技能ID
target_pos, // 目标位置
);
}
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
reset() {
this.node.destroy();
}
}