#Events related to the Spouse Councillor's diplomacy task

namespace = councillor_spouse_learning

#######################
# NOTIFICATION EVENTS # by Mathilda Bjarnehed
#######################

#Different faith/culture
#1001 - Vassal of spouse culture/faith opinion increase
#1002 - Important member of spouse's house opinion increase
#1003 - Opinion increase in domain county with spouse's culture/faith

#Same faith/culture
#1301 - Spouse converts someone of a different faith
#1302 - Spouse converts someone of a different culture
#1303 - Spouse gives piety
#1304 - Spouse increases relations with religious vassals
#1305 - Spouse increases relations with religious head

#General
#1601 - Spouse helps with focus progress
#1602 - Spouse makes child shrewed
#1603 - Opinion increased with ward at court (not your child)



#######################
# EVENTS			  # by Mathilda Bjarnehed
#######################

#Different faith/culture
#2001 - Spouse mediates with faction member

#Same faith/culture
#2301 - Spouse has good relations with religious head

#General
#2601 - Spouse offers to tutor you
#2602 - Spouse offers to tutor an important person in secondary skill
#2603 - Spouse offers to tutor a councillor


##############################################################################################


#######################
#######################
# NOTIFICATION EVENTS # by Mathilda Bjarnehed
#######################
#######################

#########################################
# NOTIFICATIONS DIFFERENT CULTURE/FAITH #
#########################################


#Vassal of spouse culture/faith opinion increase
scripted_trigger councillor_spouse_learning_1001_vassal_trigger = {
	character_same_faith_or_culture_as_councillor_but_different_from_root_trigger = yes
	is_available_ai = yes
	NOT = {
		has_opinion_modifier = {
			modifier = spouse_mediation_opinion
			target = root
		}
	}
}

councillor_spouse_learning.1001 = {
	hidden = yes
	
	trigger = {
		valid_spouse_councillor_trigger = yes
		different_faith_and_or_culture_from_councillor_trigger = yes
		any_vassal = { councillor_spouse_learning_1001_vassal_trigger = yes }
	}

	weight_multiplier = {
		base = 1
		councillor_spouse_limited_skill_rating_modifier = {
			SKILL = learning
			SCALE = 1
			SKILL_RATING = spouse_skill_rating_1
		}
	}

	immediate = {
		cp:councillor_spouse = {
			save_scope_as = active_councillor
		}
		random_vassal = {
			limit = {
				councillor_spouse_learning_1001_vassal_trigger = yes
				is_powerful_vassal = yes
				opinion = {
					target = root
					value <= 0
				}
			}
			alternative_limit = {
				councillor_spouse_learning_1001_vassal_trigger = yes
				opinion = {
					target = root
					value <= 0
				}
			}
			alternative_limit = {
				councillor_spouse_learning_1001_vassal_trigger = yes
				is_powerful_vassal = yes
			}
			alternative_limit = {
				councillor_spouse_learning_1001_vassal_trigger = yes
			}
			save_scope_as = opinion_vassal
		}

		send_interface_message = {
			type = event_spouse_task_good
			title = {
				random_valid = {
					triggered_desc = {
						trigger = { scope:opinion_vassal = { faith = scope:councillor.faith } }
						desc = councillor_spouse_learning.1001.religion.t
					}
					triggered_desc = {
						trigger = { scope:opinion_vassal = { culture = scope:councillor.culture } }
						desc = councillor_spouse_learning.1001.culture.t
					}
				}
			}
			desc = {
				triggered_desc = {
					trigger = {
						scope:active_councillor = { learning < average_skill_level }
					}
					desc = task_learning_good_unskilled_notification_tooltip
				}
				triggered_desc = {
					trigger = {
						scope:active_councillor = { learning >= average_skill_level }
					}
					desc = task_learning_good_skilled_notification_tooltip
				}
			}
			left_icon = scope:opinion_vassal
			right_icon = scope:councillor
			if = {
				limit = {
					spouse_learning_tier_3_trigger = yes
				}
				reverse_add_opinion = {
					modifier = spouse_mediation_opinion
					target = scope:opinion_vassal
					opinion = 30
				}
			}
			else_if = {
				limit = {
					spouse_learning_tier_2_trigger = yes
				}
				reverse_add_opinion = {
					modifier = spouse_mediation_opinion
					target = scope:opinion_vassal
					opinion = 20
				}
			}
			else = {
				reverse_add_opinion = {
					modifier = spouse_mediation_opinion
					target = scope:opinion_vassal
					opinion = 10
				}
			}
		}

		scope:councillor = {
			reverse_add_opinion = {
				modifier = respect_opinion
				target = scope:opinion_vassal
				opinion = 20
			}
			if = {
				limit = {
					is_ai = yes
					reverse_opinion = {
						target = scope:opinion_vassal
						value >= 30
					}
					can_set_relation_friend_trigger = { CHARACTER = scope:opinion_vassal }
				}
				random = {
					chance = 3
					set_relation_friend = scope:opinion_vassal
				}
			}
		}
	}
}		


#Important member of spouse's house opinion increase
scripted_trigger councillor_spouse_learning_1002_house_member_trigger = {
	character_same_faith_or_culture_as_councillor_but_different_from_root_trigger = yes
	NOT = { this = scope:councillor }
	is_ai = yes
	OR = {
		is_ruler = yes
		is_dynast = yes
	}
	NOR = {
		has_opinion_modifier = {
			modifier = spouse_mediation_opinion
			target = root
		}
		has_relation_rival = scope:councillor
	}
}

councillor_spouse_learning.1002 = {
	hidden = yes
	
	trigger = {
		valid_spouse_councillor_trigger = yes
		OR = { # Expensive, so we restrict the AI use of this
			is_ai = no
			highest_held_title_tier > tier_county
		}
		different_faith_and_or_culture_from_councillor_trigger = yes
		scope:councillor = {
			has_dynasty = yes
			dynasty = {
				any_dynasty_member = {
					councillor_spouse_learning_1002_house_member_trigger = yes
				}
			}
		}
	}

	weight_multiplier = {
		base = 1
		councillor_spouse_limited_skill_rating_modifier = {
			SKILL = learning
			SCALE = 1
			SKILL_RATING = spouse_skill_rating_1
		}
	}

	immediate = {
		cp:councillor_spouse = {
			save_scope_as = active_councillor
		}
		scope:councillor = {
			dynasty = {
				random_dynasty_member = {
					limit = {
						councillor_spouse_learning_1002_house_member_trigger = yes
						is_house_head = yes
						opinion = {
							target = root
							value <= 0
						}
					}
					alternative_limit = {
						councillor_spouse_learning_1002_house_member_trigger = yes
						is_powerful_vassal = yes
						opinion = {
							target = root
							value <= 0
						}
					}
					alternative_limit = {
						councillor_spouse_learning_1002_house_member_trigger = yes
						is_powerful_vassal = yes
					}
					alternative_limit = {
						councillor_spouse_learning_1002_house_member_trigger = yes
						opinion = {
							target = root
							value <= 0
						}
					}
					alternative_limit = {
						councillor_spouse_learning_1002_house_member_trigger = yes
						is_house_head = yes
					}
					alternative_limit = {
						councillor_spouse_learning_1002_house_member_trigger = yes
					}
					save_scope_as = opinion_house_member
				}
			}
		}

		send_interface_message = {
			type = event_spouse_task_good
			title = {
				random_valid = {
					triggered_desc = {
						trigger = { scope:opinion_house_member = { faith = scope:councillor.faith } }
						desc = councillor_spouse_learning.1002.religion.t
					}
					triggered_desc = {
						trigger = { scope:opinion_house_member = { culture = scope:councillor.culture } }
						desc = councillor_spouse_learning.1002.culture.t
					}
				}
			}	
			desc = {
				triggered_desc = {
					trigger = {
						scope:active_councillor = { learning < average_skill_level }
					}
					desc = task_learning_good_unskilled_notification_tooltip
				}
				triggered_desc = {
					trigger = {
						scope:active_councillor = { learning >= average_skill_level }
					}
					desc = task_learning_good_skilled_notification_tooltip
				}
			}
			left_icon = scope:opinion_house_member
			right_icon = scope:councillor
			if = {
				limit = { spouse_learning_tier_3_trigger = yes
				}
				reverse_add_opinion = {
					modifier = spouse_mediation_opinion
					target = scope:opinion_house_member
					opinion = 30
				}
			}
			else_if = {
				limit = { spouse_learning_tier_2_trigger = yes
				}
				reverse_add_opinion = {
					modifier = spouse_mediation_opinion
					target = scope:opinion_house_member
					opinion = 20
				}
			}
			else = {
				reverse_add_opinion = {
					modifier = spouse_mediation_opinion
					target = scope:opinion_house_member
					opinion = 10
				}
			}
		}

		scope:councillor = {
			reverse_add_opinion = {
				modifier = respect_opinion
				target = scope:opinion_house_member
				opinion = 20
			}
			if = {
				limit = {
					is_ai = yes
					reverse_opinion = {
						target = scope:opinion_house_member
						value >= 30
					}
					can_set_relation_friend_trigger = { CHARACTER = scope:opinion_house_member }
				}
				random = {
					chance = 3
					modifier = {
						add = 17
						has_relation_potential_friend = scope:opinion_house_member
					}
					set_relation_friend = scope:opinion_house_member
				}
			}
		}
	}
}	

#Opinion increase in domain county with spouse's culture/faith
scripted_trigger councillor_spouse_learning_1003_province = {
	province_same_faith_or_culture_as_councillor_but_different_from_root_trigger = yes
	county = {
		NOR = {
			has_county_modifier = county_mediation_1
			has_county_modifier = county_mediation_2
			has_county_modifier = county_mediation_3
		}
	}
}

councillor_spouse_learning.1003 = {
	hidden = yes
	
	trigger = {
		valid_spouse_councillor_trigger = yes
		different_faith_and_or_culture_from_councillor_trigger = yes
		any_directly_owned_province = {
			councillor_spouse_learning_1003_province = yes
		}
	}

	weight_multiplier = {
		base = 1
		councillor_spouse_limited_skill_rating_modifier = {
			SKILL = learning
			SCALE = 1
			SKILL_RATING = spouse_skill_rating_1
		}
	}

	immediate = {
		cp:councillor_spouse = {
			save_scope_as = active_councillor
		}
		
		random_directly_owned_province = {
			alternative_limit = {
				county = { county_opinion < 0 }
				councillor_spouse_learning_1003_province = yes
			}
			limit = { councillor_spouse_learning_1003_province = yes }
			county = { save_scope_as = opinion_county }
		}

		send_interface_message = {
			type = event_spouse_task_good
			title = {
				random_valid = {
					triggered_desc = {
						trigger = { scope:opinion_county = { faith = scope:councillor.faith } }
						desc = councillor_spouse_learning.1003.religion.desc
					}
					triggered_desc = {
						trigger = { scope:opinion_county = { culture = scope:councillor.culture } }
						desc = councillor_spouse_learning.1003.culture.desc
					}
				}
			}	
			desc = {
				triggered_desc = {
					trigger = {
						scope:active_councillor = { learning < average_skill_level }
					}
					desc = task_learning_good_unskilled_notification_tooltip
				}
				triggered_desc = {
					trigger = {
						scope:active_councillor = { learning >= average_skill_level }
					}
					desc = task_learning_good_skilled_notification_tooltip
				}
			}
			left_icon = scope:opinion_county
			right_icon = scope:councillor

			if = {
				limit = { spouse_learning_tier_3_trigger = yes
				}
				scope:opinion_county = {
					add_county_modifier = {
						modifier = county_mediation_3
						years = 20
					}
				}
			}
			else_if = {
				limit = { spouse_learning_tier_2_trigger = yes
				}
				scope:opinion_county = {
					add_county_modifier = {
						modifier = county_mediation_2
						years = 20
					}
				}
			}
			else = {
				scope:opinion_county = {
					add_county_modifier = {
						modifier = county_mediation_1
						years = 20
					}
				}
			}
		}

		scope:councillor = {
			add_gold = minor_gold_value
		}
	}
}	

####################################
# NOTIFICATIONS SAME CULTURE/FAITH #
####################################

#Spouse converts someone of a different faith
scripted_trigger councillor_spouse_learning_1301_convert_target = {
	character_different_faith_than_councillor_and_root_trigger = yes
	is_available_ai = yes
	is_alive = yes
	OR = {
		NOR = {
			has_trait = zealous
			has_trait = stubborn
		}
		scope:councillor = { learning >= high_skill_rating }
	}
	NOT = { this = scope:councillor }
	NOT = { this = faith.religious_head }
}

councillor_spouse_learning.1301 = {
	hidden = yes
	
	trigger = {
		valid_spouse_councillor_trigger = yes
		faith = scope:councillor.faith
		OR = {
			#Tier 1 targets
			AND = {
				exists = player_heir
				player_heir = { councillor_spouse_learning_1301_convert_target = yes }
			}
			any_close_or_extended_family_member = { councillor_spouse_learning_1301_convert_target = yes }
			#Tier 2 targets
			AND = {
				spouse_learning_tier_2_trigger = yes
				OR = {
					any_councillor = { councillor_spouse_learning_1301_convert_target = yes }
					any_vassal = { councillor_spouse_learning_1301_convert_target = yes }
				}
			}
			#Tier 3 target is guaranteed powerful vassal, and they will pass through the tier 2 vassal check
		}
	}

	weight_multiplier = {
		base = 1
		councillor_spouse_limited_skill_rating_modifier = {
			SKILL = learning
			SCALE = 1
			SKILL_RATING = spouse_skill_rating_1
		}
	}

	immediate = {
		cp:councillor_spouse = {
			save_scope_as = active_councillor
		}
		every_vassal = {
			limit = { councillor_spouse_learning_1301_convert_target = yes }
			add_to_temporary_list = faith_conversion_list
		}
		every_close_or_extended_family_member = {
			limit = { councillor_spouse_learning_1301_convert_target = yes }
			add_to_temporary_list = faith_conversion_list
		}
		if = {
			limit = {
				exists = player_heir
				player_heir = { councillor_spouse_learning_1301_convert_target = yes }
			}
			player_heir = {
				add_to_temporary_list = faith_conversion_list
			}
		}
		every_councillor = {
			limit = { councillor_spouse_learning_1301_convert_target = yes }
			add_to_temporary_list = faith_conversion_list
		}

		random_in_list = {
			list = faith_conversion_list
			limit = {
				exists = root.player_heir
				this = root.player_heir
			}
			alternative_limit = {
				is_powerful_vassal_of = root
				root = { spouse_learning_tier_3_trigger = yes
				}
			}
			alternative_limit = {
				exists = root.cp:councillor_spymaster
				this = root.cp:councillor_spymaster
				root = { spouse_learning_tier_2_trigger = yes
				}
			}
			alternative_limit = {
				is_councillor_of = root
				root = { spouse_learning_tier_2_trigger = yes
				}
			}
			alternative_limit = {
				is_vassal_of = root
				is_landed = yes
				root = { spouse_learning_tier_2_trigger = yes
				}
			}
			alternative_limit = { always = yes }
			save_scope_as = conversion_character
		}

		send_interface_message = {
			type = event_spouse_task_good
			title = councillor_spouse_learning.1301.t
			desc = {
				triggered_desc = {
					trigger = {
						scope:active_councillor = { learning < average_skill_level }
					}
					desc = task_learning_good_unskilled_notification_tooltip
				}
				triggered_desc = {
					trigger = {
						scope:active_councillor = { learning >= average_skill_level }
					}
					desc = task_learning_good_skilled_notification_tooltip
				}
			}
			left_icon = scope:conversion_character
			right_icon = scope:councillor
			scope:conversion_character = { set_character_faith = root.faith }
		}

		scope:councillor = {
			add_piety = medium_piety_gain
			reverse_add_opinion = {
				modifier = respect_opinion
				target = scope:conversion_character
				opinion = 15
			}
			if = {
				limit = {
					is_ai = yes
					reverse_opinion = {
						target = scope:conversion_character
						value >= 30
					}
					can_set_relation_friend_trigger = { CHARACTER = scope:conversion_character }
				}
				random = {
					chance = 3
					set_relation_friend = scope:conversion_character
				}
			}
		}
	}
}	


#Spouse converts someone of a different culture
scripted_trigger councillor_spouse_learning_1302_convert_target = {
	character_different_culture_than_councillor_and_root_trigger = yes
	is_available_ai = yes
	is_alive = yes
	OR = {
		NOR = {
			has_trait = arrogant
			has_trait = stubborn
		}
		scope:councillor = { learning >= decent_skill_rating }
	}
	NOT = { this = scope:councillor }
}

councillor_spouse_learning.1302 = {
	hidden = yes
	
	trigger = {
		valid_spouse_councillor_trigger = yes
		spouse_learning_tier_2_trigger = yes
		culture = scope:councillor.culture
		OR = {
			#Tier 2 targets
			any_close_or_extended_family_member = { councillor_spouse_learning_1302_convert_target = yes }
			AND = {
				exists = player_heir
				player_heir = { councillor_spouse_learning_1302_convert_target = yes }
			}
			any_councillor = { councillor_spouse_learning_1302_convert_target = yes }
			#Tier 3 targets
			AND = {
				spouse_learning_tier_3_trigger = yes
				any_vassal = { councillor_spouse_learning_1302_convert_target = yes }
			}
		}
	}

	weight_multiplier = {
		base = 1
		councillor_spouse_limited_skill_rating_modifier = {
			SKILL = learning
			SCALE = 1
			SKILL_RATING = spouse_skill_rating_2
		}
	}

	immediate = {
		cp:councillor_spouse = {
			save_scope_as = active_councillor
		}
		every_vassal = {
			limit = { councillor_spouse_learning_1302_convert_target = yes }
			add_to_temporary_list = faith_conversion_list
		}
		every_close_or_extended_family_member = {
			limit = { councillor_spouse_learning_1302_convert_target = yes }
			add_to_temporary_list = faith_conversion_list
		}
		if = {
			limit = { exists = player_heir }
			player_heir = {
				if = {
					limit = { councillor_spouse_learning_1302_convert_target = yes }
					add_to_temporary_list = faith_conversion_list
				}
			}
		}
		every_councillor = {
			limit = { councillor_spouse_learning_1302_convert_target = yes }
			add_to_temporary_list = faith_conversion_list
		}

		random_in_list = {
			list = faith_conversion_list
			limit = {
				save_temporary_scope_as = faith_conversion_list_member
				exists = root.player_heir
				root.player_heir = scope:faith_conversion_list_member
			}
			alternative_limit = {
				exists = liege
				liege = root
				is_powerful_vassal = yes
				root = { spouse_learning_tier_3_trigger = yes
				}
			}
			alternative_limit = {
				save_temporary_scope_as = faith_conversion_list_member
				root = {
					exists = cp:councillor_spymaster
					cp:councillor_spymaster = { this = scope:faith_conversion_list_member }
				}
			}
			alternative_limit = {
				save_temporary_scope_as = faith_conversion_list_member
				root = { any_councillor = { this = scope:faith_conversion_list_member } }
			}
			alternative_limit = {
				exists = liege
				liege = root
				is_landed = yes
				root = { spouse_learning_tier_3_trigger = yes
				}
			}
			alternative_limit = { always = yes }
			save_scope_as = conversion_character
		}

		send_interface_message = {
			title = councillor_spouse_learning.1302.t
			type = event_spouse_task_good
			desc = {
				triggered_desc = {
					trigger = {
						scope:active_councillor = { learning < average_skill_level }
					}
					desc = task_learning_good_unskilled_notification_tooltip
				}
				triggered_desc = {
					trigger = {
						scope:active_councillor = { learning >= average_skill_level }
					}
					desc = task_learning_good_skilled_notification_tooltip
				}
			}
			left_icon = scope:conversion_character
			right_icon = scope:councillor
			scope:conversion_character = { set_culture_same_as = root }
		}

		scope:councillor = {
			add_prestige = minor_prestige_gain
			reverse_add_opinion = {
				modifier = respect_opinion
				target = scope:conversion_character
				opinion = 15
			}
			if = {
				limit = {
					is_ai = yes
					reverse_opinion = {
						target = scope:conversion_character
						value >= 30
					}
					can_set_relation_friend_trigger = { CHARACTER = scope:conversion_character }
				}
				random = {
					chance = 3
					set_relation_friend = scope:conversion_character
				}
			}
		}
	}
}

#Spouse gives piety
councillor_spouse_learning.1303 = {
	hidden = yes
	
	trigger = {
		valid_spouse_councillor_trigger = yes
		faith = scope:councillor.faith
		scope:councillor = { ai_zeal >= 0 }
		NOT = { has_character_flag = had_event_councillor_spouse_learning_1303 }
		spouse_learning_tier_1_trigger = yes
	}

	weight_multiplier = {
		base = 1
		councillor_spouse_limited_skill_rating_modifier = {
			SKILL = learning
			SCALE = 1
			SKILL_RATING = spouse_skill_rating_1
		}
		modifier = {
			scope:councillor = { has_trait = zealous }
			factor = 1.3
		}
		modifier = {
			has_trait = cynical
			factor = 0.6
		}
	}

	immediate = {
		cp:councillor_spouse = {
			save_scope_as = active_councillor
		}
		
		send_interface_message = {
			title = councillor_spouse_learning.1303.desc
			type = event_spouse_task_good
			desc = {
				triggered_desc = {
					trigger = {
						scope:active_councillor = { learning < average_skill_level }
					}
					desc = task_learning_good_unskilled_notification_tooltip
				}
				triggered_desc = {
					trigger = {
						scope:active_councillor = { learning >= average_skill_level }
					}
					desc = task_learning_good_skilled_notification_tooltip
				}
			}
			left_icon = scope:councillor
			if = {
				limit = { spouse_learning_tier_3_trigger = yes }
				add_piety = massive_piety_gain
			}
			else_if = {
				limit = { spouse_learning_tier_2_trigger = yes }
				add_piety = major_piety_gain
			}
			else_if = {
				limit = { spouse_learning_tier_1_trigger = yes }
				add_piety = medium_piety_gain
			}
		}

		scope:councillor = {
			if = {
				limit = { spouse_learning_tier_3_trigger = yes }
				add_piety = massive_piety_gain
			}
			else_if = {
				limit = { spouse_learning_tier_2_trigger = yes }
				add_piety = major_piety_gain
			}
			else_if = {
				limit = { spouse_learning_tier_1_trigger = yes }
				add_piety = medium_piety_gain
			}
		}

		add_character_flag = {
			flag = had_event_councillor_spouse_learning_1303
			years = 2
		}
	}
}

#Spouse increases relations with religious vassals, by Mathilda Bjarnehed
scripted_trigger councillor_spouse_learning_1304_theocratic_vassal_trigger = {
	faith = root.faith
	is_available_ai = yes

	NOT = {
		has_opinion_modifier = {
			modifier = spouse_mediation_opinion
			target = root
		}
	}
}


councillor_spouse_learning.1304 = {
	hidden = yes
	
	trigger = {
		valid_spouse_councillor_trigger = yes
		faith = scope:councillor.faith
		any_theocratic_vassal = {
			councillor_spouse_learning_1304_theocratic_vassal_trigger = yes
		}
	}

	weight_multiplier = {
		base = 1
		councillor_spouse_limited_skill_rating_modifier = {
			SKILL = learning
			SCALE = 1
			SKILL_RATING = spouse_skill_rating_1
		}
		modifier = {
			scope:councillor = { ai_zeal < 0 }
			factor = 0.3
		}
	}

	immediate = {
		cp:councillor_spouse = {
			save_scope_as = active_councillor
		}
		
		random_theocratic_vassal = {
			limit = {
				councillor_spouse_learning_1304_theocratic_vassal_trigger = yes
			}
			weight = {
				base = 1
				modifier = {
					opinion = {
						target = root
						value <= 10
					}
					factor = 3
				}
				modifier = {
					highest_held_title_tier >= tier_county
					factor = 5
				}
			}
			save_scope_as = religious_vassal
		}

		

		send_interface_message = {
			title = councillor_spouse_learning.1304.desc
			type = event_spouse_task_good
			desc = {
				triggered_desc = {
					trigger = {
						scope:active_councillor = { learning < average_skill_level }
					}
					desc = task_learning_good_unskilled_notification_tooltip
				}
				triggered_desc = {
					trigger = {
						scope:active_councillor = { learning >= average_skill_level }
					}
					desc = task_learning_good_skilled_notification_tooltip
				}
			}
			left_icon = scope:religious_vassal
			right_icon = scope:councillor
		
			if = {
				limit = { spouse_learning_tier_3_trigger = yes
				}
				reverse_add_opinion = {
					modifier = spouse_mediation_opinion
					target = scope:religious_vassal
					opinion = 40
				}
			}
			else_if = {
				limit = { spouse_learning_tier_2_trigger = yes
				}
				reverse_add_opinion = {
					modifier = spouse_mediation_opinion
					target = scope:religious_vassal
					opinion = 30
				}
			}
			else = {
				reverse_add_opinion = {
					modifier = spouse_mediation_opinion
					target = scope:religious_vassal
					opinion = 20
				}
			}
		}

		scope:councillor = {
			reverse_add_opinion = {
				modifier = respect_opinion
				target = scope:religious_vassal
				opinion = 30
			}
			if = {
				limit = {
					is_ai = yes
					reverse_opinion = {
						target = scope:religious_vassal
						value >= 50
					}
					can_set_relation_friend_trigger = { CHARACTER = scope:religious_vassal }
				}
				random = {
					chance = 3
					set_relation_friend = scope:religious_vassal
				}
			}
		}
	}
}

#Spouse increases relations with religious head, by Mathilda Bjarnehed
councillor_spouse_learning.1305 = {
	hidden = yes
	
	trigger = {
		valid_spouse_councillor_trigger = yes
		spouse_learning_tier_2_trigger = yes
		NOT = { scope:councillor = { has_trait = excommunicated } }
		faith = scope:councillor.faith
		exists = faith.religious_head
		faith.religious_head = {
			NOT = {
				has_opinion_modifier = {
					modifier = spouse_mediation_opinion
					target = root
				}
			}
		}
	}

	weight_multiplier = {
		base = 1
		councillor_spouse_limited_skill_rating_modifier = {
			SKILL = learning
			SCALE = 1
			SKILL_RATING = spouse_skill_rating_2
		}
		modifier = {
			scope:councillor = { ai_zeal < 0 }
			factor = 0.1
		}
	}

	immediate = {
		cp:councillor_spouse = {
			save_scope_as = active_councillor
		}
		
		faith.religious_head = {
			save_scope_as = religious_head
		}
		
		send_interface_message = {
			title = councillor_spouse_learning.1305.desc
			type = event_spouse_task_good
			desc = {
				triggered_desc = {
					trigger = {
						scope:active_councillor = { learning < average_skill_level }
					}
					desc = task_learning_good_unskilled_notification_tooltip
				}
				triggered_desc = {
					trigger = {
						scope:active_councillor = { learning >= average_skill_level }
					}
					desc = task_learning_good_skilled_notification_tooltip
				}
			}
			left_icon = scope:religious_head
			right_icon = scope:councillor
		
			if = {
				limit = { spouse_learning_tier_3_trigger = yes
				}
				reverse_add_opinion = {
					modifier = spouse_mediation_opinion
					target = scope:religious_head
					opinion = 20
				}
			}
			else = {
				reverse_add_opinion = {
					modifier = spouse_mediation_opinion
					target = scope:religious_head
					opinion = 10
				}
			}
		}

		scope:councillor = {
			reverse_add_opinion = {
				modifier = reputation_opinion
				target = scope:religious_head
				opinion = 20
			}
		}
	}
}



#########################
# GENERAL NOTIFICATIONS #
#########################

#Spouse helps with focus progress
councillor_spouse_learning.1601 = {
	hidden = yes
	
	trigger = {
		valid_spouse_councillor_trigger = yes
		NOT = { has_character_modifier = focused_student }
		OR = {
			AND = {
				has_lifestyle = martial_lifestyle
				scope:councillor = { martial > low_skill_rating }
			}
			AND = {
				has_lifestyle = diplomacy_lifestyle
				scope:councillor = { diplomacy > low_skill_rating }
			}
			AND = {
				has_lifestyle = intrigue_lifestyle
				scope:councillor = { intrigue > low_skill_rating }
			}
			AND = {
				has_lifestyle = stewardship_lifestyle
				scope:councillor = { stewardship > low_skill_rating }
			}
			AND = {
				has_lifestyle = learning_lifestyle
				scope:councillor = { learning > low_skill_rating }
			}
		}
	}

	weight_multiplier = {
		base = 1
		councillor_spouse_limited_skill_rating_modifier = {
			SKILL = learning
			SCALE = 1
			SKILL_RATING = spouse_skill_rating_1
		}
	}

	immediate = {
		cp:councillor_spouse = {
			save_scope_as = active_councillor
		}
		
		send_interface_message = {
			title = councillor_spouse_learning.1601.desc
			type = event_spouse_task_good
			desc = {
				triggered_desc = {
					trigger = {
						scope:active_councillor = { learning < average_skill_level }
					}
					desc = task_learning_good_unskilled_notification_tooltip
				}
				triggered_desc = {
					trigger = {
						scope:active_councillor = { learning >= average_skill_level }
					}
					desc = task_learning_good_skilled_notification_tooltip
				}
			}
			left_icon = scope:councillor

		
			if = {
				limit = { has_lifestyle = martial_lifestyle }
				add_martial_lifestyle_xp = major_lifestyle_xp
			}
			else_if = {
				limit = { has_lifestyle = diplomacy_lifestyle }
				add_diplomacy_lifestyle_xp = major_lifestyle_xp
			}
			else_if = {
				limit = { has_lifestyle = intrigue_lifestyle }
				add_intrigue_lifestyle_xp = major_lifestyle_xp
			}
			else_if = {
				limit = { has_lifestyle = stewardship_lifestyle }
				add_stewardship_lifestyle_xp = major_lifestyle_xp
			}
			else_if = {
				limit = { has_lifestyle = learning_lifestyle }
				add_learning_lifestyle_xp = major_lifestyle_xp
			}
			add_character_modifier = {
				modifier = focused_student
				years = 4
			}
		}

		scope:councillor = {
			reverse_add_opinion = {
				modifier = grateful_opinion
				target = root
				opinion = 10
			}
			if = {
				limit = { is_ai = yes }
				if = {
					limit = { root = { has_lifestyle = martial_lifestyle } }
					add_character_modifier = {
						modifier = warfare_tutor
						years = 15
					}
				}
				else_if = {
					limit = { root = { has_lifestyle = diplomacy_lifestyle } }
					add_character_modifier = {
						modifier = statecraft_tutor
						years = 15
					}
				}
				else_if = {
					limit = { root = { has_lifestyle = intrigue_lifestyle } }
					add_character_modifier = {
						modifier = guile_tutor
						years = 15
					}
				}
				else_if = {
					limit = { root = { has_lifestyle = stewardship_lifestyle } }
					add_character_modifier = {
						modifier = governance_tutor
						years = 15
					}
				}
				else_if = {
					limit = { root = { has_lifestyle = learning_lifestyle } }
					add_character_modifier = {
						modifier = scholarship_tutor
						years = 15
					}
				}
			}
		}
	}
}	

#Spouse makes child shrewed
scripted_trigger councillor_spouse_learning_1602_tutored_child_trigger = {
	OR = {
		has_focus = education_learning
		has_focus = education_stewardship
		has_focus = education_martial
		has_focus = education_intrigue
		has_focus = education_diplomacy
	}
	court_owner = root
	NOR = {
		has_trait = intellect_bad
		has_trait = dull
		has_trait = shrewd
	}
	is_available_ai = yes
	OR = {
		any_parent = { this = scope:councillor }
		reverse_opinion = {
			target = scope:councillor
			value >= low_positive_opinion
		}
	}
}

councillor_spouse_learning.1602 = {
	hidden = yes
	
	trigger = {
		valid_spouse_councillor_trigger = yes
		spouse_learning_tier_3_trigger = yes
		any_child = { councillor_spouse_learning_1602_tutored_child_trigger = yes }
		NOT = { has_character_flag = had_event_councillor_spouse_learning_1602 }
	}

	weight_multiplier = {
		base = 1
		councillor_spouse_limited_skill_rating_modifier = {
			SKILL = learning
			SCALE = 1
			SKILL_RATING = spouse_skill_rating_3
		}
	}

	immediate = {
		cp:councillor_spouse = {
			save_scope_as = active_councillor
		}
		
		add_character_flag = {
			flag = had_event_councillor_spouse_learning_1602
			years = 20
		}

		random_child = {
			limit = { #Guaranteed primary heir if spouse is good enough
				save_temporary_scope_as = child
				exists = root.player_heir
				root.player_heir = scope:child
				councillor_spouse_learning_1602_tutored_child_trigger = yes
				OR = {
					has_trait = scholar
					learning >= very_high_skill_rating
				}
			}
			alternative_limit = {
				councillor_spouse_learning_1602_tutored_child_trigger = yes
			}
			save_scope_as = tutored_child
		}

		send_interface_message = {
			title = councillor_spouse_learning.1602.t
			type = event_spouse_task_good
			desc = {
				triggered_desc = {
					trigger = {
						scope:active_councillor = { learning < average_skill_level }
					}
					desc = task_learning_good_unskilled_notification_tooltip
				}
				triggered_desc = {
					trigger = {
						scope:active_councillor = { learning >= average_skill_level }
					}
					desc = task_learning_good_skilled_notification_tooltip
				}
			}
			left_icon = scope:tutored_child
			right_icon = scope:councillor

			scope:tutored_child = { add_trait = shrewd }
		}

		scope:councillor = {
			reverse_add_opinion = {
				modifier = grateful_opinion
				target = scope:tutored_child
				opinion = 50
			}
			if = {
				limit = {
					is_ai = yes
					reverse_opinion = {
						target = scope:tutored_child
						value >= 50
					}
					can_set_relation_friend_trigger = { CHARACTER = scope:tutored_child }
				}
				random = {
					chance = 20
					set_relation_friend = scope:tutored_child
				}
				random_list = {
					1 = { set_nickname_effect = { NICKNAME = nick_the_scholar } }
					1 = { set_nickname_effect = { NICKNAME = nick_the_wise } }
					10 = { }
				}
			}
		}
	}
}

#Opinion increased with ward at court (not your child)
scripted_trigger councillor_spouse_learning_1603_ward_trigger = {
	num_of_relation_guardian >= 1
	NOT = { any_parent = { this = root } }
	NOT = {
		has_opinion_modifier = {
			modifier = grateful_ward_opinion
			target = root
		}
	}
}

councillor_spouse_learning.1603 = {
	hidden = yes
	
	trigger = {
		valid_spouse_councillor_trigger = yes
		any_courtier = {
			councillor_spouse_learning_1603_ward_trigger = yes
		}
	}

	weight_multiplier = {
		base = 1
		councillor_spouse_limited_skill_rating_modifier = {
			SKILL = learning
			SCALE = 1
			SKILL_RATING = spouse_skill_rating_1
		}
		modifier = {
			any_courtier = {
				any_heir_title = { count >= 1 }
				councillor_spouse_learning_1603_ward_trigger = yes
				any_relation = { type = guardian this = scope:councillor }
			}
			factor = 1.4
		}
	}

	immediate = {

		cp:councillor_spouse = {
			save_scope_as = active_councillor
		}
		
		random_courtier = {
			limit = {
				councillor_spouse_learning_1603_ward_trigger = yes
			}
			weight = {
				base = 1
				modifier = {
					any_heir_title = { count >= 1 }
					factor = 2
				}
				modifier = {
					any_parent = {
						is_landed = yes
						liege = { this = root }
					}
					factor = 3
				}
			}
			save_scope_as = opinion_ward
		}

		scope:opinion_ward = { random_relation = { type = guardian save_scope_as = ward_guardian } }

		send_interface_message = {
			title = {
				first_valid = {
					triggered_desc = {
						trigger = { scope:ward_guardian = { this = root } }
						desc = councillor_spouse_learning.1603.root_guardian.t
					}
					triggered_desc = {
						trigger = { scope:ward_guardian = { this = scope:active_councillor } }
						desc = councillor_spouse_learning.1603.spouse_guardian.t
					}
					desc = councillor_spouse_learning.1603.other_guardian.t
				}
			}
			type = event_spouse_task_good
			desc = {
				triggered_desc = {
					trigger = {
						scope:active_councillor = { learning < average_skill_level }
					}
					desc = task_learning_good_unskilled_notification_tooltip
				}
				triggered_desc = {
					trigger = {
						scope:active_councillor = { learning >= average_skill_level }
					}
					desc = task_learning_good_skilled_notification_tooltip
				}
			}
			left_icon = scope:opinion_ward
			right_icon = scope:ward_guardian

			scope:ward_guardian = {
				reverse_add_opinion = {
					target = scope:opinion_ward
					modifier = grateful_ward_opinion
				}
			}
		}

		scope:ward_guardian = {
			reverse_add_opinion = {
				modifier = respect_opinion
				target = scope:opinion_ward
				opinion = 40
			}
			if = {
				limit = {
					is_ai = yes
					reverse_opinion = {
						target = scope:opinion_ward
						value >= 50
					}
					can_set_relation_friend_trigger = { CHARACTER = scope:opinion_ward }
				}
				random = {
					chance = 5
					set_relation_friend = scope:opinion_ward
				}
			}
		}
	}
}


#######################
#######################
#		EVENTS		# by Mathilda Bjarnehed
#######################
#######################

##################################
# EVENTS DIFFERENT CULTURE/FAITH #
##################################


#Spouse mediates with faction member
scripted_trigger councillor_spouse_learning_2001_different_culture_or_faith_faction_trigger = {
	OR = {
		faction_is_type = independence_faction
		faction_is_type = liberty_faction
		faction_is_type = claimant_faction
	}
	faction_leader = {
		save_temporary_scope_as = faction_leader
		exists = this
		is_available_ai = yes
		character_same_faith_or_culture_as_councillor_but_different_from_root_trigger = yes
	}
	any_faction_member = {
		is_available_ai = yes
		NOT = { this = scope:faction_leader }
		OR = {
			AND = {
				character_same_faith_as_councillor_but_different_from_root_trigger = yes
				scope:faction_leader = { character_same_faith_as_councillor_but_different_from_root_trigger = yes }
			}
			AND = {
				character_same_culture_as_councillor_but_different_from_root_trigger = yes
				scope:faction_leader = { character_same_culture_as_councillor_but_different_from_root_trigger = yes }
			}
		}
	}
}

scripted_trigger councillor_spouse_learning_2001_different_culture_or_faith_faction_member_trigger = {
	NOT = { this = scope:faction_leader }
	is_available_ai = yes
	OR = {
		AND = {
			character_same_faith_as_councillor_but_different_from_root_trigger = yes
			scope:difference_type = flag:faith
		}
		AND = {
			character_same_culture_as_councillor_but_different_from_root_trigger = yes
			scope:difference_type = flag:culture
		}
	}
}

councillor_spouse_learning.2001 = {
	type = character_event
	title = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:difference_type = flag:faith }
				desc = councillor_spouse_learning.2001.faith.t
			}
			triggered_desc = {
				trigger = { scope:difference_type = flag:culture }
				desc = councillor_spouse_learning.2001.culture.t
			}
		}
	}
	desc = {
		desc = councillor_spouse_learning.2001.start.desc
		first_valid = {
			triggered_desc = {
				trigger = { scope:difference_type = flag:faith }
				desc = councillor_spouse_learning.2001.faith.desc
			}
			triggered_desc = {
				trigger = { scope:difference_type = flag:culture }
				desc = councillor_spouse_learning.2001.culture.desc
			}
		}
		desc = councillor_spouse_learning.2001.middle.desc
		first_valid = {
			triggered_desc = {
				trigger = { scope:different_culture_or_faith_faction = { faction_is_type = independence_faction } }
				desc = councillor_spouse_learning.2001.independence_faction.desc
			}
			triggered_desc = {
				trigger = { scope:different_culture_or_faith_faction = { faction_is_type = liberty_faction } }
				desc = councillor_spouse_learning.2001.liberty_faction.desc
			}
			triggered_desc = {
				trigger = { scope:different_culture_or_faith_faction = { faction_is_type = claimant_faction } }
				desc = councillor_spouse_learning.2001.claimant_faction.desc
			}
		}
		desc = councillor_spouse_learning.2001.end.desc
	}
	theme = learning
	left_portrait = {
		character = scope:faction_leader
		animation = disapproval
	}
	right_portrait = {
		character = scope:councillor
		animation = scheme
	}
	lower_left_portrait = scope:faction_member_1
	lower_center_portrait = scope:faction_member_2
	
	trigger = {
		valid_spouse_councillor_trigger = yes
		spouse_learning_tier_2_trigger = yes
		any_targeting_faction = {
			councillor_spouse_learning_2001_different_culture_or_faith_faction_trigger = yes
		}
	}

	weight_multiplier = {
		base = 1
		councillor_spouse_limited_skill_rating_modifier = {
			SKILL = learning
			SCALE = 1
			SKILL_RATING = spouse_skill_rating_2
		}
	}

	immediate = {
		random_targeting_faction = {
			limit = { councillor_spouse_learning_2001_different_culture_or_faith_faction_trigger = yes }
			save_scope_as = different_culture_or_faith_faction
			faction_leader = { save_scope_as = faction_leader }
			#Determine whether the difference is religious or cultural
			if = {
				limit = { scope:faction_leader = { character_same_faith_as_councillor_but_different_from_root_trigger = yes } }
				save_scope_value_as = {
					name = difference_type
					value = flag:faith
				}
			}
			else = {
				save_scope_value_as = {
					name = difference_type
					value = flag:culture
				}
			}
			#Save 3 options for "leave faction"
			if = {
				limit = { scope:councillor = { has_trait = scholar } }
				scope:faction_leader = { save_scope_as = faction_member_1 }
			}
			else = {
				random_faction_member = {
					limit = { councillor_spouse_learning_2001_different_culture_or_faith_faction_member_trigger = yes }
					weight = {
						base = 200
						modifier = {
							is_ruler = yes
							add = {
								value = max_military_strength
								if = {
									limit = { spouse_learning_tier_3_trigger = yes
									}
									multiply = 0.2
								}
								else = {
									multiply = 0.1
								}
							}
						}
					}
					save_scope_as = faction_member_1
				}
			}
			random_faction_member = {
				limit = {
					councillor_spouse_learning_2001_different_culture_or_faith_faction_member_trigger = yes
					NOT = { this = scope:faction_member_1 }
				}
				weight = {
					base = 200
					modifier = {
						is_ruler = yes
						add = {
							value = max_military_strength
							if = {
								limit = { spouse_learning_tier_3_trigger = yes
								}
								multiply = 0.2
							}
							else = {
								multiply = 0.1
							}
						}
					}
				}
				save_scope_as = faction_member_2
			}
		}
	}


	#Make them all happier with me
	option = {
		name = {
			trigger = { scope:difference_type = flag:faith }
			text = councillor_spouse_learning.2001.a.faith
		}
		name = {
			trigger = { scope:difference_type = flag:culture }
			text = councillor_spouse_learning.2001.a.culture
		}

		scope:faction_leader = {
			if = {
				limit = { spouse_learning_tier_3_trigger = yes
				}
				add_opinion = {
					modifier = spouse_mediation_opinion
					target = root
					opinion = 40
				}
			}
			else = {
				add_opinion = {
					modifier = spouse_mediation_opinion
					target = root
					opinion = 30
				}
			}
			hidden_effect = {
				add_opinion = {
					target = scope:councillor
					modifier = respect_opinion
					opinion = 20
				}
			}
		}
		scope:different_culture_or_faith_faction = {
			if = { #Only using this if/else to change the "custom"-text, otherwise the effects are the same script
				limit = { scope:difference_type = flag:faith }
				every_faction_member = {
					limit = { councillor_spouse_learning_2001_different_culture_or_faith_faction_member_trigger = yes }
					custom = councillor_spouse_learning.2001.a.faction_members_faith

					if = {
						limit = { spouse_learning_tier_3_trigger = yes
						}
						add_opinion = {
							modifier = spouse_mediation_opinion
							target = root
							opinion = 30
						}
					}
					else = {
						add_opinion = {
							modifier = spouse_mediation_opinion
							target = root
							opinion = 20
						}
					}

					hidden_effect = {
						add_opinion = {
							target = scope:councillor
							modifier = respect_opinion
							opinion = 15
						}
					}
				}
			}
			else = {
				every_faction_member = {
					limit = { councillor_spouse_learning_2001_different_culture_or_faith_faction_member_trigger = yes }
					custom = councillor_spouse_learning.2001.a.faction_members_culture
					if = {
						limit = { spouse_learning_tier_3_trigger = yes
						}
						add_opinion = {
							modifier = spouse_mediation_opinion
							target = root
							opinion = 20
						}
					}
					else = {
						add_opinion = {
							modifier = spouse_mediation_opinion
							target = root
							opinion = 15
						}
					}
					hidden_effect = {
						add_opinion = {
							target = scope:councillor
							modifier = respect_opinion
							opinion = 15
						}
					}
				}
			}	
		}
	}

	#Ask person 1 to leave
	option = {
		name = councillor_spouse_learning.2001.b

		scope:faction_member_1 = {
			leave_faction_with_cooldown_effect = {
				FACTION = scope:different_culture_or_faith_faction
				YEARS = 20
			}
		}

		reverse_add_opinion = {
			modifier = spouse_mediation_opinion
			target = scope:faction_member_1
			opinion = 30
		}
		hidden_effect = {
			scope:faction_member_1 = {
				add_opinion = {
					target = scope:councillor
					modifier = respect_opinion
					opinion = 20
				}
			}
		}
	}
	
	#Ask person 2 to leave
	option = {
		trigger = { exists = scope:faction_member_2 }
		name = councillor_spouse_learning.2001.c

		scope:faction_member_2 = {
			leave_faction_with_cooldown_effect = {
				FACTION = scope:different_culture_or_faith_faction
				YEARS = 20
			}
		}

		reverse_add_opinion = {
			modifier = spouse_mediation_opinion
			target = scope:faction_member_2
			opinion = 30
		}
		hidden_effect = {
			scope:faction_member_1 = {
				add_opinion = {
					target = scope:councillor
					modifier = respect_opinion
					opinion = 20
				}
			}
		}
	}
}




#############################
# EVENTS SAME CULTURE/FAITH #
#############################


#Spouse has good relations with religious head
councillor_spouse_learning.2301 = {
	type = character_event
	title = councillor_spouse_learning.2301.t
	desc = councillor_spouse_learning.2301.desc
	theme = learning
	left_portrait = {
		character = scope:councillor
		animation = happiness
	}
	right_portrait = {
		character = scope:religious_head
		animation = personality_zealous
	}
	
	trigger = {
		valid_spouse_councillor_trigger = yes
		spouse_learning_tier_3_trigger = yes
		NOT = { has_character_flag = had_councillor_spouse_learning_2301_event }
		faith = scope:councillor.faith
		NOT = { scope:councillor = { has_trait = excommunicated } }
		exists = faith.religious_head
		faith.religious_head = {
			opinion = {
				target = scope:councillor
				value >= -10
			}
			NOR = {
				has_relation_friend = root
				this = root
				this = scope:councillor
			}
		}
	}

	weight_multiplier = {
		base = 1
		councillor_spouse_limited_skill_rating_modifier = {
			SKILL = learning
			SCALE = 1
			SKILL_RATING = spouse_skill_rating_3
		}
		modifier = {
			scope:councillor = { ai_zeal < 0 }
			factor = 0.1
		}
		modifier = {
			factor = 1.3
			faith.religious_head = {
				opinion = {
					target = scope:councillor
					value >= 25
				}
			}
		}
	}

	immediate = {
		hidden_effect = {
			faith.religious_head = {
				save_scope_as = religious_head
			}

			add_character_flag = {
				flag = had_councillor_spouse_learning_2301_event
				years = 30
			}

			scope:councillor = {
				reverse_add_opinion = {
					modifier = grateful_opinion
					opinion = 25
					target = scope:religious_head
				}
				add_piety = massive_piety_gain
			}
			if = {
				limit = { is_ai = yes }
				random_list = {
					1 = { set_nickname_effect = { NICKNAME = nick_the_pious } }
					1 = { set_nickname_effect = { NICKNAME = nick_the_blessed } }
					1 = { set_nickname_effect = { NICKNAME = nick_the_holy } }
					10 = { }
				}
			}
		}
	}

	#Friendship
	option = {
		name = councillor_spouse_learning.2301.a

		reverse_add_opinion = {
			modifier = friendliness_opinion
			opinion = 35
			target = scope:religious_head
		}

		if = {
			limit = {
				can_set_relation_friend_trigger = { CHARACTER = scope:religious_head }
			}

			random = {
				chance = 15
				modifier = {
					add = 10
					scope:councillor = {
						OR = {
							has_trait = scholar
							learning >= very_high_skill_rating
						}
					}
				}
				modifier = {
					is_ai = yes
					factor = 0.1
				}

				send_interface_message = {
					type = event_spouse_task_good
					title = councillor_spouse_learning.2301.a.success
					left_icon = scope:religious_head
					set_relation_friend = scope:religious_head
				}	

				hidden_effect = {
					#Your spouse also becomes friend or lover with religious head
					scope:councillor = {
						if = {
							limit = { 
								is_ai = yes 
								mgr_can_seduce = yes
							}
							random_list = {
								95 = {
									modifier = {
										has_trait = chaste
										factor = 2
									}
									modifier = {
										scope:religious_head = { has_trait = chaste }
										factor = 2
									}
									if = {
										limit = {
											can_set_relation_friend_trigger = { CHARACTER = scope:religious_head }
										}
										set_relation_friend = scope:religious_head
									}
								}
								5 = {
									trigger = {
										NOR = {
											has_trait = celibate
											scope:religious_head = { has_trait = celibate }
										}
										can_set_relation_lover_trigger = { CHARACTER = scope:religious_head }
									}
									modifier = {
										has_trait = lustful
										factor = 2
									}
									modifier = {
										scope:religious_head = { has_trait = lustful }
										factor = 2
									}
									set_relation_lover = scope:religious_head
								}
							}
						}
					}
				}
			}
		}

		ai_chance = { base = 1 }
	}

	#Hook
	option = {
		trigger = {
			can_add_hook = {
				target = scope:religious_head
				type = favor_hook
			}
		}
		name = councillor_spouse_learning.2301.b

		add_hook = {
			target = scope:religious_head
			type = favor_hook
		}
		hidden_effect = {
			scope:councillor = {
				if = {
					limit = {
						can_add_hook = {
							target = scope:religious_head
							type = favor_hook
						}
					}
				}
				add_hook = {
					target = scope:religious_head
					type = favor_hook
				}
			}
		}

		ai_chance = {
			base = 10
			modifier = {
				has_trait = zealous
				add = -10
			}
			modifier = {
				has_trait = cynical
				add = 30
			}
			modifier = {
				has_trait = ambitious
				add = 30
			}
		}

		stress_impact = {
			zealous = medium_stress_impact_gain
			content = minor_stress_impact_gain
		}
	}

	#Get me non-excommunicated
	option = {
		trigger = { has_trait = excommunicated }
		name = councillor_spouse_learning.2301.c
		remove_trait = excommunicated

		ai_chance = { base = 100 }
	}

	#Piety
	option = {
		trigger = { NOT = { has_trait = excommunicated } }
		name = councillor_spouse_learning.2301.d

		add_piety = massive_piety_gain

		reverse_add_opinion = {
			modifier = respect_opinion
			opinion = 10
			target = scope:religious_head
		}

		hidden_effect = {
			scope:councillor = { add_piety = medium_piety_gain }
		}

		ai_chance = {
			base = 100
			modifier = {
				has_trait = cynical
				add = -80
			}
			modifier = {
				has_trait = ambitious
				add = -80
			}
		}

		stress_impact = {
			cynical = medium_stress_impact_gain
			ambitious = minor_stress_impact_gain
		}
	}
}


##################
# GENERAL EVENTS #
##################

#Spouse offers to tutor you (primary skill), by Mathilda Bjarnehed
scripted_trigger councillor_spouse_learning_2601_tutoring_student_trigger = {
	is_adult = yes
	has_education_rank_4_trigger = no
	is_available_ai = yes
	exists = liege
	liege = root
}

councillor_spouse_learning.2601 = {
	type = character_event
	title = councillor_spouse_learning.2601.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					OR = {
						has_learning_lifestyle_trait_trigger = yes
						has_lifestyle = learning_lifestyle
						learning >= high_skill_rating
					}
				}
				desc = councillor_spouse_learning.2601.scholarly.desc
			}
			desc = councillor_spouse_learning.2601.not_scholarly.desc
		}
	}
	theme = learning
	left_portrait = {
		character = scope:councillor
		animation = admiration
	}
	lower_left_portrait = scope:tutoring_student_1
	lower_center_portrait = scope:tutoring_student_2
	
	trigger = {
		valid_spouse_councillor_trigger = yes
		spouse_learning_tier_2_trigger = yes
		has_education_rank_4_trigger = no
		NOT = { has_character_flag = had_councillor_spouse_learning_2601_event }
		OR = {
			AND = {
				exists = player_heir
				player_heir = { councillor_spouse_learning_2601_tutoring_student_trigger = yes }
			}
			any_child = { councillor_spouse_learning_2601_tutoring_student_trigger = yes }
			any_councillor= { councillor_spouse_learning_2601_tutoring_student_trigger = yes }
		}
	}

	weight_multiplier = {
		base = 1
		councillor_spouse_limited_skill_rating_modifier = {
			SKILL = learning
			SCALE = 1
			SKILL_RATING = spouse_skill_rating_2
		}
	}

	immediate = {
		cp:councillor_spouse = { save_scope_as = councillor }

		hidden_effect = {
			if = {
				limit = {
					exists = player_heir
				}
				player_heir = {
					if = {
						limit = { councillor_spouse_learning_2601_tutoring_student_trigger = yes }
						add_to_list = tutoring_students
					}
				}
			}
			every_child = {
				limit = { councillor_spouse_learning_2601_tutoring_student_trigger = yes }
				add_to_list = tutoring_students
			}
			every_councillor = {
				limit = { councillor_spouse_learning_2601_tutoring_student_trigger = yes }
			}

			random_in_list = {
				list = tutoring_students
				limit = {
					exists = player_heir
					save_temporary_scope_as = tutoring_student_option
					root = { player_heir = { this = scope:tutoring_student_option } }
				}
				alternative_limit = {
					always = yes
				}
				save_scope_as = tutoring_student_1
			}
			random_in_list = {
				list = tutoring_students
				limit = {
					NOT = { this = scope:tutoring_student_1 }
				}
				save_scope_as = tutoring_student_2
			}
		}
	}

	#yes, tutor me!
	option = {
		name = councillor_spouse_learning.2601.a
		councillor_spouse_learning_2601_tutoring_effect = { STUDENT = root }

		ai_chance = { base = 5 }
	}

	#No, tutor option 1
	option = {
		trigger = { exists = scope:tutoring_student_1 }
		name = councillor_spouse_learning.2601.b
		councillor_spouse_learning_2601_tutoring_effect = { STUDENT = scope:tutoring_student_1 }

		ai_chance = { base = 3 } #Might be heir
	}
	
	#No, tutor option 2
	option = {
		trigger = { exists = scope:tutoring_student_2 }
		name = councillor_spouse_learning.2601.c
		councillor_spouse_learning_2601_tutoring_effect = { STUDENT = scope:tutoring_student_2 }

		ai_chance = { base = 1 }
	}

	#Focus on yourself
	option = {
		name = councillor_spouse_learning.2601.d

		scope:councillor = {
			if = {
				limit = { has_trait = education_learning }
				councillor_spouse_learning_2601_tutoring_effect = { STUDENT = scope:councillor }
			}
			else = {
				add_character_modifier = {
					modifier = studying_learning
					years = 10
				}
			}
		}
		ai_chance = { base = 1 }
	}
}

#Spouse offers to tutor an important person in secondary skill, by Mathilda Bjarnehed
scripted_trigger councillor_spouse_learning_2602_valid_secondary_skill_trigger = {
	NOT = { highest_skill = $SKILL$ }
	scope:councillor = { $SKILL$ > low_skill_rating }
}

scripted_trigger councillor_spouse_learning_2602_student_trigger = {
	is_adult = yes
	OR = {
		AND = {
			is_available_ai = yes
			exists = liege
			liege = { this = root }
		}
		this = root
	}
	
	NOT = { has_character_flag = had_councillor_spouse_learning_2602_skill_improvement }
	NOT = { this = scope:councillor }
	calc_true_if = {
		amount >= 2
		councillor_spouse_learning_2602_valid_secondary_skill_trigger = { SKILL = diplomacy }
		councillor_spouse_learning_2602_valid_secondary_skill_trigger = { SKILL = martial }
		councillor_spouse_learning_2602_valid_secondary_skill_trigger = { SKILL = stewardship }
		councillor_spouse_learning_2602_valid_secondary_skill_trigger = { SKILL = intrigue }
		councillor_spouse_learning_2602_valid_secondary_skill_trigger = { SKILL = learning }
	}
}

councillor_spouse_learning.2602 = {
	type = character_event
	title = councillor_spouse_learning.2602.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:student = root }
				desc = councillor_spouse_learning.2602.root.desc
			}
			desc = councillor_spouse_learning.2602.not_root.desc
		}
	}
	theme = learning
	left_portrait = {
		character = scope:councillor
		animation = personality_rational
	}
	right_portrait ={
		character = scope:student_portrait
		animation = personality_bold
	}
	
	trigger = {
		valid_spouse_councillor_trigger = yes
		spouse_learning_tier_2_trigger = yes
		OR = {
			councillor_spouse_learning_2602_student_trigger = yes
			any_child = { councillor_spouse_learning_2602_student_trigger = yes }
			any_sibling = { councillor_spouse_learning_2602_student_trigger = yes }
			AND = {
				exists = player_heir
				player_heir = { councillor_spouse_learning_2602_student_trigger = yes }
			}
			
		}
	}

	weight_multiplier = {
		base = 1
		councillor_spouse_limited_skill_rating_modifier = {
			SKILL = learning
			SCALE = 1
			SKILL_RATING = spouse_skill_rating_2
		}
	}

	immediate = {

		if = {
			limit = { root = { is_ai = no } }
			scope:councillor = {
				assign_quirk_effect = yes
			}
		}
		#Pick the target
		if = {
			limit = { councillor_spouse_learning_2602_student_trigger = yes }
			add_to_list = secondary_skill_student_list
		}
		if = {
			limit = {
				exists = player_heir
			}
			player_heir = {
				if = {
					limit = { councillor_spouse_learning_2602_student_trigger = yes }
					add_to_list = secondary_skill_student_list
				}
			}
		}

		every_child = {
			limit = { councillor_spouse_learning_2602_student_trigger = yes }
			add_to_list = secondary_skill_student_list
		}
		every_sibling = {
			limit = { councillor_spouse_learning_2602_student_trigger = yes }
			add_to_list = secondary_skill_student_list
		}

		random_in_list = {
			list = secondary_skill_student_list
			weight = {
				base = 1
				modifier = {
					this = root
					factor = 5
				}
				modifier = {
					root = { player_heir = prev }
					factor = 7
				}
				modifier = {
					is_child_of = root
					factor = 2
				}
			}
			save_scope_as = student
		}

		#Save portraits scope (if student is root, no student portrait)
		if = {
			limit = { NOT = { scope:student = { this = root } } }
			scope:student = { save_scope_as = student_portrait }
		}
	}

	#Diplomacy
	option = {
		trigger = { scope:student = { councillor_spouse_learning_2602_valid_secondary_skill_trigger = { SKILL = diplomacy } } }
		name = councillor_spouse_learning.2602.a

		scope:student = {
			add_diplomacy_skill = 1
			add_character_flag = had_councillor_spouse_learning_2602_skill_improvement
		}
	}

	#Martial
	option = {
		trigger = { scope:student = { councillor_spouse_learning_2602_valid_secondary_skill_trigger = { SKILL = martial } } }
		name = councillor_spouse_learning.2602.b

		scope:student = {
			add_martial_skill = 1
			add_character_flag = had_councillor_spouse_learning_2602_skill_improvement
		}
	}
	
	#Stewardship
	option = {
		trigger = { scope:student = { councillor_spouse_learning_2602_valid_secondary_skill_trigger = { SKILL = stewardship } } }
		name = councillor_spouse_learning.2602.c

		scope:student = {
			add_stewardship_skill = 1
			add_character_flag = had_councillor_spouse_learning_2602_skill_improvement
		}
	}

	#Intrigue
	option = {
		trigger = { scope:student = { councillor_spouse_learning_2602_valid_secondary_skill_trigger = { SKILL = intrigue } } }
		name = councillor_spouse_learning.2602.d

		scope:student = {
			add_intrigue_skill = 1
			add_character_flag = had_councillor_spouse_learning_2602_skill_improvement
		}
	}

	#Learning
	option = {
		trigger = { scope:student = { councillor_spouse_learning_2602_valid_secondary_skill_trigger = { SKILL = learning } } }
		name = councillor_spouse_learning.2602.e

		scope:student = {
			add_learning_skill = 1
			add_character_flag = had_councillor_spouse_learning_2602_skill_improvement
		}
	}

	after = {
		hidden_effect = {
			scope:student = {
				add_opinion = {
					target = scope:councillor
					modifier = grateful_opinion
					opinion = 15
				}
			}
		}
	}
}

#Spouse offers to tutor a councillor
scripted_trigger councillor_spouse_learning_2603_valid_councillor_trigger = {
	is_available_ai_adult = yes
	NOT = { this = scope:councillor }
}

councillor_spouse_learning.2603 = { #by Mathilda Bjarnehed
	type = character_event
	title = councillor_spouse_learning.2603.t
	desc = councillor_spouse_learning.2603.desc
	theme = learning
	left_portrait = {
		character = scope:councillor
		animation = personality_bold
	}
	lower_left_portrait = scope:councillor_1
	lower_center_portrait = scope:councillor_2
	lower_right_portrait = scope:councillor_3

	trigger = {
		valid_spouse_councillor_trigger = yes
		NOT = { has_character_flag = had_councillor_spouse_learning_2603_event }
		any_councillor = {
			count >= 2
			councillor_spouse_learning_2603_valid_councillor_trigger = yes
		}
	}

	weight_multiplier = {
		base = 1
		councillor_spouse_limited_skill_rating_modifier = {
			SKILL = learning
			SCALE = 1
			SKILL_RATING = spouse_skill_rating_1
		}
	}

	immediate = {
		add_character_flag = {
			flag = had_councillor_spouse_learning_2603_event
			years = 15
		}

		#Save 3 councillors
		councillor_spouse_learning_2603_scope_save_effect = yes
		councillor_spouse_learning_2603_scope_save_effect = yes
		councillor_spouse_learning_2603_scope_save_effect = yes

		#Set them as portrait scopes
		councillor_spouse_learning_2603_scopes_for_portraits_effect = yes
	}

	option = {
		trigger = { exists = scope:chancellor }
		name = councillor_spouse_learning.2603.a
		
		scope:chancellor = {
			add_character_modifier = {
				modifier = studying_diplomacy
				years = 15
			}
			councillor_spouse_learning_2603_chosen_councillor_effect = yes
		}
	}

	option = {
		trigger = { exists = scope:marshal }
		name = councillor_spouse_learning.2603.b
		
		scope:marshal = {
			add_character_modifier = {
				modifier = studying_martial
				years = 15
			}
			councillor_spouse_learning_2603_chosen_councillor_effect = yes
		}
	}

	option = {
		trigger = { exists = scope:steward }
		name = councillor_spouse_learning.2603.c
		
		scope:steward = {
			add_character_modifier = {
				modifier = studying_stewardship
				years = 15
			}
			councillor_spouse_learning_2603_chosen_councillor_effect = yes
		}
	}

	option = {
		trigger = { exists = scope:spymaster }
		name = councillor_spouse_learning.2603.d
		
		scope:spymaster = {
			add_character_modifier = {
				modifier = studying_intrigue
				years = 15
			}
			councillor_spouse_learning_2603_chosen_councillor_effect = yes
		}
	}

	option = {
		trigger = { exists = scope:court_chaplain }
		name = councillor_spouse_learning.2603.e
		
		scope:court_chaplain = {
			add_character_modifier = {
				modifier = studying_learning
				years = 15
			}
			councillor_spouse_learning_2603_chosen_councillor_effect = yes
		}
	}

	#Opt out
	option = {
		name = councillor_spouse_learning.2603.f

		reverse_add_opinion = {
			modifier = romance_opinion
			opinion = 20
			target = scope:councillor
		}

		had_sex_with_effect = {
			CHARACTER = scope:councillor
			PREGNANCY_CHANCE = pregnancy_chance
		}

		hidden_effect = {
			add_opinion = {
				modifier = romance_opinion
				opinion = 20
				target = scope:councillor
			}
		}
	}
}








