Raise-Your-Wand/Scripts/playerController.gd
2024-05-02 15:39:04 -04:00

44 lines
1.6 KiB
GDScript

extends Node
@onready var data = get_node("/root/Arena/Data")
@onready var castIndicator = get_node("/root/Arena/CanvasLayer/CastIndicator")
@export var avatar: Combatant
var casting = false
var spell: Spell
var spellIndex: int
var timer: float = 0
# Called when the node enters the scene tree for the first time.
func _ready():
data.spellbook.initCooldowns()
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
if !casting:
for i in range(data.spellbook.spells.size()):
if Input.is_action_just_pressed("Spell" + str(i)) && data.spellbook.cooldowns[i] == 0:
casting = true
spell = data.spellbook.spells[i]
spellIndex = i
avatar.particleSystem.emitting = true
timer = 0
else:
timer += delta
if (Input.is_action_just_pressed(spell.castCombo[spell.castProgress])):
spell.castProgress += 1
if spell.castProgress == spell.castCombo.size():
casting = false
avatar.particleSystem.emitting = false
spell.castProgress = 0
avatar.renderer.play("attack1")
data.spellbook.cooldowns[spellIndex] = spell.cooldown
elif (timer >= spell.timeout || Input.is_action_just_pressed("up") || Input.is_action_just_pressed("down") || Input.is_action_just_pressed("left") || Input.is_action_just_pressed("right")):
avatar.alterHealth(-spell.backfireStrength, true)
casting = false
avatar.particleSystem.emitting = false
data.spellbook.cooldowns[spellIndex] = spell.cooldown * (spell.castProgress / spell.castCombo.size())
for i in range(data.spellbook.cooldowns.size()):
data.spellbook.cooldowns[i] -= delta
if data.spellbook.cooldowns[i] < 0: data.spellbook.cooldowns[i] = 0