namespace = coronation

coronation.0001 = {	#start planning
	title = coronation.0001.t
	desc = coronation.0001.desc

	theme = crown
	left_portrait = root

	immediate = {
		save_scope_as = coronee

		cp:councillor_court_chaplain = {
			save_scope_as = bishop
		}
		cp:councillor_steward = {
			save_scope_as = planer
		}

		root.faith = {
			religious_head = {
				save_scope_as = pope
			}
		}
		
		root.faith = {
			random_theocratic_ruler = {
				save_scope_as = priest
				highest_held_title_tier <= 2
				is_liege_or_above = scope:coronee
			}
		}

		#random_theocratic_ruler = 	{
		#	limit = {
		#		target_is_liege_or_above = coronee
		#		faith = root
		##		highest_held_title_tier <= 2
		#	}
		#	
		#	save_scope_as = priest
		#}
	}

	option = { #crowned by local priest  
		name = coronation.0001.a

		trigger = {
			is_available_for_activity_trigger = yes
		}

		scope:priest = {
			trigger_event = {
				id = coronation.0003
				days = 3
			}
		}
		custom_tooltip = coronation.0001.a.tt

		ai_chance = {
			base = 0
		}
	}

	option = {	#crowned by bishop			
		name = coronation.0001.b

		trigger = {
			is_available_for_activity_trigger = yes
		}

		scope:bishop = {
			trigger_event = {
				id = coronation.0003
				days = 3
			}
		}
		custom_tooltip = coronation.0001.b.tt

		ai_chance = {
			base = 40
		}
	}

	option = {	#crowned by pope			
		name = coronation.0001.c
		
		trigger = {
			is_available_for_activity_trigger = yes
		}

		root.faith = {
			religious_head = {
				trigger_event = {
					id = coronation.0003
					days = 3
				}
			}
		}
		custom_tooltip = coronation.0001.c.tt

		ai_chance = {
			base = 30
		}
	}

	option = {
		name = coronation.0001.d
		add_gold = 100

		ai_chance = {
			base = 5
		}
	}

}

coronation.0002 = {
	type = character_event
	title = coronation.0002.t 		#declination for player
	desc = coronation.0001.desc

	theme = crown
	left_portrait = root

	option = { #crowned by local priest   
		name = coronation.0001.a
		scope:priest = {
			trigger_event = {
				id = coronation.0003
				days = 3
			}
		}
		ai_chance = {
			base = 0
		}
	}

	option = {	#crowned by bishop			
		name = coronation.0001.b

		trigger = {
			not = {
				has_character_flag = bishop_declined_flag
			}
			is_available_for_activity_trigger = yes
		}
		remove_short_term_gold = minor_gold_value
		scope:bishop = {
			trigger_event = {
				id = coronation.0003
				days = 3
			}
		}
		ai_chance = {
			base = 40
		}
	}

	option = {	#crowned by pope			
		name = coronation.0001.c
		
		trigger = {
			not = {
				has_character_flag = pope_declined_flag
			}
			is_available_for_activity_trigger = yes
		}

		remove_long_term_gold = major_gold_value

		root.faith = {
			religious_head = {
				trigger_event = {
					id = coronation.0003
					days = 3
				}
			}
		}
		ai_chance = {
			base = 30
		}
	}

	option = {
		name = coronation.0001.d
		add_gold = 100

		ai_chance = {
			base = 5
		}
	}
}

coronation.0003 = { 				# ask for crown NOT FOR PLAYER
	type = letter_event
	opening = {
		desc = coronation.0003.opening
	}
	desc = coronation.0003.opening.desc

	sender = scope:coronee


	option = {	#Annahme
		name = coronation.0003.a
		this = {
			save_scope_as = coronator
		}
		add_character_flag = {
			flag  =  coronator_flag
		}

		scope:coronee = {
			trigger_event = {
				id = coronation.0004
				days = 3
			}
		}

		if = {
			limit = { this = scope:pope }
			scope:coronee = {
				add_character_flag = {
					flag = will_crowned_by_pope_flag
				}
			}
		}
		else_if = {
			limit = { this = scope:bishop }
			scope:coronee = {
				add_character_flag = {
					flag = will_crowned_by_bishop_flag
				}
			}
		}

		else_if = {
			limit = { this = scope:priest }
			scope:coronee = {
				add_character_flag = {
					flag = will_crowned_by_priest_flag
				}
			}
		}

		ai_chance = {
			base = 30
			opinion_modifier = {
				opinion_target = scope:coronee
			}
			#modifier = {
			#	add = 20
			#	scope:coronee = {
			#		piety_level > 3
			#	}
			#}
		
		}
	}

	option = { #ablehnen
		name = coronation.0003.b
		if = {
			limit = { this = scope:pope }
			scope:coronee = {
				add_character_flag = {
					flag =  pope_declined_flag
				}
			}
		}
		else_if = {
			limit = { this = scope:bishop }
			scope:coronee = {
				add_character_flag = {
					flag =  bishop_declined_flag
				}
			}
		}

		scope:coronee = {
			trigger_event = {
				id = coronation.0002
				days = 3
			}
		}

		ai_chance = {
			base = 10
			modifier = {
				if = {
					limit = {
						scope:coronee = {
							piety_level < 3
						}
					}
					add = 50
				}
			}
		#	#modifier = {
		#	#	add = 40
		#	#	scope:coronee = {
		#	#		piety_level < 3
		#	#	}
		#	#}
		#	#modifier = {
		#	#	add = 100
		#	#	is_available_for_activity_trigger = no
		#	#}
		#	#modifier = {
		#	#	add = 25
		#	#	this = scope:pope
		#	#}
		#
		}
	}
}


coronation.0004 = {
	type = letter_event
	sender = scope:coronator
	opening	= {
		desc = coronation.0004.opening
	}
	desc = coronation.0004.desc


	option = {	#start prep
		name = coronation.0004.a
		trigger_event = {
			id = prep.0001
			days = 15
		}
	}
}


coronation.0005 = {	#Einladung
	type = letter_event
	opening = {
		desc = coronation.0005.opening
	}
	desc = coronation.0005.desc
	sender = scope:sender

	trigger = {
		is_available_for_activity_trigger = yes
		exists = scope:activity.activity_owner
		target_is_liege_or_above = scope:activity.activity_owner
	}

	immediate = {
		scope:activity.activity_owner = {
			save_scope_as = sender
		}
		scope:activity.activity_province = {
			barony = {
				save_scope_as = barony
			}
		}
	}

	option = {	# For Coronator
		trigger = {
			this = scope:coronator 
		}
		scope:activity = {
			accept_invitation_for_character = prev
		}
		set_variable = {
			name = booked_for_a_party
			value = scope:sender
			days = 200
		}
		ai_chance = {
			base = 200
		}
	}

	option = {	#annahme
		name = coronation.0005.a

		set_variable = {
			name = booked_for_a_party
			value = scope:sender
			days = 200
		}

		scope:activity = {
			accept_invitation_for_character = prev
		}

		ai_chance = {
			base = 30
			opinion_modifier = {
				opinion_target = scope:coronee
			}
		}
	}

	option = {	#ablehnung
		name = coronation.0005.b
		scope:activity = {
			decline_invitation_for_character = prev
		}
		
		ai_chance = {
			base = 10
		}
	}
}

coronation.0006 = {	#Einladung not vassal
	type = letter_event
	opening = {
		desc = coronation.0006.opening
	}
	desc = coronation.0006.opening_desc

	sender = scope:coronee

	trigger = {
		is_available_for_activity_trigger = yes
		exists = scope:activity.activity_owner
	}

	immediate = {
		scope:activity.activity_owner = {
			save_scope_as = sender
		}
		scope:activity.activity_province = {
			barony = {
				save_scope_as = barony
			}
		}
	}

	option = {	# For Coronator
		trigger = {
			this = scope:coronator 
		}
		scope:activity = {
			accept_invitation_for_character = prev
		}
		set_variable = {
			name = booked_for_a_party
			value = scope:sender
			days = 200
		}
		ai_chance = {
			base = 200
		}
	}

	option = {	#accept
		name = coronation.0006.a

		set_variable = {
			name = booked_for_a_party
			value = scope:sender
			days = 200
		}

		scope:activity = {
			accept_invitation_for_character = prev
		}
		ai_chance = {
			base = 40
			opinion_modifier = {
				opinion_target = scope:coronee
			}

		}
	}

	option = {	#decline
		name = coronation.0006.b
		scope:activity = {
			decline_invitation_for_character = prev
		}

		ai_chance = {
			base = 20
		}
	}
}

coronation.1000 = {
	type = character_event
	theme = crown
	title = coronation.1000.t
	desc = coronation.1000.desc
	left_portrait = root
	right_portrait = scope:coronator

	immediate = {
		if = {
			limit = {
				scope:coronee = { has_character_flag = small_feast_flag }
			}
			remove_character_flag = small_feast_flag
			
			add_prestige = minor_prestige_gain
		}
		else_if = {
			limit = {
				scope:coronee = { has_character_flag = medium_feast_flag }
			}
			remove_character_flag = medium_feast_flag
			
			add_prestige = medium_prestige_gain
		}
		else = {
			remove_character_flag = large_feast_flag
			add_prestige = major_prestige_gain
		}
	}


	option = {
		name = coronation.1000.a
		
		if = {
			limit = {
				scope:coronee = { has_character_flag = will_crowned_by_pope_flag }
			}
			remove_character_flag = will_crowned_by_pope_flag
	
			add_character_modifier = {
				modifier = pope_crowned_modifier_king
			}
		}
		else_if = {
			limit = {
				scope:coronee = { has_character_flag = will_crowned_by_bishop_flag }
			}
			remove_character_flag = will_crowned_by_bishop_flag
			
			add_character_modifier = {
				modifier = bishop_crowned_modifier_king
			}
		}
		else = {
			remove_character_flag = will_crowned_by_priest_flag
				
			add_character_modifier = {
				modifier = priest_crowned_modifier_king
			}
		}

	}

	after = {
		remove_character_modifier = not_crowned_modifier_king
	}
}