FactorySystem.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /** 工厂数据类 */
  2. import { FactroyState } 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. for (var i = 0; i < len; i++) {
  37. if (this.factoryIcons[i].data.state == FactroyState.Producting) {
  38. this.factoryIcons[i].countDown.riped();
  39. }
  40. }
  41. }
  42. canSpeedUp() {
  43. let can = false;
  44. let len = this.factoryIcons.length;
  45. for (var i = 0; i < len; i++) {
  46. if (this.factoryIcons[i].data.state == FactroyState.Producting) {
  47. can = true;
  48. break;
  49. }
  50. }
  51. return can;
  52. }
  53. }