176 lines
3.7 KiB
JavaScript
176 lines
3.7 KiB
JavaScript
import GameModel from "../ts/core/GameModel";
|
||
import MsgAlert from "../ts/game/msg/MsgAlert";
|
||
|
||
cc.Class({
|
||
extends: cc.Component,
|
||
|
||
properties: {
|
||
pet_sprite: cc.Sprite,
|
||
pet_label: cc.Label,
|
||
fly_label: cc.Label,
|
||
fly_button: cc.Node,
|
||
property_node: cc.Node,
|
||
},
|
||
|
||
start () {
|
||
this.petid_list = [];
|
||
for (let item of GameModel.player.petInfo.list) {
|
||
if (item.grade >= 3) {
|
||
this.petid_list.push(item.petid);
|
||
}
|
||
}
|
||
if (this.petid_list.length == 0) {
|
||
MsgAlert.addMsg('你沒有符合條件的神獸!');
|
||
this.onClose();
|
||
return;
|
||
}
|
||
if (this.petid_list.length == 1) {
|
||
cc.find('PetBg/Right', this.node).active = false;
|
||
cc.find('PetBg/Left', this.node).active = false;
|
||
}
|
||
this.cur_index = this.petid_list.indexOf(GameModel.player.petInfo.curid);
|
||
if (this.cur_index == -1) {
|
||
this.cur_index = 0;
|
||
}
|
||
this.refrush();
|
||
},
|
||
|
||
/*
|
||
* 切換前一個寵物
|
||
*/
|
||
onLeftClick () {
|
||
if(!this.pet_list){
|
||
return;
|
||
}
|
||
-- this.cur_index;
|
||
if (this.cur_index < 0) {
|
||
this.cur_index = this.petid_list.length-1;
|
||
}
|
||
this.refrush();
|
||
},
|
||
|
||
/*
|
||
* 切換後一個寵物
|
||
*/
|
||
onRightClick () {
|
||
++ this.cur_index;
|
||
if (this.cur_index == this.petid_list.length) {
|
||
this.cur_index = 0;
|
||
}
|
||
this.refrush();
|
||
},
|
||
|
||
getPetByPetid (petid) {
|
||
for (let item of GameModel.player.petInfo.list) {
|
||
if (item.petid == petid) {
|
||
return item;
|
||
}
|
||
}
|
||
return null;
|
||
},
|
||
|
||
/*
|
||
* 刷新界面
|
||
*/
|
||
refrush () {
|
||
this.petid = this.petid_list[this.cur_index];
|
||
for (let item of GameModel.player.petInfo.list) {
|
||
if (item.petid == this.petid) {
|
||
this.pet = item;
|
||
}
|
||
}
|
||
if (this.pet.fly%10 == 0) {
|
||
this.fly_label.string = '第一次飛升';
|
||
}
|
||
else if (this.pet.fly%10 == 1) {
|
||
this.fly_label.string = '第二次飛升';
|
||
}
|
||
else if (this.pet.fly%10 == 2) {
|
||
this.fly_label.string = '第三次飛升';
|
||
}
|
||
else if (this.pet.fly%10 == 3) {
|
||
this.fly_label.string = '更換飛升屬性';
|
||
}
|
||
this.fly_button.active = true;
|
||
this.property_node.active = false;
|
||
this.pet_label.string = this.pet.name;
|
||
cc.loader.loadRes(`ui/photo/${this.pet.resid}`, cc.SpriteFrame, (err, spriteFrame) => {
|
||
if (err) {
|
||
cc.log(err);
|
||
}
|
||
else {
|
||
this.pet_sprite.spriteFrame = spriteFrame;
|
||
}
|
||
});
|
||
},
|
||
|
||
/*
|
||
* 點擊飛升按鈕
|
||
*/
|
||
onFlyClick () {
|
||
if(this.pet.fly==null){
|
||
return;
|
||
}
|
||
if (this.pet.fly%10 == 0) {
|
||
if (this.pet.level < 50) {
|
||
MsgAlert.addMsg('寵物需要0轉50級!');
|
||
return;
|
||
}
|
||
GameModel.send('c2s_petfly_msg', {
|
||
petid: this.petid,
|
||
type: 0,
|
||
});
|
||
}
|
||
else if (this.pet.fly%10 == 1) {
|
||
if (this.pet.level < 100 || this.pet.relive < 1) {
|
||
MsgAlert.addMsg('寵物需要1轉100級!');
|
||
return;
|
||
}
|
||
GameModel.send('c2s_petfly_msg', {
|
||
petid: this.petid,
|
||
type: 0,
|
||
});
|
||
}
|
||
else if (this.pet.fly%10 == 2) {
|
||
if (this.pet.level < 120 || this.pet.relive < 2) {
|
||
MsgAlert.addMsg('寵物需要2轉120級!');
|
||
return;
|
||
}
|
||
this.property_node.active = true;
|
||
this.fly_button.active = false;
|
||
}
|
||
else if (this.pet.fly%10 == 3) {
|
||
if (this.pet.level < 200 || this.pet.relive < 3) {
|
||
MsgAlert.addMsg('寵物需要3轉200級!');
|
||
return;
|
||
}
|
||
this.property_node.active = true;
|
||
this.fly_button.active = false;
|
||
}
|
||
},
|
||
|
||
/*
|
||
* 點擊選擇初始值
|
||
*/
|
||
onPropertyClick (event, param) {
|
||
if (GameModel.player.gameData.money < 5000000) {
|
||
MsgAlert.addMsg('需要消耗500萬銀兩,銀兩不足!');
|
||
return;
|
||
}
|
||
if (param == parseInt(this.pet.fly/10)) {
|
||
MsgAlert.addMsg('當前是已選擇此屬性,請選擇其它屬性!');
|
||
return;
|
||
}
|
||
GameModel.notice.addMsg(1, '需要消耗500萬銀兩,是否繼續? ', () => {
|
||
GameModel.send('c2s_petfly_msg', {
|
||
petid: this.petid,
|
||
type: parseInt(param),
|
||
});
|
||
}, () => {});
|
||
},
|
||
|
||
onClose () {
|
||
this.node.destroy();
|
||
},
|
||
});
|