Props1Action.ts 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. import { _decorator, Component, Label, Node, tween, Vec3,sys } from 'cc';
  2. import { Clips, DJ, DJ_TYPE } from './Enums';
  3. import { AudioMgr } from './AudioMgr';
  4. import { Global } from './Global';
  5. import { PropsAction } from './PropsAction';
  6. import { AdManger } from './ad/AdManger';
  7. import { DjManger } from './DjManger';
  8. const { ccclass, property } = _decorator;
  9. import ATRewardedVideoSDK from "./AnyThinkAds/ATRewardedVideoTSSDK"
  10. import AAJS2 from "./utils/ATAndroidJS2";
  11. import ATJSSDK from "./AnyThinkAds/ATJSSDK";
  12. import { CoinsAction } from './CoinsAction';
  13. //import { EncryptUtil } from './utils/EncryptUtil';
  14. @ccclass('Props1Action')
  15. export class Props1Action extends Component {
  16. @property(Node)
  17. lock_img:Node ;
  18. @property({ type: Label })
  19. conis_label: Label;
  20. start() {
  21. this.conis_label.string = Global.get_need_coins() + "";
  22. this.initAdForPage();
  23. }
  24. /**
  25. * 初始化广告
  26. */
  27. initAdForPage(){
  28. console.log('zh:initAdForPage foir props1Action.ts')
  29. if(sys.os===sys.OS.ANDROID){
  30. console.log('zh:initAdForPage 1')
  31. let deviceId = AAJS2.getDeviceUserId();
  32. console.log("zh:checkstatus:",ATRewardedVideoSDK.checkAdStatus(AAJS2.getPlacementId()));
  33. var setting = {};
  34. setting[ATRewardedVideoSDK.userIdKey] = deviceId;
  35. ATRewardedVideoSDK.loadRewardedVideo(AAJS2.getPlacementId(), setting);
  36. }
  37. console.log('zh:initAdForPage 2')
  38. }
  39. dt:number = 0;
  40. times:number = 0;
  41. update(deltaTime: number) {
  42. if(!this.node.active){
  43. return;
  44. }
  45. if(this.times==0){
  46. this.times++;
  47. this.show_tween();
  48. }else{
  49. this.dt+=deltaTime;
  50. if(this.dt>=1.5){
  51. this.dt = 0;
  52. this.show_tween();
  53. }
  54. }
  55. }
  56. private show_tween(){
  57. if(this.lock_img){
  58. this.lock_img.active = true;
  59. tween(this.lock_img)
  60. .to(0.25,{scale:new Vec3(1.2,1.2,1)},Global.our_easing)
  61. .to(0.35,{scale:new Vec3(0.8,0.8,1)},Global.our_easing)
  62. .to(0.15,{scale:new Vec3(1,1,1)},Global.our_easing)
  63. .call(()=>{
  64. this.lock_img.scale = new Vec3(1,1,1);
  65. this.lock_img.active = false;
  66. }).delay(0.3)
  67. .start();
  68. }
  69. }
  70. add_hole_coins(){
  71. console.log('zh:add_hole_coins111')
  72. AudioMgr.ins.playSound(Clips.btn_1);
  73. if (Global.layer_empty_action.get_unlock_num() <= 0) {
  74. Global.tips_action.show("There are no empty nail holes");//没有空位了
  75. return;
  76. }
  77. if (Global.cur_coins < Global.get_need_coins()) {
  78. Global.tips_action.show("gold Quantity Insufficient");//钻石数量不够
  79. return;
  80. }
  81. if (!DjManger.use_dj(DJ.Btn_1,DJ_TYPE.Type_coin)) {
  82. Global.tips_action.show("Current Level: Props Exhausted");//当前关卡次数已经用完
  83. return;
  84. }
  85. //消耗
  86. Global.use_coins(Global.get_need_coins());
  87. Global.layer_empty_action.unlock_empty_hole();
  88. Global.coins_action.refrush_coins();
  89. this.node.parent.getComponent(PropsAction)?.close();
  90. }
  91. add_hole_videos(){
  92. console.log('zh:add_hole_videos222')
  93. AudioMgr.ins.playSound(Clips.btn_1);
  94. if (Global.layer_empty_action.get_unlock_num() <= 0) {
  95. Global.tips_action.show("no empty nail holes");//没有空位了
  96. return;
  97. }
  98. if (!DjManger.use_dj(DJ.Btn_1,DJ_TYPE.Type_video)) {
  99. Global.tips_action.show("Current Level: Props Exhausted");//当前关卡次数已经用完
  100. return;
  101. }
  102. if(sys.os == sys.OS.ANDROID){
  103. if(ATRewardedVideoSDK.hasAdReady(AAJS2.getPlacementId())){
  104. console.log('zh:add_hole_videos ad ok')
  105. sys.localStorage.setItem('yxAdMark', 'addHole');//看广告用于 添加钉子孔 标记
  106. ATRewardedVideoSDK.showAd(AAJS2.getPlacementId());
  107. }else{
  108. console.log('zh:add_hole_videos ad no ok')
  109. Global.tips_action.show("No reward video for now");//没有奖励视频
  110. //this.useCoinsForAdPlayEnd();
  111. }
  112. }
  113. //下面是原始的逻辑
  114. // AdManger.show_video((data) => {
  115. // if (data == 1) {
  116. // console.log("add_hole_videos 获取奖励成功");
  117. // this.node.parent.getComponent(PropsAction)?.close();
  118. // //解锁
  119. // Global.layer_empty_action.unlock_empty_hole();
  120. // } else {
  121. // Global.tips_action.show("Gain reward failure");//获取奖励失败
  122. // //退款
  123. // DjManger.return_used_dj(DJ.Btn_1,DJ_TYPE.Type_video);
  124. // }
  125. // })
  126. }
  127. /**
  128. * 消耗钻石 ad 播放完毕 消耗钻石
  129. */
  130. useCoinsForAdPlayEnd(){
  131. console.log("zh:add_hole_videos 开始添加钉子孔 奖励start");
  132. this.node.parent.getComponent(PropsAction)?.close();
  133. //解锁
  134. Global.layer_empty_action.unlock_empty_hole();
  135. console.log("zh:add_hole_videos 开始添加钉子孔 奖励end");
  136. //清理AD奖励标记
  137. sys.localStorage.removeItem('yxAdMark')
  138. }
  139. open(){
  140. this.conis_label.string = Global.get_need_coins() + "";
  141. }
  142. }