import SKUIUtil from "../ts/gear_2.3.4/util/SKUIUtil"; import GameModel from "../ts/core/GameModel"; import GameUtil from "../ts/core/GameUtil"; import ItemUtil from "../ts/core/ItemUtil"; import MsgAlert from "../ts/game/msg/MsgAlert"; import SKDataUtil from "../ts/gear_2.3.4/util/SKDataUtil"; import SKLogger from "../ts/gear_2.3.4/util/SKLogger"; import Bag from "../ts/bag/Bag"; import { EAttrTypeL1 } from "../ts/core/EEnum"; cc.Class({ extends: cc.Component, properties: { bgNode: cc.Node, itemIcon: cc.Sprite, typeLab: cc.Label, nameLab: cc.Label, infoLab: cc.Node, pbNode: cc.Node, operationNode: cc.Node, useNode: cc.Node, unloadNode: cc.Node, resolveNode: cc.Node, workSopBtn: cc.Node, delNode: cc.Node, tipsNode: cc.Node, workshopPre: cc.Prefab, wingUpdatePrefab: cc.Prefab, SafeNotice: cc.Prefab, }, onLoad() { this.operationNode.active = false; this.delNode.active = false; this.height = cc.find('Canvas').height; this.node.on(cc.Node.EventType.TOUCH_START, this.touchBegan.bind(this)); this.indexarr = ['武器', '項鍊', '衣服', '頭盔', '鞋子', "翅膀", "披風", "挂件", "腰帶", "戒指", "法寶", "戒指"]; this.sexarr = ['男', '女']; this.racearr = ['人', '仙', '魔', '鬼', '龍']; }, loadInfo(info, isChat = false) { this.attr1 = GameModel.player.gameData.attr1; this.iteminfo = info; if (!info.BaseAttr) { GameModel.send('c2s_equip_info', { roleid: GameModel.player.roleid, equipid: info.EquipID }); return; } if (!isChat) this.showOperation(); this.itemIcon.spriteFrame = ItemUtil.getItemIconBy(info); this.typeLab.string = info.EDesc; this.nameLab.string = info.EName; // 仙器 if (info.EquipType == 3) { info.Grade >= 3 && (this.node.getChildByName("tips_treasures").active = true) var self = this; cc.loader.loadRes("ui_single/tips/tips_type_xq4", cc.SpriteFrame, function (err, spriteframe) { self.bgNode.getChildByName("ui_common_qiangxing_back").getComponent(cc.Sprite).spriteFrame = spriteframe; self.typeLab.node.y = 2; }); } // 神兵 if (info.EquipType == 2) { info.Grade >= 3 && (this.node.getChildByName("tips_treasures").active = true) var self = this; cc.loader.loadRes("ui_single/tips/tips_type_sb5", cc.SpriteFrame, function (err, spriteframe) { self.bgNode.getChildByName("ui_common_qiangxing_back").getComponent(cc.Sprite).spriteFrame = spriteframe; self.typeLab.node.y = 0; }); } this.node.getChildByName("score").getComponent(cc.Label).string = info.BaseScore; this.infoPos = this.infoLab.getPosition(); this.addInfoLab(info.Detail); let prefix = info.EIndex < 7 ? "裝備" : "配飾"; this.addInfoLab(`【${prefix}部位】${this.indexarr[info.EIndex - 1]}`); if (info.Sex == 9 || info.Race == 9) { this.addInfoLab(`【${prefix}適用】通用`); } else if (info.OwnerRoleId && info.OwnerRoleId > 0) { if (info.OwnerRoleId != GameModel.player.resid) { this.addInfoLab(`【${prefix}適用】${GameUtil.roleName[info.OwnerRoleId]}`, this.infoPos, true, cc.Color.RED); // this.useNode.getComponent(cc.Button).interactable = false; // this.useNode.color = cc.Color.GRAY; } else { this.addInfoLab(`【${prefix}適用】${GameUtil.roleName[info.OwnerRoleId]}`); } } else { if (info.Sex != GameModel.player.sex || info.Race != GameModel.player.race) { this.addInfoLab(`【${prefix}適用】${this.sexarr[info.Sex - 1]}${this.racearr[info.Race - 1]}`, this.infoPos, true, cc.Color.RED); // this.useNode.getComponent(cc.Button).interactable = false; // this.useNode.color = cc.Color.GRAY; } else { this.addInfoLab(`【${prefix}適用】${this.sexarr[info.Sex - 1]}${this.racearr[info.Race - 1]}`); } } let levelstr = '【等級要求】'; if (info.NeedGrade) { if (info.NeedRei) { if (info.NeedRei < 4) { levelstr += `${info.NeedRei}轉`; } else { levelstr += `飛升`; } } levelstr += `${info.NeedGrade}級`; if (info.NeedGrade > GameModel.player.level || info.NeedRei > GameModel.player.relive) { this.addInfoLab(levelstr, this.infoPos, true, cc.Color.RED); // this.useNode.getComponent(cc.Button).interactable = false; // this.useNode.color = cc.Color.GRAY; } else { this.addInfoLab(levelstr); } } if (info.Shuxingxuqiu && info.Shuxingxuqiu.length > 0) { let xuqiuInfo = JSON.parse(info.Shuxingxuqiu); let xuqiustr = ''; for (let key in xuqiuInfo) { xuqiustr = `【${GameUtil.getAttrTypeL2Name(key)}要求】${xuqiuInfo[key]}`; if (this.attr1[key] < xuqiuInfo[key]) { this.addInfoLab(xuqiustr, this.infoPos, true, cc.Color.RED); // this.useNode.getComponent(cc.Button).interactable = false; // this.useNode.color = cc.Color.GRAY; } else { this.addInfoLab(xuqiustr); } break; } } this.addInfoLab(`【${prefix}耐久】${info.MaxEndure}/${info.MaxEndure}`); // 翅膀 if (info.EquipType == 4) { if (!info.BaseAttr) { info.BaseAttr = '{}'; } info.BaseAttr = '{}'; this.workSopBtn.active = true } else this.workSopBtn.active = true if (!info.BaseAttr) { info.BaseAttr = '{}'; } let baseInfo = SKDataUtil.jsonBy(info.BaseAttr); if (baseInfo) { for (let key in baseInfo) { this.addInfoLab(GameUtil.getAttrTypeL1Name(key), this.infoPos, false, new cc.color(141, 135, 103)); let valuestr = baseInfo[key]; if (GameUtil.equipTypeNumerical.indexOf(Number(key)) == -1) { valuestr = (valuestr > 0 ? '+' : '') + (valuestr / 10).toFixed(1) + '%'; } else { valuestr = (valuestr > 0 ? '+' : '') + valuestr; } var max = this.getMaxValue(key, info.Grade, info.GemCnt) var curV = baseInfo[key]; if (GameUtil.equipTypeNumerical.indexOf(Number(key)) == -1) curV = curV / 10 this.addPb(SKUIUtil.add(this.infoPos, cc.v2(105, 1)), curV, max) this.addInfoLab(valuestr, SKUIUtil.add(this.infoPos, cc.v2(120, 0)), true, new cc.color(141, 135, 103)); } } if (info.LianhuaAttr == null) { info.LianhuaAttr = '{}'; } let lianhuaInfo = SKDataUtil.jsonBy(info.LianhuaAttr); if (Array.isArray(lianhuaInfo)) { for (const info of lianhuaInfo) { for (const key in info) { this.addInfoLab(GameUtil.getAttrTypeL1Name(key), this.infoPos, false, new cc.color(46, 143, 9)); let valuestr = info[key]; if (GameUtil.equipTypeNumerical.indexOf(Number(key)) == -1) { valuestr = (valuestr > 0 ? '+' : '') + (valuestr / 10).toFixed(1) + '%'; } else { valuestr = (valuestr > 0 ? '+' : '') + valuestr; } this.addInfoLab(valuestr, SKUIUtil.add(this.infoPos, cc.v2(120, 0)), true, new cc.color(46, 143, 9)); break; } } } // 如果已裝備 if (ItemUtil.isEquip(this.iteminfo)) { this.useNode.active = false; this.delNode.active = false; this.tipsNode.active = true; } else { this.unloadNode.active = false; } // 未裝備的二階及以上仙器可以分解 if (!ItemUtil.isEquip(info) && info.EquipType == 3 && info.Grade > 1 || info.EquipType == 4) { this.resolveNode.active = true; this.operationNode.height = 190; } else { this.resolveNode.active = false; this.operationNode.height = 130; } // if (info.EquipType == 4) // this.operationNode.height = 80; this.showGemInfo(info.GemCnt, info.EIndex); }, getMaxValue(key, grade, GemCnt) { // 一階屬性上限 let score = 15; // 如果是抗性 if (key < 12) score = 30; // 品階加成 if (grade > 1) if (key < 12) score = 30 + (grade - 1) * 5; else score = 15 + (grade - 1) * 3; // 特殊值屬性 if (key == EAttrTypeL1.ATK) { score = 3000; if (grade > 1) score = 3000 + (grade - 1) * 1000; } if (key == EAttrTypeL1.MP_MAX || key == EAttrTypeL1.HP_MAX) { score = 5040; if (grade > 1) score = 5040 + (grade - 1) * 1050; } if (key == EAttrTypeL1.SPD) { score = 87; if (grade > 1) score = 87 + (grade - 1) * 40; } score = Math.floor(SKDataUtil.toDecimal2(score * (1 + 0.03 * GemCnt))); return score; }, showGemInfo() { let gemX = this.bgNode.getChildByName('gem').x; let gemY = this.bgNode.getChildByName('gem').y; for (let index = 0; index < this.iteminfo.MaxEmbedGemCnt; index++) { let gem = cc.instantiate(this.bgNode.getChildByName('gem')); gem.active = true; gem.x = gemX + index * 15; gem.y = gemY; gem.parent = this.bgNode; if (index < this.iteminfo.GemCnt) { gem.getChildByName(`gem${this.iteminfo.EIndex}`).active = true; } } }, showOperation() { this.operationNode.active = true; this.delNode.active = !ItemUtil.isEquip(this.iteminfo); }, addPb(pos, value, max) { if (!pos && pos == null) { pos = this.infoPos; } let detail = cc.instantiate(this.pbNode); detail.active = true; detail.parent = this.bgNode; detail.setPosition(pos); var pro = value / max; pro = pro > 1 ? 1 : pro if (pro >= 0.85) { var icon = cc.find("icon", detail) if (icon) icon.active = true } detail.getComponent(cc.ProgressBar).progress = pro }, addInfoLab(info, pos, newline = true, color = cc.Color.WHITE) {//, color){ if (!pos && pos == null) { pos = this.infoPos; } let detail = cc.instantiate(this.infoLab); detail.active = true; detail.parent = this.bgNode; detail.setPosition(pos); detail.color = color; detail.getComponent(cc.Label).string = info; if (newline) { this.infoPos.y -= (detail.height + 4); } if (-this.infoPos.y > this.bgNode.height) { this.bgNode.height = -this.infoPos.y; if (this.bgNode.y + this.infoPos.y < -this.height / 2) { this.bgNode.y = -this.height / 2 - this.infoPos.y; } } }, // 點擊裝備 useBtnClicked() { GameModel.send('c2s_equip_update', { operation: 1, roleid: GameModel.player.roleid, equipid: this.iteminfo.EquipID }); this.node.destroy(); }, unloadBtnClicked() { GameModel.send('c2s_equip_update', { operation: 2, roleid: GameModel.player.roleid, equipid: this.iteminfo.EquipID }); this.node.destroy(); }, delBtnClicked() { let mainuilogic = GameModel.player.getMainUILogic(); if (mainuilogic && mainuilogic.isBattle) { MsgAlert.addMsg('戰鬥中無法丟棄裝備'); return; } if (!this.iteminfo) { cc.warn(`$警告:刪除裝備無效`); return; } let self = this; GameModel.notice.addMsg(1, ' 是否刪除裝備? ', () => { if (GameModel.player.safe_lock == 1) { let safe_notice = cc.instantiate(this.SafeNotice); if (SKUIUtil.isValid(safe_notice)) { var pNode if (SKUIUtil.isFGUIValid(Bag.Instance.bagPanel)) pNode = Bag.Instance.bagPanel.node; safe_notice.parent = pNode; safe_notice.getComponent('SafeNotice').setCallback(() => { if (self.iteminfo) { GameModel.send('c2s_equip_update', { operation: 0, roleid: GameModel.player.roleid, equipid: self.iteminfo.EquipID }); } else { SKLogger.warn(`$警告:裝備刪除找不到裝備`); } self.node.destroy(); }); } } else { if (self.iteminfo) { GameModel.send('c2s_equip_update', { operation: 0, roleid: GameModel.player.roleid, equipid: self.iteminfo.EquipID }); } else { SKLogger.warn(`$警告:裝備刪除找不到裝備`); } self.node.destroy(); } }, () => { }); }, // 點擊煉器 workshopClicked() { if (this.iteminfo.EIndex == 6) { let wingUpdate = cc.instantiate(this.wingUpdatePrefab); wingUpdate.parent = cc.find('Canvas'); wingUpdate.name = 'WingUpdatePanel'; wingUpdate.getComponent('WingUpdatePanel').setCurItem(this.iteminfo.EquipID); } else { let workshop = cc.instantiate(this.workshopPre); workshop.parent = cc.find('Canvas'); workshop.name = 'WorkShopPanel'; workshop.getComponent('WorkShopPanel').setCurItem(this.iteminfo.EquipID); } this.node.destroy(); let bagLayer = cc.find('Canvas/MainUI/BagPanel'); if (bagLayer != null) { bagLayer.destroy(); } Bag.Instance.closeBagPanel(); }, // 點擊分解 clickResolve() { ItemUtil.equipResolve(this.iteminfo); this.node.destroy(); }, touchBegan(event) { if (this.bgNode.getBoundingBoxToWorld().contains(event.getLocation())) { return; } this.node.runAction(cc.sequence(cc.fadeOut(0.1), cc.removeSelf())); }, });