import { director, find } from 'cc'; import { Http } from '../core/net/Http'; import { ADData } from './ADData'; import { BattleData } from './BattleData'; import { GameData } from './GameData'; import { User } from './User'; import { DeviceData } from "./DeviceData"; import { WechatData } from './WechatData'; import { HttpRequest } from '../core/net/HttpRequest'; import { Window } from '../core/ui/window/Window'; import { WindowManager } from '../core/ui/window/WindowManager'; import { DownLoadData } from './DownLoadData'; import { ISJSB, platform } from './platform'; import { HttpSystem } from '../core/net/HttpSystem'; export class g { public static userData = new User(); public static gameData = new GameData(); public static deviceData = new DeviceData(); public static adData = globalThis["adData"] || new ADData(); public static wechatData = new WechatData(); public static battleData = new BattleData(); public static downLoadData = new DownLoadData(); public static CodeMsg = { 100: "发送数据有误", 101: "获取不到玩家数据", 102: "没有解锁", 103: "位置不足", 104: "金钱不足", 105: "数量不足", 106: "没有这种神将", 107: "不能购买此等级", 108: "次数不足", 109: "服务器配置数据有误", 110: "数据库错误", 111: "等级不足", 112: "已经领取过了", 113: "观看时间不足", 114: "未到领取时间", 115: "获取不到战斗信息", 116: "获取不到对手信息", 117: "对手等级不足", 118: "获取不到分红数据", 119: "提现金额小于0.3元,不能提现", 120: "提现档次有误", 121: "财富数据异常" } /** * 激励视频加载失败 */ public static onRewardVideoADError() { g.adData.ad_type = 5; HttpSystem.send("/api/ad/videoLog", true, { adData: g.adData }); this.callback(null); this.callback = null; } /** * 激励视频展⽰ */ public static onRewardVideoADShow() { g.adData.ad_type = 4; HttpSystem.send("/api/ad/videoLog", true, { adData: g.adData }); } /** * 放弃视频奖励 */ public static onRewardVideoADLoss() { this.callback(null); this.callback = null; } private static callback: (value: ADData) => void; /** * 显示激励视频 * @returns */ public static showRewardVideo() { return new Promise((resolve => { if (!ISJSB) {//web版本直接返回成功 resolve(g.adData); return; } //3秒内只拉起一个视频 let now = Date.now(); if (this.time && now - this.time < 3000) { resolve(null); return; } this.time = Date.now(); // if (this.callback) {//如果正在展示则返回无奖励 // resolve(null); // return; // } this.callback = resolve; platform.showRewardVideoAD(); })); } private static time: number; /** * 视频完播 */ public static onRewardVideoADComplete() { this.callback(g.adData); this.callback = null; } /** * 横幅展示 */ public static onBannerADShow() { g.adData.ad_type = 7; HttpSystem.send("/api/ad/videoLog", true, { adData: g.adData }); } /** * 全屏展示 */ public static onFullScreenADShow() { g.adData.ad_type = 9; HttpSystem.send("/api/ad/videoLog", true, { adData: g.adData }); } /** * 全屏完播 */ public static onFullScreenADComplete() { g.adData.ad_type = 8; HttpSystem.send("/api/ad/videoLog", true, { adData: g.adData }); } /** * 插屏展示 */ public static onInterstitalADShow() { g.adData.ad_type = 2; HttpSystem.send("/api/ad/videoLog", true, { adData: g.adData }); } /** * 信息流展示 */ public static onNativeExpressADShow() { g.adData.ad_type = 3; HttpSystem.send("/api/ad/videoLog", true, { adData: g.adData }); } } Http.onData = (data: any) => { if (data.code == 1) {//需要重新登录 g.deviceData.needlogin = true; director.loadScene("Launch"); return false; } return true; } Http.onKeyError = () => { g.deviceData.needlogin = true; director.loadScene("Launch"); } globalThis["g"] = g;