Files

247 lines
6.9 KiB
JavaScript
Raw Permalink Normal View History

2026-05-23 22:10:14 +08:00
/*******************************************************************************
*
* 活动: 限定招募
*
*
******************************************************************************/
const ActBase = require( "act.base" );
const BackPackController = require( "backpack_controller" );
const ActSummonLimit4 = 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( 16660, this.handle16660.bind( this ) );
this.RegisterProtocal( 16661, this.handle16661.bind( this ) );
},
// 从服务器初始化数据
reqBaseFromServer: function( _cb ) {
// 配置加载
let cfgs = [
"holiday_theme_pool_data"
];
this.loadConfigs( cfgs, ( _ret, _data ) => {
nx.dt.fnInvoke( _cb, true );
this.reqBaseData();
} );
},
// ============================================================
// 基本操作
// ============================================================
// 请求基本信息
reqBaseData: function( _cb ) {
this.manager.reqActData( this.data.camp_id, ( _ret, _params ) => {
this.freshTips();
nx.dt.fnInvoke( _cb, _ret, _params );
} );
},
// ============================================================
// 配置相关
// ============================================================
// 获取配置
queryConfigs: function() {
if( nx.dt.objNEmpty( this.configs ) ) {
return this.configs;
}
const DATA = game.configs.holiday_theme_pool_data;
if( DATA && DATA.data_group_const ) {
for( let id in DATA.data_group_const ) {
let ifo = DATA.data_group_const[ id ];
if( ifo && ifo.holiday_id == this.data.camp_id ) {
this.configs = ifo;
break;
}
}
}
if( nx.dt.objEmpty( this.configs ) ) {
nx.error( `$SummonLimit:配置缺失! ${ this.data.camp_id }` );
}
return this.configs;
},
// 获取规则文本
queryRule: function() {
const DATA = game.configs.holiday_theme_pool_data;
if( !DATA || !DATA.data_get_rules || !this.configs ) {
nx.error( `$SummonLimit:规则获取失败! ${ this.data.camp_id }` );
return "";
}
let rule = DATA.data_get_rules[ this.configs.group_id ];
if( !rule || !rule["1"] || nx.dt.strEmpty( rule["1"].content ) ) {
return "";
}
return rule["1"].content;
},
// 获取道具数量
itemHave: function() {
if( nx.dt.objEmpty( this.configs ) ||
!nx.dt.numPositive( this.configs.prop_id, false ) ) {
nx.error( `$SummonLimit:获取道具数量失败! ${ this.data.camp_id }` );
return 0;
}
const BC = BackPackController.getInstance();
return BC.getModel().getBackPackItemNumByBid( this.configs.prop_id );
},
// ============================================================
// 抽奖操作
// ============================================================
// 抽奖请求
reqRaffle: function( _group_id, _once, _cb ) {
this.manager.reqDrawFromPool( _group_id, 1, _once ? 1 : 2, _cb );
},
// ============================================================
// 积分兑换
// ============================================================
// 请求商品列表
reqScoreProducts: function( _cb ) {
if( nx.dt.objNEmpty( this.products ) ) {
nx.dt.fnInvoke( _cb, true, this.products );
return;
}
this.cb16660 = _cb;
this.SendProtocal( 16660, {} );
},
// 请求商品列表返回
handle16660: function( _data ) {
if( !this.isGoodData( _data ) ) {
return;
}
let arr = _data.holiday_exchanges || [];
for( let i = 0; i < arr.length; ++i ) {
let tmp = arr[i];
if( tmp && tmp.bid == this.data.camp_id ) {
this.products = tmp;
break;
}
}
nx.dt.fnInvoke( this.cb16660, true, this.products );
this.cb16660 = null;
},
// 请求商品兑换
reqScoreBuy: function( _tid, _count, _cb ) {
this.cb16661 = _cb;
this.SendProtocal( 16661, {
bid: this.data.camp_id,
aim: _tid,
num: _count,
} );
},
// 请求商品列表返回
handle16661: function( _data ) {
if( !this.isGoodData( _data ) ) {
return;
}
// 次数更新
for( let i = 0; i < this.products.exchange_list.length; ++i ) {
let prod = this.products.exchange_list[i];
if( prod && prod.aim == _data.aim ) {
prod.buy_count += _data.buy_count;
nx.dt.fnInvoke( this.cb16661, true, prod );
break;
}
}
this.cb16661 = null;
},
// ============================================================
// 活动红点提示
// ============================================================
// 道具更新
onBagItemUpdate: function( _bagCode, _itemList ) {
let id = this.configs ? this.configs.prop_id : -1;
for( let k in _itemList ) {
let tm = _itemList[ k ];
if( tm && tm.base_id == id ) {
this.freshTips();
break;
}
}
},
// 活动用到的提示KEY
tipKeys: function() {
return [ "once", "ten" ];
},
// 红点提示更新
freshTips: function() {
this.openTip( "reward", false );
if( !this.configs ) {
this.openTip( "once", false );
this.openTip( "ten", false );
return;
}
let count = this.itemHave();
this.openTip( "once", count >= this.configs.draw_one[ 0 ][ 1 ] );
this.openTip( "ten", count >= this.configs.draw_ten[ 0 ][ 1 ] );
},
} );
// 模块导出
module.exports = ActSummonLimit4;