FactorySystem.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /** 工厂数据类 */
  2. import { FactroyState, GameProp } from "../../game/data/GameData";
  3. import { FactoryIcon } from "./FactoryIcon";
  4. const { ccclass } = cc._decorator;
  5. @ccclass
  6. export default class FactorySystem {
  7. private _currSelectFactory: FactoryIcon = null;
  8. public factoryIcons: Array<FactoryIcon> = [];
  9. public set currSelectFactory(factory: FactoryIcon) {
  10. this._currSelectFactory = factory;
  11. }
  12. public get currSelectFactory(): FactoryIcon {
  13. return this._currSelectFactory;
  14. }
  15. public make(id: number): void {
  16. this._currSelectFactory && this._currSelectFactory.make(id);
  17. }
  18. public addFactory(factory) {
  19. this.factoryIcons.push(factory);
  20. }
  21. public nextFactory() {
  22. let len = this.factoryIcons.length;
  23. for (var i = 0; i < len; i++) {
  24. if (this.factoryIcons[i].data.state == FactroyState.Empty) {
  25. gData.gameData.nextCanProduct = gData.gameData.getRandomFactoryConfig(this.factoryIcons[i].configID);
  26. gData.gameData.nextMake = this.factoryIcons[i];
  27. return this.factoryIcons[i];
  28. }
  29. }
  30. }
  31. public btnMake() {
  32. gData.gameData.nextMake.make(gData.gameData.nextCanProduct.picture);
  33. }
  34. setHarvest() {
  35. let len = this.factoryIcons.length;
  36. let sendToServer = false;
  37. for (var i = 0; i < len; i++) {
  38. if (this.factoryIcons[i].data.state == FactroyState.Producting) {
  39. this.factoryIcons[i].countDown.riped(false);
  40. sendToServer = true;
  41. }
  42. }
  43. if (sendToServer) {
  44. gData.gameData.freshSendToServer(3);
  45. }
  46. }
  47. canSpeedUp() {
  48. let can = false;
  49. let len = this.factoryIcons.length;
  50. for (var i = 0; i < len; i++) {
  51. if (this.factoryIcons[i].data.state == FactroyState.Producting) {
  52. can = true;
  53. break;
  54. }
  55. }
  56. return can;
  57. }
  58. canHarvest() {
  59. let can = false;
  60. let len = this.factoryIcons.length;
  61. for (var i = 0; i < len; i++) {
  62. if (this.factoryIcons[i].data.state == FactroyState.Ripe) {
  63. this.factoryIcons[i].canHarvest();
  64. can = true;
  65. break;
  66. }
  67. }
  68. return can;
  69. }
  70. canClearSick() {
  71. let can = false;
  72. let len = this.factoryIcons.length;
  73. for (var i = 0; i < len; i++) {
  74. if (this.factoryIcons[i].data.state == FactroyState.Sick) {
  75. this.factoryIcons[i].canClearSick();
  76. can = true;
  77. break;
  78. }
  79. }
  80. return can;
  81. }
  82. }