Files
fc/dev/project/assets/Scripts/mod/acts/blindBox/act.blind.box.mod.js
T

211 lines
6.0 KiB
JavaScript
Raw Normal View History

2026-05-23 22:10:14 +08:00
/*******************************************************************************
*
* 活动:开盲盒
*
*
******************************************************************************/
const ActBase = require( "act.base" );
const BackPackController = require( "backpack_controller" );
const HeroController = require( "hero_controller" );
const ActBlindBoxMod = cc.Class( {
extends: ActBase,
// 初始化配置数据
initConfig: function() {
// 视图附着
nx.plugin.add( this, [ "view" ] );
this.vattach( "Acts" );
},
// 注册监听事件
registerEvents: function() {
if( !!this.bagEvent1 ) {
gcore.GlobalEvent.unbind( this.bagEvent1 );
gcore.GlobalEvent.unbind( this.bagEvent2 );
gcore.GlobalEvent.unbind( this.bagEvent3 );
this.bagEvent1 = null;
this.bagEvent2 = null;
this.bagEvent3 = null;
}
this.bagEvent1 = gcore.GlobalEvent.bind( EventId.ADD_GOODS, this.onBagItemUpdate.bind( this ) );
this.bagEvent2 = gcore.GlobalEvent.bind( EventId.DELETE_GOODS, this.onBagItemUpdate.bind( this ) );
this.bagEvent3 = gcore.GlobalEvent.bind( EventId.MODIFY_GOODS_NUM, this.onBagItemUpdate.bind( this ) );
},
// 注册协议接受事件
registerProtocals: function() {
this.RegisterProtocal( 31130, this.handle31130.bind( this ) );
this.RegisterProtocal( 31131, this.handle31131.bind( this ) );
},
// 从服务器初始化数据
reqBaseFromServer: function( _cb ) {
// 配置加载
let cfgs = [
"holiday_blind_box_data"
];
this.loadConfigs( cfgs, ( _ret, _data ) => {
nx.dt.fnInvoke( _cb, true );
this.configs = this.queryConfigs( this.data.camp_id );
this.freshTips();
} );
},
// ============================================================
// 基本操作
// ============================================================
// 点击预抽奖
reqPreRaffle: function( _once, _cb ) {
this.SendProtocal( 31130, {
camp_id: this.data.camp_id,
times: _once ? 1 : 10,
}, _cb );
},
handle31130: function( _data ) {
if( !this.isGoodData( _data ) ) {
return;
}
},
// 点击抽奖
reqRaffle: function( _once, _cb ) {
this.SendProtocal( 31131, {
camp_id: this.data.camp_id,
times: _once ? 1 : 10,
}, _cb );
},
handle31131: function( _data ) {
if( !this.isGoodData( _data ) ) {
return;
}
},
// ============================================================
// 道具相关
// ============================================================
// 道具更新
onBagItemUpdate: function( _bagCode, _itemList ) {
let id1 = this.configs ? this.configs.item_id : -1;
let id2 = this.configs ? this.configs.skin_debris_id[ 0 ] : -1;
for( let k in _itemList ) {
let tm = _itemList[ k ];
if( tm.base_id == id1 || tm.base_id == id2 ) {
this.freshTips();
break;
}
}
},
// 获取道具数量
itemHave: function() {
if( nx.dt.objEmpty( this.configs ) ||
!nx.dt.numPositive( this.configs.item_id, false ) ) {
nx.error( `$SummonLimit:获取道具数量失败! ${ this.data.camp_id }` );
return 0;
}
const BC = BackPackController.getInstance();
return BC.getModel().getBackPackItemNumByBid( this.configs.item_id );
},
// ============================================================
// 活动红点提示
// ============================================================
// 活动用到的提示KEY
tipKeys: function() {
return [ "once", "ten" ];
},
// 红点提示更新
freshTips: function() {
this.openTip( "reward", false );
if( !this.configs ) {
this.openTip( "once", false );
this.openTip( "ten", false );
this.vset( "BlindBoxCombine", 0 );
return;
}
// 抽取提示
let count = this.itemHave();
this.openTip( "once", count >= this.configs.loss_item_once[ 0 ][ 1 ] );
this.openTip( "ten", count >= this.configs.loss_item_ten[ 0 ][ 1 ] );
// 皮肤已有
let flag = 0;
let HC = HeroController.getInstance();
let HM = HC.getModel();
let owned = HM.hero_skin_list || {};
let have = nx.dt.numGood( owned[ this.configs.skin_id ] );
if( have ) {
flag = 2;
} else {
// 合成提示
let id = this.configs.skin_debris_id[ 0 ];
let BC = BackPackController.getInstance();
let num = BC.getModel().getBackPackItemNumByBid( id );
if( num >= this.configs.skin_debris_id[ 1 ] ) {
flag = 1;
}
}
this.vset( "BlindBoxCombine", flag );
},
// ============================================================
// 配置相关
// ============================================================
// 获取配置
queryConfigs: function( _campId ) {
const DATA = game.configs.holiday_blind_box_data;
if( !DATA ) {
nx.error( `$BlindBox:配置表缺失!` );
return null;
}
let info = DATA.data_summon[ this.data.camp_id ];
if( !info ) {
nx.error( `$BlindBox:配置缺失! ${ this.data.camp_id }` );
return null;
}
return nx.dt.objClone( info );
},
// 获取规则
queryRule: function() {
const DATA = game.configs.holiday_blind_box_data;
if( !DATA ) {
nx.error( `$BlindBox:配置规则缺失!` );
return "";
}
return DATA.data_const.txt_data.desc;
},
} );
// 模块导出
module.exports = ActBlindBoxMod;