UIHomePage.ts 56 KB

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