TimeModel.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { gameMethod } from "../../common/gameMethod";
  2. import { UserAdok, UserAdokPram } from "../../common/Xyc";
  3. import { SevBack } from "../../common/Xys";
  4. import Config from "../../Config";
  5. import EventMng from "../../manager/EventMng";
  6. import { TimeEvent, UserEvent } from "../const/EventConst";
  7. import { InGame } from "../const/TypeConst";
  8. import GameDataCenter from "../GameDataCenter";
  9. import IDataModel from "../../frameWork/model/IDataModel";
  10. export default class TimeModel extends IDataModel {
  11. is_open_music: boolean = false;
  12. is_open_sound: boolean = false;
  13. defaultHeart: number = 15//心跳包时间,方便修改心跳发送时间
  14. sevTime: number = 0
  15. onlineTime: number = 0 // 上线时间
  16. guideRuoTime: number = 0 // 弱引导时间
  17. constructor() {
  18. super('time');
  19. this.sevTime = 0
  20. if (Config.upid != null) {
  21. clearInterval(Config.upid)
  22. }
  23. if (Config.upFrame != null) {
  24. clearInterval(Config.upFrame)
  25. }
  26. if (Config.upZhenWen != null) {
  27. clearInterval(Config.upZhenWen)
  28. }
  29. Config.upid = setInterval(() => {
  30. if (gameMethod.isEmpty(GameDataCenter.sevBack)) return;
  31. this.sevTime++
  32. EventMng.emit(TimeEvent.TIME_CD, this.sevTime)
  33. }, 1000)
  34. Config.upFrame = setInterval(() => {
  35. EventMng.emit(TimeEvent.TIME_FRAME_CD, this.sevTime)
  36. }, 1000 / Config.GAME_FRAME)
  37. }
  38. doSevback(result: SevBack): void {
  39. if (result.time) {
  40. this.sevTime = result.time
  41. if (this.onlineTime == 0) {
  42. this.onlineTime = result.time
  43. }
  44. }
  45. }
  46. }