1154 lines
43 KiB
TypeScript
Raw Normal View History

2025-04-24 17:03:28 +08:00
import Bag from "../bag/Bag";
import AudioUtil from "../core/AudioUtil";
import GameModel from "../core/GameModel";
import ItemUtil from "../core/ItemUtil";
import FactionTalent from "../FactionTalent";
import MsgAlert from "../game/msg/MsgAlert";
import FGAlert from "../gear_2.3.4/fgui/FGAlert";
import FGUtil from "../gear_2.3.4/fgui/FGUtil";
import SKDataUtil from "../gear_2.3.4/util/SKDataUtil";
import SKUIUtil from "../gear_2.3.4/util/SKUIUtil";
import TransformationUtil from "./TransformationUtil";
const { ccclass, property } = cc._decorator;
export default class Transformation extends cc.Component {
/**
*
*/
public static Instance: Transformation = null;
/**
*
*/
transformationPanel: fgui.GComponent = null;
/**
*
*/
decomposePanel: fgui.GComponent = null;
/**
*
*/
composePanel: fgui.GComponent = null;
/**
*
*/
libraryPanel: fgui.GComponent = null;
/**
*
*/
practicePanel: fgui.GComponent = null;
/**
*
*/
practiceData: any = null;
practiceSelectIdx: number = 1;
practiceEffCards: any = [];
/**
*
*/
showCardsList: any = [];
/**
*
*/
libraryCardsList: any = [];
/**
* idx
*/
selectCardIdx: number = -1;
/**
* idx
*/
selectLibraryCardIdx: number = -1;
/**
*
*/
stopTap: boolean = false;
/**
*
*/
prefabObject: any = {};
onLoad() {
if (Transformation.Instance === null) {
Transformation.Instance = this;
this.loadPrefab();
} else {
this.destroy();
return;
}
}
/**
*
*/
loadPrefab() {
// 加載所需的預製體
var prefabList = [
// { url: "Prefabs/UIRole", name: "UIRole" },
]
this.prefabObject = {}
for (let item of prefabList) {
cc.loader.loadRes(item.url, cc.Prefab, (err, prefab) => {
if (err)
console.warn(err);
else {
this.prefabObject[item.name] = prefab;
}
})
}
}
/**
*
*/
openTransformation() {
if (!this.transformationPanel || (this.transformationPanel && !this.transformationPanel.node && !SKUIUtil.isValid(this.transformationPanel.node))) {
this.transformationPanel = FGUtil.create("main_ui", "transformation_panel");
FGUtil.root().addChild(this.transformationPanel);
this.transformationPanel.makeFullScreen();
}
this.selectCardIdx = -1;
this.stopTap = false;
FGUtil.getControl(this.transformationPanel, "alert/page").selectedIndex = 1;
// 關閉按鈕
let closeBtn = FGUtil.getButton(this.transformationPanel, "mask")
let mask = FGUtil.getComponent(this.transformationPanel, "alert/close")
this.pushCloseEvent(closeBtn, this.transformationPanel, () => { Bag.Instance.closeBagPanel();FactionTalent.Instance.closeFCBagPanel(); AudioUtil.playCloseAudio() });
this.pushCloseEvent(mask, this.transformationPanel, () => { Bag.Instance.closeBagPanel();FactionTalent.Instance.closeFCBagPanel(); AudioUtil.playCloseAudio() });
// 顯示變身卡分類按鈕
let showTypeBtn = FGUtil.getButton(this.transformationPanel, "alert/sort_switch_btn");
showTypeBtn.onClick(this.showTypeView, this);
let typeViewList = FGUtil.getList(this.transformationPanel, "alert/sort/sort_list");
typeViewList.getChildAt(0).asCom.getController("selected").selectedIndex = 1;
// 圖鑑按鈕
let libraryBtn = FGUtil.getButton(this.transformationPanel, "alert/library_btn");
let libraryBtn2 = FGUtil.getButton(this.transformationPanel, "alert/noCard/n9");
libraryBtn.onClick(this.openLibraryPanel, this);
libraryBtn2.onClick(this.openLibraryPanel, this);
// 修煉按鈕
let practiceBtn = FGUtil.getButton(this.transformationPanel, "alert/practice_btn");
let practiceBtn2 = FGUtil.getButton(this.transformationPanel, "alert/noCard/n13");
practiceBtn.onClick(this.openPracticePanel, this);
practiceBtn2.onClick(this.openPracticePanel, this);
// 使用按鈕
let useBtn = FGUtil.getButton(this.transformationPanel, "alert/use_btn");
useBtn.onClick(this.useCard, this);
// 分解按鈕
let decomposeBtn = FGUtil.getButton(this.transformationPanel, "alert/info/decompose");
decomposeBtn.onClick(this.openDecomposePanel, this);
// 背包按鈕
var bagBtn = FGUtil.getButton(this.transformationPanel, "alert/n57");
bagBtn.onClick(this.openBagPanel, this);
// 天演符按鈕
FGUtil.getButton(this.transformationPanel, "alert/n58").onClick(this.openFactionTalentPanel, this);
let cardList = FGUtil.getList(this.transformationPanel, "alert/card_list");
// 設置變身卡初始化方法
cardList.itemRenderer = this.initCardItem.bind(this);
// 虛擬列表
cardList.setVirtual();
// 加載背包內變身卡數據
this.loadTransformationsData();
}
/**
*
*/
loadTransformationsData() {
var list = [];
let itemList = GameModel.player.itemList;
for (let itemId in itemList) {
let count = SKDataUtil.valueForKey(GameModel.player.itemList, itemId);
let data = ItemUtil.getItemData(itemId)
if (!data) continue
if (count != null && count > 0 && data.type == 15) {
let info = {
itemid: itemId,
count: count,
data: data
};
list.push(info);
}
}
this.showCardsList = SKDataUtil.clone(list);
FGUtil.getControl(this.transformationPanel, "alert/noCard").selectedIndex = this.showCardsList.length == 0 ? 1 : 0
this.sortTransformations();
}
/**
*
* @param list
*/
showTransformationsList() {
let cardList = FGUtil.getList(this.transformationPanel, "alert/card_list");
// 虛擬列表更新
cardList.numItems = this.showCardsList.length;
if (this.showCardsList.length > 0)
this.showCardInfo(null, 0)
}
sortTransformations(type: number = 0) {
// 先按id排序
this.showCardsList.sort((a, b) => {
return a.itemid - b.itemid;
})
if (type > 0) {
// 類型排序
this.showCardsList.sort((a, b) => {
if (a.data.attrType == b.data.attrType) return 0;
return a.data.attrType == type ? -1 : 0
})
}
if (this.selectCardIdx != -1) {
this.selectCardIdx = 0;
this.showCardInfo(null, 0);
}
this.showTransformationsList();
}
/**
*
*/
initCardItem(idx, obj: fairygui.GObject) {
var item = obj.asCom;
var card = FGUtil.getLoader(item, "card");
var type = FGUtil.getLoader(item, "type");
var change = FGUtil.getLoader(item, "change");
var info = this.showCardsList[idx].data;
var level = this.getTransformationLevel(parseInt(info.id));
var typeIcon = this.getTransformationTypeIcon(level, info.attrType, info.id);
card.url = `ui://main_ui/${info.icon}`;
type.url = `ui://main_ui/${typeIcon}`;
if (TransformationUtil.Instance.getCardsInfo(info.id).cardstate == 0 || level == 2) {
change.url = null;
} else
change.url = `ui://main_ui/${this.getTransformationChangeIcon(level)}`;
item.node["idx"] = idx;
FGUtil.getTextField(item, "num").text = SKDataUtil.transform(this.showCardsList[idx].count);
FGUtil.getControl(item, "selected").selectedIndex = idx == this.selectCardIdx ? 1 : 0;
item.asButton.onClick(this.showCardInfo, this);
}
showCardInfo(e: Event, id: number = 0) {
var idx;
if (e && e.target && e.target["idx"])
idx = e.target["idx"];
else
idx = id;
this.selectCardIdx = idx;
// 選中卡片並刷新
let cardList = FGUtil.getList(this.transformationPanel, "alert/card_list");
cardList.refreshVirtualList();
var cardInfo = this.showCardsList[idx];
if (cardInfo == null) return
var cardData = TransformationUtil.Instance.getCardsInfo(cardInfo.itemid);
var des = TransformationUtil.Instance.getCardDesById(cardInfo.itemid);
var addition = TransformationUtil.Instance.getCardAddition(cardInfo.itemid, this.practiceData);
let infoCom = FGUtil.getComponent(this.transformationPanel, "alert/info");
FGUtil.getComponent(infoCom, "decompose").visible = this.getTransformationLevel(cardInfo.itemid) > 0 ? true : false;
FGUtil.getControl(infoCom, "level").selectedIndex = this.getTransformationLevel(cardInfo.itemid);
FGUtil.getTextField(infoCom, "type").text = cardInfo.data.attrType == 1 ? "強" : cardInfo.data.attrType == 2 ? "抗" : "物";
FGUtil.getLoader(infoCom, "img").url = `ui://main_ui/p${cardInfo.data.icon}`;
FGUtil.getTextField(infoCom, "num").text = `擁有:[color=#1d7e43]${SKDataUtil.transform(cardInfo.count)}[/color]張`;
FGUtil.getTextField(infoCom, "name").text = `${cardInfo.data.name}`;
FGUtil.getTextField(infoCom, "needLevel").text = `等級需求:${cardData.relive}${cardData.level}`;
FGUtil.getTextField(infoCom, "5needLevel").text = `五行等級需求:${cardData.fplevel}`;
FGUtil.getTextField(infoCom, "eff").text = `五行修煉加成:[color=#00A03C]${addition}%[/color]`;
FGUtil.getTextField(infoCom, "arr_info/arr_info").text = des;
if (GameModel.player.relive < cardData.relive || (GameModel.player.relive == cardData.relive && GameModel.player.level < cardData.level)) {
FGUtil.getTextField(infoCom, "needLevel").color = new cc.Color(255, 0, 0);
FGUtil.getTextField(infoCom, "needLevel").strokeColor = new cc.Color(255, 255, 255);
} else {
FGUtil.getTextField(infoCom, "needLevel").color = new cc.Color(255, 255, 255);
FGUtil.getTextField(infoCom, "needLevel").strokeColor = new cc.Color(0, 0, 0);
}
if (GameModel.player.fplevel < cardData.fplevel) {
FGUtil.getTextField(infoCom, "5needLevel").color = new cc.Color(255, 0, 0);
FGUtil.getTextField(infoCom, "5needLevel").strokeColor = new cc.Color(255, 255, 255);
} else {
FGUtil.getTextField(infoCom, "5needLevel").color = new cc.Color(255, 255, 255);
FGUtil.getTextField(infoCom, "5needLevel").strokeColor = new cc.Color(0, 0, 0);
}
infoCom.visible = true;
}
/**
*
*/
showTypeView() {
if (this.transformationPanel && this.transformationPanel.node) {
var view = FGUtil.getComponent(this.transformationPanel, "alert/sort");
var mask = FGUtil.getComponent(view, "mask");
mask.onClick(this.hideTypeView, this);
var list = FGUtil.getList(view, "sort_list");
for (let i = 0; i < list.numChildren; i++) {
list.getChildAt(i).data = i;
}
list.on(fgui.Event.CLICK_ITEM, this.onClickTypeItem, this);
FGUtil.getControl(this.transformationPanel, "alert/showSortView").selectedIndex = 1;
}
}
/**
*
*/
hideTypeView() {
if (this.transformationPanel && this.transformationPanel.node) {
FGUtil.getControl(this.transformationPanel, "alert/showSortView").selectedIndex = 0;
}
}
/**
*
*/
onClickTypeItem(item: fgui.GObject) {
var list = FGUtil.getList(this.transformationPanel, "alert/sort/sort_list");
for (let i = 0; i < 4; i++) {
list.getChildAt(i).asCom.getController("selected").selectedIndex = i == item.data ? 1 : 0;
}
this.sortTransformations(item.data);
this.hideTypeView();
}
/**
* 使
*/
useCard() {
if (this.selectCardIdx >= 0 && this.showCardsList.length > 0 && this.showCardsList[this.selectCardIdx].itemid) {
if (GameModel.player.tResid > 0) {
FGAlert.show("您已使用過變身卡,是否再次使用?", () => {
FGAlert.hide();
}, () => {
FGAlert.hide();
GameModel.send("c2s_use_bagitem", {
roleid: GameModel.player.roleid,
itemid: this.showCardsList[this.selectCardIdx].itemid,
count: 1,
operateid: 4
})
})
return;
}
GameModel.send("c2s_use_bagitem", {
roleid: GameModel.player.roleid,
itemid: this.showCardsList[this.selectCardIdx].itemid,
count: 1,
operateid: 4
})
}
else {
MsgAlert.addMsg("請先選擇變身卡");
}
}
/**
*
*/
openDecomposePanel() {
if (!this.decomposePanel || (this.decomposePanel && !this.decomposePanel.node && !SKUIUtil.isValid(this.decomposePanel.node))) {
this.decomposePanel = FGUtil.create("main_ui", "transformation_decompose_panel");
FGUtil.root().addChild(this.decomposePanel);
this.decomposePanel.makeFullScreen();
}
// 關閉按鈕
let closeBtn = FGUtil.getButton(this.decomposePanel, "mask")
let mask = FGUtil.getComponent(this.decomposePanel, "alert/close")
this.pushCloseEvent(closeBtn, this.decomposePanel);
this.pushCloseEvent(mask, this.decomposePanel);
var info = this.showCardsList[this.selectCardIdx];
var decomposeBtn = FGUtil.getButton(this.decomposePanel, "alert/do");
var addBtn = FGUtil.getButton(this.decomposePanel, "alert/add");
var reduceBtn = FGUtil.getButton(this.decomposePanel, "alert/reduce");
var slider = FGUtil.getComponent(this.decomposePanel, "alert/slider").asSlider;
var item = FGUtil.getComponent(this.decomposePanel, "alert/item");
// 設置滑動條的最大值和默認值
slider.max = info.count;
slider.value = 1;
slider.on(fgui.Event.STATUS_CHANGED, this.onSliderChanged, this);
FGUtil.getTextField(this.decomposePanel, "alert/num").text = `數量:1張`;
// 分解的卡片圖片
FGUtil.getLoader(item, "card").url = `ui://main_ui/${info.data.icon}`;
// 獲取分解的卡片的類型Icon
var level = this.getTransformationLevel(parseInt(info.data.id));
var typeIcon = this.getTransformationTypeIcon(level, info.data.attrType, info.data.id);
FGUtil.getLoader(item, "type").url = `ui://main_ui/${typeIcon}`;
reduceBtn.clearClick();
reduceBtn.onClick(this.reduceSliderValue, this);
addBtn.clearClick();
addBtn.onClick(this.addSliderValue, this);
decomposeBtn.clearClick();
decomposeBtn.onClick(this.decomposeCard, this);
}
/**
*
*/
onSliderChanged(e) {
var value = e._value;
FGUtil.getTextField(this.decomposePanel, "alert/num").text = `數量:${value}`;
}
/**
*
*/
reduceSliderValue() {
if (this.decomposePanel && this.decomposePanel.node) {
var slider = FGUtil.getComponent(this.decomposePanel, "alert/slider").asSlider;
if (slider.value > 0) {
slider.value--;
FGUtil.getTextField(this.decomposePanel, "alert/num").text = `數量:${slider.value}`;
}
}
}
/**
*
*/
addSliderValue() {
if (this.decomposePanel && this.decomposePanel.node) {
var slider = FGUtil.getComponent(this.decomposePanel, "alert/slider").asSlider;
if (slider.value < slider.max) {
slider.value++;
FGUtil.getTextField(this.decomposePanel, "alert/num").text = `數量:${slider.value}`;
}
}
}
/**
*
*/
decomposeCard() {
if (this.stopTap) {
MsgAlert.addMsg("您點擊太快了");
return;
}
if (this.decomposePanel && this.decomposePanel.node) {
var slider = FGUtil.getComponent(this.decomposePanel, "alert/slider").asSlider;
var value = slider.value;
if (value == 0) {
MsgAlert.addMsg("請分解大於0數量的變身卡");
return;
}
this.stopTap = true;
GameModel.send("c2s_card_resolve", {
roleid: GameModel.player.roleid,
itemid: this.showCardsList[this.selectCardIdx].data.id,
count: value
})
FGUtil.dispose(this.decomposePanel);
this.decomposeAnimation(this.getTransformationLevel(this.showCardsList[this.selectCardIdx].data.id));
this.scheduleOnce(() => {
this.stopTap = false
// 分解後刷新變身卡數據並顯示
this.loadTransformationsData();
}, 0.3);
}
}
/**
*
*/
decomposeAnimation(level) {
var t = cc.tween;
var itemNode = new cc.Node("decomposeItem");
itemNode.addComponent(cc.Sprite).spriteFrame;
itemNode.getComponent(cc.Sprite).spriteFrame = ItemUtil.getItemIcon(this.getTransformationChipIcon(level));
itemNode.getComponent(cc.Sprite).sizeMode = cc.Sprite.SizeMode.CUSTOM
itemNode.width = 50;
itemNode.height = 50;
itemNode.setPosition(this.transformationPanel.node.width / 2 + 120, -this.transformationPanel.node.height + 80);
itemNode.opacity = 0;
itemNode.parent = this.transformationPanel.node;
t(itemNode)
.parallel(
t().by(0.4, { y: 80 }),
t().to(0.2, { opacity: 255 })
)
.delay(0.15)
.call(() => {
let bezerby = cc.bezierBy(0.5, [cc.v2(88, 10), cc.v2(130, 80), cc.v2(155, -350)]);
itemNode.runAction(cc.sequence(cc.spawn(bezerby, cc.rotateBy(0.3, 90)), cc.removeSelf()));
})
.start();
}
/**
*
*/
openComposePanel(count, type) {
if (!this.composePanel || (this.composePanel && !this.composePanel.node && !SKUIUtil.isValid(this.composePanel.node))) {
this.composePanel = FGUtil.create("main_ui", "transformation_compose_panel");
FGUtil.root().addChild(this.composePanel);
this.composePanel.makeFullScreen();
}
// 關閉按鈕
let closeBtn = FGUtil.getButton(this.composePanel, "mask")
let mask = FGUtil.getComponent(this.composePanel, "alert/close")
this.pushCloseEvent(closeBtn, this.composePanel);
this.pushCloseEvent(mask, this.composePanel);
var decomposeBtn = FGUtil.getButton(this.composePanel, "alert/do");
var addBtn = FGUtil.getButton(this.composePanel, "alert/add");
var reduceBtn = FGUtil.getButton(this.composePanel, "alert/reduce");
var slider = FGUtil.getComponent(this.composePanel, "alert/slider").asSlider;
// 設置滑動條的最大值和默認值
slider.max = Math.floor(count / 2);
slider.value = 1;
slider.on(fgui.Event.STATUS_CHANGED, this.onSliderChangedCompose, this);
FGUtil.getTextField(this.composePanel, "alert/num").text = `數量:1張`;
// 使用合成的卡片的道具圖片
FGUtil.getLoader(this.composePanel, "alert/n18").icon = `ui://main_ui/${type}`;
// 合成的卡片的圖片
FGUtil.getLoader(this.composePanel, "alert/n17").icon = `ui://main_ui/${parseInt(type) + 1}`;
// 獲取分解的卡片的類型Icon
reduceBtn.clearClick();
reduceBtn.onClick(this.reduceSliderValueCompose, this);
addBtn.clearClick();
addBtn.onClick(this.addSliderValueCompose, this);
decomposeBtn.clearClick();
decomposeBtn.node["itemid"] = type;
decomposeBtn.onClick(this.composeCard, this);
}
/**
*
*/
onSliderChangedCompose(e) {
var value = e._value;
FGUtil.getTextField(this.composePanel, "alert/num").text = `數量:${value}`;
}
/**
*
*/
reduceSliderValueCompose() {
if (this.composePanel && this.composePanel.node) {
var slider = FGUtil.getComponent(this.composePanel, "alert/slider").asSlider;
if (slider.value > 0) {
slider.value--;
FGUtil.getTextField(this.composePanel, "alert/num").text = `數量:${slider.value}`;
}
}
}
/**
*
*/
addSliderValueCompose() {
if (this.composePanel && this.composePanel.node) {
var slider = FGUtil.getComponent(this.composePanel, "alert/slider").asSlider;
if (slider.value < slider.max) {
slider.value++;
FGUtil.getTextField(this.composePanel, "alert/num").text = `數量:${slider.value}`;
}
}
}
/**
*
*/
composeCard(e: Event) {
if (this.stopTap) {
MsgAlert.addMsg("您點擊太快了");
return;
}
if (this.composePanel && this.composePanel.node) {
var slider = FGUtil.getComponent(this.composePanel, "alert/slider").asSlider;
var value = slider.value;
if (value == 0) {
MsgAlert.addMsg("請合成大於0數量的變身卡");
return;
}
this.stopTap = true;
var itemId;
if (e && e.target && e.target["itemid"]) {
itemId = e.target["itemid"];
GameModel.send("c2s_use_bagitem", {
roleid: GameModel.player.roleid,
itemid: itemId,
count: value,
operateid: 0
})
} else {
MsgAlert.addMsg("未找到變身卡碎片id");
return;
}
FGUtil.dispose(this.composePanel);
// this.composeAnimation(this.getTransformationLevel(this.showCardsList[this.selectCardIdx].data.id));
this.scheduleOnce(() => {
this.stopTap = false
}, 0.3);
}
}
/**
*
*/
composeAnimation(level) {
var t = cc.tween;
var itemNode = new cc.Node("decomposeItem");
itemNode.addComponent(cc.Sprite).spriteFrame;
itemNode.getComponent(cc.Sprite).spriteFrame = ItemUtil.getItemIcon(this.getTransformationChipIcon(level));
itemNode.getComponent(cc.Sprite).sizeMode = cc.Sprite.SizeMode.CUSTOM
itemNode.width = 50;
itemNode.height = 50;
itemNode.setPosition(this.transformationPanel.node.width / 2 + 120, -this.transformationPanel.node.height + 80);
itemNode.opacity = 0;
itemNode.parent = this.transformationPanel.node;
t(itemNode)
.parallel(
t().by(0.4, { y: 80 }),
t().to(0.2, { opacity: 255 })
)
.delay(0.15)
.call(() => {
let bezerby = cc.bezierBy(0.5, [cc.v2(88, 10), cc.v2(130, 80), cc.v2(155, -350)]);
itemNode.runAction(cc.sequence(cc.spawn(bezerby, cc.rotateBy(0.3, 90)), cc.removeSelf()));
})
.start();
}
/**
*
*/
openLibraryPanel() {
if (!this.libraryPanel || (this.libraryPanel && !this.libraryPanel.node && !SKUIUtil.isValid(this.libraryPanel.node))) {
this.libraryPanel = FGUtil.create("main_ui", "transformation_library_panel");
FGUtil.root().addChild(this.libraryPanel);
this.libraryPanel.makeFullScreen();
}
// 關閉按鈕
let closeBtn = FGUtil.getButton(this.libraryPanel, "mask")
let mask = FGUtil.getComponent(this.libraryPanel, "alert/close")
this.pushCloseEvent(closeBtn, this.libraryPanel);
this.pushCloseEvent(mask, this.libraryPanel);
// 強法按鈕
let qfBtn = FGUtil.getButton(this.libraryPanel, "alert/n30");
qfBtn.onClick(this.shwoQFCards, this);
// 抗性按鈕
let kxBtn = FGUtil.getButton(this.libraryPanel, "alert/n31");
kxBtn.onClick(this.shwoKXCards, this);
// 物理按鈕
let wlBtn = FGUtil.getButton(this.libraryPanel, "alert/n32");
wlBtn.onClick(this.shwoWLCards, this);
let cardList = FGUtil.getList(this.libraryPanel, "alert/card_list");
// 設置變身卡初始化方法
cardList.itemRenderer = this.initLibraryCardItem.bind(this);
// 虛擬列表
cardList.setVirtual();
// 默認展示強法卡片
this.shwoQFCards();
}
/**
*
*/
shwoQFCards() {
FGUtil.getControl(this.libraryPanel, "alert/n30/selected").selectedIndex = 1;
FGUtil.getControl(this.libraryPanel, "alert/n31/selected").selectedIndex = 0;
FGUtil.getControl(this.libraryPanel, "alert/n32/selected").selectedIndex = 0;
this.libraryCardsList = this.searchAllCardsByType(1);
let cardList = FGUtil.getList(this.libraryPanel, "alert/card_list");
cardList.numItems = this.libraryCardsList.length;
this.showLibraryCardInfo(null, 0);
cardList.scrollToView(0);
}
/**
*
*/
shwoKXCards() {
FGUtil.getControl(this.libraryPanel, "alert/n30/selected").selectedIndex = 0;
FGUtil.getControl(this.libraryPanel, "alert/n31/selected").selectedIndex = 1;
FGUtil.getControl(this.libraryPanel, "alert/n32/selected").selectedIndex = 0;
this.libraryCardsList = this.searchAllCardsByType(2);
let cardList = FGUtil.getList(this.libraryPanel, "alert/card_list");
cardList.numItems = this.libraryCardsList.length;
this.showLibraryCardInfo(null, 0);
cardList.scrollToView(0);
}
/**
*
*/
shwoWLCards() {
FGUtil.getControl(this.libraryPanel, "alert/n30/selected").selectedIndex = 0;
FGUtil.getControl(this.libraryPanel, "alert/n31/selected").selectedIndex = 0;
FGUtil.getControl(this.libraryPanel, "alert/n32/selected").selectedIndex = 1;
this.libraryCardsList = this.searchAllCardsByType(3);
let cardList = FGUtil.getList(this.libraryPanel, "alert/card_list");
cardList.numItems = this.libraryCardsList.length;
this.showLibraryCardInfo(null, 0);
cardList.scrollToView(0);
}
/**
*
*/
searchAllCardsByType(type: number = 0) {
var minId = 500001;
var maxId = 500199;
var list = [];
for (let key = minId; key < maxId; key++) {
if (key == 500051 || key == 500062 || key == 500063 || key == 500064) continue;
var info = SKDataUtil.valueForKey(GameModel.game_conf.item, key);
if (!info) continue;
if (info.attrType == type)
list.push(SKDataUtil.clone(info));
}
return list;
}
/**
*
*/
initLibraryCardItem(idx, obj: fairygui.GObject) {
var item = obj.asCom;
var card = FGUtil.getLoader(item, "card");
var type = FGUtil.getLoader(item, "type");
var change = FGUtil.getLoader(item, "change");
var info = this.libraryCardsList[idx];
var level = this.getTransformationLevel(parseInt(info.id));
var typeIcon = this.getTransformationTypeIcon(level, info.attrType, info.id);
card.url = `ui://main_ui/${info.icon}`;
type.url = `ui://main_ui/${typeIcon}`;
if (TransformationUtil.Instance.getCardsInfo(info.id).cardstate == 0 || level == 2) {
change.url = null;
} else
change.url = `ui://main_ui/${this.getTransformationChangeIcon(level)}`;
item.node["idx"] = idx;
FGUtil.getControl(item, "selected").selectedIndex = idx == this.selectLibraryCardIdx ? 1 : 0;
item.asButton.onClick(this.showLibraryCardInfo, this);
}
/**
*
*/
showLibraryCardInfo(e: Event, id: number = 0) {
var idx;
if (e && e.target && e.target["idx"])
idx = e.target["idx"];
else
idx = id;
this.selectLibraryCardIdx = idx;
// 選中卡片並刷新
let cardList = FGUtil.getList(this.libraryPanel, "alert/card_list");
cardList.refreshVirtualList();
var cardInfo = this.libraryCardsList[idx];
var cardData = TransformationUtil.Instance.getCardsInfo(cardInfo.id);
var des = TransformationUtil.Instance.getCardDesById(cardInfo.id);
var addition = TransformationUtil.Instance.getCardAddition(cardInfo.id, this.practiceData);
let infoCom = FGUtil.getComponent(this.libraryPanel, "alert/info");
FGUtil.getComponent(infoCom, "decompose").visible = false;
FGUtil.getControl(infoCom, "level").selectedIndex = this.getTransformationLevel(cardInfo.id);
FGUtil.getTextField(infoCom, "type").text = cardInfo.attrType == 1 ? "強" : cardInfo.attrType == 2 ? "抗" : "物";
FGUtil.getLoader(infoCom, "img").url = `ui://main_ui/p${cardInfo.icon}`;
let count = ItemUtil.getBagItemCount(cardInfo.id);
FGUtil.getTextField(infoCom, "num").text = `擁有:[color=#000000]${count ? count : 0}[/color]張`;
FGUtil.getTextField(infoCom, "name").text = `${cardInfo.name}`;
FGUtil.getTextField(infoCom, "needLevel").text = `等級需求:${cardData.relive}${cardData.level}`;
FGUtil.getTextField(infoCom, "5needLevel").text = `五行等級需求:${cardData.fplevel}`;
FGUtil.getTextField(infoCom, "eff").text = `五行修煉加成:[color=#00A03C]${addition}%[/color]`;
FGUtil.getTextField(infoCom, "arr_info/arr_info").text = des;
infoCom.visible = true;
}
/**
*
*/
openPracticePanel() {
if (GameModel.player.relive < 1 || (GameModel.player.relive == 1 && GameModel.player.level < 80)) {
MsgAlert.addMsg("五行修煉需要1轉80級");
return;
}
if (!this.practicePanel || (this.practicePanel && !this.practicePanel.node && !SKUIUtil.isValid(this.practicePanel.node))) {
this.practicePanel = FGUtil.create("main_ui", "wuxing_practice_panel");
FGUtil.root().addChild(this.practicePanel);
this.practicePanel.makeFullScreen();
}
// 關閉按鈕
let closeBtn = FGUtil.getButton(this.practicePanel, "mask")
let mask = FGUtil.getComponent(this.practicePanel, "alert/close")
this.pushCloseEvent(closeBtn, this.practicePanel);
this.pushCloseEvent(mask, this.practicePanel);
var effList = FGUtil.getList(this.practicePanel, "alert/left/list");
// 設置受影響變身卡初始化方法
effList.itemRenderer = this.initEffCardItem.bind(this);
// 虛擬列表
effList.setVirtual();
var leftPanel = FGUtil.getComponent(this.practicePanel, "alert/left");
var wuxingBox = FGUtil.getComponent(leftPanel, "wuxing");
var goldBtn = FGUtil.getComponent(wuxingBox, "gold");
var woodBtn = FGUtil.getComponent(wuxingBox, "wood");
var waterBtn = FGUtil.getComponent(wuxingBox, "water");
var fireBtn = FGUtil.getComponent(wuxingBox, "fire");
var soilBtn = FGUtil.getComponent(wuxingBox, "soil");
var colligateBtn = FGUtil.getComponent(wuxingBox, "colligate");
goldBtn.node["idx"] = 1;
woodBtn.node["idx"] = 2;
waterBtn.node["idx"] = 3;
fireBtn.node["idx"] = 4;
soilBtn.node["idx"] = 5;
colligateBtn.node["idx"] = 6;
goldBtn.onClick(this.wuxingBtnOnClick, this);
woodBtn.onClick(this.wuxingBtnOnClick, this);
waterBtn.onClick(this.wuxingBtnOnClick, this);
fireBtn.onClick(this.wuxingBtnOnClick, this);
soilBtn.onClick(this.wuxingBtnOnClick, this);
colligateBtn.onClick(this.wuxingBtnOnClick, this);
this.wuxingBtnOnClick(null, this.practiceSelectIdx);
}
initPracticeLeftInfo(data: any = null) {
try {
if (data != null)
this.practiceData = data;
var leftPanel = FGUtil.getComponent(this.practicePanel, "alert/left");
var wuxingBox = FGUtil.getComponent(leftPanel, "wuxing");
FGUtil.getTextField(wuxingBox, "goldLevel").text = `${data.jinlevel}`;
FGUtil.getTextField(wuxingBox, "woodLevel").text = `${data.mulevel}`;
FGUtil.getTextField(wuxingBox, "waterLevel").text = `${data.shuilevel}`;
FGUtil.getTextField(wuxingBox, "fireLevel").text = `${data.huolevel}`;
FGUtil.getTextField(wuxingBox, "soilLevel").text = `${data.tulevel}`;
FGUtil.getTextField(wuxingBox, "collLevel").text = `${data.fplevel}`;
var idx = this.practiceSelectIdx;
this.practiceEffCards = TransformationUtil.Instance.getEffCardsByAttr(idx);
FGUtil.getControl(this.practicePanel, "alert/left/wuxing/selectId").selectedIndex = idx;
var effList = FGUtil.getList(this.practicePanel, "alert/left/list");
effList.numItems = this.practiceEffCards.length;
this.initPracticeRigthInfo(idx);
} catch (err) {
console.log(err)
}
}
initEffCardItem(idx, obj: fairygui.GObject) {
var item = obj.asCom;
var card = FGUtil.getLoader(item, "card");
var type = FGUtil.getLoader(item, "type");
var info = this.practiceEffCards[idx];
var level = this.getTransformationLevel(parseInt(info.cardid));
var typeIcon = this.getTransformationChangeIcon(level);
card.url = `ui://main_ui/${info.cardid}`;
type.url = `ui://main_ui/${typeIcon}`;
}
/**
*
*/
wuxingBtnOnClick(e: Event, id: number = 1) {
var idx;
if (e && e.target && e.target["idx"])
idx = e.target["idx"];
else
idx = id;
this.practiceSelectIdx = idx;
GameModel.send("c2s_five_phases", {
roleid: GameModel.player.roleid,
type: idx
})
}
/**
*
* @param typeId
*/
getPracticeInfoByType(typeId): any {
if (typeId == 6) {
return;
}
var wordArr = ["金", "木", "水", "火", "土"];
var keyArr = ["jin", "mu", "shui", "huo", "tu"];
var colorArr = [{ r: 255, g: 155, b: 0 }, { r: 50, g: 200, b: 50 }, { r: 0, g: 20, b: 200 }, { r: 200, g: 0, b: 0 }, { r: 80, g: 50, b: 10 }];
var desArr = ['點石成金', '木秀於林', '普天率土', '火龍黼黻', '普天率土'];
var item1Arr = [1003010, 1003030, 1003050, 1003070, 1003090];
var item2Arr = [1003020, 1003040, 1003060, 1003080, 1003100];
var info = {
word: wordArr[typeId - 1],
color: colorArr[typeId - 1],
level: this.practiceData[`${keyArr[typeId - 1]}level`],
exp: this.practiceData[`${keyArr[typeId - 1]}exp`],
maxExp: this.practiceData.upexp,
des: `${desArr[typeId - 1]}:加強五行之中${wordArr[typeId - 1]}的能力,變身卡/屬性卡含${wordArr[typeId - 1]}屬性時會獲得額外的屬性加成。 `,
item1Id: item1Arr[typeId - 1],
item1Icon: `${item1Arr[typeId - 1]}`,
item1Count: ItemUtil.getBagItemCount(item1Arr[typeId - 1]),
item2Id: item2Arr[typeId - 1],
item2Icon: `${item2Arr[typeId - 1]}`,
item2Count: ItemUtil.getBagItemCount(item2Arr[typeId - 1]),
parcticeTimes: this.practiceData.count
};
return info;
}
/**
*
* @param typeId
*/
initPracticeRigthInfo(typeId) {
var info = this.getPracticeInfoByType(typeId);
if (typeId < 6) {
FGUtil.getControl(this.practicePanel, "alert/is5").selectedIndex = 0;
FGUtil.getControl(this.practicePanel, "alert/right/isMax").selectedIndex = info.level == 100 ? 1 : 0;
var rightPanel = FGUtil.getComponent(this.practicePanel, "alert/right");
FGUtil.getTextField(rightPanel, "type_title").text = info.word;
FGUtil.getTextField(rightPanel, "type_title").strokeColor = new cc.Color(info.color.r, info.color.g, info.color.b);
FGUtil.getTextField(rightPanel, "level_title").text = `${info.level}`;
FGUtil.getTextField(rightPanel, "n2/title").fontSize = 20;
FGUtil.getTextField(rightPanel, "n2/title").text = `${info.exp}/${info.maxExp}`;
FGUtil.getProgressBar(rightPanel, "n2").max = info.maxExp;
FGUtil.getProgressBar(rightPanel, "n2").value = info.exp;
FGUtil.getTextField(rightPanel, "n5").text = info.des;
FGUtil.getLoader(rightPanel, "item1/icon").url = `ui://main_ui/${info.item1Icon}`;
FGUtil.getTextField(rightPanel, "item1/title").text = `[b][color=#${info.item1Count > 0 ? '1BB457' : 'BE280B'}]${info.item1Count}[/color]/1[/b]`;
FGUtil.getLoader(rightPanel, "item2/icon").url = `ui://main_ui/${info.item2Icon}`;
FGUtil.getTextField(rightPanel, "item2/title").text = `[b][color=#${info.item2Count > 0 ? '1BB457' : 'BE280B'}]${info.item2Count}[/color]/1[/b]`;
FGUtil.getTextField(rightPanel, "times").text = `本周可修煉:${info.parcticeTimes}`;
var practiceBtn1 = FGUtil.getButton(rightPanel, "xl1");
var practiceBtn2 = FGUtil.getButton(rightPanel, "xl2");
practiceBtn1.node["itemId"] = info.item1Id;
practiceBtn2.node["itemId"] = info.item2Id;
practiceBtn1.onClick(this.useItemToPractice, this);
practiceBtn2.onClick(this.useItemToPractice, this);
} else {
FGUtil.getControl(this.practicePanel, "alert/wuxing/isMax").selectedIndex = this.practiceData.fplevel == 100 ? 1 : 0;
FGUtil.getTextField(this.practicePanel, "alert/wuxing/n9").text = `${this.practiceData.fplevel}級/100級`;
FGUtil.getButton(this.practicePanel, "alert/wuxing/n10").onClick(this.upFPLevel, this);
FGUtil.getControl(this.practicePanel, "alert/is5").selectedIndex = 1;
}
}
refreshItemCount() {
var item1id = FGUtil.getButton(this.practicePanel, "alert/right/xl1").node["itemId"]
var item2id = FGUtil.getButton(this.practicePanel, "alert/right/xl2").node["itemId"]
var count1 = ItemUtil.getBagItemCount(item1id)
var count2 = ItemUtil.getBagItemCount(item2id)
FGUtil.getTextField(this.practicePanel, "alert/right/item1/title").text = `[b][color=#${count1 > 0 ? '1BB457' : 'BE280B'}]${count1}[/color]/1[/b]`;
FGUtil.getTextField(this.practicePanel, "alert/right/item2/title").text = `[b][color=#${count2 > 0 ? '1BB457' : 'BE280B'}]${count2}[/color]/1[/b]`;
}
useItemToPractice(e: Event) {
if (this.practiceData.count <= 0) {
MsgAlert.addMsg("本周修煉次數已用完");
return;
}
var itemId;
if (e && e.target && e.target["itemId"])
itemId = e.target["itemId"];
if (!itemId)
return;
var count = ItemUtil.getBagItemCount(itemId);
if (count <= 0) {
MsgAlert.addMsg("您未擁有此道具");
return;
}
GameModel.send("c2s_use_bagitem", {
roleid: GameModel.player.roleid,
itemid: itemId,
count: 1,
operateid: 0
})
}
upFPLevel() {
GameModel.send("c2s_fplevel", {
roleid: GameModel.player.roleid
})
}
/**
*
* @param cardId id
* @returns
*/
getTransformationLevel(cardId: number = 0) {
if (cardId < 500001 || cardId > 500199) {
console.error("卡片id錯誤");
return;
}
var info = ItemUtil.getItemData(cardId);
if (!info) {
console.error("未找到卡片信息");
return;
}
var level = info.level;
if (level == 1003) {
// 橘色
return 3;
} else if (level == 1002) {
// 紫色
return 2;
} else if (level == 1001) {
// 藍色
return 1;
} else if (level == 1000) {
// 綠色
return 0;
}
return -1;
}
/**
*
* @param level
* @returns
*/
getTransformationChangeIcon(level: number = -1) {
if (level < 0 || level > 3) {
console.error("獲取卡片變字圖標時傳入數據錯誤");
return;
}
//強 抗 物 綠 藍 紫 橙
var typeArr = [
"CE379C20",
"4FF0E3B9",
"",
"743CB1F3"
];
return typeArr[level];
}
/**
*
* @param level
* @param type
* @returns
*/
getTransformationTypeIcon(level: number = -1, type: number = 0, errid: any = "") {
if (level < 0 || level > 3 || type < 1 || type > 3) {
console.error("獲取卡片顏色時傳入數據錯誤,錯誤卡片id", errid);
return;
}
//強 抗 物 綠 藍 紫 橙
var typeArr = [
["ECAE61A5", "6A45551C", "71EA9A95"],
["905A9C64", "56878EC7", "CD606498"],
["A1519957", "7844A6C6", "A71F8CC7"],
["9CC2C05E", "44D85091", "4988966A"]
];
return typeArr[level][type - 1];
}
/**
*
* @param level
* @returns
*/
getTransformationChipIcon(level: number = -1) {
if (level < 0 || level > 3) {
console.error("獲取卡片碎片傳入數據錯誤");
return;
}
//綠 藍 紫 橙
var typeArr = [
"100317", "100311", "100313", "100315"
];
return typeArr[level];
}
/**
*
*/
pushCloseEvent(item: fairygui.GComponent, target: fairygui.GComponent, call: Function = null) {
item.clearClick();
item.onClick(() => {
call && call();
FGUtil.dispose(target);
target = null;
}, this)
}
hideTransPanel() {
if (!SKUIUtil.isFGUIValid(this.transformationPanel)) return;
this.transformationPanel.visible = false;
}
closeTransPanel() {
if (!SKUIUtil.isFGUIValid(this.transformationPanel)) return;
FGUtil.dispose(this.transformationPanel);
this.transformationPanel = null;
}
/**
* /
*/
openTransPanelByBag() {
if (SKUIUtil.isFGUIValid(this.transformationPanel)) {
this.transformationPanel.visible = true;
FGUtil.getControl(this.transformationPanel, "alert/page").selectedIndex = 1;
return;
}
this.openTransformation();
}
/**
*
*/
openBagPanel() {
AudioUtil.playFenyeAudio();
Bag.Instance.openBagPanelByTrans();
this.hideTransPanel();
}
/**
*
*/
openFactionTalentPanel() {
AudioUtil.playFenyeAudio();
FactionTalent.Instance.openFcBagByOther();
this.hideTransPanel();
}
}