Props3Action.ts 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. initAdForPage(){
  36. console.log('zh:initAdForPage foir props3Action.ts')
  37. if(sys.os===sys.OS.ANDROID){
  38. let deviceId = AAJS2.getDeviceUserId();
  39. console.log("zh:checkstatus:",ATRewardedVideoSDK.checkAdStatus(AAJS2.getPlacementId()));
  40. var setting = {};
  41. setting[ATRewardedVideoSDK.userIdKey] = deviceId;
  42. ATRewardedVideoSDK.loadRewardedVideo(AAJS2.getPlacementId(), setting);
  43. }
  44. }
  45. //电子邮件puhalskijsemen@gmail.com
  46. //源码网站 开vpn打开 http://web3incubators.com/
  47. //电报https://t.me/gamecode999
  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. clear_pins_coins(){
  85. console.log('zh:clear_pins_coins 11')
  86. AudioMgr.ins.playSound(Clips.btn_1);
  87. if (Global.cur_coins < Global.get_need_coins()) {
  88. Global.tips_action.show("Diamond Quantity Insufficient");//钻石数量不够
  89. return;
  90. }
  91. let pin_arr = Global.layer_empty_action.get_pin_arr();
  92. if (pin_arr.length == 0) {
  93. Global.tips_action.show("No Screws to Clear");//没有可清理的钉子
  94. return;
  95. }
  96. if (!DjManger.use_dj(DJ.Btn_3,DJ_TYPE.Type_coin)) {
  97. Global.tips_action.show("Current Level: Props Exhausted");//当前关卡次数已经用完
  98. return;
  99. }
  100. console.log('zh:clear_pins_coins 222')
  101. //消耗
  102. Global.use_coins(Global.get_need_coins());
  103. Global.bucket_action.put_pins(pin_arr);
  104. Global.coins_action.refrush_coins();
  105. this.node.parent.getComponent(PropsAction)?.close();
  106. console.log('zh:clear_pins_coins 333')
  107. }
  108. /**
  109. * 消耗钻石 ad 播放完毕 消耗钻石
  110. */
  111. useCoinsForAdPlayEnd(){
  112. console.log("zh:clear_pins_videos 开始清理钉子 奖励start");
  113. let pin_arr = Global.layer_empty_action.get_pin_arr();
  114. this.node.parent.getComponent(PropsAction)?.close();
  115. //解锁
  116. console.log("zh:clear_pins_videos 开始清理 "+ pin_arr.length +" 个钉子 ");
  117. if (pin_arr.length >0) {
  118. Global.bucket_action.put_pins(pin_arr);
  119. }
  120. console.log("zh:clear_pins_videos 开始清理钉子 奖励end");
  121. //清理AD奖励标记
  122. sys.localStorage.removeItem('yxAdMark')
  123. }
  124. clear_pins_videos(){
  125. console.log('zh:clear_pins_videos 111')
  126. AudioMgr.ins.playSound(Clips.btn_1);
  127. let pin_arr = Global.layer_empty_action.get_pin_arr();
  128. if (pin_arr.length == 0) {
  129. Global.tips_action.show("No Screws to Clear");//没有可清理的钉子
  130. return;
  131. }
  132. if (!DjManger.use_dj(DJ.Btn_3,DJ_TYPE.Type_video)) {
  133. Global.tips_action.show("Current Level: Props Exhausted");//当前关卡次数已经用完
  134. return;
  135. }
  136. console.log('zh:clear_pins_videos 222')
  137. if(sys.os == sys.OS.ANDROID){
  138. if(ATRewardedVideoSDK.hasAdReady(AAJS2.getPlacementId())){
  139. console.log('zh:clear_pins_videos ad ok')
  140. sys.localStorage.setItem('yxAdMark', 'clearPins');//看广告用于 清理钉子 标记
  141. ATRewardedVideoSDK.showAd(AAJS2.getPlacementId());
  142. }else{
  143. console.log('zh:clear_pins_videos ad no ok')
  144. Global.tips_action.show("No reward video for now");//没有奖励视频
  145. // this.useCoinsForAdPlayEnd();
  146. }
  147. }
  148. console.log('zh:clear_pins_videos 333')
  149. //zh 下面是原先的代码
  150. // AdManger.show_video((data) => {
  151. // console.log('zh:clear_pins_videos data:',data)
  152. // if (data == 1) {
  153. // console.log("clear_pins_videos 获取奖励成功");
  154. // this.node.parent.getComponent(PropsAction)?.close();
  155. // //解锁
  156. // Global.bucket_action.put_pins(pin_arr);
  157. // } else {
  158. // Global.tips_action.show("Gain reward failure");//获取奖励失败
  159. // //退款
  160. // DjManger.return_used_dj(DJ.Btn_3,DJ_TYPE.Type_video);
  161. // }
  162. // })
  163. }
  164. open(){
  165. this.conis_label.string = Global.get_need_coins() + "";
  166. }
  167. }