2024-10-18 09:11:15 -06:00
# base player ability class
2024-10-15 08:37:50 -06:00
class_name AbilityPlayer
2024-10-16 15:59:37 -06:00
extends AbilityBase
2024-10-15 08:14:02 -06:00
2024-10-16 15:16:54 -06:00
var middleX
var playerPos
2024-10-20 16:44:08 -06:00
enum TargetType {
SINGLE ,
CLEAVE ,
CHAIN ,
SWIPE ,
WAVE ,
AREA ,
RAY ,
}
@ export var target_type : = TargetType . SINGLE
@ export var target_angle : = 2 * PI
2024-10-18 11:25:29 -06:00
@ export var base_cooldown : = 0.0
2024-10-21 09:51:28 -06:00
@ export var attack_damage : = 400
2024-10-16 15:16:54 -06:00
2024-10-15 08:14:02 -06:00
func _ready ( ) - > void :
2024-10-18 09:11:15 -06:00
middleX = get_viewport_rect ( ) . size . x / 2
2024-10-15 08:37:50 -06:00
func _process ( _delta : float ) - > void :
2024-10-18 09:11:15 -06:00
playerPos = Vector2 ( middleX , get_viewport_rect ( ) . size . y * ( 0.75 ) )
2024-10-18 11:25:29 -06:00
$ IdleCooldown . wait_time = auto_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 ( )
2024-10-16 15:04:44 -06:00
func _get_distsq_to_player ( enemy : Node ) - > float :
2024-10-15 08:14:02 -06:00
return enemy . position . distance_squared_to ( playerPos )
2024-10-16 15:04:44 -06:00
func _get_angle_to_player ( enemy : Node ) - > float :
return enemy . position . angle_to_point ( playerPos )
2024-10-15 08:14:02 -06:00
func _get_target ( enemies ) - > Node :
# var numEnemies := _get_num_enemies()
var enemyDists
var closestEnemy
# get list of distances by mapping distance to each node in enemies
2024-10-16 15:04:44 -06:00
enemyDists = enemies . map ( _get_distsq_to_player )
2024-10-15 08:37:50 -06:00
# get closest enemy by finding first index with min dist
2024-10-20 16:44:08 -06:00
if enemyDists . min ( ) < = self . attack_range * * 2 :
2024-10-18 11:25:29 -06:00
closestEnemy = enemies [ enemyDists . find ( enemyDists . min ( ) ) ]
2024-10-15 08:14:02 -06:00
return closestEnemy
2024-10-20 16:44:08 -06:00
func _get_targets_in_range ( enemies ) - > Array :
2024-10-18 11:25:29 -06:00
var enemyDists
var enemiesInRange : = [ ]
# get list of distances by mapping distance to each node in enemies
enemyDists = enemies . map ( _get_distsq_to_player )
# append enemies in range to enemiesInRange
for i in range ( enemies . size ( ) ) :
2024-10-20 16:44:08 -06:00
if enemyDists [ i ] < = self . attack_range * * 2 :
2024-10-18 11:25:29 -06:00
enemiesInRange . append ( enemies [ i ] )
return enemiesInRange
2024-10-20 16:44:08 -06:00
# func _get_targets_in_angle(enemies) -> Array:
# var enemyAngles
# var enemiesInAngle := []
# # get list of angles by mapping distance to each node in enemies
# enemyAngles = enemies.map(_get_angle_to_player)
# # append enemies in range to enemiesInAngle
# for i in range(enemies.size()):
# if enemyAngles[i] <= self.attack_range ** 2:
# enemiesInAngle.append(enemies[i])
# return enemiesInAngle
# func _get_targets(enemies) -> Array:
# if self.attack_range > 0:
# var enemiesInRange = _get_targets_in_range(enemies)
func _apply_status ( ) - > void :
# TODO: Try passing damage and status type to target for mods, e.g. burning or stunned, and use with singleton stats to add thread to target for damage or do other things depending on the case
2024-10-25 22:22:13 -06:00
# unnecessary... can just loop await get_tree().create_timer(time).timeout
2024-10-20 16:44:08 -06:00
pass
2024-10-15 08:14:02 -06:00
func _deal_idle_damage ( enemiesList ) - > void :
2024-10-18 11:25:29 -06:00
match target_type :
2024-10-20 16:44:08 -06:00
TargetType . SINGLE :
2024-10-18 11:25:29 -06:00
var target = _get_target ( enemiesList )
2024-10-18 13:24:11 -06:00
if target :
2024-10-21 09:51:28 -06:00
target . damageTaken += auto_damage
2024-10-18 11:25:29 -06:00
_ :
2024-10-20 16:44:08 -06:00
var targets = _get_targets_in_range ( enemiesList )
2024-10-18 13:24:11 -06:00
if targets :
for target in targets :
2024-10-21 09:51:28 -06:00
target . damageTaken += auto_damage
2024-10-18 11:25:29 -06:00
2024-10-15 08:14:02 -06:00
func _on_idle_cooldown_timeout ( ) - > void :
var enemiesList = _get_enemies ( )
2024-10-18 11:25:29 -06:00
if not enemiesList . is_empty ( ) and self . visible :
2024-10-15 08:14:02 -06:00
_deal_idle_damage ( enemiesList )
2024-10-25 16:12:30 -06:00
2024-10-25 22:22:13 -06:00
# TODO: implement active damage with signal to send resources spent to player cast/charge-time based instead of cooldowns for active abilities, but still uses "cooldown" value