56 lines
1.3 KiB
GDScript
56 lines
1.3 KiB
GDScript
class_name WeaponBase
|
|
extends Node2D
|
|
|
|
@export var attack_cd: float
|
|
@export var attack_damage: float
|
|
@export var attack_aoe: float
|
|
@export var attack_duration: float
|
|
@export var attack_range: float
|
|
|
|
@onready var active_cd_timer: Timer = $ActiveCDTimer
|
|
|
|
|
|
func _on_attack_cd_timer_timeout() -> void:
|
|
do_attack()
|
|
|
|
|
|
func do_attack() -> void:
|
|
push_error("%s does not implement do_attack" % self)
|
|
|
|
|
|
func do_active() -> void:
|
|
if not active_cd_timer.is_stopped():
|
|
return
|
|
active_cd_timer.start()
|
|
_do_active()
|
|
|
|
|
|
func _do_active() -> void:
|
|
push_error("%s does not implement do_active" % self)
|
|
|
|
|
|
func find_target_in_radius() -> EnemyBase:
|
|
var space_state: PhysicsDirectSpaceState2D = get_world_2d().direct_space_state
|
|
var shape := CircleShape2D.new()
|
|
shape.radius = attack_range
|
|
|
|
var query := PhysicsShapeQueryParameters2D.new()
|
|
query.shape = shape
|
|
query.transform = Transform2D(0, global_position)
|
|
query.collision_mask = 2
|
|
query.collide_with_bodies = true
|
|
var results := space_state.intersect_shape(query)
|
|
if len(results) < 1:
|
|
return null
|
|
var closest: PhysicsBody2D = results[0]["collider"]
|
|
for r in results:
|
|
var c: PhysicsBody2D = r["collider"]
|
|
if not c.is_in_group(GlobalConst.GROUP_ENEMY):
|
|
continue
|
|
if (
|
|
c.global_position.distance_to(global_position)
|
|
< closest.global_position.distance_to(global_position)
|
|
):
|
|
closest = c
|
|
return closest
|