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

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