Good place

This commit is contained in:
gamer147
2026-04-08 07:09:24 -04:00
parent e42a98fece
commit 92a0bb1d58
7 changed files with 47 additions and 94 deletions

View File

@@ -111,27 +111,15 @@ func select_ai_tactic(unit: Unit, opponent: Unit, available_tactics: Array[Comba
return best_tactic
func process_combat(attacker: Unit, defender: Unit, distance: int) -> void:
if not attacker.is_alive() or not defender.is_alive():
return
var proposal := create_proposal(attacker, defender, distance)
var atk_name := attacker.current_info.name
var def_name := defender.current_info.name
print("=== Combat: %s vs %s ===" % [atk_name, def_name])
print(" %s — HP:%d ATK:%d DEF:%d HIT:%d" % [atk_name, proposal.attacker.hp, proposal.attacker.atk, proposal.attacker.def, proposal.attacker.hit])
print(" %s — HP:%d ATK:%d DEF:%d HIT:%d" % [def_name, proposal.defender.hp, proposal.defender.atk, proposal.defender.def, proposal.defender.hit])
apply_proposal(proposal)
var atk_hp := attacker.current_stats.current_hp if is_instance_valid(attacker) else 0
var def_hp := defender.current_stats.current_hp if is_instance_valid(defender) else 0
print(" Result: %s HP=%d, %s HP=%d" % [atk_name, atk_hp, def_name, def_hp])
func apply_proposal(proposal: CombatProposal) -> void:
var atk_stats := proposal.attacker
var def_stats := proposal.defender
var atk_unit := atk_stats.unit
var def_unit := def_stats.unit
if not is_instance_valid(atk_unit) or not is_instance_valid(def_unit):
return
# Attacker strikes (if their tactic deals damage)
if atk_stats.selected_tactic and atk_stats.selected_tactic.deals_damage():
var atk_roll := randi_range(1, 100)
@@ -140,7 +128,9 @@ func apply_proposal(proposal: CombatProposal) -> void:
def_unit.take_damage(damage)
# Counterattack if defender survives and their tactic deals damage
if def_unit.is_alive() and def_stats.selected_tactic and def_stats.selected_tactic.deals_damage():
if is_instance_valid(def_unit) and def_unit.is_alive() \
and is_instance_valid(atk_unit) \
and def_stats.selected_tactic and def_stats.selected_tactic.deals_damage():
var def_roll := randi_range(1, 100)
if def_roll <= def_stats.hit:
var damage := maxi(def_stats.atk - atk_stats.def, 0)