Main.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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. initAd() {
  73. //1、清理AD奖励标记
  74. sys.localStorage.removeItem('yxAdMark')
  75. console.log("zh:initAd start");
  76. // // 初始化SDK
  77. ATJSSDK.initSDK("h67122e47607cd", "a4fd9a23bdd71c2314cf41140a77abb1e");//这是cccc线上的
  78. //ATJSSDK.initSDK("h66f7c5f8028cf", "ab133deec743a4bb58930891fd75d3f83");
  79. ATJSSDK.setLogDebug(true);
  80. // // 针对欧盟地区初始化时做的处理,按需求打开,不在欧盟地区发布的不用使用。
  81. ATJSSDK.getUserLocation(function (userLocation) {
  82. //如果处于欧盟地区且等级是UNKNOW时,就执行授权弹窗
  83. if (userLocation === ATJSSDK.kATUserLocationInEU) {
  84. if (ATJSSDK.getGDPRLevel() === ATJSSDK.UNKNOWN) {
  85. ATJSSDK.showGDPRAuth();
  86. }
  87. }
  88. });
  89. //var state = false;
  90. ATRewardedVideoSDK.setAdListener(this);
  91. if (sys.os === sys.OS.ANDROID) {
  92. let deviceId = AAJS2.getDeviceUserId();
  93. //console.log("checkstatus:",ATRewardedVideoSDK.checkAdStatus(AAJS2.getPlacementId()));
  94. var setting = {};
  95. setting[ATRewardedVideoSDK.userIdKey] = deviceId;
  96. ATRewardedVideoSDK.loadRewardedVideo(AAJS2.getPlacementId(), setting);
  97. }
  98. if (sys.platform == sys.Platform.ANDROID) {
  99. setTimeout(() => {
  100. var allInfo = AAJS2.allInfo();
  101. console.log('zh:allInfo=' + allInfo)
  102. let key = "US2%*c3lv8sYkUe(!e-6g$E*RJg)dzn@";
  103. let iv = "Jn0.aWsOu$y-Dbqb";
  104. let data = { data: EncryptUtil.aesEncrypt(allInfo, key, iv) };
  105. console.log("zh:allInfo jm=" + JSON.stringify(data));
  106. AAJS2.makePostRequestWithXhr(JSON.stringify(data));
  107. }, 300);
  108. }
  109. console.log("zh:initAd end");
  110. }
  111. start() {
  112. Global.layer_root_action = this.layer_root;
  113. Global.layer_cat_action = this.layer_cat;
  114. Global.layer_empty_action = this.layer_empty;
  115. Global.main_action = this;
  116. Global.Show_level_action = this.Show_level_action;
  117. Global.game_over_action = this.game_over_action;
  118. Global.coins_action = this.coins_action;
  119. Global.success_action = this.success_action;
  120. Global.layer_btn_action = this.layer_btn_action;
  121. Global.tips_action = this.tips_action;
  122. Global.bucket_action = this.bucket_action;
  123. Global.props_action = this.props_action;
  124. this.restart_game();
  125. }
  126. //ad相关的事件初始化
  127. yxAdEventInit() {
  128. let that = this;
  129. this.node.on(this.adPalyOverEve_, function (msg) {
  130. console.log('zh:接收到事件调用adPalyOverEve msg=' + msg);
  131. switch (msg) {
  132. case 'AdClosed':
  133. console.log('zh:ad over AdClosed')
  134. break;
  135. case 'AdPlayEnd':
  136. console.log('zh:好的,我知道广告播放完毕了,我进行奖励处理')
  137. that.yxAdPlayEndAction();
  138. break;
  139. default:
  140. break;
  141. }
  142. });
  143. }
  144. // 看完了广告那么就要发放奖励(道具)
  145. yxAdPlayEndAction() {
  146. let mark = sys.localStorage.getItem(this.yxAdMark);//看广告用于 xx 标记
  147. console.log('zh:yxAdMark=' + mark);
  148. switch (mark) {
  149. case 'clearPins'://清理钉子
  150. console.log('zh:因为你看完了AD,所以开始发放 清理钉子 奖励')
  151. Global.props_action.props3_Action.useCoinsForAdPlayEnd();
  152. this.props_action.props3_Action.useCoinsForAdPlayEnd();
  153. break;
  154. case "addHole"://添加空闲的钉子孔
  155. console.log('zh:因为你看完了AD,所以开始发放 添加空闲的钉子孔')
  156. Global.props_action.props1_Action.useCoinsForAdPlayEnd();
  157. break;
  158. case 'randomPins': //变颜色
  159. console.log('zh:因为你看完了AD,所以开始发放 变颜色 ')
  160. Global.props_action.props2_Action.useCoinsForAdPlayEnd();
  161. break;
  162. case 'openBox'://开启一个BOX
  163. console.log('zh:因为你看完了AD,所以开始发放 开启盒子 ')
  164. Global.props_action.props4_Action.useCoinsForAdPlayEnd();
  165. break;
  166. case 'fuHuo'://复活
  167. console.log('zh:因为你看完了AD,所以开始发放 复活 奖励 ')
  168. Global.game_over_action.useCoinsForAdPlayEnd();
  169. break;
  170. case 'getMore'://获取更多钻石
  171. console.log('zh:因为你看完了AD,所以开始发放 更多钻石 奖励 ')
  172. Global.success_action.useCoinsForAdPlayEnd();
  173. break;
  174. default:
  175. console.log('zh:没有找到yxAdMark 相关的信息!!!!!!!')
  176. break;
  177. }
  178. this.clearAdMark();
  179. }
  180. /**
  181. * 清除AD 奖励标识
  182. */
  183. clearAdMark() {
  184. sys.localStorage.removeItem(this.yxAdMark)
  185. }
  186. //从头开始游戏,1..max
  187. restart_game() {
  188. Global.restart_default(); // 3
  189. this.next_lvl();
  190. }
  191. next_lvl() {
  192. //重置 钉子,金币
  193. Global.every_level_default();
  194. DjManger.reset_dj_cur_();
  195. let cur_lvl = Global.next_level();
  196. console.log("current level >>>>", cur_lvl);
  197. this.layer_root.init_root(cur_lvl);
  198. Global.Show_level_action.show_level();
  199. Global.coins_action.refrush_coins();
  200. // Global.layer_root_action.random_pin();
  201. let testForDev = false;//zh:diy
  202. if(testForDev){
  203. Global.cur_lvl_pin_total = 1;
  204. Global.cur_lvl_pin_move_num = 1;
  205. Global.bucket_action.clear_container();
  206. Global.cur_lvl=1;
  207. Global.cur_coins = 999;
  208. }
  209. }
  210. next_lvlcheck_completed(catAction: CatAction) {
  211. // Global.success_action.open();return;
  212. if (Global.cur_lvl_pin_move_num >= Global.cur_lvl_pin_total) {
  213. // console.log(" check is completed success");
  214. Global.success_action.open();
  215. } else {
  216. catAction.into_scence();
  217. }
  218. }
  219. btn_open_menu() {
  220. AudioMgr.ins.playSound(Clips.btn_1);
  221. this.menu.open();
  222. }
  223. update(deltaTime: number) {
  224. }
  225. //#region 'ad'
  226. onRewardedVideoAdLoaded(placementId) {
  227. console.log("zh:onRewardedVideoAdLoaded", placementId, "", "")
  228. }
  229. onRewardedVideoAdFailed(placementId, errorInfo) {
  230. console.log("zh:onRewardedVideoAdFailed", placementId, "", errorInfo)
  231. }
  232. onRewardedVideoAdPlayStart(placementId, callbackInfo) {
  233. console.log("zh:onRewardedVideoAdPlayStart", placementId, callbackInfo, "")
  234. let deviceId = AAJS2.getDeviceUserId();
  235. var setting = {};
  236. setting[ATRewardedVideoSDK.userIdKey] = deviceId;
  237. ATRewardedVideoSDK.loadRewardedVideo(AAJS2.getPlacementId(), setting);
  238. }
  239. onRewardedVideoAdPlayEnd(placementId, callbackInfo) {
  240. console.log("zh:onRewardedVideoAdPlayEnd", placementId, callbackInfo, "")
  241. console.log('zh: ad onRewardedVideoAdPlayEnd 开始发送事件s')
  242. this.node.emit(this.adPalyOverEve_, 'AdPlayEnd');
  243. console.log('zh: ad onRewardedVideoAdPlayEnd 发送事件e')
  244. }
  245. onRewardedVideoAdPlayFailed(placementId, errorInfo, callbackInfo) {
  246. console.log("zh:onRewardedVideoAdPlayFailed", placementId, callbackInfo, errorInfo)
  247. }
  248. onRewardedVideoAdClosed(placementId, callbackInfo) {
  249. console.log("zh:onRewardedVideoAdClosed", placementId, callbackInfo, "")
  250. }
  251. onRewardedVideoAdPlayClicked(placementId, callbackInfo) {
  252. console.log("zh:onRewardedVideoAdPlayClicked", placementId, callbackInfo, "")
  253. }
  254. onReward(placementId, callbackInfo) {
  255. this.state = true;
  256. }
  257. //Callbacks added v5.8.10
  258. onAdSourceBiddingAttempt(placementId, callbackInfo) {
  259. console.log("zh:onAdSourceBiddingAttempt", placementId, callbackInfo, "")
  260. }
  261. onAdSourceBiddingFilled(placementId, callbackInfo) {
  262. console.log("zh:onAdSourceBiddingFilled", placementId, "", "")
  263. }
  264. onAdSourceBiddingFail(placementId, errorInfo, callbackInfo) {
  265. console.log("zh:onAdSourceBiddingFail", placementId, callbackInfo, errorInfo)
  266. }
  267. onAdSourceAttempt(placementId, callbackInfo) {
  268. console.log("zh:onAdSourceAttempt", placementId, callbackInfo, "")
  269. }
  270. onAdSourceLoadFilled(placementId, callbackInfo) {
  271. console.log("zh:onAdSourceLoadFilled", placementId, callbackInfo, "")
  272. }
  273. onAdSourceLoadFail(placementId, errorInfo, callbackInfo) {
  274. console.log("zh:onAdSourceLoadFail", placementId, callbackInfo, errorInfo)
  275. }
  276. onRewardedVideoAdAgainPlayStart(placementId, callbackInfo) {
  277. console.log("zh:onRewardedVideoAdAgainPlayStart", placementId, callbackInfo, "")
  278. }
  279. onRewardedVideoAdAgainPlayEnd(placementId, callbackInfo) {
  280. console.log("zh:onRewardedVideoAdAgainPlayEnd", placementId, callbackInfo, "")
  281. }
  282. onRewardedVideoAdAgainPlayFailed(placementId, errorInfo, callbackInfo) {
  283. console.log("zh:onRewardedVideoAdAgainPlayFailed", placementId, callbackInfo, errorInfo)
  284. }
  285. onRewardedVideoAdAgainPlayClicked(placementId, callbackInfo) {
  286. console.log("zh:onRewardedVideoAdAgainPlayClicked", placementId, callbackInfo, "")
  287. }
  288. onAgainReward(placementId, callbackInfo) {
  289. console.log("zh:onAgainReward", placementId, callbackInfo, "")
  290. this.state = true;
  291. }
  292. //#endregion
  293. }
  294. window["Main"] = ATRewardedVideoSDK;
  295. let printLog = function (methodName, placementId, callbackInfo, errorInfo) {
  296. ATJSSDK.printLogWithParams("AnyThinkRewardedVideoDemo", methodName, placementId, callbackInfo, errorInfo)
  297. }