Props1Action.ts 5.4 KB

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