55 lines
1.4 KiB
GDScript
55 lines
1.4 KiB
GDScript
# placerholder test ability
|
|
class_name Ability
|
|
extends TextureRect
|
|
|
|
|
|
var middleX
|
|
var playerPos
|
|
|
|
@export var attack_range := 0
|
|
@export var attack_type := "single_target"
|
|
|
|
|
|
func _ready() -> void:
|
|
middleX = get_viewport_rect().size.x/2
|
|
playerPos = Vector2(middleX, get_viewport_rect().size.y*(0.75))
|
|
|
|
|
|
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()
|
|
var enemyDists
|
|
var closestEnemy
|
|
# get array of difficulties using map
|
|
# get list of distances by mapping distance to each node in enemies
|
|
enemyDists = enemies.map(_get_distance_to_player)
|
|
# get closest enemy by finding index with min dist
|
|
closestEnemy = enemies[enemyDists.find(enemyDists.min())]
|
|
|
|
return closestEnemy
|
|
|
|
|
|
func _deal_idle_damage(enemiesList) -> void:
|
|
var damage = 200
|
|
var target = _get_target(enemiesList)
|
|
target.damageTaken += damage
|
|
|
|
|
|
func _on_idle_cooldown_timeout() -> void:
|
|
var enemiesList = _get_enemies()
|
|
if not enemiesList.is_empty():
|
|
_deal_idle_damage(enemiesList)
|