import MyModel from "../ts/core/MyModel"; import AudioUtil from "../ts/core/AudioUtil"; import { EAttrTypeL1, LongPressSpeedAttr } from "../ts/core/EEnum"; 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 PetUtil from "../ts/game/pet/PetUtil"; import ChangeNameAlert from "../ts/game/role/ChangeNameAlert"; import SkillUtil from "../ts/game/skill/core/SkillUtil"; import Report from "../ts/gear_2.3.4/net/Report"; import SKDataUtil from "../ts/gear_2.3.4/util/SKDataUtil"; import SKLogger from "../ts/gear_2.3.4/util/SKLogger"; import SKUIUtil from "../ts/gear_2.3.4/util/SKUIUtil"; import SKSocket from "../ts/gear_2.3.4/net/SKSocket"; import FGAlert from "../ts/gear_2.3.4/fgui/FGAlert"; import FGUtil from "../ts/gear_2.3.4/fgui/FGUtil"; let logic = require('../game/PetLogic'); cc.Class({ extends: cc.Component, properties: { titleNodes: [cc.Node], petContent: cc.Node, resistanceContent: cc.Node, resistanceContent1: cc.Node, resistanceLevelNode: cc.Node, resistanceSureNode: cc.Node, propertyNode: cc.Node, propertyPanel: cc.Node, addPointPanel: cc.Node, petPropertyPanel: cc.Node, addOrSubNumber: 1, /* 天資面板 */ resistanceNode: cc.Node, skillNode: cc.Node, tujianNode: cc.Node, washPropertyPanel: cc.Node, /* 洗練屬性 */ petNode: cc.Node, petItem: cc.Prefab, useItemUI: cc.Prefab, commonUIAtlas: cc.SpriteAtlas, PetShenSkillUI: cc.Prefab, petSKillBookItem: cc.Prefab, SafeNotice: cc.Prefab, SkillDetail: cc.Prefab, //寶寶支援 petSupport: cc.Node, nameEditBox: cc.EditBox, petSkillBookNodeList: [], supportPanel: null, selectSupportIdx: -1, }, onLoad() { this.petLogic = new logic.PetLogic(); this.currentSelected = -1; this.itemNodes = []; this.resistanceContent.parent.parent.active = false; this.resistanceContent1.parent.parent.active = false; this.resistancePanel = this.resistanceContent; this.resistancePanel.parent.parent.active = true; this.kangPointAdd = 0; this.loadPetList(); if (GameModel.player.petInfo.list.length >= 2) { this.petSupport.active = true; } else { this.petSupport.active = false; } this.currentBtn = null; this.timecnt = 0; this.maxtiemcnt = 4; }, initBtn(btn, data, type, iskang) { btn.datainfo = data; btn.opertype = type; btn.iskang = iskang; btn.on(cc.Node.EventType.TOUCH_START, this.propertyBtnClick.bind(this)); btn.on(cc.Node.EventType.TOUCH_CANCEL, this.propertyBtnClick.bind(this)); btn.on(cc.Node.EventType.TOUCH_END, this.propertyBtnClick.bind(this)); }, propertyBtnClick(e) { this.addOrSubNumber = LongPressSpeedAttr.OPERAINITNUM; if (e.type == cc.Node.EventType.TOUCH_START) { this.maxtiemcnt = LongPressSpeedAttr.MAXTIMECNT; this.timecnt = 0; this.currentBtn = e.target; } else if (e.type == cc.Node.EventType.TOUCH_END || e.type == cc.Node.EventType.TOUCH_CANCEL) { this.timecnt = this.maxtiemcnt; this.update(); this.currentBtn = null; } }, onEditNameClick() { ChangeNameAlert.shared.show(this.petLogic.petid, 0, this.petLogic.name); }, update() { if (this.currentBtn == null) { return; } this.timecnt += LongPressSpeedAttr.TIMECNTADD; if (this.timecnt >= this.maxtiemcnt) { if (this.maxtiemcnt > LongPressSpeedAttr.MINTIMECNT) { this.maxtiemcnt -= LongPressSpeedAttr.TIMECNTSUB; this.maxtiemcnt = Math.max(LongPressSpeedAttr.MINTIMECNT, this.maxtiemcnt) } this.timecnt = 0; if (this.currentBtn.iskang) { if (this.currentBtn.opertype == 0) { this.resistanceAddPoint(this.currentBtn.datainfo); } else if (this.currentBtn.opertype == 1) { this.resistanceSubPoint(this.currentBtn.datainfo); } } else { if (this.currentBtn.opertype == 0) { this.propertyAddPoint(this.currentBtn.datainfo); } else if (this.currentBtn.opertype == 1) { this.propertySubPoint(this.currentBtn.datainfo); } } this.addOrSubNumber += LongPressSpeedAttr.OPERADDNUM; } }, initKangBtn() { cc.find('xiupoint', this.resistanceNode).getComponent(cc.Label).string = this.petLogic.xiulianleft - this.kangPointAdd + '/' + this.petLogic.xiulianfree; this.setKangBtnInfo('fengyinitem', EAttrTypeL1.K_SEAL); this.setKangBtnInfo('hunluanitem', EAttrTypeL1.K_CONFUSION); this.setKangBtnInfo('hunshuiitem', EAttrTypeL1.K_SLEEP); this.setKangBtnInfo('yiwangitem', EAttrTypeL1.K_FORGET); this.setKangBtnInfo('fengitem', EAttrTypeL1.K_WIND); this.setKangBtnInfo('leiitem', EAttrTypeL1.K_THUNDER); this.setKangBtnInfo('shuiitem', EAttrTypeL1.K_WATER); this.setKangBtnInfo('huoitem', EAttrTypeL1.K_FIRE); this.setKangBtnInfo('guihuoitem', EAttrTypeL1.K_WILDFIRE); this.setKangBtnInfo('sanshiitem', EAttrTypeL1.K_BLOODRETURN); this.setKangBtnInfo('duitem', EAttrTypeL1.K_POISON); this.setKangBtnInfo('zhenitem', EAttrTypeL1.K_DETER); this.setKangBtnInfo('xishouitem', EAttrTypeL1.PHY_GET); this.setKangBtnInfo('mingzhongitem', EAttrTypeL1.PHY_HIT); this.setKangBtnInfo('shanduoitem', EAttrTypeL1.PHY_DODGE); this.setKangBtnInfo('lianjiitem', EAttrTypeL1.PHY_COMBO); this.setKangBtnInfo('lianjilvitem', EAttrTypeL1.PHY_COMBO_PROB); this.setKangBtnInfo('kuangbaoitem', EAttrTypeL1.PHY_DEADLY); this.setKangBtnInfo('pofangitem', EAttrTypeL1.PHY_BREAK); this.setKangBtnInfo('pofanglvitem', EAttrTypeL1.PHY_BREAK_PROB); this.setKangBtnInfo('fanzhenlvitem', EAttrTypeL1.PHY_REBOUND_PROB); this.setKangBtnInfo('fanzhenitem', EAttrTypeL1.PHY_REBOUND); }, setKangBtnInfo(name, type) { this.initBtn(cc.find(`${name}/point/addBtn`, this.resistancePanel), type, 0, true); this.initBtn(cc.find(`${name}/point/subBtn`, this.resistancePanel), type, 1, true); // cc.find(`${name}/point/addBtn`, this.resistancePanel).getComponent(cc.Button).clickEvents[0].customEventData = type; // cc.find(`${name}/point/subBtn`, this.resistancePanel).getComponent(cc.Button).clickEvents[0].customEventData = type; if (this.petLogic.xiulianleft - this.kangPointAdd <= 0 || this.petLogic.dpoint[type] >= this.petLogic.getMaxAddPoint(type)) { cc.find(`${name}/point/addBtn`, this.resistancePanel).active = false; } else { cc.find(`${name}/point/addBtn`, this.resistancePanel).active = true; } if (this.petLogic.dpointT[type] > 0) { cc.find(`${name}/point/subBtn`, this.resistancePanel).active = true; } else { cc.find(`${name}/point/subBtn`, this.resistancePanel).active = false; } }, // TODO 查一下 角色索引[7380] loadPetList() { this.propertyNode.active = false; this.resistanceNode.active = false; this.skillNode.active = false; this.tujianNode.active = false; if (GameModel.player.petInfo == null) { SKLogger.warn(`$警告:玩家[${GameModel.player.roleid}:${GameModel.player.name}]召喚獸面板獲得列表錯誤`); return; } let petInfo = GameModel.player.petInfo; this.petContent.destroyAllChildren(); this.itemNodes = []; let select_index = 0; this.petLogic.setInfo(null); this.petContent.height = petInfo.list.length * 100; if (this.petContent.height < this.petContent.parent.height) { this.petContent.height = this.petContent.parent.height; } for (let index = 0; index < petInfo.list.length; index++) { let pinfo = petInfo.list[index]; if (!pinfo || !pinfo.petid) { cc.warn(`$警告:召喚獸面板加載列表數據錯誤${index}`); continue; } console.log(pinfo.petid) GameModel.send("c2s_pet_info", { roleid: GameModel.player.roleid, petid: pinfo.petid }) let item = cc.instantiate(this.petItem); item.x = 0; item.y = -index * 100; item.parent = this.petContent; let btn = item.getComponent(cc.Button); var clickEventHandler = new cc.Component.EventHandler(); clickEventHandler.target = this.node; clickEventHandler.component = "PetPanel"; clickEventHandler.handler = "petItemClicked"; clickEventHandler.customEventData = pinfo.petid; btn.clickEvents.push(clickEventHandler); this.itemNodes.push(item); item.getComponent('NPetItem').loadInfo(pinfo, pinfo.petid == petInfo.curid); if (pinfo.petid == petInfo.curid) { select_index = index; } } let item = this.itemNodes[select_index]; if (item) { item.getComponent('NPetItem').selected(); } if (petInfo == null) { return; } let list = petInfo.list; if (list == null) { SKLogger.warn(`玩家[${GameModel.player.roleidd}:${GameModel.player.name}]召喚獸列表為空!`); return; } let info = list[select_index]; if (info == null) { SKLogger.warn(`玩家[${GameModel.player.roleidd}:${GameModel.player.name}]召喚獸[${select_index}]不存在!`); return; } this.petLogic.setInfo(info); this.showInfo(); this.currentSelected = info.petid; }, reloadInfo(info, refresh = false) { if (!info) { cc.warn(`$警告:重新加載召喚獸信息為空!`); return; } for (let item of this.itemNodes) { if (item.getComponent('NPetItem').itemInfo.petid == info.petid) { item.getComponent('NPetItem').loadInfo(info, info.petid == GameModel.player.petInfo.curid); } } if (this.currentSelected == info.petid) { this.petLogic.setInfo(info); this.showInfo(true); } if (this.useui && this.useui.parent != null) { this.useui.getComponent('UseItemUI').refreshInfo(); } if (this.useui1 && this.useui1.parent != null) { this.useui1.getComponent('UseItemUI').refreshInfo(); } if (this.useui2 && this.useui2.parent != null) { this.useui2.getComponent('UseItemUI').refreshInfo(); } }, refreshInfoNum() { if (this.useui && this.useui.parent != null) { this.useui.getComponent('UseItemUI').refreshInfoNum(); } if (this.useui1 && this.useui1.parent != null) { this.useui1.getComponent('UseItemUI').refreshInfoNum(); } if (this.useui2 && this.useui2.parent != null) { this.useui2.getComponent('UseItemUI').refreshInfoNum(); } }, showPropertyInfo() { this.propertyPanel.getChildByName('jyProgress').getComponent(cc.ProgressBar).progress = this.petLogic.exp / this.petLogic.maxexp; this.propertyPanel.getChildByName('jyProgress').getChildByName('jingyan').getComponent(cc.Label).string = this.petLogic.exp + '/' + this.petLogic.maxexp; this.propertyPanel.getChildByName('QixueLabel').getComponent(cc.Label).string = this.petLogic.cur_hp; this.propertyPanel.getChildByName('FaliLabel').getComponent(cc.Label).string = this.petLogic.cur_mp; this.propertyPanel.getChildByName('GongjiLabel').getComponent(cc.Label).string = this.petLogic.cur_atk; this.propertyPanel.getChildByName('SuduLabel').getComponent(cc.Label).string = this.petLogic.cur_spd; this.propertyPanel.getChildByName('CloseLabel').getComponent(cc.Label).string = this.petLogic.qinmi; this.addPointPanel.getChildByName('qianNeng').getChildByName('qianneng').getComponent(cc.Label).string = this.petLogic.qianneng; this.addPointPanel.getChildByName('QixueNode').getChildByName('Value1Label').getComponent(cc.Label).string = this.petLogic.cur_hp; this.addPointPanel.getChildByName('FaliNode').getChildByName('Value1Label').getComponent(cc.Label).string = this.petLogic.cur_mp; this.addPointPanel.getChildByName('GongjiNode').getChildByName('Value1Label').getComponent(cc.Label).string = this.petLogic.cur_atk; this.addPointPanel.getChildByName('SuduNode').getChildByName('Value1Label').getComponent(cc.Label).string = this.petLogic.cur_spd; this.addPointPanel.getChildByName('QixueNode').getChildByName('point').getChildByName('Value2Label').getComponent(cc.Label).string = this.petLogic.ppoint[EAttrTypeL1.BONE]; this.addPointPanel.getChildByName('FaliNode').getChildByName('point').getChildByName('Value2Label').getComponent(cc.Label).string = this.petLogic.ppoint[EAttrTypeL1.SPIRIT]; this.addPointPanel.getChildByName('GongjiNode').getChildByName('point').getChildByName('Value2Label').getComponent(cc.Label).string = this.petLogic.ppoint[EAttrTypeL1.STRENGTH]; this.addPointPanel.getChildByName('SuduNode').getChildByName('point').getChildByName('Value2Label').getComponent(cc.Label).string = this.petLogic.ppoint[EAttrTypeL1.DEXTERITY]; this.initBtn(cc.find('SuduNode/point/addBtn', this.addPointPanel), 103, 0); this.initBtn(cc.find('SuduNode/point/subBtn', this.addPointPanel), 103, 1); this.initBtn(cc.find('GongjiNode/point/addBtn', this.addPointPanel), 102, 0); this.initBtn(cc.find('GongjiNode/point/subBtn', this.addPointPanel), 102, 1); this.initBtn(cc.find('FaliNode/point/addBtn', this.addPointPanel), 101, 0); this.initBtn(cc.find('FaliNode/point/subBtn', this.addPointPanel), 101, 1); this.initBtn(cc.find('QixueNode/point/addBtn', this.addPointPanel), 100, 0); this.initBtn(cc.find('QixueNode/point/subBtn', this.addPointPanel), 100, 1); this.initPropertBtn(); }, initPropertBtn() { this.setPropertBtnInfo('QixueNode', EAttrTypeL1.BONE); this.setPropertBtnInfo('FaliNode', EAttrTypeL1.SPIRIT); this.setPropertBtnInfo('GongjiNode', EAttrTypeL1.STRENGTH); this.setPropertBtnInfo('SuduNode', EAttrTypeL1.DEXTERITY); }, setPropertBtnInfo(name, type) { if (this.petLogic.qianneng <= 0) { cc.find(`${name}/point/addBtn`, this.addPointPanel).active = false; } else { cc.find(`${name}/point/addBtn`, this.addPointPanel).active = true; } if (this.petLogic.ppointT[type] > 0) { cc.find(`${name}/point/subBtn`, this.addPointPanel).active = true; } else { cc.find(`${name}/point/subBtn`, this.addPointPanel).active = false; } }, showDInfo() { cc.find('fengyinitem/value', this.resistancePanel).getComponent(cc.Label).string = this.petLogic.dfengyin.toFixed(1) + '%'; cc.find('fengyinitem/add', this.resistancePanel).getComponent(cc.Label).string = this.petLogic.dpoint[EAttrTypeL1.K_SEAL]; cc.find('hunluanitem/value', this.resistancePanel).getComponent(cc.Label).string = this.petLogic.dhunlun.toFixed(1) + '%'; cc.find('hunluanitem/add', this.resistancePanel).getComponent(cc.Label).string = this.petLogic.dpoint[EAttrTypeL1.K_CONFUSION]; cc.find('hunshuiitem/value', this.resistancePanel).getComponent(cc.Label).string = this.petLogic.dhunshui.toFixed(1) + '%'; cc.find('hunshuiitem/add', this.resistancePanel).getComponent(cc.Label).string = this.petLogic.dpoint[EAttrTypeL1.K_SLEEP]; cc.find('yiwangitem/value', this.resistancePanel).getComponent(cc.Label).string = this.petLogic.dyiwang.toFixed(1) + '%'; cc.find('yiwangitem/add', this.resistancePanel).getComponent(cc.Label).string = this.petLogic.dpoint[EAttrTypeL1.K_FORGET]; cc.find('fengitem/value', this.resistancePanel).getComponent(cc.Label).string = this.petLogic.dfeng.toFixed(1) + '%'; cc.find('fengitem/add', this.resistancePanel).getComponent(cc.Label).string = this.petLogic.dpoint[EAttrTypeL1.K_WIND]; cc.find('leiitem/value', this.resistancePanel).getComponent(cc.Label).string = this.petLogic.dlei.toFixed(1) + '%'; cc.find('leiitem/add', this.resistancePanel).getComponent(cc.Label).string = this.petLogic.dpoint[EAttrTypeL1.K_THUNDER]; cc.find('shuiitem/value', this.resistancePanel).getComponent(cc.Label).string = this.petLogic.dshui.toFixed(1) + '%'; cc.find('shuiitem/add', this.resistancePanel).getComponent(cc.Label).string = this.petLogic.dpoint[EAttrTypeL1.K_WATER]; cc.find('huoitem/value', this.resistancePanel).getComponent(cc.Label).string = this.petLogic.dhuo.toFixed(1) + '%'; cc.find('huoitem/add', this.resistancePanel).getComponent(cc.Label).string = this.petLogic.dpoint[EAttrTypeL1.K_FIRE]; cc.find('guihuoitem/value', this.resistancePanel).getComponent(cc.Label).string = this.petLogic.dguihuo.toFixed(1) + '%'; cc.find('guihuoitem/add', this.resistancePanel).getComponent(cc.Label).string = this.petLogic.dpoint[EAttrTypeL1.K_WILDFIRE]; cc.find('sanshiitem/value', this.resistancePanel).getComponent(cc.Label).string = this.petLogic.dsanshi.toFixed(1) + '%'; cc.find('sanshiitem/add', this.resistancePanel).getComponent(cc.Label).string = this.petLogic.dpoint[EAttrTypeL1.K_BLOODRETURN]; cc.find('duitem/value', this.resistancePanel).getComponent(cc.Label).string = this.petLogic.ddu.toFixed(1) + '%'; cc.find('duitem/add', this.resistancePanel).getComponent(cc.Label).string = this.petLogic.dpoint[EAttrTypeL1.K_POISON]; cc.find('zhenitem/value', this.resistancePanel).getComponent(cc.Label).string = this.petLogic.dzhenshe.toFixed(1) + '%'; cc.find('zhenitem/add', this.resistancePanel).getComponent(cc.Label).string = this.petLogic.dpoint[EAttrTypeL1.K_DETER]; cc.find('xishouitem/value', this.resistancePanel).getComponent(cc.Label).string = this.petLogic.pxishou.toFixed(1) + '%'; cc.find('xishouitem/add', this.resistancePanel).getComponent(cc.Label).string = this.petLogic.dpoint[EAttrTypeL1.PHY_GET]; cc.find('mingzhongitem/value', this.resistancePanel).getComponent(cc.Label).string = this.petLogic.pmingzhong.toFixed(1) + '%'; cc.find('mingzhongitem/add', this.resistancePanel).getComponent(cc.Label).string = this.petLogic.dpoint[EAttrTypeL1.PHY_HIT]; cc.find('shanduoitem/value', this.resistancePanel).getComponent(cc.Label).string = this.petLogic.pshanbi.toFixed(1) + '%'; cc.find('shanduoitem/add', this.resistancePanel).getComponent(cc.Label).string = this.petLogic.dpoint[EAttrTypeL1.PHY_DODGE]; cc.find('lianjiitem/value', this.resistancePanel).getComponent(cc.Label).string = this.petLogic.plianji; cc.find('lianjiitem/add', this.resistancePanel).getComponent(cc.Label).string = this.petLogic.dpoint[EAttrTypeL1.PHY_COMBO]; cc.find('lianjilvitem/value', this.resistancePanel).getComponent(cc.Label).string = this.petLogic.plianjilv.toFixed(1) + '%'; cc.find('lianjilvitem/add', this.resistancePanel).getComponent(cc.Label).string = this.petLogic.dpoint[EAttrTypeL1.PHY_COMBO_PROB]; cc.find('kuangbaoitem/value', this.resistancePanel).getComponent(cc.Label).string = this.petLogic.pkuangbao.toFixed(1) + '%'; cc.find('kuangbaoitem/add', this.resistancePanel).getComponent(cc.Label).string = this.petLogic.dpoint[EAttrTypeL1.PHY_DEADLY]; cc.find('pofangitem/value', this.resistancePanel).getComponent(cc.Label).string = this.petLogic.ppofang.toFixed(1) + '%'; cc.find('pofangitem/add', this.resistancePanel).getComponent(cc.Label).string = this.petLogic.dpoint[EAttrTypeL1.PHY_BREAK]; cc.find('pofanglvitem/value', this.resistancePanel).getComponent(cc.Label).string = this.petLogic.ppofanglv.toFixed(1) + '%'; cc.find('pofanglvitem/add', this.resistancePanel).getComponent(cc.Label).string = this.petLogic.dpoint[EAttrTypeL1.PHY_BREAK_PROB]; cc.find('fanzhenlvitem/value', this.resistancePanel).getComponent(cc.Label).string = this.petLogic.pfanzhenlv.toFixed(1) + '%'; cc.find('fanzhenlvitem/add', this.resistancePanel).getComponent(cc.Label).string = this.petLogic.dpoint[EAttrTypeL1.PHY_REBOUND_PROB]; cc.find('fanzhenitem/value', this.resistancePanel).getComponent(cc.Label).string = this.petLogic.pfanzhen.toFixed(1) + '%'; cc.find('fanzhenitem/add', this.resistancePanel).getComponent(cc.Label).string = this.petLogic.dpoint[EAttrTypeL1.PHY_REBOUND]; }, showSkillInfo() { while (this.skillNode.getChildByName('skillbtn')) { let node = this.skillNode.getChildByName('skillbtn'); node.parent = null; node.destroy(); } let self = this; let url = `ui/photo/${this.petLogic.resid}`; cc.loader.loadRes(url, cc.SpriteFrame, (error, frame) => { if (error) { cc.warn(`$警告:資源加載${url}錯誤`); return; } let node = cc.find('photo/petNode/pet', self.skillNode); if (node) { let sprite = node.getComponent(cc.Sprite); if (sprite) { sprite.spriteFrame = frame; } else { cc.log(`$警告:找不到精靈`); } } else { cc.log(`$警告:找不到節點`); } }); let skillCnt = this.petLogic.maxskillcnt; let skillItem = cc.find('skillitem', this.skillNode); let deltaAngle = 360 / skillCnt; let firstPos = skillItem.getPosition(); let centerPos = cc.find('photo', this.skillNode).getPosition(); let radius = firstPos.y - centerPos.y; let skillinfolist = null; if (this.petLogic && this.petLogic.petinfo) { skillinfolist = this.petLogic.petinfo.skill; } if (!skillinfolist) { skillinfolist = []; } let tmpskilllist = []; for (let skillid in skillinfolist) { if (SKDataUtil.hasProperty(skillinfolist, skillid)) { let skillinfo = skillinfolist[skillid]; skillinfo.skillid = skillid; tmpskilllist.push(skillinfo); } } tmpskilllist.sort((a, b) => { return a.idx - b.idx; }); for (let index = 0; index < skillCnt; index++) { let skillinfo = null; // 神獸自帶天生技能,idx從0開始 if (tmpskilllist.length > 0) { var notShenPet = 1; if (tmpskilllist[0].idx == 0 && index == 0) { notShenPet = 0; skillinfo = tmpskilllist[0] } else { for (let j in tmpskilllist) { if (tmpskilllist[j].idx == index + notShenPet) { skillinfo = tmpskilllist[j] } } } } let item = cc.instantiate(skillItem); item.active = true; item.name = 'skillbtn'; let curAngle = -index * deltaAngle / 180 * GameUtil.PI; let curPos = cc.v2(-radius * Math.sin(curAngle), radius * Math.cos(curAngle)); curPos = SKUIUtil.add(centerPos, curPos); item.parent = this.skillNode; item.setPosition(curPos); item.getChildByName('base').active = true; if (skillinfo) { item.getChildByName('lock').active = false; let skillid = skillinfo.skillid; if (skillid > 1000) { let skill = SkillUtil.getSkill(skillid); let key = skill.icon; let spriteFrame = SkillUtil.getSkillIcon(key); if (!spriteFrame) { cc.warn(`$警告:召喚獸缺少技能圖標:${key}`); } else { cc.find('base/icon', item).getComponent(cc.Sprite).spriteFrame = spriteFrame; } item.getChildByName('lockflag').active = (skillinfo.lck == 1); let btn = item.getChildByName('base').getComponent(cc.Button); let handle = btn.clickEvents[0]; handle.customEventData = skillid; } else { let btn = item.getChildByName('base').getComponent(cc.Button); let handle = btn.clickEvents[0]; handle.customEventData = -2; } } else { item.getChildByName('lock').active = true; let btn = item.getChildByName('base').getComponent(cc.Button); let handle = btn.clickEvents[0]; handle.customEventData = { openSkillGrid: true, index: index }; } } }, changeShenSkill(petid, skillid) { if (this.petLogic.petid == petid) { let shenskillnode = cc.find('SkillNode/shenSkill', this.node); shenskillnode.active = true; let sprite = cc.find('skillicon', shenskillnode).getComponent(cc.Sprite); sprite.spriteFrame = SkillUtil.getItemIcon(skillid); } }, showInfo(refresh = false) { this.kangPointAdd = 0; this.propertyPanel.getChildByName('NameLabel').getComponent(cc.Label).string = this.petLogic.name; let level_lb = this.propertyPanel.getChildByName('LevelLabel').getComponent(cc.Label); GameUtil.setReliveLabel(level_lb, 1, this.petLogic.relive, this.petLogic.level); let petcolor = null; if (this.petLogic && this.petLogic.petinfo) { petcolor = this.petLogic.petinfo.color; } else { cc.warn(`$警告:召喚獸變色信息異常!`); } // if (!refresh) this.petNode.getComponent('UIRole').setInfo({ resid: this.petLogic.resid, name: '', petcolor: petcolor }); this.showPropertyInfo(); cc.find('xiupoint', this.resistanceNode).getComponent(cc.Label).string = this.petLogic.xiulianleft + '/' + this.petLogic.xiulianfree; cc.find('xiuexp', this.resistanceLevelNode).getComponent(cc.Label).string = this.petLogic.xexp + '/' + this.petLogic.xmaxexp; cc.find('xiulevel', this.resistanceNode).getComponent(cc.Label).string = '修煉LV.' + this.petLogic.xlevel; cc.find('xiuprogress', this.resistanceLevelNode).getComponent(cc.ProgressBar).progress = this.petLogic.xexp / this.petLogic.xmaxexp; if (this.petLogic.xlevel > 0) { this.resistancePanel.parent.parent.active = false; this.resistancePanel = this.resistanceContent1; this.resistancePanel.parent.parent.active = true; this.initKangBtn(); } else { this.resistancePanel.parent.parent.active = false; this.resistancePanel = this.resistanceContent; this.resistancePanel.parent.parent.active = true; } this.showDInfo(); this.resistanceLevelNode.active = true; this.resistanceSureNode.active = false; this.showSkillInfo(); if (this.petPropertyPanel.active == true) { this.refrushPetpropertyPanel(); } let shenskillnode = cc.find('SkillNode/shenSkill', this.node); if (this.petLogic.grade >= 3) { shenskillnode.active = true; let sprite = cc.find('skillicon', shenskillnode).getComponent(cc.Sprite); if (this.petLogic.shenSkill == 0 || this.petLogic.shenSkill == 0.0) { sprite.spriteFrame = ''; } else { sprite.spriteFrame = SkillUtil.getSkillIcon(this.petLogic.shenSkill); } } else { shenskillnode.active = false; } // let wuxingX = this.resistancePanel.getChildByName('wuxingitem0').x; // let wuxingY = this.resistancePanel.getChildByName('wuxingitem0').y; // let wuxingCount = 0; // for (let index = 0; index < 5; index++) { // if (this.petLogic.wuxing[index] == 0) { // this.resistancePanel.getChildByName('wuxingitem' + index).active = false; // continue; // } // this.resistancePanel.getChildByName('wuxingitem' + index).active = true; // this.resistancePanel.getChildByName('wuxingitem' + index).x = (wuxingCount % 2) * 228 + wuxingX; // this.resistancePanel.getChildByName('wuxingitem' + index).y = wuxingY - Math.floor(wuxingCount / 2) * 35; // this.resistancePanel.getChildByName('wuxingitem' + index).getChildByName('value').getComponent(cc.Label).string = this.petLogic.wuxing[index]; // this.resistancePanel.height = -(wuxingY - Math.floor(wuxingCount / 2) * 35 - 15); // wuxingCount++; // } if (GameModel.player.petInfo.curid == this.petLogic.petid) { this.propertyPanel.getChildByName('canzhan').active = true; this.propertyPanel.getChildByName('joinBtn').active = false; } else { this.propertyPanel.getChildByName('canzhan').active = false; this.propertyPanel.getChildByName('joinBtn').active = true; } //顯示隱藏換色按鈕 for (const itemid in GameModel.player.itemList) { if (GameModel.player.itemList[itemid] > 0) { let itemInfo = ItemUtil.getItemData(itemid); if (!this.petLogic.petinfo) { continue; } if (itemInfo && itemInfo.num == this.petLogic.petinfo.dataid) { this.propertyPanel.getChildByName('btnChangeColor').active = true; this.propertyPanel.getChildByName('btnChangeColor').getComponent(cc.Button).clickEvents[0].customEventData = itemid; break; } } } for (const item of this.titleNodes) { item.active = false; } if (cc.find('ToggleGroup/toggle1', this.node).getComponent(cc.Toggle).isChecked) { this.propertyNode.active = true; this.titleNodes[0].active = true; } else if (cc.find('ToggleGroup/toggle2', this.node).getComponent(cc.Toggle).isChecked) { this.resistanceNode.active = true; this.titleNodes[1].active = true; } else if (cc.find('ToggleGroup/toggle3', this.node).getComponent(cc.Toggle).isChecked) { this.skillNode.active = true; this.closeStudySkillPanel(); this.titleNodes[2].active = true; } else if (cc.find('ToggleGroup/toggle4', this.node).getComponent(cc.Toggle).isChecked) { this.tujianNode.active = true; this.titleNodes[3].active = true; } }, propertyJoinBtnClicked(e, d) { GameModel.send('c2s_change_pet', { petid: this.petLogic.petid }); }, //--zfy 增加 二次確認彈窗 propertyDelBtnClicked(e, d) { let mainuilogic = GameModel.player.getMainUILogic(); if (mainuilogic && mainuilogic.isBattle) { MsgAlert.addMsg('戰鬥中無法放生寵物'); return; } GameModel.notice.addMsg(1, '是否放生召喚獸' + '\n' + this.petLogic.name + '(' + this.petLogic.relive + '轉' + this.petLogic.level + '級' + ')', () => { if (GameModel.player.safe_lock == 1) { let safe_notice = cc.instantiate(this.SafeNotice); safe_notice.parent = cc.find('Canvas'); safe_notice.getComponent('SafeNotice').setCallback(() => { GameModel.send('c2s_del_pet', { roleid: Report.roleId, petid: this.petLogic.petid }); }); } else { GameModel.send('c2s_del_pet', { roleid: Report.roleId, petid: this.petLogic.petid }); } }, () => { }, 0); }, propertyAddBtnClicked(e, d) { this.addPointPanel.active = true; this.propertyPanel.active = false; }, propertyBackBtnClicked(e, d) { this.addPointPanel.active = false; this.propertyPanel.active = true; }, propertyAddPoint(d) { if (this.petLogic.qianneng <= 0) { this.currentBtn = null; return; } var addNum = parseInt(this.addOrSubNumber) addNum = addNum > this.petLogic.qianneng ? this.petLogic.qianneng : addNum; this.petLogic.ppointT[d] += addNum; this.petLogic.ppoint[d] += addNum; this.petLogic.calculateProperty(); this.showPropertyInfo(); }, propertySubPoint(d) { if (this.petLogic.ppointT[d] <= 0) { this.currentBtn = null; return; } var addNum = parseInt(this.addOrSubNumber) addNum = addNum > this.petLogic.ppointT[d] ? this.petLogic.ppointT[d] : addNum; this.petLogic.ppointT[d] -= addNum; this.petLogic.ppoint[d] -= addNum; this.petLogic.calculateProperty(); this.showPropertyInfo(); }, porpertyReset(e, d) { console.log("aa") GameModel.send('c2s_update_pet', { roleid: Report.roleId, type: 0, petid: this.petLogic.petid, info: '{}' }); }, // 點擊加點確認 porpertySure(e, d) { console.log("bb") GameModel.send('c2s_update_pet', { roleid: Report.roleId, type: 2, petid: this.petLogic.petid, info: SKDataUtil.toJson(this.petLogic.ppointT) }); }, addExpBtnClicked(e, d) { if (this.useui) { this.useui.destroy(); this.useui = null; } this.useui = cc.instantiate(this.useItemUI); this.useui.parent = this.node; this.useui.getComponent('UseItemUI').loadList('點擊/長按可使用經驗丹', [10110, 10112, 10113, 10114], this.petLogic.petid, 1); }, //管制 onCtrlBtnClicked() { this.Horselist = this.propertyPanel.getChildByName('HorseList'); this.Horselist.active = true; this.content = this.propertyPanel.getChildByName('HorseList') .getChildByName('view').getChildByName('content'); cc.log(this.content); this.initialize(); }, //動態創建坐騎item initialize() { let ctr1 = this.propertyPanel.getChildByName('BtnCtrl'); let ctr2 = this.propertyPanel.getChildByName('BtnCtrl').getComponent(cc.Sprite).spriteFrame; cc.log(ctr1, ctr2); let player = GameModel.player; let roleId = player.roleid; let petId = this.petLogic.petid; cc.log(roleId, petId); let horselist = MyModel.shared.horseList.dict; let length = Object.keys(horselist).length; let self = this; for (let i = 1; i <= length; i++) { let pinfo = horselist[i]; cc.log(pinfo); cc.loader.loadRes('Prefabs/Chat/ChatPetItem', function (err, prefab) { let item = cc.instantiate(prefab); cc.log(item); self.content.addChild(item); item.setPosition(0, -item.height * i); item.getComponent('ChatPetItem').loadInfo(pinfo); item.on('click', itemClickCallBack, this); function itemClickCallBack() { SKSocket.send("c2s_pet_control", { roleid: roleId, petid: petId, control: i }); cc.log("我是" + pinfo.name + "我被管制了"); ctr2 = ItemUtil.getItemIcon(pinfo.resId); }; }); }; }, onQuXiaoCtrBtnClicked() { cc.log("我是取消管制按鈕---我被點擊了"); // this.reHorseList(); 待定 let player = GameModel.player; let roleId = player.roleid; SKSocket.send("c2s_pet_control", { roleid: roleId, petid: this.petLogic.petid, control: 0 }); }, onCloseBtn1Clicked() { this.content.removeAllChildren(); this.Horselist.active = false; }, addColorBtnClicked(e, d) { if (SKUIUtil.isValid(this.useui)) { this.useui.destroy(); this.useui = null; } let itemId = PetUtil.getColorItemId(this.petLogic.dataid); if (itemId == 0) { return; } this.useui = cc.instantiate(this.useItemUI); this.useui.parent = cc.find('Canvas'); this.useui.getComponent('UseItemUI').loadList('點擊/長按可使用元氣丹', [itemId], this.petLogic.petid, 1); }, resistanceAddPoint(d) { if (this.petLogic.xiulianleft - this.kangPointAdd <= 0) { this.currentBtn = null; return; } if (this.petLogic.dpoint[d] >= this.petLogic.getMaxAddPoint(d)) { this.currentBtn = null; return; } this.petLogic.dpointT[d]++; this.petLogic.dpoint[d]++; this.resistanceLevelNode.active = false; this.resistanceSureNode.active = true; this.kangPointAdd++; this.initKangBtn(); this.showDInfo(); }, resistanceSubPoint(d) { if (this.petLogic.dpointT[d] <= 0) { this.currentBtn = null; return; } this.petLogic.dpointT[d]--; this.petLogic.dpoint[d]--; this.resistanceLevelNode.active = false; this.resistanceSureNode.active = true; this.kangPointAdd--; this.initKangBtn(); this.showDInfo(); }, kangAddPoint(e, d) { }, kangSubPoint(e, d) { }, kangSureBtnClicked(e, d) { this.resistanceLevelNode.active = true; this.resistanceSureNode.active = false; console.log("cc",d) console.log( this.petLogic) if (d == 1) { let dpoint = this.petLogic.dpoint for (let k in dpoint) { let v = dpoint[k] if (v > 26){ cc.log("chaoguo 26 le ") return } } GameModel.send('c2s_update_pet', { roleid: Report.roleId, type: 3, petid: this.petLogic.petid, info: SKDataUtil.toJson(this.petLogic.dpointT) }); } else { this.kangPointAdd = 0; this.petLogic.initPoint(); this.initKangBtn(); } }, kangReset(e, d) { this.resistanceLevelNode.active = true; this.resistanceSureNode.active = false; console.log("dd") GameModel.send('c2s_update_pet', { roleid: Report.roleId, type: 1, petid: this.petLogic.petid, info: '{}' }); }, xiulianBtnClicked(e, d) { if (this.useui1) { this.useui1.destroy(); this.useui1 = null; } // if (this.petLogic.level >= GameModel.player.level + 10) { // return; // } this.useui1 = cc.instantiate(this.useItemUI); this.useui1.parent = this.node; this.useui1.getComponent('UseItemUI').loadList('點擊/長按可操作', [10116, 90001], this.petLogic.petid, 1); }, longguBtnClicked(e, d) { if (this.useui2) { this.useui2.destroy(); this.useui2 = null; } // if (this.petLogic.level >= GameModel.player.level + 10) { // return; // } this.useui2 = cc.instantiate(this.useItemUI); this.useui2.parent = this.node; this.useui2.getComponent('UseItemUI').loadList('點擊/長按可使用龍之骨', [10117], this.petLogic.petid, 1); }, panelToggleClicked(e, d) { if (this.petLogic.petinfo == null && d != 4) { return; } this.propertyNode.active = false; this.resistanceNode.active = false; this.skillNode.active = false; this.tujianNode.active = false; this.petContent.parent.parent.active = true; if (d == 1) { this.propertyNode.active = true; this.closeStudySkillPanel(); } else if (d == 2) { this.resistanceNode.active = true; this.closeStudySkillPanel(); } else if (d == 3) { this.skillNode.active = true; // this.closeStudySkillPanel(); } else if (d == 4) { this.closeStudySkillPanel(); this.petContent.parent.parent.active = false; this.tujianNode.active = true; } for (const item of this.titleNodes) { item.active = false; } this.titleNodes[d - 1].active = true; let petInfo = GameModel.player.petInfo; //寶寶支援 if (d == 4) { //如果點擊的是圖鑑面板 this.petSupport.active = false; } else { if (petInfo.list.length >= 2) { this.petSupport.active = true; } else { this.petSupport.active = false; } } //zfy --分頁音效 AudioUtil.playFenyeAudio(); }, petItemClicked(e, d) { if (this.currentSelected == d) { return; } //顯示隱藏換色按鈕 let petItem = e.target.getComponent('NPetItem').itemInfo; if (petItem) { for (let itemid in GameModel.player.itemList) { if (GameModel.player.itemList[itemid] > 0) { let itemInfo = ItemUtil.getItemData(itemid); if (itemInfo) { if (itemInfo.num == petItem.dataid) { this.propertyPanel.getChildByName('btnChangeColor').active = true; this.propertyPanel.getChildByName('btnChangeColor').getComponent(cc.Button).clickEvents[0].customEventData = itemid; break; } } else { cc.warn(`${itemid}找不到道具定義`); } } else { this.propertyPanel.getChildByName('btnChangeColor').active = false; } } } else { this.propertyPanel.getChildByName('btnChangeColor').active = false; } this.currentSelected = d; for (const item of this.itemNodes) { if (e.target == item) { item.getComponent('NPetItem').selected(); } else { item.getComponent('NPetItem').unSelected(); } } this.petLogic.setInfo(e.target.getComponent('NPetItem').itemInfo); this.showInfo(); if (this.petPropertyPanel.active == true) { this.refrushPetpropertyPanel(); } }, //寶寶轉生 reliveBtnClicked(e, d) { GameModel.send('c2s_relive_pet', { petid: this.petLogic.petid }); }, onCloseBtnClicked(e, d) { //zfy --關閉音效 AudioUtil.playCloseAudio(); this.node.destroy(); }, /* * 顯示天資界面 */ showPetpropertyPanel() { this.petPropertyPanel.active = true; this.addPointPanel.active = false; this.propertyPanel.active = false; this.refrushPetpropertyPanel(); }, /* * 刷新天資界面 */ refrushPetpropertyPanel() { let info = { zizhi: this.petLogic.aptitude, rate: this.petLogic.rate, cur_hp: this.petLogic.hp, cur_mp: this.petLogic.mp, cur_atk: this.petLogic.atk, cur_spd: this.petLogic.spd, max_rate: this.petLogic.maxRate }; for (let key in GameModel.conf_pet) { if (SKDataUtil.hasProperty(GameModel.conf_pet, key)) { let item = GameModel.conf_pet[key]; if (item.id == this.petLogic.dataid) { //info.max_rate = SKDataUtil.jsonBy(item.rate)[1]; info.max_hp = SKDataUtil.jsonBy(item.hp)[1]; info.max_mp = SKDataUtil.jsonBy(item.mp)[1]; info.max_atk = SKDataUtil.jsonBy(item.atk)[1]; info.max_spd = SKDataUtil.jsonBy(item.spd)[1]; } } } var aptits = ["資質平平", "出類拔萃", "妙領天機", "萬中無一"]; let zizhi_lable = this.petPropertyPanel.getChildByName('zizhiScore').getComponent(cc.RichText); zizhi_lable.string = aptits[info.zizhi] || this.aptits[0]; let hp_progress = this.petPropertyPanel.getChildByName('hpProgress'); let hp_label = hp_progress.getChildByName('label').getComponent(cc.Label); let hpProgress = (info.cur_hp == 0) ? 0 : (info.cur_hp / info.max_hp); hp_progress.getComponent(cc.ProgressBar).progress = hpProgress > 1 ? 1 : hpProgress; hp_label.string = info.cur_hp + '/' + info.max_hp; let mp_progress = this.petPropertyPanel.getChildByName('mpProgress'); let mp_label = mp_progress.getChildByName('label').getComponent(cc.Label); let mpProgress = (info.cur_mp == 0) ? 0 : (info.cur_mp / info.max_mp); mp_progress.getComponent(cc.ProgressBar).progress = mpProgress > 1 ? 1 : mpProgress; mp_label.string = info.cur_mp + '/' + info.max_mp; let att_progress = this.petPropertyPanel.getChildByName('attProgress'); let att_label = att_progress.getChildByName('label').getComponent(cc.Label); let atkProgress = (info.cur_atk == 0) ? 0 : (info.cur_atk / info.max_atk); att_progress.getComponent(cc.ProgressBar).progress = atkProgress > 1 ? 1 : atkProgress; att_label.string = info.cur_atk + '/' + info.max_atk; let spe_progress = this.petPropertyPanel.getChildByName('speProgress'); let spe_label = spe_progress.getChildByName('label').getComponent(cc.Label); let spdProgress = (info.cur_spd == 0) ? 0 : (info.cur_spd / info.max_spd); spe_progress.getComponent(cc.ProgressBar).progress = spdProgress > 1 ? 1 : spdProgress; spe_label.string = info.cur_spd + '/' + info.max_spd; let rate_label = this.petPropertyPanel.getChildByName('RateLabel').getComponent(cc.Label); //let currate = info.rate + this.petLogic.longgu * 0.01; rate_label.string = info.rate.toFixed(3) + '/' + info.max_rate.toFixed(3); for (let i = 1; i <= 5; ++i) { let sprite = this.petPropertyPanel.getChildByName('grow' + i).getComponent(cc.Sprite); let url = 'ui_common_loading_bar2'; if (i / 5 >= info.rate / info.max_rate * 0.99) url = 'ui_common_loading_bar_bg'; sprite.spriteFrame = this.commonUIAtlas.getSpriteFrame(url); } cc.find('longgu', this.petPropertyPanel).getComponent(cc.Label).string = `龍骨(${this.petLogic.longgu}/${this.petLogic.getMaxLongGu()})`; }, /* * 不顯示天資界面 */ unshowPetpropertyPanel() { this.petPropertyPanel.active = false; this.addPointPanel.active = false; this.propertyPanel.active = true; }, /* * 顯示洗練界面 */ showPetWashPropertyPanel() { let logic = this.washPropertyPanel.getComponent('WashProperty'); logic.close_callback = this.refrushPetpropertyPanel.bind(this); logic.show(this.petLogic); }, showSkillDetail(e, d) { if (d.openSkillGrid && d.index >= 0) { this.unLockSKillGrid(d.index + 1); return; } if (d == -2) return; let detail = cc.instantiate(this.SkillDetail); let detailLogic = detail.getComponent('SkillDetail'); detailLogic.loadInfo(d); detail.parent = cc.find('Canvas'); detailLogic.showOperation({ ['forget']: () => { let skill = SkillUtil.getSkill(d); GameModel.notice.addMsg(1, `${this.petLogic.name} 遺忘掉 ${skill.name} ?`, () => { GameModel.send('c2s_pet_forgetskill', { petid: this.petLogic.petid, skillid: d, }); detailLogic.nodeDestroy(); }); }, ['lock']: () => { let skill = SkillUtil.getSkill(d); let list = this.petLogic.petinfo.skill; let n = 0; for (const skillid in list) { if (SKDataUtil.hasProperty(list, skillid)) { const skillinfo = list[skillid]; if (skillinfo.lck == 1) { n++; } } } GameModel.notice.addMsg(1, `是否花費 ${Math.pow(2, n) * GameUtil.petSkLok}仙玉 來鎖定 ${skill.name} ?`, () => { GameModel.send('c2s_pet_lockskill', { petid: this.petLogic.petid, skillid: d, }); detailLogic.nodeDestroy(); }); } }, this.tujianNode); }, /** * 解鎖技能格子 */ unLockSKillGrid(idx) { var skillList = this.petLogic.petinfo.skill; if (!skillList) skillList = {}; var isShen = 0 for (let i in skillList) { if (skillList[i].idx == 0) isShen = 1; } var skillKeyList = Object.keys(skillList) var length = skillKeyList.length + 1 - isShen; FGAlert.show2("請選擇解封技能格的方式(需消耗[color=#DD96F9][聚魄丹][/color])", `消耗[color=#00A03C]${length * 4}[/color]個`, `消耗[color=#00A03C]${length * 2}[/color]個`, "必定開啟", "概率開啟", [10115], () => { GameModel.send("c2c_pet_skill_grid", { roleId: GameModel.player.roleid, petId: this.petLogic.petid, type: 2, index: idx }) } , () => { GameModel.send("c2c_pet_skill_grid", { roleId: GameModel.player.roleid, petId: this.petLogic.petid, type: 1, index: idx }) } ) }, openShenSkillPanel() { let petshenskill = cc.instantiate(this.PetShenSkillUI); petshenskill.name = 'PetShenSkill'; petshenskill.parent = this.node; let shenlogic = petshenskill.getComponent('PetShenSkill'); shenlogic.setPetId(this.petLogic.petid); shenlogic.init(); }, /* * 點擊親密按鈕 */ onQinmiBtnClick() { if (this.useui) { this.useui.destroy(); this.useui = null; } this.useui = cc.instantiate(this.useItemUI); this.useui.parent = this.node; // this.useui.getComponent('UseItemUI').loadList('點擊/長按可使用經驗丹', [10112, 10113, 10114], this.petLogic.petid, 1); this.useui.getComponent('UseItemUI').loadList('點擊/長按可使用親密丹', [10111, 10120], this.petLogic.petid, 1); }, //寶寶支援 onPetSupport() { if (!SKUIUtil.isFGUIValid(this.supportPanel)) { this.supportPanel = FGUtil.create("main_ui", "pet_support_panel"); FGUtil.root().addChild(this.supportPanel); this.supportPanel.makeFullScreen(); } var mask = FGUtil.getComponent(this.supportPanel, "mask"); var close = FGUtil.getButton(this.supportPanel, "alert/close"); this.pushCloseEvent(mask, this.supportPanel, () => { this.selectSupportIdx = -1; GameModel.petSupportTempData = [] }); this.pushCloseEvent(close, this.supportPanel, () => { this.selectSupportIdx = -1; GameModel.petSupportTempData = [] }); FGUtil.getControl(this.supportPanel, "alert/check/selected").selectedIndex = 1; FGUtil.getButton(this.supportPanel, "alert/check").onClick(this.changeSupportCheck, this); GameModel.petSupportTempData = []; // 設置物品列表初始化方法 var petList = FGUtil.getList(this.supportPanel, "alert/list"); petList.itemRenderer = this.initPetSupportPanelItem.bind(this); // 虛擬列表 petList.setVirtual(); GameModel.send("c2s_support_list", { roleid: GameModel.player.roleid }) }, initPetSupportPanelItem(idx, obj) { var item = obj.asCom; var info = GameModel.petSupportTempData[idx]; FGUtil.getTextField(item, "id").text = info.sorder; FGUtil.getTextField(item, "name").text = info.petname; FGUtil.getLoader(item, "icon").url = `ui://main_ui/${info.resid}`; if (this.selectSupportIdx != -1 && this.selectSupportIdx != idx) { FGUtil.getControl(item, "showMask").selectedIndex = 1; } else FGUtil.getControl(item, "showMask").selectedIndex = 0; item.node["idx"] = idx; item.onClick(this.swithPetIdx, this); FGUtil.getComponent(item, "mask").node["idx"] = idx; FGUtil.getComponent(item, "mask").onClick(this.swithPetIdxEnd, this); }, swithPetIdx(e) { if (!SKDataUtil.hasProperty(e.target, "idx")) return; var idx = e.target.idx; this.selectSupportIdx = idx; FGUtil.getList(this.supportPanel, "alert/list").refreshVirtualList(); }, swithPetIdxEnd(e) { e.stopPropagation() if (!SKDataUtil.hasProperty(e.target, "idx")) return; var idx = e.target.idx; if (this.selectSupportIdx == -1 || idx < 0) { FGUtil.getList(this.supportPanel, "alert/list").refreshVirtualList(); return } GameModel.send("c2s_support_order", { roleid: GameModel.player.roleid, petid1: GameModel.petSupportTempData[this.selectSupportIdx].petid, petid2: GameModel.petSupportTempData[idx].petid }) this.selectSupportIdx = -1; FGUtil.getList(this.supportPanel, "alert/list").refreshVirtualList(); }, changeSupportCheck() { var state = FGUtil.getControl(this.supportPanel, "alert/check/selected").selectedIndex FGUtil.getControl(this.supportPanel, "alert/check/selected").selectedIndex = state ? 0 : 1; }, /** * 添加關閉事件 */ pushCloseEvent(item, target, call = null) { if (!item) { console.error("未找到節點"); return; } item.clearClick(); item.onClick(() => { call && call() FGUtil.dispose(target); target = null; }, this) }, loadPetSupportList() { if (!SKUIUtil.isFGUIValid(this.supportPanel)) return if (FGUtil.getList(this.supportPanel, "alert/list").numItems != GameModel.petSupportTempData.length) FGUtil.getList(this.supportPanel, "alert/list").numItems = GameModel.petSupportTempData.length; else FGUtil.getList(this.supportPanel, "alert/list").refreshVirtualList(); }, // 打開學習技能面板 openStudySkillPanel() { console.log("打開學習技能面板") this.skillNode.getChildByName("studyButton").active = false; this.skillNode.getChildByName("backBtn").active = true; this.node.getChildByName("ScrollView").active = false; this.petSupport.active = false; var booksList = this.getBagPetSkillBooks(); if (booksList.length > 0) { this.showPetSkillBooks(booksList); } else { // 沒有技能書 this.skillNode.getChildByName("noSkillBook").active = true; } }, // 獲取背包裡所有寵物技能書 getBagPetSkillBooks() { var booksList = []; for (let itemid in GameModel.player.itemList) { let itemInfo = ItemUtil.getItemData(itemid) if (itemInfo && itemInfo.type == 10) { itemInfo = SKDataUtil.clone(itemInfo); itemInfo.count = GameModel.player.itemList[itemid] if (itemInfo.count > 0) booksList.push(itemInfo); } } return booksList; }, showPetSkillBooks(listData) { var skillListContent = cc.find("bookScroll/view/bookList", this.skillNode); skillListContent.removeAllChildren() this.petSkillBookNodeList = []; for (let i in listData) { let item = cc.instantiate(this.petSKillBookItem); skillListContent.addChild(item) this.petSkillBookNodeList.push(item) let btn = item.getChildByName("itemBtn").getComponent(cc.Button); var clickEventHandler = new cc.Component.EventHandler(); clickEventHandler.target = this.node; clickEventHandler.component = "PetPanel"; clickEventHandler.handler = "showSkillBookInfo"; clickEventHandler.customEventData = i; btn.clickEvents.push(clickEventHandler); cc.find("itemBtn/icon", item).getComponent(cc.Sprite).spriteFrame = ItemUtil.getItemIcon(listData[i].icon); cc.find("itemBtn/title", item).getComponent(cc.Label).string = listData[i].name; cc.find("itemBtn/num", item).getComponent(cc.Label).string = listData[i].count; cc.find("desbg/des", item).getComponent(cc.Label).string = listData[i].description; cc.find("desbg/studyBtn", item).on("click", () => { this.showStudySkillAlert(listData[i].id, listData[i].name) }, this) } skillListContent.height = listData.length * 65 + 90; skillListContent.children[0].height = 155; this.skillNode.getChildByName("bookScroll").active = true; }, showStudySkillAlert(skillId, name) { // 沒有技能格子 var isShen = 0; for (let i in this.petLogic.petinfo.skill) { if (this.petLogic.petinfo.skill[i].idx == 0) isShen = 1; } var skillGridNum = Object.keys(this.petLogic.petinfo.skill).length if (skillGridNum == isShen) { MsgAlert.addMsg("請先開啟寵物技能格"); return; } var emptyGrid = 0; for (let i in this.petLogic.petinfo.skill) { if (this.petLogic.petinfo.skill[i].skillid < 1000) emptyGrid++ } // 存在空的技能格子 if (emptyGrid > 0) { GameModel.send("c2s_use_bagitem", { count: 1, itemid: skillId, operateid: this.petLogic.petid, roleid: GameModel.player.roleid }) return; } // 技能格已學滿 FGAlert.show(`本次學習技能:\n1.有概率[color=#FF7A7A]頂替[/color]其它原有技能\n確定學習[color=#0FA546][${name}][/color]麼?`, () => { FGAlert.hide(); }, () => { GameModel.send("c2s_use_bagitem", { count: 1, itemid: skillId, operateid: this.petLogic.petid, roleid: GameModel.player.roleid }) FGAlert.hide(); }) }, showSkillBookInfo(e, d) { for (let i in this.petSkillBookNodeList) { if (i == d) { this.petSkillBookNodeList[i].height = 155; } else { this.petSkillBookNodeList[i].height = 60; } } }, // 關閉學習技能面板 closeStudySkillPanel() { this.skillNode.getChildByName("studyButton").active = true; this.skillNode.getChildByName("backBtn").active = false; this.skillNode.getChildByName("noSkillBook").active = false; this.skillNode.getChildByName("bookScroll").active = false; this.node.getChildByName("ScrollView").active = true; this.petSupport.active = true; }, normalWash() { let logic = this.washPropertyPanel.getComponent('WashProperty'); logic.washLevel = 1 logic.close_callback = this.refrushPetpropertyPanel.bind(this); logic.show(this.petLogic); }, highWash() { let logic = this.washPropertyPanel.getComponent('WashProperty'); logic.washLevel = 2 logic.close_callback = this.refrushPetpropertyPanel.bind(this); logic.show(this.petLogic); } });