Props2Action.ts 5.1 KB

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