Files
fc/dev/project/library/imports/4a/4ad07c3c-efc8-4d05-a5e5-215089763748.js
2026-05-24 10:21:26 +08:00

293 lines
10 KiB
JavaScript

"use strict";
cc._RF.push(module, '4ad07w878hNBaXlIVCJdjdI', 'cmp.partner.holy.refinement');
// Scripts/mod/partner/cmps/artifact/cmp.partner.holy.refinement.js
"use strict";
/******************************************************************
*
* 战斗义肢洗炼
*
******************************************************************/
var BridgeWindow = require("bridge.window");
var BackPackConst = require("backpack_const");
var HeroController = require("hero_controller");
var BackpackController = require("backpack_controller");
var HeroEvent = require("hero_event");
var HeroCalculate = require("hero_calculate");
cc.Class({
"extends": BridgeWindow,
properties: {
nodholy: {
"default": null,
type: cc.Node,
displayName: "战斗义肢显示"
},
nodProps: {
"default": null,
type: cc.Node,
displayName: "战斗义肢当前属性"
},
nodCProps: {
"default": null,
type: cc.Node,
displayName: "战斗义肢洗炼属性"
},
nodBottom: {
"default": null,
type: cc.Node,
displayName: "操作"
},
nodScore: {
"default": null,
type: cc.Node,
displayName: "评分"
}
},
onLoad: function onLoad() {
this.bindGEvent(HeroEvent.Holy_Equipment_Update_Event, this.freshByMsg.bind(this));
this.bindGEvent(EventId.MODIFY_GOODS_NUM, this.freshAttrInbag.bind(this));
},
// 重载:参数打开
onOpenConfigs: function onOpenConfigs(_params) {
// 传入战斗义肢的数据
// console.log( "傳入的戰鬥義肢數據" + JSON.stringify( _params ) );
this.holyData = _params.eqm;
this.partner = _params.partner;
// 固定属性相关
var cmp = nx.gui.getComponent(this.nodholy, "holy", "cmp.item.base");
if (cmp) {
cmp.setData(this.holyData);
}
this.freshHolyEqm();
},
freshAttrInbag: function freshAttrInbag(_bagcode, _list) {
if (_bagcode == BackPackConst.Bag_Code.EQUIPS) {
var attrs = [];
for (var i in _list) {
var show = nx.dt.objClone(_list[i]);
if (i == this.holyData.id) {
show.partner_id = 0;
show.holy_eqm = [show];
this.freshByMsg(show);
break;
}
}
// this.freshByMsg( )
}
},
freshByMsg: function freshByMsg(_data) {
var _this = this;
this.partner = _data;
var holy = _data.holy_eqm;
var change = {};
var time = 0;
var _loop = function _loop() {
var holy_item = holy[i];
if (holy_item.id == _this.holyData.id) {
var times = holy_item.extra;
for (var _i = 0; _i < times.length; _i++) {
var item = times[_i];
if (item.extra_k == 10) {
time = item.extra_v;
}
}
var holylst = holy_item.holy_eqm_attr;
holylst.forEach(function (_item) {
if (_item.pos > 100) {
change = holy_item;
} else {
_this.holyData.holy_eqm_attr = holylst;
}
});
}
};
for (var i = 0; i < holy.length; i++) {
_loop();
}
if (!nx.dt.objEmpty(change)) {
this.freshMat();
this.freshRandomAfter(change);
} else {
this.freshHolyEqm();
}
nx.gui.setString(this.nodBottom, "times_tip", nx.text.format("The equipment has been refined", time));
},
freshHolyEqm: function freshHolyEqm() {
this.freshMat();
var main_attr = this.holyData.main_attr;
var title = game.configs.attr_data.data_id_to_name[main_attr[0].attr_id];
var icon_name = game.configs.attr_data.data_id_to_key[main_attr[0].attr_id];
var cfg = game.configs.partner_holy_eqm_data.data_holy_attr_score[icon_name];
this.base_score = cfg.score * 0.001 * main_attr[0].attr_val;
var path = cc.path.join("coms/images/" + "ico_" + icon_name);
nx.gui.setSpriteFrame(this.nodholy, "prop/ico", path);
nx.gui.setString(this.nodholy, "prop/title", title);
nx.gui.setString(this.nodholy, "prop/txt", main_attr[0].attr_val);
this.freshRandom();
},
freshRandomAfter: function freshRandomAfter(_change) {
var holy_eqm_attr = _change.holy_eqm_attr;
holy_eqm_attr.sort(Utils.tableUpperSorter(["pos"]));
var new_holy_eqm_attr = [];
var model = HeroController.getInstance().getModel();
var chd = nx.gui.find(this.nodCProps, "props").children;
nx.gui.hideAllChildren(this.nodCProps, "props");
var score1 = [];
for (var i = 0; i < holy_eqm_attr.length; i++) {
var attr = holy_eqm_attr[i];
var attr_node = chd[i];
if (attr && attr.pos > 100) {
nx.gui.setActive(attr_node, "", true);
var title = game.configs.attr_data.data_id_to_key[attr.attr_id];
nx.bridge.attrs.setAttribute(nx.gui.find(attr_node, "prop"), [title, attr.attr_val]);
var cfg = game.configs.partner_holy_eqm_data.data_holy_attr_score[title];
score1.push(cfg.score * 0.001 * attr.attr_val);
new_holy_eqm_attr.push({
attr_key: title,
attr_val: attr.attr_val
});
var prog = nx.gui.getComponent(attr_node, "prop/prog", cc.ProgressBar);
var max_count = model.getHolyEquipmentMaxAttrByItemIdAttrKey(this.holyData.config.id, title);
var per = attr.attr_val / max_count;
nx.gui.setActive(attr_node, "prop/val", per != 1);
nx.gui.setActive(attr_node, "prop/prog/max", per == 1);
if (prog) {
prog.progress = per;
}
}
}
nx.gui.setActive(this.nodBottom, "ops/save", true);
if (holy_eqm_attr && holy_eqm_attr.length > 0) {
var new_score = HeroCalculate.getInstance().holyEquipMentPower(new_holy_eqm_attr) || 0;
var num = 0;
num = parseInt(this.holyData.score);
var sum_score = new_score + num + Math.ceil(this.base_score);
var add_score = sum_score - (this.old_score + num + Math.ceil(this.base_score));
if (add_score > 0) {
add_score = "+" + add_score;
} else {
add_score = +add_score;
}
nx.gui.setString(this.nodScore, "txt", sum_score);
nx.gui.setString(this.nodScore, "add", add_score);
} else {
nx.gui.setString(this.nodScore, "txt", "???");
nx.gui.setString(this.nodScore, "add", "???");
}
},
freshRandom: function freshRandom() {
var holy_eqm_attr = this.holyData.holy_eqm_attr;
holy_eqm_attr.sort(function (a, b) {
return a.pos - b.pos;
});
var model = HeroController.getInstance().getModel();
var before_data = [];
var old_holy_eqm_attr = [];
var chd = nx.gui.find(this.nodProps, "props").children;
nx.gui.hideAllChildren(this.nodProps, "props");
var score0 = [];
for (var i = 0; i < holy_eqm_attr.length; i++) {
var attr = holy_eqm_attr[i];
var attr_node = chd[i];
if (attr && attr.pos < 100) {
nx.gui.setActive(attr_node, "", true);
var title = game.configs.attr_data.data_id_to_key[attr.attr_id];
nx.bridge.attrs.setAttribute(nx.gui.find(attr_node, "prop"), [title, attr.attr_val]);
var cfg = game.configs.partner_holy_eqm_data.data_holy_attr_score[title];
score0.push(cfg.score * 0.001 * attr.attr_val);
var prog = nx.gui.getComponent(attr_node, "prop/prog", cc.ProgressBar);
var max_count = model.getHolyEquipmentMaxAttrByItemIdAttrKey(this.holyData.config.id, title);
var per = attr.attr_val / max_count;
nx.gui.setActive(attr_node, "prop/val", per != 1);
nx.gui.setActive(attr_node, "prop/prog/max", per == 1);
if (prog) {
prog.progress = per;
}
}
if (attr.pos > 100) {
before_data.push(attr);
} else {
old_holy_eqm_attr.push({
attr_key: game.configs.attr_data.data_id_to_key[attr.attr_id],
attr_val: attr.attr_val
});
}
}
this.old_score = HeroCalculate.getInstance().holyEquipMentPower(old_holy_eqm_attr);
if (!nx.dt.arrEmpty(before_data)) {
this.freshRandomAfter({
holy_eqm_attr: before_data
});
}
nx.gui.setActive(this.nodBottom, "ops/save", !nx.dt.arrEmpty(before_data));
var times = this.holyData.extra;
var time = 0;
for (var _i2 = 0; _i2 < times.length; _i2++) {
var item = times[_i2];
if (item.extra_k == 10) {
time = item.extra_v;
}
}
nx.gui.setString(this.nodBottom, "times_tip", nx.text.format("The equipment has been refined", time));
nx.gui.setActive(this.nodProps, "desc", false);
// this.freshLockCost();
},
freshLockCost: function freshLockCost() {
// 花费取得
var pfg = game.configs.partner_holy_eqm_data.data_const.lock_pay_diamon;
// 根据当前的选择锁定属性进行取值
this.selects = [];
var chd = nx.gui.find(this.nodProps, "props").children;
for (var i = 0; i < chd.length; i++) {
var nod = chd[i];
var toggle = nx.gui.getComponent(nod, "lock", cc.Toggle);
if (toggle.isChecked) {
this.selects.push({
pos: i + 1
});
}
}
var cost = this.selects.length - 1 >= 0 ? pfg.val[this.selects.length - 1][1] : 0;
nx.bridge.setIconS(this.nodProps, "desc/icon", 3);
nx.gui.setString(this.nodProps, "desc/txt", cost);
nx.gui.setActive(this.nodProps, "desc", !nx.dt.arrEmpty(this.selects));
},
onTouchSelecton: function onTouchSelecton() {
this.freshLockCost();
},
freshMat: function freshMat() {
var mfg = gdata("partner_holy_eqm_data", "data_base_info", this.holyData.config.id);
var chd = nx.gui.find(this.nodBottom, "matInfo/mats").children;
var mats = mfg.reset_price;
for (var i = 0; i < mats.length; i++) {
var mat = mats[i];
var nod = chd[i];
if (!mat) {
nx.gui.setActive(nod, "", false);
continue;
}
var count = BackpackController.getInstance().getModel().getItemNumByBid(mat[0]);
nx.bridge.setIconS(nod, "icon", mat[0]);
nx.gui.setString(nod, "txt", nx.dt.shortCount(mat[1]) + "/" + nx.dt.shortCount(count));
}
},
onTouchRefine: function onTouchRefine() {
var HC = HeroController.getInstance();
if (HC) {
HC.sender11094(this.partner.partner_id, this.holyData.id, this.selects || []);
}
},
onTouchSave: function onTouchSave() {
var HC = HeroController.getInstance();
if (HC) {
HC.sender11090(this.partner.partner_id, this.holyData.id, 1);
}
}
});
cc._RF.pop();