|  |  |  | extends Node3D | 
					
						
							|  |  |  | class_name Effect | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @onready var afterimage: PackedScene = preload("res://scene/effect/afterimage/normal.tscn") | 
					
						
							|  |  |  | @onready var corpse: PackedScene = preload("res://scene/effect/afterimage/normal.tscn") | 
					
						
							|  |  |  | @onready var readiness_hero: PackedScene = preload("res://scene/effect/readiness/readiness_hero.tscn") | 
					
						
							|  |  |  | @onready var readiness_monster: PackedScene = preload("res://scene/effect/readiness/readiness_monster.tscn") | 
					
						
							|  |  |  | #@onready var readiness_bullet: PackedScene = preload("res://scene/effect/readiness/readiness_bullet.tscn") | 
					
						
							|  |  |  | #@onready var readiness_soul: PackedScene = preload("res://scene/effect/readiness/readiness_soul.tscn") | 
					
						
							|  |  |  | @onready var readiness_lock: PackedScene = preload("res://scene/effect/readiness/readiness_lock.tscn") | 
					
						
							|  |  |  | @onready var character: Character = (get_owner() as Character) | 
					
						
							|  |  |  | @onready var view: View = (%View as View) | 
					
						
							|  |  |  | @onready var status: Status = (%Status as Status) | 
					
						
							|  |  |  | @onready var lock: Node3D = ($Lock as Node3D) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var rediness: Decal | 
					
						
							|  |  |  | var is_pause: bool | 
					
						
							|  |  |  | var is_right: bool | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func particle_list() -> Array[Variant]: | 
					
						
							|  |  |  | 	var ret: Array[Variant] = [] | 
					
						
							|  |  |  | 	for child in get_children(): | 
					
						
							|  |  |  | 		if child is Particle: | 
					
						
							|  |  |  | 			ret.append(child) | 
					
						
							|  |  |  | 	return ret | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func init(type: Enum.ECharacterType): | 
					
						
							|  |  |  | 	match type: | 
					
						
							|  |  |  | 		Enum.ECharacterType.Player: rediness = readiness_hero.instantiate() | 
					
						
							|  |  |  | 		Enum.ECharacterType.Monster: rediness = readiness_monster.instantiate() | 
					
						
							|  |  |  | #		Enum.ECharacterType.Bullet: rediness = readiness_bullet.instantiate() | 
					
						
							|  |  |  | #		Enum.ECharacterType.Soul: rediness = readiness_soul.instantiate() | 
					
						
							|  |  |  | 		_: pass | 
					
						
							|  |  |  | 	if rediness: | 
					
						
							|  |  |  | 		add_child(rediness) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func set_body_scale(body_scale: Vector3): | 
					
						
							|  |  |  | 	if rediness: | 
					
						
							|  |  |  | 		rediness.scale = body_scale *2.2 | 
					
						
							|  |  |  | 		rediness.scale.y = 10 | 
					
						
							|  |  |  | 		rediness.position = Vector3.DOWN * 4 | 
					
						
							|  |  |  | 	lock.scale = body_scale *2.2 | 
					
						
							|  |  |  | 	lock.scale.y = 10 | 
					
						
							|  |  |  | 	lock.position = Vector3.DOWN * 4 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func set_effect_lock(is_lock: bool): | 
					
						
							|  |  |  | 	lock.visible = is_lock | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func _process(delta) -> void: | 
					
						
							|  |  |  | 	if not rediness: | 
					
						
							|  |  |  | 		return | 
					
						
							|  |  |  | 	#指针方向 | 
					
						
							|  |  |  | 	if status.move_dir: | 
					
						
							|  |  |  | 		var angle: float = status.move_dir.angle_to(Vector2.RIGHT) | 
					
						
							|  |  |  | 		rediness.rotation.y = angle | 
					
						
							|  |  |  | 	#flip | 
					
						
							|  |  |  | 	if is_right != status.is_right: | 
					
						
							|  |  |  | 		is_right = status.is_right | 
					
						
							|  |  |  | 		for particle: Particle in particle_list(): | 
					
						
							|  |  |  | 			particle.scale.x =  abs(particle.scale.x) * (1 if is_right else -1) | 
					
						
							|  |  |  | 	#pause | 
					
						
							|  |  |  | 	if is_pause != status.is_pause: | 
					
						
							|  |  |  | 		is_pause = status.is_pause | 
					
						
							|  |  |  | 		var ret: Array[Variant] = particle_list() | 
					
						
							|  |  |  | 		for particle: Particle in ret: | 
					
						
							|  |  |  | 			particle.set_pause(is_pause) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func cast_image(res: Resource, alpha: float): | 
					
						
							|  |  |  | 	var new_afterimage: Afterimage = afterimage.instantiate() as Afterimage | 
					
						
							|  |  |  | 	new_afterimage.position = character.view_pos() | 
					
						
							|  |  |  | 	new_afterimage.name = "afterimage" | 
					
						
							|  |  |  | 	new_afterimage.velocity = character.velocity / 4 | 
					
						
							|  |  |  | 	new_afterimage.target = view | 
					
						
							|  |  |  | 	new_afterimage.alpha = alpha | 
					
						
							|  |  |  | 	SignalManager.effect_create.emit(new_afterimage) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func cast_after_image(alpha: float): cast_image(afterimage, alpha) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func cast_corpse(): cast_image(corpse, 1) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func cast_particle(resource: Resource, is_attach: bool, offset: Vector3, scale: Vector3): _cast_particle(resource, is_attach, offset, scale) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func cast_attack_particle1(): _cast_attack_particle(1, true) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func cast_attack_particle1_release(): _cast_attack_particle(1, false) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func cast_attack_particle2(): _cast_attack_particle(2, true) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func cast_attack_particle2_release(): _cast_attack_particle(2, false) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func cast_attack_particle3(): _cast_attack_particle(3, true) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func cast_attack_particle3_release(): _cast_attack_particle(3, false) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func cast_self_particle() -> void: | 
					
						
							|  |  |  | 	if !status.cfg: | 
					
						
							|  |  |  | 		return | 
					
						
							|  |  |  | 	var particle: Resource = status.cfg.get_particle() | 
					
						
							|  |  |  | 	if !particle: | 
					
						
							|  |  |  | 		return | 
					
						
							|  |  |  | 	_cast_particle(particle, true, Vector3.ZERO, Vector3.ZERO) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func _cast_attack_particle(index: int, is_attach: bool) -> void: | 
					
						
							|  |  |  | 	if !status.skill_cfg: | 
					
						
							|  |  |  | 		return | 
					
						
							|  |  |  | 	var attack_particle: Resource = status.skill_cfg.get_attack_particle(index) | 
					
						
							|  |  |  | 	if !attack_particle: | 
					
						
							|  |  |  | 		print("未配置技能攻击特效:", status.skill_cfg.resource_path) | 
					
						
							|  |  |  | 		return | 
					
						
							|  |  |  | 	_cast_particle(attack_particle, is_attach, Vector3.ZERO, Vector3.ZERO) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func _cast_particle(resource: Resource, is_attach: bool, offset: Vector3, scale: Vector3) -> void: | 
					
						
							|  |  |  | 	if !resource: | 
					
						
							|  |  |  | 		print("未配置技能特效") | 
					
						
							|  |  |  | 		return | 
					
						
							|  |  |  | 	var new_particle: Particle = resource.instantiate() as Particle | 
					
						
							|  |  |  | 	new_particle.name = "particle" | 
					
						
							|  |  |  | 	if not new_particle.is_billboard: | 
					
						
							|  |  |  | 		var angle: float = Util.dir_angle(status.skill_dir) | 
					
						
							|  |  |  | 		new_particle.rotation.y = angle if is_right else -angle | 
					
						
							|  |  |  | 	if scale: | 
					
						
							|  |  |  | 		new_particle.scale = scale | 
					
						
							|  |  |  | 	new_particle.scale.x = abs(new_particle.scale.x) * (1 if is_right else -1) | 
					
						
							|  |  |  | 	if offset: | 
					
						
							|  |  |  | 		new_particle.position = offset | 
					
						
							|  |  |  | 	else: | 
					
						
							|  |  |  | 		if not new_particle.is_ground: | 
					
						
							|  |  |  | 			new_particle.position = status.basic_offset | 
					
						
							|  |  |  | 	add_child(new_particle) | 
					
						
							|  |  |  | 	if !is_attach: | 
					
						
							|  |  |  | 		_release_effect(new_particle) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func release_effect(): | 
					
						
							|  |  |  | 	for particle: Particle in particle_list(): | 
					
						
							|  |  |  | 		_release_effect(particle) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func _release_effect(particle: Particle): | 
					
						
							|  |  |  | 	var pos: Vector3 = particle.get_global_position() | 
					
						
							|  |  |  | 	particle.set_pause(false) | 
					
						
							|  |  |  | 	particle.position = pos | 
					
						
							|  |  |  | 	remove_child(particle) | 
					
						
							|  |  |  | 	SignalManager.effect_create.emit(particle) |