"use strict"; cc._RF.push(module, 'ca2e5VXeRdOi6RV7dZJpo1i', 'TimeControl'); // Script/TimeControl.ts "use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 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; return c > 3 && r && Object.defineProperty(target, key, r), r; }; Object.defineProperty(exports, "__esModule", { value: true }); var App_1 = require("./Manager/App"); var hallModel_1 = require("./model/hallModel"); var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property; var TimeControl = /** @class */ (function (_super) { __extends(TimeControl, _super); function TimeControl() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.currentTimeCount = 60; //_当前倒计时秒数 _this.timeCount = 60; //体力倒计时长 _this.consumeTili = -1; // 每局消耗体力 _this.tiliMax = 10; //体力最大值 _this.currentTili = 10; //当前体力 return _this; } TimeControl_1 = TimeControl; Object.defineProperty(TimeControl, "instance", { get: function () { return TimeControl_1._instance; }, set: function (value) { TimeControl_1._instance = value; }, enumerable: false, configurable: true }); TimeControl.prototype.onLoad = function () { TimeControl_1.instance = this; App_1.App.Facade.registerModel(hallModel_1.default); this.InitTimeLocal(); }; /** * 初始化当前缓存 */ TimeControl.prototype.InitTimeLocal = function () { var SausageCountTime = App_1.App.LocalStorageUtil.getNumber(App_1.App.LocalStorageUtil.lst_CountTime); if (!SausageCountTime) App_1.App.LocalStorageUtil.setNumber(App_1.App.LocalStorageUtil.lst_CountTime, Date.parse(new Date().toString())); var SausageCountSecond = App_1.App.LocalStorageUtil.getNumber(App_1.App.LocalStorageUtil.lst_CountSecond); if (!SausageCountSecond) App_1.App.LocalStorageUtil.setNumber(App_1.App.LocalStorageUtil.lst_CountSecond, 0); var SausageTili = App_1.App.LocalStorageUtil.getNumber(App_1.App.LocalStorageUtil.lst_Tili); if (!SausageTili) App_1.App.LocalStorageUtil.setNumber(App_1.App.LocalStorageUtil.lst_Tili, TimeControl_1.instance.currentTili); else this.currentTili = Number(SausageTili); }; TimeControl.prototype.CountTili = function () { App_1.App.Facade.getModel(hallModel_1.default).updateTiliNumber(); if (App_1.App.DataManager.TimeFlag) return; App_1.App.DataManager.TimeFlag = true; this.schedule(this.CountFunc, 1); }; TimeControl.prototype.CountFunc = function () { if (this.currentTili >= this.tiliMax) { this.StopCount(); return; } this.currentTimeCount -= 1; App_1.App.Facade.getModel(hallModel_1.default).updateTiliJishi(true, App_1.App.DataManager.TimeChange(this.currentTimeCount)); if (this.currentTimeCount <= 0) { this.currentTimeCount = this.timeCount; App_1.App.DataManager.UpdateTili(1); App_1.App.Facade.getModel(hallModel_1.default).updateTiliNumber(); } }; TimeControl.prototype.OfflineTime = function () { var _currentTime = Date.parse(new Date().toString()); var _lastTime = App_1.App.LocalStorageUtil.getNumber(App_1.App.LocalStorageUtil.lst_CountTime); var _miaoshu = App_1.App.LocalStorageUtil.getNumber(App_1.App.LocalStorageUtil.lst_CountSecond); this.currentTimeCount = Number(_miaoshu); var timeInterval = (_currentTime - Number(_lastTime)) / 1000; var _temp = timeInterval - this.currentTimeCount; if (_temp < 0) { this.currentTimeCount = Math.abs(_temp); } else { if (_temp < this.timeCount) { App_1.App.DataManager.UpdateTili(1); this.currentTimeCount = this.timeCount - _temp; } else { var _temp2 = Math.floor(_temp / this.timeCount); var _temp3 = Math.floor(_temp % this.timeCount); var tempTili = this.currentTili + _temp2; if (tempTili >= this.tiliMax) { this.currentTili = this.tiliMax; App_1.App.DataManager.SaveMessage(); } else { App_1.App.DataManager.UpdateTili(_temp2); } App_1.App.Facade.getModel(hallModel_1.default).updateTiliNumber(); this.currentTimeCount = this.timeCount - _temp3; } if (this.currentTili >= this.tiliMax) { this.StopCount(); } } // console.log('OfflineTime:this.currentTimeCount', this.currentTimeCount, typeof (this.currentTimeCount)); }; TimeControl.prototype.StopCount = function () { this.currentTimeCount = this.timeCount; this.unschedule(this.CountFunc); App_1.App.Facade.getModel(hallModel_1.default).updateTiliJishi(false); App_1.App.DataManager.TimeFlag = false; console.log('StopCount:隐藏倒计时文本********************', App_1.App.DataManager.TimeFlag); }; var TimeControl_1; TimeControl = TimeControl_1 = __decorate([ ccclass ], TimeControl); return TimeControl; }(cc.Component)); exports.default = TimeControl; cc._RF.pop();