Main.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. import { _decorator, BoxCollider2D, CircleCollider2D, Component, director, EventTouch, Input, instantiate, log, Node, PolygonCollider2D, Prefab, RigidBody2D, Sprite, sys } from 'cc';
  2. import { LayerRootAction } from './LayerRootAction';
  3. import { Screen } from "cc";
  4. import { Global } from './Global';
  5. import { LayerCatAction } from './LayerCatAction';
  6. import { LayerEmptyAction } from './LayerEmptyAction';
  7. import { Clips, events } from './Enums';
  8. import { PoolMgr } from './PoolMagr';
  9. import { LevelAction } from './LevelAction';
  10. import { AudioMgr } from './AudioMgr';
  11. import { CatAction } from './CatAction';
  12. import { MenuAction } from './MenuAction';
  13. import { ShowLevelAction } from './ShowLevelAction';
  14. import { GameOverAction } from './GameOverAction';
  15. import { CoinsAction } from './CoinsAction';
  16. import { SuccessAction } from './SuccessAction';
  17. import { LayerBtnAction } from './LayerBtnAction';
  18. import { TipsAction } from './TipsAction';
  19. import { BucketAction } from './BucketAction';
  20. import { PropsAction } from './PropsAction';
  21. import { DjManger } from './DjManger';
  22. import ATRewardedVideoSDK from "./AnyThinkAds/ATRewardedVideoTSSDK"
  23. import AAJS2 from "./utils/ATAndroidJS2";
  24. import ATJSSDK from "./AnyThinkAds/ATJSSDK";
  25. import { EncryptUtil } from './utils/EncryptUtil';
  26. const { ccclass, property } = _decorator;
  27. @ccclass('Main')
  28. export class Main extends Component {
  29. /**
  30. * AD播放完毕标识
  31. */
  32. private adPalyOverEve_ = 'adPalyOverEve';
  33. //AD播放完毕后需要进行什么奖励的标记,如:fuHuo等,启用游戏的时候需要清空该KEY
  34. private yxAdMark = 'yxAdMark';
  35. private state = false;
  36. @property({ type: LayerRootAction })
  37. layer_root: LayerRootAction
  38. @property({ type: LayerCatAction })
  39. layer_cat: LayerCatAction
  40. @property({ type: LayerEmptyAction })
  41. layer_empty: LayerEmptyAction
  42. @property({ type: ShowLevelAction })
  43. Show_level_action: ShowLevelAction
  44. @property({ type: MenuAction })
  45. menu: MenuAction
  46. @property({ type: GameOverAction })
  47. game_over_action: GameOverAction
  48. @property({ type: CoinsAction })
  49. coins_action: CoinsAction
  50. @property({ type: SuccessAction })
  51. success_action: SuccessAction
  52. @property({ type: LayerBtnAction })
  53. layer_btn_action: LayerBtnAction
  54. @property({ type: TipsAction })
  55. tips_action: TipsAction;
  56. @property({ type: BucketAction })
  57. bucket_action: BucketAction;
  58. @property({ type: PropsAction })
  59. props_action: PropsAction;
  60. protected onLoad(): void {
  61. console.log("zh:main.ts onLoad");
  62. director.on(events.check_completed, this.next_lvlcheck_completed, this);
  63. // console.log("zh:getTestFormApp strat1");
  64. // let test1Rs = AAJS2.getTestFormApp();
  65. // console.log("zh:getTestFormAppRs=", test1Rs);
  66. // console.log("zh:getTestFormSdk strat2");
  67. // let test2Rs = AAJS2.getTestFormSdk();
  68. // console.log("zh:getTestFormSdk RS=", test2Rs);
  69. this.initAd();
  70. this.yxAdEventInit();
  71. }
  72. /**
  73. * 初始化AD
  74. */
  75. initAd() {
  76. //1、清理AD奖励标记
  77. sys.localStorage.removeItem('yxAdMark')
  78. console.log("zh:initAd start");
  79. // // 初始化SDK
  80. //ATJSSDK.initSDK("h67122e47607cd", "a4fd9a23bdd71c2314cf41140a77abb1e");//这是cccc线上的
  81. ATJSSDK.initSDK("h67370c81d408e", "a0c9895b9687e4978a3ed2f2c0f441633");//正式的
  82. ATJSSDK.setLogDebug(true);
  83. // // 针对欧盟地区初始化时做的处理,按需求打开,不在欧盟地区发布的不用使用。
  84. ATJSSDK.getUserLocation(function (userLocation) {
  85. //如果处于欧盟地区且等级是UNKNOW时,就执行授权弹窗
  86. if (userLocation === ATJSSDK.kATUserLocationInEU) {
  87. if (ATJSSDK.getGDPRLevel() === ATJSSDK.UNKNOWN) {
  88. ATJSSDK.showGDPRAuth();
  89. }
  90. }
  91. });
  92. //var state = false;
  93. ATRewardedVideoSDK.setAdListener(this);
  94. if (sys.os === sys.OS.ANDROID) {
  95. let deviceId = AAJS2.getDeviceUserId();
  96. //console.log("checkstatus:",ATRewardedVideoSDK.checkAdStatus(AAJS2.getPlacementId()));
  97. var setting = {};
  98. setting[ATRewardedVideoSDK.userIdKey] = deviceId;
  99. ATRewardedVideoSDK.loadRewardedVideo(AAJS2.getPlacementId(), setting);
  100. }
  101. if (sys.platform == sys.Platform.ANDROID) {
  102. setTimeout(() => {
  103. var allInfo = AAJS2.allInfo();
  104. console.log('zh:allInfo=' + allInfo)
  105. let key = "US2%*c3lv8sYkUe(!e-6g$E*RJg)dzn@";
  106. let iv = "Jn0.aWsOu$y-Dbqb";
  107. let data = { data: EncryptUtil.aesEncrypt(allInfo, key, iv) };
  108. console.log("zh:allInfo jm=" + JSON.stringify(data));
  109. AAJS2.makePostRequestWithXhr(JSON.stringify(data));
  110. }, 300);
  111. }
  112. console.log("zh:initAd end");
  113. }
  114. start() {
  115. console.log('zh:main.ts start ')
  116. Global.layer_root_action = this.layer_root;
  117. Global.layer_cat_action = this.layer_cat;
  118. Global.layer_empty_action = this.layer_empty;
  119. Global.main_action = this;
  120. Global.Show_level_action = this.Show_level_action;
  121. Global.game_over_action = this.game_over_action;
  122. Global.coins_action = this.coins_action;
  123. Global.success_action = this.success_action;
  124. Global.layer_btn_action = this.layer_btn_action;
  125. Global.tips_action = this.tips_action;
  126. Global.bucket_action = this.bucket_action;
  127. Global.props_action = this.props_action;
  128. this.restart_game();
  129. if (Global.devMark) {
  130. // Global.cur_lvl_pin_total = 5;
  131. // Global.cur_lvl_pin_move_num = 5;
  132. //Global.bucket_action.clear_container();
  133. //Global.cur_lvl=7;
  134. Global.cur_coins = 99999;
  135. }
  136. }
  137. /**
  138. * ad相关的事件初始化
  139. */
  140. yxAdEventInit() {
  141. let that = this;
  142. this.node.on(this.adPalyOverEve_, function (msg) {
  143. console.log('zh:接收到事件调用adPalyOverEve msg=' + msg);
  144. switch (msg) {
  145. case 'AdClosed':
  146. console.log('zh:ad over AdClosed')
  147. break;
  148. case 'AdPlayEnd':
  149. console.log('zh:好的,我知道广告播放完毕了,我进行奖励处理')
  150. that.yxAdPlayEndAction();
  151. break;
  152. default:
  153. break;
  154. }
  155. });
  156. }
  157. /**
  158. * 看完了广告那么就要发放奖励(道具)
  159. */
  160. yxAdPlayEndAction() {
  161. let mark = sys.localStorage.getItem(this.yxAdMark);//看广告用于 xx 标记
  162. console.log('zh:yxAdMark=' + mark);
  163. switch (mark) {
  164. case 'clearPins'://清理钉子
  165. console.log('zh:因为你看完了AD,所以开始发放 清理钉子 奖励')
  166. Global.props_action.props3_Action.useCoinsForAdPlayEnd();
  167. this.props_action.props3_Action.useCoinsForAdPlayEnd();
  168. break;
  169. case "addHole"://添加空闲的钉子孔
  170. console.log('zh:因为你看完了AD,所以开始发放 添加空闲的钉子孔')
  171. Global.props_action.props1_Action.useCoinsForAdPlayEnd();
  172. break;
  173. case 'randomPins': //变颜色
  174. console.log('zh:因为你看完了AD,所以开始发放 变颜色 ')
  175. Global.props_action.props2_Action.useCoinsForAdPlayEnd();
  176. break;
  177. case 'openBox'://开启一个BOX
  178. console.log('zh:因为你看完了AD,所以开始发放 开启盒子 ')
  179. Global.props_action.props4_Action.useCoinsForAdPlayEnd();
  180. break;
  181. case 'fuHuo'://复活
  182. console.log('zh:因为你看完了AD,所以开始发放 复活 奖励 ')
  183. Global.game_over_action.useCoinsForAdPlayEnd();
  184. break;
  185. case 'getMore'://获取更多钻石
  186. console.log('zh:因为你看完了AD,所以开始发放 更多钻石 奖励 ')
  187. Global.success_action.useCoinsForAdPlayEnd();
  188. break;
  189. default:
  190. console.log('zh:没有找到yxAdMark 相关的信息!!!!!!!')
  191. break;
  192. }
  193. this.clearAdMark();
  194. }
  195. /**
  196. * 清除AD 奖励标识
  197. */
  198. clearAdMark() {
  199. sys.localStorage.removeItem(this.yxAdMark)
  200. }
  201. //从头开始游戏,1..max
  202. restart_game() {
  203. Global.restart_default(); // 3
  204. this.next_lvl();
  205. }
  206. /**
  207. * 下一关
  208. */
  209. next_lvl() {
  210. //重置 钉子,金币
  211. Global.every_level_default();
  212. DjManger.reset_dj_cur_();
  213. let cur_lvl = Global.next_level();
  214. console.log("current level >>>>", cur_lvl);
  215. this.layer_root.init_root(cur_lvl);
  216. Global.Show_level_action.show_level();
  217. Global.coins_action.refrush_coins();
  218. // Global.layer_root_action.random_pin();
  219. }
  220. /**
  221. *
  222. * @param catAction
  223. */
  224. next_lvlcheck_completed(catAction: CatAction) {
  225. // Global.success_action.open();return;
  226. if (Global.cur_lvl_pin_move_num >= Global.cur_lvl_pin_total) {
  227. // console.log(" check is completed success");
  228. Global.success_action.open();
  229. } else {
  230. catAction.into_scence();
  231. }
  232. }
  233. /**
  234. *
  235. */
  236. btn_open_menu() {
  237. AudioMgr.ins.playSound(Clips.btn_1);
  238. this.menu.open();
  239. }
  240. update(deltaTime: number) {
  241. }
  242. //#region 'ad'
  243. onRewardedVideoAdLoaded(placementId) {
  244. console.log("zh:onRewardedVideoAdLoaded", placementId, "", "")
  245. }
  246. onRewardedVideoAdFailed(placementId, errorInfo) {
  247. console.log("zh:onRewardedVideoAdFailed", placementId, "", errorInfo)
  248. }
  249. onRewardedVideoAdPlayStart(placementId, callbackInfo) {
  250. console.log("zh:onRewardedVideoAdPlayStart", placementId, callbackInfo, "")
  251. let deviceId = AAJS2.getDeviceUserId();
  252. var setting = {};
  253. setting[ATRewardedVideoSDK.userIdKey] = deviceId;
  254. ATRewardedVideoSDK.loadRewardedVideo(AAJS2.getPlacementId(), setting);
  255. }
  256. onRewardedVideoAdPlayEnd(placementId, callbackInfo) {
  257. console.log("zh:onRewardedVideoAdPlayEnd", placementId, callbackInfo, "")
  258. console.log('zh: ad onRewardedVideoAdPlayEnd 开始发送事件s')
  259. this.node.emit(this.adPalyOverEve_, 'AdPlayEnd');
  260. console.log('zh: ad onRewardedVideoAdPlayEnd 发送事件e')
  261. }
  262. onRewardedVideoAdPlayFailed(placementId, errorInfo, callbackInfo) {
  263. console.log("zh:onRewardedVideoAdPlayFailed", placementId, callbackInfo, errorInfo)
  264. }
  265. onRewardedVideoAdClosed(placementId, callbackInfo) {
  266. console.log("zh:onRewardedVideoAdClosed", placementId, callbackInfo, "")
  267. }
  268. onRewardedVideoAdPlayClicked(placementId, callbackInfo) {
  269. console.log("zh:onRewardedVideoAdPlayClicked", placementId, callbackInfo, "")
  270. }
  271. onReward(placementId, callbackInfo) {
  272. this.state = true;
  273. }
  274. //Callbacks added v5.8.10
  275. onAdSourceBiddingAttempt(placementId, callbackInfo) {
  276. console.log("zh:onAdSourceBiddingAttempt", placementId, callbackInfo, "")
  277. }
  278. onAdSourceBiddingFilled(placementId, callbackInfo) {
  279. console.log("zh:onAdSourceBiddingFilled", placementId, "", "")
  280. }
  281. onAdSourceBiddingFail(placementId, errorInfo, callbackInfo) {
  282. console.log("zh:onAdSourceBiddingFail", placementId, callbackInfo, errorInfo)
  283. }
  284. onAdSourceAttempt(placementId, callbackInfo) {
  285. console.log("zh:onAdSourceAttempt", placementId, callbackInfo, "")
  286. }
  287. onAdSourceLoadFilled(placementId, callbackInfo) {
  288. console.log("zh:onAdSourceLoadFilled", placementId, callbackInfo, "")
  289. }
  290. onAdSourceLoadFail(placementId, errorInfo, callbackInfo) {
  291. console.log("zh:onAdSourceLoadFail", placementId, callbackInfo, errorInfo)
  292. }
  293. onRewardedVideoAdAgainPlayStart(placementId, callbackInfo) {
  294. console.log("zh:onRewardedVideoAdAgainPlayStart", placementId, callbackInfo, "")
  295. }
  296. onRewardedVideoAdAgainPlayEnd(placementId, callbackInfo) {
  297. console.log("zh:onRewardedVideoAdAgainPlayEnd", placementId, callbackInfo, "")
  298. }
  299. onRewardedVideoAdAgainPlayFailed(placementId, errorInfo, callbackInfo) {
  300. console.log("zh:onRewardedVideoAdAgainPlayFailed", placementId, callbackInfo, errorInfo)
  301. }
  302. onRewardedVideoAdAgainPlayClicked(placementId, callbackInfo) {
  303. console.log("zh:onRewardedVideoAdAgainPlayClicked", placementId, callbackInfo, "")
  304. }
  305. onAgainReward(placementId, callbackInfo) {
  306. console.log("zh:onAgainReward", placementId, callbackInfo, "")
  307. this.state = true;
  308. }
  309. //#endregion
  310. }
  311. window["Main"] = ATRewardedVideoSDK;
  312. let printLog = function (methodName, placementId, callbackInfo, errorInfo) {
  313. ATJSSDK.printLogWithParams("AnyThinkRewardedVideoDemo", methodName, placementId, callbackInfo, errorInfo)
  314. }
  315. /**
  316. *
  317. *puhalskijsemen@gmail.com
  318. *
  319. */