462 lines
12 KiB
JavaScript
462 lines
12 KiB
JavaScript
/******************************************************************
|
|
* Copyright(C) 2019 - 2020 Nx Studio
|
|
*
|
|
* 常规召唤页
|
|
*
|
|
* 2018.05.18
|
|
******************************************************************/
|
|
|
|
const MenuPage = require( "cmp.com.menu.page" );
|
|
|
|
const SummonDefine = require( "summon.define" );
|
|
const SummonMod = require( "summon.mod" );
|
|
|
|
const HeroController = require( "hero_controller" );
|
|
const BackPackController = require( "backpack_controller" );
|
|
const BridgeItemBinder = require( "bridge.binder.item.icon.count" );
|
|
|
|
const SCRT = SummonDefine.Status;
|
|
const FID = require( "bridge.function.ids" );
|
|
|
|
|
|
const EmptyBG = "";
|
|
|
|
cc.Class( {
|
|
|
|
extends: MenuPage,
|
|
|
|
properties: {
|
|
nodOps: { default: null, type: cc.Node },
|
|
nodCoin: { default: null, type: BridgeItemBinder },
|
|
labTimes: { default: null, type: cc.Node },
|
|
},
|
|
|
|
// 载入
|
|
onLoad: function() {
|
|
this._super();
|
|
this.setEmpty();
|
|
let cmp = nx.gui.getComponent( this, "sp", "nx.fx.spine" );
|
|
if( cmp ){
|
|
cmp.load( "resDB/models/H30031/show", ( _e ) => {
|
|
if( !_e ) {
|
|
cmp.action( "action1", true );
|
|
} else {
|
|
cmp.stop();
|
|
}
|
|
} );
|
|
}
|
|
|
|
},
|
|
|
|
// 显示
|
|
onEnable: function() {
|
|
|
|
const SC = SummonMod.getInstance();
|
|
SC.reqInfiniteData( ( _ret, _data ) => {
|
|
|
|
if( !_ret ) {
|
|
this.setEmpty();
|
|
nx.tbox( _data );
|
|
return;
|
|
}
|
|
|
|
this.data = nx.dt.objClone( _data );
|
|
this.updateBase( _data );
|
|
this.updateData( _data );
|
|
|
|
} );
|
|
|
|
// 视图监听
|
|
this.vbind( [
|
|
[ "INFTimes", this.onRemainTimes.bind( this ) ],
|
|
[ "INFCurrent", this.onCurrentChanged.bind( this ) ]
|
|
] );
|
|
},
|
|
|
|
// 关闭
|
|
onDisable: function() {
|
|
|
|
// 视图监听解除
|
|
this.vunbind();
|
|
},
|
|
|
|
// 置空
|
|
setEmpty: function() {
|
|
|
|
// nx.gui.setSpriteFrame( this, "bg", EmptyBG );
|
|
|
|
this.costId = 0;
|
|
this.nodCoin.active = false;
|
|
this.nodOps.active = false;
|
|
},
|
|
|
|
// 召唤数据刷新
|
|
updateSummonData: function() {
|
|
|
|
const SC = SummonMod.getInstance();
|
|
const SM = SC.getModel();
|
|
const data = SM.getSummonGroupData();
|
|
|
|
// 数据无效,重新请求
|
|
if( nx.dt.arrEmpty( data ) ) {
|
|
SC.send23200( ( _data ) => {
|
|
this.updateSummonData();
|
|
} );
|
|
return;
|
|
}
|
|
|
|
// 获取当前页数据
|
|
let info = null;
|
|
for( let i in data ) {
|
|
let t = data[ i ];
|
|
if( t && t.group_id == this.sumId ) {
|
|
info = t;
|
|
break;
|
|
}
|
|
}
|
|
|
|
// 更新
|
|
this.updateData( info );
|
|
|
|
},
|
|
|
|
// 基础更新
|
|
updateBase: function( _data ) {
|
|
|
|
// 无效配置
|
|
if( nx.dt.objEmpty( _data ) ||
|
|
!nx.dt.numPositive( _data.camp_id, false ) ) {
|
|
this.setEmpty();
|
|
return;
|
|
}
|
|
|
|
// 召唤配置
|
|
const DATA = game.configs.infinite_ten_recruit_data;
|
|
const camp = DATA.data_action[ _data.camp_id ];
|
|
const cfgs = DATA.data_summon[ camp.group_id ];
|
|
if( nx.dt.objEmpty( cfgs ) ) {
|
|
nx.error( "无效召唤配置:", _data.camp_id );
|
|
this.setEmpty();
|
|
return;
|
|
}
|
|
|
|
// 背景图
|
|
// let path = cc.path.join( "resDB/bigs", cfgs.call_bg );
|
|
// nx.gui.setSpriteFrame( this, "bg", path );
|
|
|
|
// 看板娘
|
|
// let path = cc.path.join( "resDB/bigs", cfgs.call_bg );
|
|
// nx.gui.setSpriteFrame( this, "panel/role", path );
|
|
|
|
// 广告语
|
|
let path = cc.path.join( "locals", nx.getLocLanguage(), "images/summon", cfgs.word_art );
|
|
nx.gui.setSpriteFrame( this, "panel/word", path );
|
|
|
|
// 货币更新
|
|
let tid = 0;
|
|
if( nx.dt.arrNEmpty( cfgs.loss_item_ten ) &&
|
|
nx.dt.arrNEmpty( cfgs.loss_item_ten[ 0 ] ) ) {
|
|
tid = cfgs.loss_item_ten[ 0 ][ 0 ];
|
|
}
|
|
|
|
// 货币图标设置
|
|
let tinfo = gitemdata( tid );
|
|
if( nx.dt.objEmpty( tinfo ) ) {
|
|
nx.error( "无效召唤货币:", tid );
|
|
} else {
|
|
this.costId = tid;
|
|
this.nodCoin.active = true;
|
|
this.nodCoin.setID( tid );
|
|
}
|
|
|
|
},
|
|
|
|
// 更新数据
|
|
updateData: function( _data ) {
|
|
|
|
// 置空
|
|
if( nx.dt.objEmpty( _data ) ) {
|
|
this.setEmpty();
|
|
return;
|
|
}
|
|
|
|
// 召唤配置
|
|
const DATA = game.configs.infinite_ten_recruit_data;
|
|
const camp = DATA.data_action[ _data.camp_id ];
|
|
const cfgs = DATA.data_summon[ camp.group_id ];
|
|
if( nx.dt.objEmpty( cfgs ) ) {
|
|
nx.error( "无效召唤配置:", _data.camp_id );
|
|
this.setEmpty();
|
|
return;
|
|
}
|
|
|
|
// 更新当前货币
|
|
// 消耗修正
|
|
let count = this.updateCoin();
|
|
let autoOp = function( _node, _item ) {
|
|
|
|
let ret = {
|
|
enough: false,
|
|
type: SCRT.Item,
|
|
item: _item[ 0 ] || [],
|
|
};
|
|
|
|
// 所需道具不足 && 但是有替代品
|
|
let bid = ret.item[ 0 ];
|
|
let need = ret.item[ 1 ];
|
|
ret.enough = ( count >= need );
|
|
|
|
// 参数补充
|
|
ret.bid = bid;
|
|
ret.need = need;
|
|
|
|
// 货币刷新
|
|
let tinfo = gitemdata( bid );
|
|
nx.bridge.setIcon( _node, "need/list/icon", tinfo.icon );
|
|
nx.gui.setString( _node, "need/list/num", need );
|
|
|
|
return ret;
|
|
}
|
|
|
|
this.nodOps.active = true;
|
|
|
|
let rec = nx.dt.arrNEmpty( _data.partner_bids );
|
|
nx.gui.setActive( this.nodOps, "record", rec );
|
|
nx.gui.setActive( this.nodOps, "ten", !rec );
|
|
|
|
let ten = nx.gui.find( this.nodOps, "ten" );
|
|
this.tenArgs = autoOp( ten, cfgs.loss_item_ten );
|
|
|
|
},
|
|
|
|
// 当前改变
|
|
onCurrentChanged: function( _lst ) {
|
|
let empty = nx.dt.arrEmpty( _lst );
|
|
nx.gui.setActive( this.nodOps, "record", !empty );
|
|
nx.gui.setActive( this.nodOps, "ten", empty );
|
|
},
|
|
|
|
// 更新当前货币
|
|
updateCoin: function() {
|
|
const BC = BackPackController.getInstance();
|
|
let count = BC.getModel().getBackPackItemNumByBid( this.costId );
|
|
return count;
|
|
},
|
|
|
|
// 点击货币
|
|
onTouchCoin: function() {
|
|
|
|
},
|
|
|
|
// 点击说明
|
|
onTouchRule: function() {
|
|
|
|
// 召唤配置
|
|
const DATA = game.configs.infinite_ten_recruit_data;
|
|
const camp = DATA.data_action[ this.data.camp_id ];
|
|
if( nx.dt.objEmpty( camp ) ) {
|
|
nx.error( "无效召唤配置:", this.data.camp_id );
|
|
return;
|
|
}
|
|
|
|
let params = {
|
|
desc: camp.desc,
|
|
rates: [],
|
|
};
|
|
|
|
const pros = DATA.data_probability[ camp.group_id ];
|
|
for( let i in pros ) {
|
|
let t = pros[ i ];
|
|
params.rates.push( [
|
|
t.name,
|
|
t.probability,
|
|
] );
|
|
}
|
|
|
|
nx.bridge.createPanel( "WndSummonRateShow", params );
|
|
|
|
},
|
|
|
|
// 点击十次召唤
|
|
onTouchTen: function() {
|
|
this.doSummon( 10, this.tenArgs );
|
|
},
|
|
|
|
// 召唤请求
|
|
doSummon: function( _times, _args ) {
|
|
|
|
// 沒有次數了
|
|
let times = nx.bridge.vget( "INFTimes" );
|
|
if( times <= 0 ) {
|
|
nx.tbox( "SummonTimesNotEnough" );
|
|
return;
|
|
}
|
|
|
|
// 不够召唤处理
|
|
if( !_args.enough ) {
|
|
nx.tbox( "SummonItemNotEnough" );
|
|
return;
|
|
}
|
|
|
|
// 容量检查
|
|
if( !this.checkVolume( _times ) ) {
|
|
nx.tbox( "PartnerBagFull" );
|
|
nx.bridge.jumper.jump2Window( FID.Recycle );
|
|
return;
|
|
}
|
|
|
|
const self = this;
|
|
const SC = SummonMod.getInstance();
|
|
|
|
let args = {
|
|
op: "infinite",
|
|
cb: function( _ret ) {
|
|
|
|
if( !_ret ) {
|
|
self.onTouchTen();
|
|
return;
|
|
}
|
|
|
|
nx.mbox( "SummonInfinite", [ 'no', 'yes' ], ( _key, _box ) => {
|
|
_box.close();
|
|
if( _key == 'yes' ) {
|
|
nx.bridge.summonAnimation.doStop();
|
|
SC.reqInfiniteConfirm( 0, ( _ok, _data ) => {
|
|
|
|
// 发送引导事件
|
|
if( nx.bridge.plot ) {
|
|
nx.bridge.plot.postKey( "infinite_done" );
|
|
}
|
|
|
|
if( !_ok ) {
|
|
nx.tbox( _data );
|
|
return;
|
|
}
|
|
|
|
self.onEnable();
|
|
} );
|
|
}
|
|
} );
|
|
|
|
}
|
|
};
|
|
|
|
SC.reqInfiniteSummon( ( _ok, _data ) => {
|
|
|
|
// 失败
|
|
if( !_ok ) {
|
|
nx.tbox( _data );
|
|
return;
|
|
}
|
|
|
|
// 判空
|
|
if( nx.dt.arrEmpty( _data.partner_bids ) ) {
|
|
nx.warn( "$Summon:空召唤跳过!" );
|
|
return;
|
|
}
|
|
|
|
// 动画
|
|
nx.bridge.summonAnimation.doStart();
|
|
nx.bridge.summonAnimation.setResult( _data, args, () => {
|
|
self.updateSummonData();
|
|
} );
|
|
|
|
} );
|
|
|
|
},
|
|
|
|
// 背包容量检查
|
|
checkVolume: function( _count ) {
|
|
|
|
const HC = HeroController.getInstance();
|
|
const HM = HC.getModel();
|
|
|
|
// 背包容量判断
|
|
let bagInfo = HM.getHeroMaxCount();
|
|
let remains = bagInfo.max_count - bagInfo.have_coutn;
|
|
return _count <= remains;
|
|
},
|
|
|
|
// 点击上次结果
|
|
onTouchRecord: function() {
|
|
|
|
// 判空
|
|
if( nx.dt.objEmpty( this.data ) ) {
|
|
return;
|
|
}
|
|
|
|
let SC = SummonMod.getInstance();
|
|
let self = this;
|
|
let args = {
|
|
op: "infinite",
|
|
cb: function( _ret ) {
|
|
|
|
if( !_ret ) {
|
|
self.onTouchTen();
|
|
return;
|
|
}
|
|
|
|
nx.mbox( "SummonInfinite", [ 'no', 'yes' ], ( _key, _box ) => {
|
|
_box.close();
|
|
if( _key == 'yes' ) {
|
|
nx.bridge.summonAnimation.doStop();
|
|
SC.reqInfiniteConfirm( 0, ( _ok, _data ) => {
|
|
|
|
// 发送引导事件
|
|
if( nx.bridge.plot ) {
|
|
nx.bridge.plot.postKey( "infinite_done" );
|
|
}
|
|
|
|
if( !_ok ) {
|
|
nx.tbox( _data );
|
|
return;
|
|
}
|
|
|
|
self.onEnable();
|
|
} );
|
|
}
|
|
} );
|
|
|
|
}
|
|
};
|
|
|
|
nx.bridge.summonAnimation.jumpToFlipCards( {
|
|
partner_bids: nx.bridge.vget( "INFCurrent" )
|
|
}, args, () => {
|
|
this.updateSummonData();
|
|
} );
|
|
|
|
},
|
|
|
|
// ------------------------------------------------------
|
|
// 记录暂存
|
|
// ------------------------------------------------------
|
|
|
|
// 剩余次数
|
|
onRemainTimes: function( _times ) {
|
|
|
|
let times = _times || 0;
|
|
// if( times <= 0 ) {
|
|
// this.labTimes.active = false;
|
|
// return;
|
|
// }
|
|
|
|
// this.labTimes.active = true;
|
|
let DATA = game.configs.infinite_ten_recruit_data;
|
|
let max = DATA ? DATA.data_const.max_count.val : 0;
|
|
nx.gui.setString( this.labTimes, "times", `${ _times }/${ max }` );
|
|
},
|
|
|
|
// 打开暂存界面
|
|
onTouchSaveRecords: function() {
|
|
nx.bridge.createPanel( "WndSummonInfiniteRecord", { replace: false } );
|
|
},
|
|
|
|
onTouchRecommend: function(){
|
|
|
|
nx.bridge.createPanel( "WndPopRecommend" );
|
|
|
|
},
|
|
|
|
} );
|