48fdf28e-6128-43b2-bd60-f11e1323b5d5.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  1. "use strict";
  2. cc._RF.push(module, '48fdfKOYShDsr1g8R4TI7XV', 'SDK');
  3. // Script/sdk/SDK.ts
  4. "use strict";
  5. // Learn TypeScript:
  6. // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/typescript.html
  7. // - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html
  8. // Learn Attribute:
  9. // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
  10. // - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/reference/attributes.html
  11. // Learn life-cycle callbacks:
  12. // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
  13. // - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.htmlr
  14. var __extends = (this && this.__extends) || (function () {
  15. var extendStatics = function (d, b) {
  16. extendStatics = Object.setPrototypeOf ||
  17. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  18. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  19. return extendStatics(d, b);
  20. };
  21. return function (d, b) {
  22. extendStatics(d, b);
  23. function __() { this.constructor = d; }
  24. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  25. };
  26. })();
  27. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  28. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  29. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  30. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  31. return c > 3 && r && Object.defineProperty(target, key, r), r;
  32. };
  33. Object.defineProperty(exports, "__esModule", { value: true });
  34. exports.NodeAction = void 0;
  35. var Utils_1 = require("./tools/Utils");
  36. var Interstitial_1 = require("./vivo/Interstitial");
  37. var NativeAdComponent_1 = require("./vivo/NativeAdComponent");
  38. var VivoAd_1 = require("./vivo/VivoAd");
  39. var ATRewardedVideoJSSDK_1 = require("../AnyThinkAds/ATRewardedVideoJSSDK");
  40. var ATAndroidJS2_1 = require("../ATAndroidJS2");
  41. var keyS = ["eggplant_fwzoowni#", "2021xianYou", "Cm_touchmi"];
  42. var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
  43. //广告节点
  44. var NodeAction;
  45. (function (NodeAction) {
  46. NodeAction[NodeAction["GAME_LOADING_IN_MAIN_UI"] = 1] = "GAME_LOADING_IN_MAIN_UI";
  47. NodeAction[NodeAction["GAME_ENTER_LEVEL"] = 2] = "GAME_ENTER_LEVEL";
  48. NodeAction[NodeAction["GAME_UNLOCK_LEVEL"] = 3] = "GAME_UNLOCK_LEVEL";
  49. NodeAction[NodeAction["BANNER_SHOW"] = 4] = "BANNER_SHOW";
  50. NodeAction[NodeAction["BANNER_CLICK"] = 5] = "BANNER_CLICK";
  51. NodeAction[NodeAction["BANNER_CLOSE"] = 6] = "BANNER_CLOSE";
  52. NodeAction[NodeAction["INSERT_SHOW"] = 7] = "INSERT_SHOW";
  53. NodeAction[NodeAction["INSERT_CLICK"] = 8] = "INSERT_CLICK";
  54. NodeAction[NodeAction["INSERT_CLOSE"] = 9] = "INSERT_CLOSE";
  55. NodeAction[NodeAction["VIDEO_SHOW"] = 10] = "VIDEO_SHOW";
  56. NodeAction[NodeAction["VIDEO_CLOSE"] = 11] = "VIDEO_CLOSE";
  57. NodeAction[NodeAction["VIDER_CLICK"] = 12] = "VIDER_CLICK";
  58. NodeAction[NodeAction["NATIVE_SHOW"] = 13] = "NATIVE_SHOW";
  59. NodeAction[NodeAction["NATIVE_CLICK"] = 14] = "NATIVE_CLICK";
  60. NodeAction[NodeAction["NATIVE_CLOSE"] = 15] = "NATIVE_CLOSE";
  61. NodeAction[NodeAction["INIT"] = 16] = "INIT"; //16
  62. })(NodeAction = exports.NodeAction || (exports.NodeAction = {}));
  63. var SDK = /** @class */ (function (_super) {
  64. __extends(SDK, _super);
  65. function SDK() {
  66. var _this = _super.call(this) || this;
  67. _this._type = 1;
  68. _this._gameCode = null; //游戏id
  69. _this._gameTime = 0;
  70. _this._clipboardData = null;
  71. _this._initCallbacks = null;
  72. _this.limitClick = 0;
  73. _this._random = -1;
  74. _this.fristGame = false;
  75. _this._levelTime = 0;
  76. _this._isVivo = false;
  77. _this._netInitCount = 0;
  78. _this._loading = false;
  79. _this.ivKey = null;
  80. _this.index = 0;
  81. if (cc.sys.platform == cc.sys.VIVO_GAME) {
  82. _this._isVivo = true;
  83. }
  84. console.log("当前平台: " + cc.sys.platform + " " + cc.sys.VIVO_GAME + " " + _this._isVivo);
  85. _this._utils = Utils_1.default.instance;
  86. if (!_this._isVivo) {
  87. return _this;
  88. }
  89. VivoAd_1.default.Instance.onListenHome();
  90. VivoAd_1.default.Instance.init();
  91. _this._userId = VivoAd_1.default.Instance.getUserId();
  92. _this._source = VivoAd_1.default.Instance.getSource();
  93. var self = _this;
  94. _this._sysytemInfo = VivoAd_1.default.Instance.getSystemInfoSync();
  95. VivoAd_1.default.Instance.getNetType(function (netType) {
  96. self._netType = netType;
  97. });
  98. return _this;
  99. }
  100. SDK_1 = SDK;
  101. Object.defineProperty(SDK, "Instance", {
  102. get: function () {
  103. if (SDK_1._instance == null) {
  104. SDK_1._instance = new SDK_1();
  105. }
  106. return SDK_1._instance;
  107. },
  108. enumerable: false,
  109. configurable: true
  110. });
  111. SDK.prototype.startTime = function () {
  112. this._levelTime = new Date().getTime();
  113. };
  114. SDK.prototype.endLevelTime = function (level) {
  115. var curTime = new Date().getTime();
  116. var time = curTime - this._levelTime;
  117. this.durationLog(Math.floor(time / 1000), level);
  118. };
  119. SDK.prototype.requestConfig = function () {
  120. var _this = this;
  121. if (!this._isVivo) {
  122. return;
  123. }
  124. var self = this;
  125. this._utils.log(self._netType);
  126. VivoAd_1.default.Instance.getClipboardData(function (clipboard) {
  127. self._clipboardData = clipboard;
  128. var key = keyS[_this.edType];
  129. var bady = {
  130. key: key,
  131. gameCode: self._gameCode,
  132. clipboard: clipboard,
  133. manuId: self._type,
  134. openId: self._userId,
  135. source: JSON.stringify(self._source.query),
  136. platformVersionCode: self._sysytemInfo == null ? 0 : self._sysytemInfo.platformVersionCode,
  137. netType: self._netType,
  138. dateTime: new Date().getTime()
  139. };
  140. var body = JSON.stringify(bady);
  141. // this._utils.log(body);
  142. var u = ["pz", "gg", "cnf"];
  143. _this._utils.sendPost(u[self.edType], body);
  144. });
  145. };
  146. /**日志上报
  147. * @param type 上报日志类型
  148. */
  149. SDK.prototype.reportLog = function (type, content) {
  150. var _this = this;
  151. if (!this._isVivo) {
  152. return;
  153. }
  154. var self = this;
  155. VivoAd_1.default.Instance.getClipboardData(function (clipboard) {
  156. self._clipboardData = clipboard;
  157. var key = keyS[_this.edType];
  158. var bady = {
  159. key: key,
  160. gameCode: self._gameCode,
  161. clipboard: clipboard,
  162. manuId: self._type,
  163. openId: self._userId,
  164. type: type,
  165. content: content,
  166. source: JSON.stringify(self._source.query),
  167. dateTime: new Date().getTime()
  168. };
  169. var u = ["rz", "sb", "rpt1"];
  170. _this._utils.sendPost(u[self.edType], JSON.stringify(bady));
  171. });
  172. };
  173. /**游戏上报
  174. * @param secondes 上报日志类型
  175. */
  176. SDK.prototype.durationLog = function (seconds, level) {
  177. if (level === void 0) { level = 0; }
  178. if (!this._isVivo) {
  179. return;
  180. }
  181. var self = this;
  182. var random = -1;
  183. if (seconds > 0) {
  184. random = this._random;
  185. }
  186. var key = keyS[this.edType];
  187. var bady = {
  188. key: key,
  189. gameCode: self._gameCode,
  190. clipboard: self._clipboardData,
  191. manuId: self._type,
  192. openId: self._userId,
  193. level: level,
  194. seconds: seconds,
  195. source: JSON.stringify(self._source.query),
  196. random: random,
  197. dateTime: new Date().getTime()
  198. };
  199. var u = ["sc", "zq", "rpt2"];
  200. this._utils.sendPost(u[self.edType], JSON.stringify(bady));
  201. };
  202. /**
  203. * sdk初始化
  204. * @param gameCode 游戏id,为服务端分配
  205. * @param callbacks 请求回调 ,返回true请求成功,false请求失败
  206. * @param debug 调试模式 默认false
  207. * @returns
  208. */
  209. SDK.prototype.init = function (gameCode, type, callbacks) {
  210. var _this = this;
  211. this._initCallbacks = callbacks;
  212. this.edType = type;
  213. // console.log("=============init=========type: "+type);
  214. // if(type == 0){
  215. // console.log("=============指创=========");
  216. // }else if(type == 1){
  217. // console.log("=============闲游=========");
  218. // }else if(type == 2){
  219. // console.log("=============触米=========");
  220. // }
  221. // this.edType = EncryptType.ED_CM;
  222. // let de = EncryptUtil.de("961JU3BY4DjgsEsvjbH1VBWoxQLcT9dfvgGThac0WLgxl72I7V3+b3Uxcs3adY8gzkPvmsBxT4Os5hu9YwlqZXS6A+NA1HbZCjGdwqRHWZPOKWtOhCnKz1Pe+41YpGGj+9GKjBK5TTgKaZRSvQ9HznLtOT7RSLUZqaIdnSGObmI8AKMYcYnx4PAa9q/I5ksA5lB8/yWo1i6IR7hZxK3qXYPfDu9cD5IutZxvqm5xzxJOnjoiIvRCceKmx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LNnxwQrxD1C1xS+iojp6m+OhdQ1mjaA6q9wcf6CEN+A6FbDVnBIJyVeLC1AdTUs7H53DApXn7RaSL/R5bdK7N8VJ0xh0B1pn2DNUCiIqBwmf+Vg40QVqMUC3E/XWaaiEuqhB/GjhXFMcYfeTuAWciCGbM2Rs=");
  223. // console.log("=============触米de: "+de);
  224. if (!this._isVivo) {
  225. if (callbacks) {
  226. callbacks(true);
  227. }
  228. return;
  229. }
  230. var self = this;
  231. if (this._random <= 0) {
  232. //随机8位
  233. this._random = this._utils.getRandomInt(0, 10000);
  234. }
  235. this._gameCode = gameCode;
  236. this._utils.addListener(this);
  237. this.requestConfig();
  238. self._gameTime = new Date().getTime();
  239. VivoAd_1.default.Instance.onHide(function () {
  240. var curTime = new Date().getTime();
  241. var time = curTime - self._gameTime;
  242. self.durationLog(Math.floor(time / 1000), 0);
  243. self._gameTime = 0;
  244. _this._utils.log("********用户退出游戏或退到后台: " + (time / 1000));
  245. });
  246. VivoAd_1.default.Instance.onShow(function () {
  247. self._gameTime = new Date().getTime();
  248. _this._utils.log("*******用户回到游戏");
  249. });
  250. // this.index++;
  251. // if(this.index>2){
  252. // this.index = 0;
  253. // }
  254. // this.scheduleOnce(()=>{
  255. // SDK.Instance.init(gameCode,this.index,null);
  256. // },10);
  257. };
  258. //自动刷新广告
  259. SDK.prototype.flushConfig = function () {
  260. if (!this._isVivo) {
  261. return;
  262. }
  263. var self = this;
  264. var go = function () {
  265. if (self._loading) {
  266. self.unschedule(go);
  267. return;
  268. }
  269. if (self._netInitCount > 2) {
  270. self._utils.ok(null);
  271. self.unschedule(go);
  272. return;
  273. }
  274. self._netInitCount++;
  275. self.requestConfig();
  276. };
  277. this.schedule(go, 10);
  278. };
  279. //监听网络回调
  280. SDK.prototype.onOk = function (config) {
  281. if (!this._isVivo) {
  282. return;
  283. }
  284. this._config = config;
  285. var self = this;
  286. if (this._config) {
  287. this._loading = true;
  288. VivoAd_1.default.Instance.initConfig(this._config, function () {
  289. if (self._initCallbacks) {
  290. self._initCallbacks(true);
  291. }
  292. });
  293. }
  294. else {
  295. self._utils.log("********* initConfig is faill : " + JSON.stringify(this._config));
  296. if (self._initCallbacks && !this._loading) {
  297. self._initCallbacks(false);
  298. this.flushConfig();
  299. }
  300. }
  301. };
  302. /**
  303. * 展示banner
  304. * @param type 原生广告类型
  305. * @param top 是否展示顶部
  306. * @param x
  307. * @param y
  308. */
  309. SDK.prototype.showBanner = function (type, top, y, x) {
  310. if (type === void 0) { type = NativeAdComponent_1.NativeType.BANNER; }
  311. if (top === void 0) { top = false; }
  312. if (y === void 0) { y = 0; }
  313. if (x === void 0) { x = 0; }
  314. if (!this._isVivo) {
  315. return;
  316. }
  317. this.hideBanner();
  318. VivoAd_1.default.Instance.showBanner(type, top, y, x);
  319. };
  320. /**
  321. * 隐藏banner
  322. */
  323. SDK.prototype.hideBanner = function () {
  324. if (!this._isVivo) {
  325. return;
  326. }
  327. VivoAd_1.default.Instance.hideBanner();
  328. };
  329. SDK.prototype.hideIcon = function () {
  330. if (!this._isVivo) {
  331. return;
  332. }
  333. VivoAd_1.default.Instance.hideIcon();
  334. };
  335. /**
  336. * 展示原生插屏
  337. * 默认id节点为第一个0,有多个时,按服务端配置为准,进行传参
  338. * @param node 默认0
  339. * @param isforever true时,每次调用都会展示,false时,受服务器调用次数控制,默认false
  340. * @param id
  341. */
  342. SDK.prototype.showInterstitial = function (id) {
  343. if (id === void 0) { id = Interstitial_1.InterstitialType.INTERSTITIAL_GAME_OVER; }
  344. if (!this._isVivo) {
  345. return;
  346. }
  347. VivoAd_1.default.Instance.showInterstitial(id);
  348. };
  349. /**
  350. * 展示原生icon广告
  351. * 默认id节点为第一个0,有多个时,按服务端配置为准,进行传参
  352. * @param node
  353. * @param x
  354. * @param y
  355. * @param id
  356. */
  357. SDK.prototype.showIconAd = function (x, y, id) {
  358. if (id === void 0) { id = 0; }
  359. if (!this._isVivo) {
  360. return;
  361. }
  362. this.hideIcon();
  363. VivoAd_1.default.Instance.showIconAd(id, x, y);
  364. };
  365. /*0显示视频*/
  366. SDK.prototype.showRewardVideo = function (callBacks, fail, noAd) {
  367. console.log('a');
  368. if (!this._isVivo) {
  369. console.log('b');
  370. return;
  371. }
  372. console.log('c');
  373. VivoAd_1.default.Instance.showRewardVideo(callBacks, fail, noAd);
  374. console.log('d');
  375. };
  376. //toast提示框
  377. SDK.prototype.showToast = function (message) {
  378. if (!this._isVivo) {
  379. return;
  380. }
  381. if (VivoAd_1.default.Instance) {
  382. VivoAd_1.default.Instance.showToast(message);
  383. }
  384. };
  385. /**
  386. * 游戏结算界面数分延迟
  387. * @param lable
  388. * @param score
  389. * @param cb
  390. */
  391. SDK.prototype.gameResultDelayedTime = function (lable, score, cb) {
  392. var _this = this;
  393. if (this._config && score > 0) {
  394. var dalayedTime = this._config.maxClickCount;
  395. if (dalayedTime > 0) {
  396. var count_1 = 0;
  397. var s = Math.floor((dalayedTime / score) * 100) / 100;
  398. var add_1 = score / 200;
  399. if (add_1 < 1) {
  400. add_1 = 1;
  401. }
  402. this._utils.log("----time: " + dalayedTime + " s: " + s + " add: " + add_1);
  403. var go_1 = function () {
  404. count_1 = Math.floor(count_1 + add_1);
  405. if (count_1 > score) {
  406. _this.unschedule(go_1);
  407. lable.string = "" + score;
  408. if (cb) {
  409. cb();
  410. }
  411. return;
  412. }
  413. if (lable) {
  414. lable.string = "" + count_1;
  415. }
  416. };
  417. this.schedule(go_1, s);
  418. }
  419. else {
  420. lable.string = "" + score;
  421. if (cb) {
  422. this.scheduleOnce(function () {
  423. cb();
  424. }, 0.2);
  425. }
  426. }
  427. }
  428. else {
  429. lable.string = "" + score;
  430. if (cb) {
  431. this.scheduleOnce(function () {
  432. cb();
  433. }, 0.2);
  434. }
  435. }
  436. };
  437. /**
  438. * 激励AD 加载
  439. */
  440. SDK.prototype.initAdForPage = function () {
  441. if (cc.sys.os === cc.sys.OS_ANDROID) {
  442. var deviceId = ATAndroidJS2_1.default.getDeviceUserId();
  443. console.log("zh:checkstatus:", ATRewardedVideoJSSDK_1.default.checkAdStatus(ATAndroidJS2_1.default.getPlacementId()));
  444. var setting = {};
  445. setting[ATRewardedVideoJSSDK_1.default.userIdKey] = deviceId;
  446. ATRewardedVideoJSSDK_1.default.loadRewardedVideo(ATAndroidJS2_1.default.getPlacementId(), setting);
  447. }
  448. };
  449. var SDK_1;
  450. SDK._instance = null;
  451. SDK = SDK_1 = __decorate([
  452. ccclass
  453. ], SDK);
  454. return SDK;
  455. }(cc.Component));
  456. exports.default = SDK;
  457. cc["SDK"] = SDK.Instance;
  458. cc._RF.pop();