Combat tactics

This commit is contained in:
gamer147
2026-04-04 12:27:35 -04:00
parent 595e389033
commit 68d1406632
22 changed files with 1094 additions and 33 deletions

View File

@@ -23,15 +23,20 @@ signal fight_cancelled
@onready var def_spd_label: Label = %DefenderSPDLabel
@onready var fight_button: Button = %FightButton
@onready var cancel_button: Button = %CancelButton
@onready var atk_tactic_select: OptionButton = %AttackerTacticSelect
@onready var def_tactic_select: OptionButton = %DefenderTacticSelect
var _selected_unit: Unit
var _current_proposal: CombatProposal
var combat_system: CombatSystem
func _ready() -> void:
unit_panel.visible = false
proposal_panel.visible = false
fight_button.pressed.connect(_on_fight_pressed)
cancel_button.pressed.connect(_on_cancel_pressed)
atk_tactic_select.item_selected.connect(_on_atk_tactic_selected)
def_tactic_select.item_selected.connect(_on_def_tactic_selected)
for unit: Unit in get_tree().get_nodes_in_group("units"):
unit.unit_selected_changed.connect(_on_unit_selected_changed)
unit.unit_died.connect(_on_unit_died)
@@ -76,22 +81,9 @@ func _on_unit_selected_changed(unit: Unit, selected: bool) -> void:
func show_proposal(proposal: CombatProposal) -> void:
_current_proposal = proposal
var atk := proposal.attacker
var def := proposal.defender
atk_name_label.text = atk.unit.current_info.name
atk_hp_bar.max_value = atk.max_hp
atk_hp_bar.value = atk.hp
atk_atk_label.text = "ATK: %d" % atk.atk
atk_def_label.text = "DEF: %d" % atk.def
atk_hit_label.text = "HIT: %d%%" % atk.hit
atk_spd_label.text = "SPD: %d" % atk.spd
def_name_label.text = def.unit.current_info.name
def_hp_bar.max_value = def.max_hp
def_hp_bar.value = def.hp
def_atk_label.text = "ATK: %d" % def.atk
def_def_label.text = "DEF: %d" % def.def
def_hit_label.text = "HIT: %d%%" % def.hit
def_spd_label.text = "SPD: %d" % def.spd
_populate_tactic_select(atk_tactic_select, proposal.attacker)
_populate_tactic_select(def_tactic_select, proposal.defender)
_refresh_stats()
background_tint.visible = true
proposal_panel.visible = true
@@ -109,3 +101,51 @@ func _on_fight_pressed() -> void:
func _on_cancel_pressed() -> void:
_hide_proposal()
fight_cancelled.emit()
func _populate_tactic_select(button: OptionButton, combatant: CombatProposal.CombatantStats) -> void:
button.clear()
var selected_idx := 0
for i in combatant.available_tactics.size():
var tactic := combatant.available_tactics[i]
button.add_item(tactic.tactic_name)
if tactic == combatant.selected_tactic:
selected_idx = i
button.selected = selected_idx
var is_player := combatant.unit.current_allegiance.type == UnitAllegiance.AllegianceType.PLAYER
button.disabled = not is_player
func _refresh_stats() -> void:
var atk := _current_proposal.attacker
var def := _current_proposal.defender
atk_name_label.text = atk.unit.current_info.name
atk_hp_bar.max_value = atk.max_hp
atk_hp_bar.value = atk.hp
atk_atk_label.text = "ATK: %d" % atk.atk
atk_def_label.text = "DEF: %d" % atk.def
atk_hit_label.text = "HIT: %d%%" % atk.hit
atk_spd_label.text = "SPD: %d" % atk.spd
def_name_label.text = def.unit.current_info.name
def_hp_bar.max_value = def.max_hp
def_hp_bar.value = def.hp
def_atk_label.text = "ATK: %d" % def.atk
def_def_label.text = "DEF: %d" % def.def
def_hit_label.text = "HIT: %d%%" % def.hit
def_spd_label.text = "SPD: %d" % def.spd
func _on_atk_tactic_selected(index: int) -> void:
if not _current_proposal or not combat_system:
return
var tactic := _current_proposal.attacker.available_tactics[index]
combat_system.update_tactic(_current_proposal, true, tactic)
_refresh_stats()
func _on_def_tactic_selected(index: int) -> void:
if not _current_proposal or not combat_system:
return
var tactic := _current_proposal.defender.available_tactics[index]
combat_system.update_tactic(_current_proposal, false, tactic)
_refresh_stats()