/** @format */ import FrameAnimation from '../../uiutils/FrameAnimation' import {IBulletConfig} from '../../config/BulletConfig' import {EventProcess} from './EventProcess' import {ANI_TYPE, BULLET_EFFECT_TYPE} from '../../enums/Enum' import {FrameAniConfig} from '../../config/FrameAniConfig' import GraphicsSpriteMesh from '../../uiutils/GraphicsSpriteMesh' import { EventAttack, EventBase, EventBulletEjection, EventHurtOrAdd, EventSkill, EventSlowDown, EventType, } from './NodeEvent' const {ccclass, property} = cc._decorator @ccclass export class BulletEventProcess extends EventProcess { bulletConfig: IBulletConfig graphicsSpriteMesh: GraphicsSpriteMesh = null isLight: boolean = false startPos: cc.Vec2 = null lightInvert: number = 0 public syncPos(x: number, y: number) { super.syncPos(x, y) this.lightInvert += 1 if (this.lightInvert % 6 == 0) this.strokeLight(x, y) } onAttach(): void { this.frameAnimation = this.getComponent(FrameAnimation) if (this.bulletConfig.ani) { if (FrameAniConfig[this.bulletConfig.ani]) { let aniConfig = FrameAniConfig[this.bulletConfig.ani] if (aniConfig.type == ANI_TYPE.frameAni) { this.playFrameAni(`bullet/${this.bulletConfig.ani}`, true) } else if (aniConfig.type == ANI_TYPE.action) { this.playAnimation(`bullet/${aniConfig.url}`) } } else { this.playFrameAni(`bullet/${this.bulletConfig.ani}`, true) } } else if (this.bulletConfig.url) { this.world.fightCore.setGameTex(`bullet/${this.bulletConfig.url}`, this.node) } this.node.scale = this.bulletConfig.Uiscale[0] / 100 } onDetach() { this.graphicsSpriteMesh?.clear() } processEvent(event: EventBase): void { if (!cc.isValid(this.node)) return switch (event.type) { case EventType.BulletEjection: let bulletEjectionEvent: EventBulletEjection = event as EventBulletEjection this.startLight(bulletEjectionEvent.posX, bulletEjectionEvent.posY) break } } initLight(x: number, y: number, bulletConfig: IBulletConfig) { this.isLight = bulletConfig.effectType.includes(BULLET_EFFECT_TYPE.line) if (!this.isLight) return this.graphicsSpriteMesh = cc .find('graphicsSpriteMesh', this.world.fightCore.node) .getComponent(GraphicsSpriteMesh) this.startLight(x, y) } startLight(x: number, y: number) { if (!this.isLight) return this.graphicsSpriteMesh.clear() this.graphicsSpriteMesh.graphics.moveTo(x, y) this.startPos = cc.v2(x, y) this.lightInvert = 0 } strokeLight(x: number, y: number) { if (!this.isLight) return this.startLight(this.startPos.x, this.startPos.y) this.graphicsSpriteMesh.graphics.lineTo(x, y) this.graphicsSpriteMesh.stroke() } }