From dcb3966d54e168ed1545a32fc8fc7c6dcc3c09b5 Mon Sep 17 00:00:00 2001 From: Joey Pollack Date: Mon, 12 Aug 2024 20:13:07 -0400 Subject: [PATCH] Adds monster and start of combat menu --- actors/enemies/blob/blob.tscn | 24 ++----- actors/player chars/alex/alex.tscn | 21 +++--- systems/combat/combat_action.gd | 6 ++ systems/combat/combat_state.gd | 8 +-- systems/combat/combat_team.gd | 4 +- systems/combat/combatant.gd | 53 --------------- systems/combat/combatant/combatant.gd | 67 +++++++++++++++++++ systems/combat/combatant/combatant.tscn | 38 +++++++++++ .../combat/common actions/action_attack.gd | 4 ++ systems/combat/ui/combat_log.gd | 2 + testing/sandbox.tscn | 4 +- 11 files changed, 141 insertions(+), 90 deletions(-) delete mode 100644 systems/combat/combatant.gd create mode 100644 systems/combat/combatant/combatant.gd create mode 100644 systems/combat/combatant/combatant.tscn diff --git a/actors/enemies/blob/blob.tscn b/actors/enemies/blob/blob.tscn index 5c2109a..577fa92 100644 --- a/actors/enemies/blob/blob.tscn +++ b/actors/enemies/blob/blob.tscn @@ -1,9 +1,8 @@ -[gd_scene load_steps=9 format=3 uid="uid://dwi00nixw6eia"] +[gd_scene load_steps=7 format=3 uid="uid://dwi00nixw6eia"] [ext_resource type="Script" path="res://actors/enemies/blob/blob.gd" id="1_e8a40"] [ext_resource type="Texture2D" uid="uid://dd73lco3o6w4f" path="res://actors/enemies/blob/art/Blob.png" id="2_ej213"] -[ext_resource type="Script" path="res://systems/combat/combatant.gd" id="3_mqgr1"] -[ext_resource type="Script" path="res://systems/combat/combat_stats.gd" id="4_22gbw"] +[ext_resource type="PackedScene" uid="uid://4glu7reewmf3" path="res://systems/combat/combatant/combatant.tscn" id="3_aq8jq"] [sub_resource type="AtlasTexture" id="AtlasTexture_m73y6"] atlas = ExtResource("2_ej213") @@ -27,20 +26,6 @@ animations = [{ "speed": 3.0 }] -[sub_resource type="Resource" id="Resource_46v15"] -script = ExtResource("4_22gbw") -max_hp = 10 -max_physical_stamina = 10 -max_mental_stamina = 10 -strength = 1 -wisdom = 1 -constitution = 1 -willpower = 1 -speed = 1 -focus = 1 -accuracy = 1 -agility = 1 - [node name="Blob" type="Node2D"] script = ExtResource("1_e8a40") @@ -50,6 +35,5 @@ sprite_frames = SubResource("SpriteFrames_p36og") animation = &"Idle" frame_progress = 0.110573 -[node name="Combatant" type="Node" parent="."] -script = ExtResource("3_mqgr1") -combat_stats = SubResource("Resource_46v15") +[node name="Combatant" parent="." instance=ExtResource("3_aq8jq")] +is_player_driven = false diff --git a/actors/player chars/alex/alex.tscn b/actors/player chars/alex/alex.tscn index 94dc02b..a0f0d91 100644 --- a/actors/player chars/alex/alex.tscn +++ b/actors/player chars/alex/alex.tscn @@ -2,7 +2,7 @@ [ext_resource type="Script" path="res://actors/player chars/alex/alex.gd" id="1_3ppui"] [ext_resource type="Texture2D" uid="uid://cs6uqgpyvwy7r" path="res://actors/player chars/alex/art/alex.png" id="2_2yoh5"] -[ext_resource type="Script" path="res://systems/combat/combatant.gd" id="3_m4k76"] +[ext_resource type="PackedScene" uid="uid://4glu7reewmf3" path="res://systems/combat/combatant/combatant.tscn" id="3_wnv85"] [ext_resource type="Script" path="res://systems/combat/combat_stats.gd" id="4_6ae2h"] [ext_resource type="Script" path="res://systems/combat/common actions/action_attack.gd" id="5_dhgwv"] @@ -132,21 +132,21 @@ animations = [{ "speed": 5.0 }] -[sub_resource type="Resource" id="Resource_y86ab"] +[sub_resource type="Resource" id="Resource_5fm47"] script = ExtResource("4_6ae2h") -max_hp = 100 +max_hp = 10 max_physical_stamina = 10 max_mental_stamina = 10 -strength = 5 +strength = 1 wisdom = 1 -constitution = 2 +constitution = 1 willpower = 1 speed = 1 focus = 1 accuracy = 1 agility = 1 -[sub_resource type="Resource" id="Resource_2d861"] +[sub_resource type="Resource" id="Resource_pwlmc"] script = ExtResource("5_dhgwv") [node name="Alex" type="Node2D" node_paths=PackedStringArray("sprite")] @@ -156,10 +156,11 @@ sprite = NodePath("AnimatedSprite2D") [node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."] texture_filter = 1 +scale = Vector2(2, 2) sprite_frames = SubResource("SpriteFrames_vu5b1") animation = &"Idle_West" -[node name="Combatant" type="Node" parent="."] -script = ExtResource("3_m4k76") -combat_stats = SubResource("Resource_y86ab") -actions = Array[Resource("res://systems/combat/combat_action.gd")]([SubResource("Resource_2d861")]) +[node name="Combatant" parent="." instance=ExtResource("3_wnv85")] +position = Vector2(0, 10) +combat_stats = SubResource("Resource_5fm47") +actions = Array[Resource("res://systems/combat/combat_action.gd")]([SubResource("Resource_pwlmc")]) diff --git a/systems/combat/combat_action.gd b/systems/combat/combat_action.gd index 87afb18..31abf07 100644 --- a/systems/combat/combat_action.gd +++ b/systems/combat/combat_action.gd @@ -2,8 +2,14 @@ class_name CombatAction extends Resource +# The action's name +var name: String + # The character performing the action var source_actor: Combatant +func init(): + pass + func execute(): push_warning("Default CombatAction::execute method called! This method should be overridden!") \ No newline at end of file diff --git a/systems/combat/combat_state.gd b/systems/combat/combat_state.gd index ccc74b1..89e6ea7 100644 --- a/systems/combat/combat_state.gd +++ b/systems/combat/combat_state.gd @@ -15,8 +15,6 @@ func state_enter(_params: Dictionary): defeated_teams.clear() - print("Combat started!") - combat_log = find_child("CombatLog") if !combat_log: push_warning("Combat Log not found!") @@ -27,9 +25,11 @@ func state_enter(_params: Dictionary): if teams.size() < 2: push_warning("Combat started with less than 2 teams!") - # Connect to all needed signals + # Connect to all needed signals and initialize the combatants for team in teams: for combatant in team.members: + combatant.init_combat() + if !combatant.damaged.is_connected(on_combatant_damaged): combatant.damaged.connect(on_combatant_damaged) @@ -42,7 +42,7 @@ func state_process(delta): # Tick all of the teams for team in teams: - team.tick_atb(delta) + team.process_tick(delta) action_queue.append_array(team.get_ready_actions()) # TODO: Execute all ready actions diff --git a/systems/combat/combat_team.gd b/systems/combat/combat_team.gd index 7b9d99b..54f5c9c 100644 --- a/systems/combat/combat_team.gd +++ b/systems/combat/combat_team.gd @@ -26,9 +26,9 @@ func is_defeated(): return true -func tick_atb(delta): +func process_tick(delta): for combatant in members: - combatant.tick_atb(delta) + combatant.process_tick(delta, self) func get_ready_actions(): return action_queue diff --git a/systems/combat/combatant.gd b/systems/combat/combatant.gd deleted file mode 100644 index c65e078..0000000 --- a/systems/combat/combatant.gd +++ /dev/null @@ -1,53 +0,0 @@ - -class_name Combatant -extends Node - -## This class/component represents anything that can particpate in combat -## -## This class is responsible for things like combat animations, -## tracking combat stats, executing combat actions, etc. -## Anything that can take a turn in combat needs to use this component: -## Player characters, enemys, allies, neutral units, etc. - -signal damaged(damaged_combatant: Combatant, source: DamageSource, final_amount: int) - -@export var combat_stats: CombatStats -@export var actions: Array[CombatAction] = [] - -# current state -var hp: int = 0 # Health Points -var ps: int = 0 # Physical Stamina -var ms: int = 0 # Mental Stamina -var atb: float = 0 # ATB Timer - counts down, turn is ready at 0 - -func is_defeated(): - - # TODO: add checks for status conditions - # that cause this combantant to be - # considered defeated (like stone) - return hp <= 0 - -func is_turn_ready(): - return atb <= 0 - -func tick_atb(delta): - if atb <= 0: - return - - atb -= delta - -func take_damage(source: DamageSource): - - # TODO: Apply stats and status to adjust the incoming damage amount - - var final_amount = source.amount - - if source.element == DamageSource.Element.PHYSICAL: - final_amount -= combat_stats.constitution - - if source.type == DamageSource.Type.MAGIC: - final_amount -= combat_stats.willpower - - hp -= final_amount - - damaged.emit(self, source, final_amount) \ No newline at end of file diff --git a/systems/combat/combatant/combatant.gd b/systems/combat/combatant/combatant.gd new file mode 100644 index 0000000..7cee394 --- /dev/null +++ b/systems/combat/combatant/combatant.gd @@ -0,0 +1,67 @@ + +class_name Combatant +extends Node2D + +## This class/component represents anything that can particpate in combat +## +## This class is responsible for things like combat animations, +## tracking combat stats, executing combat actions, etc. +## Anything that can take a turn in combat needs to use this component: +## Player characters, enemys, allies, neutral units, etc. + +signal damaged(damaged_combatant: Combatant, source: DamageSource, final_amount: int) + +@export var combat_stats: CombatStats +@export var actions: Array[CombatAction] = [] +@export var is_player_driven = true + +var next_action: CombatAction = null + +# current state +var hp: int = 0 # Health Points +var ps: int = 0 # Physical Stamina +var ms: int = 0 # Mental Stamina +var atb: float = 0 # ATB Timer - counts down, turn is ready at 0 + +func init_combat(): + print("Initing Combatant") + + if !is_player_driven: + $"Combat Menu".visible = false + pass + +func is_defeated(): + + # TODO: add checks for status conditions + # that cause this combantant to be + # considered defeated (like stone) + return hp <= 0 + +func is_turn_ready(): + return atb <= 0 + +func process_tick(delta, _team: CombatTeam): + if atb > 0: + atb -= delta + + # TODO: handle input + + +func take_damage(source: DamageSource): + + # TODO: Apply stats and status to adjust the incoming damage amount + + var final_amount = source.amount + + if source.element == DamageSource.Element.PHYSICAL: + final_amount -= combat_stats.constitution + + if source.type == DamageSource.Type.MAGIC: + final_amount -= combat_stats.willpower + + hp -= final_amount + + damaged.emit(self, source, final_amount) + +func on_action_clicked(btn): + print("Action Clicked: %s" % btn.text) diff --git a/systems/combat/combatant/combatant.tscn b/systems/combat/combatant/combatant.tscn new file mode 100644 index 0000000..953c56a --- /dev/null +++ b/systems/combat/combatant/combatant.tscn @@ -0,0 +1,38 @@ +[gd_scene load_steps=2 format=3 uid="uid://4glu7reewmf3"] + +[ext_resource type="Script" path="res://systems/combat/combatant/combatant.gd" id="1_7ynxf"] + +[node name="Combatant" type="Node2D"] +script = ExtResource("1_7ynxf") + +[node name="Combat Menu" type="Control" parent="."] +texture_filter = 2 +layout_mode = 3 +anchors_preset = 0 +offset_right = 40.0 +offset_bottom = 40.0 + +[node name="PanelContainer" type="PanelContainer" parent="Combat Menu"] +layout_mode = 2 +offset_right = 44.0 +offset_bottom = 48.0 + +[node name="MarginContainer" type="MarginContainer" parent="Combat Menu/PanelContainer"] +layout_mode = 2 +theme_override_constants/margin_left = 2 +theme_override_constants/margin_top = 2 +theme_override_constants/margin_right = 2 +theme_override_constants/margin_bottom = 2 + +[node name="VBoxContainer" type="VBoxContainer" parent="Combat Menu/PanelContainer/MarginContainer"] +layout_mode = 2 + +[node name="BtnAttack" type="Button" parent="Combat Menu/PanelContainer/MarginContainer/VBoxContainer"] +layout_mode = 2 +theme_override_font_sizes/font_size = 10 +text = "Attack" + +[node name="BtnDefend" type="Button" parent="Combat Menu/PanelContainer/MarginContainer/VBoxContainer"] +layout_mode = 2 +theme_override_font_sizes/font_size = 10 +text = "Defend" diff --git a/systems/combat/common actions/action_attack.gd b/systems/combat/common actions/action_attack.gd index 0bf9326..ee091e7 100644 --- a/systems/combat/common actions/action_attack.gd +++ b/systems/combat/common actions/action_attack.gd @@ -5,5 +5,9 @@ extends CombatAction var target: Combatant var damage: DamageSource +func init(): + print("Setting action name") + name = "Attack" + func execute(): target.take_damage(damage) \ No newline at end of file diff --git a/systems/combat/ui/combat_log.gd b/systems/combat/ui/combat_log.gd index 3971d6a..72a18f7 100644 --- a/systems/combat/ui/combat_log.gd +++ b/systems/combat/ui/combat_log.gd @@ -18,11 +18,13 @@ func _ready(): func on_timeout(): history.append(log_label.text) log_label.text = "" + $PanelContainer.visible = false timer.stop() func push_message(msg: String): if !timer.is_stopped(): on_timeout() + $PanelContainer.visible = true log_label.text = msg timer.start(5.0) diff --git a/testing/sandbox.tscn b/testing/sandbox.tscn index 6a4f414..bef82b2 100644 --- a/testing/sandbox.tscn +++ b/testing/sandbox.tscn @@ -12603,7 +12603,9 @@ offset_bottom = 656.0 [node name="Alex" parent="." instance=ExtResource("7_c3ubv")] texture_filter = 1 position = Vector2(505, 516) -scale = Vector2(2, 2) [node name="Blob" parent="." instance=ExtResource("8_vcyws")] position = Vector2(417, 513) + +[node name="Camera2D" type="Camera2D" parent="."] +position = Vector2(642, 362)