﻿namespace = COR_ceremony
#################################
#
# Coronation Ceremony Events
# 0001 - 0100 Core Events, Decision and Setup
# 0101 - 0200 Priest & Powerful Theocrat
# 0201 - 0300 Pope & Antipope
# 0301 - 0500 Coronation Activity Events
# 7001 - 7999 2.4 Jewel of Byzantium
# 9000 - 9999 Mechanical
# by Kaepora Gaebora
# 
#################################

# Explain coronation preparation, ask whom to ask to be crowned by.
COR_ceremony.0001 = {
	type = character_event
	title = COR_ceremony.0001.t
	desc = COR_ceremony.0001.desc
	theme = crown
	
	left_portrait = scope:COR_bishop
	lower_left_portrait = scope:COR_antipope
	right_portrait = scope:COR_priest
	lower_right_portrait = scope:COR_pope
	
	immediate = {
		##Set up some scopes we'll need
		save_scope_as = COR_ruler
		##Fetch valid coronators
		#Antipope
		if = {
			limit = {
				exists = global_var:Trinity_is_loaded
			}
			random_living_character = {
				limit = {
					is_available_healthy_ai_adult = yes
					has_trait = TCT_antipope
					top_liege = root
				}
				alternative_limit = {
					has_trait = TCT_antipope
					top_liege = root
				}
				alternative_limit = {
					is_available_healthy_ai_adult = yes
					has_trait = TCT_antipope
				}
				alternative_limit = {
					has_trait = TCT_antipope
				}
				save_scope_as = COR_antipope
			}
		}
		#Pope
		faith:catholic.religious_head = {
			save_scope_as = COR_pope
		}
		#Powerful Bishop
		if = { #Search for a valid cardinal first (TCT feature)
			limit = {
				exists = global_var:Trinity_is_loaded
			}
			random_living_cardinal = {
				limit = {
					is_available_healthy_ai_adult = yes
					faith = root.faith
					top_liege = root
				}
				save_scope_as = COR_bishop
			}
		}
		if = { #Grab random powerful theocrat
			limit = {
				NOT = { exists = scope:COR_bishop }
			}
			random_sub_realm_county = {
				limit = {
					any_county_province = {
						has_holding_type = church_holding
						barony = {
							exists = lessee
							lessee = {
								NOR = {
									AND = {
										exists = global_var:Trinity_is_loaded
										has_trait = TCT_antipope
									}
									this = scope:COR_pope
								}
								is_available_healthy_ai_adult = yes
								faith = root.faith
								is_landed = yes
								highest_held_title_tier >= tier_duchy
								save_temporary_scope_as = COR_bishop_temp
							}
						}
					}
				}
				alternative_limit = {
					any_county_province = {
						has_holding_type = church_holding
						barony = {
							exists = lessee
							lessee = {
								NOR = {
									AND = {
										exists = global_var:Trinity_is_loaded
										has_trait = TCT_antipope
									}
									this = scope:COR_pope
								}
								is_available_healthy_ai_adult = yes
								faith = root.faith
								is_landed = yes
								highest_held_title_tier >= tier_county
								save_temporary_scope_as = COR_bishop_temp
							}
						}
					}
				}
				scope:COR_bishop_temp = { save_scope_as = COR_bishop } #isn't there a better way?
			}
		}
		if = { #Pick court chaplain if we still have no valid theocrat
			limit = {
				NOT = { exists = scope:COR_bishop }
			}
			cp:councillor_court_chaplain = { save_scope_as = COR_bishop	}
		}
		#Priest
		random_sub_realm_county = {
			limit = {
				any_county_province = {
					has_holding_type = church_holding
					barony = {
						exists = lessee
						lessee = {
							is_available_healthy_ai_adult = yes
							faith = root.faith
							highest_held_title_tier <= tier_barony
							NOR = {
								AND = {
									exists = global_var:Trinity_is_loaded
									has_trait = TCT_antipope
								}
								this = scope:COR_pope
								this ?= scope:COR_bishop
								this = root.cp:councillor_court_chaplain
							}
							save_temporary_scope_as = COR_priest_temp
						}
					}
				}
			}
			scope:COR_priest_temp = { save_scope_as = COR_priest }
		}
		if = { #Pick vassal's court chaplain if we still have no valid priest
			limit = {
				NOT = { exists = scope:COR_priest }
			}
			random_vassal_or_below = {
				limit = {
					exists = cp:councillor_court_chaplain
					cp:councillor_court_chaplain = {
						is_available_adult = yes
						faith = root.faith
						NOR = {
							AND = {
								exists = global_var:Trinity_is_loaded
								has_trait = TCT_antipope
							}
							this = scope:COR_pope
							this ?= scope:COR_bishop
							this = root.cp:councillor_court_chaplain
						}
					}
				}
				cp:councillor_court_chaplain = {
					save_scope_as = COR_priest
				}
			}
		}
	}

	option = { #Ask to be crowned by the Antipope (TCT feature)
		name = COR_ceremony.0001.a
		trigger = {
			exists = scope:COR_antipope
		}
		add_internal_flag = dangerous
		custom_tooltip = COR_ceremony.0001.a.tt

		#TODO TCT catalyst
		set_variable = {
			name = COR_coronator_rank
			value = 1
		}
		scope:COR_antipope = {
			trigger_event = {
				id = COR_ceremony.0201
				days = 30
			}
		}
		scope:COR_pope = {
			add_opinion = {
				target = root
				modifier = angry_opinion
				opinion = -60
			}
		}

		ai_chance = {
			base = 30
			modifier = {
				highest_held_title_tier = tier_empire
				add = 40
			}
			modifier = {
				scope:COR_pope = {
					save_temporary_opinion_value_as = {
						name = COR_popinion
						target = scope:COR_ruler
					}
				}
				scope:COR_antipope = {
					opinion = {
						target = scope:COR_ruler
						value >= scope:COR_popinion
					}
				}
				factor = 2
			}
			modifier = {
				scope:COR_antipope = {
					opinion = {
						target = scope:COR_ruler
						value < very_high_negative_opinion
					}
				}
				factor = 0.1
			}
			modifier = {
				scope:COR_antipope = {
					opinion = {
						target = scope:COR_ruler
						value < high_negative_opinion
					}
				}
				factor = 0.25
			}
			modifier = {
				scope:COR_antipope = {
					opinion = {
						target = scope:COR_ruler
						value < medium_negative_opinion
					}
				}
				factor = 0.5
			}
			modifier = {
				scope:COR_antipope = {
					opinion = {
						target = scope:COR_ruler
						value < low_negative_opinion
					}
				}
				factor = 0.7
			}
			modifier = {
				scope:COR_antipope = {
					opinion = {
						target = scope:COR_ruler
						value <= neutral_opinion
					}
				}
				factor = 0.8
			}
			modifier = {
				scope:COR_antipope = {
					opinion = {
						target = scope:COR_ruler
						value > neutral_opinion
					}
				}
				factor = 1.25
			}
			modifier = {
				scope:COR_antipope = {
					opinion = {
						target = scope:COR_ruler
						value > low_positive_opinion
					}
				}
				factor = 1.25
			}
			modifier = {
				scope:COR_antipope = {
					opinion = {
						target = scope:COR_ruler
						value > medium_positive_opinion
					}
				}
				factor = 1.5
			}
			modifier = {
				scope:COR_antipope = {
					opinion = {
						target = scope:COR_ruler
						value > high_positive_opinion
					}
				}
				factor = 1.75
			}
			modifier = {
				scope:COR_antipope = {
					opinion = {
						target = scope:COR_ruler
						value > very_high_positive_opinion
					}
				}
				factor = 2
			}
			modifier = {
				this = character:1316
				has_realm_law_flag = free_enacted
				add = 1000
			}
		}
	}

	option = { #Ask to be crowned by the Pope
		name = COR_ceremony.0001.b
		trigger = {
			NOT = { has_trait = excommunicated }
			exists = scope:COR_pope
		}
		custom_tooltip = COR_ceremony.0001.b.tt

		set_variable = {
			name = COR_coronator_rank
			value = 1
		}
		scope:COR_pope = {
			trigger_event = {
				id = COR_ceremony.0201
				days = 30
			}
		}

		ai_chance = {
			base = 20
			modifier = {
				highest_held_title_tier = tier_empire
				add = 50
			}
			modifier = {
				scope:COR_pope = {
					opinion = {
						target = scope:COR_ruler
						value <= very_high_negative_opinion
					}
				}
				factor = 0.1
			}
			modifier = {
				scope:COR_pope = {
					opinion = {
						target = scope:COR_ruler
						value < high_negative_opinion
					}
				}
				factor = 0.25
			}
			modifier = {
				scope:COR_pope = {
					opinion = {
						target = scope:COR_ruler
						value < medium_negative_opinion
					}
				}
				factor = 0.5
			}
			modifier = {
				scope:COR_pope = {
					opinion = {
						target = scope:COR_ruler
						value < low_negative_opinion
					}
				}
				factor = 0.7
			}
			modifier = {
				scope:COR_pope = {
					opinion = {
						target = scope:COR_ruler
						value < neutral_opinion
					}
				}
				factor = 0.8
			}
			modifier = {
				scope:COR_pope = {
					opinion = {
						target = scope:COR_ruler
						value > medium_positive_opinion
					}
				}
				factor = 1.25
			}
			modifier = {
				scope:COR_pope = {
					opinion = {
						target = scope:COR_ruler
						value > very_high_positive_opinion
					}
				}
				factor = 1.25
			}
			modifier = {
				scope:COR_pope = {
					has_opinion_modifier = {
						modifier = COR_opinion_requested_papal_investiture
						target = scope:COR_ruler
					}
				}
				factor = 0.1
			}
			modifier = {
				this = character:1316
				has_realm_law_flag = free_enacted
				factor = 0
			}
			modifier = {
				NOT = { highest_held_title_tier = tier_empire }
				capital_province = {
					NOR = {
						geographical_region = world_europe_west_germania
						geographical_region = world_europe_west_francia
						geographical_region = world_europe_south_italy
					}
				}
				factor = 0.5
			}
		}
	}

	option = { #Invested by powerful Bishop
		name = COR_ceremony.0001.c
		trigger = {
			NOT = { has_trait = excommunicated }
			OR = {
				AND = {
					HRT_is_emperor_trigger = no
					highest_held_title_tier < tier_empire
				}
				AND = {
					OR = {
						HRT_is_emperor_trigger = yes
						highest_held_title_tier = tier_empire
					}
					has_realm_law_flag = free_enacted
				}
			}
			exists = scope:COR_bishop
		}
		custom_tooltip = COR_ceremony.0001.c.tt

		if = { #If Pope is available but he's snubbed by an Emperor, he'll get mad.
			limit = {
				highest_held_title_tier = tier_empire
			}
			custom_tooltip = COR_ceremony.0001.c.offended_the_pope

			scope:COR_pope = {
				add_opinion = {
					target = root
					modifier = angry_opinion
					opinion = -30
				}
			}
		}
		set_variable = {
			name = COR_coronator_rank
			value = 0
		}
		scope:COR_bishop = {
			trigger_event = {
				id = COR_ceremony.0101
				days = 30
			}
		}

		ai_chance = {
			base = 80
			modifier = {
				highest_held_title_tier = tier_empire
				add = -50
			}
			modifier = {
				this = character:1316
				has_realm_law_flag = free_enacted
				factor = 0
			}
			modifier = {
				capital_province = {
					geographical_region = world_europe_north
				}
				factor = 0.5
			}
		}
	}
	option = { #Invested by random priest
		add_internal_flag = dangerous
		name = COR_ceremony.0001.d
		trigger = {
			OR = {
				AND = {
					HRT_is_emperor_trigger = no
					highest_held_title_tier < tier_empire
				}
				AND = {
					OR = {
						HRT_is_emperor_trigger = yes
						highest_held_title_tier = tier_empire
					}
					has_realm_law_flag = free_enacted
				}
			}
			exists = scope:COR_priest
		}
		custom_tooltip = COR_ceremony.0001.d.tt

		if = { #Emperors not crowned by Pope or Antipope receive an additional penalty
			limit = {
				highest_held_title_tier = tier_empire
				exists = scope:COR_bishop
			}
			custom_tooltip = COR_ceremony.0001.d.offended_everyone
			add_prestige = major_prestige_loss
			add_piety = medium_piety_loss
			scope:COR_pope = { #If Pope is available but he's snubbed by an Emperor, he'll get mad.
				add_opinion = {
					target = root
					modifier = angry_opinion
					opinion = -30
				}
			}
			every_theocratic_vassal = { #If powerful theocrats are available but player picks random priest, the other theocrats will be mad.
				limit = {
					faith = root.faith
					NOR = {
						this = scope:COR_pope
						this = scope:COR_priest
						this = root.cp:councillor_court_chaplain
					}
				}
				add_opinion = {
					target = root
					modifier = angry_opinion
					opinion = -10
				}
			}
			cp:councillor_court_chaplain = {
				if = {
					limit = {
						NOT = { this = scope:COR_priest }
					}
					add_opinion = {
						target = root
						modifier = angry_opinion
						opinion = -10
					}
				}
			}
		}
		else_if = { #If powerful theocrats are available but player picks random priest, the other theocrats will be mad.
			limit = {
				highest_held_title_tier < tier_empire
				NOT = { has_trait = excommunicated }
				exists = scope:COR_bishop
			}
			custom_tooltip = COR_ceremony.0001.d.offended_powerful_theocrats

			every_theocratic_vassal = {
				limit = {
					faith = root.faith
					NOR = {
						this = scope:COR_priest
						this = root.cp:councillor_court_chaplain
					}
				}
				add_opinion = {
					target = root
					modifier = angry_opinion
					opinion = -10
				}
			}
			cp:councillor_court_chaplain = {
				if = {
					limit = {
						NOT = { this = scope:COR_priest }
					}
					add_opinion = {
						target = root
						modifier = angry_opinion
						opinion = -10
					}
				}
			}
		}
		#scope:COR_priest = {
		#	trigger_event = {
		#		id = COR_ceremony.0101
		#		days = 30
		#	}
		#}

		remove_short_term_gold = COR_skip_activity_cost

		switch = {
			trigger = has_trait
			COR_crowned_by_priest = { remove_trait = COR_crowned_by_priest }
			COR_crowned_by_bishop = { remove_trait = COR_crowned_by_bishop }
			COR_crowned_by_pope = { remove_trait = COR_crowned_by_pope }
			COR_crowned_by_myself = { remove_trait = COR_crowned_by_myself }
			HRT_emperor = { remove_trait = HRT_emperor }
			COR_byz_crowned_by_patriarch = { remove_trait = COR_byz_crowned_by_patriarch }
		}
		if = {
			limit = {
				OR = {
					has_title = title:e_hre
					HRT_is_emperor_trigger = yes
				}
			}
			add_trait = HRT_emperor
		}
		else = {
			add_trait = COR_crowned_by_priest
		}

		hidden_effect = {
			remove_character_flag = HRT_italienzug
			remove_character_flag = COR_flag_preparing_coronation
			remove_variable = COR_years_reigned
			remove_variable = COR_coronation_request_cooldown
			remove_variable = COR_coronator_rank
			remove_character_modifier ?= COR_uncrowned_modifier
			scope:COR_coronator ?= {
				remove_list_variable = {
					name = COR_coronation_targets
					target = scope:COR_ruler
				}
			}
			if = {
				limit = {
					NOT = { has_nickname = nick_the_crownless }
				}
				remove_character_flag = sold_crown_charmod
			}
			every_spouse = {
				limit = {
					NOT = { has_nickname = nick_the_crownless }
					has_character_flag = sold_crown_charmod
				}
				remove_character_flag = sold_crown_charmod
			}
		}

		ai_chance = {
			base = 10
			modifier = {
				has_trait = lazy
				factor = 1.5
			}
			modifier = {
				has_trait = shy
				factor = 1.5
			}
			modifier = {
				has_trait = content
				factor = 1.25
			}
			modifier = {
				has_trait = arrogant
				factor = 0.7
			}
			modifier = {
				has_trait = ambitious
				factor = 0.7
			}
			modifier = {
				highest_held_title_tier = tier_empire
				factor = 0.7
			}
			modifier = {
				OR = {
					has_title = title:e_hre
					HRT_is_emperor_trigger = yes
				}
				factor = 0.5
			}
			modifier = {
				gold < minor_gold_value
				add = 30
			}
			modifier = {
				this = character:1316
				has_realm_law_flag = free_enacted
				factor = 0
			}
			modifier = {
				capital_province = {
					geographical_region = world_europe_north
				}
				add = 50
			}
		}
	}

	option = { #Changed your mind, not yet.
		name = COR_ceremony.0001.e

		custom_tooltip = COR_ceremony.0001.e.tt

		hidden_effect = {
			remove_variable = COR_coronation_request_cooldown
		}

		ai_chance = {
			base = 0
			modifier = {
				this = character:1316
				has_realm_law_flag = free_enacted
				add = 10
			}
		}
	}
}

## Notify ruler of coronator's death ## Moved to Coronator Story
#COR_ceremony.0002 = {
#	hidden = yes
#	
#	trigger = {
#		has_variable_list = COR_coronation_targets
#	}
#	
#	immediate = {
#		every_in_list = {
#			variable = COR_coronation_targets
#			limit = {
#				is_alive = yes
#			}
#			trigger_event = COR_ceremony.0003
#		}
#	}
#}

COR_ceremony.0003 = {
	type = character_event
	title = COR_ceremony.0003.t
	desc = COR_ceremony.0003.desc
	theme = crown
	
	trigger = {
		has_variable = COR_coronator
	}
	
	right_portrait = {
		character = root
		animation = worry
	}
	lower_right_portrait = scope:COR_deceased
	
	immediate = {
		var:COR_coronator = {
			save_scope_as = COR_deceased
		}
	}
	
	option = {
		name = COR_ceremony.0003.a

		if = {
			limit = {
				NOR = {
					has_trait = COR_crowned_by_priest
					has_trait = COR_crowned_by_bishop
					has_trait = COR_crowned_by_pope
					has_trait = COR_crowned_by_myself
					has_trait = HRT_emperor
					has_trait = COR_byz_crowned_by_patriarch
				}
			}
			remove_variable = COR_coronator
		}
		remove_variable ?= COR_coronation_request_cooldown
		remove_character_flag ?= COR_flag_preparing_coronation
	}
}

## 0101 - 0200 Priest & Powerful Theocrat
# Letter event determining what the priest is going to ask from the King/Emperor in exchange for the Coronation.
COR_ceremony.0101 = {
	type = letter_event
	opening = COR_ceremony.0101.t
	desc = COR_ceremony.0101.desc
	sender = scope:COR_ruler

	immediate = { }

	option = { #For random priest
		name = COR_ceremony.0101.a
		trigger = {
			trigger_if = {
				limit = {
					exists = scope:COR_priest
				}
				root = scope:COR_priest
			}
		}
		save_scope_as = COR_coronator
		random_list = {
			50 = {
				desc = COR_ceremony.0101.a.nothing
				scope:COR_ruler = {
					trigger_event = COR_ceremony.0102 #Priest asks for nothing
				}
				modifier = {
					opinion = {
						target = scope:COR_ruler
						value < high_negative_opinion
					}
					factor = 0.1
				}
				modifier = {
					opinion = {
						target = scope:COR_ruler
						value < low_negative_opinion
					}
					factor = 0.25
				}
				modifier = {
					opinion = {
						target = scope:COR_ruler
						value < medium_negative_opinion
					}
					factor = 0.5
				}
				modifier = {
					opinion = {
						target = scope:COR_ruler
						value < low_negative_opinion
					}
					factor = 0.7
				}
				modifier = {
					opinion = {
						target = scope:COR_ruler
						value <= neutral_opinion
					}
					factor = 0.8
				}
				modifier = {
					opinion = {
						target = scope:COR_ruler
						value > neutral_opinion
					}
					factor = 1.25
				}
				modifier = {
					opinion = {
						target = scope:COR_ruler
						value > medium_positive_opinion
					}
					factor = 1.5
				}
				modifier = {
					opinion = {
						target = scope:COR_ruler
						value > high_positive_opinion
					}
					factor = 1.75
				}
				modifier = {
					opinion = {
						target = scope:COR_ruler
						value > very_high_positive_opinion
					}
					factor = 2
				}
			}
			50 = {
				desc = COR_ceremony.0101.a.small_donation
				scope:COR_ruler = {
					trigger_event = COR_ceremony.0103 #Priest asks for small donation
				}
				modifier = {
					has_trait = greedy
					factor = 1.5
				}
				modifier = {
					has_trait = lazy
					factor = 1.25
				}
				modifier = {
					has_trait = callous
					factor = 1.25
				}
				modifier = {
					num_sinful_traits > 1
					factor = 1.5
				}
			}
		}
	}
	option = { #For powerful theocrat
		name = COR_ceremony.0101.b
		trigger = {
			trigger_if = {
				limit = {
					exists = scope:COR_priest
				}
				NOT = { root = scope:COR_priest }
			}
		}
		save_scope_as = COR_coronator
		random_list = {
			40 = {
				desc = COR_ceremony.0101.b.donation
				scope:COR_ruler = {
					trigger_event = COR_ceremony.0104 #Donate money to me.
				}
				modifier = {
					has_trait = greedy
					factor = 1.5
				}
				modifier = {
					has_trait = lazy
					factor = 1.25
				}
				modifier = {
					has_trait = callous
					factor = 1.25
				}
			}
			#40 = {
			#	desc = COR_ceremony.0101.b.donation_pope
			#	scope:COR_ruler = {
			#		trigger_event = COR_ceremony.0105 #Donate money to the Pope.
			#	}
			#	modifier = {
			#		OR = {
			#			root = faith.religious_head
			#			has_trait = TCT_antipope
			#		}
			#		factor = 0
			#	}
			#	modifier = {
			#		has_trait = cynical
			#		factor = 0
			#	}
			#	modifier = {
			#		has_trait = generous
			#		factor = 1.5
			#	}
			#	modifier = {
			#		has_trait = zealous
			#		factor = 1.5
			#	}
			#	modifier = {
			#		is_cardinal = yes
			#		factor = 1.5
			#	}
			#	modifier = {
			#		num_sinful_traits > 1
			#		factor = 0.5
			#	}
			#}
			20 = {
				desc = COR_ceremony.0101.b.send_child_to_monastery
				trigger = {
					scope:COR_ruler = {
						any_child = {
							COR_child_can_take_vows_trigger = yes
						}
					}
				}
				scope:COR_ruler = {
					trigger_event = COR_ceremony.0106 #Send child to monastery/nunnery.
				}
				modifier = {
					scope:COR_ruler = {
						any_child = {
							count >= 3
							COR_child_can_take_vows_trigger = yes
						}
					}
					factor = 1.5
				}
				modifier = {
					scope:COR_ruler = {
						any_child = {
							count >= 4
							COR_child_can_take_vows_trigger = yes
						}
					}
					factor = 1.5
				}
				modifier = {
					scope:COR_ruler = {
						any_child = {
							count >= 5
							COR_child_can_take_vows_trigger = yes
						}
					}
					factor = 1.5
				}
				modifier = {
					scope:COR_ruler = {
						any_child = {
							count >= 6
							COR_child_can_take_vows_trigger = yes
						}
					}
					factor = 1.5
				}
				modifier = {
					num_sinful_traits > 1
					factor = 0.25
				}
				modifier = {
					has_trait = cynical
					factor = 0.25
				}
			}
			10 = {
				desc = COR_ceremony.0101.b.send_child_to_holy_order
				trigger = {
					faith = {
						any_faith_holy_order = { #Your faith must have a Holy Order
							always = yes
						}
					}
					scope:COR_ruler = {
						any_child = {
							COR_holy_order_child_trigger = yes
						}
					}
				}
				scope:COR_ruler = {
					trigger_event = COR_ceremony.0107 #Send son to holy order.
				}
				modifier = {
					scope:COR_ruler = {
						any_child = {
							count >= 3
							COR_holy_order_child_trigger = yes
						}
					}
					factor = 1.5
				}
				modifier = {
					scope:COR_ruler = {
						any_child = {
							count >= 4
							COR_holy_order_child_trigger = yes
						}
					}
					factor = 1.5
				}
				modifier = {
					scope:COR_ruler = {
						any_child = {
							count >= 5
							COR_holy_order_child_trigger = yes
						}
					}
					factor = 1.5
				}
				modifier = {
					scope:COR_ruler = {
						any_child = {
							count >= 6
							COR_holy_order_child_trigger = yes
						}
					}
					factor = 1.5
				}
				modifier = {
					num_sinful_traits > 1
					factor = 0.25
				}
				modifier = {
					has_trait = cynical
					factor = 0.25
				}
			}
			#10 = {  #NOTE place story cycle on COR_ruler that checks weekly if a feast is hosted
			#	desc = COR_ceremony.0101.b.host_feast
			#	scope:COR_ruler = {
			#		trigger_event = COR_ceremony.0108 #Wishes to have a feast hosted.
			#	}
			#	trigger = {
			#		num_sinful_traits >= 1
			#		scope:COR_ruler = {
			#			is_at_war = no
			#		}
			#	}
			#	modifier = {
			#		has_trait = lifestyle_reveler
			#		factor = 2
			#	}
			#	modifier = {
			#		has_trait = gluttonous
			#		factor = 1.5
			#	}
			#	modifier = {
			#		has_trait = drunkard
			#		factor = 1.5
			#	}
			#	modifier = {
			#		has_trait = greedy
			#		factor = 1.5
			#	}
			#	modifier = {
			#		has_trait = cynical
			#		factor = 1.25
			#	}
			#	modifier = {
			#		has_trait = zealous
			#		factor = 0.5
			#	}
			#}
			#10 = {
			#	desc = COR_ceremony.0101.b.give_county
			#	scope:COR_ruler = {
			#		trigger_event = COR_ceremony.0109 #Wishes for another County.
			#	}
			#	trigger = {
			#		scope:COR_ruler = {
			#			is_at_war = no
			#			OR = {
			#				any_held_title = {
			#					tier = tier_barony
			#					is_capital_barony = no
			#					is_leased_out = no
			#					NOT = { this = scope:COR_ruler.capital_barony }
			#				}
			#				any_held_title = {
			#					count >= 4
			#					tier = tier_county
			#				}
			#			}
			#		}
			#	}
			#	modifier = {
			#		scope:COR_ruler = {
			#			any_held_title = {
			#				count > 2
			#				tier = tier_county
			#			}
			#		}
			#		factor = 1.5
			#	}
			#	modifier = {
			#		scope:COR_ruler = {
			#			any_held_title = {
			#				count >= 5
			#				tier = tier_county
			#			}
			#		}
			#		factor = 2
			#	}
			#}
			10 = {
				desc = COR_ceremony.0101.b.gift_artifact
				scope:COR_ruler = {
					trigger_event = COR_ceremony.0110 #Give me an artifact.
				}
				trigger = {
					scope:COR_ruler = {
						any_character_artifact = {
							exists = var:relic
							prev = {
								can_benefit_from_artifact = prev
							}
							NOR = {
								rarity = famed
								rarity = illustrious
							}
						}
					}
				}
				modifier = {
					has_trait = zealous
					factor = 1.5
				}
				modifier = {
					has_trait = scholar
					factor = 1.5
				}
				modifier = {
					has_trait = theologian
					factor = 1.5
				}
				modifier = {
					has_trait = lifestyle_mystic
					factor = 1.5
				}
				modifier = {
					scope:COR_ruler = { is_ai = yes }
					factor = 0
				}
			}
		}
	}
}

#Priest asks for nothing
COR_ceremony.0102 = { 
	type = letter_event
	opening = COR_ceremony.0104.t
	desc = COR_ceremony.0102.desc
	sender = scope:COR_coronator

	immediate = { }

	option = {
		name = COR_ceremony.0102.a
		custom_tooltip = COR_ceremony.0102.a.tt

		var:COR_coronator ?= {
			remove_list_variable = {
				name = COR_coronation_targets
				target = scope:COR_ruler
			}
		}
		scope:COR_coronator = {
			add_to_variable_list = {
				name = COR_coronation_targets
				target = scope:COR_ruler
			}
			create_story = COR_coronator_story
		}
		set_variable = {
			name = COR_coronator
			value = scope:COR_coronator
		}
		add_character_flag = COR_flag_preparing_coronation

		ai_chance = {
			base = 100
		}
	}
}

#Priest asks for small donation
COR_ceremony.0103 = {
	type = letter_event
	opening = COR_ceremony.0104.t
	desc = COR_ceremony.0103.desc
	sender = scope:COR_coronator

	immediate = { }

	option = {
		name = COR_ceremony.0103.a
		custom_tooltip = COR_ceremony.0104.a.tt

		if = {
			limit = { is_ai = no }
			pay_short_term_gold = {
				target = scope:COR_coronator
				gold = tiny_gold_value
			}
		}

		var:COR_coronator ?= {
			remove_list_variable = {
				name = COR_coronation_targets
				target = scope:COR_ruler
			}
		}
		scope:COR_coronator = {
			add_to_variable_list = {
				name = COR_coronation_targets
				target = scope:COR_ruler
			}
			create_story = COR_coronator_story
		}
		set_variable = {
			name = COR_coronator
			value = scope:COR_coronator
		}
		add_character_flag = COR_flag_preparing_coronation

		ai_chance = {
			base = 100
		}
	}
	option = {
		name = COR_ceremony.0104.b

		ai_chance = {
			base = 0
		}
	}
}

#Priest asks for donation
COR_ceremony.0104 = {
	type = letter_event
	opening = COR_ceremony.0104.t
	desc = COR_ceremony.0104.desc
	sender = scope:COR_coronator

	immediate = { }

	option = {
		name = COR_ceremony.0104.a
		custom_tooltip = COR_ceremony.0104.a.tt

		if = {
			limit = {
				is_ai = no
				scope:COR_coronator = {
					this = faith:catholic.religious_head
				}
			}
			pay_short_term_gold = {
				target = scope:COR_coronator
				gold = major_gold_value
			}
		}
		else_if = {
			limit = { is_ai = no }
			pay_short_term_gold = {
				target = scope:COR_coronator
				gold = minor_gold_value
			}
		}

		var:COR_coronator ?= {
			remove_list_variable = {
				name = COR_coronation_targets
				target = scope:COR_ruler
			}
		}
		scope:COR_coronator = {
			add_to_variable_list = {
				name = COR_coronation_targets
				target = scope:COR_ruler
			}
			create_story = COR_coronator_story
		}
		set_variable = {
			name = COR_coronator
			value = scope:COR_coronator
		}
		add_character_flag = COR_flag_preparing_coronation

		ai_chance = {
			base = 100
		}
	}
	option = {
		name = COR_ceremony.0104.b

		ai_chance = {
			base = 0
		}
	}
}

#Send child to monastery/nunnery
COR_ceremony.0106 = {
	type = letter_event
	opening = COR_ceremony.0104.t
	desc = COR_ceremony.0106.desc
	sender = scope:COR_coronator

	immediate = {
		scope:COR_ruler = {
			random_child = {
				limit = {
					COR_child_can_take_vows_trigger = yes
				}
				save_scope_as = COR_childofruler1
			}
		}
	}

	option = {
		name = COR_ceremony.0106.a
		custom_tooltip = COR_ceremony.0104.a.tt

		scope:COR_childofruler1 = {
			add_opinion = {
				modifier = demanded_taking_vows
				target = root
			}
			add_trait = devoted
			add_piety_level = 1
			if = {
				limit = { is_ruler = yes }
				depose = yes
			}
			if = {
				limit = {
					is_married = yes
				}
				every_spouse = {
					divorce = scope:COR_childofruler1
				}
			}
			if = {
				limit = {
					exists = betrothed
				}
				break_betrothal = betrothed
				if = {
					limit = {
						has_been_promised_grand_wedding = yes
					}
					break_grand_wedding_betrothal_effect = yes
				}
			}
			if = {
				limit = {
					is_concubine = yes
				}
				this.concubinist = {
					remove_concubine = scope:COR_childofruler1
				}
			}
			if = {
				limit = {
					number_of_concubines > 0
				}
				every_concubine = {
					scope:recipient = {
						remove_concubine = prev
					}
				}
			}
		}

		var:COR_coronator ?= {
			remove_list_variable = {
				name = COR_coronation_targets
				target = scope:COR_ruler
			}
		}
		scope:COR_coronator = {
			add_to_variable_list = {
				name = COR_coronation_targets
				target = scope:COR_ruler
			}
			create_story = COR_coronator_story
		}
		set_variable = {
			name = COR_coronator
			value = scope:COR_coronator
		}
		add_character_flag = COR_flag_preparing_coronation

		ai_chance = {
			base = 100
		}
	}
	option = {
		name = COR_ceremony.0106.b
	
		ai_chance = {
			base = 0
		}
	}
}

#Send child to holy order
COR_ceremony.0107 = {
	type = letter_event
	opening = COR_ceremony.0104.t
	desc = COR_ceremony.0107.desc
	sender = scope:COR_coronator

	immediate = {
		scope:COR_ruler = {
			random_child = {
				limit = {
					COR_holy_order_child_trigger = yes
				}
				save_scope_as = COR_childofruler2
			}
		}
	}

	option = {
		name = COR_ceremony.0107.a
		custom_tooltip = COR_ceremony.0104.a.tt

		scope:COR_childofruler2 = {
			add_trait = order_member
			add_piety_level = 1
			if = {
				limit = { is_ruler = yes }
				depose = yes
			}
			if = {
				limit = {
					is_married = yes
				}
				every_spouse = {
					divorce = scope:COR_childofruler2
				}
			}
			if = {
				limit = {
					exists = betrothed
				}
				break_betrothal = betrothed
				if = {
					limit = {
						has_been_promised_grand_wedding = yes
					}
					break_grand_wedding_betrothal_effect = yes
				}
			}
			if = {
				limit = {
					is_concubine = yes
				}
				this.concubinist = {
					remove_concubine = scope:COR_childofruler2
				}
			}
			if = {
				limit = {
					number_of_concubines > 0
				}
				every_concubine = {
					scope:recipient = {
						remove_concubine = prev
					}
				}
			}
		}

		var:COR_coronator ?= {
			remove_list_variable = {
				name = COR_coronation_targets
				target = scope:COR_ruler
			}
		}
		scope:COR_coronator = {
			add_to_variable_list = {
				name = COR_coronation_targets
				target = scope:COR_ruler
			}
			create_story = COR_coronator_story
		}
		set_variable = {
			name = COR_coronator
			value = scope:COR_coronator
		}
		add_character_flag = COR_flag_preparing_coronation

		ai_chance = {
			base = 100
		}
	}
	option = {
		name = COR_ceremony.0107.b
	
		ai_chance = {
			base = 0
		}
	}
}

COR_ceremony.0110 = {
	type = letter_event
	opening = COR_ceremony.0104.t
	desc = COR_ceremony.0110.desc
	sender = scope:COR_coronator

	immediate = {
		if = {
			limit = {
				NOT = { exists = scope:COR_relic }
			}
			scope:COR_ruler = {
				random_character_artifact = {
					limit = {
						exists = var:relic
						prev = {
							can_benefit_from_artifact = prev
						}
						NOR = {
							rarity = famed
							rarity = illustrious
						}
					}
					save_scope_as = COR_relic
				}
			}
		}
	}

	option = {
		name = COR_ceremony.0110.a
		custom_tooltip = COR_ceremony.0104.a.tt

		scope:COR_relic = {
			set_owner = scope:COR_coronator
		}

		var:COR_coronator ?= {
			remove_list_variable = {
				name = COR_coronation_targets
				target = scope:COR_ruler
			}
		}
		scope:COR_coronator = {
			add_to_variable_list = {
				name = COR_coronation_targets
				target = scope:COR_ruler
			}
			create_story = COR_coronator_story
		}
		set_variable = {
			name = COR_coronator
			value = scope:COR_coronator
		}
		add_character_flag = COR_flag_preparing_coronation

		ai_chance = {
			base = 100
		}
	}
	option = {
		name = COR_ceremony.0110.b
		
		if = {
			limit = {
				scope:COR_coronator = {
					this = faith:catholic.religious_head
				}
			}
			scope:COR_coronator = {
				add_opinion = {
					target = root
					modifier = COR_opinion_requested_artifact
				}
			}
		}
	
		ai_chance = {
			base = 0
		}
	}
}

## 0201 - 0300 Pope & Antipope
# Letter event determining what the pope is going to ask from the King/Emperor in exchange for the Coronation.
COR_ceremony.0201 = {
	type = character_event
	title = COR_ceremony.0201.t
	desc = {
		random_valid = {
			desc = COR_ceremony.0201.desc.a
			desc = COR_ceremony.0201.desc.b
			desc = COR_ceremony.0201.desc.c
			desc = COR_ceremony.0201.desc.d
			desc = COR_ceremony.0201.desc.e
			desc = COR_ceremony.0201.desc.f
		}
	}
	lower_left_portrait = scope:COR_childofruler1
	left_portrait = scope:COR_ruler
	right_portrait = scope:COR_cardinal
	lower_right_portrait = {
		character = scope:COR_childofruler2
		trigger = {
			scope:COR_childofruler2 = { 
				NOT = {	this = scope:COR_childofruler1 }
			}
		}
	}

	theme = crown
	override_background = { reference = temple }

	immediate = {
		##Set up scopes
		save_scope_as = COR_coronator
		#Cardinal to deliver the message
		if = {
			limit = {
				exists = global_var:Trinity_is_loaded
			}
			random_living_cardinal = {
				limit = {
					is_cardinal = yes
					is_available_ai = yes
					top_liege = scope:COR_ruler
				}
				alternative_limit = {
					is_cardinal = yes
					is_available_ai = yes
					top_liege = root
				}
				save_scope_as = COR_cardinal
			}
		}
		#Relic to demand
		scope:COR_ruler = {
			random_character_artifact = {
				limit = {
					exists = var:relic
					prev = {
						can_benefit_from_artifact = prev
					}
					OR = {
						rarity = famed
						rarity = illustrious
					}
				}
				save_scope_as = COR_relic
			}
		}
	}

	option = { #I want gold.
		name = COR_ceremony.0201.a
		custom_tooltip = COR_ceremony.0101.b.donation

		scope:COR_ruler = {
			trigger_event = {
				id = COR_ceremony.0104 #Donate money to me.
				#days = 1 #DEBUG
			}
		}

		ai_chance = {
			base = 20
			modifier = {
				factor = 0.5
				is_vassal_of = scope:COR_ruler
			}
			modifier = {
				opinion = {
					target = scope:COR_ruler
					value < very_high_negative_opinion
				}
				factor = 0.1
			}
			modifier = {
				opinion = {
					target = scope:COR_ruler
					value < high_negative_opinion
				}
				factor = 0.2
			}
			modifier = {
				opinion = {
					target = scope:COR_ruler
					value < medium_negative_opinion
				}
				factor = 0.3
			}
			modifier = {
				opinion = {
					target = scope:COR_ruler
					value < low_negative_opinion
				}
				factor = 0.4
			}
			modifier = {
				opinion = {
					target = scope:COR_ruler
					value < neutral_opinion
				}
				factor = 0.5
			}
			modifier = {
				opinion = {
					target = scope:COR_ruler
					value < low_positive_opinion
				}
				factor = 0.6
			}
			modifier = {
				opinion = {
					target = scope:COR_ruler
					value >= low_positive_opinion
				}
				factor = 1.25
			}
			modifier = {
				opinion = {
					target = scope:COR_ruler
					value > medium_positive_opinion
				}
				factor = 1.5
			}
			modifier = {
				factor = 1.5
				has_trait = greedy
			}
			modifier = {
				factor = 0.5
				has_trait = zealous
			}
		}
	}

	option = { #I want to be independent.
		name = COR_ceremony.0201.b
		custom_tooltip = COR_ceremony.0201.b.tt

		trigger = {
			is_landed = yes
			is_vassal_of = scope:COR_ruler
		}

		scope:COR_ruler = {
			trigger_event = {
				id = COR_ceremony.0202
				#days = 1 #DEBUG
			}
		}

		ai_chance = {
			base = 80
			modifier = {
				has_opinion_modifier = { #Opinion modifier keeps track of the Pope's previous decision, should the player deny his first request and then attempt to ask again immediately after for a different result.
					modifier = COR_opinion_requested_independence
					target = scope:COR_ruler
				}
				factor = 2
			}
			modifier = {
				factor = 0.5
				has_trait = TCT_antipope
			}
			modifier = {
				factor = 1.5
				has_title = title:k_papal_state
			}
			modifier = {
				opinion = {
					target = scope:COR_ruler
					value < high_negative_opinion
				}
				factor = 2
			}
			modifier = {
				opinion = {
					target = scope:COR_ruler
					value < low_negative_opinion
				}
				factor = 1.75
			}
			modifier = {
				opinion = {
					target = scope:COR_ruler
					value < neutral_opinion
				}
				factor = 1.5
			}
			modifier = {
				opinion = {
					target = scope:COR_ruler
					value > low_positive_opinion
				}
				factor = 0.9
			}
			modifier = {
				opinion = {
					target = scope:COR_ruler
					value > medium_positive_opinion
				}
				factor = 0.8
			}
			modifier = {
				opinion = {
					target = scope:COR_ruler
					value > high_positive_opinion
				}
				factor = 0.7
			}
		}
	}
	option = { #I want you to enact Papal Investiture.
		name = COR_ceremony.0201.c
		custom_tooltip = COR_ceremony.0201.c.tt
		add_internal_flag = special

		trigger = {
			NOT = { has_trait = TCT_antipope }
			scope:COR_ruler = {
				is_independent_ruler = yes
				has_realm_law_flag = free_enacted
			}
		}

		scope:COR_ruler = {
			trigger_event = {
				id = COR_ceremony.0203
				#days = 1 #DEBUG
			}
		}

		ai_chance = {
			base = 30
			modifier = {
				has_opinion_modifier = { #Opinion modifier keeps track of the Pope's previous decision, should the player deny his first request and then attempt to ask again immediately after for a different result.
					modifier = COR_opinion_requested_papal_investiture
					target = scope:COR_ruler
				}
				factor = 2
			}
			modifier = {
				scope:COR_ruler = {
					highest_held_title_tier = tier_empire
				}
				factor = 1.5
			}
			modifier = {
				scope:COR_ruler = {
					OR = {
						has_title = title:e_hre
						HRT_is_emperor_trigger = yes
					}
				}
				factor = 1.75
			}
			modifier = {
				highest_held_title_tier >= tier_kingdom
				factor = 1.5
			}
			modifier = {
				has_trait = arrogant
				factor = 1.5
			}
			modifier = {
				is_independent_ruler = yes
				factor = 1.75
			}
		}
	}
	option = { #Send child to monastery/nunnery.
		name = COR_ceremony.0201.d
		custom_tooltip = COR_ceremony.0101.b.send_child_to_monastery

		trigger = {
			scope:COR_ruler = {
				any_child = {
					COR_child_can_take_vows_trigger = yes
				}
			}
		}

		scope:COR_ruler = {
			trigger_event = {
				id = COR_ceremony.0106
				#days = 1 #DEBUG
			}
		}

		ai_chance = {
			base = 20
			modifier = {
				scope:COR_ruler = {
					any_child = {
						count >= 3
						COR_child_can_take_vows_trigger = yes
					}
				}
				factor = 1.5
			}
			modifier = {
				scope:COR_ruler = {
					any_child = {
						count >= 4
						COR_child_can_take_vows_trigger = yes
					}
				}
				factor = 1.5
			}
			modifier = {
				scope:COR_ruler = {
					any_child = {
						count >= 5
						COR_child_can_take_vows_trigger = yes
					}
				}
				factor = 1.5
			}
			modifier = {
				scope:COR_ruler = {
					any_child = {
						count >= 6
						COR_child_can_take_vows_trigger = yes
					}
				}
				factor = 1.5
			}
			modifier = {
				num_sinful_traits > 1
				factor = 0.25
			}
			modifier = {
				has_trait = cynical
				factor = 0.25
			}
		}
	}
	option = { #Send son to holy order.
		name = COR_ceremony.0201.e
		custom_tooltip = COR_ceremony.0101.b.send_child_to_holy_order

		trigger = {
			scope:COR_ruler = {
				any_child = {
					COR_holy_order_child_trigger = yes
				}
			}
		}

		scope:COR_ruler = {
			trigger_event = {
				id = COR_ceremony.0107
				#days = 1 #DEBUG
			}
		}

		ai_chance = {
			base = 10
			modifier = {
				scope:COR_ruler = {
					any_child = {
						count >= 3
						can_be_warrior_trigger = { ARMY_OWNER = scope:COR_ruler }
						is_available_ai = yes
						faith = faith:catholic
						is_ruler = no
						is_married = no
						is_betrothed = no
						NOR = {
							is_primary_heir_of = scope:COR_ruler
							has_trait = devoted
							has_trait = order_member
							has_trait = excommunicated
							has_character_flag = holy_order_member_requested_return_home
						}
					}
				}
				factor = 1.5
			}
			modifier = {
				scope:COR_ruler = {
					any_child = {
						count >= 4
						can_be_warrior_trigger = { ARMY_OWNER = scope:COR_ruler }
						is_available_ai = yes
						faith = faith:catholic
						is_ruler = no
						is_married = no
						is_betrothed = no
						NOR = {
							is_primary_heir_of = scope:COR_ruler
							has_trait = devoted
							has_trait = order_member
							has_trait = excommunicated
							has_character_flag = holy_order_member_requested_return_home
						}
					}
				}
				factor = 1.5
			}
			modifier = {
				scope:COR_ruler = {
					any_child = {
						count >= 5
						can_be_warrior_trigger = { ARMY_OWNER = scope:COR_ruler }
						is_available_ai = yes
						faith = faith:catholic
						is_ruler = no
						is_married = no
						is_betrothed = no
						NOR = {
							is_primary_heir_of = scope:COR_ruler
							has_trait = devoted
							has_trait = order_member
							has_trait = excommunicated
							has_character_flag = holy_order_member_requested_return_home
						}
					}
				}
				factor = 1.5
			}
			modifier = {
				scope:COR_ruler = {
					any_child = {
						count >= 6
						can_be_warrior_trigger = { ARMY_OWNER = scope:COR_ruler }
						is_available_ai = yes
						faith = faith:catholic
						is_ruler = no
						is_married = no
						is_betrothed = no
						NOR = {
							is_primary_heir_of = scope:COR_ruler
							has_trait = devoted
							has_trait = order_member
							has_trait = excommunicated
							has_character_flag = holy_order_member_requested_return_home
						}
					}
				}
				factor = 1.5
			}
			modifier = {
				num_sinful_traits > 1
				factor = 0.25
			}
			modifier = {
				has_trait = cynical
				factor = 0.25
			}
		}
	}
	option = { #Give me an artifact.
		name = COR_ceremony.0201.f
		custom_tooltip = COR_ceremony.0101.b.gift_artifact
		trigger = {
			exists = scope:COR_relic
		}

		scope:COR_ruler = {
			trigger_event = {
				id = COR_ceremony.0110
				#days = 1 #DEBUG
			}
		}

		ai_chance = {
			base = 15
			modifier = {
				opinion = {
					target = scope:COR_ruler
					value < high_negative_opinion
				}
				factor = 1.75
			}
			modifier = {
				opinion = {
					target = scope:COR_ruler
					value < low_negative_opinion
				}
				factor = 1.5
			}
			modifier = {
				opinion = {
					target = scope:COR_ruler
					value < neutral_opinion
				}
				factor = 1.25
			}
			modifier = {
				has_opinion_modifier = { #Opinion modifier keeps track of the Pope's previous decision, should the player deny his first request and then attempt to ask again immediately after for a different result.
					modifier = COR_opinion_requested_artifact
					target = scope:COR_ruler
				}
				factor = 10
			}
			modifier = {
				scope:COR_ruler = { is_ai = yes }
				factor = 0
			}
		}
	}
}

#Pope asks for independence
COR_ceremony.0202 = {
	type = letter_event
	opening = COR_ceremony.0104.t
	desc = COR_ceremony.0202.desc
	sender = scope:COR_coronator

	immediate = { }

	option = {
		name = COR_ceremony.0202.a
		custom_tooltip = COR_ceremony.0104.a.tt

		var:COR_coronator ?= {
			remove_list_variable = {
				name = COR_coronation_targets
				target = scope:COR_ruler
			}
		}
		scope:COR_coronator = {
			create_title_and_vassal_change = {
				type = independency
				save_scope_as = change
				add_claim_on_loss = yes
			}
			becomes_independent = {
				change = scope:change
			}
			resolve_title_and_vassal_change = scope:change

			add_to_variable_list = {
				name = COR_coronation_targets
				target = scope:COR_ruler
			}
			create_story = COR_coronator_story
		}
		set_variable = {
			name = COR_coronator
			value = scope:COR_coronator
		}
		add_character_flag = COR_flag_preparing_coronation

		ai_chance = {
			base = 100
		}
	}
	option = {
		name = COR_ceremony.0202.b

		scope:COR_coronator = {
			add_opinion = {
				target = root
				modifier = COR_opinion_requested_independence
			}
		}

		ai_chance = {
			base = 0
		}
	}
}

#Pope demands Papal Investiture
COR_ceremony.0203 = {
	type = letter_event
	opening = COR_ceremony.0104.t
	desc = COR_ceremony.0203.desc
	sender = scope:COR_coronator

	immediate = { }

	option = {
		name = COR_ceremony.0203.a
		custom_tooltip = COR_ceremony.0104.a.tt

		if = {
			limit = {
				has_realm_law = free_investiture_early
			}
			remove_realm_law = free_investiture_early
			add_realm_law_skip_effects = papal_investiture_early
		}
		else_if = {
			limit = {
				has_realm_law = free_investiture_late
			}
			remove_realm_law = free_investiture_late
			add_realm_law_skip_effects = papal_investiture_late
		}
		set_variable = {
			name = investiture_cooldown
			years = 10
		}
		#TODO TCT catalyst

		var:COR_coronator ?= {
			remove_list_variable = {
				name = COR_coronation_targets
				target = scope:COR_ruler
			}
		}
		scope:COR_coronator = {
			add_to_variable_list = {
				name = COR_coronation_targets
				target = scope:COR_ruler
			}
			create_story = COR_coronator_story
		}
		set_variable = {
			name = COR_coronator
			value = scope:COR_coronator
		}
		add_character_flag = COR_flag_preparing_coronation

		ai_chance = {
			base = 80
			modifier = {
				OR = {
					has_title = title:e_hre
					#HRT
					HRT_is_emperor_trigger = yes
				}
				factor = 0.1
			}
		}
	}
	option = {
		name = COR_ceremony.0203.b

		scope:COR_coronator = {
			add_opinion = {
				target = root
				modifier = COR_opinion_requested_papal_investiture
			}
		}
		#TODO TCT catalyst

		ai_chance = {
			base = 20
		}
	}
}

####################################
# Coronation Activity Events
# 0301 - 0400
####################################

# The host has died during the coronation - event for guests
COR_ceremony.0301 = {
	type = character_event
	title = COR_ceremony.0301.t
	desc = COR_ceremony.0301.desc
	theme = wedding_ceremony_activity
	override_icon = {
		reference = "gfx/interface/icons/event_types/type_illness.dds"
	}
	left_portrait = {
		character = scope:host
	}
	
	option = {
		name = COR_ceremony.0301.a
	}
}

# Invalidation for Host Death - Player Heir
COR_ceremony.0302 = {
	type = character_event
	title = COR_ceremony.0301.t
	desc = {
		desc = COR_ceremony.0302.desc
		desc = COR_ceremony.0302.desc.entourage
		desc = COR_ceremony.0302.desc.ruler
	}
	theme = crown

	left_portrait = {
		character = root
		animation = worry
	}

	immediate = { }

	option = { 
		name = COR_ceremony.0302.a
		custom_tooltip = COR_ceremony.0302.tt
	}
}

# The host has been imprisoned - for host
COR_ceremony.0303 = {
	type = character_event
	title = COR_ceremony.0301.t
	desc = COR_ceremony.0303.desc
	theme = crown
	override_icon = {
		reference = "gfx/interface/icons/event_types/type_prison.dds"
	}
	left_portrait = {
		character = scope:host
		animation = prison_dungeon
	}

	immediate = { }
	
	option = {
		name = COR_ceremony.0303.a
	}
}

# The host has been imprisoned - for guests
COR_ceremony.0304 = {
	type = character_event
	title = COR_ceremony.0301.t
	desc = COR_ceremony.0304.desc
	theme = wedding_ceremony_activity
	override_icon = {
		reference = "gfx/interface/icons/event_types/type_prison.dds"
	}
	left_portrait = {
		character = scope:host
		animation = prison_dungeon
	}
	
	option = {
		name = COR_ceremony.0303.a
		custom_tooltip = COR_ceremony.0304.a.tt
	}
}

# Coronator has died: for host
COR_ceremony.0305 = {
	type = character_event
	title = COR_ceremony.0301.t
	desc = COR_ceremony.0305.desc
	theme = crown
	left_portrait = {
		character = root
		animation = sadness
	}
	lower_center_portrait = scope:COR_coronator

	immediate = {
		# The Coronation Ceremony is invalidated: get a refund
		if = {
			limit = {
				has_variable = COR_ceremony_gold_recoup_value
				var:COR_ceremony_gold_recoup_value > 0
			}
			custom_tooltip = {
				text = COR_ceremony_refund_tt
				add_gold = var:COR_ceremony_gold_recoup_value
			}
		}
		remove_character_flag = COR_flag_preparing_coronation
		remove_variable = COR_coronation_request_cooldown
		remove_variable = COR_coronator_rank
		var:COR_coronator ?= {
			remove_list_variable = {
				name = COR_coronation_targets
				target = scope:COR_ruler
			}
		}
		if = {
			limit = {
				NOR = {
					has_trait = COR_crowned_by_priest
					has_trait = COR_crowned_by_bishop
					has_trait = COR_crowned_by_pope
					has_trait = COR_crowned_by_myself
					has_trait = HRT_emperor
					has_trait = COR_byz_crowned_by_patriarch
				}
			}
			remove_variable = COR_coronator
		}
	}

	option = {
		name = COR_ceremony.0305.a
		custom_tooltip = COR_ceremony.0304.a.tt
	}

	after = {
		if = {
			limit = {
				has_variable = COR_ceremony_gold_recoup_value
			}
			remove_variable = COR_ceremony_gold_recoup_value
		}
	}
}

# Coronator has died: for everyone else
COR_ceremony.0306 = {
	type = character_event
	title = COR_ceremony.0301.t
	desc = COR_ceremony.0306.desc
	theme = crown
	left_portrait = {
		character = root
		animation = sadness
	}
	lower_center_portrait = scope:COR_coronator

	immediate = { } 

	option = {
		name = COR_ceremony.0306.a
		custom_tooltip = COR_ceremony.0304.a.tt
	}
}

# Coronator has been imprisoned: for host
COR_ceremony.0307 = {
	type = character_event
	title = COR_ceremony.0301.t
	desc = COR_ceremony.0307.desc
	theme = crown
	left_portrait = {
		character = root
		animation = sadness
	}
	lower_center_portrait = scope:COR_coronator

	immediate = {
		# The Coronation Ceremony is invalidated: get a refund
		if = {
			limit = {
				has_variable = COR_ceremony_gold_recoup_value
				var:COR_ceremony_gold_recoup_value > 0
			}
			custom_tooltip = {
				text = COR_ceremony_refund_tt
				add_gold = var:COR_ceremony_gold_recoup_value
			}
		}
		var:COR_coronator ?= { save_scope_as = COR_coronator }
		remove_character_flag = COR_flag_preparing_coronation
		remove_variable = COR_coronation_request_cooldown
		remove_variable = COR_coronator_rank
		var:COR_coronator ?= {
			remove_list_variable = {
				name = COR_coronation_targets
				target = scope:COR_ruler
			}
		}
		if = {
			limit = {
				NOR = {
					has_trait = COR_crowned_by_priest
					has_trait = COR_crowned_by_bishop
					has_trait = COR_crowned_by_pope
					has_trait = COR_crowned_by_myself
					has_trait = HRT_emperor
					has_trait = COR_byz_crowned_by_patriarch
				}
			}
			remove_variable = COR_coronator
		}
	}

	option = {
		name = COR_ceremony.0305.a
		custom_tooltip = COR_ceremony.0304.a.tt
	}

	after = {
		if = {
			limit = {
				has_variable = COR_ceremony_gold_recoup_value
			}
			remove_variable = COR_ceremony_gold_recoup_value
		}
	}
}

# Coronator has been imprisoned: for everyone else
COR_ceremony.0308 = {
	type = character_event
	title = COR_ceremony.0301.t
	desc = COR_ceremony.0308.desc
	theme = crown
	left_portrait = {
		character = root
		animation = sadness
	}
	lower_center_portrait = scope:COR_coronator

	immediate = { } 

	option = {
		name = COR_ceremony.0308.a
		custom_tooltip = COR_ceremony.0304.a.tt
	}
}

# Coronator is not showing up: for host
COR_ceremony.0309 = {
	type = character_event
	title = COR_ceremony.0301.t
	desc = COR_ceremony.0309.desc
	theme = crown
	override_icon = {
		reference = "gfx/interface/icons/event_types/type_feast.dds"
	}
	left_portrait = {
		character = scope:host
	}

	immediate = {
		# The Coronation Ceremony is invalidated: get a refund
		if = {
			limit = {
				has_variable = COR_ceremony_gold_recoup_value
				var:COR_ceremony_gold_recoup_value > 0
			}
			custom_tooltip = {
				text = COR_ceremony_refund_tt
				add_gold = var:COR_ceremony_gold_recoup_value
			}
		}
		remove_character_flag = COR_flag_preparing_coronation
		remove_variable = COR_coronation_request_cooldown
	}
	
	option = {
		name = COR_ceremony.0309.a
		custom_tooltip = COR_ceremony.0304.a.tt
	}

	after = {
		if = {
			limit = {
				has_variable = COR_ceremony_gold_recoup_value
			}
			remove_variable = COR_ceremony_gold_recoup_value
		}
	}
}

# Coronator is not showing up: for everyone else
COR_ceremony.0310 = {
	type = character_event
	title = COR_ceremony.0301.t
	desc = COR_ceremony.0310.desc
	theme = wedding_ceremony_activity
	override_icon = {
		reference = "gfx/interface/icons/event_types/type_feast.dds"
	}
	left_portrait = {
		character = root
		animation = disapproval
	}
	right_portrait = {
		character = scope:host
	}
	
	option = {
		name = COR_ceremony.0310.a
		custom_tooltip = COR_ceremony.0304.a.tt
	}
}

# Host tier too low: for host
COR_ceremony.0311 = {
	type = character_event
	title = COR_ceremony.0301.t
	desc = COR_ceremony.0311.desc
	theme = crown

	left_portrait = {
		character = scope:host
		animation = grief
	}

	immediate = {
		remove_character_flag ?= COR_flag_preparing_coronation
		remove_variable = COR_coronation_request_cooldown
		remove_variable = COR_coronator_rank
		var:COR_coronator ?= {
			remove_list_variable = {
				name = COR_coronation_targets
				target = scope:COR_ruler
			}
		}
		if = {
			limit = {
				NOR = {
					has_trait = COR_crowned_by_priest
					has_trait = COR_crowned_by_bishop
					has_trait = COR_crowned_by_pope
					has_trait = COR_crowned_by_myself
					has_trait = HRT_emperor
					has_trait = COR_byz_crowned_by_patriarch
				}
			}
			remove_variable = COR_coronator
		}
	}

	option = {
		name = COR_ceremony.0311.a
		custom_tooltip = COR_ceremony.0304.a.tt
	}
}

# Host tier too low: for everyone else
COR_ceremony.0312 = {
	type = character_event
	title = COR_ceremony.0301.t
	desc = COR_ceremony.0312.desc
	theme = crown

	left_portrait = {
		character = scope:host
		animation = grief
	}

	immediate = { }

	option = {
		name = COR_ceremony.0312.a
		custom_tooltip = COR_ceremony.0304.a.tt
	}
}

# Host selfcrowned: for host
COR_ceremony.0313 = {
	type = character_event
	title = COR_ceremony.0324.t
	desc = COR_ceremony.0313.desc
	theme = crown
	override_background = { reference = holy_site_generic }
	left_portrait = {
		character = root
		animation = jockey_walk
	}

	immediate = { } 

	option = {
		name = COR_ceremony.0313.a
		remove_character_flag = COR_selfcrowned
	}
}

# Host selfcrowned: for everyone else
COR_ceremony.0314 = {
	type = character_event
	title = COR_ceremony.0324.t
	desc = COR_ceremony.0314.desc
	theme = crown
	override_background = { reference = holy_site_generic }
	left_portrait = {
		character = scope:COR_ruler
		animation = jockey_idle
	}
	right_portrait = {
		character = root
		animation = worry
	}
	lower_center_portrait = scope:COR_coronator

	immediate = { } 

	option = {
		name = COR_ceremony.0314.a
	}
}

# Invalidation because the Coronator is no valid priest
COR_ceremony.0315 = {
	type = character_event
	title = COR_ceremony.0301.t
	desc = COR_ceremony.0315.desc
	theme = crown

	left_portrait = {
		character = root
		animation = sadness
	}
	lower_center_portrait = scope:COR_coronator

	immediate = {
		# The Coronation Ceremony is invalidated: get a refund
		if = {
			limit = {
				has_variable = COR_ceremony_gold_recoup_value
				var:COR_ceremony_gold_recoup_value > 0
			}
			custom_tooltip = {
				text = COR_ceremony_refund_tt
				add_gold = var:COR_ceremony_gold_recoup_value
			}
		}
		var:COR_coronator ?= { save_scope_as = COR_coronator }
		remove_character_flag = COR_flag_preparing_coronation
		remove_variable = COR_coronation_request_cooldown
		remove_variable = COR_coronator_rank
		var:COR_coronator ?= {
			remove_list_variable = {
				name = COR_coronation_targets
				target = scope:COR_ruler
			}
		}
		if = {
			limit = {
				NOR = {
					has_trait = COR_crowned_by_priest
					has_trait = COR_crowned_by_bishop
					has_trait = COR_crowned_by_pope
					has_trait = COR_crowned_by_myself
					has_trait = HRT_emperor
					has_trait = COR_byz_crowned_by_patriarch
				}
			}
			remove_variable = COR_coronator
		}
	}
	
	option = {
		name = COR_ceremony.0312.a
		custom_tooltip = COR_ceremony.0304.a.tt
	}

	after = {
		if = {
			limit = {
				has_variable = COR_ceremony_gold_recoup_value
			}
			remove_variable = COR_ceremony_gold_recoup_value
		}
	}
}

# FALLBACK INVALIDATION - we should never get this far
COR_ceremony.0316 = {
	type = character_event
	title = COR_ceremony.0301.t
	desc = COR_ceremony.0315.desc
	theme = crown

	left_portrait = {
		character = root
		animation = sadness
	}

	immediate = {
		# The Coronation Ceremony is invalidated: get a refund
		if = {
			limit = {
				has_variable = COR_ceremony_gold_recoup_value
				var:COR_ceremony_gold_recoup_value > 0
			}
			custom_tooltip = {
				text = COR_ceremony_refund_tt
				add_gold = var:COR_ceremony_gold_recoup_value
			}
		}
		remove_character_flag = COR_flag_preparing_coronation
		remove_variable = COR_coronation_request_cooldown
	}

	option = {
		name = COR_ceremony.0305.a
	}

	after = {
		if = {
			limit = {
				has_variable = COR_ceremony_gold_recoup_value
			}
			remove_variable = COR_ceremony_gold_recoup_value
		}
	}
}

# ON START - CORONATION CEREMONY
# For host
COR_ceremony.0320 = {
	type = activity_event
	title = COR_ceremony.0320.t

	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:activity = {
						OR = {
							AND = {
								has_activity_type = COR_activity_coronation_ceremony
								has_activity_option = {
									category = COR_ceremony_type
									option = COR_ceremony_type_private
								}
							}
							AND = {
								has_activity_type = COR_activity_coronation_ceremony_hof
								has_activity_option = {
									category = COR_ceremony_type
									option = COR_ceremony_type_private
								}
							}
						}
					}
				}
				desc = COR_ceremony.0320.desc.private
			}
			triggered_desc = {
				trigger = {
					scope:activity = {
						OR = {
							AND = {
								has_activity_type = COR_activity_coronation_ceremony
								has_activity_option = {
									category = COR_ceremony_type
									option = COR_ceremony_type_dignified
								}
							}
							AND = {
								has_activity_type = COR_activity_coronation_ceremony_hof
								has_activity_option = {
									category = COR_ceremony_type
									option = COR_ceremony_type_dignified
								}
							}
						}
					}
				}
				desc = COR_ceremony.0320.desc.dignified
			}
			triggered_desc = {
				trigger = {
					scope:activity = {
						OR = {
							has_activity_type = activity_HRT_italienzug
							AND = {
								has_activity_type = COR_activity_coronation_ceremony
								has_activity_option = {
									category = COR_ceremony_type
									option = COR_ceremony_type_extravagant
								}
							}
							AND = {
								has_activity_type = COR_activity_coronation_ceremony_hof
								has_activity_option = {
									category = COR_ceremony_type
									option = COR_ceremony_type_extravagant
								}
							}
						}
					}
				}
				desc = COR_ceremony.0320.desc.extravagant
			}
		}
	}

	theme = crown
	override_background = { reference = temple }

	right_portrait = {
		character = root
		animation = personality_honorable
	}

	immediate = { }

	option = {
		name = COR_ceremony.0320.a
	}
}

# ON END - CEREMONY

# For host
COR_ceremony.0322 = {
	type = activity_event
	title = COR_ceremony.0322.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					OR = {
						has_title = title:e_hre
						HRT_is_emperor_trigger = yes
					}
				}
				desc = COR_ceremony.0322.desc_hre.1
			}
			triggered_desc = {
				trigger = {
					has_nickname = HRT_in_romanorum_regem_electus
				}
				desc = COR_ceremony.0322.desc_king_of_the_germans.1
			}
			random_valid = {
				triggered_desc = {
					trigger = {
						OR = {
							has_trait = education_diplomacy_3
							has_trait = education_diplomacy_4
							has_trait = education_diplomacy_5
							has_trait = education_stewardship_3
							has_trait = education_stewardship_4
							has_trait = education_stewardship_5
							has_trait = diplomat
							has_trait = administrator
							has_trait = ambitious
						}
					}
					desc = COR_ceremony.0322.desc_diplo
				}
				triggered_desc = {
					trigger = {
						OR = {
							has_trait = education_learning_3
							has_trait = education_learning_4
							has_trait = education_learning_5
							has_trait = scholar
							has_trait = theologian
							has_trait = zealous
							has_character_modifier = bp1_superstition_modifier
						}
					}
					desc = COR_ceremony.0322.desc_religious
				}
				triggered_desc = {
					trigger = {
						OR = {
							has_trait = lifestyle_reveler
							has_trait = gluttonous
							has_trait = gregarious
							has_trait = drunkard
							has_trait = hashishiyah
						}
					}
					desc = COR_ceremony.0322.desc_party
				}
				triggered_desc = {
					trigger = {
						OR = {
							has_trait = chaste
							has_trait = humble
							has_trait = shy
							has_trait = reclusive
						}
					}
					desc = COR_ceremony.0322.desc_shy
				}
				triggered_desc = {
					trigger = {
						OR = {
							has_trait = wrathful
							has_trait = arrogant
							has_trait = callous
							has_trait = irritable
							has_trait = impatient
						}
					}
					desc = COR_ceremony.0322.desc_arrogant
				}
				triggered_desc = {
					trigger = {
						OR = {
							has_trait = paranoid
							has_trait = craven
						}
					}
					desc = COR_ceremony.0322.desc_paranoid
				}
				desc = COR_ceremony.0322.desc
			}
		}
	}
	theme = crown
	override_background = { reference = temple }
	left_portrait = {
		character = scope:COR_coronator
		animation = wedding_priest
	}
	right_portrait = {
		character = root
		animation = throne_room_bow_1 #throne_room_kneel_1
	}

	trigger = {
		this = scope:COR_ruler
	}

	immediate = {
		play_sound_effect = "event:/DLC/EP2/SFX/Stingers/Grand_Activities/ep2_mx_sting_wedding_west" #TODO
	}

	option = {
		name = COR_ceremony.0322.a
		add_internal_flag = dangerous
		trigger = {
			is_ai = no
			is_adult = yes # Has to be strong enough to grab the crown from the Pope's clutches.
			highest_held_title_tier = tier_empire
			scope:COR_coronator = {
				this = faith:catholic.religious_head
			}
			OR = {
				trigger_if = {
					limit = {
						scope:activity = {
							has_activity_type = COR_activity_coronation_ceremony_hof
						}
					}
					scope:activity = {
						has_activity_option = {
							category = COR_ceremony_type
							option = COR_ceremony_type_extravagant #Only allowed to screw everything up if you have spent the most money in it already.
						}
					}
				}
				trigger_if = {
					limit = {
						scope:activity = {
							has_activity_type = activity_HRT_italienzug
						}
					}
					scope:activity = {
						has_activity_option = {
							category = HRT_italienzug_expedition_type
							option = HRT_italienzug_expedition_type_grand
						}
					}
				}
			}
			OR = {
				has_trait = lunatic
				has_trait = possessed
				has_trait = eccentric
				AND = {
					has_trait = ambitious
					OR = {
						has_realm_law = crown_authority_3
						has_realm_law = imperial_bureaucracy_3
					}
				}
			}
		}

		switch = {
			trigger = has_trait
			COR_crowned_by_priest = { remove_trait = COR_crowned_by_priest }
			COR_crowned_by_bishop = { remove_trait = COR_crowned_by_bishop }
			COR_crowned_by_pope = { remove_trait = COR_crowned_by_pope }
			HRT_emperor = { remove_trait = HRT_emperor }
		}

		add_trait = COR_crowned_by_myself

		scope:activity.activity_location.county = {
			add_county_modifier = {
				modifier = COR_improved_trade
				years = 10
			}
		}
		add_character_modifier = {
			modifier = COR_extravagant_coronation
			years = 20
		}
		if = {
			limit = {
				is_at_war = yes
			}
			add_character_modifier = {
				modifier = COR_crowned_in_war
				years = 10
			}
		}
		dynasty = { add_dynasty_prestige = medium_dynasty_prestige_gain }

		#Notify all guests
		scope:activity = {
			every_attending_character = {
				limit = {
					NOT = { this = scope:COR_coronator }
				}
				trigger_event = COR_ceremony.0324
			}
		}
		#Notify pope and all vassals
		scope:COR_coronator = {
			trigger_event = COR_ceremony.0325
		}
		every_vassal = {
			limit = {
				NOR = {
					involved_activity ?= { has_activity_type = COR_activity_coronation_ceremony }
					involved_activity ?= { has_activity_type = COR_activity_coronation_ceremony_hof }
				}
			}
			trigger_event = {
				id = COR_ceremony.0325
				days = { 3 10 }
			}
		}

		ai_chance = {
			base = 5
		}
	}
	option = {
		name = COR_ceremony.0322.b

		switch = {
			trigger = has_trait
			COR_crowned_by_priest = { remove_trait = COR_crowned_by_priest }
			COR_crowned_by_bishop = { remove_trait = COR_crowned_by_bishop }
			COR_crowned_by_pope = { remove_trait = COR_crowned_by_pope }
			COR_crowned_by_myself = { remove_trait = COR_crowned_by_myself }
			HRT_emperor = { remove_trait = HRT_emperor }
			COR_byz_crowned_by_patriarch = { remove_trait = COR_byz_crowned_by_patriarch }
		}

		if = {
			limit = {
				OR = {
					has_title = title:e_hre
					HRT_is_emperor_trigger = yes
				}
			}
			add_trait = HRT_emperor
			if = {
				limit = {
					has_nickname = HRT_in_romanorum_regem_electus
				}
				remove_nickname = yes
			}
		}
		else_if = {
			limit = {
				OR = {
					var:COR_coronator_rank ?= 1
					scope:officiant ?= faith:catholic.religious_head
					involved_activity ?= { has_activity_type = COR_activity_coronation_ceremony_hof }
				}
			}
			add_trait = COR_crowned_by_pope
		}
		else_if = {
			limit = { var:COR_coronator_rank ?= 0 }
			add_trait = COR_crowned_by_bishop
		}
		else = {
			add_trait = COR_crowned_by_priest
		}

		if = {
			limit = {
				NOR = {
					has_title = title:e_hre
					HRT_is_emperor_trigger = yes
					has_nickname = HRT_in_romanorum_regem_electus
				}
			}		
			if = {
				limit = { scope:officiant ?= faith:catholic.religious_head }
				add_piety = major_piety_gain
			}
			else = {
				add_piety = minor_piety_gain
			}
			dynasty ?= { add_dynasty_prestige = medium_dynasty_prestige_gain }

			#Assign possible modifier.
			if = {
				limit = {
					scope:activity = {
						NOR = {
							AND = {
								has_activity_type = COR_activity_coronation_ceremony
								has_activity_option = {
									category = COR_ceremony_type
									option = COR_ceremony_type_private
								}
							}
							AND = {
								has_activity_type = COR_activity_coronation_ceremony_hof
								has_activity_option = {
									category = COR_ceremony_type
									option = COR_ceremony_type_private
								}
							}
						}
					}
				}
				scope:activity.activity_location.county = {
					add_county_modifier = {
						modifier = COR_improved_trade
						years = 10
					}
				}
			}
			if = {
				limit = {
					is_at_war = no
					scope:activity = {
						OR = {
							AND = {
								has_activity_type = COR_activity_coronation_ceremony
								has_activity_option = {
									category = COR_ceremony_type
									option = COR_ceremony_type_private
								}
							}
							AND = {
								has_activity_type = COR_activity_coronation_ceremony_hof
								has_activity_option = {
									category = COR_ceremony_type
									option = COR_ceremony_type_private
								}
							}
						}
					}
					NOT = { var:COR_coronator_rank ?= 1 }
				}
				add_character_modifier = {
					modifier = COR_crowned_in_barn
					years = 20
				}
			}
			else_if = {
				limit = {
					is_at_war = yes
				}
				add_character_modifier = {
					modifier = COR_crowned_in_war
					years = 20
				}
			}
			if = {
				limit = {
					scope:activity = {
						OR = {
							AND = {
								has_activity_type = activity_HRT_italienzug
								has_activity_option = {
									category = HRT_italienzug_expedition_type
									option = HRT_italienzug_expedition_type_grand
								}
							}
							AND = {
								has_activity_type = COR_activity_coronation_ceremony
								has_activity_option = {
									category = COR_ceremony_type
									option = COR_ceremony_type_extravagant
								}
							}
							AND = {
								has_activity_type = COR_activity_coronation_ceremony_hof
								has_activity_option = {
									category = COR_ceremony_type
									option = COR_ceremony_type_extravagant
								}
							}
						}
					}
				}
				add_character_modifier = {
					modifier = COR_extravagant_coronation
					years = 20
				}
			}

			# Progress to next phase
			hidden_effect = {
				scope:activity = { progress_activity_phase_after = { days = 1 } }
			}
		}
		else_if = {
			limit = {
				OR = {
					has_title = title:e_hre
					HRT_is_emperor_trigger = yes
					has_nickname = HRT_in_romanorum_regem_electus
				}
			}
			if = {
				limit = {
					is_at_war = yes
				}
				add_character_modifier = {
					modifier = COR_crowned_in_war
					years = 20
				}
			}
			trigger_event = COR_ceremony.0326 # Because the desc is too long. I will never sort this event id
		}

		ai_chance = {
			base = 95
		}
	}

	after = {
		remove_character_flag = HRT_italienzug
		remove_character_flag = COR_flag_preparing_coronation
		remove_variable = COR_years_reigned
		remove_variable = COR_coronation_request_cooldown
		remove_variable = COR_coronator_rank
		remove_character_modifier ?= COR_uncrowned_modifier
		scope:COR_coronator = {
			remove_list_variable = {
				name = COR_coronation_targets
				target = scope:COR_ruler
			}
		}
		if = {
			limit = {
				NOT = { has_nickname = nick_the_crownless }
			}
			remove_character_flag = sold_crown_charmod
		}
		every_spouse = {
			limit = {
				NOT = { has_nickname = nick_the_crownless }
				has_character_flag = sold_crown_charmod
			}
			remove_character_flag = sold_crown_charmod
		}
	}
}

# For guests
COR_ceremony.0323 = {
	type = activity_event
	title = COR_ceremony.0322.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:host = {
						OR = {
							has_title = title:e_hre
							HRT_is_emperor_trigger = yes
						}
					}
				}
				desc = COR_ceremony.0323.desc_hre.1
			}
			triggered_desc = {
				trigger = {
					scope:host = {
						has_nickname = HRT_in_romanorum_regem_electus
					}
				}
				desc = COR_ceremony.0323.desc_king_of_the_germans.1
			}
			triggered_desc = {
				trigger = {
					scope:host = {
						is_adult = no
					}
				}
				desc = COR_ceremony.0323.desc_child
			}
			desc = COR_ceremony.0323.desc
		}
	}
	theme = crown
	override_background = { reference = temple }
	left_portrait = {
		character = scope:COR_coronator
		animation = wedding_priest
	}
	right_portrait = {
		character = scope:COR_ruler
		animation = throne_room_bow_1 #throne_room_kneel_1
	}

	trigger = {
		NOR = {
			this = scope:COR_ruler
			this = scope:COR_coronator
		}
	}

	immediate = {
		play_sound_effect = "event:/DLC/EP2/SFX/Stingers/Grand_Activities/ep2_mx_sting_wedding_west" #TODO
	}

	option = {
		name = COR_ceremony.0323.a
		trigger = {
			scope:host = {
				NOR = {
					has_title = title:e_hre
					HRT_is_emperor_trigger = yes
					has_nickname = HRT_in_romanorum_regem_electus
				}
			}
		}
	}
	option = {
		name = COR_ceremony.7322.a
		trigger = {
			scope:host = {
				OR = {
					has_title = title:e_hre
					HRT_is_emperor_trigger = yes
					has_nickname = HRT_in_romanorum_regem_electus
				}
			}
		}
		trigger_event = COR_ceremony.0327
	}
}

#Crazy Napoleon ruler snatched the crown from the Pope's hands and crowned himself Emperor.
#For host and guests
COR_ceremony.0324 = {
	type = activity_event
	title = COR_ceremony.0324.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					root = scope:COR_ruler #Desc for Ruler.
				}
				desc = COR_ceremony.0324.desc_host
			}
			desc = COR_ceremony.0324.desc #Desc for Guests.
		}
	}
	theme = crown
	override_background = { reference = temple }

	left_portrait = {
		character = scope:COR_coronator
		animation = fear
	}
	right_portrait = {
		character = scope:COR_ruler
		animation = war_attacker
	}

	immediate = { }

	option = {
		name = COR_ceremony.0324.a_host

		trigger = {
			root = scope:COR_ruler
		}

		add_prestige = major_prestige_gain
		add_piety = major_piety_loss
		add_trait = excommunicated
		add_character_flag = COR_selfcrowned
	}
	option = {
		name = COR_ceremony.0324.a
		trigger = {
			NOT = { root = scope:COR_ruler }
		}
	}
}

#For pope and vassals
COR_ceremony.0325 = {
	type = character_event
	title = COR_ceremony.0324.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					root = scope:COR_coronator #Desc for Pope.
				}
				desc = COR_ceremony.0325.desc_pope
			}
			desc = COR_ceremony.0325.desc #Desc for Vassals.
		}
	}
	theme = crown
	override_background = { reference = temple }

	left_portrait = {
		character = scope:COR_coronator
		animation = fear
	}
	right_portrait = {
		character = scope:COR_ruler
		animation = personality_bold
	}

	immediate = { }

	option = {
		name = COR_ceremony.0325.a_pope
		trigger = {
			root = scope:COR_coronator
		}
		custom_tooltip = COR_ceremony.0325.a_pope.tt
	}
	option = {
		name = COR_ceremony.0325.a
		trigger = {
			NOT = { root = scope:COR_coronator }
		}
	}
}

#HRE coronation for host part 2
COR_ceremony.0326 = {
	type = activity_event
	title = COR_ceremony.0322.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					OR = {
						has_title = title:e_hre
						HRT_is_emperor_trigger = yes
					}
				}
				desc = COR_ceremony.0322.desc_hre.2
			}
			triggered_desc = {
				trigger = {
					has_nickname = HRT_in_romanorum_regem_electus
				}
				desc = COR_ceremony.0322.desc_king_of_the_germans.2
			}
		}
	}
	theme = crown
	override_background = { reference = temple }
	left_portrait = {
		character = scope:COR_coronator
		animation = personality_zealous
	}
	right_portrait = {
		character = root
		triggered_animation = {
			trigger = {
				exists = global_var:cfp_is_loaded
			}
			animation = cfp_globus
		}
		animation = scepter
	}

	immediate = {
	}

	option = {
		name = COR_ceremony.7322.a
		
		if = {
			limit = { scope:officiant ?= faith:catholic.religious_head }
			add_piety = major_piety_gain
		}
		else = {
			add_piety = minor_piety_gain
		}
		dynasty ?= { add_dynasty_prestige = medium_dynasty_prestige_gain }

		#Assign possible modifier.
		if = {
			limit = {
				scope:activity = {
					NOR = {
						AND = {
							has_activity_type = COR_activity_coronation_ceremony
							has_activity_option = {
								category = COR_ceremony_type
								option = COR_ceremony_type_private
							}
						}
						AND = {
							has_activity_type = COR_activity_coronation_ceremony_hof
							has_activity_option = {
								category = COR_ceremony_type
								option = COR_ceremony_type_private
							}
						}
					}
				}
			}
			scope:activity.activity_location.county = {
				add_county_modifier = {
					modifier = COR_improved_trade
					years = 10
				}
			}
		}
		if = {
			limit = {
				is_at_war = no
				scope:activity = {
					OR = {
						AND = {
							has_activity_type = COR_activity_coronation_ceremony
							has_activity_option = {
								category = COR_ceremony_type
								option = COR_ceremony_type_private
							}
						}
						AND = {
							has_activity_type = COR_activity_coronation_ceremony_hof
							has_activity_option = {
								category = COR_ceremony_type
								option = COR_ceremony_type_private
							}
						}
					}
				}
				NOT = { var:COR_coronator_rank ?= 1 }
			}
			add_character_modifier = {
				modifier = COR_crowned_in_barn
				years = 20
			}
		}
		if = {
			limit = {
				scope:activity = {
					OR = {
						AND = {
							has_activity_type = activity_HRT_italienzug
							has_activity_option = {
								category = HRT_italienzug_expedition_type
								option = HRT_italienzug_expedition_type_grand
							}
						}
						AND = {
							has_activity_type = COR_activity_coronation_ceremony
							has_activity_option = {
								category = COR_ceremony_type
								option = COR_ceremony_type_extravagant
							}
						}
						AND = {
							has_activity_type = COR_activity_coronation_ceremony_hof
							has_activity_option = {
								category = COR_ceremony_type
								option = COR_ceremony_type_extravagant
							}
						}
					}
				}
			}
			add_character_modifier = {
				modifier = COR_extravagant_coronation
				years = 20
			}
		}

		# Progress to next phase
		hidden_effect = {
			scope:activity = { progress_activity_phase_after = { days = 1 } }
		}
		ai_chance = {
			base = 95
		}
	}
}

#HRE coronation for guests part 2
COR_ceremony.0327 = {
	type = activity_event
	title = COR_ceremony.0322.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:host = {
						OR = {
							has_title = title:e_hre
							HRT_is_emperor_trigger = yes
						}
					}
				}
				desc = COR_ceremony.0323.desc_hre.2
			}
			triggered_desc = {
				trigger = {
					scope:host = {
						has_nickname = HRT_in_romanorum_regem_electus
					}
				}
				desc = COR_ceremony.0323.desc_king_of_the_germans.2
			}
		}
	}
	theme = crown
	override_background = { reference = temple }
	left_portrait = {
		character = scope:COR_coronator
		animation = personality_zealous
	}
	right_portrait = {
		character = scope:COR_ruler
		triggered_animation = {
			trigger = {
				exists = global_var:cfp_is_loaded
			}
			animation = cfp_globus
		}
		animation = scepter
	}

	immediate = {
	}

	option = {
		name = COR_ceremony.0323.a_hre # Hail Caesar
		trigger = {
			scope:host = {
				OR = {
					has_title = title:e_hre
					HRT_is_emperor_trigger = yes
				}
			}
		}
	}
	option = {
		name = COR_ceremony.0323.a # Hail the King
		trigger = {
			scope:host = {
				NOR = {
					has_title = title:e_hre
					HRT_is_emperor_trigger = yes
				}
			}
		}
	}
}

# CEREMONY EVENT PULSE

##################################################
# Gatecrashers
# by Claudia Baldassi
# ep2_wedding.1160
##################################################

# Some pesants are at the gate of the festivity - what do you do?

COR_ceremony.0330 = {
	type = activity_event
	title = ep2_wedding.1160.t
	desc = COR_ceremony.0330.desc
	theme = wedding_ceremony_activity
	left_portrait = {
		character = root
		animation = schadenfreude
	}

	lower_right_portrait = scope:host

	cooldown = { years = 1 }

	widget = {
		gui = "event_window_widget_activity_intent"
		container = "custom_widgets_container"
	}

	trigger = {
		has_activity_intent = banquet_mischief_intent
		NOR = {
			this = scope:host
			this = scope:activity.special_guest:COR_coronator
		}
		scope:activity = {
			NOT = {
				has_variable = has_had_1160_event
			}
		}
	}

	weight_multiplier = {
		base = 1
	}

	immediate = {
		add_character_flag = busy_in_ceremony_event
		scope:activity = {
			set_variable = has_had_1160_event
		}
	}

	# Option A: let the peasants in
	option = {
		name = ep2_wedding.1160.a
		flavor = ep2_wedding.1160.a.tt
		# for the follow-up event
		root = {
			save_scope_as = mischief_maker
		}
		scope:host = { trigger_event = COR_ceremony.0331 }
		stress_impact = {
			base = minor_stress_impact_loss
			wrathful = medium_stress_impact_loss
			impatient = medium_stress_impact_loss
			arrogant = medium_stress_impact_loss
			deceitful = major_stress_impact_loss
			arbitrary = major_stress_impact_loss
			callous = major_stress_impact_loss
			fickle = major_stress_impact_loss
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = deceitful
				add = 50
			}
			modifier = {
				has_trait = arbitrary
				add = 50
			}
			modifier = {
				has_trait = callous
				add = 50
			}
			modifier = {
				has_trait = fickle
				add = 50
			}
		}
	}

	# Option B: smuggle food to the pesants
	option = {
		name = ep2_wedding.1160.b
		flavor = ep2_wedding.1160.b.tt
		stress_impact = {
			base = minor_stress_impact_loss
			gluttonous = medium_stress_impact_loss
			diligent = medium_stress_impact_loss
			generous = major_stress_impact_loss
			humble = major_stress_impact_loss
			gregarious = major_stress_impact_loss
			compassionate = massive_stress_impact_loss
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = generous
				add = 50
			}
			modifier = {
				has_trait = humble
				add = 50
			}
			modifier = {
				has_trait = gregarious
				add = 50
			}
			modifier = {
				has_trait = compassionate
				add = 50
			}
		}
	}

	# Option C: this is below me
	option = {
		name = ep2_wedding.1160.c	
		stress_impact = {
			greedy = minor_stress_impact_loss
			temperate = minor_stress_impact_loss
			lazy = minor_stress_impact_loss
			honest = medium_stress_impact_loss
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = lazy
				add = 50
			}
			modifier = {
				has_trait = honest
				add = 50
			}
		}
	}

	after = {
		remove_character_flag = busy_in_ceremony_event
	}
}

# Follow-up for the host

COR_ceremony.0331 = {
	type = activity_event
	title = ep2_wedding.1160.t
	desc = ep2_wedding.1161.desc
	theme = wedding_ceremony_activity
	left_portrait = {
		character = root
		animation = anger
	}

	cooldown = { years = 1 }

	weight_multiplier = {
		base = 1
	}

	immediate = {
		add_character_flag = busy_in_ceremony_event
	}

	# Option A: kick them out!
	option = {
		name = ep2_wedding.1161.a
		duel = {
			skill = martial
			value = average_skill_rating
			50 = {
				# Success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = ep2_wedding.1161.success
				send_interface_toast = {
					title = ep2_wedding.1161.success.tt
					left_icon = root
					scope:activity = {
						add_activity_log_entry = {
							key = wedding_peasant_invasion_managed_log
							tags = { good }
							score = 20
							character = root

							root = {
								add_character_modifier = {
									modifier = COR_enforced_security_modifier
									years = 5
								}
							}
						}
					}

					stress_impact = {
						base = minor_stress_impact_loss
						wrathful = medium_stress_impact_loss
						arrogant = medium_stress_impact_loss
						callous = major_stress_impact_loss
						paranoid = massive_stress_impact_loss
					}
				}
				scope:mischief_maker = {
					send_interface_toast = {
						title = ep2_wedding.1161.success.tt2
						left_icon = root
					}
				}
			}
			50 = {
				# Failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = ep2_wedding.1161.failure
				send_interface_toast = {
					title = ep2_wedding.1161.failure.tt
					left_icon = root
					scope:activity = {
						add_activity_log_entry = {
							key = wedding_peasant_invasion_not_managed_log
							tags = { bad }
							score = 20
							character = root

							root = {
								add_character_modifier = {
									modifier = COR_peasants_overrun_modifier
									years = 5
								}
							}
						}
					}
					stress_impact = {
						wrathful = medium_stress_impact_gain
						arrogant = medium_stress_impact_gain
						callous = medium_stress_impact_gain
						paranoid = major_stress_impact_gain
					}
				}
				scope:mischief_maker = {
					send_interface_toast = {
						title = ep2_wedding.1161.failure.tt2
						left_icon = root
					}
				}
			}
		}
		ai_chance = {
			base = 100
		}
	}

	# Option B: let them stay
	option = {
		name = ep2_wedding.1161.b
		scope:activity = {
			add_activity_log_entry = {
				key = wedding_peasant_invasion_stay_log
				tags = { bad }
				score = 20
				character = root

				root.location.county = {
					add_county_modifier = {
						modifier = COR_peasants_connections_county_modifier
						years = 5
					}
				}
			}
		}
		if = {
			limit = {
				has_activity_intent = reduce_stress_intent
			}
			stress_impact = {
				base = medium_stress_impact_loss
			}
		}
		else = {
			stress_impact = {
				generous = medium_stress_impact_loss
				humble = medium_stress_impact_loss
				gregarious = medium_stress_impact_loss
				compassionate = medium_stress_impact_loss
				paranoid = medium_stress_impact_gain
				greedy = medium_stress_impact_gain
			}
		}
		scope:mischief_maker = {
			send_interface_toast = {
				title = ep2_wedding.1161.b.tt
				left_icon = root
			}
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = compassionate
				add = 50
			}
			modifier = {
				has_trait = gregarious
				add = 50
			}
			modifier = {
				has_trait = humble
				add = 50
			}
			modifier = {
				has_trait = generous
				add = 50
			}
		}
	}

	after = {
		remove_character_flag = busy_in_ceremony_event
	}
}

##################################################
# The Parade
# by Claudia Baldassi
# ep2_wedding.1170
##################################################

# Ruler has arrived with a whole parade. Interact with it

COR_ceremony.0340 = {
	type = activity_event
	title = ep2_wedding.1170.t
	desc = {
		desc = COR_ceremony.0331.desc
		triggered_desc = {
			trigger = {
				has_activity_intent = reduce_stress_intent
			}
			desc = ep2_wedding.1170.desc_relax
		}
		triggered_desc = {
			trigger = {
				has_activity_intent = banquet_mischief_intent
			}
			desc = ep2_wedding.1170.desc_mischief
		}
		triggered_desc = {
			trigger = {
				has_activity_intent = murder_attendee_intent
			}
			desc = ep2_wedding.1170.desc_murder
		}
	}
	theme = wedding_ceremony_activity
	left_portrait = {
		character = root
		animation = ecstasy
	}
	lower_center_portrait = scope:COR_ruler
	lower_right_portrait = scope:murderee

	cooldown = { years = 1 }

	trigger = {
		scope:activity = {
			has_activity_option = {
				category = COR_ceremony_option_decoration
				option = COR_ceremony_decoration_good
			}
		}
		NOR = {
			this = scope:host
			this = scope:activity.special_guest:COR_coronator
		}
		NOT = {
			scope:activity = {
				has_variable = has_had_event_1170
			}
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			OR = {
				has_activity_intent = reduce_stress_intent
				has_activity_intent = banquet_mischief_intent
			}
			add = 2
		}
		modifier = {
			has_activity_intent = murder_attendee_intent
			add = 1
		}
	}

	immediate = {
		add_character_flag = busy_in_ceremony_event
		scope:activity = {
			set_variable = has_had_event_1170
		}
		scope:host = { save_scope_as = COR_ruler }
		if = {
			limit = {
				has_activity_intent = murder_attendee_intent
			}
			intent_target = {
				save_scope_as = murderee
				add_character_flag = busy_in_ceremony_event
			}
		}
		scope:activity = {
			add_activity_log_entry = {
				key = COR_ceremony_parade_arrival_log
				tags = { good }
				score = 20
				character = scope:COR_ruler
			}
		}
	}

	# Option A: Pocket some horseshoes
	option = {
		name = ep2_wedding.1170.a
		flavor = ep2_wedding.1170.a.tt
		add_gold = minor_gold_value
		stress_impact = {
			greedy = medium_stress_impact_loss
			generous = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = 1
			}
		}
	}

	# Option B: What a show
	option = {
		name = ep2_wedding.1170.b
		trigger = {
			NOT = {
				has_activity_intent = reduce_stress_intent
			}
		}
		flavor = ep2_wedding.1170.b.tt
		stress_impact = {
			base = minor_stress_impact_loss
			generous = medium_stress_impact_loss
			compassionate = medium_stress_impact_loss
			greedy = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = -1
			}
		}
	}

	# Option C: Enjoy the show
	option = {
		name = ep2_wedding.1170.c
		trigger = {
			has_activity_intent = reduce_stress_intent
		}
		custom_tooltip = available_because_intent_tt
		stress_impact = {
			base = medium_stress_impact_loss
			humble = major_stress_impact_loss
			compassionate = major_stress_impact_loss
			gregarious = major_stress_impact_loss
			trusting = major_stress_impact_loss
			generous = major_stress_impact_loss
		}
		ai_chance = {
			base = 200
		}
	}

	# Option D: mayhem
	option = {
		name = ep2_wedding.1170.d
		trigger = {
			has_activity_intent = banquet_mischief_intent
		}
		custom_tooltip = available_because_intent_tt
		add_character_modifier = {
			modifier = COR_parade_mayhem_modifier
			years = 5
		}
		stress_impact = {
			base = medium_stress_impact_loss
		}
		ai_chance = {
			base = 200
		}
	}

	# Option E: try to kill
	option = {
		name = ep2_wedding.1170.e
		trigger = {
			has_activity_intent = murder_attendee_intent
		}
		flavor = ep2_wedding.1170.e.tt
		custom_tooltip = available_because_intent_tt
		duel = {
			skills = { intrigue prowess }
			target = scope:murderee
			40 = {
				# Success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = ep2_wedding.1170.success
				send_interface_toast = {
					title = ep2_wedding.1170.success.tt
					left_icon = root
					right_icon = scope:murderee
					scope:activity = {
						add_activity_log_entry = {
							key = COR_ceremony_parade_death_log
							tags = { good }
							score = 20
							character = scope:COR_ruler
							target = scope:murderee
						}
					}		
					scope:murderee = {
						death = {
							killer = root
							death_reason = death_plotting
						}
					}
					complete_activity_intent = yes
					stress_impact = {
						base = minor_stress_impact_loss
						vengeful = medium_stress_impact_loss
						paranoid = medium_stress_impact_loss
						deceitful = medium_stress_impact_loss
					}
				}
			}
			60 = {
				# Failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = ep2_wedding.1170.failure
				send_interface_toast = {
					title = ep2_wedding.1170.failure.tt
					left_icon = root
					right_icon = scope:murderee
					stress_impact = {
						base = minor_stress_impact_gain
						vengeful = medium_stress_impact_gain
						paranoid = medium_stress_impact_gain
						deceitful = medium_stress_impact_gain
					}
				}
			}
		}
		
		ai_chance = {
			base = 200
		}
	}

	after = {
		remove_character_flag = busy_in_ceremony_event
		if = {
			limit = {
				intent_target ?= { has_character_flag = busy_in_ceremony_event }
			}
			intent_target = { remove_character_flag = busy_in_ceremony_event }
		}
	}
}

##################################################
# Political Talk
# by Claudia Baldassi
# ep2_wedding.1210
##################################################

# Political talk with a fellow ruler

COR_ceremony.0350 = {
	type = activity_event
	title = ep2_wedding.1210.t
	desc = {
		desc = ep2_wedding.1210.desc
		random_valid = {
			triggered_desc = {
				trigger = {
					scope:talk_to.gold < 0
				}
				desc = ep2_wedding.1210.desc_gold
			}
			triggered_desc = {
				trigger = {
					scope:talk_to = {
						OR = {
							has_trait = shy
							has_trait = craven
						}
					}
				}
				desc = ep2_wedding.1210.desc_fear
			}
			triggered_desc = {
				trigger = {
					scope:talk_to = {
						any_sub_realm_county = {
							any_province = {
								has_province_modifier = recently_looted_modifier
							}
						}
					}
				}
				desc = ep2_wedding.1210.desc_raids
			}
			triggered_desc = {
				trigger = {
					scope:talk_to = {
						OR = {
							any_relation = {
								type = rival
							}
							has_trait = paranoid
						}
					}
				}
				desc = ep2_wedding.1210.desc_rivals
			}
			triggered_desc = {
				trigger = {
					scope:talk_to = {
						age > 65
					}
				}
				desc = ep2_wedding.1210.desc_age
			}
			desc = ep2_wedding.1210.desc_bad_harvest
			desc = ep2_wedding.1210.desc_rain
			desc = ep2_wedding.1210.desc_enemies
		}
	}
	theme = wedding_ceremony_activity
	left_portrait = {
		character = root
		animation = personality_rational
	}
	right_portrait = {
		character = scope:talk_to
		animation = thinking
	}

	cooldown = { years = 1 }

	widget = {
		gui = "event_window_widget_activity_intent"
		container = "custom_widgets_container"
	}

	trigger = {
		is_landed = yes
		has_activity_intent = diplomatic_intent
		intent_target = {
			is_landed = yes
			NOT = { is_vassal_of = root }
			is_ai = yes
			NOR = {
				this = scope:host
				this = scope:activity.special_guest:COR_coronator
			}
		}
		NOR = {
			this = scope:host
			this = scope:activity.special_guest:COR_coronator
		}
	}

	weight_multiplier = {
		base = 1
	}

	immediate = {
		add_character_flag = busy_in_ceremony_event
		intent_target = {
			save_scope_as = talk_to
			add_character_flag = busy_in_ceremony_event
		}
	}

	# Option A: gain hook
	option = {
		name = ep2_wedding.1210.a
		trigger = {
			can_add_hook = {
				target = scope:talk_to
				type = threat_hook
			}
		}
		duel = {
			skill = intrigue
			target = scope:talk_to
			50 = {
				# Success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				modifier = {
					has_trait = schemer
					add = 10
				}
				modifier = {
					has_trait = torturer
					add = 20
				}
				modifier = {
					scope:talk_to = { has_trait = lazy }
					add = 20
				}
				modifier = {
					scope:talk_to = { has_trait = craven }
					add = 20
				}
				desc = ep2_wedding.1210.a.success
				send_interface_toast = {
					title = ep2_wedding.1210.a.success
					left_icon = root
					right_icon = scope:talk_to
					scope:activity = {
						add_activity_log_entry = {
							key = wedding_intimidation_log
							tags = { good }
							score = 20
							character = root
							target = scope:talk_to

							root = {
								add_hook = {
									target = scope:talk_to
									type = threat_hook
								}
							}
						}
					}
					stress_impact = {
						base = minor_stress_impact_loss
						deceitful = medium_stress_impact_loss
						sadistic = medium_stress_impact_loss
						ambitious = medium_stress_impact_loss
					}
				}
			}
			50 = {
				# Failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				modifier = {
					scope:talk_to = { has_trait = torturer }
					add = 20
				}
				modifier = {
					scope:talk_to = { has_trait = brave }
					add = 20
				}
				desc = ep2_wedding.1210.a.failure
				send_interface_toast = {
					title = ep2_wedding.1210.a.failure
					left_icon = root
					right_icon = scope:talk_to
					reverse_add_opinion = {
						target = scope:talk_to
						modifier = threatened_opinion
						opinion = -20
					}
					stress_impact = {
						base = minor_stress_impact_gain
						deceitful = medium_stress_impact_gain
						sadistic = medium_stress_impact_gain
						ambitious = medium_stress_impact_gain
					}
				}
			}
		}
		ai_chance = {
			base = 100
		}
	}

	# Option B: gain alliance
	option = {
		name = ep2_wedding.1210.b
		duel = {
			skill = diplomacy
			target = scope:talk_to
			40 = {
				# Success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				modifier = {
					has_trait = diplomat
					add = 20
				}
				modifier = {
					has_trait = august
					add = 10
				}
				modifier = {
					scope:talk_to = { has_trait = lazy }
					add = 20
				}
				modifier = {
					scope:talk_to = { has_trait = trusting }
					add = 20
				}
				desc = ep2_wedding.1210.b.success
				send_interface_toast = {
					title = ep2_wedding.1210.b.success
					left_icon = root
					right_icon = scope:talk_to
					complete_activity_intent = yes
					scope:activity = {
						add_activity_log_entry = {
							key = wedding_alliance_log
							tags = { good }
							score = 20
							character = root
							target = scope:talk_to

							root = {
								create_alliance = {
									target = scope:talk_to
									allied_through_owner = root
									allied_through_target = scope:talk_to
								}
							}
							scope:talk_to = {
								add_opinion = {
									target = root
									modifier = event_negotiated_alliance_opinion
								}
							}
						}
					}
					stress_impact = {
						base = minor_stress_impact_loss
						ambitious = medium_stress_impact_loss
						gregarious = medium_stress_impact_loss
					}
				}
			}
			60 = {
				# Failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				modifier = {
					scope:talk_to = { has_trait = diplomat }
					add = 20
				}
				modifier = {
					scope:talk_to = { has_trait = august }
					add = 10
				}
				modifier = {
					scope:talk_to = { has_trait = paranoid }
					add = 20
				}
				modifier = {
					scope:talk_to = { has_trait = shy }
					add = 20
				}
				desc = ep2_wedding.1210.b.failure
				send_interface_toast = {
					title = ep2_wedding.1210.b.failure
					left_icon = root
					right_icon = scope:talk_to
					scope:talk_to = {
						add_opinion = {
							target = root
							modifier = suspicion_opinion
							opinion = -10
						}
					}
					stress_impact = {
						base = minor_stress_impact_gain
						ambitious = medium_stress_impact_gain
						gregarious = medium_stress_impact_gain
					}
				}
			}
		}
		ai_chance = {
			base = 100
		}
	}

	# Option C: subjugate
	option = {
		name = ep2_wedding.1210.c
		trigger = {
			scope:talk_to = { activity_wedding_diplomatic_intent_impressible_target = yes }
		}
		duel = {
			skills = { diplomacy intrigue }
			target = scope:talk_to
			30 = {
				# Success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				modifier = {
					has_trait = diplomat
					add = 20
				}
				modifier = {
					has_trait = august
					add = 10
				}
				modifier = {
					scope:talk_to = { has_trait = trusting }
					add = 20
				}
				modifier = {
					scope:talk_to = { has_trait = craven }
					add = 20
				}
				modifier = {
					scope:talk_to = { has_trait = shy }
					add = 20
				}
				desc = ep2_wedding.1210.c.success
				send_interface_toast = {
					title = ep2_wedding.1210.c.success
					left_icon = root
					right_icon = scope:talk_to
					complete_activity_intent = yes
					scope:activity = {
						add_activity_log_entry = {
							key = wedding_fealty_log
							tags = { good }
							score = 20
							character = root
							target = scope:talk_to

							root = {
								create_title_and_vassal_change = {
									type = swear_fealty
									save_scope_as = title_change
									add_claim_on_loss = no
								}
								scope:talk_to = {
									change_liege = {
										liege = root
										change = scope:title_change
									}
								}
								resolve_title_and_vassal_change = scope:title_change
							}
						}
					}
					stress_impact = {
						base = minor_stress_impact_loss
						ambitious = major_stress_impact_loss
					}
				}
			}
			70 = {
				# Failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				modifier = {
					scope:talk_to = { has_trait = diplomat }
					add = 20
				}
				modifier = {
					scope:talk_to = { has_trait = august }
					add = 10
				}
				modifier = {
					scope:talk_to = { has_trait = paranoid }
					add = 20
				}
				desc = ep2_wedding.1210.c.failure
				send_interface_toast = {
					title = ep2_wedding.1210.c.failure
					left_icon = root
					right_icon = scope:talk_to
					scope:talk_to = {
						add_opinion = {
							target = root
							modifier = suspicion_opinion
							opinion = -20
						}
					}
					stress_impact = {
						base = minor_stress_impact_gain
						ambitious = medium_stress_impact_gain
					}
				}
			}
		}
		ai_chance = {
			base = 100
		}
	}

	after = {
		remove_character_flag = busy_in_ceremony_event
		scope:talk_to = { remove_character_flag = busy_in_ceremony_event }
	}
}

#King has chance to befriend ruler.
COR_ceremony.0360 = {
	type = activity_event
	title = COR_ceremony.0360.t
	desc = COR_ceremony.0360.desc
	theme = wedding_ceremony_activity
	right_portrait = {
		character = root
		animation = idle
	}
	left_portrait = {
		character = scope:COR_potential_friend
		animation = idle
	}

	cooldown = { years = 1 }

	weight_multiplier = {
		base = 1
	}

	trigger = {
		this = scope:host
		scope:activity = {
			NOT = {
				has_variable = has_had_0360_event
			}
			any_attending_character = {
				is_independent_ruler = yes
				NOR = {
					this = scope:host
					this = scope:activity.special_guest:COR_coronator
					has_any_relation_trigger = { CHARACTER = scope:host }
					any_relation = {
						type = friend
						count > 2
					}
				}
				opinion = {
					target = scope:host
					value > low_negative_opinion
				}
			}
		}
	}
	
	immediate = {
		scope:activity = {
			set_variable = has_had_0360_event
			random_attending_character = {
				limit = {
					is_independent_ruler = yes
					NOR = {
						this = scope:host
						this = scope:activity.special_guest:COR_coronator
						has_any_relation_trigger = { CHARACTER = scope:host }
						any_relation = {
							type = friend
							count > 2
						}
					}
					opinion = {
						target = scope:host
						value > low_negative_opinion
					}
				}
				save_scope_as = COR_potential_friend
			}
		}
	}
	
	option = {
		name = COR_ceremony.0360.a
		scope:COR_potential_friend = { 
			trigger_event = COR_ceremony.0362
		}
		stress_impact = {
			shy = medium_stress_impact_gain
			paranoid = medium_stress_impact_gain
		}
		ai_chance = { 	
			base = 90
			modifier = { 
				factor = 0.5
				has_trait = shy
			}	
			modifier = { 
				factor = 0.5
				has_trait = paranoid
			}	
		}
	}
	option = {
		name = COR_ceremony.0360.b
		ai_chance = { 	
			base = 10	
		}
	}
}

#King has chance to befriend vassal.
COR_ceremony.0361 = {
	type = activity_event
	title = COR_ceremony.0360.t
	desc = COR_ceremony.0361.desc
	theme = wedding_ceremony_activity
	right_portrait = {
		character = root
		animation = idle
	}
	left_portrait = {
		character = scope:COR_potential_friend
		animation = idle
	}

	cooldown = { years = 1 }

	weight_multiplier = {
		base = 1
	}

	trigger = {
		this = scope:host
		scope:activity = {
			NOT = {
				has_variable = has_had_0360_event
			}
			any_attending_character = {
				is_vassal_of = root
				NOR = {
					this = scope:host
					this = scope:activity.special_guest:COR_coronator
					is_heir_of = scope:host
					is_consort_of = scope:host
					is_close_or_extended_family_of = scope:host
					has_relation_lover = scope:host
					has_relation_guardian = scope:host
					has_relation_ward = scope:host
					AND = {
						has_employed_any_court_position = yes
						any_court_position_holder = {
							this = scope:host
						}
					}
					any_relation = {
						type = friend
						count > 2
					}
				}
				opinion = {
					target = scope:host
					value > low_negative_opinion
				}
				can_set_relation_friend_trigger = {
					CHARACTER = scope:host
				}
			}
		}
	}
	
	immediate = {
		scope:activity = {
			set_variable = has_had_0360_event
			random_attending_character = {
				limit = {
					is_vassal_of = root
					NOR = {
						this = scope:host
						this = scope:activity.special_guest:COR_coronator
						is_heir_of = scope:host
						is_consort_of = scope:host
						is_close_or_extended_family_of = scope:host
						has_relation_lover = scope:host
						has_relation_guardian = scope:host
						has_relation_ward = scope:host
						AND = {
							has_employed_any_court_position = yes
							any_court_position_holder = {
								this = scope:host
							}
						}
						any_relation = {
							type = friend
							count > 2
						}
					}
					opinion = {
						target = scope:host
						value > low_negative_opinion
					}
					can_set_relation_friend_trigger = {
						CHARACTER = scope:host
					}
				}
				save_scope_as = COR_potential_friend
			}
		}
	}
	
	option = {
		name = COR_ceremony.0360.a
		scope:COR_potential_friend = { 
			trigger_event = COR_ceremony.0362
		}
		stress_impact = {
			shy = medium_stress_impact_gain
			paranoid = medium_stress_impact_gain
		}
		ai_chance = { 	
			base = 90
			modifier = { 
				factor = 0.5
				has_trait = shy
			}	
			modifier = { 
				factor = 0.5
				has_trait = paranoid
			}	
		}
	}
	option = {
		name = COR_ceremony.0360.b
		ai_chance = { 	
			base = 10	
		}
	}
}

#Foreign ruler/Vassal: King wants to become your friend.
COR_ceremony.0362 = {
	type = activity_event
	title = COR_ceremony.0360.t
	desc = COR_ceremony.0362.desc
	theme = wedding_ceremony_activity
	left_portrait = {
		character = root
		animation = throne_room_conversation_4
	}
	right_portrait = {
		character = scope:host
		animation = throne_room_conversation_1
	}
	
	immediate = { }
	
	option = {
		name = COR_ceremony.0362.a
		custom_tooltip = COR_ceremony.0362.a.tt
		set_relation_friend = {
			reason = friend_politics
			target = scope:host
		}
		scope:host = {
			trigger_event = COR_ceremony.0363
		}
		ai_chance = {
			base = 90
			modifier = {
				factor = 0.8
				scope:host = { has_trait = shy }
			}	
			modifier = {
				factor = 0.75
				scope:host = { has_trait = sadistic }
				NOT = { has_trait = sadistic }
			}
			modifier = {
				factor = 0.5
				has_trait = callous
			}
		}
	}
	option = {
		name = COR_ceremony.0360.b
		scope:host = {
			trigger_event = COR_ceremony.0364
		}
		ai_chance = {
			base = 10
		}
	}
}

#King: you've acquired a new friend.
COR_ceremony.0363 = {
	type = activity_event
	title = COR_ceremony.0360.t
	desc = COR_ceremony.0363.desc
	theme = wedding_ceremony_activity
	right_portrait = {
		character = root
		animation = toast
	}
	left_portrait = {
		character = scope:COR_potential_friend
		animation = toast
	}
	
	immediate = { }
	
	option = {
		name = COR_ceremony.0499.a #Excellent
		custom_tooltip = COR_ceremony.0363.a.tt
		ai_chance = {
			base = 100
		}
	}
}

#King: you have not acquired a new friend.
COR_ceremony.0364 = {
	type = activity_event
	title = COR_ceremony.0360.t
	desc = COR_ceremony.0364.desc
	theme = wedding_ceremony_activity
	right_portrait = {
		character = root
		animation = dismissal
	}
	left_portrait = {
		character = scope:COR_potential_friend
		animation = disapproval
	}
	
	immediate = { }
	
	option = {
		name = COR_ceremony.0364.a
		ai_chance = {
			base = 100
		}
	}
}

#King talks with guests, chance to gain diplomacy or stewardship.
COR_ceremony.0370 = {
	type = activity_event
	title = COR_ceremony.0370.t
	desc = COR_ceremony.0370.desc
	theme = wedding_ceremony_activity
	left_portrait = {
		character = scope:COR_diplomat
		animation = chancellor
	}
	right_portrait = {
		character = scope:COR_steward
		animation = steward
	}

	cooldown = { years = 1 }

	weight_multiplier = {
		base = 1
	}

	trigger = {
		this = scope:host
		scope:activity = {
			NOT = {
				has_variable = has_had_0370_event
			}
			any_attending_character = {
				NOR = {
					this = scope:host
					this = scope:activity.special_guest:COR_coronator
				}
				OR = {
					is_ruler = yes
					is_councillor = yes
				}
				diplomacy > excellent_skill_level
			}
			any_attending_character = {
				NOR = {
					this = scope:host
					this = scope:activity.special_guest:COR_coronator
				}
				OR = {
					is_ruler = yes
					is_councillor = yes
				}
				stewardship > excellent_skill_level
			}
		}
	}

	immediate = {
		scope:activity = {
			set_variable = has_had_0370_event
			ordered_attending_character = {
				limit = {
					NOR = {
						this = scope:host
						this = scope:activity.special_guest:COR_coronator
					}
					OR = {
						is_ruler = yes
						is_councillor = yes
					}
					diplomacy > excellent_skill_level
				}
				order_by = diplomacy
				save_scope_as = COR_diplomat
			}
			ordered_attending_character = {
				limit = {
					NOR = {
						this = scope:host
						this = scope:activity.special_guest:COR_coronator
						this = scope:COR_diplomat
					}
					OR = {
						is_ruler = yes
						is_councillor = yes
					}
					learning > excellent_skill_level
				}
				order_by = stewardship
				save_scope_as = COR_steward
			}
		}
	}

	option = {
		name = COR_ceremony.0370.a
		add_character_modifier = {
			modifier = confident_diplomat
			years = 5
		}
		ai_chance = {
			base = 50
			modifier = {
				factor = 0.5
				diplomacy < decent_skill_rating
			}
		}
	}
	option = {
		name = COR_ceremony.0370.b
		add_character_modifier = {
			modifier = confident_organizer
			years = 5
		}
		ai_chance = {
			base = 50
			modifier = {
				factor = 0.5
				stewardship < decent_skill_rating
			}
		}
	}
}

#King talks with guests, chance to gain diplomacy or stewardship.
COR_ceremony.0371 = {
	type = activity_event
	title = COR_ceremony.0370.t
	desc = COR_ceremony.0371.desc
	theme = wedding_ceremony_activity
	override_background = { reference = temple }
	left_portrait = {
		character = scope:COR_scholar1
		animation = thinking
	}
	right_portrait = {
		character = scope:COR_scholar2
		animation = happy_teacher
	}

	cooldown = { years = 1 }

	weight_multiplier = {
		base = 1
	}

	trigger = {
		this = scope:host
		scope:activity = {
			NOT = {
				has_variable = has_had_0370_event
			}
			any_attending_character = {
				NOR = {
					this = scope:host
					this = scope:activity.special_guest:COR_coronator
				}
				learning > excellent_skill_level
				count >= 2
			}
		}
	}

	immediate = {
		scope:activity = {
			set_variable = has_had_0370_event
			ordered_attending_character = {
				limit = {
					NOR = {
						this = scope:host
						this = scope:activity.special_guest:COR_coronator
					}
					learning > excellent_skill_level
				}
				order_by = learning
				save_scope_as = COR_scholar1
			}
			ordered_attending_character = {
				limit = {
					NOR = {
						this = scope:host
						this = scope:activity.special_guest:COR_coronator
						this = scope:COR_scholar1
					}
					learning > excellent_skill_level
				}
				order_by = learning
				save_scope_as = COR_scholar2
			}
		}
		scope:activity.special_guest:COR_coronator = { save_scope_as = COR_coronator }
	}

	option = {
		name = COR_ceremony.0371.a
		add_character_modifier = {
			modifier = confident_schemer
			years = 5
		}
		ai_chance = {
			base = 50
			modifier = {
				factor = 0.5
				intrigue < decent_skill_rating
			}
		}
	}
	option = {
		name = COR_ceremony.0371.b
		add_character_modifier = {
			modifier = confident_scholar
			years = 5
		}
		ai_chance = {
			base = 50
			modifier = {
				factor = 0.5
				learning < decent_skill_rating
			}
		}
	}
}

#King shows off with guests, chance to improve opinion.
COR_ceremony.0380 = {
	type = activity_event
	title = COR_ceremony.0380.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					root = { is_adult = no }
				}
				desc = COR_ceremony.0380.desc_child
			}
			desc = COR_ceremony.0380.desc
		}
	}
	theme = wedding_ceremony_activity

	right_portrait = {
		character = root
		animation = idle
	}

	cooldown = { years = 1 }

	weight_multiplier = {
		base = 1
	}

	trigger = {
		this = scope:host
		scope:activity = {
			NOT = {
				has_variable = has_had_0380_event
			}
		}
	}

	immediate = { 
		scope:activity = {
			set_variable = has_had_0380_event
		}
	}
	
	option = {
		name = COR_ceremony.0380.a
		custom_tooltip = COR_ceremony.0380.a.tt
		hidden_effect = {
			random_list = {
				50 = {
					modifier = {
						factor = 1.5
						scope:activity = {
							OR = {
								AND = {
									has_activity_type = activity_HRT_italienzug
									has_activity_option = {
										category = HRT_italienzug_expedition_type
										option = HRT_italienzug_expedition_type_grand
									}
								}
								AND = {
									has_activity_type = COR_activity_coronation_ceremony
									has_activity_option = {
										category = COR_ceremony_type
										option = COR_ceremony_type_extravagant
									}
								}
								AND = {
									has_activity_type = COR_activity_coronation_ceremony_hof
									has_activity_option = {
										category = COR_ceremony_type
										option = COR_ceremony_type_extravagant
									}
								}
							}
						}
					}
					modifier = { 
						factor = 1.25
						diplomacy >= medium_skill_rating
					}
					modifier = { 
						factor = 1.25
						diplomacy >= decent_skill_rating
					}
					modifier = { 
						factor = 1.25
						diplomacy >= high_skill_rating
					}
					modifier = { 
						factor = 1.5
						diplomacy >= very_high_skill_rating
					}
					modifier = { 
						factor = 1.75
						diplomacy >= extremely_high_skill_rating
					}	
					modifier = { 
						factor = 1.25
						has_trait = gregarious
					}
					modifier = { 
						factor = 0.5
						has_trait = shy
					}
					modifier = { 
						factor = 1.15
						has_trait = education_diplomacy_2
					}
					modifier = { 
						factor = 1.25
						has_trait = education_diplomacy_3
					}
					modifier = { 
						factor = 1.5
						has_trait = education_diplomacy_4
					}
					modifier = { 
						factor = 1.75
						has_trait = education_diplomacy_5
					}
					modifier = { 
						factor = 1.75
						is_adult = no #Lower expectations
					}
					trigger_event = COR_ceremony.0381 #Success
					scope:activity = {
						every_attending_character = {
							limit = {
								NOT = { this = root }
							}
							trigger_event = COR_ceremony.0382
						}
					}
				}
				50 = {
					trigger_event = COR_ceremony.0383 #Failure
					scope:activity = {
						every_attending_character = {
							limit = {
								NOT = { this = root }
							}
							trigger_event = COR_ceremony.0384
						}
					}
				}
			}
		}
		ai_chance = {
			base = 90
			modifier = {
				factor = 0.75
				diplomacy < decent_skill_rating
			}
			modifier = {
				factor = 0.5
				has_trait = shy
			}		
		}
	}
	option = {
		name = COR_ceremony.0380.b
		ai_chance = {
			base = 10
		}
	}
}

#Success: King has impressed his guests
COR_ceremony.0381 = {
	type = activity_event
	title = COR_ceremony.0380.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					root = { is_adult = no }
				}
				desc = COR_ceremony.0381.desc_child
			}
			desc = COR_ceremony.0381.desc
		}
	}
	theme = wedding_ceremony_activity

	right_portrait = {
		character = root
		animation = personality_content
	}
	left_portrait = {
		character = scope:COR_auditor
		animation = throne_room_applaud_1
	}

	immediate = {
		scope:activity = {
			random_attending_character = {
				limit = {
					NOR = {
						this = scope:host
						this = scope:activity.special_guest:COR_coronator
					}
					is_ruler = yes
				}
				alternative_limit = {
					NOR = {
						this = scope:host
						this = scope:activity.special_guest:COR_coronator
					}
				}
				save_scope_as = COR_auditor
			}
		}
	}
	
	option = {
		name = COR_ceremony.0381.a
		custom_tooltip = COR_ceremony.0381.a.tt
		if = { 
			limit = { is_adult = no } 
			add_prestige = 75
		}
		else = { 
			add_prestige = 150
		}
		ai_chance = { 	
			base = 100
		}
	}
}

#Coronation guest: ruler speech increased opinion.
COR_ceremony.0382 = {
	type = activity_event
	title = COR_ceremony.0380.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					root = { is_adult = no }
				}
				desc = COR_ceremony.0382.desc_child
			}
			desc = COR_ceremony.0382.desc
		}
	}
	theme = wedding_ceremony_activity

	right_portrait = {
		character = scope:host
		animation = personality_content
	}
	left_portrait = {
		character = root
		animation = throne_room_applaud_1
	}

	immediate = { }
	
	option = {
		name = COR_ceremony.0382.a
		add_opinion = {
			target = scope:host
			modifier = impressed_opinion
			opinion = 5
		}
		ai_chance = { 	
			base = 100
		}
	}
}

#Failure: King has not impressed his guests
COR_ceremony.0383 = {
	type = activity_event
	title = COR_ceremony.0380.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					root = { is_adult = no }
				}
				desc = COR_ceremony.0383.desc_child
			}
			desc = COR_ceremony.0383.desc
		}
	}
	theme = wedding_ceremony_activity

	right_portrait = {
		character = root
		animation = stress
	}
	left_portrait = {
		character = scope:COR_auditor
		animation = disapproval
	}

	immediate = {
		scope:activity = {
			random_attending_character = {
				limit = {
					NOR = {
						this = scope:host
						this = scope:activity.special_guest:COR_coronator
					}
					is_ruler = yes
				}
				alternative_limit = {
					NOR = {
						this = scope:host
						this = scope:activity.special_guest:COR_coronator
					}
				}
				save_scope_as = COR_auditor
			}
		}
	}
	
	option = {
		name = COR_ceremony.0383.a
		custom_tooltip = COR_ceremony.0383.a.tt
		if = { 
			limit = { is_adult = no } 
			add_prestige = -40
		}
		else = { 
			add_prestige = -90
		}
		ai_chance = { 	
			base = 100
		}
	}
}

#Coronation guest: ruler speech did not increase opinion.
COR_ceremony.0384 = {
	type = activity_event
	title = COR_ceremony.0380.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					root = { is_adult = no }
				}
				desc = COR_ceremony.0384.desc_child
			}
			desc = COR_ceremony.0384.desc
		}
	}
	theme = wedding_ceremony_activity

	right_portrait = {
		character = scope:host
		animation = stress
	}
	left_portrait = {
		character = root
		animation = disapproval
	}

	immediate = { }
	
	option = {
		name = COR_ceremony.0384.a
		add_opinion = {
			target = scope:host
			modifier = dismissive_opinion
			opinion = -10
		}
		ai_chance = { 	
			base = 100
		}
	}
}

#King galvanized by upcoming coronation, chance to trade content->ambitious or lazy->diligent.
COR_ceremony.0390 = {
	type = activity_event
	title = COR_ceremony.0390.t
	desc = COR_ceremony.0390.desc
	theme = wedding_ceremony_activity

	right_portrait = {
		character = root
		animation = idle
	}

	cooldown = { years = 1 }

	weight_multiplier = {
		base = 1
	}

	trigger = {
		this = scope:host
		scope:host = {
			OR = {
				has_trait = lazy
				has_trait = content
			}
		}
		scope:activity = {
			NOT = {
				has_variable = has_had_0390_event
			}
		}
	}

	immediate = { 
		scope:activity = {
			set_variable = has_had_0390_event
		}
	}
	
	option = {
		name = COR_ceremony.0390.a
		trigger = { has_trait = content }
		add_prestige = 75
		random = { 
			chance = 50
			remove_trait = content
			add_trait = ambitious
		}
		ai_chance = { 	
			factor = 50	
		}
	}
	option = {
		name = COR_ceremony.0390.b
		trigger = { has_trait = lazy }
		add_piety = 20
		random = { 
			chance = 50
			remove_trait = lazy
			add_trait = diligent 
		}
		ai_chance = { 	
			factor = 50		
		}
	}
}

# ON START - BANQUET

COR_ceremony.0401 = {
	type = activity_event
	title = COR_ceremony.0401.t
	desc = {
		first_valid = {
			triggered_desc = { #host
				trigger = {
					root = scope:host
				}
				desc = COR_ceremony.0401.desc_host
			}
			desc = COR_ceremony.0401.desc #guest
		}
	}
	theme = wedding_banquet_activity
	left_portrait = {
		trigger = {
			NOR = {
				root = scope:COR_ruler
				root = scope:COR_coronator
			}
		}
		character = root
		animation = toast_goblet
	}
	right_portrait = {
		character = scope:COR_ruler
		animation = personality_honorable
	}

	trigger = {
		exists = scope:activity
	}

	immediate = {
		scope:activity.special_guest:COR_coronator = { save_scope_as = COR_coronator }
		scope:host = { save_scope_as = COR_ruler }
	}

	option = {
		name = COR_ceremony.0401.a
		if = {
			limit = {
				OR = {
					root = scope:COR_ruler
					root = scope:COR_coronator
				}
			}
			add_prestige = minor_prestige_gain
		}
	}
}

# BANQUET EVENTS

##################################################
# A Kindred Spirit
# by Claudia Baldassi
# ep2_wedding.1040
##################################################

# You make a new friend

COR_ceremony.0402 = {
	type = activity_event
	title = ep2_wedding.1040.t
	desc = COR_ceremony.0402.desc
	theme = wedding_banquet_activity
	center_portrait = {
		character = root
		animation = laugh
	}
	right_portrait = {
		character = scope:new_friend
		animation = personality_content
	}

	cooldown = { years = 1 }

	trigger = {
		NOR = {
			this = scope:host
			this = scope:activity.special_guest:COR_coronator
		}
		scope:activity = {
			any_attending_character = {
				OR = {
					has_relation_potential_friend = root
					AND = {
						has_any_good_relationship_with_root_trigger = no
						has_any_bad_relationship_with_root_trigger = no
					}
				}
				is_ai = yes
				is_adult = yes
				NOR = {
					has_character_flag = busy_in_banquet_event
					this = scope:host
					this = scope:activity.special_guest:COR_coronator
				}
			}
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			is_ai = yes
			factor = 0.1
		}
	}

	immediate = {
		add_character_flag = busy_in_banquet_event
		scope:activity = {
			random_attending_character = {
				limit = {
					OR = {
						has_relation_potential_friend = root
						AND = {
							has_any_good_relationship_with_root_trigger = no
							has_any_bad_relationship_with_root_trigger = no
						}
					}
					is_ai = yes
					is_adult = yes
					NOR = {
						has_character_flag = busy_in_banquet_event
						this = scope:host
						this = scope:activity.special_guest:COR_coronator
					}
				}
				save_scope_as = new_friend
			}
		}
		scope:new_friend = { add_character_flag = busy_in_banquet_event }
	}

	#Option A:
	option = {
		name = ep2_wedding.1040.a
		scope:activity = {
			add_activity_log_entry = {
				key = wedding_kindred_log
				tags = { good }
				score = 50
				character = root
				target = scope:new_friend

				# Effect
				root = {
					set_relation_friend = { reason = COR_friend_enjoyable_chat target = scope:new_friend }
					reverse_add_opinion = {
						target = scope:new_friend
						modifier = friendliness_opinion
						opinion = 10
					}
				}
			}
		}
		stress_impact = {
			shy = minor_stress_impact_gain
			reclusive = minor_stress_impact_gain
			paranoid = minor_stress_impact_gain
			trusting = medium_stress_impact_loss
			gregarious = major_stress_impact_loss
		}

		ai_chance = {
			base = 100
			modifier = {
				has_trait = shy
				add = -50
			}
			modifier = {
				has_trait = reclusive
				add = -75
			}
			modifier = {
				has_trait = paranoid
				add = -75
			}
		}
	}

	#Option B:
	option = {
		name = ep2_wedding.1040.b
		reverse_add_opinion = {
			target = scope:new_friend
			modifier = unfriendly_opinion
			opinion = -15
		}
		stress_impact = {
			gregarious = medium_stress_impact_gain
			reclusive = major_stress_impact_loss
			paranoid = major_stress_impact_loss
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = gregarious
				add = -75
			}
		}
	}
	after = {
		remove_character_flag = busy_in_banquet_event
		scope:new_friend = { remove_character_flag = busy_in_banquet_event }
	}
}

##################################################
# A Fiery Dance
# by Claudia Baldassi
# ep2_wedding.1050
##################################################

# Someone catches fire from the torches

scripted_trigger COR_cermony_extra_victim_valid_trigger = {
	is_ai = yes
	is_adult = yes
	NOR = {
		this = root
		this = scope:host
		this = scope:activity.special_guest:COR_coronator
		this = scope:1050_victim
	}
	NOT = { has_character_flag = busy_in_banquet_event }
}

COR_ceremony.0403 = {
	type = activity_event
	title = ep2_wedding.1050.t
	desc = ep2_wedding.1050.desc
	theme = wedding_banquet_activity
	left_portrait = {
		character = root
		animation = fear
	}
	center_portrait = {
		trigger = {
			exists = scope:extra_victim_1
		}
		character = scope:extra_victim_1
		animation = shock
	}
	right_portrait = {
		character = scope:victim
		animation = pain
	}
	lower_center_portrait = scope:other_victim
	lower_right_portrait = scope:extra_victim_2

	cooldown = { years = 15 }

	trigger = {
		scope:activity = {
			NOT = {
				has_variable = has_had_event_1050
			}
		}

		scope:activity = {
			has_activity_option = {
				category = COR_ceremony_option_entertainment
				option = COR_ceremony_entertainment_good
			}
		}
		scope:activity = {
			any_attending_character = {
				is_adult = yes
				NOR = {
					this = root
					this = scope:host
					this = scope:activity.special_guest:COR_coronator
				}
				is_ai = yes
				NOT = { has_character_flag = busy_in_banquet_event }
			}
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			is_ai = yes
			factor = 0.1
		}
	}

	immediate = {
		scope:activity = {
			set_variable = has_had_event_1050
		}
		scope:activity = {
			random_attending_character = {
				limit = {
					is_adult = yes
					NOR = {
						this = root
						this = scope:host
						this = scope:activity.special_guest:COR_coronator
					}
					is_ai = yes
					NOT = { has_character_flag = busy_in_banquet_event }
				}
				save_scope_as = 1050_victim
				increase_wounds_effect = { REASON = burned }
				add_character_flag = busy_in_banquet_event
			}
		}
		add_character_flag = busy_in_banquet_event
		if = {
			limit = {
				scope:activity = {
					any_attending_character = {
						COR_cermony_extra_victim_valid_trigger = yes
						save_temporary_scope_as = extra_victim_1
					}
				}
				scope:activity = {
					any_attending_character = {
						COR_cermony_extra_victim_valid_trigger = yes
						NOT = { this = scope:extra_victim_1 }
					}
				}
			}
			scope:activity = {
				random_attending_character = {
					limit = {
						COR_cermony_extra_victim_valid_trigger = yes
					}
					save_scope_as = extra_victim_1
					add_character_flag = busy_in_banquet_event
				}
				random_attending_character = {
					limit = {
						COR_cermony_extra_victim_valid_trigger = yes
						NOT = { this = scope:extra_victim_1 }
					}
					save_scope_as = extra_victim_2
					add_character_flag = busy_in_banquet_event
				}
			}
		}
		if = {
			limit = {
				scope:activity = {
					any_attending_character = {
						COR_cermony_extra_victim_valid_trigger = yes
						NOR = {
							this = scope:extra_victim_1
							this = scope:extra_victim_2
						}
					}
				}
			}
			scope:activity = {
				random_attending_character = {
					limit = {
						COR_cermony_extra_victim_valid_trigger = yes
						NOR = {
							this = scope:extra_victim_1
							this = scope:extra_victim_2
						}
					}
					save_scope_as = other_victim
					add_character_flag = busy_in_banquet_event
				}
			}
		}
	}

	#Option A: try to save them
	option = {
		name = ep2_wedding.1050.a
		duel = {
			skill = prowess
			value = decent_skill_rating
			40 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = ep2_wedding.1050.a.success
				send_interface_toast = {
					title = ep2_wedding.1050.a.success.tt
					left_icon = scope:1050_victim
					scope:activity = {
						add_activity_log_entry = {
							key = wedding_dance_rescue_log
							tags = { good }
							score = 25
							character = root
							target = scope:1050_victim

							# Effect
							root = {
								reverse_add_opinion = {
									target = scope:1050_victim
									modifier = grateful_opinion
									opinion = 15
								}
								if = {
									limit = {
										can_add_hook = {
											type = indebted_hook
											target = scope:1050_victim
										}
									}
									add_hook = {
										type = indebted_hook
										target = scope:1050_victim
									}
								}
								if = {
									limit = {
										has_activity_intent = diplomatic_intent
										intent_target = scope:1050_victim
									}
									create_alliance = {
										target = scope:1050_victim
										allied_through_owner = root
										allied_through_target = scope:1050_victim
									}
									scope:1050_victim = {
										add_opinion = {
											target = root
											modifier = event_negotiated_alliance_opinion
										}
									}
								}
							}
						}
					}
				}				
			}
			60 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = ep2_wedding.1050.a.failure
				send_interface_toast = {
					title = ep2_wedding.1050.a.failure.tt
					left_icon = scope:1050_victim
					scope:activity = {
						add_activity_log_entry = {
							key = wedding_dance_rescue_fail_log
							tags = { bad }
							score = 25
							character = root
							target = scope:1050_victim

							# Effect
							root = {
								increase_wounds_effect = { REASON = burned }
								scope:1050_victim = {
									increase_wounds_effect = { REASON = burned }
								}
							}
						}
					}
				}
			}
		}
		stress_impact = {
			craven = massive_stress_impact_gain
		}
		ai_chance = {
			base = 50
			modifier = {
				has_trait = brave
				add = 100
			}
			modifier = {
				has_trait = craven
				add = -100
			}
		}
	}

	#Option B: call for help
	option = {
		name = ep2_wedding.1050.b
		random_list = {
			50 = {
				#Saved!
				desc = ep2_wedding.1050.b.1
				modifier = {
					scope:activity = {
						has_activity_option = {
							category = COR_ceremony_option_decoration
							option = COR_ceremony_decoration_bad
						}
					}
					add = -25
				}
				modifier = {
					scope:activity = {
						has_activity_option = {
							category = COR_ceremony_option_decoration
							option = COR_ceremony_decoration_good
						}
					}
					add = 25
				}
				send_interface_toast = {
					title = ep2_wedding.1050.b.1.tt
					left_icon = scope:1050_victim
					scope:activity = {
						add_activity_log_entry = {
							key = wedding_dance_saved_log
							tags = { good }
							score = 25
							character = scope:1050_victim
						}

						root = {
							reverse_add_opinion = {
								target = scope:1050_victim
								modifier = grateful_opinion
								opinion = 5
							}
							if = {
								limit = {
									can_add_hook = {
										type = indebted_hook
										target = scope:1050_victim
									}
								}
								add_hook = {
									type = indebted_hook
									target = scope:1050_victim
								}
							}
						}
					}
				}
			}
			50 = {
				#Keeps burning!
				desc = ep2_wedding.1050.b.2
				send_interface_toast = {
					title = ep2_wedding.1050.b.2.tt
					left_icon = scope:1050_victim
					scope:activity = {
						add_activity_log_entry = {
							key = wedding_dance_saved_fail_log
							tags = { bad }
							score = 25
							character = scope:1050_victim

							# Effect
							scope:1050_victim = {
								increase_wounds_effect = { REASON = burned }
							}
						}
					}
				}
			}
		}
		ai_chance = {
			base = 50
		}
	}

	#Option C: FIRE! 
	option = {
		name = ep2_wedding.1050.c
		trigger = {
			exists = scope:extra_victim_1
			exists = scope:extra_victim_2
		}
		scope:activity = {
			add_activity_log_entry = {
				key = wedding_dance_disaster_log
				tags = { bad }
				score = 25
				character = scope:1050_victim

				# Effect
				scope:extra_victim_1 = {
					increase_wounds_effect = { REASON = burned }
				}
				scope:extra_victim_2 = {
					increase_wounds_effect = { REASON = burned }
				}

				root = { add_dread = medium_dread_gain }
			}
		}
		stress_impact = {
			compassionate = major_stress_impact_gain
			callous = medium_stress_impact_loss
			vengeful = major_stress_impact_loss
			sadistic = massive_stress_impact_loss
			torturer = massive_stress_impact_loss
		}
		ai_chance = {
			base = 30
			modifier = {
				has_trait = sadistic
				add = 70
			}
			modifier = {
				has_trait = callous
				add = 20
			}
			modifier = {
				has_trait = compassionate
				add = -70
			}
		}
	}

	#Option D: panic
	option = {
		name = ep2_wedding.1050.d
		trigger = { exists = scope:other_victim }
		random = {
			chance = 30			
			send_interface_toast = {
				title = ep2_wedding.1050.d.tt.2
				left_icon = scope:other_victim
				scope:activity = {
					add_activity_log_entry = {
						key = wedding_dance_knocked_log
						tags = { bad }
						score = 25
						character = root
						target = scope:other_victim

						# Effect
						root = { custom_tooltip = ep2_wedding.1050.d.tt }
						scope:other_victim = {
							increase_wounds_effect = { REASON = burned }
						}
					}
				}
			}
			
		}
		stress_impact = {
			brave = massive_stress_impact_gain
		}
		ai_chance = {
			base = 50
			modifier = {
				has_trait = craven
				add = 100
			}
			modifier = {
				has_trait = brave
				add = -100
			}
		}
	}
	after = {
		remove_character_flag = busy_in_banquet_event
		scope:1050_victim = { remove_character_flag = busy_in_banquet_event }
		if = {
			limit = { exists = scope:other_victim }
			scope:other_victim = { remove_character_flag = busy_in_banquet_event }
		}
		if = {
			limit = { exists = scope:extra_victim_1 }
			scope:extra_victim_1 = { remove_character_flag = busy_in_banquet_event }
		}
		if = {
			limit = { exists = scope:extra_victim_2 }
			scope:extra_victim_2 = { remove_character_flag = busy_in_banquet_event }
		}
	}
}

# Host: Gain Renown Intent - Bring a white animal to the Banquet to flex (it's painted)

scripted_trigger COR_ceremony_impressed = {
	OR = { #what kind of people would be impressed by a legendary animal?
		has_trait = gregarious
		has_trait = brave 
		has_trait = lifestyle_reveler 
		has_trait = lifestyle_hunter
		has_trait = drunkard
		has_trait = gallant #white animals were a pretty chivalrous thing to find/hunt
	}
}

COR_ceremony.0404 = {
	type = activity_event
	title = ep2_wedding.2010.t
	desc = {
		desc = ep2_wedding.2010.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = {
					root = scope:host
				}
				desc = COR_ceremony.0404.desc_host
			}
		}
	}
	theme = wedding_banquet_activity
	left_portrait = {
		character = root
		animation = personality_rational
	}

	cooldown = { years = 5 }

	widget = {
		gui = "event_window_widget_activity_intent"
		container = "custom_widgets_container"
	}

	trigger = {
		this = scope:host #you're the host
		has_activity_intent = diplomatic_intent
		intent_target = { COR_ceremony_impressed = yes }
	}

	weight_multiplier = {
		base = 1
		modifier = {
			factor = 2
			has_trait = deceitful
		}
		modifier = {
			factor = 0.5
			has_trait = honest
		}
	}

	immediate = {
		select_local_animal_effect = { TYPE = big } # Save scope to limit possible animals: any/big/small/dangerous/harmless/prowling
		intent_target = {
			add_to_list = ep2_wedding_2010_impressed_list
			save_scope_as = diplo_target
		}
		if = {
			limit = {
				scope:activity = { #there's someone else to impress
					any_attending_character = {
						feast_default_adult_participant_trigger = yes
						NOR = {
							this = root
							this = root.intent_target
						}
						COR_ceremony_impressed = yes
					}
				}
			}	
			scope:activity = {
				every_attending_character = {
					limit = {
						feast_default_adult_participant_trigger = yes
						NOR = {
							this = root
							this = root.intent_target
						}
						COR_ceremony_impressed = yes
					}
					add_to_list = ep2_wedding_2010_impressed_list
				}
			}
		}
	}

	#Yeah
	option = {
		name = ep2_wedding.2010.a
		custom_tooltip = ep2_wedding.2010.a.tt
		every_in_list = {
			list = ep2_wedding_2010_impressed_list
			custom = ep2_wedding.2010.impressed_list
			add_opinion = {
				modifier = wbanquet_white_animal_opinion
				target = root
				opinion = 10
			}
		}
		#Does anyone suspect? 
		hidden_effect = {
			if = {
				limit = {
					scope:diplo_target = {
						OR = {
							has_trait = cynical
							has_trait = callous
						}
						has_any_good_relationship_with_root_trigger = no
					}
				}
				random_list = {
					50 = { #they don't notice
						remove_variable = animal_type
						if = {
							limit = {
								scope:diplo_target = { activity_wedding_diplomatic_intent_impressible_target = yes }
							}
							send_interface_toast = {
								title = ep2_wedding.2000.after.subjugate
								left_icon = scope:diplo_target
								custom_tooltip = {
									text = ep2_wedding.2000.after.subjugate.tt
									complete_activity_intent = yes
									create_title_and_vassal_change = {
										type = swear_fealty
										save_scope_as = title_change
										add_claim_on_loss = no
									}
									scope:diplo_target = {
										change_liege = {
											liege = root
											change = scope:title_change
										}
									}
									resolve_title_and_vassal_change = scope:title_change
								}
							}
						}
					}
					50 = { #they do
						trigger_event = ep2_wedding.2011
					}
				}
			}
			else_if = {
				limit = {
					scope:activity = {
						any_attending_character = {
							feast_default_adult_participant_trigger = yes
							OR = {
								has_trait = cynical
								has_trait = callous
							}
							has_any_good_relationship_with_root_trigger = no
						}
					}
				}
				random_list = {
					50 = { #they don't notice
						remove_variable = animal_type
					}
					50 = { #they do
						trigger_event = ep2_wedding.2011
					}
				}
			}
		}
		remove_short_term_gold = minor_gold_value
		stress_impact = {
			greedy = medium_stress_impact_gain
			honest = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0 
				short_term_gold <= minor_gold_value
			}
			modifier = {
				factor = 0 
				OR = {
					has_trait = greedy
					has_trait = honest
				}
			}
		}
	}
	
	#Nah
	option = {
		name = ep2_wedding.2010.b
		remove_variable = animal_type
		stress_impact = {
			gallant = medium_stress_impact_gain
			gregarious = medium_stress_impact_gain
			lifestyle_reveler = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0 
				OR = {
					has_trait = gallant
					has_trait = gregarious
					has_trait = lifestyle_reveler
				}
			}
			modifier = {
				factor = 1.25
				has_trait = deceitful
			}
		}
	}
}

#####################
# Enjoy Magnificent Food!
# by Petter Vilberg
#####################
COR_ceremony.0405 = {
	type = activity_event
	title = feast_default.1004.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:activity = {
						OR = {
							AND = {
								#has_activity_type = COR_activity_coronation_ceremony
								has_activity_option = {
									category = COR_ceremony_option_food
									option = COR_ceremony_food_good
								}
							}
							AND = {
								#has_activity_type = COR_activity_coronation_ceremony_hof
								has_activity_option = {
									category = COR_ceremony_option_food
									option = COR_ceremony_food_good
								}
							}
						}
					}
				}
				desc = feast_default.1004.desc_exotic
			}
			triggered_desc = {
				trigger = {
					scope:activity = {
						OR = {
							AND = {
								#has_activity_type = COR_activity_coronation_ceremony
								has_activity_option = {
									category = COR_ceremony_option_food
									option = COR_ceremony_food_normal
								}
							}
							AND = {
								#has_activity_type = COR_activity_coronation_ceremony_hof
								has_activity_option = {
									category = COR_ceremony_option_food
									option = COR_ceremony_food_normal
								}
							}
						}
					}
				}
				desc = feast_default.1004.desc_lavish
			}
			triggered_desc = {
				trigger = {
					scope:activity = {
						OR = {
							has_activity_option = {
								category = COR_ceremony_option_food
								option = COR_ceremony_food_bad
							}
							has_activity_option = {
								category = COR_ceremony_option_food
								option = COR_ceremony_food_bad
							}
						}
					}
				}
				desc = feast_default.1004.desc_meager
			}
			desc = feast_default.1004.desc
		}
	}
	theme = feast_activity
	left_portrait = {
		character = root
		animation = happiness
	}
	cooldown = { years = 1 }

	trigger = {
		NOT = { exists = local_var:had_1004 }
		NOR = {
			has_trait = greedy
			has_trait = temperate
			has_trait = inappetetic
		}
	}

	immediate = {
		set_local_variable = {
			name = had_1004
			value = yes
		}
	}

	option = { #Amazing!
		name = {
			trigger = {
				scope:activity.activity_host = {
					has_royal_court = yes
					amenity_level = { type = court_food_quality value <= 1 }
				}
			}
			text = feast_default.1004.a_meager
		}
		name = {
			text = feast_default.1004.a
		}
		if = {
			limit = {
				scope:activity.activity_host = {
					has_royal_court = yes
					amenity_level = { type = court_food_quality value <= 1 }
				}
			}
			add_stress = minor_stress_gain
			scope:activity.activity_host = {
				add_prestige = minor_prestige_loss
			}
		}
		else = {
			add_stress = medium_stress_loss
			add_character_modifier = {
				modifier = feast_life_reaffirmed_modifier
				years = 5
			}
			scope:activity.activity_host = {
				add_prestige = minor_prestige_gain
			}
		}
	}

	option = { #INCREDIBLE!
		name = {
			trigger = {
				scope:activity.activity_host = {
					has_royal_court = yes
					amenity_level = { type = court_food_quality value <= 1 }
				}
			}
			text = feast_default.1004.b_meager
		}
		name = {
			text = feast_default.1004.b
		}
		trigger = {
			OR = {
				has_trait = gluttonous
				has_trait = comfort_eater
			}
		}
		exclusive = yes
		if = {
			limit = {
				scope:activity.activity_host = {
					has_royal_court = yes
					amenity_level = { type = court_food_quality value <= 1 }
				}
			}
			add_stress = medium_stress_gain
			scope:activity.activity_host = {
				add_prestige = minor_prestige_loss
				if = {
					limit = {
						NOT = { this = root }
					}
					add_opinion = {
						target = root
						modifier = feast_meager_food_glutton_opinion
					}
				}
			}
		}
		else = {
			stress_impact = {
				base = medium_stress_loss
				gluttonous = medium_stress_loss
				comfort_eater = medium_stress_loss
			}
			add_character_modifier = {
				modifier = feast_life_reaffirmed_modifier
				years = 5
			}
			scope:activity.activity_host = {
				add_prestige = minor_prestige_gain
				if = {
					limit = {
						NOT = { this = root }
					}
					add_opinion = {
						target = root
						modifier = feast_amazing_food_glutton_opinion
					}
				}
				hidden_effect = {
					random_spouse = {
						limit = {
							NOT = { this = root }
						}
						reverse_add_opinion = {
							target = root
							modifier = feast_amazing_food_glutton_opinion
						}	
					}
				}
			}
		}
	}	
}

# CONCLUSION - HOST
COR_ceremony.0499 = {
	type = activity_event
	title = ep2_wedding.0950.t # The Conclusion
	desc = COR_ceremony.0499.desc
	theme = crown
	override_background = { reference = temple }
	right_portrait = {
		character = root
		animation = personality_honorable
	}

	immediate = {
		play_sound_effect = "event:/DLC/EP2/SFX/Stingers/Grand_Activities/ep2_mx_sting_wedding_end" #TODO
		play_music_cue = weddingend_cue #TODO
		save_scope_as = root_scope
		show_as_tooltip = {
			COR_tooltip_disburse_ceremony_host_activity_rewards = yes
		}
		if = {
			limit = { has_activity_intent = legitimacy_intent }
			add_legitimacy = medium_legitimacy_gain
			complete_activity_intent = yes
		}
		else = { base_legitimacy_intent_reward = yes }
	}

	option = {
		name = COR_ceremony.0499.a
	}
}

# CONCLUSION - GUESTS
COR_ceremony.0500 = {
	type = activity_event
	title = ep2_wedding.0950.t # The Conclusion
	desc = COR_ceremony.0500.desc
	theme = crown
	override_background = { reference = temple }
	right_portrait = {
		character = root
		animation = personality_honorable
	}

	immediate = {
		play_sound_effect = "event:/DLC/EP2/SFX/Stingers/Grand_Activities/ep2_mx_sting_wedding_end" #TODO
		play_music_cue = weddingend_cue #TODO
		save_scope_as = root_scope
	}

	option = {
		name = COR_ceremony.0500.a
	}
}

##########################
# 2.4 Jewel of Byzantium #
##########################

COR_ceremony.7001 = {
	type = character_event
	title = COR_ceremony.0001.t
	desc = COR_ceremony.7001.desc
	theme = crown
	override_background = { reference = ep3_hagia_sophia }
	
	left_portrait = scope:COR_coronator
	
	immediate = {
		##Set up some scopes we'll need
		save_scope_as = COR_ruler

		##Fetch valid coronators
		#Patriarch
		faith:orthodox.religious_head = {
			save_scope_as = COR_coronator
		}
	}

	option = { #Ask to be crowned by the Patriarch
		name = COR_ceremony.7001.a
		trigger = {
			NOT = { has_trait = excommunicated }
			exists = scope:COR_coronator
		}
		custom_tooltip = COR_ceremony.7001.a.tt

		var:COR_coronator ?= {
			remove_list_variable = {
				name = COR_coronation_targets
				target = scope:COR_ruler
			}
		}
		scope:COR_coronator = {
			add_to_variable_list = {
				name = COR_coronation_targets
				target = scope:COR_ruler
			}
			create_story = COR_coronator_story
		}
		set_variable = {
			name = COR_coronator
			value = scope:COR_coronator
		}
		add_character_flag = COR_flag_preparing_coronation

		open_view_data = {
			view = activity_list_detail_host_window
			data = activity_type:COR_byz_activity_coronation_ceremony
			player = root
		}

		ai_chance = {
			base = 20
		}
	}

	option = { #Changed your mind, not yet.
		name = COR_ceremony.0001.e

		custom_tooltip = COR_ceremony.0001.e.tt

		hidden_effect = {
			remove_variable = COR_coronation_request_cooldown
		}

		ai_chance = {
			base = 0
		}
	}
}

# ON START - CORONATION CEREMONY
# For host
COR_ceremony.7320 = {
	type = activity_event
	title = COR_ceremony.0320.t

	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:activity = {
						AND = {
							has_activity_type = COR_byz_activity_coronation_ceremony
							has_activity_option = {
								category = COR_ceremony_type
								option = COR_ceremony_type_dignified
							}
						}
					}
				}
				desc = COR_ceremony.0320.desc.dignified
			}
			triggered_desc = {
				trigger = {
					scope:activity = {
						AND = {
							has_activity_type = COR_byz_activity_coronation_ceremony
							has_activity_option = {
								category = COR_ceremony_type
								option = COR_ceremony_type_extravagant
							}
						}
					}
				}
				desc = COR_ceremony.0320.desc.extravagant
			}
		}
	}

	theme = crown
	override_background = { reference = ep3_hagia_sophia }

	right_portrait = {
		character = root
		animation = personality_honorable
	}

	immediate = { }

	option = {
		name = COR_ceremony.0320.a
	}
}

# ON END - CEREMONY

# For host
COR_ceremony.7322 = {
	type = activity_event
	title = COR_ceremony.0322.t
	desc = COR_ceremony.7322.desc
	theme = crown
	override_background = { reference = ep3_hagia_sophia }
	left_portrait = {
		character = scope:COR_coronator
		animation = wedding_priest
	}
	right_portrait = {
		character = root
		animation = throne_room_bow_1 #throne_room_kneel_1
	}

	trigger = {
		this = scope:COR_ruler
	}

	immediate = {
		play_sound_effect = "event:/DLC/EP2/SFX/Stingers/Grand_Activities/ep2_mx_sting_wedding_west" #TODO
	}

	option = {
		name = COR_ceremony.7322.a

		switch = {
			trigger = has_trait
			COR_crowned_by_priest = { remove_trait = COR_crowned_by_priest }
			COR_crowned_by_bishop = { remove_trait = COR_crowned_by_bishop }
			COR_crowned_by_pope = { remove_trait = COR_crowned_by_pope }
			COR_crowned_by_myself = { remove_trait = COR_crowned_by_myself }
			HRT_emperor = { remove_trait = HRT_emperor }
		}

		add_trait = COR_byz_crowned_by_patriarch
		if = {
			limit = {
				is_at_war = yes
			}
			add_character_modifier = {
				modifier = COR_crowned_in_war
				years = 20
			}
		}

		trigger_event = COR_ceremony.7323

		ai_chance = {
			base = 95
		}
	}

	after = {
		remove_character_flag = COR_flag_preparing_coronation
		remove_variable = COR_years_reigned
		remove_variable = COR_coronation_request_cooldown
		remove_character_modifier ?= COR_uncrowned_modifier
		scope:COR_coronator = {
			remove_list_variable = {
				name = COR_coronation_targets
				target = scope:COR_ruler
			}
		}
		if = {
			limit = {
				NOT = { has_nickname = nick_the_crownless }
			}
			remove_character_flag = sold_crown_charmod
		}
		every_spouse = {
			limit = {
				NOT = { has_nickname = nick_the_crownless }
				has_character_flag = sold_crown_charmod
			}
			remove_character_flag = sold_crown_charmod
		}
	}
}

COR_ceremony.7323 = {
	type = activity_event
	title = COR_ceremony.0322.t
	desc = COR_ceremony.7323.desc
	theme = crown
	override_background = { reference = ep3_hagia_sophia }
	left_portrait = {
		character = scope:COR_coronator
		animation = personality_zealous
	}
	right_portrait = {
		character = root
		animation = scepter
	}

	immediate = {
	}

	option = {
		name = COR_ceremony.0323.a
		
		add_piety = major_piety_gain
		dynasty ?= { add_dynasty_prestige = medium_dynasty_prestige_gain }

		#Assign possible modifier.
		scope:activity.activity_location.county = {
			add_county_modifier = {
				modifier = COR_improved_trade
				years = 10
			}
		}
		if = {
			limit = {
				scope:activity = {
					AND = {
						has_activity_type = COR_byz_activity_coronation_ceremony
						has_activity_option = {
							category = COR_ceremony_type
							option = COR_ceremony_type_extravagant
						}
					}
				}
			}
			add_character_modifier = {
				modifier = COR_extravagant_coronation
				years = 20
			}
		}

		# Progress to next phase
		hidden_effect = {
			scope:activity = { progress_activity_phase_after = { days = 1 } }
		}
		ai_chance = {
			base = 95
		}
	}
}

# For guests
COR_ceremony.7324 = {
	type = activity_event
	title = COR_ceremony.0322.t
	desc = COR_ceremony.7324.desc
	theme = crown
	override_background = { reference = ep3_hagia_sophia }
	left_portrait = {
		character = scope:COR_coronator
		animation = wedding_priest
	}
	right_portrait = {
		character = scope:COR_ruler
		animation = throne_room_bow_1 #throne_room_kneel_1
	}

	trigger = {
		NOR = {
			this = scope:COR_ruler
			this = scope:COR_coronator
		}
	}

	immediate = {
		play_sound_effect = "event:/DLC/EP2/SFX/Stingers/Grand_Activities/ep2_mx_sting_wedding_west" #TODO
	}

	option = {
		name = COR_ceremony.7324.a
		trigger_event = COR_ceremony.7325
	}
}

COR_ceremony.7325 = {
	type = activity_event
	title = COR_ceremony.0322.t
	desc = COR_ceremony.7325.desc
	theme = crown
	override_background = { reference = ep3_hagia_sophia }
	left_portrait = {
		character = scope:COR_coronator
		animation = personality_zealous
	}
	right_portrait = {
		character = scope:COR_ruler
		animation = personality_honorable
	}

	immediate = {
	}

	option = {
		name = COR_ceremony.0323.a_hre # Hail Caesar
	}
}