"use strict"; cc._RF.push(module, '10204VYbwtM+7+wKwoLfnbg', 'cmp.partner.reform.artifact'); // Scripts/mod/partner/cmps/reform/cmp/cmp.partner.reform.artifact.js "use strict"; /****************************************************************** * * 伙伴改造页: 芯片合成(符文合成) * ******************************************************************/ var BridgeComponent = require("bridge.component"); var HeroEvent = require("hero_event"); var HeroControl = require("hero_controller"); var TipsController = require("tips_controller"); var BackPackConst = require("backpack_const"); var BackpackController = require("backpack_controller"); var RoleController = require("role_controller"); var GoodsVo = require("goods_vo"); var BIT = BackPackConst.item_type; var BITT = BackPackConst.item_sub_type; var CompoundLimit = [2, 5]; cc.Class({ "extends": BridgeComponent, properties: { nodSlots: { "default": [], type: cc.Node }, nodTarget: { "default": null, type: cc.Node }, nodRate: { "default": null, type: cc.Node }, nodLevel: { "default": null, type: cc.Node }, nodReward: { "default": null, type: cc.Node }, nodPutIn: { "default": null, type: cc.Node }, nodCompound: { "default": null, type: cc.Node } }, // 载入 onLoad: function onLoad() { this._super(); // 事件监听 this.bindGEvent(HeroEvent.Artifact_Lucky_Event, this.onLuckyFresh.bind(this)); this.bindGEvent(HeroEvent.Artifact_Lucky_Red_Event, this.onLuckyTipFresh.bind(this)); this.bindGEvent(HeroEvent.Artifact_Compound_Event, this.setEmpty.bind(this)); this.setEmpty(null, true); this.onLuckyFresh(); }, onDisable: function onDisable() { if (nx.bridge.prompt) { nx.bridge.prompt.delPrompt(29); } }, // 置空 setEmpty: function setEmpty(_, _reset) { // 全部重置 if (_reset) { nx.gui.setSpriteFrame(this.nodReward, "icon/img", null); nx.gui.setActive(this.nodReward, "tip", false); nx.gui.setActive(this.nodReward, "icon/prog", false); nx.gui.setString(this.nodReward, "val/cur", "0"); nx.gui.setString(this.nodReward, "val/total", "0"); } nx.gui.setActive(this.nodTarget, "", false); this.selects = []; nx.gui.setActive(this.nodTarget, "empty", true); nx.gui.setActive(this.nodTarget, "icon", false); this.nodSlots.forEach(function (_node) { nx.gui.setActive(_node, "empty", true); nx.gui.setActive(_node, "icon", false); }); nx.gui.setString(this.nodRate, "txt", nx.text.getKey("ArtCompoundRateTip")); nx.gui.setString(this.nodLevel, "", ""); this.setLimit(CompoundLimit[1]); this.setCost(); HeroControl.getInstance().getModel().dealReformEqm(); }, // 插槽刷新 freshSlots: function freshSlots() { var BC = BackpackController.getInstance(); var BM = BC.getModel(); this.target_id = 0; // 材料刷新 for (var i = 0; i < this.nodSlots.length; ++i) { var st = this.selects[i]; var slot = this.nodSlots[i]; if (nx.dt.objEmpty(st) || !nx.dt.numPositive(st.id, false)) { nx.gui.setActive(slot, "empty", true); nx.gui.setActive(slot, "icon", false); continue; } var cfgs = BM.getBackPackItemById(st.id); if (nx.dt.objEmpty(cfgs)) { nx.gui.setActive(slot, "empty", true); nx.gui.setActive(slot, "icon", false); continue; } if (this.target_id == 0) { var atc = game.configs.partner_artifact_data.data_artifact_data[cfgs.config.id]; this.target_id = atc.com_artifact; } nx.gui.setActive(slot, "empty", false); nx.gui.setActive(slot, "icon", true); var icon = nx.gui.getComponent(slot, "icon", "cmp.item.base"); if (icon) { icon.setData(cfgs); } } // 目标刷新 var cost = 0; var descR = "", descL = ""; if (nx.dt.numPositive(this.target_id, false)) { nx.gui.setActive(this.nodTarget, "empty", false); nx.gui.setActive(this.nodTarget, "icon", true); var _icon = nx.gui.getComponent(this.nodTarget, "icon", "cmp.item.base"); if (_icon) { _icon.setData(this.target_id); } nx.gui.setActive(this.nodTarget, "", false); // 成功率 var ccf = game.configs.partner_artifact_data.data_artifact_compound[this.target_id]; var role = RoleController.getInstance().getRoleVo(); if (ccf && role) { var tf = ccf[this.selects.length]; var rate = tf ? tf.rate : 0; descL = nx.text.format("ArtCompoundRate", Math.floor(rate / 10)); cost = tf ? tf.other_expend : []; } // 等级要求 var bcf = game.configs.partner_artifact_data.data_artifact_data[this.target_id]; if (bcf && bcf.limit_lv > role.lev) { descR = nx.text.format("forge_str4", bcf.limit_lv); } } else { nx.gui.setActive(this.nodTarget, "empty", true); nx.gui.setActive(this.nodTarget, "icon", false); } nx.gui.setString(this.nodRate, "txt", descL); nx.gui.setString(this.nodLevel, "", descR); this.setCost(cost, nx.dt.strEmpty(descR)); }, // 设置限制 setLimit: function setLimit(_limit) { if (!nx.dt.numGood(_limit) || _limit < CompoundLimit[0] || _limit > CompoundLimit[1]) { return; } var counter = nx.gui.find(this.nodPutIn, "counter"); if (counter) { this.limit = _limit; nx.gui.setString(counter, "num", this.limit); nx.gui.setLocked(counter, "dec", this.limit <= CompoundLimit[0]); nx.gui.setLocked(counter, "inc", this.limit >= CompoundLimit[1]); } }, // 设置合成花费 setCost: function setCost(_cost, _lvGood) { if (_lvGood === void 0) { _lvGood = true; } if (nx.dt.arrEmpty(_cost)) { nx.gui.setString(this.nodCompound, "cost/txt", 0); } else { // 解第一个(目前就一个) var fst = _cost[0]; nx.bridge.setIconS(this.nodCompound, "cost/icon", fst[0]); nx.gui.setString(this.nodCompound, "cost/txt", fst[1]); } var lock = false; if (!_lvGood || nx.dt.arrEmpty(_cost)) { lock = true; } nx.gui.setLocked(this.nodCompound, "btn", lock); }, // 祝福值刷新 onLuckyFresh: function onLuckyFresh() { // 奖励刷新 if (!this.rewardItem) { var gift = game.configs.partner_artifact_data.data_artifact_const["change_gift"]; this.rewardItem = { bid: gift.val[0][0], count: gift.val[0][1] }; var item = gitemdata(this.rewardItem.bid); nx.bridge.setIcon(this.nodReward, "icon/img", item ? item.icon : ""); } var HC = HeroControl.getInstance(); var cfgs = game.configs.partner_artifact_data.data_artifact_const["change_condition"]; var max = cfgs ? cfgs.val : 0; var cur = HC.getModel().getArtifactLucky(); nx.gui.setString(this.nodReward, "val/cur", cur); nx.gui.setString(this.nodReward, "val/total", max); var node = nx.gui.setActive(this.nodReward, "icon/prog", true); var cmp = nx.gui.getComponent(node, "bar", cc.Sprite); if (cmp) { cmp.fillRange = cur / max; } // 祝福值红点更新 this.onLuckyTipFresh(); }, // 祝福值红点更新 onLuckyTipFresh: function onLuckyTipFresh() { var HC = HeroControl.getInstance(); var tip = HC.getModel().getArtifactLuckyRedStatus(); nx.gui.setActive(this.nodReward, "tip", tip); }, // 点击奖励 onTouchRewardPreview: function onTouchRewardPreview() { var TC = TipsController.getInstance(); if (TC && this.rewardItem) { TC.showItemTips(this.rewardItem.bid); } }, // 点击奖励领取 onTouchRewardGet: function onTouchRewardGet() { var HC = HeroControl.getInstance(); HC.sender11038(); }, // 点击技能预览 onTouchSkillPreview: function onTouchSkillPreview() { var HC = HeroControl.getInstance(); HC.openArtifactSkillWindow(true, 1); }, // 点击合成 onTouchCompound: function onTouchCompound() { // 判空 if (!nx.dt.numPositive(this.target_id, false) || nx.dt.arrEmpty(this.selects)) { nx.tbox("forge_str7"); return; } // 材料不足 if (this.selects.length < CompoundLimit[0]) { nx.tbox("forge_str8"); return; } var expends = []; for (var i in this.selects) { expends.push({ artifact_id: this.selects[i].id }); } var HC = HeroControl.getInstance(); HC.sender11036(this.target_id, expends); }, // 点击数量增减 onTouchAddDec: function onTouchAddDec(_flag) { var step = _flag == "1" ? 1 : -1; this.setLimit(this.limit + step); }, // 点击帮助 onTouchHelp: function onTouchHelp() { var TC = TipsController.getInstance(); if (TC) { var txt = game.configs.partner_artifact_data.data_artifact_const.artifact_rule.desc; TC.showTextPanel("tip", nx.text.getKey(txt)); } }, // 添加材料 onTouchPutIn: function onTouchPutIn() { var _this = this; // 统计道具 var BC = BackpackController.getInstance(); var BM = BC.getModel(); var items = []; var all = BM.getBackPackItemListByType(BIT.ARTIFACTCHIPS); all.sort(Utils.tableLowerSorter(["quality", "id"])); for (var i = 0; i < all.length; ++i) { var v = all[i]; if (v && v.config && v.config.type == BIT.ARTIFACTCHIPS) { var cfg = game.configs.partner_artifact_data.data_artifact_data[v.config.id]; if (cfg && cfg.com_artifact != 0) { items.push(v); } } } // 参数传递 var args = { items: items, count: CompoundLimit[1], selects: this.selects, flag: 1 }; // 筛选器 var tid = this.target_id || 0; args.fnSelector = function (_selector, _data) { var id = _data.config.id; var cfg = game.configs.partner_artifact_data.data_artifact_data[id]; if (!cfg) { return false; } // 空处理 if (_selector.svcList.focusList.length == 0) { tid = 0; } if (tid == 0 || cfg.com_artifact == tid) { if (tid == 0) { tid = cfg.com_artifact; } return true; } nx.tbox("lab_artifact_chose_window_tip3"); return false; }; BC.openItemSelector(true, args, function (_selects) { _this.selects = []; for (var _i in _selects) { _this.selects.push(_selects[_i]); } _this.freshSlots(); BC.openItemSelector(false); }); }, // 添加材料(快捷) onTouchPutInOnce: function onTouchPutInOnce() { var BC = BackpackController.getInstance(); var BM = BC.getModel(); var all = BM.getBackPackItemListByType(BIT.ARTIFACTCHIPS); all.sort(Utils.tableLowerSorter(["quality", "id"])); for (var i = 0; i < all.length; ++i) { var item = all[i]; var bid = item.config.id; var cfgs = game.configs.partner_artifact_data.data_artifact_data[bid]; if (nx.dt.objEmpty(cfgs) || !nx.dt.numPositive(cfgs.com_artifact, false)) { continue; } var cnt = BM.getItemNumByBid(bid); var atc = game.configs.partner_artifact_data.data_artifact_data[cfgs.com_artifact]; if (nx.dt.objEmpty(atc) || cnt < atc.limit_num) { continue; } var items = BM.getBackPackItemIdListByBid(bid); items.sort(function (_a, _b) { return _a - _b; }); var ids = []; if (items.length >= this.limit) { for (var v = 0; v < this.limit; ++v) { ids.push(items[v]); } } else { ids = items; } this.selects = []; for (var _v = 0; _v < ids.length; ++_v) { this.selects.push({ id: ids[_v] }); } break; } // 判空 if (nx.dt.arrEmpty(this.selects)) { nx.tbox("forge_str6"); return; } // 刷新 this.freshSlots(); } }); cc._RF.pop();