TimeModel.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import Gamecfg from "../../common/gameCfg";
  2. import { gameMethod } from "../../common/gameMethod";
  3. import { UserAdok, UserAdokPram } from "../../common/Xyc";
  4. import { SevBack } from "../../common/Xys";
  5. import Config from "../../Config";
  6. import UIGame from "../../logic/ui/scene/UIGame";
  7. import EventMng from "../../manager/EventMng";
  8. import UIMng from "../../manager/UIMng";
  9. import { TimeEvent, UserEvent } from "../const/EventConst";
  10. import { InGame } from "../const/TypeConst";
  11. import GameDataCenter from "../GameDataCenter";
  12. import IDataModel from "./IDataModel";
  13. export default class TimeModel extends IDataModel {
  14. is_open_music: boolean = false;
  15. is_open_sound: boolean = false;
  16. defaultHeart: number = 15//心跳包时间,方便修改心跳发送时间
  17. heart: number = 15
  18. sevTime: number = 0
  19. onlineTime: number = 0 // 上线时间
  20. guideRuoTime: number = 0 // 弱引导时间
  21. constructor() {
  22. super('time');
  23. this.sevTime = 0
  24. if (Config.upid != null) {
  25. clearInterval(Config.upid)
  26. }
  27. if (Config.upFrame != null) {
  28. clearInterval(Config.upFrame)
  29. }
  30. if (Config.upZhenWen != null) {
  31. clearInterval(Config.upZhenWen)
  32. }
  33. Config.upid = setInterval(() => {
  34. if (gameMethod.isEmpty(GameDataCenter.sevBack)) return;
  35. this.sevTime++
  36. this.heart--
  37. if (this.heart <= 0) {
  38. this.heart = this.defaultHeart
  39. this.sendAdok()
  40. }
  41. this.checkGuideRuo()
  42. EventMng.emit(TimeEvent.TIME_CD, this.sevTime)
  43. }, 1000)
  44. Config.upFrame = setInterval(() => {
  45. EventMng.emit(TimeEvent.TIME_FRAME_CD, this.sevTime)
  46. }, 1000 / Config.GAME_FRAME)
  47. }
  48. doSevback(result: SevBack): void {
  49. this.heart = this.defaultHeart
  50. if (result.time) {
  51. this.sevTime = result.time
  52. if (this.onlineTime == 0) {
  53. this.onlineTime = result.time
  54. }
  55. }
  56. }
  57. // 检测是否需要展示弱引导 在主界面5s没动作就展示
  58. private checkGuideRuo() {
  59. if (Config.inGame != InGame.home) {
  60. return
  61. }
  62. if (this.guideRuoTime >= 0) {
  63. this.guideRuoTime++
  64. if (this.guideRuoTime >= 2) {
  65. this.guideRuoTime = -1
  66. // GameDataCenter.task.CheckSpecTaskHand(true)
  67. }
  68. }
  69. }
  70. sendAdok(kid: string = "", hdcid: string = "", cb: Function = () => { }) {
  71. if (Config.inGame != InGame.home) {
  72. return
  73. }
  74. let param: UserAdokPram = {
  75. kid: kid,
  76. hdcid: hdcid
  77. }
  78. this.send(UserAdok.url, param, (result: SevBack) => {
  79. if (result.type == 1) {
  80. cb()
  81. }
  82. })
  83. }
  84. }