187 lines
6.5 KiB
TypeScript
Raw Permalink Normal View History

2025-04-24 17:03:28 +08:00
import SKUIUtil from "./gear_2.3.4/util/SKUIUtil";
import FGUtil from "./gear_2.3.4/fgui/FGUtil";
import GameUtil from "./core/GameUtil";
import SKDataUtil from "./gear_2.3.4/util/SKDataUtil";
import GameModel from "./core/GameModel";
import MsgAlert from "./game/msg/MsgAlert";
import FGAlert from "./gear_2.3.4/fgui/FGAlert";
const { ccclass, property } = cc._decorator;
export default class PetRefine extends cc.Component {
/**
*
*/
public static Instance: PetRefine = null;
/**
*
*/
refinePanel: fgui.GComponent = null;
refineList: any = [];
selectId: number = 0;
petLogic: any = null;
tipWarn: boolean = false;
curLevel: number = 0;
tipHighWarn: boolean = false;
inCD: boolean = false;
onLoad() {
if (PetRefine.Instance === null) {
PetRefine.Instance = this;
} else {
this.destroy();
return;
}
}
openEquipRefinePanel(listData: any, curLevel) {
this.curLevel = curLevel
if (!SKUIUtil.isFGUIValid(this.refinePanel)) {
this.refinePanel = FGUtil.create("main_ui", "priview_pet_more_panel");
FGUtil.root().addChild(this.refinePanel);
this.refinePanel.makeFullScreen();
}
this.refineList = listData;
FGUtil.getButton(this.refinePanel, "alert/back").onClick(this.backClick, this);
FGUtil.getButton(this.refinePanel, "alert/coast").onClick(this.changeRefine, this);
FGUtil.getButton(this.refinePanel, "alert/change").onClick(this.changeProp, this);
var hasNum = GameModel.player.itemList[10118] == null ? 0 : GameModel.player.itemList[10118]
FGUtil.getRichTextField(this.refinePanel, "alert/num").text = `[color=#${hasNum > 30 ? "00A03C" : "FB8C84"}]${hasNum}[/color]/30`
for (let i = 0; i < 6; i++) {
var item = FGUtil.getComponent(this.refinePanel, `alert/n${i}`);
var data = listData[i];
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,
max_hp: 0,
max_mp: 0,
max_atk: 0,
max_spd: 0,
};
if (info.cur_aptitude > this.curLevel)
this.tipHighWarn = true
for (let key in GameModel.conf_pet) {
if (GameModel.conf_pet.hasOwnProperty(key)) {
let item = GameModel.conf_pet[key];
if (key == this.petLogic.dataid) {
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];
}
}
}
var tips = ["[color=#009F3C]資質平平[/color]", "[color=#5666F4]出類拔萃[/color]", "[color=#D887F5]妙領天機[/color]", "[color=#B2521B]萬中無一[/color]"];
if (!this.tipWarn)
this.tipWarn = info.cur_aptitude == 3;
FGUtil.getRichTextField(item, "n13").text = tips[info.cur_aptitude] || tips[0];
FGUtil.getTextField(item, "chengzhang").text = `${info.rate.toFixed(3)}/${info.max_rate.toFixed(3)}`;
var qixuePb = FGUtil.getProgressBar(item, "qixue");
qixuePb.max = info.max_hp
qixuePb.value = info.cur_hp
var faliPb = FGUtil.getProgressBar(item, "fali");
faliPb.max = info.max_mp
faliPb.value = info.cur_mp
var gongjiPb = FGUtil.getProgressBar(item, "gongji");
gongjiPb.max = info.max_atk
gongjiPb.value = info.cur_atk
var suduPb = FGUtil.getProgressBar(item, "sudu");
suduPb.max = info.max_spd
suduPb.value = info.cur_spd
var level = 0
for (let i = 1; i <= 5; i++) {
if (info.rate / info.max_rate * 0.99 >= i / 5)
level++
}
FGUtil.getControl(item, "level").selectedIndex = level
item.node["idx"] = i
item.onClick(this.ClickRefineItem, this)
}
}
ClickRefineItem(e: Event) {
var id = 0;
if (e && e.target && SKDataUtil.hasProperty(e.target, "idx"))
id = e.target["idx"];
if (id == this.selectId) return;
FGUtil.getControl(this.refinePanel, `alert/n${this.selectId}/selected`).selectedIndex = 0
FGUtil.getControl(this.refinePanel, `alert/n${id}/selected`).selectedIndex = 1
this.selectId = id
}
backClick() {
FGUtil.dispose(this.refinePanel);
this.refinePanel = null;
}
changeProp() {
this.tipWarn = false
this.tipHighWarn = false
GameModel.send("c2s_save_petproperty", {
petid: this.petLogic.petid,
info: JSON.stringify(this.refineList[this.selectId])
})
this.backClick()
}
changeRefine() {
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.changeRefine()
})
return
}
// if (this.tipHighWarn) {
// FGAlert.show("預覽中有更高評級,確定要重新洗練麼?", () => {
// FGAlert.hide()
// }, () => {
// FGAlert.hide()
// this.tipWarn = false
// this.tipHighWarn = false
// this.changeRefine()
// })
// return
// }
this.tipWarn = false
this.tipHighWarn = false
if (GameModel.player.itemList[10118] && GameModel.player.itemList[10118] >= 30)
GameModel.player.itemList[10118] -= 30;
else {
MsgAlert.addMsg("金柳露不足")
return;
}
GameModel.send('c2s_wash_petproperty', {
petid: this.petLogic.petid,
dataid: this.petLogic.dataid,
washtaype: 2
});
}
}