Wheel.js 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906
  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. ManageAd: cc.Node,
  95. },
  96. // use this for initialization
  97. onLoad: function () {
  98. // cc.log("....onload");
  99. // console.log("....onload");
  100. //消耗钻石数量
  101. this.Diamond = 100;
  102. this.spin = this.getNode("spin");
  103. this.Sprite = this.getNode("New Sprite", this.spin);
  104. this.Label = this.getNode("New Label", this.spin);
  105. this.Label.getComponent(cc.Label).string = this.Diamond;
  106. // GlobalD.GameData.SetDiamond(100);
  107. this.wheelState = 0;
  108. this.curSpeed = 0;
  109. this.spinTime = 0; //减速前旋转时间
  110. this.gearNum = 8;
  111. this.defaultAngle = 360 / this.gearNum / 2; //修正默认角度
  112. this.gearAngle = 360 / this.gearNum; //每个齿轮的角度
  113. this.wheelSp.node.angle = -this.defaultAngle;
  114. // console.log("修正默认角度",this.defaultAngle);
  115. this.finalAngle = 0; //最终结果指定的角度
  116. this.effectFlag = 0; //用于音效播放
  117. this.restMaxSpeed = this.maxSpeed;
  118. this.duration = 1;
  119. if (!cc.sys.isBrowser) {
  120. cc.loader.loadRes('Sound/game_turntable', function (err, res) {
  121. if (err) {
  122. // cc.log('...err:' + err);
  123. }
  124. });
  125. }
  126. this.spinBtn.node.on(cc.Node.EventType.TOUCH_END, function (event) {
  127. // cc.log("begin spin");
  128. if (this.wheelState !== 0) {
  129. return;
  130. }
  131. // if (GlobalD.GameData.GetDiamond()>=this.Diamond) {
  132. // GlobalD.GameData.PlusDiamond(-this.Diamond);
  133. //
  134. // this.startLuck();
  135. //
  136. //
  137. // }else{
  138. // // cc.log("没"+this.Diamond+"钻石转不了");
  139. //
  140. // this._showDialog(function () {
  141. // this.watchvideo.on(cc.Node.EventType.TOUCH_END, function (event) {
  142. // this.startLuck();
  143. // this._closeDialog();
  144. // }.bind(this));
  145. // this.close.on(cc.Node.EventType.TOUCH_END, function (event) {
  146. // this._closeDialog();
  147. // }.bind(this));
  148. // }.bind(this));
  149. // }
  150. //每日签到
  151. let myDate = new Date();
  152. //'2019/05/01'
  153. let Today = myDate.toLocaleDateString();
  154. let LastTimeLuckDate = GlobalD.GameData.GetLastTimeLuckDate();
  155. // LastTimeLuckDate = "2019/3/20";
  156. let s = "2019/3/20"
  157. console.log("today", Today);
  158. console.log("LastTimeLuckDate", LastTimeLuckDate);
  159. // GlobalD.GameData.SetLotteryTimes(10);
  160. if (Today == LastTimeLuckDate && LastTimeLuckDate != '0000/00/00') {
  161. }
  162. else {
  163. // console.log("走着么");
  164. //过了一天
  165. GlobalD.GameData.SetLotteryTimes(10);
  166. // GlobalD.GameData.SetLastTimeLuckDate(Today);
  167. GlobalD.GameData.SetLastTimeLuckDate(Today);
  168. }
  169. if (GlobalD.GameData.GetLotteryTimes() > 0) {
  170. //预加载广告
  171. // 'adunit-96a5ca68065cc57a',//视频激励广告4
  172. AD.loadVideoAdFromIndex('Wheel', 1, (res) => {
  173. console.log('预加载广告回调:', res);
  174. });
  175. this._showDialog(function () {
  176. this.watchvideo.on(cc.Node.EventType.TOUCH_END, function (event) {
  177. //关闭一下底部广告组件
  178. this.ManageAd.getComponent('ManageAd').onCloseBannerAd();
  179. //观看广告视频
  180. AD.playVideoAd((res) => {
  181. if (!res.isPlay) {
  182. console.log('不能播放广告:', res.data);
  183. } else {
  184. this.startLuck();
  185. }
  186. });
  187. this._closeDialog();
  188. }.bind(this));
  189. this.close.on(cc.Node.EventType.TOUCH_END, function (event) {
  190. this._closeDialog();
  191. }.bind(this));
  192. }.bind(this));
  193. // cc.log('11111111=='+GlobalD.GameData.GetLotteryTimes())
  194. GlobalD.GameData.PlusLotteryTimes(-1);
  195. }
  196. else {
  197. cc.loader.loadRes('resUI/ShowNotEnoughMoney', function (err, texture) {
  198. var prefab = cc.instantiate(texture);
  199. prefab.getComponent('ShowNotEnoughMoney').Text('明天再来试试手气吧!');
  200. this.node.addChild(prefab);
  201. }.bind(this));
  202. }
  203. }.bind(this));
  204. //初始化网络引用资源
  205. // this.initSpriteFrame();
  206. this.initNetwork();
  207. },
  208. initNetwork: function () {
  209. UtilsPrefabs.loadResSpriteFrame('taskres/diamond_1', function (texture) {
  210. }.bind(this));
  211. UtilsPrefabs.loadResSpriteFrame('taskres/diamond_2', function (texture) {
  212. }.bind(this));
  213. },
  214. startLuck: function () {
  215. this.getRandom();
  216. this.decAngle = 1 * 360; // 减速旋转两圈
  217. this.wheelState = 1;
  218. this.curSpeed = 0;
  219. this.spinTime = 0;
  220. this.maxSpeed = this.restMaxSpeed;
  221. },
  222. mystart: function () {
  223. // console.log("自己的开始", this.wheelSp);
  224. },
  225. initSpriteFrame: function () {
  226. cc.loader.loadRes('Luckdraw/Wheel_03', cc.SpriteFrame, function (err, texture) {
  227. this.wheelSp.spriteFrame = texture;
  228. }.bind(this));
  229. cc.loader.loadRes('Luckdraw/Wheel_01', cc.SpriteFrame, function (err, texture) {
  230. this.startbtn.spriteFrame = texture;
  231. }.bind(this));
  232. cc.loader.loadRes('Luckdraw/Wheel_02', cc.SpriteFrame, function (err, texture) {
  233. this.pointer.spriteFrame = texture;
  234. }.bind(this));
  235. cc.loader.loadRes('Luckdraw/Wheel_05', cc.SpriteFrame, function (err, texture) {
  236. this.title.spriteFrame = texture;
  237. }.bind(this));
  238. cc.loader.loadRes('Luckdraw/Wheel_04', cc.SpriteFrame, function (err, texture) {
  239. this.background.spriteFrame = texture;
  240. // console.log("网络资源加载完毕");
  241. }.bind(this));
  242. },
  243. start: function () {
  244. // cc.log('....start');
  245. },
  246. caculateFinalAngle: function (targetID) {
  247. this.finalAngle = 360 - this.targetID * this.gearAngle + this.defaultAngle;
  248. if (this.springback) {
  249. this.finalAngle += this.gearAngle;
  250. }
  251. },
  252. editBoxDidBegin: function (edit) {
  253. },
  254. editBoxDidChanged: function (text) {
  255. },
  256. editBoxDidEndEditing: function (edit) {
  257. var res = parseInt(edit.string);
  258. if (isNaN(res)) {
  259. if (cc.sys.isBrowser) {
  260. // alert('please input a number!');
  261. } else {
  262. // cc.log(".....invalid input");
  263. }
  264. this.targetID = Math.round(Math.random() * (this.gearNum - 1));
  265. // cc.log("停止的位置是", this.targetID);
  266. return;
  267. }
  268. this.targetID = res;
  269. },
  270. getRandom: function () {
  271. let TerritoryStateArray = GlobalD.GameData.GetTerritoryStateArray();
  272. var BuildingStateArray = GlobalD.GameData.BuildingStateArray;
  273. var tempcout = 0;
  274. var tempcout7 = 0;
  275. var probability = 0.1;
  276. var probability7 = 0.1;
  277. var probability100 = 0.1;
  278. var probability10 = 0.15;
  279. for (let i = 0; i < TerritoryStateArray.length; i++) {
  280. // console.log("结构遍历",TerritoryStateArray[i]);
  281. if (TerritoryStateArray[i] == 1) {
  282. tempcout++;
  283. }
  284. }
  285. for (let i = 0; i < BuildingStateArray.length; i++) {
  286. // console.log("结构遍历",BuildingStateArray[i]);
  287. if (BuildingStateArray[i] == 1) {
  288. tempcout7++;
  289. }
  290. }
  291. if (tempcout == TerritoryStateArray.length) {
  292. //没有能开的了
  293. probability = 0;
  294. probability100 = 0.1;
  295. probability10 = 0.2;
  296. }
  297. if (tempcout7 == BuildingStateArray.length) {
  298. //没有能开的了
  299. probability7 = 0;
  300. probability100 = 0.1;
  301. probability10 = 0.2;
  302. }
  303. // console.log("设置概率",tempcout,probability);
  304. // 随机数范围 :40~900
  305. let random = new GLRandom(0, this.gearNum);
  306. // 0 金币 x10
  307. // 1 随机建筑 x1
  308. // 2 金币 x50
  309. // 3 土地开发证件 x1
  310. // 4 金币 x10
  311. // 5 金币 x100
  312. // 6 金币 x10
  313. // 7 经营许可证 x1
  314. // 调整概率
  315. random.percentage = new Map([
  316. [0, 0.2], // 调整值为41的数值,概率为20%
  317. [1, 0.05], // 调整值为41的数值,概率为20%
  318. [2, 0.1], // 调整值为41的数值,概率为20%
  319. [3, 0.1], // 调整值为41的数值,概率为20%
  320. [4, 0.2], // 调整值为41的数值,概率为20%
  321. [5, 0.1], // 调整值为41的数值,概率为20%
  322. [6, 0.2], // 调整值为41的数值,概率为20%
  323. [7, 0.05], // 调整值为46的数值,概率为50%
  324. ]);
  325. // 生成值区间
  326. random.range();
  327. this.targetID = random.create();
  328. // 生成概率随机数
  329. // console.log("停止的位置是区间随机数", this.targetID);
  330. // this.targetID = Math.round(Math.random() * (this.gearNum - 1));
  331. // cc.log("停止的位置是", this.targetID);
  332. },
  333. // called every frame, uncomment this function to activate update callback
  334. update: function (dt) {
  335. if (this.wheelState === 0) {
  336. return;
  337. }
  338. // cc.log('......update');
  339. // cc.log('......state=%d',this.wheelState);
  340. // 播放音效有可能卡
  341. // this.effectFlag += this.curSpeed;
  342. // if (!cc.sys.isBrowser && this.effectFlag >= this.gearAngle) {
  343. // if (this.audioID) {
  344. // // cc.audioEngine.pauseEffect(this.audioID);
  345. // }
  346. // // this.audioID = cc.audioEngine.playEffect(this.effectAudio,false);
  347. // this.audioID = cc.audioEngine.playEffect(cc.url.raw('resources/Sound/game_turntable.mp3'));
  348. // this.effectFlag = 0;
  349. // }
  350. if (this.wheelState == 1) {
  351. // cc.log('....加速,speed:' + this.curSpeed);
  352. this.spinTime += dt;
  353. this.wheelSp.node.angle = Math.abs(this.wheelSp.node.angle) + this.curSpeed;
  354. if (this.curSpeed <= this.maxSpeed) {
  355. this.curSpeed += this.acc;
  356. } else {
  357. if (this.spinTime < this.duration) {
  358. return;
  359. }
  360. // cc.log('....开始减速');
  361. //设置目标角度
  362. this.finalAngle = 360 - this.targetID * this.gearAngle - this.defaultAngle;
  363. this.maxSpeed = this.curSpeed;
  364. if (this.springback) {
  365. this.finalAngle += this.gearAngle;
  366. }
  367. this.wheelSp.node.angle = this.finalAngle;
  368. this.wheelState = 2;
  369. }
  370. } else if (this.wheelState == 2) {
  371. // cc.log('......减速');
  372. var curRo = Math.abs(this.wheelSp.node.angle); //应该等于finalAngle
  373. var hadRo = curRo - this.finalAngle;
  374. this.curSpeed = this.maxSpeed * ((this.decAngle - hadRo) / this.decAngle) + 0.1;
  375. this.wheelSp.node.angle = curRo + this.curSpeed;
  376. if ((this.decAngle - hadRo) <= 0) {
  377. // cc.log('....停止');
  378. this.wheelState = 0;
  379. this.wheelSp.node.angle = this.finalAngle;
  380. if (this.springback) {
  381. //倒转一个齿轮
  382. // var act = new cc.rotateBy(0.6, -this.gearAngle);
  383. var act = cc.rotateBy(0.6, -this.gearAngle);
  384. var seq = cc.sequence(cc.delayTime(0.2), act, cc.callFunc(this.showRes, this));
  385. this.wheelSp.node.runAction(seq);
  386. } else {
  387. this.showRes();
  388. }
  389. }
  390. }
  391. },
  392. showRes: function () {
  393. // console.log("随机转盘是",this.targetID);
  394. // this.targetID = 1;
  395. // this.targetID=7;
  396. this.Rewards.removeAllChildren();
  397. // 0 金币 x10
  398. // 1 随机建筑 x1
  399. // 2 金币 x50
  400. // 3 土地开发证件 x1
  401. // 4 金币 x10
  402. // 5 金币 x100
  403. // 6 金币 x10
  404. // 7 经营许可证 x1
  405. switch (this.targetID) {
  406. case 0:
  407. case 4:
  408. case 6:
  409. GlobalD.GameData.PlusGolden(10000);
  410. this.Rewards.getComponent(cc.Sprite).spriteFrame = this.Golden10;
  411. this.Rewards.scale = 2;
  412. this.showShareDialogManager1(this.targetID);
  413. break;
  414. case 1:
  415. this.myScale = 0.2;
  416. // [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0];
  417. this.myScales = [
  418. 0.2,
  419. 0.2,
  420. 0.2,
  421. //3
  422. 1,
  423. 1,
  424. 1,
  425. 1,
  426. //7
  427. 1,
  428. 1,
  429. 1,
  430. 1,
  431. //11
  432. 1,
  433. 1,
  434. 1,
  435. 1,
  436. //15
  437. 1,
  438. 1,
  439. 1,
  440. 1.5,
  441. //19
  442. 1.5,
  443. 1,
  444. 1,
  445. 1,
  446. ];
  447. let BuildingLockStateArray = GlobalD.GameData.BuildingLockStateArray;
  448. // console.log("我当前有什么",BuildingLockStateArray);
  449. let HadBuildingArray = [];
  450. // console.log("我当前有什么 领取之前",GlobalD.GameData.BuildingNumArray);
  451. for (let i = 3; i < BuildingLockStateArray.length; i++) {
  452. // cc.log('BuildingStateArray[i]='+BuildingStateArray[i]);
  453. if (parseInt(BuildingLockStateArray[i]) == 1) {
  454. HadBuildingArray.push(i);
  455. }
  456. }
  457. // console.log("我当前有什么 库存是 抽签",HadBuildingArray);
  458. let RandomIndex = this.GetRandomRange(0, HadBuildingArray.length - 1);
  459. let BuildingNumArray = GlobalD.GameData.BuildingNumArray;
  460. // cc.log('BuildingNumArray[RandomIndex]===='+BuildingNumArray[RandomIndex]);
  461. let num = parseInt(BuildingNumArray[HadBuildingArray[RandomIndex]]) + 1;
  462. BuildingNumArray[HadBuildingArray[RandomIndex]] = num;
  463. // console.log("我当前有什么 库存是",BuildingNumArray,"索引是",RandomIndex);
  464. // console.log("我当前有什么 领取之后",BuildingNumArray);
  465. GlobalD.GameData.SetBuildingNumArray(BuildingNumArray);
  466. let SelectedBuildingIndex = HadBuildingArray[RandomIndex];
  467. // SelectedBuildingIndex = 19;
  468. let SelectedBuilding = this.ManageUI.getComponent('ManageBuildings').BuildingArray[SelectedBuildingIndex];
  469. SelectedBuilding.getChildByName('Name').getChildByName('Num').getComponent(cc.Label).string = num;
  470. // console.log("都有啥",this.ManageUI.getComponent('ManageBuildings').BuildingArray,"抽到啥",SelectedBuildingIndex);
  471. this.Rewards.getComponent(cc.Sprite).spriteFrame = "";
  472. if (SelectedBuildingIndex == 6) {
  473. var node = new cc.Node();
  474. var sprite = node.addComponent(cc.Sprite);
  475. sprite.spriteFrame = SelectedBuilding.getChildByName('New Sprite(Splash)').getComponent(cc.Sprite).spriteFrame;
  476. this.Rewards.addChild(node);
  477. var cnode = new cc.Node();
  478. var csprite = cnode.addComponent(cc.Sprite);
  479. cnode.y = 20;
  480. csprite.spriteFrame = SelectedBuilding.getChildByName('New Sprite(Splash)').getChildByName('Labour_01_2').getComponent(cc.Sprite).spriteFrame;
  481. node.addChild(cnode);
  482. } else {
  483. this.Rewards.getComponent(cc.Sprite).spriteFrame = SelectedBuilding.getChildByName('New Sprite(Splash)').getComponent(cc.Sprite).spriteFrame;
  484. }
  485. // console.log("现在是什么",SelectedBuildingIndex);
  486. // SelectedBuildingIndex
  487. this.Rewards.scale = this.myScales[SelectedBuildingIndex];
  488. this.showShareDialogManager(this.targetID);
  489. break;
  490. case 2:
  491. GlobalD.GameData.PlusGolden(15000);
  492. this.Rewards.getComponent(cc.Sprite).spriteFrame = this.Golden50;
  493. this.Rewards.scale = 2;
  494. this.showShareDialogManager1(this.targetID);
  495. break;
  496. case 3:
  497. case 7:
  498. let TerritoryStateArray = GlobalD.GameData.GetTerritoryStateArray();
  499. // for(let i=0;i<TerritoryStateArray.length;i++)
  500. // {
  501. // // console.log("结构遍历",TerritoryStateArray[i]);
  502. // if(TerritoryStateArray[i]==0)
  503. // {
  504. // TerritoryStateArray[i]=1;
  505. //
  506. // GlobalD.GameData.SetTerritoryStateArray(TerritoryStateArray);
  507. //
  508. // let _ManageMap = this.ManageMap.getComponent('ManageMap');
  509. // let Territory = _ManageMap.Territories[i];
  510. // //开土地后清空土地的占位信息
  511. // _ManageMap.onClearSolidArea(i);
  512. //
  513. //
  514. // // let Territory = this.ManageMap.getComponent('ManageMap').Territories[i];
  515. // Territory.enabled = false;
  516. // this.Rewards.getComponent(cc.Sprite).spriteFrame = this.LandDevelopmentCertificate;
  517. // // console.log("结构",this.Rewards);
  518. // this.Rewards.scale=2;
  519. // this.showShareDialogManager(this.targetID);
  520. // break;
  521. // }
  522. // }
  523. if (this.targetID == 3) {
  524. GlobalD.GameData.PlusDiamond(250);
  525. UtilsPrefabs.loadResSpriteFrame('taskres/diamond_1', function (texture) {
  526. // var prefab = cc.instantiate(texture);
  527. this.Rewards.getComponent(cc.Sprite).spriteFrame = texture;
  528. this.Rewards.scale = 2;
  529. }.bind(this));
  530. } else if (this.targetID == 7) {
  531. GlobalD.GameData.PlusDiamond(350);
  532. UtilsPrefabs.loadResSpriteFrame('taskres/diamond_2', function (texture) {
  533. // var prefab = cc.instantiate(texture);
  534. this.Rewards.getComponent(cc.Sprite).spriteFrame = texture;
  535. this.Rewards.scale = 2;
  536. }.bind(this));
  537. }
  538. break;
  539. case 5:
  540. GlobalD.GameData.PlusGolden(30000);
  541. this.Rewards.getComponent(cc.Sprite).spriteFrame = this.Golden100;
  542. this.Rewards.scale = 2;
  543. this.showShareDialogManager1(this.targetID);
  544. break;
  545. // case 7:
  546. //
  547. // var BuildingStateArray = GlobalD.GameData.BuildingStateArray;
  548. //
  549. // for(let i=3;i<BuildingStateArray.length;i++)
  550. // {
  551. // cc.log('BuildingStateArray[i]='+BuildingStateArray[i]);
  552. // if(BuildingStateArray[i]==0)
  553. // {
  554. // BuildingStateArray[i]=1;
  555. // GlobalD.GameData.SetBuildingStateArray(BuildingStateArray);
  556. //
  557. // let Building = this.ManageUI.getComponent('ManageBuildings').BuildingArray[i];
  558. // Building.active = true;
  559. // this.Rewards.getComponent(cc.Sprite).spriteFrame = Building.getChildByName('New Sprite(Splash)').getComponent(cc.Sprite).spriteFrame;
  560. // this.Rewards.scale=1;
  561. // this.showShareDialogManager(this.targetID);
  562. //
  563. // break;
  564. // }
  565. // }
  566. //
  567. // break;
  568. default:
  569. break;
  570. }
  571. // console.log("结果是",this.RewardDetail[this.targetID]);
  572. this.showDialog();
  573. },
  574. showShareDialogManager: function (targetID) {
  575. // this._showShareDialog(function () {
  576. // this.gosharebtn.on(cc.Node.EventType.TOUCH_END, function (event) {
  577. // console.log("点击分享按钮");
  578. // UtilsWX.sharebtn();
  579. // this._closeShareDialog();
  580. // GlobalD.GameData.PlusGolden(GlobalD.GameData.shareGive[0]);
  581. // GlobalD.GameData.PlusDiamond(GlobalD.GameData.shareGive[1]);
  582. //
  583. // }.bind(this));
  584. // }.bind(this));
  585. return;
  586. setTimeout(function () {
  587. UtilsPrefabs
  588. .init(this.node.parent)
  589. .addPrefabs(UtilsPrefabs.sharePrefab[0], null, function (node) {
  590. var gosharebtn = UtilsPrefabs.getNode("gosharebtn", node);
  591. var img1 = UtilsPrefabs.getNode("img1", node);
  592. var NewLabel1 = UtilsPrefabs.getNode("New Label", img1);
  593. var img2 = UtilsPrefabs.getNode("img2", node);
  594. var NewLabel2 = UtilsPrefabs.getNode("New Label", img2);
  595. // NewLabel1.getComponent(cc.Label).string = 'x'+GlobalD.GameData.signInGive[0];
  596. // NewLabel2.getComponent(cc.Label).string = 'x'+GlobalD.GameData.signInGive[1];
  597. var close = UtilsPrefabs.getNode("close", node);
  598. UtilsPrefabs.setOn(close, function () {
  599. UtilsPrefabs.removePrefabs(this.node.parent, node.name);
  600. }.bind(this))
  601. UtilsPrefabs.setOn(gosharebtn, function () {
  602. // console.log("点击分享按钮");
  603. UtilsWX.sharebtn();
  604. UtilsPrefabs.setOff(gosharebtn);
  605. UtilsPrefabs.removePrefabs(this.node.parent, node.name);
  606. GlobalD.GameData.PlusGolden(GlobalD.GameData.signInGive[0]);
  607. GlobalD.GameData.PlusDiamond(GlobalD.GameData.signInGive[1]);
  608. }.bind(this))
  609. }.bind(this));
  610. }.bind(this), 1000);
  611. },
  612. isTask: function () {
  613. if (task.TaskIconCountClick == 5) {
  614. task.addTaskIconCountClick();
  615. task.removeTaskNodes();
  616. }
  617. },
  618. showShareDialogManager1: function (targetID) {
  619. // this._showShareDialog(function () {
  620. // this.gosharebtn.on(cc.Node.EventType.TOUCH_END, function (event) {
  621. // console.log("点击分享按钮");
  622. // UtilsWX.sharebtn();
  623. // this._closeShareDialog();
  624. // GlobalD.GameData.PlusGolden(GlobalD.GameData.shareGive[0]);
  625. // GlobalD.GameData.PlusDiamond(GlobalD.GameData.shareGive[1]);
  626. //
  627. // }.bind(this));
  628. // }.bind(this));
  629. return;
  630. setTimeout(function () {
  631. UtilsPrefabs
  632. .init(this.node.parent)
  633. .addPrefabs(UtilsPrefabs.sharePrefab[1], null, function (node) {
  634. var gosharebtn = UtilsPrefabs.getNode("gosharebtn", node);
  635. var img1 = UtilsPrefabs.getNode("img1", node);
  636. var NewLabel1 = UtilsPrefabs.getNode("New Label", img1);
  637. var img2 = UtilsPrefabs.getNode("img2", node);
  638. var NewLabel2 = UtilsPrefabs.getNode("New Label", img2);
  639. // NewLabel1.getComponent(cc.Label).string = 'x'+GlobalD.GameData.signInGive[0];
  640. // NewLabel2.getComponent(cc.Label).string = 'x'+GlobalD.GameData.signInGive[1];
  641. // var infoLabel = UtilsPrefabs.getNode("infoLabel",node);
  642. // infoLabel.getComponent(cc.Label).string = "去分享";
  643. var close = UtilsPrefabs.getNode("close", node);
  644. UtilsPrefabs.setOn(close, function () {
  645. UtilsPrefabs.removePrefabs(this.node.parent, node.name);
  646. }.bind(this))
  647. UtilsPrefabs.setOn(gosharebtn, function () {
  648. // console.log("点击分享按钮");
  649. UtilsWX.sharebtn();
  650. UtilsPrefabs.setOff(gosharebtn);
  651. UtilsPrefabs.removePrefabs(this.node.parent, node.name);
  652. GlobalD.GameData.PlusGolden(GlobalD.GameData.signInGive[0]);
  653. GlobalD.GameData.PlusDiamond(GlobalD.GameData.signInGive[1]);
  654. }.bind(this))
  655. }.bind(this));
  656. }.bind(this), 1000);
  657. },
  658. _showShareDialog: function (callback) {
  659. cc.loader.loadRes("prefab/share", function (err, texture) {
  660. this.shares = cc.instantiate(texture);
  661. this._closeShareDialog();
  662. this.node.parent.addChild(this.shares);
  663. this.gosharebtn = this.getNode("gosharebtn", this.shares);
  664. // this.close = this.getNode("close",this.dialogLuckView);
  665. this.gosharebtn.off(cc.Node.EventType.TOUCH_END);
  666. var img1 = UtilsPrefabs.getNode("img1", this.shares);
  667. var NewLabel1 = UtilsPrefabs.getNode("New Label", img1);
  668. var img2 = UtilsPrefabs.getNode("img2", this.shares);
  669. var NewLabel2 = UtilsPrefabs.getNode("New Label", img2);
  670. NewLabel1.getComponent(cc.Label).string = 'x' + GlobalD.GameData.shareGive[0];
  671. NewLabel2.getComponent(cc.Label).string = 'x' + GlobalD.GameData.shareGive[1];
  672. if (callback != null) {
  673. callback();
  674. }
  675. }.bind(this));
  676. },
  677. showDialog: function () {
  678. // cc.loader.loadRes("test assets/prefab", function (err, prefab) {
  679. // var newNode = cc.instantiate(prefab);
  680. //
  681. // });
  682. this.node.active = false;
  683. var Sunshine = this.ShowRewards.getChildByName('GivePrize').getChildByName('Sunshine');
  684. var GivePrize = this.ShowRewards.getChildByName('GivePrize');
  685. Sunshine.scaleX = 0;
  686. Sunshine.scaleY = 0;
  687. GivePrize.scaleX = 0;
  688. GivePrize.scaleY = 0;
  689. Sunshine.stopAllActions();
  690. GivePrize.stopAllActions();
  691. this.scheduleOnce(function () {
  692. this.ShowRewards.opacity = 255;
  693. this.ShowRewards.active = true;
  694. var sc2 = cc.scaleTo(0.5, 0.5, 0.5);
  695. Sunshine.runAction(sc2);
  696. var sc3 = cc.scaleTo(0.5, 1, 1);
  697. GivePrize.runAction(sc3);
  698. var repeat = cc.repeatForever(cc.rotateBy(5.0, 360));
  699. Sunshine.runAction(repeat);
  700. }, 0.1);
  701. this.scheduleOnce(function () {
  702. // let Particle = this.ShowRewards.getChildByName('GivePrize').getChildByName('Particle');
  703. // Particle.active = true;
  704. // Particle.getComponent(cc.ParticleSystem).resetSystem();
  705. // this.scheduleOnce(function () {
  706. // Particle.active = false;
  707. // }, 2);
  708. }, 0.5);
  709. // this.ShowRewards.getChildByName('GivePrize').getChildByName('share').off(cc.Node.EventType.TOUCH_END);
  710. // this.ShowRewards.getChildByName('GivePrize').getChildByName('share').on(cc.Node.EventType.TOUCH_END, function (event) {
  711. // console.log("点击分享按钮");
  712. // UtilsWX.sharebtn();
  713. // }.bind(this));
  714. },
  715. GetRandomRange(n, m) {
  716. var random = Math.floor(Math.random() * (m - n + 1) + n);
  717. return random;
  718. },
  719. _showDialog: function (callback) {
  720. cc.loader.loadRes("prefab/dialogLuckView", function (err, texture) {
  721. this.dialogLuckView = cc.instantiate(texture);
  722. if (this.node.getChildByName(this.dialogLuckView.name) != null) {
  723. this.node.getChildByName(this.dialogLuckView.name).destroy();
  724. }
  725. this.node.addChild(this.dialogLuckView);
  726. // this.dialogLuckView.active = false;
  727. this.dialogLuckView.y = -100;
  728. this.watchvideo = this.getNode("watchvideo", this.dialogLuckView);
  729. this.close = this.getNode("close", this.dialogLuckView);
  730. if (callback != null) {
  731. callback();
  732. }
  733. }.bind(this));
  734. },
  735. _closeDialog: function () {
  736. if (this.node.getChildByName(this.dialogLuckView.name) != null) {
  737. this.node.getChildByName(this.dialogLuckView.name).destroy();
  738. }
  739. },
  740. _closeShareDialog: function () {
  741. if (this.node.parent.getChildByName(this.shares.name) != null) {
  742. this.node.parent.getChildByName(this.shares.name).destroy();
  743. }
  744. },
  745. getNode: function (name, parent) {
  746. if (parent == null) {
  747. return this.node.getChildByName(name);
  748. } else {
  749. return parent.getChildByName(name);
  750. }
  751. },
  752. });
  753. class GLRandom {
  754. /**
  755. * 构造函数
  756. * @param {number} min 最小整数值
  757. * @param {number} max 最大整数值
  758. * @param {Map} percentage 概率数 [值,百分比]
  759. */
  760. constructor(min, max, percentage = new Map()) {
  761. this.min = Math.trunc(min);
  762. this.max = Math.trunc(max);
  763. this.MATH_RANGE = 100; // 分成100份
  764. this.percentage = percentage;
  765. }
  766. get percentage() {
  767. if (!this._percentage) {
  768. this._percentage = new Map();
  769. }
  770. return this._percentage;
  771. }
  772. /**
  773. * 分配比例
  774. * @param {Map} map 设置 值-百分比
  775. */
  776. set percentage(map) {
  777. let result = Array.from(map.values()).reduce((p, v, a) => {
  778. return p - v;
  779. }, 1);
  780. for (let i = this.min; i < this.max; i++) {
  781. if (map.has(i)) {
  782. this.percentage.set(i, map.get(i));
  783. } else {
  784. this.percentage.set(i, result / (this.max - this.min - map.size));
  785. }
  786. }
  787. }
  788. /**
  789. * 根据比例生成取值范围
  790. */
  791. range() {
  792. let [start, random, keys] = [0, this.MATH_RANGE, Array.from(this.percentage.keys())];
  793. for (let i = 0; i < keys.length; i++) {
  794. let temp = this.percentage.get(keys[i]);
  795. this.percentage.set(keys[i], [start, start += temp * random]);
  796. }
  797. }
  798. /**
  799. * 生成随机数
  800. */
  801. create() {
  802. let num = Math.random() * this.MATH_RANGE;
  803. for (let data of this.percentage.entries()) {
  804. if (num >= data[1][0] && num < data[1][1]) {
  805. return data[0];
  806. }
  807. }
  808. return null;
  809. }
  810. }