Add event inventory pickups
This commit is contained in:
@@ -2776,7 +2776,7 @@ func _run_events(trigger_type: String, team := "", turn := -1, trigger_unit: Dic
|
||||
continue
|
||||
if not _campaign_flags_match(when.get("campaign_flags", {})):
|
||||
continue
|
||||
_execute_event_actions(event.get("actions", []))
|
||||
_execute_event_actions(event.get("actions", []), trigger_unit)
|
||||
if bool(event.get("once", false)) and not event_id.is_empty():
|
||||
fired_event_ids[event_id] = true
|
||||
_check_battle_status()
|
||||
@@ -2807,14 +2807,14 @@ func _campaign_flags_match(required_flags) -> bool:
|
||||
return true
|
||||
|
||||
|
||||
func _execute_event_actions(actions: Array) -> void:
|
||||
func _execute_event_actions(actions: Array, trigger_unit: Dictionary = {}) -> void:
|
||||
for action in actions:
|
||||
if typeof(action) != TYPE_DICTIONARY:
|
||||
continue
|
||||
_execute_event_action(action)
|
||||
_execute_event_action(action, trigger_unit)
|
||||
|
||||
|
||||
func _execute_event_action(action: Dictionary) -> void:
|
||||
func _execute_event_action(action: Dictionary, trigger_unit: Dictionary = {}) -> void:
|
||||
var action_type := str(action.get("type", ""))
|
||||
if action_type == "log":
|
||||
_emit_log(str(action.get("text", "")))
|
||||
@@ -2824,6 +2824,10 @@ func _execute_event_action(action: Dictionary) -> void:
|
||||
dialogue_requested.emit(lines)
|
||||
elif action_type == "set_objective":
|
||||
_apply_objective_event(action)
|
||||
elif action_type == "grant_item":
|
||||
_grant_event_item(action, trigger_unit)
|
||||
elif action_type == "grant_items":
|
||||
_grant_event_items(action.get("items", []), trigger_unit)
|
||||
elif action_type == "spawn_deployment":
|
||||
_spawn_event_deployment(action.get("deployment", {}))
|
||||
elif action_type == "spawn_deployments":
|
||||
@@ -2835,6 +2839,38 @@ func _execute_event_action(action: Dictionary) -> void:
|
||||
_spawn_event_deployment(deployment)
|
||||
|
||||
|
||||
func _grant_event_items(item_entries, trigger_unit: Dictionary = {}) -> void:
|
||||
if typeof(item_entries) != TYPE_ARRAY:
|
||||
push_error("Skipping malformed event item grants in %s." % battle_id)
|
||||
return
|
||||
for entry in item_entries:
|
||||
if typeof(entry) == TYPE_STRING:
|
||||
_grant_event_item({"item_id": str(entry)}, trigger_unit)
|
||||
elif typeof(entry) == TYPE_DICTIONARY:
|
||||
_grant_event_item(entry, trigger_unit)
|
||||
else:
|
||||
push_error("Skipping malformed event item grant in %s." % battle_id)
|
||||
|
||||
|
||||
func _grant_event_item(action: Dictionary, trigger_unit: Dictionary = {}) -> bool:
|
||||
var item_id := str(action.get("item_id", action.get("id", ""))).strip_edges()
|
||||
if item_id.is_empty():
|
||||
push_error("Skipping event item grant with no item_id in %s." % battle_id)
|
||||
return false
|
||||
var item := get_item_def(item_id)
|
||||
if item.is_empty():
|
||||
push_error("Skipping unknown event item grant %s in %s." % [item_id, battle_id])
|
||||
return false
|
||||
var count: int = maxi(1, int(action.get("count", 1)))
|
||||
battle_inventory[item_id] = int(battle_inventory.get(item_id, 0)) + count
|
||||
var item_name: String = str(item.get("name", item_id))
|
||||
var count_text: String = "" if count == 1 else " x%d" % count
|
||||
_emit_log("Received %s%s." % [item_name, count_text])
|
||||
if not trigger_unit.is_empty() and bool(trigger_unit.get("alive", false)):
|
||||
_emit_combat_feedback(trigger_unit, "+%s" % item_name, "item")
|
||||
return true
|
||||
|
||||
|
||||
func _apply_objective_event(action: Dictionary) -> void:
|
||||
if action.has("victory"):
|
||||
objectives["victory"] = str(action["victory"])
|
||||
|
||||
Reference in New Issue
Block a user