import GameModel from "../ts/core/GameModel"; import ItemUtil from "../ts/core/ItemUtil"; import TransformationUtil from "../ts/transformation/TransformationUtil"; import HorsePanel from "../ts/horse/HorsePanel"; import MsgAlert from "../ts/game/msg/MsgAlert"; import SKUIUtil from "../ts/gear_2.3.4/util/SKUIUtil"; import SKDataUtil from "../ts/gear_2.3.4/util/SKDataUtil"; import Transformation from "../ts/transformation/Transformation"; import Bag from "../ts/bag/Bag"; import FactionTalent from "../ts/FactionTalent"; import BabyMgrPannel from "../ts/nurture/BabyMgrPannel"; import DestinyPannel from "../ts/nurture/DestinyPannel"; import StarHome from "../ts/star/StarHome"; let GoodsMgr = require('../game/GoodsMgr'); let PubFunction = require('../game/PubFunction'); cc.Class({ extends: cc.Component, properties: { bgNode: cc.Node, itemIcon: cc.Sprite, transformationType: cc.Sprite, transformationChange: cc.Sprite, typeLab: cc.Label, nameLab: cc.Label, infoLab: cc.Label, gongxiaoLab: cc.Label, delNode: cc.Node, operationNode: cc.Node, operationAllNode: cc.Node, composeNode: cc.Node, resolveNode: cc.Node, ComposUI: cc.Prefab, PetsPanel: cc.Prefab, WorkShopPanel: cc.Prefab, RestoryUI: cc.Prefab, XianQiUpPanel: cc.Prefab, ShenBingCombinePanel: cc.Prefab, PetHeChengPanel: cc.Prefab, PartnerUI: cc.Prefab, NoticeEditUI: cc.Prefab, SafeNotice: cc.Prefab, }, onLoad() { this.operationNode.active = false; this.operationAllNode.active = false; this.composeNode.active = false; this.resolveNode.active = false; this.delNode.active = false; this.node.on(cc.Node.EventType.TOUCH_START, this.touchBegan.bind(this)); this.typearr = ['物品', '五行天書', '材料', '藥品', '經驗', '銀兩', '仙玉', '神兵', '仙器', '召喚獸', '技能書', '綁定仙玉', '元氣丹', '寶箱', `鑰匙`, `變身卡`, "特效", "法寶","守護信物","孩子道具"]; }, loadInfo(info) { this.iteminfo = info; this.itemIcon.spriteFrame = ItemUtil.getItemIconBy(info); let type = this.typearr[info.type]; this.typeLab.string = type; this.nameLab.string = info.name; this.infoLab.string = info.description; this.gongxiaoLab.string = `【用途】${info.usedetail}`; cc.tween(this.node).delay(0.05).call(() => { this.gongxiaoLab.node.y = this.infoLab.node.y - this.infoLab.node.height - 10; }).start(); // 變身卡 需要添加類型圖標 if (info.type == 15) { if (info.level == 1003) { // 橘色 var typeArr = ["9CC2C05E", "44D85091", "4988966A"]//強 抗 物 this.transformationType.spriteFrame = ItemUtil.getItemIcon(typeArr[info.attrType - 1]); if (TransformationUtil.Instance.getCardsInfo(info.id).cardstate == 0) this.transformationChange.spriteFrame = null else this.transformationChange.spriteFrame = ItemUtil.getItemIcon("743CB1F3") } else if (info.level == 1002) { // 紫色 var typeArr = ["A1519957", "7844A6C6", "A71F8CC7"]//強 抗 物 this.transformationType.spriteFrame = ItemUtil.getItemIcon(typeArr[info.attrType - 1]); this.transformationChange.spriteFrame = null } else if (info.level == 1001) { // 藍色 var typeArr = ["905A9C64", "56878EC7", "CD606498"]//強 抗 物 this.transformationType.spriteFrame = ItemUtil.getItemIcon(typeArr[info.attrType - 1]); if (TransformationUtil.Instance.getCardsInfo(info.id).cardstate == 0) this.transformationChange.spriteFrame = null else this.transformationChange.spriteFrame = ItemUtil.getItemIcon("4FF0E3B9") } else if (info.level == 1000) { // 綠色 var typeArr = ["ECAE61A5", "6A45551C", "71EA9A95"]//強 抗 物 this.transformationType.spriteFrame = ItemUtil.getItemIcon(typeArr[info.attrType - 1]); if (TransformationUtil.Instance.getCardsInfo(info.id).cardstate == 0) this.transformationChange.spriteFrame = null else this.transformationChange.spriteFrame = ItemUtil.getItemIcon("CE379C20") } else { return } this.transformationType.node.active = true; this.transformationChange.node.active = true; } }, showOperation() { this.operationNode.active = true; this.delNode.active = true; if (this.iteminfo.undel) { this.delNode.active = false } if (this.iteminfo.type == 19 && ItemUtil.getBagItemCount(this.iteminfo.id) == 0) { this.operationNode.active = false } if (this.iteminfo.noopt){ this.operationNode.active = false } this.composeNode.active = ItemUtil.canSynthesis(this.iteminfo.id); let count = ItemUtil.canResolve(this.iteminfo); if (count > 0) { this.resolveNode.active = true; if (this.composeNode.active) { this.resolveNode.y = -160; } } else if (this.iteminfo.type == 10) { this.resolveNode.active = true; this.resolveNode.y = -80 } else { this.resolveNode.active = false; this.resolveNode.y = -80; } if (this.canUseAll(this.iteminfo.id)) { var offY = 0 if (this.composeNode.active) offY++; if (this.resolveNode.active) offY++; this.operationAllNode.y = -80 - 80 * offY; this.operationAllNode.active = true; } }, // 點擊合成 composBtnClicked() { let composUI = PubFunction.CreateSubNode(cc.find('Canvas/MainUI'), { nX: 0, nY: 0 }, this.ComposUI, 'ComposUI'); let itemId = SKDataUtil.toNumber(this.iteminfo.id); if (isNaN(itemId)) { itemId = 0; } let ui = composUI.getComponent('ComposUI'); ui.selectedItem = itemId; this.node.destroy(); Bag.Instance.closeBagPanel(); }, // 點擊分解 clickResolve() { ItemUtil.itemResolve(this.iteminfo); this.node.destroy(); }, useBtnClicked(e, d) { this.node.destroy(); let canuse = true; if (ItemUtil.isPetUse(this.iteminfo.id)) { // 親密丹,靈獸丹,聖獸丹,神獸丹,凝魂丹,龍之骨,金柳露 let petpanel = cc.instantiate(this.PetsPanel); petpanel.name = 'PetPanel'; petpanel.parent = cc.find('Canvas/MainUI'); canuse = false; } else if (this.iteminfo.id == 10401) {//悔夢石 let workshop = cc.instantiate(this.WorkShopPanel); workshop.parent = cc.find('Canvas'); workshop.getComponent('WorkShopPanel').setCurPanel(4); canuse = false; Bag.Instance.closeBagPanel(); } else if (this.iteminfo.id == 10201) //回夢丹 { Bag.Instance.closeBagPanel(); PubFunction.CreateSubNode(cc.find('Canvas/MainUI'), { nX: 0, nY: 0 }, this.RestoryUI, 'RestoryUI'); canuse = false; } else if (this.iteminfo.id >= 10402 && this.iteminfo.id <= 10404) { let workshop = cc.instantiate(this.WorkShopPanel); workshop.parent = cc.find('Canvas'); workshop.getComponent('WorkShopPanel').setCurPanel(2); canuse = false; Bag.Instance.closeBagPanel(); } else if (this.iteminfo.id == 10405) {//盤古精鐵 let workshop = cc.instantiate(this.WorkShopPanel); workshop.parent = cc.find('Canvas'); canuse = false; Bag.Instance.closeBagPanel(); } else if (this.iteminfo.id == 10406) {//八荒遺風 let xianqi = cc.instantiate(this.XianQiUpPanel); xianqi.parent = cc.find('Canvas'); canuse = false; Bag.Instance.closeBagPanel(); } else if (this.iteminfo.id == 10408) {//神兵碎片 let shenbing = cc.instantiate(this.ShenBingCombinePanel); shenbing.parent = cc.find('Canvas'); canuse = false; Bag.Instance.closeBagPanel(); } else if (this.iteminfo.id >= 20001 && this.iteminfo.id <= 20015) {//五行材料,合成召喚獸 let hecheng = cc.instantiate(this.PetHeChengPanel); hecheng.parent = cc.find('Canvas'); canuse = false; Bag.Instance.closeBagPanel(); } else if (this.iteminfo.id == 10202 || this.iteminfo.id == 10204) {//夥伴修煉冊 PubFunction.CreateSubNode(cc.find('Canvas/MainUI'), { nX: 0, nY: 0 }, this.PartnerUI, 'PartnerUI'); canuse = false; Bag.Instance.closeBagPanel(); } else if (this.iteminfo.id == 10205) { // 世界鈴鐺廣播 relive let myLevel = GameModel.player.relive; let itemLevel = this.iteminfo.relive; if (myLevel < itemLevel) { MsgAlert.addMsg(`${this.iteminfo.name}需要${this.iteminfo.level}转才能使用`); return; } let lgNode = cc.find("Canvas/PalaceNotice") if (SKUIUtil.isValid(lgNode)) { let lg = lgNode.getComponent("PalaceNotice"); if (lg) { if (lg.str_list && lg.str_list.length > 10) { MsgAlert.addMsg(`鈴鐺消息隊列已滿,請稍後使用`); return; } } } let notice_edit_node = cc.instantiate(this.NoticeEditUI); notice_edit_node.parent = cc.find('Canvas'); canuse = false; Bag.Instance.closeBagPanel(); } else if (this.iteminfo.id >= 10501 && this.iteminfo.id <= 10583) { //元氣丹 let petpanel = cc.instantiate(this.PetsPanel); petpanel.name = 'PetPanel'; petpanel.parent = cc.find('Canvas/MainUI'); canuse = false; Bag.Instance.closeBagPanel(); } // 使用坐騎修煉丹,則打開坐騎面板,關閉背包 else if (SKDataUtil.atRange(this.iteminfo.id, [10605, 10606, 10607, 10608])) { HorsePanel.shared.show(); canuse = false; Bag.Instance.closeBagPanel(); } // 使用變身卡 else if (this.isComposeTransformation(this.iteminfo.id)) { Transformation.Instance.openComposePanel(ItemUtil.getBagItemCount(this.iteminfo.id), this.iteminfo.id) return; } // 合成天演符 else if (this.iteminfo.id == 100320) { FactionTalent.Instance.openComposeFcFuPanel(ItemUtil.getBagItemCount(this.iteminfo.id)) return; } else if (this.iteminfo.id == 100321) { GameModel.send("c2s_authenticate_ofuda", { roleid: GameModel.player.roleid, ofudatype: 1 }) return; } else if (this.iteminfo.id == 100322) { GameModel.send("c2s_authenticate_ofuda", { roleid: GameModel.player.roleid, ofudatype: 2 }) return; } else if (this.iteminfo.id == 100323) { GameModel.send("c2s_authenticate_ofuda", { roleid: GameModel.player.roleid, ofudatype: 3 }) return; }else if (this.iteminfo.id == 9650) { BabyMgrPannel.shared.onClickDestiny() DestinyPannel.shared.onUpgrade() return }else if (this.iteminfo.id == 9651) { BabyMgrPannel.shared.onClickDestiny() return }else if (this.iteminfo.id == 9654){//煉星石 StarHome.shared.show() }else if (this.iteminfo.id == 9655){//渾天石 StarHome.shared.show() StarHome.shared.onClickStarInfo() } if (!canuse) { Bag.Instance.closeBagPanel(); let bagLayer = cc.find('Canvas/MainUI/BagPanel'); if (bagLayer != null) { bagLayer.destroy(); } return; } if (d == "all") ItemUtil.useItem(this.iteminfo.id, ItemUtil.getBagItemCount(this.iteminfo.id), this.iteminfo.operateid); else ItemUtil.useItem(this.iteminfo.id, 1, this.iteminfo.operateid); }, // 刪除道具 delBtnClicked() { let count = GameModel.player.itemList[this.iteminfo.id]; let info = `是否刪除${this.iteminfo.name}${count}個?`; let self = this; GameModel.notice.addMsg(1, info, () => { if (GameModel.player.safe_lock == 1) { let safe_notice = cc.instantiate(self.SafeNotice); if (SKUIUtil.isValid(safe_notice)) { safe_notice.parent = cc.find('Canvas'); Bag.Instance.hideBagPanel() safe_notice.getComponent('SafeNotice').setCallback(() => { GoodsMgr.subItem(this.iteminfo.id); self.node.destroy(); Bag.Instance.showBagPanel() }); } } else { if (self.iteminfo) { GoodsMgr.subItem(self.iteminfo.id); self.node.destroy(); } } }, () => { }); }, touchBegan(event) { if (this.bgNode.getBoundingBoxToWorld().contains(event.getLocation())) { return; } this.node.runAction(cc.sequence(cc.fadeOut(0.1), cc.removeSelf())); }, // 能否批量使用 canUseAll(id) { // if (SKDataUtil.atRange(id, [80001,50020,50018,50016,50015,50014,50013,50012,50011])) { // return true; // } return false; }, isComposeTransformation(id) { if (SKDataUtil.atRange(id, [100311, 100313, 100315, 100317])) { return true; } return false; } });