Partial refactor of the Combat system - Adds combatant controller base scene and the beginnings of player combat controller. Still need to finish hooking up actions.

combat_refactor
Joey Pollack 2 years ago
parent 566c563446
commit f41441e347

@ -1,6 +1,6 @@
[gd_scene load_steps=2 format=3 uid="uid://bbbyup8pp6uam"]
[ext_resource type="Script" path="res://Systems/Combat/Actions/Standard Actions/attack.gd" id="1_nmi0m"]
[ext_resource type="Script" path="res://Systems/Combat/Actions/Scripts/attack.gd" id="1_nmi0m"]
[node name="attack" type="Node"]
script = ExtResource("1_nmi0m")

@ -3,15 +3,20 @@ class_name Combatant
# @export var Behavior:
@export var Controller: CombatantController
@export var Stats: CombatStats
@export var ATBSpeedCoeffecient = 25
#@onready var ATB = $battle_menu/ATB
var is_init = false
var ATBCurrent = 0
signal atb_update(atb_current)
func _ready():
pass
Controller.init_combat(Stats)
func next_turn():
@ -26,11 +31,14 @@ func tick_atb(delta):
return
ATBCurrent += Stats.Speed * delta * ATBSpeedCoeffecient
atb_update.emit(ATBCurrent)
#ATB.value = ATBCurrent
#func _process(delta):
# if not is_init:
# init()
func _process(delta):
tick_atb(delta)
#
#func init():
# for action in Actions:

@ -0,0 +1,51 @@
extends CombatantController
@export var Name = "NONE"
@export var TeamPosition = 0
@onready var Menu = $battle_menu
func init_combat(stats):
Menu.init_state(Name, stats, TeamPosition)
func on_atb_update(new):
Menu.ATB.value = new
#@export var SpecialActions: Array[Action] = []
#
#@onready var ATB = $battle_menu/ATB
#@onready var ActionState = $battle_menu/ActionPanel/ActionState
#@onready var Actions = $Combatant/Actions
#var NextAction
#var ActionReady = false
#
#
#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)
#
#
#func do_action(a):
#
# var action = Actions.get_node(a)
# if !action:
# push_error("Unknown battle action: %s" % a)
# return
#
# ActionState.text = "Action Queued: %s" % action.ActionName
# NextAction = action
# ActionReady = true
#
#func action_done():
# ActionState.text = ""

@ -0,0 +1,6 @@
extends Node
class_name CombatantController
func init_combat(stats):
push_warning("Base init_combat method called")

@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=3 uid="uid://dokn6d31y1bxv"]
[ext_resource type="Script" path="res://Systems/Combat/Scripts/combatant_controller.gd" id="1_kxwx8"]
[node name="CombatantController" type="Node"]
script = ExtResource("1_kxwx8")

@ -0,0 +1,12 @@
[gd_scene load_steps=4 format=3 uid="uid://b0swegor2jejg"]
[ext_resource type="PackedScene" uid="uid://dokn6d31y1bxv" path="res://Systems/Combat/combatant_controller.tscn" id="1_f3a3l"]
[ext_resource type="Script" path="res://Systems/Combat/Scripts/PlayerCombatantController.gd" id="2_rhclm"]
[ext_resource type="PackedScene" uid="uid://cl5d768roh8ir" path="res://Systems/UI/Menu System/battle_menu.tscn" id="3_7ys45"]
[node name="PlayerCombatantController" instance=ExtResource("1_f3a3l")]
script = ExtResource("2_rhclm")
Name = "NONE"
TeamPosition = 0
[node name="battle_menu" parent="." index="0" instance=ExtResource("3_7ys45")]

@ -1,13 +1,30 @@
extends Control
class_name BattleMenu
@onready var BasePanel = $Panel
@onready var Name = $Panel/InfoPanel/Name
@onready var HP = $Panel/InfoPanel/HP
@onready var MStam = $Panel/InfoPanel/MentalStamina
@onready var PStam = $Panel/InfoPanel/PhysicalStamina
@onready var ATB = $Panel/InfoPanel/ATB
var top_margin = 100
var item_padding = 10
enum ACTION { ATTACK, DEFEND, ITEM }
signal action_selected(action)
func init_state(name, stats, team_position):
offset_top = 300
offset_left = BasePanel.size.x * team_position
Name.text = name
HP.text = "HP: %s/%s" % [stats.HP, stats.MaxHP]
MStam.text = "M Stam: %s/%s" % [stats.MentalStamina, stats.MaxMentalStamina]
PStam.text = "P Stam: %s/%s" % [stats.PhysicalStamina, stats.MaxPhysicalStamina]
# TODO Set the rest of the stats
func _on_attack_pressed():

@ -1,6 +1,8 @@
[gd_scene load_steps=2 format=3 uid="uid://cl5d768roh8ir"]
[gd_scene load_steps=4 format=3 uid="uid://cl5d768roh8ir"]
[ext_resource type="Script" path="res://Systems/UI/Menu System/Scripts/battle_menu.gd" id="1_fije1"]
[ext_resource type="Texture2D" uid="uid://dqf1p1mfki3vc" path="res://assets/art/ui/bar_under.png" id="2_ayq4q"]
[ext_resource type="Texture2D" uid="uid://bnp5t7o26kb0c" path="res://assets/art/ui/bar_over.png" id="3_s7h0n"]
[node name="battle_menu" type="Control"]
layout_mode = 3
@ -13,43 +15,114 @@ script = ExtResource("1_fije1")
[node name="Panel" type="Panel" parent="."]
layout_mode = 1
anchors_preset = 8
offset_right = 190.0
offset_bottom = 408.0
[node name="InfoPanel" type="Panel" parent="Panel"]
layout_mode = 1
anchors_preset = 5
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -100.0
offset_top = -86.0
offset_right = 70.0
offset_bottom = 145.0
offset_left = -85.0
offset_right = 85.0
offset_bottom = 148.0
grow_horizontal = 2
grow_vertical = 2
[node name="ATB" type="TextureProgressBar" parent="Panel/InfoPanel"]
layout_mode = 1
anchors_preset = 7
anchor_left = 0.5
anchor_top = 1.0
anchor_right = 0.5
anchor_bottom = 1.0
offset_left = -85.0
offset_top = -29.0
offset_right = 185.0
offset_bottom = 21.0
grow_horizontal = 2
grow_vertical = 0
scale = Vector2(0.63, 0.403)
value = 50.0
texture_under = ExtResource("2_ayq4q")
texture_progress = ExtResource("3_s7h0n")
texture_progress_offset = Vector2(16, 8)
[node name="Name" type="Label" parent="Panel/InfoPanel"]
layout_mode = 1
anchors_preset = 5
anchor_left = 0.5
anchor_right = 0.5
offset_left = -52.5
offset_right = 52.5
offset_bottom = 26.0
grow_horizontal = 2
text = "Fighter Name
"
[node name="HP" type="Label" parent="Panel/InfoPanel"]
layout_mode = 1
anchors_preset = 5
anchor_left = 0.5
anchor_right = 0.5
offset_left = -71.5
offset_top = 26.0
offset_right = 71.5
offset_bottom = 52.0
grow_horizontal = 2
text = "CurrentHP/MaxHP
"
[node name="MentalStamina" type="Label" parent="Panel/InfoPanel"]
layout_mode = 1
anchors_preset = 5
anchor_left = 0.5
anchor_right = 0.5
offset_left = -71.5
offset_top = 52.0
offset_right = 71.5
offset_bottom = 78.0
grow_horizontal = 2
text = "Current/Max
"
[node name="PhysicalStamina" type="Label" parent="Panel/InfoPanel"]
layout_mode = 1
anchors_preset = 5
anchor_left = 0.5
anchor_right = 0.5
offset_left = -71.5
offset_top = 78.0
offset_right = 71.5
offset_bottom = 104.0
grow_horizontal = 2
text = "Current/Max
"
[node name="Label" type="Label" parent="Panel"]
layout_mode = 1
anchors_preset = 5
anchor_left = 0.5
anchor_right = 0.5
offset_left = -60.0
offset_top = 16.0
offset_right = 53.0
offset_bottom = 45.0
offset_left = -56.0
offset_top = 159.0
offset_right = 57.0
offset_bottom = 188.0
grow_horizontal = 2
text = "Battle Menu"
horizontal_alignment = 1
[node name="Panel" type="Panel" parent="Panel"]
[node name="MenuPanel" type="Panel" parent="Panel"]
layout_mode = 1
anchors_preset = 5
anchor_left = 0.5
anchor_right = 0.5
offset_left = -72.0
offset_top = 45.0
offset_top = 190.0
offset_right = 75.0
offset_bottom = 228.0
offset_bottom = 373.0
grow_horizontal = 2
[node name="Attack" type="Button" parent="Panel/Panel"]
[node name="Attack" type="Button" parent="Panel/MenuPanel"]
layout_mode = 1
anchors_preset = 5
anchor_left = 0.5
@ -62,7 +135,7 @@ grow_horizontal = 2
text = "Attack
"
[node name="Tech" type="Button" parent="Panel/Panel"]
[node name="Tech" type="Button" parent="Panel/MenuPanel"]
layout_mode = 1
anchors_preset = 5
anchor_left = 0.5
@ -74,7 +147,7 @@ offset_bottom = 72.0
grow_horizontal = 2
text = "Tech"
[node name="Defend" type="Button" parent="Panel/Panel"]
[node name="Defend" type="Button" parent="Panel/MenuPanel"]
layout_mode = 1
anchors_preset = 5
anchor_left = 0.5
@ -86,7 +159,7 @@ offset_bottom = 107.0
grow_horizontal = 2
text = "Defend"
[node name="Item" type="Button" parent="Panel/Panel"]
[node name="Item" type="Button" parent="Panel/MenuPanel"]
layout_mode = 1
anchors_preset = 5
anchor_left = 0.5
@ -98,7 +171,7 @@ offset_bottom = 142.0
grow_horizontal = 2
text = "Item"
[node name="Rest" type="Button" parent="Panel/Panel"]
[node name="Rest" type="Button" parent="Panel/MenuPanel"]
layout_mode = 1
anchors_preset = 5
anchor_left = 0.5
@ -110,8 +183,35 @@ offset_bottom = 177.0
grow_horizontal = 2
text = "Rest"
[connection signal="pressed" from="Panel/Panel/Attack" to="." method="_on_attack_pressed"]
[connection signal="pressed" from="Panel/Panel/Tech" to="." method="_on_tech_pressed"]
[connection signal="pressed" from="Panel/Panel/Defend" to="." method="_on_defend_pressed"]
[connection signal="pressed" from="Panel/Panel/Item" to="." method="_on_item_pressed"]
[connection signal="pressed" from="Panel/Panel/Rest" to="." method="_on_item_pressed"]
[node name="ActionPanel" type="Panel" parent="Panel"]
layout_mode = 1
anchors_preset = 12
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
offset_top = -33.0
grow_horizontal = 2
grow_vertical = 0
[node name="ActionState" type="Label" parent="Panel/ActionPanel"]
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -85.0
offset_top = -13.0
offset_right = 85.0
offset_bottom = 13.0
grow_horizontal = 2
grow_vertical = 2
theme_override_font_sizes/font_size = 10
horizontal_alignment = 1
vertical_alignment = 1
[connection signal="pressed" from="Panel/MenuPanel/Attack" to="." method="_on_attack_pressed"]
[connection signal="pressed" from="Panel/MenuPanel/Tech" to="." method="_on_tech_pressed"]
[connection signal="pressed" from="Panel/MenuPanel/Defend" to="." method="_on_defend_pressed"]
[connection signal="pressed" from="Panel/MenuPanel/Item" to="." method="_on_item_pressed"]
[connection signal="pressed" from="Panel/MenuPanel/Rest" to="." method="_on_item_pressed"]

@ -1,40 +1,7 @@
extends Sprite2D
@export var SpecialActions: Array[Action] = []
@onready var ATB = $battle_menu/ATB
@onready var ActionState = $battle_menu/ActionPanel/ActionState
@onready var Actions = $Combatant/Actions
var NextAction
var ActionReady = false
@onready var Combantant = $Combatant
@onready var Controller = $Combatant/PlayerCombatantController
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(a):
var action = Actions.get_node(a)
if !action:
push_error("Unknown battle action: %s" % a)
return
ActionState.text = "Action Queued: %s" % action.ActionName
NextAction = action
ActionReady = true
func action_done():
ActionState.text = ""
func _ready():
pass

@ -1,12 +1,10 @@
[gd_scene load_steps=10 format=3 uid="uid://b2iq5inxeoe82"]
[gd_scene load_steps=8 format=3 uid="uid://b2iq5inxeoe82"]
[ext_resource type="Texture2D" uid="uid://dedauf4ntkthu" path="res://icon.svg" id="1_d15px"]
[ext_resource type="Script" path="res://Test Scenes/Player.gd" id="2_8b3bs"]
[ext_resource type="PackedScene" uid="uid://cl5d768roh8ir" path="res://Systems/UI/Menu System/battle_menu.tscn" id="3_ubnwv"]
[ext_resource type="Texture2D" uid="uid://dqf1p1mfki3vc" path="res://assets/art/ui/bar_under.png" id="4_afpwe"]
[ext_resource type="PackedScene" uid="uid://ch1sc85jxy1r7" path="res://Systems/Combat/Combatant.tscn" id="4_w3vb5"]
[ext_resource type="Texture2D" uid="uid://bnp5t7o26kb0c" path="res://assets/art/ui/bar_over.png" id="5_5mhew"]
[ext_resource type="PackedScene" uid="uid://bbbyup8pp6uam" path="res://Systems/Combat/Actions/Standard Actions/attack.tscn" id="5_17k7n"]
[ext_resource type="PackedScene" uid="uid://b0swegor2jejg" path="res://Systems/Combat/player_combatant_controller.tscn" id="6_fabcu"]
[ext_resource type="Script" path="res://Systems/Combat/Scripts/combat_stats.gd" id="7_ynhjd"]
[sub_resource type="Resource" id="Resource_28c5l"]
@ -28,60 +26,17 @@ position = Vector2(553, 219)
texture = ExtResource("1_d15px")
script = ExtResource("2_8b3bs")
[node name="battle_menu" parent="." instance=ExtResource("3_ubnwv")]
offset_left = -49.0
offset_top = 126.0
offset_right = -49.0
offset_bottom = 103.0
[node name="ATB" type="TextureProgressBar" parent="battle_menu"]
layout_mode = 0
offset_left = -36.0
offset_top = -57.575
offset_right = 234.0
offset_bottom = -7.575
scale = Vector2(0.63, 0.403)
value = 50.0
texture_under = ExtResource("4_afpwe")
texture_progress = ExtResource("5_5mhew")
texture_progress_offset = Vector2(16, 8)
[node name="ActionPanel" type="Panel" parent="battle_menu"]
layout_mode = 1
anchors_preset = 12
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = -36.0
offset_top = 93.0
offset_right = 6.0
offset_bottom = 119.0
grow_horizontal = 2
grow_vertical = 0
[node name="ActionState" type="Label" parent="battle_menu/ActionPanel"]
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -85.0
offset_top = -13.0
offset_right = 85.0
offset_bottom = 13.0
grow_horizontal = 2
grow_vertical = 2
theme_override_font_sizes/font_size = 10
horizontal_alignment = 1
vertical_alignment = 1
[node name="Combatant" parent="." instance=ExtResource("4_w3vb5")]
[node name="Combatant" parent="." node_paths=PackedStringArray("Controller") instance=ExtResource("4_w3vb5")]
Controller = NodePath("PlayerCombatantController")
Stats = SubResource("Resource_28c5l")
[node name="Actions" type="Node" parent="Combatant"]
[node name="attack" parent="Combatant/Actions" instance=ExtResource("5_17k7n")]
[connection signal="action_selected" from="battle_menu" to="." method="do_action"]
[node name="PlayerCombatantController" parent="Combatant" instance=ExtResource("6_fabcu")]
Name = "TEST_DUDE"
TeamPosition = 1
[connection signal="atb_update" from="Combatant" to="Combatant/PlayerCombatantController" method="on_atb_update"]
[connection signal="action_finished" from="Combatant/Actions/attack" to="." method="action_done"]

Loading…
Cancel
Save