LevelHomeItem.js 24 KB

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