g.ts 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. import { director, find } from 'cc';
  2. import { Http } from '../core/net/Http';
  3. import { ADData } from './ADData';
  4. import { BattleData } from './BattleData';
  5. import { GameData } from './GameData';
  6. import { User } from './User';
  7. import { DeviceData } from "./DeviceData";
  8. import { WechatData } from './WechatData';
  9. import { HttpRequest } from '../core/net/HttpRequest';
  10. import { Window } from '../core/ui/window/Window';
  11. import { WindowManager } from '../core/ui/window/WindowManager';
  12. import { DownLoadData } from './DownLoadData';
  13. import { ISJSB, platform } from './platform';
  14. import { HttpSystem } from '../core/net/HttpSystem';
  15. export class g {
  16. public static userData = new User();
  17. public static gameData = new GameData();
  18. public static deviceData = new DeviceData();
  19. public static adData = globalThis["adData"] || new ADData();
  20. public static wechatData = new WechatData();
  21. public static battleData = new BattleData();
  22. public static downLoadData = new DownLoadData();
  23. public static CodeMsg = {
  24. 100: "发送数据有误",
  25. 101: "获取不到玩家数据",
  26. 102: "没有解锁",
  27. 103: "位置不足",
  28. 104: "金钱不足",
  29. 105: "数量不足",
  30. 106: "没有这种神将",
  31. 107: "不能购买此等级",
  32. 108: "次数不足",
  33. 109: "服务器配置数据有误",
  34. 110: "数据库错误",
  35. 111: "等级不足",
  36. 112: "已经领取过了",
  37. 113: "观看时间不足",
  38. 114: "未到领取时间",
  39. 115: "获取不到战斗信息",
  40. 116: "获取不到对手信息",
  41. 117: "对手等级不足",
  42. 118: "获取不到分红数据",
  43. 119: "提现金额小于0.3元,不能提现",
  44. 120: "提现档次有误",
  45. 121: "财富数据异常"
  46. }
  47. /**
  48. * 激励视频加载失败
  49. */
  50. public static onRewardVideoADError() {
  51. g.adData.ad_type = 5;
  52. HttpSystem.send("/api/ad/videoLog", true, { adData: g.adData });
  53. this.callback(null);
  54. this.callback = null;
  55. }
  56. /**
  57. * 激励视频展⽰
  58. */
  59. public static onRewardVideoADShow() {
  60. g.adData.ad_type = 4;
  61. HttpSystem.send("/api/ad/videoLog", true, { adData: g.adData });
  62. }
  63. /**
  64. * 放弃视频奖励
  65. */
  66. public static onRewardVideoADLoss() {
  67. this.callback(null);
  68. this.callback = null;
  69. }
  70. private static callback: (value: ADData) => void;
  71. /**
  72. * 显示激励视频
  73. * @returns
  74. */
  75. public static showRewardVideo() {
  76. return new Promise<ADData>((resolve => {
  77. if (!ISJSB) {//web版本直接返回成功
  78. resolve(g.adData);
  79. return;
  80. }
  81. //3秒内只拉起一个视频
  82. let now = Date.now();
  83. if (this.time && now - this.time < 3000) {
  84. resolve(null);
  85. return;
  86. }
  87. this.time = Date.now();
  88. // if (this.callback) {//如果正在展示则返回无奖励
  89. // resolve(null);
  90. // return;
  91. // }
  92. this.callback = resolve;
  93. platform.showRewardVideoAD();
  94. }));
  95. }
  96. private static time: number;
  97. /**
  98. * 视频完播
  99. */
  100. public static onRewardVideoADComplete() {
  101. this.callback(g.adData);
  102. this.callback = null;
  103. }
  104. /**
  105. * 横幅展示
  106. */
  107. public static onBannerADShow() {
  108. g.adData.ad_type = 7;
  109. HttpSystem.send("/api/ad/videoLog", true, { adData: g.adData });
  110. }
  111. /**
  112. * 全屏展示
  113. */
  114. public static onFullScreenADShow() {
  115. g.adData.ad_type = 9;
  116. HttpSystem.send("/api/ad/videoLog", true, { adData: g.adData });
  117. }
  118. /**
  119. * 全屏完播
  120. */
  121. public static onFullScreenADComplete() {
  122. g.adData.ad_type = 8;
  123. HttpSystem.send("/api/ad/videoLog", true, { adData: g.adData });
  124. }
  125. /**
  126. * 插屏展示
  127. */
  128. public static onInterstitalADShow() {
  129. g.adData.ad_type = 2;
  130. HttpSystem.send("/api/ad/videoLog", true, { adData: g.adData });
  131. }
  132. /**
  133. * 信息流展示
  134. */
  135. public static onNativeExpressADShow() {
  136. g.adData.ad_type = 3;
  137. HttpSystem.send("/api/ad/videoLog", true, { adData: g.adData });
  138. }
  139. }
  140. Http.onData = (data: any) => {
  141. if (data.code == 1) {//需要重新登录
  142. g.deviceData.needlogin = true;
  143. director.loadScene("Launch");
  144. return false;
  145. }
  146. return true;
  147. }
  148. Http.onKeyError = () => {
  149. g.deviceData.needlogin = true;
  150. director.loadScene("Launch");
  151. }
  152. globalThis["g"] = g;