Props2Action.ts 5.1 KB

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