LevelHomeItem.js 25 KB

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