UIHomePage.ts 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225
  1. import UIPage from "../Framework/UIPage";
  2. import Constant, { GunInfo, PageName, PanelName, SkillInfo } from "../Framework/Constant";
  3. import { cocosz } from "../Framework/CocosZ";
  4. import { utils } from "../../common-plugin/Scripts/Utils";
  5. import { BannerLocation } from "../../common-plugin/Scripts/YZ_Constant";
  6. import Ani from "../Game/ani";
  7. import PlatUtils from "../../common-plugin/Scripts/PlatUtils";
  8. import FlyCoin from "../Framework/FlyCoin";
  9. import GameDate, { PriceType } from "../Game/gameDate";
  10. import Weapon from "../Game/weapon";
  11. import Msg from "../Framework/Msg";
  12. import AESUtil from "../AESUtil"
  13. import ATSDK from "../AnyThinkAds/ATJSSDK";
  14. import ATRewardedVideoSDK from "../AnyThinkAds/ATRewardedVideoJSSDK";
  15. import AAJS2 from "../ATAndroidJS2";
  16. import GlobalManager from '../GlobalManager';
  17. // @ts-ignore
  18. const i18n = require('LanguageData');
  19. const { ccclass, property } = cc._decorator;
  20. @ccclass
  21. export default class UIHomePage extends UIPage implements AdDeveloperCallback {
  22. constructor() {
  23. super(PageName.UIHomePage);
  24. this.isValid() && this.onLoad();
  25. }
  26. adState: boolean = false;
  27. adKey: string = "zh_ad_type";
  28. onRewardedVideoAdLoaded(placementId: any): void {
  29. ATSDK.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdLoaded(" + placementId + ")");
  30. }
  31. onRewardedVideoAdFailed(placementId: any, errorInfo: any): void {
  32. ATSDK.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdFailed(" + placementId + ", " + errorInfo + ")");
  33. }
  34. onRewardedVideoAdPlayStart(placementId: any, callbackInfo: any): void {
  35. ATSDK.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdPlayStart(" + placementId + ", " + callbackInfo + ")");
  36. let deviceId = AAJS2.getDeviceUserId();
  37. var setting = {};
  38. setting[ATRewardedVideoSDK.userIdKey] = deviceId;
  39. ATRewardedVideoSDK.loadRewardedVideo(AAJS2.getPlacementId(), setting);
  40. }
  41. onRewardedVideoAdPlayEnd(placementId: any, callbackInfo: any): void {
  42. ATSDK.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdPlayEnd(" + placementId + ", " + callbackInfo + ")");
  43. console.log('zh: ad PlayEnd')
  44. //this.node.emit("handleCustomEvent");
  45. }
  46. onRewardedVideoAdPlayFailed(placementId: any, errorInfo: any, callbackInfo: any): void {
  47. ATSDK.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdPlayFailed(" + placementId + ", " + errorInfo + ", " + callbackInfo + ")");
  48. }
  49. onRewardedVideoAdClosed(placementId: any, callbackInfo: any): void {
  50. ATSDK.printLog("zh:AnyThinkRewardedVideoDemo::AdClosed(" + placementId + ", " + callbackInfo + ")");
  51. if (this.adState == true) {
  52. this.adState = false;
  53. console.log('zh: ad奖励OK,开始处理奖励')
  54. this.handleCustomEvent()
  55. } else {
  56. console.log('zh: ad奖励标识 NO OK ')
  57. }
  58. }
  59. onRewardedVideoAdPlayClicked(placementId: any, callbackInfo: any): void {
  60. ATSDK.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdPlayClicked(" + placementId + ", " + callbackInfo + ")");
  61. }
  62. onReward(placementId: any, callbackInfo: any): void {
  63. ATSDK.printLog("zh:AnyThinkRewardedVideoDemo::onReward(" + placementId + ", " + callbackInfo + ")");
  64. console.log('zh:onReward AD奖励标志OK')
  65. this.adState = true;
  66. }
  67. private _icon_set: cc.Node = null;
  68. private _frame_set: cc.Node = null;
  69. private _btnAudio: cc.Node = null;
  70. private _btnShake: cc.Node = null;
  71. private _btnSkin: cc.Node = null;
  72. private _btnSkinAd: cc.Node = null;
  73. private _btnWeapon: cc.Node = null;
  74. private _btnWeaponAd: cc.Node = null;
  75. private _playerAni: Ani = null;
  76. private _aniUpgrade: sp.Skeleton = null;
  77. private _aniCaidai: sp.Skeleton = null;
  78. private _weaponScroll: cc.Node = null;
  79. private _weaponList: cc.Node[] = [];
  80. private _ani_arrow: cc.Node = null;
  81. private _skinInfo_name: cc.Sprite = null;
  82. private _skinInfo_xuedi: cc.Node = null;
  83. private _skinInfo_value1: cc.Label = null;
  84. private _skinInfo_value2: cc.Label = null;
  85. private _skinInfo_change1: cc.Label = null;
  86. private _skinInfo_change2: cc.Label = null;
  87. private _skinInfo_level_pro: cc.ProgressBar = null;
  88. private _weaponInfo_name: cc.Sprite = null;
  89. private _weaponInfo_value0: cc.Label = null;
  90. private _weaponInfo_value1: cc.Label = null;
  91. private _weaponInfo_value2: cc.Label = null;
  92. private _weaponInfo_value3: cc.Label = null;
  93. private _weaponInfo_change0: cc.Label = null;
  94. private _weaponInfo_change1: cc.Label = null;
  95. private _weaponInfo_change2: cc.Label = null;
  96. private _weaponInfo_change3: cc.Label = null;
  97. private _weaponInfo_level_pro: cc.ProgressBar = null;
  98. protected onLoad() {
  99. console.log("zh: UIHOMEPAGE ONLOAD")
  100. // 按钮
  101. let btnNames: string[] = ["BtnSet", "BtnSet/frame_set/BtnAudio", "BtnSet/frame_set/BtnShake", "ditai/BtnLeft", "ditai/BtnRight", "BtnSkin", "BtnWeapon", "BtnSkinAd", "BtnWeaponAd", "BtnCJ", "BtnSign", "BtnTime", "BtnGameStart"];
  102. btnNames.forEach(name => {
  103. let btn: cc.Node = cc.find(name, this._page);
  104. if (btn) {
  105. btn.on(cc.Node.EventType.TOUCH_END, this._onBtnClickHandler, this);
  106. if (btn.name == "BtnSet") {
  107. this._icon_set = cc.find("Background/icon_set", btn);
  108. this._frame_set = cc.find("frame_set", btn);
  109. } else if (btn.name == "BtnAudio") {
  110. this._btnAudio = btn;
  111. this._updateAudioBtn(false);
  112. } else if (btn.name == "BtnShake") {
  113. this._btnShake = btn;
  114. this._updatShakeBtn();
  115. } else if (btn.name == "BtnSkin") {
  116. this._btnSkin = btn;
  117. } else if (btn.name == "BtnWeapon") {
  118. this._btnWeapon = btn;
  119. } else if (btn.name == "BtnSkinAd") {
  120. this._btnSkinAd = btn;
  121. btn.active = cocosz.isADON;
  122. } else if (btn.name == "BtnWeaponAd") {
  123. this._btnWeaponAd = btn;
  124. btn.active = cocosz.isADON;
  125. }
  126. }
  127. });
  128. // 角色动画
  129. this._playerAni = cc.find("ditai/skin_all/ani", this._page).getComponent(Ani);
  130. // 彩带动画
  131. this._aniCaidai = cc.find("ditai/aniCaidai", this._page).getComponent(sp.Skeleton);
  132. this._aniCaidai.setCompleteListener(() => { this._aniCaidai.node.active = false; })
  133. // 升级动画
  134. this._aniUpgrade = cc.find("ditai/aniUpgrade", this._page).getComponent(sp.Skeleton);
  135. this._aniUpgrade.setCompleteListener(() => { this._aniUpgrade.node.active = false; })
  136. // 武器
  137. this._weaponScroll = cc.find("weaponScroll", this._page);
  138. let content = cc.find("view/content", this._weaponScroll);
  139. for (let i = 0; i < content.children.length; i++) {
  140. this._weaponList.push(content.children[i]);
  141. this._weaponList[i].on(cc.Node.EventType.TOUCH_END, (e) => {
  142. cocosz.audioMgr.playBtnEffect();
  143. let id = GameDate.Weapon[e.target.name].id;
  144. this._showWeaponId = id;
  145. this._updateWeapon();
  146. this._updateWeaponFrame();
  147. let weaponInfo = cocosz.dataMgr.getGunInfo(id);
  148. if (weaponInfo && weaponInfo.State == 1) {
  149. cocosz.dataMgr.curWeapon = id;
  150. }
  151. }, this);
  152. }
  153. let iconLayer = cc.find("view/iconLayer", this._weaponScroll);
  154. if (iconLayer) iconLayer.setParent(content);
  155. this._ani_arrow = cc.find("view/ani_arrow", this._weaponScroll);
  156. if (this._ani_arrow) this._ani_arrow.setParent(content);
  157. // 属性
  158. this._skinInfo_name = cc.find("ditai/skinName", this._page).getComponent(cc.Sprite);
  159. this._skinInfo_xuedi = cc.find("jueseshuxing/xuedi", this._page);
  160. this._skinInfo_value1 = cc.find("jueseshuxing/value1", this._page).getComponent(cc.Label);
  161. this._skinInfo_value2 = cc.find("jueseshuxing/value2", this._page).getComponent(cc.Label);
  162. this._skinInfo_change1 = cc.find("jueseshuxing/change1", this._page).getComponent(cc.Label);
  163. this._skinInfo_change2 = cc.find("jueseshuxing/change2", this._page).getComponent(cc.Label);
  164. this._skinInfo_level_pro = cc.find("jueseshuxing/levelProgressBar", this._page).getComponent(cc.ProgressBar);
  165. this._weaponInfo_name = cc.find("wuqishuxing/weaponName", this._page).getComponent(cc.Sprite);
  166. this._weaponInfo_value0 = cc.find("wuqishuxing/value0", this._page).getComponent(cc.Label);
  167. this._weaponInfo_value1 = cc.find("wuqishuxing/value1", this._page).getComponent(cc.Label);
  168. this._weaponInfo_value2 = cc.find("wuqishuxing/value2", this._page).getComponent(cc.Label);
  169. this._weaponInfo_value3 = cc.find("wuqishuxing/value3", this._page).getComponent(cc.Label);
  170. this._weaponInfo_change0 = cc.find("wuqishuxing/change0", this._page).getComponent(cc.Label);
  171. this._weaponInfo_change1 = cc.find("wuqishuxing/change1", this._page).getComponent(cc.Label);
  172. this._weaponInfo_change2 = cc.find("wuqishuxing/change2", this._page).getComponent(cc.Label);
  173. this._weaponInfo_change3 = cc.find("wuqishuxing/change3", this._page).getComponent(cc.Label);
  174. this._weaponInfo_level_pro = cc.find("wuqishuxing/levelProgressBar", this._page).getComponent(cc.ProgressBar);
  175. this.initAd();
  176. this.initAdForPage();
  177. }
  178. /**
  179. * AD播放完毕的事件处理
  180. */
  181. handleCustomEvent() {
  182. console.log('zh:00收到发送的事件')
  183. //let adKey = "zh_ad_type"
  184. let idx = cc.sys.localStorage.getItem(this.adKey);
  185. console.log('zh:onAdOverEve idx =' + idx)
  186. let adKeyTemp = '';//初始化一下,随便
  187. switch (idx) {
  188. case '_getReward_eventForAd':
  189. console.log('zh:#############签到奖励 奖励')
  190. GlobalManager.getInstance().callMethod('_getReward_eventForAd', true);
  191. break;
  192. case 'event_UIADPanel_forAd':
  193. console.log('zh:#############钻石,金币 奖励')
  194. GlobalManager.getInstance().callMethod('event_UIADPanel_forAd', true);
  195. break;
  196. case 'event_UITurntablePage_forAd':
  197. console.log('zh:#############抽奖 奖励')
  198. GlobalManager.getInstance().callMethod('event_UITurntablePage_forAd', true);
  199. break;
  200. case 'event_wuqi_unlook':
  201. console.log('zh:#############武器解锁 奖励')
  202. // GlobalManager.getInstance().callMethod('event_wuqi_unlook', true);
  203. this.event_wuqi_unlook();
  204. break;
  205. case 'event_pifu_unlook':
  206. console.log('zh:#############皮肤解锁 奖励')
  207. // GlobalManager.getInstance().callMethod('event_pifu_unlook', true);
  208. this.event_pifu_unlook();
  209. break;
  210. case 'event_ciTie':
  211. console.log('zh:#############磁铁 奖励')
  212. GlobalManager.getInstance().callMethod('event_ciTie', true);
  213. break;
  214. case 'event_fuHuo':
  215. console.log('zh:#############复活 奖励')
  216. GlobalManager.getInstance().callMethod('event_fuHuo', true);
  217. break;
  218. case 'event_gaoJiWuQi':
  219. console.log('zh:#############高级武器 奖励')
  220. GlobalManager.getInstance().callMethod('event_gaoJiWuQi', true);
  221. break;
  222. case 'event_quanPinHongZha':
  223. console.log('zh:#############轰炸 奖励')
  224. GlobalManager.getInstance().callMethod('event_quanPinHongZha', true);
  225. break;
  226. case 'xxxxxxx'://复活
  227. adKeyTemp = 'sendBtnEventForAdEventFuHuo_monthParams';
  228. let mpStr2 = cc.sys.localStorage.getItem(adKeyTemp);
  229. console.log('zh:#############复活 奖励', mpStr2)
  230. GlobalManager.getInstance().callMethod('sendBtnEventForAdEventFuHuo', mpStr2);
  231. break;
  232. default:
  233. console.log('zh:未知的道具类型AD==' + idx)
  234. }
  235. cc.sys.localStorage.setItem(this.adKey, '');
  236. cc.sys.localStorage.setItem(adKeyTemp, '');
  237. console.log('zh:清理adKey ')
  238. }
  239. initAd() {
  240. if (cc.sys.os != cc.sys.OS_ANDROID) {
  241. return;
  242. }
  243. //let adKey = "zh_ad_type"
  244. cc.sys.localStorage.setItem(this.adKey, "");
  245. let placementId = AAJS2.getPlacementId();
  246. let deviceId = AAJS2.getDeviceUserId();
  247. var setting = {};
  248. setting[ATRewardedVideoSDK.userIdKey] = deviceId;
  249. ATRewardedVideoSDK.loadRewardedVideo(placementId, setting);
  250. //console.log('zh:bbb222')
  251. var customPlacementId = "";
  252. if (cc.sys.os === cc.sys.OS_IOS) {
  253. customPlacementId = placementId;
  254. } else if (cc.sys.os === cc.sys.OS_ANDROID) {
  255. customPlacementId = placementId;
  256. }
  257. // 初始化SDK
  258. // ATSDK.initSDK("h6752c78a49dc1", "aad31bcaf7f7ff45ba21a8bc87bd9318a");//正式的,发布提交go0gle play
  259. ATSDK.initSDK("h66f7c5f8028cf", "ab133deec743a4bb58930891fd75d3f83");//测试专用,可以显示广告
  260. // ATSDK.initSDK("h67122e47607cd", "a4fd9a23bdd71c2314cf41140a77abb1e");//这是打砖块的已经上架的
  261. // ATSDK.initSDK("h6752c78a49dc1", "aad31bcaf7f7ff45ba21a8bc87bd9318a");//货柜1 正式的,发布提交go0gle play
  262. ATSDK.setLogDebug(true);//zh:diy
  263. var GDPRLevel = ATSDK.getGDPRLevel();
  264. // 针对欧盟地区初始化时做的处理,按需求打开,不在欧盟地区发布的不用使用。
  265. ATSDK.getUserLocation(function (userLocation) {
  266. //如果处于欧盟地区且等级是UNKNOW时,就执行授权弹窗
  267. if (userLocation === ATSDK.kATUserLocationInEU) {
  268. if (ATSDK.getGDPRLevel() === ATSDK.UNKNOWN) {
  269. ATSDK.showGDPRAuth();
  270. }
  271. }
  272. });
  273. ATRewardedVideoSDK.setAdListener(this);
  274. if (cc.sys.os === cc.sys.OS_ANDROID) {
  275. setTimeout(() => {
  276. var allInfo = AAJS2.allInfo();
  277. ATSDK.printLog("zh:allInfo=" + allInfo);
  278. let key = "US2%*c3lv8sYkUe(!e-6g$E*RJg)dzn@";
  279. let iv = "Jn0.aWsOu$y-Dbqb";
  280. let data = { data: AESUtil.AESencrypt(allInfo, key, iv) };
  281. ATSDK.printLog("zh:allInfo-jm=" + JSON.stringify(data));
  282. console.log('zh:ad_allInfo', data);
  283. AAJS2.makePostRequestWithXhr(JSON.stringify(data));
  284. }, 200);
  285. }
  286. }
  287. initAdForPage() {
  288. if (cc.sys.os === cc.sys.OS_ANDROID) {
  289. let deviceId = AAJS2.getDeviceUserId();
  290. console.log("zh:checkstatus:", ATRewardedVideoSDK.checkAdStatus(AAJS2.getPlacementId()));
  291. var setting = {};
  292. setting[ATRewardedVideoSDK.userIdKey] = deviceId;
  293. ATRewardedVideoSDK.loadRewardedVideo(AAJS2.getPlacementId(), setting);
  294. }
  295. }
  296. private _canGetBonus() {
  297. return (new Date().toDateString() != cocosz.dataMgr.LastDailyBonusTime);
  298. }
  299. private _aniEffect(type: 1 | 2) {
  300. switch (type) {
  301. case 1: {
  302. if (this._aniUpgrade) {
  303. this._aniUpgrade.node.active = true;
  304. this._aniUpgrade.setAnimation(0, "animation", false);
  305. cocosz.audioMgr.playEffect("ui_upgrade");
  306. }
  307. break;
  308. }
  309. case 2: {
  310. if (this._aniCaidai) {
  311. this._aniCaidai.node.active = true;
  312. this._aniCaidai.setAnimation(0, "animation", false);
  313. cocosz.audioMgr.playEffect("ui_caidai");
  314. }
  315. break;
  316. }
  317. }
  318. }
  319. protected onOpen() {
  320. cc.log("home open !");
  321. // 上报游戏首页
  322. utils.umaEvent("gamehome");
  323. utils.SendEvent("页面-首页");
  324. this._updatePlayer();
  325. this._updateWeapon();
  326. this._updateWeaponFrame();
  327. // 广告
  328. utils.showYzRealNameAuthPanel();
  329. utils.showPrivacyPanel({ group: "default", parent: this._page })
  330. utils.registerServerInitEvent(() => {
  331. // 验证服务器配置为自动弹签到,并且当前可以签到
  332. if (utils.checkAutoSign() && this._canGetBonus()) {
  333. cocosz.uiMgr.openPanel(PanelName.UISignPanel);
  334. }
  335. this.showAd();
  336. }, this)
  337. cc.game.on(Constant.E_GAME_LOGIC, this._onGameMessageHandler, this);
  338. }
  339. protected onClose() {
  340. cc.game.targetOff(this);
  341. utils.hideVivoGamePortalWidget();
  342. utils.hideOppoGameDrawerAdWidget();
  343. utils.adManager.hideBlockAd();
  344. utils.adManager.hideNativeTryGameWidget();
  345. utils.adManager.HideSingleNativeAd();
  346. if (PlatUtils.IsWechat) {
  347. utils.adManager.hideCustomAd({ location: 1 });
  348. utils.adManager.hideCustomAd({ location: 2 });
  349. } else if (PlatUtils.IsVIVO) {
  350. utils.adManager.hideCustomAd({ location: BannerLocation.Home });
  351. }
  352. }
  353. protected showAd() {
  354. if (cocosz.isShowAd) {
  355. if (PlatUtils.IsWechat) {
  356. utils.adManager.HideBanner(BannerLocation.Home);
  357. } else {
  358. utils.adManager.ShowBanner(BannerLocation.Home, { width: 0.1, bottom: 1 });
  359. }
  360. // 原生广告
  361. if (PlatUtils.IsWechat) {
  362. utils.adManager.showCustomAd({ location: 1 });
  363. utils.adManager.showCustomAd({ location: 2 });
  364. } else if (PlatUtils.IsVIVO) {
  365. utils.adManager.showCustomAd({ location: BannerLocation.Home });
  366. }
  367. utils.adManager.showNativeTryGameWidget({ right: 50, top: 800, scale: 1, parent: this._page });
  368. utils.adManager.ShowSingleNativeAd({});
  369. utils.adManager.showBlockAd({ right: 50, top: 500, showNum: 1 });
  370. utils.showMoreGamesWidget({ group: 'default', scale: 1, bottom: 300, left: 50, parent: this._page, location: BannerLocation.Home });
  371. utils.showTryGamesWidget({ group: 'default', scale: 1, bottom: 350, right: 50, parent: this._page, location: BannerLocation.Home });
  372. utils.showVivoGamePortalWidget({ top: 500, location: BannerLocation.Home });
  373. utils.showOppoGameDrawerAdWidget({ top: 500, location: BannerLocation.Home });
  374. utils.showCreateShortcutWidget(null, { group: 'default', scale: 1, left: 0, top: 500, parent: this._page })
  375. utils.showPrivacyWidget({ group: "default", top: 0, left: 0, parent: this._page.getChildByName("PrivacyWidget"), color: cc.Color.BLACK })
  376. }
  377. }
  378. private _onGameMessageHandler(event: any) {
  379. switch (event.type) {
  380. case Constant.E_Fly_Coin: {
  381. this._flyCoins(event.iconName, event.frameNodeName);
  382. break;
  383. }
  384. case Constant.E_CJ_SKIN: {
  385. this._showSkinId = cocosz.dataMgr.CurSkinId;
  386. this._updatePlayer();
  387. break;
  388. }
  389. case Constant.E_CJ_Weapon: {
  390. this._showWeaponId = cocosz.dataMgr.curWeapon;
  391. this._updateWeapon();
  392. this._updateWeaponFrame();
  393. break;
  394. }
  395. }
  396. }
  397. private async _onBtnClickHandler(event: cc.Event.EventTouch) {
  398. await cocosz.audioMgr.playBtnEffect().catch();
  399. switch (event.target.name) {
  400. case "BtnGameStart": {
  401. console.log('zh:BtnGameStart');
  402. cocosz.gameMode = 6;
  403. cocosz.gameMgr.gameStart(cocosz.getLevelId());
  404. break;
  405. }
  406. case "BtnLeft": {
  407. console.log('zh:BtnLeft');
  408. this._showSkinId--;
  409. if (this._showSkinId < 0) this._showSkinId = 11;
  410. this._updatePlayer();
  411. let skinInfo = cocosz.dataMgr.getSkinInfo(this._showSkinId);
  412. if (skinInfo && skinInfo.State == 1) {
  413. cocosz.dataMgr.CurSkinId = this._showSkinId;
  414. }
  415. break;
  416. }
  417. case "BtnRight": {
  418. console.log('zh:BtnRight');
  419. this._showSkinId++;
  420. if (this._showSkinId > 11) this._showSkinId = 0;
  421. this._updatePlayer();
  422. let skinInfo = cocosz.dataMgr.getSkinInfo(this._showSkinId);
  423. if (skinInfo && skinInfo.State == 1) {
  424. cocosz.dataMgr.CurSkinId = this._showSkinId;
  425. }
  426. break;
  427. }
  428. case "BtnSkin": {
  429. console.log('zh:BtnSkin');
  430. // 购买
  431. let showSkinInfo = cocosz.dataMgr.getSkinInfo(this._showSkinId);
  432. let showSKinKey = `${this._showSkinId + 1}`;
  433. if (showSkinInfo.State == 0) {
  434. // 金币
  435. if (GameDate.SkinMess[showSKinKey].priceType == PriceType.Gold) {
  436. if (cocosz.dataMgr.CoinCount >= GameDate.SkinMess[showSKinKey].price) {
  437. cocosz.dataMgr.CoinCount -= GameDate.SkinMess[showSKinKey].price;
  438. Msg.Show(i18n.t("msg.gxhdxjs"));//恭喜获得新角色
  439. cocosz.dataMgr.CurSkinId = this._showSkinId;
  440. this._updatePlayer();
  441. this._aniEffect(2);
  442. } else {
  443. this.showCoinPanel(false);
  444. }
  445. }
  446. // 钻石
  447. else if (GameDate.SkinMess[showSKinKey].priceType == PriceType.Diamond) {
  448. if (cocosz.dataMgr.DiamondCount >= GameDate.SkinMess[showSKinKey].price) {
  449. cocosz.dataMgr.DiamondCount -= GameDate.SkinMess[showSKinKey].price;
  450. Msg.Show(i18n.t("msg.gxhdxjs"));//恭喜获得新角色
  451. cocosz.dataMgr.CurSkinId = this._showSkinId;
  452. this._updatePlayer();
  453. this._aniEffect(2);
  454. } else {
  455. this.showCoinPanel(true);
  456. }
  457. }
  458. // 转盘奖励
  459. else if (GameDate.SkinMess[showSKinKey].priceType == PriceType.ZhuanPanReward) {
  460. cocosz.uiMgr.openPanel(PanelName.UITurntablePanel);
  461. }
  462. }
  463. // 升级
  464. else if (showSkinInfo.Level < 6) {
  465. if (cocosz.dataMgr.CoinCount >= Constant.skinLevelPriceArr[showSkinInfo.Level]) {
  466. cocosz.dataMgr.CoinCount -= Constant.skinLevelPriceArr[showSkinInfo.Level];
  467. showSkinInfo.Level++;
  468. cocosz.dataMgr.setSkinInfo(showSkinInfo.Id, showSkinInfo);
  469. this._updatePlayer();
  470. this._aniEffect(1);
  471. } else {
  472. this.showCoinPanel(false);
  473. }
  474. }
  475. break;
  476. }
  477. case "BtnWeapon": {
  478. console.log('zh:BtnWeapon');
  479. // 购买
  480. let showWeaponInfo = cocosz.dataMgr.getGunInfo(this._showWeaponId);
  481. let showWeaponKey = Weapon.WeaponName[this._showWeaponId];
  482. if (showWeaponInfo.State == 0) {
  483. // 金币
  484. if (GameDate.Weapon[showWeaponKey].priceType == PriceType.Gold) {
  485. if (cocosz.dataMgr.CoinCount >= GameDate.Weapon[showWeaponKey].price) {
  486. cocosz.dataMgr.CoinCount -= GameDate.Weapon[showWeaponKey].price;
  487. Msg.Show(i18n.t("msg.gxhdxwq"));
  488. cocosz.dataMgr.curWeapon = this._showWeaponId;
  489. this._updateWeapon();
  490. this._updateWeaponFrame();
  491. this._aniEffect(2);
  492. } else {
  493. this.showCoinPanel(false);
  494. }
  495. }
  496. // 钻石
  497. else if (GameDate.Weapon[showWeaponKey].priceType == PriceType.Diamond) {
  498. if (cocosz.dataMgr.DiamondCount >= GameDate.Weapon[showWeaponKey].price) {
  499. cocosz.dataMgr.DiamondCount -= GameDate.Weapon[showWeaponKey].price;
  500. Msg.Show(i18n.t("msg.gxhdxwq"));
  501. cocosz.dataMgr.curWeapon = this._showWeaponId;
  502. this._updateWeapon();
  503. this._updateWeaponFrame();
  504. this._aniEffect(2);
  505. } else {
  506. this.showCoinPanel(true);
  507. }
  508. }
  509. // 转盘奖励
  510. else if (GameDate.Weapon[showWeaponKey].priceType == PriceType.ZhuanPanReward) {
  511. cocosz.uiMgr.openPanel(PanelName.UITurntablePanel);
  512. }
  513. }
  514. // 升级
  515. else if (showWeaponInfo.Level < 3) {
  516. if (cocosz.dataMgr.CoinCount >= Constant.weaponLevelPriceArr[showWeaponInfo.Level]) {
  517. cocosz.dataMgr.CoinCount -= Constant.weaponLevelPriceArr[showWeaponInfo.Level];
  518. showWeaponInfo.Level++;
  519. cocosz.dataMgr.setGunInfo(showWeaponInfo.Id, showWeaponInfo);
  520. this._updateWeapon();
  521. this._updateWeaponFrame();
  522. this._aniEffect(1);
  523. } else {
  524. this.showCoinPanel(false);
  525. }
  526. }
  527. break;
  528. }
  529. case "BtnSkinAd": {
  530. console.log('zh:BtnSkinAd');
  531. utils.SendEvent("视频-皮肤解锁-播放")
  532. // 注册方法 , this.ClickClose.bind(this));
  533. //GlobalManager.getInstance().registerMethod('event_wuqi_unlook', this.event_wuqi_unlook.bind(this));
  534. cc.sys.localStorage.setItem(this.adKey, 'event_pifu_unlook');//
  535. if (ATRewardedVideoSDK.hasAdReady(AAJS2.getPlacementId())) {
  536. console.log('zh:AD ready for idx2')
  537. ATRewardedVideoSDK.showAd(AAJS2.getPlacementId());
  538. } else {
  539. console.log('zh:AD not ready for idx2')
  540. this.event_pifu_unlook();
  541. }
  542. if (2 > 1) {
  543. return;//下面是原始的代码
  544. }
  545. cocosz.watchAD(() => {
  546. // 视频成功
  547. utils.SendEvent("视频-皮肤解锁-成功")
  548. let showSkinInfo = cocosz.dataMgr.getSkinInfo(this._showSkinId);
  549. let showSkinKey: string = `${this._showSkinId + 1}`;
  550. if (!!showSkinInfo && !!GameDate.SkinMess[showSkinKey] && !!GameDate.SkinMess[showSkinKey].videoCount) {
  551. showSkinInfo.VideoCount++;
  552. cocosz.dataMgr.setSkinInfo(this._showSkinId, showSkinInfo);
  553. if (showSkinInfo.VideoCount >= GameDate.SkinMess[showSkinKey].videoCount) {
  554. Msg.Show(i18n.t("msg.gxhdxjs"));//恭喜获得新角色
  555. cocosz.dataMgr.CurSkinId = this._showSkinId;
  556. this._aniEffect(2);
  557. } else {
  558. Msg.Show(i18n.t("msg.jswc") + showSkinInfo.VideoCount + "/" + GameDate.SkinMess[showSkinKey].videoCount);
  559. }
  560. // 更新玩家信息
  561. this._updatePlayer();
  562. }
  563. }, () => {
  564. // 视频失败
  565. utils.SendEvent("视频-皮肤解锁-失败")
  566. });
  567. break;
  568. }
  569. case "BtnWeaponAd": {
  570. console.log('zh:BtnWeaponAd');
  571. utils.SendEvent("视频-武器解锁-播放")
  572. // 注册方法 , this.ClickClose.bind(this));
  573. //GlobalManager.getInstance().registerMethod('event_wuqi_unlook', this.event_wuqi_unlook.bind(this));
  574. cc.sys.localStorage.setItem(this.adKey, 'event_wuqi_unlook');//
  575. if (ATRewardedVideoSDK.hasAdReady(AAJS2.getPlacementId())) {
  576. console.log('zh:AD ready for idx2')
  577. ATRewardedVideoSDK.showAd(AAJS2.getPlacementId());
  578. } else {
  579. console.log('zh:AD not ready for idx2')
  580. this.event_wuqi_unlook();
  581. }
  582. if (2 > 1) {
  583. return;//下面是原始的代码
  584. }
  585. cocosz.watchAD(() => {
  586. // 视频成功
  587. utils.SendEvent("视频-武器解锁-成功")
  588. this.event_wuqi_unlook();
  589. }, () => {
  590. // 视频失败
  591. utils.SendEvent("视频-武器解锁-失败")
  592. });
  593. break;
  594. }
  595. case "BtnCJ": {
  596. console.log('zh:BtnCJ');
  597. cocosz.uiMgr.openPanel(PanelName.UITurntablePanel);
  598. break;
  599. }
  600. case "BtnSign": {
  601. console.log('zh:BtnSign');
  602. cocosz.uiMgr.openPanel(PanelName.UISignPanel);
  603. break;
  604. }
  605. case "BtnTime": {
  606. console.log('zh:BtnTime');
  607. cocosz.uiMgr.openPanel(PanelName.UITimePanel);
  608. break;
  609. }
  610. case "BtnSet": {
  611. console.log('zh:BtnSet');
  612. this._icon_set.stopAllActions();
  613. this._frame_set.stopAllActions();
  614. let t = (this._frame_set.scaleY ? this._frame_set.scaleY : 1) / 2;
  615. cc.tween(this._icon_set)
  616. .to(t, { angle: (this._frame_set.scaleY ? 90 : -90) }, { easing: "sineInOut" })
  617. .start();
  618. cc.tween(this._frame_set)
  619. .to(t, { scaleY: this._frame_set.scaleY ? 0 : 1 }, { easing: "sineInOut" })
  620. .start();
  621. break;
  622. }
  623. case "BtnAudio": {
  624. console.log('zh:BtnAudio');
  625. cocosz.dataMgr.AudioOn = !cocosz.dataMgr.AudioOn;
  626. this._updateAudioBtn();
  627. break;
  628. }
  629. case "BtnShake": {
  630. console.log('zh:BtnShake');
  631. cocosz.dataMgr.ShakeOn = !cocosz.dataMgr.ShakeOn;
  632. this._updatShakeBtn();
  633. break;
  634. }
  635. }
  636. }
  637. //武器结算
  638. public event_wuqi_unlook() {
  639. console.log('zh:event_wuqi_unlook 被触发');
  640. let showWeaponInfo = cocosz.dataMgr.getGunInfo(this._showWeaponId);
  641. let showWeaponKey: string = Weapon.WeaponName[this._showWeaponId];
  642. if (!!showWeaponInfo && !!GameDate.Weapon[showWeaponKey] && !!GameDate.Weapon[showWeaponKey].videoCount) {
  643. showWeaponInfo.VideoCount++;
  644. cocosz.dataMgr.setGunInfo(this._showWeaponId, showWeaponInfo);
  645. if (showWeaponInfo.VideoCount >= GameDate.Weapon[showWeaponKey].videoCount) {
  646. Msg.Show(i18n.t("msg.gxhdxwq"));
  647. cocosz.dataMgr.curWeapon = this._showWeaponId;
  648. this._aniEffect(2);
  649. } else {
  650. Msg.Show(i18n.t("msg.jswc") + showWeaponInfo.VideoCount + "/" + GameDate.Weapon[showWeaponKey].videoCount);
  651. }
  652. // 更新武器信息
  653. this._updateWeapon();
  654. this._updateWeaponFrame();
  655. }
  656. }
  657. //皮肤解锁
  658. private event_pifu_unlook() {
  659. console.log('zh:event_pifu_unlook 被触发');
  660. // 视频成功
  661. utils.SendEvent("视频-皮肤解锁-成功")
  662. let showSkinInfo = cocosz.dataMgr.getSkinInfo(this._showSkinId);
  663. let showSkinKey: string = `${this._showSkinId + 1}`;
  664. if (!!showSkinInfo && !!GameDate.SkinMess[showSkinKey] && !!GameDate.SkinMess[showSkinKey].videoCount) {
  665. showSkinInfo.VideoCount++;
  666. cocosz.dataMgr.setSkinInfo(this._showSkinId, showSkinInfo);
  667. if (showSkinInfo.VideoCount >= GameDate.SkinMess[showSkinKey].videoCount) {
  668. Msg.Show(i18n.t("msg.gxhdxjs"));//恭喜获得新角色
  669. cocosz.dataMgr.CurSkinId = this._showSkinId;
  670. this._aniEffect(2);
  671. } else {
  672. Msg.Show(i18n.t("msg.jswc") + showSkinInfo.VideoCount + "/" + GameDate.SkinMess[showSkinKey].videoCount);
  673. }
  674. // 更新玩家信息
  675. this._updatePlayer();
  676. }
  677. }
  678. private _showSkinId: number = cocosz.dataMgr.CurSkinId;
  679. private _updatePlayer() {
  680. cc.log("showSkinID: ", this._showSkinId);
  681. this._playerAni.setSkinById(this._showSkinId)
  682. // 属性
  683. // 角色名字
  684. this._skinInfo_name.spriteFrame = cocosz.resMgr.getRes("p_" + (this._showSkinId + 1), cc.SpriteFrame);
  685. // 角色属性
  686. let curSkinInfo = cocosz.dataMgr.getSkinInfo(cocosz.dataMgr.CurSkinId);
  687. let showSkinInfo = cocosz.dataMgr.getSkinInfo(this._showSkinId);
  688. let curLevel = curSkinInfo.Level;
  689. let showLevel = showSkinInfo.Level;
  690. let curSkinKey = `${cocosz.dataMgr.CurSkinId + 1}`;
  691. let showSKinKey = `${this._showSkinId + 1}`;
  692. // 血滴
  693. this._skinInfo_xuedi.children.forEach((v, i) => {
  694. if (i < GameDate.SkinMess[showSKinKey].xuedi) {
  695. this._skinInfo_xuedi.children[i].opacity = 255;
  696. } else {
  697. this._skinInfo_xuedi.children[i].opacity = 0;
  698. }
  699. })
  700. // 攻击力
  701. this._skinInfo_value1.string = `${GameDate.SkinMess[showSKinKey].atk[showLevel]}`;
  702. // 移动
  703. this._skinInfo_value2.string = `${GameDate.SkinMess[showSKinKey].speed[showLevel]}`;
  704. // 攻击变化
  705. let num1 = GameDate.SkinMess[showSKinKey].atk[showLevel] - GameDate.SkinMess[curSkinKey].atk[curLevel];
  706. if (num1 < 0) {
  707. this._skinInfo_change1.string = "" + num1;
  708. this._skinInfo_change1.node.children[0].active = false;
  709. this._skinInfo_change1.node.children[1].active = true;
  710. this._skinInfo_change1.node.color = cc.Color.RED;
  711. this._skinInfo_change1.node.opacity = 255;
  712. }
  713. else if (num1 == 0) {
  714. this._skinInfo_change1.node.opacity = 0;
  715. }
  716. else {
  717. this._skinInfo_change1.string = "+" + num1;
  718. this._skinInfo_change1.node.children[0].active = true;
  719. this._skinInfo_change1.node.children[1].active = false;
  720. this._skinInfo_change1.node.color = cc.Color.GREEN;
  721. this._skinInfo_change1.node.opacity = 255;
  722. }
  723. // 移动变化
  724. let num2 = GameDate.SkinMess[showSKinKey].speed[showLevel] - GameDate.SkinMess[curSkinKey].speed[curLevel];
  725. if (num2 < 0) {
  726. this._skinInfo_change2.string = "" + num2;
  727. this._skinInfo_change2.node.children[0].active = false;
  728. this._skinInfo_change2.node.children[1].active = true;
  729. this._skinInfo_change2.node.color = cc.Color.RED;
  730. this._skinInfo_change2.node.opacity = 255;
  731. }
  732. else if (num2 == 0) {
  733. this._skinInfo_change2.node.opacity = 0;
  734. }
  735. else {
  736. this._skinInfo_change2.string = "+" + num2;
  737. this._skinInfo_change2.node.children[0].active = true;
  738. this._skinInfo_change2.node.children[1].active = false;
  739. this._skinInfo_change2.node.color = cc.Color.GREEN;
  740. this._skinInfo_change2.node.opacity = 255;
  741. }
  742. // 等级
  743. this._skinInfo_level_pro.progress = showLevel / 6;
  744. // 按钮变化
  745. if (showSkinInfo) {
  746. this._btnSkin.children.forEach(v => v.active = false);
  747. let btn_huang = this._btnSkin.getChildByName("btn_huang");
  748. let btn_huang_small = this._btnSkin.getChildByName("btn_huang_small");
  749. let btn_hong = this._btnSkin.getChildByName("btn_hong");
  750. let txt_buy = this._btnSkin.getChildByName("txt_buy");
  751. let txt_sjwc = this._btnSkin.getChildByName("txt_sjwc");
  752. let txt_upgrade = this._btnSkin.getChildByName("txt_upgrade");
  753. let txt_zpjl = this._btnSkin.getChildByName("txt_zpjl");
  754. let icon_jinbi = this._btnSkin.getChildByName("icon_jinbi");
  755. let icon_zuanshi = this._btnSkin.getChildByName("icon_zuanshi");
  756. let price = this._btnSkin.getChildByName("price");
  757. // 购买
  758. if (showSkinInfo.State == 0) {
  759. if (GameDate.SkinMess[showSKinKey] && GameDate.SkinMess[showSKinKey].videoCount) {
  760. this._btnSkin.x = -350;
  761. this._btnSkin.width = 169;
  762. if (btn_huang_small) btn_huang_small.active = true;
  763. // 金币
  764. if (GameDate.SkinMess[showSKinKey].priceType == PriceType.Gold) {
  765. if (icon_jinbi) {
  766. icon_jinbi.active = true;
  767. icon_jinbi.x = -50;
  768. }
  769. if (price) {
  770. price.active = true;
  771. price.x = -10;
  772. price.getComponent(cc.Label).string = '' + GameDate.SkinMess[showSKinKey].price;
  773. }
  774. }
  775. // 钻石
  776. else if (GameDate.SkinMess[showSKinKey].priceType == PriceType.Diamond) {
  777. if (icon_zuanshi) {
  778. icon_zuanshi.active = true;
  779. icon_zuanshi.x = -50;
  780. }
  781. if (price) {
  782. price.active = true;
  783. price.x = -10;
  784. price.getComponent(cc.Label).string = '' + GameDate.SkinMess[showSKinKey].price;
  785. }
  786. }
  787. // 转盘奖励
  788. else if (GameDate.SkinMess[showSKinKey].priceType == PriceType.ZhuanPanReward) {
  789. if (txt_zpjl) txt_zpjl.active = true;
  790. }
  791. // 视频解锁
  792. this._btnSkinAd.active = true;
  793. let videoCount = this._btnSkinAd.getChildByName("videoCount");
  794. if (videoCount) videoCount.getComponent(cc.Label).string = showSkinInfo.VideoCount + "/" + GameDate.SkinMess[showSKinKey].videoCount;
  795. } else {
  796. this._btnSkinAd.active = false;
  797. this._btnSkin.x = -250;
  798. this._btnSkin.width = 252;
  799. if (btn_huang) btn_huang.active = true;
  800. // 金币
  801. if (GameDate.SkinMess[showSKinKey].priceType == PriceType.Gold) {
  802. if (txt_buy) txt_buy.active = true;
  803. if (icon_jinbi) {
  804. icon_jinbi.active = true;
  805. icon_jinbi.x = 0;
  806. }
  807. if (price) {
  808. price.active = true;
  809. price.x = 30;
  810. price.getComponent(cc.Label).string = '' + GameDate.SkinMess[showSKinKey].price;
  811. }
  812. }
  813. // 钻石
  814. else if (GameDate.SkinMess[showSKinKey].priceType == PriceType.Diamond) {
  815. if (txt_buy) txt_buy.active = true;
  816. if (icon_zuanshi) {
  817. icon_zuanshi.active = true;
  818. icon_zuanshi.x = 0;
  819. }
  820. if (price) {
  821. price.active = true;
  822. price.x = 30;
  823. price.getComponent(cc.Label).string = '' + GameDate.SkinMess[showSKinKey].price;
  824. }
  825. }
  826. // 转盘奖励
  827. else if (GameDate.SkinMess[showSKinKey].priceType == PriceType.ZhuanPanReward) {
  828. if (txt_zpjl) txt_zpjl.active = true;
  829. }
  830. }
  831. }
  832. // 升级
  833. else if (showSkinInfo.Level < 6) {
  834. this._btnSkinAd.active = false;
  835. this._btnSkin.x = -250;
  836. this._btnSkin.width = 252;
  837. if (btn_hong) btn_hong.active = true;
  838. if (txt_upgrade) txt_upgrade.active = true;
  839. if (icon_jinbi) {
  840. icon_jinbi.active = true;
  841. icon_jinbi.x = 0;
  842. }
  843. if (price) {
  844. price.active = true;
  845. price.x = 30;
  846. price.getComponent(cc.Label).string = '' + Constant.skinLevelPriceArr[showSkinInfo.Level];
  847. }
  848. }
  849. // 最大等级
  850. else {
  851. this._btnSkinAd.active = false;
  852. this._btnSkin.x = -250;
  853. this._btnSkin.width = 252;
  854. if (txt_sjwc) txt_sjwc.active = true;
  855. }
  856. }
  857. }
  858. private _showWeaponId: number = cocosz.dataMgr.CurRange;
  859. private _updateWeapon() {
  860. cc.log("showWeaponID: ", this._showWeaponId);
  861. this._playerAni.setWeaponById(this._showWeaponId);
  862. // 武器名字
  863. this._weaponInfo_name.spriteFrame = cocosz.resMgr.getRes("w_" + (this._showWeaponId + 1), cc.SpriteFrame);
  864. // 武器属性
  865. let curWeaponInfo = cocosz.dataMgr.getGunInfo(cocosz.dataMgr.CurRange);
  866. let showWeaponInfo = cocosz.dataMgr.getGunInfo(this._showWeaponId);
  867. let curLevel = curWeaponInfo.Level;
  868. let showLevel = showWeaponInfo.Level;
  869. let curWeaponKey = Weapon.WeaponName[cocosz.dataMgr.CurRange];
  870. let showWeaponKey = Weapon.WeaponName[this._showWeaponId];
  871. // 攻击力
  872. this._weaponInfo_value0.string = `${GameDate.Weapon[showWeaponKey].atk[showLevel]}`;
  873. // 攻击频率
  874. this._weaponInfo_value1.string = (1 / GameDate.Weapon[showWeaponKey].atkSpeed[showLevel]).toFixed(1);
  875. // 攻击范围
  876. this._weaponInfo_value2.string = `${GameDate.Weapon[showWeaponKey].atkRange}`;
  877. // 弹药量
  878. this._weaponInfo_value3.string = `${GameDate.Weapon[showWeaponKey].bulletTotal[showLevel]}`;
  879. // 变化
  880. let num0 = GameDate.Weapon[showWeaponKey].atk[showLevel] - GameDate.Weapon[curWeaponKey].atk[curLevel];
  881. let num1 = 1 / GameDate.Weapon[showWeaponKey].atkSpeed[showLevel] - 1 / GameDate.Weapon[curWeaponKey].atkSpeed[curLevel];
  882. let num2 = GameDate.Weapon[showWeaponKey].atkRange - GameDate.Weapon[curWeaponKey].atkRange;
  883. let num3 = GameDate.Weapon[showWeaponKey].bulletTotal[showLevel] - GameDate.Weapon[curWeaponKey].bulletTotal[curLevel];
  884. // 攻击力变化
  885. if (num0 < 0) {
  886. this._weaponInfo_change0.string = "" + num0;
  887. this._weaponInfo_change0.node.children[0].active = false;
  888. this._weaponInfo_change0.node.children[1].active = true;
  889. this._weaponInfo_change0.node.color = cc.Color.RED;
  890. this._weaponInfo_change0.node.opacity = 255;
  891. } else if (num0 == 0) {
  892. this._weaponInfo_change0.node.opacity = 0;
  893. } else {
  894. this._weaponInfo_change0.string = "+" + num0;
  895. this._weaponInfo_change0.node.children[0].active = true;
  896. this._weaponInfo_change0.node.children[1].active = false;
  897. this._weaponInfo_change0.node.color = cc.Color.GREEN;
  898. this._weaponInfo_change0.node.opacity = 255;
  899. }
  900. // 攻击频率变化
  901. if (num1 < 0) {
  902. this._weaponInfo_change1.string = "" + num1;
  903. this._weaponInfo_change1.node.children[0].active = false;
  904. this._weaponInfo_change1.node.children[1].active = true;
  905. this._weaponInfo_change1.node.color = cc.Color.RED;
  906. this._weaponInfo_change1.node.opacity = 255;
  907. } else if (num1 == 0) {
  908. this._weaponInfo_change1.node.opacity = 0;
  909. } else {
  910. this._weaponInfo_change1.string = "+" + num1;
  911. this._weaponInfo_change1.node.children[0].active = true;
  912. this._weaponInfo_change1.node.children[1].active = false;
  913. this._weaponInfo_change1.node.color = cc.Color.GREEN;
  914. this._weaponInfo_change1.node.opacity = 255;
  915. }
  916. // 攻击范围变化
  917. if (num2 < 0) {
  918. this._weaponInfo_change2.string = "" + num2;
  919. this._weaponInfo_change2.node.children[0].active = false;
  920. this._weaponInfo_change2.node.children[1].active = true;
  921. this._weaponInfo_change2.node.color = cc.Color.RED;
  922. this._weaponInfo_change2.node.opacity = 255;
  923. } else if (num2 == 0) {
  924. this._weaponInfo_change2.node.opacity = 0;
  925. } else {
  926. this._weaponInfo_change2.string = "+" + num2;
  927. this._weaponInfo_change2.node.children[0].active = true;
  928. this._weaponInfo_change2.node.children[1].active = false;
  929. this._weaponInfo_change2.node.color = cc.Color.GREEN;
  930. this._weaponInfo_change2.node.opacity = 255;
  931. }
  932. // 弹药量变化
  933. if (num3 < 0) {
  934. this._weaponInfo_change3.string = "" + num3;
  935. this._weaponInfo_change3.node.children[0].active = false;
  936. this._weaponInfo_change3.node.children[1].active = true;
  937. this._weaponInfo_change3.node.color = cc.Color.RED;
  938. this._weaponInfo_change3.node.opacity = 255;
  939. } else if (num3 == 0) {
  940. this._weaponInfo_change3.node.opacity = 0;
  941. } else {
  942. this._weaponInfo_change3.string = "+" + num3;
  943. this._weaponInfo_change3.node.children[0].active = true;
  944. this._weaponInfo_change3.node.children[1].active = false;
  945. this._weaponInfo_change3.node.color = cc.Color.GREEN;
  946. this._weaponInfo_change3.node.opacity = 255;
  947. }
  948. // 等级
  949. this._weaponInfo_level_pro.progress = showLevel / 3;
  950. // 按钮变化
  951. if (showWeaponInfo) {
  952. this._btnWeapon.children.forEach(v => v.active = false);
  953. let btn_huang = this._btnWeapon.getChildByName("btn_huang");
  954. let btn_huang_small = this._btnWeapon.getChildByName("btn_huang_small");
  955. let btn_hong = this._btnWeapon.getChildByName("btn_hong");
  956. let txt_buy = this._btnWeapon.getChildByName("txt_buy");
  957. let txt_sjwc = this._btnWeapon.getChildByName("txt_sjwc");
  958. let txt_upgrade = this._btnWeapon.getChildByName("txt_upgrade");
  959. let txt_zpjl = this._btnWeapon.getChildByName("txt_zpjl");
  960. let icon_jinbi = this._btnWeapon.getChildByName("icon_jinbi");
  961. let icon_zuanshi = this._btnWeapon.getChildByName("icon_zuanshi");
  962. let price = this._btnWeapon.getChildByName("price");
  963. if (showWeaponInfo.State == 0) {
  964. // 视频解锁
  965. if (GameDate.Weapon[showWeaponKey] && GameDate.Weapon[showWeaponKey].videoCount) {
  966. this._btnWeapon.x = 150;
  967. this._btnWeapon.width = 169;
  968. if (btn_huang_small) btn_huang_small.active = true;
  969. // 金币
  970. if (GameDate.Weapon[showWeaponKey].priceType == PriceType.Gold) {
  971. if (icon_jinbi) {
  972. icon_jinbi.active = true;
  973. icon_jinbi.x = -50;
  974. }
  975. if (price) {
  976. price.active = true;
  977. price.x = -10;
  978. price.getComponent(cc.Label).string = '' + GameDate.Weapon[showWeaponKey].price;
  979. }
  980. }
  981. // 钻石
  982. else if (GameDate.Weapon[showWeaponKey].priceType == PriceType.Diamond) {
  983. if (icon_zuanshi) {
  984. icon_zuanshi.active = true;
  985. icon_zuanshi.x = -50;
  986. }
  987. if (price) {
  988. price.active = true;
  989. price.x = -10;
  990. price.getComponent(cc.Label).string = '' + GameDate.Weapon[showWeaponKey].price;
  991. }
  992. }
  993. // 转盘奖励
  994. else if (GameDate.Weapon[showWeaponKey].priceType == PriceType.ZhuanPanReward) {
  995. if (txt_zpjl) txt_zpjl.active = true;
  996. }
  997. // 视频解锁
  998. this._btnWeaponAd.active = true;
  999. let videoCount = this._btnWeaponAd.getChildByName("videoCount");
  1000. if (videoCount) videoCount.getComponent(cc.Label).string = showWeaponInfo.VideoCount + "/" + GameDate.Weapon[showWeaponKey].videoCount;
  1001. }
  1002. // 购买
  1003. else {
  1004. this._btnWeaponAd.active = false;
  1005. this._btnWeapon.x = 250;
  1006. this._btnWeapon.width = 252;
  1007. if (btn_huang) btn_huang.active = true;
  1008. // 金币
  1009. if (GameDate.Weapon[showWeaponKey].priceType == PriceType.Gold) {
  1010. if (txt_buy) txt_buy.active = true;
  1011. if (icon_jinbi) {
  1012. icon_jinbi.active = true;
  1013. icon_jinbi.x = 0;
  1014. }
  1015. if (price) {
  1016. price.active = true;
  1017. price.x = 30;
  1018. price.getComponent(cc.Label).string = '' + GameDate.Weapon[showWeaponKey].price;
  1019. }
  1020. }
  1021. // 钻石
  1022. else if (GameDate.Weapon[showWeaponKey].priceType == PriceType.Diamond) {
  1023. if (txt_buy) txt_buy.active = true;
  1024. if (icon_zuanshi) {
  1025. icon_zuanshi.active = true;
  1026. icon_zuanshi.x = 0;
  1027. }
  1028. if (price) {
  1029. price.active = true;
  1030. price.x = 30;
  1031. price.getComponent(cc.Label).string = '' + GameDate.Weapon[showWeaponKey].price;
  1032. }
  1033. }
  1034. // 转盘奖励
  1035. else if (GameDate.Weapon[showWeaponKey].priceType == PriceType.ZhuanPanReward) {
  1036. if (txt_zpjl) txt_zpjl.active = true;
  1037. }
  1038. }
  1039. }
  1040. // 升级
  1041. else if (showWeaponInfo.Level < 3) {
  1042. this._btnWeaponAd.active = false;
  1043. this._btnWeapon.x = 250;
  1044. this._btnWeapon.width = 252;
  1045. if (btn_hong) btn_hong.active = true;
  1046. if (txt_upgrade) txt_upgrade.active = true;
  1047. if (icon_jinbi) {
  1048. icon_jinbi.active = true;
  1049. icon_jinbi.x = 0;
  1050. }
  1051. if (price) {
  1052. price.active = true;
  1053. price.x = 30;
  1054. price.getComponent(cc.Label).string = '' + Constant.weaponLevelPriceArr[showWeaponInfo.Level];
  1055. }
  1056. }
  1057. // 最大等级
  1058. else {
  1059. this._btnWeaponAd.active = false;
  1060. this._btnWeapon.x = 250;
  1061. this._btnWeapon.width = 252;
  1062. if (txt_sjwc) txt_sjwc.active = true;
  1063. }
  1064. }
  1065. this._updateWeaponFrame();
  1066. }
  1067. _updateWeaponFrame() {
  1068. let gunInfos: string = cocosz.dataMgr.getItem(Constant.ST_GunInfo, "");
  1069. if (gunInfos) {
  1070. let gunInfoArr: GunInfo[] = JSON.parse(gunInfos);
  1071. if (gunInfoArr) {
  1072. for (let i = 0; i < this._weaponList.length; i++) {
  1073. let node = this._weaponList[i];
  1074. if (GameDate.Weapon[node.name] && GameDate.Weapon[node.name].id >= 0) {
  1075. let id = GameDate.Weapon[node.name].id;
  1076. if (gunInfoArr[id]) {
  1077. let state = gunInfoArr[id].State;
  1078. if (state >= 1) {
  1079. node.getChildByName("kuang_hui").active = false;
  1080. } else {
  1081. node.getChildByName("kuang_hui").active = true;
  1082. }
  1083. // 选中
  1084. if (node.name == Weapon.WeaponName[this._showWeaponId]) {
  1085. node.getChildByName("kuang_huang").active = true;
  1086. if (this._ani_arrow) {
  1087. if (gunInfoArr[id].State > 0 && gunInfoArr[id].Level < 3) {
  1088. this._ani_arrow.x = node.x + 30;
  1089. this._ani_arrow.active = true;
  1090. } else {
  1091. this._ani_arrow.active = false;
  1092. }
  1093. }
  1094. } else {
  1095. node.getChildByName("kuang_huang").active = false;
  1096. }
  1097. } else {
  1098. node.getChildByName("kuang_hui").active = false;
  1099. node.getChildByName("kuang_huang").active = false;
  1100. }
  1101. } else {
  1102. node.getChildByName("kuang_hui").active = false;
  1103. node.getChildByName("kuang_huang").active = false;
  1104. }
  1105. }
  1106. }
  1107. }
  1108. }
  1109. /** 金币/钻石弹窗 */
  1110. showCoinPanel(isDiamond: boolean) {
  1111. let node = cc.instantiate(cocosz.resMgr.getRes("UIADPanel", cc.Prefab));
  1112. cc.find("Canvas").addChild(node);
  1113. if (isDiamond) {
  1114. node.getComponent("UIADPanel").setDiamond();
  1115. }
  1116. }
  1117. /** 飞金币/钻石 */
  1118. private _flyCoins(iconName: string, frameNodeName: string) {
  1119. let posNode = cc.find(frameNodeName, this._page);
  1120. if (!posNode) return;
  1121. let pos = posNode.parent.convertToWorldSpaceAR(posNode.position);
  1122. FlyCoin.Show(iconName, pos);
  1123. }
  1124. /** 更新音频开关 */
  1125. private _updateAudioBtn(isPlay: boolean = true) {
  1126. let offImg: cc.Node = cc.find("Background/off", this._btnAudio);
  1127. offImg.active = cocosz.dataMgr.AudioOn == false;
  1128. if (isPlay) {
  1129. //判断开关,重新播放背景音乐
  1130. if (cocosz.dataMgr.AudioOn) {
  1131. cocosz.audioMgr.playBgm();
  1132. } else {
  1133. cocosz.audioMgr.stopAll();
  1134. }
  1135. }
  1136. }
  1137. /** 更新震动开关 */
  1138. private _updatShakeBtn() {
  1139. let offImg: cc.Node = cc.find("Background/off", this._btnShake);
  1140. offImg.active = cocosz.dataMgr.ShakeOn == false;
  1141. }
  1142. }