Add unit defeat event reactions
This commit is contained in:
@@ -2957,6 +2957,7 @@ func _resolve_attack(attacker: Dictionary, target: Dictionary, is_counter := fal
|
||||
target["alive"] = false
|
||||
_emit_log("%s is defeated." % target["name"])
|
||||
_emit_combat_feedback(target, "DOWN", "defeat")
|
||||
_handle_unit_defeated(target)
|
||||
return {"hit": true, "defeated": true}
|
||||
return {"hit": true, "defeated": false}
|
||||
|
||||
@@ -2976,10 +2977,17 @@ func _resolve_skill_damage(caster: Dictionary, target: Dictionary, skill: Dictio
|
||||
target["alive"] = false
|
||||
_emit_log("%s is defeated." % target["name"])
|
||||
_emit_combat_feedback(target, "DOWN", "defeat")
|
||||
_handle_unit_defeated(target)
|
||||
return true
|
||||
return false
|
||||
|
||||
|
||||
func _handle_unit_defeated(unit: Dictionary) -> void:
|
||||
if unit.is_empty():
|
||||
return
|
||||
_run_events("unit_defeated", str(unit.get("team", "")), turn_number, unit)
|
||||
|
||||
|
||||
func _resolve_skill_heal(caster: Dictionary, target: Dictionary, skill: Dictionary) -> int:
|
||||
var healed := calculate_skill_heal(caster, target, skill)
|
||||
target["hp"] = min(int(target["max_hp"]), int(target["hp"]) + healed)
|
||||
@@ -3585,6 +3593,8 @@ func _run_events(trigger_type: String, team := "", turn := -1, trigger_unit: Dic
|
||||
continue
|
||||
if trigger_type == "unit_reaches_tile" and not _unit_reaches_event_tile(trigger_unit, when):
|
||||
continue
|
||||
if trigger_type == "unit_defeated" and not _unit_defeated_event_matches(trigger_unit, when):
|
||||
continue
|
||||
if not _event_gate_open(when):
|
||||
continue
|
||||
if not _campaign_flags_match(when.get("campaign_flags", {})):
|
||||
@@ -3606,6 +3616,12 @@ func _unit_reaches_event_tile(unit: Dictionary, when: Dictionary) -> bool:
|
||||
return _unit_matches_condition_ids(unit, when.get("unit_ids", []), when.get("officer_ids", []))
|
||||
|
||||
|
||||
func _unit_defeated_event_matches(unit: Dictionary, when: Dictionary) -> bool:
|
||||
if unit.is_empty() or not unit.get("deployed", true) or unit.get("alive", true):
|
||||
return false
|
||||
return _unit_matches_condition_ids(unit, when.get("unit_ids", []), when.get("officer_ids", []))
|
||||
|
||||
|
||||
func _event_gate_open(when: Dictionary) -> bool:
|
||||
var after_event := str(when.get("after_event", ""))
|
||||
if after_event.is_empty():
|
||||
@@ -3848,6 +3864,7 @@ func _apply_phase_status_effects_for_team(team: String) -> void:
|
||||
unit["alive"] = false
|
||||
_emit_log("%s is defeated by %s." % [unit["name"], status.replace("_", " ")])
|
||||
_emit_combat_feedback(unit, "DOWN", "defeat")
|
||||
_handle_unit_defeated(unit)
|
||||
break
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user