310 lines
11 KiB
JavaScript
310 lines
11 KiB
JavaScript
|
|
/******************************************************************
|
|||
|
|
*
|
|||
|
|
* 僚机背包页
|
|||
|
|
*
|
|||
|
|
******************************************************************/
|
|||
|
|
const BridgeComponent = require( "bridge.component" );
|
|||
|
|
const PathTool = require("pathtool");
|
|||
|
|
const HallowsConst = require("hallows_const");
|
|||
|
|
const HallowsEvent = require("hallows_event");
|
|||
|
|
const HallowsController = require("hallows_controller");
|
|||
|
|
const BackpackController = require("backpack_controller");
|
|||
|
|
var PartnerCalculate = require("partner_calculate");
|
|||
|
|
|
|||
|
|
cc.Class( {
|
|||
|
|
|
|||
|
|
extends: BridgeComponent,
|
|||
|
|
|
|||
|
|
properties: {
|
|||
|
|
step_lvup_value:{
|
|||
|
|
default:null,
|
|||
|
|
type:cc.RichText
|
|||
|
|
},
|
|||
|
|
step_progress_value:{
|
|||
|
|
default:null,
|
|||
|
|
type:cc.RichText
|
|||
|
|
},
|
|||
|
|
step_progress:{
|
|||
|
|
default:null,
|
|||
|
|
type:cc.ProgressBar
|
|||
|
|
},
|
|||
|
|
cost_icon_1:{
|
|||
|
|
default:null,
|
|||
|
|
type:cc.Sprite
|
|||
|
|
},
|
|||
|
|
cost_icon_2:{
|
|||
|
|
default:null,
|
|||
|
|
type:cc.Sprite
|
|||
|
|
},
|
|||
|
|
cost_num_1:{
|
|||
|
|
default:null,
|
|||
|
|
type:cc.Label
|
|||
|
|
},
|
|||
|
|
cost_num_2:{
|
|||
|
|
default:null,
|
|||
|
|
type:cc.Label
|
|||
|
|
},
|
|||
|
|
auto_advanced_label:{
|
|||
|
|
default:null,
|
|||
|
|
type:cc.Label
|
|||
|
|
},
|
|||
|
|
attr_labels:{
|
|||
|
|
default:[],
|
|||
|
|
type:[cc.Label]
|
|||
|
|
},
|
|||
|
|
step_auto_advanced_btn_label:{
|
|||
|
|
default:null,
|
|||
|
|
type:cc.Label
|
|||
|
|
},
|
|||
|
|
main:{
|
|||
|
|
default:null,
|
|||
|
|
type:cc.Node
|
|||
|
|
},
|
|||
|
|
lv_max:{
|
|||
|
|
default:null,
|
|||
|
|
type:cc.Node
|
|||
|
|
}
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
onLoad: function() {
|
|||
|
|
this._super();
|
|||
|
|
|
|||
|
|
this.ctrl = HallowsController.getInstance();
|
|||
|
|
this.model = this.ctrl.getModel();
|
|||
|
|
this.is_in_advance = false;
|
|||
|
|
this.hallows_uplv_cost_bid_1 = 0;
|
|||
|
|
this.hallows_uplv_cost_num_1 = 0;
|
|||
|
|
this.hallows_uplv_cost_bid_2 = 0;
|
|||
|
|
this.hallows_uplv_cost_num_2 = 0;
|
|||
|
|
|
|||
|
|
// 事件监听
|
|||
|
|
this.bindGEvent( HallowsEvent.HallowsAdvanceEvent, this.updateHallowsAdvence.bind( this ) );
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
updateHallowsAdvence(id, result){
|
|||
|
|
if(this.select_hallows && this.select_hallows.id != id){
|
|||
|
|
this.changeAutoAdvanceStatus(false);
|
|||
|
|
}else{
|
|||
|
|
if(result == 0 || result == 1){//0标识材料之类的不足 1标识升阶了,这两种情况都停掉
|
|||
|
|
this.changeAutoAdvanceStatus(false);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
getCostObj(bid){
|
|||
|
|
if(bid == this.hallows_uplv_cost_bid_1){
|
|||
|
|
this.setCostDataToNode(this.cost_icon_1, this.cost_num_1, bid, this.hallows_uplv_cost_num_1);
|
|||
|
|
}else if(bid == this.hallows_uplv_cost_bid_2){
|
|||
|
|
this.setCostDataToNode(this.cost_icon_2, this.cost_num_2, bid, this.hallows_uplv_cost_num_2);
|
|||
|
|
}
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
onEnable(){
|
|||
|
|
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
onDisable(){
|
|||
|
|
this.changeAutoAdvanceStatus(false);
|
|||
|
|
this.clearAutoTimeticket();
|
|||
|
|
// 监听事件释放
|
|||
|
|
// this.unbindGEvents();
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
setData(hallows){
|
|||
|
|
this.select_hallows = hallows;
|
|||
|
|
|
|||
|
|
let max_lev = game.configs.hallows_data.data_max_lev[this.select_hallows.id];
|
|||
|
|
if(this.select_hallows && this.select_hallows.vo.step >= max_lev){
|
|||
|
|
this.lv_max.active = true;
|
|||
|
|
this.main.active = false;
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
this.updateStepInfo();
|
|||
|
|
this.updateHallowsBaseInfo();
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
updateHallowsBaseInfo(){
|
|||
|
|
if(this.select_hallows == null)return;
|
|||
|
|
|
|||
|
|
// 基础属性
|
|||
|
|
var vo = this.select_hallows.vo;
|
|||
|
|
if(vo == null)return;
|
|||
|
|
//名称
|
|||
|
|
this.step_lvup_value.string =cc.js.formatStr("<color=#27ae10>%s</color>/%s",vo.step,game.configs.hallows_data.data_max_lev[vo.id]);
|
|||
|
|
|
|||
|
|
var step_config = gdata("hallows_data","data_info",Utils.getNorKey(vo.id, vo.step));
|
|||
|
|
var next_step_config = gdata("hallows_data","data_info",Utils.getNorKey(vo.id, vo.step+1)) || {};
|
|||
|
|
|
|||
|
|
|
|||
|
|
for(var j in step_config.attr){
|
|||
|
|
if(j > 2)break;//UI只支持显示两个技能
|
|||
|
|
var attr_key = step_config.attr[j][0];
|
|||
|
|
var attr_val = step_config.attr[j][1] || 0;
|
|||
|
|
let vals = nx.bridge.attrs.fmtAttribute(attr_key,attr_val);
|
|||
|
|
var next_attr_val = 0;
|
|||
|
|
//取出下一级属性加成,计算临时变量
|
|||
|
|
if(next_step_config.attr){
|
|||
|
|
for(var k in next_step_config.attr){
|
|||
|
|
if(next_step_config.attr[k][0] && next_step_config.attr[k][0] == attr_key){
|
|||
|
|
next_attr_val = next_step_config.attr[k][1] || 0;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
var icon = PathTool.getAttrIconRes(attr_key);
|
|||
|
|
var add_value = 0;; // 临时变量
|
|||
|
|
|
|||
|
|
if(next_attr_val > 0){
|
|||
|
|
var ratio_config = game.configs.hallows_data.data_const["temporary_ratio"] || {};
|
|||
|
|
var ratio = ratio_config.val || 800;
|
|||
|
|
add_value = Math.round(vo.lucky/step_config.max_lucky*(next_attr_val-attr_val)*(ratio/1000))
|
|||
|
|
}
|
|||
|
|
let is_per = PartnerCalculate.isShowPerByStr(attr_key);
|
|||
|
|
//当前属性值=配置表中的值+圣印加成的值
|
|||
|
|
var stone_config = game.configs.hallows_data.data_const["stone_attribute"];
|
|||
|
|
if(vo.seal > 0 && stone_config){
|
|||
|
|
var stone_val = 0;
|
|||
|
|
for(var k in stone_config.val){
|
|||
|
|
if(stone_config.val[k][0] && stone_config.val[k][0] == attr_key){
|
|||
|
|
stone_val = stone_config.val[k][1] || 0;
|
|||
|
|
break
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
attr_val = attr_val + stone_val*vo.seal;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
attr_val = vals.val;
|
|||
|
|
// if(is_per){
|
|||
|
|
// attr_val = (attr_val/10) +"%";
|
|||
|
|
// }
|
|||
|
|
var attr_str = cc.js.formatStr("<img src='%s'/> %s:%s",icon, vals.name, attr_val.toString());
|
|||
|
|
if(add_value > 0){
|
|||
|
|
if(is_per){
|
|||
|
|
add_value = (add_value/10) + "%";
|
|||
|
|
}
|
|||
|
|
attr_str = attr_str + cc.js.formatStr(" +%s", add_value.toString());
|
|||
|
|
}
|
|||
|
|
this.attr_labels[j].string = ""+vals.name+":"+attr_val.toString();
|
|||
|
|
}
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
// 重载:关闭前
|
|||
|
|
onPreClosed: function() {
|
|||
|
|
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
//设置神器升级相关显示
|
|||
|
|
updateStepInfo:function(){
|
|||
|
|
if(this.select_hallows == null)return;
|
|||
|
|
var vo = this.select_hallows.vo;
|
|||
|
|
if(!vo)return;
|
|||
|
|
|
|||
|
|
var step_config = gdata("hallows_data","data_info",Utils.getNorKey(vo.id, vo.step));
|
|||
|
|
if(step_config){
|
|||
|
|
//进度条
|
|||
|
|
this.step_progress_value.string = cc.js.formatStr("<color=#27ae10>%s</color>/%s",vo.lucky,step_config.max_lucky);
|
|||
|
|
this.step_progress.progress = vo.lucky/step_config.max_lucky;
|
|||
|
|
|
|||
|
|
// 神器升级消耗
|
|||
|
|
var expend_1 = step_config.loss[0];
|
|||
|
|
var expend_2 = step_config.loss[1];
|
|||
|
|
let is_one = false;
|
|||
|
|
let is_two = false;
|
|||
|
|
if(expend_1){
|
|||
|
|
var bid = expend_1[0];
|
|||
|
|
var num = expend_1[1];
|
|||
|
|
this.hallows_uplv_cost_bid_1 = bid;
|
|||
|
|
this.hallows_uplv_cost_num_1 = num;
|
|||
|
|
this.setCostDataToNode(this.cost_icon_1, this.cost_num_1, bid, num);
|
|||
|
|
var count = BackpackController.getInstance().getModel().getItemNumByBid(bid);
|
|||
|
|
if(count >= num){
|
|||
|
|
is_one = true;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
if(expend_2){
|
|||
|
|
var bid2 = expend_2[0];
|
|||
|
|
var num2 = expend_2[1];
|
|||
|
|
this.hallows_uplv_cost_bid_2 = bid2;
|
|||
|
|
this.hallows_uplv_cost_num_2 = num2;
|
|||
|
|
this.setCostDataToNode(this.cost_icon_2, this.cost_num_2, bid2, num2) ;
|
|||
|
|
var count2 = BackpackController.getInstance().getModel().getItemNumByBid(bid2);
|
|||
|
|
if(count2 >= num2){
|
|||
|
|
is_two = true;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if(is_one && is_two){
|
|||
|
|
nx.mTip.openTip("partner.hallows.levup",true);
|
|||
|
|
}else{
|
|||
|
|
nx.mTip.openTip("partner.hallows.levup",false);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
// 显示消耗数据
|
|||
|
|
setCostDataToNode:function( item_icon, item_label, item_bid, item_num ){
|
|||
|
|
var item_config = Utils.getItemConfig(item_bid);
|
|||
|
|
if(item_config){
|
|||
|
|
var res = PathTool.queryIconPath(item_config.icon)
|
|||
|
|
cc.loader.loadRes(res, cc.SpriteFrame, (err,sf_obj)=> {
|
|||
|
|
if(err){
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
item_icon.spriteFrame = sf_obj;
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
var count = BackpackController.getInstance().getModel().getItemNumByBid(item_bid);
|
|||
|
|
item_label.string = cc.js.formatStr("%s/%s", Utils.getMoneyString(count, true,false), Utils.getMoneyString(item_num, true,false));
|
|||
|
|
}
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
clickStepAdvanced(){
|
|||
|
|
this.changeAutoAdvanceStatus(false);
|
|||
|
|
if(this.select_hallows){
|
|||
|
|
this.ctrl.requestHallowsAdvance(this.select_hallows.id, false) ;
|
|||
|
|
}
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
clickAutoStepAdvanced(){
|
|||
|
|
let is_in_advance = !this.is_in_advance;
|
|||
|
|
if(is_in_advance && this.select_hallows){
|
|||
|
|
this.ctrl.requestHallowsAdvance(this.select_hallows.id, false) ;
|
|||
|
|
}
|
|||
|
|
this.changeAutoAdvanceStatus(is_in_advance);
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
//自动进阶显示状态
|
|||
|
|
changeAutoAdvanceStatus:function(is_in_advance){
|
|||
|
|
if(is_in_advance == this.is_in_advance)return;
|
|||
|
|
this.is_in_advance = is_in_advance;
|
|||
|
|
if(!this.select_hallows.id){
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if(this.is_in_advance){
|
|||
|
|
this.step_auto_advanced_btn_label.string = nx.text.getKey("lab_hallows_main_window_tip20");
|
|||
|
|
if(this.auto_time_ticket == null){
|
|||
|
|
this.auto_time_ticket = gcore.Timer.set((function () {
|
|||
|
|
if(this.is_in_advance){
|
|||
|
|
this.ctrl.requestHallowsAdvance(this.select_hallows.id, false);
|
|||
|
|
}
|
|||
|
|
}).bind(this), 200,-1);
|
|||
|
|
}
|
|||
|
|
}else{
|
|||
|
|
this.clearAutoTimeticket();
|
|||
|
|
this.step_auto_advanced_btn_label.string = nx.text.getKey("QuickUpLev");
|
|||
|
|
}
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
getLvupStatus(){
|
|||
|
|
return this.is_in_advance;
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
clearAutoTimeticket:function(){
|
|||
|
|
if(this.auto_time_ticket){
|
|||
|
|
gcore.Timer.del(this.auto_time_ticket);
|
|||
|
|
this.auto_time_ticket = null;
|
|||
|
|
}
|
|||
|
|
},
|
|||
|
|
} );
|