nestCondition.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { LevelMgr } from "../../levelMgr";
  2. import { Utils } from "../common/utils";
  3. import { GameSysLogic } from "../update/gameSysLogic";
  4. enum ENestConditionState {
  5. none,
  6. start,
  7. done,
  8. }
  9. export class NestCondition extends GameSysLogic {
  10. time: number = 0;
  11. num: number;
  12. call: Function = null;
  13. state: ENestConditionState = ENestConditionState.none;
  14. name: string;
  15. _str:string;
  16. fill(str: string = '[4;5]'){
  17. str = Utils.strReplaceSeparator(str);
  18. let obj = JSON.parse(str);
  19. // console.log(obj);
  20. this.time = obj[0];
  21. this.num = obj[1];
  22. this._str = str;
  23. console.log(this.name,`[${this._str}]`,'create');
  24. }
  25. start(){
  26. this.state = ENestConditionState.start;
  27. console.log(this.name,`[${this._str}]`,'start');
  28. }
  29. isDone(){
  30. return this.state == ENestConditionState.done;
  31. }
  32. gameUpdate(dt){
  33. if(this.state != ENestConditionState.start) return;
  34. this.time -= dt;
  35. if(this.time <= 0 && LevelMgr.inst.getMonsterCnt() <= this.num) {
  36. console.log(this.name,`[${this._str}]`,'done');
  37. this.state = ENestConditionState.done;
  38. this.call && this.call();
  39. }
  40. }
  41. }