Adds monster and start of combat menu

combat_refactor
Joey Pollack 1 year ago
parent 8c835b408a
commit dcb3966d54

@ -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

@ -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")])

@ -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!")

@ -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

@ -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

@ -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)

@ -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)

@ -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"

@ -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)

@ -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)

@ -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)

Loading…
Cancel
Save