FactoryCountDown.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import Util from "../util/Util";
  2. const { ccclass, property } = cc._decorator;
  3. @ccclass
  4. export class FactoryCountDown extends cc.Component {
  5. @property({ tooltip: "配置ID" }) configID: number = 0;
  6. @property({ type: cc.Component.EventHandler, tooltip: "商品制作完成时的回调" }) onComplete: cc.Component.EventHandler = null;
  7. public progress: number = 0;
  8. public timerString: string = "";
  9. private config: any;
  10. async start() {
  11. this.config = gData.configData.configMap.get("product");
  12. }
  13. update() {
  14. let producting = gData.gameData.getProductingList(this.configID);
  15. let now = Date.now();
  16. if (producting.length > 0 && this.config) {
  17. let totleTime = this.config[producting[0].productID]["time"];
  18. if (producting[0].ripeDate > now) {
  19. this.progress = 1 - ((producting[0].ripeDate - now) / (totleTime * 1000));
  20. this.timerString = Util.formatCountDown(producting[0].ripeDate - now);
  21. } else {
  22. this.onComplete && this.onComplete.emit([producting[0].productID]);
  23. gData.gameData.getProductingList(this.configID).shift();
  24. }
  25. }
  26. }
  27. public async ripe() {
  28. let producting = gData.gameData.getProductingList(this.configID);
  29. this.onComplete && this.onComplete.emit([producting[0].productID]);
  30. let build = gData.configData.configMap.get("build");
  31. if (build[this.configID]["sequence"] == 1) {
  32. let lastTime = producting[0].ripeDate - Date.now();
  33. gData.gameData.getProductingList(this.configID).shift();
  34. for (let i = 0; i < gData.gameData.getProductingList(this.configID).length; i++) {
  35. gData.gameData.getProductingList(this.configID)[i].ripeDate -= lastTime;
  36. }
  37. } else {
  38. gData.gameData.getProductingList(this.configID).shift();
  39. }
  40. }
  41. }