import JiaZai from "../../Script/JiaZai"; import Utils from "../../Script/module/Pay/Utils"; import { MiniGameManager } from "../../Script/Sdk/MiniGameManager"; import { MiniGameSdk } from "../../Script/Sdk/MiniGameSdk"; const { ccclass, property } = cc._decorator; //排行榜 @ccclass export default class GachaManager extends cc.Component { @property(cc.Node) //用户头像换图 avatar: cc.Node = null; avatarData: any = null; own = 0; onLoad() { this.avatarData = []; this.own = 0; // this.init(); } //初始化数据 init(data) { this.avatarData = []; this.own = 0; console.log("222222初始化数据", data); if (data) { this.avatarData = data; this.own = this.avatarData.length; } for (let i = 0; i < this.avatarData.length; i++) { let iphone = this.avatarData[i] - 19; this.avatar.children[iphone].getChildByName("own").active = true; } let botoom = this.node.getChildByName("bottom"); botoom.getChildByName("no").active = false; botoom.getChildByName("yes").active = false; if (this.own >= 8) { botoom.getChildByName("total").active = false; botoom.getChildByName("finishi").active = true; } else { let cost = this.getCostFilm(); botoom.getChildByName("total").getComponent(cc.Label).string = cost.toString(); console.log("抽卡所需film", cost); if (cc.fx.GameConfig.GM_INFO.film >= cost) { botoom.getChildByName("yes").active = true; console.log("有足够film"); botoom.getChildByName("yes").getComponent(cc.Label).string = cc.fx.GameConfig.GM_INFO.film.toString(); } else { console.log("没有足够film"); botoom.getChildByName("no").active = true; botoom.getChildByName("no").getComponent(cc.Label).string = cc.fx.GameConfig.GM_INFO.film.toString(); } console.log("拥有film", cc.fx.GameConfig.GM_INFO.film); } } getCostFilm() { let film = [5, 10, 25, 35, 55, 70, 100, 120]; if (this.own > film.length) this.own = film.length - 1; let count = film[this.own]; return count; } closeGacha() { const jiazaiNode = cc.find("Canvas"); // 假设 JiaZai 挂在 Canvas 节点 const jiazaiComp = jiazaiNode.getComponent(JiaZai); if (jiazaiComp) { jiazaiComp.closeGacha(); } else { console.log("无法获取JiaZai组件"); } } playGacha() { if (this.own >= 8) { MiniGameSdk.API.showToast("已拥有当期所有头像"); return; } else { let cost = this.getCostFilm(); if (cc.fx.GameConfig.GM_INFO.film < cost) { MiniGameSdk.API.showToast("代币不足,闯关获取更多代币!"); return; } } this.openLoad(); Utils.getGacha‌(res => { console.log("抽卡结果", res); if (res.code == 1) { console.log("抽卡成功"); cc.fx.GameConfig.GM_INFO.film = res.data.film; console.log("所剩余代币", cc.fx.GameConfig.GM_INFO.film); let headArr = cc.fx.GameTool.getAvatarData(res.data.headArr); this.init(headArr); this.openReward(res.data.reward); } else if (res.code == 0) { MiniGameSdk.API.showToast(res.msg); } else { MiniGameSdk.API.showToast("网络异常,请稍后再试"); } this.closeLoad(); }); // let cost = this.getCostFilm(); // if (cc.fx.GameConfig.GM_INFO.film >= cost) { // } } openReward(data) { this.node.getChildByName("geReward").active = true; this.node.getChildByName("geReward").getChildByName("r").active = false; this.node.getChildByName("geReward").getChildByName("sr").active = false; this.node.getChildByName("geReward").getChildByName("ssr").active = false; let actionName = cc.fx.GameTool.getActionName(data.toString()); if (data < 24) { this.node.getChildByName("geReward").getChildByName("r").active = true; cc.fx.GameTool.loadSpineSimple(this.node.getChildByName("geReward").getChildByName("r").getChildByName("sp"), actionName); } else if (data == 24 || data == 25) { this.node.getChildByName("geReward").getChildByName("sr").active = true; cc.fx.GameTool.loadSpineSimple(this.node.getChildByName("geReward").getChildByName("sr").getChildByName("sp"), actionName); } else if (data == 26) { this.node.getChildByName("geReward").getChildByName("ssr").active = true; cc.fx.GameTool.loadSpineSimple(this.node.getChildByName("geReward").getChildByName("ssr").getChildByName("sp"), actionName); } } closeReward() { this.node.getChildByName("geReward").active = false; } openLoad() { this.node.getChildByName("Loading").active = true; this.node.getChildByName("Loading").getChildByName("load").stopAllActions(); this.node.getChildByName("Loading").getChildByName("load").runAction(cc.rotateTo(2, 1080).repeatForever()); } closeLoad() { this.node.getChildByName("Loading").active = false; } start() { } }