302 lines
8.1 KiB
JavaScript
302 lines
8.1 KiB
JavaScript
/*******************************************************************************
|
|
*
|
|
* 活动: 大富翁活动
|
|
*
|
|
*
|
|
******************************************************************************/
|
|
|
|
const ActBase = require( "act.base" );
|
|
const BackPackController = require( "backpack_controller" );
|
|
` `
|
|
const ActModCircleWalk = 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( 29410, this.handle29410.bind( this ) );
|
|
this.RegisterProtocal( 29411, this.handle29411.bind( this ) );
|
|
this.RegisterProtocal( 29412, this.handle29412.bind( this ) );
|
|
this.RegisterProtocal( 29413, this.handle29413.bind( this ) );
|
|
this.RegisterProtocal( 29414, this.handle29414.bind( this ) );
|
|
this.RegisterProtocal( 29415, this.handle29415.bind( this ) );
|
|
|
|
},
|
|
|
|
// 从服务器初始化数据
|
|
reqBaseFromServer: function( _cb ) {
|
|
|
|
// 配置加载
|
|
let cfgs = [
|
|
"happy_treasure_data"
|
|
];
|
|
this.loadConfigs( cfgs, ( _ret, _data ) => {
|
|
nx.dt.fnInvoke( _cb, true );
|
|
this.reqBaseData();
|
|
} );
|
|
},
|
|
|
|
// ============================================================
|
|
// 配置相关
|
|
// ============================================================
|
|
|
|
// 获取本轮奖励表
|
|
queryRoundRewards: function( _idx ) {
|
|
|
|
let rewards = [];
|
|
let data = game.configs.happy_treasure_data.data_get_reward[this.data.camp_id];
|
|
let list = data ? data[_idx] : {};
|
|
for( let pos in list ) {
|
|
rewards.push( list[pos] );
|
|
}
|
|
|
|
if( rewards.length == 0 ) {
|
|
nx.error( `$CircleWalk:获取奖励表失败!${_idx}` );
|
|
}
|
|
|
|
return rewards;
|
|
},
|
|
|
|
// 获取规则文本
|
|
queryRule: function() {
|
|
let data = game.configs.happy_treasure_data.data_const;
|
|
return data ? data.trueas_rules.desc : "";
|
|
},
|
|
|
|
// 获取配置
|
|
queryConfig: function() {
|
|
let data = game.configs.happy_treasure_data.data_infos[this.data.camp_id];
|
|
if( !data ) {
|
|
nx.error( `$CircleWalk:获取配置失败!${this.data.camp_id}` );
|
|
}
|
|
return data;
|
|
},
|
|
|
|
// 获取礼盒列表
|
|
queryBoxes: function() {
|
|
|
|
let list = [];
|
|
let boxs = this.vget( 'cwRewards' );
|
|
let data = game.configs.happy_treasure_data.data_get_schedule_reward;
|
|
for( let id in data ) {
|
|
let item = data[id];
|
|
if( item.camp_id == this.data.camp_id ) {
|
|
let info = nx.dt.objClone( item );
|
|
for( let i in boxs ) {
|
|
if( boxs[i].turn == item.index ) {
|
|
info.turn = boxs[i].turn;
|
|
info.status = boxs[i].is_get_reward;
|
|
}
|
|
}
|
|
list.push( info );
|
|
}
|
|
}
|
|
|
|
list.sort( ( a, b ) => {
|
|
return a.turn - b.turn;
|
|
} );
|
|
return list;
|
|
},
|
|
|
|
// 获取道具数量
|
|
itemHave: function() {
|
|
|
|
let cfgs = this.queryConfig();
|
|
let need = cfgs ? cfgs.item : 0;
|
|
if( !nx.dt.numPositive( need, false ) ) {
|
|
nx.error( `$CircleWalk:获取道具数量失败! ${need}` );
|
|
return 0;
|
|
}
|
|
|
|
const BC = BackPackController.getInstance();
|
|
return BC.getModel().getBackPackItemNumByBid( need );
|
|
},
|
|
|
|
// ============================================================
|
|
// 基本操作
|
|
// ============================================================
|
|
|
|
// 请求基本信息
|
|
reqBaseData: function( _cb ) {
|
|
|
|
this.SendProtocal( 29410, {
|
|
camp_id: this.data.camp_id,
|
|
}, _cb );
|
|
},
|
|
|
|
// 基本信息返回
|
|
handle29410: function( _data ) {
|
|
this.handle29411( _data );
|
|
},
|
|
|
|
// 更新推送
|
|
handle29411: function( _data ) {
|
|
|
|
if( !this.isGoodData( _data ) ||
|
|
_data.camp_id != this.data.camp_id ) {
|
|
return;
|
|
}
|
|
|
|
if( this.vget( "cwGroup" ) != _data.group ) {
|
|
this.vset( "cwGroup", _data.group );
|
|
}
|
|
|
|
if( this.vget( "cwPosition" ) != _data.curr_pos ) {
|
|
this.vset( "cwPosition", _data.curr_pos );
|
|
}
|
|
|
|
if( this.vget( "cwSteps" ) != _data.all_num ) {
|
|
this.vset( "cwSteps", _data.all_num );
|
|
}
|
|
|
|
if( this.vget( "cwTime" ) != _data.end_time ) {
|
|
this.vset( "cwTime", _data.end_time );
|
|
}
|
|
|
|
this.vset( "cwDice", _data.surplus_sieve );
|
|
this.vset( "cwRewards", _data.reward_list );
|
|
|
|
this.freshTips();
|
|
},
|
|
|
|
// ============================================================
|
|
// 行动相关
|
|
// ============================================================
|
|
|
|
// 开始行动
|
|
reqStartRoll: function( _cb ) {
|
|
this.vset( "cwRewardList", null );
|
|
this.SendProtocal( 29412, {
|
|
camp_id: this.data.camp_id,
|
|
}, _cb );
|
|
},
|
|
|
|
// 开始行动
|
|
handle29412: function( _data ) {
|
|
if( !this.isGoodData( _data ) ||
|
|
_data.camp_id != this.data.camp_id ) {
|
|
return;
|
|
}
|
|
this.vset( "cwRewardList", _data.reward_list );
|
|
},
|
|
|
|
// 行动奖励
|
|
reqReward: function( _point, _cb ) {
|
|
this.SendProtocal( 29413, {
|
|
camp_id: this.data.camp_id,
|
|
num: _point
|
|
}, _cb );
|
|
},
|
|
|
|
// 行动奖励
|
|
handle29413: function( _data ) {
|
|
if( !this.isGoodData( _data ) ) {
|
|
return;
|
|
}
|
|
},
|
|
|
|
// 一键十连
|
|
reqRewardTen: function( _cb ) {
|
|
this.SendProtocal( 29414, {
|
|
camp_id: this.data.camp_id,
|
|
}, _cb );
|
|
},
|
|
|
|
// 一键十连
|
|
handle29414: function( _data ) {
|
|
if( this.isGoodData( _data ) ) {
|
|
return;
|
|
}
|
|
},
|
|
|
|
// 领取达成奖励
|
|
reqOpenBox: function( _cb ) {
|
|
this.SendProtocal( 29415, {
|
|
camp_id: this.data.camp_id
|
|
}, _cb );
|
|
},
|
|
|
|
// 领取达成奖励
|
|
handle29415: function( _data ) {
|
|
if( this.isGoodData( _data ) ) {
|
|
return;
|
|
}
|
|
},
|
|
|
|
// ============================================================
|
|
// 活动红点提示
|
|
// ============================================================
|
|
|
|
// 道具更新
|
|
onBagItemUpdate: function( _bagCode, _itemList ) {
|
|
|
|
let cfgs = this.queryConfig();
|
|
if( !cfgs ) {
|
|
return;
|
|
}
|
|
|
|
for( let k in _itemList ) {
|
|
let tm = _itemList[k];
|
|
if( tm && tm.base_id == cfgs.item ) {
|
|
this.freshTips();
|
|
break;
|
|
}
|
|
}
|
|
},
|
|
|
|
// 活动用到的提示KEY
|
|
tipKeys: function() {
|
|
return ["go"];
|
|
},
|
|
|
|
// 红点提示更新
|
|
freshTips: function() {
|
|
|
|
if( !this.configs ) {
|
|
this.openTip( "reward", false );
|
|
return;
|
|
}
|
|
|
|
// status: 0-未完成,1-可领取,2-已领取
|
|
let can = false;
|
|
let rewards = this.vget( "cwRewards" );
|
|
for( let i in rewards ) {
|
|
if( rewards[i].status == 1 ) {
|
|
can = true;
|
|
break;
|
|
}
|
|
}
|
|
this.openTip( "reward", can );
|
|
|
|
},
|
|
|
|
} );
|
|
|
|
// 模块导出
|
|
module.exports = ActModCircleWalk; |