﻿
namespace = yearly

# yearly.4001 - A powerful vassal has angered neighboring ruler
# yearly.4011 - Heir is spending a lot of time with one of your powerful vassals
# yearly.4021 - Mamaaaa, just killed a child
# yearly.4022 - The child has been released from prison. Better watch out!
# yearly.4031 - Who keeps leaving dead bodies all around the castle?!
# yearly.4051 - Get a gift from a neighboring ruler
# yearly.4061 - A wise man visits your court
# yearly.4071 - You're very educated!
# yearly.4081 - Sponsor the translation of a book from Greek
# yearly.4091 - Your ward and you visit scholars
# by Linnéa Thimrén
#yearly.4095 - Congestion in the Capitol
#######################


#######################
# A powerful vassal has angered neighboring ruler
# by Linnéa Thimrén
#######################

scripted_trigger yearly_4001_neighboring_ruler_trigger = {
	basic_is_available_ai = yes
	NOT = { is_at_war_with = root } 
	is_adult = yes
	save_temporary_scope_as = neighboring_ruler_temp
	OR = {
		any_relation = {
			type = rival
			is_in_list = potential_vassal
		}
		any_known_secret = {
			secret_owner = { is_in_list = potential_vassal }
			OR = {
				secret_type = secret_lover
				secret_type = secret_murder
			}
			secret_target = {
				is_close_or_extended_family_of = scope:neighboring_ruler_temp
				reverse_opinion = {
					target = scope:neighboring_ruler_temp
					value <= neutral_opinion
				}
			}
		}
		any_in_list = {
			list = potential_vassal
			reverse_has_opinion_modifier = {
				modifier = declared_war
				target = prev
			}
		}
		any_in_list = {
			list = potential_vassal
			reverse_has_opinion_modifier = {
				modifier = rejected_call_to_defensive_war
				target = prev
			}
		}
	}
}

scripted_trigger yearly_4001_vassal_trigger = {
	is_adult = yes
	OR = {
		any_relation = {
			type = rival
			this = scope:neighboring_ruler
		}
		any_secret = {
			OR = {
				secret_type = secret_lover
				secret_type = secret_murder
			}
			scope:neighboring_ruler = {
				is_close_or_extended_family_of = prev.secret_target
			}
			prev = {
				reverse_opinion = {
					target = scope:neighboring_ruler
					value <= neutral_opinion
				}
			}
		}
		reverse_has_opinion_modifier = {
			modifier = declared_war
			target = scope:neighboring_ruler
		}
		reverse_has_opinion_modifier = {
			modifier = rejected_call_to_defensive_war
			target = scope:neighboring_ruler
		}
	}
}

yearly.4001 = {
	type = letter_event
	opening = {
		desc = yearly.4001.opening
	}
	desc = {
		desc = yearly.4001.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:opinion
				}
				desc = yearly.4001.desc_opinion
			}
			triggered_desc = {
				trigger = {
					exists = scope:lover
				}
				desc = yearly.4001.desc_lover
			}
			triggered_desc = {
				trigger = {
					exists = scope:murder
				}
				desc = yearly.4001.desc_murder
			}
		}
		first_valid = {
			triggered_desc = {
				trigger = { #Are they a rival of yours?
					has_relation_rival = scope:neighboring_ruler
				}
				desc = yearly.4001.desc_rival
			}
			desc = yearly.4001.desc_end
		}
	}
	sender = {
		character = scope:neighboring_ruler
		animation = anger
	}
	
	trigger = {
		NOT = { has_character_flag = had_event_yearly_4001 }
		is_ai = no
		any_vassal = {
			is_adult = yes
			is_powerful_vassal = yes
			basic_is_available_ai = yes
			add_to_temporary_list = potential_vassal
		}
		any_neighboring_top_liege_realm_owner = {
			OR = {
				yearly_4001_neighboring_ruler_trigger = yes
				any_in_list = {
					list = potential_vassal
					number_of_opposing_personality_traits = {
						target = prev
						value >= 1
					}
				}
				any_in_list = {
					list = potential_vassal
					opinion = {
						target = prev
						value <= neutral_opinion
					}
				}
			}
		}
	}

	weight_multiplier = {
		base = 0.75
		modifier = {
			add = 0.5
			any_neighboring_top_liege_realm_owner = {
				any_relation = {
					type = rival
					is_vassal_of = root
				}
			}
		}
	}

	immediate = {
		add_character_flag = {
			flag = had_event_yearly_4001
			days = 3650
		}
		every_vassal = {
			limit = {
				is_adult = yes
				is_powerful_vassal = yes
				basic_is_available_ai = yes
			}
			add_to_list = potential_vassal
		}
		if = {
			limit = {
				any_neighboring_top_liege_realm_owner = {
					yearly_4001_neighboring_ruler_trigger = yes
				}
			}
			random_neighboring_top_liege_realm_owner = {
				limit = {
					yearly_4001_neighboring_ruler_trigger = yes
				}
				save_scope_as = neighboring_ruler
			}
			random_in_list = {
				list = potential_vassal
				limit = {
					yearly_4001_vassal_trigger = yes
				}
				save_scope_as = vassal
			}
			hidden_effect = {
				scope:vassal = {
					reverse_add_opinion = {
						target = scope:neighboring_ruler
						modifier = insult_opinion
						opinion = medium_negative_opinion
					}
				}
			}
			save_scope_value_as = {
				name = opinion
				value = yes
			}
		}
		else = {
			random_in_list = {
				list = potential_vassal
				weight = {
					base = 1
					ai_value_modifier = {
						ai_vengefulness = 0.5
						ai_compassion = -0.5
						ai_honor = -0.25
					}
				}
				save_scope_as = vassal
			}
			random_neighboring_top_liege_realm_owner = {
				limit = {
					NOT = { is_at_war_with = root } 
					is_adult = yes
					basic_is_available_ai = yes
					number_of_opposing_personality_traits = {
						target = scope:vassal
						value >= 1
					}
					opinion = {
						target = scope:vassal
						value <= neutral_opinion
					}
				}
				alternative_limit = {
					basic_is_available_ai = yes
					opinion = {
						target = scope:vassal
						value <= neutral_opinion
					}
				}
				alternative_limit = {
					basic_is_available_ai = yes
				}
				weight = {
					base = 1
					modifier = {
						add = 1
						OR = {
							has_relation_potential_rival = root
							has_relation_rival = root
						}
					}
				}
				save_scope_as = neighboring_ruler
			}
			hidden_effect = { #To give them something to hate each other over
				random_list = {
					10 = { #Rivalry
						scope:vassal = {
							set_relation_rival = {
								target = scope:neighboring_ruler
								reason = rival_grave_insult
							}
							reverse_add_opinion = {
								target = scope:neighboring_ruler
								modifier = insult_opinion
								opinion = medium_negative_opinion
							}
						}
						save_scope_value_as = {
							name = opinion
							value = yes
						}
					}
					10 = { #Lover
						trigger = {
							scope:neighboring_ruler = {
								any_close_family_member = {
									is_ai = yes
									is_adult = yes
									AND = {
										is_attracted_to_gender_of = scope:vassal
										save_temporary_scope_as = attraction_check
										scope:vassal = {
											is_attracted_to_gender_of = scope:attraction_check
										}
									}
									NOR = {
										has_relation_lover = scope:vassal
										has_trait = chaste
										has_trait = celibate 
									}
								}
							}
						}
						scope:neighboring_ruler = {
							random_close_family_member = {
								limit = {
									is_ai = yes
									can_set_relation_lover_trigger = { CHARACTER = scope:neighboring_ruler }
									NOR = {
										any_relation = { type = lover }
										has_trait = chaste
										has_trait = celibate 
									}
								}
								save_scope_value_as = {
									name = lover
									value = yes
								}
								save_scope_as = neighboring_ruler_secondary
								set_random_lover_reason = { TARGET = scope:vassal }
								scope:vassal = {
									random_secret = {
										type = secret_lover
										limit = {
											secret_target = scope:neighboring_ruler_secondary
										}
										reveal_to = root
									}
								}
							}
						}
					}
					2 = { #Murdered relative
						trigger = {
							scope:neighboring_ruler = {
								any_close_or_extended_family_member = {
									is_ai = yes
									age >= 14
									has_any_good_relationship_with_root_trigger = no
									has_any_bad_relationship_with_root_trigger = no
								}
							}
						}
						modifier = {
							add = 5
							scope:vassal = {
								has_trait = drunkard
							}
						}
						modifier = {
							add = 5
							scope:vassal = {
								has_trait = wrathful
							}
						}
						modifier = {
							add = 5
							scope:vassal = {
								dread_modified_ai_boldness = {
									dreaded_character = scope:neighboring_ruler
									value > 0
								}
							}
						}
						scope:neighboring_ruler = {
							random_close_or_extended_family_member = {
								limit = {
									is_ai = yes
									age >= 14
									has_any_good_relationship_with_root_trigger = no
									has_any_bad_relationship_with_root_trigger = no
								}
								save_scope_as = neighboring_ruler_secondary
								save_scope_value_as = {
									name = murder
									value = yes
								}
								death = {
									killer = scope:vassal
									death_reason = death_fight
								}
							}
						}
					}
				}
			}
		}
		#To show the right tooltip:
		show_as_tooltip = {
			if = {
				limit = {
					exists = scope:opinion
				}
				scope:vassal = {
					reverse_add_opinion = {
						target = scope:neighboring_ruler
						modifier = insult_opinion
						opinion = medium_negative_opinion
					}
				}
			}
			else_if = {
				limit = {
					exists = scope:lover
				}
				scope:vassal = {
					random_secret = {
						type = secret_lover
						limit = {
							secret_target = scope:neighboring_ruler_secondary
						}
						reveal_to = root
					}
				}
			}
			else_if = {
				limit = {
					exists = scope:murder
				}
				scope:neighboring_ruler_secondary = {
					death = {
						killer = scope:vassal
						death_reason = death_murder
					}
				}
			}
		}
		hidden_effect = {
			scope:vassal = { #Add the neighboring ruler as a potential rival for the vassal if they're not already at that stage
				if = {
					limit = {
						can_set_relation_potential_rival_trigger = { CHARACTER = scope:neighboring_ruler }
					}
					set_relation_potential_rival = scope:neighboring_ruler
				}
			}
		}
	}

	option = { #Here, have some money
		name = yearly.4001.a
		trigger = {
			gold >= minor_gold_value_check
		}
		pay_short_term_gold = {
			target = scope:neighboring_ruler
			gold = minor_gold_value
		}
		add_prestige = minor_prestige_loss
		if = {
			limit = {
				scope:neighboring_ruler = {
					has_trait = greedy
				}
			}
			scope:neighboring_ruler = {
				add_opinion = {
					target = root
					modifier = pleased_opinion
					opinion = 20
				}
			}
		}
		else = {
			scope:neighboring_ruler = {
				add_opinion = {
					target = root
					modifier = pleased_opinion
					opinion = 15
				}
			}
		}
		scope:vassal = {
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 10
			}
		}
		hidden_effect = {
			if = { #The vassal might continue to cause you trouble!
				limit = {
					can_set_relation_potential_rival_trigger = { CHARACTER = scope:vassal }
				}
				set_relation_potential_rival = scope:vassal
			}
		}
		stress_impact = {
			greedy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = 0.5
				ai_greed = -0.25
			}
		}
	}

	option = { #Vassal will ask for forgiveness publicly
		name = yearly.4001.b
		scope:neighboring_ruler = {
			add_opinion = {
				target = root
				modifier = pleased_opinion
				opinion = low_positive_opinion
			}
		}
		scope:vassal = {
			add_opinion = {
				target = root
				modifier = insult_opinion
				opinion = low_negative_opinion
			}
			add_prestige = medium_prestige_loss
		}
		hidden_effect = {
			if = { #The vassal might continue to cause you trouble!
				limit = {
					can_set_relation_potential_rival_trigger = { CHARACTER = scope:vassal }
				}
				set_relation_potential_rival = scope:vassal
			}
		}
		stress_impact = {
			arbitrary = minor_stress_impact_gain
			just = minor_stress_impact_loss
		}
		ai_chance = {
			base = 40
			ai_value_modifier = {
				ai_compassion = 0.25
				ai_honor = 0.5
			}
		}
	}
	
	option = { #Back up your vassal
		name = yearly.4001.c
		scope:neighboring_ruler = {
			add_opinion = {
				target = root
				modifier = respect_opinion
				opinion = -30
			}
		}
		if = { #If the neighboring ruler is a rival of yours you gain a friend
			limit = {
				has_relation_rival = scope:neighboring_ruler
			}
			if = { #The enemy of my enemy...
				limit = {
					can_set_relation_friend_trigger = { CHARACTER = scope:vassal }
				}
				set_relation_friend = { reason = friend_insulted_rival target = scope:vassal involved_character = scope:neighboring_ruler }
			}
		}
		else = { #If they don't become your friend you get an opinion boost!
			scope:vassal = {
				add_opinion = {
					target = root
					modifier = grateful_opinion
					opinion = 25
				}
			}
		}
		stress_impact = {
			just = minor_stress_impact_gain
			arbitrary = minor_stress_impact_loss
		}
		ai_chance = {
			base = 5
			modifier = {
				add = 100
				has_relation_rival = scope:neighboring_ruler
			}
			modifier = {
				add = 75
				has_relation_potential_rival = scope:neighboring_ruler
			}
			ai_value_modifier = {
				ai_boldness = 0.25
			}
		}
	}
}



#######################
# Heir is spending a lot of time with one of your powerful vassals
# by Linnéa Thimrén
#######################

scripted_trigger yearly_4011_vassal_trigger = {
	basic_is_available_ai = yes
	is_powerful_vassal = yes
	is_adult = yes
	NOR = {
		is_player_heir_of = root
		is_close_or_extended_family_of = root.player_heir
		has_relation_lover = root
		has_relation_friend = root
		any_scheme = {
			type = murder
			scheme_target_character = root
		}
	}
	opinion = {
		target = root.player_heir
		value >= neutral_opinion
	}
	opinion = {
		target = root
		value <= neutral_opinion
	}
	OR = {
		can_start_scheme = {
			type = murder
			target_character = root
		}
		root.player_heir = {
			can_start_scheme = {
				type = murder
				target_character = root
			}
		}
	}
}

scripted_trigger yearly_4011_potential_plot_conditions_trigger = {
	scope:heir = {
		is_ai = yes
	}
	scope:vassal = {
		is_ai = yes
	}
	NOR = {
		scope:heir = {
			is_scheming_against = { target = root type = murder }
		}
		scope:vassal = {
			is_scheming_against = { target = root type = murder }
		}
	}
	OR = {
		scope:heir = {
			can_start_scheme = {
				type = murder
				target_character = root
			}
		}
		scope:vassal = {
			can_start_scheme = {
				type = murder
				target_character = root
			}
		}
	}
}

yearly.4011 = {
	type = character_event
	title = yearly.4011.t
	desc = yearly.4011.desc
	theme = vassal
	left_portrait = scope:heir
	right_portrait = scope:vassal
	
	trigger = {
		player_heir ?= {
			basic_is_available_ai = yes
			is_adult = yes
			NOT = {
				any_scheme = {
					type = murder
					scheme_target_character = root
				}
			}
		}
		any_vassal = {
			yearly_4011_vassal_trigger = yes
		}
	}

	immediate = {
		player_heir = {
			save_scope_as = heir
		}
		random_vassal = {
			limit ={
				yearly_4011_vassal_trigger = yes
			}
			save_scope_as = vassal
		}
		#What are they up to?
		hidden_effect = {
			random_list = {
				40 = { #friends
					save_scope_value_as = {
						name = friends
						value = yes
					}
				}
				20 = { #lovers
					save_scope_value_as = {
						name = lovers
						value = yes
					}
					modifier = {
						add = 10
						scope:heir = {
							has_trait = lustful
						}
					}
					modifier = {
						add = 10
						scope:vassal = {
							has_trait = lustful
						}
					}
					modifier = {
						add = 100
						scope:heir = {
							has_relation_potential_lover = scope:vassal
						}
					}
					modifier = { #If none of them are lustful this can't happen if they're not into the other's gender
						add = -20
						NOT = {
							scope:heir = {
								is_attracted_to_gender_of = scope:vassal
							}
							scope:vassal = {
								is_attracted_to_gender_of = scope:heir
							}
						}
					}
				}
				10 = { #murder
					trigger = {
						yearly_4011_potential_plot_conditions_trigger = yes
					}
					modifier = {
						add = 20
						scope:heir = {
							has_trait = ambitious
						}
					}
					modifier = {
						add = 10
						scope:heir = {
							has_trait = impatient
						}
					}
					modifier = {
						add = 5
						scope:heir = {
							ai_greed >= high_positive_greed
						}
					}
					modifier = {
						add = 10
						scope:vassal = {
							has_trait = ambitious
						}
					}
					#How brave are they?
					modifier = {
						add = 10
						scope:heir = {
							dread_modified_ai_boldness = {
								dreaded_character = root
								value >= 0
							}
						}
					}
					modifier = {
						add = 10
						scope:heir = {
							dread_modified_ai_boldness = {
								dreaded_character = root
								value >= 20
							}
						}
					}
					modifier = {
						add = 5
						scope:vassal = {
							dread_modified_ai_boldness = {
								dreaded_character = root
								value >= 0
							}
						}
					}
					#Are they intimidated? Small chance...
					modifier = {
						add = -10
						scope:heir = {
							dread_modified_ai_boldness = {
								dreaded_character = root
								value <= -40
							}
						}
					}
					modifier = {
						add = -5
						scope:vassal = {
							dread_modified_ai_boldness = {
								dreaded_character = root
								value <= -40
							}
						}
					}
					#Are they intimidated? No way then!
					modifier = {
						add = -100
						scope:heir = {
							dread_modified_ai_boldness = {
								dreaded_character = root
								value <= -75
							}
						}
					}
					modifier = {
						add = -50
						scope:vassal = {
							dread_modified_ai_boldness = {
								dreaded_character = root
								value <= -75
							}
						}
					}
					#Less likely the more they like you
					opinion_modifier = {
						who = root
						opinion_target = scope:heir
						multiplier = -0.25
					}
					opinion_modifier = {
						who = root
						opinion_target = scope:vassal
						multiplier = -0.1
					}
					save_scope_value_as = {
						name = murder
						value = yes
					}
				}
			}
		}
	}

	option = { #Encourage them
		name = yearly.4011.a
		if = {
			limit = {
				exists = scope:friends
			}
			trigger_event = {
				id = yearly.4012
				days = { 7 14 }
			}
		}
		else_if = {
			limit = {
				exists = scope:lovers
			}
			trigger_event = {
				id = yearly.4013
				days = { 7 14 }
			}
		}
		else_if = {
			limit = {
				exists = scope:murder
			}
			trigger_event = {
				id = yearly.4014
				days = { 7 14 }
			}
		}
		scope:heir = {
			add_opinion = {
				target = scope:vassal
				modifier = friendliness_opinion
				opinion = 20
			}
		}
		scope:vassal = {
			add_opinion = {
				target = scope:heir
				modifier = friendliness_opinion
				opinion = 20
			}
		}
		stress_impact = {
			callous = medium_stress_impact_gain
			paranoid = medium_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = 0.5
			}
		}
	}

	option = { #Stop this!
		name = yearly.4011.b
		scope:heir = {
			add_opinion = {
				target = root
				modifier = angry_opinion
				opinion = -20
			}
		}
		scope:vassal = {
			add_opinion = {
				target = root
				modifier = angry_opinion
				opinion = -20
			}
		}
		stress_impact = {
			trusting = medium_stress_impact_gain
			paranoid = medium_stress_impact_loss
		}
		ai_chance = {
			base = 40
			ai_value_modifier = {
				ai_boldness = 0.25
			}
			modifier = {
				add = 20
				has_trait = paranoid
			}
			modifier = {
				add = 10
				has_trait = callous
			}
		}
	}
	
	option = { #I want to be part of this...
		name = yearly.4011.c
		duel = {
			skill = diplomacy
			target = scope:heir
			10 = {
				desc = yearly.4011.c.success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 2
				}
				opinion_modifier = {
					opinion_target = root
					who = scope:heir
					multiplier = 0.15
				}
				opinion_modifier = {
					opinion_target = root
					who = scope:vassal
					multiplier = 0.1
				}
				hidden_effect = {
					if = {
						limit = {
							NOR = {
								has_relation_potential_friend = scope:heir
								has_relation_friend = scope:heir
							}
						}
						progress_towards_friend_effect = {
							CHARACTER = scope:heir
							OPINION = 0
							REASON = friend_pleasant_conversation
						}
					}
					if = {
						limit = {
							NOR = {
								has_relation_potential_friend = scope:vassal
								has_relation_friend = scope:vassal
							}
						}
						progress_towards_friend_effect = {
							CHARACTER = scope:vassal
							OPINION = 0
							REASON = friend_pleasant_conversation
						}
					}
				}
				send_interface_toast = {
					left_icon = scope:heir
					right_icon = scope:vassal
					title = yearly.4011.c.toast.success

					scope:heir = {
						add_opinion = {
							target = root
							modifier = friendliness_opinion
							opinion = 10
						}
					}
					scope:vassal = {
						add_opinion = {
							target = root
							modifier = friendliness_opinion
							opinion = 10
						}
					}
				}
			}
			15 = {
				desc = yearly.4011.c.failure
				send_interface_toast = {
					left_icon = scope:heir
					right_icon = scope:vassal
					title = yearly.4011.c.toast.failure

					add_prestige = minor_prestige_loss
					scope:heir = {
						add_opinion = {
							target = root
							modifier = respect_opinion
							opinion = -10
						}
					}
					scope:vassal = {
						add_opinion = {
							target = root
							modifier = respect_opinion
							opinion = -10
						}
					}
				}
			}
		}
		ai_chance = {
			base = 10
			modifier = {
				add = 20
				has_trait = gregarious
			}
			modifier = { #They're lonely :(
				add = 75
				num_of_relation_friend <= 0
			}
		}
	}
}

#friends
yearly.4012 = {
	hidden = yes

	trigger = { #To make sure that nothing has changed since the last event
		scope:heir = {
			is_alive = yes
			NOT = {
				has_relation_friend = scope:vassal
			}
		}
		scope:vassal = {
			is_alive = yes
		}
	}

	immediate = {
		scope:heir = {
			set_relation_friend = { reason = friend_common_ground target = scope:vassal }
		}
	}
}

#lovers
yearly.4013 = {
	hidden = yes

	trigger = { #To make sure that nothing has changed since the last event
		scope:heir = {
			is_alive = yes
			can_set_relation_lover_trigger = { CHARACTER = scope:vassal }
		}
		scope:vassal = {
			is_alive = yes
		}
	}

	immediate = {
		scope:heir = {
			set_relation_lover = { reason = lover_encouraged target = scope:vassal involved_character = root }
		}
	}
}

#murder!!
yearly.4014 = {
	hidden = yes

	trigger = { #To make sure that nothing has changed since the last event
		scope:vassal = {
			is_alive = yes
		}
		scope:heir = {
			is_alive = yes
		}
		yearly_4011_potential_plot_conditions_trigger = yes
	}

	immediate = {
		if = {
			limit = {
				scope:vassal = {
					can_start_scheme = {
						type = murder
						target_character = root
					}
				}
			}
			scope:vassal = {
				start_scheme = {
					type = murder
					target_character = root
				}
				random_scheme = {
					type = murder
					limit = {
						scheme_target_character = root
					}
					save_scope_as = murder_friends_scheme
				}
			}
			scope:heir = {
				if = {
					limit = {
						scope:murder_friends_scheme = {
							NOT = { scheme_is_character_agent = prev }
						}
						char_can_fit_into_scheme_trigger = { SCHEME = scope:murder_friends_scheme }
					}
					force_assign_character_to_random_agent_slot_effect = {
						SCHEME = scope:murder_friends_scheme
						CHAR = scope:heir
						YEARS = 5
					}
				}
			}
		}
		else_if = {
			limit = {
				scope:heir = {
					can_start_scheme = {
						type = murder
						target_character = root
					}
				}
			}
			scope:heir = {
				start_scheme = {
					type = murder
					target_character = root
				}
				random_scheme = {
					type = murder
					limit = {
						scheme_target_character = root
					}
					save_scope_as = murder_friends_scheme
				}
			}
			scope:vassal = {
				if = {
					limit = {
						scope:murder_friends_scheme = {
							NOT = { scheme_is_character_agent = prev }
						}
						char_can_fit_into_scheme_trigger = { SCHEME = scope:murder_friends_scheme }
					}
					force_assign_character_to_random_agent_slot_effect = {
						SCHEME = scope:murder_friends_scheme
						CHAR = scope:vassal
						YEARS = 5
					}
				}
			}
		}
		scope:murder_friends_scheme = {
			add_scheme_progress = scheme_progress_gain
		}
	}
}


#######################
# Mamaaaa, just killed a child
# by Linnéa Thimrén
#######################

scripted_trigger yearly_4021_basic_child_trigger = {
	is_adult = no
	age >= 4
	basic_is_available_ai = yes
}

yearly.4021 = {
	type = character_event
	title = yearly.4021.t
	desc = yearly.4021.desc
	theme = vassal
	left_portrait = scope:child
	right_portrait = scope:vassal
	lower_right_portrait = scope:vassal_kid
	
	trigger = {
		any_child = {
			yearly_4021_basic_child_trigger = yes
		}
		any_vassal = {
			basic_is_available_ai = yes
			any_child = {
				yearly_4021_basic_child_trigger = yes
				NOT = {
					any_parent = { this = root }
				}
			}
		}
	}

	weight_multiplier = {
		base = 0.5
		modifier = {
			add = 0.5
			any_child = {
				yearly_4021_basic_child_trigger = yes
				has_personality_malicious_trigger = yes
			}
		}
		modifier = {
			add = 0.5
			any_child = {
				yearly_4021_basic_child_trigger = yes
				has_trait = sadistic
			}
		}
	}

	immediate = {
		random_child = {
			limit = {
				yearly_4021_basic_child_trigger = yes
				has_trait = sadistic
			}
			alternative_limit = {
				yearly_4021_basic_child_trigger = yes
				has_personality_malicious_trigger = yes
			}
			alternative_limit = {
				yearly_4021_basic_child_trigger = yes
			}
			weight = {
				base = 1
				modifier = {
					add = 4
					is_player_heir_of = root
				}
			}
			save_scope_as = child
			if = {
				limit = {
					has_personality_malicious_trigger = no
				}
				stress_impact = {
					base = medium_stress_impact_gain
				}
			}
		}
		random_vassal = {
			limit = {
				basic_is_available_ai = yes
				any_child = {
					yearly_4021_basic_child_trigger = yes
					NOT = {
						any_parent = { this = root }
					}
				}
			}
			weight = {
				base = 1
				modifier = {
					add = 4
					is_powerful_vassal = yes
				}
			}
			save_scope_as = vassal
			add_opinion = {
				target = scope:child
				modifier = reason_child_died
			}
			random_child = {
				limit = {
					yearly_4021_basic_child_trigger = yes
					NOT = {
						any_parent = { this = root }
					}
				}
				save_scope_as = vassal_kid
				death = {
					death_reason = death_accident
				}
			}
			#They will not be happy with your kid
			if = {
				limit = {
					NOT = {
						has_relation_rival = scope:child
					}
				}
				hidden_effect = {
					set_relation_rival = {
						target = scope:child
						reason = rival_roughed_up_child
						involved_character = scope:vassal_kid
					}
				}
			}
		}
	}

	option = { #Don't touch my kid!
		name = yearly.4021.a
		scope:vassal = {
			add_opinion = {
				target = root
				modifier = respect_opinion
				opinion = low_negative_opinion
			}
		}
		#This vassal will not be happy with you...
		progress_towards_rival_effect = { 
			REASON = rival_dead_child
			CHARACTER = scope:vassal 
			OPINION = 0
		}
		
		hidden_effect = { #It's more likely that the kid turns into a sadist if they face no consequences!
			scope:child = {
				random_list = {
					7 = {
						ai_value_modifier = {
							ai_compassion = 0.75
						}
					}
					10 = {
						trigger ={
							number_of_personality_traits < personality_trait_limit
							NOT = { has_trait = sadistic }
						}
						modifier = {
							add = 10
							has_personality_malicious_trigger = yes
						}
						modifier = {
							add = 10
							any_relation = {
								type = guardian
								has_trait = sadistic
							}
						}
						add_character_flag = {
							flag = marked_for_sadistic_in_yearly_4021
							days = 365
						}
						trigger_event = { #Make them sadistic
							id = child_personality.0010
							days = { 14 30 }
						}
					}
				}
			}
		}
		ai_chance = {
			base = 75
			ai_value_modifier = {
				ai_boldness = 0.25
			}
			opinion_modifier = {
				opinion_target = scope:vassal
				multiplier = -0.15
			}
		}
	}

	option = { #Hand over your child
		name = yearly.4021.b
		scope:vassal = {
			imprison = {
				target = scope:child
				type = dungeon
			}
		}
		scope:vassal = {
			add_opinion = {
				target = root
				modifier = respect_opinion
				opinion = low_positive_opinion
			}
		}
		hidden_effect = { #The kid will be out to get you if they get out
			scope:child = {
				random_list = {
					10 = {
						ai_value_modifier = {
							ai_compassion = 0.5
						}
					}
					15 = {
						trigger ={
							OR = {
								AND = {
									number_of_personality_traits < personality_trait_limit
									NOT = { has_trait = sadistic }
								}
								has_trait = sadistic
							}
						}
						modifier = {
							add = 10
							has_personality_malicious_trigger = yes
						}
						modifier = {
							add = 10
							any_relation = {
								type = guardian
								has_trait = sadistic
							}
						}
						set_variable = {
							name = marked_for_revenge_in_event_yearly_4021
							value = root
							days = 7300
						}
					}
				}
			}
		}
		stress_impact = {
			arbitrary = medium_stress_impact_gain
			just = medium_stress_impact_loss
		}
		ai_chance = {
			base = 5
			ai_value_modifier = {
				ai_honor = 0.3
				ai_rationality = 0.15
			}
			modifier = {
				add = 10
				dread_modified_ai_boldness = { #Am I scared of this vassal?
					dreaded_character = scope:vassal
					value <= 0
				}
			}
			modifier = {
				add = 20
				dread_modified_ai_boldness = { #Am I very scared of this vassal?
					dreaded_character = scope:vassal
					value <= -40
				}
			}
			modifier = {
				add = 50
				dread_modified_ai_boldness = { #Am I VERY scared of this vassal?
					dreaded_character = scope:vassal
					value <= -75
				}
			}
		}
	}
	
	option = { #Discipline the child yourself
		name = yearly.4021.c
		random_list = {
			15 = { #they listen and learn
				desc = yearly.4021.c_success
				modifier = {
					add = 20
					has_trait = compassionate
				}
				modifier = {
					add = 10
					has_trait = just
				}
				ai_value_modifier = {
					ai_compassion = 0.30
				}
				scope:child = {
					if = {
						limit = {
							number_of_personality_traits < personality_trait_limit
						}
						if = {
							limit = {
								has_trait = sadistic
							}
							remove_trait = sadistic
						}
						else_if = {
							limit = {
								has_trait = callous
							}
							remove_trait = callous
						}
						else_if = {
							limit = {
								NOT = { has_trait = compassionate }
							}
							add_trait = compassionate
						}
						else_if = {
							limit = {
								NOT = { has_trait = just }
							}
							add_trait = just
						}
						else = { #If they have all the traits
							add_diplomacy_skill = 1
						}
					}
					else = {
						add_diplomacy_skill = 1
					}
				}
			}
			10 = { #they continue down their wicked path
				desc = yearly.4021.c_failure
				modifier = {
					add = 20
					has_trait = sadistic
				}
				modifier = {
					add = 10
					has_trait = callous
				}
				scope:child = {
					if = {
						limit = {
							number_of_personality_traits < personality_trait_limit
						}
						if = {
							limit = {
								has_trait = compassionate
							}
							remove_trait = compassionate
						}
						else_if = {
							limit = {
								NOT = { has_trait = sadistic }
							}
							add_trait = sadistic
						}
						else_if = {
							limit = {
								NOT = { has_trait = callous }
							}
							add_trait = callous
						}
						else_if = {
							limit = {
								has_trait = just
							}
							remove_trait = just
						}
						else = { #If they have all the traits
							add_diplomacy_skill = 1
						}
					}
					else = {
						add_diplomacy_skill = -1
					}
				}
			}
		}
		add_prestige = medium_prestige_loss
		scope:vassal = {
			add_opinion = {
				target = root
				modifier = respect_opinion
				opinion = -10
			}
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_rationality = 0.3
				ai_energy = 0.1
			}
		}
	}

	option = { #Have a favor and shut up.
		name = yearly.4021.d
		trigger = {
			scope:vassal = {
				can_add_hook = {
					type = favor_hook
					target = root
				}
			}
		}
		scope:vassal = {
			add_hook = {
				type = favor_hook
				target = root
			}
		}
		hidden_effect = {
			if = {
				limit = {
					is_ai = no
					NOT = {
						has_character_flag = had_murderer_at_court_story_cycle
					}
				}
				random = {
					chance = 75
					#To start story about finding dead people around your house
					add_character_flag = {
						flag = child_as_murderer
						days = 3
					}
					set_variable = {
						name = murderer_to_save
						value = scope:child
						days = 3
					}
					create_story = story_cycle_murders_at_court
				}
			}
		}
		stress_impact = {
			just = medium_stress_impact_gain
			arbitrary = medium_stress_impact_loss
		}
		ai_chance = {
			base = 0
			ai_value_modifier = {
				ai_rationality = 0.3
			}
			modifier = {
				add = 20
				dread_modified_ai_boldness = { #Am I scared of this vassal?
					dreaded_character = scope:vassal
					value <= 0
				}
			}
		}
	}
}

#The child has been released from prison. Better watch out!
yearly.4022 = {
	type = character_event
	title = yearly.4022.t
	desc = yearly.4022.desc
	theme = unfriendly
	left_portrait = {
		character = scope:child
		animation = personality_vengeful
	}

	trigger = {
		#Blocking for landless adventurer/administrative
		OR = {
			is_landless_adventurer = no
			is_landless_administrative = no
		}	
	}

	immediate = {
		scope:child = {
			if = {
				limit = { root = { is_ai = no }	}
				assign_quirk_effect = yes
			}
			show_as_tooltip = {
				release_from_prison = yes
			}
		}
	}

	option = {
		name = yearly.4022.a
		scope:child = {
			set_relation_rival = {
				target= root
				reason = rival_was_imprisoned_by_parent
			}
			#To start story about finding dead people around your house
			if = {
				limit = {
					root = {
						is_ai = no
						NOT = {
							has_character_flag = had_murderer_at_court_story_cycle
						}
					}
				}
				root = {
					add_character_flag = {
						flag = child_as_murderer
						days = 3
					}
					set_variable = {
						name = murderer_to_save
						value = scope:child
						days = 3
					}
					create_story = story_cycle_murders_at_court
				}
			}
		}
	}
}


#######################
# Who keeps leaving dead bodies all around the castle?!
# by Linnéa Thimrén
#######################

scripted_trigger yearly_4031_basic_check_trigger = {
	is_ai = yes
	is_available = yes
	is_physically_able_adult = yes
}

scripted_trigger yearly_4031_courtier_trigger = {
	yearly_4031_basic_check_trigger = yes
	OR = {
		is_of_major_interest_to_root_trigger = yes
		is_of_minor_interest_to_root_trigger = yes
		is_cannibal_trigger = yes
		AND = {
			faith = { NOT = { has_doctrine_parameter = witchcraft_accepted } }
			is_witch_trigger = yes
		}
	}
}

scripted_trigger yearly_4031_murderous_trigger = {
	OR = {
		has_trait = sadistic
		has_trait = callous
		has_trait = murderer
		any_secret = {
			type = secret_murder
		}
	}
}

yearly.4031 = {
	type = character_event
	title = yearly.4031.t
	desc = {
		desc = yearly.4031.desc_opening
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:physician
				}
				desc = yearly.4031.desc_physician
			}
			desc = yearly.4031.desc
		}
	}
	left_portrait = root
	right_portrait = scope:physician
	theme = death
	
	trigger = {
		NOT = { has_character_flag = had_event_yearly_4031 }
		is_landed = yes # Thematically landed
		OR = {
			any_owned_story = {
				type = story_cycle_murders_at_court
			}
			AND = {
				player_heir ?= {
					yearly_4031_basic_check_trigger = yes
				}
			}
			any_relation = {
				type = rival
				yearly_4031_basic_check_trigger = yes
			}
			any_courtier = {
				yearly_4031_courtier_trigger = yes
			}
		}
	}

	weight_multiplier = {
		base = 1
		modifier = { #More likely if they've already shown these tendencies
			add = 1.5
			AND = {
				player_heir ?= {
					yearly_4031_basic_check_trigger = yes
					has_personality_malicious_trigger = yes
				}
			}
		}
		modifier = { #More likely if they're at the same court
			add = 1.5
			AND = {
				player_heir ?= {
					yearly_4031_basic_check_trigger = yes
					is_in_the_same_court_as = root
				}
			}
		}
		modifier = { #More likely if they're at the same court
			add = 1
			any_relation = {
				type = rival
				yearly_4031_basic_check_trigger = yes
				is_in_the_same_court_as = root
			}
		}
	}

	immediate = {
		add_character_flag = {
			flag = had_event_yearly_4031
			years = 20
		}
		if = {
			limit = {
				any_owned_story = {
					type = story_cycle_murders_at_court
					var:murderer = {
						is_alive = yes
					}
				}
			}
			random_owned_story = {
				type = story_cycle_murders_at_court
				limit = {
					var:murderer = {
						is_alive = yes
					}
				}
				var:murderer = {
					save_scope_as = murderer
				}
			}
		}
		else = {
			hidden_effect = {
				random_list = {
					40 = {
						trigger = {
							player_heir ?= {
								yearly_4031_basic_check_trigger = yes
							}
						}
						modifier = {
							add = 50
							player_heir = {
								yearly_4031_murderous_trigger = yes
							}
						}
						player_heir = {
							save_scope_as = murderer
						}
					}
					40 = {
						trigger ={
							any_relation = {
								type = nemesis
								yearly_4031_basic_check_trigger = yes
							}
						}
						random_relation = {
							type = nemesis
							weight = {
								base = 1
								modifier = {
									add = 60
									is_in_the_same_court_as = root
								}
								modifier = {
									add = 40
									has_trait = sadistic
								}
							}
							save_scope_as = murderer
						}
					}
					20 = {
						trigger = {
							any_courtier = {
								yearly_4031_courtier_trigger = yes
							}
						}
						modifier = {
							add = 60
							any_courtier = {
								yearly_4031_courtier_trigger = yes
								yearly_4031_murderous_trigger = yes
							}
						}
						random_courtier = {
							limit = {
								yearly_4031_courtier_trigger = yes
							}
							weight = {
								base = 1
								ai_value_modifier = {
									ai_compassion = -1
								}
								modifier = {
									add = 100
									yearly_4031_murderous_trigger = yes
								}
								modifier = {
									add = 200
									exists = var:2037_rescued_manhunted_prisoner
								}
							}
							save_scope_as = murderer
						}
					}
				}
			}
		}

		#To save the court physician
		save_court_physician_as_effect = { SCOPE_NAME = physician }
	}

	option = { #We will launch an investigation!!
		name = yearly.4031.a
		if = {
			limit = {
				is_ai = no
				NOT = {
					has_character_flag = had_murderer_at_court_story_cycle
				}
			}
			set_variable = {
				name = murderer_to_save
				value = scope:murderer
				days = 3
			}
			create_story = story_cycle_murders_at_court
		}
		custom_tooltip = yearly.4031.tt
		ai_chance = {
			base = 20
			modifier = {
				factor = 0
				has_trait = arbitrary
			}
			modifier = {
				factor = 3
				has_trait = just
			}
		}
	}

	option = { # Why should I care?
		name = yearly.4031.b
		every_courtier = {
			custom = yearly.4031.b_every_courtier
			add_opinion = {
				target = root
				modifier = respect_opinion
				opinion = -15
			}
		}
		stress_impact = {
			compassionate = medium_stress_impact_gain
			paranoid = medium_stress_impact_gain
			callous = medium_stress_impact_loss
		}
		ai_chance = {
			base = 10
			modifier = {
				factor = 3
				has_trait = callous
			}
			modifier = {
				factor = 0
				has_trait = just
			}
		}
	}
	
	option = { #You will investigate the bodies
		name = yearly.4031.c
		trigger = {
			exists = scope:physician
		}
		if = {
			limit = {
				is_ai = no
				NOT = {
					has_character_flag = had_murderer_at_court_story_cycle
				}
			}
			set_variable = {
				name = murderer_to_save
				value = scope:murderer
				days = 3
			}
			create_story = story_cycle_murders_at_court
		}
		custom_tooltip = yearly.4031.tt
		ai_chance = {
			base = 60
		}
	}
}





#######################
# Get a gift from a neighboring ruler (triggered here so you can't know for sure if someone has a scheme towards you)
# by Linnéa Thimrén
#######################

yearly.4051 = {
	type = character_event
	title = {
		first_valid = {
			triggered_desc = {
				trigger = {
					has_fp3_dlc_trigger = yes
					culture = { has_cultural_pillar = heritage_iranian }
				}
				desc = intrigue_scheme_ongoing.5014.t_persian
			}
			desc = intrigue_scheme_ongoing.5014.t
		}
	}
	desc = intrigue_scheme_ongoing.5015.desc
	left_portrait = scope:owner
	theme = diplomacy
	
	trigger = {
		NOT = { has_character_flag = had_event_yearly_4051 }
		highest_held_title_tier >= tier_county
		any_neighboring_realm_same_rank_owner = {
			is_ai = yes
			NOR = {
				has_important_relationship_with_root_trigger = yes
				has_any_bad_relationship_with_root_trigger = yes
			}
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = 2
			has_trait = paranoid
		}
	}

	immediate = {
		add_character_flag = {
			flag = had_event_yearly_4051
			days = 3650
		}
		random_neighboring_realm_same_rank_owner = {
			limit = {
				primary_title.tier >= tier_county
				is_ai = yes
				NOR = {
					has_important_relationship_with_root_trigger = yes
					has_any_bad_relationship_with_root_trigger = yes
				}
			}
			save_scope_as = owner
		}
	}

	option = {
		name = intrigue_scheme_ongoing.5015.a
		add_carpet_modifier_effect = yes
			
		ai_chance = {
			base = 1
			ai_value_modifier = {
				ai_compassion = 0.25
			}
			modifier = {
				add = 2
				has_trait = trusting
			}
		}
	}

	option = {
		name = intrigue_scheme_ongoing.5015.b
		add_gold = minor_gold_value
		add_character_modifier = {
			modifier = suspicious_of_carpet_modifier
			days = 3650
		}
		ai_chance = {
			base = 1
			ai_value_modifier = {
				ai_greed = 0.75
			}
			modifier = {
				add = 2
				has_trait = paranoid
			}
		}
	}
}



#######################
# A wise man visits your court
# by Linnéa Thimrén
#######################

yearly.4061 = {
	type = character_event
	title = yearly.4061.t
	desc = {
		desc = yearly.4061.desc_opening
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:guard
				}
				desc = yearly.4061.desc_guard
			}
			desc = yearly.4061.desc
		}
		desc = yearly.4061.desc_ending
	}
	theme = learning
	override_background = {
		reference = throne_room
	}
	left_portrait = scope:hodja
	right_portrait = {
		character = scope:guard
		animation = dismissal
	}
	
	trigger = {
		is_landed = yes # Thematically landed
		faith.religion = religion:islam_religion
		NOT = { has_character_flag = had_event_yearly_4061 }
		NOT = { has_character_modifier = useful_insights_modifier }
	}

	immediate = {
		add_character_flag = {
			flag = had_event_yearly_4061
			years = 10
		}
		create_character = {
			location = root.capital_province
			template = scholar_character
			faith = root.faith
			culture = root.culture
			gender_female_chance = 0
			save_scope_as = hodja
		}
		if = {
			limit = {
				any_knight = {
					is_available_healthy_ai_adult = yes
				}
			}
			random_knight = {
				limit = {
					is_available_healthy_ai_adult = yes
				}
				save_scope_as = guard
			}
		}
	}

	option = { #Teach me!
		name = yearly.4061.a
		random_list = {
			80 = {
				show_chance = no
				desc = yearly.4061.a_success
				send_interface_toast = {
					left_icon = scope:hodja
					title = yearly.4061.a_success

					add_character_modifier = {
						modifier = useful_insights_modifier
						years = 5
					}
				}
			}
			20 = {
				show_chance = no
				desc = yearly.4061.a_failure
				send_interface_toast = {
					left_icon = scope:hodja
					title = yearly.4061.a_failure

					add_character_modifier = {
						modifier = confused_modifier
						years = 5
					}
				}	
			}
		}
		scope:hodja = {
			add_opinion = {
				target = root
				modifier = friendliness_opinion
				opinion = 10
			}
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_honor = 0.5
			}
		}
	}

	option = { #Stay at my court
		name = yearly.4061.b
		scope:hodja = {
			add_opinion = {
				target = root
				modifier = friendliness_opinion
				opinion = 20
			}
		}
		add_courtier = scope:hodja
		ai_chance = {
			base = 50
			modifier = {
				add = 100
				NOT = { exists = cp:councillor_court_chaplain }
			}
		}
	}

	option = { #Go away
		name = yearly.4061.c
		custom_tooltip = yearly.4061.c.tt
		scope:hodja = {
			add_opinion = {
				target = root
				modifier = refusal_opinion
				opinion = -10
			}
		}
		ai_chance = {
			base = 50
		}
	}

	option = { #You're a fool and I will treat you like one
		name = yearly.4061.d
		custom_tooltip = yearly.4061.d.tt
		add_prestige = minor_prestige_gain
		scope:hodja = {
			add_opinion = {
				target = root
				modifier = insult_opinion
				opinion = -20
			}
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_vengefulness = 0.5
			}
		}
	}
}


#######################
# You're very educated!
# by Linnéa Thimrén
#######################

yearly.4071 = {
	type = character_event
	title = yearly.4071.t
	desc = {
		desc = yearly.4071.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					has_any_lifestyle_focus_trigger = yes
				}
				desc = yearly.4071.desc_focus
			}
			desc = yearly.4071.desc_no_focus
		}
		desc = yearly.4071.desc_ending
	}
	theme = learning
	override_background = {
		reference = throne_room
	}
	left_portrait = {
		character = scope:councillor
		animation = happiness
	}
	
	trigger = {
		faith.religion = religion:islam_religion
		OR = {
			exists = cp:councillor_court_chaplain
			employs_court_position = chief_engineer_camp_officer			
		}
		NOT = { has_character_flag = had_event_yearly_4071 }
		learning >= medium_skill_rating
		NOT = { has_character_modifier = useful_insights_modifier }
	}

	weight_multiplier = {
		base = 0.75
		modifier = {
			add = 0.5
			learning >= high_skill_rating
		}
	}

	immediate = {
		add_character_flag = {
			flag = had_event_yearly_4071
			years = 10
		}
		cp:councillor_court_chaplain ?= {
			save_scope_as = councillor
		}
		random_court_position_holder = {
			type = chief_engineer_camp_officer
			save_scope_as = councillor
		}
		
	}

	option = { #Study the books
		name = yearly.4071.a
		add_piety = medium_piety_gain
		add_character_modifier = {
			modifier = useful_insights_modifier
			years = 5
		}
		stress_impact = {
			cynical = medium_stress_impact_gain
		}
		ai_chance = {
			base = 50
			modifier = {
				add = 100
				piety <= 0
			}
			modifier = {
				add = 50
				has_trait = zealous
			}
		}
	}

	option = { #Give books to courtiers
		name = yearly.4071.b
		add_prestige = medium_prestige_gain
		every_courtier = {
			custom = councillor_spouse_stewardship_1006_every_courtier
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 10
			}
		}
		ai_chance = {
			base = 50
			modifier = {
				add = 100
				prestige <= 0
			}
			modifier = {
				add = 50
				has_trait = arrogant
			}
		}
	}
}

scripted_effect create_translated_arabic_book_effect = {
	create_artifact = {
		name = translated_arabic_book_$NAME$_name
		description = translated_arabic_book_$NAME$_desc
		type = journal
		visuals = book
		template = arabic_book_template
		history = {
			location = root.capital_province
			actor = scope:councillor
			recipient = root
			type = given
		}
		modifier = $MODIFIER$
		save_scope_as = book
	}
}

#######################
# Sponsor the translation of a book from Greek
# by Linnéa Thimrén
#######################

yearly.4081 = {
	type = character_event
	title = yearly.4081.t
	desc = yearly.4081.desc
	theme = learning
	override_background = {
		reference = throne_room
	}
	left_portrait = scope:councillor
	
	trigger = {
		faith.religion = religion:islam_religion
		culture = { has_cultural_pillar = language_arabic }
		knows_language = language_arabic
		exists = cp:councillor_court_chaplain
		cp:councillor_court_chaplain = { knows_language = language_arabic }
		NOT = { has_character_flag = had_event_yearly_4081 }
		learning >= medium_skill_rating
		short_term_gold >= medium_gold_value
		trigger_if = {
			limit = { has_ep1_dlc_trigger = yes }
			has_royal_court = yes
		}
	}

	weight_multiplier = {
		base = 0.75
		modifier = {
			add = 0.5
			learning >= high_skill_rating
		}
	}

	immediate = {
		add_character_flag = {
			flag = had_event_yearly_4081
			years = 10
		}
		cp:councillor_court_chaplain = {
			save_scope_as = councillor
		}
		if = {
			limit = {
				court_physician_available_trigger = yes
			}
			save_court_physician_as_effect = { SCOPE_NAME = court_physician }
		}
		while = {
			limit = {
				calc_true_if = {
					amount < 3
					has_variable = arabic_book_1
					has_variable = arabic_book_2
					has_variable = arabic_book_3
					has_variable = arabic_book_4
					has_variable = arabic_book_5
					has_variable = arabic_book_6
				}
			}
			random_list = {
				2 = {
					trigger = { NOT = { has_variable = arabic_book_1 } }
					set_variable = arabic_book_1
				}
				2 = {
					trigger = { NOT = { has_variable = arabic_book_2 } }
					set_variable = arabic_book_2
				}
				2 = {
					trigger = { NOT = { has_variable = arabic_book_3 } }
					set_variable = arabic_book_3
				}
				2 = {
					trigger = { NOT = { has_variable = arabic_book_4 } }
					set_variable = arabic_book_4
				}
				2 = {
					trigger = { NOT = { has_variable = arabic_book_5 } }
					set_variable = arabic_book_5
				}
				2 = {
					trigger = { NOT = { has_variable = arabic_book_6 } }
					set_variable = arabic_book_6
				}
			}
		}
	}

	option = { #De materia Medica - medicine
		name = yearly.4081.a
		custom_tooltip = yearly.4081.a.tt
		trigger = {
			exists = scope:court_physician
			has_variable = arabic_book_1
		}
		remove_short_term_gold = medium_gold_value
		scope:court_physician = {
			physician_lifestyle_rank_up_effect = yes
		}
		create_translated_arabic_book_effect = { NAME = de_materia_medica MODIFIER = artifact_health_gain_1_modifier }
		ai_chance = {
			base = 100
			modifier = {
				add = -100
				scope:court_physician = {
					has_trait = lifestyle_physician
					has_trait_xp = {
						trait = lifestyle_physician
						value >= 100
					}
				}
			}
			modifier = {
				add = 50
				OR = {
					has_treatable_disease_trigger = yes
					any_courtier = {
						has_treatable_disease_trigger = yes
					}
				}
			}
		}
	}

	option = { #On Ascensions - astronomy
		name = yearly.4081.b
		trigger = { has_variable = arabic_book_2 }
		custom_tooltip = yearly.4081.b.tt
		remove_short_term_gold = medium_gold_value
		create_translated_arabic_book_effect = { NAME = on_ascensions MODIFIER = artifact_learning_1_modifier }
		ai_chance = {
			base = 50
		}
	}

	option = { #Elements - math(s!)
		name = yearly.4081.c
		trigger = { has_variable = arabic_book_3 }
		custom_tooltip = yearly.4081.c.tt
		remove_short_term_gold = medium_gold_value
		create_translated_arabic_book_effect = { NAME = elements MODIFIER = artifact_stewardship_1_modifier }
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_greed = 0.75
			}
		}
	}

	option = { #On the Soul - motivations
		name = yearly.4081.e
		trigger = { has_variable = arabic_book_4 }
		custom_tooltip = yearly.4081.e.tt
		remove_short_term_gold = medium_gold_value
		create_translated_arabic_book_effect = { NAME = on_the_soul MODIFIER = artifact_intrigue_1_modifier }
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_honor = -0.75
			}
		}
	}

	option = { #Thucydides - military
		name = yearly.4081.f
		trigger = { has_variable = arabic_book_5 }
		custom_tooltip = yearly.4081.f.tt
		remove_short_term_gold = medium_gold_value
		create_translated_arabic_book_effect = { NAME = thucydides MODIFIER = artifact_martial_1_modifier }
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_energy = 0.75
			}
		}
	}

	option = { #Plutarch - diplomacy
		name = yearly.4081.g
		trigger = { has_variable = arabic_book_6 }
		custom_tooltip = yearly.4081.g.tt
		remove_short_term_gold = medium_gold_value
		create_translated_arabic_book_effect = { NAME = plutarch MODIFIER = artifact_diplomacy_1_modifier }
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = 0.75
			}
		}
	}

	option = { #Nah
		name = yearly.4081.d
		custom_tooltip = yearly.4081.d.tt
		ai_chance = {
			base = 25
		}
	}

	after = {
		if = {
			limit = { exists = scope:book }
			send_interface_toast = {
				left_icon = scope:book
				title = yearly.4081.toast
				scope:book = {
					set_variable = {
						name = suppress_artifact_notifications
						value = yes
						days = 1
					}
					show_as_tooltip = { set_owner = root }
				}
			}
		}
		if = {
			limit = { has_variable = arabic_book_1 }
			remove_variable = arabic_book_1
		}
		if = {
			limit = { has_variable = arabic_book_2 }
			remove_variable = arabic_book_2
		}
		if = {
			limit = { has_variable = arabic_book_3 }
			remove_variable = arabic_book_3
		}
		if = {
			limit = { has_variable = arabic_book_4 }
			remove_variable = arabic_book_4
		}
		if = {
			limit = { has_variable = arabic_book_5 }
			remove_variable = arabic_book_5
		}
		if = {
			limit = { has_variable = arabic_book_6 }
			remove_variable = arabic_book_6
		}
	}
}


#######################
# Your ward and you visit scholars
# by Linnéa Thimrén
#######################

yearly.4091 = {
	type = character_event
	title = yearly.4091.t
	override_background = { reference = market }
	desc = {
		desc = yearly.4091.desc_opening
		first_valid = {
			triggered_desc = {
				trigger = {
					any_realm_province = {
						has_building = house_of_wisdom_01
					}
				}
				desc = yearly.4091.desc_house
			}
			desc = yearly.4091.desc_no_house
		}
		desc = yearly.4091.desc
	}
	theme = learning
	left_portrait = {
		character = scope:ward 
		animation = reading
	}
	right_portrait = {
		character = scope:baghdad_scholar 
		animation = happy_teacher
	}
	
	cooldown = { years = 20 }
	
	trigger = {
		location = title:c_baghdad.title_province
		any_relation = {
			type = ward
			is_available_ai_child = yes
			has_education_focus_trigger = yes
			location = title:c_baghdad.title_province
		}
		title:c_baghdad.holder ?= root
		any_pool_character = {
			province = title:c_baghdad.title_province
			is_available_healthy_ai_adult = yes
			learning >= 8
			has_no_particular_noble_roots_trigger = yes
			can_be_clergy_due_to_gender_trigger = yes
		}
	}

	immediate = {
		random_pool_character = {
			province = title:c_baghdad.title_province
			limit = {
				is_available_healthy_ai_adult = yes
				learning >= 8
				has_no_particular_noble_roots_trigger = yes
				can_be_clergy_due_to_gender_trigger = yes
			}
			save_scope_as = baghdad_scholar
		}
		random_relation = {
			type = ward
			limit = {
				is_available_ai_child = yes
			}
			save_scope_as = ward
		}
		capital_province = {
			save_scope_as = capital
		}
	}

	option = { #Ward learns
		name = yearly.4091.a
		custom_tooltip = yearly.4091.a.tt
		scope:ward = {
			hidden_effect = {
				education_point_acquisition_effect = yes
			}
			add_character_modifier = {
				modifier = diligent_student
				years = 16
			}
		}
		ai_chance = {
			base = 50
		}
	}

	option = { #I'll learn
		name = yearly.4091.b
		add_character_modifier = {
			modifier = diligent_student
			years = 5
		}
		ai_chance = {
			base = 50
		}
	}
}
