/****************************************************************** * * 联盟挑战 * ******************************************************************/ const TipController = require( "tips_controller" ); const HeroController = require("hero_controller"); const PartnerConst = require("partner_const"); const RoleController = require("role_controller"); const GuildbossEvent = require("guildboss_event"); const GuildBossConst = require("guildboss_const"); const GuildBossController = require("guildboss_controller"); const BackpackController = require("backpack_controller"); const BridgeWindow = require( "bridge.window" ); const ItemLay = require("cmp.common.itemlayout"); const RankController = require( "rank_controller" ); const RankConst = require( "rank_constant" ); cc.Class( { extends: BridgeWindow, properties: { //Left chapterList:{ default:null, type:cc.Node }, roleSp:{ default:null, type:cc.Node }, hpLb:{ default:null, type:cc.Label }, hpBar:{ default:null, type:cc.ProgressBar }, roleName:{ default:null, type:cc.Label }, roleId:{ default:null, type:cc.Label }, buffBtn:{ default:null, type:cc.Node }, //Right rankList:{ default:null, type:cc.Node }, rankItem:{ default:null, type:cc.Node }, rankIcons:{ default:[], type:[cc.SpriteFrame] }, remainLb:{ default:null, type:cc.Label }, challengeLb:{ default:null, type:cc.Label }, dpsLay:{ default:null, type:ItemLay }, fixedLay:{ default:null, type:ItemLay }, challenge_btn:{ default:null, type:cc.Button }, mopup_btn:{ default:null, type:cc.Button }, }, onLoad: function(){ this.select_cfg = {}; this.ctrl = GuildBossController.getInstance(); this.model = this.ctrl.getModel(); this.role_vo = RoleController.getInstance().getRoleVo(); this.bindGEvent( GuildbossEvent.MusterCoolTime, this.musterCoolTime.bind( this ) ); this.bindGEvent( GuildbossEvent.BossActivityDoubleTime, this.doubleTimeAction.bind( this ) ); //面板基礎信息 this.bindGEvent( GuildbossEvent.UpdateGuildDunBaseInfo, this.upBossInfo.bind( this ) ); this.bindGEvent( GuildbossEvent.UpdateChangeStatus, this.updateChangeStatus.bind( this ) ); this.bindGEvent( GuildbossEvent.UpdateGuildDunRank, this.upDunRank.bind( this ) ); this.bindGEvent( GuildbossEvent.UpdateGuildBossChallengeTimes, this.upChanllengeTimes.bind( this ) ); }, upChanllengeTimes(buy_type){ if (this.base_info != null) { this.challengeLb.string = this.base_info.count; this.remainBuyCount(this.base_info.buy_count); } else { var base_info = this.model.getBaseInfo(); if (base_info != null) { this.remainBuyCount(base_info.buy_count); this.challengeLb.string = base_info.count; } } //挑战购买的时候自动打开挑战界面 if (buy_type == 1) { this.autoOpenChallengeWindow(); } }, upDunRank(){ nx.bridge.NodeChidrenDestroy(this.rankList); var rank_list = this.ctrl.getModel().getRaknRoleTopThreeList(); if (rank_list) { for (var i in rank_list) { var v = rank_list[i]; var item = cc.instantiate(this.rankItem); if (item) { nx.gui.setString(item,"name",v.name); if (v.all_dps) { nx.gui.setString(item,"dps",Utils.getMoneyString(v.all_dps, false)); } else { nx.gui.setString(item,"dps","0"); } let sp = nx.gui.getComponent(item,"ico",cc.Sprite); sp.spriteFrame = this.rankIcons[v.rank - 1]; item.parent = this.rankList; item.active = true; } } } }, ///////////////////////////////// musterCoolTime: function(data){ // if (this.role_vo.position == 1 || this.role_vo.position == 2) { // this.musterCoolCountTime(data); // } else { // this.muster_btn_tips.string = nx.text.getKey("lab_guild_main_window_tip_3"); // } }, doubleTimeAction: function (bool) { if (!bool) { } }, upBossInfo: function(){ this.cell_data_list = this.getCellData()[0]; //刷新boss this.updateDunBaseInfo(); }, //切换Boss的时候 updateChangeStatus: function (boss_data) { if (nx.dt.objEmpty(boss_data)) return; let data = this.cell_data_list[boss_data.id - 1]; var fid = 0; var base_info = this.model.getBaseInfo(); var hp_info = null; if (data.status == 0) { fid = base_info.fid; if (base_info != null && base_info.info != null) { //储存容器里面相关的boss模型 for (var i in base_info.info) { var v = base_info.info[i]; var boss_config = gdata("guild_dun_data", "data_guildboss_list", [v.boss_id]); if (boss_config) { this.select_cfg.boss_id = boss_config.boss_id; this.select_cfg.config = boss_config; hp_info = v; } } if (base_info.combat_info) { for (var i in base_info.combat_info) { var v = base_info.combat_info[i]; if (v.boss_id == this.select_cfg.config.boss_id) { this.select_cfg.dps = v.dps; } } } } // this.buff_container.active = true; } else { fid = boss_data.id; this.select_cfg.boss_id = boss_data.boss_id; this.select_cfg.config = boss_data; hp_info = { boss_id: boss_data.boss_id, hp: 0 }; this.select_cfg.dps = 0; // this.buff_container.active = false; } if (fid) { var chatpter_config = gdata("guild_dun_data", "data_chapter_reward", [fid]); var config = gdata("guild_dun_data", "data_guildboss_list", [chatpter_config.show_id]); // if (chatpter_config != null) { // this.chapter_name.string = chatpter_config.chapter_name + " " + chatpter_config.chapter_desc; // } if (hp_info) { this.updateMonsterHPStatus(config, hp_info); } if (config) { this.updateMonsterInfo(config); } this.setMainBossInfos(); } }, //////////////////////////////// getCellData: function () { var base_info = this.model.getBaseInfo(); var item_list = []; var select_index = null; if (base_info) { var is_first_lock = false; for (var i in game.configs.guild_dun_data.data_chapter_reward) { var v = gdata("guild_dun_data", "data_chapter_reward", [i]); var object = {}; object.desc = v.chapter_name; object.show_id = v.show_id; if (base_info.fid && base_info.fid == v.id) { //进行中 select_index = i; object.status = 0; } else if (base_info.fid > v.id) { //已通关 object.status = 1; } else { if (is_first_lock == false) { ////第一个未通关的,做文本显示 object.status = 3; is_first_lock = true; } else { object.status = 2; } } item_list[i - 1] = object; } } return [item_list, select_index - 1] }, onOpenConfigs() { //基础信息,服务端要求没次打开面板的时候都请求一下 this.roleSp.opacity = 0; this.ctrl.requestGuildDunBaseInfo(); }, onPreClosed() { nx.bridge.NodeChidrenDestroy(this.rankList); this.dpsLay.rebuild([]); this.fixedLay.rebuild([]); }, // 显示 onEnable: function() { }, // 关闭 onDisable: function() { if( nx.bridge.prompt ) { nx.bridge.prompt.delPrompt(21); } }, //协议返回用于更新基础信息 updateDunBaseInfo: function () { this.base_info = this.model.getBaseInfo(); var base_info = this.base_info; if (!nx.dt.objEmpty(base_info)) { this.remainBuyCount(base_info.buy_count); //储存容器里面相关的boss模型 for (var i in base_info.info) { let v = base_info.info[i]; var boss_config = gdata("guild_dun_data", "data_guildboss_list", [v.boss_id]); if (boss_config) { this.select_cfg.boss_id = boss_config.boss_id; this.select_cfg.config = boss_config; //更新血量 this.updateMonsterHPStatus(boss_config, v); } } //存储dps if (base_info.combat_info) { for (var i in this.base_info.combat_info) { var v = this.base_info.combat_info[i]; if (v.boss_id == this.select_cfg.config.boss_id) { this.select_cfg.dps = v.dps; } } } //设置基础信息显示 this.challengeLb.string = base_info.count; // if (this.cur_fid != base_info.fid) { this.cur_fid = base_info.fid; let chatpter_config = gdata("guild_dun_data", "data_chapter_reward", [base_info.fid]); if (chatpter_config != null) { var config = gdata("guild_dun_data", "data_guildboss_list", [chatpter_config.show_id]); if (config) { this.updateMonsterInfo(config); } //这里设置挑战奖励吧 this.updateFillRewardsItems(chatpter_config.dps_awrard, chatpter_config.award, chatpter_config.guild_exp); } // } this.setMainBossInfos(); if (base_info != null && base_info.buff_end_time != 0) { var buff_config = gdata("guild_dun_data", "data_buff_data", [base_info.buff_lev]); if (buff_config) { nx.gui.setString(this.buffBtn,"name",buff_config.desc); } nx.gui.setCdTxt(this.buffBtn,"acitive",base_info.buff_end_time); } else { nx.gui.setString(this.buffBtn,"name",gdata("guild_dun_data", "data_const", ["des_nobuff"]).desc); nx.gui.setString(this.buffBtn,"acitive",nx.text.getKey("lab_guild_main_window_tip_16")); } var protocal = { boss_id: this.select_cfg.config.boss_id, start_num: 1, end_num: 3 } this.ctrl.requestGuildDunRank(GuildBossConst.rank.role, protocal) } }, //创建模型,根据config updateMonsterInfo: function (config) { let partner_cfg = game.configs.partner_data.data_partner_base[config.head_icon]; let res_path = cc.js.formatStr("resDB/models/%s/show",partner_cfg.bustid); let rcmp = nx.gui.getComponent( this.roleSp, "role", "nx.fx.spine" ); if( rcmp ){ rcmp.load( res_path, ( _e ) => { if( !_e ) { rcmp.action( "action1", true ); rcmp.node.active = true; } else { rcmp.stop(); rcmp.node.active = false; } } ); } // nx.gui.setSpriteFrame(this.roleSp,"",res_path); //需要處理一下絲滑動作 this.roleSp.runAction(cc.sequence(cc.fadeOut(0.1).easing(cc.easeOut(0.1)),cc.delayTime(0.1),cc.fadeIn(0.1))); }, //剩余购买次数 remainBuyCount: function (count) { var num = 0; var length = game.configs.guild_dun_data.data_buy_count_length; var buy_config = game.configs.guild_dun_data.data_buy_count[length]; if (buy_config) { num = buy_config.count - count; } this.remainLb.string = num; }, setMainBossInfos: function(){ if(!nx.dt.objEmpty(this.select_cfg.config)){ let mid_id = this.select_cfg.config.id; //判斷前後是否有數據,規則是id*100+1 let fore_id = (mid_id-1)*100 + 1; let fore_cfg = gdata("guild_dun_data", "data_guildboss_list", [fore_id]); let left_nd = this.chapterList.children[0]; let left_cmp = left_nd.getComponent("cmp.guildboss.item"); if(!nx.dt.objEmpty(fore_cfg)){ let cell_data = this.cell_data_list[fore_cfg.id - 1]; if( cell_data ){ left_cmp.setData(fore_cfg,cell_data); }else{ left_cmp.setData({}); } }else{ left_cmp.setData({}); } let beh_id =(mid_id+1)*100 + 1; let beh_cfg = gdata("guild_dun_data", "data_guildboss_list", [beh_id]); let right_nd = this.chapterList.children[1]; let right_cmp = right_nd.getComponent("cmp.guildboss.item"); if(!nx.dt.objEmpty(beh_cfg)){ let cell_data = this.cell_data_list[beh_cfg.id - 1]; right_cmp.setData(beh_cfg,cell_data); }else{ right_cmp.setData({}); } } //刷新按鈕狀態 this.updateSelectedBtnStatus(); }, //更新选中对象的按钮状态 updateSelectedBtnStatus: function () { if (nx.dt.numGood(this.select_cfg.hp) || nx.dt.numGood(this.select_cfg.dps)){ let btn = nx.gui.getComponent(this.roleSp,"",cc.Button); if (this.select_cfg.hp == 0) { //已经被击杀了 nx.gui.setLocked(this.challenge_btn.node,"",true); nx.gui.setLocked(this.mopup_btn.node,"",true); btn.interactable = false; } else { btn.interactable = true; if (this.select_cfg.dps == 0) { //没有挑战过,不可以扫荡 nx.gui.setLocked(this.challenge_btn.node,"",false); nx.gui.setLocked(this.mopup_btn.node,"",true); } else { nx.gui.setLocked(this.challenge_btn.node,"",false); nx.gui.setLocked(this.mopup_btn.node,"",false); } } } }, //更新血条 updateMonsterHPStatus: function (config, info) { if (nx.dt.objEmpty(info)) return; //设置血量 let percent = Math.ceil(100 * info.hp / config.hp); this.hpLb.string = percent + "%"; this.hpBar.progress = percent / 100; // object.pass_icon.active = info.hp == 0; // object.boss_icon.setVisible(info.hp != 0); this.roleName.string = config.item_name; this.roleId.string = nx.text.getKey( "Challenge" ) + "0" + config.id; this.select_cfg.hp = info.hp; }, //设置物品奖励 //dps_award:伤害奖励列表 //fixed_award:固定奖励列表 //guild_award:公会贡献特殊 updateFillRewardsItems: function (dps_award, fixed_award, guild_award) { fixed_award.push([Number(gdata("item_data", "data_assets_label2id", "guild_exp")), guild_award]); this.dpsLay.rebuild(dps_award); this.fixedLay.rebuild(fixed_award); }, checkBuff: function () { if (this.base_info) { var item = gdata("guild_dun_data", "data_const", "buff_item").val; var num = BackpackController.getInstance().getModel().getBackPackItemNumByBid(item); var cost = gdata("guild_dun_data", "data_const", "buff_cost").val; var item_icon = Utils.getItemConfig(item).icon; var index_lev = Math.min(this.base_info.buff_lev + 1, game.configs.guild_dun_data.data_buff_data_length); var desc = gdata("guild_dun_data", "data_buff_data", [index_lev]).desc; var str = ""; var str_ = ""; var str_end = cc.js.formatStr(nx.text.getKey("lab_guild_main_window_tip_5"), desc); if (num > 0) { //如果存在道具 if (this.base_info.buff_lev == 0) { //表示没buff str = cc.js.formatStr(nx.text.getKey("lab_guild_main_window_tip_6"), item_icon, 1, num); str_ = str + str_end; } else { str = cc.js.formatStr(nx.text.getKey("lab_guild_main_window_tip_7"), item_icon, 1, num); str_ = str + str_end; } } else { if (this.base_info.buff_lev == 0) { //表示没buff str = cc.js.formatStr(nx.text.getKey("lab_guild_main_window_tip_8"), game.configs.item_data.data_assets_label2id.gold, cost); str_ = str + str_end; } else { str = cc.js.formatStr(nx.text.getKey("lab_guild_main_window_tip_9"), game.configs.item_data.data_assets_label2id.gold, cost); str_ = str + str_end; } } nx.mbox(str,["cancel","confirm"],(_key,_box)=>{ _box.close(); if(_key == "confirm"){ this.ctrl.send21305(); } }); } }, //挑战购买次数的时候自动打开面板 autoOpenChallengeWindow: function () { if (this.select_cfg.config && this.base_info) { if (this.base_info.count > 0) { HeroController.getInstance().openFormGoFightPanel(true, PartnerConst.Fun_Form.GuildDun_AD, { boss_id: this.select_cfg.boss_id }) } } }, onClickClear(){ if (this.role_vo.position == 1 || this.role_vo.position == 2) { var str = nx.text.getKey("lab_guild_main_window_tip_2"); nx.mbox(str,["cancel","confirm"],(_key,_box)=>{ _box.close(); if(_key == "confirm"){ this.ctrl.send21323(); } }); } else { nx.tbox("lab_guild_main_window_tip_1") } if( nx.bridge.prompt ) { nx.bridge.prompt.delPrompt(10); } }, onAddBuyNum(){ this.ctrl.requestBuyChallengeTimes(0); }, onClickRank(){ RankController.getInstance().openRankDetail( RankConst.RankType.union_boss , this.select_cfg.config.boss_id ); // if (this.select_cfg) { // // require("rank_controller").getInstance().openRankView(true, require("rank_constant").RankType.union_boss, null, this.select_cfg.config); // } }, onChallengeBoss(){ if (this.select_cfg && this.select_cfg.config && this.base_info) { if (this.base_info.count > 0) { HeroController.getInstance().openFormGoFightPanel(true, PartnerConst.Fun_Form.GuildDun_AD, { boss_id: this.select_cfg.config.boss_id }) } else { this.ctrl.requestBuyChallengeTimes(1); } } }, onMopupBoss(){ if (this.select_cfg && this.select_cfg.config && this.base_info) { this.requestMopupMonster(); } }, requestMopupMonster: function () { var base_info = this.base_info; if (base_info.count > 0) { var msg = cc.js.formatStr(nx.text.getKey("lab_guild_main_window_tip_11"), this.select_cfg.dps); nx.mbox(msg,["cancel","confirm"],(_key,_box)=>{ _box.close(); if(_key == "confirm"){ this.ctrl.requestMopupMonster(this.select_cfg.boss_id) } }); } else { var buy_next_num = base_info.buy_count + 1; var buy_config = gdata("guild_dun_data", "data_buy_count", [buy_next_num]); let buy_configdiff = game.configs.guild_dun_data.data_buy_count[buy_next_num]; if ( !buy_configdiff ) { nx.tbox("lab_guild_main_window_tip_12"); } else { if (this.role_vo) { if (this.role_vo.vip_lev < buy_config.vip_lev) { var msg = cc.js.formatStr(nx.text.getKey("lab_guild_main_window_tip_13"), buy_config.vip_lev); nx.mbox(msg,["cancel","confirm"],(_key,_box)=>{ _box.close(); if(_key == "confirm"){ nx.bridge.createPanel( "WndPayment", { key: "recharge" } ); } }); } else { var cost = buy_config.expend; if (cost == null || cost.length < 2) return var item_config = Utils.getItemConfig(cost[0]); if (item_config) { var msg = cc.js.formatStr(nx.text.getKey("lab_guild_main_window_tip_14"), item_config.icon, cost[1], this.select_cfg.dps); nx.mbox(msg,["cancel","confirm"],(_key,_box)=>{ _box.close(); if(_key == "confirm"){ this.ctrl.requestMopupMonster(this.select_cfg.boss_id); } }); } } } } } }, } );