LevelHomeItem.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778
  1. const DWTool = require('../utils/DWTool');
  2. const { RoomState, GameNotificationKey, LevelHomeArtistItemStyle } = require("../utils/GameEnum");
  3. const GameModule = require("../utils/GameModule");
  4. const ThemeManager = require("../utils/ThemeManger");
  5. const HomeApi = require("../net/HomeApi");
  6. // const StateMachine = require('../lib/StateMachine');
  7. // const StateMachineHistory = require('../lib/StateMachineHistory');
  8. cc.Class({
  9. extends: cc.Component,
  10. properties: {
  11. // Public Properties
  12. /** 当前显示的图片 */
  13. buildSprite: cc.Sprite,
  14. // 两边的柱子
  15. pillars: [cc.Sprite],
  16. bottomBg: cc.Sprite,
  17. lockBottomBg: cc.Sprite,
  18. /** 升级按钮的两种状态图 */
  19. updateBtnFrames: [cc.SpriteFrame],
  20. /** 未解锁, 解锁的图片 */
  21. lockSpriteFrames: [cc.SpriteFrame],
  22. /** 未解锁状态的节点 */
  23. lockNode: cc.Node,
  24. /** 需要花费所有金币 */
  25. costLabel: cc.Label,
  26. /** 未解锁需要花费多少金币 */
  27. unlockLabel: cc.Label,
  28. /** 建筑昵称 */
  29. buildNameLabel: cc.Label,
  30. /** 这里当做升级建筑按钮 */
  31. updateBtn: cc.Sprite,
  32. /** 更新按钮的背景, 用来做呼吸灯效果 */
  33. // updateBtnBg: cc.Sprite,
  34. /** 解锁按钮 */
  35. lockBtn: cc.Sprite,
  36. /** 解锁按钮背景图 */
  37. lockSprite: cc.Sprite,
  38. lockBottomNode: cc.Node,
  39. /** 等级节点 */
  40. levelProgressNode: cc.Node,
  41. /** 等级进度条 */
  42. levelProgressBar: cc.ProgressBar,
  43. /** 等级 */
  44. levelProgressLabel: cc.RichText,
  45. /** 生产金币节点 */
  46. rateProgressNode: cc.Node,
  47. /** 生产金币进度条 */
  48. rateProgressBar: cc.ProgressBar,
  49. /** 生产了多少金币 */
  50. rateProgressLabel: cc.Label,
  51. /** 倒计时 */
  52. countdownLabel: cc.Label,
  53. /** 金币满了提示 */
  54. coinFullTip: cc.Node,
  55. artistList: cc.Node,
  56. artistListItem: cc.Prefab,
  57. openDoorSkeletion: sp.Skeleton,
  58. updateSkeletion: sp.Skeleton,
  59. // 显示加成的节点
  60. additionNode: cc.Node,
  61. // 显示加成倍数
  62. additionLabel: cc.Label,
  63. // 满级提示
  64. maxNode: cc.Node,
  65. addition: {
  66. get: function () {
  67. if (!this._addition) {
  68. this._addition = 0;
  69. }
  70. return this._addition;
  71. },
  72. set: function (value) {
  73. this._addition = value;
  74. if (this._addition === 0) {
  75. this.additionNode.active = false;
  76. } else {
  77. this.additionNode.active = true;
  78. this.additionLabel.string = `X${this._addition}`;
  79. }
  80. }
  81. },
  82. coinArrayMax: {
  83. default: 3,
  84. type: cc.Integer,
  85. tooltip: "当前楼层最大存储金币数"
  86. },
  87. coinWrap: cc.Node,
  88. coinPrefab: cc.Prefab,
  89. countDown: {
  90. get: function () {
  91. if (!this._countDown) {
  92. this._countDown = 0;
  93. }
  94. return this._countDown;
  95. },
  96. set: function (value) {
  97. this._countDown = value;
  98. this.countdownLabel.string = DWTool.calculateTime(this._countDown);
  99. this._preCountDown = this._countDown;
  100. }
  101. },
  102. rate: {
  103. get: function () {
  104. if (!this._rate) {
  105. this._rate = 0;
  106. }
  107. return this._rate;
  108. },
  109. set: function (value) {
  110. this._rate = value;
  111. if (this.addition > 0) {
  112. this._rate = this._rate * this.addition;
  113. }
  114. this.rateProgressLabel.string = DWTool.coinParse(this._rate);
  115. }
  116. },
  117. notPickupCount: {
  118. get: function () {
  119. if (!this._notPickupCount) {
  120. this._notPickupCount = 0;
  121. }
  122. return this._notPickupCount;
  123. },
  124. set: function (value) {
  125. this._notPickupCount = value;
  126. this.buildingInfo.coinCount = value;
  127. this.isNeedToReport = true;
  128. }
  129. },
  130. },
  131. // LIFE-CYCLE CALLBACKS:
  132. onLoad() {
  133. this.isNeedToReport = false;
  134. this.coinArray = [];
  135. this._currentTime = 0;
  136. this.isFirstLoad = true;
  137. this.humanList = [];
  138. this.updateSkeletion.node.active = false;
  139. // 监听自定义事件
  140. this.setEventListener();
  141. // 解锁建筑事件
  142. this.lockBtn.node.on(cc.Node.EventType.TOUCH_END, () => {
  143. // 如果当前不够钱, 点击不生效
  144. if (GameModule.userInfo.grossIncome < this.buildingInfo.unlockScore) { return; }
  145. // 点完立刻隐藏
  146. this.lockBtn.node.active = false;
  147. this.openDoorSkeletion.setAnimation(0, "changjing_kaiqi2");
  148. this.lockBottomNode.runAction(cc.fadeOut(0.1));
  149. this.openDoorSkeletion.setCompleteListener(() => {
  150. // 升级建筑
  151. this.updateBuilding();
  152. GameEvent.fire(GameNotificationKey.PlaySuccessAnimation);
  153. });
  154. }, this);
  155. // 升级建筑事件
  156. this.updateBtn.node.on(cc.Node.EventType.TOUCH_END, () => {
  157. if (this.state === RoomState.Update) {
  158. // 清空当前用来存储金币节点
  159. this.currentCoin = null;
  160. for (let i = 0; i < this.coinArrayMax; i++) {
  161. this.pickupCoin(this.coinArray[i], i);
  162. }
  163. this.updateBuilding();
  164. if (!this.updateSkeletion.node.active) {
  165. this.updateSkeletion.node.active = true;
  166. this.updateSkeletion.setAnimation(0, "changjing_sj");
  167. this.updateSkeletion.setCompleteListener(() => {
  168. this.updateSkeletion.node.active = false;
  169. });
  170. }
  171. }
  172. }, this);
  173. this.schedule(() => {
  174. if (this.isNeedToReport) {
  175. this.isNeedToReport = false;
  176. GameModule.userInfo.updateRecordModify(this.buildingInfo);
  177. }
  178. }, 2.0);
  179. // 配置界面上的金币
  180. this.configCoins();
  181. },
  182. onDestroy() {
  183. GameEvent.off(GameNotificationKey.ResidentArtist, this);
  184. GameEvent.off(GameNotificationKey.RefreshLevelHomeArtistList, this);
  185. GameEvent.off(GameNotificationKey.LevelHomeItemBuildingAllFull, this);
  186. },
  187. setEventListener() {
  188. // 这个是入驻艺人成功时调用的
  189. GameEvent.on(GameNotificationKey.ResidentArtist, this, (uid, buildingId) => {
  190. if (this.node.active && this.uid === uid && this.buildingInfo.buildingId === buildingId) {
  191. HomeApi.friendGetArtistsInBuilding(this.uid, this.buildingInfo.buildingId, (data) => {
  192. // 为了不让当前的金币出现多种不同金额的币种, 当列表刷新时, 要收取一次
  193. if (this.state === RoomState.Update || this.state === RoomState.Full) {
  194. // 清空当前用来存储金币节点
  195. this.currentCoin = null;
  196. for (let i = 0; i < this.coinArrayMax; i++) {
  197. this.pickupCoin(this.coinArray[i], i, false);
  198. }
  199. }
  200. this.artists = data.list || [];
  201. this.artistListLayout();
  202. }, (code, msg) => {
  203. console.log(msg);
  204. })
  205. }
  206. });
  207. // 这个是召回驱赶艺人时调用的
  208. GameEvent.on(GameNotificationKey.RefreshLevelHomeArtistList, this, (uid, buildingId) => {
  209. if (this.node.active && this.uid === uid && this.buildingInfo.buildingId === buildingId) {
  210. HomeApi.friendGetArtistsInBuilding(this.uid, this.buildingInfo.buildingId, (data) => {
  211. this.artists = data.list || [];
  212. this.artistListLayout();
  213. }, (code, msg) => {
  214. console.log(msg);
  215. })
  216. }
  217. });
  218. // 所有建筑满级之后调用
  219. GameEvent.on(GameNotificationKey.LevelHomeItemBuildingAllFull, this, () => {
  220. if (this.isFirstLoad) { // 代表游戏一打开, 就是满级的
  221. this.currentCoin = null;
  222. this.coinWrap.active = false;
  223. this.artistList.active = false;
  224. this.coinFullTip.active = false;
  225. } else {
  226. GameModule.userInfo.updateRecordModify(this.buildingInfo);
  227. this.currentCoin = null;
  228. for (let i = 0; i < this.coinArrayMax; i++) {
  229. this.pickupCoin(this.coinArray[i], i);
  230. }
  231. this.coinWrap.active = false;
  232. this.artistList.active = false;
  233. this.coinFullTip.active = false;
  234. }
  235. })
  236. },
  237. configCoins() {
  238. for (let i = 0; i < this.coinArrayMax; i++) {
  239. // 初始化
  240. let coinNode = cc.instantiate(this.coinPrefab)
  241. this.coinWrap.addChild(coinNode);
  242. coinNode = coinNode.getComponent("LevelHomeCoin");
  243. this.coinHide(coinNode, i)
  244. this.coinArray[i] = coinNode;
  245. coinNode.node.on(cc.Node.EventType.TOUCH_END, (event) => {
  246. this.pickupCoin(coinNode, i);
  247. }, this);
  248. }
  249. },
  250. /**
  251. * Public Method, 用来设置建筑背景图
  252. * @param {*} index
  253. */
  254. init(cityId, index) {
  255. if (arguments.length < 1) {
  256. throw new Error("init Missing parameter...");
  257. }
  258. this.cityId = cityId;
  259. this.index = index;
  260. this.isFirstLoad = true;
  261. ThemeManager.setItemBuildSpriteFrame(this.cityId, this.buildSprite, index);
  262. ThemeManager.setItemPillarSpriteFrame(this.cityId, this.pillars);
  263. ThemeManager.setItemDownSpriteFrame(this.cityId, this.bottomBg);
  264. ThemeManager.setItemLockDownSpriteFrame(this.cityId, this.lockBottomBg);
  265. },
  266. /**
  267. * Public Method, 配置建筑的内部样式
  268. * @param {*} buildingInfo 建筑信息
  269. * @param {*} uid 当前用户的uid
  270. */
  271. config(buildingInfo, uid) {
  272. if (arguments.length < 2) {
  273. throw new Error("Config Missing parameter...");
  274. }
  275. this.buildingInfo = buildingInfo;
  276. this.uid = uid;
  277. this.artists = this.buildingInfo.artists;
  278. // 这里设置一些只需要设置一次的数据
  279. this.countDown = buildingInfo.rateUnit;
  280. this.buildNameLabel.string = buildingInfo.name;
  281. this._notPickupCount = buildingInfo.coinCount;
  282. if (buildingInfo.coinCount === this.coinArrayMax * 10) {
  283. this.rateProgressBar.progress = 1;
  284. this.countdownLabel.string = DWTool.calculateTime(0);
  285. }
  286. this.levelProgressBar.progress = buildingInfo.level / Global.BuildingManager.getLevelCount(buildingInfo.buildingId);
  287. this.levelProgressLabel.string = `<outline color=#ffffff width=2><b><color= #0e689c>LV.${buildingInfo.level}</c></b></outline>`
  288. if (this.isFirstLoad) {
  289. this.isFirstLoad = false;
  290. this.artistListLayout();
  291. }
  292. //城市开发完毕的时候不显示艺人入驻按钮
  293. if (GameModule.userInfo.levelHomeItemFullCount != 5 && this.cityId === Global.cityId) {
  294. this.artistList.active = true;
  295. } else {
  296. this.artistList.active = false;
  297. }
  298. this.initializeCoinPosition();
  299. this.layout(buildingInfo);
  300. },
  301. /** 初始化金币的位置 */
  302. initializeCoinPosition() {
  303. // 2018年08月18日15:25, 子奇要求我去好友家园时, 不显示未收取金币
  304. // 城市已经开发完毕不显示金币
  305. if (this.cityId === Global.cityId && GameModule.userInfo.levelHomeItemFullCount != 5) {
  306. this.coinWrap.active = true;
  307. } else {
  308. this.coinWrap.active = false;
  309. return;
  310. }
  311. if (!this.buildingInfo.coinCount) {
  312. for (let i = 0; i < this.coinArrayMax; i++) {
  313. let coin = this.coinArray[i];
  314. this.coinHide(coin, i);
  315. }
  316. return;
  317. }
  318. for (let i = 0; i < this.coinArrayMax; i++) {
  319. let coin = this.coinArray[i];
  320. while (this.buildingInfo.coinCount != 0 && coin.coinCount != 10) {
  321. coin.coinCount += 1;
  322. this.buildingInfo.coinCount -= 1;
  323. }
  324. if (coin.coinCount != 0) {
  325. let x = -140 + (85 * i);
  326. coin.isPlay = true;
  327. coin.node.position = cc.v2(x, -28);
  328. coin.node.active = true;
  329. if (this.addition > 0) {
  330. let rate = this.buildingInfo.rate * this.addition;
  331. coin.totalRate = rate * coin.coinCount;
  332. } else {
  333. coin.totalRate = this.buildingInfo.rate * coin.coinCount;
  334. }
  335. coin.initStatic(i);
  336. }
  337. }
  338. },
  339. artistListLayout() {
  340. for (let child of this.artistList.children) { child.destroy(); }
  341. for (let child of this.humanList) { child.destroy(); }
  342. let self = this;
  343. let addAddItemToList = function () {
  344. let addArtistItem = cc.instantiate(self.artistListItem);
  345. self.artistList.addChild(addArtistItem);
  346. let addArtistScript = addArtistItem.getComponent('LevelHomeArtistItem');
  347. addArtistScript.initWithBuildingInfo(self.buildingInfo, self.uid, true);
  348. }
  349. let addArtistItemToList = function (artist) {
  350. let artistItem = cc.instantiate(self.artistListItem);
  351. self.artistList.addChild(artistItem);
  352. let artistScript = artistItem.getComponent('LevelHomeArtistItem');
  353. artistScript.initWithArtistData(self.buildingInfo, self.uid, true, artist);
  354. }
  355. let addHuman = function (artist, index) {
  356. DWTool.loadResPrefab("./prefabs/artist_man")
  357. .then((prefab) => {
  358. let human = cc.instantiate(prefab);
  359. human.getComponent('ArtistMan').init(artist);
  360. human.getComponent('ArtistMan').direction = (index > 0) ? 1 : -1;
  361. self.node.addChild(human);
  362. self.humanList.push(human);
  363. });
  364. }
  365. // 当没有自己艺人, 也没有好友艺人入驻时, 这里还得区分主态和客态
  366. if (this.artists.length === 0) {
  367. addAddItemToList();
  368. // 没有艺人不显示倍数
  369. this.addition = 0;
  370. } else {
  371. // 有艺人入驻要显示倍数
  372. this.additionNode.active = true;
  373. if (this.artists.length === 1) {
  374. let artist = this.artists[0];
  375. console.log(JSON.stringify(artist));
  376. this.addition += artist.stationJobLevel + 1;
  377. // 这里要区分主态和客态, 去别人家园时, 如果有一个是客态自己的艺人, 那么另一个就是可以入驻的按钮
  378. if (artist.role === 2) {
  379. addArtistItemToList(artist);
  380. addHuman(artist, (Math.random() - 0.5) * 2);
  381. } else {
  382. addAddItemToList();
  383. addArtistItemToList(artist);
  384. addHuman(artist, (Math.random() - 0.5) * 2);
  385. }
  386. } else {
  387. for (let i = 0; i < this.artists.length; i++) {
  388. let artist = this.artists[i];
  389. this.addition += artist.stationJobLevel + 1;
  390. addArtistItemToList(artist);
  391. addHuman(artist, i);
  392. }
  393. }
  394. }
  395. },
  396. layout(buildingInfo) {
  397. // 判断是否有下一级, 没有的话就是满级
  398. if (buildingInfo.hasNext === 1 && buildingInfo.level <= Global.BuildingManager.getLevelCount(buildingInfo.buildingId)) {
  399. // 判断是否已经解锁
  400. if (buildingInfo.isUnlocked) {
  401. this.lockNode.active = false;
  402. this.costLabel.string = DWTool.coinParse(buildingInfo.nextUpScore);
  403. this.rate = buildingInfo.rate;
  404. // 判断是否有足够的金额解锁
  405. if (GameModule.userInfo.grossIncome >= buildingInfo.nextUpScore) {
  406. this.setState(RoomState.Update);
  407. } else {
  408. this.setState(RoomState.Lock);
  409. }
  410. } else {
  411. this.countDown = 0;
  412. this.rateProgressBar.progress = 0;
  413. this.totalRate = 0;
  414. this.lockNode.active = true;
  415. this.costLabel.string = 0;
  416. this.unlockLabel.string = DWTool.coinParse(buildingInfo.unlockScore);
  417. // 判断是否有足够的金额解锁
  418. if (GameModule.userInfo.grossIncome >= buildingInfo.unlockScore) {
  419. this.lockSprite.spriteFrame = this.lockSpriteFrames[1];
  420. this.lockBtn.spriteFrame = this.updateBtnFrames[1];
  421. this.lockBtn.node.getComponent(cc.Button).interactable = true;
  422. } else {
  423. this.lockSprite.spriteFrame = this.lockSpriteFrames[0];
  424. this.lockBtn.spriteFrame = this.updateBtnFrames[0];
  425. this.lockBtn.node.getComponent(cc.Button).interactable = false;
  426. }
  427. this.setState(RoomState.Lock);
  428. }
  429. } else {
  430. this.rate = buildingInfo.rate;
  431. this.setState(RoomState.Full);
  432. }
  433. },
  434. setState(state) {
  435. if (this.state === state) { return;}
  436. switch (state) {
  437. case RoomState.Lock:
  438. this.updateBtn.node.active = true;
  439. this.updateBtn.spriteFrame = this.updateBtnFrames[0];
  440. this.updateBtn.node.getComponent(cc.Button).interactable = false;
  441. this.maxNode.active = false;
  442. break;
  443. case RoomState.Update:
  444. this.updateBtn.node.active = true;
  445. this.lockNode.active = false;
  446. this.updateBtn.spriteFrame = this.updateBtnFrames[1];
  447. this.updateBtn.node.getComponent(cc.Button).interactable = true;
  448. this.maxNode.active = false;
  449. break;
  450. case RoomState.Full:
  451. this.lockNode.active = false;
  452. this.maxNode.active = true;
  453. this.updateBtn.node.active = false;
  454. default:
  455. break;
  456. }
  457. this.state = state;
  458. },
  459. // 升级建筑
  460. updateBuilding() {
  461. // 从配置文件里获取
  462. let buildModel = Global.BuildingManager.getBuildingInfo(this.cityId, this.buildingInfo.buildingId, this.buildingInfo.level + 1);
  463. // 将已有入驻的艺人赋值给新的model, 保持一个引用
  464. buildModel.artists = this.buildingInfo.artists;
  465. if (this.buildingInfo.isUnlocked) {
  466. GameModule.userInfo.grossIncome -= this.buildingInfo.nextUpScore;
  467. GameModule.userInfo.updateRecordModify(buildModel);
  468. } else {
  469. GameModule.userInfo.grossIncome -= this.buildingInfo.unlockScore;
  470. GameModule.userInfo.recordUnlockModify.push(buildModel);
  471. }
  472. GameModule.userInfo.stars += 1;
  473. this.config(buildModel, this.uid);
  474. // 如果满级了, 就发通知告诉userinfo
  475. if (buildModel.hasNext != 1) {
  476. GameEvent.fire(GameNotificationKey.LevelHomeItemBuildingFull);
  477. }
  478. },
  479. // 收取金币
  480. pickupCoin(coin, i, isShowAnimation = true) {
  481. if (this.currentCoin === coin) {
  482. this.currentCoin = null;
  483. }
  484. if (isShowAnimation) {
  485. let pos = coin.node.convertToWorldSpace(cc.v2(coin.node.width / 2, coin.node.height / 2));
  486. this.showCollectAnim(pos, coin.coinCount)
  487. }
  488. // 点击一次金币, 就将notPickupCount减去coinNode.coinCount
  489. this.notPickupCount -= coin.coinCount;
  490. // console.log(`收入: ${buildingInfo.rate * coin.coinCount}`);
  491. GameModule.userInfo.grossIncome += (this.buildingInfo.rate * coin.coinCount);
  492. this.coinHide(coin, i);
  493. },
  494. showCollectAnim(pos, colNums) {
  495. let canvasNode = cc.find("Canvas");
  496. let grossCoin = GameModule.userInfo.grossCoin;
  497. let grossCoinPos = grossCoin.node.convertToWorldSpace(cc.v2(grossCoin.node.width / 2, grossCoin.node.height / 2));
  498. // let colNums = 5
  499. let vSize = cc.view.getVisibleSize();
  500. let target = cc.v2(grossCoinPos.x - vSize.width / 2, grossCoinPos.y - vSize.height / 2)
  501. let i = 0;
  502. let runSt = setInterval(() => {
  503. if (i == colNums) {
  504. clearInterval(runSt)
  505. } else {
  506. let ran = (Math.random() - 0.5) * 2 * 3;
  507. let newCoin = cc.instantiate(this.coinPrefab);
  508. let posX = pos.x - vSize.width / 2;
  509. let posY = pos.y - vSize.height / 2;
  510. canvasNode.addChild(newCoin)
  511. newCoin.x = posX + ran * 15;
  512. newCoin.y = posY + 30 + ran * 15;
  513. newCoin.active = true;
  514. newCoin = newCoin.getComponent("LevelHomeCoin")
  515. newCoin.initAnim()
  516. let cbNotiStart = cc.callFunc(() => {
  517. GameEvent.fire(GameNotificationKey.UserCollectCoin, true);
  518. })
  519. let cbDestroy = cc.callFunc(() => {
  520. newCoin.node.destroy();
  521. })
  522. let act = cc.sequence(cc.moveTo(1, target), cbDestroy, cbNotiStart)
  523. newCoin.node.runAction(act.easing(cc.easeIn(2.1)));
  524. i++
  525. }
  526. }, 100);
  527. },
  528. coinHide(coin, i) {
  529. // 算出金币的x值, 70是金币宽度, -130是第一个金币的x值
  530. let x = -140 + (85 * i);
  531. // 重置金币状态
  532. coin.node.position = cc.v2(x, -108);
  533. coin.node.active = false;
  534. coin.isPlay = false;
  535. coin.isPlaying = false;
  536. coin.coinCount = 0;
  537. coin.totalRate = 0;
  538. },
  539. getFreeCoin() {
  540. for (let i = 0; i < this.coinArrayMax; i++) {
  541. let coinNode = this.coinArray[i];
  542. if (coinNode.coinCount != 10) {
  543. return coinNode;
  544. }
  545. }
  546. return null;
  547. },
  548. generateCoin() {
  549. if (this.currentCoin && this.currentCoin.coinCount < 10) {
  550. this.currentCoin.totalRate += this.rate;
  551. this.currentCoin.coinCount += 1;
  552. this.currentCoin.updateAnimation();
  553. } else {
  554. this.currentCoin = this.getFreeCoin();
  555. if (this.currentCoin) {
  556. this.currentCoin.totalRate += this.rate;
  557. this.currentCoin.coinCount += 1;
  558. if (!this.currentCoin.isPlay) {
  559. this.currentCoin.showAnimation();
  560. } else {
  561. this.currentCoin.updateAnimation();
  562. }
  563. }
  564. }
  565. },
  566. update(dt) {
  567. if (this.buildingInfo) {
  568. // 不断刷新界面
  569. this.layout(this.buildingInfo);
  570. // 只有已经解锁进度条才会走
  571. if (this.buildingInfo.isUnlocked) {
  572. // 进度条走完, 开始生产金币
  573. if (Math.floor(this.rateProgressBar.progress) === 1) {
  574. if (GameModule.userInfo.levelHomeItemFullCount != 5 && // 是否满级
  575. this.cityId === Global.cityId) { // 当前访问的是不是这个city
  576. if (this.notPickupCount >= this.coinArrayMax * 10) {
  577. this.coinFullTip.active = true;
  578. } else {
  579. this.coinFullTip.active = false;
  580. this.notPickupCount += 1;
  581. this.generateCoin();
  582. this.rateProgressBar.progress = 0;
  583. this._currentTime = 0;
  584. }
  585. } else { // 满级后的状态
  586. this.rateProgressBar.progress = 0;
  587. this._currentTime = 0;
  588. this.coinFullTip.active = false;
  589. }
  590. } else {
  591. this._currentTime += dt;
  592. this.rateProgressBar.progress = this._currentTime / this.countDown;
  593. let resultCountDown = this.countDown - Math.floor(this._currentTime);
  594. if (this._preCountDown !== resultCountDown) {
  595. this.countdownLabel.string = DWTool.calculateTime(resultCountDown);
  596. this._preCountDown = resultCountDown;
  597. }
  598. }
  599. }
  600. }
  601. },
  602. });