176 lines
6.6 KiB
TypeScript
176 lines
6.6 KiB
TypeScript
import { _decorator, resources, Sprite, SpriteAtlas ,Node, ProgressBar} 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 { GameEvent } from "../common/config/GameEvent";
|
|
import { SkillSet } from "../common/config/SkillSet";
|
|
import { smc } from "../common/SingletonModuleComp";
|
|
import { oops } from "db://oops-framework/core/Oops";
|
|
import { MissionEvent } from "../common/config/MissionEvent";
|
|
import { EquipsComp } from "./EquipsComp";
|
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
/** 视图层对象 */
|
|
@ccclass('EquipSkillComp')
|
|
@ecs.register('EquipSkill', false)
|
|
export class EquipSkillComp extends CCComp {
|
|
skill1:any=null
|
|
skill2:any=null
|
|
skill3:any=null
|
|
equips:EquipsComp=null
|
|
boxs:Node=null
|
|
/** 视图层逻辑代码分离演示 */
|
|
onLoad() {
|
|
this.on(GameEvent.UseSkillCard, this.get_skill, this);
|
|
this.on(GameEvent.FightReady,this.fight_ready,this)
|
|
this.boxs=this.node.getChildByName("boxs")
|
|
this.equips=this.node.getComponent(EquipsComp)
|
|
}
|
|
start(){
|
|
this.fight_ready()
|
|
this.equips=this.node.getComponent(EquipsComp)
|
|
}
|
|
fight_ready(){
|
|
this.boxs.getChildByName("skill1").getChildByName("icon").active=false
|
|
this.boxs.getChildByName("skill2").getChildByName("icon").active=false
|
|
this.boxs.getChildByName("skill3").getChildByName("icon").active=false
|
|
this.skill1={
|
|
uuid:0,
|
|
name:"skill1",
|
|
type:0, //1 被动 0 主动
|
|
level:0,
|
|
quality:0,
|
|
cd:0,
|
|
cd_time:0,
|
|
}
|
|
this.skill2={
|
|
uuid:0,
|
|
name:"skill2",
|
|
type:0,//
|
|
level:0,
|
|
quality:0,
|
|
cd:0,
|
|
cd_time:0,
|
|
}
|
|
this.skill3={
|
|
uuid:0,
|
|
name:"skill3",
|
|
type:0,//
|
|
level:0,
|
|
quality:0,
|
|
cd:0,
|
|
cd_time:0,
|
|
}
|
|
}
|
|
update(dt: number): void {
|
|
if(!smc.mission.play||smc.mission.pause) return
|
|
if(this.skill1.uuid!=0){
|
|
if(this.skill1.cd_time < (this.skill1.cd-this.equips.attrs.hero.SKILL_CD)){
|
|
this.skill1.cd_time+=dt
|
|
}else{
|
|
this.skill1.cd_time=0
|
|
if(this.skill1.type==1){
|
|
this.do_skill1()
|
|
}
|
|
}
|
|
this.boxs.getChildByName("skill1").getChildByName("icon").getChildByName("cd").getComponent(ProgressBar).progress=(1-this.skill1.cd_time/this.skill1.cd)
|
|
}
|
|
if(this.skill2.uuid!=0){
|
|
if(this.skill2.cd_time < (this.skill2.cd-this.equips.attrs.hero.SKILL_CD)){
|
|
this.skill2.cd_time+=dt
|
|
}else{
|
|
this.skill2.cd_time=0
|
|
if(this.skill2.type==1){
|
|
this.do_skill2()
|
|
}
|
|
}
|
|
this.boxs.getChildByName("skill2").getChildByName("icon").getChildByName("cd").getComponent(ProgressBar).progress=(1-this.skill2.cd_time/this.skill2.cd)
|
|
}
|
|
if(this.skill3.uuid!=0){
|
|
if(this.skill3.cd_time < (this.skill3.cd-this.equips.attrs.hero.SKILL_CD)){
|
|
this.skill3.cd_time+=dt
|
|
}else{
|
|
this.skill3.cd_time=0
|
|
if(this.skill3.type==1){
|
|
this.do_skill3()
|
|
}
|
|
}
|
|
this.boxs.getChildByName("skill3").getChildByName("icon").getChildByName("cd").getComponent(ProgressBar).progress=(1-this.skill3.cd_time/this.skill3.cd)
|
|
}
|
|
}
|
|
do_skill1(){
|
|
console.log("do_skill1")
|
|
this.skill1.cd_time=0
|
|
this.do_skill(this.skill1.uuid)
|
|
}
|
|
do_skill2(){
|
|
console.log("do_skill2")
|
|
this.skill2.cd_time=0
|
|
this.do_skill(this.skill2.uuid)
|
|
}
|
|
do_skill3(){
|
|
console.log("do_skill3")
|
|
this.skill3.cd_time=0
|
|
this.do_skill(this.skill3.uuid)
|
|
}
|
|
|
|
do_skill(uuid:number){
|
|
console.log("出发技能:",uuid)
|
|
oops.message.dispatchEvent(GameEvent.CastHeroSkill,uuid)
|
|
}
|
|
|
|
get_skill(e:GameEvent,data:any){
|
|
console.log("get_skill")
|
|
if(this.skill1.uuid==0){
|
|
this.skill1.uuid=data.uuid
|
|
this.skill1.skill_name=SkillSet[data.uuid].name
|
|
this.skill1.type=1
|
|
this.skill1.cd=SkillSet[data.uuid].cd
|
|
this.skill1.cd_time=SkillSet[data.uuid].cd
|
|
let icon = this.node.getChildByName("boxs").getChildByName("skill1").getChildByName("icon")
|
|
icon.active=true
|
|
var icon_path = "game/skills/skill_icon"
|
|
resources.load(icon_path, SpriteAtlas, (err: any, atlas) => {
|
|
const sprite = icon.getChildByName("skill").getComponent(Sprite);
|
|
sprite.spriteFrame = atlas.getSpriteFrame(SkillSet[data.uuid].path);
|
|
});
|
|
return
|
|
}
|
|
if(this.skill2.uuid==0){
|
|
this.skill2.uuid=data.uuid
|
|
this.skill2.skill_name=SkillSet[data.uuid].name
|
|
this.skill2.type=1
|
|
this.skill2.cd=SkillSet[data.uuid].cd
|
|
this.skill2.cd_time=SkillSet[data.uuid].cd
|
|
let icon = this.node.getChildByName("boxs").getChildByName("skill2").getChildByName("icon")
|
|
icon.active=true
|
|
var icon_path = "game/skills/skill_icon"
|
|
resources.load(icon_path, SpriteAtlas, (err: any, atlas) => {
|
|
const sprite = icon.getChildByName("skill").getComponent(Sprite);
|
|
sprite.spriteFrame = atlas.getSpriteFrame(SkillSet[data.uuid].path);
|
|
});
|
|
return
|
|
}
|
|
if(this.skill3.uuid==0){
|
|
this.skill3.uuid=data.uuid
|
|
this.skill3.skill_name=SkillSet[data.uuid].name
|
|
this.skill3.type=1
|
|
this.skill3.cd=SkillSet[data.uuid].cd
|
|
this.skill3.cd_time=SkillSet[data.uuid].cd
|
|
let icon = this.node.getChildByName("boxs").getChildByName("skill3").getChildByName("icon")
|
|
icon.active=true
|
|
var icon_path = "game/skills/skill_icon"
|
|
resources.load(icon_path, SpriteAtlas, (err: any, atlas) => {
|
|
const sprite = icon.getChildByName("skill").getComponent(Sprite);
|
|
sprite.spriteFrame = atlas.getSpriteFrame(SkillSet[data.uuid].path);
|
|
});
|
|
return
|
|
}
|
|
console.log("技能栏满了")
|
|
}
|
|
|
|
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
|
reset() {
|
|
this.node.destroy();
|
|
}
|
|
} |