43 lines
1.3 KiB
GDScript
43 lines
1.3 KiB
GDScript
extends State
|
|
|
|
var hit = false
|
|
var players_in_area = {}
|
|
|
|
func enter() -> void:
|
|
super()
|
|
if has_node("%AttackHitbox"): %AttackHitbox.visible = true
|
|
if has_node("%AttackTimer"): %AttackTimer.start()
|
|
if has_node("%AttackCooldown"): %AttackCooldown.start()
|
|
hit = false
|
|
|
|
func exit() -> void:
|
|
super()
|
|
if has_node("%AttackHitbox"): %AttackHitbox.visible = false
|
|
|
|
func process_physics(delta: float) -> State:
|
|
if not Main.is_server_or_predicting(subject.player_id, subject.client_prediction): return
|
|
var input_direction = %Input.direction if subject.is_on_floor() else Vector2.ZERO
|
|
|
|
subject.apply_input_velocity(delta, input_direction, subject.run_speed, subject.acceleration if subject.is_on_floor() else subject.air_deceleration)
|
|
|
|
if players_in_area.size() > 0:
|
|
var hit_player = players_in_area[players_in_area.keys()[0]]
|
|
hit_player.dead = true
|
|
hit = true
|
|
|
|
if has_node("%AttackTimer") and %AttackTimer.time_left > 0 and not hit: return
|
|
if not subject.is_on_floor(): return %Fall
|
|
if input_direction.length() < 0.05: return %Idle
|
|
if has_node("%Walk") and %Input.walk: return %Walk
|
|
return %Run
|
|
|
|
func _on_attack_body_entered(body: Node3D) -> void:
|
|
if body == subject: return
|
|
if not "player" in body or not body.player: return
|
|
if body.dead: return
|
|
|
|
players_in_area[body.name] = body
|
|
|
|
func _on_attack_body_exited(body: Node3D) -> void:
|
|
players_in_area.erase(body.name)
|