Fixed major spellcasting bug
- The player and enemy were using a cast progress variable that was part of the spell object, so they were altering it at the same time
This commit is contained in:
parent
9f7cb83789
commit
8fce25f619
@ -10,7 +10,6 @@ class_name Spell
|
|||||||
@export var damage: float = 1
|
@export var damage: float = 1
|
||||||
@export var backfireStrength: float = 1
|
@export var backfireStrength: float = 1
|
||||||
@export var castCombo: Array[String]
|
@export var castCombo: Array[String]
|
||||||
@export var castProgress: int = 0
|
|
||||||
@export var element: Data.Element
|
@export var element: Data.Element
|
||||||
@export var stunning: bool
|
@export var stunning: bool
|
||||||
@export var timeout: float = 10
|
@export var timeout: float = 10
|
||||||
|
File diff suppressed because one or more lines are too long
@ -1,6 +1,7 @@
|
|||||||
class_name Combatant extends Node2D
|
class_name Combatant extends Node2D
|
||||||
|
|
||||||
signal healthChanged(health: float)
|
signal healthChanged(health: float)
|
||||||
|
signal stunned
|
||||||
|
|
||||||
@onready var renderer: AnimatedSprite2D = $AnimatedSprite2D
|
@onready var renderer: AnimatedSprite2D = $AnimatedSprite2D
|
||||||
@onready var healthbar: HealthBar = $HealthBar
|
@onready var healthbar: HealthBar = $HealthBar
|
||||||
@ -16,6 +17,7 @@ var spellIndex: int
|
|||||||
var anim: AnimationBase
|
var anim: AnimationBase
|
||||||
var casting: bool = false
|
var casting: bool = false
|
||||||
var castCooldown: float = 0
|
var castCooldown: float = 0
|
||||||
|
var castProgress: int = 0
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
# Called when the node enters the scene tree for the first time.
|
||||||
func _ready():
|
func _ready():
|
||||||
@ -51,7 +53,6 @@ func _finishedCasting() -> void:
|
|||||||
func timing(delta) -> void:
|
func timing(delta) -> void:
|
||||||
castCooldown -= delta
|
castCooldown -= delta
|
||||||
if castCooldown <= 0:
|
if castCooldown <= 0:
|
||||||
print("Attempt cast")
|
|
||||||
cast()
|
cast()
|
||||||
|
|
||||||
func cast() -> void:
|
func cast() -> void:
|
||||||
@ -95,12 +96,12 @@ func attemptCast():
|
|||||||
Data.Difficulty.EASY:
|
Data.Difficulty.EASY:
|
||||||
await get_tree().create_timer(randf_range(0.5, 1.5)).timeout
|
await get_tree().create_timer(randf_range(0.5, 1.5)).timeout
|
||||||
if randi_range(0, 99) < 90:
|
if randi_range(0, 99) < 90:
|
||||||
spell.castProgress += 1
|
castProgress += 1
|
||||||
anim.setProgress(spell.castProgress)
|
anim.setProgress(castProgress)
|
||||||
|
|
||||||
if spell.castProgress == spell.castCombo.size():
|
if castProgress == spell.castCombo.size():
|
||||||
casting = false
|
casting = false
|
||||||
spell.castProgress = 0
|
castProgress = 0
|
||||||
renderer.play("attack1")
|
renderer.play("attack1")
|
||||||
spellbook.cooldowns[spellIndex] = spell.cooldown
|
spellbook.cooldowns[spellIndex] = spell.cooldown
|
||||||
data.player.alterHealth(-spell.damage, false)
|
data.player.alterHealth(-spell.damage, false)
|
||||||
@ -111,18 +112,18 @@ func attemptCast():
|
|||||||
alterHealth(-spell.backfireStrength, true)
|
alterHealth(-spell.backfireStrength, true)
|
||||||
casting = false
|
casting = false
|
||||||
anim.castFailed()
|
anim.castFailed()
|
||||||
spell.castProgress = 0
|
castProgress = 0
|
||||||
spellbook.cooldowns[spellIndex] = spell.cooldown * (float(spell.castProgress) / float(spell.castCombo.size()))
|
spellbook.cooldowns[spellIndex] = spell.cooldown * (float(castProgress) / float(spell.castCombo.size()))
|
||||||
_finishedCasting()
|
_finishedCasting()
|
||||||
Data.Difficulty.NORMAL:
|
Data.Difficulty.NORMAL:
|
||||||
await get_tree().create_timer(randf_range(0.4, 1)).timeout
|
await get_tree().create_timer(randf_range(0.4, 1)).timeout
|
||||||
if randi_range(0, 99) < 95:
|
if randi_range(0, 99) < 95:
|
||||||
spell.castProgress += 1
|
castProgress += 1
|
||||||
anim.setProgress(spell.castProgress)
|
anim.setProgress(castProgress)
|
||||||
|
|
||||||
if spell.castProgress == spell.castCombo.size():
|
if castProgress == spell.castCombo.size():
|
||||||
casting = false
|
casting = false
|
||||||
spell.castProgress = 0
|
castProgress = 0
|
||||||
renderer.play("attack1")
|
renderer.play("attack1")
|
||||||
spellbook.cooldowns[spellIndex] = spell.cooldown
|
spellbook.cooldowns[spellIndex] = spell.cooldown
|
||||||
data.player.alterHealth(-spell.damage, false)
|
data.player.alterHealth(-spell.damage, false)
|
||||||
@ -133,18 +134,18 @@ func attemptCast():
|
|||||||
alterHealth(-spell.backfireStrength, true)
|
alterHealth(-spell.backfireStrength, true)
|
||||||
casting = false
|
casting = false
|
||||||
anim.castFailed()
|
anim.castFailed()
|
||||||
spell.castProgress = 0
|
castProgress = 0
|
||||||
spellbook.cooldowns[spellIndex] = spell.cooldown * (float(spell.castProgress) / float(spell.castCombo.size()))
|
spellbook.cooldowns[spellIndex] = spell.cooldown * (float(castProgress) / float(spell.castCombo.size()))
|
||||||
_finishedCasting()
|
_finishedCasting()
|
||||||
Data.Difficulty.HARD:
|
Data.Difficulty.HARD:
|
||||||
await get_tree().create_timer(randf_range(0.2, 0.6)).timeout
|
await get_tree().create_timer(randf_range(0.2, 0.6)).timeout
|
||||||
if randi_range(0, 99) < 98:
|
if randi_range(0, 99) < 98:
|
||||||
spell.castProgress += 1
|
castProgress += 1
|
||||||
anim.setProgress(spell.castProgress)
|
anim.setProgress(castProgress)
|
||||||
|
|
||||||
if spell.castProgress == spell.castCombo.size():
|
if castProgress == spell.castCombo.size():
|
||||||
casting = false
|
casting = false
|
||||||
spell.castProgress = 0
|
castProgress = 0
|
||||||
renderer.play("attack1")
|
renderer.play("attack1")
|
||||||
spellbook.cooldowns[spellIndex] = spell.cooldown
|
spellbook.cooldowns[spellIndex] = spell.cooldown
|
||||||
data.player.alterHealth(-spell.damage, false)
|
data.player.alterHealth(-spell.damage, false)
|
||||||
@ -155,17 +156,17 @@ func attemptCast():
|
|||||||
alterHealth(-spell.backfireStrength, true)
|
alterHealth(-spell.backfireStrength, true)
|
||||||
casting = false
|
casting = false
|
||||||
anim.castFailed()
|
anim.castFailed()
|
||||||
spell.castProgress = 0
|
castProgress = 0
|
||||||
spellbook.cooldowns[spellIndex] = spell.cooldown * (float(spell.castProgress) / float(spell.castCombo.size()))
|
spellbook.cooldowns[spellIndex] = spell.cooldown * (float(castProgress) / float(spell.castCombo.size()))
|
||||||
_finishedCasting()
|
_finishedCasting()
|
||||||
Data.Difficulty.GAMER:
|
Data.Difficulty.GAMER:
|
||||||
await get_tree().create_timer(.1).timeout
|
await get_tree().create_timer(.1).timeout
|
||||||
spell.castProgress += 1
|
castProgress += 1
|
||||||
anim.setProgress(spell.castProgress)
|
anim.setProgress(castProgress)
|
||||||
|
|
||||||
if spell.castProgress == spell.castCombo.size():
|
if castProgress == spell.castCombo.size():
|
||||||
casting = false
|
casting = false
|
||||||
spell.castProgress = 0
|
castProgress = 0
|
||||||
renderer.play("attack1")
|
renderer.play("attack1")
|
||||||
spellbook.cooldowns[spellIndex] = spell.cooldown
|
spellbook.cooldowns[spellIndex] = spell.cooldown
|
||||||
data.player.alterHealth(-spell.damage, false)
|
data.player.alterHealth(-spell.damage, false)
|
||||||
@ -178,6 +179,8 @@ func alterHealth(change: float, stun: bool) -> void:
|
|||||||
if stun:
|
if stun:
|
||||||
casting = false
|
casting = false
|
||||||
renderer.play("hit")
|
renderer.play("hit")
|
||||||
|
if player:
|
||||||
|
stunned.emit()
|
||||||
healthChanged.emit(health)
|
healthChanged.emit(health)
|
||||||
|
|
||||||
func animationFinished() -> void:
|
func animationFinished() -> void:
|
||||||
|
@ -4,5 +4,4 @@ class_name HealthBar extends Control
|
|||||||
@export var maxHealth: float = 1
|
@export var maxHealth: float = 1
|
||||||
|
|
||||||
func healthChanged(health) -> void:
|
func healthChanged(health) -> void:
|
||||||
print("Health Changed")
|
|
||||||
bar.size.y = (health / maxHealth) * 100
|
bar.size.y = (health / maxHealth) * 100
|
||||||
|
@ -2,7 +2,9 @@ extends Node
|
|||||||
|
|
||||||
@onready var data: Data = get_node("/root/Root/Data")
|
@onready var data: Data = get_node("/root/Root/Data")
|
||||||
@onready var castIndicator: CastIndicator = get_node("/root/Root/Arena/CastIndicator")
|
@onready var castIndicator: CastIndicator = get_node("/root/Root/Arena/CastIndicator")
|
||||||
|
|
||||||
@export var avatar: Combatant
|
@export var avatar: Combatant
|
||||||
|
|
||||||
var casting = false
|
var casting = false
|
||||||
var spell: Spell
|
var spell: Spell
|
||||||
var spellIndex: int
|
var spellIndex: int
|
||||||
@ -11,6 +13,8 @@ var anim: AnimationBase
|
|||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
# Called when the node enters the scene tree for the first time.
|
||||||
func _ready():
|
func _ready():
|
||||||
|
avatar.connect("stunned", stunned)
|
||||||
|
#connect(data.player.stunned, stunned)
|
||||||
data.spellbook.initCooldowns()
|
data.spellbook.initCooldowns()
|
||||||
for spel: Spell in data.spellbook.spells:
|
for spel: Spell in data.spellbook.spells:
|
||||||
if (spel == null): continue
|
if (spel == null): continue
|
||||||
@ -30,22 +34,21 @@ func _process(delta):
|
|||||||
anim = data.animations[spell.animation].instantiate()
|
anim = data.animations[spell.animation].instantiate()
|
||||||
anim.setProgress(0, spell.castCombo.size())
|
anim.setProgress(0, spell.castCombo.size())
|
||||||
get_node("/root").add_child(anim)
|
get_node("/root").add_child(anim)
|
||||||
|
|
||||||
timer = 0
|
timer = 0
|
||||||
else:
|
else:
|
||||||
timer += delta
|
timer += delta
|
||||||
if (Input.is_action_just_pressed(spell.castCombo[spell.castProgress])):
|
if (Input.is_action_just_pressed(spell.castCombo[avatar.castProgress])):
|
||||||
spell.castProgress += 1
|
avatar.castProgress += 1
|
||||||
anim.setProgress(spell.castProgress)
|
anim.setProgress(avatar.castProgress)
|
||||||
|
|
||||||
if spell.castProgress == spell.castCombo.size() - 1:
|
if avatar.castProgress == spell.castCombo.size() - 1:
|
||||||
castIndicator.setDirs(spell.castCombo[spell.castProgress])
|
castIndicator.setDirs(spell.castCombo[avatar.castProgress])
|
||||||
elif spell.castProgress < spell.castCombo.size() - 1:
|
elif avatar.castProgress < spell.castCombo.size() - 1:
|
||||||
castIndicator.setDirs(spell.castCombo[spell.castProgress], spell.castCombo[spell.castProgress + 1])
|
castIndicator.setDirs(spell.castCombo[avatar.castProgress], spell.castCombo[avatar.castProgress + 1])
|
||||||
|
|
||||||
if spell.castProgress == spell.castCombo.size():
|
if avatar.castProgress == spell.castCombo.size():
|
||||||
casting = false
|
casting = false
|
||||||
spell.castProgress = 0
|
avatar.castProgress = 0
|
||||||
avatar.renderer.play("attack1")
|
avatar.renderer.play("attack1")
|
||||||
data.spellbook.cooldowns[spellIndex] = spell.cooldown
|
data.spellbook.cooldowns[spellIndex] = spell.cooldown
|
||||||
castIndicator.hide()
|
castIndicator.hide()
|
||||||
@ -54,10 +57,16 @@ func _process(delta):
|
|||||||
avatar.alterHealth(-spell.backfireStrength, true)
|
avatar.alterHealth(-spell.backfireStrength, true)
|
||||||
casting = false
|
casting = false
|
||||||
anim.castFailed()
|
anim.castFailed()
|
||||||
spell.castProgress = 0
|
avatar.castProgress = 0
|
||||||
data.spellbook.cooldowns[spellIndex] = spell.cooldown * (float(spell.castProgress) / float(spell.castCombo.size()))
|
data.spellbook.cooldowns[spellIndex] = spell.cooldown * (float(avatar.castProgress) / float(spell.castCombo.size()))
|
||||||
castIndicator.hide()
|
castIndicator.hide()
|
||||||
|
|
||||||
for i in range(data.spellbook.cooldowns.size()):
|
for i in range(data.spellbook.cooldowns.size()):
|
||||||
data.spellbook.cooldowns[i] -= delta
|
data.spellbook.cooldowns[i] -= delta
|
||||||
if data.spellbook.cooldowns[i] < 0: data.spellbook.cooldowns[i] = 0
|
if data.spellbook.cooldowns[i] < 0: data.spellbook.cooldowns[i] = 0
|
||||||
|
|
||||||
|
func stunned():
|
||||||
|
casting = false
|
||||||
|
avatar.castProgress = 0
|
||||||
|
data.spellbook.cooldowns[spellIndex] = spell.cooldown * (float(avatar.castProgress) / float(spell.castCombo.size()))
|
||||||
|
castIndicator.hide()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user