Files

183 lines
4.5 KiB
JavaScript
Raw Permalink Normal View History

2026-05-23 22:10:14 +08:00
/******************************************************************
*
* 大富翁模块
*
******************************************************************/
const BC = require( "bridge.controller" );
const BackPackController = require( "backpack_controller" );
const SGMonopoly = cc.Class( {
extends: BC,
// 初始化配置数据
initConfig: function() {
// 缓存标记--连续投掷
let val = cc.sys.localStorage.getItem( "MonoAuto" );
nx.bridge.vset( "MonoAutoDice", val == "open" );
},
// 注册监听事件
registerEvents: function() {
},
// 注册协议接受事件
registerProtocals: function() {
this.RegisterProtocal( 29400, this.handle29400.bind( this ) ); // 信息返回
this.RegisterProtocal( 29401, this.handle29401.bind( this ) ); // 更新推送
this.RegisterProtocal( 29402, this.handle29402.bind( this ) ); // 投掷筛子
this.RegisterProtocal( 29403, this.handle29403.bind( this ) ); // 领取奖励
this.RegisterProtocal( 29404, this.handle29404.bind( this ) ); // 购买筛子
this.RegisterProtocal( 29405, this.handle29405.bind( this ) ); // 投掷筛子--格子奖励
},
// 从服务器初始化数据
reqBaseFromServer: function( _cb ) {
// 配置加载
let cfgs = [
"star_tower_data",
"monopoly_data"
];
this.loadConfigs( cfgs, ( _ret, _data ) => {
this.reqMonopolyData( _cb );
} );
},
reqMonopolyData( _cb ){
// 功能解锁检查
let is_open = this.checkLock();
// 锁定中不请求数据
if( nx.dt.objNEmpty( is_open ) ) {
nx.dt.fnInvoke( _cb, true );
return;
}
this.fetchData( _cb );
},
// 锁定判定
checkLock: function() {
let DATA = game.configs.monopoly_data.data_const;
if( nx.dt.objEmpty( DATA ) ||
nx.dt.objEmpty( DATA.lev_limit ) ) {
return {};
}
return nx.bridge.checkConditions( [
[ "lev", DATA.lev_limit.val]
] );
},
// 请求信息
fetchData: function( _cb ) {
this.SendProtocal( 29400, {}, _cb );
},
// 信息返回
handle29400: function( _data ) {
// 失败判定
if( !this.isGoodData( _data ) ) {
return;
}
// 数据更新
this.updateData( _data, true );
let DATA = game.configs.monopoly_data.data_const.item_bid;
this.coinId = DATA.val;
let model = BackPackController.getInstance().getModel();
let count = model.getBackPackItemNumByBid( this.coinId );
nx.mTip.openTip( "bar.monopoly", count > 0 );
},
// 信息返回
handle29401: function( _data ) {
// 数据更新
this.updateData( _data, false );
},
// 数据更新
updateData: function( _data, _reset ) {
if( nx.dt.objEmpty( _data ) ) {
return;
}
nx.bridge.vset( "MonoTurn", _data.turn );
nx.bridge.vset( "MonoPos", _data.curr_pos );
nx.bridge.vset( "MonoBuyNum", _data.buy_num );
nx.bridge.vset( "MonoEndTime", _data.end_time );
nx.bridge.vset( "MonoRewards", _data.reward_list );
},
// 投掷筛子
reqRoll: function( _cb ) {
this.SendProtocal( 29402, {}, _cb );
},
// 投掷筛子,获取点数与目标格子
handle29402: function( _data ) {
// TODO...
},
// 投掷行走指定格子后领取格子奖励
reqRollMoveEnd: function( _dice, _cb ) {
this.SendProtocal( 29405, {
num: _dice,
}, _cb );
},
// 投掷格子领取
handle29405: function( _data ) {
// TODO...
},
// 领取奖励
reqReward: function( _turn, _cb ) {
this.SendProtocal( 29403, {
turn: _turn
}, _cb );
},
// 领取奖励
handle29403: function( _data ) {
// TODO...
},
// 购买筛子
reqBuyDice: function( _num, _cb ) {
this.SendProtocal( 29404, {
num: _num
}, _cb );
},
// 购买筛子
handle29404: function( _data ) {
// TODO...
},
// 连续投掷切换
togAutoRoll: function( _cb ) {
let open = !nx.bridge.vget( "MonoAutoDice" );
nx.bridge.vset( "MonoAutoDice", open );
nx.dt.fnInvoke( _cb, open );
cc.sys.localStorage.setItem( "MonoAuto", open ? "open" : "close" );
},
} );
module.exports = SGMonopoly;