import GameModel from "../ts/core/GameModel";
import MsgAlert from "../ts/game/msg/MsgAlert";
import FGAlert from "../ts/gear_2.3.4/fgui/FGAlert";
import PetRefine from "../ts/petRefine"
const jll_id = 10118; /* 金柳露id */
cc.Class({
extends: cc.Component,
properties: {
left_panel: cc.Node,
right_panel: cc.Node,
sprite_atlas: cc.SpriteAtlas,
bag_item: cc.Node,
jll_count_label: cc.Label,
washLevel: 1,
tipWarn: false,
curLevel: 0,
tipHighWarn: false,
inCD: false
},
/*
* 顯示界面
* @param pet_logic 寵物logic
*/
onLoad() {
this.aptits = ["資質平平", "出類拔萃", "妙領天機", "萬中無一"];
// this.petLogic = new logic.PetLogic();
},
show(pet_logic) {
this.node.active = true;
this.pet_logic = pet_logic;
PetRefine.Instance.petLogic = pet_logic;
let resid = this.pet_logic.resid;
let info = {
cur_aptitude: this.pet_logic.aptitude,
rate: this.pet_logic.rate,
/* cur_hp: this.pet_logic.cur_hp,
cur_mp: this.pet_logic.cur_mp,
cur_atk: this.pet_logic.cur_atk,
cur_spd: this.pet_logic.cur_spd, */
cur_hp: this.pet_logic.hp,
cur_mp: this.pet_logic.mp,
cur_atk: this.pet_logic.atk,
cur_spd: this.pet_logic.spd,
max_rate: this.pet_logic.maxRate
};
this.curLevel = info.cur_aptitude
this.showPropertyPanel(info, this.left_panel);
for (let node of this.right_panel.children)
node.active = false;
this.showBagItem();
},
showBagItem() {
let logic = this.bag_item.getComponent('BagItem');
logic.loadInfo({ itemid: jll_id });
logic.item_selected.opacity = 0;
let jll_count = GameModel.player.itemList[jll_id] || 0;
var need = this.washLevel == 1 ? "3" : "30"
this.jll_count_label.string = jll_count + '/' + need;
},
unshow() {
this.node.active = false;
for (let node of this.right_panel.children)
node.active = false;
if (this.close_callback)
this.close_callback();
},
/*
* 顯示屬性信息
* @param info 資訊
* @param panel 面板
*/
showPropertyPanel(info, panel) {
//if (!info.max_rate) {
for (let key in GameModel.conf_pet) {
if (GameModel.conf_pet.hasOwnProperty(key)) {
let item = GameModel.conf_pet[key];
if (key == this.pet_logic.dataid) {
//info.max_rate = JSON.parse(item.rate)[1];
info.max_hp = JSON.parse(item.hp)[1];
info.max_mp = JSON.parse(item.mp)[1];
info.max_atk = JSON.parse(item.atk)[1];
info.max_spd = JSON.parse(item.spd)[1];
}
}
}
//}
let zizhi_lable = panel.getChildByName('TextScore').getComponent(cc.RichText);
zizhi_lable.string = this.aptits[info.cur_aptitude] || this.aptits[0];
let hp_progress = panel.getChildByName('hpProgress');
let hp_label = hp_progress.getChildByName('label').getComponent(cc.Label);
hp_progress.getComponent(cc.ProgressBar).progress = (info.cur_hp == 0) ? 0 : (info.cur_hp / info.max_hp);
hp_label.string = info.cur_hp + '/' + info.max_hp;
let mp_progress = panel.getChildByName('mpProgress');
let mp_label = mp_progress.getChildByName('label').getComponent(cc.Label);
mp_progress.getComponent(cc.ProgressBar).progress = (info.cur_mp == 0) ? 0 : (info.cur_mp / info.max_mp);
mp_label.string = info.cur_mp + '/' + info.max_mp;
let att_progress = panel.getChildByName('attProgress');
let att_label = att_progress.getChildByName('label').getComponent(cc.Label);
att_progress.getComponent(cc.ProgressBar).progress = (info.cur_atk == 0) ? 0 : (info.cur_atk / info.max_atk);
att_label.string = info.cur_atk + '/' + info.max_atk;
let spe_progress = panel.getChildByName('speProgress');
let spe_label = spe_progress.getChildByName('label').getComponent(cc.Label);
spe_progress.getComponent(cc.ProgressBar).progress = (info.cur_spd == 0) ? 0 : (info.cur_spd / info.max_spd);
spe_label.string = info.cur_spd + '/' + info.max_spd;
let rate_label = panel.getChildByName('RateLabel').getComponent(cc.Label);
rate_label.string = info.rate.toFixed(3) + '/' + info.max_rate.toFixed(3);
for (let i = 1; i <= 5; ++i) {
let sprite = panel.getChildByName('grow' + i).getComponent(cc.Sprite);
let url = 'ui_common_loading_bar2';
if (i / 5 >= info.rate / info.max_rate * 0.99)
url = 'ui_common_loading_bar_bg';
sprite.spriteFrame = this.sprite_atlas.getSpriteFrame(url);
}
},
/*
* 洗練屬性
*/
washProperty(data) {
for (let node of this.right_panel.children)
node.active = true;
let info = {
cur_aptitude: data.aptitude,
rate: data.rate / 10000,
cur_hp: data.hp,
cur_mp: data.mp,
cur_atk: data.atk,
cur_spd: data.spd,
max_rate: data.maxrate / 10000
};
this.tipWarn = info.cur_aptitude == 3
if (!this.tipWarn) {
if (info.cur_aptitude > this.curLevel)
this.tipHighWarn = true
}
this.showPropertyPanel(info, this.right_panel);
this.can_save_property = true;
let jll_count = GameModel.player.itemList[jll_id] || 0;
this.jll_count_label.string = jll_count + '/' + 3;
},
/*
* 保存洗練屬性
*/
saveProperty(data) {
MsgAlert.addMsg('洗練的屬性保存成功!');
this.can_save_property = false;
this.pet_logic.aptitude = data.aptitude;
console.log(data.aptitude);
console.log(this.pet_logic.aptitude);
this.pet_logic.rate = data.rate / 10000;
this.pet_logic.hp = data.hp;
this.pet_logic.mp = data.mp;
this.pet_logic.atk = data.atk;
this.pet_logic.spd = data.spd;
let info = {
cur_aptitude: data.aptitude, //data.aptitude==undefined
rate: data.rate / 10000,
max_rate: data.maxrate / 10000,
cur_hp: data.hp,
cur_mp: data.mp,
cur_atk: data.atk,
cur_spd: data.spd,
};
this.curLevel = info.cur_aptitude
this.showPropertyPanel(info, this.left_panel);
this.tipWarn = false
this.tipHighWarn = false
},
onButtonClick(event, param) {
if (param == 'close') {
this.unshow();
}
else if (param == 'wash') {
if (this.inCD) {
MsgAlert.addMsg("您點擊太快啦")
return;
}
this.inCD = true
this.scheduleOnce(() => {
this.inCD = false
}, 0.8)
if (this.tipWarn) {
FGAlert.show("預覽中存在萬中無一的資質,確定要重新洗練麼?", () => {
FGAlert.hide()
}, () => {
FGAlert.hide()
this.tipWarn = false
this.tipHighWarn = false
this.onButtonClick(null, "wash")
})
return
}
// if (this.tipHighWarn) {
// FGAlert.show("預覽中有更高評級,確定要重新洗練麼?", () => {
// FGAlert.hide()
// }, () => {
// FGAlert.hide()
// this.tipWarn = false
// this.tipHighWarn = false
// this.onButtonClick(null, "wash")
// })
// return
// }
this.tipWarn = false
this.tipHighWarn = false
let jll_count = GameModel.player.itemList[jll_id] || 0;
if (jll_count < 3) {
MsgAlert.addMsg('金柳露數量不足!');
return;
}
GameModel.send('c2s_wash_petproperty', {
petid: this.pet_logic.petid,
dataid: this.pet_logic.dataid,
washtaype: this.washLevel
});
}
else if (param == 'save') {
if (!this.can_save_property) {
MsgAlert.addMsg('請先洗練屬性,再保存!');
return;
}
GameModel.send('c2s_save_petproperty', {
petid: this.pet_logic.petid,
});
}
},
});