526 lines
14 KiB
JavaScript
526 lines
14 KiB
JavaScript
"use strict";
|
|
cc._RF.push(module, '59b4bRlErlEVbwYkpc6ZqPF', 'acts.mod');
|
|
// Scripts/mod/acts/acts.mod.js
|
|
|
|
"use strict";
|
|
|
|
/*******************************************************************************
|
|
*
|
|
* 活动管理
|
|
*
|
|
*
|
|
*
|
|
* 2023.06.25
|
|
******************************************************************************/
|
|
|
|
var BridgeController = require("bridge.controller");
|
|
var ActDefine = require("acts.define");
|
|
var ActManager = cc.Class({
|
|
"extends": BridgeController,
|
|
// 初始化配置数据
|
|
initConfig: function initConfig() {
|
|
// 插件
|
|
nx.plugin.add(this, ["view"]);
|
|
|
|
// 视图创建
|
|
this.vbuild(ActDefine.ViewActs);
|
|
|
|
// 全局支持
|
|
nx.bridge.acts = this;
|
|
},
|
|
// 注册监听事件
|
|
registerEvents: function registerEvents() {},
|
|
// 注册协议接受事件
|
|
registerProtocals: function registerProtocals() {
|
|
// 前端准备完毕
|
|
this.RegisterProtocal(16600, this.onBaseData.bind(this));
|
|
|
|
// 活动基础信息
|
|
this.RegisterProtocal(16603, this.handle16603.bind(this));
|
|
|
|
// 整点更新
|
|
this.RegisterProtocal(16607, this.onFreshActs.bind(this));
|
|
|
|
// 奖励更新
|
|
this.RegisterProtocal(16602, this.onFreshActsRewards.bind(this));
|
|
this.RegisterProtocal(16606, this.onUpdateActsRewards.bind(this));
|
|
|
|
// 推送弹窗
|
|
this.RegisterProtocal(16621, this.onPushPopup.bind(this));
|
|
this.RegisterProtocal(16622, this.onPushPopupClose.bind(this));
|
|
|
|
// 活动引导
|
|
this.RegisterProtocal(16623, this.onActGuide.bind(this));
|
|
this.RegisterProtocal(16624, this.onActGuideDone.bind(this));
|
|
|
|
// 活动抽奖
|
|
this.RegisterProtocal(31111, this.handle31111.bind(this));
|
|
},
|
|
// 从服务器初始化数据
|
|
reqBaseFromServer: function reqBaseFromServer(_cb) {
|
|
var _this = this;
|
|
// 配置加载
|
|
var cfgs = ["ad_show", "login_popup_data"];
|
|
this.vreset();
|
|
this.loadConfigs(cfgs, function (_ret, _data) {
|
|
_this.reqBaseData(_cb);
|
|
});
|
|
},
|
|
// ============================================================
|
|
// 基本数据
|
|
// ============================================================
|
|
|
|
// 请求基本数据
|
|
reqBaseData: function reqBaseData(_cb) {
|
|
this.SendProtocal(16600, {}, _cb);
|
|
},
|
|
// 基本数据
|
|
onBaseData: function onBaseData(_data) {
|
|
if (!this.isGoodData(_data)) {
|
|
return;
|
|
}
|
|
var themes = _data.holiday_theme_list;
|
|
themes.sort(function (_a, _b) {
|
|
return _a.sort - _b.sort;
|
|
});
|
|
this.vset("themes", themes, false);
|
|
|
|
// 活动模块更新
|
|
this.buildActMods();
|
|
|
|
// 重构提示链
|
|
this.buildTipsView();
|
|
|
|
// 奖励信息
|
|
this.reqActsRewards();
|
|
|
|
// 通知
|
|
this.vnotify("themes");
|
|
this.freshForeshow();
|
|
},
|
|
// 活动模块更新
|
|
buildActMods: function buildActMods() {
|
|
var self = this;
|
|
var MODS = ActDefine.ActsMods;
|
|
var themes = this.vget("themes");
|
|
|
|
// 子活动统计
|
|
var ids = [];
|
|
var temp = {};
|
|
for (var i = 0; i < themes.length; ++i) {
|
|
var theme = themes[i];
|
|
theme.theme_holiday_list.forEach(function (_t) {
|
|
ids.push(_t.camp_id);
|
|
temp[_t.camp_id] = nx.dt.objClone(_t);
|
|
});
|
|
}
|
|
|
|
// 活动列表是否改变
|
|
if (nx.dt.objNEmpty(this.acts)) {
|
|
var ids2 = [];
|
|
for (var id in this.acts) {
|
|
ids.push(parseInt(id));
|
|
}
|
|
|
|
// 如果活动发生了变化,则需要重建列表
|
|
ids.sort(function (_a, _b) {
|
|
return _a - _b;
|
|
});
|
|
ids2.sort(function (_a, _b) {
|
|
return _a - _b;
|
|
});
|
|
if (ids.toString() != ids2.toString()) {
|
|
this.acts = {};
|
|
nx.debug("$Acts:活动列表发生改变:");
|
|
nx.debug("$Acts:老:", ids2.toString());
|
|
nx.debug("$Acts:新:", ids.toString());
|
|
}
|
|
}
|
|
|
|
// 列表重建
|
|
if (nx.dt.objEmpty(this.acts)) {
|
|
var push = function push(_data) {
|
|
var cfg = MODS[_data.source];
|
|
if (nx.dt.objEmpty(cfg)) {
|
|
nx.warn("$Acts:无效活动:", _data.source);
|
|
return;
|
|
}
|
|
if (nx.dt.strNEmpty(cfg.mod)) {
|
|
var ref = require(cfg.mod);
|
|
var mod = ref.getInstance(_data.source, cfg.mod, true);
|
|
if (mod) {
|
|
nx.debug("$ActMods:" + cfg.mod);
|
|
mod.bindData(self, _data);
|
|
self.acts[_data.camp_id] = mod;
|
|
}
|
|
}
|
|
};
|
|
this.acts = {};
|
|
var _loop = function _loop() {
|
|
var theme = themes[_i];
|
|
theme.theme_holiday_list.forEach(function (_t) {
|
|
_t.theme_id = theme.theme_id;
|
|
try {
|
|
push(_t);
|
|
} catch (e) {
|
|
nx.error("[异常]:" + (e ? e.message + "\n" + e.stack : "未知错误!"));
|
|
if (e && cc.sys.isNative && window && window.__errorHandler) {
|
|
window.__errorHandler(e.message, "", "", e.stack);
|
|
}
|
|
}
|
|
});
|
|
};
|
|
for (var _i = 0; _i < themes.length; ++_i) {
|
|
_loop();
|
|
}
|
|
nx.debug("$Acts:创建子活动%s个", nx.dt.objLen(this.acts));
|
|
}
|
|
for (var _id in this.acts) {
|
|
var at = this.acts[_id];
|
|
if (at) {
|
|
at.reqBaseFromServer();
|
|
}
|
|
}
|
|
},
|
|
// 获取指定主题信息
|
|
queryTheme: function queryTheme(_theme) {
|
|
var themes = this.vget("themes");
|
|
for (var i in themes) {
|
|
var tm = themes[i];
|
|
if (tm && tm.theme_id == _theme) {
|
|
return tm;
|
|
}
|
|
}
|
|
},
|
|
// 获得指定source的主题信息
|
|
queryThemeBySource: function queryThemeBySource(_source) {
|
|
var themes = this.vget("themes");
|
|
for (var i in themes) {
|
|
var tm = themes[i];
|
|
if (tm && tm.source == _source) {
|
|
return tm;
|
|
}
|
|
}
|
|
},
|
|
// 查询活动信息
|
|
searchAct: function searchAct(_camp_id) {
|
|
var themes = this.vget("themes");
|
|
for (var i in themes) {
|
|
var theme = themes[i];
|
|
if (!theme || nx.dt.arrEmpty(theme.theme_holiday_list)) {
|
|
continue;
|
|
}
|
|
for (var k in theme.theme_holiday_list) {
|
|
var act = theme.theme_holiday_list[k];
|
|
if (act && act.camp_id == _camp_id) {
|
|
return {
|
|
theme: theme,
|
|
infos: act
|
|
};
|
|
}
|
|
}
|
|
}
|
|
nx.error("$Acts:子活动信息不存在:", _camp_id);
|
|
return null;
|
|
},
|
|
// 获取指定主题信息
|
|
queryThemeByType: function queryThemeByType(_type) {
|
|
var themes = this.vget("themes");
|
|
for (var i in themes) {
|
|
var tm = themes[i];
|
|
if (tm && tm.type == _type) {
|
|
return tm;
|
|
}
|
|
}
|
|
},
|
|
// 查询子活动
|
|
queryAct: function queryAct(_camp_id, _warn) {
|
|
if (_warn === void 0) {
|
|
_warn = true;
|
|
}
|
|
if (!this.acts) {
|
|
return;
|
|
}
|
|
var act = this.acts[_camp_id];
|
|
if (!act && _warn) {
|
|
nx.error("$Acts:子活动不存在:", _camp_id);
|
|
return null;
|
|
}
|
|
return act;
|
|
},
|
|
// ============================================================
|
|
// 活动信息
|
|
// ============================================================
|
|
|
|
// 获取活动基础信息
|
|
reqActData: function reqActData(_camp_id, _cb) {
|
|
this.SendProtocal(16603, {
|
|
bid: _camp_id
|
|
}, function (_ret, _data) {
|
|
if (_ret && _data.bid == _camp_id) {
|
|
nx.dt.fnInvoke(_cb, true, _data);
|
|
}
|
|
});
|
|
},
|
|
// 请求基本信息返回
|
|
handle16603: function handle16603(_data) {
|
|
if (!this.isGoodData(_data)) {
|
|
return;
|
|
}
|
|
},
|
|
// ============================================================
|
|
// "主题卡池-招募(抽奖)
|
|
// type1: 1-道具抽
|
|
// type2: 1-单抽,2-+连抽
|
|
// ============================================================
|
|
|
|
// 卡池抽取
|
|
reqDrawFromPool: function reqDrawFromPool(_gid, _type1, _type2, _cb) {
|
|
this.SendProtocal(31111, {
|
|
group_id: _gid,
|
|
type1: _type1,
|
|
type2: _type2
|
|
}, _cb);
|
|
},
|
|
// 卡池抽取返回
|
|
handle31111: function handle31111(_data) {
|
|
if (!this.isGoodData(_data)) {
|
|
return;
|
|
}
|
|
},
|
|
// ============================================================
|
|
// 活动奖励
|
|
// ============================================================
|
|
|
|
// 请求所有活动未领取奖励
|
|
reqActsRewards: function reqActsRewards(_cb) {
|
|
this.SendProtocal(16602, {}, _cb);
|
|
},
|
|
// 请求所有活动未领取奖励
|
|
onFreshActsRewards: function onFreshActsRewards(_data) {
|
|
if (this.isGoodData(_data)) {
|
|
this.onUpdateActsRewards(_data.holiday_list);
|
|
}
|
|
},
|
|
// 领取奖励返回结果
|
|
onUpdateActsRewards: function onUpdateActsRewards(_data) {
|
|
if (nx.dt.objGood(_data)) {
|
|
var act = this.queryAct(_data.bid);
|
|
if (act) {
|
|
act.openTip("reward", _data.can_get_num != 0);
|
|
}
|
|
return;
|
|
}
|
|
if (nx.dt.arrEmpty(_data)) {
|
|
return;
|
|
}
|
|
for (var i = 0; i < _data.length; ++i) {
|
|
var ifo = _data[i];
|
|
var _act = this.queryAct(ifo.bid);
|
|
if (!_act) {
|
|
nx.warn("$Acts:无效活动 ", ifo.bid);
|
|
continue;
|
|
}
|
|
_act.openTip("reward", ifo.can_get_num != 0);
|
|
}
|
|
},
|
|
// ============================================================
|
|
// 活动预告
|
|
// ============================================================
|
|
|
|
// 刷新
|
|
freshForeshow: function freshForeshow() {
|
|
var themes = this.vget("themes");
|
|
var DATA = game.configs.ad_show;
|
|
if (nx.dt.arrEmpty(themes) || nx.dt.objEmpty(DATA)) {
|
|
this.vset("foreshow", []);
|
|
return;
|
|
}
|
|
var ads = [];
|
|
var find = function find(_theme, _camp) {
|
|
// 0为常驻
|
|
if (_theme == 0) {
|
|
return true;
|
|
}
|
|
|
|
// 999为不显示
|
|
if (_theme == 999) {
|
|
return false;
|
|
}
|
|
for (var i in themes) {
|
|
var tm = themes[i];
|
|
if (!tm || tm.theme_id != _theme) {
|
|
continue;
|
|
}
|
|
for (var k in tm.theme_holiday_list) {
|
|
var at = tm.theme_holiday_list[k];
|
|
if (at && at.camp_id == _camp) {
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
};
|
|
for (var id in DATA.data_adshow_roll) {
|
|
var roll = DATA.data_adshow_roll[id];
|
|
var func = DATA.data_adshow_func[id];
|
|
if (!roll || !func || !find(func.total_id, func.camp_id)) {
|
|
continue;
|
|
}
|
|
var actitem = this.queryAct(func.camp_id);
|
|
var ret = nx.bridge.jumper.checkSource(actitem.data.source);
|
|
if (nx.dt.objEmpty(ret)) {
|
|
ads.push({
|
|
id: id,
|
|
sc: roll.img,
|
|
sk: roll.link,
|
|
name: func.name,
|
|
img: func.img,
|
|
link: func.link,
|
|
is_new: func.is_new,
|
|
theme_id: func.total_id,
|
|
camp_id: func.camp_id,
|
|
ico: func.cli_icon
|
|
});
|
|
}
|
|
}
|
|
this.vset("foreshow", ads);
|
|
},
|
|
// ============================================================
|
|
// 推送弹窗
|
|
// ============================================================
|
|
|
|
// 今日推送
|
|
reqPushPopup: function reqPushPopup() {
|
|
this.SendProtocal(16621, {});
|
|
},
|
|
// 今日推送
|
|
onPushPopup: function onPushPopup(_data) {
|
|
if (!this.isGoodData(_data)) {
|
|
this.vset("pushPopup", 0);
|
|
this.vset("pushToday", false);
|
|
return;
|
|
}
|
|
this.vset("pushPopup", _data.id);
|
|
this.vset("pushToday", true);
|
|
},
|
|
// 关闭推送
|
|
reqClosePushPopup: function reqClosePushPopup(_cb) {
|
|
this.SendProtocal(16622, {}, _cb);
|
|
},
|
|
// 关闭推送回复
|
|
onPushPopupClose: function onPushPopupClose(_data) {
|
|
if (!this.isGoodData(_data)) {
|
|
return;
|
|
}
|
|
this.vset("pushToday", false);
|
|
},
|
|
// ============================================================
|
|
// 活动更新通知
|
|
// ============================================================
|
|
|
|
// 固定时间更新
|
|
onFreshActs: function onFreshActs() {
|
|
for (var id in this.acts) {
|
|
var act = this.acts[id];
|
|
if (act) {
|
|
act.reqBaseFromServer();
|
|
}
|
|
}
|
|
},
|
|
// ============================================================
|
|
// 活动红点提示
|
|
// ============================================================
|
|
|
|
// 组建红点结构
|
|
buildTipsView: function buildTipsView() {
|
|
var _this2 = this;
|
|
var themes = this.vget("themes");
|
|
var tree = {
|
|
key: "acts",
|
|
sub: {}
|
|
};
|
|
|
|
// 全主题遍历
|
|
var _loop2 = function _loop2() {
|
|
var tm = themes[i];
|
|
var tk = "acts." + tm.theme_id;
|
|
var ifo = {
|
|
key: tk,
|
|
sub: {}
|
|
};
|
|
|
|
// 全活动遍历
|
|
var arr = tm.theme_holiday_list || [];
|
|
var _loop3 = function _loop3() {
|
|
var temp = arr[k];
|
|
var cateId = "" + temp.cate;
|
|
var campId = "" + temp.camp_id;
|
|
var act = _this2.queryAct(campId, false);
|
|
if (!act) {
|
|
return "continue";
|
|
}
|
|
|
|
// 活动前缀格式: acts.{主题编号}.{Cate类别}.{活动编号}
|
|
if (!ifo.sub[cateId]) {
|
|
ifo.sub[cateId] = {
|
|
key: tk + "." + cateId,
|
|
sub: {}
|
|
};
|
|
}
|
|
if (!ifo.sub[cateId].sub[campId]) {
|
|
ifo.sub[cateId].sub[campId] = {
|
|
key: tk + "." + cateId + "." + campId,
|
|
sub: {}
|
|
};
|
|
}
|
|
var keys = act.tipKeys();
|
|
keys = ["reward"].concat(keys);
|
|
keys.forEach(function (_key) {
|
|
ifo.sub[cateId].sub[campId].sub[_key] = {
|
|
key: tk + "." + cateId + "." + campId + "." + _key
|
|
};
|
|
});
|
|
};
|
|
for (var k in arr) {
|
|
var _ret2 = _loop3();
|
|
if (_ret2 === "continue") continue;
|
|
}
|
|
tree.sub["" + tm.theme_id] = ifo;
|
|
};
|
|
for (var i in themes) {
|
|
_loop2();
|
|
}
|
|
nx.mTip.append(tree);
|
|
return tree;
|
|
},
|
|
// 获取主题提示键
|
|
getThemeTipKey: function getThemeTipKey(_theme_id) {
|
|
return "acts." + _theme_id;
|
|
},
|
|
// ============================================================
|
|
// 活动引导
|
|
// ============================================================
|
|
|
|
// 活动引导
|
|
needGuide: function needGuide(_camp_id, _cb) {
|
|
this.SendProtocal(16623, {
|
|
camp_id: _camp_id
|
|
}, _cb);
|
|
},
|
|
// 活动引导
|
|
onActGuide: function onActGuide() {},
|
|
// 引导完成上传
|
|
reqDoneGuide: function reqDoneGuide(_camp_id, _cb) {
|
|
this.SendProtocal(16624, {
|
|
camp_id: _camp_id
|
|
}, _cb);
|
|
},
|
|
// 引导上传
|
|
onActGuideDone: function onActGuideDone() {}
|
|
});
|
|
|
|
// 模块导出
|
|
module.exports = ActManager;
|
|
|
|
cc._RF.pop(); |