555 lines
16 KiB
JavaScript
555 lines
16 KiB
JavaScript
/******************************************************************
|
|
* Copyright(C) 2019 - 2020 Nx Studio
|
|
*
|
|
* 精英召唤主界面
|
|
*
|
|
* 2018.05.18
|
|
******************************************************************/
|
|
|
|
const ActPage = require( "act.page.base" );
|
|
const SummonDefine = require( "summon.define" );
|
|
const EliteMod = require( "act.elite.mod" );
|
|
const HeroController = require( "hero_controller" );
|
|
const RoleController = require( "role_controller" );
|
|
const BackPackController = require( "backpack_controller" );
|
|
const BridgeItemBinder = require( "bridge.binder.item.icon.count" );
|
|
const MALL = require( "mall_controller" );
|
|
const MallConst = require( "mall_const" );
|
|
|
|
const FID = require( "bridge.function.ids" );
|
|
|
|
const NxSpine = require( "nx.fx.spine" );
|
|
|
|
const SCRT = SummonDefine.Status;
|
|
|
|
cc.Class( {
|
|
|
|
extends: ActPage,
|
|
|
|
properties: {
|
|
nodOps: { default: null, type: cc.Node },
|
|
spRole: { default: null, type: NxSpine },
|
|
spMini: { default: null, type: NxSpine },
|
|
nodInfo: { default: null, type: cc.Node },
|
|
nodTarget: { default: null, type: cc.Node },
|
|
nodDate: { default: null, type: cc.Node },
|
|
nodCoin: { default: null, type: BridgeItemBinder },
|
|
nodGTimes: { default: null, type: cc.Node },
|
|
},
|
|
|
|
// 初始化
|
|
build: function( _data ) {
|
|
|
|
this._super( _data );
|
|
|
|
let model = EliteMod.getInstance();
|
|
if( !model ) {
|
|
nx.tbox( "尚未开启" );
|
|
return;
|
|
}
|
|
|
|
// 视图监听
|
|
model.vbind( this, [
|
|
[ "eliteBase", this.onFreshBase.bind( this ) ],
|
|
[ "eliteTimes", this.onFreshTimes.bind( this ) ],
|
|
] );
|
|
|
|
this.setEmpty();
|
|
model.fetchData();
|
|
},
|
|
|
|
// 关闭
|
|
onDestroy: function() {
|
|
|
|
// 视图监听
|
|
let model = EliteMod.getInstance();
|
|
if( model ) {
|
|
model.vunbind( this );
|
|
}
|
|
|
|
this.setFreeCD();
|
|
},
|
|
|
|
// 置空
|
|
setEmpty: function() {
|
|
|
|
this.costId = 0;
|
|
this.setFreeCD();
|
|
|
|
nx.gui.setActive( this, "right/panel/select", false );
|
|
nx.gui.setActive( this, "right/panel/open", false );
|
|
},
|
|
|
|
// 基本信息
|
|
onFreshBase: function( _info, _old, _init ) {
|
|
|
|
let model = EliteMod.getInstance();
|
|
if( !model || _init || nx.dt.objEmpty( _info ) ) {
|
|
return;
|
|
}
|
|
|
|
// 首选
|
|
if( !nx.dt.numPositive( _info.lucky_bid, false ) ) {
|
|
nx.gui.setActive( this, "right/panel/open", false );
|
|
nx.gui.setActive( this, "right/panel/select", true );
|
|
return;
|
|
}
|
|
|
|
nx.gui.setActive( this, "right/panel/select", false );
|
|
nx.gui.setActive( this, "right/panel/open", true );
|
|
|
|
// 英雄信息
|
|
const DATA = game.configs.recruit_holiday_lucky_data;
|
|
const camp = DATA.data_action[ _info.camp_id ];
|
|
const info = DATA.data_summon[ camp.group_id ];
|
|
|
|
// 货币更新
|
|
let tid = 0;
|
|
if( nx.dt.arrNEmpty( info.loss_item_once ) &&
|
|
nx.dt.arrNEmpty( info.loss_item_once[ 0 ] ) ) {
|
|
tid = info.loss_item_once[ 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, () => {
|
|
this.onFreshTimes();
|
|
} );
|
|
}
|
|
|
|
const bid = _info.lucky_bid;
|
|
const dat = game.configs.partner_data.data_partner_base[ bid ];
|
|
const star = dat.init_star || ( dat ? dat.star : 0 );
|
|
const scfgs = gdata( "partner_data", "data_partner_star", `${ bid }_${ star }` );
|
|
if( nx.dt.objEmpty( scfgs ) ) {
|
|
nx.error( "精英召唤角色无效:", bid );
|
|
return;
|
|
}
|
|
|
|
// 名字
|
|
nx.gui.setString( this.nodInfo, "base/name", nx.text.getKey( dat.name ) );
|
|
|
|
// 品质
|
|
let path = cc.path.join( "coms/images", "mk_partner_qa" + dat.quality );
|
|
nx.gui.setSpriteFrame( this.nodInfo, "qa", path );
|
|
|
|
// 阵营
|
|
path = cc.path.join( "prefab/partner/ui/camp" + dat.camp_type );
|
|
nx.gui.setSpriteFrame( this.nodInfo, "base/camp", path );
|
|
|
|
// 星级
|
|
path = cc.path.join( "coms/images/star" + dat.init_star );
|
|
nx.gui.setSpriteFrame( this.nodInfo, "stars", path );
|
|
|
|
// 角色动画
|
|
let act = "action1";
|
|
let WISH = DATA.data_wish[ _info.camp_id ];
|
|
if( WISH ) {
|
|
for( let id in WISH ) {
|
|
if( id == bid ) {
|
|
act = WISH[ id ].action;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
path = PathTool.getSpinePath( scfgs.res_id, "show", false );
|
|
this.spRole.load( path, ( _e ) => {
|
|
if( !_e ) {
|
|
this.spRole.action( act, true );
|
|
} else {
|
|
this.spRole.stop();
|
|
}
|
|
} );
|
|
|
|
// MINI动画
|
|
path = PathTool.getSpinePath( scfgs.res_id, scfgs.res_id, false );
|
|
this.spMini.load( path, ( _e ) => {
|
|
if( !_e ) {
|
|
this.spMini.action( "stand2", true );
|
|
} else {
|
|
this.spMini.stop();
|
|
}
|
|
} );
|
|
|
|
// 技能
|
|
let sknode = nx.gui.find( this.nodInfo, "skills" );
|
|
for( let i = 0; i < sknode.children.length; ++i ) {
|
|
|
|
// 技能数组[0]为普攻,直接忽略,最多4个技能
|
|
let item = sknode.children[ i ];
|
|
let sifo = scfgs.skills[ i + 1 ];
|
|
if( !sifo ) {
|
|
item.active = false;
|
|
continue;
|
|
}
|
|
|
|
item.active = true;
|
|
let cmp = nx.gui.getComponent( item, "", "cmp.skill.base" );
|
|
if( cmp ) {
|
|
cmp.setData( sifo[ 1 ] );
|
|
}
|
|
}
|
|
|
|
// 目标英雄
|
|
let icon = nx.gui.getComponent( this.nodTarget, "icon", "cmp.item.base" );
|
|
icon.setData( _info.lucky_bid );
|
|
|
|
// 免费
|
|
let tip = nx.gui.getComponent( this.nodOps, "once/tip", "nx.vb.visible" );
|
|
if( tip ) {
|
|
let key = model.getTipKey( "free" );
|
|
tip.setTarget( nx.mTip, key );
|
|
}
|
|
|
|
},
|
|
|
|
// 次数信息
|
|
onFreshTimes: function( _cur, _old, _init ) {
|
|
|
|
if( _init ) return;
|
|
|
|
let model = EliteMod.getInstance();
|
|
let base = model ? model.vget( "eliteBase" ) : null;
|
|
let times = model ? model.vget( "eliteTimes" ) : null;
|
|
if( nx.dt.objEmpty( base ) ||
|
|
nx.dt.objEmpty( times ) ) {
|
|
return;
|
|
}
|
|
|
|
const DATA = game.configs.recruit_holiday_lucky_data;
|
|
const camp = DATA.data_action[ base.camp_id ];
|
|
const cfgs = DATA.data_summon[ camp.group_id ];
|
|
|
|
const BC = BackPackController.getInstance();
|
|
const BM = BC.getModel();
|
|
|
|
// 更新当前货币
|
|
// 消耗修正
|
|
let count = this.updateCoin();
|
|
let autoOp = function( _node, _times, _freeDt, _item, _exchange, _exchangeInfo ) {
|
|
|
|
let ret = {
|
|
enough: false,
|
|
type: SCRT.Item,
|
|
time: _freeDt,
|
|
item: _item[ 0 ] || [],
|
|
exc: _exchange[ 0 ] || [],
|
|
excInfo: _exchangeInfo[ 0 ] || [],
|
|
};
|
|
|
|
// 所需道具不足 && 但是有替代品
|
|
let bid = ret.item[ 0 ];
|
|
let need = ret.item[ 1 ];
|
|
if( count < need &&
|
|
nx.dt.arrNEmpty( ret.exc ) &&
|
|
times.gold_time >= _times ) {
|
|
bid = ret.exc[ 0 ];
|
|
need = ret.exc[ 1 ];
|
|
let cnt = BM.getBackPackItemNumByBid( bid );
|
|
ret.enough = ( cnt >= need );
|
|
ret.type = SCRT.Diamond;
|
|
}
|
|
else {
|
|
ret.enough = ( count >= need );
|
|
}
|
|
|
|
// 参数补充
|
|
ret.bid = bid;
|
|
ret.need = need;
|
|
|
|
// 免费
|
|
if( _freeDt == 0 ) {
|
|
ret.enough = true;
|
|
ret.type = SCRT.Free;
|
|
nx.gui.setActive( _node, "need/list", false );
|
|
nx.gui.setActive( _node, "need/free", true );
|
|
nx.gui.setActive( _node, "freeCD", false );
|
|
return ret;
|
|
}
|
|
|
|
nx.gui.setActive( _node, "need/list", true );
|
|
nx.gui.setActive( _node, "need/free", false );
|
|
|
|
// 货币刷新
|
|
let tinfo = gitemdata( bid );
|
|
nx.bridge.setIcon( _node, "need/list/icon", tinfo.icon );
|
|
nx.gui.setString( _node, "need/list/num", need );
|
|
|
|
// 免费倒计时
|
|
nx.gui.setActive( _node, "freeCD", _freeDt > 0 );
|
|
return ret;
|
|
}
|
|
|
|
this.nodOps.active = true;
|
|
let once = nx.gui.find( this.nodOps, "once" );
|
|
let ten = nx.gui.find( this.nodOps, "ten" );
|
|
let dtFree = times.free_time;
|
|
this.onceArgs = autoOp( once, 1, dtFree, cfgs.loss_item_once, cfgs.loss_gold_once, cfgs.gain_once );
|
|
this.tenArgs = autoOp( ten, 10, -1, cfgs.loss_item_ten, cfgs.loss_gold_ten, cfgs.gain_ten );
|
|
|
|
// 免费倒计时
|
|
this.setFreeCD( dtFree );
|
|
|
|
// 活动日期
|
|
let secs = base.end_time - client.socket.getTime();
|
|
if( !nx.dt.numPositive( secs, false ) ) {
|
|
nx.gui.setActive( this.nodDate, "txt", false );
|
|
nx.gui.setActive( this.nodDate, "done", true );
|
|
}
|
|
else {
|
|
nx.gui.setActive( this.nodDate, "txt", true );
|
|
nx.gui.setActive( this.nodDate, "done", false );
|
|
nx.gui.setCdTxt( this.nodDate, "txt", secs );
|
|
}
|
|
|
|
// 保底次数
|
|
let txt = nx.text.format( "EliteReleaseTimes", times.must_count );
|
|
nx.gui.setString( this.nodTarget, "times/txt", txt );
|
|
|
|
// 免费次数
|
|
let total = DATA.data_const.diamond_times.val || 20;
|
|
nx.gui.setString( this.nodGTimes, "times", `${times.gold_time}/${total}` );
|
|
|
|
},
|
|
|
|
// 更新当前货币
|
|
updateCoin: function() {
|
|
|
|
const BC = BackPackController.getInstance();
|
|
let count = BC.getModel().getBackPackItemNumByBid( this.costId );
|
|
return count;
|
|
},
|
|
|
|
// 免费倒计时
|
|
setFreeCD: function( _dtFree ) {
|
|
|
|
this.unscheduleAllCallbacks();
|
|
|
|
if( !nx.dt.numPositive( _dtFree, false ) ) {
|
|
return;
|
|
}
|
|
|
|
let self = this;
|
|
let node = nx.gui.find( this.nodOps, "once/freeCD" );
|
|
let tick = function() {
|
|
|
|
let interval = Utils.getTimeInterval( _dtFree );
|
|
if( interval <= 0 ) {
|
|
self.unscheduleAllCallbacks();
|
|
nx.gui.setString( node, "", "" );
|
|
return;
|
|
}
|
|
|
|
let time = Utils.changeIntevalToDate( interval );
|
|
let txt = time.H + ":" + time.M + ":" + time.S;
|
|
nx.gui.setString( node, "", nx.text.format( "FreeCD", txt ) );
|
|
};
|
|
|
|
this.schedule( tick, 1, cc.macro.REPEAT_FOREVER );
|
|
tick();
|
|
|
|
},
|
|
|
|
// 点击单次召唤
|
|
onTouchOnce: function( _ret ) {
|
|
|
|
// 关闭召唤动画界面
|
|
if( _ret == false ) {
|
|
nx.bridge.summonAnimation.doStop();
|
|
return;
|
|
}
|
|
|
|
this.onceArgs.txt = "SummonOnce";
|
|
this.onceArgs.cb = this.onTouchOnce.bind( this );
|
|
this.doSummon( 1, this.onceArgs );
|
|
},
|
|
|
|
// 点击十次召唤
|
|
onTouchTen: function( _ret ) {
|
|
|
|
// 关闭召唤动画界面
|
|
if( _ret == false ) {
|
|
nx.bridge.summonAnimation.doStop();
|
|
return;
|
|
}
|
|
|
|
this.tenArgs.txt = "SummonTen";
|
|
this.tenArgs.cb = this.onTouchTen.bind( this );
|
|
this.doSummon( 10, this.tenArgs );
|
|
},
|
|
|
|
// 召唤请求
|
|
doSummon: function( _times, _args ) {
|
|
|
|
// 容量检查
|
|
if( !this.checkVolume( _times ) ) {
|
|
nx.tbox( "PartnerBagFull" );
|
|
nx.bridge.jumper.jump2Window( FID.Recycle );
|
|
return;
|
|
}
|
|
|
|
// 不够召唤处理
|
|
if( !_args.enough ) {
|
|
|
|
// 道具不足
|
|
if( _args.type == SCRT.Item ) {
|
|
nx.tbox( "SummonItemNotEnough" );
|
|
return;
|
|
}
|
|
|
|
// 替代不足
|
|
if( _args.type == SCRT.Diamond ) {
|
|
|
|
let good_res_path = "3";
|
|
let need_num = _args.exc[ 1 ];
|
|
let hvae_num = RoleController.getInstance().getRoleVo().gold;
|
|
// let val_str = Utils.getItemConfig( _args.excInfo[ 0 ] ).name
|
|
// let val_num = _args.excInfo[ 1 ];
|
|
// let call_num = _times;
|
|
if( hvae_num < need_num ) {
|
|
let self = this;
|
|
let str = nx.text.format( "elfin_hatch_unlock_6", nx.text.getKey( "Dia" ) );
|
|
( str, [ 'cancel', 'GotoCharge' ], ( _key, _box ) => {
|
|
_box.close();
|
|
if( _key == "GotoCharge" ) {
|
|
// this.reqSummon( _args.type, _times, _args );
|
|
// nx.bridge.jumper.jump2Window( FID.Charge );
|
|
self.onTouchGift();
|
|
}
|
|
} );
|
|
|
|
return;
|
|
}
|
|
|
|
this.reqSummon( _args.type, _times, _args );
|
|
// let buy_ori = nx.text.format( "tip_diamondConsume", String( good_res_path ), need_num, hvae_num );
|
|
// // let get_ori = nx.text.format( "tip_buyDesc", val_num, val_str, call_num );
|
|
// // let des_str = buy_ori + get_ori;
|
|
// nx.mbox( buy_ori, [ 'cancel', 'confirm' ], ( _key, _box ) => {
|
|
// _box.close();
|
|
// if( _key == "confirm" ) {
|
|
// this.reqSummon( _args.type, _times, _args );
|
|
// }
|
|
// } );
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
// 召唤
|
|
this.reqSummon( _args.type, _times, _args );
|
|
},
|
|
|
|
// 召唤
|
|
reqSummon: function( _type, _times, _args ) {
|
|
|
|
const self = this;
|
|
const SC = EliteMod.getInstance();
|
|
SC.reqSummon( _times, _type, ( _ret, _data ) => {
|
|
|
|
// 失败
|
|
if( !_ret ) {
|
|
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, () => {
|
|
} );
|
|
|
|
} );
|
|
|
|
},
|
|
|
|
// 背包容量检查
|
|
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;
|
|
},
|
|
|
|
// 点击切换心愿目标
|
|
onTouchChangeTarget: function( _key ) {
|
|
|
|
let model = EliteMod.getInstance();
|
|
let base = model ? model.vget( "eliteBase" ) : null;
|
|
if( nx.dt.objEmpty( base ) ) {
|
|
return;
|
|
}
|
|
|
|
let args = {
|
|
cur: base.lucky_bid,
|
|
camp_id: base.camp_id,
|
|
};
|
|
|
|
// 选择回调
|
|
args.cb = function( _bid ) {
|
|
model.reqTarget( _bid );
|
|
};
|
|
|
|
nx.bridge.createPanel( "WndActEliteSelector", args );
|
|
|
|
},
|
|
|
|
// 点击说明
|
|
onTouchRule: function() {
|
|
|
|
// 召唤配置
|
|
const DATA = game.configs.recruit_holiday_lucky_data;
|
|
const camp = DATA.data_desc[ "1" ];
|
|
|
|
let params = {
|
|
desc: camp.desc,
|
|
rates: [],
|
|
};
|
|
|
|
const pros = DATA.data_probability[ "10001" ];
|
|
for( let i in pros ) {
|
|
let t = pros[ i ];
|
|
params.rates.push( [
|
|
t.name,
|
|
t.probability,
|
|
] );
|
|
}
|
|
|
|
nx.bridge.createPanel( "WndSummonRateShow", params );
|
|
|
|
},
|
|
|
|
// 积分商城
|
|
onTouchScoreShop: function() {
|
|
MALL.getInstance().openMallPanel( true, [ MallConst.MallType.SummonShop, 55 ] );
|
|
},
|
|
|
|
// 点击助力奖励
|
|
onTouchGift: function() {
|
|
|
|
let campId = this.data ? this.data.camp_id : 0;
|
|
let DATA = game.configs.recruit_holiday_lucky_data;
|
|
let info = DATA.data_action[ campId ];
|
|
if( info &&
|
|
this.actRoot &&
|
|
nx.dt.numPositive( info.jump, false ) ) {
|
|
this.actRoot.jumpToMenu( info.jump );
|
|
}
|
|
},
|
|
|
|
} );
|