﻿#Events for bishop and Liege relationships

namespace = bishop

#bishop.1001 - Forced divorce
#bishop.1011 - Force you to leave faction
#bishop.2001 - Force to release a prisoner
#bishop.2002 - Set family members against ruler
#bishop.2003 - Decrease demesne county control

scripted_trigger bishop_1001_suitable_theocrat_trigger = {
	opinion = {
		target = liege
		value <= -10
	}
	faith = root.faith
	is_imprisoned = no
}


#######################
# Forced divorce
# by Linnéa Thimrén
#######################
bishop.1001 = {
	type = letter_event
	opening = {
		desc = bishop.1001.opening
	}
	desc = bishop.1001.desc
	sender = scope:bishop

	trigger = {
		NOT = { has_character_flag = had_event_bishop_1001 }
		is_available_adult = yes
		root.faith = { has_doctrine = doctrine_theocracy_temporal }
		exists = cp:councillor_court_chaplain
		any_spouse = {
			NOT = { this = root.cp:councillor_court_chaplain }
			is_ai = yes
			save_temporary_scope_as = spouse_check
		}
		cp:councillor_court_chaplain = {
			bishop_1001_suitable_theocrat_trigger = yes
			NOT = { is_spouse_of = root }
		}
		faith = {
			faith_allows_marriage_consanguinity_trigger = { CHARACTER_1 = root CHARACTER_2 = scope:spouse_check }
		}
	}

	weight_multiplier = { #More likely the more they dislike you
		base = 0.5
		modifier = {
			add = 0.5
			cp:councillor_court_chaplain = {
				opinion = {
					target = root
					value <= low_negative_opinion
				}
				NOT = { is_spouse_of = root }
			}
		}
		modifier = {
			add = 0.5
			cp:councillor_court_chaplain = {
				opinion = {
					target = root
					value <= medium_negative_opinion
				}
				NOT = { is_spouse_of = root }
			}
		}
	}

	immediate = {
		add_character_flag = {
			flag = had_event_bishop_1001
			years = 10
		}
		cp:councillor_court_chaplain = {
			save_scope_as = bishop
		}
		random_spouse = {
			limit = {
				NOT = { this = scope:bishop }
				is_ai = yes
			}
			save_scope_as = spouse
		}
	}

	option = { #Divorce your spouse
		name = bishop.1001.a
		custom_tooltip = bishop.1001.a.tt
		divorce_effect = {
			DIVORCER = root
			DIVORCEE = scope:spouse
		}
		scope:bishop = {
			add_opinion = {
				modifier = pleased_opinion
				target = liege
				opinion = low_positive_opinion
			}
		}
		ai_chance = {
			base = 25
			modifier = {
				add = 25
				dread_modified_ai_boldness = { #Am I scared of the bishop?
					dreaded_character = scope:bishop
					value <= 0
				}
			}
		}
	}

	option = { #Refuse - intrigue
		name = bishop.1001.b
		trigger = {
			intrigue >= medium_skill_rating
		}
		skill = intrigue
		scope:bishop = {
			add_opinion = {
				modifier = refusal_opinion
				target = liege
				opinion = -10
			}
		}
		duel = {
			skill = intrigue
			target = scope:bishop
			25 = {
				desc = bishop.1001.b.success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 0.5
				}
				send_interface_toast = {
					title = bishop.1001.b.success
					left_icon = scope:spouse
					right_icon = scope:bishop
					scope:bishop = {
						add_prestige = major_prestige_loss
					}
				}
			}
			10 = {
				desc = bishop.1001.b.failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -0.75
				}
				send_interface_toast = {
					title = bishop.1001.b.failure
					left_icon = scope:spouse
					right_icon = scope:bishop
					add_trait = incestuous
					add_piety_level = -1
					scope:spouse = {
						add_trait = incestuous
						add_piety_level = -1
					}
					add_prestige = major_prestige_loss
				}
			}
		}
		ai_chance = {
			base = 50
			compare_modifier = {
				value = intrigue
				multiplier = 1
			}
		}
	}

	option = { #Refuse - learning
		name = bishop.1001.c
		trigger = {
			learning >= medium_skill_rating
		}
		skill = learning
		scope:bishop = {
			add_opinion = {
				modifier = refusal_opinion
				target = liege
				opinion = -10
			}
		}
		duel = {
			skill = learning
			target = scope:bishop
			25 = {
				desc = bishop.1001.c.success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 0.5
				}
				send_interface_toast = {
					title = bishop.1001.c.success
					left_icon = scope:spouse
					right_icon = scope:bishop
					add_piety = medium_piety_gain
				}
			}
			10 = {
				desc = bishop.1001.c.failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -0.75
				}
				send_interface_toast = {
					title = bishop.1001.c.failure
					left_icon = scope:spouse
					right_icon = scope:bishop
					add_trait = incestuous
					add_piety_level = -1
					scope:spouse = {
						add_trait = incestuous
						add_piety_level = -1
					}
					add_prestige = major_prestige_loss
				}
			}
		}
		ai_chance = {
			base = 50
			compare_modifier = {
				value = learning
				multiplier = 1
			}
		}
	}

	option = { #Refuse - hook
		name = bishop.1001.d
		if = {
			limit = {
				NOT = {
					scope:bishop = {
						has_hook = root
					}
				}
			}
			scope:bishop = {
				add_hook = {
					target = root
					type = favor_hook
				}
			}
		}
		else = {
			pay_short_term_gold = {
				target = scope:bishop
				gold = root.major_gold_value
			}
		}
		ai_chance = {
			base = 75
		}
	}
}


#######################
# Force you to leave faction
# by Linnéa Thimrén
#######################
bishop.1011 = {
	type = letter_event
	opening = {
		desc = bishop.1001.opening
	}
	desc = {
		desc = bishop.1011.desc_opening
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:cannibal_food
				}
				desc = bishop.1011.desc_cannibal
			}
			triggered_desc = {
				trigger = {
					exists = scope:to_beat_up
				}
				desc = bishop.1011.desc_beating
			}
		}
	}
	sender = scope:bishop

	trigger = {
		NOT = { has_character_flag = had_event_bishop_1011 }
		is_ai = no
		root.faith = { has_doctrine = doctrine_theocracy_temporal }
		exists = cp:councillor_court_chaplain
		cp:councillor_court_chaplain = {
			bishop_1001_suitable_theocrat_trigger = yes
			save_temporary_scope_as = bishop_check
		}
		is_a_faction_member = yes
		# [LTAF]
		LTAF_is_loyalist = no
		# [/LTAF]
		joined_faction = {
			NOT = {
				any_faction_member = { this = scope:bishop_check }
			}
		}
	}

	weight_multiplier = { #More likely the more they dislike you
		base = 0.5
		modifier = {
			add = 0.5
			cp:councillor_court_chaplain = {
				opinion = {
					target = liege
					value <= low_negative_opinion
				}
			}
		}
		modifier = {
			add = 0.5
			cp:councillor_court_chaplain = {
				opinion = {
					target = liege
					value <= medium_negative_opinion
				}
			}
		}
	}

	immediate = {
		add_character_flag = {
			flag = had_event_bishop_1011
			years = 10
		}
		cp:councillor_court_chaplain = {
			save_scope_as = bishop
		}
		joined_faction = {
			save_scope_as = faction
			faction_target = {
				save_scope_as = targeting
				if = {
					limit = {
						any_theocratic_vassal = {
							opinion = {
								target = scope:targeting
								value <= -10
							}
							can_join_faction = scope:faction
						}
					}
					random_theocratic_vassal = {
						limit = {
							opinion = {
								target = scope:targeting
								value <= -10
							}
							can_join_faction = scope:faction
						}
						save_scope_as = targets_vassal
					}
				}
			}
		}
		#To get some fun flavor in there!
		if = {
			limit = {
				scope:bishop = {
					has_trait = cannibal
				}
				any_courtier = {
					NOT = { this = scope:bishop }
				}
			}
			random_courtier = {
				limit = {
					NOT = { this = scope:bishop }
					exists = root.player_heir
					this = root.player_heir
				}
				alternative_limit = {
					NOT = { this = scope:bishop }
					OR = {
						has_relation_friend = root
						has_relation_lover = root
					}
				}
				alternative_limit = {
					NOT = { this = scope:bishop }
					is_close_or_extended_family_of = root
				}
				alternative_limit = {
					NOT = { this = scope:bishop }
				}
				save_scope_as = cannibal_food
			}
		}
		if = {
			limit = {
				scope:bishop = {
					has_trait = wrathful
				}
				any_courtier = {
					NOT = { this = scope:bishop }
					NOT = {
						has_trait_rank = {
							trait = wounded
							rank >= 2
						}
					}
				}
			}
			random_courtier = {
				limit = {
					NOT = { this = scope:bishop }
					exists = root.player_heir
					this = root.player_heir
					NOT = {
						has_trait_rank = {
							trait = wounded
							rank >= 2
						}
					}
				}
				alternative_limit = {
					NOT = { this = scope:bishop }
					OR = {
						has_relation_friend = root
						has_relation_lover = root
					}
					NOT = {
						has_trait_rank = {
							trait = wounded
							rank >= 2
						}
					}
				}
				alternative_limit = {
					NOT = { this = scope:bishop }
					is_close_or_extended_family_of = root
					NOT = {
						has_trait_rank = {
							trait = wounded
							rank >= 2
						}
					}
				}
				alternative_limit = {
					NOT = { this = scope:bishop }
					NOT = {
						has_trait_rank = {
							trait = wounded
							rank >= 2
						}
					}
				}
				save_scope_as = to_beat_up
			}
		}
	}

	option = { #Sure, I'll leave the faction
		name = bishop.1011.a
		leave_faction_with_cooldown_effect = {
			FACTION = scope:faction
 			YEARS = 10
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_zeal = 0.75
			}
		}
	}

	option = { #No!
		name = bishop.1011.b
		flavor = bishop.1011.b.tt
		if = {
			limit = {
				exists = scope:cannibal_food
			}
			trigger_event = {
				id = bishop.1012
				days = { 7 14 }
			}
		}
		else_if = {
			limit = {
				exists = scope:to_beat_up
			}
			hidden_effect = {
				send_interface_message = {
					type = bishop_bad_message
					title = bishop.1011.b.outcome
					left_icon = scope:to_beat_up
					scope:to_beat_up = {
						increase_wounds_no_death_effect = { REASON = beaten }
					}
				}
			}
		}
		else = {
			faith.religious_head = {
				add_opinion = {
					modifier = respect_opinion
					target = root
					opinion = -10
				}
			}
			if = {
				limit = {
					any_theocratic_vassal = {
						NOT = { this = scope:bishop }
					}
				}
				every_theocratic_vassal = {
					limit = {
						NOT = { this = scope:bishop }
					}
					custom = all_my_theocratic_vassals
					add_opinion = {
						modifier = respect_opinion
						target = root
						opinion = low_negative_opinion
					}
				}
			}
		}
		stress_impact = {
			zealous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_boldness = 0.5
			}
		}
	}

	option = { #no - diplomacy challenge
		name = bishop.1011.c
		trigger = {
			OR = {
				AND = {
					has_trait = gregarious
					diplomacy >= mediocre_skill_rating
				}
				diplomacy >= medium_skill_rating
			}
		}
		trait = gregarious
		skill = diplomacy
		duel = {
			skill = diplomacy
			target = scope:bishop
			25 = {
				trigger = {
					exists = scope:targets_vassal
				}
				desc = bishop.1011.c.success_vassal
				compare_modifier = {
					value = scope:duel_value
					multiplier = 0.1
				}
				send_interface_toast = {
					type = bishop_good_message
					title = bishop.1011.c.success_vassal
					left_icon = scope:targets_vassal
					right_icon = scope:bishop
					
					scope:targets_vassal = {
						join_faction = scope:faction
					}
					add_piety = medium_piety_gain
				}
			}
			25 = {
				trigger = {
					NOT = { exists = scope:targets_vassal }
				}
				desc = bishop.1011.c.success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 0.1
				}
				send_interface_toast = {
					title = bishop.1011.c.success
					left_icon = scope:bishop
					
					every_theocratic_vassal = {
						custom = all_my_theocratic_vassals
						add_opinion = {
							modifier = respect_opinion
							target = root
							opinion = 15
						}
					}
					add_piety = medium_piety_gain
				}
			}
			10 = {
				desc = bishop.1011.c.failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -0.75
				}
				if = {
					limit = {
						exists = scope:cannibal_food
					}
					custom_tooltip = bishop.1011.c.failure.tt
					trigger_event = {
						id = bishop.1012
						days = { 7 14 }
					}
				}
				else_if = {
					limit = {
						exists = scope:to_beat_up
					}
					custom_tooltip = bishop.1011.c.failure.tt
					hidden_effect = {
						send_interface_message = {
							type = bishop_bad_message
							title = bishop.1011.b.outcome
							left_icon = scope:to_beat_up
							scope:to_beat_up = {
								increase_wounds_no_death_effect = { REASON = beaten }
							}
						}
					}
				}
				else = {
					send_interface_toast = {
						title = bishop.1011.c.failure
						left_icon = scope:bishop
						add_prestige = medium_prestige_loss
					}
				}
			}
		}
	}
}

bishop.1012 = {
	hidden = yes
	
	trigger = {
		scope:cannibal_food = {
			is_alive = yes
		}
	}

	immediate = {
		unknown_cannibal_murder_effect = {
			VICTIM = scope:cannibal_food
			MURDERER = scope:bishop
		}
		send_interface_message = {
			type = bishop_good_message
			title = bishop.1012.title
			desc = bishop.1012.desc
			left_icon = scope:cannibal_food
		}
	}
}


#Bishop weasels prisoners out of dungeon with privilegium clericale.

scripted_trigger bishop_2001_suitable_prisoner_trigger = {
	faith = root.faith #From the same faith
	top_liege = root.top_liege #From the same realm
	age >= 12 #Old enough to read
	NOT = { has_trait = excommunicated }
}

scripted_trigger bishop_2001_suitable_theocrat_trigger = {
	opinion = {
		target = liege
		value <= -10
	}
	faith = root.faith
	is_imprisoned = no
}

bishop.2001 = {
	type = character_event
	title = bishop.2001.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:scoped_prisoner = { has_government = theocracy_government }
				}
					desc = bishop.2001.desc.a
			}
			triggered_desc = {
				trigger = {
					scope:scoped_prisoner = {
						learning >= high_skill_rating
						NOT = {
							has_government = theocracy_government
						}
					}
				}
					desc = bishop.2001.desc.b
			}
			triggered_desc = {
				trigger = {
					scope:scoped_prisoner = {
						learning < high_skill_rating
						NOT = {
							has_government = theocracy_government
						}
					}
				}
					desc = bishop.2001.desc.c
			}
		}
		}
	left_portrait = {
		character = scope:scoped_bishop
		animation = anger
	}
	right_portrait = {
		character = scope:scoped_prisoner
		triggered_animation = {
			trigger = {
				scope:scoped_prisoner = {
					learning < high_skill_rating
					NOT = {
						has_government = theocracy_government
					}
				}
			}
			animation = personality_coward
		}
		triggered_animation = {
			trigger = { always = yes }
			animation = idle
		}
	}
	theme = faith

	trigger = {
		NOT = { has_character_flag = had_event_bishop_2001_cooldown }
		is_available_adult = yes
		root.faith = { has_doctrine = doctrine_theocracy_temporal }
		exists = cp:councillor_court_chaplain
		cp:councillor_court_chaplain = {
			bishop_2001_suitable_theocrat_trigger = yes
		}
		any_prisoner = {
			bishop_2001_suitable_prisoner_trigger = yes
		}
	}

	weight_multiplier = {
		base = 1
		modifier = { #Much more likely if ruler is detaining an actual priest.
			add = 1.75
			any_prisoner = {
				has_government = theocracy_government
				bishop_2001_suitable_prisoner_trigger = yes
			}
		}
	}

	immediate = {
		hidden_effect = {
			add_character_flag = {
				flag = had_event_bishop_2001_cooldown
				days = 7200
			}
			random_prisoner = {
				limit = {
					bishop_2001_suitable_prisoner_trigger = yes
					has_government = theocracy_government
				}
				alternative_limit = {
					bishop_2001_suitable_prisoner_trigger = yes
					learning >= decent_skill_rating
					has_strong_religious_conviction_trigger = yes
				}
				alternative_limit = {
					bishop_2001_suitable_prisoner_trigger = yes
					has_strong_religious_conviction_trigger = yes
				}
				alternative_limit = {
					bishop_2001_suitable_prisoner_trigger = yes
				}
				save_scope_as = scoped_prisoner
			}
			cp:councillor_court_chaplain = {
				save_scope_as = scoped_bishop
			}
		}
	}

	#Smart ruler asks to recite different passage of the Bible. (prisoner learning check)
	#Ruler has to let the prisoner go.
	#Sneaky ruler has prisoner assassinated.

	option = { #Smart ruler asks to recite different passage of the Bible. (prisoner learning check)
		name = bishop.2001.a
		trigger = {
			scope:scoped_prisoner = { NOT = { has_government = theocracy_government } }
			learning >= high_skill_rating
		}
		skill = learning
		scope:scoped_prisoner = {
			duel = {
				skill = learning
				value = mediocre_skill_rating
				10 = { #Successful reading.
					desc = tooltip.bishop.2001.a.success
						compare_modifier = {
							value = scope:duel_value
							multiplier = 1.5
						}
					root = {
							add_prestige = medium_prestige_loss
						}
					release_from_prison = yes
					scope:scoped_bishop = {
						hidden_effect = { add_piety = medium_piety_gain }
						add_opinion = {
							target = root
							modifier = humbled_opinion
							opinion = 15
						}
					}
					root = {
						send_interface_toast = {
							title = bishop.2001.success.a.desc.tt
							custom_tooltip = bishop.2001.success.a.desc.tt
							left_icon = scope:scoped_bishop
							right_icon = scope:scoped_prisoner
						}
					}
				}
				10 = { #Failed reading.
						compare_modifier = {
							value = scope:duel_value
							multiplier = -1.5
						}
					desc = tooltip.bishop.a.2001.fail
					root = {
							add_prestige = minor_prestige_gain
						}
					scope:scoped_bishop = {
						hidden_effect = { add_piety = medium_piety_loss }
					}
					root = {
						send_interface_toast = {
							title = bishop.2001.failure.a.desc.tt
							custom_tooltip = bishop.2001.failure.a.desc.tt
							left_icon = scope:scoped_bishop
							right_icon = scope:scoped_prisoner
						}
					}
				}
			}
		}
		ai_chance = {
			base = 50
			modifier = {
				add = 25
				has_trait = cynical
			}
		}
	}

	option = { #Ruler has to let the prisoner go.
		name = bishop.2001.b
		scope:scoped_prisoner = {
			release_from_prison = yes
			if = {
				limit = {
					is_ruler = no
					scope:scoped_bishop = { is_ruler = yes }
				}
				scope:scoped_bishop = { add_courtier = scope:scoped_prisoner }
			}
		}
		scope:scoped_bishop = {
			add_opinion = {
				target = root
				modifier = pleased_opinion
				opinion = 10
			}
		}
		ai_chance = {
			base = 30
			modifier = {
				add = 15
				has_trait = zealous
			}
		}
	}

	option = { #Sneaky ruler has prisoner assassinated.
		name = bishop.2001.c
		duel = {
			skill = intrigue
			target = scope:scoped_prisoner
			10 = { #Successful assassination on release.
				desc = tooltip.bishop.c.2001.success
					compare_modifier = {
						value = scope:duel_value
						multiplier = 1
					}
				unknown_murder_effect = {
					VICTIM = scope:scoped_prisoner
					MURDERER = root
					REASON = death_mysterious
				}
				send_interface_toast = {
					left_icon = scope:scoped_bishop
					right_icon = scope:scoped_prisoner
					title = bishop.2001.success.c.desc.tt
					custom_tooltip = bishop.2001.success.c.desc.tt
				}
				add_dread = minor_dread_gain
			}
			10 = { #Failed assassination.
					compare_modifier = {
						value = scope:duel_value
						multiplier = -0.75
					}
				desc = tooltip.bishop.c.2001.fail
				scope:scoped_prisoner = {
					release_from_prison = yes
					if = {
						limit = {
							is_ruler = no
							scope:scoped_bishop = { is_ruler = yes }
						}
						scope:scoped_bishop = { add_courtier = scope:scoped_prisoner }
					}
				}
				send_interface_toast = {
					left_icon = scope:scoped_bishop
					right_icon = scope:scoped_prisoner
					title = bishop.2001.failure.c.desc.tt
					custom_tooltip = bishop.2001.failure.c.desc.tt
				}
			}
		}
		ai_chance = {
			base = 10
			modifier = {
				add = 15
				has_trait = deceitful
			}
		}
	}
	option = { #Ruler refuses the Bishop's request altogether.
		name = bishop.2001.d
		add_piety = medium_piety_loss
		scope:scoped_bishop = {
			add_opinion = {
				target = root
				modifier = insulted_opinion
				opinion = -40
			}
		}
		every_theocratic_vassal = {
			custom = bishop.2003.everytheocrat.custom
			limit = {
				faith = scope:scoped_bishop.faith
				NOT = { this = scope:scoped_bishop }
			}
			add_opinion = {
				target = root
				modifier = impious_opinion
				opinion = -20
			}
		}
		stress_impact = {
			zealous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 5
			modifier = {
				add = 15
				has_trait = cynical
			}
		}
	}
}


#Bishop sets close family against ruler.

scripted_trigger bishop_2002_suitable_relative_trigger = {
	faith = root.faith #From the same faith
	top_liege = root #From the same realm
	age >= 16 #Old enough to understand
	is_imprisoned = no
	NOR = {
		has_trait = excommunicated
		has_trait = cynical
	}
	is_close_family_or_spouse_of_root_trigger = yes
}

scripted_trigger bishop_2002_suitable_theocrat_trigger = {
	opinion = {
		target = liege
		value <= -20
	}
	is_imprisoned = no
	faith = root.faith
}

bishop.2002 = {
	type = character_event
	title = bishop.2002.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:scoped_relative
				}
					desc = bishop.2002.desc.b
			}
			triggered_desc = {
				trigger = {
					NOT = {
						exists = scope:scoped_relative
					}
				}
					desc = bishop.2002.desc.c
			}
		}
		desc = bishop.2002.desc.a
		}
	left_portrait = {
		character = scope:scoped_relative
		animation = dismissal
	}
	right_portrait = scope:scoped_bishop
	theme = faith

	trigger = {
		NOT = { has_character_flag = had_event_bishop_2002_cooldown }
		is_available_adult = yes
		exists = cp:councillor_court_chaplain
		cp:councillor_court_chaplain = {
			bishop_2002_suitable_theocrat_trigger = yes
		}
		any_close_or_extended_family_member = {
			bishop_2002_suitable_relative_trigger = yes
			count >= 3
		}
	}

	weight_multiplier = {
		base = 1
		modifier = { #More likely if in large family.
			add = 1.5
			any_close_or_extended_family_member = {
				bishop_2002_suitable_relative_trigger = yes
				count >= 15
			}
		}
		modifier = { #More likely if in large family.
			add = 1.5
			any_close_or_extended_family_member = {
				bishop_2002_suitable_relative_trigger = yes
				is_child_of = root
				count >= 5
			}
		}
		modifier = { #More likely if chaplain is good talker.
			add = 1.5
			exists = cp:councillor_court_chaplain
			cp:councillor_court_chaplain = {
				diplomacy >= high_skill_rating
			}
		}
		modifier = { #More likely if chaplain is good talker.
			add = 1.5
			exists = cp:councillor_court_chaplain
			cp:councillor_court_chaplain = {
				diplomacy >= average_skill_rating
			}
		}
		modifier = { #More likely if chaplain doesn't like liege.
			add = 1.5
			exists = cp:councillor_court_chaplain
			cp:councillor_court_chaplain = {
				opinion = {
					target = root
					value <= -50
				}
			}
		}
		modifier = { #More likely if chaplain doesn't like liege.
			add = 1.5
			exists = cp:councillor_court_chaplain
			cp:councillor_court_chaplain = {
				opinion = {
					target = root
					value <= -25
				}
			}
		}
	}

	immediate = {
		hidden_effect = {
			add_character_flag = {
				flag = had_event_bishop_2002_cooldown
				days = 7200
			}
			cp:councillor_court_chaplain = {
				save_scope_as = scoped_bishop
			}
			if = {
				limit = {
					any_close_or_extended_family_member = {
						bishop_2002_suitable_relative_trigger = yes
						opinion = {
							target = root
							value >= 25
						}
					}
				}
				random_close_or_extended_family_member = {
					limit = {
						bishop_2002_suitable_relative_trigger = yes
						opinion = {
							target = root
							value >= 50
						}
						OR = {
							is_spouse_of = root
							is_player_heir_of_trigger = { CHARACTER = root }
						}
					}
					alternative_limit = {
						bishop_2002_suitable_relative_trigger = yes
						opinion = {
							target = root
							value >= 25
						}
						OR = {
							is_spouse_of = root
							is_player_heir_of_trigger = { CHARACTER = root }
						}
					}
					alternative_limit = {
						bishop_2002_suitable_relative_trigger = yes
						opinion = {
							target = root
							value >= 25
						}
						OR = {
							is_spouse_of = root
							is_child_of = root
							is_player_heir_of_trigger = { CHARACTER = root }
						}
					}
					alternative_limit = {
						bishop_2002_suitable_relative_trigger = yes
						opinion = {
							target = root
							value >= 25
						}
					}
					save_scope_as = scoped_relative
				}
			}
		}
	}

	#Option A: Use diplomacy. (Success = +Prestige//Failure = -Prestige, -Opinion)
	#Option B: Apologize. (+Piety, -Prestige, - Opinion)
	#Option C: Use Dread. (-Piety, Negative modifier against Theocracies)

	option = { # Use diplomacy.
		name = bishop.2002.a
		duel = {
			skill = diplomacy
			target = scope:scoped_bishop
			10 = { #Success.
				desc = tooltip.bishop.2002.a.success
					compare_modifier = {
						value = scope:duel_value
						multiplier = 1.25
					}
					add_prestige = minor_prestige_gain
				send_interface_toast = {
					left_icon = scope:scoped_bishop
					title = bishop.2002.success.a.desc.tt
					custom_tooltip = bishop.2002.success.a.desc.tt
				}
			}
			10 = { #Failure.
					compare_modifier = {
						value = scope:duel_value
						multiplier = -1.25
					}
				desc = tooltip.bishop.a.2002.fail
					add_prestige = medium_prestige_loss
				send_interface_toast = {
					left_icon = scope:scoped_bishop
					title = bishop.2002.failure.a.desc.tt
					custom_tooltip = bishop.2002.failure.a.desc.tt
				}
			  	if = {
			  		limit = {
						any_close_or_extended_family_member = {
								NOT = { this = scope:scoped_bishop }
								has_strong_religious_conviction_trigger = yes
								bishop_2002_suitable_relative_trigger = yes
							}
			  		}
				  	every_close_or_extended_family_member = {
						custom = bishop.2002.everypiousrelative.custom
							limit = {
								NOT = { this = scope:scoped_bishop }
								has_strong_religious_conviction_trigger = yes
								bishop_2002_suitable_relative_trigger = yes
							}
							add_opinion = {
							target = root
							modifier = impious_opinion
							opinion = -40
							}
					}
				}
			  	every_close_or_extended_family_member = {
					custom = bishop.2002.everyrelative.custom
						limit = {
							NOT = { this = scope:scoped_bishop }
							has_strong_religious_conviction_trigger = no
							bishop_2002_suitable_relative_trigger = yes
						}
						add_opinion = {
						target = root
						modifier = impious_opinion
						opinion = -20
						}
				}
			}
		}
		stress_impact = {
			shy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 50
			modifier = {
				add = 25
				has_trait = gregarious
			}
		}
	}

	option = { #Apologize.
		name = bishop.2002.b
		add_piety = minor_piety_gain
		add_prestige = medium_prestige_loss
		if = {
			limit = {
				any_close_or_extended_family_member = {
					NOT = { this = scope:scoped_bishop }
					has_strong_religious_conviction_trigger = yes
					bishop_2002_suitable_relative_trigger = yes
				}
			}
			every_close_or_extended_family_member = {
				custom = bishop.2002.everypiousrelative.custom
				limit = {
					NOT = { this = scope:scoped_bishop }
					has_strong_religious_conviction_trigger = yes
					bishop_2002_suitable_relative_trigger = yes
				}
				add_opinion = {
					target = root
					modifier = impious_opinion
					opinion = -20
				}
		  	}
	  	}
		every_close_or_extended_family_member = {
			custom = bishop.2002.everyrelative.custom
			limit = {
				NOT = { this = scope:scoped_bishop }
				has_strong_religious_conviction_trigger = no
				bishop_2002_suitable_relative_trigger = yes
			}
			add_opinion = {
				target = root
				modifier = impious_opinion
				opinion = -10
			}
	  	}
		scope:scoped_bishop = {
			add_opinion = {
				target = root
				modifier = pleased_opinion
				opinion = 10
			}
		}
		stress_impact = {
			cynical = minor_stress_impact_gain
		}
		ai_chance = {
			base = 30
			modifier = {
				add = 15
				has_trait = zealous
			}
		}
	}

	option = { #Use Dread.
		name = bishop.2002.c
		add_dread = minor_dread_gain
		add_piety = medium_piety_loss
		 add_character_modifier = {
		 	modifier = scorned_theocrats_modifier
		 	years = 2
		 }
		stress_impact = {
			compassionate = minor_stress_impact_gain
			patient = minor_stress_impact_gain
		}
		ai_chance = {
			base = 5
			modifier = {
				add = 15
				has_trait = callous
			}
			modifier = {
				add = 25
				dread >= medium_dread
			}
		}
	}
}

#Bishop sows dissent within a ruler's demesne provinces.

scripted_trigger bishop_2003_suitable_province_trigger = {
	OR = { #Cities and Churches
		has_building_with_flag = city
		has_building_with_flag = temple
	}
}

scripted_trigger bishop_2003_suitable_theocrat_trigger = {
	opinion = {
		target = liege
		value <= -20
	}
	is_imprisoned = no
	save_temporary_scope_as = potential_bishop
	liege = { #Should have at least a couple counties of his religion.
		any_directly_owned_province = {
			faith = scope:potential_bishop.faith
			count >= 2
		}
	}
}

bishop.2003 = {
	type = character_event
	title = bishop.2003.t
	desc = bishop.2003.desc
	right_portrait = scope:scoped_bishop
	theme = faith

	trigger = {
		NOT = { has_character_flag = had_event_bishop_2003_cooldown }
		is_available_adult = yes
		exists = cp:councillor_court_chaplain
		cp:councillor_court_chaplain = {
			bishop_2003_suitable_theocrat_trigger = yes
			save_temporary_scope_as = potential_bishop
		}
		any_directly_owned_province = {
			bishop_2003_suitable_province_trigger = yes
			faith = scope:potential_bishop.faith
		}
	}

	weight_multiplier = {
		base = 1
		modifier = { #More likely if infidel.
			add = 1.5
			any_theocratic_vassal = {
				bishop_2003_suitable_theocrat_trigger = yes
				NOT = { faith = root.faith }
			}
		}
		modifier = { #More likely if chaplain doesn't like liege.
			add = 1.5
			exists = cp:councillor_court_chaplain
			cp:councillor_court_chaplain = {
				opinion = {
					target = root
					value <= -50
				}
			}
		}
		modifier = { #More likely if chaplain doesn't like liege.
			add = 1.5
			exists = cp:councillor_court_chaplain
			cp:councillor_court_chaplain = {
				opinion = {
					target = root
					value <= -25
				}
			}
		}
	}

	immediate = {
		hidden_effect = {
			add_character_flag = {
				flag = had_event_bishop_2003_cooldown
				days = 3600
			}
			cp:councillor_court_chaplain = {
				save_scope_as = scoped_bishop
			}
		}
	}

	#Option A: Donation. (+Piety, -Prestige, + Opinion, - Wealth)
	#Option B: Endure (-Prestige, - Opinion, - Control)
	#Option C: Dread. (-Piety, Negative modifier against Theocracies if same faith/ if infidel, bishop killed and tyranny gained)


	option = { # Donation. (+Piety, -Prestige, + Opinion, - Wealth)
		name = bishop.2003.a
		if = {
			limit = { faith = scope:scoped_bishop.faith }
			add_piety = minor_piety_gain
		}
		if = {
			limit = { NOT = { faith = scope:scoped_bishop.faith } }
			add_piety = minor_piety_loss
		}
		add_prestige = medium_prestige_loss
		scope:scoped_bishop = {
			add_opinion = {
				target = root
				modifier = pleased_opinion
				opinion = 15
			}
		}
		pay_short_term_gold = {
			target = scope:scoped_bishop
			gold = root.medium_gold_value
		}
		if = {
			limit = {
				faith = scope:scoped_bishop.faith
			}
			stress_impact = {
				greedy = minor_stress_impact_gain
			}
		}
		else = {
			stress_impact = {
				zealous = medium_stress_impact_gain
			}
		}
		ai_chance = {
			base = 30
			modifier = {
				add = 15
				faith = scope:scoped_bishop.faith
				has_trait = zealous
			}
		}
	}
	option = { #Endure.
		name = {
			trigger = { has_personality_dominant_trigger = yes }
			text = bishop.2003.b.a
		}
		name = {
			trigger = { has_personality_dominant_trigger = no }
			text = bishop.2003.b.b
		}
		add_prestige = minor_prestige_loss
		if = {
			limit = {
				OR = {
					faith = scope:scoped_bishop.faith
					faith = { has_doctrine = doctrine_pluralism_pluralistic }
				}
			}
			every_sub_realm_county = {
				custom = bishop.2003.countyunrest.custom
				limit = {
					holder = root
					faith = scope:scoped_bishop.faith
				}
				change_county_control = minor_county_control_loss
			}
		}
		else = {
			every_sub_realm_county = {
				custom = bishop.2003.countyunrest.custom
				limit = {
					holder = root
					faith = scope:scoped_bishop.faith
				}
				change_county_control = medium_county_control_loss
			}
		}
		ai_chance = {
			base = 30
			modifier = {
				add = 15
				has_trait = greedy
			}
		}
	}

	option = { #Use Dread.
		name = {
			trigger = { has_personality_malicious_trigger = no }
			text = bishop.2003.c
		}
		name = {
			trigger = { has_personality_malicious_trigger = yes }
			text = bishop.2003.c.infidel
		}
		if = {
			limit = {
				has_personality_malicious_trigger = no
			}
			add_dread = minor_dread_gain
			add_piety = minor_piety_loss
			every_theocratic_vassal = {
				custom = bishop.2003.everytheocrat.custom
				limit = {
					faith = scope:scoped_bishop.faith
					OR = {
						faith = root.faith
						faith = { has_doctrine = doctrine_pluralism_pluralistic }
					}
				}
				add_opinion = {
					target = root
					modifier = impious_opinion
					opinion = -25
				}
			}
		}
		else_if = {
			limit = {
				has_personality_malicious_trigger = yes
			}
			execute_prisoner_effect = { VICTIM = scope:scoped_bishop EXECUTIONER = root }
		}
		if = {
			limit = {
				OR = {
					faith = scope:scoped_bishop.faith
					faith = { has_doctrine = doctrine_pluralism_pluralistic }
				}
			}
			stress_impact = {
				compassionate = minor_stress_impact_gain
			}
		}
		else = {
			stress_impact = {
				zealous = medium_stress_impact_gain
			}
		}
		ai_chance = {
			base = 5
			modifier = {
				add = 15
				has_trait = callous
			}
			modifier = {
				add = 25
				dread >= medium_dread
			}
		}
	}
}