bulletPlay.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { EConfigConst } from "../cfg/ConfigDef";
  2. import { BulletItem } from "../cfg/bulletItem";
  3. import { ConfigMgr } from "../cfg/configMgr";
  4. import { Utils } from "../common/utils";
  5. import { Barrage } from "../nest/barrage";
  6. import { GameLogic } from "../update/GameLogic";
  7. import { GameSysLogic } from "../update/gameSysLogic";
  8. enum EBulletPlayState{
  9. none,
  10. start,
  11. done,
  12. }
  13. export class BulletPlay extends GameLogic{
  14. private _bulletId: string;
  15. private _delay: number;
  16. private _state = EBulletPlayState.none;
  17. private _cd: number;
  18. private _nextTime: number;
  19. monsterZooid: number;
  20. init(bulletId: string, delay: number){
  21. this._bulletId = bulletId;
  22. this._delay = delay;
  23. let bulletData = ConfigMgr.inst.getCfgClassById(EConfigConst.bullet, bulletId, BulletItem);
  24. this._cd = bulletData.data.cd;
  25. this._nextTime = Date.now();
  26. }
  27. start(){
  28. this._state = EBulletPlayState.start;
  29. }
  30. protected gameUpdate(dt: any): void {
  31. if(this._state != EBulletPlayState.start) return;
  32. this._delay -= dt;
  33. if(this._delay > 0) return;
  34. let now = Date.now();
  35. if(now > this._nextTime){
  36. this._nextTime = now + this._cd * 1000;
  37. // 攻击
  38. Barrage.inst.createMonsterBulletByZooid(this.monsterZooid, this._bulletId);
  39. }
  40. }
  41. }