extends Node @onready var data: Data = $/root/Root/Data @onready var castIndicator: CastIndicator = $/root/Root/Arena/CastIndicator @onready var hud: HudController = $/root/Root/Arena/HUD @export var avatar: Combatant var casting = false var spell: Spell var spellIndex: int var timer: float = 0 var anim: AnimationBase # Called when the node enters the scene tree for the first time. func _ready(): avatar.connect("stunned", stunned) #connect(data.player.stunned, stunned) data.spellbook.initCooldowns() for spel: Spell in data.spellbook.spells: if (spel == null): continue if !data.animations.has(spel.animation): data.animations[spel.animation] = load(spel.animation) # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta): if (!data.playing): return 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 castIndicator.show() castIndicator.setDirs(spell.castCombo[0], spell.castCombo[1]) anim = data.animations[spell.animation].instantiate() anim.setProgress(0, spell.castCombo.size()) anim.spell = spell anim.connect("animationFinished", avatar.finalizeSpell) get_node("/root").add_child(anim) timer = 0 else: timer += delta if (Input.is_action_just_pressed(spell.castCombo[avatar.castProgress])): avatar.castProgress += 1 if (anim != null): anim.setProgress(avatar.castProgress) else: casting = false avatar.castProgress = 0 if avatar.castProgress == spell.castCombo.size() - 1: castIndicator.setDirs(spell.castCombo[avatar.castProgress]) elif avatar.castProgress < spell.castCombo.size() - 1: castIndicator.setDirs(spell.castCombo[avatar.castProgress], spell.castCombo[avatar.castProgress + 1]) if avatar.castProgress == spell.castCombo.size(): casting = false avatar.castProgress = 0 avatar.renderer.play("attack1") data.spellbook.cooldowns[spellIndex] = spell.cooldown avatar.defending.append(spell) castIndicator.hide() hud.spellCast(spell, 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, spell.element) stunned() for i in range(data.spellbook.cooldowns.size()): data.spellbook.cooldowns[i] -= delta if data.spellbook.cooldowns[i] < 0: data.spellbook.cooldowns[i] = 0 func stunned(): if (!casting): return casting = false anim.castFailed() data.spellbook.cooldowns[spellIndex] = spell.cooldown * (float(avatar.castProgress) / float(spell.castCombo.size())) hud.spellCast(spell, data.spellbook.cooldowns[spellIndex]) avatar.castProgress = 0 castIndicator.hide() spell = null