57 lines
1.6 KiB
GDScript
57 lines
1.6 KiB
GDScript
class_name WeaponSword
|
|
extends WeaponBase
|
|
|
|
const WEAPON_SWORD_PROJECTILE = preload("res://scenes/weapons/weapon_sword_projectile.tscn")
|
|
|
|
@onready var targeting_range: Area2D = $TargetingRange
|
|
@onready var targeting_range_shape: CollisionShape2D = $TargetingRange/CollisionShape2D
|
|
|
|
signal projectile_hit(projectile: WeaponSwordProjectile, enemy: EnemyBase)
|
|
|
|
|
|
func _ready() -> void:
|
|
bleed_chance = 0.2
|
|
targeting_range_shape.shape.radius = attack_range
|
|
projectile_hit.connect(_on_projectile_hit)
|
|
super._ready()
|
|
|
|
|
|
func do_attack() -> void:
|
|
var target: EnemyBase = find_target_in_radius()
|
|
if not target:
|
|
return
|
|
|
|
var projectile = WEAPON_SWORD_PROJECTILE.instantiate()
|
|
projectile.target = target
|
|
projectile.on_hit_sig = projectile_hit
|
|
add_child(projectile)
|
|
|
|
|
|
func _do_active() -> void:
|
|
var radius = targeting_range_shape.shape.radius
|
|
var count = 15
|
|
for i in count:
|
|
var angle = TAU * float(i) / float(count)
|
|
var target_pos = Vector2(cos(angle), sin(angle)) * radius
|
|
var new_target := Marker2D.new()
|
|
new_target.global_position = global_position + target_pos
|
|
var projectile = WEAPON_SWORD_PROJECTILE.instantiate()
|
|
projectile.damage_mult = 3.0
|
|
projectile.target = new_target
|
|
projectile.on_hit_sig = projectile_hit
|
|
add_child(projectile)
|
|
|
|
|
|
func deal_damage(enemy: EnemyBase, damage_mult: float):
|
|
var damage_and_crit = base_damage()
|
|
# TODO: Fix crit value
|
|
enemy.take_damage(damage_and_crit[0], damage_and_crit[1])
|
|
|
|
if did_bleed():
|
|
var bleed = EnemyEffectBleed.new(enemy, damage_and_crit[0], bleed_duration)
|
|
bleed.apply(enemy)
|
|
|
|
|
|
func _on_projectile_hit(projectile: WeaponSwordProjectile, enemy: EnemyBase, damage_mult: float):
|
|
deal_damage(enemy, damage_mult)
|