"use strict"; cc._RF.push(module, 'ea72b1X/sVPgrYp8NJnmtD9', 'cmp.startower.item'); // Scripts/mod/pve/startower/cmp/cmp.startower.item.js "use strict"; var ItemBase = require("nx.fx.sv.expand.item"); var TowerMod = require("startower.mod"); var PathTool = require("pathtool"); var BattleDramaController = require("battle_drama_controller"); var RoleController = require("role_controller"); var StartowerEvent = require("startower.define"); var NxSpine = require("nx.fx.spine"); cc.Class({ "extends": ItemBase, properties: { tower_name: { "default": null, type: cc.Label }, come_btn: { "default": null, type: cc.Node }, count_nd: { "default": null, type: cc.Node }, count_txt: { "default": null, type: cc.Label }, cost_num: { "default": null, type: cc.Label }, FloorAward: { "default": null, type: cc.Node }, fabItem: { "default": null, type: cc.Prefab }, Dianmond: { "default": null, type: cc.Node }, btn_view: { "default": null, type: cc.Node }, btn_clear: { "default": null, type: cc.Node }, completeNd: { "default": null, type: cc.Node }, smod: { "default": null, type: cc.Prefab }, towerBg: { "default": null, type: cc.Node }, powerNd: { "default": null, type: cc.Node }, towerSp: { "default": null, type: NxSpine } }, // LIFE-CYCLE CALLBACKS: onLoad: function onLoad() {}, setConfig: function setConfig() { this.ctrl = TowerMod.getInstance(); this.is_lock = false; this.is_open_tower = true; this.star_list = {}; this.config = game.configs.star_tower_data.data_tower_base; this.itemNum = 6; // 层级奖励 }, setSmod: function setSmod(status) { if (status) { //秘书组id var _id = nx.bridge.vget("clerkShowId"); var arr = _id.split("_"); var id = cc.js.formatStr("%s_%s", arr[0], arr[1]); var cfg = gdata("partner_data", "data_partner_star", id); if (cfg && cfg.bid) { if (!this.splayer) { this.splayer = cc.instantiate(this.smod); this.splayer.parent = this.towerBg; this.splayer.position = cc.v2(0, -100); } var cmp = this.splayer.getComponent("cmp.partner.smod"); cmp.setData(cfg, true, false); } } else { if (this.splayer) { this.splayer.active = false; } } }, setEmpty: function setEmpty() { this.countVisible(false); this.setSmod(false); this.FloorAward.active = false; this.data = null; this.tower_name.string = ""; this.completeNd.active = false; this.powerNd.active = false; this.setTowerEft(1); // this.btn_view.active = false; }, setData: function setData(data, index, key) { if (nx.dt.objEmpty(data)) { this.setEmpty(); return false; } this.setConfig(); this.floor_key = key; this.data = data; this.updateData(); }, updateData: function updateData() { var name = this.data.lev || ""; this.tower_name.string = name; nx.gui.setString(this.powerNd, "num", cc.js.formatStr("%s%s", nx.text.getKey("EBP_"), this.data.recommend)); this.towerSp.stop(); this.updateMessage(); }, updateMessage: function updateMessage() { var max_tower = this.ctrl.getNowTowerId() || 0; var bool = false; //已通关的判断 if (this.data.lev <= max_tower) { bool = true; } this.is_pass = bool; this.sweepCount(this.data); this.is_lock = !(this.data.lev >= max_tower + 1); //下一关可挑战 this.come_btn.active = false; nx.gui.setActive(this.powerNd, "", false); this.is_open_tower = true; if (!this.is_pass && !this.is_lock) { var limit_dun_id = this.data.limit_dun_id || 0; var data = BattleDramaController.getInstance().getModel().getDramaData(); if (limit_dun_id != 0 && data && data.max_dun_id && data.max_dun_id < limit_dun_id) { this.is_open_tower = false; return; } if (this.data.lev == max_tower + 1) { this.setSmod(true); this.come_btn.active = true; nx.gui.setActive(this.powerNd, "", true); this.setTowerEft(2); gcore.GlobalEvent.fire(StartowerEvent.Update_Cur_Floor_Award, this.data.award); } else { this.setSmod(false); this.setTowerEft(1); } } else { this.setSmod(false); this.setTowerEft(3); } }, setTowerEft: function setTowerEft(type) { var _this = this; var act = ""; switch (type) { case 1: act = "action1"; break; case 2: act = "action2"; break; case 3: act = "action3"; break; default: act = "action1"; break; } var res = PathTool.getSpinePath("E80051", "action", false); this.towerSp.load(res, function (_e) { if (!_e) { _this.towerSp.action(act, true); } else { _this.towerSp.stop(); } }); }, sweepCount: function sweepCount(data) { this.countVisible(false); this.completeNd.active = false; var max_tower = this.ctrl.getNowTowerId() || 0; if (data && data.lev == max_tower) { //当前已通关的层数 var count = this.ctrl.getTowerLessCount() || 0; var buyCount = this.ctrl.getBuyCount(); if (count <= 0) { if (buyCount >= 0) { this.countVisible(true); this.Dianmond.active = true; var have_buycount = this.ctrl.getBuyCount() || 0; if (game.configs.star_tower_data.data_tower_buy[have_buycount + 1]) { var num = game.configs.star_tower_data.data_tower_buy[have_buycount + 1].expend[0][1] || 0; var str = cc.js.formatStr(nx.text.getKey("lab_star_tower_item_panel_tip1"), num); this.count_txt.string = str; } else { this.countVisible(false); this.Dianmond.active = false; this.completeNd.active = true; } } else { this.countVisible(false); this.Dianmond.active = false; this.completeNd.active = true; } } else { var str = cc.js.formatStr(nx.text.getKey("lab_star_tower_item_panel_tip2"), count); this.count_txt.string = str; this.countVisible(true); this.Dianmond.active = false; } } // 层级奖励 var max_tower = this.ctrl.getNowTowerId() || 0; var max = max_tower; // if((max_tower+this.itemNum) >= this.config.length){ max = game.configs.star_tower_data.data_tower_base_length; // }else{ // max = max_tower+this.itemNum; // } var current = max_tower; if (max_tower + 1 >= game.configs.star_tower_data.data_tower_base_length) { current = game.configs.star_tower_data.data_tower_base_length; } if (this.data.lev > current && this.data.lev <= max) { var item_show = data.item_show[0]; if (item_show) { var baseid = item_show[0]; var num = item_show[1]; if (this.goods_item == null) { var item = cc.instantiate(this.fabItem); var par = nx.gui.find(this.FloorAward, "tag"); item.parent = par; item.scale = 0.6; this.goods_item = item; } var itemVo = { bid: baseid, num: num }; var cmp = this.goods_item.getComponent("cmp.item.base"); cmp.setData(itemVo); this.FloorAward.active = true; } else { this.FloorAward.active = false; } } else { this.FloorAward.active = false; } }, countVisible: function countVisible(visible) { this.count_nd.active = visible; this.count_txt.node.active = visible; // this.btn_clear.active = visible; this.Dianmond.active = false; this.come_btn.active = false; }, clickStartowerInfo: function clickStartowerInfo() { this.ctrl.openStarTowerMainView(true, this.data); }, clickFight: function clickFight() { var tower = this.data.lev || 0; var auto = 0; // let is_vip_skip = nx.storage.get("vip_skip"); // auto = Number(is_vip_skip) || 0; this.ctrl.sender11322(tower, auto); }, clickClear: function clickClear() { var count = this.ctrl.getTowerLessCount() || 0; if (count <= 0) { this.openBuyCountPanel(); return; } var tower = this.data.lev || 0; this.ctrl.sender11324(tower); }, //次数不足弹开购买次数界面 openBuyCountPanel: function openBuyCountPanel() { var have_buycount = this.ctrl.getBuyCount() || 0; var role_vo = RoleController.getInstance().getRoleVo(); var config = game.configs.star_tower_data.data_tower_vip[role_vo.vip_lev]; var fun = function () { var tower = this.data.lev || 0; this.ctrl.sender11324(tower); }.bind(this); if (config && config.buy_count) { if (have_buycount >= config.buy_count) { nx.tbox("lab_star_tower_main_window_tip6"); } else { var buy_config = game.configs.star_tower_data.data_tower_buy[have_buycount + 1]; if (buy_config && buy_config.expend && buy_config.expend[0] && buy_config.expend[0][0]) { var item_id = buy_config.expend[0][0]; var num = buy_config.expend[0][1] || 0; var item_config = Utils.getItemConfig(item_id); if (item_config && item_config.icon) { var str = cc.js.formatStr(nx.text.getKey("lab_star_tower_main_window_tip7"), item_id, num); nx.mbox(str, ["cancel", "confirm"], function (_key, _box) { _box.close(); if (_key == "confirm") { fun(); } }); } } } } } // update (dt) {}, }); cc._RF.pop();