import { _decorator, Animation, Label, resources, SpriteAtlas,Sprite } 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 { HeroInfo, HeroList } from "../common/config/heroSet"; import { RandomManager } from "db://oops-framework/core/common/random/RandomManager"; import { oops } from "db://oops-framework/core/Oops"; import { HeroModelComp } from "../hero/HeroModelComp"; import { HeroViewComp } from "../hero/HeroViewComp"; import { smc } from "../common/SingletonModuleComp"; import { HeroSkillList, SkillSet } from "../common/config/SkillSet"; import { cardType, getRandomCardUUID } from "../common/config/CardSet"; import { EquipInfo } from "../common/config/Equips"; const { ccclass, property } = _decorator; /** 视图层对象 */ @ccclass('CardComp') @ecs.register('Card', false) export class CardComp extends CCComp { c_uuid:number=0; c_type:number=0; //0英雄,1 技能.2 装备 is_used:boolean=false; onLoad(){ // this.on(GameEvent.HeroSelect,this.hero_select,this) // this.on(GameEvent.HeroSkillSelect,this.hero_skill_select,this) // this.on(GameEvent.CardRefresh,this.rad,this) } start() { } init_card(){ this.node.getChildByName("Button").active=false this.node.getChildByName("show").active=false } hero_select(args: any){ this.c_type=0 this.c_uuid=args.uuid console.log("card hero_select c_uuid:"+this.c_uuid) this.show_hero(this.c_uuid) this.node.getChildByName("show").active=false this.node.getChildByName("anim").getChildByName("up").getComponent(Animation).play('carsup') this.scheduleOnce(() => { this.node.getChildByName("show").active=true this.node.getChildByName("Button").active=true }, 0.1); } hero_skill_select(args: any){ this.c_type=1 console.log("card hero_skill_select",args) this.c_uuid=args.uuid this.node.getChildByName("show").active=false this.node.getChildByName("anim").getChildByName("up").getComponent(Animation).play('carsup') this.show_skill(this.c_uuid) this.scheduleOnce(() => { this.node.getChildByName("show").active=true this.node.getChildByName("Button").active=true }, 0.1); } equip_select(args: any){ this.c_type=2 this.c_uuid=args.uuid this.node.getChildByName("show").active=false this.node.getChildByName("anim").getChildByName("up").getComponent(Animation).play('carsup') this.show_equip(this.c_uuid) this.scheduleOnce(() => { this.node.getChildByName("show").active=true this.node.getChildByName("Button").active=true }, 0.1); } func_select(args: any){ console.log("card func_select",args) } random_select(){ let card =getRandomCardUUID() //随机获取卡牌类型 console.log("rad 开始请求卡牌",card) switch(card.type){ case cardType.HERO: this.hero_select(card) break case cardType.SKILL: this.hero_skill_select(card) break case cardType.EQUIP: this.equip_select(card) break } } show_skill(uuid:number){ let show=this.node.getChildByName("show") show.getChildByName("name").getComponent(Label).string=SkillSet[uuid].name show.getChildByName("ap").active=false show.getChildByName("hp").active=false show.getChildByName("mask").getChildByName("skill").active=true show.getChildByName("mask").getChildByName("s_bg").active=true show.getChildByName("mask").getChildByName("equip").active=false show.getChildByName("mask").getChildByName("e_bg").active=false show.getChildByName("mask").getChildByName("hero").active=false show.getChildByName("mask").getChildByName("h_bg").active=false var icon_path = "game/skills/skill_icon" resources.load(icon_path, SpriteAtlas, (err: any, atlas) => { const sprite = show.getChildByName("mask").getChildByName("skill").getComponent(Sprite); sprite.spriteFrame = atlas.getSpriteFrame(SkillSet[uuid].path); }); this.node.getChildByName("Button").getChildByName("Label").getComponent(Label).string=this.check_heros() } show_hero(uuid:number){ let show=this.node.getChildByName("show") show.getChildByName("ap").active=true show.getChildByName("hp").active=true show.getChildByName("mask").getChildByName("skill").active=false show.getChildByName("mask").getChildByName("s_bg").active=false show.getChildByName("mask").getChildByName("equip").active=false show.getChildByName("mask").getChildByName("e_bg").active=false show.getChildByName("mask").getChildByName("hero").active=true show.getChildByName("mask").getChildByName("h_bg").active=true show.getChildByName("name").getComponent(Label).string=HeroInfo[uuid].name show.getChildByName("ap").getChildByName("num").getComponent(Label).string=HeroInfo[uuid].ap.toString() show.getChildByName("hp").getChildByName("num").getComponent(Label).string=HeroInfo[uuid].hp.toString() // show.getChildByName("type").getChildByName("war").active=HeroInfo[uuid].type==0 // show.getChildByName("type").getChildByName("bow").active=HeroInfo[uuid].type==1 // show.getChildByName("type").getChildByName("mag").active=HeroInfo[uuid].type==2 // show.getChildByName("lv").getChildByName("num").getComponent(Label).string=HeroInfo[uuid].lv.toString() var icon_path = "game/heros/herois" resources.load(icon_path, SpriteAtlas, (err: any, atlas) => { const sprite = show.getChildByName("mask").getChildByName("hero").getComponent(Sprite); sprite.spriteFrame = atlas.getSpriteFrame(HeroInfo[uuid].path); }); this.node.getChildByName("Button").getChildByName("Label").getComponent(Label).string=this.check_heros() } show_equip(uuid:number){ let show=this.node.getChildByName("show") show.getChildByName("ap").active=false show.getChildByName("hp").active=false show.getChildByName("mask").getChildByName("skill").active=false show.getChildByName("mask").getChildByName("s_bg").active=false show.getChildByName("mask").getChildByName("equip").active=true show.getChildByName("mask").getChildByName("e_bg").active=true show.getChildByName("mask").getChildByName("hero").active=false show.getChildByName("mask").getChildByName("h_bg").active=false show.getChildByName("name").getComponent(Label).string=EquipInfo[uuid].name var icon_path = "game/heros/equips" resources.load(icon_path, SpriteAtlas, (err: any, atlas) => { const sprite = show.getChildByName("mask").getChildByName("equip").getComponent(Sprite); sprite.spriteFrame = atlas.getSpriteFrame(EquipInfo[uuid].uuid.toString()); }); this.node.getChildByName("Button").getChildByName("Label").getComponent(Label).string=this.check_heros() } check_heros(){ // let heros=ecs.query(ecs.allOf(HeroModelComp)) // for(let hero of heros){ // if(hero.get(HeroViewComp).hero_uuid == this.c_uuid){ // return "升级" // } // if(hero.get(HeroViewComp).type==HeroInfo[this.c_uuid].type){ // return "替换" // } // } return "选择" } use_card(){ switch(this.c_type){ case 0: if(smc.vmdata.mission_data.gold< smc.vmdata.mission_data.call_gold){ oops.gui.toast("金币不足", false); return } oops.message.dispatchEvent(GameEvent.UseHeroCard,{uuid:this.c_uuid}) smc.vmdata.mission_data.gold-=smc.vmdata.mission_data.call_gold oops.message.dispatchEvent(GameEvent.CardsClose) break case 1: console.log("use_card 技能卡") oops.message.dispatchEvent(GameEvent.UseSkillCard,{uuid:this.c_uuid}) oops.message.dispatchEvent(GameEvent.CardsClose) break case 2: console.log("use_card 装备卡") oops.message.dispatchEvent(GameEvent.EquipAdd,{uuid:this.c_uuid,type:EquipInfo[this.c_uuid].type}) oops.message.dispatchEvent(GameEvent.CardsClose) break } } reset() { this.node.destroy(); } }