# Supported types:
# character, spouse, rivals, friends, liege_titles, vassal_titles, realm_titles, realm_characters, realm_characters_plus, independent_rulers

###############
# AMBITIONS
###############

# Strengthen Religion
obj_strengthen_religion = {
	type = character

	potential = {
		has_dlc = "Jade Dragon"
		independent = yes
		is_landed = yes
		higher_tier_than = BARON
		is_nomadic = no
		is_adult = yes
		has_secret_religion = no
		is_devil_worshiper_trigger = no
		is_inaccessible_trigger = no
		is_incapable = no

		NOR = {
			has_character_flag = strengthened_religion
			religion_authority >= 0.30
		}
	}

	creation_effect = {
		change_variable = {
			which = strengthen_religion
			value = 0
		}

		random_list = {
			150 = { # No Opportunity
				set_character_flag = had_ambition_opportunity_chance
			}

			50 = { # Liberate Opportunity
				trigger = {
					mercenary = no
					pacifist = no

					NOR = {
						trait = cynical
						has_character_flag = had_liberate_opportunity
						has_character_flag = had_ambition_opportunity_chance
					}

					any_neighbor_independent_ruler = {								# You need to neighbour a ruler
						NOT = { religion = ROOT }									# ... who is NOT of your religion

						any_realm_province = {										# ... and has any province in their realm...
							held_under_PREV = yes
							religion = ROOT											# ... that is of your religion...

							kingdom = {												# ... and a De Jure part of a Kingdom, created or not...
								any_de_jure_vassal_title = {						# ... which contains any title...
									tier = COUNT									# ... of Count tier...

									holder_scope = {								# ... that is in the same realm as the Top Liege of the neighbor
										same_realm = PREVPREVPREVPREV				# ... Province's holder...
									}

									location = {									# ... and where the associated province...
										any_neighbor_province = {					# ... has a neighboring province...
											owner = {								# ... whose holder...
												top_liege = {						# ... has a Top Liege...
													character = ROOT				# ... who is you!
												}
											}
										}
									}
								}
							}
						}
					}
				}

				mult_modifier = {
					trait = zealous
					factor = 5
				}

				mult_modifier = {
					has_focus = focus_theology
					factor = 2
				}

				character_event = {
					id = JD.2100
					days = 14
					random = 14
				}

				set_character_flag = had_ambition_opportunity_chance
			}
		}
	}

	success = {
		custom_tooltip = {
			text = tooltip_obj_strengthen_religion

			check_variable = {
				which = strengthen_religion
				value = 3
			}
		}
	}

	effect = {
		set_character_flag = strengthened_religion
		piety = 100

		religion_authority = {
			name = strengthened_religion
			years = 50
		}

		add_character_modifier = {
			name = strengthen_religion_ambition
			years = 30
		}
	}

	abort = {
		religion_authority >= 0.50
	}

	chance = {
		factor = 50

		mult_modifier = {
			factor = 0.1
			lower_real_tier_than = KING
		}

		mult_modifier = {
			factor = 10.0
			has_education_learning_trigger = yes
		}

		mult_modifier = {
			factor = 10.0
			trait = zealous
		}

		mult_modifier = {
			factor = 0.01
			trait = cynical
		}
	}
}