5105109e-d0ae-43e5-b0ee-22d75f090ed3.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  1. "use strict";
  2. cc._RF.push(module, '51051Ce0K5D5bDuItdfCQ7T', 'YZ_Turntable');
  3. // common-plugin/Scripts/YZ_Turntable.ts
  4. "use strict";
  5. var __extends = (this && this.__extends) || (function () {
  6. var extendStatics = function (d, b) {
  7. extendStatics = Object.setPrototypeOf ||
  8. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  9. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  10. return extendStatics(d, b);
  11. };
  12. return function (d, b) {
  13. extendStatics(d, b);
  14. function __() { this.constructor = d; }
  15. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  16. };
  17. })();
  18. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  19. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  20. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  21. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  22. return c > 3 && r && Object.defineProperty(target, key, r), r;
  23. };
  24. Object.defineProperty(exports, "__esModule", { value: true });
  25. var Utils_1 = require("./Utils");
  26. var YZ_Constant_1 = require("./YZ_Constant");
  27. var CompatibleTool_1 = require("./CompatibleTool");
  28. var YZ_LocalStorage_1 = require("./YZ_LocalStorage");
  29. var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
  30. // const gearInfo = [200, 100, 300, 400, 800, 500, 1000, 4000];
  31. var ST_TurntableCounts = "turntable_counts";
  32. var ST_TurntableTimes = "turntable_times";
  33. /**
  34. * 转盘
  35. */
  36. var YZ_Turntable = /** @class */ (function (_super) {
  37. __extends(YZ_Turntable, _super);
  38. function YZ_Turntable() {
  39. var _this = _super !== null && _super.apply(this, arguments) || this;
  40. _this.spinBtn = null;
  41. _this.wheelSp = null;
  42. _this.greaSprite = null;
  43. _this.firstSpriteFrame = null;
  44. _this.secondSpriteFrame = null;
  45. _this.lastSpriteFrame = null;
  46. _this.effectAudio = null;
  47. _this.panel = null;
  48. _this.videoIcon = null;
  49. _this.spriteDouble = null;
  50. _this.spritePass = null;
  51. _this.tirpNode = null;
  52. _this.checked = null;
  53. _this.closeBtn = null;
  54. _this.videoBtn = null;
  55. _this.resultMsg = null;
  56. _this.turnCountLbl = null;
  57. _this.luckBox = null;
  58. _this.countBar = null;
  59. _this.normalBtn = null;
  60. _this.normalCloseBtn = null;
  61. _this.topCloseBtn = null;
  62. /**
  63. * max: 15,
  64. min: 2,
  65. */
  66. _this.maxSpeed = 12;
  67. /**
  68. * 减速前旋转时间
  69. * max: 5,
  70. min: 1,
  71. */
  72. _this.duration = 3;
  73. /**
  74. * 加速度
  75. * max: 0.2,
  76. min: 0.01,
  77. */
  78. _this.acc = 0.1;
  79. /**
  80. * 指定结束时的齿轮
  81. * max: 17,
  82. min: 0,
  83. */
  84. _this.targetID = 0;
  85. /**
  86. * 旋转结束是否回弹
  87. *
  88. */
  89. _this.springback = false;
  90. _this.wheelState = 0;
  91. _this.curSpeed = 0;
  92. _this.spinTime = 0; //减速前旋转时间
  93. _this.gearNum = 8;
  94. _this.defaultAngle = 360 / 8 / 2 - 22; //修正默认角度
  95. _this.gearAngle = 360 / _this.gearNum; //每个齿轮的角度
  96. _this.finalAngle = 0; //最终结果指定的角度
  97. _this.effectFlag = 0; //用于音效播放
  98. _this.audioID = 0;
  99. _this.decAngle = 0;
  100. /**
  101. * 抽奖次数
  102. */
  103. _this._turntableCount = 0;
  104. /**
  105. * 抽奖次数
  106. */
  107. _this._turntablePlayCount = 0;
  108. _this.luckBoxCount = 4;
  109. _this._updateProgress = false;
  110. _this._progress = 0;
  111. _this.defaultProgress = 0.00000001;
  112. /**
  113. * 奖励回调
  114. */
  115. _this.rewardCallFunc = null;
  116. _this.gearInfo = [200, 100, 300, 400, 800, 500, 1000, 4000];
  117. return _this;
  118. }
  119. Object.defineProperty(YZ_Turntable.prototype, "turntableCount", {
  120. get: function () {
  121. return this._turntableCount;
  122. },
  123. set: function (count) {
  124. this._turntableCount = count;
  125. YZ_LocalStorage_1.default.setItem(ST_TurntableTimes, new Date().toDateString());
  126. YZ_LocalStorage_1.default.setItem(ST_TurntableCounts, this._turntableCount);
  127. },
  128. enumerable: false,
  129. configurable: true
  130. });
  131. Object.defineProperty(YZ_Turntable.prototype, "turntablePlayCount", {
  132. get: function () {
  133. return this._turntablePlayCount;
  134. },
  135. set: function (count) {
  136. var _this = this;
  137. if (this.luckBoxCount - count == 0) {
  138. this.luckBox.node.active = true;
  139. count = 0;
  140. this.countBar.progress = this.defaultProgress;
  141. this.luckBox.setAnimation(1, "dakai", false);
  142. this.scheduleOnce(function () {
  143. Utils_1.utils.SendEvent("转盘抽奖获取累计4次大奖!");
  144. _this.showMsg(_this.gearInfo[7]);
  145. if (_this.rewardCallFunc) {
  146. var result = new YZ_Constant_1.YZ_Reward();
  147. result.rewardValue = _this.gearInfo[7];
  148. _this.rewardCallFunc(result);
  149. }
  150. }, 0.6);
  151. this.scheduleOnce(function () {
  152. _this.luckBox.setAnimation(1, "kd", false);
  153. }, 2);
  154. this.scheduleOnce(function () {
  155. _this.luckBox.node.runAction(cc.sequence(cc.scaleTo(0.2, 0.8), cc.callFunc(function () {
  156. _this.luckBox.node.active = false;
  157. _this.luckBox.node.scale = 2;
  158. })));
  159. }, 4);
  160. }
  161. this._turntablePlayCount = count;
  162. YZ_LocalStorage_1.default.setItem("turntablePlayCount", this._turntablePlayCount);
  163. this._progress = count / this.luckBoxCount;
  164. this.turnCountLbl.string = (this.luckBoxCount - count) + "";
  165. this.turnCountLbl.node.runAction(cc.sequence(cc.scaleTo(0.3, 1.8), cc.scaleTo(0.3, 1)));
  166. },
  167. enumerable: false,
  168. configurable: true
  169. });
  170. /**
  171. * 初始化事件回调
  172. * @param closeCallFunc
  173. * @param rewardCallFunc
  174. */
  175. YZ_Turntable.prototype.init = function (closeCallFunc, rewardCallFunc, gearInfo, gearImagePath) {
  176. var _this = this;
  177. // this.closeCallFunc = closeCallFunc;
  178. this.rewardCallFunc = rewardCallFunc;
  179. if (gearInfo.length > 0) {
  180. this.gearInfo = gearInfo;
  181. }
  182. if (gearImagePath) {
  183. Utils_1.utils.showLog("配置为服务器的奖励图片:", gearImagePath);
  184. CompatibleTool_1.default.LoadRes(gearImagePath, function (err, res) {
  185. if (!err && cc.isValid(_this) && _this.greaSprite) {
  186. _this.greaSprite.spriteFrame = new cc.SpriteFrame(res);
  187. }
  188. });
  189. }
  190. };
  191. YZ_Turntable.prototype.onLoad = function () {
  192. if (Utils_1.utils.otherConfig && Utils_1.utils.otherConfig.group) {
  193. this.node.group = Utils_1.utils.otherConfig.group;
  194. }
  195. this.wheelSp.node.rotation = this.defaultAngle;
  196. // this.spinBtn.on(cc.Node.EventType.TOUCH_END, (event) => {
  197. // this.startTurnTable();
  198. // });
  199. Utils_1.utils.SendEvent("转盘抽奖-显示成功!");
  200. this.initCount();
  201. if (this.turntableCount <= 0) {
  202. this.normalBtn.active = false;
  203. this.videoBtn.active = true;
  204. this.normalCloseBtn.active = true;
  205. Utils_1.utils.showScaleAction(this.videoBtn, null, false, false);
  206. }
  207. else {
  208. this.normalCloseBtn.active = false;
  209. Utils_1.utils.showScaleAction(this.normalBtn, null, false, false);
  210. }
  211. Utils_1.utils.showSkipBtn(this.closeBtn, true);
  212. // if (this.turntableCount <= 0 && !CC_DEBUG) {
  213. // let result = utils.controView(ViewLocation.turntable);
  214. // if (result.is_open === true) {
  215. // utils.delayShowNode(this.tirpNode);
  216. // this.checked.active = result.isSelect;
  217. // this.spritePass.active = !this.checked.active;
  218. // this.spriteDouble.active = this.checked.active;
  219. // this.videoIcon.active = this.checked.active;
  220. // this.closeBtn.active = false;
  221. // this.videoBtn.active = true;
  222. // this.spinBtn.active = false;
  223. // } else {
  224. // this.checked.active = false;
  225. // this.videoBtn.active = false;
  226. // this.spinBtn.active = true;
  227. // this.spinBtn.children[0].getComponent(cc.Sprite).spriteFrame = this.secondSpriteFrame;
  228. // }
  229. // }
  230. this.rewardCallFunc = Utils_1.utils.rewardCallFunc;
  231. if (cc.winSize.height < cc.winSize.width) {
  232. Utils_1.utils.adManager.HideBanner(YZ_Constant_1.BannerLocation.Game);
  233. }
  234. else {
  235. Utils_1.utils.adManager.ShowBanner(YZ_Constant_1.BannerLocation.Game);
  236. }
  237. };
  238. /**
  239. * 开始抽奖
  240. */
  241. YZ_Turntable.prototype.startTurnTable = function () {
  242. var _this = this;
  243. if (this.wheelState !== 0) {
  244. return;
  245. }
  246. if (this.turntableCount <= 0) {
  247. if (this.checked.active || this.spinBtn.active) {
  248. Utils_1.utils.adManager.ShowVideo(function (ret, msg) {
  249. if (ret) {
  250. _this.turntableCount = 1;
  251. _this.startTurnTable();
  252. Utils_1.utils.SendEvent("转盘抽奖获取奖励-成功!");
  253. }
  254. else {
  255. Utils_1.utils.showMsg("观看完整视频可以获取一次抽奖机会!");
  256. Utils_1.utils.SendEvent("转盘抽奖视频播放-失败!");
  257. _this.onClose();
  258. }
  259. });
  260. return;
  261. }
  262. else {
  263. // AldUtils.SendEvent("转盘抽奖-未勾选!");
  264. this.onClose();
  265. return;
  266. }
  267. }
  268. this.turntableCount = 0;
  269. this.targetID = this.getTargetId();
  270. this.decAngle = 2 * 360; // 减速旋转两圈
  271. this.wheelState = 1;
  272. this.curSpeed = 0;
  273. this.spinTime = 0;
  274. };
  275. YZ_Turntable.prototype.onCheck = function () {
  276. this.checked.active = !this.checked.active;
  277. this.spritePass.active = !this.checked.active;
  278. this.spriteDouble.active = this.checked.active;
  279. this.videoIcon.active = this.checked.active;
  280. // AldUtils.SendEvent(`转盘抽奖-用户${this.checked.active ? "点击勾选" : "取消勾选"}`);
  281. };
  282. YZ_Turntable.prototype.onClose = function () {
  283. var _this = this;
  284. this.panel.runAction(cc.sequence(cc.scaleTo(0.3, 0).easing(cc.easeBackIn()), cc.callFunc(function () {
  285. _this.node.destroy();
  286. })));
  287. };
  288. YZ_Turntable.prototype.onEnable = function () {
  289. this.panel.scale = 0;
  290. var ratio = 1;
  291. if (cc.winSize.height < cc.winSize.width) {
  292. // 横屏游戏
  293. ratio = 0.6;
  294. }
  295. else {
  296. ratio = cc.winSize.width / 1080;
  297. }
  298. this.panel.runAction(cc.scaleTo(0.3, ratio).easing(cc.easeBackOut()));
  299. };
  300. YZ_Turntable.prototype.onDestroy = function () {
  301. if (Utils_1.utils.turnTablePanelCloseFunc) {
  302. Utils_1.utils.turnTablePanelCloseFunc();
  303. Utils_1.utils.turnTablePanelCloseFunc = null;
  304. }
  305. else {
  306. Utils_1.utils.rewardCloseFunc && Utils_1.utils.rewardCloseFunc();
  307. Utils_1.utils.rewardCloseFunc = null;
  308. }
  309. Utils_1.utils.adManager.HideBanner(YZ_Constant_1.BannerLocation.Game);
  310. };
  311. YZ_Turntable.prototype.checkBtnSpriteFrame = function () {
  312. if (this.turntableCount <= 0) {
  313. this.normalBtn.active = false;
  314. this.videoBtn.active = true;
  315. this.normalCloseBtn.active = true;
  316. Utils_1.utils.showScaleAction(this.videoBtn, null, false, false);
  317. }
  318. else {
  319. this.normalCloseBtn.active = false;
  320. }
  321. // if (this.turntableCount <= 0) {
  322. // let result = utils.controView(ViewLocation.turntable);
  323. // if (result.is_open === true) {
  324. // utils.delayShowNode(this.tirpNode);
  325. // this.checked.active = result.isSelect;
  326. // this.spritePass.active = !this.checked.active;
  327. // this.spriteDouble.active = this.checked.active;
  328. // this.videoIcon.active = this.checked.active;
  329. // this.closeBtn.active = false;
  330. // this.videoBtn.active = true;
  331. // this.spinBtn.active = false;
  332. // } else {
  333. // this.checked.active = false;
  334. // this.videoBtn.active = false;
  335. // this.spinBtn.children[0].getComponent(cc.Sprite).spriteFrame = this.lastSpriteFrame;
  336. // }
  337. // }
  338. };
  339. YZ_Turntable.prototype.initCount = function () {
  340. var turntableCount = YZ_LocalStorage_1.default.getItem(ST_TurntableCounts);
  341. var day = YZ_LocalStorage_1.default.getItem(ST_TurntableTimes);
  342. var curDate = new Date();
  343. if (day != curDate.toDateString()) {
  344. this.turntableCount = 1;
  345. }
  346. else {
  347. this._turntableCount = turntableCount;
  348. }
  349. this.countBar.progress = this.defaultProgress;
  350. this.turntablePlayCount = YZ_LocalStorage_1.default.getItem("turntablePlayCount") ? YZ_LocalStorage_1.default.getItem("turntablePlayCount") : 0;
  351. this.countBar.progress = this.turntablePlayCount / this.luckBoxCount;
  352. Utils_1.utils.showLog("当前剩余抽奖次数:", this.turntableCount);
  353. };
  354. YZ_Turntable.prototype.test = function () {
  355. if (this.wheelState !== 0) {
  356. return;
  357. }
  358. this.targetID = this.getTargetId();
  359. cc.log("结果:", this.targetID);
  360. this.decAngle = 2 * 360; // 减速旋转两圈
  361. this.wheelState = 1;
  362. this.curSpeed = 0;
  363. this.spinTime = 0;
  364. };
  365. YZ_Turntable.prototype.getTargetId = function () {
  366. var ranNum = Math.random(); //生成一个0-1的随机数
  367. var n = Math.random() / 4; //0-0.25随机数
  368. var result = 0;
  369. if (ranNum < 0.01) {
  370. result = 1; // 8
  371. }
  372. else if (ranNum < 0.04) {
  373. result = 0.9; // 7
  374. }
  375. else if (ranNum < 0.1) {
  376. result = 0.5; // 4
  377. }
  378. else if (ranNum < 0.2) {
  379. result = 0.7; // 5
  380. }
  381. else if (ranNum < 1) {
  382. result = Math.floor(Math.random() * 4) * 0.1; //0-4
  383. }
  384. return Math.floor(8 * result);
  385. };
  386. YZ_Turntable.prototype.showMsg = function (gold) {
  387. var msg = cc.instantiate(this.resultMsg);
  388. cc.find("kuang/goldLbl", msg).getComponent(cc.Label).string = "" + gold;
  389. msg.active = true;
  390. msg.scale = 0.3;
  391. this.node.addChild(msg);
  392. msg.runAction(cc.scaleTo(0.3, this.panel.scale).easing(cc.easeBackOut()));
  393. this.scheduleOnce(function () {
  394. msg.destroy();
  395. msg.removeFromParent();
  396. }, 1.2);
  397. };
  398. YZ_Turntable.prototype.showRes = function () {
  399. var _this = this;
  400. this.showMsg(this.gearInfo[this.targetID]);
  401. this.scheduleOnce(function () {
  402. _this.turntablePlayCount++;
  403. }, 1);
  404. if (this.rewardCallFunc) {
  405. var result = new YZ_Constant_1.YZ_Reward();
  406. result.rewardValue = this.gearInfo[this.targetID];
  407. this.rewardCallFunc(result);
  408. }
  409. this.checkBtnSpriteFrame();
  410. };
  411. YZ_Turntable.prototype.update = function (dt) {
  412. if (this.countBar.progress < this._progress) {
  413. this.countBar.progress += dt;
  414. }
  415. if (this.wheelState === 0) {
  416. return;
  417. }
  418. // 播放音效有可能卡
  419. this.effectFlag += this.curSpeed;
  420. if (this.effectFlag >= this.gearAngle) {
  421. this.audioID = cc.audioEngine.playEffect(this.effectAudio, false);
  422. this.effectFlag = 0;
  423. }
  424. if (this.wheelState == 1) {
  425. // cc.log('....加速,speed:' + this.curSpeed);
  426. this.spinTime += dt;
  427. this.wheelSp.node.rotation = this.wheelSp.node.rotation + this.curSpeed;
  428. if (this.curSpeed <= this.maxSpeed) {
  429. this.curSpeed += this.acc;
  430. }
  431. else {
  432. if (this.spinTime < this.duration) {
  433. return;
  434. }
  435. // cc.log('....开始减速');
  436. //设置目标角度
  437. this.finalAngle = 360 - this.targetID * this.gearAngle + this.defaultAngle;
  438. this.maxSpeed = this.curSpeed;
  439. if (this.springback) {
  440. this.finalAngle += this.gearAngle;
  441. }
  442. this.wheelSp.node.rotation = this.finalAngle;
  443. this.wheelState = 2;
  444. }
  445. }
  446. else if (this.wheelState == 2) {
  447. // cc.log('......减速');
  448. var curRo = this.wheelSp.node.rotation; //应该等于finalAngle
  449. var hadRo = curRo - this.finalAngle;
  450. this.curSpeed = this.maxSpeed * ((this.decAngle - hadRo) / this.decAngle) + 0.2;
  451. this.wheelSp.node.rotation = curRo + this.curSpeed;
  452. if ((this.decAngle - hadRo) <= 0) {
  453. // cc.log('....停止');
  454. this.wheelState = 0;
  455. this.wheelSp.node.rotation = this.finalAngle;
  456. if (this.springback) {
  457. //倒转一个齿轮
  458. // var act = new cc.rotateBy(0.6, -this.gearAngle);
  459. var act = cc.rotateBy(0.6, -this.gearAngle);
  460. var seq = cc.sequence(cc.delayTime(0.2), act, cc.callFunc(this.showRes, this));
  461. this.wheelSp.node.runAction(seq);
  462. }
  463. else {
  464. this.showRes();
  465. }
  466. }
  467. }
  468. };
  469. __decorate([
  470. property(cc.Node)
  471. ], YZ_Turntable.prototype, "spinBtn", void 0);
  472. __decorate([
  473. property(cc.Sprite)
  474. ], YZ_Turntable.prototype, "wheelSp", void 0);
  475. __decorate([
  476. property(cc.Sprite)
  477. ], YZ_Turntable.prototype, "greaSprite", void 0);
  478. __decorate([
  479. property(cc.SpriteFrame)
  480. ], YZ_Turntable.prototype, "firstSpriteFrame", void 0);
  481. __decorate([
  482. property(cc.SpriteFrame)
  483. ], YZ_Turntable.prototype, "secondSpriteFrame", void 0);
  484. __decorate([
  485. property(cc.SpriteFrame)
  486. ], YZ_Turntable.prototype, "lastSpriteFrame", void 0);
  487. __decorate([
  488. property({ type: cc.AudioClip })
  489. ], YZ_Turntable.prototype, "effectAudio", void 0);
  490. __decorate([
  491. property(cc.Node)
  492. ], YZ_Turntable.prototype, "panel", void 0);
  493. __decorate([
  494. property(cc.Node)
  495. ], YZ_Turntable.prototype, "videoIcon", void 0);
  496. __decorate([
  497. property(cc.Node)
  498. ], YZ_Turntable.prototype, "spriteDouble", void 0);
  499. __decorate([
  500. property(cc.Node)
  501. ], YZ_Turntable.prototype, "spritePass", void 0);
  502. __decorate([
  503. property(cc.Node)
  504. ], YZ_Turntable.prototype, "tirpNode", void 0);
  505. __decorate([
  506. property(cc.Node)
  507. ], YZ_Turntable.prototype, "checked", void 0);
  508. __decorate([
  509. property(cc.Node)
  510. ], YZ_Turntable.prototype, "closeBtn", void 0);
  511. __decorate([
  512. property(cc.Node)
  513. ], YZ_Turntable.prototype, "videoBtn", void 0);
  514. __decorate([
  515. property(cc.Node)
  516. ], YZ_Turntable.prototype, "resultMsg", void 0);
  517. __decorate([
  518. property(cc.Label)
  519. ], YZ_Turntable.prototype, "turnCountLbl", void 0);
  520. __decorate([
  521. property(sp.Skeleton)
  522. ], YZ_Turntable.prototype, "luckBox", void 0);
  523. __decorate([
  524. property(cc.ProgressBar)
  525. ], YZ_Turntable.prototype, "countBar", void 0);
  526. __decorate([
  527. property(cc.Node)
  528. ], YZ_Turntable.prototype, "normalBtn", void 0);
  529. __decorate([
  530. property(cc.Node)
  531. ], YZ_Turntable.prototype, "normalCloseBtn", void 0);
  532. __decorate([
  533. property(cc.Node)
  534. ], YZ_Turntable.prototype, "topCloseBtn", void 0);
  535. YZ_Turntable = __decorate([
  536. ccclass
  537. ], YZ_Turntable);
  538. return YZ_Turntable;
  539. }(cc.Component));
  540. exports.default = YZ_Turntable;
  541. cc._RF.pop();