Good place
This commit is contained in:
@@ -74,9 +74,6 @@ func _apply_deploy(unit: Unit, coords: Vector2i) -> void:
|
||||
add_child(unit)
|
||||
|
||||
|
||||
func is_wall(coords: Vector2i) -> bool:
|
||||
return tile_map.get_cell_atlas_coords(coords) == tile_set.wall_tile_coords
|
||||
|
||||
func remove_unit(unit: Unit) -> void:
|
||||
if unit.get_parent() == self:
|
||||
remove_child(unit)
|
||||
@@ -95,17 +92,13 @@ func apply_layout(layout: MapLayout) -> void:
|
||||
|
||||
|
||||
func is_tile_passable(from: Vector2i, to: Vector2i) -> bool:
|
||||
if map_layout:
|
||||
return map_layout.is_passable(from, to)
|
||||
# Fallback: no room system, use legacy wall check
|
||||
return not is_wall(to)
|
||||
assert(map_layout != null, "CombatMap.is_tile_passable called before map_layout was set")
|
||||
return map_layout.is_passable(from, to)
|
||||
|
||||
|
||||
func is_tile_valid(coords: Vector2i) -> bool:
|
||||
if map_layout:
|
||||
return map_layout.is_tile_valid(coords)
|
||||
# Fallback: no room system, any non-wall tile is valid
|
||||
return not is_wall(coords)
|
||||
assert(map_layout != null, "CombatMap.is_tile_valid called before map_layout was set")
|
||||
return map_layout.is_tile_valid(coords)
|
||||
|
||||
|
||||
func draw_room_walls() -> void:
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user