Files
fc/dev/project/library/imports/33/3325e087-4f87-4953-9413-b902e64c30ae.js
T
2026-05-24 10:21:26 +08:00

269 lines
8.2 KiB
JavaScript

"use strict";
cc._RF.push(module, '3325eCHT4dJU5QTuQLmTDCu', 'act.limit.pray.mod');
// Scripts/mod/acts/limitPray/act.limit.pray.mod.js
"use strict";
/*******************************************************************************
*
* 活动: 限定祈愿
*
*
******************************************************************************/
var ActBase = require("act.base");
var BackPackController = require("backpack_controller");
var ActLimitPray = 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(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 reqBaseFromServer(_cb) {
var _this = this;
// 配置加载
var cfgs = ["holiday_prayer_theme_pool_data"];
this.loadConfigs(cfgs, function (_ret, _data) {
nx.dt.fnInvoke(_cb, true);
_this.reqBaseData();
});
},
// ============================================================
// 配置相关
// ============================================================
// 获取配置
queryConfigs: function queryConfigs() {
if (nx.dt.objNEmpty(this.configs)) {
return this.configs;
}
var DATA = game.configs.holiday_prayer_theme_pool_data;
if (DATA && DATA.data_group_const) {
for (var id in DATA.data_group_const) {
var 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:\u914D\u7F6E\u7F3A\u5931! " + this.data.camp_id);
}
return this.configs;
},
// 获取规则文本
queryRule: function queryRule() {
var DATA = game.configs.holiday_prayer_theme_pool_data;
if (!DATA || !DATA.data_get_rules || !this.configs) {
nx.error("$LimitPray:\u89C4\u5219\u83B7\u53D6\u5931\u8D25! " + this.data.camp_id);
return "";
}
var 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 queryReward(_id) {
var gid = this.configs.group_id;
var DATA = game.configs.holiday_prayer_theme_pool_data.data_reward[gid];
return DATA[_id];
},
// 获取道具数量
itemHave: function itemHave() {
if (nx.dt.objEmpty(this.configs) || !nx.dt.numPositive(this.configs.prop_id, false)) {
nx.error("$LimitPray:\u83B7\u53D6\u9053\u5177\u6570\u91CF\u5931\u8D25! " + this.data.camp_id);
return 0;
}
var BC = BackPackController.getInstance();
return BC.getModel().getBackPackItemNumByBid(this.configs.prop_id);
},
// ============================================================
// 基本操作
// ============================================================
// 请求基本信息
reqBaseData: function reqBaseData(_cb) {
this.SendProtocal(31140, {
group_id: this.data.camp_id
}, _cb);
},
// 基本信息返回
handle31140: function handle31140(_data) {
this.handle31143(_data);
},
// 更新推送
handle31143: function handle31143(_data) {
if (!this.isGoodData(_data) || _data.camp_id != this.data.camp_id) {
return;
}
this.vset("LimitPrayRewards", _data.ids || [], false);
this.vset("LimitPrayTimes", _data.draw_times, false);
this.vset("LimitPrayFreshed", this.vget("LimitPrayFreshed") + 1);
this.freshTips();
},
// ============================================================
// 招募相关
// ============================================================
// 请求招募
reqSummon: function reqSummon(_single, _cb) {
this.SendProtocal(31141, {
group_id: this.data.camp_id,
type: _single ? 1 : 2
}, _cb);
},
// 招募返回
handle31141: function handle31141(_data) {
if (_data.camp_id != this.data.camp_id || !this.isGoodData(_data)) {
return;
}
},
// ============================================================
// 奖励相关
// ============================================================
// 是否有奖励未领取
canReward: function canReward() {
var list = this.vget("LimitPrayRewards");
for (var i in list) {
var re = list[i];
// status: 0-未完成,1-可领取,2-已领取
if (re && re.status == 1) {
return true;
}
}
return false;
},
// 领取奖励
reqReward: function reqReward(_cb) {
this.SendProtocal(31142, {
group_id: this.data.camp_id
}, _cb);
},
// 领取返回
handle31142: function handle31142(_data) {
if (_data.camp_id != this.data.camp_id || !this.isGoodData(_data)) {
return;
}
},
// ============================================================
// 积分兑换
// ============================================================
// 请求商品列表
reqScoreProducts: function reqScoreProducts(_cb) {
if (nx.dt.objNEmpty(this.products)) {
nx.dt.fnInvoke(_cb, true, this.products);
return;
}
this.cb16660 = _cb;
this.SendProtocal(16660, {});
},
// 请求商品列表返回
handle16660: function handle16660(_data) {
if (!this.isGoodData(_data)) {
return;
}
var arr = _data.holiday_exchanges || [];
for (var i = 0; i < arr.length; ++i) {
var 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 reqScoreBuy(_tid, _count, _cb) {
this.cb16661 = _cb;
this.SendProtocal(16661, {
bid: this.data.camp_id,
aim: _tid,
num: _count
});
},
// 商品兑换返回
handle16661: function handle16661(_data) {
if (!this.isGoodData(_data)) {
return;
}
// 次数更新
for (var i = 0; i < this.products.exchange_list.length; ++i) {
var 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 onBagItemUpdate(_bagCode, _itemList) {
var id = this.configs ? this.configs.prop_id : -1;
for (var k in _itemList) {
var tm = _itemList[k];
if (tm && tm.base_id == id) {
this.freshTips();
break;
}
}
},
// 活动用到的提示KEY
tipKeys: function tipKeys() {
return ["once", "ten"];
},
// 红点提示更新
freshTips: function freshTips() {
if (!this.configs) {
this.openTip("reward", false);
this.openTip("once", false);
this.openTip("ten", false);
return;
}
var count = this.itemHave();
this.openTip("once", count >= this.configs.draw_one[0][1]);
this.openTip("ten", count >= this.configs.draw_ten[0][1]);
var can = this.canReward();
this.openTip("reward", can);
}
});
// 模块导出
module.exports = ActLimitPray;
cc._RF.pop();