376 lines
17 KiB
TypeScript
376 lines
17 KiB
TypeScript
import { _decorator, Animation, Label, resources, SpriteAtlas,Sprite, Skeleton, SkinnedMeshRenderer, sp } 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} 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, SuperCards } from "../common/config/CardSet";
|
|
import { EquipInfo, EquipType } from "../common/config/Equips";
|
|
import { FightSet } from "../common/config/Mission";
|
|
import { EnhancementOptions } from "../common/config/LevelUp";
|
|
import { TalentList } from "../common/config/TalentSet";
|
|
import { QualitySet } from "../common/config/BoxSet";
|
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
/** 视图层对象 */
|
|
@ccclass('CardComp')
|
|
@ecs.register('Card', false)
|
|
export class CardComp extends CCComp {
|
|
c_uuid:number=0;
|
|
c_type:number=0; //1英雄,2 技能.3 装备 4.功能卡牌
|
|
is_used:boolean=false;
|
|
cost_gold:number=0;
|
|
skill_slot:string="skill1"
|
|
equip_slot:string="weapon"
|
|
talent_slot:string="tal1"
|
|
enhancement_data:any=null;
|
|
onLoad(){
|
|
// this.on(GameEvent.HeroSelect,this.hero_select,this)
|
|
}
|
|
|
|
start() {
|
|
|
|
}
|
|
|
|
init_card(){
|
|
this.node.getChildByName("Button").active=false
|
|
this.node.getChildByName("show").active=false
|
|
}
|
|
talent_select(args: any,data:any){
|
|
this.c_type=cardType.TALENT
|
|
this.c_uuid=args.uuid
|
|
// this.talent_slot=data.slot
|
|
this.show_talent(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_select(args: any){
|
|
this.c_type=cardType.HERO
|
|
this.c_uuid=args.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,data:any){
|
|
this.c_type=cardType.SKILL
|
|
// console.log("[cardcomp]:card hero_skill_select",args)
|
|
this.c_uuid=args.uuid
|
|
this.skill_slot=data.slot
|
|
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,slot:string="weapon"){
|
|
this.c_type=cardType.EQUIP
|
|
this.c_uuid=args.uuid
|
|
this.equip_slot=slot
|
|
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("[cardcomp]:card func_select",args)
|
|
this.c_type=cardType.SPECIAL
|
|
this.c_uuid=args.uuid
|
|
this.node.getChildByName("show").active=false
|
|
this.node.getChildByName("anim").getChildByName("up").getComponent(Animation).play('carsup')
|
|
this.show_func(this.c_uuid)
|
|
this.scheduleOnce(() => {
|
|
this.node.getChildByName("show").active=true
|
|
this.node.getChildByName("Button").active=true
|
|
}, 0.1);
|
|
}
|
|
enhancement_select(args: any){
|
|
this.c_type=cardType.ENHANCEMENT
|
|
this.enhancement_data=args
|
|
this.node.getChildByName("show").active=false
|
|
this.node.getChildByName("anim").getChildByName("up").getComponent(Animation).play('carsup')
|
|
this.show_enhancement(args)
|
|
this.scheduleOnce(() => {
|
|
this.node.getChildByName("show").active=true
|
|
this.node.getChildByName("Button").active=true
|
|
}, 0.1);
|
|
}
|
|
|
|
random_select(){
|
|
let card =getRandomCardUUID() //随机获取卡牌类型
|
|
console.log("[cardcomp]:rad 开始请求卡牌",card)
|
|
switch(card.type){
|
|
case cardType.EQUIP:
|
|
this.equip_select(card)
|
|
break
|
|
case cardType.SPECIAL:
|
|
this.func_select(card)
|
|
break
|
|
}
|
|
}
|
|
show_talent(uuid:number,){
|
|
let show=this.node.getChildByName("show")
|
|
show.getChildByName("name").getChildByName("name").getComponent(Label).string=TalentList[uuid].name
|
|
this.do_card_bg_show(TalentList[uuid].quality)
|
|
this.node.getChildByName("show").getChildByName("coins").active=false
|
|
var icon_path = "game/heros/cards"
|
|
resources.load(icon_path, SpriteAtlas, (err: any, atlas) => {
|
|
const sprite = show.getChildByName("mask").getChildByName("tal").getComponent(Sprite);
|
|
sprite.spriteFrame = atlas.getSpriteFrame(TalentList[uuid].path);
|
|
});
|
|
show.getChildByName("info").getComponent(Label).string=TalentList[uuid].info
|
|
console.log("[cardcomp]:show_talent",TalentList[uuid],show)
|
|
}
|
|
show_skill(uuid:number){
|
|
let show=this.node.getChildByName("show")
|
|
show.getChildByName("name").getChildByName("name").getComponent(Label).string=SkillSet[uuid].name
|
|
this.do_card_bg_show(SkillSet[uuid].quality)
|
|
this.node.getChildByName("show").getChildByName("coins").active=false
|
|
var icon_path = "game/heros/cards"
|
|
resources.load(icon_path, SpriteAtlas, (err: any, atlas) => {
|
|
const sprite = show.getChildByName("mask").getChildByName("skill").getComponent(Sprite);
|
|
sprite.spriteFrame = atlas.getSpriteFrame(SkillSet[uuid].path);
|
|
});
|
|
show.getChildByName("info").getComponent(Label).string=SkillSet[uuid].info
|
|
}
|
|
/* 英雄 直接加载骨骼动画 */ //注意 动画名称为Idle
|
|
show_hero(uuid:number){
|
|
let show=this.node.getChildByName("show")
|
|
show.getChildByName("name").getChildByName("name").getComponent(Label).string=HeroInfo[uuid].name
|
|
this.do_card_bg_show(HeroInfo[uuid].quality)
|
|
show.getChildByName("coins").active=false
|
|
var icon_path = "game/heros/heros/"+HeroInfo[uuid].path
|
|
// resources.load(icon_path, sp.SkeletonData, (err, skeleton) => {
|
|
// if (err) {
|
|
// console.error("[CardComp]: 加载骨骼数据失败:", err);
|
|
// return;
|
|
// }
|
|
// console.log("[CardComp]: 加载骨骼数据成功:", skeleton)
|
|
// // 检查节点是否仍然存在
|
|
// const maskNode = show.getChildByName("mask");
|
|
// if (!maskNode) {
|
|
// console.error("[CardComp]: mask节点不存在");
|
|
// return;
|
|
// }
|
|
|
|
// const heroNode = maskNode.getChildByName("hero");
|
|
// if (!heroNode) {
|
|
// console.error("[CardComp]: hero节点不存在");
|
|
// return;
|
|
// }
|
|
|
|
// const spine = heroNode.getComponent(sp.Skeleton);
|
|
// if (!spine) {
|
|
// console.error("[CardComp]: hero节点上没有找到SkinnedMeshRenderer组件");
|
|
// return;
|
|
// }
|
|
|
|
// if (spine) {
|
|
// spine.skeletonData = skeleton;
|
|
// spine.setAnimation(0, "Idle", true);
|
|
// }
|
|
// });
|
|
// resources.load(icon_path, SpriteAtlas, (err: any, atlas) => {
|
|
// const sprite = show.getChildByName("mask").getChildByName("hero").getComponent(Sprite);
|
|
// sprite.spriteFrame = atlas.getSpriteFrame(HeroInfo[uuid].path);
|
|
// });
|
|
show.getChildByName("info").getComponent(Label).string=HeroInfo[uuid].info
|
|
|
|
}
|
|
|
|
show_equip(uuid:number){
|
|
let show=this.node.getChildByName("show")
|
|
show.getChildByName("name").getChildByName("name").getComponent(Label).string=EquipInfo[uuid].name
|
|
this.do_card_bg_show(EquipInfo[uuid].quality)
|
|
var icon_path = "game/heros/equips2"
|
|
resources.load(icon_path, SpriteAtlas, (err: any, atlas) => {
|
|
const sprite = show.getChildByName("mask").getChildByName("equip").getComponent(Sprite);
|
|
sprite.spriteFrame = atlas.getSpriteFrame(EquipInfo[uuid].path);
|
|
});
|
|
show.getChildByName("info").getComponent(Label).string=EquipInfo[uuid].info
|
|
}
|
|
|
|
show_func(uuid:number){
|
|
let show=this.node.getChildByName("show")
|
|
show.getChildByName("name").getChildByName("name").getComponent(Label).string=SuperCards[uuid].name
|
|
this.do_card_bg_show(SuperCards[uuid].quality)
|
|
|
|
var icon_path = "game/heros/cards"
|
|
resources.load(icon_path, SpriteAtlas, (err: any, atlas) => {
|
|
const sprite = show.getChildByName("mask").getChildByName("func").getComponent(Sprite);
|
|
sprite.spriteFrame = atlas.getSpriteFrame(SuperCards[uuid].path);
|
|
});
|
|
show.getChildByName("info").getComponent(Label).string=SuperCards[uuid].info
|
|
}
|
|
|
|
show_enhancement(data:any){
|
|
let show=this.node.getChildByName("show")
|
|
show.getChildByName("name").getChildByName("name").getComponent(Label).string=data.name
|
|
this.do_card_bg_show(data.rarity)
|
|
var icon_path = "game/heros/cards"
|
|
resources.load(icon_path, SpriteAtlas, (err: any, atlas) => {
|
|
const sprite = show.getChildByName("mask").getChildByName("func").getComponent(Sprite);
|
|
sprite.spriteFrame = atlas.getSpriteFrame(data.icon);
|
|
});
|
|
show.getChildByName("info").getComponent(Label).string=data.description
|
|
}
|
|
|
|
do_card_bg_show(q:number=QualitySet.GREEN){
|
|
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("equip").active=false
|
|
show.getChildByName("mask").getChildByName("hero").active=false
|
|
show.getChildByName("mask").getChildByName("func").active=false
|
|
show.getChildByName("mask").getChildByName("tal").active=false
|
|
show.getChildByName("mask").getChildByName("lv1").active=false
|
|
show.getChildByName("mask").getChildByName("lv2").active=false
|
|
show.getChildByName("mask").getChildByName("lv3").active=false
|
|
show.getChildByName("mask").getChildByName("lv4").active=false
|
|
show.getChildByName("mask").getChildByName("lv5").active=false
|
|
switch(this.c_type){
|
|
case cardType.HERO:
|
|
show.getChildByName("mask").getChildByName("hero").active=true
|
|
break
|
|
case cardType.SKILL:
|
|
show.getChildByName("mask").getChildByName("skill").active=true
|
|
break
|
|
case cardType.TALENT:
|
|
show.getChildByName("mask").getChildByName("tal").active=true
|
|
break
|
|
case cardType.EQUIP:
|
|
show.getChildByName("mask").getChildByName("equip").active=true
|
|
switch(EquipInfo[this.c_uuid].type){
|
|
case EquipType.ARMOR:
|
|
show.getChildByName("mask").getChildByName("abg").active=true
|
|
break
|
|
case EquipType.WEAPON:
|
|
show.getChildByName("mask").getChildByName("wbg").active=true
|
|
break
|
|
case EquipType.ACCESSORY:
|
|
console.log("[cardcomp]:装备卡 饰品")
|
|
break
|
|
}
|
|
|
|
break
|
|
case cardType.SPECIAL:
|
|
show.getChildByName("mask").getChildByName("func").active=true
|
|
break
|
|
}
|
|
show.getChildByName("q2").active=q==QualitySet.GREEN
|
|
show.getChildByName("q3").active=q==QualitySet.BLUE
|
|
show.getChildByName("q4").active=q==QualitySet.PURPLE
|
|
show.getChildByName("q5").active=q==QualitySet.ORANGE
|
|
show.getChildByName("fq2").active=q==QualitySet.GREEN
|
|
show.getChildByName("fq3").active=q==QualitySet.BLUE
|
|
show.getChildByName("fq4").active=q==QualitySet.PURPLE
|
|
show.getChildByName("fq5").active=q==QualitySet.ORANGE
|
|
// this.node.getChildByName("show").getChildByName("coins").active=false
|
|
// this.node.getChildByName("show").getChildByName("coins").getChildByName("num").getComponent(Label).string=this.get_cost_gold(q).toString()
|
|
}
|
|
|
|
get_cost_gold(quality:number){
|
|
switch(quality){
|
|
case QualitySet.GREEN:
|
|
return FightSet.GREEN_GOLD
|
|
|
|
case QualitySet.BLUE:
|
|
return FightSet.BLUE_GOLD
|
|
|
|
case QualitySet.PURPLE:
|
|
return FightSet.PURPLE_GOLD
|
|
|
|
case QualitySet.ORANGE:
|
|
return FightSet.ORANGE_GOLD
|
|
default:
|
|
return 0
|
|
}
|
|
}
|
|
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 "获取"
|
|
}
|
|
reset_card(){
|
|
this.cost_gold=0
|
|
this.c_type=0
|
|
this.c_uuid=0
|
|
this.is_used=false
|
|
}
|
|
use_card(){
|
|
switch(this.c_type){
|
|
case cardType.HERO:
|
|
oops.message.dispatchEvent(GameEvent.UseHeroCard,{uuid:this.c_uuid})
|
|
oops.message.dispatchEvent(GameEvent.CardsClose)
|
|
break
|
|
case cardType.SKILL:
|
|
console.log("[cardcomp]:use_card 技能卡")
|
|
oops.message.dispatchEvent(GameEvent.UseSkillCard,{uuid:this.c_uuid,slot:this.skill_slot})
|
|
oops.message.dispatchEvent(GameEvent.CardsClose)
|
|
this.skill_slot="skill1"
|
|
break
|
|
case cardType.EQUIP:
|
|
console.log("[cardcomp]:use_card 装备卡")
|
|
// if(!this.cost_gold_check()) return
|
|
oops.message.dispatchEvent(GameEvent.EquipAdd,{uuid:this.c_uuid,type:EquipInfo[this.c_uuid].type,slot:this.equip_slot})
|
|
oops.message.dispatchEvent(GameEvent.CardsClose)
|
|
break
|
|
case cardType.SPECIAL:
|
|
console.log("[cardcomp]:use_card 功能卡")
|
|
// if(!this.cost_gold_check()) return
|
|
oops.message.dispatchEvent(GameEvent.UseSpecialCard,{uuid:this.c_uuid})
|
|
oops.message.dispatchEvent(GameEvent.CardsClose)
|
|
break
|
|
case cardType.ENHANCEMENT:
|
|
console.log("[cardcomp]:use_card 强化卡",this.enhancement_data,smc.enhancements)
|
|
oops.message.dispatchEvent(GameEvent.UseEnhancement,this.enhancement_data)
|
|
smc.enhancements[this.enhancement_data.type]=this.enhancement_data.lv
|
|
console.log("[cardcomp]:use_card 强化卡",this.enhancement_data,smc.enhancements)
|
|
oops.message.dispatchEvent(GameEvent.CardsClose)
|
|
break
|
|
case cardType.TALENT:
|
|
console.log("[cardcomp]:use_card 天赋卡",this.c_uuid)
|
|
oops.message.dispatchEvent(GameEvent.UseTalentCard,{uuid:this.c_uuid,slot:this.talent_slot})
|
|
oops.message.dispatchEvent(GameEvent.CardsClose)
|
|
break
|
|
}
|
|
this.reset_card()
|
|
}
|
|
cost_gold_check(){
|
|
if(smc.vmdata.data.gold< this.cost_gold){
|
|
oops.gui.toast("[cardcomp]:金币不足", false);
|
|
return false
|
|
}
|
|
smc.vmdata.data.gold-=this.cost_gold
|
|
return true
|
|
}
|
|
reset() {
|
|
this.node.destroy();
|
|
}
|
|
} |