﻿# Unique Artifacts+ on_actions.
# CK3 supports appending to vanilla on_actions through nested on_actions.
# Do NOT add effect/events blocks directly to existing vanilla on_action keys here: that conflicts with vanilla definitions.

on_artifact_changed_owner = {
	on_actions = { mar_celestial_tablet_artifact_changed_owner }
}

mar_celestial_tablet_artifact_changed_owner = {
	effect = {
		if = {
			limit = {
				has_variable = mar_celestial_tablet
				exists = scope:owner
			}
			scope:owner = {
				mar_handle_celestial_tablet_effect = yes
			}
		}
	}
}

on_government_change = {
	on_actions = { mar_celestial_tablet_government_changed }
}

mar_celestial_tablet_government_changed = {
	effect = {
		mar_handle_celestial_tablet_effect = yes
	}
}

# UA 1.22 dedicated RELIC acquisition.
# Standard pilgrimages attempt once on arrival; the destination pulse is a fallback.
# The activity variable prevents repeated rolls during the same pilgrimage.
pilgrimage_arrival_events = {
	on_actions = { mar_unique_artifacts_pilgrimage_relic_attempt }
}

pilgrimage_destination_events = {
	on_actions = { mar_unique_artifacts_pilgrimage_relic_attempt }
}

mar_unique_artifacts_pilgrimage_relic_attempt = {
	trigger = {
		exists = scope:activity
		scope:activity = { NOT = { has_variable = mar_unique_artifacts_relic_attempted } }
	}
	effect = {
		scope:activity = { set_variable = mar_unique_artifacts_relic_attempted }
		scope:activity.activity_location = { save_scope_as = location }
		if = {
			limit = { mar_has_available_relic_artifact_trigger = yes }
			random = {
				chance = 15
				mar_create_random_relic_artifact_effect = { OWNER = root }
			}
		}
	}
}

# UA 1.22 dedicated OCCULT acquisition: a rare outcome of vanilla Mystical Communion.
mystic_communion_side_effect_events = {
	on_actions = { mar_unique_artifacts_mystic_communion_occult }
}

mar_unique_artifacts_mystic_communion_occult = {
	effect = {
		root.location = { save_scope_as = location }
		if = {
			limit = { mar_has_available_occult_artifact_trigger = yes }
			random = {
				chance = 10
				mar_create_random_occult_artifact_effect = { OWNER = root }
			}
		}
	}
}
