﻿namespace = author_book

### Author Book - Poetry
author_book.0001 = {
	type = character_event
	title = author_book.0001.t
	desc = author_book.0001.desc
	theme = realm
	override_background = { reference = study }
	
	left_portrait = {
		character = root
		animation = writing
	}

	immediate = {
		generate_ci_poem_title_effect = yes
		if = {
			limit = {
				num_of_relation_elder > 0
			}
			random_relation = { 
				type = elder
				save_scope_as = trusted_influencer
			}
		}
		else_if = {
			limit = {
				num_of_relation_disciple > 0
			}
			random_relation = { 
				type = disciple
				save_scope_as = trusted_influencer
			}
		}
		else_if = {
			limit = {
				exists = primary_spouse
			}
			primary_spouse = {
				save_scope_as = trusted_influencer
			}
		}
		else_if = {
			limit = {
				any_close_family_member = {
					count > 0
					is_physically_able_adult = yes
				}
			}
			random_close_family_member = {
				limit = {
					is_physically_able_adult = yes
				}
				save_scope_as = trusted_influencer
			}
		}
		else_if = {
			limit = {
				any_courtier = {
					is_physically_able_adult = yes
				}
			}
			random_courtier = {
				limit = {
					has_any_mild_good_relationship_with_character_trigger = {
						CHARACTER = ROOT
					}
				}
				alternative_limit = {
					is_physically_able_adult = yes
				}
				save_scope_as = trusted_influencer
			}
		}
		else = { #We only get here if there are no physically able adults in your own court.
			top_liege = {
				random_vassal = {
					limit = {
						has_any_mild_good_relationship_with_character_trigger = {
							CHARACTER = ROOT
						}
					}
					alternative_limit = {
						is_physically_able_adult = yes
					}
					save_scope_as = trusted_influencer
				}
			}
		}
	}

	option = { 
		name = author_book.0001.a #I will choose this tune!
		add_prestige = minor_prestige_gain
		custom_tooltip = author_book.0001.a.tt
		save_scope_value_as = {
			name = topic
			value = flag:poem_own
		}
	}
	option = { 
		name = author_book.0001.b #I will let my elder/spouse/other select one
		custom_tooltip = author_book.0001.b.tt
		scope:trusted_influencer = {
			add_opinion = {
				opinion = 30
				modifier = paid_me_respect
				target = root
			}
		}
		save_scope_value_as = {
			name = topic
			value = flag:poem_friend
		}
	}
	after = {
		trigger_event = {
			id = author_book.1000
			days = 5 
		}
		stress_impact = {
			base = minor_stress_impact_gain
			lazy = minor_stress_impact_gain
			lifestyle_poet = minor_stress_impact_loss #offsets penalty a bit
		}
	}
}

#Author Book Prose
author_book.0004 = {
	type = character_event
	title = author_book.0004.t
	desc = author_book.0004.desc
	theme = realm
	
	override_background = {

		reference = study
	}
	

	left_portrait = {
		character = root
		animation = writing #We change the background in each event but not the animation, the background is what root is writing about
	}


	immediate = {
		if = {
			limit = {
				num_of_relation_elder > 0
			}
			random_relation = { 
				type = elder
				save_scope_as = trusted_influencer
			}
		}
		else_if = {
			limit = {
				num_of_relation_disciple > 0
			}
			random_relation = { 
				type = disciple
				save_scope_as = trusted_influencer
			}
		}
		else_if = {
			limit = {
				exists = primary_spouse
			}
			primary_spouse = {
				save_scope_as = trusted_influencer
			}
		}
		else_if = {
			limit = {
				any_close_family_member = {
					count > 0
					is_physically_able_adult = yes
				}
			}
			random_close_family_member = {
				limit = {
					is_physically_able_adult = yes
				}
				save_scope_as = trusted_influencer
			}
		}
		else_if = {
			limit = {
				any_courtier = {
					is_physically_able_adult = yes
				}
			}
			random_courtier = {
				limit = {
					has_any_mild_good_relationship_with_character_trigger = {
						CHARACTER = ROOT
					}
				}
				alternative_limit = {
					is_physically_able_adult = yes
				}
				save_scope_as = trusted_influencer
			}
		}
		else = { #We only get here if there are no physically able adults in your own court.
			top_liege = {
				random_vassal = {
					limit = {
						has_any_mild_good_relationship_with_character_trigger = {
							CHARACTER = ROOT
						}
					}
					alternative_limit = {
						is_physically_able_adult = yes
					}
					save_scope_as = trusted_influencer
				}
			}
		}
	}

	option = { 
		name = author_book.0004.a #A Work of History
		custom_tooltip = author_book.0004.a.tt
		save_scope_value_as = {
			name = topic
			value = flag:prose_history
		}
	}
	option = { 
		name = author_book.0004.b #A Philosophical Essay
		custom_tooltip = author_book.0004.b.tt

		save_scope_value_as = {
			name = topic
			value = flag:prose_philosophy
		}
	}
	after = {
		add_character_modifier = {
			modifier = writing_prose
			months = 6
		}
		trigger_event = {
			id = author_book.1000
			months = 6
		}
		stress_impact = {
			base = medium_stress_impact_gain
			lazy = minor_stress_impact_gain
			journaller = minor_stress_impact_loss #offsets penalty a bit
			confucian_education = minor_stress_impact_loss #offsets penalty a bit
		}
	}
}

#Author Book Scholarship
author_book.0005 = {
	type = character_event
	title = author_book.0005.t
	desc = author_book.0005.desc
	theme = realm
	
	override_background = {

		reference = study
	}

	left_portrait = {
		character = root
		animation = writing #We change the background in each event but not the animation, the background is what root is writing about
	}


	immediate = {
		if = {
			limit = {
				num_of_relation_elder > 0
			}
			random_relation = { 
				type = elder
				save_scope_as = trusted_influencer
			}
		}
		else_if = {
			limit = {
				num_of_relation_disciple > 0
			}
			random_relation = { 
				type = disciple
				save_scope_as = trusted_influencer
			}
		}
		else_if = {
			limit = {
				exists = primary_spouse
			}
			primary_spouse = {
				save_scope_as = trusted_influencer
			}
		}
		else_if = {
			limit = {
				any_close_family_member = {
					count > 0
					is_physically_able_adult = yes
				}
			}
			random_close_family_member = {
				limit = {
					is_physically_able_adult = yes
				}
				save_scope_as = trusted_influencer
			}
		}
		else_if = {
			limit = {
				any_courtier = {
					is_physically_able_adult = yes
				}
			}
			random_courtier = {
				limit = {
					has_any_mild_good_relationship_with_character_trigger = {
						CHARACTER = ROOT
					}
				}
				alternative_limit = {
					is_physically_able_adult = yes
				}
				save_scope_as = trusted_influencer
			}
		}
		else = { #We only get here if there are no physically able adults in your own court.
			top_liege = {
				random_vassal = {
					limit = {
						has_any_mild_good_relationship_with_character_trigger = {
							CHARACTER = ROOT
						}
					}
					alternative_limit = {
						is_physically_able_adult = yes
					}
					save_scope_as = trusted_influencer
				}
			}
		}
	}

	option = { 
		name = author_book.0005.a #Geography
		custom_tooltip = author_book.0005.a.tt
		save_scope_value_as = {
			name = topic
			value = flag:monograph_geography
		}
	}
	option = { 
		name = author_book.0005.b #Mathematics
		custom_tooltip = author_book.0005.b.tt
		save_scope_value_as = {
			name = topic
			value = flag:monograph_mathematics
		}
	}
	after = {
		add_character_modifier = {
			modifier = writing_monograph
			years = 1
		}
		trigger_event = {
			id = author_book.1000
			years = 1 
		}
		stress_impact = {
			base = major_stress_impact_gain
			lazy = minor_stress_impact_gain
			journaller = minor_stress_impact_loss #offsets penalty a bit
			confucian_education = minor_stress_impact_loss #offsets penalty a bit
		}
	}
}
	


# Finish Event
author_book.1000 = {
	type = character_event
	title = author_book.1000.t
	desc = {
		#Poems
		triggered_desc = {
			trigger = {
				OR = {
					scope:topic = flag:poem_friend
					scope:topic = flag:poem_own
				}
			}
			desc = author_book.1000.poem_intro.desc
		}
		triggered_desc = {
			trigger = {
				OR = {
					scope:topic = flag:poem_friend
					scope:topic = flag:poem_own
				}
				scope:quality_of_artifact = flag:weak
			}
			desc = author_book.1000.poem_weak.desc
		}
		triggered_desc = {
			trigger = {
				OR = {
					scope:topic = flag:poem_friend
					scope:topic = flag:poem_own
				}
				scope:quality_of_artifact = flag:mid
			}
			desc = author_book.1000.poem_mid.desc
		}
		triggered_desc = {
			trigger = {
				OR = {
					scope:topic = flag:poem_friend
					scope:topic = flag:poem_own
				}
				scope:quality_of_artifact = flag:great
			}
			desc = author_book.1000.poem_great.desc
		}
		#Prose
		triggered_desc = {
			trigger = {
				OR = {
					scope:topic = flag:prose_philosophy
					scope:topic = flag:prose_history
				}
			}
			desc = author_book.1000.prose_intro.desc
		}
		triggered_desc = {
			trigger = {
				OR = {
					scope:topic = flag:prose_philosophy
					scope:topic = flag:prose_history
				}
				scope:quality_of_artifact = flag:weak
			}
			desc = author_book.1000.prose_weak.desc
		}
		triggered_desc = {
			trigger = {
				OR = {
					scope:topic = flag:prose_philosophy
					scope:topic = flag:prose_history
				}
				scope:quality_of_artifact = flag:mid
			}
			desc = author_book.1000.prose_mid.desc
		}
		triggered_desc = {
			trigger = {
				OR = {
					scope:topic = flag:prose_philosophy
					scope:topic = flag:prose_history
				}
				scope:quality_of_artifact = flag:great
			}
			desc = author_book.1000.prose_great.desc
		}
		#Scholarship
		triggered_desc = {
			trigger = {
				OR = {
					scope:topic = flag:monograph_geography
					scope:topic = flag:monograph_mathematics
				}
			}
			desc = author_book.1000.scholarship_intro.desc
		}
		triggered_desc = {
			trigger = {
				OR = {
					scope:topic = flag:monograph_geography
					scope:topic = flag:monograph_mathematics
				}
				scope:quality_of_artifact = flag:weak
			}
			desc = author_book.1000.scholarship_weak.desc
		}
		triggered_desc = {
			trigger = {
				OR = {
					scope:topic = flag:monograph_geography
					scope:topic = flag:monograph_mathematics
				}
				scope:quality_of_artifact = flag:mid
			}
			desc = author_book.1000.scholarship_mid.desc
		}
		triggered_desc = {
			trigger = {
				OR = {
					scope:topic = flag:monograph_geography
					scope:topic = flag:monograph_mathematics
				}
				scope:quality_of_artifact = flag:great
			}
			desc = author_book.1000.scholarship_great.desc
		}
	}

	theme = realm

	override_background = { #Poetry
		trigger = {
			OR = {
				scope:topic = flag:poem_friend
				scope:topic = flag:poem_own
			}
		}
		reference = relaxing_room
	}
	override_background = { #Prose
		trigger = {
			OR = {
				scope:topic = flag:prose_philosophy
				scope:topic = flag:prose_history
			}
		}
		reference = garden
	}
	override_background = { #Scholarship
		trigger = {
			OR = {
				scope:topic = flag:monograph_geography
				scope:topic = flag:monograph_mathematics
			}
		}
		reference = courtyard
	}
	
	left_portrait = {
		character = root
		animation = writing #We change the background in each event but not the animation, the background is what root is writing about
	}
	right_portrait = { # An elder, or other influencer
		character = scope:trusted_influencer
		animation = admiration
	}
	artifact = { # To display the artifact in the event-window
		trigger = { exists = scope:newly_created_artifact }
		target = scope:newly_created_artifact
		position = lower_right_portrait
	}

	immediate = {
		save_scope_as = author
		#First we make the artifact, then we assign effects and descriptions.
		hidden_effect = {
			if = { #Are we writing a poem?
				limit = {
					OR = {
						scope:topic = flag:poem_friend
						scope:topic = flag:poem_own
					}
				}
				if = {
					limit = {
						scope:topic = flag:poem_friend
					}
					generate_ci_poem_title_effect = yes #We need a title
				}
				create_artifact = {
					name = ci_poem_name
					type = miscellaneous
					creator = root
					description = TODO #This is replaced below
					visuals = scroll
					modifier = artifact_placeholder_modifier
					save_scope_as = newly_created_artifact
					wealth = 50
					quality = 50
				}
			}
			else = { #For Prose and Scholarship we generate a book artifact
				if = {
					limit = {
						artifacts_use_indian_books_trigger = yes
					}
					create_artifact = {
						name = TODO #This is replaced below
						type = journal
						creator = root
						description = TODO #This is replaced below
						visuals = indian_book
						modifier = artifact_placeholder_modifier
						save_scope_as = newly_created_artifact
						wealth = 50
						quality = 50
					}
				}
				else = {
					create_artifact = {
						name = TODO #This is replaced below
						type = journal
						creator = root
						description = TODO #This is replaced below
						visuals = book
						modifier = artifact_placeholder_modifier
						save_scope_as = newly_created_artifact
						wealth = 50
						quality = 50
					}
				}
			}
		}

		#Common effect for adding modifiers!
		hidden_effect_new_object = {
			if = { #Poems
				limit = {
					OR = {
						scope:topic = flag:poem_friend
						scope:topic = flag:poem_own
					}
				}
				#First we randomize the theme:
				random_list = {
					1 = {
						save_scope_value_as = {
							name = poetry_theme
							value = flag:love
						}
						save_scope_value_as = {
							name = poetry_theme
							value = flag:nature
						}
						save_scope_value_as = {
							name = poetry_theme
							value = flag:longing
						}
						save_scope_value_as = {
							name = poetry_theme
							value = flag:separation
						}
						save_scope_value_as = {
							name = poetry_theme
							value = flag:sadness_and_pain
						}
						save_scope_value_as = {
							name = poetry_theme
							value = flag:philosophy
						}
						save_scope_value_as = {
							name = poetry_theme
							value = flag:mythological_events
						}
						save_scope_value_as = {
							name = poetry_theme
							value = flag:daily_chores
						}
						save_scope_value_as = {
							name = poetry_theme
							value = flag:daily_chores
						}
						save_scope_value_as = {
							name = poetry_theme
							value = flag:historical_events
						}
					}
				}
				#Then we decide the skill level:
				random_list = {
					33 = {
						trigger = {
							OR = {
								NOT = { has_trait = lifestyle_poet }
								AND = {
									has_trait = lifestyle_poet
									has_trait_xp = {
										trait = lifestyle_poet
										value < 60
									}
								}
							}
						}
						modifier = {
							trigger = {
								has_trait = lifestyle_poet
							}
							add = -10
						}
						modifier = {
							trigger = {
								has_trait = lifestyle_poet
								has_trait_xp = {
									trait = lifestyle_poet
									value > 20
								}
							}
							add = -10
						}
						modifier = {
							trigger = {
								has_trait = lifestyle_poet
								has_trait_xp = {
									trait = lifestyle_poet
									value > 40
								}
							}
							add = -10
						}
						save_scope_value_as = {
							name = quality_of_artifact
							value = flag:weak
						}
					}
					33 = {
						save_scope_value_as = {
							name = quality_of_artifact
							value = flag:mid
						}

					}
					33 = {
						trigger = {
							has_trait = lifestyle_poet
						}
						modifier = {
							trigger = {
								has_trait_xp = {
									trait = lifestyle_poet
									value > 40
								}
							}
							add = 10
						}
						modifier = {
							trigger = {
								has_trait_xp = {
									trait = lifestyle_poet
									value > 60
								}
							}
							add = 17
						}
						modifier = {
							trigger = {
								has_trait_xp = {
									trait = lifestyle_poet
									value > 80
								}
							}
							add = 20
						}
						save_scope_value_as = {
							name = quality_of_artifact
							value = flag:great
						}
					}
				}
				#Now we set the description:
				scope:newly_created_artifact = {
					set_artifact_description = ci_poem_description_full
					#And now we give modifiers:
					switch = {
						trigger = scope:quality_of_artifact
						flag:weak = {
							#Piety
							set_artifact_rarity_common = yes
							random_list = {
								60 = {
									add_artifact_modifier = artifact_monthly_piety_2_modifier
								}
								30 = {
									add_artifact_modifier = artifact_monthly_piety_3_modifier
								}
								10 = {
									add_artifact_modifier = artifact_monthly_piety_4_modifier
								}
							}
							random_list = {
								80 = { }
								10 = { add_artifact_modifier = artifact_stress_gain_1_modifier }
							}
						}
						flag:mid = {
							#Piety
							set_artifact_rarity_masterwork = yes
							random_list = {
								25 = {
									add_artifact_modifier = artifact_monthly_piety_2_modifier
								}
								50 = {
									add_artifact_modifier = artifact_monthly_piety_3_modifier
								}
								25 = {
									modifier = {
										add = root.learning
									}
									add_artifact_modifier = artifact_monthly_piety_4_modifier
								}
							}
							#Lifestyle XP
							random_list = {
								80 = {
									add_artifact_modifier = artifact_poetry_1_modifier
								}
								20 = {
									modifier = {
										add = root.diplomacy
									}
									add_artifact_modifier = artifact_poetry_2_modifier
								}
							}
							#Stress
							random_list = {
								70 = { }
								30 = { add_artifact_modifier = artifact_stress_gain_1_modifier }
							}
						}
						flag:great = {
							#Piety
							set_artifact_rarity_famed = yes
							random_list = {
								60 = {
									add_artifact_modifier = artifact_monthly_piety_3_modifier
								}
								40 = {
									modifier = {
										add = root.learning
									}
									add_artifact_modifier = artifact_monthly_piety_4_modifier
								}
							}
							#Lifestyle XP
							random_list = {
								30 = {
									add_artifact_modifier = artifact_poetry_1_modifier
								}
								50 = {
									add_artifact_modifier = artifact_poetry_2_modifier
								}
								20 = {
									modifier = {
										add = root.diplomacy
									}
									add_artifact_modifier = artifact_poetry_3_modifier
								}
							}

							#Stress
							add_artifact_modifier = artifact_stress_gain_1_modifier
						}
					}
				}
			}
			else_if = { #Books
				limit = {
					OR = {
						scope:topic = flag:prose_philosophy
						scope:topic = flag:prose_history
					}
				}
				#First we randomize the theme:

				random_list = {
					1 = {
						trigger = { scope:topic = flag:prose_philosophy }
						save_scope_value_as = {
							name = prose_theme 
							value = flag:commentary_on_the_four_books
						}
					}
					1 = {
						trigger = { scope:topic = flag:prose_philosophy }
						save_scope_value_as = {
							name = prose_theme 
							value = flag:logic
						}
					}
					1 = {
						trigger = { scope:topic = flag:prose_philosophy }
						save_scope_value_as = {
							name = prose_theme 
							value = flag:critiquing_opponents
						}
					}
					1 = {
						trigger = { scope:topic = flag:prose_philosophy }
						save_scope_value_as = {
							name = prose_theme 
							value = flag:sentiments
						}
					}
					1 = {
						trigger = { scope:topic = flag:prose_philosophy }
						save_scope_value_as = {
							name = prose_theme 
							value = flag:betterment
						}
					}
					1 = { #Either
						save_scope_value_as = {
							name = prose_theme 
							value = flag:human_existance
						}
					}
					1 = { #Either
						save_scope_value_as = {
							name = prose_theme 
							value = flag:prose_theme_lands_ideals
						}
					}
					1 = {
						trigger = { scope:topic = flag:prose_history }
						save_scope_value_as = {
							name = prose_theme 
							value = flag:rewriting_history
						}
					}
					1 = {
						trigger = { scope:topic = flag:prose_history }
						save_scope_value_as = {
							name = prose_theme 
							value = flag:bio
						}
					}
					1 = {
						trigger = { scope:topic = flag:prose_history }
						save_scope_value_as = {
							name = prose_theme 
							value = flag:emperor
						}
					}
				}

				#Then we decide the skill level:
				random_list = {
					33 = {
						trigger = {
							OR = {
								NOT = { has_trait = confucian_education }
								AND = {
									has_trait = confucian_education
									has_trait_xp = {
										trait = confucian_education
										value < 60
									}
								}
							}
						}
						modifier = {
							trigger = {
								has_trait = confucian_education
							}
							add = -10
						}
						modifier = {
							trigger = {
								has_trait = confucian_education
								has_trait_xp = {
									trait = confucian_education
									value > 20
								}
							}
							add = -10
						}
						modifier = {
							trigger = {
								has_trait = confucian_education
								has_trait_xp = {
									trait = confucian_education
									value > 40
								}
							}
							add = -10
						}
						save_scope_value_as = {
							name = quality_of_artifact
							value = flag:weak
						}
					}
					33 = {
						save_scope_value_as = {
							name = quality_of_artifact
							value = flag:mid
						}

					}
					33 = {
						trigger = {
							has_trait = confucian_education
						}
						modifier = {
							trigger = {
								has_trait_xp = {
									trait = confucian_education
									value > 40
								}
							}
							add = 10
						}
						modifier = {
							trigger = {
								has_trait_xp = {
									trait = confucian_education
									value > 60
								}
							}
							add = 17
						}
						modifier = {
							trigger = {
								has_trait_xp = {
									trait = confucian_education
									value > 80
								}
							}
							add = 20
						}
						save_scope_value_as = {
							name = quality_of_artifact
							value = flag:great
						}
					}
				}
				#Now we set the description:
				scope:newly_created_artifact = {
					#And now we give modifiers:
					switch = {
						trigger = scope:quality_of_artifact
						flag:weak = {
							#Influence & Confucian Education Gain
							set_artifact_rarity_common = yes
							switch = {
								trigger = scope:topic
								flag:prose_philosophy = {
									add_artifact_modifier = artifact_monthly_confucian_education_xp_1_modifier
								}
								flag:prose_history = {
									random_list = {
										70 = {
											add_artifact_modifier = artifact_monthly_influence_mult_1_modifier
										}
										30 = {
											modifier = {
												add = root.learning
											}
											add_artifact_modifier = artifact_monthly_influence_mult_2_modifier
										}
									}
								}
							}

							add_artifact_modifier = artifact_learning_lifestyle_xp_1_modifier

							random_list = {
								80 = { }
								10 = { add_artifact_modifier = artifact_study_confucian_classics_scheme_phase_duration_add_1_modifier }
							}
						}
						flag:mid = {
							#Influence & Confucian Education Gain
							set_artifact_rarity_masterwork = yes
							switch = {
								trigger = scope:topic
								flag:prose_philosophy = {
									add_artifact_modifier = artifact_monthly_confucian_education_xp_2_modifier
								}
								flag:prose_history = {
									random_list = {
										70 = {
											add_artifact_modifier = artifact_monthly_influence_mult_2_modifier
										}
										30 = {
											modifier = {
												add = root.learning
											}
											add_artifact_modifier = artifact_monthly_influence_mult_3_modifier
										}
									}
								}
							}

							add_artifact_modifier = artifact_learning_lifestyle_xp_2_modifier

							random_list = {
								40 = { add_artifact_modifier = artifact_study_confucian_classics_scheme_phase_duration_add_1_modifier }
								60 = {
									modifier = {
										add = root.learning
									}
									add_artifact_modifier = artifact_study_confucian_classics_scheme_phase_duration_add_2_modifier
								}
							}
						}
						flag:great = {
							#Influence & Confucian Education Gain
							set_artifact_rarity_famed = yes
							switch = {
								trigger = scope:topic
								flag:prose_philosophy = {
									add_artifact_modifier = artifact_monthly_confucian_education_xp_3_modifier
								}
								flag:prose_history = {
									random_list = {
										70 = {
											add_artifact_modifier = artifact_monthly_influence_mult_3_modifier
										}
										30 = {
											modifier = {
												add = root.learning
											}
											add_artifact_modifier = artifact_monthly_influence_mult_4_modifier
										}
									}
								}
							}

							add_artifact_modifier = artifact_learning_lifestyle_xp_2_modifier

							add_artifact_modifier = artifact_study_confucian_classics_scheme_phase_duration_add_2_modifier
						}
					}
					set_artifact_description = prose_book_description
					set_artifact_name = prose_name_hashcollision
				}
			}
			else = { #Science!

				#First we randomize the theme:
				if = {
					limit = {
						scope:topic = flag:monograph_geography
					}
					random_list = {
						1 = {
							save_scope_value_as = {
								name = monograph_theme 
								value = flag:home_duchy
							}
						}
						1 = {
							save_scope_value_as = {
								name = monograph_theme 
								value = flag:home_kingdom
							}
						}
						1 = {
							save_scope_value_as = {
								name = monograph_theme 
								value = flag:home_empire
							}
						}
						1 = {
							trigger = {
								top_liege.highest_held_title_tier = tier_hegemony
							}
							save_scope_value_as = {
								name = monograph_theme 
								value = flag:home_hegemony
							}
						}
						1 = {
							trigger = { #A point of interest that is not your own capital
								has_variable_list = visited_poi
								any_in_list = {
									variable = visited_poi
									this = county.holder.capital_province
									county.holder != root
								}
							}
							random_in_list = {
								variable = visited_poi
								limit = {
									this = county.holder.capital_province
									county.holder != root
								}
								save_scope_as = poi_topic
							}
							save_scope_value_as = {
								name = monograph_theme 
								value = flag:point_of_interest
							}
						}
					}
				}
				else = { #Mathematics
					#This is set after we determine skill, so this is a fallback flag that will be overriden
					save_scope_value_as = {
						name = monograph_theme 
						value = flag:commentary_on_earlier_works
					}
				}


				#Then we decide the skill level:
				#Skills for high quality dependent on type of book chosen
				#Then we decide the skill level:

				#Geography
				if = {
					limit = {
						scope:topic = flag:monograph_geography
					}
					random_list = {
						30 = {
							trigger = {
								travel_lifestyle_track_less_trigger = {
									TRACK = travel
									LESS_THAN = 50
								}
							}
							modifier = {
								add = {
									value = learning
									multiply = -1
								}
							}
							save_scope_value_as = {
								name = quality_of_artifact
								value = flag:weak
							}
						}
						55 = {
							save_scope_value_as = {
								name = quality_of_artifact
								value = flag:mid
							}
						}
						15 = {
							trigger = {
								travel_lifestyle_track_greater_equal_trigger = {
									TRACK = travel
									GREATER_EQUAL = 50
								}
							}
							modifier = {
								add = learning
							}
							save_scope_value_as = {
								name = quality_of_artifact
								value = flag:great
							}
						}
					}
				}

				#Mathematics
				if = {
					limit = {
						scope:topic = flag:monograph_mathematics
					}
					random_list = {
						40 = {
							trigger = {
								learning < high_skill_rating
							}
							modifier = {
								add = {
									value = learning
									multiply = -1
								}
							}
							save_scope_value_as = {
								name = quality_of_artifact
								value = flag:weak
							}
						}
						45 = {
							save_scope_value_as = {
								name = quality_of_artifact
								value = flag:mid
							}
						}
						15 = {
							trigger = {
								learning > high_skill_rating
							}
							modifier = {
								add = learning
							}
							save_scope_value_as = {
								name = quality_of_artifact
								value = flag:great
							}
						}
					}

					#For mathematics this is also were we determine the theme - since it relates to the skill - overrides what was set in theme before
					random_list = {
						1 = {
							modifier = {
								trigger = {
									scope:quality_of_artifact = flag:weak
								}
								add = 3
							}
							save_scope_value_as = {
								name = monograph_theme 
								value = flag:algebraic_geometry
							}
						}
						1 = {
							modifier = {
								trigger = {
									scope:quality_of_artifact = flag:weak
								}
								add = 5
							}
							save_scope_value_as = {
								name = monograph_theme 
								value = flag:linear_algebra
							}
						}
						1 = { #Chance of keeping the fallback modifier
							modifier = {
								trigger = {
									scope:quality_of_artifact = flag:weak
								}
								add = 5
							}
							#save_scope_value_as = {
							#	name = monograph_theme 
							#	value = flag:commentary_on_earlier_works
							#}
						}
						1 = {
							save_scope_value_as = {
								name = monograph_theme 
								value = flag:spherical_trigonometry
							}
						}
						1 = {
							save_scope_value_as = {
								name = monograph_theme 
								value = flag:computational_studies 
							}
						}
						1 = {
							save_scope_value_as = {
								name = monograph_theme 
								value = flag:method_of_solving_simultaneous_congruences
							}
						}
						1 = {
							modifier = {
								trigger = {
									scope:quality_of_artifact = flag:great
								}
								add = 5
							}
							save_scope_value_as = {
								name = monograph_theme 
								value = flag:method_of_solving_simultaneous_congruences
							}
						}
						1 = {
							modifier = {
								trigger = {
									scope:quality_of_artifact = flag:great
								}
								add = 5
							}
							save_scope_value_as = {
								name = monograph_theme 
								value = flag:magic_squares_magic_circles
							}
						}
						1 = {
							modifier = {
								trigger = {
									scope:quality_of_artifact = flag:great
								}
								add = 5
							}
							save_scope_value_as = {
								name = monograph_theme 
								value = flag:teaching_overview_of_all_mathematical_methods
							}
						}
					}
				}



				scope:newly_created_artifact = {
						

						#And now we give modifiers:
						switch = {
							trigger = scope:quality_of_artifact
							flag:weak = {
								#Merit & Prestige Gain
								set_artifact_rarity_masterwork = yes
								random_list = { #Merit
									60 = {
										add_artifact_modifier = artifact_monthly_merit_mult_1_modifier
									}
									20 = {
										add_artifact_modifier = artifact_monthly_merit_mult_2_modifier
									}
									10 = {
										add_artifact_modifier = artifact_monthly_merit_mult_3_modifier
									}
								}
								
								random_list = { #Prestige
									60 = {
										add_artifact_modifier = artifact_monthly_minor_prestige_2_modifier
									}
									20 = {
										add_artifact_modifier = artifact_monthly_minor_prestige_4_modifier
									}
									10 = {
										add_artifact_modifier = artifact_monthly_minor_prestige_6_modifier
									}
								}

								add_artifact_modifier = artifact_learning_lifestyle_xp_1_modifier

								random_list = {
									80 = { }
									10 = {
										add_artifact_modifier = artifact_study_confucian_classics_scheme_phase_duration_add_1_modifier
									}
								}
							}
							flag:mid = {
								#Influence & Confucian Education Gain
								set_artifact_rarity_famed = yes
								random_list = { #Merit
									30 = {
										add_artifact_modifier = artifact_monthly_merit_mult_2_modifier
									}
									50 = {
										add_artifact_modifier = artifact_monthly_merit_mult_3_modifier
									}
									20 = {
										modifier = {
											add = root.learning
										}
										add_artifact_modifier = artifact_monthly_merit_mult_4_modifier
									}
								}
								random_list = { #Prestige
									30 = {
										add_artifact_modifier = artifact_monthly_merit_mult_4_modifier
									}
									50 = {
										add_artifact_modifier = artifact_monthly_minor_prestige_6_modifier
									}
									20 = {
										modifier = {
											add = root.learning
										}
										add_artifact_modifier = artifact_monthly_minor_prestige_8_modifier
									}
								}

								add_artifact_modifier = artifact_learning_lifestyle_xp_2_modifier

								random_list = {
									40 = { add_artifact_modifier = artifact_study_confucian_classics_scheme_phase_duration_add_1_modifier }
									60 = { add_artifact_modifier = artifact_study_confucian_classics_scheme_phase_duration_add_2_modifier }
								}
							}
							flag:great = {
								#Influence & Confucian Education Gain
								set_artifact_rarity_illustrious = yes
								random_list = { #Merit
									65 = {
										add_artifact_modifier = artifact_monthly_merit_mult_3_modifier
									}
									30 = {
										add_artifact_modifier = artifact_monthly_merit_mult_4_modifier
									}
									5 = {
										modifier = {
											add = root.learning
										}
										add_artifact_modifier = artifact_monthly_merit_mult_5_modifier
									}
								}
								
								random_list = { #Prestige
									65 = {
										add_artifact_modifier = artifact_monthly_prestige_2_modifier
									}
									30 = {
										add_artifact_modifier = artifact_monthly_prestige_3_modifier
									}
									5 = {
										modifier = {
											add = root.learning
										}
										add_artifact_modifier = artifact_monthly_prestige_4_modifier
									}
								}

								add_artifact_modifier = artifact_learning_lifestyle_xp_2_modifier

								add_artifact_modifier = artifact_study_confucian_classics_scheme_phase_duration_add_2_modifier
							}
						}

						switch = {
							trigger = scope:topic
							flag:monograph_geography = {
								random_list =	{
									2 = { add_artifact_modifier = artifact_travel_safety_1 }
									2 = { add_artifact_modifier = character_travel_speed_1 }
									1 = {
										add_artifact_modifier = artifact_travel_safety_2
										modifier = {
											trigger = {
												scope:quality_of_artifact = flag:mid
											}
											add = 1
										}
										modifier = {
											trigger = {
												scope:quality_of_artifact = flag:great
											}
											add = 3
										}
									}
									1 = {
										add_artifact_modifier = character_travel_speed_2
										modifier = {
											trigger = {
												scope:quality_of_artifact = flag:mid
											}
											add = 1
										}
										modifier = {
											trigger = {
												scope:quality_of_artifact = flag:great
											}
											add = 3
										}
									}
								}
							}
							flag:monograph_mathematics = {
								random_list = {
									2 = { add_artifact_modifier = artifact_stewardship_lifestyle_xp_1_modifier }
									2 = { add_artifact_modifier = artifact_learning_lifestyle_xp_1_modifier }
									1 = {
										add_artifact_modifier = artifact_learning_lifestyle_xp_2_modifier
										modifier = {
											trigger = {
												scope:quality_of_artifact = flag:mid
											}
											add = 1
										}
										modifier = {
											trigger = {
												scope:quality_of_artifact = flag:great
											}
											add = 3
										}
									}
									1 = {
										add_artifact_modifier = artifact_stewardship_lifestyle_xp_2_modifier
										modifier = {
											trigger = {
												scope:quality_of_artifact = flag:mid
											}
											add = 1
										}
										modifier = {
											trigger = {
												scope:quality_of_artifact = flag:great
											}
											add = 3
										}
									}
								}
							}
						}

						set_artifact_name = monograph_name_hashcollision
						set_artifact_description = monograph_description_full
				}
				scope:newly_created_artifact = {
					flag_as_trash_artifact = yes
					remove_artifact_modifier = artifact_placeholder_modifier
				}
			}
		}
	}

	option = {
		name = author_book.1000.a
		trigger = {
			scope:quality_of_artifact = flag:weak
		}

		add_merit_if_relevant_effect = {
			MERIT = miniscule_merit_value
		}
		if = {
			limit = {
				OR = {
					scope:topic = flag:poem_friend
					scope:topic = flag:poem_own
				}
				has_trait = lifestyle_poet
				has_trait_xp = {
					trait = lifestyle_poet
					value < 100
				}
			}
			add_trait_xp = {
				trait = lifestyle_poet
				value = { 1 3 }
			}
		}

		#XP Gain for Confucian Education or Poet
		if = {
			limit = {
				NOR = { #I wrote a book
					scope:topic = flag:poem_friend
					scope:topic = flag:poem_own
				}
			}
			if = {
				limit = {
					NOT = {
						has_trait = confucian_education
					}
				}
				add_trait = confucian_education
			}
			else_if = {
				limit = {
					has_trait = confucian_education
					has_trait_xp = {
						trait = confucian_education
						value < 100
					}
				}
				add_trait_xp = {
					trait = confucian_education
					value = { 1 3 }
				}
			}
		}
	}

	option = {
		name = author_book.1000.b
		trigger = {
			scope:quality_of_artifact = flag:mid
		}

		add_merit_if_relevant_effect = {
			MERIT = miniscule_merit_value
		}

		if = {
			limit = {
				OR = {
					scope:topic = flag:poem_friend
					scope:topic = flag:poem_own
				}
				has_trait = lifestyle_poet
				has_trait_xp = {
					trait = lifestyle_poet
					value < 100
				}
			}
			add_trait_xp = {
				trait = lifestyle_poet
				value = { 1 3 }
			}
		}

		#XP Gain for Confucian Education or Poet
		if = {
			limit = {
				NOR = { #I wrote a book
					scope:topic = flag:poem_friend
					scope:topic = flag:poem_own
				}
			}
			if = {
				limit = {
					NOT = {
						has_trait = confucian_education
					}
				}
				add_trait = confucian_education
			}
			else_if = {
				limit = {
					has_trait = confucian_education
					has_trait_xp = {
						trait = confucian_education
						value < 100
					}
				}
				add_trait_xp = {
					trait = confucian_education
					value = { 1 3 }
				}
			}
		}

	}

	option = {
		name = author_book.1000.c
		trigger = {
			scope:quality_of_artifact = flag:great
		}

		add_merit_if_relevant_effect = {
			MERIT = minor_merit_value
		}

		if = {
			limit = {
				OR = {
					scope:topic = flag:poem_friend
					scope:topic = flag:poem_own
				}
				has_trait = lifestyle_poet
				has_trait_xp = {
					trait = lifestyle_poet
					value < 100
				}
			}
			add_trait_xp = {
				trait = lifestyle_poet
				value = { 3 5 }
			}
		}

		#XP Gain for Confucian Education
		if = {
			limit = {
				NOR = { #I wrote a book
					scope:topic = flag:poem_friend
					scope:topic = flag:poem_own
				}
				has_trait = confucian_education
				has_trait_xp = {
					trait = confucian_education
					value < 100
				}
			}
			add_trait_xp = {
				trait = confucian_education
				value = { 3 5 }
			}
		}
	}

	option = {
		name = author_book.1000.d
		trigger = {
			scope:quality_of_artifact = flag:great
		}
		add_merit_if_relevant_effect = {
			MERIT = minor_merit_value
		}

		if = {
			limit = {
				OR = {
					scope:topic = flag:poem_friend
					scope:topic = flag:poem_own
				}
				has_trait = lifestyle_poet
				has_trait_xp = {
					trait = lifestyle_poet
					value < 100
				}
			}
			add_trait_xp = {
				trait = lifestyle_poet
				value = { 3 5 }
			}
		}

		#XP Gain for Confucian Education
		if = {
			limit = {
				NOR = { #I wrote a book
					scope:topic = flag:poem_friend
					scope:topic = flag:poem_own
				}
				has_trait = confucian_education
				has_trait_xp = {
					trait = confucian_education
					value < 100
				}
			}
			add_trait_xp = {
				trait = confucian_education
				value = { 3 5 }
			}
		}

		improve_relationship_effect = {
			TARGET = scope:trusted_influencer
			REASON = gifted_poem
		}
		scope:newly_created_artifact = {
			set_owner = scope:trusted_influencer
		}
	}
}


