import GameReport from "../../../FrameWork/Report/ZyZyReport"; import User from "../../../FrameWork/User/User"; import AppPlatform from "../../../FrameWork/Util/AppPlatform"; import Common5 from "../../../Platform/th/Common5"; import GameBase from "../../SCommon/GameBase"; import { ZhanLanGuanManager } from "./ZhanLanGuanManager"; const { ccclass, property } = cc._decorator; @ccclass export default class ZhanLanGuan extends GameBase { @property(cc.Node) fishListDialog: cc.Node = null; //鱼列表弹窗 @property(cc.Node) fishContent: cc.Node = null; //鱼列表内容 @property(cc.Node) fishNode: cc.Node = null; //鱼列表节点 @property(cc.Node) fishShowNode: cc.Node = null; //鱼展示节点 @property(cc.Node) zhaoMuNode: cc.Node = null; _dt = 0 fishNodeList: cc.Node[] = null; //展示鱼节点列表 fishMoveRange: cc.Rect = null; //鱼移动范围 onLoad() { super.onLoad(); } onDestroy() { Common5.playMusic("sound/背景音"); super.onDestroy(); } start() { //Common5.playMusic("sound/冰雪世界"); this.initData(); this.initComponent(); // EventMgr.onEvent_custom(ryw_Event.refreshZhaoMuTimes, () => { // this.showShouYiNode() // this.refreshZhaoMuTime() // }, this) // this.schedule(() => { // let dt = 0.016 // this.fishAnimation(dt); // this._dt += dt // if (this._dt >= 1.0) { // this._dt = 0 // this.refreshZhaoMuTime() // } // }, 0.016) } //初始化数据 initData() { this.fishNodeList = []; this.fishMoveRange = new cc.Rect(-this.fishShowNode.width / 2, -this.fishShowNode.height / 2, this.fishShowNode.width, this.fishShowNode.height); } //初始化组件 initComponent() { this.fishListDialog.active = false; this.initFishList(); this.showFishNodeList(); //this.refreshZhaoMuTime() //this.showShouYiNode() } //初始化鱼列表 initFishList() { this.fishNode.active = false; let fishShowDataList = User.getShowFishDataList(); //this.checkTaskFinish() let bagGoodsList = User.getBagGoodsList(); console.log("物品列表", bagGoodsList); for (const good of bagGoodsList) { let fishShowInfo = ZhanLanGuanManager.getFishShowInfoByGoodId(good.goodId); if (fishShowInfo) { console.log("+++++++++++++", fishShowInfo); let isShow = true; for (let i = 0; i < fishShowDataList.length; i++) { let fishShowInfo2 = ZhanLanGuanManager.getFishShowInfoById(fishShowDataList[i]); if (fishShowInfo.goodId == fishShowInfo2.goodId) { isShow = false; break; } } if (isShow) { let fishNode = cc.instantiate(this.fishNode) fishNode.setPosition(cc.v2(0, 0)) fishNode.parent = this.fishContent; fishNode.active = true; fishNode['goodId'] = fishShowInfo.goodId; let icon = fishNode.getChildByName('icon'); let fishNum = fishNode.getChildByName('fishNum'); let labName = fishNode.getChildByName('labName').getComponent(cc.Label); fishNum.getComponent(cc.Label).string = 'x' + good.goodNum; // Common5.getSpriteFrameFromBundle("GoodIcon", "icon/" + good.goodId, icon.getComponent(cc.Sprite)); Common5.setRemoteSpriteFrame(icon.getComponent(cc.Sprite),'GoodIcon/'+ good.goodId) labName.string = fishShowInfo.name; } } } } //展示鱼列表 showFishNodeList() { let fishShowDataList = User.getShowFishDataList(); for (let i = 0; i < fishShowDataList.length; i++) { let fishShowInfo = ZhanLanGuanManager.getFishShowInfoById(fishShowDataList[i]); this.initFishNode(fishShowInfo); } } //初始化鱼节点 initFishNode(fishShowInfo) { Common5.getPrefabFromBundle("GameRes", 'huangjinyufu/' + fishShowInfo.url, this.fishShowNode, (fish: cc.Node) => { fish.active = true; fish['id'] = fishShowInfo.id; fish['moveType'] = fishShowInfo.moveType; fish['moveSpeed'] = fishShowInfo.moveSpeed; fish.getChildByName('光').active = false; //随机生成鱼速度 if (fishShowInfo.moveType == 1) { if (Math.random() < 0.5) { fish.scaleX = -Math.abs(fish.scaleX); } } else if (fishShowInfo.moveType == 2) { fish['moveSpeVec'] = new cc.Vec2(0, 0); fish['moveSpeVec'].x = (Math.random() + 1) / 2; if (Math.random() < 0.5) { fish['moveSpeVec'].y = - (Math.random() + 1) / 2; } else { fish['moveSpeVec'].y = (Math.random() + 1) / 2; } } //随机生成鱼坐标 const randomNodePos = (fish: cc.Node) => { fish.x = Common5.getRandomNum(-this.fishMoveRange.width / 2 + 100, this.fishMoveRange.width / 2 - 100); fish.y = Common5.getRandomNum(-this.fishMoveRange.height / 2 + 100, this.fishMoveRange.height / 2 - 100); for (const iterator of this.fishNodeList) { if (iterator.getBoundingBox().intersects(fish.getBoundingBox())) { randomNodePos(fish); } } } randomNodePos(fish); this.fishNodeList.push(fish); }); } //刷新收益信息 // showShouYiNode() { // let hetong = User.getUserHeTong() // let xishuIndex = 1 // if(hetong.signMishuForever){ // xishuIndex = 2 // } // let index = ZhaoMuGameType.ZhanLanGuan // let localZhaoMuData = MeiNvZhaoMuManager.getMeiNvZhaoMuData() // let zhaoMuBeiShu = localZhaoMuData[index].zhaoMuBeiShu // const income = ZhanLanGuanManager.getIncomeSecondAll()*zhaoMuBeiShu*xishuIndex; // const length = User.getShowFishDataList().length; // const quat = User.getShowFishQuantity(); // const shouYiNode = this.node.getChildByName('shouYiNode'); // shouYiNode.getChildByName('moneyStr').getComponent(cc.Label).string = `${income}元/秒`; // shouYiNode.getChildByName('showFishStr').getComponent(cc.Label).string = `展位数:${length}/${quat}`; // } update(dt) { } //鱼动画 fishAnimation(deltaTime: number) { for (const iterator of this.fishNodeList) { if (iterator['moveType'] == 1) { if (iterator.scaleX > 0) { iterator.x -= iterator['moveSpeed'] * deltaTime; } else { iterator.x += iterator['moveSpeed'] * deltaTime; } if (iterator.x >= this.fishMoveRange.xMax) { iterator.scaleX = Math.abs(iterator.scaleX); } else if (iterator.x <= this.fishMoveRange.xMin) { iterator.scaleX = -Math.abs(iterator.scaleX); } } else if (iterator['moveType'] == 2) { iterator.x += iterator['moveSpeVec'].x * deltaTime * iterator['moveSpeed']; iterator.y += iterator['moveSpeVec'].y * deltaTime * iterator['moveSpeed']; if (iterator.x >= this.fishMoveRange.xMax) { iterator['moveSpeVec'].x = -(Math.random() + 1) / 2; } else if (iterator.x <= this.fishMoveRange.xMin) { iterator['moveSpeVec'].x = (Math.random() + 1) / 2; } if (iterator.y >= this.fishMoveRange.yMax) { iterator['moveSpeVec'].y = -(Math.random() + 1) / 2; } else if (iterator.y <= this.fishMoveRange.yMin) { iterator['moveSpeVec'].y = (Math.random() + 1) / 2; } } } } //展示所有鱼 onShowAllFishClick() { // Common5.playEffect("sound/按键点击"); if (User.getShowFishDataList().length >= User.getShowFishQuantity()) { Common5.showTips_custom("展位已满!"); return; } this.fishListDialog.active = true; } //增加展位 onAddZhanBeiClick(event) { // Common5.playEffect("sound/按键点击"); if (User.getShowFishQuantity() >= 15) { Common5.showTips_custom("无法再增加新展位!"); return; } let target = event.target; let tab = { onClose: (finish) => { if (finish) { Common5.ReportDY("inLevel", "展览馆-AD-增加展位"); let quat = User.getShowFishQuantity() + 1; User.setShowFishQuantity(quat); Common5.showTips_custom("目前展位数:" + quat); //this.showShouYiNode(); this.reportKey(() => { GameReport.ADReport('展览馆增加展位', 1); }) } else { this.reportKey(() => { GameReport.ADReport('展览馆增加展位', 0); }) Common5.showTips_custom("广告未观看完"); } }, onFailed: () => { } } AppPlatform.playVideo_custom(tab); } //放鱼 onReleaseFishClick(event) { // Common5.playEffect("sound/按键点击"); let target = event.target; target.active = false; let fishShowInfo = ZhanLanGuanManager.getFishShowInfoByGoodId(target['goodId']); let showFishDataList = User.getShowFishDataList(); let showFishData = fishShowInfo.id showFishDataList.push(showFishData); User.setShowFishDataList(showFishDataList); //this.checkTaskFinish() this.initFishNode(fishShowInfo); //this.showShouYiNode(); this.fishListDialog.active = false; } //关闭展览 onCloseXClick(event) { // Common5.playEffect("sound/按键点击"); let target = event.target; this.fishListDialog.active = false; } // checkTaskFinish() { // let fishShowDataList = User.getShowFishDataList() // let mainTaskId = TaskManager.getCurUnLockMainTaskId() // if (mainTaskId == MainTaskIdEnum.MainTask_527) { // let array = [4, 5, 6, 7, 8] // let isHave = true // for (let i = 0; i < array.length; i++) { // if (fishShowDataList.indexOf(array[i]) < 0) { // isHave = false // } // } // if (isHave) { // TaskManager.finishCurMainTask(MainTaskIdEnum.MainTask_527) // } // } else if (mainTaskId == MainTaskIdEnum.MainTask_528) { // let array = [9] // let isHave = true // for (let i = 0; i < array.length; i++) { // if (fishShowDataList.indexOf(array[i]) < 0) { // isHave = false // } // } // if (isHave) { // TaskManager.finishCurMainTask(MainTaskIdEnum.MainTask_528) // } // } else if (mainTaskId == MainTaskIdEnum.MainTask_534) { // let array = [0, 1, 2, 3] // let isHave = true // for (let i = 0; i < array.length; i++) { // if (fishShowDataList.indexOf(array[i]) < 0) { // isHave = false // } // } // if (isHave) { // TaskManager.finishCurMainTask(MainTaskIdEnum.MainTask_534) // } // } else if (mainTaskId == MainTaskIdEnum.MainTask_540) { // let array = [10, 11] // let isHave = true // for (let i = 0; i < array.length; i++) { // if (fishShowDataList.indexOf(array[i]) < 0) { // isHave = false // } // } // if (isHave) { // TaskManager.finishCurMainTask(MainTaskIdEnum.MainTask_540) // } // } // } // refreshZhaoMuTime() { // let localZhaoMuData = MeiNvZhaoMuManager.getMeiNvZhaoMuData() // let maxTime = localZhaoMuData[ZhaoMuGameType.ZhanLanGuan].zhaoMuTime // let zhaoMuBeiShu = localZhaoMuData[ZhaoMuGameType.ZhanLanGuan].zhaoMuBeiShu // // let maxUnlockIndex = localZhaoMuData[ZhaoMuGameType.YuanYangChuan].maxUnlockIndex // let hetong = User.getUserHeTong() // let xishuIndex = 1 // if (hetong.signMishuForever) { // xishuIndex = 2 // } // zhaoMuBeiShu = zhaoMuBeiShu * xishuIndex // if (maxTime > 0) { // //按钮上人物显示第一个 // // let config = MeiNvZhaoMuManager.getConfigById(HaiYangQingjie.XiaShuiDao,0) // // this.zhaoMuNode.getChildByName('tipSpr').active = false // this.zhaoMuNode.getChildByName('renSpine').active = true // // this.zhaoMuNode.getChildByName('renSpine').getComponent(sp.Skeleton).setAnimation(0,'半身呼吸',true) // // this.zhaoMuNode.getChildByName('renSpine').getComponent(sp.Skeleton).setSkin(config.skinIndex) // this.zhaoMuNode.getChildByName('timeStr').getComponent(cc.Label).string = `${DateUtils.formatTime_custom(maxTime)}` // this.zhaoMuNode.getChildByName('tipSpr').getChildByName('shouYiStr').getComponent(cc.Label).string = `收益x${zhaoMuBeiShu}` // } else { // // this.zhaoMuNode.getChildByName('tipSpr').active = true // this.zhaoMuNode.getChildByName('renSpine').active = false // this.zhaoMuNode.getChildByName('timeStr').getComponent(cc.Label).string = `` // // this.zhaoMuNode.getChildByName('shouYiStr').getComponent(cc.Label).string = `秘书招聘` // if (xishuIndex == 2) { // this.zhaoMuNode.getChildByName('tipSpr').getChildByName('shouYiStr').getComponent(cc.Label).string = `收益 x 2` // } else { // this.zhaoMuNode.getChildByName('tipSpr').getChildByName('shouYiStr').getComponent(cc.Label).string = `收益 x N` // } // } // } // zhaomuClickEvent() { // Common5.playEffect("CommonRes/sound/按键点击") // PrefabManage.loadPrefabByType(GameType.MeiNvZhaoMu, null, (prefabNode) => { // prefabNode.getComponent(MeiNvZhaoMu).initView(ZhaoMuGameType.ZhanLanGuan) // }) // } }