"use strict"; cc._RF.push(module, 'fa797x+fo9Jzp35upgY47ee', 'cmp.act.limit.pray2'); // Scripts/mod/acts/limitPray/cmp/cmp.act.limit.pray2.js "use strict"; /****************************************************************** * * 限定招募 * ******************************************************************/ var ActPage = require("act.page.base"); var NxSpine = require("nx.fx.spine"); var ItemLayout = require("cmp.item.layout"); var BridgeItemBinder = require("bridge.binder.item.icon.count"); var TipsController = require("tips_controller"); var FID = require("bridge.function.ids"); cc.Class({ "extends": ActPage, properties: { spRole: { "default": null, type: NxSpine }, spMini: { "default": null, type: NxSpine }, nodInfo: { "default": null, type: cc.Node }, nodDate: { "default": null, type: cc.Node }, tipTimes: { "default": null, type: cc.Node }, nodCoin: { "default": null, type: BridgeItemBinder }, nodScore: { "default": null, type: BridgeItemBinder }, nodAvatars: { "default": null, type: cc.Node }, nodOps: { "default": null, type: cc.Node }, nodReward: { "default": null, type: cc.Node }, nodTotal: { "default": null, type: cc.Node }, tipCover: { "default": null, type: cc.Node }, tipReward: { "default": null, type: ItemLayout } }, // 初始化 build: function build(_data) { this._super(_data); // 置空 if (!this.mod || nx.dt.objEmpty(this.data)) { this.setEmpty(); return; } // 配置查询 this.configs = this.mod.queryConfigs(); if (!this.configs) { this.setEmpty(); return; } // 活动监听 this.mod.vbind(this, [["LimitPrayFreshed2", this.onFreshData.bind(this)]]); // 基本信息 this.freshBasic(); }, // 显示 onEnable: function onEnable() { this.tipCover.active = false; this.tipTimes.active = false; // 刷新 if (this.mod) { this.mod.reqBaseData(); } }, // 销毁 onDestroy: function onDestroy() { // 活动监听解除 if (this.mod) { this.mod.vunbind(this); } this._super(); }, // 置空 setEmpty: function setEmpty() { nx.gui.setActive(this, "right", false); }, // 基本信息 freshBasic: function freshBasic() { var _this = this; // 置空 if (!this.mod || !this.configs || nx.dt.objEmpty(this.data)) { this.setEmpty(); return; } // 背景刷新 var bg = cc.path.join("resDB/bigs", this.configs.bg || "bg005"); nx.gui.setSpriteFrame(this, "bg", bg); nx.gui.setActive(this, "right", true); // 标签刷新 var tags = cc.path.join("locals/{lang}/images/prayer", this.configs.effect); nx.gui.setSpriteFrame(this.nodInfo, "desc", nx.res.fmtPath(tags)); // 道具绑定 this.nodCoin.setID(this.configs.prop_id, function () { _this.freshOps(); }); // 积分绑定 this.nodScore.setID(this.configs.point_id); // 角色信息刷新 this.freshPartner(this.configs.partner_id); // 配角信息刷新 this.freshOthers(this.configs.other_partner_id); // 红点绑定 var tip1 = nx.gui.getComponent(this.nodOps, "once/tip", "nx.vb.visible"); if (tip1) { tip1.setTarget(nx.mTip, this.mod.getTipKey("once")); } var tip2 = nx.gui.getComponent(this.nodOps, "ten/tip", "nx.vb.visible"); if (tip2) { tip2.setTarget(nx.mTip, this.mod.getTipKey("ten")); } // 自选提示 var txt = nx.text.format("自选提示", this.configs.min_num); nx.gui.setString(this.nodTotal, "txt", txt); // 剩余时间 var secs = this.mod.data.end_time - client.socket.getTime(); this.freshDate(secs); }, // 刷新角色 freshPartner: function freshPartner(_bid) { var _this2 = this; var dat = game.configs.partner_data.data_partner_base[_bid]; var scfgs = gdata("partner_data", "data_partner_star", _bid + "_" + dat.init_star); if (nx.dt.objEmpty(scfgs)) { nx.error("刷新角色失败,无效伙伴:", _bid); return; } // 名字 nx.gui.setString(this.nodInfo, "base/name", nx.text.getKey(dat.name)); // 品质 var path = cc.path.join("coms/images", "mk_partner_qa" + dat.quality); nx.gui.setSpriteFrame(this.nodInfo, "qa", path); // 阵营 path = cc.path.join("prefab/partner/ui/camp" + dat.camp_type); nx.gui.setSpriteFrame(this.nodInfo, "base/camp", path); // 星级 path = cc.path.join("coms/images/star" + dat.init_star); nx.gui.setSpriteFrame(this.nodInfo, "stars", path); // 角色动画 path = PathTool.getSpinePath(scfgs.res_id, "show", false); this.spRole.load(path, function (_e) { if (!_e) { _this2.spRole.action("action1", true); } else { _this2.spRole.stop(); } }); // MINI动画 path = PathTool.getSpinePath(scfgs.res_id, scfgs.res_id, false); this.spMini.load(path, function (_e) { if (!_e) { _this2.spMini.action("stand2", true); } else { _this2.spMini.stop(); } }); // 技能 var sknode = nx.gui.find(this.nodInfo, "skills"); for (var i = 0; i < sknode.children.length; ++i) { // 技能数组[0]为普攻,直接忽略,最多4个技能 var item = sknode.children[i]; var sifo = scfgs.skills[i + 1]; if (!sifo) { item.active = false; continue; } item.active = true; var cmp = nx.gui.getComponent(item, "", "cmp.skill.base"); if (cmp) { cmp.setData(sifo[1]); } } }, // 配角信息刷新 freshOthers: function freshOthers(_ids) { var ids = _ids || []; for (var i = 0; i < this.nodAvatars.children.length; ++i) { var node = this.nodAvatars.children[i]; var id = ids[i] || 0; if (id == 0) { node.active = false; continue; } var dat = game.configs.partner_data.data_partner_base[id]; if (nx.dt.objEmpty(dat)) { nx.error("刷新角色失败,无效伙伴:", id); node.active = false; continue; } node.pdata = dat; node.active = true; nx.bridge.setAvatarByFaceId(node, "mask/img", dat.item_id); } }, // 刷新活动日期 freshDate: function freshDate(_secs) { var time = nx.bridge.time.toNeedSeconds(_secs); nx.gui.setString(this.nodDate, "txt", time); }, // 信息刷新 onFreshData: function onFreshData() { // 累计 var times = this.mod.vget("LimitPrayTimes2"); nx.gui.setString(this.nodTotal, "num", times); // 自选剩余 if (times >= this.configs.max_num) { this.tipTimes.active = false; } else { this.tipTimes.active = true; var loop = this.configs.min_num || 40; var remains = loop - times % loop; var txt = nx.text.format("伙伴自选", remains); nx.gui.setString(this.tipTimes, "txt", txt); } // 一轮结束的特殊判断 var prog = Math.floor(times % this.configs.min_num) / this.configs.min_num; if (times > 0 && times % this.configs.min_num == 0) { if (this.mod.canReward()) { times -= 1; prog = 1; } } // 特殊:次数超过一轮并且有奖品 if (times >= this.configs.min_num && this.mod.canReward()) { prog = 1; } // 奖励统计 var items = this.mod.vget("LimitPrayRewards2"); var limit1 = Math.floor(this.configs.max_num / this.configs.min_num) - 1; var limit2 = Math.floor(Math.max(0, times) / this.configs.min_num); var limit = Math.min(limit1, limit2); var range = [limit * this.configs.min_num, (limit + 1) * this.configs.min_num]; // let arr = []; // items.forEach( _t => { // if( _t.id > range[0] && _t.id <= range[1] ) { // arr.push( _t ); // } // } ); // arr.sort( ( _a, _b ) => { // return _a.id - _b.id; // } ); items.sort(function (_a, _b) { return _a.id - _b.id; }); this.freshRewards(Math.min(1, prog), items); }, // 刷新奖励 freshRewards: function freshRewards(_progress, _list) { // 进度 var prog = nx.gui.getComponent(this.nodReward, "progress", cc.ProgressBar); if (prog) { prog.progress = _progress; } var rewards = _list || []; if (rewards.length != 5) { nx.error("\u9650\u65F6\u7948\u613F\u5956\u52B1\u6709\u8BEF\uFF1A" + rewards.length); return; } // 状态转动作 // status: 0-未完成,1-可领取,2-已领取 // action1 普通状态 // action2 可开启状态 // action3 开启过程,reword事件出获得道具 // action4 开完状态 var st2act = function st2act(_st) { switch (_st) { case 0: return 'action1'; case 1: return 'action2'; case 2: return 'action4'; default: return 'action1'; } }; // 单设 var self = this; var single = function single(_box, _time, _data) { // 次数 nx.gui.setString(_time, "num", _data.id); // 宝箱 var cfgs = self.mod.queryReward(_data.id); if (!cfgs) { return; } var act = st2act(_data.status); var res = PathTool.getSpinePath(cfgs.res_id, "action", false); var cmp = nx.gui.getComponent(_box, "", "nx.fx.spine"); cmp.play(res, act, null, true); _box.prayData = _data; nx.gui.setActive(_box, "tip", _data.status == 1); }; for (var i = 0; i < rewards.length; ++i) { single(nx.gui.find(this.nodReward, "boxes/b" + (i + 1)), nx.gui.find(this.nodReward, "times/t" + (i + 1)), rewards[i]); } }, // 变化信息 freshOps: function freshOps() { // 置空 if (!this.mod || !this.configs || nx.dt.objEmpty(this.data)) { return; } // 按钮设置 var autoOp = function autoOp(_node, _draw, _pt) { var tinfo = gitemdata(_draw[0]); if (tinfo) { nx.bridge.setIcon(_node, "btn/list/icon", tinfo.icon); nx.gui.setString(_node, "btn/list/num", _draw[1]); } var pinfo = gitemdata(_pt[0]); if (pinfo) { nx.bridge.setIcon(_node, "score/infos/icon", pinfo.icon); nx.gui.setString(_node, "score/infos/num", "x" + _pt[1]); } }; // 操作刷新 autoOp(nx.gui.find(this.nodOps, "once"), this.configs.draw_one[0], this.configs.one_point_num[0]); autoOp(nx.gui.find(this.nodOps, "ten"), this.configs.draw_ten[0], this.configs.ten_point_num[0]); }, // 点击单抽 onTouchOnce: function onTouchOnce() { var _this3 = this; if (!this.configs || !this.mod) { return; } this.mod.reqSummon(true, function (_ret, _msg, _code) { // 道具不足 if (!_ret && _code == 101) { nx.tbox(_msg); _this3.onTouchCoin(); } }); }, // 点击十抽 onTouchTen: function onTouchTen() { var _this4 = this; if (!this.configs || !this.mod) { return; } this.mod.reqSummon(false, function (_ret, _msg, _code) { // 道具不足 if (!_ret && _code == 101) { nx.tbox(_msg); _this4.onTouchCoin(); } }); }, // 点击规则 onTouchRule: function onTouchRule() { var rule = this.mod ? this.mod.queryRule() : ""; if (nx.dt.strNEmpty(rule)) { var TC = TipsController.getInstance(); TC.showTextPanel("tip", rule); } }, // 点击道具 onTouchCoin: function onTouchCoin() { if (this.actRoot && this.configs) { this.actRoot.jumpToMenu(this.configs.jump); } }, // 点击奖池 onTouchChi: function onTouchChi() { var data = this.configs.award; if (nx.dt.arrEmpty(data)) { return; } var args = { title: "奖池详情", group: [] }; var ids = []; for (var i = 0; i < data[0].length; ++i) { ids.push(data[0][i][0]); } args.group.push({ name: "限定奖池", partners: ids }); var ids2 = []; for (var _i = 0; _i < data[1].length; ++_i) { ids2.push(data[1][_i][0]); } args.group.push({ name: "基础奖池", partners: ids2 }); nx.bridge.createPanel("WndPartnerPool", args); }, // 点击兑换 onTouchShop: function onTouchShop() { nx.bridge.jumper.jump2Window(FID.PartnerPrayShops); }, // 点击头像 onTouchAvatar: function onTouchAvatar(_btn) { var pdata = _btn ? _btn.pdata : null; if (!pdata) { return; } var key = pdata.bid + "_" + pdata.init_star; var propsData = gdata("partner_data", "data_partner_show", key); propsData.star = pdata.init_star; propsData.break_lev = 0; TipsController.getInstance().showPartnerTips(propsData); }, // 点击宝箱 onTouchBox: function onTouchBox(_box) { var _this5 = this; var info = _box ? _box.prayData : null; if (!info) { return; } // 详情 if (info.status != 1) { var cfgs = this.mod.queryReward(info.id); if (cfgs && nx.dt.arrNEmpty(cfgs.rewards)) { this.tipCover.active = true; this.tipReward.rebuild(cfgs.rewards); var pos = _box.convertToWorldSpaceAR(cc.Vec2.ZERO); pos = this.tipCover.convertToNodeSpaceAR(pos); this.tipReward.node.y = pos.y; } return; } // 拆盒 // action3 开启过程,reword事件出获得道具 var cmp = nx.gui.getComponent(_box, "", "nx.fx.spine"); if (cmp) { cmp.action("action3", false, function (_event) { // 音效 if (_event == 'reword') { nx.audio.playSFX("audios/effects/del", false); } // 完成 if (_event == 'complete') { _this5.mod.reqReward(); } }); } }, // 点击提示覆盖层 onTouchTipCover: function onTouchTipCover() { this.tipCover.active = false; } }); cc._RF.pop();