123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460 |
- "use strict";
- cc._RF.push(module, '48fdfKOYShDsr1g8R4TI7XV', 'SDK');
- // Script/sdk/SDK.ts
- "use strict";
- // Learn TypeScript:
- // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/typescript.html
- // - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html
- // Learn Attribute:
- // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
- // - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/reference/attributes.html
- // Learn life-cycle callbacks:
- // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
- // - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.htmlr
- var __extends = (this && this.__extends) || (function () {
- var extendStatics = function (d, b) {
- extendStatics = Object.setPrototypeOf ||
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
- return extendStatics(d, b);
- };
- return function (d, b) {
- extendStatics(d, b);
- function __() { this.constructor = d; }
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
- };
- })();
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
- 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;
- return c > 3 && r && Object.defineProperty(target, key, r), r;
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- exports.NodeAction = void 0;
- var Utils_1 = require("./tools/Utils");
- var Interstitial_1 = require("./vivo/Interstitial");
- var NativeAdComponent_1 = require("./vivo/NativeAdComponent");
- var VivoAd_1 = require("./vivo/VivoAd");
- var ATRewardedVideoJSSDK_1 = require("../AnyThinkAds/ATRewardedVideoJSSDK");
- var ATAndroidJS2_1 = require("../ATAndroidJS2");
- var keyS = ["eggplant_fwzoowni#", "2021xianYou", "Cm_touchmi"];
- var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
- //广告节点
- var NodeAction;
- (function (NodeAction) {
- NodeAction[NodeAction["GAME_LOADING_IN_MAIN_UI"] = 1] = "GAME_LOADING_IN_MAIN_UI";
- NodeAction[NodeAction["GAME_ENTER_LEVEL"] = 2] = "GAME_ENTER_LEVEL";
- NodeAction[NodeAction["GAME_UNLOCK_LEVEL"] = 3] = "GAME_UNLOCK_LEVEL";
- NodeAction[NodeAction["BANNER_SHOW"] = 4] = "BANNER_SHOW";
- NodeAction[NodeAction["BANNER_CLICK"] = 5] = "BANNER_CLICK";
- NodeAction[NodeAction["BANNER_CLOSE"] = 6] = "BANNER_CLOSE";
- NodeAction[NodeAction["INSERT_SHOW"] = 7] = "INSERT_SHOW";
- NodeAction[NodeAction["INSERT_CLICK"] = 8] = "INSERT_CLICK";
- NodeAction[NodeAction["INSERT_CLOSE"] = 9] = "INSERT_CLOSE";
- NodeAction[NodeAction["VIDEO_SHOW"] = 10] = "VIDEO_SHOW";
- NodeAction[NodeAction["VIDEO_CLOSE"] = 11] = "VIDEO_CLOSE";
- NodeAction[NodeAction["VIDER_CLICK"] = 12] = "VIDER_CLICK";
- NodeAction[NodeAction["NATIVE_SHOW"] = 13] = "NATIVE_SHOW";
- NodeAction[NodeAction["NATIVE_CLICK"] = 14] = "NATIVE_CLICK";
- NodeAction[NodeAction["NATIVE_CLOSE"] = 15] = "NATIVE_CLOSE";
- NodeAction[NodeAction["INIT"] = 16] = "INIT"; //16
- })(NodeAction = exports.NodeAction || (exports.NodeAction = {}));
- var SDK = /** @class */ (function (_super) {
- __extends(SDK, _super);
- function SDK() {
- var _this = _super.call(this) || this;
- _this._type = 1;
- _this._gameCode = null; //游戏id
- _this._gameTime = 0;
- _this._clipboardData = null;
- _this._initCallbacks = null;
- _this.limitClick = 0;
- _this._random = -1;
- _this.fristGame = false;
- _this._levelTime = 0;
- _this._isVivo = false;
- _this._netInitCount = 0;
- _this._loading = false;
- _this.ivKey = null;
- _this.index = 0;
- if (cc.sys.platform == cc.sys.VIVO_GAME) {
- _this._isVivo = true;
- }
- console.log("当前平台: " + cc.sys.platform + " " + cc.sys.VIVO_GAME + " " + _this._isVivo);
- _this._utils = Utils_1.default.instance;
- if (!_this._isVivo) {
- return _this;
- }
- VivoAd_1.default.Instance.onListenHome();
- VivoAd_1.default.Instance.init();
- _this._userId = VivoAd_1.default.Instance.getUserId();
- _this._source = VivoAd_1.default.Instance.getSource();
- var self = _this;
- _this._sysytemInfo = VivoAd_1.default.Instance.getSystemInfoSync();
- VivoAd_1.default.Instance.getNetType(function (netType) {
- self._netType = netType;
- });
- return _this;
- }
- SDK_1 = SDK;
- Object.defineProperty(SDK, "Instance", {
- get: function () {
- if (SDK_1._instance == null) {
- SDK_1._instance = new SDK_1();
- }
- return SDK_1._instance;
- },
- enumerable: false,
- configurable: true
- });
- SDK.prototype.startTime = function () {
- this._levelTime = new Date().getTime();
- };
- SDK.prototype.endLevelTime = function (level) {
- var curTime = new Date().getTime();
- var time = curTime - this._levelTime;
- this.durationLog(Math.floor(time / 1000), level);
- };
- SDK.prototype.requestConfig = function () {
- var _this = this;
- if (!this._isVivo) {
- return;
- }
- var self = this;
- this._utils.log(self._netType);
- VivoAd_1.default.Instance.getClipboardData(function (clipboard) {
- self._clipboardData = clipboard;
- var key = keyS[_this.edType];
- var bady = {
- key: key,
- gameCode: self._gameCode,
- clipboard: clipboard,
- manuId: self._type,
- openId: self._userId,
- source: JSON.stringify(self._source.query),
- platformVersionCode: self._sysytemInfo == null ? 0 : self._sysytemInfo.platformVersionCode,
- netType: self._netType,
- dateTime: new Date().getTime()
- };
- var body = JSON.stringify(bady);
- // this._utils.log(body);
- var u = ["pz", "gg", "cnf"];
- _this._utils.sendPost(u[self.edType], body);
- });
- };
- /**日志上报
- * @param type 上报日志类型
- */
- SDK.prototype.reportLog = function (type, content) {
- var _this = this;
- if (!this._isVivo) {
- return;
- }
- var self = this;
- VivoAd_1.default.Instance.getClipboardData(function (clipboard) {
- self._clipboardData = clipboard;
- var key = keyS[_this.edType];
- var bady = {
- key: key,
- gameCode: self._gameCode,
- clipboard: clipboard,
- manuId: self._type,
- openId: self._userId,
- type: type,
- content: content,
- source: JSON.stringify(self._source.query),
- dateTime: new Date().getTime()
- };
- var u = ["rz", "sb", "rpt1"];
- _this._utils.sendPost(u[self.edType], JSON.stringify(bady));
- });
- };
- /**游戏上报
- * @param secondes 上报日志类型
- */
- SDK.prototype.durationLog = function (seconds, level) {
- if (level === void 0) { level = 0; }
- if (!this._isVivo) {
- return;
- }
- var self = this;
- var random = -1;
- if (seconds > 0) {
- random = this._random;
- }
- var key = keyS[this.edType];
- var bady = {
- key: key,
- gameCode: self._gameCode,
- clipboard: self._clipboardData,
- manuId: self._type,
- openId: self._userId,
- level: level,
- seconds: seconds,
- source: JSON.stringify(self._source.query),
- random: random,
- dateTime: new Date().getTime()
- };
- var u = ["sc", "zq", "rpt2"];
- this._utils.sendPost(u[self.edType], JSON.stringify(bady));
- };
- /**
- * sdk初始化
- * @param gameCode 游戏id,为服务端分配
- * @param callbacks 请求回调 ,返回true请求成功,false请求失败
- * @param debug 调试模式 默认false
- * @returns
- */
- SDK.prototype.init = function (gameCode, type, callbacks) {
- var _this = this;
- this._initCallbacks = callbacks;
- this.edType = type;
- // console.log("=============init=========type: "+type);
- // if(type == 0){
- // console.log("=============指创=========");
- // }else if(type == 1){
- // console.log("=============闲游=========");
- // }else if(type == 2){
- // console.log("=============触米=========");
- // }
- // this.edType = EncryptType.ED_CM;
- // let de = EncryptUtil.de("961JU3BY4DjgsEsvjbH1VBWoxQLcT9dfvgGThac0WLgxl72I7V3+b3Uxcs3adY8gzkPvmsBxT4Os5hu9YwlqZXS6A+NA1HbZCjGdwqRHWZPOKWtOhCnKz1Pe+41YpGGj+9GKjBK5TTgKaZRSvQ9HznLtOT7RSLUZqaIdnSGObmI8AKMYcYnx4PAa9q/I5ksA5lB8/yWo1i6IR7hZxK3qXYPfDu9cD5IutZxvqm5xzxJOnjoiIvRCceKmxpqd66AumUjLGAcV2mBMMUe0B5NrO/X1bWUQgi2yKE6EB0ipQE9A7921RANGfTax5zIpSfnv8gLiv8/fc7aDoxFrVpPIhUyBp18G5kVXOwNftWje+4s0dTc67HKSXTEEMBbWIhSqfe5/Nrp306Ls8QsqO50L3WNCfEC+THO5XQgn57AN5X0j2FSz7Exy1fdscRFAf2q4Zx7R9NEMBnaDoxFrVpPIgQ0u4UQOeRSg7W/nQgRYhW0j2FSz7Exy3rToMyhSJesZqaIdnSGObmI8AKMYcYnx4PAa9q/I5ksA5lB8/yWo1i6IR7hZxK3qXYPfDu9cD5Irt3RlAGZCE7EO0auILwjWEU/QovnDWQ+Ng98O71wPkiEv31hBKtl9FNWSzD5W93HcDzUSiQz1irsEXvTx9t7m95U5Rex0B121a0BvjXmhTQiAOfhB+pVUXwkoJol/0gCBvO8RHqt7exx6XqgOxXAujWip285CirBY9CFOJ/tqxQAQSUaGUjFBwiZmiGzrKcT0PSEyYOvZdJkE1KFziq1+mwbLd9pa6vxAsS9XscBkB4OxA0tJkvk2g9sL4eyHHZmEFScfIMeTcJkJPHgxbNLOcEChcfQmIii3z0y2D6PwBm8JKCaJf9IAgDkci7sTftYMbTK9rLir8vJkjHiLQcxFIbzvER6re3scel6oDsVwLo1oqdvOQoqwWos3giRKK3UJlWj2zdEEu4sYvcfqEqZ655sGCl96/upxraKdWT6ToZyeTNJ+WQkjE426FLcuWc/xgV9dRmnQWy2OWwbd0Cii26yZlSKBRPSn/eAtmqX1D7DOQ++awHFPhzV2zakldbpcWrzj0NtQXyexdz/gt25eaQqlLcrTDPuuh2nUL7SKZLET28fSVMvwGxt/uXy2IdBBjW9l/GHWh5bx0XlWHIJfLZay2hRwOBHnaYRXBj9jyCAyGQn7Kzbsh4Uf2C3K3mJ45yZTMLFMDUQVqMUC3E/XUFaJp6XWZwBRPC7qG9aomgmUbnuVJToziBjQb7AiD939KiAXt7qh3/RgB3U4+ioxycRaYuNvMgjcRthfoVguHRt1G/yLCqyIRKWxMLNnxwQrxD1C1xS+iojp6m+OhdQ1mjaA6q9wcf6CEN+A6FbDVnBIJyVeLC1AdTUs7H53DApXn7RaSL/R5bdK7N8VJ0xh0B1pn2DNUCiIqBwmf+Vg40QVqMUC3E/XWaaiEuqhB/GjhXFMcYfeTuAWciCGbM2Rs=");
- // console.log("=============触米de: "+de);
- if (!this._isVivo) {
- if (callbacks) {
- callbacks(true);
- }
- return;
- }
- var self = this;
- if (this._random <= 0) {
- //随机8位
- this._random = this._utils.getRandomInt(0, 10000);
- }
- this._gameCode = gameCode;
- this._utils.addListener(this);
- this.requestConfig();
- self._gameTime = new Date().getTime();
- VivoAd_1.default.Instance.onHide(function () {
- var curTime = new Date().getTime();
- var time = curTime - self._gameTime;
- self.durationLog(Math.floor(time / 1000), 0);
- self._gameTime = 0;
- _this._utils.log("********用户退出游戏或退到后台: " + (time / 1000));
- });
- VivoAd_1.default.Instance.onShow(function () {
- self._gameTime = new Date().getTime();
- _this._utils.log("*******用户回到游戏");
- });
- // this.index++;
- // if(this.index>2){
- // this.index = 0;
- // }
- // this.scheduleOnce(()=>{
- // SDK.Instance.init(gameCode,this.index,null);
- // },10);
- };
- //自动刷新广告
- SDK.prototype.flushConfig = function () {
- if (!this._isVivo) {
- return;
- }
- var self = this;
- var go = function () {
- if (self._loading) {
- self.unschedule(go);
- return;
- }
- if (self._netInitCount > 2) {
- self._utils.ok(null);
- self.unschedule(go);
- return;
- }
- self._netInitCount++;
- self.requestConfig();
- };
- this.schedule(go, 10);
- };
- //监听网络回调
- SDK.prototype.onOk = function (config) {
- if (!this._isVivo) {
- return;
- }
- this._config = config;
- var self = this;
- if (this._config) {
- this._loading = true;
- VivoAd_1.default.Instance.initConfig(this._config, function () {
- if (self._initCallbacks) {
- self._initCallbacks(true);
- }
- });
- }
- else {
- self._utils.log("********* initConfig is faill : " + JSON.stringify(this._config));
- if (self._initCallbacks && !this._loading) {
- self._initCallbacks(false);
- this.flushConfig();
- }
- }
- };
- /**
- * 展示banner
- * @param type 原生广告类型
- * @param top 是否展示顶部
- * @param x
- * @param y
- */
- SDK.prototype.showBanner = function (type, top, y, x) {
- if (type === void 0) { type = NativeAdComponent_1.NativeType.BANNER; }
- if (top === void 0) { top = false; }
- if (y === void 0) { y = 0; }
- if (x === void 0) { x = 0; }
- if (!this._isVivo) {
- return;
- }
- this.hideBanner();
- VivoAd_1.default.Instance.showBanner(type, top, y, x);
- };
- /**
- * 隐藏banner
- */
- SDK.prototype.hideBanner = function () {
- if (!this._isVivo) {
- return;
- }
- VivoAd_1.default.Instance.hideBanner();
- };
- SDK.prototype.hideIcon = function () {
- if (!this._isVivo) {
- return;
- }
- VivoAd_1.default.Instance.hideIcon();
- };
- /**
- * 展示原生插屏
- * 默认id节点为第一个0,有多个时,按服务端配置为准,进行传参
- * @param node 默认0
- * @param isforever true时,每次调用都会展示,false时,受服务器调用次数控制,默认false
- * @param id
- */
- SDK.prototype.showInterstitial = function (id) {
- if (id === void 0) { id = Interstitial_1.InterstitialType.INTERSTITIAL_GAME_OVER; }
- if (!this._isVivo) {
- return;
- }
- VivoAd_1.default.Instance.showInterstitial(id);
- };
- /**
- * 展示原生icon广告
- * 默认id节点为第一个0,有多个时,按服务端配置为准,进行传参
- * @param node
- * @param x
- * @param y
- * @param id
- */
- SDK.prototype.showIconAd = function (x, y, id) {
- if (id === void 0) { id = 0; }
- if (!this._isVivo) {
- return;
- }
- this.hideIcon();
- VivoAd_1.default.Instance.showIconAd(id, x, y);
- };
- /*0显示视频*/
- SDK.prototype.showRewardVideo = function (callBacks, fail, noAd) {
- console.log('a');
- if (!this._isVivo) {
- console.log('b');
- return;
- }
- console.log('c');
- VivoAd_1.default.Instance.showRewardVideo(callBacks, fail, noAd);
- console.log('d');
- };
- //toast提示框
- SDK.prototype.showToast = function (message) {
- if (!this._isVivo) {
- return;
- }
- if (VivoAd_1.default.Instance) {
- VivoAd_1.default.Instance.showToast(message);
- }
- };
- /**
- * 游戏结算界面数分延迟
- * @param lable
- * @param score
- * @param cb
- */
- SDK.prototype.gameResultDelayedTime = function (lable, score, cb) {
- var _this = this;
- if (this._config && score > 0) {
- var dalayedTime = this._config.maxClickCount;
- if (dalayedTime > 0) {
- var count_1 = 0;
- var s = Math.floor((dalayedTime / score) * 100) / 100;
- var add_1 = score / 200;
- if (add_1 < 1) {
- add_1 = 1;
- }
- this._utils.log("----time: " + dalayedTime + " s: " + s + " add: " + add_1);
- var go_1 = function () {
- count_1 = Math.floor(count_1 + add_1);
- if (count_1 > score) {
- _this.unschedule(go_1);
- lable.string = "" + score;
- if (cb) {
- cb();
- }
- return;
- }
- if (lable) {
- lable.string = "" + count_1;
- }
- };
- this.schedule(go_1, s);
- }
- else {
- lable.string = "" + score;
- if (cb) {
- this.scheduleOnce(function () {
- cb();
- }, 0.2);
- }
- }
- }
- else {
- lable.string = "" + score;
- if (cb) {
- this.scheduleOnce(function () {
- cb();
- }, 0.2);
- }
- }
- };
- /**
- * 激励AD 加载
- */
- SDK.prototype.initAdForPage = function () {
- if (cc.sys.os === cc.sys.OS_ANDROID) {
- var deviceId = ATAndroidJS2_1.default.getDeviceUserId();
- console.log("zh:checkstatus:", ATRewardedVideoJSSDK_1.default.checkAdStatus(ATAndroidJS2_1.default.getPlacementId()));
- var setting = {};
- setting[ATRewardedVideoJSSDK_1.default.userIdKey] = deviceId;
- ATRewardedVideoJSSDK_1.default.loadRewardedVideo(ATAndroidJS2_1.default.getPlacementId(), setting);
- }
- };
- var SDK_1;
- SDK._instance = null;
- SDK = SDK_1 = __decorate([
- ccclass
- ], SDK);
- return SDK;
- }(cc.Component));
- exports.default = SDK;
- cc["SDK"] = SDK.Instance;
- cc._RF.pop();
|