357 lines
11 KiB
JavaScript
357 lines
11 KiB
JavaScript
const ItemBase = require( "nx.fx.sv.expand.item" );
|
|
const TowerMod = require("startower.mod");
|
|
const PathTool = require("pathtool");
|
|
const BattleDramaController = require("battle_drama_controller");
|
|
const RoleController = require("role_controller");
|
|
const StartowerEvent = require("startower.define");
|
|
const 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 () {
|
|
|
|
},
|
|
|
|
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(status){
|
|
if(status){
|
|
//秘书组id
|
|
let _id = nx.bridge.vget("clerkShowId");
|
|
let arr = _id.split( "_" );
|
|
let id = cc.js.formatStr("%s_%s",arr[0],arr[1]);
|
|
let 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);
|
|
}
|
|
let cmp = this.splayer.getComponent("cmp.partner.smod");
|
|
cmp.setData(cfg,true,false);
|
|
}
|
|
}else{
|
|
if(this.splayer){
|
|
this.splayer.active = false;
|
|
}
|
|
}
|
|
},
|
|
|
|
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(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(){
|
|
let 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(){
|
|
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(type){
|
|
let act = "";
|
|
switch (type) {
|
|
case 1:
|
|
act = "action1";
|
|
break;
|
|
case 2:
|
|
act = "action2";
|
|
break;
|
|
case 3:
|
|
act = "action3";
|
|
break;
|
|
default:
|
|
act = "action1";
|
|
break;
|
|
}
|
|
|
|
let res = PathTool.getSpinePath("E80051","action",false);
|
|
this.towerSp.load(res,(_e)=>{
|
|
if(!_e){
|
|
this.towerSp.action(act,true);
|
|
}else{
|
|
this.towerSp.stop();
|
|
}
|
|
});
|
|
},
|
|
|
|
sweepCount:function(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){
|
|
let item = cc.instantiate(this.fabItem);
|
|
let par = nx.gui.find(this.FloorAward,"tag");
|
|
item.parent = par;
|
|
item.scale = 0.6;
|
|
this.goods_item = item;
|
|
}
|
|
var itemVo = {bid:baseid, num:num};
|
|
let 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(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(){
|
|
this.ctrl.openStarTowerMainView(true,this.data);
|
|
},
|
|
|
|
clickFight(){
|
|
var tower =this.data.lev || 0;
|
|
|
|
let auto = 0;
|
|
// let is_vip_skip = nx.storage.get("vip_skip");
|
|
// auto = Number(is_vip_skip) || 0;
|
|
|
|
this.ctrl.sender11322(tower,auto);
|
|
},
|
|
|
|
clickClear(){
|
|
let count = this.ctrl.getTowerLessCount() || 0;
|
|
if(count <= 0){
|
|
this.openBuyCountPanel();
|
|
return;
|
|
}
|
|
var tower = this.data.lev || 0;
|
|
this.ctrl.sender11324(tower);
|
|
},
|
|
|
|
//次数不足弹开购买次数界面
|
|
openBuyCountPanel:function(){
|
|
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];
|
|
|
|
let 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{
|
|
let 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"],(_key,_box)=>{
|
|
_box.close();
|
|
if(_key == "confirm"){
|
|
fun();
|
|
}
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
// update (dt) {},
|
|
});
|