Files
heros/assets/script/game/map/CardsComp.ts
2025-08-21 14:33:42 +08:00

317 lines
12 KiB
TypeScript

import { _decorator, Label, tween, v3 } 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 { CardComp } from "./CardComp";
import { cardType, getRandomCardsByType } from "../common/config/CardSet";
import { smc } from "../common/SingletonModuleComp";
import { RandomManager } from "db://oops-framework/core/common/random/RandomManager";
import { EquipType } from "../common/config/Equips";
import { getSkills } from "../common/config/SkillSet";
import { getEnhancement } from "../common/config/LevelUp";
import { FightSet } from "../common/config/Mission";
import { oops } from "db://oops-framework/core/Oops";
import { getHeroList } from "../common/config/heroSet";
import { QualitySet } from "../common/config/BoxSet";
const { ccclass, property } = _decorator;
/** 视图层对象 */
@ccclass('CardsCompComp')
@ecs.register('CardsComp', false)
export class CardsCompComp extends CCComp {
card1:any=null
card2:any=null
card3:any=null
// card4:any=null
card1c:CardComp=null
card2c:CardComp=null
card3c:CardComp=null
// card4c:CardComp=null
more_btn:any=null
refresh_btn:any=null
cancel_btn:any=null
/** 卡牌展示队列 */
private cardQueue: Array<{type: GameEvent, data?: any}> = [];
/** 是否正在展示卡牌 */
private isShowing: boolean = false;
//**当前卡组 */
private now_card:any=null;
//**是否正在倒计时 */
private is_countdown:boolean=false;
//**倒计时时间 */
private countdown_time:number=10;
/** 视图层逻辑代码分离演示 */
onLoad() {
// var entity = this.ent as ecs.Entity; // ecs.Entity 可转为当前模块的具体实体对象
this.on(GameEvent.HeroSkillSelect, this.addToQueue, this);
this.on(GameEvent.HeroSelect, this.addToQueue, this);
this.on(GameEvent.CardRefresh, this.addToQueue, this);
this.on(GameEvent.FuncSelect, this.addToQueue, this);
this.on(GameEvent.MissionEnd, this.clear_cards, this);
this.on(GameEvent.HeroSkillSelectEnd, this.close_cards, this);
this.on(GameEvent.CardsClose, this.close_cards, this);
this.on(GameEvent.EquipSelect, this.addToQueue, this);
this.on(GameEvent.EnhancementSelect, this.addToQueue, this);
this.on(GameEvent.TalentSelect, this.addToQueue, this);
this.on(GameEvent.AD_BACK_TRUE,this.ad_back_true,this)
this.on(GameEvent.AD_BACK_FALSE,this.ad_back_false,this)
this.card1=this.node.getChildByName("cards").getChildByName("card1")
this.card2=this.node.getChildByName("cards").getChildByName("card2")
this.card3=this.node.getChildByName("cards").getChildByName("card3")
// this.card4=this.node.getChildByName("card4")
this.card1c=this.card1.getComponent(CardComp)
this.card2c=this.card2.getComponent(CardComp)
this.card3c=this.card3.getComponent(CardComp)
// this.card4c=this.card4.getComponent(CardComp)
this.more_btn=this.node.getChildByName("btns").getChildByName("more")
this.refresh_btn=this.node.getChildByName("btns").getChildByName("new")
this.cancel_btn=this.node.getChildByName("btns").getChildByName("cancel")
}
show_cards(e:GameEvent,data:any,is_refresh:boolean=false){
this.cancel_btn.active=false
switch(e){
case GameEvent.HeroSelect:
// console.log("[CardsComp]:显示英雄选择卡牌",data)
let title="选择英雄"
this.node.getChildByName("top").getChildByName("title").getChildByName("Label").getComponent(Label).string=title
this.hero_select(data)
break
case GameEvent.HeroSkillSelect:
// console.log("[CardsComp]:显示技能选择卡牌")
this.node.getChildByName("top").getChildByName("title").getChildByName("Label").getComponent(Label).string="选择技能"
this.hero_skill_select(data)
break
case GameEvent.FuncSelect:
// console.log("[CardsComp]:显示功能卡牌")
this.cancel_btn.active=true
this.node.getChildByName("top").getChildByName("title").getChildByName("Label").getComponent(Label).string="选择卡牌"
this.func_select()
break
case GameEvent.EquipSelect:
// console.log("[CardsComp]:显示装备选择卡牌")
this.cancel_btn.active=true
this.node.getChildByName("top").getChildByName("title").getChildByName("Label").getComponent(Label).string="选择装备"
this.equip_select(data)
break
case GameEvent.EnhancementSelect:
// console.log("[CardsComp]:显示强化选择卡牌")
this.cancel_btn.active=true
this.node.getChildByName("top").getChildByName("title").getChildByName("Label").getComponent(Label).string="选择强化"
this.enhancement_select()
break
case GameEvent.TalentSelect:
// console.log("[CardsComp]:显示天赋选择卡牌")
this.cancel_btn.active=true
this.node.getChildByName("top").getChildByName("title").getChildByName("Label").getComponent(Label).string="选择天赋"
this.talent_select(data)
break
}
if(!is_refresh) this.show()
}
talent_select(data:any){
let list=getRandomCardsByType(cardType.TALENT,3,QualitySet.GREEN)
// console.log("[CardsComp]:天赋选择卡牌列表",list)
this.card1c.talent_select(list[0],data)
this.card2c.talent_select(list[1],data)
this.card3c.talent_select(list[2],data)
}
enhancement_select(){
let list=getEnhancement(smc.enhancements,3)
// console.log("[CardsComp]:强化选择卡牌列表",smc.enhancements,list)
this.card1c.enhancement_select(list[0])
this.card2c.enhancement_select(list[1])
this.card3c.enhancement_select(list[2])
}
hero_select(data:any){
let list=getHeroList(data.called)
// console.log("[CardsComp]:英雄选择卡牌列表",list)
this.card1c.hero_select(list[0])
this.card2c.hero_select(list[1])
this.card3c.hero_select(list[2])
// this.card4c.hero_select(list[3])
}
hero_skill_select(data:any){
let list=[]
if(data.slot=="skill1"){
list =getRandomCardsByType(cardType.SKILL,3,QualitySet.GREEN)
}else if(data.slot=="skill2"){
list=getRandomCardsByType(cardType.SKILL,3,QualitySet.BLUE)
}else if(data.slot=="skill3"){
list=getRandomCardsByType(cardType.SKILL,3,QualitySet.PURPLE)
}
// console.log("[CardsComp]:技能选择卡牌列表",list)
this.card1c.hero_skill_select(list[0],data)
this.card2c.hero_skill_select(list[1],data)
this.card3c.hero_skill_select(list[2],data)
// this.card4c.hero_skill_select(list[3])
}
equip_select(data:any){
let list=[]
switch(data.slot){
case "weapon":
list=getRandomCardsByType(cardType.EQUIP,3,EquipType.WEAPON,data.lv)
break
case "armor":
list=getRandomCardsByType(cardType.EQUIP,3,EquipType.ARMOR,data.lv)
break
case "accessory":
list=getRandomCardsByType(cardType.EQUIP,3,EquipType.ACCESSORY,data.lv)
break
}
// console.log("[CardsComp]:装备选择卡牌列表",list)
this.card1c.equip_select(list[0],data)
this.card2c.equip_select(list[1],data)
this.card3c.equip_select(list[2],data)
// this.card4c.equip_select(list[3])
}
func_select(){
let list=getRandomCardsByType(cardType.SPECIAL,3)
// console.log("[CardsComp]:功能选择卡牌列表",list)
this.card1c.func_select(list[0])
this.card2c.func_select(list[1])
this.card3c.func_select(list[2])
// this.card4c.func_select(list[3])
}
random_select(){
this.card1c.random_select()
this.card2c.random_select()
this.card3c.random_select()
// this.card4c.random_select()
}
/** 添加卡牌展示到队列 */
private addToQueue(e: GameEvent, data?: any) {
// console.log("[CardsComp]:添加卡牌到队列", e,data);
this.cardQueue.push({type: e, data: data});
this.processQueue();
}
/** 处理卡牌队列 */
private processQueue() {
if (this.isShowing || this.cardQueue.length === 0) {
return;
}
const nextCard = this.cardQueue.shift();
this.isShowing = true;
this.now_card=nextCard
this.show_cards(nextCard.type, nextCard.data);
}
close_cards(e:GameEvent,data:any){
switch(e){
case GameEvent.HeroSelect:
// console.log("[CardsComp]:关闭英雄选择卡牌")
break
case GameEvent.HeroSkillSelect:
// console.log("[CardsComp]:关闭技能选择卡牌")
break
case GameEvent.CardRefresh:
// console.log("[CardsComp]:关闭随机刷新卡牌")
break
case GameEvent.CardsClose:
// console.log("[CardsComp]:关闭所有卡牌")
break
}
this.hide()
}
show(){
// 设置初始状态
smc.mission.pause=true
// this.node.getChildByName("btns").getChildByName("cancel").setPosition(v3(0, this.node.getChildByName("btns").getChildByName("cancel").getPosition().y, 0))
// this.node.getChildByName("top").setPosition(v3(0, this.node.getChildByName("top").getPosition().y, 0))
this.node.setPosition(v3(0, 0, 0));
this.node.setScale(v3(0, 0, 1));
// 使用缓动动画放大和移动
tween(this.node)
.parallel(
tween().to(0.3, { scale: v3(1, 1, 1) }, { easing: 'backOut' }),
tween().to(0.3, { position: v3(0, 640, 0) }, { easing: 'backOut' })
)
.start();
this.is_countdown=true
this.countdown_time=10
}
hide(){
smc.mission.pause=false
tween(this.node)
.parallel(
tween().to(0.3, { scale: v3(0, 0, 1) }, { easing: 'backIn' }),
tween().to(0.3, { position: v3(0, 0, 0) }, { easing: 'backIn' })
)
.call(()=>{
this.node.setPosition(v3(1500, 640, 0));
this.isShowing = false;
this.processQueue(); // 处理队列中的下一个卡牌
})
.start();
}
clear_cards(){
// console.log("[CardsComp]:清除卡牌队列")
this.cardQueue = [];
this.close_cards(GameEvent.CardsClose,null)
}
refresh_card(){
if(smc.vmdata.mission_data.refresh_count>0){
smc.vmdata.mission_data.refresh_count--
this.show_cards(this.now_card.type,this.now_card.data,true)
if(smc.vmdata.mission_data.refresh_count==0){
this.more_btn.active=true
this.refresh_btn.active=false
}
}else{
this.more_btn.active=true
this.refresh_btn.active=false
}
}
ad_callback(){
oops.message.dispatchEvent(GameEvent.DO_AD_BACK)
}
ad_back_true(){
this.more_btn.active=false
this.refresh_btn.active=true
}
ad_back_false(){
this.more_btn.active=true
this.refresh_btn.active=false
}
//检测广告是否成功观看
checkout_ad_back(){
return true
}
//放弃选择
give_up_select(){
this.hide()
// let mission_data=smc.vmdata.mission_data
// mission_data.gold+=(mission_data.back_gold+mission_data.buff_back_gold) //返还金币
}
update(dt: number) {
if(this.is_countdown){
this.countdown_time-=dt
if(this.countdown_time<=0){
this.is_countdown=false
}
}
}
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
reset() {
this.cardQueue = [];
this.isShowing = false;
this.node.destroy();
}
}