123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- const DrawApi = require("../net/DrawApi");
- const {GameNotificationKey, WechatShareType} = require('../utils/GameEnum');
- const GameModule = require("../utils/GameModule");
- const DWTool = require("../utils/DWTool");
- var Promise = require('../lib/es6-promise').Promise;
- const lottery = require('../data/lottery');
- const TapTapTool = require("../utils/TapTapTool");
- const WeChat = require('../net/WeChat');
- cc.Class({
- extends: cc.Component,
- properties: {
- starNameLabel: cc.Label,
- bottomTitleLabel: cc.Label,
- starNode: cc.Node,
- againButton: cc.Button,
- againRichText: cc.RichText,
- againSprite: cc.Sprite,
- /// 副标题 label
- subTitleLabel: cc.Label,
- /// 炫耀的按钮
- subButton: cc.Button,
- },
- // LIFE-CYCLE CALLBACKS:
- onLoad () {
- this._localDrawStarDatas = lottery;
- },
- start () {
- },
- init(drawData, typeId) {
- this.typeId = typeId;
- this.drawData = drawData;
- let drawSuccessData = drawData.drawSuccessData;
- let nameString = '获得';
- let desc = '';
- let starId = -1;
- this.subTitleLabel.string = '现在不需要';
- /// 抽奖获得金币数
- if (drawSuccessData.type == 1) {
- let rate = TapTapTool.multiple(GameModule.skill.multiple, GameModule.userInfo.perpetualMt);
- rate = TapTapTool.multiple(rate, {'n': GameModule.shop.multiple, 'e': 0});
- let add = TapTapTool.multiple(rate, GameModule.userInfo.rateGold);
- add = TapTapTool.multiple(add, drawSuccessData.opt);
- GameModule.userInfo.gold = TapTapTool.add(GameModule.userInfo.gold, add);
- nameString += `金币 ${TapTapTool.parseToString(add)}`;
- ///抽奖获得金币 强制上报一次
- if (GameModule.userInfo) {
- GameModule.userInfo.doReport();
- }
- /// 如果是抽到了钻石
- } else if (drawSuccessData.type == 2) {
- GameModule.userInfo.diamond += drawSuccessData.opt;
- nameString += `钻石 ${drawSuccessData.opt}`;
- /// 如果是红包
- } else if (drawSuccessData.type == 4) {
- GameGlobal.userData.hb += drawSuccessData.hb;
- nameString += ` ${(drawSuccessData.hb / 100).toFixed(2)}元`;
- desc += '红包满十元可提现噢~';
- /// 如果抽中的是明星
- } else if (drawSuccessData.type == 3) {
- let starData = lottery.filter((n) => {
- return n.propId == drawSuccessData.starId;
- })[0];
- this.subTitleLabel.string = '炫耀';
- nameString = '获得 ' + starData.propName;
- desc = starData.propName + '加入你的明星图集';
- GameModule.userInfo.perpetualClickMt = TapTapTool.multiple(GameModule.userInfo.perpetualClickMt, {'n': starData.mt, 'e': 0});
- GameModule.userInfo.perpetualMt = TapTapTool.multiple(GameModule.userInfo.perpetualMt, {'n': starData.mt, 'e': 0});
- GameEvent.fire(GameNotificationKey.StarEnterRoom, starData.propId, drawSuccessData.roomId);
- starId = starData.propId;
- let imageId = 50000 + starId;
- let mul = parseInt(starData.mt * 100);
- let desc = `<color=#fe4e00>明星奖励</c><br/><br/><img src='skill_click_coin'/><color=#540904>每次点击产出金币提升${mul}%</c><br/><img src='userInfo_rate_coin'/><color=#540904>所有房间产出金币提升${mul}%</c>`;
- DWTool.loadResPrefab("./prefabs/common/commonAlert")
- .then((result) => {
- let alert = cc.instantiate(result);
- cc.find('Canvas').addChild(alert);
- alert.getComponent('commAlert').initBuyStar(imageId, desc, `${starData.propName}`);
- });
- }
- this.starNameLabel.string = nameString;
- this.bottomTitleLabel.string = desc;
- let backGroudId = 700000 + drawSuccessData.type;
-
- this.starNode.getComponent("DrawStarContent").init(backGroudId, starId);
-
- if (this.typeId == 1) {
- this._diamond = this.drawData.diamond1;
- } else if (this.typeId == 2) {
- this._diamond = this.drawData.diamond2;
- } else {
- this._diamond = this.drawData.diamond3;
- }
- this.againRichText.string = `<img src='skill_diamond'/><b><color=#ffffff> ${this._diamond}</c></b>`;
- if (GameModule.userInfo.diamond < this._diamond) {
- this.setUpUseBtnBg(false);
- }
- },
- // init(drawData, typeId, backGroudId) {
- // this.typeId = typeId;
- // this.drawData = drawData;
- // this.starNameLabel.string = '获得 ' + drawData.propName;
- // this.bottomTitleLabel.string = drawData.propName + '加入你的明星图集';
- // this.starNode.getComponent("DrawStarContent").init(backGroudId, drawData.propId);
-
- // if (this.typeId == 1) {
- // this._diamond = this.drawData.diamond1;
- // } else if (this.typeId == 2) {
- // this._diamond = this.drawData.diamond2;
- // } else {
- // this._diamond = this.drawData.diamond3;
- // }
- // this.againRichText.string = `<img src='skill_diamond'/><b><color=#ffffff> ${this._diamond}</c></b>`;
- // ////发通知 已经获取明星
- // GameEvent.fire(GameNotificationKey.StarEnterRoom, this.drawData.propId, this.drawData.roomId);
- // console.log(`抽奖获得明星 starid${this.drawData.propId} roomid${this.drawData.roomId}`);
- // if (GameModule.userInfo.diamond < this._diamond) {
- // this.setUpUseBtnBg(false);
- // }
- // },
- /// 设置签约的button是否能点击 type 123
- setUpUseBtnBg(isActive) {
- let path = isActive ? './textures/draw/draw_green_btn_bg' : './textures/draw/draw_gray_btn_bg';
- this.againButton.interactable = isActive;
- DWTool.loadResSpriteFrame(path)
- .then((spriteFrame) => {
- this.againSprite.spriteFrame = spriteFrame;
- });
- },
-
- dismissAction () {
- GameModule.audioMng.playClickButton();
- if (this.drawData.drawSuccessData.type === 3) {
- GameEvent.on(GameNotificationKey.ShowShareAction, this, (type, isOk) => {
- if (type != WechatShareType.drawShare) { return; }
- if (isOk) {
- this.node.destroy();
- GameEvent.fire("draw_done_action");
- } else {
- this.subButton.interactable = true;
- }
- GameEvent.off(GameNotificationKey.ShowShareAction, this);
- });
- this.subButton.interactable = false;
- WeChat.shareAction(WechatShareType.drawShare, () => {
- }, () => {
- this.subButton.interactable = true;
- console.log('分享失败或取消');
- });
- } else {
- this.node.destroy();
- GameEvent.fire("draw_done_action");
- }
- },
- closeAction() {
- this.node.destroy();
- GameEvent.fire("draw_done_action");
- },
- scrollAgainAction() {
- GameModule.audioMng.playClickButton();
- this.againButton.interactable = false;
- this.startDrawRequest(this.typeId).then((respondData) => {
- this.againButton.interactable = true;
- GameModule.userInfo.diamond -= this._diamond;
- this.node.destroy();
- GameEvent.fire("draw_again", respondData);
- }).catch(({code, msg}) => {
- this.againButton.interactable = true;
- cc.log(code, msg);
- });
-
- },
- startDrawRequest(typeId) {
- return new Promise((resolve, reject) => {
- ///开始抽奖
- DrawApi.startNewLottery(typeId, 1, (respondData) => {
- resolve(respondData);
- }, (code, msg) => {
- reject({code, msg});
- });
- })
- },
- // update (dt) {},
- });
|