From 7e599a5f97f286bd0374cd18fb94001987616c66 Mon Sep 17 00:00:00 2001 From: Joey Pollack Date: Mon, 17 Jul 2023 13:16:10 -0400 Subject: [PATCH] Adds action queuing and ATB charging --- Systems/Combat/Actions/Scripts/action.gd | 2 ++ Systems/Combat/Scripts/Combatant.gd | 11 ++++---- Test Scenes/Player.gd | 28 +++++++++++++++++-- .../Test Player Actions/Scripts/attack.gd | 14 ++++++++-- .../Scripts/spin_attack.gd | 12 +++++++- Test Scenes/player.tscn | 9 +++++- 6 files changed, 63 insertions(+), 13 deletions(-) diff --git a/Systems/Combat/Actions/Scripts/action.gd b/Systems/Combat/Actions/Scripts/action.gd index 6cd9531..f1a4b10 100644 --- a/Systems/Combat/Actions/Scripts/action.gd +++ b/Systems/Combat/Actions/Scripts/action.gd @@ -7,6 +7,8 @@ class_name Action var ActionIndex = 0 +signal action_finished + func _ready(): if ActionName == "NONE": push_warning("Actions has NONE name") diff --git a/Systems/Combat/Scripts/Combatant.gd b/Systems/Combat/Scripts/Combatant.gd index 6bdda51..4f191f0 100644 --- a/Systems/Combat/Scripts/Combatant.gd +++ b/Systems/Combat/Scripts/Combatant.gd @@ -10,23 +10,22 @@ class_name Combatant var is_init = false var ATBCurrent = 0 -var ActionReady = false func _ready(): pass func tick_atb(delta): - if ActionReady: + + if ATBCurrent >= 100: + ATBCurrent = 100 return - ATBCurrent += Stats.Speed * delta - if ATBCurrent >= 100: - ActionReady = true + ATBCurrent += Stats.Speed * delta * ATBSpeedCoeffecient func execute_action(index: int): Actions[index].execute() - ActionReady = false + ATBCurrent = 0 #func _process(delta): # if not is_init: diff --git a/Test Scenes/Player.gd b/Test Scenes/Player.gd index d998ffc..e2cc4f5 100644 --- a/Test Scenes/Player.gd +++ b/Test Scenes/Player.gd @@ -1,18 +1,40 @@ extends Sprite2D @onready var ATB = $battle_menu/ATB +@onready var ActionState = $battle_menu/ActionState +var NextAction +var ActionReady = false func _ready(): var menu = $battle_menu - menu.add_action($Combatant/Actions/attack).action_selected.connect(do_action) - menu.add_action($Combatant/Actions/spin_attack).action_selected.connect(do_action) + var item = menu.add_action($Combatant/Actions/attack) + item.action_selected.connect(do_action) + item.action.action_finished.connect(action_done) + item = menu.add_action($Combatant/Actions/spin_attack) + item.action_selected.connect(do_action) + item.action.action_finished.connect(action_done) func _process(delta): + var combatant = $Combatant + if ActionReady and ATB.value == 100: + NextAction.execute() + ActionState.text = "Action Executing: %s" % NextAction.ActionName + combatant.ATBCurrent = 0 + ATB.value = 0 + ActionReady = false + return + + combatant.tick_atb(delta) ATB.value = combatant.ATBCurrent func do_action(action): - print("Player selected: %s" % action.ActionName) + ActionState.text = "Action Queued: %s" % action.ActionName + NextAction = action + ActionReady = true + +func action_done(): + ActionState.text = "" diff --git a/Test Scenes/Test Player Actions/Scripts/attack.gd b/Test Scenes/Test Player Actions/Scripts/attack.gd index e89504f..fa6fdcb 100644 --- a/Test Scenes/Test Player Actions/Scripts/attack.gd +++ b/Test Scenes/Test Player Actions/Scripts/attack.gd @@ -1,6 +1,16 @@ extends Action - +var timer func execute(): - print("Test Player Attacking!") + timer = Timer.new() + timer.timeout.connect(done) + timer.wait_time = 1 + add_child(timer) + timer.start() + print("Executing Attack!") + +func done(): + timer.queue_free() + action_finished.emit() + diff --git a/Test Scenes/Test Player Actions/Scripts/spin_attack.gd b/Test Scenes/Test Player Actions/Scripts/spin_attack.gd index 2c086ff..64b6fd2 100644 --- a/Test Scenes/Test Player Actions/Scripts/spin_attack.gd +++ b/Test Scenes/Test Player Actions/Scripts/spin_attack.gd @@ -1,4 +1,14 @@ extends Action +var timer func execute(): - print("Test Player uses Spin Attack!") + timer = Timer.new() + timer.timeout.connect(done) + timer.wait_time = 1 + add_child(timer) + timer.start() + print("Executing Spin Attack!") + +func done(): + timer.queue_free() + action_finished.emit() diff --git a/Test Scenes/player.tscn b/Test Scenes/player.tscn index 8996a0d..bd5db7f 100644 --- a/Test Scenes/player.tscn +++ b/Test Scenes/player.tscn @@ -25,7 +25,7 @@ Accuracy = 1 Agility = 1 [node name="Player" type="Sprite2D"] -position = Vector2(447, 283) +position = Vector2(553, 219) texture = ExtResource("1_d15px") script = ExtResource("2_8b3bs") @@ -47,6 +47,13 @@ texture_under = ExtResource("4_afpwe") texture_progress = ExtResource("5_5mhew") texture_progress_offset = Vector2(16, 8) +[node name="ActionState" type="Label" parent="battle_menu"] +layout_mode = 0 +offset_left = -36.0 +offset_top = 237.0 +offset_right = 170.0 +offset_bottom = 280.0 + [node name="Combatant" parent="." node_paths=PackedStringArray("Actions") instance=ExtResource("4_w3vb5")] Stats = SubResource("Resource_28c5l") Actions = [null, null]