Files
fc/dev/project/library/imports/7c/7c451003-08e4-4342-b8e0-5667f33466a0.js
2026-05-24 10:21:26 +08:00

411 lines
11 KiB
JavaScript

"use strict";
cc._RF.push(module, '7c451ADCORDQrjgVmfzNGag', 'cmp.act.limit.wings');
// Scripts/mod/acts/limitWings/cmp/cmp.act.limit.wings.js
"use strict";
/******************************************************************
*
* 限定僚机
*
******************************************************************/
var ActPage = require("act.page.base");
var ItemLayout = require("cmp.item.layout");
var BridgeItemBinder = require("bridge.binder.item.icon.count");
var TipsController = require("tips_controller");
var FID = require("bridge.function.ids");
cc.Class({
"extends": ActPage,
properties: {
nodLogo: {
"default": null,
type: cc.Node
},
nodDate: {
"default": null,
type: cc.Node
},
tipTimes: {
"default": null,
type: cc.Node
},
nodCoin: {
"default": null,
type: BridgeItemBinder
},
nodScore: {
"default": null,
type: BridgeItemBinder
},
nodOps: {
"default": null,
type: cc.Node
},
nodReward: {
"default": null,
type: cc.Node
},
nodTotal: {
"default": null,
type: cc.Node
},
tipCover: {
"default": null,
type: cc.Node
},
tipReward: {
"default": null,
type: ItemLayout
}
},
// 初始化
build: function build(_data) {
this._super(_data);
// 置空
if (!this.mod || nx.dt.objEmpty(this.data)) {
this.setEmpty();
return;
}
// 配置查询
this.configs = this.mod.queryConfigs();
if (!this.configs) {
this.setEmpty();
return;
}
// 活动监听
this.mod.vbind(this, [["LimitWingsFreshed", this.onFreshData.bind(this)]]);
// 基本信息
this.freshBasic();
},
// 显示
onEnable: function onEnable() {
this.tipCover.active = false;
this.tipTimes.active = false;
// 刷新
if (this.mod) {
this.mod.reqBaseData();
}
},
// 销毁
onDestroy: function onDestroy() {
// 活动监听解除
if (this.mod) {
this.mod.vunbind(this);
}
this._super();
},
// 置空
setEmpty: function setEmpty() {
nx.gui.setActive(this, "right", false);
},
// 基本信息
freshBasic: function freshBasic() {
var _this = this;
// 置空
if (!this.mod || !this.configs || nx.dt.objEmpty(this.data)) {
this.setEmpty();
return;
}
// Logo刷新
var tags = cc.path.join("locals/{lang}/images/spriteparty", this.configs.bg);
nx.gui.setSpriteFrame(this.nodLogo, "img", nx.res.fmtPath(tags));
// 道具绑定
this.nodCoin.setID(this.configs.prop_id, function () {
_this.freshOps();
});
// 积分绑定
this.nodScore.setID(this.configs.point_id);
// 红点绑定
var tip1 = nx.gui.getComponent(this.nodOps, "once/tip", "nx.vb.visible");
if (tip1) {
tip1.setTarget(nx.mTip, this.mod.getTipKey("once"));
}
var tip2 = nx.gui.getComponent(this.nodOps, "ten/tip", "nx.vb.visible");
if (tip2) {
tip2.setTarget(nx.mTip, this.mod.getTipKey("ten"));
}
// 自选提示
var txt = nx.text.format("僚机自选提示", this.configs.min_num);
nx.gui.setString(this.nodTotal, "txt", txt);
// 剩余时间
var secs = this.mod.data.end_time - client.socket.getTime();
this.freshDate(secs);
},
// 刷新活动日期
freshDate: function freshDate(_secs) {
var time = nx.bridge.time.toNeedSeconds(_secs);
nx.gui.setString(this.nodDate, "txt", time);
},
// 信息刷新
onFreshData: function onFreshData() {
// 累计
var times = this.mod.vget("LimitWingsTimes");
nx.gui.setString(this.nodTotal, "num", times);
// 自选剩余
if (times >= this.configs.max_num) {
this.tipTimes.active = false;
} else {
this.tipTimes.active = true;
var loop = this.configs.min_num || 40;
var remains = loop - times % loop;
var txt = nx.text.format("僚机自选", remains);
nx.gui.setString(this.tipTimes, "txt", txt);
}
// 一轮结束的特殊判断
var prog = Math.floor(times % this.configs.min_num) / this.configs.min_num;
if (times > 0 && times % this.configs.min_num == 0) {
if (this.mod.canReward()) {
times -= 1;
prog = 1;
}
}
// 特殊:次数超过一轮并且有奖品
if (times >= this.configs.min_num && this.mod.canReward()) {
prog = 1;
}
// 奖励统计
var items = this.mod.vget("LimitWingsRewards");
var limit1 = Math.floor(this.configs.max_num / this.configs.min_num) - 1;
var limit2 = Math.floor(Math.max(0, times) / this.configs.min_num);
var limit = Math.min(limit1, limit2);
var range = [limit * this.configs.min_num, (limit + 1) * this.configs.min_num];
// let arr = [];
// items.forEach( _t => {
// if( _t.id > range[0] && _t.id <= range[1] ) {
// arr.push( _t );
// }
// } );
// arr.sort( ( _a, _b ) => {
// return _a.id - _b.id;
// } );
items.sort(function (_a, _b) {
return _a.id - _b.id;
});
this.freshRewards(Math.min(1, prog), items);
},
// 刷新奖励
freshRewards: function freshRewards(_progress, _list) {
// 进度
var prog = nx.gui.getComponent(this.nodReward, "progress", cc.ProgressBar);
if (prog) {
prog.progress = _progress;
}
var rewards = _list || [];
if (rewards.length != 5) {
nx.error("\u50DA\u673A\u7948\u613F\u5956\u52B1\u6709\u8BEF\uFF1A" + rewards.length);
return;
}
// 状态转动作
// status: 0-未完成,1-可领取,2-已领取
// action1 普通状态
// action2 可开启状态
// action3 开启过程,reword事件出获得道具
// action4 开完状态
var st2act = function st2act(_st) {
switch (_st) {
case 0:
return 'action1';
case 1:
return 'action2';
case 2:
return 'action4';
default:
return 'action1';
}
};
// 单设
var self = this;
var single = function single(_box, _time, _data) {
// 次数
nx.gui.setString(_time, "num", _data.id);
// 宝箱
var cfgs = self.mod.queryReward(_data.id);
if (!cfgs) {
return;
}
var act = st2act(_data.status);
var res = PathTool.getSpinePath(cfgs.res_id, "action", false);
var cmp = nx.gui.getComponent(_box, "", "nx.fx.spine");
cmp.play(res, act, null, true);
_box.prayData = _data;
nx.gui.setActive(_box, "tip", _data.status == 1);
};
for (var i = 0; i < rewards.length; ++i) {
single(nx.gui.find(this.nodReward, "boxes/b" + (i + 1)), nx.gui.find(this.nodReward, "times/t" + (i + 1)), rewards[i]);
}
},
// 变化信息
freshOps: function freshOps() {
// 置空
if (!this.mod || !this.configs || nx.dt.objEmpty(this.data)) {
return;
}
// 按钮设置
var autoOp = function autoOp(_node, _draw, _pt) {
var tinfo = gitemdata(_draw[0]);
if (tinfo) {
nx.bridge.setIcon(_node, "btn/list/icon", tinfo.icon);
nx.gui.setString(_node, "btn/list/num", _draw[1]);
}
var pinfo = gitemdata(_pt[0]);
if (pinfo) {
nx.bridge.setIcon(_node, "score/infos/icon", pinfo.icon);
nx.gui.setString(_node, "score/infos/num", "x" + _pt[1]);
}
};
// 操作刷新
autoOp(nx.gui.find(this.nodOps, "once"), this.configs.draw_one[0], this.configs.one_point_num[0]);
autoOp(nx.gui.find(this.nodOps, "ten"), this.configs.draw_ten[0], this.configs.ten_point_num[0]);
},
// 点击单抽
onTouchOnce: function onTouchOnce() {
var _this2 = this;
if (!this.configs || !this.mod) {
return;
}
this.mod.reqSummon(true, function (_ret, _msg, _code) {
// 道具不足
if (!_ret && _code == 101) {
nx.tbox(_msg);
_this2.onTouchCoin();
}
});
},
// 点击十抽
onTouchTen: function onTouchTen() {
var _this3 = this;
if (!this.configs || !this.mod) {
return;
}
this.mod.reqSummon(false, function (_ret, _msg, _code) {
// 道具不足
if (!_ret && _code == 101) {
nx.tbox(_msg);
_this3.onTouchCoin();
}
});
},
// 点击规则
onTouchRule: function onTouchRule() {
var rule = this.mod ? this.mod.queryRule() : "";
if (nx.dt.strNEmpty(rule)) {
var TC = TipsController.getInstance();
TC.showTextPanel("tip", rule);
}
},
// 点击道具
onTouchCoin: function onTouchCoin() {
if (this.actRoot && this.configs) {
this.actRoot.jumpToMenu(this.configs.jump);
}
},
// 点击奖池
onTouchChi: function onTouchChi() {
var data = this.configs.award;
if (nx.dt.arrEmpty(data)) {
return;
}
var args = {
title: "奖池详情",
group: []
};
var ids = [];
for (var i = 0; i < data[0].length; ++i) {
ids.push(data[0][i][0]);
}
args.group.push({
name: "限定奖池",
partners: ids
});
var ids2 = [];
for (var _i = 0; _i < data[1].length; ++_i) {
ids2.push(data[1][_i][0]);
}
args.group.push({
name: "基础奖池",
partners: ids2
});
nx.bridge.createPanel("WndPartnerPool", args);
},
// 点击兑换
onTouchShop: function onTouchShop() {
nx.bridge.jumper.jump2Window(FID.PartnerWingsShops);
},
// 点击头像
onTouchAvatar: function onTouchAvatar(_btn) {
var pdata = _btn ? _btn.pdata : null;
if (!pdata) {
return;
}
var key = pdata.bid + "_" + pdata.init_star;
var propsData = gdata("partner_data", "data_partner_show", key);
propsData.star = pdata.init_star;
propsData.break_lev = 0;
TipsController.getInstance().showPartnerTips(propsData);
},
// 点击宝箱
onTouchBox: function onTouchBox(_box) {
var _this4 = this;
var info = _box ? _box.prayData : null;
if (!info) {
return;
}
// 详情
if (info.status != 1) {
var cfgs = this.mod.queryReward(info.id);
if (cfgs && nx.dt.arrNEmpty(cfgs.rewards)) {
this.tipCover.active = true;
this.tipReward.rebuild(cfgs.rewards);
var pos = _box.convertToWorldSpaceAR(cc.Vec2.ZERO);
pos = this.tipCover.convertToNodeSpaceAR(pos);
this.tipReward.node.y = pos.y;
}
return;
}
// 拆盒
// action3 开启过程,reword事件出获得道具
var cmp = nx.gui.getComponent(_box, "", "nx.fx.spine");
if (cmp) {
cmp.action("action3", false, function (_event) {
// 音效
if (_event == 'reword') {
nx.audio.playSFX("audios/effects/del", false);
}
// 完成
if (_event == 'complete') {
_this4.mod.reqReward();
}
});
}
},
// 点击提示覆盖层
onTouchTipCover: function onTouchTipCover() {
this.tipCover.active = false;
}
});
cc._RF.pop();