Files
fc/dev/project/library/imports/e9/e9e49307-c4ea-4516-accf-4f5401827983.js
2026-05-24 10:21:26 +08:00

257 lines
7.5 KiB
JavaScript

"use strict";
cc._RF.push(module, 'e9e49MHxOpFFqzPT1QBgnmD', 'act.circle.walk.mod');
// Scripts/mod/acts/circleWalk/act.circle.walk.mod.js
"use strict";
/*******************************************************************************
*
* 活动: 大富翁活动
*
*
******************************************************************************/
var ActBase = require("act.base");
var BackPackController = require("backpack_controller");
" ";
var ActModCircleWalk = cc.Class({
"extends": ActBase,
// 初始化配置数据
initConfig: function initConfig() {
// 视图附着
nx.plugin.add(this, ["view"]);
this.vattach("Acts");
},
// 注册监听事件
registerEvents: function registerEvents() {
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 registerProtocals() {
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 reqBaseFromServer(_cb) {
var _this = this;
// 配置加载
var cfgs = ["happy_treasure_data"];
this.loadConfigs(cfgs, function (_ret, _data) {
nx.dt.fnInvoke(_cb, true);
_this.reqBaseData();
});
},
// ============================================================
// 配置相关
// ============================================================
// 获取本轮奖励表
queryRoundRewards: function queryRoundRewards(_idx) {
var rewards = [];
var data = game.configs.happy_treasure_data.data_get_reward[this.data.camp_id];
var list = data ? data[_idx] : {};
for (var pos in list) {
rewards.push(list[pos]);
}
if (rewards.length == 0) {
nx.error("$CircleWalk:\u83B7\u53D6\u5956\u52B1\u8868\u5931\u8D25!" + _idx);
}
return rewards;
},
// 获取规则文本
queryRule: function queryRule() {
var data = game.configs.happy_treasure_data.data_const;
return data ? data.trueas_rules.desc : "";
},
// 获取配置
queryConfig: function queryConfig() {
var data = game.configs.happy_treasure_data.data_infos[this.data.camp_id];
if (!data) {
nx.error("$CircleWalk:\u83B7\u53D6\u914D\u7F6E\u5931\u8D25!" + this.data.camp_id);
}
return data;
},
// 获取礼盒列表
queryBoxes: function queryBoxes() {
var list = [];
var boxs = this.vget('cwRewards');
var data = game.configs.happy_treasure_data.data_get_schedule_reward;
for (var id in data) {
var item = data[id];
if (item.camp_id == this.data.camp_id) {
var info = nx.dt.objClone(item);
for (var 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(function (a, b) {
return a.turn - b.turn;
});
return list;
},
// 获取道具数量
itemHave: function itemHave() {
var cfgs = this.queryConfig();
var need = cfgs ? cfgs.item : 0;
if (!nx.dt.numPositive(need, false)) {
nx.error("$CircleWalk:\u83B7\u53D6\u9053\u5177\u6570\u91CF\u5931\u8D25! " + need);
return 0;
}
var BC = BackPackController.getInstance();
return BC.getModel().getBackPackItemNumByBid(need);
},
// ============================================================
// 基本操作
// ============================================================
// 请求基本信息
reqBaseData: function reqBaseData(_cb) {
this.SendProtocal(29410, {
camp_id: this.data.camp_id
}, _cb);
},
// 基本信息返回
handle29410: function handle29410(_data) {
this.handle29411(_data);
},
// 更新推送
handle29411: function handle29411(_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 reqStartRoll(_cb) {
this.vset("cwRewardList", null);
this.SendProtocal(29412, {
camp_id: this.data.camp_id
}, _cb);
},
// 开始行动
handle29412: function handle29412(_data) {
if (!this.isGoodData(_data) || _data.camp_id != this.data.camp_id) {
return;
}
this.vset("cwRewardList", _data.reward_list);
},
// 行动奖励
reqReward: function reqReward(_point, _cb) {
this.SendProtocal(29413, {
camp_id: this.data.camp_id,
num: _point
}, _cb);
},
// 行动奖励
handle29413: function handle29413(_data) {
if (!this.isGoodData(_data)) {
return;
}
},
// 一键十连
reqRewardTen: function reqRewardTen(_cb) {
this.SendProtocal(29414, {
camp_id: this.data.camp_id
}, _cb);
},
// 一键十连
handle29414: function handle29414(_data) {
if (this.isGoodData(_data)) {
return;
}
},
// 领取达成奖励
reqOpenBox: function reqOpenBox(_cb) {
this.SendProtocal(29415, {
camp_id: this.data.camp_id
}, _cb);
},
// 领取达成奖励
handle29415: function handle29415(_data) {
if (this.isGoodData(_data)) {
return;
}
},
// ============================================================
// 活动红点提示
// ============================================================
// 道具更新
onBagItemUpdate: function onBagItemUpdate(_bagCode, _itemList) {
var cfgs = this.queryConfig();
if (!cfgs) {
return;
}
for (var k in _itemList) {
var tm = _itemList[k];
if (tm && tm.base_id == cfgs.item) {
this.freshTips();
break;
}
}
},
// 活动用到的提示KEY
tipKeys: function tipKeys() {
return ["go"];
},
// 红点提示更新
freshTips: function freshTips() {
if (!this.configs) {
this.openTip("reward", false);
return;
}
// status: 0-未完成,1-可领取,2-已领取
var can = false;
var rewards = this.vget("cwRewards");
for (var i in rewards) {
if (rewards[i].status == 1) {
can = true;
break;
}
}
this.openTip("reward", can);
}
});
// 模块导出
module.exports = ActModCircleWalk;
cc._RF.pop();