456 lines
16 KiB
JavaScript
456 lines
16 KiB
JavaScript
/******************************************************************
|
|
*
|
|
* 僚机科研
|
|
*
|
|
******************************************************************/
|
|
|
|
const BridgeWindow = require( "bridge.window" );
|
|
const HeroController = require( "hero_controller" );
|
|
const BackpackController = require( "backpack_controller" );
|
|
const ElfinEvent = require( "elfin_event" );
|
|
const ElfinController = require( "elfin_controller" );
|
|
const TipsController = require( "tips_controller" );
|
|
const FID = require( "bridge.function.ids" );
|
|
|
|
|
|
cc.Class( {
|
|
|
|
extends: BridgeWindow,
|
|
|
|
properties: {
|
|
|
|
nodProcess : {
|
|
default: null,
|
|
type : cc.Node,
|
|
displayName: "抽奖进度",
|
|
},
|
|
|
|
nodShowWings: {
|
|
default: null,
|
|
type : cc.Node,
|
|
displayName: "展示節點",
|
|
},
|
|
|
|
nodOps : {
|
|
default: null,
|
|
type : cc.Node,
|
|
displayName: "操作",
|
|
},
|
|
|
|
nodWishPool : {
|
|
default : null,
|
|
type: cc.Node,
|
|
displayName: "许愿池",
|
|
},
|
|
|
|
nodRule : {
|
|
default : null,
|
|
type: cc.Node,
|
|
displayName: "说明",
|
|
},
|
|
|
|
nodReward : {
|
|
default : [],
|
|
type: cc.Node,
|
|
displayName: "奖励组",
|
|
}
|
|
},
|
|
|
|
onLoad: function() {
|
|
this.bindGEvent( ElfinEvent.Update_Elfin_Summon_Data_Event, this.freshSumon.bind( this) );
|
|
this.screen_width = cc.winSize.width;
|
|
},
|
|
|
|
// 重载:参数打开
|
|
onOpenConfigs: function( _params ) {
|
|
|
|
this.unscheduleAllCallbacks();
|
|
this.schedule( ()=>{
|
|
for ( let i = 0; i < this.nodShowWings.children.length; i++ ) {
|
|
let nod = this.nodShowWings.children[i];
|
|
nod.x -= 1 * 0.9;
|
|
if( nod.x <= -( this.nodShowWings.children[0].width + ( this.screen_width < 1920 ? 1920 : this.screen_width ) ) ){
|
|
nod.x = ( this.screen_width < 1920 ? 1920 : this.screen_width ) - this.nodShowWings.children[0].width + 370;
|
|
nx.tween.fadeIn( nod, "", 0.001 );
|
|
}
|
|
}
|
|
}, 0, cc.macro.REPEAT_FOREVER );
|
|
// this.summon = {};
|
|
this.freshSumon();
|
|
},
|
|
|
|
// 重载:关闭前
|
|
onPreClosed: function() {
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
// 刷新所有的方案列表
|
|
freshSumon : function( _summon ){
|
|
// console.log( "许愿池相关" + JSON.stringify( _summon ) );
|
|
|
|
let EC = ElfinController.getInstance();
|
|
let model = EC.getModel();
|
|
let summon = {};
|
|
if( model ){
|
|
summon = model.getElfinSummonData();
|
|
}
|
|
this.summon = summon || _summon;
|
|
let max = 120;
|
|
// console.log( "许愿池相关当前" + JSON.stringify( this.summon ) );
|
|
/********
|
|
* {"camp_id":0,"free_time":1683475200,"times":84,"do_awards":[{"award_id":1}],"lucky_ids":[{"lucky_sprites_bid":113003}],"day_count":20}
|
|
* [26550]:{"camp_id":0,"free_time":1682784000,"times":121,"do_awards":[{"award_id":1}],"lucky_ids":[],"day_count":120}
|
|
* [26550]:{"camp_id":0,"free_time":1682611200,"times":22,"do_awards":[],"lucky_ids":[{"lucky_sprites_bid":113004}],"day_count":0}
|
|
* {"camp_id":0,"free_time":1682697600,"times":1,"do_awards":[],"lucky_ids":[{"lucky_sprites_bid":113003}],"day_count":0}
|
|
*/
|
|
for (let i = 0; i < this.nodReward.length; i++) {
|
|
let item = this.nodReward[i];
|
|
nx.gui.setActive( item, "get", false );
|
|
|
|
}
|
|
|
|
if( this.summon ){
|
|
nx.gui.setString( this.nodProcess, "point/txt", this.summon.times );
|
|
nx.gui.find( this.nodProcess, "prog/progress" ).getComponent( cc.ProgressBar ).progress = this.summon.times / max;
|
|
let cmp = this.nodWishPool.getComponent( "cmp.item.base" );
|
|
if( cmp ){
|
|
if( !nx.dt.arrEmpty( this.summon.lucky_ids ) ){
|
|
cmp.setData( this.summon.lucky_ids[0].lucky_sprites_bid );
|
|
let ifg = gdata( "item_data","data_unit9", this.summon.lucky_ids[0].lucky_sprites_bid );
|
|
nx.bridge.setIcon( this.nodRule,"descs/wish/icon" , ifg.imageid );
|
|
nx.bridge.setIcon( this.nodWishPool, "icon" , ifg.imageid );
|
|
nx.gui.setActive( this.nodWishPool, "add", false );
|
|
}else{
|
|
cmp.setData( 0 );
|
|
nx.gui.setSpriteFrame( this.nodRule,"descs/wish/icon" , "" );
|
|
nx.gui.setSpriteFrame( this.nodWishPool, "icon" , "" );
|
|
nx.gui.setActive( this.nodWishPool, "add", true );
|
|
}
|
|
|
|
}
|
|
|
|
// nx.gui.setString( )
|
|
this.freshOp();
|
|
}
|
|
|
|
|
|
},
|
|
|
|
freshOp: function(){
|
|
|
|
nx.gui.setActive( this.nodRule, "", false );
|
|
// 读取配置信息
|
|
let slcfg = game.configs.holiday_sprite_lottery_data;
|
|
let mfg = slcfg.data_const.common_s;
|
|
let mat = mfg.val;
|
|
let allCfg = slcfg.data_summon[110];
|
|
let count = BackpackController.getInstance().getModel().getItemNumByBid( mat );
|
|
|
|
let afg = slcfg.data_award[0];
|
|
let time = this.summon.times;
|
|
let all_rewards = [0,0,0];
|
|
let awards = this.summon.do_awards;
|
|
for (let i = 0; i < all_rewards.length; i++) {
|
|
let a = awards[i];
|
|
if( a ){
|
|
all_rewards[a.award_id - 1] = a.award_id;
|
|
}
|
|
|
|
}
|
|
if( nx.dt.arrEmpty( awards ) ){
|
|
awards.sort( Utils.tableLowerSorter( [ "award_id" ] ) );
|
|
|
|
}
|
|
|
|
// console.log( "当前的award" + JSON.stringify( awards ) );
|
|
// 领取奖励的操作
|
|
for (let i = 0; i < this.nodReward.length; i++) {
|
|
let item = this.nodReward[i];
|
|
nx.bridge.setIcon( item, "icon", afg[i+1].reward[0][0] );
|
|
|
|
if( time >= afg[i+1].times ){
|
|
if( all_rewards[i] == 0 ){
|
|
nx.gui.setActive( item, "get", true );
|
|
nx.gui.btnFadeColorAndAlphaChildren( item, "bg", false );
|
|
nx.gui.btnFadeColorAndAlphaChildren( item, "icon", false );
|
|
}else{
|
|
nx.gui.setActive( item, "get", false );
|
|
nx.gui.btnFadeColorAndAlphaChildren( item, "bg", true );
|
|
nx.gui.btnFadeColorAndAlphaChildren( item, "icon", true );
|
|
}
|
|
|
|
}else{
|
|
nx.gui.btnFadeColorAndAlphaChildren( item, "bg", false );
|
|
nx.gui.btnFadeColorAndAlphaChildren( item, "icon", false );
|
|
}
|
|
}
|
|
|
|
|
|
// 单抽次数上限
|
|
let max = slcfg.data_const.sprite_lottery_daily_limit.val;
|
|
let desc = slcfg.data_const.sprite_lottery_daily_limit.desc;
|
|
nx.gui.setString( this.nodOps, "mat/txt", nx.dt.shortCount( count ) );
|
|
nx.bridge.setIconS( this.nodOps, "mat/icon", mat );
|
|
|
|
let icon = count > 0 ? mat : allCfg.loss_gold_once[0][0];
|
|
let ticon = count >= allCfg.loss_item_ten[0][1] ? mat : allCfg.loss_gold_once[0][0];
|
|
let once = count > 0 ? allCfg.loss_item_once[0][1] : allCfg.loss_gold_once[0][1];
|
|
let ten = count >= allCfg.loss_item_ten[0][1] ? allCfg.loss_item_ten[0][1] : allCfg.loss_gold_ten[0][1];
|
|
let Nowtimes = this.summon.day_count ;
|
|
// nx.gui.setString( this.nodOps, "tips/desc", desc + ":" );
|
|
nx.gui.setString( this.nodOps, "tips/num", Nowtimes );
|
|
nx.gui.setString( this.nodOps, "tips/max", "/" + max );
|
|
|
|
// 材料不同显示不同
|
|
nx.bridge.setIconS( this.nodOps, "free/mat/icon", icon );
|
|
nx.bridge.setIconS( this.nodOps, "ten/mat/icon", ticon );
|
|
nx.gui.setString( this.nodOps, "free/mat/txt", once );
|
|
nx.gui.setString( this.nodOps, "ten/mat/txt", ten );
|
|
|
|
nx.gui.setActive( this.nodOps, "free/tips/tip", this.summon.free_time > 0 );
|
|
if( this.summon.free_time > 0 ){
|
|
nx.gui.setCdTxt( this.nodOps, "free/tips/tip", ( this.summon.free_time - Math.floor( cc.sys.now() / 1000 ) ) );
|
|
}
|
|
if( slcfg.data_action[0] ){
|
|
let rule = slcfg.data_action[0].desc;
|
|
nx.gui.find( this.nodRule, "descs/rule/txt" ).getComponent( cc.RichText ).string = rule;
|
|
}
|
|
|
|
let rateDescs = slcfg.data_probability[110];
|
|
|
|
// console.log( "当前的数据" + JSON.stringify( rateDescs ) );
|
|
let chd = nx.gui.find( this.nodRule, "descs/rate/rateDesc" ).children;
|
|
|
|
for (let i = 0; i < chd.length; i++) {
|
|
let node = chd[i];
|
|
let desc = rateDescs[i+1];
|
|
nx.gui.setString( node, "txt", desc.name );
|
|
nx.gui.setString( node, "rate", desc.probability + "%" );
|
|
}
|
|
|
|
},
|
|
|
|
// 设置要领取的奖励信息
|
|
setAward: function( _index ){
|
|
|
|
// 抽奖次数奖励配置
|
|
let afg = game.configs.holiday_sprite_lottery_data.data_award[0];
|
|
let safg = afg[_index];
|
|
let mfg = game.configs.holiday_sprite_lottery_data.data_const.common_s;
|
|
let mat = mfg.val;
|
|
const TC = TipsController.getInstance();
|
|
|
|
if( _index == 4 ){
|
|
if( mat ){
|
|
TC.showItemTips( mat );
|
|
}
|
|
|
|
}else{
|
|
let rewards = safg.reward;
|
|
if( rewards ) {
|
|
TC.showItemTips( rewards[0][0] );
|
|
}
|
|
}
|
|
|
|
},
|
|
|
|
// 领取
|
|
getAward: function( _index ){
|
|
|
|
// 抽奖次数奖励配置
|
|
let afg = game.configs.holiday_sprite_lottery_data.data_award[0];
|
|
let safg = afg[_index];
|
|
let mfg = game.configs.holiday_sprite_lottery_data.data_const.common_s;
|
|
const TC = TipsController.getInstance();
|
|
if( !TC ){
|
|
return;
|
|
}
|
|
if( !nx.dt.arrEmpty( this.summon.do_awards ) ){
|
|
let now_award_id = this.summon.do_awards[ _index - 1 ];
|
|
if( now_award_id && now_award_id == _index ){
|
|
nx.tbox( nx.text.getKey( "Cannot claim the reward" ) );
|
|
return;
|
|
}
|
|
}
|
|
|
|
let EC = ElfinController.getInstance();
|
|
let rewards = safg.reward;
|
|
if( this.summon.times >= safg.times ){
|
|
if( rewards ) {
|
|
if( EC ){
|
|
EC.send26552( _index );
|
|
}
|
|
|
|
}
|
|
}else{
|
|
nx.tbox( nx.text.getKey( "Cannot get the reward" ) );
|
|
}
|
|
|
|
},
|
|
|
|
|
|
// 返回主场景
|
|
onBackToMain: function(){
|
|
|
|
let HR = HeroController.getInstance();
|
|
const BC = BackpackController.getInstance();
|
|
if( BC ) {
|
|
BC.openMainWindow( false );
|
|
}
|
|
ElfinController.getInstance().openElfinWishWindow( false );
|
|
HR.openHeroMainInfoWindow( false );
|
|
HR.openHeroBagWindow( true );
|
|
|
|
},
|
|
|
|
|
|
// 点击抽奖
|
|
onTouchLottery : function( _index ){
|
|
|
|
// let type = this.free_time == 0 ? 1 :
|
|
// 抽1次 与抽 10 次同一条信息 free 1 diamond 2 mat 4
|
|
|
|
// 读取配置信息
|
|
let slcfg = game.configs.holiday_sprite_lottery_data;
|
|
let mfg = slcfg.data_const.common_s;
|
|
let mat = mfg.val;
|
|
let allCfg = slcfg.data_summon[110];
|
|
let count = BackpackController.getInstance().getModel().getItemNumByBid( mat );
|
|
let have = BackpackController.getInstance().getModel().getItemNumByBid( allCfg.loss_gold_once[0][0] );
|
|
// 单日次数上限
|
|
let max = slcfg.data_const.sprite_lottery_daily_limit.val;
|
|
console.log( "free" + JSON.stringify( this.summon ) );
|
|
// let gain_once_num = ;
|
|
let time = this.summon.times;
|
|
let EC = ElfinController.getInstance();
|
|
let dayCount = this.summon.day_count;
|
|
|
|
if( EC ){
|
|
if( _index == 0 ){
|
|
|
|
if( this.summon.free_time == 0 ){
|
|
EC.send26551( 1, 1 , false );
|
|
}
|
|
if( this.summon.free_time != 0 ){
|
|
// 有材料使用相应的材料
|
|
if( count > 0 ){
|
|
EC.send26551( 1, 4 , false );
|
|
}else{
|
|
|
|
if( dayCount == max ){
|
|
nx.tbox( nx.text.getKey( "lab_elfin_summon_tips_11" ) );
|
|
return;
|
|
}
|
|
let timeNow = dayCount + 1;
|
|
if( timeNow > max ){
|
|
nx.tbox( nx.text.getKey( "lab_elfin_summon_tips_11" ) );
|
|
return;
|
|
}
|
|
let mat0 = allCfg.loss_gold_once[0][0];
|
|
let mat1 = allCfg.gain_once[0][0];
|
|
|
|
let txt = nx.text.format( "lab_elfin_summon_tips_9t", allCfg.loss_gold_once[0][1], allCfg.gain_once[0][1] , 1 );
|
|
EC.openElfUseTipsWindow( true , txt, [mat0, mat1], [ allCfg.loss_gold_once[0][1], allCfg.gain_once[0][1] ], ( _deal =>{
|
|
EC.send26551( 1, 3 , false );
|
|
EC.openElfUseTipsWindow( false );
|
|
} ) );
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}else{
|
|
|
|
if( count >= 10 ){
|
|
EC.send26551( 10, 4 , false );
|
|
}else{
|
|
if( dayCount == max ){
|
|
nx.tbox( nx.text.getKey( "lab_elfin_summon_tips_11" ) );
|
|
return;
|
|
}
|
|
time = this.summon.dayCount + 10;
|
|
if( time > max ){
|
|
nx.tbox( nx.text.getKey( "lab_elfin_summon_tips_11" ) );
|
|
return;
|
|
}
|
|
let mat0 = allCfg.loss_gold_ten[0][0];
|
|
let mat1 = allCfg.gain_ten[0][0];
|
|
|
|
let txt = nx.text.format( "lab_elfin_summon_tips_9t", allCfg.loss_gold_ten[0][1], allCfg.gain_ten[0][1] , 10 );
|
|
EC.openElfUseTipsWindow( true , txt, [mat0, mat1], [ allCfg.loss_gold_ten[0][1], allCfg.gain_ten[0][1] ], ( _deal =>{
|
|
EC.send26551( 10, 3 , false );
|
|
EC.openElfUseTipsWindow( false );
|
|
} ) );
|
|
}
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
// 许愿
|
|
onTouchWish: function(){
|
|
|
|
let EC = ElfinController.getInstance();
|
|
if( EC ){
|
|
let cmp = this.nodWishPool.getComponent( "cmp.item.base" );
|
|
let nowSelect = this.summon.lucky_ids;
|
|
// if( cmp ){
|
|
// if( cmp.mdata ){
|
|
// nowSelect = cmp.mdata;
|
|
// }
|
|
|
|
// }
|
|
let wfg = game.configs.holiday_sprite_lottery_data.data_const.lucky_sprite_ids;
|
|
let wishList = wfg.val;
|
|
let args = {
|
|
wishLst : wishList,
|
|
count : 1,
|
|
selects : nowSelect,
|
|
}
|
|
|
|
EC.openElfinWishTip( true, args );
|
|
}
|
|
|
|
},
|
|
|
|
// 点击帮助
|
|
onTouchHelp: function() {
|
|
|
|
let TC = TipsController.getInstance();
|
|
if( TC ) {
|
|
let txt = game.configs.holiday_sprite_lottery_data.data_const.reward_desc;
|
|
TC.showTextPanel( "tip", txt.desc );
|
|
}
|
|
|
|
},
|
|
|
|
// 点击帮助
|
|
onTouchRule: function() {
|
|
nx.gui.setActive( this.nodRule, "", !nx.gui.find( this.nodRule ).active );
|
|
},
|
|
|
|
close : function(){
|
|
|
|
|
|
if( nx.bridge.plot && nx.bridge.plot.isDoing() ){
|
|
|
|
nx.bridge.jumper.jump2Window( FID.Wing );
|
|
|
|
}
|
|
this._super();
|
|
|
|
},
|
|
|
|
/*******
|
|
* [26553]:{"group_id":110,"times":1,"rewards":[{"base_id":112004,"num":1}],"sprite_bids":[{"sprite_bid":112004,"quality":3,"jie":1}]}
|
|
*/
|
|
|
|
} );
|