LevelHomeItem.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  1. const ThemeManager = require("../utils/ThemeManger");
  2. const { RoomState, GameNotificationKey, WechatShareType } = require("../utils/GameEnum");
  3. const GameModule = require("../utils/GameModule");
  4. const TapTapTool = require("../utils/TapTapTool");
  5. const WeChat = require('../net/WeChat');
  6. const HomeApi = require('../net/HomeApi');
  7. const DWTool = require('../utils/DWTool');
  8. cc.Class({
  9. extends: cc.Component,
  10. properties: {
  11. // Public Properties
  12. bgNode: cc.Node,
  13. /** 当前显示的图片 */
  14. buildSprite: cc.Sprite,
  15. /** 柱子 */
  16. pillarTop: cc.Sprite,
  17. pillarBottom: cc.Sprite,
  18. pillarRight: cc.Sprite,
  19. pillarLeft: cc.Sprite,
  20. bottomBg: cc.Sprite,
  21. lockBtnFrames: [cc.SpriteFrame],
  22. /** 升级按钮的两种状态图 */
  23. updateBtnFrames: [cc.SpriteFrame],
  24. /** 未解锁状态的节点 */
  25. lockNode: cc.Node,
  26. /** 需要花费所有金币 */
  27. costLabel: cc.Label,
  28. /** 未解锁的建筑名称 */
  29. unLockBuildName: cc.RichText,
  30. /** 未解锁需要花费多少金币 */
  31. unlockRichText: cc.RichText,
  32. /** 未解锁需要总部等级 */
  33. unlockLevelLabel: cc.Label,
  34. /** 建筑昵称 */
  35. buildNameLabel: cc.Label,
  36. /** 这里当做升级建筑按钮 */
  37. updateBtn: cc.Node,
  38. /** 看广告或者分享群免费升级 */
  39. videoBtn: cc.Button,
  40. videoRichText: cc.RichText,
  41. /** 解锁按钮 */
  42. lockBtn: cc.Sprite,
  43. /** 将要解锁建筑的类型图 */
  44. unlockBuildingType: cc.Sprite,
  45. lockBottomNode: cc.Node,
  46. /** 等级进度条 */
  47. levelProgressBar: cc.ProgressBar,
  48. /** 生产了多少金币 */
  49. rateProgressLabel: cc.Label,
  50. /** 下一级生产多少金币 */
  51. nextRateLabel: cc.Label,
  52. openDoorSkeletion: sp.Skeleton,
  53. updateSkeletion: sp.Skeleton,
  54. // 满级提示
  55. maxNode: cc.Node,
  56. //
  57. artistNode: cc.Node,
  58. //
  59. artistMan: cc.Prefab,
  60. awardWrap: cc.Node,
  61. awardPrefab: cc.Prefab,
  62. _itemId: 0,
  63. skillEfcNode: cc.Node,
  64. coupletLeftSrpite: cc.Sprite,
  65. coupletRightSrpite: cc.Sprite,
  66. //对联数组
  67. coupletFrames: [cc.SpriteFrame]
  68. },
  69. // LIFE-CYCLE CALLBACKS:
  70. onLoad () {
  71. this.setupUI();
  72. this.openDoorSkeletion.setCompleteListener(() => {
  73. // 升级建筑
  74. this.updateBuilding();
  75. GameEvent.fire(GameNotificationKey.PlaySuccessAnimation, true);
  76. });
  77. //点击解锁建筑
  78. let self = this;
  79. this.unlockBuildingEvent = _.debounce(() => {
  80. // 如果当前不够钱, 点击不生效
  81. if (!TapTapTool.compare(GameModule.userInfo.gold, self.data.unlockScore)) {
  82. return;
  83. }
  84. // 点完立刻隐藏
  85. self.lockBtn.node.active = false;
  86. let position = self.lockBtn.node.convertToWorldSpace(cc.v2(self.lockBtn.node.width / 2, self.lockBtn.node.height / 2));
  87. GameEvent.fire(GameNotificationKey.PlayUpdateCoinAnimation, position);
  88. self.openDoorSkeletion.setAnimation(1, "changjing_kaiqi2");
  89. self.lockBottomNode.runAction(cc.fadeOut(0.7));
  90. self.lockBottomNode.active = false;
  91. }, 1000, true);
  92. this.isFullUpdate = false;
  93. this.longCount = 0;
  94. //点击升级建筑
  95. this.updateBtn.on(cc.Node.EventType.TOUCH_START, () => {
  96. if (!this._isTouch) {
  97. this._isTouch = true;
  98. this.schedule(this.longUpdateBuilding, 0.3);
  99. }
  100. }, this);
  101. this.updateBtn.on(cc.Node.EventType.TOUCH_CANCEL, () => {
  102. this._isTouch = false;
  103. this.unschedule(this.longUpdateBuilding, this);
  104. this.isFullUpdate = false;
  105. this.longCount = 0
  106. }, this);
  107. this.updateBtn.on(cc.Node.EventType.TOUCH_END, () => {
  108. this._isTouch = false;
  109. this.updateBuildingEvent();
  110. this.unschedule(this.longUpdateBuilding, this);
  111. this.isFullUpdate = false;
  112. this.longCount = 0
  113. }, this);
  114. this.setupEventListener();
  115. },
  116. //长按升级建筑
  117. longUpdateBuilding() {
  118. this.updateBuildingEvent();
  119. this.longCount += 1;
  120. if (this.longCount > 5 && !this.isFullUpdate) {
  121. this.unschedule(this.longUpdateBuilding, this);
  122. this.isFullUpdate = true;
  123. this.schedule(this.longUpdateBuilding, 0.2);
  124. }
  125. },
  126. setupUI() {
  127. this._adState = GameGlobal._adVideoState;
  128. this.refreshWatchVideoUI();
  129. this.humanList = [];
  130. this.humanPool = new cc.NodePool();
  131. for (let i = 0; i < 5; i++) {
  132. let artist = cc.instantiate(this.artistMan);
  133. this.humanPool.put(artist);
  134. this.humanList.push(artist);
  135. }
  136. },
  137. setupEventListener() {
  138. GameEvent.on(GameNotificationKey.AdUpdateStateNotification, this, (adState, callBack) => {
  139. if (adState === 3 && callBack.type != undefined && callBack.type == 'updateRoom') {
  140. this.finishVideoOrShare(callBack.roomId);
  141. }
  142. if (adState === 0 || adState === 1) {
  143. this.initRoomAd();
  144. }
  145. this.videoBtn.interactable = true;
  146. });
  147. },
  148. initRoomAd() {
  149. if (!CC_WECHATGAME || window.tt == undefined) {
  150. return;
  151. }
  152. //// 说明有广告
  153. if (GameGlobal._adVideoState == 0) {
  154. this._adState = 2;
  155. } else if (GameGlobal._adVideoState === 1) {
  156. this._adState = 1;
  157. }
  158. this.refreshWatchVideoUI();
  159. },
  160. ///观看广告或者分享获取升级建筑
  161. watchVideoOrShare() {
  162. if (CC_WECHATGAME) {
  163. if (this._adState == 1) {
  164. this.videoBtn.interactable = false;
  165. GameEvent.on(GameNotificationKey.ShowShareAction, this, (type, isOk) => {
  166. if (type == WechatShareType.UpRoomLevel) {
  167. if (isOk) {
  168. this.finishVideoOrShare(this.data.roomId);
  169. } else {
  170. this.videoBtn.interactable = true;
  171. }
  172. GameEvent.off(GameNotificationKey.ShowShareAction, this);
  173. }
  174. });
  175. WeChat.shareAction(WechatShareType.UpRoomLevel, () => {
  176. }, () => {
  177. this.videoBtn.interactable = true;
  178. console.log('分享失败或取消');
  179. });
  180. } else if (this._adState == 2) {
  181. this.videoBtn.interactable = false;
  182. let adObject = new Object();
  183. adObject.type = 'updateRoom';
  184. adObject.roomId = this.data.roomId;
  185. GameGlobal._adVideo.showVideo(adObject);
  186. }
  187. }
  188. },
  189. finishVideoOrShare(roomId) {
  190. if (this.data.roomId == roomId) {
  191. HomeApi.reportInformation(2, () => {
  192. GameGlobal._upRoomInfo.count += 1;
  193. /// 时间重置为5分钟
  194. GameGlobal._upRoomInfo.cdTime = 5 * 60 * 1000;
  195. this.updateBuildingEvent(true);
  196. this.refreshWatchVideoUI();
  197. this.videoBtn.interactable = true;
  198. }, (code, msg) => {
  199. this.videoBtn.interactable = true;
  200. });
  201. }
  202. },
  203. //刷新观看视频或者分享文案
  204. refreshWatchVideoUI() {
  205. if (this._adState == 1) {
  206. if (window.tt != undefined) {
  207. this.videoRichText.string = '<b>分享\n免费升级</b>';
  208. } else {
  209. this.videoRichText.string = '<b>分享到群\n免费升级</b>';
  210. }
  211. } else if (this._adState == 2) {
  212. this.videoRichText.string = '<b>看广告\n免费升级</b>';
  213. }
  214. },
  215. //每帧更新数据
  216. update (dt) {
  217. if (this.data) {
  218. // 不断刷新界面
  219. this.layout(this.data);
  220. }
  221. },
  222. updateItem(data, itemId, resetCallback) {
  223. if (!isNaN(itemId)) {
  224. // if (this._itemId == itemId && itemId != 0) {
  225. // return;
  226. // }
  227. this._itemId = itemId;
  228. }
  229. if (typeof data != 'object') {
  230. return;
  231. }
  232. if (resetCallback) {
  233. this.resetCallback = resetCallback;
  234. }
  235. this.data = data;
  236. this.buildNameLabel.string = `等级${data.level} ${data.name}` ;
  237. this.refreshTheme();
  238. this.layout(data);
  239. // 配置界面上的奖励礼包
  240. this.configAward();
  241. //升级房间时不用刷新人物
  242. if (!isNaN(itemId)) {
  243. this.artistListLayout();
  244. }
  245. },
  246. layout(data) {
  247. // console.log(GameModule.skill.isUsingSkill3);
  248. // 判断是否有下一级, 没有的话就是满级
  249. if (data.hasNext === 1 && data.level < GameGlobal.BuildingManager.getLevelCount(data.roomId)) {
  250. // 判断是否已经解锁
  251. if (data.isUnlocked) {
  252. let ratio = data.level % 25;
  253. this.levelProgressBar.progress = ratio / 25;
  254. //
  255. let gold1 = TapTapTool.goldStrToClass(data.gold1);
  256. let gold2 = TapTapTool.goldStrToClass(data.gold2);
  257. let roomMt = TapTapTool.goldStrToClass(data.roomMt);
  258. var secondGold = TapTapTool.multiple(gold1,data.level);
  259. secondGold = TapTapTool.add(secondGold, gold2);
  260. var nextGold = TapTapTool.multiple(gold1,(data.level+1));
  261. nextGold = TapTapTool.add(nextGold, gold2);
  262. let nextDiffer = TapTapTool.sub(nextGold, secondGold);
  263. secondGold = TapTapTool.multiple(secondGold,roomMt);
  264. secondGold = TapTapTool.multiple(secondGold, GameModule.skill.multiple);
  265. secondGold = TapTapTool.multiple(secondGold, GameModule.userInfo.perpetualMt);
  266. secondGold = TapTapTool.multiple(secondGold, {'n': GameModule.shop.multiple, 'e': 0});
  267. this.rateProgressLabel.string = `${TapTapTool.parseToString(secondGold)}/秒`;
  268. nextDiffer = TapTapTool.multiple(nextDiffer,roomMt);
  269. nextDiffer = TapTapTool.multiple(nextDiffer, GameModule.skill.multiple);
  270. nextDiffer = TapTapTool.multiple(nextDiffer, {'n': GameModule.shop.multiple, 'e': 0});
  271. nextDiffer = TapTapTool.multiple(nextDiffer, GameModule.userInfo.perpetualMt);
  272. this.nextRateLabel.string = `+${TapTapTool.parseToString(nextDiffer)}/秒`;
  273. this.lockNode.active = false;
  274. this.costLabel.string = TapTapTool.parseToString(data.nextUpGold);
  275. // 判断是否有足够的金额解锁
  276. if (TapTapTool.compare(GameModule.userInfo.gold, data.nextUpGold)) {
  277. this.setState(RoomState.Update);
  278. } else {
  279. let isAd = DWTool.checkIsOldUser() && GameGlobal._upRoomInfo != undefined && GameGlobal._upRoomInfo.count < GameGlobal._upRoomInfo.maxCount && GameGlobal._upRoomInfo.cdTime <= 0;
  280. if (isAd) {
  281. this.setState(RoomState.WatchVideo);
  282. } else {
  283. this.setState(RoomState.UnLock);
  284. }
  285. }
  286. } else {
  287. this.lockNode.active = true;
  288. this.costLabel.string = 0;
  289. this.unLockBuildName.string = `<b><color=#ffffff>${data.name}</c></b>`;
  290. let unLockData = TapTapTool.goldStrToClass(data.unlockScore);
  291. this.unlockRichText.string = `<img src='coin_small'/><b><color=#ffffff> ${TapTapTool.parseToString(unLockData)}</c><b/>`;
  292. // 判断是否有足够的金额解锁
  293. if (TapTapTool.compare(GameModule.userInfo.gold, unLockData) && GameModule.userInfo.buildingLevel >= data.buildingLevel) {
  294. this.unlockBuildingType.node.active = true;
  295. this.lockBtn.spriteFrame = this.lockBtnFrames[1];
  296. this.lockBtn.node.getComponent(cc.Button).interactable = true;
  297. } else {
  298. this.unlockBuildingType.node.active = false;
  299. this.lockBtn.spriteFrame = this.lockBtnFrames[0];
  300. this.lockBtn.node.getComponent(cc.Button).interactable = false;
  301. }
  302. if (data.buildingLevel > 0) {
  303. this.unlockLevelLabel.node.active = true;
  304. this.unlockLevelLabel.string = `需要总部等级${data.buildingLevel}级`;
  305. } else {
  306. this.unlockLevelLabel.node.active = false;
  307. this.unlockLevelLabel.string = '';
  308. }
  309. this.setState(RoomState.Lock);
  310. }
  311. } else {
  312. this.rate = data.rate;
  313. this.levelProgressBar.progress = 1.0;
  314. this.setState(RoomState.Full);
  315. let gold1 = TapTapTool.goldStrToClass(data.gold1);
  316. let gold2 = TapTapTool.goldStrToClass(data.gold2);
  317. let roomMt = TapTapTool.goldStrToClass(data.roomMt);
  318. var secondGold = TapTapTool.multiple(gold1,data.level);
  319. secondGold = TapTapTool.add(secondGold, gold2);
  320. secondGold = TapTapTool.multiple(secondGold,roomMt);
  321. this.rateProgressLabel.string = `${TapTapTool.parseToString(secondGold)}/秒`;
  322. }
  323. //使用技能3的时候楼层增加对联效果
  324. if (data.isUnlocked && GameModule.skill.isUsingSkill3) {
  325. //大于0为单层显示对联
  326. if (GameModule.skill.skill3Floor > 0) {
  327. if (this.data.roomId % 2 == 0) {
  328. this.skillEfcNode.active = false;
  329. } else {
  330. if (this.skillEfcNode.active == false) {
  331. this.skillEfcNode.active = true;
  332. let arr = this.randNum(0,(this.coupletFrames.length - 1),2);
  333. this.coupletLeftSrpite.spriteFrame = this.coupletFrames[arr[0]];
  334. this.coupletRightSrpite.spriteFrame = this.coupletFrames[arr[1]];
  335. }
  336. }
  337. } else {
  338. if (this.data.roomId % 2 == 0) {
  339. if (this.skillEfcNode.active == false) {
  340. this.skillEfcNode.active = true;
  341. let arr = this.randNum(0,(this.coupletFrames.length - 1),2);
  342. this.coupletLeftSrpite.spriteFrame = this.coupletFrames[arr[0]];
  343. this.coupletRightSrpite.spriteFrame = this.coupletFrames[arr[1]];
  344. }
  345. } else {
  346. this.skillEfcNode.active = false;
  347. }
  348. }
  349. } else {
  350. this.skillEfcNode.active = false;
  351. }
  352. },
  353. randNum(min, max, num) {
  354. var arr = [],
  355. t;
  356. function fn(i) {
  357. for (i; i < num; i++) {
  358. t = parseInt(Math.random() * (max - min + 1) + min);
  359. for(var k in arr) {
  360. if (arr[k] == t) {
  361. fn(i);
  362. break;
  363. }
  364. }
  365. arr[i] = t;
  366. }
  367. }
  368. fn(0);
  369. return arr
  370. },
  371. //根据房间不同状态显示不同界面
  372. setState(state) {
  373. if (this.state === state) { return; }
  374. switch (state) {
  375. case RoomState.Lock:
  376. this.openDoorSkeletion.node.active = true;
  377. this.openDoorSkeletion.clearTracks();
  378. this.openDoorSkeletion.setToSetupPose();
  379. this.lockBtn.node.active = true;
  380. this.lockBottomNode.stopAllActions();
  381. this.lockBottomNode.opacity = 255;
  382. this.lockBottomNode.active = true;
  383. this.lockNode.active = true;
  384. this.updateBtn.active = false;
  385. this.updateBtn.getComponent(cc.Button).interactable = false;
  386. this.updateBtn.getComponent(cc.Sprite).spriteFrame = this.updateBtnFrames[0];
  387. this.maxNode.active = false;
  388. this.videoBtn.node.active = false;
  389. this._isTouch = false;
  390. this.unschedule(this.longUpdateBuilding, this);
  391. break;
  392. case RoomState.UnLock:
  393. this.openDoorSkeletion.node.active = false;
  394. this.lockBtn.node.active = false;
  395. this.lockBottomNode.active = false;
  396. this.updateBtn.active = true;
  397. this.lockNode.active = false;
  398. this.updateBtn.getComponent(cc.Button).interactable = false;
  399. this.updateBtn.getComponent(cc.Sprite).spriteFrame = this.updateBtnFrames[0];
  400. this.maxNode.active = false;
  401. this.videoBtn.node.active = false;
  402. this._isTouch = false;
  403. this.unschedule(this.longUpdateBuilding, this);
  404. break;
  405. case RoomState.Update:
  406. this.openDoorSkeletion.node.active = false;
  407. this.lockBtn.node.active = false;
  408. this.lockBottomNode.active = false;
  409. this.updateBtn.active = true;
  410. this.lockNode.active = false;
  411. this.updateBtn.getComponent(cc.Sprite).spriteFrame = this.updateBtnFrames[1];
  412. this.updateBtn.getComponent(cc.Button).interactable = true;
  413. this.maxNode.active = false;
  414. this.videoBtn.node.active = false;
  415. break;
  416. case RoomState.Full:
  417. this.openDoorSkeletion.node.active = false;
  418. this.lockBtn.node.active = false;
  419. this.lockBottomNode.active = false;
  420. this.lockNode.active = false;
  421. this.maxNode.active = true;
  422. this.updateBtn.active = false;
  423. this.videoBtn.node.active = false;
  424. this._isTouch = false;
  425. this.unschedule(this.longUpdateBuilding, this);
  426. break;
  427. case RoomState.WatchVideo:
  428. this.openDoorSkeletion.node.active = false;
  429. this.lockBtn.node.active = false;
  430. this.lockBottomNode.active = false;
  431. this.updateBtn.active = true;
  432. this.lockNode.active = false;
  433. this.updateBtn.getComponent(cc.Button).interactable = false;
  434. this.updateBtn.getComponent(cc.Sprite).spriteFrame = this.updateBtnFrames[0];
  435. this.maxNode.active = false;
  436. this.updateBtn.active = false;
  437. this.videoBtn.node.active = true;
  438. this._isTouch = false;
  439. this.unschedule(this.longUpdateBuilding, this);
  440. break;
  441. default:
  442. break;
  443. }
  444. this.state = state;
  445. },
  446. refreshTheme() {
  447. ThemeManager.setItemBuildSpriteFrame(this.data.roomId, this.buildSprite);
  448. let lockBottomSprite = this.lockBottomNode.getComponent(cc.Sprite);
  449. ThemeManager.setItemLockDownSpriteFrame(lockBottomSprite);
  450. },
  451. setListViewAdapter(listViewAdapter) {
  452. this._listViewAdapter = listViewAdapter;
  453. },
  454. deleteItem() {
  455. this._listViewAdapter.removeItem(this);
  456. },
  457. // 解锁建筑事件
  458. unlockBuilding() {
  459. this.unlockBuildingEvent();
  460. },
  461. updateBuildingEvent(isFree = false) {
  462. if (this.state === RoomState.Update || this.state === RoomState.WatchVideo) {
  463. let position = this.updateBtn.convertToWorldSpace(cc.v2(this.updateBtn.width / 2, this.updateBtn.height / 2));
  464. GameEvent.fire(GameNotificationKey.PlayUpdateCoinAnimation, position);
  465. this.updateBuilding(isFree);
  466. if (!this.updateSkeletion.node.active) {
  467. this.updateSkeletion.node.active = true;
  468. this.updateSkeletion.setAnimation(0, "changjing_sj");
  469. this.updateSkeletion.setCompleteListener(() => {
  470. this.updateSkeletion.node.active = false;
  471. });
  472. }
  473. }
  474. },
  475. // 升级建筑
  476. updateBuilding(isFree) {
  477. //判断是否免费升级
  478. if (!isFree) {
  479. //升级前判断金币是否足够
  480. if (this.data.isUnlocked) {
  481. if (!TapTapTool.compare(GameModule.userInfo.gold, this.data.nextUpGold)) {
  482. return;
  483. }
  484. } else {
  485. if (!TapTapTool.compare(GameModule.userInfo.gold, this.data.unlockScore)) {
  486. return;
  487. }
  488. }
  489. }
  490. GameModule.audioMng.playUpdateBuilding();
  491. // 从配置文件里获取
  492. let maxLevel = GameGlobal.BuildingManager.getLevelCount(this.data.roomId);
  493. let nextLevel = this.data.level + 1;
  494. let level = nextLevel > maxLevel ? maxLevel : nextLevel;
  495. let buildModel = GameGlobal.BuildingManager.getBuildingInfo(this.data.roomId, level);
  496. buildModel.roomStars = this.data.roomStars;
  497. buildModel.roomMt = this.data.roomMt;
  498. buildModel.awardCount = this.data.awardCount;
  499. buildModel.isUnlocked = 1;
  500. if (this.resetCallback) {
  501. this.resetCallback(buildModel, this._itemId);
  502. }
  503. if (this.awardScript) {
  504. this.awardScript.roomLevel = level;
  505. }
  506. if (this.data.isUnlocked) {
  507. // 当前楼层已解锁
  508. if (!isFree) {
  509. GameModule.userInfo.gold = TapTapTool.sub(GameModule.userInfo.gold, this.data.nextUpGold);
  510. }
  511. GameModule.userInfo.updateRecordModify(buildModel);
  512. } else {
  513. // 当前楼层未解锁
  514. GameModule.userInfo.gold = TapTapTool.sub(GameModule.userInfo.gold, this.data.unlockScore);
  515. GameModule.userInfo.recordUnlockModify.push(buildModel);
  516. // 成功解锁后立刻调用上报,提交数据
  517. GameModule.userInfo.doReport();
  518. GameEvent.fire(GameNotificationKey.UnlockLevelHome,buildModel);
  519. }
  520. this.updateItem(buildModel);
  521. GameEvent.fire(GameNotificationKey.RefreshBuildingData, buildModel);
  522. },
  523. artistListLayout() {
  524. for (let child of this.humanList) {
  525. this.humanPool.put(child);
  526. }
  527. let self = this;
  528. let addHuman = function (artist, index) {
  529. let human = null;
  530. if (self.humanPool.size() > 0) {
  531. human = self.humanPool.get();
  532. } else {
  533. human = cc.instantiate(self.artistMan);
  534. self.humanList.push(human);
  535. }
  536. self.artistNode.addChild(human);
  537. let direction = (index > 0) ? 1 : -1;
  538. human.getComponent('ArtistMan').init(artist, direction);
  539. };
  540. if (this.data.isUnlocked && this.data.roomStars && this.data.roomStars.length > 0) {
  541. let direction = (Math.random() - 0.5) * 2;
  542. for(let i = 0; i < this.data.roomStars.length; ++i) {
  543. let starId = this.data.roomStars[i];
  544. let artist = new Object();
  545. artist.starId = starId;
  546. addHuman(artist, direction);
  547. direction = -direction;
  548. }
  549. }
  550. },
  551. configAward() {
  552. //每25级可以领取一次里程碑加成奖励
  553. let awardCount = this.data.awardCount;
  554. let totalCount = Math.floor(this.data.level / 25);
  555. if (awardCount < totalCount) {
  556. if (!this.isHasAward) {
  557. let awardNode = cc.instantiate(this.awardPrefab);
  558. this.awardScript = awardNode.getComponent('LevelHomeAward');
  559. this.awardWrap.addChild(awardNode);
  560. this.showProp();
  561. } else {
  562. if (parseInt(this.data.level) % 25 == 0) {
  563. this.showProp();
  564. }
  565. }
  566. } else {
  567. if (this.awardScript) {
  568. this.isHasAward = false;
  569. this.awardScript.node.position = cc.v2(150, -10);
  570. this.awardScript.node.active = false;
  571. this.awardScript.isPlay = false;
  572. this.awardScript.isPlaying = false;
  573. }
  574. }
  575. },
  576. hideAward() {
  577. this.isHasAward = false;
  578. this.awardScript.node.position = cc.v2(150, -10);
  579. this.awardScript.node.active = false;
  580. this.awardScript.isPlay = false;
  581. this.awardScript.isPlaying = false;
  582. this.configAward();
  583. },
  584. showProp(isPlayAnimation=true) {
  585. if (!this.isHasAward) {
  586. this.isHasAward = true;
  587. this.awardScript.init(this.data.roomId, this.data.level, (awardCount) => {
  588. // 显示领取动画
  589. this.data.awardCount = awardCount;
  590. this.hideAward();
  591. });
  592. if (isPlayAnimation) {
  593. this.awardScript.showAnimation();
  594. } else {
  595. this.awardScript.node.position = cc.v2(150, -10);
  596. this.awardScript.node.active = true;
  597. }
  598. } else {
  599. this.awardScript.updateAnimation();
  600. }
  601. },
  602. });