UIUpgradePanel.ts 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  1. import UIPage from "../Framework/UIPage";
  2. import { PanelName } from "../Framework/Constant";
  3. import { cocosz } from "../Framework/CocosZ";
  4. import { utils } from "../../common-plugin/Scripts/Utils";
  5. import TweenEffect from "../Framework/TweenEffect";
  6. import { SkillType, upgradeMgr } from "../Game/UpgradeMgr";
  7. import PlatUtils from "../../common-plugin/Scripts/PlatUtils";
  8. import { gameMgr } from "../Game/gameMgr";
  9. import AESUtil from "../AESUtil"
  10. import ATSDK from "../AnyThinkAds/ATJSSDK";
  11. import ATRewardedVideoSDK from "../AnyThinkAds/ATRewardedVideoJSSDK";
  12. import AAJS2 from "../ATAndroidJS2";
  13. import GlobalManager from '../GlobalManager';
  14. const { ccclass, property } = cc._decorator;
  15. /**
  16. * 皮肤试用面板
  17. */
  18. @ccclass
  19. export default class UIUpgradePanel extends UIPage {
  20. private _mask: cc.Node = null;
  21. private _panel: cc.Node = null;
  22. private _skill0: cc.Node = null;
  23. private _skill1: cc.Node = null;
  24. private _skill2: cc.Node = null;
  25. private _skill3: cc.Node = null;
  26. private _skill4: cc.Node = null;
  27. private _btnRefresh: cc.Node = null;
  28. private _betterArr: number[] = [];
  29. private _otherArr: number[] = [];// 可以获取的技能数组
  30. private _uiSkillIdArr: number[] = [];// 随机4个技能
  31. private _curIndex: number = -1;// 当前选中下标
  32. private _canClick: boolean = true;// 能否点击
  33. private _lockArr: boolean[] = [false, false, false, false, false];
  34. constructor() {
  35. super(PanelName.UIUpgradePanel);
  36. this.isValid() && this.onLoad();
  37. }
  38. protected onLoad() {
  39. this._mask = this._page.getChildByName("Mask");
  40. this._panel = this._page.getChildByName("Panel");
  41. let btnNames: string[] = ["skill0", "skill1", "skill2", "skill3", "skill4", "btnRefresh"];
  42. for (let i = 0; i < btnNames.length; i++) {
  43. let btn: cc.Node = cc.find(btnNames[i], this._panel);
  44. if (btn) {
  45. btn.on(cc.Node.EventType.TOUCH_END, this._onBtnClickedHandler, this);
  46. if (btn.name == "skill0") {
  47. this._skill0 = btn;
  48. } else if (btn.name == "skill1") {
  49. this._skill1 = btn;
  50. } else if (btn.name == "skill2") {
  51. this._skill2 = btn;
  52. } else if (btn.name == "skill3") {
  53. this._skill3 = btn;
  54. } else if (btn.name == "skill4") {
  55. this._skill4 = btn;
  56. } else if (btn.name == "btnRefresh") {
  57. this._btnRefresh = btn;
  58. btn.active = cocosz.isADON;
  59. }
  60. }
  61. }
  62. // 服务器锁的数量
  63. let serverValue = cocosz.getConfigByKey("skillLockNum");
  64. if (Number.isInteger(serverValue)) {
  65. for (let i = 0; i < 5; i++) {
  66. if (i + serverValue >= 5) {
  67. this._lockArr[i] = true;
  68. } else {
  69. this._lockArr[i] = false;
  70. }
  71. }
  72. }
  73. this.initAdForPage();
  74. }
  75. initAdForPage() {
  76. if (cc.sys.os === cc.sys.OS_ANDROID) {
  77. let deviceId = AAJS2.getDeviceUserId();
  78. console.log("zh:checkstatus:", ATRewardedVideoSDK.checkAdStatus(AAJS2.getPlacementId()));
  79. var setting = {};
  80. setting[ATRewardedVideoSDK.userIdKey] = deviceId;
  81. ATRewardedVideoSDK.loadRewardedVideo(AAJS2.getPlacementId(), setting);
  82. }
  83. }
  84. protected onOpen() {
  85. utils.SendEvent("页面-技能");
  86. // 优先技能数组
  87. let better = [
  88. SkillType.双发, SkillType.子弹碎片, SkillType.枪林弹雨, SkillType.谢幕,
  89. SkillType.瞬斩, SkillType.冰霜精通, SkillType.火焰精通, SkillType.萃取,
  90. SkillType.再生, SkillType.护甲靴子, SkillType.疾走, SkillType.神圣守护,
  91. SkillType.通灵匕首, SkillType.飞轮, SkillType.闪电, SkillType.燃烧瓶
  92. ];
  93. // 可以获取的技能数组
  94. for (let i = 0; i <= 34; i++) {
  95. if ([SkillType.雷电精通, SkillType.龙卵, SkillType.通灵镰刀].includes(i)) {
  96. // 剔除的技能
  97. } else if (upgradeMgr && upgradeMgr.isValid && upgradeMgr.upgradeSkillArr[i] >= upgradeMgr.upgradeSkillMaxLevelArr[i]) {
  98. // 达到最大级
  99. } else if (better.includes(i)) {
  100. // 优先数组
  101. this._betterArr.push(i);
  102. } else {
  103. // 其它数组
  104. this._otherArr.push(i);
  105. }
  106. }
  107. this._initPanel();
  108. if (PlatUtils.IsWechat) {
  109. utils.adManager.hideCustomAd({ location: 3 });
  110. utils.adManager.hideCustomAd({ location: 4 });
  111. }
  112. }
  113. protected onClose(): void {
  114. cocosz.pauseCount--;
  115. if (PlatUtils.IsWechat) {
  116. utils.adManager.showCustomAd({ location: 3 });
  117. utils.adManager.showCustomAd({ location: 4 });
  118. }
  119. }
  120. private _initPanel() {
  121. TweenEffect.panel_mask_opacity(this._mask)
  122. TweenEffect.panel_open_moveY(this._panel);
  123. this._curIndex = -1;
  124. // 刷新技能
  125. this._skill_refresh();
  126. }
  127. /**
  128. * 所有按钮点击事件
  129. * @param event
  130. * @param data
  131. */
  132. private async _onBtnClickedHandler(event: cc.Event, data: any) {
  133. //播放按钮点击音效
  134. await cocosz.audioMgr.playBtnEffect().catch();
  135. if (!this._canClick) return;
  136. switch (event.target.name) {
  137. case "btnRefresh": {
  138. this._canClick = false;
  139. // 分享
  140. if (event.target.getChildByName("share") && event.target.getChildByName("share").active) {
  141. utils.SendEvent("分享-刷新技能")
  142. let adKey = "zh_ad_type";
  143. // 注册方法 , this.ClickClose.bind(this));
  144. GlobalManager.getInstance().registerMethod('event_shuaXinJiNeng', this.event_shuaXinJiNeng.bind(this));
  145. cc.sys.localStorage.setItem(adKey, 'event_shuaXinJiNeng');//
  146. if (ATRewardedVideoSDK.hasAdReady(AAJS2.getPlacementId())) {
  147. console.log('zh:AD ready for event_shuaXinJiNeng')
  148. ATRewardedVideoSDK.showAd(AAJS2.getPlacementId());
  149. } else {
  150. console.log('zh:AD not ready for event_shuaXinJiNeng')
  151. this.event_shuaXinJiNeng();
  152. }
  153. if (2 > 1) {
  154. return;//下面是原始的代码
  155. }
  156. cocosz.share(() => {
  157. utils.SendEvent("分享-刷新技能-成功")
  158. this._skill_refresh();
  159. this._canClick = true;
  160. }, () => {
  161. utils.SendEvent("分享-刷新技能-失败")
  162. this._canClick = true;
  163. })
  164. }
  165. // 视频
  166. else if (event.target.getChildByName("video") && event.target.getChildByName("video").active) {
  167. utils.SendEvent("视频-技能刷新(地下城僵尸)-播放")
  168. let adKey = "zh_ad_type";
  169. // 注册方法 , this.ClickClose.bind(this));
  170. GlobalManager.getInstance().registerMethod('event_shuaXinJiNeng', this.event_shuaXinJiNeng.bind(this));
  171. cc.sys.localStorage.setItem(adKey, 'event_shuaXinJiNeng');//
  172. if (ATRewardedVideoSDK.hasAdReady(AAJS2.getPlacementId())) {
  173. console.log('zh:AD ready for event_shuaXinJiNeng')
  174. ATRewardedVideoSDK.showAd(AAJS2.getPlacementId());
  175. } else {
  176. console.log('zh:AD not ready for event_shuaXinJiNeng')
  177. this.event_shuaXinJiNeng();
  178. }
  179. if (2 > 1) {
  180. return;//下面是原始的代码
  181. }
  182. cocosz.watchAD(() => {
  183. utils.SendEvent("视频-技能刷新(地下城僵尸)-成功")
  184. this._skill_refresh();
  185. this._canClick = true;
  186. }, () => {
  187. utils.SendEvent("视频-技能刷新(地下城僵尸)-失败")
  188. this._canClick = true;
  189. });
  190. }
  191. break;
  192. }
  193. case "skill0":
  194. case "skill1":
  195. case "skill2":
  196. case "skill3":
  197. case "skill4": {
  198. this._canClick = false;
  199. let callback = () => {
  200. if ("skill0" == event.target.name)
  201. this._curIndex = 0;
  202. else if ("skill1" == event.target.name)
  203. this._curIndex = 1;
  204. else if ("skill2" == event.target.name)
  205. this._curIndex = 2;
  206. else if ("skill3" == event.target.name)
  207. this._curIndex = 3;
  208. else if ("skill4" == event.target.name)
  209. this._curIndex = 4;
  210. // 刷新
  211. this.updateFrame();
  212. // 选中技能
  213. this._selectSkill();
  214. }
  215. let lockNode = event.target.getChildByName("lock");
  216. if (lockNode && lockNode.active) {
  217. // 分享
  218. if (lockNode.getChildByName("share") && lockNode.getChildByName("share").active) {
  219. utils.SendEvent("分享-技能解锁")
  220. cocosz.share(() => {
  221. utils.SendEvent("分享-技能解锁-成功")
  222. callback && callback();
  223. }, () => {
  224. utils.SendEvent("分享-技能解锁-失败")
  225. this._canClick = true;
  226. })
  227. }
  228. // 视频
  229. else if (lockNode.getChildByName("video") && lockNode.getChildByName("video").active) {
  230. utils.SendEvent("视频-技能解锁-播放")
  231. cocosz.watchAD(() => {
  232. utils.SendEvent("视频-技能解锁-成功")
  233. callback && callback();
  234. }, () => {
  235. utils.SendEvent("视频-技能解锁-失败")
  236. this._canClick = true;
  237. });
  238. } else {
  239. callback && callback();
  240. }
  241. } else {
  242. callback && callback();
  243. }
  244. break;
  245. }
  246. }
  247. }
  248. public event_shuaXinJiNeng() {
  249. console.log('zh: event_shuaXinJiNeng 刷新技能 被触发')
  250. utils.SendEvent("zh:-刷新技能 被触发")
  251. this._skill_refresh();
  252. this._canClick = true;
  253. }
  254. private _selectSkill() {
  255. this._canClick = false;
  256. // 获取技能
  257. if (this._uiSkillIdArr[this._curIndex]) {
  258. upgradeMgr && upgradeMgr.isValid && upgradeMgr.getSkill(this._uiSkillIdArr[this._curIndex]);
  259. }
  260. // 卡片效果
  261. let arr: cc.Node[] = [this._skill0, this._skill1, this._skill2, this._skill3, this._skill4];
  262. arr.forEach((v, i) => {
  263. if (i == this._curIndex) {
  264. this.card_click(v);
  265. } else {
  266. this.card_recycle(v);
  267. }
  268. })
  269. // 关闭弹窗
  270. cocosz.scheduleOnce(() => {
  271. cocosz.uiMgr.closePanel(PanelName.UIUpgradePanel);
  272. if (gameMgr && gameMgr.playerTs && gameMgr.playerTs.isValid) {
  273. gameMgr.playerTs.avoidInjury(2);
  274. }
  275. }, 1.5);
  276. }
  277. private _getSkillIDName(id: number) {
  278. return id + (upgradeMgr.upgradeSkillMaxLevelArr[id] > 1 ? "_" + (upgradeMgr.upgradeSkillArr[id] + 1) : "")
  279. }
  280. private _skill_load(card: cc.Node, id) {
  281. // 名字
  282. let node_name = card.getChildByName("name");
  283. if (node_name) {
  284. let spr_name = node_name.getComponent(cc.Sprite);
  285. if (spr_name) {
  286. cocosz.resMgr.loadAndCacheRes("i18n/tex_zombie/" + cocosz.curLanguage + "/zombieSkill_name_" + this._getSkillIDName(id), cc.SpriteFrame, null, (err, res) => {
  287. if (spr_name && spr_name.isValid) {
  288. spr_name.spriteFrame = res;
  289. }
  290. });
  291. }
  292. }
  293. // 图标
  294. let node_icon = card.getChildByName("icon");
  295. if (node_icon) {
  296. let spr_icon = node_icon.getComponent(cc.Sprite);
  297. if (spr_icon) {
  298. cocosz.resMgr.loadAndCacheRes("tex_zombie/zombieSkill_icon_" + this._getSkillIDName(id), cc.SpriteFrame, null, (err, res) => {
  299. if (spr_icon && spr_icon.isValid) {
  300. spr_icon.spriteFrame = res;
  301. }
  302. });
  303. }
  304. }
  305. // 介绍
  306. let node_introduce = card.getChildByName("introduce");
  307. if (node_introduce) {
  308. let spr_introduce = node_introduce.getComponent(cc.Sprite);
  309. if (spr_introduce) {
  310. cocosz.resMgr.loadAndCacheRes("i18n/tex_zombie/" + cocosz.curLanguage + "/zombieSkill_introduce_" + this._getSkillIDName(id), cc.SpriteFrame, null, (err, res) => {
  311. if (spr_introduce && spr_introduce.isValid) {
  312. spr_introduce.spriteFrame = res;
  313. }
  314. });
  315. }
  316. }
  317. }
  318. /** 技能刷新 */
  319. private _skill_refresh() {
  320. this._uiSkillIdArr.length = 0;
  321. // 从技能数组中获取5个技能
  322. if (this._betterArr.length) {
  323. for (let i = Math.min(5 - this._uiSkillIdArr.length, this._betterArr.length); i > 0; i--) {
  324. let index = Math.floor(Math.random() * this._betterArr.length);
  325. if (this._betterArr[index] >= 0) {
  326. this._uiSkillIdArr.push(this._betterArr[index]);
  327. this._betterArr.splice(index, 1);
  328. }
  329. }
  330. }
  331. if (this._otherArr.length) {
  332. for (let i = Math.min(5 - this._uiSkillIdArr.length, this._otherArr.length); i > 0; i--) {
  333. let index = Math.floor(Math.random() * this._otherArr.length);
  334. if (this._otherArr[index] >= 0) {
  335. this._uiSkillIdArr.push(this._otherArr[index]);
  336. this._otherArr.splice(index, 1);
  337. }
  338. }
  339. }
  340. // 排序
  341. for (let i = 0; i < this._uiSkillIdArr.length; i++) {
  342. // 3级技能(非视频位置)
  343. if (upgradeMgr.upgradeSkillArr[this._uiSkillIdArr[i]] == 2 && !this._lockArr[i]) {
  344. // 与视频位置交换
  345. for (let j = this._uiSkillIdArr.length - 1; j > i; j--) {
  346. if (this._lockArr[j] && upgradeMgr.upgradeSkillArr[this._uiSkillIdArr[j]] != 2) {
  347. // 交换
  348. [this._uiSkillIdArr[i], this._uiSkillIdArr[j]] = [this._uiSkillIdArr[j], this._uiSkillIdArr[i]]
  349. }
  350. }
  351. }
  352. }
  353. // 技能0 ///////////////////////////////////////////////////////////////////////////////////////////////
  354. if (this._uiSkillIdArr[0] >= 0) {
  355. this._skill0.active = true;
  356. let id = this._uiSkillIdArr[0];
  357. this._skill_load(this._skill0, id);
  358. } else {
  359. this._skill0.active = false;
  360. }
  361. // 技能1 ///////////////////////////////////////////////////////////////////////////////////////////////
  362. if (this._uiSkillIdArr[1] >= 0) {
  363. this._skill1.active = true;
  364. let id = this._uiSkillIdArr[1];
  365. this._skill_load(this._skill1, id);
  366. } else {
  367. this._skill1.active = false;
  368. }
  369. // 技能2 ///////////////////////////////////////////////////////////////////////////////////////////////
  370. if (this._uiSkillIdArr[2] >= 0) {
  371. this._skill2.active = true;
  372. let id = this._uiSkillIdArr[2];
  373. this._skill_load(this._skill2, id);
  374. } else {
  375. this._skill2.active = false;
  376. }
  377. // 技能3 ///////////////////////////////////////////////////////////////////////////////////////////////
  378. if (this._uiSkillIdArr[3] >= 0) {
  379. this._skill3.active = true;
  380. let id = this._uiSkillIdArr[3];
  381. this._skill_load(this._skill3, id);
  382. } else {
  383. this._skill3.active = false;
  384. }
  385. // 技能4 ///////////////////////////////////////////////////////////////////////////////////////////////
  386. if (this._uiSkillIdArr[4] >= 0) {
  387. this._skill4.active = true;
  388. let id = this._uiSkillIdArr[4];
  389. this._skill_load(this._skill4, id);
  390. } else {
  391. this._skill4.active = false;
  392. }
  393. // 视频按钮隐藏
  394. if (this._otherArr.length == 0 && this._btnRefresh && this._btnRefresh.active) {
  395. this._btnRefresh.active = false;
  396. }
  397. this.updateFrame();
  398. }
  399. // 更新外发光
  400. updateFrame() {
  401. // 选中框
  402. this._skill0.children[0].active = (this._curIndex == 0);
  403. this._skill1.children[0].active = (this._curIndex == 1);
  404. this._skill2.children[0].active = (this._curIndex == 2);
  405. this._skill3.children[0].active = (this._curIndex == 3);
  406. this._skill4.children[0].active = (this._curIndex == 4);
  407. // 解锁框
  408. this._skill0.children[5].active = this._lockArr[0] && this._curIndex != 0;
  409. this._skill1.children[5].active = this._lockArr[1] && this._curIndex != 1;
  410. this._skill2.children[5].active = this._lockArr[2] && this._curIndex != 2;
  411. this._skill3.children[5].active = this._lockArr[3] && this._curIndex != 3;
  412. this._skill4.children[5].active = this._lockArr[4] && this._curIndex != 4;
  413. }
  414. /** 卡牌选中特效 */
  415. card_click(card: cc.Node) {
  416. card.zIndex = cc.macro.MAX_ZINDEX;
  417. cc.tween(card)
  418. .to(0.5, { x: 0, y: 200 }, { easing: "sineIn" })
  419. .to(1, { scale: 2, opacity: 0 }, { easing: "fade" })
  420. .start();
  421. }
  422. /** 卡牌回收 */
  423. card_recycle(card: cc.Node) {
  424. let btnUnLock = card.getChildByName("btnUnLock")
  425. if (btnUnLock) btnUnLock.active = false;
  426. cc.tween(card)
  427. .to(0.5, { opacity: 0 }, { easing: "sineIn" })
  428. .start();
  429. }
  430. }