"use strict"; cc._RF.push(module, '2e238t/F+1BiJznrnoidayU', 'cmp.act.elite.wnd'); // Scripts/mod/acts/elite/cmps/cmp.act.elite.wnd.js "use strict"; /****************************************************************** * Copyright(C) 2019 - 2020 Nx Studio * * 精英召唤主界面 * * 2018.05.18 ******************************************************************/ var ActPage = require("act.page.base"); var SummonDefine = require("summon.define"); var EliteMod = require("act.elite.mod"); var HeroController = require("hero_controller"); var RoleController = require("role_controller"); var BackPackController = require("backpack_controller"); var BridgeItemBinder = require("bridge.binder.item.icon.count"); var MALL = require("mall_controller"); var MallConst = require("mall_const"); var FID = require("bridge.function.ids"); var NxSpine = require("nx.fx.spine"); var SCRT = SummonDefine.Status; cc.Class({ "extends": ActPage, properties: { nodOps: { "default": null, type: cc.Node }, spRole: { "default": null, type: NxSpine }, spMini: { "default": null, type: NxSpine }, nodInfo: { "default": null, type: cc.Node }, nodTarget: { "default": null, type: cc.Node }, nodDate: { "default": null, type: cc.Node }, nodCoin: { "default": null, type: BridgeItemBinder }, nodGTimes: { "default": null, type: cc.Node } }, // 初始化 build: function build(_data) { this._super(_data); var model = EliteMod.getInstance(); if (!model) { nx.tbox("尚未开启"); return; } // 视图监听 model.vbind(this, [["eliteBase", this.onFreshBase.bind(this)], ["eliteTimes", this.onFreshTimes.bind(this)]]); this.setEmpty(); model.fetchData(); }, // 关闭 onDestroy: function onDestroy() { // 视图监听 var model = EliteMod.getInstance(); if (model) { model.vunbind(this); } this.setFreeCD(); }, // 置空 setEmpty: function setEmpty() { this.costId = 0; this.setFreeCD(); nx.gui.setActive(this, "right/panel/select", false); nx.gui.setActive(this, "right/panel/open", false); }, // 基本信息 onFreshBase: function onFreshBase(_info, _old, _init) { var _this = this; var model = EliteMod.getInstance(); if (!model || _init || nx.dt.objEmpty(_info)) { return; } // 首选 if (!nx.dt.numPositive(_info.lucky_bid, false)) { nx.gui.setActive(this, "right/panel/open", false); nx.gui.setActive(this, "right/panel/select", true); return; } nx.gui.setActive(this, "right/panel/select", false); nx.gui.setActive(this, "right/panel/open", true); // 英雄信息 var DATA = game.configs.recruit_holiday_lucky_data; var camp = DATA.data_action[_info.camp_id]; var info = DATA.data_summon[camp.group_id]; // 货币更新 var tid = 0; if (nx.dt.arrNEmpty(info.loss_item_once) && nx.dt.arrNEmpty(info.loss_item_once[0])) { tid = info.loss_item_once[0][0]; } // 货币图标设置 var tinfo = gitemdata(tid); if (nx.dt.objEmpty(tinfo)) { nx.error("无效召唤货币:", tid); } else { this.costId = tid; this.nodCoin.active = true; this.nodCoin.setID(tid, function () { _this.onFreshTimes(); }); } var bid = _info.lucky_bid; var dat = game.configs.partner_data.data_partner_base[bid]; var star = dat.init_star || (dat ? dat.star : 0); var scfgs = gdata("partner_data", "data_partner_star", bid + "_" + 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); // 角色动画 var act = "action1"; var WISH = DATA.data_wish[_info.camp_id]; if (WISH) { for (var id in WISH) { if (id == bid) { act = WISH[id].action; break; } } } path = PathTool.getSpinePath(scfgs.res_id, "show", false); this.spRole.load(path, function (_e) { if (!_e) { _this.spRole.action(act, true); } else { _this.spRole.stop(); } }); // MINI动画 path = PathTool.getSpinePath(scfgs.res_id, scfgs.res_id, false); this.spMini.load(path, function (_e) { if (!_e) { _this.spMini.action("stand2", true); } else { _this.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]); } } // 目标英雄 var icon = nx.gui.getComponent(this.nodTarget, "icon", "cmp.item.base"); icon.setData(_info.lucky_bid); // 免费 var tip = nx.gui.getComponent(this.nodOps, "once/tip", "nx.vb.visible"); if (tip) { var key = model.getTipKey("free"); tip.setTarget(nx.mTip, key); } }, // 次数信息 onFreshTimes: function onFreshTimes(_cur, _old, _init) { if (_init) return; var model = EliteMod.getInstance(); var base = model ? model.vget("eliteBase") : null; var times = model ? model.vget("eliteTimes") : null; if (nx.dt.objEmpty(base) || nx.dt.objEmpty(times)) { return; } var DATA = game.configs.recruit_holiday_lucky_data; var camp = DATA.data_action[base.camp_id]; var cfgs = DATA.data_summon[camp.group_id]; var BC = BackPackController.getInstance(); var BM = BC.getModel(); // 更新当前货币 // 消耗修正 var count = this.updateCoin(); var autoOp = function autoOp(_node, _times, _freeDt, _item, _exchange, _exchangeInfo) { var ret = { enough: false, type: SCRT.Item, time: _freeDt, item: _item[0] || [], exc: _exchange[0] || [], excInfo: _exchangeInfo[0] || [] }; // 所需道具不足 && 但是有替代品 var bid = ret.item[0]; var need = ret.item[1]; if (count < need && nx.dt.arrNEmpty(ret.exc) && times.gold_time >= _times) { bid = ret.exc[0]; need = ret.exc[1]; var cnt = BM.getBackPackItemNumByBid(bid); ret.enough = cnt >= need; ret.type = SCRT.Diamond; } else { ret.enough = count >= need; } // 参数补充 ret.bid = bid; ret.need = need; // 免费 if (_freeDt == 0) { ret.enough = true; ret.type = SCRT.Free; nx.gui.setActive(_node, "need/list", false); nx.gui.setActive(_node, "need/free", true); nx.gui.setActive(_node, "freeCD", false); return ret; } nx.gui.setActive(_node, "need/list", true); nx.gui.setActive(_node, "need/free", false); // 货币刷新 var tinfo = gitemdata(bid); nx.bridge.setIcon(_node, "need/list/icon", tinfo.icon); nx.gui.setString(_node, "need/list/num", need); // 免费倒计时 nx.gui.setActive(_node, "freeCD", _freeDt > 0); return ret; }; this.nodOps.active = true; var once = nx.gui.find(this.nodOps, "once"); var ten = nx.gui.find(this.nodOps, "ten"); var dtFree = times.free_time; this.onceArgs = autoOp(once, 1, dtFree, cfgs.loss_item_once, cfgs.loss_gold_once, cfgs.gain_once); this.tenArgs = autoOp(ten, 10, -1, cfgs.loss_item_ten, cfgs.loss_gold_ten, cfgs.gain_ten); // 免费倒计时 this.setFreeCD(dtFree); // 活动日期 var secs = base.end_time - client.socket.getTime(); if (!nx.dt.numPositive(secs, false)) { nx.gui.setActive(this.nodDate, "txt", false); nx.gui.setActive(this.nodDate, "done", true); } else { nx.gui.setActive(this.nodDate, "txt", true); nx.gui.setActive(this.nodDate, "done", false); nx.gui.setCdTxt(this.nodDate, "txt", secs); } // 保底次数 var txt = nx.text.format("EliteReleaseTimes", times.must_count); nx.gui.setString(this.nodTarget, "times/txt", txt); // 免费次数 var total = DATA.data_const.diamond_times.val || 20; nx.gui.setString(this.nodGTimes, "times", times.gold_time + "/" + total); }, // 更新当前货币 updateCoin: function updateCoin() { var BC = BackPackController.getInstance(); var count = BC.getModel().getBackPackItemNumByBid(this.costId); return count; }, // 免费倒计时 setFreeCD: function setFreeCD(_dtFree) { this.unscheduleAllCallbacks(); if (!nx.dt.numPositive(_dtFree, false)) { return; } var self = this; var node = nx.gui.find(this.nodOps, "once/freeCD"); var tick = function tick() { var interval = Utils.getTimeInterval(_dtFree); if (interval <= 0) { self.unscheduleAllCallbacks(); nx.gui.setString(node, "", ""); return; } var time = Utils.changeIntevalToDate(interval); var txt = time.H + ":" + time.M + ":" + time.S; nx.gui.setString(node, "", nx.text.format("FreeCD", txt)); }; this.schedule(tick, 1, cc.macro.REPEAT_FOREVER); tick(); }, // 点击单次召唤 onTouchOnce: function onTouchOnce(_ret) { // 关闭召唤动画界面 if (_ret == false) { nx.bridge.summonAnimation.doStop(); return; } this.onceArgs.txt = "SummonOnce"; this.onceArgs.cb = this.onTouchOnce.bind(this); this.doSummon(1, this.onceArgs); }, // 点击十次召唤 onTouchTen: function onTouchTen(_ret) { // 关闭召唤动画界面 if (_ret == false) { nx.bridge.summonAnimation.doStop(); return; } this.tenArgs.txt = "SummonTen"; this.tenArgs.cb = this.onTouchTen.bind(this); this.doSummon(10, this.tenArgs); }, // 召唤请求 doSummon: function doSummon(_times, _args) { // 容量检查 if (!this.checkVolume(_times)) { nx.tbox("PartnerBagFull"); nx.bridge.jumper.jump2Window(FID.Recycle); return; } // 不够召唤处理 if (!_args.enough) { // 道具不足 if (_args.type == SCRT.Item) { nx.tbox("SummonItemNotEnough"); return; } // 替代不足 if (_args.type == SCRT.Diamond) { var good_res_path = "3"; var need_num = _args.exc[1]; var hvae_num = RoleController.getInstance().getRoleVo().gold; // let val_str = Utils.getItemConfig( _args.excInfo[ 0 ] ).name // let val_num = _args.excInfo[ 1 ]; // let call_num = _times; if (hvae_num < need_num) { var self = this; var str = nx.text.format("elfin_hatch_unlock_6", nx.text.getKey("Dia")); str, ['cancel', 'GotoCharge'], function (_key, _box) { _box.close(); if (_key == "GotoCharge") { // this.reqSummon( _args.type, _times, _args ); // nx.bridge.jumper.jump2Window( FID.Charge ); self.onTouchGift(); } }; return; } this.reqSummon(_args.type, _times, _args); // let buy_ori = nx.text.format( "tip_diamondConsume", String( good_res_path ), need_num, hvae_num ); // // let get_ori = nx.text.format( "tip_buyDesc", val_num, val_str, call_num ); // // let des_str = buy_ori + get_ori; // nx.mbox( buy_ori, [ 'cancel', 'confirm' ], ( _key, _box ) => { // _box.close(); // if( _key == "confirm" ) { // this.reqSummon( _args.type, _times, _args ); // } // } ); } return; } // 召唤 this.reqSummon(_args.type, _times, _args); }, // 召唤 reqSummon: function reqSummon(_type, _times, _args) { var self = this; var SC = EliteMod.getInstance(); SC.reqSummon(_times, _type, function (_ret, _data) { // 失败 if (!_ret) { nx.tbox(_data); return; } // 判空 if (nx.dt.arrEmpty(_data.partner_bids)) { nx.warn("$Summon:空召唤跳过!"); return; } // 动画 nx.bridge.summonAnimation.doStart(); nx.bridge.summonAnimation.setResult(_data, _args, function () {}); }); }, // 背包容量检查 checkVolume: function checkVolume(_count) { var HC = HeroController.getInstance(); var HM = HC.getModel(); // 背包容量判断 var bagInfo = HM.getHeroMaxCount(); var remains = bagInfo.max_count - bagInfo.have_coutn; return _count <= remains; }, // 点击切换心愿目标 onTouchChangeTarget: function onTouchChangeTarget(_key) { var model = EliteMod.getInstance(); var base = model ? model.vget("eliteBase") : null; if (nx.dt.objEmpty(base)) { return; } var args = { cur: base.lucky_bid, camp_id: base.camp_id }; // 选择回调 args.cb = function (_bid) { model.reqTarget(_bid); }; nx.bridge.createPanel("WndActEliteSelector", args); }, // 点击说明 onTouchRule: function onTouchRule() { // 召唤配置 var DATA = game.configs.recruit_holiday_lucky_data; var camp = DATA.data_desc["1"]; var params = { desc: camp.desc, rates: [] }; var pros = DATA.data_probability["10001"]; for (var i in pros) { var t = pros[i]; params.rates.push([t.name, t.probability]); } nx.bridge.createPanel("WndSummonRateShow", params); }, // 积分商城 onTouchScoreShop: function onTouchScoreShop() { MALL.getInstance().openMallPanel(true, [MallConst.MallType.SummonShop, 55]); }, // 点击助力奖励 onTouchGift: function onTouchGift() { var campId = this.data ? this.data.camp_id : 0; var DATA = game.configs.recruit_holiday_lucky_data; var info = DATA.data_action[campId]; if (info && this.actRoot && nx.dt.numPositive(info.jump, false)) { this.actRoot.jumpToMenu(info.jump); } } }); cc._RF.pop();