ca2e5557-7917-4e8b-a455-edd649a68d62.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. "use strict";
  2. cc._RF.push(module, 'ca2e5VXeRdOi6RV7dZJpo1i', 'TimeControl');
  3. // Script/TimeControl.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 (Object.prototype.hasOwnProperty.call(b, 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 App_1 = require("./Manager/App");
  26. var hallModel_1 = require("./model/hallModel");
  27. var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
  28. var TimeControl = /** @class */ (function (_super) {
  29. __extends(TimeControl, _super);
  30. function TimeControl() {
  31. var _this = _super !== null && _super.apply(this, arguments) || this;
  32. _this.currentTimeCount = 60; //_当前倒计时秒数
  33. _this.timeCount = 60; //体力倒计时长
  34. _this.consumeTili = -1; // 每局消耗体力
  35. _this.tiliMax = 10; //体力最大值
  36. _this.currentTili = 10; //当前体力
  37. return _this;
  38. }
  39. TimeControl_1 = TimeControl;
  40. Object.defineProperty(TimeControl, "instance", {
  41. get: function () {
  42. return TimeControl_1._instance;
  43. },
  44. set: function (value) {
  45. TimeControl_1._instance = value;
  46. },
  47. enumerable: false,
  48. configurable: true
  49. });
  50. TimeControl.prototype.onLoad = function () {
  51. TimeControl_1.instance = this;
  52. App_1.App.Facade.registerModel(hallModel_1.default);
  53. this.InitTimeLocal();
  54. };
  55. /**
  56. * 初始化当前缓存
  57. */
  58. TimeControl.prototype.InitTimeLocal = function () {
  59. var SausageCountTime = App_1.App.LocalStorageUtil.getNumber(App_1.App.LocalStorageUtil.lst_CountTime);
  60. if (!SausageCountTime)
  61. App_1.App.LocalStorageUtil.setNumber(App_1.App.LocalStorageUtil.lst_CountTime, Date.parse(new Date().toString()));
  62. var SausageCountSecond = App_1.App.LocalStorageUtil.getNumber(App_1.App.LocalStorageUtil.lst_CountSecond);
  63. if (!SausageCountSecond)
  64. App_1.App.LocalStorageUtil.setNumber(App_1.App.LocalStorageUtil.lst_CountSecond, 0);
  65. var SausageTili = App_1.App.LocalStorageUtil.getNumber(App_1.App.LocalStorageUtil.lst_Tili);
  66. if (!SausageTili)
  67. App_1.App.LocalStorageUtil.setNumber(App_1.App.LocalStorageUtil.lst_Tili, TimeControl_1.instance.currentTili);
  68. else
  69. this.currentTili = Number(SausageTili);
  70. };
  71. TimeControl.prototype.CountTili = function () {
  72. App_1.App.Facade.getModel(hallModel_1.default).updateTiliNumber();
  73. if (App_1.App.DataManager.TimeFlag)
  74. return;
  75. App_1.App.DataManager.TimeFlag = true;
  76. this.schedule(this.CountFunc, 1);
  77. };
  78. TimeControl.prototype.CountFunc = function () {
  79. if (this.currentTili >= this.tiliMax) {
  80. this.StopCount();
  81. return;
  82. }
  83. this.currentTimeCount -= 1;
  84. App_1.App.Facade.getModel(hallModel_1.default).updateTiliJishi(true, App_1.App.DataManager.TimeChange(this.currentTimeCount));
  85. if (this.currentTimeCount <= 0) {
  86. this.currentTimeCount = this.timeCount;
  87. App_1.App.DataManager.UpdateTili(1);
  88. App_1.App.Facade.getModel(hallModel_1.default).updateTiliNumber();
  89. }
  90. };
  91. TimeControl.prototype.OfflineTime = function () {
  92. var _currentTime = Date.parse(new Date().toString());
  93. var _lastTime = App_1.App.LocalStorageUtil.getNumber(App_1.App.LocalStorageUtil.lst_CountTime);
  94. var _miaoshu = App_1.App.LocalStorageUtil.getNumber(App_1.App.LocalStorageUtil.lst_CountSecond);
  95. this.currentTimeCount = Number(_miaoshu);
  96. var timeInterval = (_currentTime - Number(_lastTime)) / 1000;
  97. var _temp = timeInterval - this.currentTimeCount;
  98. if (_temp < 0) {
  99. this.currentTimeCount = Math.abs(_temp);
  100. }
  101. else {
  102. if (_temp < this.timeCount) {
  103. App_1.App.DataManager.UpdateTili(1);
  104. this.currentTimeCount = this.timeCount - _temp;
  105. }
  106. else {
  107. var _temp2 = Math.floor(_temp / this.timeCount);
  108. var _temp3 = Math.floor(_temp % this.timeCount);
  109. var tempTili = this.currentTili + _temp2;
  110. if (tempTili >= this.tiliMax) {
  111. this.currentTili = this.tiliMax;
  112. App_1.App.DataManager.SaveMessage();
  113. }
  114. else {
  115. App_1.App.DataManager.UpdateTili(_temp2);
  116. }
  117. App_1.App.Facade.getModel(hallModel_1.default).updateTiliNumber();
  118. this.currentTimeCount = this.timeCount - _temp3;
  119. }
  120. if (this.currentTili >= this.tiliMax) {
  121. this.StopCount();
  122. }
  123. }
  124. // console.log('OfflineTime:this.currentTimeCount', this.currentTimeCount, typeof (this.currentTimeCount));
  125. };
  126. TimeControl.prototype.StopCount = function () {
  127. this.currentTimeCount = this.timeCount;
  128. this.unschedule(this.CountFunc);
  129. App_1.App.Facade.getModel(hallModel_1.default).updateTiliJishi(false);
  130. App_1.App.DataManager.TimeFlag = false;
  131. console.log('StopCount:隐藏倒计时文本********************', App_1.App.DataManager.TimeFlag);
  132. };
  133. var TimeControl_1;
  134. TimeControl = TimeControl_1 = __decorate([
  135. ccclass
  136. ], TimeControl);
  137. return TimeControl;
  138. }(cc.Component));
  139. exports.default = TimeControl;
  140. cc._RF.pop();