210 lines
6.5 KiB
JavaScript
210 lines
6.5 KiB
JavaScript
"use strict";
|
|
cc._RF.push(module, '294141mMPpBlp7jVJvpHaiN', 'act.summon.limit.mod.5');
|
|
// Scripts/mod/acts/summonLimit/act.summon.limit.mod.5.js
|
|
|
|
"use strict";
|
|
|
|
/*******************************************************************************
|
|
*
|
|
* 活动: 限定招募
|
|
*
|
|
*
|
|
******************************************************************************/
|
|
|
|
var ActBase = require("act.base");
|
|
var BackPackController = require("backpack_controller");
|
|
var ActSummonLimit5 = 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(16660, this.handle16660.bind(this));
|
|
this.RegisterProtocal(16661, this.handle16661.bind(this));
|
|
},
|
|
// 从服务器初始化数据
|
|
reqBaseFromServer: function reqBaseFromServer(_cb) {
|
|
var _this = this;
|
|
// 配置加载
|
|
var cfgs = ["holiday_theme_pool_data"];
|
|
this.loadConfigs(cfgs, function (_ret, _data) {
|
|
nx.dt.fnInvoke(_cb, true);
|
|
_this.reqBaseData();
|
|
});
|
|
},
|
|
// ============================================================
|
|
// 基本操作
|
|
// ============================================================
|
|
|
|
// 请求基本信息
|
|
reqBaseData: function reqBaseData(_cb) {
|
|
var _this2 = this;
|
|
this.manager.reqActData(this.data.camp_id, function (_ret, _params) {
|
|
_this2.freshTips();
|
|
nx.dt.fnInvoke(_cb, _ret, _params);
|
|
});
|
|
},
|
|
// ============================================================
|
|
// 配置相关
|
|
// ============================================================
|
|
|
|
// 获取配置
|
|
queryConfigs: function queryConfigs() {
|
|
if (nx.dt.objNEmpty(this.configs)) {
|
|
return this.configs;
|
|
}
|
|
var DATA = game.configs.holiday_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("$SummonLimit:\u914D\u7F6E\u7F3A\u5931! " + this.data.camp_id);
|
|
}
|
|
return this.configs;
|
|
},
|
|
// 获取规则文本
|
|
queryRule: function queryRule() {
|
|
var DATA = game.configs.holiday_theme_pool_data;
|
|
if (!DATA || !DATA.data_get_rules || !this.configs) {
|
|
nx.error("$SummonLimit:\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;
|
|
},
|
|
// 获取道具数量
|
|
itemHave: function itemHave() {
|
|
if (nx.dt.objEmpty(this.configs) || !nx.dt.numPositive(this.configs.prop_id, false)) {
|
|
nx.error("$SummonLimit:\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);
|
|
},
|
|
// ============================================================
|
|
// 抽奖操作
|
|
// ============================================================
|
|
|
|
// 抽奖请求
|
|
reqRaffle: function reqRaffle(_group_id, _once, _cb) {
|
|
this.manager.reqDrawFromPool(_group_id, 1, _once ? 1 : 2, _cb);
|
|
},
|
|
// ============================================================
|
|
// 积分兑换
|
|
// ============================================================
|
|
|
|
// 请求商品列表
|
|
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() {
|
|
this.openTip("reward", false);
|
|
if (!this.configs) {
|
|
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]);
|
|
}
|
|
});
|
|
|
|
// 模块导出
|
|
module.exports = ActSummonLimit5;
|
|
|
|
cc._RF.pop(); |