Wheel.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751
  1. cc.Class({
  2. extends: cc.Component,
  3. properties: {
  4. spinBtn: {
  5. default: null, // The default value will be used only when the component attachin // to a node for the first time
  6. type: cc.Button, // optional, default is typeof default
  7. visible: true, // optional, default is true
  8. displayName: 'SpinBtn', // optional
  9. },
  10. wheelSp: {
  11. default: null,
  12. type: cc.Sprite,
  13. tooltip: "转盘图片"
  14. },
  15. background: {
  16. default: null,
  17. type: cc.Sprite,
  18. tooltip: "背景图片"
  19. },
  20. pointer: {
  21. default: null,
  22. type: cc.Sprite,
  23. tooltip: "指针图片"
  24. },
  25. title: {
  26. default: null,
  27. type: cc.Sprite,
  28. tooltip: "欢天喜地幸运大转盘"
  29. },
  30. startbtn: {
  31. default: null,
  32. type: cc.Sprite,
  33. tooltip: "开始按钮"
  34. },
  35. maxSpeed: {
  36. default: 5,
  37. type: cc.Float,
  38. max: 20,
  39. min: 2,
  40. },
  41. duration: {
  42. default: 0.1,
  43. type: cc.Float,
  44. max: 2,
  45. min: 0.1,
  46. tooltip: "减速前旋转时间"
  47. },
  48. acc: {
  49. default: 2,
  50. type: cc.Float,
  51. max: 20,
  52. min: 0.01,
  53. tooltip: "加速度"
  54. },
  55. targetID: {
  56. default: 0,
  57. type: cc.Integer,
  58. max: 7,
  59. min: 0,
  60. tooltip: "指定结束时的齿轮"
  61. },
  62. springback: {
  63. default: false,
  64. tooltip: "旋转结束是否回弹"
  65. },
  66. ShowRewards:cc.Node,
  67. Rewards:cc.Node,
  68. RewardDetail: {
  69. default: [],
  70. type: [cc.String],
  71. },
  72. Businesslicense: {
  73. default: null,
  74. type: cc.SpriteFrame,
  75. },
  76. LandDevelopmentCertificate: {
  77. default: null,
  78. type: cc.SpriteFrame,
  79. },
  80. Golden10: {
  81. default: null,
  82. type: cc.SpriteFrame,
  83. },
  84. Golden50: {
  85. default: null,
  86. type: cc.SpriteFrame,
  87. },
  88. Golden100: {
  89. default: null,
  90. type: cc.SpriteFrame,
  91. },
  92. ManageUI:cc.Node,
  93. ManageMap:cc.Node,
  94. },
  95. // use this for initialization
  96. onLoad: function () {
  97. //消耗钻石数量
  98. this.Diamond = 100;
  99. this.spin = this.getNode("spin");
  100. this.Sprite = this.getNode("New Sprite",this.spin);
  101. this.wheelState = 0;
  102. this.curSpeed = 0;
  103. this.spinTime = 0; //减速前旋转时间
  104. this.gearNum = 8;
  105. this.defaultAngle = 360 / this.gearNum / 2; //修正默认角度
  106. this.gearAngle = 360 / this.gearNum; //每个齿轮的角度
  107. this.wheelSp.node.angle = -this.defaultAngle;
  108. // console.log("修正默认角度",this.defaultAngle);
  109. this.finalAngle = 0; //最终结果指定的角度
  110. this.effectFlag = 0; //用于音效播放
  111. this.restMaxSpeed = this.maxSpeed;
  112. this.duration = 1;
  113. if (!cc.sys.isBrowser) {
  114. cc.loader.loadRes('Sound/game_turntable', function (err, res) {
  115. if (err) {
  116. // cc.log('...err:' + err);
  117. }
  118. });
  119. }
  120. this.spinBtn.node.on(cc.Node.EventType.TOUCH_END, function (event) {
  121. // cc.log("begin spin");
  122. if (this.wheelState !== 0) {
  123. return;
  124. }
  125. // if (GlobalD.GameData.GetDiamond()>=this.Diamond) {
  126. // GlobalD.GameData.PlusDiamond(-this.Diamond);
  127. //
  128. // this.startLuck();
  129. //
  130. //
  131. // }else{
  132. // // cc.log("没"+this.Diamond+"钻石转不了");
  133. //
  134. // this._showDialog(function () {
  135. // this.watchvideo.on(cc.Node.EventType.TOUCH_END, function (event) {
  136. // this.startLuck();
  137. // this._closeDialog();
  138. // }.bind(this));
  139. // this.close.on(cc.Node.EventType.TOUCH_END, function (event) {
  140. // this._closeDialog();
  141. // }.bind(this));
  142. // }.bind(this));
  143. // }
  144. //每日签到
  145. let myDate = new Date();
  146. //'2019/05/01'
  147. let Today = myDate.toLocaleDateString();
  148. let LastTimeLuckDate = GlobalD.GameData.GetLastTimeLuckDate();
  149. // LastTimeLuckDate = "2019/3/20";
  150. let s = "2019/3/20"
  151. console.log("today",Today);
  152. console.log("LastTimeLuckDate",LastTimeLuckDate);
  153. if(Today == LastTimeLuckDate && LastTimeLuckDate!='0000/00/00')
  154. {
  155. }
  156. else
  157. {
  158. // console.log("走着么");
  159. //过了一天
  160. GlobalD.GameData.SetLotteryTimes(10);
  161. // GlobalD.GameData.SetLastTimeLuckDate(Today);
  162. GlobalD.GameData.SetLastTimeLuckDate(Today);
  163. }
  164. if (GlobalD.GameData.GetLotteryTimes()>0) {
  165. // cc.log("没"+this.Diamond+"钻石转不了");
  166. this._showDialog(function () {
  167. this.watchvideo.on(cc.Node.EventType.TOUCH_END, function (event) {
  168. this.startLuck();
  169. this._closeDialog();
  170. }.bind(this));
  171. this.close.on(cc.Node.EventType.TOUCH_END, function (event) {
  172. this._closeDialog();
  173. }.bind(this));
  174. }.bind(this));
  175. // cc.log('11111111=='+GlobalD.GameData.GetLotteryTimes())
  176. GlobalD.GameData.PlusLotteryTimes(-1);
  177. }
  178. else
  179. {
  180. cc.loader.loadRes('resUI/ShowNotEnoughMoney', function (err, texture) {
  181. var prefab = cc.instantiate(texture);
  182. prefab.getComponent('ShowNotEnoughMoney').Text('明天再来试试手气吧!');
  183. this.node.addChild(prefab);
  184. }.bind(this));
  185. }
  186. }.bind(this));
  187. this.initNetwork();
  188. },
  189. initNetwork : function(){
  190. UtilsPrefabs.loadResSpriteFrame('taskres/diamond_1',function (texture) {
  191. }.bind(this));
  192. UtilsPrefabs.loadResSpriteFrame('taskres/diamond_2',function (texture) {
  193. }.bind(this));
  194. },
  195. startLuck : function(){
  196. this.getRandom();
  197. this.decAngle = 1 * 360; // 减速旋转两圈
  198. this.wheelState = 1;
  199. this.curSpeed = 0;
  200. this.spinTime = 0;
  201. this.maxSpeed = this.restMaxSpeed;
  202. },
  203. caculateFinalAngle: function (targetID) {
  204. this.finalAngle = 360 - this.targetID * this.gearAngle + this.defaultAngle;
  205. if (this.springback) {
  206. this.finalAngle += this.gearAngle;
  207. }
  208. },
  209. editBoxDidBegin: function (edit) {
  210. },
  211. editBoxDidChanged: function (text) {
  212. },
  213. editBoxDidEndEditing: function (edit) {
  214. var res = parseInt(edit.string);
  215. if (isNaN(res)) {
  216. if (cc.sys.isBrowser) {
  217. // alert('please input a number!');
  218. } else
  219. {
  220. // cc.log(".....invalid input");
  221. }
  222. this.targetID = Math.round(Math.random() * (this.gearNum - 1));
  223. // cc.log("停止的位置是", this.targetID);
  224. return;
  225. }
  226. this.targetID = res;
  227. },
  228. getRandom: function () {
  229. let TerritoryStateArray = GlobalD.GameData.GetTerritoryStateArray();
  230. var BuildingStateArray = GlobalD.GameData.BuildingStateArray;
  231. var tempcout = 0;
  232. var tempcout7 = 0;
  233. var probability = 0.1;
  234. var probability7 = 0.1;
  235. var probability100 = 0.1;
  236. var probability10 = 0.15;
  237. for(let i=0;i<TerritoryStateArray.length;i++)
  238. {
  239. // console.log("结构遍历",TerritoryStateArray[i]);
  240. if(TerritoryStateArray[i]==1)
  241. {
  242. tempcout++;
  243. }
  244. }
  245. for(let i=0;i<BuildingStateArray.length;i++)
  246. {
  247. // console.log("结构遍历",BuildingStateArray[i]);
  248. if(BuildingStateArray[i]==1)
  249. {
  250. tempcout7++;
  251. }
  252. }
  253. if (tempcout==TerritoryStateArray.length) {
  254. //没有能开的了
  255. probability = 0;
  256. probability100 = 0.1;
  257. probability10 = 0.2;
  258. }
  259. if (tempcout7==BuildingStateArray.length) {
  260. //没有能开的了
  261. probability7 = 0;
  262. probability100 = 0.1;
  263. probability10 = 0.2;
  264. }
  265. // console.log("设置概率",tempcout,probability);
  266. // 随机数范围 :40~900
  267. let random = new GLRandom(0, this.gearNum);
  268. // 0 金币 x10
  269. // 1 随机建筑 x1
  270. // 2 金币 x50
  271. // 3 土地开发证件 x1
  272. // 4 金币 x10
  273. // 5 金币 x100
  274. // 6 金币 x10
  275. // 7 经营许可证 x1
  276. // 调整概率
  277. random.percentage = new Map([
  278. [0, 0.2], // 调整值为41的数值,概率为20%
  279. [1, 0.05], // 调整值为41的数值,概率为20%
  280. [2, 0.1], // 调整值为41的数值,概率为20%
  281. [3, 0.1], // 调整值为41的数值,概率为20%
  282. [4, 0.2], // 调整值为41的数值,概率为20%
  283. [5, 0.1], // 调整值为41的数值,概率为20%
  284. [6, 0.2], // 调整值为41的数值,概率为20%
  285. [7, 0.05], // 调整值为46的数值,概率为50%
  286. ]);
  287. // 生成值区间
  288. random.range();
  289. this.targetID = random.create();
  290. // 生成概率随机数
  291. // console.log("停止的位置是区间随机数", this.targetID);
  292. // this.targetID = Math.round(Math.random() * (this.gearNum - 1));
  293. // cc.log("停止的位置是", this.targetID);
  294. },
  295. // called every frame, uncomment this function to activate update callback
  296. update: function (dt) {
  297. if (this.wheelState === 0) {
  298. return;
  299. }
  300. // cc.log('......update');
  301. // cc.log('......state=%d',this.wheelState);
  302. // 播放音效有可能卡
  303. // this.effectFlag += this.curSpeed;
  304. // if (!cc.sys.isBrowser && this.effectFlag >= this.gearAngle) {
  305. // if (this.audioID) {
  306. // // cc.audioEngine.pauseEffect(this.audioID);
  307. // }
  308. // // this.audioID = cc.audioEngine.playEffect(this.effectAudio,false);
  309. // this.audioID = cc.audioEngine.playEffect(cc.url.raw('resources/Sound/game_turntable.mp3'));
  310. // this.effectFlag = 0;
  311. // }
  312. if (this.wheelState == 1) {
  313. // cc.log('....加速,speed:' + this.curSpeed);
  314. this.spinTime += dt;
  315. this.wheelSp.node.angle = Math.abs(this.wheelSp.node.angle) + this.curSpeed;
  316. if (this.curSpeed <= this.maxSpeed) {
  317. this.curSpeed += this.acc;
  318. } else {
  319. if (this.spinTime < this.duration) {
  320. return;
  321. }
  322. // cc.log('....开始减速');
  323. //设置目标角度
  324. this.finalAngle = 360 - this.targetID * this.gearAngle - this.defaultAngle;
  325. this.maxSpeed = this.curSpeed;
  326. if (this.springback) {
  327. this.finalAngle += this.gearAngle;
  328. }
  329. this.wheelSp.node.angle = this.finalAngle;
  330. this.wheelState = 2;
  331. }
  332. } else if (this.wheelState == 2) {
  333. // cc.log('......减速');
  334. var curRo = Math.abs(this.wheelSp.node.angle); //应该等于finalAngle
  335. var hadRo = curRo - this.finalAngle;
  336. this.curSpeed = this.maxSpeed * ((this.decAngle - hadRo) / this.decAngle) + 0.1;
  337. this.wheelSp.node.angle = curRo + this.curSpeed;
  338. if ((this.decAngle - hadRo) <= 0) {
  339. // cc.log('....停止');
  340. this.wheelState = 0;
  341. this.wheelSp.node.angle = this.finalAngle;
  342. if (this.springback) {
  343. //倒转一个齿轮
  344. // var act = new cc.rotateBy(0.6, -this.gearAngle);
  345. var act = cc.rotateBy(0.6, -this.gearAngle);
  346. var seq = cc.sequence(cc.delayTime(0.2), act, cc.callFunc(this.showRes, this));
  347. this.wheelSp.node.runAction(seq);
  348. } else {
  349. this.showRes();
  350. }
  351. }
  352. }
  353. },
  354. showRes: function () {
  355. // console.log("随机转盘是",this.targetID);
  356. // this.targetID = 1;
  357. // this.targetID=7;
  358. this.Rewards.removeAllChildren();
  359. // 0 金币 x10
  360. // 1 随机建筑 x1
  361. // 2 金币 x50
  362. // 3 土地开发证件 x1
  363. // 4 金币 x10
  364. // 5 金币 x100
  365. // 6 金币 x10
  366. // 7 经营许可证 x1
  367. switch (this.targetID) {
  368. case 0:
  369. case 4:
  370. case 6:
  371. GlobalD.GameData.PlusGolden(10000);
  372. this.Rewards.getComponent(cc.Sprite).spriteFrame = this.Golden10;
  373. this.Rewards.scale=2;
  374. break;
  375. case 1:
  376. this.myScale = 0.2;
  377. // [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0];
  378. this.myScales = [
  379. 0.2,
  380. 0.2,
  381. 0.2,
  382. //3
  383. 1,
  384. 1,
  385. 1,
  386. 1,
  387. //7
  388. 1,
  389. 1,
  390. 1,
  391. 1,
  392. //11
  393. 1,
  394. 1,
  395. 1,
  396. 1,
  397. //15
  398. 1,
  399. 1,
  400. 1,
  401. 1.5,
  402. //19
  403. 1.5,
  404. 1,
  405. 1,
  406. 1,
  407. ];
  408. let BuildingLockStateArray = GlobalD.GameData.BuildingLockStateArray;
  409. // console.log("我当前有什么",BuildingLockStateArray);
  410. let HadBuildingArray = [];
  411. // console.log("我当前有什么 领取之前",GlobalD.GameData.BuildingNumArray);
  412. for(let i=3;i<BuildingLockStateArray.length;i++)
  413. {
  414. // cc.log('BuildingStateArray[i]='+BuildingStateArray[i]);
  415. if(parseInt(BuildingLockStateArray[i])==1)
  416. {
  417. HadBuildingArray.push(i);
  418. }
  419. }
  420. // console.log("我当前有什么 库存是 抽签",HadBuildingArray);
  421. let RandomIndex = this.GetRandomRange(0,HadBuildingArray.length-1);
  422. let BuildingNumArray = GlobalD.GameData.BuildingNumArray;
  423. // cc.log('BuildingNumArray[RandomIndex]===='+BuildingNumArray[RandomIndex]);
  424. let num = parseInt(BuildingNumArray[HadBuildingArray[RandomIndex]])+1;
  425. BuildingNumArray[HadBuildingArray[RandomIndex]] = num;
  426. // console.log("我当前有什么 库存是",BuildingNumArray,"索引是",RandomIndex);
  427. // console.log("我当前有什么 领取之后",BuildingNumArray);
  428. GlobalD.GameData.SetBuildingNumArray(BuildingNumArray);
  429. let SelectedBuildingIndex = HadBuildingArray[RandomIndex];
  430. // SelectedBuildingIndex = 19;
  431. let SelectedBuilding = this.ManageUI.getComponent('ManageBuildings').BuildingArray[SelectedBuildingIndex];
  432. SelectedBuilding.getChildByName('Name').getChildByName('Num').getComponent(cc.Label).string = num;
  433. // console.log("都有啥",this.ManageUI.getComponent('ManageBuildings').BuildingArray,"抽到啥",SelectedBuildingIndex);
  434. this.Rewards.getComponent(cc.Sprite).spriteFrame = "";
  435. if (SelectedBuildingIndex == 6) {
  436. var node = new cc.Node();
  437. var sprite = node.addComponent(cc.Sprite);
  438. sprite.spriteFrame = SelectedBuilding.getChildByName('New Sprite(Splash)').getComponent(cc.Sprite).spriteFrame;
  439. this.Rewards.addChild(node);
  440. var cnode = new cc.Node();
  441. var csprite = cnode.addComponent(cc.Sprite);
  442. cnode.y = 20;
  443. csprite.spriteFrame = SelectedBuilding.getChildByName('New Sprite(Splash)').getChildByName('Labour_01_2').getComponent(cc.Sprite).spriteFrame;
  444. node.addChild(cnode);
  445. }else{
  446. this.Rewards.getComponent(cc.Sprite).spriteFrame = SelectedBuilding.getChildByName('New Sprite(Splash)').getComponent(cc.Sprite).spriteFrame;
  447. }
  448. // console.log("现在是什么",SelectedBuildingIndex);
  449. // SelectedBuildingIndex
  450. this.Rewards.scale=this.myScales[SelectedBuildingIndex];
  451. break;
  452. case 2:
  453. GlobalD.GameData.PlusGolden(15000);
  454. this.Rewards.getComponent(cc.Sprite).spriteFrame = this.Golden50;
  455. this.Rewards.scale=2;
  456. break;
  457. case 3:
  458. case 7:
  459. let TerritoryStateArray = GlobalD.GameData.GetTerritoryStateArray();
  460. // for(let i=0;i<TerritoryStateArray.length;i++)
  461. // {
  462. // // console.log("结构遍历",TerritoryStateArray[i]);
  463. // if(TerritoryStateArray[i]==0)
  464. // {
  465. // TerritoryStateArray[i]=1;
  466. //
  467. // GlobalD.GameData.SetTerritoryStateArray(TerritoryStateArray);
  468. //
  469. // let _ManageMap = this.ManageMap.getComponent('ManageMap');
  470. // let Territory = _ManageMap.Territories[i];
  471. // //开土地后清空土地的占位信息
  472. // _ManageMap.onClearSolidArea(i);
  473. //
  474. //
  475. // // let Territory = this.ManageMap.getComponent('ManageMap').Territories[i];
  476. // Territory.enabled = false;
  477. // this.Rewards.getComponent(cc.Sprite).spriteFrame = this.LandDevelopmentCertificate;
  478. // // console.log("结构",this.Rewards);
  479. // this.Rewards.scale=2;
  480. // break;
  481. // }
  482. // }
  483. if (this.targetID == 3) {
  484. GlobalD.GameData.PlusDiamond(250);
  485. UtilsPrefabs.loadResSpriteFrame('taskres/diamond_1',function (texture) {
  486. // var prefab = cc.instantiate(texture);
  487. this.Rewards.getComponent(cc.Sprite).spriteFrame = texture;
  488. this.Rewards.scale=2;
  489. }.bind(this));
  490. }else if (this.targetID == 7) {
  491. GlobalD.GameData.PlusDiamond(350);
  492. UtilsPrefabs.loadResSpriteFrame('taskres/diamond_2',function (texture) {
  493. // var prefab = cc.instantiate(texture);
  494. this.Rewards.getComponent(cc.Sprite).spriteFrame = texture;
  495. this.Rewards.scale=2;
  496. }.bind(this));
  497. }
  498. break;
  499. case 5:
  500. GlobalD.GameData.PlusGolden(30000);
  501. this.Rewards.getComponent(cc.Sprite).spriteFrame = this.Golden100;
  502. this.Rewards.scale=2;
  503. break;
  504. // case 7:
  505. //
  506. // var BuildingStateArray = GlobalD.GameData.BuildingStateArray;
  507. //
  508. // for(let i=3;i<BuildingStateArray.length;i++)
  509. // {
  510. // cc.log('BuildingStateArray[i]='+BuildingStateArray[i]);
  511. // if(BuildingStateArray[i]==0)
  512. // {
  513. // BuildingStateArray[i]=1;
  514. // GlobalD.GameData.SetBuildingStateArray(BuildingStateArray);
  515. //
  516. // let Building = this.ManageUI.getComponent('ManageBuildings').BuildingArray[i];
  517. // Building.active = true;
  518. // this.Rewards.getComponent(cc.Sprite).spriteFrame = Building.getChildByName('New Sprite(Splash)').getComponent(cc.Sprite).spriteFrame;
  519. // this.Rewards.scale=1;
  520. //
  521. // break;
  522. // }
  523. // }
  524. //
  525. // break;
  526. default:
  527. break;
  528. }
  529. // console.log("结果是",this.RewardDetail[this.targetID]);
  530. this.showDialog();
  531. },
  532. isTask : function(){
  533. if (task.TaskIconCountClick == 5) {
  534. task.addTaskIconCountClick();
  535. task.removeTaskNodes();
  536. }
  537. },
  538. _showShareDialog: function (callback) {
  539. cc.loader.loadRes("prefab/share", function (err, texture) {
  540. this.shares = cc.instantiate(texture);
  541. this._closeShareDialog();
  542. this.node.parent.addChild(this.shares);
  543. this.gosharebtn = this.getNode("gosharebtn",this.shares);
  544. // this.close = this.getNode("close",this.dialogLuckView);
  545. this.gosharebtn.off(cc.Node.EventType.TOUCH_END);
  546. var img1 = UtilsPrefabs.getNode("img1",this.shares);
  547. var NewLabel1 = UtilsPrefabs.getNode("New Label",img1);
  548. var img2 = UtilsPrefabs.getNode("img2",this.shares);
  549. var NewLabel2 = UtilsPrefabs.getNode("New Label",img2);
  550. NewLabel1.getComponent(cc.Label).string = 'x'+GlobalD.GameData.shareGive[0];
  551. NewLabel2.getComponent(cc.Label).string = 'x'+GlobalD.GameData.shareGive[1];
  552. if (callback != null) {
  553. callback();
  554. }
  555. }.bind(this));
  556. },
  557. showDialog: function () {
  558. this.node.active = false;
  559. var Sunshine = this.ShowRewards.getChildByName('GivePrize').getChildByName('Sunshine');
  560. var GivePrize = this.ShowRewards.getChildByName('GivePrize');
  561. Sunshine.scaleX = 0;
  562. Sunshine.scaleY = 0;
  563. GivePrize.scaleX = 0;
  564. GivePrize.scaleY = 0;
  565. Sunshine.stopAllActions();
  566. GivePrize.stopAllActions();
  567. this.scheduleOnce(function () {
  568. this.ShowRewards.opacity = 255;
  569. this.ShowRewards.active = true;
  570. var sc2 = cc.scaleTo(0.5,1.2,1.2);
  571. Sunshine.runAction(sc2);
  572. var sc3 = cc.scaleTo(0.5,1,1);
  573. GivePrize.runAction(sc3);
  574. var repeat = cc.repeatForever(cc.rotateBy(5.0, 360));
  575. Sunshine.runAction(repeat);
  576. }, 0.1);
  577. },
  578. GetRandomRange(n, m){
  579. var random = Math.floor(Math.random()*(m-n+1)+n);
  580. return random;
  581. },
  582. _showDialog: function (callback) {
  583. cc.loader.loadRes("prefab/dialogLuckView", function (err, texture) {
  584. this.dialogLuckView = cc.instantiate(texture);
  585. if (this.node.getChildByName(this.dialogLuckView.name) != null) {
  586. this.node.getChildByName(this.dialogLuckView.name).destroy();
  587. }
  588. this.node.addChild(this.dialogLuckView);
  589. // this.dialogLuckView.active = false;
  590. this.dialogLuckView.y=-100;
  591. this.watchvideo = this.getNode("watchvideo",this.dialogLuckView);
  592. this.close = this.getNode("close",this.dialogLuckView);
  593. if (callback != null) {
  594. callback();
  595. }
  596. }.bind(this));
  597. },
  598. _closeDialog: function () {
  599. if (this.node.getChildByName(this.dialogLuckView.name) != null) {
  600. this.node.getChildByName(this.dialogLuckView.name).destroy();
  601. }
  602. },
  603. _closeShareDialog: function () {
  604. if (this.node.parent.getChildByName(this.shares.name) != null) {
  605. this.node.parent.getChildByName(this.shares.name).destroy();
  606. }
  607. },
  608. getNode: function (name, parent) {
  609. if (parent == null) {
  610. return this.node.getChildByName(name);
  611. } else {
  612. return parent.getChildByName(name);
  613. }
  614. },
  615. });
  616. class GLRandom {
  617. /**
  618. * 构造函数
  619. * @param {number} min 最小整数值
  620. * @param {number} max 最大整数值
  621. * @param {Map} percentage 概率数 [值,百分比]
  622. */
  623. constructor(min, max, percentage = new Map()) {
  624. this.min = Math.trunc(min);
  625. this.max = Math.trunc(max);
  626. this.MATH_RANGE = 100; // 分成100份
  627. this.percentage = percentage;
  628. }
  629. get percentage() {
  630. if (!this._percentage) {
  631. this._percentage = new Map();
  632. }
  633. return this._percentage;
  634. }
  635. /**
  636. * 分配比例
  637. * @param {Map} map 设置 值-百分比
  638. */
  639. set percentage(map) {
  640. let result = Array.from(map.values()).reduce((p, v, a) => {
  641. return p - v;
  642. }, 1);
  643. for (let i = this.min; i < this.max; i++) {
  644. if (map.has(i)) {
  645. this.percentage.set(i, map.get(i));
  646. } else {
  647. this.percentage.set(i, result / (this.max - this.min - map.size));
  648. }
  649. }
  650. }
  651. /**
  652. * 根据比例生成取值范围
  653. */
  654. range() {
  655. let [start, random, keys] = [0, this.MATH_RANGE, Array.from(this.percentage.keys())];
  656. for (let i = 0; i < keys.length; i++) {
  657. let temp = this.percentage.get(keys[i]);
  658. this.percentage.set(keys[i], [start, start += temp * random]);
  659. }
  660. }
  661. /**
  662. * 生成随机数
  663. */
  664. create() {
  665. let num = Math.random() * this.MATH_RANGE;
  666. for (let data of this.percentage.entries()) {
  667. if (num >= data[1][0] && num < data[1][1]) {
  668. return data[0];
  669. }
  670. }
  671. return null;
  672. }
  673. }