# IDs JD.10060-10083
#     JD.60002-60008

namespace = JD

# Written by:
# Matthew Clohessy
# Milla Isaksson

### Events for aquiring Chinese Artifacts ###

# An envoy from China has arrived at your court offering to trade
character_event = {
	id = JD.60002
	picture = GFX_evt_chinese_bureaucrat
	border = GFX_event_normal_frame_diplomacy
	portrait = event_target:chinese_envoy

	desc = {
		text = evt_DESC_JD_60002_A
		trigger = { event_target:chinese_envoy = { has_character_flag = chinese_envoy_artifacts } }
	}
	desc = { # Envoy from HL.5000
		text = evt_DESC_JD_60002_B
		trigger = { event_target:chinese_envoy = { has_character_flag = is_chinese_envoy } }
	}

	is_triggered_only = yes # on_yearly_pulse, random_events

	only_playable = yes
	has_dlc = "Jade Dragon"
	min_age = 16
	only_capable = yes
	prisoner = no
	war = no

	trigger = {
		china_diplo_interaction_trigger = yes
		is_inaccessible_trigger = no

		offmap_china = {
			NOR = {
				governor = { character = ROOT }
				has_status = china_civil_war
				has_status = china_plague
			}
		}
	}

	weight_multiplier = {
		factor = 1

		mult_modifier = {
			factor = 0.1
			any_artifact = { has_artifact_flag = chinese }
		}

		mult_modifier = {
			factor = 0.6
			offmap_china = { has_status = china_unrest }
		}

		mult_modifier = {
			factor = 0.3
			offmap_china = { has_status = china_mongol_invasion }
		}

		mult_modifier = {
			factor = 0.3
			offmap_china = { has_status = china_jurchen_invasion }
		}

		mult_modifier = {
			factor = 0.3
			offmap_china = { has_status = china_famine }
		}

		mult_modifier = {
			factor = 3
			offmap_china = { has_status = china_golden_age }
		}

		mult_modifier = {
			factor = 2
			offmap_china = { has_policy = china_expansionist }
		}
	}

	immediate = {
		# Already exists if fired from HL.5002
		if = {
			limit = {
				NOT = { event_target:chinese_envoy = { always = yes } }
			}

			offmap_china = {
				governor = {
					random_list = {
						50 = {
							mult_modifier = {
								factor = 0.05
								has_gender_equal_game_rule_trigger = no
							}

							create_character = {
								age = 32
								culture = PREV
								religion = PREV
								dynasty = actually_culture
								female = yes
								random_traits = yes
								historical = yes
							}
						}

						50 = {
							create_character = {
								age = 32
								culture = PREV
								religion = PREV
								dynasty = actually_culture
								female = no
								random_traits = yes
								historical = yes
							}
						}
					}

					new_character = {
						set_character_flag = chinese_envoy_artifacts
						save_event_target_as = chinese_envoy

						random = {
							chance = 10

							clear_education_trait = yes
							add_trait = brilliant_strategist
							change_martial = 5
							set_character_flag = chinese_envoy_warrior
						}
					}
				}
			}
		}

		### Find possible people to trade

		# Eunuch, same requirements as grace decision
		random_courtier = {
			limit = {
				OR = {
					is_close_relative = ROOT
					diplomacy >= 20
					martial >= 20
					stewardship >= 20
					intrigue >= 20
					learning >= 20
					has_fair_trait_trigger = yes
					trait = strong
					trait = genius
					trait = quick
					trait = brawny
					trait = shrewd
					trait = architect
					trait = strategist
					trait = scholar
					trait = faqih
				}

				trigger_if = {
					limit = { is_adult = no }

					is_close_relative = ROOT
					age >= 12
				}

				is_heir = no
				is_ill = no
				is_incapable = no
				is_married = no
				is_landed = no
				is_female = no
				is_betrothed = no
				is_inaccessible_trigger = no

				NOR = {
					has_character_flag = originated_from_chinese_court
					has_character_flag = eunuch_gift
					trait = inbred
					trait = imbecile
				}
			}

			save_event_target_as = chinese_envoy_eunuch_target
		}

		# Concubine, same potential as grace decision
		random_courtier = {
			limit = {
				is_close_relative = ROOT

				offmap_china = {
					offmap_ruler = {
						is_opposite_sex = PREVPREV
					}
				}

				is_adult = yes
				practical_age <= 45
				is_landed = no
				is_betrothed = no
				is_married = no
				is_incapable = no
				is_heir = no
				is_ill = no
				is_inaccessible_trigger = no

				NOR = {
					has_character_flag = originated_from_chinese_court
					trait = wounded
					trait = inbred
					trait = imbecile
					trait = celibate
				}
			}

			save_event_target_as = chinese_envoy_concubine_target
		}
	}

	option = { # Send a eunuch
		name = evt_OPTA_JD_60002
		tooltip_info_custom = JD_60002_eunuch_tt

		trigger = {
			event_target:chinese_envoy_eunuch_target = { always = yes }
		}

		event_target:chinese_envoy_eunuch_target = {
			show_scope_change = no

			hidden_effect = {
				if = {
					limit = {
						NOT = { trait = eunuch }
					}

					add_trait = eunuch
				}
			}

			leave_court_for_china_effect = yes
		}

		if = {
			limit = {
				OR = {
					liked_by_offmap = {
						type = offmap_china
						context = eunuch
					}

					event_target:chinese_envoy_eunuch_target = {
						liked_by_offmap = {
							type = offmap_china
							context = eunuch
						}
					}
				}
			}

			if = {
				limit = {
					OR = {
						disliked_by_offmap = {
							type = offmap_china
							context = eunuch
						}

						event_target:chinese_envoy_eunuch_target = {
							disliked_by_offmap = {
								type = offmap_china
								context = eunuch
							}
						}
					}
				}

				custom_tooltip = { text = JD_60002_likes_but_dislikes_tt }
			}
			else = {
				custom_tooltip = { text = JD_60002_likes_tt }
				set_character_flag = chinese_envoy_trade_like
			}
		}
		else_if = {
			limit = {
				OR = {
					disliked_by_offmap = {
						type = offmap_china
						context = eunuch
					}

					event_target:chinese_envoy_eunuch_target = {
						disliked_by_offmap = {
							type = offmap_china
							context = eunuch
						}
					}
				}
			}

			custom_tooltip = { text = JD_60002_dislikes_tt }
			set_character_flag = chinese_envoy_trade_dislike
		}

		character_event = {
			id = JD.60003
			days = 1
		}
	}

	option = { # Send a concubine
		name = evt_OPTB_JD_60002
		tooltip_info_custom = JD_60002_concubine_tt

		trigger = {
			event_target:chinese_envoy_concubine_target = { always = yes }
		}

		event_target:chinese_envoy_concubine_target = {
			show_scope_change = no

			leave_court_for_china_effect = yes
		}

		if = {
			limit = {
				OR = {
					liked_by_offmap = {
						type = offmap_china
						context = concubine
					}

					event_target:chinese_envoy_concubine_target = {
						liked_by_offmap = {
							type = offmap_china
							context = concubine
						}
					}
				}
			}

			if = {
				limit = {
					OR = {
						disliked_by_offmap = {
							type = offmap_china
							context = concubine
						}

						event_target:chinese_envoy_concubine_target = {
							disliked_by_offmap = {
								type = offmap_china
								context = concubine
							}
						}
					}
				}

				custom_tooltip = { text = JD_60002_likes_but_dislikes_tt }
			}
			else = {
				custom_tooltip = { text = JD_60002_likes_tt }
				set_character_flag = chinese_envoy_trade_like
			}
		}
		else_if = {
			limit = {
				OR = {
					disliked_by_offmap = {
						type = offmap_china
						context = concubine
					}

					event_target:chinese_envoy_concubine_target = {
						disliked_by_offmap = {
							type = offmap_china
							context = concubine
						}
					}
				}
			}

			custom_tooltip = { text = JD_60002_dislikes_tt }
			set_character_flag = chinese_envoy_trade_dislike
		}

		character_event = {
			id = JD.60003
			days = 1
		}
	}

	option = { # Send gold
		name = evt_OPTC_JD_60002

		trigger = {
			NOR = {
				event_target:chinese_envoy_eunuch_target = { always = yes }
				event_target:chinese_envoy_concubine_target = { always = yes }
			}
		}

		scaled_wealth = {
			value = -2
			min = -200
		}

		if = {
			limit = {
				liked_by_offmap = {
					type = offmap_china
					context = wealth
				}
			}

			if = {
				limit = {
					disliked_by_offmap = {
						type = offmap_china
						context = wealth
					}
				}

				custom_tooltip = { text = JD_60002_likes_but_dislikes_tt }
			}
			else = {
				custom_tooltip = { text = JD_60002_likes_tt }
				set_character_flag = chinese_envoy_trade_like
			}
		}
		else_if = {
			limit = {
				disliked_by_offmap = {
					type = offmap_china
					context = wealth
				}
			}

			custom_tooltip = { text = JD_60002_dislikes_tt }
			set_character_flag = chinese_envoy_trade_dislike
		}

		character_event = {
			id = JD.60003
			days = 1
		}
	}

	option = {
		name = evt_OPTD_JD_60002 # Host a feast

		prestige = -150

		if = {
			limit = { liked_by_offmap = { type = offmap_china } }

			if = {
				limit = { disliked_by_offmap = { type = offmap_china } }

				custom_tooltip = { text = JD_60002_likes_but_dislikes_tt }
			}
			else = {
				custom_tooltip = { text = JD_60002_likes_tt }
				set_character_flag = chinese_envoy_trade_like
			}
		}
		else_if = {
			limit = { disliked_by_offmap = { type = offmap_china } }

			custom_tooltip = { text = JD_60002_dislikes_tt }
			set_character_flag = chinese_envoy_trade_dislike
		}

		hidden_effect = {
			random_list = {
				8 = { set_character_flag = chinese_envoy_feast_good }
				2 = { set_character_flag = chinese_envoy_feast_bad }
			}
		}

		character_event = {
			id = JD.60003
			days = 1
		}
	}

	option = {
		name = evt_OPTE_JD_60002

		detract_grace_trivial_effect = yes

		hidden_effect = {
			event_target:chinese_envoy = {
				if = {
					limit = { has_character_flag = chinese_envoy_artifacts  }
					death = { death_reason = death_went_back_to_china }
				}
			}
		}
	}
}

# Get an random artifact in exchange for your trade
character_event = {
	id = JD.60003
	picture = GFX_evt_china_diplomatic_success
	border = GFX_event_normal_frame_diplomacy

	desc = {
		text = evt_DESC_JD_60003_A
		trigger = {
			NOR = {
				has_character_flag = chinese_envoy_feast_good
				has_character_flag = chinese_envoy_feast_bad
			}
		}
	}
	desc = {
		text = evt_DESC_JD_60003_B
		trigger = { has_character_flag = chinese_envoy_feast_good }
	}
	desc = {
		text = evt_DESC_JD_60003_C
		trigger = { has_character_flag = chinese_envoy_feast_bad }
	}

	is_triggered_only = yes

	immediate = {
		offmap_china = {
			governor = { save_event_target_as = the_protector_general }
		}

		if = {
			limit = {
				NOT = { has_character_flag = chinese_envoy_feast_bad }
			}

			# Spawn artifacts in a character with the current Emperor's culture and religion so loc reffering that stays static and then transfer to intended owner.
			random_list = {
				5 = {
					trigger = {
						NOT = { has_artifact = jade_dragon }
					}

					mult_modifier = {
						factor = 3
						has_character_flag = chinese_envoy_trade_like
					}

					mult_modifier = {
						factor = 0.3
						has_character_flag = chinese_envoy_trade_dislike
					}

					event_target:the_protector_general = {
						add_artifact = jade_dragon
					}
				}

				15 = {
					trigger = {
						NOT = { has_artifact = chinese_dragon_amulet }
					}

					mult_modifier = {
						factor = 3
						has_character_flag = chinese_envoy_trade_like
					}

					mult_modifier = {
						factor = 0.3
						has_character_flag = chinese_envoy_trade_dislike
					}

					event_target:the_protector_general = {
						add_artifact = chinese_dragon_amulet
					}
				}

				40 = {
					trigger = {
						NOT = { has_artifact = chinese_artwork }
					}

					mult_modifier = {
						factor = 0.3
						has_character_flag = chinese_envoy_trade_like
					}

					event_target:the_protector_general = {
						add_artifact = chinese_artwork

						new_artifact = {
							set_name = chinese_artwork_name
						}
					}
				}

				40 = {
					trigger = {
						NOT = { has_artifact = chinese_calligraphy }
					}

					mult_modifier = {
						factor = 0.3
						has_character_flag = chinese_envoy_trade_like
					}

					event_target:the_protector_general = {
						add_artifact = chinese_calligraphy

						new_artifact = {
							set_name = chinese_calligraphy_name
						}
					}
				}

				40 = {
					trigger = {
						NOT = { has_artifact = chinese_sculpture }
					}

					mult_modifier = {
						factor = 0.3
						has_character_flag = chinese_envoy_trade_like
					}

					event_target:the_protector_general = {
						add_artifact = chinese_sculpture

						new_artifact = {
							set_name = chinese_sculpture_name
						}
					}
				}

				20 = {
					trigger = {
						NOT = { has_artifact = chinese_ceremonial_robes }
					}

					mult_modifier = {
						factor = 3
						has_character_flag = chinese_envoy_trade_like
					}

					mult_modifier = {
						factor = 0.3
						has_character_flag = chinese_envoy_trade_dislike
					}

					event_target:the_protector_general = {
						add_artifact = chinese_ceremonial_robes
					}
				}

				20 = {
					trigger = {
						has_character_flag = chinese_envoy_trade_like
						martial > 10
						event_target:chinese_envoy = { has_character_flag = chinese_envoy_warrior }
					}

					mult_modifier = {
						factor = 0.1
						has_artifact = art_of_war
					}

					mult_modifier = {
						factor = 2
						martial >= 14
					}

					mult_modifier = {
						factor = 2
						martial >= 18
					}

					mult_modifier = {
						factor = 2
						martial >= 22
					}

					mult_modifier = {
						factor = 2
						martial >= 24
					}

					event_target:the_protector_general = {
						add_artifact = art_of_war
					}
				}

				20 = {
					trigger = {
						NOT = { has_artifact = silk_shroud }
					}

					mult_modifier = {
						factor = 3
						has_character_flag = chinese_envoy_trade_like
					}

					mult_modifier = {
						factor = 0.3
						has_character_flag = chinese_envoy_trade_dislike
					}

					event_target:the_protector_general = {
						add_artifact = silk_shroud
					}
				}

				15 = {
					trigger = {
						NOT = { has_artifact = water_clock }
					}

					mult_modifier = {
						factor = 3
						has_character_flag = chinese_envoy_trade_like
					}

					mult_modifier = {
						factor = 0.3
						has_character_flag = chinese_envoy_trade_dislike
					}

					event_target:the_protector_general = {
						add_artifact = water_clock
					}
				}

				15 = {
					trigger = {
						NOT = { has_artifact = jian_sword }
					}

					mult_modifier = {
						factor = 3
						has_character_flag = chinese_envoy_trade_like
					}

					mult_modifier = {
						factor = 0.3
						has_character_flag = chinese_envoy_trade_dislike
					}

					event_target:the_protector_general = {
						add_artifact = jian_sword
					}
				}

				10 = {
					trigger = {
						NOT = { has_artifact = classic_of_poetry }
					}

					mult_modifier = {
						factor = 3
						has_character_flag = chinese_envoy_trade_like
					}

					mult_modifier = {
						factor = 0.3
						has_character_flag = chinese_envoy_trade_dislike
					}

					event_target:the_protector_general = {
						add_artifact = classic_of_poetry
					}
				}

				1 = {
					event_target:the_protector_general = {
						add_artifact = chinese_prev_emperor_sculpture

						new_artifact = {
							set_name = chinese_figurine_name
						}
					}
				}
			}
		}

		new_artifact = {
			save_event_target_as = chinese_envoy_artifact

			transfer_artifact = {
				from = event_target:the_protector_general
				to = ROOT
			}
		}
	}

	option = {
		name = {
			text = evt_OPTA_JD_60003
			trigger = {
				event_target:chinese_envoy_artifact = { has_artifact_flag = decor }
			}
		}
		name = {
			text = evt_OPTB_JD_60003
			trigger = {
				NOT = {
					event_target:chinese_envoy_artifact = { has_artifact_flag = decor }
				}
			}
		}

		trigger = {
			NOT = { has_character_flag = chinese_envoy_feast_bad }
		}

		sound_effect = china_grace_gain

		custom_tooltip = { text = artifact_added_tt }

		add_grace_trivial_effect = yes
	}

	option = {
		name = evt_OPTC_JD_60003

		trigger = { has_character_flag = chinese_envoy_feast_bad }

		detract_grace_minor_effect = yes
	}

	after = {
		clr_character_flag = chinese_envoy_trade_like
		clr_character_flag = chinese_envoy_trade_dislike
		clr_character_flag = chinese_envoy_feast_good
		clr_character_flag = chinese_envoy_feast_bad

		hidden_effect = {
			event_target:chinese_envoy = {
				if = {
					limit = { has_character_flag = chinese_envoy_artifacts }
					death = { death_reason = death_went_back_to_china }
				}
			}
		}
	}
}

# Visiting councillor leaves you a gift, from JD.20000
character_event = {
	id = JD.60004
	desc = evt_DESC_JD_60004
	picture = GFX_evt_china_diplomatic_success
	border = GFX_event_normal_frame_diplomacy

	is_triggered_only = yes

	has_dlc = "Jade Dragon"

	immediate = {
		# Spawn artifacts in a character with the current Emperor's culture and religion so loc reffering that stays static and then transfer to intended owner.
		offmap_china = {
			governor = {
				random_list = {
					5 = {
						mult_modifier = {
							factor = 0.1
							ROOT = { has_artifact = jade_dragon }
						}

						add_artifact = jade_dragon
					}

					15 = {
						mult_modifier = {
							factor = 0.1
							ROOT = { has_artifact = chinese_dragon_amulet }
						}

						add_artifact = chinese_dragon_amulet
					}

					40 = {
						mult_modifier = {
							factor = 0.1
							ROOT = { has_artifact = chinese_artwork }
						}

						add_artifact = chinese_artwork
					}

					40 = {
						mult_modifier = {
							factor = 0.1
							ROOT = { has_artifact = chinese_calligraphy }
						}

						add_artifact = chinese_calligraphy
					}

					40 = {
						mult_modifier = {
							factor = 0.1
							ROOT = { has_artifact = chinese_sculpture }
						}

						add_artifact = chinese_sculpture
					}

					20 = {
						mult_modifier = {
							factor = 0.1
							ROOT = { has_artifact = chinese_ceremonial_robes }
						}

						add_artifact = chinese_ceremonial_robes
					}

					20 = {
						trigger = {
							event_target:chinese_guest = { has_job_title = job_marshal }
						}

						mult_modifier = {
							factor = 0.1
							ROOT = { has_artifact = art_of_war }
						}
						mult_modifier = {
							factor = 2
							ROOT = { martial >= 14 }
						}
						mult_modifier = {
							factor = 2
							ROOT = { martial >= 18 }
						}
						mult_modifier = {
							factor = 2
							ROOT = { martial >= 22 }
						}
						mult_modifier = {
							factor = 2
							ROOT = { martial >= 24 }
						}

						add_artifact = art_of_war
					}

					20 = {
						mult_modifier = {
							factor = 0.1
							ROOT = { has_artifact = silk_shroud }
						}

						add_artifact = silk_shroud
					}

					15 = {
						mult_modifier = {
							factor = 0.1
							ROOT = { has_artifact = water_clock }
						}

						add_artifact = water_clock
					}

					15 = {
						mult_modifier = {
							factor = 0.1
							ROOT = { has_artifact = jian_sword }
						}

						add_artifact = jian_sword
					}

					10 = {
						mult_modifier = {
							factor = 0.1
							ROOT = { has_artifact = classic_of_poetry }
						}

						add_artifact = classic_of_poetry
					}
				}

				new_artifact = {
					transfer_artifact = {
						from = PREV
						to = ROOT
					}

					save_event_target_as = chinese_envoy_artifact
				}
			}
		}
	}

	option = {
		name = {
			text = evt_OPTA_JD_60003
			trigger = {
				event_target:chinese_envoy_artifact = { has_artifact_flag = decor }
			}
		}
		name = {
			text = evt_OPTB_JD_60003
			trigger = {
				NOT = { event_target:chinese_envoy_artifact = { has_artifact_flag = decor } }
			}
		}

		tooltip = {
			event_target:chinese_envoy_artifact = {
				show_scope_change = no

				transfer_artifact = {
					from = event_target:chinese_guest
					to = ROOT
				}
			}
		}

		sound_effect = china_grace_gain
		add_grace_trivial_effect = yes
	}
}

# Ruler can get an artifact in JD.10013 as well

# Destroy prosthetics on death
character_event = {
	id = JD.60006

	is_triggered_only = yes # on_death
	hide_window = yes

	trigger = {
		OR = {
			has_artifact = prosthetic_hand_gold
			has_artifact = prosthetic_hand_metal
			has_artifact = prosthetic_leg_artifact
		}
	}

	immediate = {
		if = {
			limit = { has_artifact = prosthetic_hand_gold }
			destroy_artifact = prosthetic_hand_gold
		}
		if = {
			limit = { has_artifact = prosthetic_hand_metal }
			destroy_artifact = prosthetic_hand_metal
		}
		if = {
			limit = { has_artifact = prosthetic_leg_artifact }
			destroy_artifact = prosthetic_leg_artifact
		}
	}
}

### WRITE A BOOK ### Start (fired from decision)

# CleanSlate: What kind of lunatic came up with the flag system for this event chain?
character_event = {
	id = JD.10060
	title = EVTTITLE_JD_10060
	picture = GFX_evt_council
	border = GFX_event_normal_frame_religion

	desc = {
		text = EVTDESC_JD_10060_A
		trigger = { trait = lunatic }
	}
	desc = {
		text = EVTDESC_JD_10060_B
		trigger = { is_smart_trigger = yes }
	}
	desc = {
		text = EVTDESC_JD_10060_C
		trigger = { is_dumb_trigger = yes }
	}
	desc = {
		text = EVTDESC_JD_10060_D
		trigger = {
			is_smart_trigger = no
			is_dumb_trigger = no
			NOT = { trait = lunatic }
		}
	}

	is_triggered_only = yes

	immediate = {
		if = {
			limit = {
				OR = {
					martial >= 10
					has_education_martial_trigger = yes
				}

				OR = {
					stewardship >= 10
					has_education_stewardship_trigger = yes
				}

				OR = {
					learning >= 10
					is_monastic_member_trigger = yes
					has_education_learning_trigger = yes
				}

				OR = {
					diplomacy >= 10
					intrigue >= 10
					has_education_diplomacy_trigger = yes
					has_education_intrigue_trigger = yes
				}
			}

			set_character_flag = prepare_fallback_event

			random_list = {
				25 = { set_character_flag = hide_martial_this_time }
				25 = { set_character_flag = hide_relationships_this_time }
				25 = { set_character_flag = hide_administration_this_time }
				25 = { set_character_flag = hide_learning_this_time }
			}
		}
	}

	option = { # (only available with the right education or stats)
		name = EVTOPTA_JD_10060 # I will write about battle and strategy

		trigger = {
			OR = {
				has_education_martial_trigger = yes
				martial >= 10
			}

			NOR = {
				has_character_flag = hide_martial_this_time
				has_character_flag = wrote_about_battle
			}
		}

		custom_tooltip = { text = EVTOPTA_JD_10060_TT }

		set_character_flag = writing_about_battle

		if = {
			limit = {
				OR = {
					martial < 5
					is_dumb_trigger = yes
					has_bottom_tier_education_trait_trigger = yes
				}
			}

			set_character_flag = decent_book_potential
		}

		if = {
			limit = {
				OR = {
					martial >= 7
					has_medium_education_trait_trigger = yes
				}
			}

			set_character_flag = good_book_potential
		}

		if = {
			limit = {
				OR = {
					martial >= 15
					trait = brilliant_strategist
					is_smart_trigger = yes
				}
			}

			set_character_flag = great_book_potential
		}

		ai_chance = {
			factor = 10

			mult_modifier = {
				factor = 2
				trait = brilliant_strategist
			}

			mult_modifier = {
				factor = 1.5
				martial >= 12
			}
		}

	}

	option = { # (only available with the right education or stats)
		name = EVTOPTB_JD_10060 # I will write about the value and intricacies of diplomatic relationships.

		trigger = {
			OR = {
				has_education_diplomacy_trigger = yes
				has_education_intrigue_trigger = yes
				diplomacy >= 10
				intrigue >= 10
			}

			NOR = {
				has_character_flag = hide_relationships_this_time
				has_character_flag = wrote_about_relationships
			}
		}

		custom_tooltip = { text = EVTOPTB_JD_10060_TT }

		set_character_flag = writing_about_relationships

		if = {
			limit = {
				OR = {
					diplomacy < 5
					intrigue < 5
					is_dumb_trigger = yes
					has_bottom_tier_education_trait_trigger = yes
				}
			}

			set_character_flag = decent_book_potential
		}

		if = {
			limit = {
				OR = {
					diplomacy >= 8
					intrigue >= 8
					has_medium_education_trait_trigger = yes
				}
			}

			set_character_flag = good_book_potential
		}

		if = {
			limit = {
				OR = {
					diplomacy >= 15
					intrigue >= 15
					trait = elusive_shadow
					trait = grey_eminence
					is_smart_trigger = yes
				}
			}

			set_character_flag = great_book_potential
		}

		ai_chance = {
			factor = 10

			mult_modifier = {
				factor = 2

				OR = {
					trait = elusive_shadow
					trait = grey_eminence
				}
			}

			mult_modifier = {
				factor = 1.5

				OR = {
					diplomacy >= 12
					intrigue >= 12
				}
			}
		}

	}

	option = { # (only available with the right education or stats)
		name = EVTOPTC_JD_10060 # I will write about managing a realm...

		trigger = {
			OR = {
				has_education_stewardship_trigger = yes
				stewardship >= 10
			}

			NOR = {
				has_character_flag = hide_administration_this_time
				has_character_flag = wrote_about_administration
			}
		}

		custom_tooltip = { text = EVTOPTC_JD_10060_TT }

		set_character_flag = writing_about_administration

		if = {
			limit = {
				OR = {
					stewardship < 5
					is_dumb_trigger = yes
					has_bottom_tier_education_trait_trigger = yes
				}
			}

			set_character_flag = decent_book_potential
		}

		if = {
			limit = {
				OR = {
					stewardship >= 7
					has_medium_education_trait_trigger = yes
				}
			}

			set_character_flag = good_book_potential
		}

		if = {
			limit = {
				OR = {
					stewardship >= 15
					trait = midas_touched
					is_smart_trigger = yes
				}
			}

			set_character_flag = great_book_potential
		}

		ai_chance = {
			factor = 10

			mult_modifier = {
				factor = 0.5
				NOT = { trait = midas_touched } # Basically, to decrease the amount of cookbooks in the world. :D
			}
		}
	}

	option = { # (only available with the right education or stats, OR a monastic member with not great stats or education)
		name = EVTOPTD_JD_10060 # I will write about religion...

		trigger = {
			OR = {
				has_education_learning_trigger = yes
				learning >= 10
				is_monastic_member_trigger = yes
			}

			NOR = {
				has_character_flag = hide_learning_this_time
				has_character_flag = wrote_about_religion
			}
		}

		custom_tooltip = { text = EVTOPTD_JD_10060_TT }

		set_character_flag = writing_about_religion

		if = {
			limit = {
				OR = {
					learning < 5
					is_dumb_trigger = yes
					has_bottom_tier_education_trait_trigger = yes
				}
			}

			set_character_flag = decent_book_potential
		}

		if = {
			limit = {
				OR = {
					learning >= 7
					has_medium_education_trait_trigger = yes
				}
			}

			set_character_flag = good_book_potential
		}

		if = {
			limit = {
				OR = {
					learning >= 15
					trait = mastermind_theologian
					is_smart_trigger = yes
				}
			}

			set_character_flag = great_book_potential
		}

		ai_chance = {
			factor = 10

			mult_modifier = {
				factor = 2
				trait = mastermind_theologian
			}

			mult_modifier = {
				factor = 1.5
				is_monastic_member_trigger = yes
			}

			mult_modifier = {
				factor = 1.5
				learning >= 12
			}
		}
	}

	option = { # (always available)
		name = EVTOPTH_JD_10060 # I shall chronicle my family history!

		trigger = {
			NOT = { has_character_flag = wrote_about_dynasty }
		}

		custom_tooltip = { text = EVTOPTH_JD_10060_TT }

		set_character_flag = writing_about_dynasty

		if = {
			limit = {
				OR = {
					calc_true_if = {
						amount = 3

						diplomacy < 8
						martial < 8
						intrigue < 8
						stewardship < 8
						learning < 8
					}

					is_dumb_trigger = yes
					has_bottom_tier_education_trait_trigger = yes
				}
			}

			set_character_flag = decent_book_potential
		}

		if = {
			limit = {
				OR = {
					calc_true_if = {
						amount = 3

						diplomacy >= 12
						martial >= 12
						intrigue >= 12
						stewardship >= 12
						learning >= 12
					}

					has_medium_education_trait_trigger = yes
				}
			}

			set_character_flag = good_book_potential
		}

		if = {
			limit = {
				OR = {
					calc_true_if = {
						amount = 3

						diplomacy >= 20
						martial >= 20
						intrigue >= 20
						stewardship >= 20
						learning >= 20
					}

					is_smart_trigger = yes
					has_top_tier_education_trait_trigger = yes
				}
			}

			set_character_flag = great_book_potential
		}

		ai_chance = { factor = 10 }
	}

	after = {
		if = {
			limit = { ai = no }

			add_character_modifier = {
				name = writing_a_book
				duration = -1
			}
		}

		character_event = {
			id = LT.60101 # Library lets you write a cooler book
			months = 1
			random = 5850 # 195 Months
		}

		hidden_effect = {
			random_list = {
				25 = { character_event = { id = JD.10061 months = 20 random = 1095 } } # invest more time/money/hire scribes
				25 = { character_event = { id = JD.10062 months = 20 random = 1095 } } # change direction/unhappy with work
				25 = { character_event = { id = JD.10063 months = 20 random = 1095 } } # deal with writer's block
				25 = { character_event = { id = JD.10064 months = 20 random = 1095 } } # stay up all night studying or not

				# testing values....
#				25 = { character_event = { id = JD.10061 days = 5 random = 5 } } # invest more time/money/hire scribes
#				25 = { character_event = { id = JD.10062 days = 5 random = 5 } } # change direction/unhappy with work
#				25 = { character_event = { id = JD.10063 days = 5 random = 5 } } # deal with writer's block
#				25 = { character_event = { id = JD.10064 days = 5 random = 5 } } # stay up all night studying or not
			}
		}
	}
}

character_event = { # Progress event type 1!  # invest more time/money/hire scribes
	id = JD.10061
	title = EVTTITLE_JD_10061
	picture = GFX_evt_monk
	border = GFX_event_normal_frame_religion

	desc = {
		text = EVTDESC_JD_10061_A
		trigger = {
			job_chancellor = { always = yes }
		}
	}
	desc = {
		text = EVTDESC_JD_10061_B
		trigger = {
			NOT = { job_chancellor = { always = yes } }
		}
	}

	is_triggered_only = yes

	immediate = {
		job_chancellor = { # For GetChancellorName
			save_event_target_as = advisor_target
		}
	}

	option = { # I want to invest in more into scribes and ink.
		name = EVTOPTA_JD_10061

		scaled_wealth = -0.2
	}

	option = { # Maybe I can help..?
		name = EVTOPTB_JD_10061
		tooltip_info = yes

		trigger = {
			OR = {
				trait = erudite
				trait = scholar
				trait = mastermind_theologian
				trait = lunatic
				is_dumb_trigger = yes
			}
		}

		# If a dumb character, you might learn something, but the work might suffer...
		if = {
			limit = { is_dumb_trigger = yes }

			custom_tooltip = { text = available_because_is_dumb_tt }

			random = {
				chance = 50
				change_learning = 1
			}

			custom_tooltip = { text = lower_quality_of_book_TT }
			set_lower_quality_of_book_flags_effect = yes
		}

		# If a learned character, things might go well, regardless!
		else = {
			trigger_switch = {
				on_trigger = trait

				erudite               = { custom_tooltip = { text = available_because_trait_erudite_tt } }
				scholar               = { custom_tooltip = { text = available_because_trait_scholar_tt } }
				mastermind_theologian = { custom_tooltip = { text = available_because_trait_mastermind_theologian_tt } }
				lunatic               = { custom_tooltip = { text = available_because_trait_lunatic_tt } }
			}

			custom_tooltip = { text = higher_quality_of_book_TT }
			set_higher_quality_of_book_flags_effect = yes
		}
	}

	option = { # Things are going great!
		name = EVTOPTC_JD_10061

		custom_tooltip = { text = lower_quality_of_book_TT }
		set_lower_quality_of_book_flags_effect = yes
	}

	after = {
		# Finish book
		character_event = {
			id = JD.10070
			days = 565
			random = 3650
		}
	}
}

character_event = { # Progress event type 2! # Unhappy with work (gain stressed or not)
	id = JD.10062
	title = EVTTITLE_JD_10061
	desc = EVTDESC_JD_10062
	picture = GFX_evt_library
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	immediate = {
		trigger_switch = {
			on_trigger = has_character_flag

			writing_about_battle = {
				job_marshal = {
					save_event_target_as = friendly_advice_target
				}
			}

			writing_about_relationships = {
				if = {
					limit = { job_spymaster = { is_alive = yes } }

					job_spymaster = {
						save_event_target_as = friendly_advice_target
					}
				}
				else = {
					job_chancellor = {
						save_event_target_as = friendly_advice_target
					}
				}
			}

			writing_about_administration = {
				job_treasurer = {
					save_event_target_as = friendly_advice_target
				}
			}

			writing_about_religion = {
				job_spiritual = {
					save_event_target_as = friendly_advice_target
				}
			}

			writing_about_dynasty = {
				if = {
					limit = { has_lover = yes }
					random_lover = { save_event_target_as = friendly_advice_target }
				}
				else_if = {
					limit = { is_married = yes }
					random_spouse = { save_event_target_as = friendly_advice_target }
				}
				else = {
					job_chancellor = {
						save_event_target_as = friendly_advice_target
					}
				}
			}
		}

		if = {
			limit = {
				NOT = { event_target:friendly_advice_target = { always = yes } }
			}

			random_courtier = { # fallbacks in case no council member... (except lunatics, who just don't care)
				limit = {
					NOT = { trait = lunatic } # CleanSlate: Not sure that this is what they were going for. I suspect it may have been intended to be if ROOT is a lunatic, select someone at random.
				}

				preferred_limit = {
					is_adult = yes
					is_incapable = no
					is_inaccessible_trigger = no
				}

				preferred_limit = {
					is_incapable = no
					is_inaccessible_trigger = no
				}

				save_event_target_as = friendly_advice_target
			}
		}
	}

	option = { # I'll ask random_target for advice!
		name = EVTOPTA_JD_10062

		trigger_switch = {
			on_trigger = has_character_flag

			writing_about_battle = {
				event_target:friendly_advice_target = {
					show_scope_change = no

					if = {
						limit = {
							attribute_diff = { character = ROOT attribute = martial value >= 3 }
						}

						ROOT = {
							show_scope_change = no

							custom_tooltip = { text = higher_quality_of_book_TT }
							set_higher_quality_of_book_flags_effect = yes
						}
					}
					else = {
						ROOT = {
							show_scope_change = no

							custom_tooltip = { text = lower_quality_of_book_TT }
							set_lower_quality_of_book_flags_effect = yes
						}
					}
				}
			}

			writing_about_relationships = {
				event_target:friendly_advice_target = {
					show_scope_change = no

					if = {
						limit = {
							has_job_title = job_spymaster
							attribute_diff = { character = ROOT attribute = intrigue value >= 3 }
						}

						ROOT = {
							show_scope_change = no

							custom_tooltip = { text = higher_quality_of_book_TT }
							set_higher_quality_of_book_flags_effect = yes
						}
					}
					else_if = {
						limit = {
							has_job_title = job_chancellor
							attribute_diff = { character = ROOT attribute = diplomacy value >= 3 }
						}

						ROOT = {
							show_scope_change = no

							custom_tooltip = { text = higher_quality_of_book_TT }
							set_higher_quality_of_book_flags_effect = yes
						}
					}
					else = {
						ROOT = {
							show_scope_change = no

							custom_tooltip = { text = lower_quality_of_book_TT }
							set_lower_quality_of_book_flags_effect = yes
						}
					}
				}
			}

			writing_about_administration = {
				event_target:friendly_advice_target = {
					show_scope_change = no

					if = {
						limit = {
							attribute_diff = { character = ROOT attribute = stewardship value >= 3 }
						}

						ROOT = {
							show_scope_change = no

							custom_tooltip = { text = higher_quality_of_book_TT }
							set_higher_quality_of_book_flags_effect = yes
						}
					}
					else = {
						ROOT = {
							show_scope_change = no

							custom_tooltip = { text = lower_quality_of_book_TT }
							set_lower_quality_of_book_flags_effect = yes
						}
					}
				}
			}

			writing_about_religion = {
				event_target:friendly_advice_target = {
					show_scope_change = no

					if = {
						limit = {
							attribute_diff = { character = ROOT attribute = learning value >= 3 }
						}

						ROOT = {
							show_scope_change = no

							custom_tooltip = { text = higher_quality_of_book_TT }
							set_higher_quality_of_book_flags_effect = yes
						}
					}
					else = {
						ROOT = {
							show_scope_change = no

							custom_tooltip = { text = lower_quality_of_book_TT }
							set_lower_quality_of_book_flags_effect = yes
						}
					}
				}
			}

			writing_about_dynasty = {
				event_target:friendly_advice_target = {
					show_scope_change = no

					if = {
						limit = {
							OR = {
								attribute_diff = { character = ROOT attribute = diplomacy value >= 4 }
								attribute_diff = { character = ROOT attribute = learning value >= 4 }
							}
						}

						ROOT = {
							show_scope_change = no

							custom_tooltip = { text = higher_quality_of_book_TT }
							set_higher_quality_of_book_flags_effect = yes
						}
					}
					else = {
						ROOT = {
							show_scope_change = no

							custom_tooltip = { text = lower_quality_of_book_TT }
							set_lower_quality_of_book_flags_effect = yes
						}
					}
				}
			}
		}

		# Add opinion boost with target.
		reverse_opinion = {
			name = opinion_grateful
			who = event_target:friendly_advice_target
			years = 10
		}
	}

	option = { # I'd rather not involve anyone else.
		name = EVTOPTB_JD_10062

		add_trait_silently_stressed_effect = yes
	}

	after = {
		# Finish book
		character_event = {
			id = JD.10070
			days = 565
			random = 3650
		}
	}
}

character_event = { # Progress event type 3!  # deal with writer's block (risk doing something stupid?
	id = JD.10063
	title = EVTTITLE_JD_10061
	desc = EVTDESC_JD_10063
	picture = GFX_evt_princess_byzantine
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	immediate = {
		if = {
			limit = { has_assigned_minor_title = title_court_physician }

			random_courtier_or_vassal = {
				limit = { has_minor_title = title_court_physician }
				save_event_target_as = my_doctor
			}
		}
	}

	option = { # Go mingle with the commoners!
		name = EVTOPTA_JD_10063

		custom_tooltip = { text = EVTOPTA_JD_10063_TT }

		random_list = {
			45 = { add_trait_wounded_effect = yes }
			 5 = { add_maimed_trait_effect = yes }
			55 = { } # Nothing happens!
		}

		custom_tooltip = { text = higher_quality_of_book_TT }
		set_higher_quality_of_book_flags_effect = yes
	}

	option = { # Drink something poisonous...?
		name = EVTOPTB_JD_10063
		show_portrait = event_target:my_doctor

		trigger = {
			event_target:my_doctor = { always = yes }
		}

		custom_tooltip = { text = EVTOPTB_JD_10063_TT }

		random_list = {
			99 = {
				add_trait = vomiting
				set_character_flag = disease_not_serious

				character_event = {
					id = HFP.14005 # remove vomiting
					days = 10
					random = 30
				}
			}

			1 = {
				death = { death_reason = death_drank_poison }
			}
		}

		custom_tooltip = { text = higher_quality_of_book_TT }
		set_higher_quality_of_book_flags_effect = yes
	}

	option = { # I clearly need a break...
		name = EVTOPTC_JD_10063

		custom_tooltip = { text = lower_quality_of_book_TT }
		set_lower_quality_of_book_flags_effect = yes
	}

	after = {
		# Finish book
		character_event = {
			id = JD.10070
			days = 565
			random = 3650
		}
	}
}

character_event = { # Progress event type 4!  # stay up all night or not
	id = JD.10064
	title = EVTTITLE_JD_10061
	picture = GFX_evt_daughter_asking_father
	border = GFX_event_normal_frame_religion

	desc = {
		text = EVTDESC_JD_10064_martial
		trigger = { has_character_flag = writing_about_battle }
	}
	desc = {
		text = EVTDESC_JD_10064_relationships
		trigger = { has_character_flag = writing_about_relationships }
	}
	desc = {
		text = EVTDESC_JD_10064_administration
		trigger = { has_character_flag = writing_about_administration }
	}
	desc = {
		text = EVTDESC_JD_10064_religion
		trigger = { has_character_flag = writing_about_religion }
	}
	desc = {
		text = EVTDESC_JD_10064_dynasty
		trigger = { has_character_flag = writing_about_dynasty }
	}

	is_triggered_only = yes

	option = { # Stay up all night
		name = {
			text = EVTOPTA_JD_10064
			trigger = {
				NOT = { has_character_flag = writing_about_dynasty }
			}
		}
		name = {
			text = EVTOPTA_JD_10064_dynasty
			trigger = { has_character_flag = writing_about_dynasty }
		}

		if = {
			limit = { has_character_flag = writing_about_relationships }

			random = {
				chance = 90
				add_trait_stressed_effect = yes
			}
		}
		else = {
			if = {
				limit = { has_character_flag = writing_about_dynasty }
				piety = -50
			}

			random = {
				chance = 80

				if = {
					limit = { has_dlc = Reapers }
					custom_tooltip = { text = you_get_a_cold_of_some_sort_tt }

					hidden_effect = {
						random_list = {
							50 = { give_pneumonic_effect = yes }
							50 = { give_flu_effect = yes }
						}
					}
				}
				else = {
					add_trait_ill_effect = yes
				}
			}
		}

		custom_tooltip = { text = higher_quality_of_book_TT }
		set_higher_quality_of_book_flags_effect = yes
	}

	option = { # I probably just need to sleep on it.
		name = {
			text = EVTOPTB_JD_10064
			trigger = {
				NOT = { has_character_flag = writing_about_dynasty }
			}
		}
		name = {
			text = EVTOPTB_JD_10064_dynasty
			trigger = {
				has_character_flag = writing_about_dynasty
			}
		}

		# custom_tooltip = { text = lower_quality_of_book_TT }
		# set_lower_quality_of_book_flags_effect = yes
	}

	after = {
		# Finish book
		character_event = {
			id = JD.10070
			days = 565
			random = 3650
		}
	}
}

character_event = { # Outcome: Book is finished! It went Great/Good/Decent!
	id = JD.10070
	title = EVTTITLE_JD_10070
	desc = EVTDESC_JD_10070_A
	picture = GFX_evt_library
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes
	hide_from = yes

	trigger = { is_landed = yes }

	immediate = {
		clear_delayed_event = { id = LT.60101 }

		hidden_effect = {
			# Fallback in case flags have cleared somehow...
			if = {
				limit = {
					NOR = {
						has_character_flag = decent_book_potential
						has_character_flag = good_book_potential
						has_character_flag = great_book_potential
					}
				}

				set_character_flag = decent_book_potential
			}

			# Evaluates how it's gone, from stats, traits, and choices. The flags unlock quality-level of book (or eliminates a level). Relevant event_targets (spouse/lover?) are saved, for loc (custom book names and descs) and opinion bonuses.
			trigger_switch = {
				on_trigger = has_character_flag

				writing_about_battle = {
					set_character_flag = wrote_about_battle

					random_list = {
						10 = { # quality level 1
							trigger = { has_character_flag = decent_book_potential }

							additive_modifier = {
								value = 10
								has_lifestyle_martial_trigger = no
							}
							additive_modifier = {
								value = 10
								has_education_martial_trigger = no
							}
							additive_modifier = {
								value = 10

								OR = {
									is_the_worst_duelist_trigger = yes
									is_terrible_duelist_trigger = yes
								}
							}
							additive_modifier = {
								value = 10
								martial < 5
							}
							additive_modifier = {
								value = 10
								martial < 10
							}

							random_list = {
								10 = {
									trigger = {
										NOT = {
											any_artifact = {
												artifact_type = how_to_hold_a_sword
												original_owner = { character = ROOT }
											}
										}
									}

									add_artifact = how_to_hold_a_sword

									random = {
										chance = 50

										new_artifact = {
											set_name = how_to_carry_a_bow
											set_description = how_to_carry_a_bow_desc
										}
									}
								}

								20 = {
									trigger = {
										any_rival = { is_adult = yes }

										NOT = {
											any_artifact = {
												artifact_type = lessons_taught_to_me_by_rival_1
												original_owner = { character = ROOT }
											}
										}
									}

									random_rival = { save_event_target_as = dedication_target }

									add_artifact = lessons_taught_to_me_by_rival_1

									new_artifact = {
										set_description = lessons_taught_to_me_by_rival_1_desc_rename
									}
								}
							}
						}

						10 = { # quality level 2
							trigger = { has_character_flag = good_book_potential }

							additive_modifier = {
								value = 10
								duelist_skill_is_medium_group_trigger = yes
							}
							additive_modifier = {
								value = 10

								OR = {
									trait = misguided_warrior
									trait = tough_soldier
								}
							}
							additive_modifier = {
								value = 10

								OR = {
									has_focus = focus_war
									has_focus = focus_hunting
								}
							}

							random_list = {
								10 = {
									trigger = {
										NOT = {
											any_artifact = {
												artifact_type = a_history_of_armor
												original_owner = { character = ROOT }
											}
										}
									}

									additive_modifier = {
										value = 10
										trait = administrator
									}

									add_artifact = a_history_of_armor
								}

								10 = {
									trigger = {
										NOT = {
											any_artifact = {
												artifact_type = the_life_of_root
												original_owner = { character = ROOT }
											}
										}
									}

									additive_modifier = {
										value = 10
										trait = strategist
									}
									additive_modifier = {
										value = 10
										trait = proud
									}

									add_artifact = the_life_of_root

									new_artifact = {
										set_description = the_life_of_root_desc_rename
									}
								}

								10 = {
									trigger = {
										NOT = {
											any_artifact = {
												artifact_type = a_soldiers_life
												original_owner = { character = ROOT }
											}
										}
									}

									additive_modifier = {
										value = 10
										trait = poet
									}

									add_artifact = a_soldiers_life
								}

								20 = {
									trigger = {
										any_rival = { is_adult = yes }

										NOT = {
											any_artifact = {
												artifact_type = lessons_taught_to_me_by_rival_2
												original_owner = { character = ROOT }
											}
										}
									}

									random_rival = { save_event_target_as = dedication_target }

									add_artifact = lessons_taught_to_me_by_rival_2

									new_artifact = {
										set_description = lessons_taught_to_me_by_rival_2_desc_rename

										random_list = {
											50 = { set_name = lessons_taught_to_me_by_rival_2_rename_1 }
											50 = { set_name = lessons_taught_to_me_by_rival_2_rename_2 }
										}
									}
								}

								20 = {
									trigger = {
										trait = falconer

										NOT = {
											any_artifact = {
												artifact_type = the_wisdom_of_the_heavens
												original_owner = { character = ROOT }
											}
										}
									}

									additive_modifier = {
										value = 10
										trait = hunter
									}
									additive_modifier = {
										value = 10
										has_focus = focus_hunting
									}

									add_artifact = the_wisdom_of_the_heavens
								}
							}
						}

						10 = { # quality level 3 (or 4)
							trigger = { has_character_flag = great_book_potential }

							additive_modifier = {
								value = 10
								has_lifestyle_martial_trigger = yes
							}
							additive_modifier = {
								value = 10
								has_education_martial_trigger = yes
								NOT = { trait = misguided_warrior }
							}
							additive_modifier = {
								value = 10
								duelist_skill_is_high_group_trigger = yes
							}
							additive_modifier = {
								value = 10
								is_the_best_duelist_trigger = yes
							}
							additive_modifier = {
								value = 10
								can_have_more_leadership_traits = no
							}
							additive_modifier = {
								value = 10

								OR = {
									has_focus = focus_war
									has_focus = focus_hunting
								}
							}
							additive_modifier = {
								value = 10
								martial >= 10
							}
							additive_modifier = {
								value = 10
								martial >= 15
							}
							additive_modifier = {
								value = 10
								martial >= 20
							}

							random_list = {
								10 = {
									trigger = {
										NOT = {
											any_artifact = {
												artifact_type = military_strategy_guide
												original_owner = { character = ROOT }
											}
										}
									}

									additive_modifier = {
										value = 10
										trait = strategist
									}

									add_artifact = military_strategy_guide
								}

								10 = {
									trigger = {
										NOT = {
											any_artifact = {
												artifact_type = my_fechtbuch
												original_owner = { character = ROOT }
											}
										}
									}

									additive_modifier = {
										value = 5
										trait = duelist
									}

									add_artifact = my_fechtbuch

									new_artifact = {
										set_name = my_fechtbuch_rename
									}
								}

								10 = {
									trigger = {
										NOT = {
											any_artifact = {
												artifact_type = codex_dynasty_name
												original_owner = { character = ROOT }
											}
										}
									}

									add_artifact = codex_dynasty_name
								}

								10 = {
									trigger = {
										OR = {
											trait = duelist
											trait = hunter
											trait = strategist
											has_education_martial_trigger = yes
										}

										NOT = {
											any_artifact = {
												artifact_type = the_sword_and_buckler
												original_owner = { character = ROOT }
											}
										}
									}

									additive_modifier = {
										value = 10
										trait = duelist
									}

									add_artifact = the_sword_and_buckler
								}

								20 = {
									trigger = {
										any_rival = {
											root_attraction_trigger = yes
											is_adult = yes

											trigger_if = {
												limit = { is_close_relative = ROOT }
												ROOT = { religion_has_incest = yes }
											}
										}

										NOT = {
											any_artifact = {
												artifact_type = lessons_taught_to_me_by_rival_3
												original_owner = { character = ROOT }
											}
										}
									}

									additive_modifier = {
										value = 10
										OR = {
											trait = lustful
											trait = hedonist
										}
									}

									random_rival = { # if ROOT can be attracted to them...
										limit = {
											root_attraction_trigger = yes
											is_adult = yes

											trigger_if = {
												limit = { is_close_relative = ROOT }
												ROOT = { religion_has_incest = yes }
											}
										}

										save_event_target_as = dedication_target
									}

									add_artifact = lessons_taught_to_me_by_rival_3

									new_artifact = {
										set_description = lessons_taught_to_me_by_rival_3_desc_rename
									}
								}

								10 = {
									trigger = {
										NOT = {
											any_artifact = {
												artifact_type = ordinary_beasts
												original_owner = { character = ROOT }
											}
										}
									}

									additive_modifier = {
										value = 10
										has_focus = focus_intrigue
									}
									additive_modifier = {
										value = 10
										trait = arbitrary
									}
									additive_modifier = {
										value = 10
										trait = cruel
									}
									additive_modifier = {
										value = 10
										has_lifestyle_intrigue_trigger = yes
									}
									additive_modifier = {
										value = 10
										is_weak_trigger = yes
									}

									add_artifact = ordinary_beasts
								}

								10 = {
									trigger = {
										NOT = {
											any_artifact = {
												artifact_type = the_white_animal
												original_owner = { character = ROOT }
											}
										}
									}

									additive_modifier = {
										value = 10
										trait = hunter
									}
									additive_modifier = {
										value = 10
										trait = falconer
									}
									additive_modifier = {
										value = 10
										has_focus = focus_hunting
									}

									add_artifact = the_white_animal

									new_artifact = {
										set_name = the_white_animal_rename
										set_description = the_white_animal_desc_rename
									}
								}

								10 = {
									trigger = {
										NOT = {
											any_artifact = {
												artifact_type = the_bestiary
												original_owner = { character = ROOT }
											}
										}
									}

									additive_modifier = {
										value = 10
										trait = hunter
									}
									additive_modifier = {
										value = 10
										trait = falconer
									}
									additive_modifier = {
										value = 10
										has_focus = focus_hunting
									}

									add_artifact = the_bestiary
								}

								10 = {
									trigger = {
										NOT = {
											any_artifact = {
												artifact_type = the_book_of_shadows
												original_owner = { character = ROOT }
											}
										}
									}

									additive_modifier = {
										value = 10
										trait = duelist
									}
									additive_modifier = {
										value = 10
										has_education_intrigue_trigger = yes
									}
									additive_modifier = {
										value = 10
										has_lifestyle_intrigue_trigger = yes
									}
									additive_modifier = {
										value = 10
										has_focus = focus_intrigue
									}

									add_artifact = the_book_of_shadows
								}

								10 = {
									trigger = {
										NOT = {
											any_artifact = {
												artifact_type = on_government_type_warfare
												original_owner = { character = ROOT }
											}
										}
									}

									additive_modifier = {
										value = 10
										trait = strategist
									}
									additive_modifier = {
										value = 10
										has_education_martial_trigger = yes
									}
									additive_modifier = {
										value = 10
										has_focus = focus_war
									}
									additive_modifier = {
										value = 10

										OR = {
											trait = diligent
											trait = organizer
											trait = inspiring_leader
											trait = defensive_leader
										}
									}

									add_artifact = on_government_type_warfare

									new_artifact = {
										set_name = on_government_type_warfare_rename
										set_description = on_government_type_warfare_desc_rename
									}
								}
							}
						}
					}
				}

				writing_about_relationships = {
					set_character_flag = wrote_about_relationships

					random_list = {
						10 = { # quality level 1
							trigger = { has_character_flag = decent_book_potential }

							additive_modifier = {
								value = 10
								has_bottom_tier_education_trait_trigger = yes
							}
							additive_modifier = {
								value = 10

								OR = {
									diplomacy < 1
									intrigue < 1
								}
							}
							additive_modifier = {
								value = 10

								OR = {
									diplomacy < 5
									intrigue < 5
								}
							}
							additive_modifier = {
								value = 10

								OR = {
									diplomacy < 10
									intrigue < 10
								}
							}

							random_list = {
								10 = {
									trigger = {
										NOT = {
											any_artifact = {
												artifact_type = to_my_descendants
												original_owner = { dynasty = ROOT }
											}
										}
									}

									additive_modifier = {
										value = 10
										trait = stubborn
									}
									additive_modifier = {
										value = 10
										trait = cynical
									}
									additive_modifier = {
										value = 10
										trait = diligent
									}
									additive_modifier = {
										value = 10
										trait = paranoid
									}

									add_artifact = to_my_descendants
								}

								10 = {
									trigger = {
										has_lover = yes

										NOT = {
											any_artifact = {
												artifact_type = in_honor_of_roots_beloved_1
												original_owner = { character = ROOT }
											}
										}
									}

									additive_modifier = {
										value = 10
										trait = kind
									}
									additive_modifier = {
										value = 10
										trait = shy
									}
									additive_modifier = {
										value = 10
										trait = lustful
									}

									random_lover = { save_event_target_as = dedication_target }

									add_artifact = in_honor_of_roots_beloved_1

									new_artifact = {
										set_name = in_honor_of_roots_beloved_1_rename
										set_description = in_honor_of_roots_beloved_1_desc_rename_lover
									}
								}

								10 = {
									trigger = { is_married = yes }

									additive_modifier = {
										value = 10
										trait = kind
									}
									additive_modifier = {
										value = 10
										trait = shy
									}

									random_spouse = { save_event_target_as = dedication_target }

									add_artifact = in_honor_of_roots_beloved_1

									new_artifact = {
										set_name = in_honor_of_roots_beloved_1_rename
										set_description = in_honor_of_roots_beloved_1_desc_rename_spouse
									}
								}

								10 = {
									trigger = {
										NOT = {
											any_artifact = {
												OR = {
													artifact_type = court_etiquette_2
													artifact_type = court_etiquette_3
												}
											}
										}
									}

									add_artifact = court_etiquette_1 # only if have no other volumes in the series
								}
							}
						}

						10 = { # quality level 2
							trigger = { has_character_flag = good_book_potential }

							additive_modifier = {
								value = 10

								OR = {
									has_focus = focus_intrigue
									has_focus = focus_family
								}
							}
							additive_modifier = {
								value = 10
								diplomacy < 10
							}
							additive_modifier = {
								value = 10
								intrigue < 10
							}

							random_list = {
								10 = {
									trigger = {
										is_married = yes

										NOT = {
											any_artifact = {
												artifact_type = in_honor_of_roots_beloved_2
												original_owner = { character = ROOT }
											}
										}
									}

									additive_modifier = {
										value = 10
										any_spouse = { possibly_romantically_interested_in_ROOT_trigger = yes }
									}
									additive_modifier = {
										value = 5
										has_focus = focus_family
									}
									additive_modifier = {
										value = 10
										trait = poet
									}

									random_spouse = { save_event_target_as = dedication_target }

									add_artifact = in_honor_of_roots_beloved_2

									new_artifact = {
										set_name = in_honor_of_roots_beloved_2_rename
										set_description = in_honor_of_roots_beloved_2_desc_rename_spouse
									}
								}

								10 = {
									trigger = {
										has_lover = yes

										NOT = {
											any_spouse = { is_lover = ROOT }
										}

										NOT = {
											any_artifact = {
												artifact_type = in_honor_of_roots_beloved_2
												original_owner = { character = ROOT }
											}
										}
									}

									additive_modifier = {
										value = 10
										trait = cynical
									}
									additive_modifier = {
										value = 10
										trait = lustful
									}
									additive_modifier = {
										value = 10
										trait = cruel
									}
									additive_modifier = {
										value = 5
										trait = poet
									}

									random_lover = { save_event_target_as = dedication_target }

									add_artifact = in_honor_of_roots_beloved_2

									new_artifact = {
										set_name = in_honor_of_roots_beloved_2_rename
										set_description = in_honor_of_roots_beloved_2_desc_rename_lover
									}
								}

								10 = {
									trigger = {
										NOT = {
											any_artifact = {
												artifact_type = notes_from_a_kitchen
												original_owner = { character = ROOT }
											}
										}
									}

									additive_modifier = {
										value = 10
										trait = poet
									}
									additive_modifier = {
										value = 5
										trait = gluttonous
									}

									add_artifact = notes_from_a_kitchen
								}

								20 = {
									trigger = {
										any_artifact = {
											artifact_type = court_etiquette_1
										}

										NOT = {
											any_artifact = {
												OR = {
													artifact_type = court_etiquette_2
													artifact_type = court_etiquette_3
												}
											}
										}
									}

									random_artifact = {
										limit = { artifact_type = court_etiquette_1 }

										original_artifact_owner = {
											save_event_target_as = other_author
										}
									}

									add_artifact = court_etiquette_2 # if you have volume I already!

									new_artifact = {
										set_description = court_etiquette_2_desc_rename # sets the name of the other author
									}
								}

								10 = {
									trigger = {
										NOT = {
											any_artifact = {
												artifact_type = how_to_write_a_letter
												original_owner = { character = ROOT }
											}
										}
									}

									add_artifact = how_to_write_a_letter
								}

								10 = {
									trigger = {
										OR = {
											trait = lustful
											trait = hedonist
											trait = master_seducer
											trait = master_seductress
										}

										NOT = {
											any_artifact = {
												artifact_type = fifty_shades_of_root
											}
										}
									}

									additive_modifier = {
										value = -5
										is_learned_trigger = yes
									}
									additive_modifier = {
										value = 5
										trait = lustful
									}
									additive_modifier = {
										value = 5
										trait = cruel
									}
									additive_modifier = {
										value = 5
										trait = impaler
									}
									additive_modifier = {
										value = 5
										trait = arbitrary
									}
									additive_modifier = {
										value = 5
										is_evil_trigger = yes
									}

									add_artifact = fifty_shades_of_root

									new_artifact = {
										set_description = fifty_shades_of_root_desc_rename
									}
								}

								10 = {
									trigger = {
										NOT = {
											any_artifact = {
												artifact_type = how_to_make_allies
												original_owner = { character = ROOT }
											}
										}
									}

									additive_modifier = {
										value = 10
										trait = shy
									}
									additive_modifier = {
										value = 10
										trait = paranoid
									}
									additive_modifier = {
										value = 10
										trait = ambitious
									}
									additive_modifier = {
										value = 10
										trait = cynical
									}
									additive_modifier = {
										value = 5

										OR = {
											has_education_stewardship_trigger = yes
											has_education_intrigue_trigger = yes
										}
									}

									add_artifact = how_to_make_allies
								}
							}
						}

						10 = { # quality level 3 (or 4)
							trigger = { has_character_flag = great_book_potential }

							additive_modifier = {
								value = 10

								OR = {
									has_lifestyle_diplomacy_trigger = yes
									has_lifestyle_intrigue_trigger = yes
								}
							}
							additive_modifier = {
								value = 10

								OR = {
									has_education_diplomacy_trigger = yes
									has_education_intrigue_trigger = yes
								}
							}
							additive_modifier = {
								value = 10

								OR = {
									has_focus = focus_intrigue
									has_focus = focus_family
								}
							}
							additive_modifier = {
								value = 10

								OR = {
									diplomacy >= 10
									intrigue >= 10
								}
							}
							additive_modifier = {
								value = 10

								OR = {
									diplomacy >= 15
									intrigue >= 15
								}
							}
							additive_modifier = {
								value = 10

								OR = {
									diplomacy >= 20
									intrigue >= 20
								}
							}

							random_list = {
								10 = {
									trigger = {
										OR = {
											has_lover = yes
											is_married = yes
										}

										NOT = {
											any_artifact = {
												artifact_type = in_honor_of_roots_beloved_3
												original_owner = { character = ROOT }
											}
										}
									}

									additive_modifier = {
										value = 10
										trait = lustful
									}
									additive_modifier = {
										value = 10
										trait = poet
									}

									random_spouse = { save_event_target_as = dedication_target }
									random_lover = { save_event_target_as = dedication_target }

									add_artifact = in_honor_of_roots_beloved_3
									new_artifact = { set_name = in_honor_of_roots_beloved_3_rename }
								}
								10 = {
									trigger = {
										any_artifact = {
											artifact_type = court_etiquette_2
										}

										NOT = {
											any_artifact = {
												artifact_type = court_etiquette_3
											}
										}
									}

									add_artifact = court_etiquette_3 # if you have volume II already!
								}

								10 = {
									trigger = {
										culture_group = indo_aryan_group

										OR = {
											trait = master_seducer
											trait = master_seductress

											AND = {
												trait = lustful
												trait = hedonist
											}
										}

										NOT = {
											any_artifact = {
												artifact_type = kama_sutra
											}
										}
									}

									add_artifact = kama_sutra
								}

								10 = {
									trigger = {
										NOT = {
											any_artifact = {
												artifact_type = the_art_of_love
												original_owner = { character = ROOT }
											}
										}
									}

									additive_modifier = {
										value = 10
										trait = lustful
									}
									additive_modifier = {
										value = 10
										trait = poet
									}
									additive_modifier = {
										value = 10
										trait = hedonist
									}
									additive_modifier = {
										value = 10
										has_lifestyle_diplomacy_trigger = yes
									}
									additive_modifier = {
										value = -5
										is_pious_trigger = yes
									}

									add_artifact = the_art_of_love

									if = {
										limit = { culture_group = latin }
										new_artifact = { set_name = the_art_of_love_rename_1 }
									}
									else = {
										new_artifact = { set_name = the_art_of_love_rename_2 }
									}
								}

								10 = {
									trigger = {
										trait = hunchback

										NOT = {
											any_artifact = {
												artifact_type = the_hunchback_of_capital
												original_owner = { character = ROOT }
											}
										}
									}

									additive_modifier = {
										value = 10
										has_lifestyle_diplomacy_trigger = yes
									}
									additive_modifier = {
										value = 10
										NOT = { trait = shy }
									}
									additive_modifier = {
										value = 10
										has_pleasant_trait_trigger = yes
									}
									additive_modifier = {
										value = 10
										trait = honest
									}

									add_artifact = the_hunchback_of_capital

									new_artifact = {
										set_name = the_hunchback_of_capital_rename
										set_description = the_hunchback_of_capital_desc_rename
									}
								}

								10 = {
									trigger = {
										NOT = {
											any_artifact = {
												artifact_type = the_iliad
											}
										}
									}

									additive_modifier = {
										value = 10
										has_lifestyle_martial_trigger = yes
									}
									additive_modifier = {
										value = 10
										has_education_martial_trigger = yes
									}
									additive_modifier = {
										value = 10
										trait = poet
									}

									add_artifact = the_iliad

									new_artifact = {
										set_description = the_iliad_desc_rename
									}
								}

								10 = {
									trigger = {
										any_artifact = {
											artifact_type = the_iliad
										}

										NOT = {
											any_artifact = {
												artifact_type = the_odyssey
											}
										}
									}

									additive_modifier = {
										value = 10
										has_lifestyle_martial_trigger = yes
									}
									additive_modifier = {
										value = 10
										has_education_martial_trigger = yes
									}
									additive_modifier = {
										value = 10
										trait = poet
									}
									additive_modifier = {
										value = 20
										OR = {
											trait = viking
											trait = pirate
											trait = ravager
											trait = sea_king
											trait = sea_queen
										}
									}

									random_artifact = {
										limit = { artifact_type = the_iliad }

										original_artifact_owner = {
											save_event_target_as = other_author
										}
									}

									add_artifact = the_odyssey

									new_artifact = {
										set_description = the_odyssey_desc_rename
									}
								}

								10 = {
									trigger = {
										NOT = {
											any_artifact = {
												artifact_type = contracts_of_the_romans
												original_owner = { character = ROOT }
											}
										}
									}

									additive_modifier = {
										value = 10
										has_education_stewardship_trigger = yes
									}
									additive_modifier = {
										value = 10
										has_lifestyle_stewardship_trigger = yes
									}

									add_artifact = contracts_of_the_romans
								}

								10 = {
									trigger = {
										NOT = {
											any_artifact = {
												artifact_type = speculum_regale
												original_owner = { character = ROOT }
											}
										}
									}

									additive_modifier = {
										value = 10
										is_smart_trigger = yes
									}
									additive_modifier = {
										value = 10
										age >= 50
									}
									additive_modifier = {
										value = 10
										age >= 70
									}

									add_artifact = speculum_regale
								}

								10 = {
									trigger = {
										rightful_religious_head_scope = { always = yes }

										NOT = {
											any_artifact = {
												artifact_type = religious_head_culture_courtesy
												original_owner = { character = ROOT }
											}
										}
									}

									additive_modifier = {
										value = 10
										is_pious_trigger = yes
									}
									additive_modifier = {
										value = 10
										trait = stubborn
									}

									add_artifact = religious_head_culture_courtesy

									new_artifact = {
										set_name = religious_head_culture_courtesy_rename
										set_description = religious_head_culture_courtesy_desc_rename
									}
								}

								10 = {
									trigger = {
										NOT = {
											any_artifact = {
												artifact_type = keeping_government_court
												original_owner = { character = ROOT }
											}
										}
									}

									additive_modifier = {
										value = 10
										is_pious_trigger = yes
									}
									additive_modifier = {
										value = 10
										trait = stubborn
									}

									add_artifact = keeping_government_court

									new_artifact = {
										set_name = keeping_government_court_rename
										set_description = keeping_government_court_desc_rename
									}
								}
							}
						}
					}
				}

				writing_about_administration = {
					set_character_flag = wrote_about_administration

					random_list = {
						10 = { # quality level 1
							trigger = { has_character_flag = decent_book_potential }

							additive_modifier = {
								value = 10
								has_bottom_tier_education_trait_trigger = yes
							}
							additive_modifier = {
								value = 10
								stewardship < 1
							}
							additive_modifier = {
								value = 10
								stewardship < 5
							}
							additive_modifier = {
								value = 10
								stewardship < 10
							}

							random_list = {
								10 = {
									trigger = {
										NOT = {
											any_artifact = {
												artifact_type = culinary_diary
												original_owner = { character = ROOT }
											}
										}
									}

									additive_modifier = {
										value = 10
										trait = stubborn
									}

									add_artifact = culinary_diary
								}
								10 = {
									trigger = {
										NOT = {
											any_artifact = {
												artifact_type = yes_I_ate_that
												original_owner = { character = ROOT }
											}
										}
									}

									additive_modifier = {
										value = 10
										trait = arbitrary
									}
									additive_modifier = {
										value = 10
										trait = gluttonous
									}
									additive_modifier = {
										value = 10
										trait = adventurer
									}
									additive_modifier = {
										value = -5
										trait = proud
									}

									add_artifact = yes_I_ate_that

									new_artifact = {
										set_description = yes_I_ate_that_desc_rename
									}
								}

								10 = {
									trigger = {
										NOT = {
											any_artifact = {
												artifact_type = the_well_dressed_chef
												original_owner = { character = ROOT }
											}
										}
									}

									additive_modifier = {
										value = 10
										trait = proud
									}
									additive_modifier = {
										value = 10
										has_fair_trait_trigger = yes
									}

									add_artifact = the_well_dressed_chef
								}

								10 = {
									trigger = {
										NOR = {
											religion = jain

											any_artifact = {
												artifact_type = big_book_of_meat
												original_owner = { character = ROOT }
											}
										}
									}

									additive_modifier = {
										value = 10
										trait = arbitrary
									}
									additive_modifier = {
										value = 10
										trait = gluttonous
									}
									additive_modifier = {
										value = 10
										trait = hunter
									}
									additive_modifier = {
										value = -5
										trait = proud
									}

									add_artifact = big_book_of_meat
								}

								10 = {
									trigger = {
										NOT = {
											any_artifact = {
												artifact_type = a_book_of_vegetables
												original_owner = { character = ROOT }
											}
										}
									}

									additive_modifier = {
										value = 10
										trait = arbitrary
									}
									additive_modifier = {
										value = 10
										trait = gluttonous
									}
									additive_modifier = {
										value = 10
										trait = hunter
									}
									additive_modifier = {
										value = -5
										trait = proud
									}

									add_artifact = a_book_of_vegetables
								}
								10 = {
									trigger = {
										NOT = {
											any_artifact = {
												artifact_type = fruits_the_book
												original_owner = { character = ROOT }
											}
										}
									}

									additive_modifier = {
										value = -5
										trait = cannibal
									}

									add_artifact = fruits_the_book

									new_artifact = {
										set_description = fruits_the_book_desc_rename
									}
								}

								10 = {
									trigger = {
										NOT = {
											any_artifact = {
												artifact_type = shoddy_recipes
												original_owner = { character = ROOT }
											}
										}
									}

									additive_modifier = {
										value = -5
										trait = administrator
									}

									add_artifact = shoddy_recipes
								}

								10 = {
									trigger = {
										NOT = {
											any_artifact = {
												artifact_type = bad_fishing_book
												original_owner = { character = ROOT }
											}
										}
									}

									add_artifact = bad_fishing_book
								}
							}
						}

						10 = { # quality level 2
							trigger = { has_character_flag = good_book_potential }

							additive_modifier = {
								value = 10
								stewardship < 15
							}
							additive_modifier = {
								value = 10
								OR = {
									has_focus = focus_business
									has_focus = focus_rulership
								}
							}

							random_list = {
								10 = {
									trigger = {
										NOT = {
											any_artifact = {
												artifact_type = decent_cookbook
												original_owner = { character = ROOT }
											}
										}
									}

									add_artifact = decent_cookbook
								}

								10 = {
									trigger = {
										NOT = {
											any_artifact = {
												artifact_type = honest_recipes
												original_owner = { character = ROOT }
											}
										}
									}

									add_artifact = honest_recipes
								}

								10 = {
									trigger = {
										OR = {
											has_education_intrigue_trigger = yes
											has_lifestyle_intrigue_trigger = yes
											intrigue >= 10
										}

										NOT = {
											any_artifact = {
												artifact_type = gastronomic_tonics
											}
										}
									}

									add_artifact = gastronomic_tonics # if intrigue/deceitful? (plot power!)
								}

								10 = {
									trigger = {
										trait = cannibal

										NOT = {
											any_artifact = {
												artifact_type = the_omnivore
											}
										}
									}

									add_artifact = the_omnivore # if cannibal
								}
							}
						}

						10 = { # quality level 3 (or 4)
							trigger = { has_character_flag = great_book_potential }

							additive_modifier = {
								value = 10
								has_lifestyle_stewardship_trigger = yes
							}
							additive_modifier = {
								value = 10
								has_education_stewardship_trigger = yes
							}
							additive_modifier = {
								value = 10

								OR = {
									has_focus = focus_business
									has_focus = focus_rulership
								}
							}
							additive_modifier = {
								value = 10
								stewardship >= 10
							}
							additive_modifier = {
								value = 10
								stewardship >= 15
							}
							additive_modifier = {
								value = 10
								stewardship >= 20
							}

							random_list = {
								10 = {
									trigger = {
										NOT = {
											any_artifact = {
												artifact_type = the_dynasty_cookbook
												original_owner = { dynasty = ROOT }
											}
										}
									}

									additive_modifier = {
										value = 10
										has_focus = focus_family
									}

									add_artifact = the_dynasty_cookbook
								}

								10 = {
									trigger = {
										NOT = {
											any_artifact = {
												artifact_type = modest_measures
												original_owner = { character = ROOT }
											}
										}
									}

									additive_modifier = {
										value = 10
										trait = temperate
									}
									additive_modifier = {
										value = 10
										trait = humble
									}

									add_artifact = modest_measures

									new_artifact = {
										set_description = modest_measures_desc_rename
									}
								}

								10 = { add_artifact = good_cookbook }

								10 = {
									trigger = {
										culture_group = latin

										NOT = {
											any_artifact = {
												artifact_type = cookbook_3_roman
											}
										}
									}

									add_artifact = cookbook_3_roman

									new_artifact = {
										set_description = cookbook_3_roman_desc_rename
									}
								}

								10 = {
									trigger = {
										culture_group = arabic

										NOT = {
											any_artifact = {
												artifact_type = cookbook_3_arabic
											}
										}
									}

									add_artifact = cookbook_3_arabic
								}

								10 = {
									trigger = {
										culture_group = chinese_group

										NOT = {
											any_artifact = {
												artifact_type = cookbook_3_chinese_group
											}
										}
									}

									add_artifact = cookbook_3_chinese_group
								}

								10 = {
									trigger = {
										culture_group = central_germanic

										NOT = {
											any_artifact = {
												artifact_type = cookbook_3_central_german
											}
										}
									}

									add_artifact = cookbook_3_central_german

									new_artifact = {
										set_description = cookbook_3_central_german_desc_rename
									}
								}

								10 = {
									trigger = {
										NOT = {
											any_artifact = {
												artifact_type = on_culture_architecture
												original_owner = { character = ROOT }
											}
										}
									}

									additive_modifier = {
										value = 10
										trait = architect
									}
									additive_modifier = {
										value = 10
										trait = organizer
									}

									add_artifact = on_culture_architecture
								}

								10 = {
									trigger = {
										NOT = {
											any_artifact = {
												artifact_type = how_to_build_a_well
												original_owner = { character = ROOT }
											}
										}
									}

									additive_modifier = {
										value = 10
										trait = architect
									}
									additive_modifier = {
										value = 10
										trait = stubborn
									}
									additive_modifier = {
										value = 10
										is_smart_trigger = yes
									}

									add_artifact = how_to_build_a_well
								}

								10 = {
									trigger = {
										NOT = {
											any_artifact = {
												artifact_type = gardens_of_planet
												original_owner = { character = ROOT }
											}
										}
									}

									additive_modifier = {
										value = -5
										NOT = { society_member_of = hermetics }
									}
									additive_modifier = {
										value = 10
										trait = gardener
									}

									add_artifact = gardens_of_planet

									new_artifact = {
										set_name = gardens_of_planet_rename
									}
								}

								10 = {
									trigger = {
										NOT = {
											any_artifact = {
												artifact_type = treatise_on_fishing
												original_owner = { character = ROOT }
											}
										}
									}

									additive_modifier = {
										value = 10
										trait = hunter
									}
									additive_modifier = {
										value = 10
										trait = falconer
									}
									additive_modifier = {
										value = 10
										trait = gardener
									}

									add_artifact = treatise_on_fishing
								}
							}
						}
					}
				}

				writing_about_religion = {
					set_character_flag = wrote_about_religion

					random_list = {
						10 = { # quality level 1
							trigger = { has_character_flag = decent_book_potential }

							additive_modifier = {
								value = 10
								learning < 1
							}
							additive_modifier = {
								value = 10
								learning < 5
							}
							additive_modifier = {
								value = 10
								learning < 10
							}
							additive_modifier = {
								value = 10
								has_bottom_tier_education_trait_trigger = yes
							}

							random_list = {
								10 = {
									trigger = {
										NOT = {
											any_artifact = {
												artifact_type = in_honor_of_highgod
												original_owner = { character = ROOT }
											}
										}
									}

									add_artifact = in_honor_of_highgod
								}

								10 = {
									trigger = {
										NOT = {
											any_artifact = {
												artifact_type = faith_eternal
												original_owner = { character = ROOT }
											}
										}
									}

									add_artifact = faith_eternal
								}

								10 = {
									trigger = {
										OR = {
											is_monastic_member_trigger = yes
											religion_group = christian
											religion_group = indian_group
										}

										NOT = {
											any_artifact = {
												artifact_type = what_do_monks_wear
												original_owner = { character = ROOT }
											}
										}
									}

									add_artifact = what_do_monks_wear
								}

								10 = {
									trigger = {
										NOT = {
											any_artifact = {
												artifact_type = learning_languages_1
												original_owner = { character = ROOT }
											}
										}
									}

									add_artifact = learning_languages_1
								}

								10 = {
									trigger = {
										NOT = {
											any_artifact = {
												artifact_type = choice_passages
												original_owner = { character = ROOT }
											}
										}
									}

									add_artifact = choice_passages
								}
							}
						}
						10 = { # quality level 2
							trigger = { has_character_flag = good_book_potential }

							additive_modifier = {
								value = 10
								learning < 15
							}
							additive_modifier = {
								value = 10

								OR = {
									has_focus = focus_theology
									has_focus = focus_scholarship
								}
							}

							random_list = {
								10 = {
									trigger = {
										NOT = {
											any_artifact = {
												artifact_type = hymns_to_highgod
												original_owner = { character = ROOT }
											}
										}
									}

									additive_modifier = {
										value = 10
										trait = poet
									}

									add_artifact = hymns_to_highgod
								}

								10 = {
									trigger = {
										NOT = {
											any_artifact = {
												artifact_type = learning_languages_2
												original_owner = { character = ROOT }
											}
										}
									}

									add_artifact = learning_languages_2
								}

								10 = {
									trigger = {
										NOT = {
											any_artifact = {
												artifact_type = unnatural_history
												original_owner = { character = ROOT }
											}
										}
									}

									additive_modifier = {
										value = 10
										trait = hedonist
									}
									additive_modifier = {
										value = 10
										trait = drunkard
									}
									additive_modifier = {
										value = 10
										trait = depressed
									}
									additive_modifier = {
										value = 10
										is_impious_trigger = yes
									}
									additive_modifier = {
										value = 10
										is_devil_worshiper_trigger = yes
									}
									additive_modifier = {
										value = 10
										age >= 60
									}

									add_artifact = unnatural_history
								}

								10 = {
									trigger = {
										NOT = {
											any_artifact = {
												artifact_type = human_anatomy
												original_owner = { character = ROOT }
											}
										}
									}

									additive_modifier = {
										value = 20
										trait = cannibal
									}
									additive_modifier = {
										value = 20
										trait = physician
									}
									additive_modifier = {
										value = 10
										trait = impaler
									}
									additive_modifier = {
										value = 10
										trait = erudite
									}
									additive_modifier = {
										value = 10
										has_lifestyle_learning_trigger = yes
									}
									additive_modifier = {
										value = 10
										has_lifestyle_intrigue_trigger = yes
									}
									additive_modifier = {
										value = 10
										has_education_intrigue_trigger = yes
									}

									add_artifact = human_anatomy
								}

								10 = {
									trigger = {
										NOT = {
											any_artifact = {
												artifact_type = maladies_and_remedies
												original_owner = { character = ROOT }
											}
										}
									}

									additive_modifier = {
										value = 10
										trait = physician
									}
									additive_modifier = {
										value = 10
										trait = erudite
									}
									additive_modifier = {
										value = 10
										has_lifestyle_learning_trigger = yes
									}
									additive_modifier = {
										value = 10
										has_lifestyle_intrigue_trigger = yes
									}
									additive_modifier = {
										value = 10
										has_education_intrigue_trigger = yes
									}

									add_artifact = maladies_and_remedies
								}

								10 = {
									trigger = {
										any_courtier = {
											culture = horse
										}

										NOT = {
											any_artifact = {
												artifact_type = equine_maxims
												original_owner = { character = ROOT }
											}
										}
									}

									additive_modifier = {
										value = 10
										culture = horse
									}
									additive_modifier = {
										value = 30

										any_courtier = {
											culture = horse
										}
									}
									additive_modifier = {
										value = 10

										any_courtier = {
											count >= 2

											culture = horse
										}
									}

									random_courtier = {
										limit = { culture = horse }
										save_event_target_as = dedication_target
									}

									add_artifact = equine_maxims

									new_artifact = {
										set_name = equine_maxims_rename
									}
								}
							}
						}

						10 = { # quality level 3 (or 4)
							trigger = { has_character_flag = great_book_potential }

							additive_modifier = {
								value = 10
								has_lifestyle_learning_trigger = yes
							}
							additive_modifier = {
								value = 10
								has_education_learning_trigger = yes
							}
							additive_modifier = {
								value = 10
								is_monastic_member_trigger = yes
							}
							additive_modifier = {
								value = 10

								OR = {
									has_focus = focus_theology
									has_focus = focus_scholarship
								}
							}
							additive_modifier = {
								value = 10
								learning >= 10
							}
							additive_modifier = {
								value = 10
								learning >= 15
							}
							additive_modifier = {
								value = 10
								learning >= 20
							}

							random_list = {
								10 = {
									trigger = {
										NOT = {
											any_artifact = {
												artifact_type = a_history_of_churches
												original_owner = { character = ROOT }
											}
										}
									}

									additive_modifier = {
										value = 10
										trait = architect
									}

									add_artifact = a_history_of_churches
								}

								10 = {
									trigger = {
										NOT = {
											any_artifact = {
												artifact_type = how_to_worship
												original_owner = { character = ROOT }
											}
										}
									}

									add_artifact = how_to_worship
								}

								10 = {
									trigger = {
										trait = lunatic

										NOT = {
											any_artifact = { artifact_type = the_not_actual_holy_book }
										}
									}

									additive_modifier = {
										value = 10
										trait = lunatic
									}
									additive_modifier = {
										value = 10
										trait = possessed
									}

									add_artifact = the_not_actual_holy_book # lunatic only
								}

								10 = {
									trigger = {
										religion_group = pagan_group

										NOT = {
											any_artifact = {
												artifact_type = the_spirits
												original_owner = { character = ROOT }
											}
										}
									}

									add_artifact = the_spirits
								}

								10 = {
									trigger = {
										NOT = {
											any_artifact = {
												artifact_type = learning_languages_3
												original_owner = { character = ROOT }
											}
										}
									}

									add_artifact = learning_languages_3
								}

								10 = {
									trigger = {
										NOT = {
											any_artifact = {
												artifact_type = learning_languages_4
												original_owner = { character = ROOT }
											}
										}
									}

									add_artifact = learning_languages_4
								}

								10 = {
									trigger = {
										NOT = {
											any_artifact = {
												artifact_type = the_republic
												original_owner = { character = ROOT }
											}
										}
									}

									add_artifact = the_republic

									new_artifact = {
										set_name = the_republic_rename
									}
								}

								10 = {
									trigger = {
										NOT = {
											any_artifact = {
												artifact_type = the_confessions_of_root
												original_owner = { character = ROOT }
											}
										}
									}

									additive_modifier = {
										value = -3
										trait = drunkard
									}
									additive_modifier = {
										value = -3
										trait = depressed
									}
									additive_modifier = {
										value = 10
										is_pious_trigger = yes
									}
									additive_modifier = {
										value = 10
										is_monastic_member_trigger = yes
									}
									additive_modifier = {
										value = 10
										age >= 40
									}

									add_artifact = the_confessions_of_root
								}

								10 = {
									trigger = {
										culture_group = arabic

										NOT = {
											any_artifact = {
												artifact_type = the_book_of_healing
												original_owner = { character = ROOT }
											}
										}
									}

									additive_modifier = {
										value = -5
										is_learned_trigger = yes
									}
									additive_modifier = {
										value = 10
										is_pious_trigger = yes
									}
									additive_modifier = {
										value = 10

										OR = {
											is_monastic_member_trigger = yes
											society_member_of = hermetics
										}
									}
									additive_modifier = {
										value = 10
										age = 40
									}
									additive_modifier = {
										value = 5
										has_lifestyle_learning_trigger = yes
									}
									additive_modifier = {
										value = 5
										has_education_learning_trigger = yes
									}

									add_artifact = the_book_of_healing
								}

								10 = {
									trigger = {
										OR = {
											trait = stressed
											trait = depressed
										}

										NOT = {
											any_artifact = {
												artifact_type = comforting_poetry
												original_owner = { character = ROOT }
											}
										}
									}

									additive_modifier = {
										value = 20
										trait = poet
									}
									additive_modifier = {
										value = 10
										trait = stressed
									}
									additive_modifier = {
										value = 20
										trait = depressed
									}

									add_artifact = comforting_poetry
								}

								10 = {
									trigger = {
										any_courtier = {
											culture = horse
										}

										NOT = {
											any_artifact = {
												artifact_type = comforting_poetry
												original_owner = { character = ROOT }
											}
										}
									}

									additive_modifier = {
										value = 20
										has_education_stewardship_trigger = yes
									}
									additive_modifier = {
										value = 10
										trait = stressed
									}
									additive_modifier = {
										value = 10
										culture = horse
									}
									additive_modifier = {
										value = 10
										any_courtier = { culture = horse }
									}

									add_artifact = equine_sequins
								}
							}
						}
					}
				}

				writing_about_dynasty = {
					set_character_flag = wrote_about_dynasty

					random_list = {
						10 = { # quality level 1
							trigger = { has_character_flag = decent_book_potential }

							random_list = {
								10 = {
									trigger = {
										NOT = {
											any_artifact = {
												artifact_type = to_my_descendants
												original_owner = { character = ROOT }
											}
										}
									}

									add_artifact = to_my_descendants
								}

								10 = {
									trigger = {
										NOT = {
											any_artifact = {
												artifact_type = the_legend_of_roots_ancestors_1
												original_owner = { character = ROOT }
											}
										}
									}

									add_artifact = the_legend_of_roots_ancestors_1
								}
							}
						}

						10 = { # quality level 2
							trigger = { has_character_flag = good_book_potential }

							random_list = {
								10 = {
									trigger = {
										NOT = {
											any_artifact = {
												artifact_type = records_of_roots_dynasty
												original_owner = { character = ROOT }
											}
										}
									}

									add_artifact = records_of_roots_dynasty
								}

								10 = {
									trigger = {
										NOT = {
											any_artifact = {
												artifact_type = the_legend_of_roots_ancestors_2
												original_owner = { character = ROOT }
											}
										}
									}

									add_artifact = the_legend_of_roots_ancestors_2
								}
							}
						}
						10 = { # quality level 3 (or 4)
							trigger = { has_character_flag = great_book_potential } # trigger for the following randomlist (certain quality needed)...

							random_list = {
								10 = {
									trigger = {
										NOT = {
											any_artifact = {
												artifact_type = the_legend_of_roots_ancestors_3
												original_owner = { character = ROOT }
											}
										}
									}

									add_artifact = the_legend_of_roots_ancestors_3
								}

								10 = {

									trigger = {
										NOT = {
											any_artifact = { artifact_type = a_story_about_my_aunt }
										}
									}

									additive_modifier = {
										value = 10

										any_dynasty_member = {
											trait = adventurer
										}
									}
									additive_modifier = {
										value = 5
										trait = poet
									}
									additive_modifier = { # If you actually have an aunt...
										value = 10

										any_dynasty_member = {
											is_female = yes
											is_aunt_uncle_of = ROOT
											NOT = { is_married = ROOT }
										}
									}

									add_artifact = a_story_about_my_aunt
								}

								10 = {
									trigger = {
										NOT = {
											any_artifact = {
												artifact_type = the_dynasty_cookbook
												original_owner = { dynasty = ROOT }
											}
										}
									}

									additive_modifier = {
										value = 10
										trait = gluttonous
									}
									additive_modifier = {
										value = 10
										trait = hedonist
									}
									additive_modifier = {
										value = 10
										trait = drunkard
									}

									add_artifact = the_dynasty_cookbook
								}

								10 = {
									trigger = {
										NOT = {
											any_artifact = {
												artifact_type = the_annals_of_roots_dynasty
												original_owner = { character = ROOT }
											}
										}
									}

									additive_modifier = {
										value = 10
										trait = proud
									}

									add_artifact = the_annals_of_roots_dynasty
								}

								10 = {
									trigger = {
										any_owned_bloodline = {
											has_bloodline_flag = legendary_warrior_lodge_bloodline
											founder = { character = ROOT }
										}

										NOT = {
											any_artifact = {
												artifact_type = the_legendary_dynasty_warrior
												original_owner = { character = ROOT }
											}
										}
									}

									additive_modifier = {
										value = 10
										trait = brave
									}
									additive_modifier = {
										value = 10
										is_member_of_any_warrior_lodge_trigger = yes
									}
									additive_modifier = {
										value = 10
										prestige = 500
									}

									add_artifact = the_legendary_dynasty_warrior # about you!

									new_artifact = {
										set_name = the_legendary_dynasty_warrior_root
									}
								}

								10 = {
									trigger = {
										any_owned_bloodline = {
											has_bloodline_flag = legendary_warrior_lodge_bloodline
											founder = { NOT = { character = ROOT } }
										}

										NOT = {
											any_artifact = {
												artifact_type = the_legendary_dynasty_warrior
												original_owner = { character = ROOT }
											}
										}
									}

									additive_modifier = {
										value = 10
										trait = brave
									}
									additive_modifier = {
										value = 10
										is_member_of_any_warrior_lodge_trigger = yes
									}
									additive_modifier = {
										value = 10
										prestige = 500
									}

									random_owned_bloodline = {
										limit = { has_bloodline_flag = legendary_warrior_lodge_bloodline }
										founder = { save_event_target_as = warrior_relative }
									}

									add_artifact = the_legendary_dynasty_warrior # about a relative

									new_artifact = {
										set_name = the_legendary_dynasty_warrior_not_root
										set_description = the_legendary_dynasty_warrior_desc_not_root
									}
								}

								10 = {
									trigger = {
										any_owned_bloodline = {
											has_bloodline_flag = saintly_bloodline
											founder = { religion = ROOT }
										}

										NOT = {
											any_artifact = {
												artifact_type = the_saintly_relative
												original_owner = { character = ROOT }
											}
										}
									}

									additive_modifier = {
										value = 10
										trait = zealous
									}
									additive_modifier = {
										value = 10
										is_christian_monastic_member_trigger = yes
									}
									additive_modifier = {
										value = 10
										trait = celibate
									}

									random_owned_bloodline = {
										limit = { has_bloodline_flag = saintly_bloodline }
										founder = { save_event_target_as = saintly_relative }
									}

									add_artifact = the_saintly_relative

									new_artifact = {
										set_name = the_saintly_relative_1 # contains event-target, so need to be "set"
										set_description = the_saintly_relative_desc
									}
								}

								10 = {
									trigger = {
										NOT = {
											any_artifact = {
												artifact_type = the_secret_history_of_culture
												original_owner = { character = ROOT }
											}
										}
									}

									additive_modifier = {
										value = 10
										trait = proud
									}
									additive_modifier = {
										value = 10
										culture = mongol
									}

									add_artifact = the_secret_history_of_culture
								}
							}
						}
					}
				}
			}

			new_artifact = {
				save_event_target_as = new_book # for effects and localization purposes!
			}
		}
	}

	option = { # How swell!
		name = {
			text = EVTOPTA_JD_10070_A # I suppose we got a little sidetracked...
			trigger = {
				event_target:new_book = { quality == 1 }
				NOT = { trait = lunatic }
			}
		}
		name = {
			text = EVTOPTA_JD_10070_B # I felt inspired...!
			trigger = {
				event_target:new_book = { quality == 2 }
				NOT = { trait = lunatic }
			}
		}
		name = {
			text = EVTOPTA_JD_10070_C # It was all worth the hard work.
			trigger = {
				event_target:new_book = { quality >= 3 }
				NOR = {
					trait = lunatic
					trait = poet
				}
			}
		}
		name = {
			text = EVTOPTA_JD_10070_great_poet # Perhaps I have found my calling?
			trigger = {
				event_target:new_book = { quality >= 3 }
				NOT = { trait = lunatic }
				trait = poet
			}
		}
		name = {
			text = EVTOPTA_JD_10070_lunatic # Should've dedicated it to demons in my head...
			trigger = { trait = lunatic }
		}
		name = {
			text = EVTOPTA_JD_10070_dying # At least we finished it before I died!
			trigger = {
				OR = {
					practical_age >= 75

					AND = {
						is_ill = yes
						NOT = { has_character_flag = disease_not_serious }
					}
				}

				NOT = { trait = lunatic }
			}
		}

		custom_tooltip = { text = new_book_added_tt }

		if = { # Add some prestige...
			limit = {
				event_target:new_book = { quality < 2 }
			}
			prestige = 20
		}
		else_if = {
			limit = {
				event_target:new_book = { quality == 2 }
			}
			prestige = 50
		}
		else = {
			prestige = 100
		}

		if = { # add opinion bonus with the correct targets...
			limit = { event_target:dedication_target = { always = yes } }

			if = {
				limit = {
					event_target:dedication_target = {
						OR = {
							is_lover = ROOT
							is_married = ROOT
						}
					}
				}

				reverse_opinion = {
					name = opinion_flattered
					who = event_target:dedication_target
					years = 20
				}
			}
			else_if = {
				limit = {
					event_target:dedication_target = {
						is_rival = ROOT
					}
				}

				reverse_opinion = {
					name = opinion_strangely_flattered
					who = event_target:dedication_target
					years = 20
				}
			}

		}
	}

	after = { # Clear and set all relevant flags...
		if = {
			limit = {
				has_character_flag = wrote_about_battle
				has_character_flag = wrote_about_relationships
				has_character_flag = wrote_about_administration
				has_character_flag = wrote_about_religion
				has_character_flag = wrote_about_dynasty
			}

			set_character_flag = has_explored_all_topics
		}

		clr_character_flag = writing_about_battle
		clr_character_flag = writing_about_relationships
		clr_character_flag = writing_about_administration
		clr_character_flag = writing_about_religion
		clr_character_flag = writing_poetry
		clr_character_flag = writing_about_dynasty
		clr_character_flag = decent_book_potential
		clr_character_flag = good_book_potential
		clr_character_flag = great_book_potential
		clr_character_flag = hide_martial_this_time
		clr_character_flag = hide_relationships_this_time
		clr_character_flag = hide_administration_this_time
		clr_character_flag = hide_learning_this_time
		clr_character_flag = currently_working_on_a_book

		add_character_modifier = {
			name = uninspired
			years = 20
		}

		hidden_effect = {
			remove_character_modifier = writing_a_book
		}
	}
}

### Protect your Horse ###
character_event = {
	id = JD.60008
	desc = evt_DESC_JD_60008
	border = GFX_event_normal_frame_economy
	picture = GFX_evt_courier
	portrait = event_target:glitterhoof

	picture = {
		picture = GFX_evt_horse_friend
		trigger = { is_nomadic = yes }
	}
	picture = {
		picture = GFX_evt_courier
		trigger = { is_nomadic = no }
	}

	is_triggered_only = yes

	only_playable = yes

	trigger = {
		trait = lunatic

		event_target:glitterhoof = {
			NOR = {
				has_artifact = horse_armor_tier_3_golden_stallion
				has_artifact = horse_armor_tier_3_gilded_mare
				has_artifact = horse_armor_tier_3_ornate_steed
				has_artifact = horse_armor_tier_2
				has_artifact = horse_armor_tier_1
			}
		}
	}

	option = {
		name = evt_OPTA_JD_60008

		scaled_wealth = {
			value = -2
			min = -200
			max = -400
		}

		prestige = 300

		event_target:glitterhoof = {
			show_scope_change = no

			random_list = {
				50 = {
					trigger = { is_female = no }
					add_artifact = horse_armor_tier_3_golden_stallion
				}

				50 = {
					trigger = { is_female = yes }
					add_artifact = horse_armor_tier_3_gilded_mare
				}

				50 = {
					add_artifact = horse_armor_tier_3_ornate_steed
				}
			}
		}
	}

	option = {
		name = evt_OPTB_JD_60008

		scaled_wealth = {
			value = -1
			min = -100
			max = -200
		}

		prestige = 200

		event_target:glitterhoof = {
			show_scope_change = no

			add_artifact = horse_armor_tier_2
		}
	}

	option = {
		name = evt_OPTC_JD_60008

		scaled_wealth = {
			value = -0.5
			min =  -50
			max = -100
		}

		prestige = 100

		event_target:glitterhoof = {
			show_scope_change = no

			add_artifact = horse_armor_tier_1
		}
	}

	option = {
		name = evt_OPTD_JD_60008
	}
}


### A Chinese Prince/Princess has died - Sends event to spouse or child ### (fired from on_death)
character_event = {
	id = JD.10080

	hide_window = yes
	is_triggered_only = yes # on_death

	has_dlc = "Jade Dragon"

	trigger = {
		NOT = {
			offmap_china = {
				has_policy = china_isolationist
			}
		}

		NAND = {
			killer = { character = liege }

			OR = { # make sure China doesn't know they were actually murdered by you
				death_murder_known_trigger = yes
				death_execution_trigger = yes
				death_sacrificed_trigger = yes
				death_reason = death_duel
				death_reason = death_dungeon
			}
		}

		OR = {
			has_character_modifier = jd_prince
			has_character_modifier = jd_princess
		}

		OR = { # Must have either a spouse or a landed child still around
			any_spouse = {
				ai = no
				is_alive = yes
				is_landed = yes
				NOT = { is_rival = ROOT }
				opinion = { who = ROOT value >= 30 } # Spouse must have liked the prince/princess at least A LITTLE
				root_has_terrible_opinion_modifier_of_this_trigger = no
			}

			any_child = {
				ai = no
				is_landed = yes
				is_alive = yes
				age >= 10
				NOT = { is_rival = ROOT }
				root_has_terrible_opinion_modifier_of_this_trigger = no
			}
		}

		had_character_flag = {
			flag = originated_from_chinese_court
			years >= 5 # If less, the regular "grace refund" event will fire instead
		}
	}

	immediate = {
		offmap_china = {
			governor = {
				save_event_target_as = the_protector_general
			}
		}

		random_list = {
			40 = { # China sends their condolences...
				trigger = {
					offmap_china = {
						offmap_ruler = {
							dynasty = ROOT
						}
					}

					OR = {
						any_spouse = {
							ai = no
							is_landed = yes
							root_has_terrible_opinion_modifier_of_this_trigger = no

							NOR = {
								is_rival = ROOT
								event_target:the_protector_general = { war_with = PREV }
							}
						}

						any_child = {
							ai = no
							age >= 10
							is_landed = yes
							root_has_terrible_opinion_modifier_of_this_trigger = no

							NOR = {
								is_rival = ROOT
								event_target:the_protector_general = { war_with = PREV }
							}
						}
					}
				}

				random_spouse = {
					limit = {
						ai = no
						is_landed = yes
						root_has_terrible_opinion_modifier_of_this_trigger = no

						NOR = {
							is_rival = ROOT
							event_target:the_protector_general = { war_with = PREV }
						}
					}

					set_character_flag = scenario_1
					set_character_flag = mourner_is_spouse
					character_event = { id = JD.10079 days = 35 }
				}

				any_child = {
					limit = {
						ai = no
						age >= 10
						is_landed = yes
						root_has_terrible_opinion_modifier_of_this_trigger = no

						NOR = {
							is_rival = ROOT
							event_target:the_protector_general = { war_with = PREV }
						}
					}

					if = {
						limit = { practical_age >= 15 }
						set_character_flag = mourner_is_grown_child
					}
					else = {
						set_character_flag = mourner_is_small_child
					}

					set_character_flag = scenario_1

					character_event = { id = JD.10079 days = 35 }
				}
			}

			30 = { # China sends you an artifact
				trigger = {
					offmap_china = {
						offmap_ruler = {
							dynasty = ROOT
						}
					}

					OR = {
						any_spouse = {
							ai = no
							is_landed = yes
							root_has_terrible_opinion_modifier_of_this_trigger = no

							NOR = {
								is_rival = ROOT
								event_target:the_protector_general = { war_with = PREV }
							}
						}

						any_child = {
							ai = no
							age >= 10
							is_landed = yes
							root_has_terrible_opinion_modifier_of_this_trigger = no

							NOR = {
								is_rival = ROOT
								event_target:the_protector_general = { war_with = PREV }
							}
						}
					}
				}

				add_chinese_artifact_effect = yes

				while = { # runs until it finds an appropriate artifact...
					limit = {
						event_target:chinese_artifact = {
							NOR = {
								has_artifact_flag = decor
								has_artifact_flag = statue
								has_artifact_flag = art
								has_artifact_flag = clothing
								has_artifact_flag = textile
							}
						}
					}

					event_target:chinese_artifact = {
						destroy_artifact = yes
					}

					add_chinese_artifact_effect = yes
				}

				event_target:chinese_artifact = {
					set_name = the_chinese_royals_favorite
					set_description = the_chinese_royals_favorite_desc
					set_artifact_flag = royal_inheritance_gift@ROOT

					transfer_artifact = {
						from = PREV
						to = event_target:the_protector_general
					}
				}

				random_spouse = {
					limit = {
						ai = no
						is_landed = yes
						root_has_terrible_opinion_modifier_of_this_trigger = no

						NOR = {
							is_rival = ROOT
							event_target:the_protector_general = { war_with = PREV }
						}
					}

					set_character_flag = scenario_2
					set_character_flag = mourner_is_spouse

					character_event = { id = JD.10079 days = 35 }
				}

				any_child = {
					limit = {
						ai = no
						age >= 10
						is_landed = yes
						root_has_terrible_opinion_modifier_of_this_trigger = no

						NOR = {
							is_rival = ROOT
							event_target:the_protector_general = { war_with = PREV }
						}
					}

					if = {
						limit = { age >= 15 }
						set_character_flag = mourner_is_grown_child
					}
					else = {
						set_character_flag = mourner_is_small_child
					}

					set_character_flag = scenario_2

					character_event = { id = JD.10079 days = 35 }
				}
			}

			15 = { # You find a personal diary...
				mult_modifier = {
					factor = 0.5 # less likely if an alive spouse does NOT have family focus (since the prince/princess will write about their family in their journal)

					any_spouse = {
						is_landed = yes
						NOT = { has_focus = focus_family }
					}
				}
				mult_modifier = {
					factor = 1.1 # more likely if there was love between the prince/princess and their spouse

					any_spouse = {
						is_landed = yes
						is_lover = ROOT
					}
				}

				add_artifact = chinese_journal

				new_artifact = {
					save_event_target_as = chinese_artifact
				}

				event_target:chinese_artifact = {
					set_name = the_chinese_royals_personal_note_book
					set_description = the_chinese_royals_personal_note_book_desc
					set_artifact_flag = royal_inheritance_gift@ROOT

					transfer_artifact = {
						from = PREV
						to = event_target:the_protector_general
					}
				}

				random_spouse = {
					limit = {
						ai = no
						is_landed = yes
						root_has_terrible_opinion_modifier_of_this_trigger = no
						NOT = { is_rival = ROOT }
					}

					set_character_flag = scenario_3
					set_character_flag = mourner_is_spouse
					character_event = { id = JD.10079 days = 35 }
				}

				any_child = {
					limit = {
						ai = no
						is_landed = yes
						root_has_terrible_opinion_modifier_of_this_trigger = no
						NOT = { is_rival = ROOT }
					}

					if = {
						limit = { age >= 14 }
						set_character_flag = mourner_is_grown_child
					}
					else = {
						set_character_flag = mourner_is_small_child
					}

					set_character_flag = scenario_3
					character_event = { id = JD.10079 days = 35 }
				}
			}
			15 = {
				# Nothing happens (more likely if China is busy with other stuff)
				mult_modifier = {
					factor = 5
					china_is_suffering_trigger = yes
				}

				set_character_flag = nothing_happened
			}
		}
		if = {
			limit = {
				NOT = { has_character_flag = nothing_happened }
			}

			set_character_flag = ignore_refund # (blocks the other letter of condolences-event from China)
		}
	}
}

### Delayed gating event to make sure the Protector General is still alive, and still has the artifact
# Sent on target character, from JD.10080
character_event = {
	id = JD.10079

	hide_window = yes
	is_triggered_only = yes

	has_dlc = "Jade Dragon"

	immediate = {
		if = {  # for loc + artifact purposes
			limit = {
				event_target:the_protector_general = { is_alive = no }
			}

			offmap_china = {
				governor = { save_event_target_as = the_protector_general }
			}
		}

		### Fall-back clearing of flags (if at war with WP already)...
		if = {
			limit = { event_target:the_protector_general = { war_with = ROOT } }

			if = {
				limit = { has_character_flag = scenario_2 }
				# to make sure the WP doesn't end up with a ton of Chinese artifacts (named things like "Shan Li's Favorite Tapestry") when the follow-up (JD.10082) doesn't trigger...
				event_target:chinese_artifact = { destroy_artifact = yes }
			}

			if = {
				limit = { NOT = { has_character_flag = scenario_3 } } # The only event that doesn't require peace with WP...
				clr_character_flag = mourner_is_spouse
				clr_character_flag = mourner_is_grown_child
				clr_character_flag = mourner_is_small_child
				clr_character_flag = scenario_1
				clr_character_flag = scenario_2
				clr_character_flag = scenario_3
			}
		}

		trigger_switch = {
			on_trigger = has_character_flag

			scenario_1 = { ### (1) If you are to receive a letter...
				character_event = { id = JD.10081 }
			}

			scenario_2 = { ### (2) If you are to be gifted a Chinese artifact...
				if = { # if the artifact still exists in the treasury of the WP... (even if the Protector General might've died, but HOPEFULLY they inherited the thing?)
					limit = {
						event_target:the_protector_general = {
							any_artifact = { has_artifact_flag = royal_inheritance_gift@FROM }
						}
					}

					character_event = { id = JD.10082 } # Continue and send scenario 2...!
				}
				else = {
					character_event = { id = JD.10081 } # else, send scenario 1 instead...
				}
			}

			scenario_3 = { ### (3) If you are to find a personal journal...
				if = { # if the artifact still exists in the treasury of the WP... (even if the Protector General might've died, but HOPEFULLY they inherited the thing?)
					limit = {
						event_target:the_protector_general = {
							any_artifact = { has_artifact_flag = royal_inheritance_gift@FROM }
						}
					}

					character_event = { id = JD.10083 }  # Continue and send scenario 3...!
				}
				else = {
					character_event = { id = JD.10081 } # else, send scenario 1 instead...
				}
			}
		}
	}
}

### For a spouse or child ###
character_event = { # China sends their condolences, in the form of a LETTER...
	id = JD.10081
	desc = EVTDESC_JD_10081
	picture = GFX_evt_chinese_bureaucrat
	border = GFX_event_normal_frame_diplomacy
	portrait = FROMFROM

	is_triggered_only = yes

	has_dlc = "Jade Dragon"

	# Basically, if you are Depressed, you get to choose between a shot at losing Depressed
	# or some Grace. If you are NOT Depressed, there is a risk you will gain the trait instead, if you choose to read the letter.

	option = {
		name = EVTOPTA_JD_10081

		custom_tooltip = { text = EVTOPTA_JD_10081_TT }

		random = {
			chance = 50
			add_trait_depressed_effect = yes
		}

		add_grace_minor_effect = yes
	}

	option = {
		name = {
			text = EVTOPTB_JD_10081_depressed
			trigger = { trait = depressed }
		}
		name = {
			text = EVTOPTB_JD_10081_regular
			trigger = { NOT = { trait = depressed } }
		}

		if = {
			limit = { trait = depressed }

			custom_tooltip = { text = EVTOPTB_JD_10081_TT }

			random = {
				chance = 50
				remove_trait_depressed_effect = yes
			}
		}
	}

	after = {
		clr_character_flag = mourner_is_spouse
		clr_character_flag = mourner_is_grown_child
		clr_character_flag = mourner_is_small_child
		clr_character_flag = scenario_1
		clr_character_flag = scenario_2
		clr_character_flag = scenario_3
	}
}

### For a spouse or child ###
character_event = { # China sends their condolences, in the form of a GIFT...
	id = JD.10082
	desc = EVTDESC_JD_10082
	picture = GFX_evt_chinese_bureaucrat
	border = GFX_event_normal_frame_diplomacy
	portrait = FROMFROM

	is_triggered_only = yes

	has_dlc = "Jade Dragon"

	# Basically, if you are Depressed, you get to choose between a shot at losing Depressed
	# or an artifact. If you are NOT Depressed, there is a risk you will gain the trait instead, if you choose to accept the gift.
	option = {
		name = EVTOPTA_JD_10082

		custom_tooltip = { text = EVTOPTA_JD_10082_TT }

		hidden_effect = {
			event_target:chinese_artifact = {
				transfer_artifact = {
					from = event_target:the_protector_general
					to = ROOT
				}
			}
		}

		random = {
			chance = 50
			add_trait_depressed_effect = yes
		}
	}

	option = {
		name = EVTOPTB_JD_10082

		custom_tooltip = { text = EVTOPTB_JD_10082_TT }

		random = {
			chance = 50
			remove_trait_depressed_effect = yes
		}

		hidden_effect = {
			event_target:chinese_artifact = {
				destroy_artifact = yes
			}
		}
	}

	after = {
		clr_character_flag = mourner_is_spouse
		clr_character_flag = mourner_is_grown_child
		clr_character_flag = mourner_is_small_child
		clr_character_flag = scenario_1
		clr_character_flag = scenario_2
		clr_character_flag = scenario_3
	}
}


### For a spouse or child ###
character_event = { # You find their journal...
	id = JD.10083
	desc = EVTDESC_JD_10083
	picture = GFX_evt_library
	border = GFX_event_normal_frame_diplomacy
	portrait = FROMFROM

	is_triggered_only = yes

	has_dlc = "Jade Dragon"

	option = {
		name = EVTOPTA_JD_10083

		custom_tooltip = { text = EVTOPTA_JD_10083_TT }

		hidden_effect = {
			event_target:chinese_artifact = {
				transfer_artifact = {
					from = event_target:the_protector_general
					to = ROOT
				}
			}
		}
	}

	option = {
		name = EVTOPTB_JD_10083

		custom_tooltip = { text = EVTOPTB_JD_10083_TT }

		add_trait_fully_silently_cynical_effect = yes

		hidden_effect = {
			event_target:chinese_artifact = {
				destroy_artifact = yes
			}
		}
	}

	after = {
		clr_character_flag = mourner_is_spouse
		clr_character_flag = mourner_is_grown_child
		clr_character_flag = mourner_is_small_child
		clr_character_flag = scenario_1
		clr_character_flag = scenario_2
		clr_character_flag = scenario_3
	}
}
