Props4Action.ts 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. import { _decorator, Color, Component, Label, Node, Sprite, tween, Vec2, Vec3,sys } from 'cc';
  2. import { Global } from './Global';
  3. import { PropsAction } from './PropsAction';
  4. import { Clips } from './Enums';
  5. import { AudioMgr } from './AudioMgr';
  6. import { CatAction } from './CatAction';
  7. import { DataModel } from './DataModel';
  8. import { AdManger } from './ad/AdManger';
  9. const { ccclass, property } = _decorator;
  10. import ATRewardedVideoSDK from "./AnyThinkAds/ATRewardedVideoTSSDK"
  11. import AAJS2 from "./utils/ATAndroidJS2";
  12. import ATJSSDK from "./AnyThinkAds/ATJSSDK";
  13. import { CoinsAction } from './CoinsAction';
  14. //import { EncryptUtil } from './utils/EncryptUtil';
  15. @ccclass('Props4Action')
  16. export class Props4Action extends Component {
  17. @property(Node)
  18. target:Node = null;
  19. @property(Sprite)
  20. cat_img:Sprite = null;
  21. color_arr = [];
  22. color_arr_index = 0;
  23. cat_action:CatAction
  24. @property({ type: Label })
  25. conis_label: Label;
  26. start() {
  27. this.conis_label.string = Global.get_need_coins() + "";
  28. for(let i = 0;i<DataModel.base_color_arr.length;i++){
  29. this.color_arr.push(DataModel.base_color_arr[i].clone());
  30. }
  31. this.initAdForPage();
  32. }
  33. initAdForPage(){
  34. console.log('zh:initAdForPage foir props3Action.ts')
  35. if(sys.os===sys.OS.ANDROID){
  36. let deviceId = AAJS2.getDeviceUserId();
  37. console.log("zh:checkstatus:",ATRewardedVideoSDK.checkAdStatus(AAJS2.getPlacementId()));
  38. var setting = {};
  39. setting[ATRewardedVideoSDK.userIdKey] = deviceId;
  40. ATRewardedVideoSDK.loadRewardedVideo(AAJS2.getPlacementId(), setting);
  41. }
  42. }
  43. dt:number = 0;
  44. times:number = 0;
  45. update(deltaTime: number) {
  46. if(!this.node.active){
  47. return;
  48. }
  49. if(this.times==0){
  50. this.times++;
  51. this.play_tween();
  52. }else{
  53. this.dt+=deltaTime;
  54. if(this.dt>=1){
  55. this.dt = 0;
  56. this.play_tween();
  57. }
  58. }
  59. }
  60. private play_tween(){
  61. this.color_arr_index++;
  62. if(this.color_arr_index>=this.color_arr.length){
  63. this.color_arr_index = 0;
  64. }
  65. let c = this.color_arr[this.color_arr_index];
  66. this.cat_img.color = new Color(c.r,c.g,c.b,255);
  67. }
  68. show_box(cat_action:CatAction){
  69. this.cat_action = cat_action;
  70. }
  71. //开启一个盒子
  72. open_box_coins(){
  73. AudioMgr.ins.playSound(Clips.btn_1);
  74. if(Global.cur_coins<Global.get_need_coins()){
  75. Global.tips_action.show("Diamond Quantity Insufficient");//钻石数量不够
  76. return;
  77. }
  78. //消耗
  79. Global.use_coins(Global.get_need_coins());
  80. {
  81. //解开
  82. this.cat_action.set_lock_unlock(false);
  83. this.cat_action.into_scence(new Vec2(0,400));
  84. }
  85. Global.coins_action.refrush_coins();
  86. this.node.parent.getComponent(PropsAction)?.close();
  87. }
  88. open_box_video(){
  89. AudioMgr.ins.playSound(Clips.btn_1);
  90. if(!this.cat_action){
  91. return;
  92. }
  93. //检查上锁情况
  94. // if (!Global.used_cur_level_props_(4)) {
  95. // Global.tips_action.show("当前关卡次数已经用完");
  96. // return;
  97. // }
  98. if(sys.os == sys.OS.ANDROID){
  99. if(ATRewardedVideoSDK.hasAdReady(AAJS2.getPlacementId())){
  100. console.log('zh:open_box_video ad ok')
  101. sys.localStorage.setItem('yxAdMark', 'openBox');//看广告用于 清理钉子 标记
  102. ATRewardedVideoSDK.showAd(AAJS2.getPlacementId());
  103. }else{
  104. console.log('zh:open_box_video ad no ok')
  105. Global.tips_action.show("No reward video for now");//没有奖励视频
  106. // this.useCoinsForAdPlayEnd();
  107. }
  108. }
  109. //下面是原始的代码
  110. // AdManger.show_video((data) => {
  111. // if (data == 1) {
  112. // console.log("open_box_video 获取奖励成功");
  113. // this.node.parent.getComponent(PropsAction)?.close();
  114. // //解锁
  115. // this.cat_action.set_lock_unlock(false);
  116. // this.cat_action.into_scence(new Vec2(0,400));
  117. // } else {
  118. // Global.tips_action.show("获取奖励失败5");
  119. // //退款
  120. // // Global.return_used_cur_level_props_(4);
  121. // }
  122. // })
  123. }
  124. /**
  125. * 消耗钻石 ad 播放完毕 消耗钻石
  126. */
  127. useCoinsForAdPlayEnd(){
  128. console.log("zh:clear_pins_videos 开始openBox 奖励start");
  129. this.node.parent.getComponent(PropsAction)?.close();
  130. this.cat_action.set_lock_unlock(false);
  131. this.cat_action.into_scence(new Vec2(0,400));
  132. console.log("zh:clear_pins_videos 开始openBox 奖励end");
  133. //清理AD奖励标记
  134. sys.localStorage.removeItem('yxAdMark')
  135. }
  136. open(){
  137. this.conis_label.string = Global.get_need_coins() + "";
  138. }
  139. }