BulletEventProcess.ts 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /** @format */
  2. import FrameAnimation from '../../uiutils/FrameAnimation'
  3. import {IBulletConfig} from '../../config/BulletConfig'
  4. import {EventProcess} from './EventProcess'
  5. import {ANI_TYPE, BULLET_EFFECT_TYPE} from '../../enums/Enum'
  6. import {FrameAniConfig} from '../../config/FrameAniConfig'
  7. import GraphicsSpriteMesh from '../../uiutils/GraphicsSpriteMesh'
  8. import {
  9. EventAttack,
  10. EventBase,
  11. EventBulletEjection,
  12. EventHurtOrAdd,
  13. EventSkill,
  14. EventSlowDown,
  15. EventType,
  16. } from './NodeEvent'
  17. const {ccclass, property} = cc._decorator
  18. @ccclass
  19. export class BulletEventProcess extends EventProcess {
  20. bulletConfig: IBulletConfig
  21. graphicsSpriteMesh: GraphicsSpriteMesh = null
  22. isLight: boolean = false
  23. startPos: cc.Vec2 = null
  24. lightInvert: number = 0
  25. public syncPos(x: number, y: number) {
  26. super.syncPos(x, y)
  27. this.lightInvert += 1
  28. if (this.lightInvert % 6 == 0) this.strokeLight(x, y)
  29. }
  30. onAttach(): void {
  31. this.frameAnimation = this.getComponent(FrameAnimation)
  32. if (this.bulletConfig.ani) {
  33. if (FrameAniConfig[this.bulletConfig.ani]) {
  34. let aniConfig = FrameAniConfig[this.bulletConfig.ani]
  35. if (aniConfig.type == ANI_TYPE.frameAni) {
  36. this.playFrameAni(`bullet/${this.bulletConfig.ani}`, true)
  37. } else if (aniConfig.type == ANI_TYPE.action) {
  38. this.playAnimation(`bullet/${aniConfig.url}`)
  39. }
  40. } else {
  41. this.playFrameAni(`bullet/${this.bulletConfig.ani}`, true)
  42. }
  43. } else if (this.bulletConfig.url) {
  44. this.world.fightCore.setGameTex(`bullet/${this.bulletConfig.url}`, this.node)
  45. }
  46. this.node.scale = this.bulletConfig.Uiscale[0] / 100
  47. }
  48. onDetach() {
  49. this.graphicsSpriteMesh?.clear()
  50. }
  51. processEvent(event: EventBase): void {
  52. if (!cc.isValid(this.node)) return
  53. switch (event.type) {
  54. case EventType.BulletEjection:
  55. let bulletEjectionEvent: EventBulletEjection = event as EventBulletEjection
  56. this.startLight(bulletEjectionEvent.posX, bulletEjectionEvent.posY)
  57. break
  58. }
  59. }
  60. initLight(x: number, y: number, bulletConfig: IBulletConfig) {
  61. this.isLight = bulletConfig.effectType.includes(BULLET_EFFECT_TYPE.line)
  62. if (!this.isLight) return
  63. this.graphicsSpriteMesh = cc
  64. .find('graphicsSpriteMesh', this.world.fightCore.node)
  65. .getComponent(GraphicsSpriteMesh)
  66. this.startLight(x, y)
  67. }
  68. startLight(x: number, y: number) {
  69. if (!this.isLight) return
  70. this.graphicsSpriteMesh.clear()
  71. this.graphicsSpriteMesh.graphics.moveTo(x, y)
  72. this.startPos = cc.v2(x, y)
  73. this.lightInvert = 0
  74. }
  75. strokeLight(x: number, y: number) {
  76. if (!this.isLight) return
  77. this.startLight(this.startPos.x, this.startPos.y)
  78. this.graphicsSpriteMesh.graphics.lineTo(x, y)
  79. this.graphicsSpriteMesh.stroke()
  80. }
  81. }