TimeModel.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. heart: number = 15
  15. sevTime: number = 0
  16. onlineTime: number = 0 // 上线时间
  17. guideRuoTime: number = 0 // 弱引导时间
  18. constructor() {
  19. super('time');
  20. this.sevTime = 0
  21. if (Config.upid != null) {
  22. clearInterval(Config.upid)
  23. }
  24. if (Config.upFrame != null) {
  25. clearInterval(Config.upFrame)
  26. }
  27. if (Config.upZhenWen != null) {
  28. clearInterval(Config.upZhenWen)
  29. }
  30. Config.upid = setInterval(() => {
  31. if (gameMethod.isEmpty(GameDataCenter.sevBack)) return;
  32. this.sevTime++
  33. this.heart--
  34. if (this.heart <= 0) {
  35. this.heart = this.defaultHeart
  36. this.sendAdok()
  37. }
  38. this.checkGuideRuo()
  39. EventMng.emit(TimeEvent.TIME_CD, this.sevTime)
  40. }, 1000)
  41. Config.upFrame = setInterval(() => {
  42. EventMng.emit(TimeEvent.TIME_FRAME_CD, this.sevTime)
  43. }, 1000 / Config.GAME_FRAME)
  44. }
  45. doSevback(result: SevBack): void {
  46. this.heart = this.defaultHeart
  47. if (result.time) {
  48. this.sevTime = result.time
  49. if (this.onlineTime == 0) {
  50. this.onlineTime = result.time
  51. }
  52. }
  53. }
  54. // 检测是否需要展示弱引导 在主界面5s没动作就展示
  55. private checkGuideRuo() {
  56. if (Config.inGame != InGame.home) {
  57. return
  58. }
  59. if (this.guideRuoTime >= 0) {
  60. this.guideRuoTime++
  61. if (this.guideRuoTime >= 2) {
  62. this.guideRuoTime = -1
  63. // GameDataCenter.task.CheckSpecTaskHand(true)
  64. }
  65. }
  66. }
  67. sendAdok(kid: string = "", hdcid: string = "", cb: Function = () => { }) {
  68. if (Config.inGame != InGame.home) {
  69. return
  70. }
  71. let param: UserAdokPram = {
  72. kid: kid,
  73. hdcid: hdcid
  74. }
  75. this.send(UserAdok.url, param, (result: SevBack) => {
  76. if (result.type == 1) {
  77. cb()
  78. }
  79. })
  80. }
  81. }