import GameModel from "../ts/core/GameModel"; import GameUtil from "../ts/core/GameUtil"; import ItemUtil from "../ts/core/ItemUtil"; import SKDataUtil from "../ts/gear_2.3.4/util/SKDataUtil"; import SKUIUtil from "../ts/gear_2.3.4/util/SKUIUtil"; let GameRes = require('./GameRes'); let pScreenNoticeMgr = require('./ScreenNotice'); class CPubFunction { constructor() { this.vecScreenCutDown = []; this.noticeNum = 0; this.vecRoleBroadCast = []; this.nTimeIndex = 0; this.btntimer = { timer: null, times: 0, }; this.vecExpLevel = [0, 100, 500, 1000, 5000, 10000, 50000, 100000, 500000, 1000000, 5000000, 10000000, 50000000, 100000000]; //zzzErr this.mapAttribute = {}; this.mapAttribute['AdSpdEhan'] = { Name: '加強加速', Kind: '物理屬性' }; this.mapAttribute['CharmEhan'] = { Name: '加強魅惑', Kind: '法術增強' }; this.mapAttribute['AdAtkEhan'] = { Name: '加強加功', Kind: '物理屬性' }; this.mapAttribute['AdDefEhan'] = { Name: '加強防禦', Kind: '物理屬性' }; this.mapAttribute['RecoverEhan'] = { Name: '加強遺忘', Kind: '法術增強' }; this.mapAttribute['DisorderDef'] = { Name: '抗混亂', Kind: '法術抗性' }; this.mapAttribute['DisorderDefNeg'] = { Name: '忽視抗混', Kind: '法術增強' }; this.mapAttribute['DisorderEhan'] = { Name: '加強混亂', Kind: '法術增強' }; this.mapAttribute['Atk'] = { Name: '攻擊', Kind: '物理屬性' }; this.mapAttribute['Speed'] = { Name: '速度', Kind: '物理屬性' }; this.mapAttribute['HitCombo'] = { Name: '連擊次數', Kind: '物理屬性' }; this.mapAttribute['HitComboRate'] = { Name: '連擊率', Kind: '物理屬性' }; this.mapAttribute['HitRate'] = { Name: '命中率', Kind: '物理屬性' }; this.mapAttribute['FatalRate'] = { Name: '狂暴率', Kind: '物理屬性' }; this.mapAttribute['PhyDef'] = { Name: '物理吸收', Kind: '物理屬性' }; this.mapAttribute['PhyDefNef'] = { Name: '破防程度', Kind: '物理屬性' }; this.mapAttribute['PhyDefNefRate'] = { Name: '破防概率', Kind: '物理屬性' }; this.mapAttribute['VoidRate'] = { Name: '閃避率', Kind: '物理屬性' }; this.mapAttribute['HpMax'] = { Name: '氣血', Kind: '物理屬性' }; this.mapAttribute['FireDef'] = { Name: '抗火', Kind: '法術抗性' }; this.mapAttribute['ForgetDef'] = { Name: '抗遺忘', Kind: '法術抗性' }; this.mapAttribute['GfireDef'] = { Name: '抗鬼火', Kind: '法術抗性' }; this.mapAttribute['GfireDefNeg'] = { Name: '忽視抗鬼火', Kind: '法術增強' }; this.mapAttribute['GfireRageOdds'] = { Name: '鬼火狂暴率', Kind: '法術增強' }; this.mapAttribute['PoisonDef'] = { Name: '抗毒', Kind: '法術抗性' }; this.mapAttribute['RainDef'] = { Name: '抗水', Kind: '法術抗性' }; this.mapAttribute['RainDefNeg'] = { Name: '忽視抗水', Kind: '法術增強' }; this.mapAttribute['RainEhan'] = { Name: '加強水系', Kind: '法術增強' }; this.mapAttribute['RainRageOdds'] = { Name: '水系狂暴率', Kind: '法術增強' }; this.mapAttribute['SanshiDef'] = { Name: '抗三尸', Kind: '法術抗性' }; this.mapAttribute['SanshiDefNeg'] = { Name: '忽視抗三尸', Kind: '法術增強' }; this.mapAttribute['ShanshiRageOdds'] = { Name: '三尸狂暴率', Kind: '法術增強' }; this.mapAttribute['SealDef'] = { Name: '抗封印', Kind: '法術抗性' }; this.mapAttribute['ShockDef'] = { Name: '抗震', Kind: '法術抗性' }; this.mapAttribute['ShockDefNeg'] = { Name: '忽視抗震懾', Kind: '法術增強' }; this.mapAttribute['ShockEhan'] = { Name: '加強震懾', Kind: '法術增強' }; this.mapAttribute['SleepDef'] = { Name: '抗昏睡', Kind: '法術抗性' }; this.mapAttribute['ThunderDef'] = { Name: '抗雷', Kind: '法術抗性' }; this.mapAttribute['ThunderRageOdds'] = { Name: '雷系狂暴率', Kind: '法術增強' }; this.mapAttribute['WindDef'] = { Name: '抗風', Kind: '法術抗性' }; this.mapAttribute['WindDefNeg'] = { Name: '忽視抗風', Kind: '法術增強' }; this.mapAttribute['WindEhan'] = { Name: '加強風系', Kind: '法術增強' }; this.mapAttribute['WindRageOdds'] = { Name: '風系狂暴率', Kind: '法術增強' }; this.mapAttribute['AtkPercent'] = { Name: '攻擊改變', Kind: '物理屬性' }; //---------------------------------- } // ResetTimer(nValue) { // let pSelf = this; // clearInterval(this.m_timer); // this.m_timer = setInterval(function () { // pSelf.OnTimer(); // }, nValue); // } // OnTimer() { //50 毫秒一次 // this.nTimeIndex += 1; // if (this.nTimeIndex % 20 == 0) // 降頻為 1 秒一次 // { // // this.CheckAndDeleteNotice(); // //this.CheckAndDeleteRoleBroadCast(); // } // // if (pScreenNoticeMgr) { // // pScreenNoticeMgr.OnUpdate(this.nTimeIndex); // // } // } runAnimation(runNode) { runNode.active = false; let url = 'ccbtex/panel/2251' cc.loader.loadRes(url, cc.SpriteAtlas, function (error, atlas) { if (error) { cc.warn(`$警告:加載動畫資源錯誤:${url}`); return; } if (!SKUIUtil.isValid(runNode)) { return; } if (!atlas) { return; } let curFrames = atlas.getSpriteFrames(); let curClip = cc.AnimationClip.createWithSpriteFrames(curFrames, 8); curClip.name = 'run'; curClip.wrapMode = cc.WrapMode.Loop; let nodeAni = runNode.getComponent(cc.Animation); nodeAni.addClip(curClip); nodeAni.play(curClip.name); runNode.active = true; }); } BtnAnimation(btnNode1,btnNode2) { btnNode1.active = false; btnNode2.active = false; let url = 'ccbtex/panel/2249' cc.loader.loadRes(url, cc.SpriteAtlas, function (error, atlas) { if (error) { cc.warn(`$警告:加載動畫資源錯誤:${url}`); return; } if (!SKUIUtil.isValid(btnNode1)) { return; } if (!atlas) { return; } let curFrames = atlas.getSpriteFrames(); let curClip = cc.AnimationClip.createWithSpriteFrames(curFrames, 12); curClip.name = 'run'; curClip.wrapMode = cc.WrapMode.Normal; let nodeAni = btnNode1.getComponent(cc.Animation); nodeAni.addClip(curClip); nodeAni.play(curClip.name); btnNode1.active = true; }); let url1 = 'ccbtex/panel/2250' cc.loader.loadRes(url1, cc.SpriteAtlas, function (error, atlas) { if (error) { cc.warn(`$警告:加載動畫資源錯誤:${url1}`); return; } if (!SKUIUtil.isValid(btnNode2)) { return; } if (!atlas) { return; } let curFrames = atlas.getSpriteFrames(); let curClip = cc.AnimationClip.createWithSpriteFrames(curFrames, 12); curClip.name = 'run'; curClip.wrapMode = cc.WrapMode.Normal; let nodeAni = btnNode2.getComponent(cc.Animation); nodeAni.addClip(curClip); nodeAni.play(curClip.name); btnNode2.active = true; }); } CreateScreenNotice(strRichText, bInstertFront) { pScreenNoticeMgr.AddNotice(strRichText, bInstertFront); } // CheckAndDeleteRoleBroadCast() { // let nCurTime = this.GetTime(); // for (let nIndex in this.vecRoleBroadCast) { // if (nCurTime >= this.vecRoleBroadCast[nIndex].nCreateTime + this.vecRoleBroadCast[nIndex].nLiveTime) { // let goTmp = this.vecRoleBroadCast[nIndex]; // goTmp.goRoleBroadCast.destroy(); // this.vecRoleBroadCast.splice(nIndex, 1); // } // } // } CreateNpcNotice(nNpcConfigID, strText) { let pNpcMgr = require('../game/NpcMgr'); let CSpeak = require('../game/Speak'); let pConfigInfo = pNpcMgr.GetNpcConfigInfo(nNpcConfigID); if (null == pConfigInfo) return; let stSpeak = new CSpeak(pConfigInfo.nResID, strText, pConfigInfo.strName, 2); this.CreateNpcTalk([stSpeak], null); } GetLevel(nExp) { let nLen = this.vecExpLevel.length; for (let nIndex = nLen - 1; nIndex >= 0; nIndex--) { if (nExp >= this.vecExpLevel[nIndex]) { let nCur = 0; let nMax = 0; if (nIndex == nLen - 1) { nCur = this.vecExpLevel[nIndex]; nMax = this.vecExpLevel[nIndex]; } else { nCur = nExp - this.vecExpLevel[nIndex]; nMax = this.vecExpLevel[nIndex + 1]; } return { nLevel: nIndex + 1, nMax: nMax, nCur: nCur }; } } return {}; } CreateSubNode(vParent, stPos, strPrefab, strName) { let goItem = cc.instantiate(strPrefab); goItem.parent = vParent; goItem.name = strName; goItem.setPosition(cc.v2(stPos.nX, stPos.nY)); return goItem; } CreateSubNodeByType(vParent, stPos, strPrefab, strName, type) { let goItem = cc.instantiate(strPrefab); goItem.parent = vParent; goItem.name = strName; goItem.opType = type; goItem.setPosition(cc.v2(stPos.nX, stPos.nY)); return goItem; } isNumString(str) { var regPos = /^\d+$/; //非負浮點數 if (regPos.test(str)) { return true; } else { return false; } } getWeaponName(equip) { // console.log(equip) let weaponname = ''; if (equip.type == 0) { weaponname = '0000'; } //新手裝備 if (equip.type == 1) { //高級裝備 weaponname = '0100'; if (equip.level == 100 && equip.gemcnt >= 10) { //100級打滿寶石 weaponname = '0101'; } else if (equip.level == 120) { //120級 weaponname = '0200'; if (equip.gemcnt >= 12) { //打滿寶石 weaponname = '0202'; } } } else if (equip.type == 2) { weaponname = '0300'; if (equip.gemcnt >= 13) { weaponname = '0302'; } else if (equip.gemcnt >= 10) { weaponname = '0301'; } } else if (equip.type == 3) { weaponname = '0400'; if (equip.level == 5) weaponname = "0601" else if (equip.gemcnt >= 16) { weaponname = '0501'; } else if (equip.gemcnt >= 13) { weaponname = '0403'; } else if (equip.gemcnt >= 10) { weaponname = '0401'; } } return weaponname; } addWeaponAnimation(weaponInfo, weaponNode, animationNode, logic, resid, act, dir, show = false) { if (animationNode.name.length < 1) { cc.log("?"); } if (!animationNode || !weaponNode || GameUtil.roleName[resid] == null || animationNode.active == false) { return; } let clips = weaponNode.getComponent(cc.Animation).getClips(); for (const clip of clips) { if (clip.name == act) { weaponNode.getComponent(cc.Animation).stop(act); weaponNode.getComponent(cc.Animation).removeClip(clip, true); } } weaponNode.active = false; let weaponname = '0000'; if (weaponInfo.length > 0) { weaponname = this.getWeaponName(JSON.parse(weaponInfo)); } let url = `weapon/${resid}/${weaponname}_${act}_${dir}_wp`; if (resid == 1111 && weaponname != '0601') { url = `weapon/${resid}/${weaponname}_${act}_${dir}_wp_l`; } cc.loader.loadRes(url, cc.SpriteAtlas, function (error, atlas) { if(error){ cc.error(error); return; } if (!animationNode || !animationNode.parent || animationNode.parent.parent == null) return; if (Array.isArray(atlas)) { return; } if (GameModel.player.tResid != 0 && !show) return; let curFrames = []; for (let i = 1; ; i++) { let frame = atlas.getSpriteFrame(i); if (frame) curFrames.push(frame); else break; } if (curFrames.length == 0) curFrames = atlas.getSpriteFrames() let curClip = cc.AnimationClip.createWithSpriteFrames(curFrames, 15); curClip.name = act; if (act == 'stand' || act == 'run') { curClip.wrapMode = cc.WrapMode.Loop; } else { curClip.wrapMode = cc.WrapMode.Normal; } let nodeAni = weaponNode.getComponent(cc.Animation); nodeAni.addClip(curClip); nodeAni.play(act); logic.scheduleOnce(() => { if (SKUIUtil.isValid(animationNode)) { weaponNode.scaleX = animationNode.width / weaponNode.width; weaponNode.scaleY = animationNode.height / weaponNode.height; } }, 0); weaponNode.active = true; if (GameModel.conf_res_anchor[resid]) { weaponNode.anchorY = GameModel.conf_res_anchor[resid].anchorY; } }); if (!animationNode.getChildByName('addon')) { let addon = new cc.Node(); addon.parent = animationNode; addon.addComponent(cc.Animation); let addonsp = addon.addComponent(cc.Sprite); addonsp.trim = false; addonsp.sizeMode = cc.Sprite.SizeMode.RAW; addon.name = 'addon'; } let addonNode = animationNode.getChildByName('addon'); let addonclips = addonNode.getComponent(cc.Animation).getClips(); for (const clip of addonclips) { if (clip.name == act) { addonNode.getComponent(cc.Animation).stop(act); addonNode.getComponent(cc.Animation).removeClip(clip, true); } } addonNode.active = false; //let addonname = weaponname.substr(0, 3) + '0'; let urls = `weapon/${resid}/${weaponname}_${act}_${dir}_wp_addon`; if (resid == 1111 && weaponname != '0601') { urls = `weapon/${resid}/${weaponname}_${act}_${dir}_wp_r`; } if (resid == 3006 && weaponname != '0601') { urls = `weapon/${resid}/${weaponname}_${act}_${dir}_addon`; } cc.loader.loadRes(urls, cc.SpriteAtlas, function (err, atlas) { if (!animationNode || !animationNode.parent || !animationNode.parent.parent == null) return; if (Array.isArray(atlas)) { return; } let addonani = addonNode.getComponent(cc.Animation); let addonsp = addonNode.getComponent(cc.Sprite); addonsp.spriteFrame = atlas.getSpriteFrame(0); let addonFrames = []; for (let i = 1; ; i++) { let frame = atlas.getSpriteFrame(i); if (frame) addonFrames.push(frame); else break; } if (addonFrames.length == 0) addonFrames = atlas.getSpriteFrames() let curClip = cc.AnimationClip.createWithSpriteFrames(addonFrames, 15); curClip.name = act; if (act == 'stand' || act == 'run') { curClip.wrapMode = cc.WrapMode.Loop; } else { curClip.wrapMode = cc.WrapMode.Normal; } addonani.addClip(curClip); addonani.play(act); logic.scheduleOnce(() => { if (SKUIUtil.isValid(addonNode) && SKUIUtil.isValid(animationNode)) { addonNode.scaleX = animationNode.width / addonNode.width; addonNode.scaleY = animationNode.height / addonNode.height; } }, 0); if (GameModel.conf_res_anchor[resid]) { addonNode.anchorY = GameModel.conf_res_anchor[resid].anchorY; } else addonNode.anchorY = 0.4 addonNode.active = true; }); } CreateRole(nOnlyID, nResID, strName, nHP, nMP, stPos, vParent) { let preRole = GameModel.role; let goRole = this.CreateSubNode(vParent, stPos, preRole, 'BattleSoldier'); cc.find('name', goRole).getComponent(cc.Label).string = strName; let comRole = goRole.getComponent('role'); comRole.onlyid = nOnlyID; comRole.resid = nResID; comRole.hp = nHP; comRole.animationNode.anchorY = 0; if (SKDataUtil.hasProperty(GameModel.conf_res_anchor, nResID)) { comRole.animationNode.anchorY = GameModel.conf_res_anchor[nResID].anchorY; } comRole.resAtlas = GameRes.getRoleRes(nResID); comRole.initAnimation(); return goRole; } CreateNpc(nOnlyID, nResID, strName, nHP, nMP, stPos, vParent) { let preRole = GameModel.npc; let goRole = this.CreateSubNode(vParent, stPos, preRole, 'BattleSoldier'); cc.find('name', goRole).getComponent(cc.Label).string = strName; let comRole = goRole.getComponent('Npc'); if (SKDataUtil.hasProperty(GameModel.conf_res_anchor, nResID)) { comRole.animationNode.anchorY = GameModel.conf_res_anchor[nResID].anchorY; } return goRole; } GetMapSum(mapTmp) { let nNum = 0; for (const it in mapTmp) { nNum += mapTmp[it]; } return nNum; } GetMapLen(mapTmp) { let nCnt = 0; for (let key in mapTmp) { key; nCnt++; } return nCnt; } CreateEventHandler(goNode, comName, strFunction, varParam) { let varHandler = new cc.Component.EventHandler(); varHandler.target = goNode; varHandler.component = comName; varHandler.handler = strFunction; varHandler.customEventData = varParam; return varHandler; } FindAndDeleteNode(nodParent, strName) { let nodTmp = nodParent.getChildByName(strName); if (nodTmp != null) nodTmp.destroy(); } FindAndHidenNode(nodParent, stPos) { let nodTmp = nodParent.getChildByName("TalkUI"); if (nodTmp == null) { nodTmp = this.CreateSubNode(nodParent, { nX: 0, nY: 0 }, GameModel.talkUI, "TalkUI"); } nodTmp.setPosition(cc.v2(stPos.nX, stPos.nY)); nodTmp.zIndex = 1; return nodTmp; } NumToString(nNum, nLen) { return (Array(nLen).join(0) + nNum).slice(-nLen); } CreateSubFrame(vParent, stPos, strPrefab, strClipName, callback) { let goEffectFrame = this.CreateSubNode(vParent, { nX: stPos.nX, nY: stPos.nY }, strPrefab, ''); SKUIUtil.loadAtlasAni("effect", strClipName, (clip) => { if (!SKUIUtil.isValid(goEffectFrame)) { cc.warn(`$警告:創建幀動畫節點無效${strClipName}`); } else { clip.name = strClipName; clip.wrapMode = cc.WrapMode.Normal; //循環播放 ? let effect = goEffectFrame.getComponent('Effect'); effect.CreateAndPlayAnimation(clip, callback); } }); } CreateSubFrame1(vParent, stPos, strPrefab, strClipName, callback) { let goEffectFrame = this.CreateSubNode(vParent, { nX: stPos.nX, nY: stPos.nY }, strPrefab, ''); SKUIUtil.loadAtlasAni("buff", strClipName, (clip) => { if (!SKUIUtil.isValid(goEffectFrame)) { cc.warn(`$警告:創建幀動畫節點無效${strClipName}`); } else { clip.name = strClipName; clip.wrapMode = cc.WrapMode.Normal; //循環播放 ? let effect = goEffectFrame.getComponent('Effect'); effect.CreateAndPlayAnimation(clip, callback); } }); } CreateSubFrameBoom(vParent, stPos, strPrefab, strClipName, callback) { let goEffectFrame = this.CreateSubNode(vParent, { nX: stPos.nX, nY: stPos.nY }, strPrefab, ''); SKUIUtil.loadAtlasAni("buff", strClipName, (clip) => { if (!SKUIUtil.isValid(goEffectFrame)) { cc.warn(`$警告:創建幀動畫節點無效${strClipName}`); } else { clip.name = strClipName; clip.wrapMode = cc.WrapMode.Normal; //循環播放 ? let effect = goEffectFrame.getComponent('Effect'); effect.CreateAndPlayAnimation(clip, callback); } }); } CreateSubFrameLoop(vParent, stPos, strPrefab, strClipName) { let goEffectFrame = this.CreateSubNode(vParent, { nX: stPos.nX, nY: stPos.nY }, strPrefab, ''); SKUIUtil.loadAtlasAni("effect", strClipName, (clip) => { if (!SKUIUtil.isValid(goEffectFrame)) { cc.warn(`$警告:創建幀循環節點無效${strClipName}`); } else { clip.name = strClipName; clip.wrapMode = cc.WrapMode.Loop; //循環播放 ? let effect = goEffectFrame.getComponent('Effect'); effect.CreateAndPlayAnimation(clip); } }); return goEffectFrame; } CreateNpcTalk(vecSpeak, pCallBack) { if (vecSpeak.length <= 0) { if (pCallBack) pCallBack(); return; } let goTalkUI = this.FindAndHidenNode(cc.find('Canvas/MainUI'), { nX: 0, nY: -188 }); goTalkUI.getComponent('Talk').Init(vecSpeak, pCallBack); } //spine骨骼動畫 SetSpineAvatar(nodSpine, nodAvatar, nResID, nodDragonBone) { nodSpine.active = false; nodDragonBone.active = false; if (nodAvatar) nodAvatar.active = false; cc.loader.loadResDir(`spineres/${nResID}`, function (err, assets){ if (err != null || nodSpine.isValid == false) return; if (assets.length > 0) { nodSpine.active = true; let spineRes = {}; for (let i = 0; i < assets.length; i++) { if (assets[i] instanceof sp.SkeletonData) { spineRes.spineAsset = assets[i]; } } //展現 let t = nodSpine.getComponent(sp.Skeleton); let oldAnimationName = null; if(t){ oldAnimationName = t.animation; } if(nResID == 6140 || nResID == 6141 || nResID == 6142 ){ oldAnimationName = "idle"; } nodSpine.removeComponent(sp.Skeleton); let comArmatureDisplay = nodSpine.addComponent(sp.Skeleton); comArmatureDisplay.skeletonData = null; comArmatureDisplay.skeletonData = spineRes.spineAsset; //comArmatureDisplay.setSkin = 'default'; if(oldAnimationName){ comArmatureDisplay.setAnimation(0, oldAnimationName, true); } } else { if (nodAvatar == null) return; cc.loader.loadResDir(`ui/photo/${nResID}`, cc.SpriteFrame, (e, frame) => { nodAvatar.active = true; nodAvatar.getComponent(cc.Sprite).spriteFrame = frame[0]; }) } }); } //龍骨動畫 SetDragonBoneAvatar(nodDragonBone, nodAvatar, nResID, nodSpine) { nodDragonBone.active = false; nodSpine.active = false; if (nodAvatar) nodAvatar.active = false; cc.loader.loadResDir(`dragonbone/${nResID}`, function (err, assets){ if (err != null || nodDragonBone.isValid == false) return; if (assets.length > 0) { nodDragonBone.active = true; let dragonRes = {}; for (let i = 0; i < assets.length; i++) { if (assets[i] instanceof dragonBones.DragonBonesAsset) { dragonRes.dragonAsset = assets[i]; } if (assets[i] instanceof dragonBones.DragonBonesAtlasAsset) { dragonRes.dragonAtlasAsset = assets[i]; } } //展現 let t = nodDragonBone.getComponent(dragonBones.ArmatureDisplay); let oldAnimationName = null; if(t){ oldAnimationName = t.animationName; } nodDragonBone.removeComponent(dragonBones.ArmatureDisplay); let comArmatureDisplay = nodDragonBone.addComponent(dragonBones.ArmatureDisplay); // cc.sys.isNative && comArmatureDisplay._factory.clear(false); //在手機上加載相同的資源會出現閃退 comArmatureDisplay.dragonAsset = null; comArmatureDisplay.dragonAtlasAsset = null; comArmatureDisplay.dragonAsset = dragonRes.dragonAsset; comArmatureDisplay.dragonAtlasAsset = dragonRes.dragonAtlasAsset; comArmatureDisplay.armatureName = 'armatureName'; if(oldAnimationName){ comArmatureDisplay.playAnimation(oldAnimationName, 0); } } else { if (nodAvatar == null) return; cc.loader.loadResDir(`ui/photo/${nResID}`, cc.SpriteFrame, (e, frame) => { nodAvatar.active = true; nodAvatar.getComponent(cc.Sprite).spriteFrame = frame[0]; }) } }); } //spine骨骼動畫(扩展一个) SetSpineAvatars(nodSpine, nodAvatar, nResID) { nodSpine.active = false; if (nodAvatar) nodAvatar.active = false; cc.loader.loadResDir(`spineres/${nResID}`, function (err, assets){ if (err != null || nodSpine.isValid == false) return; if (assets.length > 0) { nodSpine.active = true; let spineRes = {}; for (let i = 0; i < assets.length; i++) { if (assets[i] instanceof sp.SkeletonData) { spineRes.spineAsset = assets[i]; } } //console.log('dragonRes.dragonAsset9999999', dragonRes.dragonAsset); //展現 let t = nodSpine.getComponent(sp.Skeleton); let oldAnimationName = null; if(t){ oldAnimationName = t.animation; } nodSpine.removeComponent(sp.Skeleton); let comArmatureDisplay = nodSpine.addComponent(sp.Skeleton); // cc.sys.isNative && comArmatureDisplay._factory.clear(false); //在手機上加載相同的資源會出現閃退 comArmatureDisplay.skeletonData = null; comArmatureDisplay.skeletonData = spineRes.spineAsset; //comArmatureDisplay.setSkin = 'default'; if(oldAnimationName){ comArmatureDisplay.setAnimation(0, oldAnimationName, true); } } else { if (nodAvatar == null) return; cc.loader.loadResDir(`ui/photo/${nResID}`, cc.SpriteFrame, (e, frame) => { nodAvatar.active = true; nodAvatar.getComponent(cc.Sprite).spriteFrame = frame[0]; }) } }); } //龍骨動畫(扩展一个) SetDragonBoneAvatars(nodDragonBone, nodAvatar, nResID) { nodDragonBone.active = false; if (nodAvatar) nodAvatar.active = false; cc.loader.loadResDir(`dragonbone/${nResID}`, function (err, assets){ if (err != null || nodDragonBone.isValid == false) return; if (assets.length > 0) { nodDragonBone.active = true; let dragonRes = {}; for (let i = 0; i < assets.length; i++) { if (assets[i] instanceof dragonBones.DragonBonesAsset) { dragonRes.dragonAsset = assets[i]; } if (assets[i] instanceof dragonBones.DragonBonesAtlasAsset) { dragonRes.dragonAtlasAsset = assets[i]; } } //展現 let t = nodDragonBone.getComponent(dragonBones.ArmatureDisplay); let oldAnimationName = null; if(t){ oldAnimationName = t.animationName; } nodDragonBone.removeComponent(dragonBones.ArmatureDisplay); let comArmatureDisplay = nodDragonBone.addComponent(dragonBones.ArmatureDisplay); // cc.sys.isNative && comArmatureDisplay._factory.clear(false); //在手機上加載相同的資源會出現閃退 comArmatureDisplay.dragonAsset = null; comArmatureDisplay.dragonAtlasAsset = null; comArmatureDisplay.dragonAsset = dragonRes.dragonAsset; comArmatureDisplay.dragonAtlasAsset = dragonRes.dragonAtlasAsset; comArmatureDisplay.armatureName = 'armatureName'; if(oldAnimationName){ comArmatureDisplay.playAnimation(oldAnimationName, 0); } } else { if (nodAvatar == null) return; cc.loader.loadResDir(`ui/photo/${nResID}`, cc.SpriteFrame, (e, frame) => { nodAvatar.active = true; nodAvatar.getComponent(cc.Sprite).spriteFrame = frame[0]; }) } }); } GetRaceFileName(nRace) { if (nRace == 1) return 'ui_common_icon_race1'; if (nRace == 2) return 'ui_common_icon_race3'; if (nRace == 3) return 'ui_common_icon_race2'; if (nRace == 4) return 'ui_common_icon_race4'; if (nRace == 5) return 'ui_common_icon_race5'; } DestroyVecNode(vecNod) { for (let item of vecNod) { if (item) { item.destroy(); } } vecNod.length = 0; } FindAndDoUIFunction(strUI, strFun, stData) { let strPath = `Canvas/MainUI/${strUI}`; let goUI = cc.find(strPath); if (null == goUI) return; let comUI = goUI.getComponent(strUI); if (null == comUI) return; comUI[strFun](stData); } CreateRoleBroadCast(goRole, strMsg) { if (null == strMsg || '' == strMsg) return; let goRoleBroadCast = this.CreateSubNode(goRole, { nX: -120, nY: 200 }, GameModel.preRoleBrodcast, 'preRoleBrodcast'); cc.find('Label', goRoleBroadCast).getComponent(cc.Label).string = strMsg; // this.vecRoleBroadCast.push({ goRoleBroadCast: goRoleBroadCast, nCreateTime: this.GetTime(), nLiveTime: 3 }); goRoleBroadCast.runAction(cc.sequence(cc.delayTime(3), cc.removeSelf())); } CreateRoleEmojBroadCast(goRole, strMsg, emojiAtlas) { if (null == strMsg || '' == strMsg) return; let goRoleBroadCast = this.CreateSubNode(goRole, { nX: -120, nY: 200 }, GameModel.preRoleBrodcast, 'preRoleBrodcast'); //cc.find('Label', goRoleBroadCast).getComponent(cc.Label).string = strMsg; let chatItem = new cc.Node(); chatItem.parent = goRoleBroadCast; let richText = chatItem.addComponent('CustomRichText'); richText.maxWidth = 259; richText.fontSize = 20; richText.lineHeight = 22; richText.type = 1; richText.scale = -1; richText.emojiAtlas = emojiAtlas; richText.string = strMsg; richText.strColor = cc.Color.WHITE; chatItem.x = 0; chatItem.color = cc.color(200, 0, 0, 255); chatItem.parent = goRoleBroadCast; chatItem.name = 'emojBroadCast'; //chatItem.setPosition(cc.v2(stPos.nX, stPos.nY)); chatItem.y = 0; // this.vecRoleBroadCast.push({ goRoleBroadCast: goRoleBroadCast, nCreateTime: this.GetTime(), nLiveTime: 3 }); goRoleBroadCast.runAction(cc.sequence(cc.delayTime(3), cc.removeSelf())); } GetRole() { return cc.find('Canvas/MapUI').getComponent('GameMapLogic').myRole; } ChangeTeamButtonState(vecButton, strAtlas, strDarkFrame, strLightFrame, nCurBtn) { for (var it in vecButton) { if (it != nCurBtn) { SKUIUtil.setSpriteFrame(vecButton[it], strAtlas, strDarkFrame); } else { SKUIUtil.setSpriteFrame(vecButton[it], strAtlas, strLightFrame); } } } ChangeTeamNodeState(vecNode, nCurNode) { for (var it in vecNode) { vecNode[it].active = it == nCurNode ? true : false; } } GetTime() { let nTime = Math.floor(Date.parse(new Date()) / 1000); let nLocalTime = nTime + 28800; return nLocalTime; } GetAttributeName(strKey) { let result = ""; if (SKDataUtil.hasProperty(this.mapAttribute, strKey)) { result = this.mapAttribute[strKey].Name; } return result; } GetAttributeType(strKey) { let result = ""; if (SKDataUtil.hasProperty(this.mapAttribute, strKey)) { result = this.mapAttribute[strKey].Kind; } return result; } ChangeNumToRange(fData, fMin, fMax) { fData = Math.max(fData, fMin); fData = Math.min(fData, fMax); return fData; } GetDistance(stPosA, stPosB) { let nXDis = Math.abs(stPosA.x - stPosB.x); let nYDis = Math.abs(stPosA.y - stPosB.y); let nDis = Math.pow(nXDis * nXDis + nYDis * nYDis, 0.5); return nDis; } GetMapDataByIndex(mapData, nIndex) { if (nIndex < 0 || nIndex >= this.GetMapLen(mapData)) return null; let nCnt = -1; for (let it in mapData) { nCnt++; if (nCnt == nIndex) return mapData[it]; } return null; } IsDataInVecter(stData, vecData) { for (let it in vecData) { if (stData == vecData[it]) return true; } return false; } GetDefault(stData, stDefault) { if (typeof stData == "undefined") return stDefault; return stData; } GetTaskTalkList(nTaskID, nStep) { let vecTmp = []; let CSpeak = require('./Speak'); let pNpcMgr = require('./NpcMgr'); let pTaskConfigMgr = require('./task_config').g_pTaskConfigMgr; let stStep = pTaskConfigMgr.GetTaskStepInfo(nTaskID, nStep); if (!stStep) { return vecTmp; } for (let stData of stStep.vecSpeak) { if (!stData.nValue) { cc.warn("$警告:對話內容不能為空"); stData.nValue = "..."; } let nSpeakerResID = 0; let strSpeaderName = ''; let nPosType = 1; if (stData.nKey > 0) { //Npc說話 let stConfigInfo = pNpcMgr.GetNpcConfigInfo(stData.nKey); console.log(stData) console.log(stConfigInfo) nSpeakerResID = stConfigInfo.nResID; strSpeaderName = stConfigInfo.strName; nPosType = 2; } else { //主角說話 nSpeakerResID = GameModel.player.resid; strSpeaderName = GameModel.player.name; nPosType = 1; } let stSpead = new CSpeak(nSpeakerResID, stData.nValue, strSpeaderName, nPosType); // console.log(nSpeakerResID, stData.nValue, strSpeaderName, nPosType) vecTmp.push(stSpead); } return vecTmp; } SetPrizeIcon(goPrizeIcon, strItem) { if (strItem == 'exp') { SKUIUtil.setSpriteFrame(goPrizeIcon, 'Common/ui_common', 'ui_common_icon_exp'); } else if (strItem == 'petexp') { SKUIUtil.setSpriteFrame(goPrizeIcon, 'Common/ui_common', 'ui_common_icon_exppet'); } else if (strItem == 'money') { if (goPrizeIcon) { let sprite = goPrizeIcon.getComponent(cc.Sprite); if (sprite) { sprite.spriteFrame = ItemUtil.getItemIcon(9001); } else { cc.warn(`$警告:價值圖標異常${strItem}`); } } else { cc.warn(`$警告:價值圖標異常${strItem}`); } } else { let stConfigInfo = ItemUtil.getItemData(strItem); if (goPrizeIcon) { let sprite = goPrizeIcon.getComponent(cc.Sprite); if (sprite) { sprite.spriteFrame = ItemUtil.getItemIconBy(stConfigInfo); } else { cc.warn(`$警告:價值圖標異常${strItem}`); } } else { cc.warn(`$警告:價值圖標異常${strItem}`); } } } SetMaskAnimation(goAnim, nResID, strClipName) { goAnim.active = false; let url = `shape_mask/${nResID}/${strClipName}`; cc.loader.loadRes(url, cc.SpriteAtlas, function (error, atlas) { if (error) { cc.warn(`$警告:加載資源${url}失敗!`); return; } if (!SKUIUtil.isValid(goAnim)) { return; } goAnim.active = true; let curFrames = atlas.getSpriteFrames(); let fn = 10; if(nResID <= 4038){ fn = 15; } let curClip = cc.AnimationClip.createWithSpriteFrames(curFrames, fn); curClip.name = strClipName; curClip.wrapMode = cc.WrapMode.Loop; let nodeAni = goAnim.getComponent(cc.Animation); if (nodeAni) { nodeAni.addClip(curClip); nodeAni.play(curClip.name); } let anchorY = 0.4; let anchorX = 0.5; if (SKDataUtil.hasProperty(GameModel.conf_res_anchor, nResID)) { anchorY = GameModel.conf_res_anchor[nResID].anchorY; anchorX = GameModel.conf_res_anchor[nResID].anchorX; } goAnim.anchorY = anchorY; goAnim.anchorX = anchorX; }); } SetAnimation(goAnim, nResID, strClipName) { goAnim.active = false; let url = `shap/${nResID}/${strClipName}`; cc.loader.loadRes(url, cc.SpriteAtlas, function (error, atlas) { if (error) { cc.warn(`$警告:加載資源${url}失敗!`); return; } if (!SKUIUtil.isValid(goAnim)) { return; } goAnim.active = true; let curFrames = atlas.getSpriteFrames(); let fn = 10; if(nResID <= 4038){ fn = 15; } let curClip = cc.AnimationClip.createWithSpriteFrames(curFrames, fn); curClip.name = strClipName; curClip.wrapMode = cc.WrapMode.Loop; let nodeAni = goAnim.getComponent(cc.Animation); if (nodeAni) { nodeAni.addClip(curClip); nodeAni.play(curClip.name); } let anchorY = 0.4; let anchorX = 0.5; if (SKDataUtil.hasProperty(GameModel.conf_res_anchor, nResID)) { anchorY = GameModel.conf_res_anchor[nResID].anchorY; anchorX = GameModel.conf_res_anchor[nResID].anchorX; } goAnim.anchorY = anchorY; goAnim.anchorX = anchorX; }); } initLongTouchBtn(btn, callback, param) { btn.on(cc.Node.EventType.TOUCH_START, () => { if (this.btntimer.timer != null) { return; } this.btntimer.timer = setInterval(() => { this.btntimer.times++; if (this.btntimer.times >= this.btntimer.step) { this.btntimer.times = 0; this.btntimer.step = this.btntimer.step / 2; if (this.btntimer.step < 1) { this.btntimer.step = 1; } callback(param); } }, 50); callback(param); }); let cancelfunc = () => { clearInterval(this.btntimer.timer); this.btntimer.timer = null; this.btntimer.times = 0; this.btntimer.step = 20; }; btn.on(cc.Node.EventType.TOUCH_CANCEL, cancelfunc); btn.on(cc.Node.EventType.TOUCH_END, cancelfunc); } } let g_ctFunctionInstance = null; module.exports = (() => { if (g_ctFunctionInstance == null) { g_ctFunctionInstance = new CPubFunction(); } return g_ctFunctionInstance; })();