Add event AI target priority shifts
This commit is contained in:
@@ -3696,6 +3696,8 @@ func _execute_event_action(action: Dictionary, trigger_unit: Dictionary = {}) ->
|
||||
return
|
||||
for unit_id in unit_ids:
|
||||
_withdraw_event_unit(str(unit_id))
|
||||
elif action_type == "set_ai_target_priority":
|
||||
_set_event_ai_target_priority(action)
|
||||
|
||||
|
||||
func _grant_event_items(item_entries, trigger_unit: Dictionary = {}) -> void:
|
||||
@@ -3730,6 +3732,52 @@ func _grant_event_item(action: Dictionary, trigger_unit: Dictionary = {}) -> boo
|
||||
return true
|
||||
|
||||
|
||||
func _set_event_ai_target_priority(action: Dictionary) -> void:
|
||||
var unit_ids := _event_action_unit_ids(action)
|
||||
if unit_ids.is_empty():
|
||||
push_error("Skipping AI target priority event with no unit ids in %s." % battle_id)
|
||||
return
|
||||
var priority := clampi(int(action.get("priority", 0)), 0, 20)
|
||||
for unit_id in unit_ids:
|
||||
var unit := get_unit(unit_id)
|
||||
if unit.is_empty():
|
||||
push_error("Skipping unknown AI target priority unit %s in %s." % [unit_id, battle_id])
|
||||
continue
|
||||
var previous_priority := int(unit.get("ai_target_priority", 0))
|
||||
unit["ai_target_priority"] = priority
|
||||
if bool(action.get("silent", false)):
|
||||
continue
|
||||
_emit_ai_target_priority_feedback(unit, previous_priority, priority, str(action.get("text", "")))
|
||||
_notify_changed()
|
||||
|
||||
|
||||
func _event_action_unit_ids(action: Dictionary) -> Array[String]:
|
||||
var result: Array[String] = []
|
||||
if action.has("unit_ids") and typeof(action["unit_ids"]) == TYPE_ARRAY:
|
||||
for unit_id in action["unit_ids"]:
|
||||
var unit_id_text := str(unit_id).strip_edges()
|
||||
if not unit_id_text.is_empty() and not result.has(unit_id_text):
|
||||
result.append(unit_id_text)
|
||||
else:
|
||||
var unit_id_text := str(action.get("unit_id", action.get("id", ""))).strip_edges()
|
||||
if not unit_id_text.is_empty():
|
||||
result.append(unit_id_text)
|
||||
return result
|
||||
|
||||
|
||||
func _emit_ai_target_priority_feedback(unit: Dictionary, previous_priority: int, priority: int, text: String = "") -> void:
|
||||
if text.is_empty():
|
||||
if priority > previous_priority:
|
||||
text = "%s is exposed to enemy focus." % str(unit.get("name", "Unit"))
|
||||
elif priority < previous_priority:
|
||||
text = "%s is less exposed to enemy focus." % str(unit.get("name", "Unit"))
|
||||
else:
|
||||
text = "%s remains an enemy priority." % str(unit.get("name", "Unit"))
|
||||
_emit_log(text)
|
||||
if bool(unit.get("alive", false)) and bool(unit.get("deployed", true)):
|
||||
_emit_combat_feedback(unit, "TARGET", "priority")
|
||||
|
||||
|
||||
func _apply_objective_event(action: Dictionary) -> void:
|
||||
var updated := false
|
||||
var updated_victory := ""
|
||||
|
||||
Reference in New Issue
Block a user