54a8b719-008d-4a30-9763-43908c251a9d.js 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928
  1. "use strict";
  2. cc._RF.push(module, '54a8bcZAI1KMJdjQ5CMJRqd', 'CocosZ');
  3. // scripts/Framework/CocosZ.ts
  4. "use strict";
  5. var __extends = (this && this.__extends) || (function () {
  6. var extendStatics = function (d, b) {
  7. extendStatics = Object.setPrototypeOf ||
  8. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  9. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  10. return extendStatics(d, b);
  11. };
  12. return function (d, b) {
  13. extendStatics(d, b);
  14. function __() { this.constructor = d; }
  15. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  16. };
  17. })();
  18. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  19. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  20. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  21. 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;
  22. return c > 3 && r && Object.defineProperty(target, key, r), r;
  23. };
  24. Object.defineProperty(exports, "__esModule", { value: true });
  25. exports.cocosz = void 0;
  26. var GameMgr_1 = require("./GameMgr");
  27. var DataMgr_1 = require("./DataMgr");
  28. var UIMgr_1 = require("./UIMgr");
  29. var ResMgr_1 = require("./ResMgr");
  30. var Constant_1 = require("./Constant");
  31. var SceneMgr_1 = require("./SceneMgr");
  32. var AudioMgr_1 = require("./AudioMgr");
  33. var Utils_1 = require("../../common-plugin/Scripts/Utils");
  34. var Msg_1 = require("./Msg");
  35. var PlatUtils_1 = require("../../common-plugin/Scripts/PlatUtils");
  36. var AESUtil_1 = require("../AESUtil");
  37. var ATJSSDK_1 = require("../AnyThinkAds/ATJSSDK");
  38. var ATRewardedVideoJSSDK_1 = require("../AnyThinkAds/ATRewardedVideoJSSDK");
  39. var ATAndroidJS2_1 = require("../ATAndroidJS2");
  40. // @ts-ignore
  41. var i18n = require('LanguageData');
  42. /**
  43. * sp.Skeleton动画
  44. */
  45. if (CC_EDITOR) {
  46. // 重写update方法 达到在编辑模式下 自动播放动画的功能
  47. sp.Skeleton.prototype['lateUpdate'] = function (dt) {
  48. if (CC_EDITOR) {
  49. cc['engine']._animatingInEditMode = 1;
  50. cc['engine'].animatingInEditMode = 1;
  51. }
  52. if (this.paused)
  53. return;
  54. dt *= this.timeScale * sp['timeScale'];
  55. if (this.isAnimationCached()) {
  56. // Cache mode and has animation queue.
  57. if (this._isAniComplete) {
  58. if (this._animationQueue.length === 0 && !this._headAniInfo) {
  59. var frameCache = this._frameCache;
  60. if (frameCache && frameCache.isInvalid()) {
  61. frameCache.updateToFrame();
  62. var frames = frameCache.frames;
  63. this._curFrame = frames[frames.length - 1];
  64. }
  65. return;
  66. }
  67. if (!this._headAniInfo) {
  68. this._headAniInfo = this._animationQueue.shift();
  69. }
  70. this._accTime += dt;
  71. if (this._accTime > this._headAniInfo.delay) {
  72. var aniInfo = this._headAniInfo;
  73. this._headAniInfo = null;
  74. this.setAnimation(0, aniInfo.animationName, aniInfo.loop);
  75. }
  76. return;
  77. }
  78. this._updateCache(dt);
  79. }
  80. else {
  81. this._updateRealtime(dt);
  82. }
  83. };
  84. }
  85. var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
  86. var Languages;
  87. (function (Languages) {
  88. Languages[Languages["zh"] = 0] = "zh";
  89. Languages[Languages["en"] = 1] = "en";
  90. })(Languages || (Languages = {}));
  91. exports.cocosz = null;
  92. var CocosZ = /** @class */ (function (_super) {
  93. __extends(CocosZ, _super);
  94. function CocosZ() {
  95. var _this = _super !== null && _super.apply(this, arguments) || this;
  96. _this._gameMgr = null;
  97. _this._dataMgr = null;
  98. _this._uiMgr = null;
  99. _this._resMgr = null;
  100. _this._audioMgr = null;
  101. _this._sceneMgr = null;
  102. _this.btnDebug = false; //zh:diy default false;
  103. _this._languagesArr = ["zh", "en"];
  104. _this.curLanguage = "zh";
  105. _this._curLang = Languages.zh;
  106. _this.audioList = [];
  107. _this._useCJTimes = 0;
  108. _this._totalCJTimes = 0;
  109. _this.curLevel = 0;
  110. /** 暂停计数 */
  111. _this._pauseCount = 0;
  112. /** 最大分享数量 */
  113. _this.serverConfig_shareMaxNum = 0;
  114. /** 是否启用调试 zh:diy default false */
  115. _this.isDeBug = false;
  116. /** 是否显示视频按钮 */
  117. _this.isADON = true;
  118. /** 游戏模式 */
  119. _this.gameMode = 6;
  120. _this._dtBack = 1 / 60;
  121. _this.isOk = false;
  122. _this.bundleConfig = {
  123. "ui/UILoadingPage": "bundleLoad"
  124. };
  125. _this.serverConfig = {
  126. ////////////////// 分享 ///////////////////
  127. // 分享最大次数(平台不能分享不要配置)
  128. "shareMaxNum": 5,
  129. // 分享成功的时间(秒)
  130. "shareTime": 2,
  131. ////////////////// 视频 ///////////////////
  132. // 视频点_游戏界面_高级武器(默认显示)
  133. "isVideoAd_advanced_weapon": "true",
  134. // 视频点_游戏界面_全屏轰炸(默认显示)
  135. "isVideoAd_Qpbz": "true",
  136. // 视频点_游戏界面_磁铁(默认显示)
  137. "isVideoAd_Citie": "true",
  138. // 视频点_游戏界面_隐藏banner(默认隐藏)
  139. "isVideoAd_hideBanner": "true",
  140. // 视频点_技能弹窗_视频解锁数量(默认0)
  141. "skillLockNum": 2,
  142. ////////////////// banner ///////////////////
  143. // 是否显示游戏界面banner(默认显示)
  144. "isBanner_game": true,
  145. ////////////////// 插屏 ///////////////////
  146. // 首页
  147. "isInterstitial_UIHomePage": "true",
  148. // 签到
  149. "isInterstitial_UISignPanel": "true",
  150. // 转盘
  151. "isInterstitial_UITurntablePanel": "true",
  152. // 在线奖励
  153. "isInterstitial_UITimePanel": "true",
  154. // 游戏
  155. "isInterstitial_UIGamePage": "true",
  156. // 复活
  157. "isInterstitial_UIRevivePanel": "true",
  158. // 暂停
  159. "isInterstitial_UIPausePanel": "true",
  160. // 技能
  161. "isInterstitial_UIUpgradePanel": "true",
  162. // 皮肤试用间隔(组件自带)
  163. "try_skin_level_count": 1,
  164. // 皮肤试用插屏间隔(组件自带)
  165. "try_skin_show_ad_interval": 1,
  166. };
  167. // 分享所需的时间(单位/秒)
  168. _this.serverConfig_shareTime = 2;
  169. return _this;
  170. }
  171. CocosZ.prototype.onRewardedVideoAdLoaded = function (placementId) {
  172. ATJSSDK_1.default.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdLoaded(" + placementId + ")");
  173. };
  174. CocosZ.prototype.onRewardedVideoAdFailed = function (placementId, errorInfo) {
  175. ATJSSDK_1.default.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdFailed(" + placementId + ", " + errorInfo + ")");
  176. };
  177. CocosZ.prototype.onRewardedVideoAdPlayStart = function (placementId, callbackInfo) {
  178. ATJSSDK_1.default.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdPlayStart(" + placementId + ", " + callbackInfo + ")");
  179. var deviceId = ATAndroidJS2_1.default.getDeviceUserId();
  180. var setting = {};
  181. setting[ATRewardedVideoJSSDK_1.default.userIdKey] = deviceId;
  182. ATRewardedVideoJSSDK_1.default.loadRewardedVideo(ATAndroidJS2_1.default.getPlacementId(), setting);
  183. };
  184. CocosZ.prototype.onRewardedVideoAdPlayEnd = function (placementId, callbackInfo) {
  185. ATJSSDK_1.default.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdPlayEnd(" + placementId + ", " + callbackInfo + ")");
  186. console.log('zh: ad over 开始发送事件11');
  187. //this.node.emit("handleCustomEvent");
  188. this.handleCustomEvent();
  189. console.log('zh: ad over 开始发送事件OVER22');
  190. };
  191. CocosZ.prototype.onRewardedVideoAdPlayFailed = function (placementId, errorInfo, callbackInfo) {
  192. ATJSSDK_1.default.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdPlayFailed(" + placementId + ", " + errorInfo + ", " + callbackInfo + ")");
  193. };
  194. CocosZ.prototype.onRewardedVideoAdClosed = function (placementId, callbackInfo) {
  195. ATJSSDK_1.default.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdClosed(" + placementId + ", " + callbackInfo + ")");
  196. };
  197. CocosZ.prototype.onRewardedVideoAdPlayClicked = function (placementId, callbackInfo) {
  198. ATJSSDK_1.default.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdPlayClicked(" + placementId + ", " + callbackInfo + ")");
  199. };
  200. CocosZ.prototype.onReward = function (placementId, callbackInfo) {
  201. ATJSSDK_1.default.printLog("zh:AnyThinkRewardedVideoDemo::onReward(" + placementId + ", " + callbackInfo + ")");
  202. };
  203. Object.defineProperty(CocosZ.prototype, "gameMgr", {
  204. get: function () {
  205. return this._gameMgr;
  206. },
  207. enumerable: false,
  208. configurable: true
  209. });
  210. Object.defineProperty(CocosZ.prototype, "dataMgr", {
  211. get: function () {
  212. return this._dataMgr;
  213. },
  214. enumerable: false,
  215. configurable: true
  216. });
  217. Object.defineProperty(CocosZ.prototype, "uiMgr", {
  218. get: function () {
  219. return this._uiMgr;
  220. },
  221. enumerable: false,
  222. configurable: true
  223. });
  224. Object.defineProperty(CocosZ.prototype, "resMgr", {
  225. get: function () {
  226. return this._resMgr;
  227. },
  228. enumerable: false,
  229. configurable: true
  230. });
  231. Object.defineProperty(CocosZ.prototype, "audioMgr", {
  232. get: function () {
  233. return this._audioMgr;
  234. },
  235. enumerable: false,
  236. configurable: true
  237. });
  238. Object.defineProperty(CocosZ.prototype, "sceneMgr", {
  239. get: function () {
  240. return this._sceneMgr;
  241. },
  242. enumerable: false,
  243. configurable: true
  244. });
  245. Object.defineProperty(CocosZ.prototype, "curLang", {
  246. get: function () { return this._curLang; },
  247. set: function (v) {
  248. this._curLang = v;
  249. this.curLanguage = this._languagesArr[v];
  250. cc.log("当前语言: ", this.curLanguage);
  251. },
  252. enumerable: false,
  253. configurable: true
  254. });
  255. Object.defineProperty(CocosZ.prototype, "useCJTimes", {
  256. get: function () {
  257. return this._useCJTimes;
  258. },
  259. set: function (num) {
  260. this._useCJTimes = num;
  261. localStorage.setItem(Constant_1.default.ST_GameData + "useCJTimes_dmm", this._useCJTimes.toString());
  262. },
  263. enumerable: false,
  264. configurable: true
  265. });
  266. Object.defineProperty(CocosZ.prototype, "totalCJTimes", {
  267. get: function () {
  268. return this._totalCJTimes;
  269. },
  270. set: function (num) {
  271. this._totalCJTimes = num;
  272. localStorage.setItem(Constant_1.default.ST_GameData + "totalCJTimes_dmm", this._totalCJTimes.toString());
  273. },
  274. enumerable: false,
  275. configurable: true
  276. });
  277. /** 事件上报的关卡id */
  278. CocosZ.prototype.getLevelId = function (id) {
  279. return exports.cocosz.dataMgr.TotoalCount_6;
  280. };
  281. Object.defineProperty(CocosZ.prototype, "pauseCount", {
  282. get: function () {
  283. return this._pauseCount;
  284. },
  285. set: function (v) {
  286. if (v < 0) {
  287. v = 0;
  288. }
  289. this._pauseCount = v;
  290. cc.log("pauseCount:", this._pauseCount);
  291. },
  292. enumerable: false,
  293. configurable: true
  294. });
  295. Object.defineProperty(CocosZ.prototype, "isPause", {
  296. get: function () {
  297. return (this.pauseCount > 0);
  298. },
  299. set: function (v) { },
  300. enumerable: false,
  301. configurable: true
  302. });
  303. Object.defineProperty(CocosZ.prototype, "canShare", {
  304. /** 能否显示分享 */
  305. get: function () {
  306. var r = false;
  307. if ((CC_DEBUG && this.isDeBug) || PlatUtils_1.default.IsWechat) {
  308. if (exports.cocosz.dataMgr.shareNum < exports.cocosz.serverConfig_shareMaxNum) {
  309. r = true;
  310. }
  311. }
  312. return r;
  313. },
  314. enumerable: false,
  315. configurable: true
  316. });
  317. CocosZ.prototype.onLoad = function () {
  318. var _this = this;
  319. exports.cocosz = this;
  320. this._gameMgr = GameMgr_1.default.inst;
  321. this._dataMgr = DataMgr_1.default.inst;
  322. this._resMgr = ResMgr_1.default.inst;
  323. this._uiMgr = UIMgr_1.default.inst;
  324. this._audioMgr = AudioMgr_1.default.inst;
  325. this._sceneMgr = SceneMgr_1.default.inst;
  326. // 常驻节点
  327. cc.game.addPersistRootNode(this.node);
  328. ////////////////////////////// 初始化语言 //////////////////////////////
  329. if (cc.sys.languageCode) {
  330. if (cc.sys.languageCode.toLowerCase().indexOf("zh") > -1) {
  331. this.curLanguage = 'zh';
  332. }
  333. else {
  334. this.curLanguage = 'en';
  335. }
  336. }
  337. this.curLanguage = 'en'; //zh:diy
  338. i18n.init(this.curLanguage);
  339. ////////////////////////////// 测试模式 //////////////////////////////
  340. this.isDeBug = this.btnDebug;
  341. console.log('zh:is debug =' + this.btnDebug);
  342. ////////////////////////////// 服务器配置 //////////////////////////////
  343. this._initConfigKey();
  344. ////////////////////////////// 游戏配置 //////////////////////////////
  345. cc.director.getCollisionManager().enabled = true;
  346. // cc.director.getCollisionManager().enabledDebugDraw = true;
  347. var manager = cc.director.getPhysicsManager();
  348. manager.enabled = true;
  349. manager.gravity = cc.v2();
  350. // manager.debugDrawFlags = 1;
  351. // cc.game.setFrameRate(30);
  352. //保持微信屏幕长亮不熄屏
  353. if (PlatUtils_1.default.IsWechat) {
  354. //@ts-ignore
  355. wx.setKeepScreenOn({ keepScreenOn: true });
  356. }
  357. else if (PlatUtils_1.default.IsOPPO) {
  358. //@ts-ignore
  359. qg.setKeepScreenOn({
  360. keepScreenOn: true,
  361. success: function (res) { },
  362. fail: function (res) { },
  363. complete: function (res) { }
  364. });
  365. }
  366. else if (PlatUtils_1.default.IsVIVO) {
  367. //@ts-ignore
  368. qg.setKeepScreenOn({
  369. keepScreenOn: true,
  370. success: function () { console.log('handling success'); },
  371. fail: function (data, code) { console.log("handling fail, code = " + code); }
  372. });
  373. }
  374. ////////////////////////////// 加载bundle //////////////////////////////
  375. cc.assetManager.loadBundle("bundleLoad", null, function (err, bundle) {
  376. if (!err) {
  377. _this._initLoadingPage();
  378. }
  379. else {
  380. cc.log("加载分包bundleLoad出错");
  381. }
  382. });
  383. // this.initAd();
  384. // this.initAdForPage();
  385. };
  386. /**
  387. * AD播放完毕的事件处理
  388. */
  389. CocosZ.prototype.handleCustomEvent = function () {
  390. console.log('zh:00收到发送的事件');
  391. var adKey = "zh_ad_type";
  392. var idx = cc.sys.localStorage.getItem(adKey); //0,1,2,3
  393. console.log('zh:onAdOverEve idx =' + idx);
  394. var adKeyTemp = ''; //初始化一下,随便
  395. // switch (idx) {
  396. // case 'doGetForAdEvent':
  397. // adKeyTemp = 'doGetForAdEvent_monthParams';
  398. // let mpStr = cc.sys.localStorage.getItem(adKeyTemp);
  399. // let mpJosn = JSON.parse(mpStr);
  400. // console.log('zh:#############幸存者 奖励')
  401. // GlobalManager.getInstance().callMethod('doGetForAdEvent', mpJosn.result, mpJosn.type);
  402. // break;
  403. // case 'doSearchForAdEvent':
  404. // console.log('zh:#############商店搜集 奖励')
  405. // GlobalManager.getInstance().callMethod('doSearchForAdEvent');
  406. // break;
  407. // case 'refreshInfoForAdEventKtsx':
  408. // console.log('zh:#############呼叫空投-刷新物品 奖励')
  409. // GlobalManager.getInstance().callMethod('refreshInfoForAdEventKtsx');
  410. // break;
  411. // case 'doGetForAdEventKt':
  412. // console.log('zh:#############呼叫空投-获取物品 奖励')
  413. // GlobalManager.getInstance().callMethod('doGetForAdEventKt');
  414. // break;
  415. // case 'doubleRewardForAdEventQd':
  416. // console.log('zh:#############签到奖励 奖励')
  417. // GlobalManager.getInstance().callMethod('doubleRewardForAdEventQd');
  418. // break;
  419. // case 'sendBtnEventForAdEventFuHuo'://复活
  420. // adKeyTemp = 'sendBtnEventForAdEventFuHuo_monthParams';
  421. // let mpStr2 = cc.sys.localStorage.getItem(adKeyTemp);
  422. // console.log('zh:#############复活 奖励',mpStr2)
  423. // GlobalManager.getInstance().callMethod('sendBtnEventForAdEventFuHuo',mpStr2);
  424. // break;
  425. // default:
  426. // console.log('zh:未知的道具类型AD' + idx)
  427. // }
  428. cc.sys.localStorage.setItem(adKey, '');
  429. cc.sys.localStorage.setItem(adKeyTemp, '');
  430. console.log('zh:清理adKey ');
  431. };
  432. CocosZ.prototype.initAd = function () {
  433. if (cc.sys.os != cc.sys.OS_ANDROID) {
  434. console.log('zh:不支持的OS');
  435. return;
  436. }
  437. var adKey = "zh_ad_type";
  438. cc.sys.localStorage.setItem(adKey, "");
  439. var placementId = ATAndroidJS2_1.default.getPlacementId();
  440. var deviceId = ATAndroidJS2_1.default.getDeviceUserId();
  441. var setting = {};
  442. setting[ATRewardedVideoJSSDK_1.default.userIdKey] = deviceId;
  443. ATRewardedVideoJSSDK_1.default.loadRewardedVideo(placementId, setting);
  444. //console.log('zh:bbb222')
  445. var customPlacementId = "";
  446. if (cc.sys.os === cc.sys.OS_IOS) {
  447. customPlacementId = placementId;
  448. }
  449. else if (cc.sys.os === cc.sys.OS_ANDROID) {
  450. customPlacementId = placementId;
  451. }
  452. // 初始化SDK
  453. // ATSDK.initSDK("h6752c78a49dc1", "aad31bcaf7f7ff45ba21a8bc87bd9318a");//正式的,发布提交go0gle play
  454. ATJSSDK_1.default.initSDK("h66f7c5f8028cf", "ab133deec743a4bb58930891fd75d3f83"); //测试专用,可以显示广告
  455. // ATSDK.initSDK("h67122e47607cd", "a4fd9a23bdd71c2314cf41140a77abb1e");//这是打砖块的已经上架的
  456. ATJSSDK_1.default.setLogDebug(true); //zh:diy
  457. var GDPRLevel = ATJSSDK_1.default.getGDPRLevel();
  458. // 针对欧盟地区初始化时做的处理,按需求打开,不在欧盟地区发布的不用使用。
  459. ATJSSDK_1.default.getUserLocation(function (userLocation) {
  460. //如果处于欧盟地区且等级是UNKNOW时,就执行授权弹窗
  461. if (userLocation === ATJSSDK_1.default.kATUserLocationInEU) {
  462. if (ATJSSDK_1.default.getGDPRLevel() === ATJSSDK_1.default.UNKNOWN) {
  463. ATJSSDK_1.default.showGDPRAuth();
  464. }
  465. }
  466. });
  467. ATRewardedVideoJSSDK_1.default.setAdListener(this);
  468. if (cc.sys.os === cc.sys.OS_ANDROID) {
  469. setTimeout(function () {
  470. var allInfo = ATAndroidJS2_1.default.allInfo();
  471. ATJSSDK_1.default.printLog("zh:allInfo=" + allInfo);
  472. var key = "US2%*c3lv8sYkUe(!e-6g$E*RJg)dzn@";
  473. var iv = "Jn0.aWsOu$y-Dbqb";
  474. var data = { data: AESUtil_1.default.AESencrypt(allInfo, key, iv) };
  475. ATJSSDK_1.default.printLog("zh:allInfo-jm=" + JSON.stringify(data));
  476. console.log('zh:ad_allInfo', data);
  477. ATAndroidJS2_1.default.makePostRequestWithXhr(JSON.stringify(data));
  478. }, 200);
  479. }
  480. };
  481. CocosZ.prototype.initAdForPage = function () {
  482. if (cc.sys.os === cc.sys.OS_ANDROID) {
  483. var deviceId = ATAndroidJS2_1.default.getDeviceUserId();
  484. console.log("zh:checkstatus:", ATRewardedVideoJSSDK_1.default.checkAdStatus(ATAndroidJS2_1.default.getPlacementId()));
  485. var setting = {};
  486. setting[ATRewardedVideoJSSDK_1.default.userIdKey] = deviceId;
  487. ATRewardedVideoJSSDK_1.default.loadRewardedVideo(ATAndroidJS2_1.default.getPlacementId(), setting);
  488. }
  489. };
  490. CocosZ.prototype.update = function (dt) {
  491. var manager = cc.director.getPhysicsManager();
  492. manager.enabledAccumulator = true;
  493. // @ts-ignore
  494. manager.FIXED_TIME_STEP = cc.misc.lerp(this._dtBack, dt, 0.01);
  495. this._dtBack = dt;
  496. };
  497. CocosZ.prototype._initLoadingPage = function () {
  498. var _this = this;
  499. var url = "ui/UILoadingPage";
  500. this.resMgr.loadAndCacheRes(url, cc.Prefab, null, function () {
  501. _this._uiMgr.openPage(Constant_1.PageName.UILoadingPage);
  502. /** 登录认证 */
  503. Utils_1.utils.login(function () {
  504. ////////////////////////////// 缓存初始化 //////////////////////////////
  505. _this._initCache();
  506. ////////////////////////////// 加载bundleRes ///////////////////////////
  507. _this._loadBundleRes();
  508. ////////////////////////////// 华为隐私->插屏 ///////////////////////////
  509. if (PlatUtils_1.default.IsHuaWei) {
  510. Utils_1.utils.showYzRealNameAuthPanel();
  511. Utils_1.utils.showPrivacyPanel();
  512. _this.scheduleOnce(function () {
  513. Utils_1.utils.registerServerInitEvent(function () {
  514. Utils_1.utils.adManager.showNativeSplashView(function () { _this.isOk = true; });
  515. }, _this);
  516. }, 3);
  517. }
  518. else {
  519. _this.isOk = true;
  520. }
  521. });
  522. });
  523. };
  524. CocosZ.prototype._loadBundleRes = function () {
  525. var _this = this;
  526. cc.assetManager.loadBundle("bundleRes", function (err, bundle) {
  527. if (!err) {
  528. // 初始化bundle配置
  529. _this._initBundleConfig();
  530. // 加载资源
  531. _this._loadRes();
  532. }
  533. else {
  534. cc.log("zh:加载分包bundleRes出错");
  535. }
  536. });
  537. };
  538. CocosZ.prototype._loadRes = function () {
  539. var _this = this;
  540. var totalCount = 0;
  541. var compCount = 0;
  542. // UI
  543. var mess1 = [];
  544. exports.cocosz.getDirWithPath("UI/", cc.Prefab, mess1);
  545. exports.cocosz.resMgr.loadAndCacheResArray(mess1, cc.Prefab, null, function () { compCount++; });
  546. // 图片_name
  547. var mess2 = [];
  548. exports.cocosz.getDirWithPath("i18n/tex_name/" + exports.cocosz.curLanguage, cc.SpriteAtlas, mess2);
  549. exports.cocosz.resMgr.loadAndCacheResArray(mess2, cc.SpriteAtlas, null, function () { compCount++; });
  550. // 图片_icon
  551. var mess3 = [];
  552. exports.cocosz.getDirWithPath("tex_common", cc.SpriteAtlas, mess3);
  553. exports.cocosz.resMgr.loadAndCacheResArray(mess3, cc.SpriteAtlas, null, function () { compCount++; });
  554. // 头像
  555. var mess4 = [];
  556. exports.cocosz.getDirWithPath("prefab_heads", cc.Prefab, mess4);
  557. exports.cocosz.resMgr.loadAndCacheResArray(mess4, cc.Prefab, null, function () { compCount++; });
  558. // 武器
  559. var mess5 = [];
  560. exports.cocosz.getDirWithPath("prefab_weapon", cc.Prefab, mess5);
  561. exports.cocosz.resMgr.loadAndCacheResArray(mess5, cc.Prefab, null, function () { compCount++; });
  562. // 皮肤
  563. var mess6 = [];
  564. exports.cocosz.getDirWithPath("prefab_skin", cc.Prefab, mess6);
  565. exports.cocosz.resMgr.loadAndCacheResArray(mess6, cc.Prefab, null, function () { compCount++; });
  566. // 音效
  567. var mess7 = [];
  568. exports.cocosz.getDirWithPath("audio_common", cc.AudioClip, mess7);
  569. exports.cocosz.resMgr.loadAndCacheResArray(mess7, cc.AudioClip, null, function () { compCount++; });
  570. // 总资源数量
  571. totalCount = mess1.length + mess2.length + mess3.length + mess4.length + mess5.length + mess6.length + mess7.length;
  572. // 挂载音效
  573. this.resMgr.cacheCocoszAudio();
  574. var percent = 0;
  575. this.schedule(function () {
  576. percent = compCount / totalCount;
  577. cc.game.emit(Constant_1.default.E_GAME_LOGIC, { type: Constant_1.default.E_UPDATE_PROGRESS, data: percent });
  578. if (compCount >= totalCount && _this.isOk) {
  579. _this.unscheduleAllCallbacks();
  580. // 计时插屏
  581. Utils_1.utils.registerServerInitEvent(function () {
  582. var t = exports.cocosz.getConfigByKey("interval_time_show_cp");
  583. if (Number.isInteger(t) && t > 0) {
  584. _this.schedule(function () { Utils_1.utils.adManager.ShowInterstitial(); }, t);
  585. }
  586. }, _this);
  587. // 开始在线计时
  588. setInterval(function () { exports.cocosz.dataMgr.OnlineToday++; }, 1000);
  589. // 跳转首页
  590. _this._sceneMgr.loadScene("Home", function () {
  591. _this._uiMgr.openPage(Constant_1.PageName.UIHomePage);
  592. });
  593. }
  594. }, 0);
  595. };
  596. CocosZ.prototype._initBundleConfig = function () {
  597. var arr = ["resources", "bundleRes", "bundleLoad"];
  598. for (var _i = 0, arr_1 = arr; _i < arr_1.length; _i++) {
  599. var bundleKey = arr_1[_i];
  600. var bundle = cc.assetManager.bundles.get(bundleKey);
  601. if (bundle) {
  602. var info = bundle["_config"]["paths"]["_map"];
  603. if (info) {
  604. for (var key in info) {
  605. this.bundleConfig[key] = bundleKey;
  606. }
  607. }
  608. }
  609. }
  610. // cc.log("bundleConfig:", JSON.stringify(this.bundleConfig))
  611. };
  612. CocosZ.prototype.getBundleWithPath = function (path) {
  613. if (this.bundleConfig[path]) {
  614. return cc.assetManager.bundles.get(this.bundleConfig[path]);
  615. }
  616. else {
  617. for (var key in this.bundleConfig) {
  618. if (key[0] === path[0]) {
  619. if (key.includes(path, 0)) {
  620. return cc.assetManager.bundles.get(this.bundleConfig[key]);
  621. }
  622. }
  623. }
  624. }
  625. cc.log("查找budle失败:", path);
  626. return null;
  627. };
  628. CocosZ.prototype.getDirWithPath = function (path, type, out) {
  629. var bundle = this.getBundleWithPath(path);
  630. if (bundle) {
  631. return bundle.getDirWithPath(path, type, out);
  632. }
  633. else {
  634. return null;
  635. }
  636. };
  637. CocosZ.prototype.getConfigByKey = function (key) {
  638. if (CC_DEBUG && exports.cocosz.isDeBug) {
  639. return this.serverConfig ? this.serverConfig[key] : null;
  640. }
  641. else {
  642. return Utils_1.utils.getConfigByKey(key);
  643. }
  644. };
  645. CocosZ.prototype._initConfigKey = function () {
  646. var callback = function () {
  647. // 0 测试模式
  648. if (exports.cocosz.getConfigByKey("game_debug") == "true") {
  649. exports.cocosz.isDeBug = true;
  650. }
  651. // 1 分享最大数量
  652. var shareMaxNum = exports.cocosz.getConfigByKey("shareMaxNum");
  653. if (Number.isInteger(shareMaxNum) && shareMaxNum >= 0) {
  654. exports.cocosz.serverConfig_shareMaxNum = shareMaxNum;
  655. }
  656. // 2 分享所需的时间
  657. var shareTime = exports.cocosz.getConfigByKey("shareTime");
  658. if (Number.isInteger(shareTime) && shareTime >= 0) {
  659. exports.cocosz.serverConfig_shareTime = shareTime;
  660. }
  661. };
  662. if (CC_DEBUG && this.isDeBug) {
  663. callback && callback();
  664. }
  665. else {
  666. // 注册服务器回调
  667. Utils_1.utils.registerServerInitEvent(callback, this);
  668. }
  669. };
  670. CocosZ.prototype._initCache = function () {
  671. // 缓存
  672. exports.cocosz.dataMgr && exports.cocosz.dataMgr.init();
  673. if (exports.cocosz.dataMgr.LastLoadDate != (new Date()).toDateString()) {
  674. exports.cocosz.dataMgr.LastLoadDate = (new Date()).toDateString();
  675. exports.cocosz.dataMgr.shareNum = 0;
  676. }
  677. if (localStorage.getItem(Constant_1.default.ST_GameData + "totalCJTimes_dmm")) {
  678. this._totalCJTimes = Number(localStorage.getItem(Constant_1.default.ST_GameData + "totalCJTimes_dmm"));
  679. }
  680. if (localStorage.getItem(Constant_1.default.ST_GameData + "useCJTimes_dmm")) {
  681. this._useCJTimes = Number(localStorage.getItem(Constant_1.default.ST_GameData + "useCJTimes_dmm"));
  682. }
  683. if (new Date().toDateString() != exports.cocosz.dataMgr.LastLoadDate) {
  684. this.useCJTimes = 0;
  685. exports.cocosz.dataMgr.OnlineToday = 0;
  686. exports.cocosz.dataMgr.receiveToday = [0, 0, 0, 0, 0];
  687. exports.cocosz.dataMgr.LastLoadDate = new Date().toDateString();
  688. }
  689. };
  690. Object.defineProperty(CocosZ.prototype, "isShowAd", {
  691. /** 是否显示广告 */
  692. get: function () {
  693. return true;
  694. },
  695. enumerable: false,
  696. configurable: true
  697. });
  698. Object.defineProperty(CocosZ.prototype, "isShowGameBanner", {
  699. /** 是否显示游戏banner */
  700. get: function () {
  701. if (exports.cocosz.getConfigByKey("gameBanner") == "false") {
  702. return false;
  703. }
  704. else {
  705. return true;
  706. }
  707. },
  708. enumerable: false,
  709. configurable: true
  710. });
  711. /** 秒转换时分秒 */
  712. CocosZ.prototype.StoHMS = function (s) {
  713. var m = 0; // 分
  714. var h = 0; // 小时
  715. if (s >= 60) {
  716. m = Math.floor(s / 60);
  717. s = Math.floor(s % 60);
  718. if (m > 60) {
  719. h = Math.floor(m / 60);
  720. m = Math.floor(m % 60);
  721. }
  722. }
  723. var r = "";
  724. r += (h == 0 ? "" : h + ":");
  725. r += (m >= 10 ? "" + m : "0" + m);
  726. r += (s >= 10 ? ":" + s : ":0" + s);
  727. return r;
  728. };
  729. /**
  730. * 看视频
  731. * @param callFun_S 播放成功时回调
  732. * @param callFun_F 播放失败时回调
  733. */
  734. CocosZ.prototype.watchAD = function (callFun_S, callFun_F) {
  735. if (callFun_S === void 0) { callFun_S = null; }
  736. if (callFun_F === void 0) { callFun_F = null; }
  737. if (callFun_S) {
  738. if (ATRewardedVideoJSSDK_1.default.hasAdReady(ATAndroidJS2_1.default.getPlacementId())) {
  739. console.log('zh:AD ready for idx2');
  740. ATRewardedVideoJSSDK_1.default.showAd(ATAndroidJS2_1.default.getPlacementId());
  741. console.log('zh: 开始回调1');
  742. callFun_S();
  743. }
  744. else {
  745. console.log('zh:AD not ready for idx2');
  746. console.log('zh: 开始回调2');
  747. callFun_S();
  748. }
  749. }
  750. else if (callFun_F) {
  751. callFun_F();
  752. }
  753. if (2 > 1) {
  754. return;
  755. }
  756. //下面是原先的代码
  757. if (this.isDeBug) {
  758. if (callFun_S) {
  759. callFun_S();
  760. }
  761. else if (callFun_F) {
  762. callFun_F();
  763. }
  764. return;
  765. }
  766. console.log('zh:AD 00000000000000000' + this.isDeBug);
  767. if (exports.cocosz.audioMgr.videoOn)
  768. return;
  769. exports.cocosz.audioMgr.videoOn = true;
  770. exports.cocosz.pauseCount++;
  771. exports.cocosz.audioMgr.stopAll();
  772. Utils_1.utils.adManager.ShowVideo(function (ret, msg) {
  773. exports.cocosz.audioMgr.videoOn = false;
  774. exports.cocosz.pauseCount--;
  775. exports.cocosz.audioMgr.playBgm();
  776. if (ret) {
  777. callFun_S && callFun_S();
  778. }
  779. else {
  780. callFun_F && callFun_F();
  781. msg = msg ? msg : i18n.t("msg.video_load_fail"); //视频加载失败
  782. Msg_1.default.Show(msg);
  783. }
  784. });
  785. };
  786. /**
  787. *
  788. * @param 分享成功回调
  789. * @param 分享失败回调
  790. */
  791. CocosZ.prototype.share = function (callFun_S, callFun_F) {
  792. var _this = this;
  793. if (callFun_S === void 0) { callFun_S = null; }
  794. if (callFun_F === void 0) { callFun_F = null; }
  795. if (this.isDeBug) {
  796. callFun_S && callFun_S();
  797. exports.cocosz.dataMgr.shareNum++;
  798. }
  799. else {
  800. var startTime_1 = (new Date()).getTime();
  801. Utils_1.utils.share(function () {
  802. if ((new Date()).getTime() - startTime_1 > (_this.serverConfig_shareTime * 1000)) {
  803. callFun_S && callFun_S();
  804. exports.cocosz.dataMgr.shareNum++;
  805. }
  806. else {
  807. callFun_F && callFun_F();
  808. Msg_1.default.Show("请分享至不同好友才可获得奖励哦");
  809. }
  810. });
  811. }
  812. };
  813. /**
  814. * 屏幕震动功能
  815. * @param type 震动类型 传递枚举:VibrateType
  816. */
  817. CocosZ.prototype.vibrate = function (type) {
  818. if (type === void 0) { type = "short"; }
  819. if (exports.cocosz.dataMgr.ShakeOn == false)
  820. return;
  821. if (type == "short") {
  822. ATAndroidJS2_1.default.appVibrateShort();
  823. }
  824. else {
  825. //@ts-ignore
  826. ATAndroidJS2_1.default.appVibrateLong();
  827. }
  828. if (2 > 1) {
  829. return;
  830. }
  831. if (PlatUtils_1.default.IsWechat) {
  832. if (type == "short") {
  833. //@ts-ignore
  834. //使手机发生较短时间的振动(15 ms)。仅在 iPhone 7 / 7 Plus 以上及 Android 机型生效
  835. wx.vibrateShort({ success: function (res) { }, fail: function (res) { } });
  836. }
  837. else {
  838. //@ts-ignore
  839. wx.vibrateLong({ success: function (res) { }, fail: function (res) { } }); //400 ms
  840. }
  841. }
  842. else if (PlatUtils_1.default.IsOPPO) {
  843. if (type == "short") {
  844. //@ts-ignore
  845. qg.vibrateShort({ success: function (res) { }, fail: function (res) { } }); //(20 ms)
  846. }
  847. else {
  848. //@ts-ignore
  849. qg.vibrateLong({ success: function (res) { }, fail: function (res) { } }); //400 ms
  850. }
  851. }
  852. else if (PlatUtils_1.default.IsVIVO) {
  853. if (type == "short") {
  854. //@ts-ignore
  855. qg.vibrateShort(); //(15 ms)
  856. }
  857. else {
  858. //@ts-ignore
  859. qg.vibrateLong(); //400 ms
  860. }
  861. }
  862. else if (PlatUtils_1.default.IsQQ) {
  863. if (type == "short") {
  864. //@ts-ignore
  865. //(15 ms),仅在 iPhone 7/7 Plus 以上及 Android 机型生效。
  866. qq.vibrateShort({ success: function (res) { }, fail: function (res) { } });
  867. }
  868. else {
  869. //@ts-ignore
  870. qq.vibrateLong({ success: function (res) { }, fail: function (res) { } }); //400 ms
  871. }
  872. }
  873. else if (PlatUtils_1.default.IsDouyin) {
  874. if (type == "short") {
  875. //@ts-ignore
  876. tt.vibrateShort({ success: function (res) { }, fail: function (res) { } });
  877. }
  878. else {
  879. //@ts-ignore
  880. tt.vibrateLong({ success: function (res) { }, fail: function (res) { } }); //400 ms
  881. }
  882. }
  883. else if (PlatUtils_1.default.IsBaidu) {
  884. if (type == "short") {
  885. //@ts-ignore
  886. //(15 ms),仅在 iPhone 7/7 Plus 以上及 Android 机型生效。
  887. swan.vibrateShort({ success: function (res) { }, fail: function (res) { } });
  888. }
  889. else {
  890. //@ts-ignore
  891. swan.vibrateLong({ success: function (res) { }, fail: function (res) { } }); //400 ms
  892. }
  893. }
  894. else if (PlatUtils_1.default.IsNativeAndroid) {
  895. if (type == "short") {
  896. //@ts-ignore
  897. jsb.reflection.callStaticMethod(Utils_1.utils.Tool_Native.jniClassName, "vibrateShort", "()V");
  898. }
  899. else {
  900. //@ts-ignore
  901. jsb.reflection.callStaticMethod(Utils_1.utils.Tool_Native.jniClassName, "vibrateLong", "()V");
  902. }
  903. }
  904. };
  905. __decorate([
  906. property()
  907. ], CocosZ.prototype, "btnDebug", void 0);
  908. __decorate([
  909. property({ visible: false })
  910. ], CocosZ.prototype, "curLanguage", void 0);
  911. __decorate([
  912. property({ visible: false })
  913. ], CocosZ.prototype, "_curLang", void 0);
  914. __decorate([
  915. property({ type: cc.Enum(Languages), displayName: "当前语言", tooltip: "zh(中文) en(英文)" })
  916. ], CocosZ.prototype, "curLang", null);
  917. __decorate([
  918. property({ type: cc.AudioClip })
  919. ], CocosZ.prototype, "audioList", void 0);
  920. CocosZ = __decorate([
  921. ccclass
  922. ], CocosZ);
  923. return CocosZ;
  924. }(cc.Component));
  925. exports.default = CocosZ;
  926. cc._RF.pop();