327 lines
8.9 KiB
JavaScript
327 lines
8.9 KiB
JavaScript
|
|
/*******************************************************************************
|
||
|
|
*
|
||
|
|
* 活动: 限定祈愿
|
||
|
|
*
|
||
|
|
*
|
||
|
|
******************************************************************************/
|
||
|
|
|
||
|
|
const ActBase = require( "act.base" );
|
||
|
|
const BackPackController = require( "backpack_controller" );
|
||
|
|
|
||
|
|
const ActLimitPray = 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( 31140, this.handle31140.bind( this ) );
|
||
|
|
this.RegisterProtocal( 31143, this.handle31143.bind( this ) );
|
||
|
|
this.RegisterProtocal( 31141, this.handle31141.bind( this ) );
|
||
|
|
this.RegisterProtocal( 31142, this.handle31142.bind( this ) );
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
// 从服务器初始化数据
|
||
|
|
reqBaseFromServer: function( _cb ) {
|
||
|
|
|
||
|
|
// 配置加载
|
||
|
|
let cfgs = [
|
||
|
|
"holiday_prayer_theme_pool_data"
|
||
|
|
];
|
||
|
|
this.loadConfigs( cfgs, ( _ret, _data ) => {
|
||
|
|
nx.dt.fnInvoke( _cb, true );
|
||
|
|
this.reqBaseData();
|
||
|
|
} );
|
||
|
|
},
|
||
|
|
|
||
|
|
// ============================================================
|
||
|
|
// 配置相关
|
||
|
|
// ============================================================
|
||
|
|
|
||
|
|
// 获取配置
|
||
|
|
queryConfigs: function() {
|
||
|
|
|
||
|
|
if( nx.dt.objNEmpty( this.configs ) ) {
|
||
|
|
return this.configs;
|
||
|
|
}
|
||
|
|
|
||
|
|
const DATA = game.configs.holiday_prayer_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( `$LimitPray:配置缺失! ${this.data.camp_id}` );
|
||
|
|
}
|
||
|
|
return this.configs;
|
||
|
|
},
|
||
|
|
|
||
|
|
// 获取规则文本
|
||
|
|
queryRule: function() {
|
||
|
|
|
||
|
|
const DATA = game.configs.holiday_prayer_theme_pool_data;
|
||
|
|
if( !DATA || !DATA.data_get_rules || !this.configs ) {
|
||
|
|
nx.error( `$LimitPray:规则获取失败! ${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;
|
||
|
|
},
|
||
|
|
|
||
|
|
// 获取指定奖励信息
|
||
|
|
queryReward: function( _id ) {
|
||
|
|
|
||
|
|
let gid = this.configs.group_id;
|
||
|
|
const DATA = game.configs.holiday_prayer_theme_pool_data.data_reward[gid];
|
||
|
|
return DATA[_id];
|
||
|
|
},
|
||
|
|
|
||
|
|
// 获取道具数量
|
||
|
|
itemHave: function() {
|
||
|
|
|
||
|
|
if( nx.dt.objEmpty( this.configs ) ||
|
||
|
|
!nx.dt.numPositive( this.configs.prop_id, false ) ) {
|
||
|
|
nx.error( `$LimitPray:获取道具数量失败! ${this.data.camp_id}` );
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
const BC = BackPackController.getInstance();
|
||
|
|
return BC.getModel().getBackPackItemNumByBid( this.configs.prop_id );
|
||
|
|
},
|
||
|
|
|
||
|
|
// ============================================================
|
||
|
|
// 基本操作
|
||
|
|
// ============================================================
|
||
|
|
|
||
|
|
// 请求基本信息
|
||
|
|
reqBaseData: function( _cb ) {
|
||
|
|
|
||
|
|
this.SendProtocal( 31140, {
|
||
|
|
group_id: this.data.camp_id,
|
||
|
|
}, _cb );
|
||
|
|
},
|
||
|
|
|
||
|
|
// 基本信息返回
|
||
|
|
handle31140: function( _data ) {
|
||
|
|
this.handle31143( _data );
|
||
|
|
},
|
||
|
|
|
||
|
|
// 更新推送
|
||
|
|
handle31143: function( _data ) {
|
||
|
|
|
||
|
|
if( !this.isGoodData( _data ) ||
|
||
|
|
_data.camp_id != this.data.camp_id ) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
this.vset( "LimitPrayRewards2", _data.ids || [], false );
|
||
|
|
this.vset( "LimitPrayTimes2", _data.draw_times, false );
|
||
|
|
this.vset( "LimitPrayFreshed2", this.vget( "LimitPrayFreshed2" ) + 1 );
|
||
|
|
this.freshTips();
|
||
|
|
},
|
||
|
|
|
||
|
|
// ============================================================
|
||
|
|
// 招募相关
|
||
|
|
// ============================================================
|
||
|
|
|
||
|
|
// 请求招募
|
||
|
|
reqSummon: function( _single, _cb ) {
|
||
|
|
|
||
|
|
this.SendProtocal( 31141, {
|
||
|
|
group_id: this.data.camp_id,
|
||
|
|
type: _single ? 1 : 2
|
||
|
|
}, _cb );
|
||
|
|
},
|
||
|
|
|
||
|
|
// 招募返回
|
||
|
|
handle31141: function( _data ) {
|
||
|
|
|
||
|
|
if( _data.camp_id != this.data.camp_id ||
|
||
|
|
!this.isGoodData( _data ) ) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
},
|
||
|
|
|
||
|
|
// ============================================================
|
||
|
|
// 奖励相关
|
||
|
|
// ============================================================
|
||
|
|
|
||
|
|
// 是否有奖励未领取
|
||
|
|
canReward: function() {
|
||
|
|
let list = this.vget( "LimitPrayRewards2" );
|
||
|
|
for( let i in list ) {
|
||
|
|
let re = list[i];
|
||
|
|
// status: 0-未完成,1-可领取,2-已领取
|
||
|
|
if( re && re.status == 1 ) {
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return false;
|
||
|
|
},
|
||
|
|
|
||
|
|
// 领取奖励
|
||
|
|
reqReward: function( _cb ) {
|
||
|
|
|
||
|
|
this.SendProtocal( 31142, {
|
||
|
|
group_id: this.data.camp_id,
|
||
|
|
}, _cb );
|
||
|
|
},
|
||
|
|
|
||
|
|
// 领取返回
|
||
|
|
handle31142: function( _data ) {
|
||
|
|
|
||
|
|
if( _data.camp_id != this.data.camp_id ||
|
||
|
|
!this.isGoodData( _data ) ) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
},
|
||
|
|
|
||
|
|
// ============================================================
|
||
|
|
// 积分兑换
|
||
|
|
// ============================================================
|
||
|
|
|
||
|
|
// 请求商品列表
|
||
|
|
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() {
|
||
|
|
|
||
|
|
if( !this.configs ) {
|
||
|
|
this.openTip( "reward", false );
|
||
|
|
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] );
|
||
|
|
|
||
|
|
let can = this.canReward();
|
||
|
|
this.openTip( "reward", can );
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
} );
|
||
|
|
|
||
|
|
// 模块导出
|
||
|
|
module.exports = ActLimitPray;
|