Props3Action.ts 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. import { _decorator, Component, Label, Node, tween, Vec2, Vec3,sys } from 'cc';
  2. import { Global } from './Global';
  3. import { PropsAction } from './PropsAction';
  4. import { Clips, DJ, DJ_TYPE } from './Enums';
  5. import { AudioMgr } from './AudioMgr';
  6. import { Tools } from './Tools';
  7. import { AdManger } from './ad/AdManger';
  8. import { DjManger } from './DjManger';
  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. const { ccclass, property } = _decorator;
  15. @ccclass('Props3Action')
  16. export class Props3Action extends Component {
  17. @property([Node])
  18. pin_img_arr:Node[] = [];
  19. @property(Node)
  20. bucket:Node = null;
  21. pos_pin = [];
  22. @property({ type: Label })
  23. conis_label: Label;
  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_pin.push({pos:ele.getPosition().clone(),pin:ele});
  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.pos_pin.forEach((ele)=>{
  67. this.play_tween(ele.pos,ele.pin);
  68. });
  69. }
  70. private play_tween(pos:Vec3,pin:Node){
  71. {
  72. //set pos default
  73. pin.setPosition(pos.x,pos.y,pos.z);
  74. }
  75. let target_pos = this.bucket.position.clone();
  76. target_pos.x = target_pos.x+ Tools.random_between(-20,20);
  77. target_pos.y = target_pos.y+ Tools.random_between(-20,20);
  78. tween(pin)
  79. .to(0.75, { position: target_pos },Global.our_easing)
  80. .call(() => {
  81. }).delay(0.3)
  82. .start();
  83. }
  84. /**
  85. * 清理钉子孔
  86. * @returns
  87. */
  88. clear_pins_coins(){
  89. console.log('zh:clear_pins_coins 11')
  90. AudioMgr.ins.playSound(Clips.btn_1);
  91. if (Global.cur_coins < Global.get_need_coins()) {
  92. Global.tips_action.show("Diamond Quantity Insufficient");//钻石数量不够
  93. return;
  94. }
  95. let pin_arr = Global.layer_empty_action.get_pin_arr();
  96. if (pin_arr.length == 0) {
  97. Global.tips_action.show("No Screws to Clear");//没有可清理的钉子
  98. return;
  99. }
  100. //如果不是开发调试就限制
  101. if(!Global.devMark){
  102. if (!DjManger.use_dj(DJ.Btn_3,DJ_TYPE.Type_coin)) {
  103. Global.tips_action.show("Current Level: Props Exhausted");//当前关卡次数已经用完
  104. return;
  105. }
  106. }
  107. console.log('zh:clear_pins_coins 222')
  108. //消耗
  109. Global.use_coins(Global.get_need_coins());
  110. Global.bucket_action.put_pins(pin_arr);
  111. Global.coins_action.refrush_coins();
  112. this.node.parent.getComponent(PropsAction)?.close();
  113. console.log('zh:clear_pins_coins 333')
  114. }
  115. /**
  116. * 消耗钻石 ad 播放完毕 消耗钻石
  117. */
  118. useCoinsForAdPlayEnd(){
  119. console.log("zh:clear_pins_videos 开始清理钉子 奖励start");
  120. let pin_arr = Global.layer_empty_action.get_pin_arr();
  121. this.node.parent.getComponent(PropsAction)?.close();
  122. //解锁
  123. console.log("zh:clear_pins_videos 开始清理 "+ pin_arr.length +" 个钉子 ");
  124. if (pin_arr.length >0) {
  125. Global.bucket_action.put_pins(pin_arr);
  126. }
  127. console.log("zh:clear_pins_videos 开始清理钉子 奖励end");
  128. //清理AD奖励标记
  129. sys.localStorage.removeItem('yxAdMark')
  130. }
  131. /**
  132. * 清理钉子孔
  133. * @returns
  134. */
  135. clear_pins_videos(){
  136. console.log('zh:clear_pins_videos 111')
  137. AudioMgr.ins.playSound(Clips.btn_1);
  138. let pin_arr = Global.layer_empty_action.get_pin_arr();
  139. if (pin_arr.length == 0) {
  140. Global.tips_action.show("No Screws to Clear");//没有可清理的钉子
  141. return;
  142. }
  143. if (!DjManger.use_dj(DJ.Btn_3,DJ_TYPE.Type_video)) {
  144. Global.tips_action.show("Current Level: Props Exhausted");//当前关卡次数已经用完
  145. return;
  146. }
  147. console.log('zh:clear_pins_videos 222')
  148. if(sys.os == sys.OS.ANDROID){
  149. if(ATRewardedVideoSDK.hasAdReady(AAJS2.getPlacementId())){
  150. console.log('zh:clear_pins_videos ad ok')
  151. sys.localStorage.setItem('yxAdMark', 'clearPins');//看广告用于 清理钉子 标记
  152. ATRewardedVideoSDK.showAd(AAJS2.getPlacementId());
  153. }else{
  154. console.log('zh:clear_pins_videos ad no ok')
  155. Global.tips_action.show("No reward video for now");//没有奖励视频
  156. // this.useCoinsForAdPlayEnd();
  157. }
  158. }
  159. console.log('zh:clear_pins_videos 333')
  160. //zh 下面是原先的代码
  161. // AdManger.show_video((data) => {
  162. // console.log('zh:clear_pins_videos data:',data)
  163. // if (data == 1) {
  164. // console.log("clear_pins_videos 获取奖励成功");
  165. // this.node.parent.getComponent(PropsAction)?.close();
  166. // //解锁
  167. // Global.bucket_action.put_pins(pin_arr);
  168. // } else {
  169. // Global.tips_action.show("Gain reward failure");//获取奖励失败
  170. // //退款
  171. // DjManger.return_used_dj(DJ.Btn_3,DJ_TYPE.Type_video);
  172. // }
  173. // })
  174. }
  175. open(){
  176. this.conis_label.string = Global.get_need_coins() + "";
  177. }
  178. }