2024-10-15 08:14:02 -06:00
|
|
|
# placerholder test ability
|
2024-10-15 08:37:50 -06:00
|
|
|
class_name AbilityPlayer
|
2024-10-15 08:14:02 -06:00
|
|
|
extends TextureRect
|
2024-10-13 20:42:32 -06:00
|
|
|
|
|
|
|
|
2024-10-15 08:14:02 -06:00
|
|
|
var middleX
|
|
|
|
var playerPos
|
|
|
|
|
|
|
|
@export var attack_range := 0
|
|
|
|
@export var attack_type := "single_target"
|
2024-10-15 16:35:03 -06:00
|
|
|
@export var attack_damage := 200
|
|
|
|
@export var attack_speed := 1.0
|
2024-10-15 08:14:02 -06:00
|
|
|
|
|
|
|
|
|
|
|
func _ready() -> void:
|
|
|
|
middleX = get_viewport_rect().size.x/2
|
2024-10-15 08:37:50 -06:00
|
|
|
|
|
|
|
|
|
|
|
func _process(_delta: float) -> void:
|
2024-10-15 08:14:02 -06:00
|
|
|
playerPos = Vector2(middleX, get_viewport_rect().size.y*(0.75))
|
2024-10-15 16:35:03 -06:00
|
|
|
$IdleCooldown.wait_time = attack_speed
|
2024-10-15 08:14:02 -06:00
|
|
|
|
|
|
|
|
|
|
|
func _get_enemies() -> Array:
|
|
|
|
var enemies := get_tree().get_nodes_in_group("enemies")
|
|
|
|
return enemies
|
|
|
|
|
|
|
|
|
|
|
|
func _get_num_enemies() -> int:
|
|
|
|
var enemies := get_tree().get_nodes_in_group("enemies")
|
|
|
|
return enemies.size()
|
|
|
|
|
|
|
|
|
|
|
|
func _get_distance_to_player(enemy: Node) -> float:
|
|
|
|
return enemy.position.distance_squared_to(playerPos)
|
|
|
|
|
|
|
|
|
|
|
|
func _get_target(enemies) -> Node:
|
|
|
|
# var numEnemies := _get_num_enemies()
|
2024-10-15 16:35:03 -06:00
|
|
|
# TODO implement range, i.e. closest within range
|
2024-10-15 08:14:02 -06:00
|
|
|
var enemyDists
|
|
|
|
var closestEnemy
|
|
|
|
# get list of distances by mapping distance to each node in enemies
|
|
|
|
enemyDists = enemies.map(_get_distance_to_player)
|
2024-10-15 08:37:50 -06:00
|
|
|
# get closest enemy by finding first index with min dist
|
2024-10-15 08:14:02 -06:00
|
|
|
closestEnemy = enemies[enemyDists.find(enemyDists.min())]
|
|
|
|
|
|
|
|
return closestEnemy
|
|
|
|
|
|
|
|
|
|
|
|
func _deal_idle_damage(enemiesList) -> void:
|
|
|
|
var target = _get_target(enemiesList)
|
2024-10-15 16:35:03 -06:00
|
|
|
if self.visible:
|
|
|
|
target.damageTaken += attack_damage
|
2024-10-15 08:14:02 -06:00
|
|
|
|
|
|
|
|
|
|
|
func _on_idle_cooldown_timeout() -> void:
|
|
|
|
var enemiesList = _get_enemies()
|
|
|
|
if not enemiesList.is_empty():
|
|
|
|
_deal_idle_damage(enemiesList)
|