146 lines
4.3 KiB
JavaScript
146 lines
4.3 KiB
JavaScript
"use strict";
|
|
cc._RF.push(module, '9d09f4SyvdGG7+p1NWNgZdc', 'monopoly.mod');
|
|
// Scripts/mod/sgames/monopoly/monopoly.mod.js
|
|
|
|
"use strict";
|
|
|
|
/******************************************************************
|
|
*
|
|
* 大富翁模块
|
|
*
|
|
******************************************************************/
|
|
|
|
var BC = require("bridge.controller");
|
|
var BackPackController = require("backpack_controller");
|
|
var SGMonopoly = cc.Class({
|
|
"extends": BC,
|
|
// 初始化配置数据
|
|
initConfig: function initConfig() {
|
|
// 缓存标记--连续投掷
|
|
var val = cc.sys.localStorage.getItem("MonoAuto");
|
|
nx.bridge.vset("MonoAutoDice", val == "open");
|
|
},
|
|
// 注册监听事件
|
|
registerEvents: function registerEvents() {},
|
|
// 注册协议接受事件
|
|
registerProtocals: function registerProtocals() {
|
|
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 reqBaseFromServer(_cb) {
|
|
var _this = this;
|
|
// 配置加载
|
|
var cfgs = ["star_tower_data", "monopoly_data"];
|
|
this.loadConfigs(cfgs, function (_ret, _data) {
|
|
_this.reqMonopolyData(_cb);
|
|
});
|
|
},
|
|
reqMonopolyData: function reqMonopolyData(_cb) {
|
|
// 功能解锁检查
|
|
var is_open = this.checkLock();
|
|
|
|
// 锁定中不请求数据
|
|
if (nx.dt.objNEmpty(is_open)) {
|
|
nx.dt.fnInvoke(_cb, true);
|
|
return;
|
|
}
|
|
this.fetchData(_cb);
|
|
},
|
|
// 锁定判定
|
|
checkLock: function checkLock() {
|
|
var 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 fetchData(_cb) {
|
|
this.SendProtocal(29400, {}, _cb);
|
|
},
|
|
// 信息返回
|
|
handle29400: function handle29400(_data) {
|
|
// 失败判定
|
|
if (!this.isGoodData(_data)) {
|
|
return;
|
|
}
|
|
|
|
// 数据更新
|
|
this.updateData(_data, true);
|
|
var DATA = game.configs.monopoly_data.data_const.item_bid;
|
|
this.coinId = DATA.val;
|
|
var model = BackPackController.getInstance().getModel();
|
|
var count = model.getBackPackItemNumByBid(this.coinId);
|
|
nx.mTip.openTip("bar.monopoly", count > 0);
|
|
},
|
|
// 信息返回
|
|
handle29401: function handle29401(_data) {
|
|
// 数据更新
|
|
this.updateData(_data, false);
|
|
},
|
|
// 数据更新
|
|
updateData: function updateData(_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 reqRoll(_cb) {
|
|
this.SendProtocal(29402, {}, _cb);
|
|
},
|
|
// 投掷筛子,获取点数与目标格子
|
|
handle29402: function handle29402(_data) {
|
|
// TODO...
|
|
},
|
|
// 投掷行走指定格子后领取格子奖励
|
|
reqRollMoveEnd: function reqRollMoveEnd(_dice, _cb) {
|
|
this.SendProtocal(29405, {
|
|
num: _dice
|
|
}, _cb);
|
|
},
|
|
// 投掷格子领取
|
|
handle29405: function handle29405(_data) {
|
|
// TODO...
|
|
},
|
|
// 领取奖励
|
|
reqReward: function reqReward(_turn, _cb) {
|
|
this.SendProtocal(29403, {
|
|
turn: _turn
|
|
}, _cb);
|
|
},
|
|
// 领取奖励
|
|
handle29403: function handle29403(_data) {
|
|
// TODO...
|
|
},
|
|
// 购买筛子
|
|
reqBuyDice: function reqBuyDice(_num, _cb) {
|
|
this.SendProtocal(29404, {
|
|
num: _num
|
|
}, _cb);
|
|
},
|
|
// 购买筛子
|
|
handle29404: function handle29404(_data) {
|
|
// TODO...
|
|
},
|
|
// 连续投掷切换
|
|
togAutoRoll: function togAutoRoll(_cb) {
|
|
var 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;
|
|
|
|
cc._RF.pop(); |