Files
2026-05-23 22:10:14 +08:00

453 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 RoleController = require( "role_controller" );
const BackPackController = require( "backpack_controller" );
const BridgeItemBinder = require( "bridge.binder.item.icon.count" );
const FID = require( "bridge.function.ids" );
const SCRK = SummonDefine.Recruit_Key;
const SCST = SummonDefine.Summon_Type;
const SCRT = SummonDefine.Status;
const EmptyBG = "";
cc.Class( {
extends: MenuPage,
properties: {
sumId: { default: 0 },
nodOps: { default: null, type: cc.Node },
nodCoin: { default: null, type: BridgeItemBinder },
},
// 载入
onLoad: function() {
this._super();
this.bindId( this.sumId );
},
// 显示
onEnable: function() {
// 事件监听
this.bindGEvent(
SummonDefine.UpdateSummonDataEvent,
this.updateSummonData.bind( this ) );
// 主动更新
this.updateSummonData();
},
// 关闭
onDisable: function() {
this.setFreeCD();
this.unbindGEvents();
},
// 置空
setEmpty: function() {
// nx.gui.setSpriteFrame( this, "bg", EmptyBG );
this.costId = 0;
this.setFreeCD();
this.nodCoin.active = false;
this.nodOps.active = false;
},
// 设置召唤库编号
bindId: function( _id ) {
this.sumId = _id;
// 召唤配置
const DATA = game.configs.recruit_data.data_partnersummon_data;
const info = DATA ? DATA[ _id ] : null;
if( nx.dt.objEmpty( info ) ) {
nx.error( "无效召唤配置:", _id );
this.setEmpty();
return false;
}
// 背景图
// let path = cc.path.join( "resDB/bigs", info.call_bg );
// nx.gui.setSpriteFrame( this, "bg", path );
// // 看板娘
// path = cc.path.join( "resDB/bigs", info.card_bg_res );
// nx.gui.setSpriteFrame( this, "panel/role", path );
// 广告语
let path = cc.path.join( "locals", nx.getLocLanguage(), "images/summon", info.word_art );
nx.gui.setSpriteFrame( this, "panel/word", path );
// 货币更新
let tid = 0;
if( nx.dt.arrNEmpty( info.item_once ) &&
nx.dt.arrNEmpty( info.item_once[ 0 ] ) ) {
tid = info.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 );
}
return true;
},
// 召唤数据刷新
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 );
},
// 更新数据
updateData: function( _data ) {
// 置空
if( nx.dt.objEmpty( _data ) ) {
this.setEmpty();
return;
}
// 参数配置缺失
let rdata = _data.recruit_data;
let cfgs = _data.config_data;
if( nx.dt.objEmpty( rdata ) || nx.dt.objEmpty( cfgs ) ) {
nx.error( "召唤更新失败,配置缺失!" );
this.setEmpty();
return;
}
const BC = BackPackController.getInstance();
const BM = BC.getModel();
// 更新当前货币
// 消耗修正
let count = this.updateCoin();
let autoOp = function( _node, _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 ) ) {
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 = this.evalFreeOnce( rdata.draw_list );
this.onceArgs = autoOp( once, dtFree, cfgs.item_once, cfgs.exchange_once, cfgs.exchange_once_gain );
this.tenArgs = autoOp( ten, -1, cfgs.item_five, cfgs.exchange_five, cfgs.exchange_five_gain );
// 免费倒计时
this.setFreeCD( dtFree );
},
// 更新当前货币
updateCoin: function() {
// 友情点
let count = 0;
if( this.sumId == SCST.Friend ) {
const RC = RoleController.getInstance();
const role = RC.getRoleVo();
if( role ) {
count = role.friend_point;
}
}
else {
const BC = BackPackController.getInstance();
count = BC.getModel().getBackPackItemNumByBid( this.costId );
}
// nx.gui.setString( this.nodCoin, "txt", nx.dt.shortCount( count ) );
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();
},
// 单次免费评估
evalFreeOnce: function( _draws ) {
let dtFree = -1; // -1不免费 0免费 >0下次时间
if( nx.dt.arrEmpty( _draws ) ) {
return dtFree;
}
let ifo = null;
for( let i in _draws ) {
if( _draws[ i ] && _draws[ i ].times == 1 ) {
ifo = _draws[ i ];
break;
}
}
if( ifo && nx.dt.arrNEmpty( ifo.kv_list ) ) {
for( let k in ifo.kv_list ) {
let kt = ifo.kv_list[ k ];
if( !kt || !nx.dt.numPositive( kt.val, false ) ) {
continue;
}
// 有免费次数
if( kt.key == SCRK.Free_Count ) {
dtFree = 0;
break;
}
// 下次免费时间
if( kt.key == SCRK.Free_Time ) {
dtFree = kt.val;
}
}
}
return dtFree;
},
// 点击货币
onTouchCoin: function() {
},
// 点击单次召唤
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;
let buy_ori = nx.text.format( "tip_diamondConsume", 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( des_str, [ '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 = SummonMod.getInstance();
SC.send23201( this.sumId, _times, _type, ( _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;
},
} );