182 lines
5.6 KiB
JavaScript
182 lines
5.6 KiB
JavaScript
|
|
"use strict";
|
||
|
|
cc._RF.push(module, '811245TdsVI+o3ggO5E0cFg', 'act.blind.box.mod');
|
||
|
|
// Scripts/mod/acts/blindBox/act.blind.box.mod.js
|
||
|
|
|
||
|
|
"use strict";
|
||
|
|
|
||
|
|
/*******************************************************************************
|
||
|
|
*
|
||
|
|
* 活动:开盲盒
|
||
|
|
*
|
||
|
|
*
|
||
|
|
******************************************************************************/
|
||
|
|
|
||
|
|
var ActBase = require("act.base");
|
||
|
|
var BackPackController = require("backpack_controller");
|
||
|
|
var HeroController = require("hero_controller");
|
||
|
|
var ActBlindBoxMod = 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(31130, this.handle31130.bind(this));
|
||
|
|
this.RegisterProtocal(31131, this.handle31131.bind(this));
|
||
|
|
},
|
||
|
|
// 从服务器初始化数据
|
||
|
|
reqBaseFromServer: function reqBaseFromServer(_cb) {
|
||
|
|
var _this = this;
|
||
|
|
// 配置加载
|
||
|
|
var cfgs = ["holiday_blind_box_data"];
|
||
|
|
this.loadConfigs(cfgs, function (_ret, _data) {
|
||
|
|
nx.dt.fnInvoke(_cb, true);
|
||
|
|
_this.configs = _this.queryConfigs(_this.data.camp_id);
|
||
|
|
_this.freshTips();
|
||
|
|
});
|
||
|
|
},
|
||
|
|
// ============================================================
|
||
|
|
// 基本操作
|
||
|
|
// ============================================================
|
||
|
|
|
||
|
|
// 点击预抽奖
|
||
|
|
reqPreRaffle: function reqPreRaffle(_once, _cb) {
|
||
|
|
this.SendProtocal(31130, {
|
||
|
|
camp_id: this.data.camp_id,
|
||
|
|
times: _once ? 1 : 10
|
||
|
|
}, _cb);
|
||
|
|
},
|
||
|
|
handle31130: function handle31130(_data) {
|
||
|
|
if (!this.isGoodData(_data)) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
},
|
||
|
|
// 点击抽奖
|
||
|
|
reqRaffle: function reqRaffle(_once, _cb) {
|
||
|
|
this.SendProtocal(31131, {
|
||
|
|
camp_id: this.data.camp_id,
|
||
|
|
times: _once ? 1 : 10
|
||
|
|
}, _cb);
|
||
|
|
},
|
||
|
|
handle31131: function handle31131(_data) {
|
||
|
|
if (!this.isGoodData(_data)) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
},
|
||
|
|
// ============================================================
|
||
|
|
// 道具相关
|
||
|
|
// ============================================================
|
||
|
|
|
||
|
|
// 道具更新
|
||
|
|
onBagItemUpdate: function onBagItemUpdate(_bagCode, _itemList) {
|
||
|
|
var id1 = this.configs ? this.configs.item_id : -1;
|
||
|
|
var id2 = this.configs ? this.configs.skin_debris_id[0] : -1;
|
||
|
|
for (var k in _itemList) {
|
||
|
|
var tm = _itemList[k];
|
||
|
|
if (tm.base_id == id1 || tm.base_id == id2) {
|
||
|
|
this.freshTips();
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
},
|
||
|
|
// 获取道具数量
|
||
|
|
itemHave: function itemHave() {
|
||
|
|
if (nx.dt.objEmpty(this.configs) || !nx.dt.numPositive(this.configs.item_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.item_id);
|
||
|
|
},
|
||
|
|
// ============================================================
|
||
|
|
// 活动红点提示
|
||
|
|
// ============================================================
|
||
|
|
|
||
|
|
// 活动用到的提示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);
|
||
|
|
this.vset("BlindBoxCombine", 0);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 抽取提示
|
||
|
|
var count = this.itemHave();
|
||
|
|
this.openTip("once", count >= this.configs.loss_item_once[0][1]);
|
||
|
|
this.openTip("ten", count >= this.configs.loss_item_ten[0][1]);
|
||
|
|
|
||
|
|
// 皮肤已有
|
||
|
|
var flag = 0;
|
||
|
|
var HC = HeroController.getInstance();
|
||
|
|
var HM = HC.getModel();
|
||
|
|
var owned = HM.hero_skin_list || {};
|
||
|
|
var have = nx.dt.numGood(owned[this.configs.skin_id]);
|
||
|
|
if (have) {
|
||
|
|
flag = 2;
|
||
|
|
} else {
|
||
|
|
// 合成提示
|
||
|
|
var id = this.configs.skin_debris_id[0];
|
||
|
|
var BC = BackPackController.getInstance();
|
||
|
|
var num = BC.getModel().getBackPackItemNumByBid(id);
|
||
|
|
if (num >= this.configs.skin_debris_id[1]) {
|
||
|
|
flag = 1;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
this.vset("BlindBoxCombine", flag);
|
||
|
|
},
|
||
|
|
// ============================================================
|
||
|
|
// 配置相关
|
||
|
|
// ============================================================
|
||
|
|
|
||
|
|
// 获取配置
|
||
|
|
queryConfigs: function queryConfigs(_campId) {
|
||
|
|
var DATA = game.configs.holiday_blind_box_data;
|
||
|
|
if (!DATA) {
|
||
|
|
nx.error("$BlindBox:\u914D\u7F6E\u8868\u7F3A\u5931!");
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
var info = DATA.data_summon[this.data.camp_id];
|
||
|
|
if (!info) {
|
||
|
|
nx.error("$BlindBox:\u914D\u7F6E\u7F3A\u5931! " + this.data.camp_id);
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
return nx.dt.objClone(info);
|
||
|
|
},
|
||
|
|
// 获取规则
|
||
|
|
queryRule: function queryRule() {
|
||
|
|
var DATA = game.configs.holiday_blind_box_data;
|
||
|
|
if (!DATA) {
|
||
|
|
nx.error("$BlindBox:\u914D\u7F6E\u89C4\u5219\u7F3A\u5931!");
|
||
|
|
return "";
|
||
|
|
}
|
||
|
|
return DATA.data_const.txt_data.desc;
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
// 模块导出
|
||
|
|
module.exports = ActBlindBoxMod;
|
||
|
|
|
||
|
|
cc._RF.pop();
|