cc.Class({ extends: cc.Component, properties: { spinBtn: { default: null, // The default value will be used only when the component attachin // to a node for the first time type: cc.Button, // optional, default is typeof default visible: true, // optional, default is true displayName: 'SpinBtn', // optional }, wheelSp: { default: null, type: cc.Sprite, tooltip: "转盘图片" }, background: { default: null, type: cc.Sprite, tooltip: "背景图片" }, pointer: { default: null, type: cc.Sprite, tooltip: "指针图片" }, title: { default: null, type: cc.Sprite, tooltip: "欢天喜地幸运大转盘" }, startbtn: { default: null, type: cc.Sprite, tooltip: "开始按钮" }, maxSpeed: { default: 5, type: cc.Float, max: 20, min: 2, }, duration: { default: 0.1, type: cc.Float, max: 2, min: 0.1, tooltip: "减速前旋转时间" }, acc: { default: 2, type: cc.Float, max: 20, min: 0.01, tooltip: "加速度" }, targetID: { default: 0, type: cc.Integer, max: 7, min: 0, tooltip: "指定结束时的齿轮" }, springback: { default: false, tooltip: "旋转结束是否回弹" }, ShowRewards:cc.Node, Rewards:cc.Node, RewardDetail: { default: [], type: [cc.String], }, Businesslicense: { default: null, type: cc.SpriteFrame, }, LandDevelopmentCertificate: { default: null, type: cc.SpriteFrame, }, Golden10: { default: null, type: cc.SpriteFrame, }, Golden50: { default: null, type: cc.SpriteFrame, }, Golden100: { default: null, type: cc.SpriteFrame, }, ManageUI:cc.Node, ManageMap:cc.Node, }, // use this for initialization onLoad: function () { //消耗钻石数量 this.Diamond = 100; this.spin = this.getNode("spin"); this.Sprite = this.getNode("New Sprite",this.spin); this.wheelState = 0; this.curSpeed = 0; this.spinTime = 0; //减速前旋转时间 this.gearNum = 8; this.defaultAngle = 360 / this.gearNum / 2; //修正默认角度 this.gearAngle = 360 / this.gearNum; //每个齿轮的角度 this.wheelSp.node.angle = -this.defaultAngle; // console.log("修正默认角度",this.defaultAngle); this.finalAngle = 0; //最终结果指定的角度 this.effectFlag = 0; //用于音效播放 this.restMaxSpeed = this.maxSpeed; this.duration = 1; if (!cc.sys.isBrowser) { cc.loader.loadRes('Sound/game_turntable', function (err, res) { if (err) { // cc.log('...err:' + err); } }); } this.spinBtn.node.on(cc.Node.EventType.TOUCH_END, function (event) { // cc.log("begin spin"); if (this.wheelState !== 0) { return; } // if (GlobalD.GameData.GetDiamond()>=this.Diamond) { // GlobalD.GameData.PlusDiamond(-this.Diamond); // // this.startLuck(); // // // }else{ // // cc.log("没"+this.Diamond+"钻石转不了"); // // this._showDialog(function () { // this.watchvideo.on(cc.Node.EventType.TOUCH_END, function (event) { // this.startLuck(); // this._closeDialog(); // }.bind(this)); // this.close.on(cc.Node.EventType.TOUCH_END, function (event) { // this._closeDialog(); // }.bind(this)); // }.bind(this)); // } //每日签到 let myDate = new Date(); //'2019/05/01' let Today = myDate.toLocaleDateString(); let LastTimeLuckDate = GlobalD.GameData.GetLastTimeLuckDate(); // LastTimeLuckDate = "2019/3/20"; let s = "2019/3/20" console.log("today",Today); console.log("LastTimeLuckDate",LastTimeLuckDate); if(Today == LastTimeLuckDate && LastTimeLuckDate!='0000/00/00') { } else { // console.log("走着么"); //过了一天 GlobalD.GameData.SetLotteryTimes(10); // GlobalD.GameData.SetLastTimeLuckDate(Today); GlobalD.GameData.SetLastTimeLuckDate(Today); } if (GlobalD.GameData.GetLotteryTimes()>0) { // cc.log("没"+this.Diamond+"钻石转不了"); this._showDialog(function () { this.watchvideo.on(cc.Node.EventType.TOUCH_END, function (event) { this.startLuck(); this._closeDialog(); }.bind(this)); this.close.on(cc.Node.EventType.TOUCH_END, function (event) { this._closeDialog(); }.bind(this)); }.bind(this)); // cc.log('11111111=='+GlobalD.GameData.GetLotteryTimes()) GlobalD.GameData.PlusLotteryTimes(-1); } else { cc.loader.loadRes('resUI/ShowNotEnoughMoney', function (err, texture) { var prefab = cc.instantiate(texture); prefab.getComponent('ShowNotEnoughMoney').Text('明天再来试试手气吧!'); this.node.addChild(prefab); }.bind(this)); } }.bind(this)); this.initNetwork(); }, initNetwork : function(){ UtilsPrefabs.loadResSpriteFrame('taskres/diamond_1',function (texture) { }.bind(this)); UtilsPrefabs.loadResSpriteFrame('taskres/diamond_2',function (texture) { }.bind(this)); }, startLuck : function(){ this.getRandom(); this.decAngle = 1 * 360; // 减速旋转两圈 this.wheelState = 1; this.curSpeed = 0; this.spinTime = 0; this.maxSpeed = this.restMaxSpeed; }, caculateFinalAngle: function (targetID) { this.finalAngle = 360 - this.targetID * this.gearAngle + this.defaultAngle; if (this.springback) { this.finalAngle += this.gearAngle; } }, editBoxDidBegin: function (edit) { }, editBoxDidChanged: function (text) { }, editBoxDidEndEditing: function (edit) { var res = parseInt(edit.string); if (isNaN(res)) { if (cc.sys.isBrowser) { // alert('please input a number!'); } else { // cc.log(".....invalid input"); } this.targetID = Math.round(Math.random() * (this.gearNum - 1)); // cc.log("停止的位置是", this.targetID); return; } this.targetID = res; }, getRandom: function () { let TerritoryStateArray = GlobalD.GameData.GetTerritoryStateArray(); var BuildingStateArray = GlobalD.GameData.BuildingStateArray; var tempcout = 0; var tempcout7 = 0; var probability = 0.1; var probability7 = 0.1; var probability100 = 0.1; var probability10 = 0.15; for(let i=0;i= this.gearAngle) { // if (this.audioID) { // // cc.audioEngine.pauseEffect(this.audioID); // } // // this.audioID = cc.audioEngine.playEffect(this.effectAudio,false); // this.audioID = cc.audioEngine.playEffect(cc.url.raw('resources/Sound/game_turntable.mp3')); // this.effectFlag = 0; // } if (this.wheelState == 1) { // cc.log('....加速,speed:' + this.curSpeed); this.spinTime += dt; this.wheelSp.node.angle = Math.abs(this.wheelSp.node.angle) + this.curSpeed; if (this.curSpeed <= this.maxSpeed) { this.curSpeed += this.acc; } else { if (this.spinTime < this.duration) { return; } // cc.log('....开始减速'); //设置目标角度 this.finalAngle = 360 - this.targetID * this.gearAngle - this.defaultAngle; this.maxSpeed = this.curSpeed; if (this.springback) { this.finalAngle += this.gearAngle; } this.wheelSp.node.angle = this.finalAngle; this.wheelState = 2; } } else if (this.wheelState == 2) { // cc.log('......减速'); var curRo = Math.abs(this.wheelSp.node.angle); //应该等于finalAngle var hadRo = curRo - this.finalAngle; this.curSpeed = this.maxSpeed * ((this.decAngle - hadRo) / this.decAngle) + 0.1; this.wheelSp.node.angle = curRo + this.curSpeed; if ((this.decAngle - hadRo) <= 0) { // cc.log('....停止'); this.wheelState = 0; this.wheelSp.node.angle = this.finalAngle; if (this.springback) { //倒转一个齿轮 // var act = new cc.rotateBy(0.6, -this.gearAngle); var act = cc.rotateBy(0.6, -this.gearAngle); var seq = cc.sequence(cc.delayTime(0.2), act, cc.callFunc(this.showRes, this)); this.wheelSp.node.runAction(seq); } else { this.showRes(); } } } }, showRes: function () { // console.log("随机转盘是",this.targetID); // this.targetID = 1; // this.targetID=7; this.Rewards.removeAllChildren(); // 0 金币 x10 // 1 随机建筑 x1 // 2 金币 x50 // 3 土地开发证件 x1 // 4 金币 x10 // 5 金币 x100 // 6 金币 x10 // 7 经营许可证 x1 switch (this.targetID) { case 0: case 4: case 6: GlobalD.GameData.PlusGolden(10000); this.Rewards.getComponent(cc.Sprite).spriteFrame = this.Golden10; this.Rewards.scale=2; break; case 1: this.myScale = 0.2; // [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0]; this.myScales = [ 0.2, 0.2, 0.2, //3 1, 1, 1, 1, //7 1, 1, 1, 1, //11 1, 1, 1, 1, //15 1, 1, 1, 1.5, //19 1.5, 1, 1, 1, ]; let BuildingLockStateArray = GlobalD.GameData.BuildingLockStateArray; // console.log("我当前有什么",BuildingLockStateArray); let HadBuildingArray = []; // console.log("我当前有什么 领取之前",GlobalD.GameData.BuildingNumArray); for(let i=3;i { return p - v; }, 1); for (let i = this.min; i < this.max; i++) { if (map.has(i)) { this.percentage.set(i, map.get(i)); } else { this.percentage.set(i, result / (this.max - this.min - map.size)); } } } /** * 根据比例生成取值范围 */ range() { let [start, random, keys] = [0, this.MATH_RANGE, Array.from(this.percentage.keys())]; for (let i = 0; i < keys.length; i++) { let temp = this.percentage.get(keys[i]); this.percentage.set(keys[i], [start, start += temp * random]); } } /** * 生成随机数 */ create() { let num = Math.random() * this.MATH_RANGE; for (let data of this.percentage.entries()) { if (num >= data[1][0] && num < data[1][1]) { return data[0]; } } return null; } }