Show physical threat damage hints
This commit is contained in:
@@ -1336,6 +1336,40 @@ func get_threatening_unit_names(cell: Vector2i, source_team := TEAM_ENEMY) -> Ar
|
||||
return result
|
||||
|
||||
|
||||
func get_physical_threat_previews(cell: Vector2i, source_team := TEAM_ENEMY) -> Array[Dictionary]:
|
||||
var result: Array[Dictionary] = []
|
||||
if not is_inside(cell):
|
||||
return result
|
||||
var target := get_unit_at(cell)
|
||||
if target.is_empty() or target.get("team", "") == source_team:
|
||||
return result
|
||||
|
||||
for unit in get_living_units(source_team):
|
||||
if not _unit_physical_threat_cells(unit).has(cell):
|
||||
continue
|
||||
var damage := calculate_damage(unit, target)
|
||||
var hit_chance := calculate_hit_chance(unit, target)
|
||||
var effective_bonus := _weapon_effectiveness_bonus(unit, target)
|
||||
result.append({
|
||||
"source_id": str(unit.get("id", "")),
|
||||
"source_name": str(unit.get("name", unit.get("id", "Unit"))),
|
||||
"damage": damage,
|
||||
"hit_chance": hit_chance,
|
||||
"target_hp_after": max(0, int(target.get("hp", 0)) - damage),
|
||||
"would_defeat": int(target.get("hp", 0)) - damage <= 0,
|
||||
"effective_bonus": effective_bonus,
|
||||
"effective_target_type": _weapon_effectiveness_target_type(target) if effective_bonus > 0 else ""
|
||||
})
|
||||
result.sort_custom(func(a: Dictionary, b: Dictionary) -> bool:
|
||||
if bool(a.get("would_defeat", false)) != bool(b.get("would_defeat", false)):
|
||||
return bool(a.get("would_defeat", false))
|
||||
if int(a.get("damage", 0)) != int(b.get("damage", 0)):
|
||||
return int(a.get("damage", 0)) > int(b.get("damage", 0))
|
||||
return str(a.get("source_name", "")) < str(b.get("source_name", ""))
|
||||
)
|
||||
return result
|
||||
|
||||
|
||||
func get_objective_cells() -> Array[Vector2i]:
|
||||
var result: Array[Vector2i] = []
|
||||
_collect_objective_cells(battle_conditions.get("victory", {}), result)
|
||||
|
||||
Reference in New Issue
Block a user