UICrazyAwardView.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. import auto_crazyAwardView from "../../../ui/uidata/Interface/auto_crazyAwardView";
  2. import UIBase from "../../../framework/ui/UIBase";
  3. import UIHelp from "../../../framework/ui/UIHelp";
  4. import PlayerView from "../../../gameLogic/gameObject/player/playerView";
  5. import PlayerObject from "../../../gameLogic/gameObject/player/playerObject";
  6. import Utils from "../../../framework/utils/utils";
  7. import ZomBieObject from "../../../gameLogic/gameObject/zombie/zombieObject";
  8. import BulletObject from "../../../gameLogic/gameObject/bullet/bulletObject";
  9. import gameData from "../../../gameLogic/utrl/gameData";
  10. import gameEventManager from "../../../gameLogic/utrl/gameEventManager";
  11. import {EVENT_TYPE, FALLITEM_TYPE, ITEM_TYPE} from "../../../gameLogic/utrl/gameEnum";
  12. import UIObtainView from "./UIObtainView";
  13. import UIMng from "../../../framework/ui/UIMng";
  14. import UIGameScene from "../scene/UIGameScene";
  15. import EventManager from "../../../framework/event/EventManager";
  16. import tween = cc.tween;
  17. import AccountModel from "../../../data/Account/AccountModel";
  18. import AESUtil from "../../../AESUtil"
  19. import ATSDK from "../../../AnyThinkAds/ATJSSDK";
  20. import ATRewardedVideoSDK from "../../../AnyThinkAds/ATRewardedVideoJSSDK";
  21. import AAJS2 from "../../../ATAndroidJS2";
  22. import GlobalManager from '../../../GlobalManager';
  23. const {ccclass, menu, property} = cc._decorator;
  24. @ccclass
  25. @menu("UI/Interface/UICrazyAwardView")
  26. export default class UICrazyAwardView extends UIBase {
  27. ui: auto_crazyAwardView = null;
  28. protected static prefabUrl = "Interface/crazyAwardView";
  29. protected static className = "UICrazyAwardView";
  30. @property(cc.Prefab)
  31. heroPrefab: cc.Prefab = null;
  32. @property(cc.Prefab)
  33. zombiePrefab: cc.Prefab = null;
  34. @property(cc.Prefab)
  35. bulletPrefab: cc.Prefab = null;
  36. playerObjects: PlayerObject [] = [];
  37. zomBieObjects: ZomBieObject [] = [];
  38. lastClickTime = -1;
  39. nowClickTIme = -1;
  40. curProgress = 100;
  41. isShowBanner = false;
  42. bannerClick = false;
  43. triggerCloseSecond = -1;
  44. bannerType = 0;
  45. temp = 0;
  46. isClosing = false;
  47. isADShowed = false;
  48. onUILoad() {
  49. this.ui = this.node.addComponent(auto_crazyAwardView);
  50. AccountModel.getInstance().show_crazy_in_level ++;
  51. UIMng.getInstance().setLock(true)
  52. this.initAdForPage();
  53. }
  54. initAdForPage() {
  55. if (cc.sys.os === cc.sys.OS_ANDROID) {
  56. let deviceId = AAJS2.getDeviceUserId();
  57. console.log("zh:checkstatus:", ATRewardedVideoSDK.checkAdStatus(AAJS2.getPlacementId()));
  58. var setting = {};
  59. setting[ATRewardedVideoSDK.userIdKey] = deviceId;
  60. ATRewardedVideoSDK.loadRewardedVideo(AAJS2.getPlacementId(), setting);
  61. }
  62. }
  63. onShow() {
  64. tween(this.ui.kdzl)
  65. .repeatForever(
  66. cc.tween(this.ui.kdzl)
  67. .to(0.8,{scale:0.5,opacity:0})
  68. .to(0.8,{scale:1,opacity:255})
  69. )
  70. .start();
  71. tween(this.ui.fxtsjs_btn)
  72. .repeatForever(
  73. cc.tween(this.ui.fxtsjs_btn)
  74. .to(0.8,{scale:0.8})
  75. .to(0.8,{scale:1})
  76. )
  77. .start();
  78. tween(this.ui.point)
  79. .repeatForever(
  80. cc.tween(this.ui.point)
  81. .to(0.8,{opacity:0})
  82. .to(0.8,{opacity:255})
  83. )
  84. .start();
  85. this.bannerType = Utils.random(0, 2); // 随机一个banner的显示方案
  86. for (let i = 1; i <= 4; i++) {
  87. this.randomHero(i);
  88. }
  89. this.randomZombie(1);
  90. }
  91. randomZombie(index: number) {
  92. let id = 0;
  93. // let isBoss = false;
  94. // if (Utils.random(0, 1)) {
  95. id = Utils.random(53, 56);
  96. if (id == 54){
  97. id = 56
  98. }
  99. // }else {
  100. // id = Utils.random(22, 48);
  101. // }
  102. let nd = cc.instantiate(this.zombiePrefab);
  103. // if (isBoss){
  104. nd.scale = 0.8;
  105. // }
  106. let comp = nd.getComponent(ZomBieObject);
  107. this.zomBieObjects.push(comp);
  108. this.ui[`zombieSlot${index}`].addChild(nd)
  109. nd.group = 'default';
  110. comp.init(id, cc.v3(0, 0, 0), [], false, true);
  111. this.scheduleOnce(() => {
  112. nd.setPosition(cc.v3(0, 0, 0));
  113. comp.cur_hp_bar.parent.active = false;
  114. })
  115. }
  116. private randomHero(index: number) {
  117. let id = Utils.random(1, 9);
  118. let nd = cc.instantiate(this.heroPrefab);
  119. let playerViewCom = nd.getChildByName('view').getComponent(PlayerView);
  120. let playerObjCom = nd.getComponent(PlayerObject);
  121. this.playerObjects.push(playerObjCom);
  122. playerObjCom.init(id, []);
  123. nd.group = 'default';
  124. nd.scaleX *= -1;
  125. this.scheduleOnce(() => {
  126. nd.setPosition(cc.v3(0, 0, 0));
  127. const randomWeapon = 41;
  128. playerObjCom.player_prop.setWeapon(randomWeapon, false);
  129. playerObjCom.player_prop.cur_weapon = playerObjCom.player_prop.remote_weapon;
  130. playerViewCom.init(id);
  131. this.scheduleOnce(() => {
  132. playerViewCom.playIdle(randomWeapon)
  133. },0)
  134. }, 0);
  135. // playerObjCom.setLeader(false);
  136. this.ui[`heroSlot${index}`].addChild(nd)
  137. }
  138. onHide() {
  139. }
  140. onStart() {
  141. }
  142. update(dt) {
  143. let speed = 60 * dt;
  144. let subNum = this.curProgress + speed;
  145. this.curProgress = subNum < 100 ? subNum : 100;
  146. this.ui.nodeProgress.getComponent(cc.Sprite).fillRange = this.curProgress / 100;
  147. if (this.triggerCloseSecond !== -1 && this.triggerCloseSecond > 0) {
  148. this.triggerCloseSecond -= dt;
  149. if (this.triggerCloseSecond <= 0) {
  150. if (this.bannerClick) {
  151. if (this.isADShowed) {
  152. zjSdk?.hideBannerAd();
  153. this.toClose();
  154. }
  155. } else {
  156. this.triggerCloseSecond = -1
  157. this.isShowBanner = false;
  158. zjSdk?.hideBannerAd();
  159. this.toClose();
  160. }
  161. }
  162. }
  163. }
  164. toClose() {
  165. this.isClosing = true;
  166. this.schedule(() => {
  167. this.clickCrazy();
  168. }, 0.1)
  169. }
  170. clickCrazy() {
  171. this.heroAttack();
  172. // 存储上一次点击时间与当前点击时间
  173. const clickTime = new Date().getTime() / 1000;
  174. if (this.lastClickTime <= 0) {
  175. this.lastClickTime = clickTime;
  176. } else {
  177. this.lastClickTime = this.nowClickTIme;
  178. }
  179. this.nowClickTIme = clickTime;
  180. const addProgress = Utils.random(12, 15);
  181. this.curProgress -= addProgress;
  182. if (this.curProgress < 0) {
  183. this.curProgress = 0;
  184. }
  185. this.ui.nodeProgress.getComponent(cc.Sprite).fillRange = this.curProgress / 100;
  186. this.checkShow();
  187. }
  188. checkShow() {
  189. if (this.curProgress == 0) {
  190. this.reword();
  191. return;
  192. }
  193. if (this.isShowBanner) {
  194. return;
  195. }
  196. if (this.isClosing) {
  197. return;
  198. }
  199. // 每次点击均有50%的几率出现banner
  200. if (this.bannerType === 0) {
  201. if (Math.random() <= 0.5) {
  202. this.showBanner();
  203. }
  204. return;
  205. }
  206. // 进度条到达20%出现banner
  207. if (this.bannerType === 1) {
  208. if (this.curProgress < 20) {
  209. this.showBanner();
  210. }
  211. return;
  212. }
  213. // 阶段点击按钮时显示banner的概率
  214. if (this.bannerType === 2) {
  215. if (this.curProgress < 25 && Math.random() < 0.75) {
  216. this.showBanner();
  217. } else if (this.curProgress < 50 && Math.random() < 0.5) {
  218. this.showBanner();
  219. } else if (this.curProgress < 75 && Math.random() < 0.25) {
  220. this.showBanner();
  221. } else {
  222. this.showBanner();
  223. }
  224. return;
  225. }
  226. // 两次点击间隔小于0.3秒时出现banner
  227. if (this.bannerType === 3) {
  228. if (this.nowClickTIme !== this.lastClickTime && this.nowClickTIme - this.lastClickTime < 0.31) {
  229. this.showBanner();
  230. }
  231. return;
  232. }
  233. }
  234. private heroAttack() {
  235. for (let i = 0; i < 4; i++) {
  236. this.fire(this.playerObjects[i], i);
  237. }
  238. }
  239. private reword() {
  240. gameData.curPowerNum += 100;
  241. gameData.curBulletNum += 100;
  242. const randomId = Utils.random(1, 10);
  243. gameEventManager.emit(EVENT_TYPE.ADD_HERO_BY_ID, randomId);
  244. this.clickClose();
  245. gameEventManager.emit(EVENT_TYPE.CHANGE_STATUS,true)
  246. EventManager.once(EVENT_TYPE.closeObtain, () => {
  247. gameEventManager.emit(EVENT_TYPE.CHANGE_STATUS,false)
  248. })
  249. UIHelp.ShowUI(UIObtainView, null, {
  250. ids: [FALLITEM_TYPE.qiaokeli, FALLITEM_TYPE.zidan1],
  251. nums: [100, 100],
  252. modelIds: [randomId]
  253. })
  254. }
  255. private fire(playerObject: PlayerObject, i) {
  256. let b = cc.instantiate(this.bulletPrefab);
  257. this.node.addChild(b);
  258. let com = b.getComponent(BulletObject);
  259. com.max_dis = 400;
  260. const pos = playerObject.node.position;
  261. pos.x += this.ui.heroContent.x;
  262. pos.y += this.ui.heroContent.y;
  263. pos.x += this.ui[`heroSlot${i + 1}`].x;
  264. pos.y += this.ui[`heroSlot${i + 1}`].y;
  265. let red = 0;
  266. if (i == 0) {
  267. red = -0.1;
  268. } else if (i == 3) {
  269. red = 0.1;
  270. }
  271. com.init(pos.add(cc.v3(0, 30, 0)), red, 50, playerObject);
  272. com.destroyCall = () => {
  273. const zombieView = this.zomBieObjects[0].zombie_view;
  274. if (zombieView) {
  275. zombieView.hitEff();
  276. }
  277. }
  278. }
  279. clickClose() {
  280. gameEventManager.emit(EVENT_TYPE.CHANGE_STATUS, false);
  281. this.onClose();
  282. }
  283. showBanner() {
  284. this.isShowBanner = true;
  285. zjSdk?.showBannerAd({
  286. adPlaceName: '大按钮狂点',
  287. success: () => {
  288. this.isADShowed = true;
  289. },
  290. fail: (err) => {
  291. this.isADShowed = true;
  292. },
  293. }, (isStateClick) => {
  294. this.bannerClick = isStateClick;
  295. });
  296. this.triggerCloseSecond = 2;
  297. }
  298. onClose() {
  299. zjSdk?.hideBannerAd();
  300. cc.Canvas.instance.scheduleOnce(() => {
  301. UIMng.getInstance().setLock(false)
  302. }, 1)
  303. UIHelp.CloseUI(UICrazyAwardView);
  304. }
  305. }