import Gamecfg from "../../common/gameCfg"; import { gameMethod } from "../../common/gameMethod"; import { UserAdok, UserAdokPram } from "../../common/Xyc"; import { SevBack } from "../../common/Xys"; import Config from "../../Config"; import UIGame from "../../logic/ui/scene/UIGame"; import EventMng from "../../manager/EventMng"; import UIMng from "../../manager/UIMng"; import { TimeEvent, UserEvent } from "../const/EventConst"; import { InGame } from "../const/TypeConst"; import GameDataCenter from "../GameDataCenter"; import IDataModel from "./IDataModel"; export default class TimeModel extends IDataModel { is_open_music: boolean = false; is_open_sound: boolean = false; defaultHeart: number = 15//心跳包时间,方便修改心跳发送时间 heart: number = 15 sevTime: number = 0 onlineTime: number = 0 // 上线时间 guideRuoTime: number = 0 // 弱引导时间 constructor() { super('time'); this.sevTime = 0 if (Config.upid != null) { clearInterval(Config.upid) } if (Config.upFrame != null) { clearInterval(Config.upFrame) } if (Config.upZhenWen != null) { clearInterval(Config.upZhenWen) } Config.upid = setInterval(() => { if (gameMethod.isEmpty(GameDataCenter.sevBack)) return; this.sevTime++ this.heart-- if (this.heart <= 0) { this.heart = this.defaultHeart this.sendAdok() } this.checkGuideRuo() EventMng.emit(TimeEvent.TIME_CD, this.sevTime) }, 1000) Config.upFrame = setInterval(() => { EventMng.emit(TimeEvent.TIME_FRAME_CD, this.sevTime) }, 1000 / Config.GAME_FRAME) } doSevback(result: SevBack): void { this.heart = this.defaultHeart if (result.time) { this.sevTime = result.time if (this.onlineTime == 0) { this.onlineTime = result.time } } } // 检测是否需要展示弱引导 在主界面5s没动作就展示 private checkGuideRuo() { if (Config.inGame != InGame.home) { return } if (this.guideRuoTime >= 0) { this.guideRuoTime++ if (this.guideRuoTime >= 2) { this.guideRuoTime = -1 // GameDataCenter.task.CheckSpecTaskHand(true) } } } sendAdok(kid: string = "", hdcid: string = "", cb: Function = () => { }) { if (Config.inGame != InGame.home) { return } let param: UserAdokPram = { kid: kid, hdcid: hdcid } this.send(UserAdok.url, param, (result: SevBack) => { if (result.type == 1) { cb() } }) } }