﻿
namespace = commission_epic

#########################
# Commission Epic Chain
#########################


#####################
# Start Composition
# by Petter Vilberg
#####################
scripted_trigger commission_epic_writer_trigger = {	
	has_character_flag = writer
	NOT = { exists = inspiration }
	is_available_ai_adult = yes
}

commission_epic.0001 = {
	type = character_event
	title = commission_epic.0001.t
	desc = commission_epic.0001.desc
	theme = diplomacy
	override_background = { reference = study }
	left_portrait = {
		character = scope:writer
		animation = personality_bold
	}
	right_portrait = {
		character = scope:servant
		animation = worry
	}

	
	immediate = {
		# Check if you have any writers around
		if = {
			limit = {
				any_courtier_or_guest = {
					commission_epic_writer_trigger = yes
				}
			}
			random_courtier_or_guest = {
				limit = {
					commission_epic_writer_trigger = yes
				}
				save_scope_as = writer
			}
		}
		else_if = { # Check in vassal's Courts
			limit = {
				NOT = {
					exists = scope:writer
				}
				any_vassal = {
					is_ai = yes
					any_courtier_or_guest = {
						commission_epic_writer_trigger = yes
					}
				}
			}
			random_vassal = {
				limit = {
					is_ai = yes
					any_courtier_or_guest = {
						commission_epic_writer_trigger = yes
					}
				}
				random_courtier_or_guest = {
					limit = {
						commission_epic_writer_trigger = yes
					}
					save_scope_as = writer
				}
			}
		}
		else_if = {
			limit = {
				is_ai = yes
				any_courtier_or_guest = { is_available_ai_adult = yes }
			}
			random_courtier_or_guest = {
				limit = {
					is_available_ai_adult = yes
				}
				save_scope_as = writer
			}
		}
		else = {
			create_character = {
				save_scope_as = writer
				location = root.capital_province
				template = writer_character
			}
			scope:writer = {
				add_character_flag = writer
				hidden_effect = {
					visit_court_of = root
				}
			}
		}

		# Set up Servant character for players only
		# Note: No need to add extra characters for AI
		if = {
			limit = {
				is_ai = no
			}
			create_character = {
				save_scope_as = servant
				employer = root
				template = servant_character
				gender_female_chance = root_faith_dominant_gender_adjusted_female_chance
			}
		}

		# Set story type
		if = {
			limit = {
				government_has_flag = government_is_tribal
			}
			set_variable = {
				name = composition_type
				value = flag:song
			}
			save_scope_value_as = {
				name = composition_type
				value = flag:song
			}	
		}
		else = {
			random_list = {
				1 = {
					set_variable = {
						name = composition_type
						value = flag:song
					}
				}
				4 = {
					set_variable = {
						name = composition_type
						value = flag:chronicle
					}		
				}
				2 = {
					set_variable = {
						name = composition_type
						value = flag:poem
					}		
				}
			}
		}
	}

	option = { # Go with the writer
		name = commission_epic.0001.a
		flavor = commission_epic.writing_begins
		custom_tooltip = writer_writes_epic
		custom_tooltip = commission_epic.high_chance
		remove_short_term_gold = {
			add = medium_gold_value
			multiply = 2
		}
		scope:writer = {
			add_character_flag = {
				flag = blocked_from_leaving
				years = 5
			}
			if = {
				limit = {
					NOT = { is_courtier_of = root }
				}
				visit_court_of = root
			}
			save_scope_as = composer # For use in next setup event
		}
		set_variable = { # For use in the Story
			name = composer
			value = scope:writer
		}
		set_variable = { # For use in the Story
			name = epic_approach
			value = flag:writer
		}
		stress_impact = {
			greedy = medium_stress_impact_gain
		}

		ai_chance = {
			base = 100
			modifier = {
				add = -50
				short_term_gold < major_gold_value
			}
			ai_value_modifier = {
				ai_greed = -1
				ai_honor = 0.5
			}
			modifier = {
				factor = 0
				short_term_gold <= minor_gold_value
			}
		}
	}

	option = { # Scribes
		name = commission_epic.0001.b
		flavor = commission_epic.writing_begins
		if = {
			limit = { government_has_flag = government_is_tribal }
			custom_tooltip = bards_write_epic
		}
		else = {
			custom_tooltip = scribes_write_epic
		}
		custom_tooltip = commission_epic.medium_chance
		remove_short_term_gold = medium_gold_value
		save_scope_as = composer # Root, to be displayed in the next setup event
		set_variable = { # For use in the Story cycle
			name = epic_approach
			value = flag:scribes
		}
		ai_chance = {
			base = 100
		}
	}
	
	option = { # A random servant
		name = commission_epic.0001.c
		flavor = commission_epic.writing_begins
		trigger = {
			exists = scope:servant
		}
		custom_tooltip = servant_writes_epic
		custom_tooltip = commission_epic.low_chance
		remove_short_term_gold = 2
		scope:servant = {
			add_character_flag = writer
			save_scope_as = composer # For use in next setup event
		}
		set_variable = { # For use in the Story
			name = composer
			value = scope:servant
		}
		set_variable = { # For use in the Story
			name = epic_approach
			value = flag:servant
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = 1
				ai_rationality = -1
			}
		}
	}

	option = { # Simply rewrite something old
		name = commission_epic.0001.d
		add_prestige = minor_prestige_gain
		custom_tooltip = commission_epic.opt_out
		save_scope_value_as = {
			name = opt_out
			value = yes
		}
		stress_impact = {
			stubborn = medium_stress_impact_gain
		}
		ai_chance = {
			base = 0
		}
	}

	after = {
		if = {
			limit = {
				NOT = { exists = scope:opt_out }
			}
			trigger_event = {
				id = commission_epic.0002
				days = 10
			}
		}
	}
}


########################
# Perspective
# by Petter Vilberg  (additions for FP2 by Ola Jentzsch)
########################
commission_epic.0002 = {
	type = character_event
	title = commission_epic.0002.t
	desc ={
		first_valid = {
			triggered_desc = {
				trigger = { scope:story.var:epic_approach = flag:writer }
				desc = commission_epic.0002.writer
			}
			triggered_desc = {
				trigger = { scope:story.var:epic_approach = flag:servant }
				desc = commission_epic.0002.servant
			}
			desc = commission_epic.0002.scribes
		}
	}
	theme = diplomacy
	override_background = { reference = study }
	left_portrait = scope:composer

	immediate = {
		create_story = commission_epic_story
		random_owned_story = {
			type = commission_epic_story
			save_scope_as = story
		}
	}

	option = { #Focus on stories of my dynasty's ancestral claims
		name = {
			text = {
				first_valid = {
					triggered_desc = {
						trigger = {
							any_character_struggle = {
   								involvement = involved
  								is_struggle_type = iberian_struggle
  							}
  						}
  						desc = commission_epic.0002.iberia_epic.a
  					}
  					desc = commission_epic.0002.a
  				}
  			}
  		}
		custom_tooltip = commission_epic.propaganda


		trigger = {	
			any_character_to_title_neighboring_county = { 
				count >= 3 
				holder = {
					NOT = {
						is_vassal_of = root	
					}
				}
			}
		}

		stress_impact = {
			just = minor_stress_impact_gain
		}

		trigger_event = {
  			id = commission_epic.6000 
  			days = { 3 10 }
  		}

  		set_variable = {
  			name = propaganda_path
  			value = yes
  		} 

  		scope:story = {
  			set_variable = {
  				name = composer
  				value = scope:composer
  			}
  		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = 0.5
				ai_boldness = 0.3
				ai_compassion = -0.5
			}
		}
	}

	option = { # It's about me!
		name = commission_epic.0002.b
		custom_tooltip = commission_epic.more_prestige
		scope:story = {
			set_variable = {
				name = perspective
				value = flag:personal_prestige
			}
			set_variable = prestige_artifact
		}
		stress_impact = {
			family_first = medium_stress_impact_gain
			humble = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = 1
			}
		}

		hidden_effect = { clear_commission_epic_loc_variables = yes }
	}

	option = { # Take a broad perspective
		name = commission_epic.0002.c
		custom_tooltip = commission_epic.more_dynasty_prestige
		scope:story = {
			set_variable = {
				name = perspective
				value = flag:dynasty_prestige
			}
			set_variable = dynasty_prestige_artifact
		}
		stress_impact = {
			arrogant = medium_stress_impact_gain
		}
		ai_chance = {
			base = 30
		}

		hidden_effect = { clear_commission_epic_loc_variables = yes }
	}
	
	option = { # Be as honest as possible
		name = commission_epic.0002.d
		custom_tooltip = commission_epic.more_piety
		scope:story = {
			set_variable = {
				name = perspective
				value = flag:piety
			}
			set_variable = extra_pious_artifact
		}
		stress_impact = {
			deceitful = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_zeal = 0.5
			}
		}

		hidden_effect = { clear_commission_epic_loc_variables = yes }
	}
}


########################
# A Question of Time
# by Petter Vilberg
########################
commission_epic.1001 = {
	type = character_event
	title = commission_epic.1001.t
	desc = {
		desc = commission_epic.1001.opening
		first_valid	= {
			triggered_desc = {
				trigger = { exists = scope:composer }
				desc = commission_epic.1001.composer
			}
			desc = commission_epic.1001.scribes
		}
	}
	theme = diplomacy
	override_background = { reference = study }
	left_portrait = root
	right_portrait = scope:story.var:composer
	
	trigger = {
		NOT = {
			exists = scope:story.var:had_event_1001
		}
	}

	weight_multiplier = {
		base = 1
	}

	immediate = {
		scope:story = {
			set_variable = {
				name = had_event_1001
				value = yes
			}
		}
	}

	option = { # Be demanding
		name = commission_epic.1001.a
		custom_tooltip = commission_epic.reduced_chance
		scope:story = {
			change_variable = {
				name = final_outcome_chance
				add = -20
			}
		}
		stress_impact = {
			patient = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = -0.5
			}
		}
	}

	option = { # Take as much time as necessary
		name = {
			trigger = { exists = scope:composer }
			text = commission_epic.1001.b
		}
		name = {
			trigger = { NOT = { exists = scope:composer } }
			text = commission_epic.1001.b_scribes
		}
		remove_short_term_gold = minor_gold_value
		stress_impact = {
			impatient = major_stress_impact_gain
			greedy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 1
				ai_rationality = 1
			}
		}
	}
	
	option = { # Well done on part 1!
		name = commission_epic.1001.c
		trigger = {
			has_trait = administrator
		}
		trait = administrator
		add_prestige = minor_prestige_value
		add_gold = minor_gold_value
		ai_chance = {
			base = 1000
		}
	}

	after = {
		clear_commission_epic_loc_variables = yes
	}
}


########################
# Rich Source Material
# by Petter Vilberg
########################
commission_epic.1002 = {
	type = character_event
	title = commission_epic.1002.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:composer }
				desc = commission_epic.1002.composer
			}
			desc = commission_epic.1002.scribes
		}
	}
	theme = diplomacy
	override_background = { reference = study }
	left_portrait = root
	right_portrait = scope:powerful_vassal
	lower_right_portrait = scope:story.var:composer
	
	trigger = {
		NOT = { exists = scope:story.var:had_event_1002 }
	}

	weight_multiplier = {
		base = 1
	}

	immediate = {
		scope:story = {
			set_variable = {
				name = had_event_1002
				value = yes
			}
		}
		random_powerful_vassal = {
			save_scope_as = powerful_vassal
		}
	}

	option = { # Share these stories with others
		name = commission_epic.1002.a
		add_prestige = minor_prestige_gain
		custom_tooltip = commission_epic.1002.a.tt
		scope:story = { set_variable = opinion_artifact }
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = 0.5
			}
			modifier = {
				add = {
					every_vassal = {
						limit = {
							opinion = {
								target = root
								value < 0
							}
						}
						add = 20
					}
				}
				always = yes
			}
		}
	}

	option = { # Sounds like the work will be easier than expected
		name = commission_epic.1002.b
		add_gold = medium_gold_value
		custom_tooltip = commission_epic.1002.b.tt
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = 1
			}
		}
	}

	after = {
		clear_commission_epic_loc_variables = yes
	}
}



##########################
# Writer's Retreat
# by Petter Vilberg
##########################
commission_epic.1003 = {
	type = character_event
	title = commission_epic.1003.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:composer }
				desc = commission_epic.1003.composer
			}
			desc = commission_epic.1003.scribes
		}
	}
	theme = diplomacy
	override_background = { reference = study }
	left_portrait = root
	right_portrait = scope:composer
	
	trigger = {
		NOT = { exists = scope:story.var:had_event_1003 }
	}

	weight_multiplier = {
		base = 1
	}

	immediate = {
		scope:story = {
			set_variable = {
				name = had_event_1003
				value = yes
			}
		}
	}

	option = { # Perhaps a break is in order
		name = commission_epic.1003.a
		remove_short_term_gold = medium_gold_value
		custom_tooltip = commission_epic.increased_chance
		scope:story = {
			change_variable = {
				name = final_outcome_chance
				add = 20
			}
		}
		stress_impact = {
			impatient = medium_stress_impact_gain
			vengeful = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 1
				ai_rationality = 1
			}
		}
	}

	option = { # Chain them to their desk!
		name = {
			trigger = { exists = scope:composer }
			text = commission_epic.1003.b
		}
		name = {
			trigger = { NOT = { exists = scope:composer } }
			text = commission_epic.1003.b_scribes
		}
		custom_tooltip = commission_epic.reduced_chance
		add_dread = medium_dread_gain
		scope:story = {
			change_variable = {
				name = final_outcome_chance
				add = -20
			}
		}
		stress_impact = {
			compassionate = major_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_greed = 0.5
				ai_vengefulness = 1
			}
		}
	}

	after = {
		clear_commission_epic_loc_variables = yes
	}
}



#########################
# Expert Illuminator
# by Petter Vilberg
#########################
commission_epic.1004 = {
	type = character_event
	title = commission_epic.1004.t
	desc = {
		desc = commission_epic.1004.opening
		first_valid = {
			triggered_desc = {
				trigger = { scope:illuminator = { is_male = yes } }
				desc = commission_epic.1004.devotee_male
			}
			desc = commission_epic.1004.devotee_female
		}
		desc = commission_epic.1004.ending
	}
	theme = diplomacy
	override_background = { reference = study }
	left_portrait = root
	right_portrait = scope:composer
	
	trigger = {
		NOT = { exists = scope:story.var:had_event_1004 }
		OR = {
			scope:story.var:composition_type = flag:chronicle
			scope:story.var:composition_type = flag:poem
		}
		is_landed = yes
	}

	weight_multiplier = {
		base = 1
	}

	immediate = {
		scope:story = {
			set_variable = {
				name = had_event_1004
				value = yes
			}
		}
		random_sub_realm_barony = {
			limit = {
				county.holder = root
			}
			save_scope_as = barony
		}
		random = { # Generate a dummy gender character
			chance = root_faith_dominant_gender_female_chance
			dummy_female = {
				save_scope_as = illuminator
			}
		}
		if = {
			limit = {
				NOT = { exists = scope:illuminator }
			}
			dummy_male = {
				save_scope_as = illuminator
			}
		}
	}

	option = { # Hire the illuminator!
		name = commission_epic.1004.a
		remove_short_term_gold = medium_gold_value
		custom_tooltip = commission_epic.increased_chance
		scope:story = {
			change_variable = {
				name = final_outcome_chance
				add = 20
			}
		}
		ai_chance = {
			base = 100
			modifier = {
				add = -80
				short_term_gold < medium_gold_value
			}
			ai_value_modifier = {
				ai_greed = -1
				ai_honor = 0.5
			}
		}
	}

	option = { # The Composer can do it themselves
		name = commission_epic.1004.b
		trigger = {
			exists = scope:composer
		}
		scope:composer = {
			duel = {
				skill = learning
				value = high_skill_rating
				20 = {
					desc = commission_epic.1004.success
					compare_modifier = {
						value = scope:duel_value
					}
					root = {
						send_interface_toast = {
							title = commission_epic.1004.success
							custom_tooltip = commission_epic.increased_chance
							scope:story = {
								change_variable = {
									name = final_outcome_chance
									add = 20
								}
							}
						}
					}
				}
				20 = {
					desc = commission_epic.1004.failure
					compare_modifier = {
						value = scope:duel_value
						multiplier = -1
					}
					root = {
						send_interface_toast = {
							title = commission_epic.1004.failure
							custom_tooltip = commission_epic.reduced_chance
							scope:story = {
								change_variable = {
									name = final_outcome_chance
									add = -10
								}
							}
						}
					}
				}
			}
		}
		ai_chance = {
			base = 20
			compare_modifier = {
				target = scope:composer
				value = learning
				multiplier = 6
			}
		}
	}

	option = {
		name = commission_epic.1004.b_scribes
		trigger = {
			NOT = {
				exists = scope:composer
			}
		}
		random_list = {
			50 = {
				desc = commission_epic.1004.success
				send_interface_toast = {
					title = commission_epic.1004.success
					custom_tooltip = commission_epic.increased_chance
					scope:story = {
						change_variable = {
							name = final_outcome_chance
							add = 20
						}
					}
				}
			}
			50 = {
				desc = commission_epic.1004.failure
				send_interface_toast = {
					title = commission_epic.1004.failure
					custom_tooltip = commission_epic.reduced_chance
					scope:story = {
						change_variable = {
							name = final_outcome_chance
							add = -10
						}
					}
				}
			}
		}
	}
	
	option = { # I've always wanted to be an artist...
		name = commission_epic.1004.c
		duel = {
			skill = learning
			value = high_skill_rating
			15 = {
				desc = commission_epic.1004.success
				compare_modifier = {
					value = scope:duel_value
				}
				send_interface_toast = {
					title = commission_epic.1004.success
					custom_tooltip = commission_epic.increased_chance
					scope:story = {
						change_variable = {
							name = final_outcome_chance
							add = 20
						}
					}
				}
			}
			30 = {
				desc = commission_epic.1004.failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -1
				}
				send_interface_toast = {
					title = commission_epic.1004.failure
					custom_tooltip = commission_epic.reduced_chance
					scope:story = {
						change_variable = {
							name = final_outcome_chance
							add = -10
						}
					}
				}
			}
		}
		stress_impact = {
			lazy = major_stress_impact_gain
			humble = medium_stress_impact_gain
		}
		ai_chance = {
			base = 50
			compare_modifier = {
				value = learning
				multiplier = 6
			}
			ai_value_modifier = {
				ai_boldness = 0.5
			}
		}
	}

	after = {
		clear_commission_epic_loc_variables = yes
	}
}



###########################
# The Song of Our People
# by Petter Vilberg
###########################
commission_epic.1005 = {
	type = character_event
	title = commission_epic.1005.t
	desc = {
		desc = commission_epic.1005.opening
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:composer }
				desc = commission_epic.1005.composer
			}
			desc = commission_epic.1005.scribes
		}
		desc = commission_epic.1005.ending
	}
	theme = diplomacy
	override_background = { reference = study }
	left_portrait = root
	right_portrait = scope:composer

	trigger = {
		NOT = { exists = scope:story.var:had_event_1005 }
		government_has_flag = government_is_tribal
		scope:story.var:composition_type = flag:song
	}

	weight_multiplier = {
		base = 1
	}

	immediate = {
		scope:story = {
			set_variable = {
				name = had_event_1005
				value = yes
			}
		}
	}

	option = { # Use the classic song!
		name = commission_epic.1005.a
		dynasty = {
			add_dynasty_prestige = medium_dynasty_prestige_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = 1
				ai_compassion = 0.3
			}
		}
	}

	option = { # The composer should compose something equally good
		name = {
			trigger = { exists = scope:composer }
			text = commission_epic.1005.b_composer
		}
		name = {
			trigger = { NOT = { exists = scope:composer } }
			text = commission_epic.1005.b
		}
		random_list = {
			20 = {
				desc = commission_epic.1005.classic
				send_interface_toast = {
					title = commission_epic.1005.classic
					add_prestige = medium_prestige_gain
					dynasty = {
						add_dynasty_prestige = medium_dynasty_prestige_gain
					}
				}
			}
			60 = {
				desc = commission_epic.1005.enjoyable
				send_interface_toast = {
					title = commission_epic.1005.enjoyable
					add_prestige = medium_prestige_gain
				}
			}
			20 = {
				desc = commission_epic.1005.terrible
				send_interface_toast = {
					title = commission_epic.1005.terrible
					add_prestige = minor_prestige_loss
				}
			}
		}
		ai_chance = {
			base = 50
		}
	}

	after = {
		clear_commission_epic_loc_variables = yes
	}
}


################################
# Friends From Legends (Become friends with a Vassal)
# by Petter Vilberg
################################
scripted_trigger commission_epic_1006_vassal_trigger = {
	NOT = {
		is_close_family_of = root
		can_set_relation_friend_trigger = { CHARACTER = root }
		has_relation_lover = root
	}
	is_available_ai_adult = yes
	opinion = {
		target = root
		value >= 40
	}
}

commission_epic.1006 = {
	type = letter_event
	opening = commission_epic.1006.opening
	desc = commission_epic.1006.desc
	sender = scope:vassal
	
	trigger = {
		NOT = { exists = scope:story.var:had_event_1006 }
		any_vassal = {
			commission_epic_1006_vassal_trigger = yes
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = -0.5
			NOR = {
				any_vassal = {
					commission_epic_1006_vassal_trigger = yes
					is_of_major_interest_trigger = {
						CHARACTER = root
					}
				}
				any_vassal = {
					commission_epic_1006_vassal_trigger = yes
					has_relation_potential_friend = root
				}
			}
		}
		modifier = {
			factor = 0.1
			any_relation = {
				type = friend
				count > 2
			}
		}
	}

	immediate = {
		scope:story = {
			set_variable = {
				name = had_event_1006
				value = yes
			}
		}
		random_vassal = {
			limit = {
				commission_epic_1006_vassal_trigger = yes
				is_of_major_interest_trigger = {
					CHARACTER = root
				}
			}
			alternative_limit = {
				commission_epic_1006_vassal_trigger = yes
			}
			weight = {
				base = 10
				opinion_modifier = {
					opinion_target = root
				}
				modifier = {
					add = 200
					has_relation_potential_friend = root
				}
			}
			save_scope_as = vassal
		}
	}

	option = { # Of course!
		name = commission_epic.1006.a
		if = {
			limit = {
				NOT = { has_relation_friend = scope:vassal }
			}
			set_relation_friend = { reason = friend_epic_vassal_inspiration target = scope:vassal }
		}
		else = {
			reverse_add_opinion = {
				modifier = friendliness_opinion
				target = scope:vassal
				opinion = 20
			}
		}
		hidden_effect = {
			if = {
				limit = {
					has_relation_potential_friend = scope:vassal
				}
				remove_relation_potential_friend = scope:vassal
			}
		}
		stress_impact = {
			shy = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			opinion_modifier = {
				opinion_target = scope:vassal
			}
		}
	}

	option = { # You should serve me no matter what
		name = commission_epic.1006.b
		add_prestige = minor_prestige_gain
		stress_impact = {
			gregarious = medium_stress_impact_gain
		}
		ai_chance = {
			base = 10
			modifier = {
				add = 100
				has_trait = shy
			}
			modifier = {
				add = 200
				has_trait = reclusive
			}
		}
	}

	after = {
		clear_commission_epic_loc_variables = yes
	}
}


################################
# Epic Emnity (Become rivals with a Vassal)
# by Petter Vilberg
################################
scripted_trigger commission_epic_1007_vassal_trigger = {
	NOT = {
		is_close_family_of = root
		has_relation_friend = root
		has_relation_potential_friend = root
		has_relation_rival = root
		has_relation_lover = root
		# Not from the same dynasty
		dynasty = root.dynasty
	}
	is_available_ai_adult = yes
	opinion = {
		target = root
		value <= -30
	}
}

commission_epic.1007 = {
	type = letter_event
	opening = commission_epic.1007.opening
	desc = commission_epic.1007.desc
	sender = scope:vassal
	
	trigger = {
		NOT = { exists = scope:story.var:had_event_1007 }
		any_vassal = {
			commission_epic_1007_vassal_trigger = yes
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = -0.5
			NOR = {
				any_vassal = {
					commission_epic_1007_vassal_trigger = yes
					is_of_major_interest_trigger = {
						CHARACTER = root
					}
				}
				any_vassal = {
					commission_epic_1007_vassal_trigger = yes
					has_relation_potential_rival = root
				}
			}
		}
		modifier = {
			factor = 0.1
			any_relation = {
				type = rival
				count > 2
			}
		}
	}

	immediate = {
		scope:story = {
			set_variable = {
				name = had_event_1007
				value = yes
			}
		}
		random_vassal = {
			limit = {
				commission_epic_1007_vassal_trigger = yes
				is_of_major_interest_trigger = {
					CHARACTER = root
				}
			}
			alternative_limit = {
				commission_epic_1007_vassal_trigger = yes
			}
			weight = {
				base = 10
				opinion_modifier = { # Make way more likely the higher the opinion
					opinion_target = root
					multiplier = -1
				}
				modifier = {
					add = 200
					has_relation_potential_rival = root
				}
			}
			save_scope_as = vassal
		}
	}

	option = { # How dare you?!
		name = commission_epic.1007.a
		set_relation_rival = {
			target = scope:vassal
			reason = rival_left_out_of_chronicle
		}
		stress_impact = {
			gregarious = medium_stress_impact_gain
			forgiving = medium_stress_impact_gain
		}
		hidden_effect = {
			if = {
				limit = {
					has_relation_potential_rival = scope:vassal
				}
				remove_relation_potential_rival = scope:vassal
			}
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_vengefulness = 2
			}
			opinion_modifier = {
				opinion_target = scope:vassal
				multiplier = -1
			}
		}
	}

	option = { # I will make amends
		name = commission_epic.1007.b
		add_prestige = medium_prestige_loss
		stress_impact = {
			vengeful = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = -1
				ai_compassion = 0.5
				ai_rationality = 0.5
			}
		}
	}

	after = {
		clear_commission_epic_loc_variables = yes
	}
}


#####################
# COUNCILLOR EVENTS
#####################

########################
# Precedence (Steward)
# by Petter Vilberg
########################
scripted_trigger commission_epic_2001_county_trigger = {
	tier = tier_county
	# Not already claimed by Root
	NOT = {
		root = {
			has_claim_on = prev
		}
	}
	# It needs to not have changed hands for a while
	NOT = {
		recent_history = {
			years = 10
		}
	}
}

scripted_trigger commission_epic_2001_vassal_trigger = {
	is_ai = yes
	is_imprisoned = no
	NOT = { this = root.cp:councillor_steward }
	any_held_title = {
		commission_epic_2001_county_trigger = yes
	}
	vassal_contract_obligation_level_can_be_increased = feudal_government_taxes
}

commission_epic.2001 = {
	type = character_event
	title = commission_epic.2001.t
	desc = {
		first_valid = {
			triggered_desc = {
			    trigger = { exists = scope:composer }
				desc = commission_epic.2001.desc_composer
			}
			desc = commission_epic.2001.desc_scribes
		}
		desc = commission_epic.2001.desc
	}
	theme = diplomacy
	override_background = { reference = study }
	left_portrait = {
		character = scope:steward
		animation = schadenfreude
	}
	right_portrait = {
		character = scope:vassal
		animation = worry
	}
	lower_right_portrait = scope:composer
	
	trigger = {
		NOT = { exists = scope:story.var:had_event_2001 }
		exists = cp:councillor_steward
		cp:councillor_steward = {
			NOT = { has_relation_rival = root }
		}
		any_vassal = {
			commission_epic_2001_vassal_trigger = yes
		}
	}

	weight_multiplier = {
		base = 1
	}

	immediate = {
		scope:story = {
			set_variable = {
				name = had_event_2001
				value = yes
			}
		}
		cp:councillor_steward = {
			save_scope_as = steward
		}
		random_vassal = {
			limit = {
				commission_epic_2001_vassal_trigger = yes
			}
			save_scope_as = vassal
			random_held_title = {
				limit = {
					commission_epic_2001_county_trigger = yes
				}
				save_scope_as = county
			}
		}
	}

	option = { # It will be mine again!
		name = commission_epic.2001.a
		add_unpressed_claim = scope:county
		scope:vassal = {
			add_opinion = {
				target = root
				modifier = insult_opinion
				opinion = -30
			}
		}
		stress_impact = {
			content = medium_stress_impact_gain
			just = medium_stress_impact_gain
		}
		ai_chance = {
			base = 30
			ai_value_modifier = {
				ai_boldness = 0.5
			}
		}
	}

	option = { # We should formalise this
		name = commission_epic.2001.b
		scope:vassal = {
			vassal_contract_increase_obligation_level = feudal_government_taxes
		}
		scope:vassal = {
			add_opinion = {
				target = root
				modifier = insult_opinion
				opinion = -20
			}
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = 0.5
				ai_honor = 0.5
			}
		}
	}

	option = { # We can let it pass
		name = commission_epic.2001.c
		flavor = commission_epic.2001.c.flavor
		stress_impact = {
			greedy = medium_stress_impact_gain
		}
		scope:vassal = {
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 30
			}
		}
		ai_chance = {
			base = 60
			opinion_modifier = {
				opinion_target = scope:vassal
				multiplier = -0.5
			}
		}
	}

	after = {
		clear_commission_epic_loc_variables = yes
	}
}


##################################
# Pride of the Family (Spymaster)
# by Petter Vilberg
##################################
commission_epic.2002 = {
	type = character_event
	title = commission_epic.2002.t
	desc = commission_epic.2002.desc
	theme = diplomacy
	override_background = { reference = study }
	left_portrait = {
		character = root
		animation = personality_bold
	}
	right_portrait = {
		character = scope:spymaster
		animation = scheme
	}
	lower_right_portrait = scope:composer
	
	trigger = {
		NOT = { exists = scope:story.var:had_event_2002 }
		exists = cp:councillor_spymaster
		cp:councillor_spymaster = {
			NOT = { has_relation_rival = root }
		}
	}

	weight_multiplier = {
		base = 1
	}

	immediate = {
		scope:story = {
			set_variable = {
				name = had_event_2002
				value = yes
			}
		}
		cp:councillor_spymaster = {
			save_scope_as = spymaster
		}
		random_list = {
			50 = {
				dummy_female = {
					save_scope_as = grandparent
				}
			}
			50 = {
				dummy_male = {
					save_scope_as = grandparent
				}
			}
		}
	}

	option = { # Emphasize sneakiness
		name = commission_epic.2002.a
		add_dread = minor_dread_gain
		custom_tooltip = commission_epic.2002.a.tt
		scope:story = { set_variable = scheme_artifact }
		add_intrigue_lifestyle_xp = major_lifestyle_xp
		ai_chance = {
			base = 100
		}
	}

	option = { # Perhaps we should massage the truth a little
		name = commission_epic.2002.b
		add_prestige = medium_prestige_gain
		ai_chance = {
			base = 100
		}
	}

	after = {
		clear_commission_epic_loc_variables = yes
	}
}


################################
# Eternal Obligations (Court Chaplain, Theocratic)
# by Petter Vilberg
################################
scripted_trigger commission_epic_2003_county_for_lease = {
	tier = tier_county
	this != root.capital_county
	county_control >= medium_county_control
}

commission_epic.2003 = {
	type = character_event
	title = commission_epic.2003.t
	desc = commission_epic.2003.desc
	theme = diplomacy
	override_background = { reference = study }
	left_portrait = {
		character = scope:court_chaplain
		animation = personality_bold
	}
	lower_left_portrait = scope:composer
	
	trigger = {
		NOT = { exists = scope:story.var:had_event_2003 }
		faith = {
			has_doctrine_parameter = theocracy_temple_lease	
		}
		exists = cp:councillor_court_chaplain
		cp:councillor_court_chaplain = {
			NOT = { has_relation_rival = root }
		}
		any_held_title = {
			commission_epic_2003_county_for_lease = yes
		}
	}

	weight_multiplier = {
		base = 1
	}

	immediate = {
		scope:story = {
			set_variable = {
				name = had_event_2003
				value = yes
			}
		}
		cp:councillor_court_chaplain = {
			save_scope_as = court_chaplain
		}
		random_held_title = {
			limit = {
				commission_epic_2003_county_for_lease = yes
			}
			save_scope_as = county
		}
	}

	option = { # We keep promises
		name = {
			trigger = { dynasty = scope:court_chaplain.dynasty}
			text = commission_epic.2003.a_same_dynasty
		}
		name = commission_epic.2003.a
		scope:county = {
			change_county_control = major_county_control_loss
		}
		scope:court_chaplain = {
			add_opinion = {
				target = root
				modifier = respect_opinion
				opinion = 30
			}
		}
		add_prestige = minor_prestige_gain
		add_piety = medium_piety_gain
		stress_impact = {
			deceitful = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_zeal = 1
			}
		}
	}

	option = { # My ancestors made a mistake
		name = commission_epic.2003.b
		scope:court_chaplain = {
			add_opinion = {
				target = root
				modifier = respect_opinion
				opinion = -10
			}
		}
		add_prestige = medium_prestige_gain
		stress_impact = {
			zealous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
		}
	}

	after = {
		clear_commission_epic_loc_variables = yes
	}
}



################################
# Inspiration Strikes (Marshal)
# by Petter Vilberg
################################
commission_epic.2004 = {
	type = character_event
	title = commission_epic.2004.t
	desc = {
		first_valid = {
			triggered_desc = {
			    trigger = { exists = scope:composer }
				desc = commission_epic.2004.desc_composer
			}
			desc = commission_epic.2004.desc_scribes
		}
		desc = commission_epic.2004.desc
	}
	theme = diplomacy
	override_background = { reference = study }
	left_portrait = {
		character = scope:marshal
		animation = admiration
	}
	lower_left_portrait = scope:composer
	
	trigger = {
		NOT = { exists = scope:story.var:had_event_2004 }
		exists = cp:councillor_marshal
		cp:councillor_marshal = {
			NOT = { has_relation_rival = root }
		}
	}

	weight_multiplier = {
		base = 1
	}

	immediate = {
		scope:story = {
			set_variable = {
				name = had_event_2004
				value = yes
			}
		}
		cp:councillor_marshal = {
			save_scope_as = marshal
		}
	}

	option = { # Wherever you can find innovation!
		name = commission_epic.2004.a
		custom_tooltip = commission_epic.2004.a.tt
		scope:story = { set_variable = advantage_artifact }
		ai_chance = {
			base = 100
		}
	}

	option = { # Let's all talk about this
		name = commission_epic.2004.b
		add_martial_lifestyle_xp = massive_lifestyle_xp
		ai_chance = {
			base = 50
		}
	}

	after = {
		clear_commission_epic_loc_variables = yes
	}
}


################################
# Honesty and Perception (Chancellor)
# by Petter Vilberg
################################
commission_epic.2005 = {
	type = character_event
	title = commission_epic.2005.t
	desc = commission_epic.2005.desc
	theme = diplomacy
	override_background = { reference = study }
	left_portrait = {
		character = scope:chancellor
		animation = personality_honorable
	}
	lower_left_portrait = scope:composer
	
	trigger = {
		NOT = { exists = scope:story.var:had_event_2005 }
		exists = cp:councillor_chancellor
	}

	weight_multiplier = {
		base = 1
	}

	immediate = {
		scope:story = {
			set_variable = {
				name = had_event_2005
				value = yes
			}
		}
		cp:councillor_chancellor = {
			save_scope_as = chancellor
		}
	}

	option = {
		name = commission_epic.2005.a
		add_prestige = medium_prestige_gain
		dynasty = {
			add_dynasty_prestige = medium_dynasty_prestige_gain
		}
		stress_impact = {
			honest = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
		}
	}

	option = {
		name = commission_epic.2005.b
		add_learning_lifestyle_xp = major_lifestyle_xp
		custom_tooltip = commission_epic.2005.b.tt
		scope:story = { set_variable = sway_artifact }
		stress_impact = {
			deceitful = medium_stress_impact_gain
		}
		ai_chance = {
			base = 50
		}
	}

	after = {
		clear_commission_epic_loc_variables = yes
	}
}


################################
# Bound in Faith (Court Chaplain, Lay Clergy)
# by Petter Vilberg
################################
commission_epic.2006 = {
	type = character_event
	title = commission_epic.2006.t
	desc = commission_epic.2006.desc
	theme = diplomacy
	override_background = { reference = study }
	left_portrait = scope:court_chaplain
	lower_left_portrait = scope:composer
	
	trigger = {
		NOT = { exists = scope:story.var:had_event_2006 }
		exists = cp:councillor_court_chaplain
		cp:councillor_court_chaplain = {
			NOT = { has_relation_rival = root }
		}
	}

	weight_multiplier = {
		base = 1
	}

	immediate = {
		scope:story = {
			set_variable = {
				name = had_event_2006
				value = yes
			}
		}
		cp:councillor_court_chaplain = {
			save_scope_as = court_chaplain
		}
	}

	option = { # As we always have, we always will
		name = commission_epic.2006.a
		custom_tooltip = commission_epic.2006.a.tt
		scope:story = { set_variable = piety_artifact }
		ai_chance = {
			base = 100
		}
	}

	option = { # We are the ones who lead, clergy follows
		name = commission_epic.2006.b
		flavor = commission_epic.2006.b.flavor
		add_prestige = medium_prestige_gain
		add_learning_lifestyle_xp = major_lifestyle_xp
		dynasty = {
			add_dynasty_prestige = minor_dynasty_prestige_value
		}
		ai_chance = {
			base = 100
		}
	}
	
	option = { # Family comes first in all things
		name = commission_epic.2006.c
		trigger = {
			dynasty = scope:court_chaplain.dynasty
		}
		custom_tooltip = commission_epic.2006.c.same_dynasty
		add_learning_lifestyle_xp = major_lifestyle_xp
		dynasty = {
			add_dynasty_prestige = medium_dynasty_prestige_value
		}
		ai_chance = {
			base = 100
		}
	}

	after = {
		clear_commission_epic_loc_variables = yes
	}
}

#################################
# Propaganda Chronicle Events (FP2 Additions)
# 6000-6666 
##################################

scripted_trigger composer_unavailable_trigger = {
	exists = var:composer
	scope:composer = {
		is_alive = yes
		OR = {
			is_imprisoned = yes
			has_contagious_deadly_disease_trigger = yes
			has_trait = incapable
			NOR = {
				is_courtier_of = scope:story.story_owner
				is_foreign_court_or_pool_guest_of = scope:story.story_owner
			}
		}
	}
}

scripted_trigger composer_dead_trigger = {
	exists = var:composer
	scope:composer = { is_alive = no	}
}

########################
# The Empty Event 
# by Ola Jentzsch  
########################

commission_epic.6000 = { #This is a safeguard to set up the chain so it doesn't break due to changing circumstances 
	type = character_event
	hidden = yes

	immediate = {


		if = {
			limit = {
				any_character_to_title_neighboring_county = { 
					count >= 3 
					holder = {
						NOT = {
							is_vassal_of = root	
						}
					}
				}
			}
			trigger_event = {
  				id = commission_epic.6001 #the expected progression
  			}
		}
		else_if = {
			limit = {
				any_character_to_title_neighboring_county = { 
					count < 3 
					holder = {
						NOT = {
							is_vassal_of = root	
						}
					}
				}
			}
			trigger_event = {
  				id = commission_epic.6005 #a fallback event, if the chain breaks
  			}
		}
	}
}

########################
# Some Small Embellishments  
# by Ola Jentzsch  
########################

commission_epic.6001 = {
	type = character_event
	title = commission_epic.6001.t
	desc ={
		first_valid = {
			triggered_desc = {
				trigger = { 
					OR = { #this trigger works in this event, but not in 6003 and 6004 - might it be due to a failure to save it through the "empty" event 6002? 
						scope:story.var:epic_approach = flag:writer 
						scope:story.var:epic_approach = flag:servant
					}
				}
				desc = commission_epic.6001.writerservant
			}
			desc = commission_epic.6001.scribes
		}
	}
	theme = diplomacy
	override_background = { reference = study }
	left_portrait = {
		character = scope:composer
		animation = chancellor 
	}

	trigger = {
		composer_unavailable_trigger = no
		composer_dead_trigger = no 
	}


	option = { #Embellish whatever you want, just get it finished! 
		name = commission_epic.6001.a

		custom_tooltip = commission_epic.less_credible

		set_variable = {
			name = lie_positive
			value = flag:dubious_claims	#this makes sure that your choice is remembered later in the chain
		}

		trigger_event = {
  			id = commission_epic.6002
  			days = { 20 40 }
  		}

  		stress_impact = {
			diligent = minor_stress_impact_gain 
			honest = medium_stress_impact_gain
			just = medium_stress_impact_gain
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = 1
				ai_boldness = 0.5
				ai_honor = -1
			}
		}
	}

	option = { #Just take my gold, and do more research
		name = commission_epic.6001.b

		custom_tooltip = commission_epic.more_credible 

		remove_short_term_gold = medium_gold_value  
		
		set_variable = {
			name = lie_negative
			value = flag:credible_claims #this makes sure that your choice is remembered later in the chain
		}

		trigger_event = {
  			id = commission_epic.6002
  			days = { 20 40 }
  		}

  		stress_impact = {
			deceitful = medium_stress_impact_gain
			greedy = medium_stress_impact_gain
			impatient = medium_stress_impact_gain

		}
		
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = -1
				ai_rationality = 0.5
				ai_honor = 1
			}
		}
	}
}

########################
# Empty Event #2
# by Ola Jentzsch  
########################

commission_epic.6002 = { #This is a safeguard to set up the chain so it doesn't break due to changing circumstances 
	type = character_event
	hidden = yes

	immediate = {
		if = {
			limit = {
				AND = {
					any_character_to_title_neighboring_county = { 
						count >= 3 
						holder = {
							NOT = {
								is_vassal_of = root	
							}
						}
					}
					exists = var:lie_positive 
					var:lie_positive = flag:dubious_claims
				}
			}
			trigger_event = {
  				id = commission_epic.6003 
  			}
		}

		else_if = {
			limit = {
				AND = {
					any_character_to_title_neighboring_county = { 
						count >= 3 
						holder = {
							NOT = {
								is_vassal_of = root	
							}
						}
					}
					exists = var:lie_negative 
					var:lie_negative = flag:credible_claims
				}
			}
			trigger_event = {
  				id = commission_epic.6004 
  			}
  		}

			
  		else_if = {
			limit = {
				any_character_to_title_neighboring_county = { 
					count < 3 
					holder = {
						NOT = {
							is_vassal_of = root	
						}
					}
				}
			}
			trigger_event = {
  				id = commission_epic.6005 #the fallback event again, if there is less than three proper counties to scope for any reason. 
  			}
		}
	}
}

########################
# Cold Claims 
# by Ola Jentzsch  
########################

commission_epic.6003 = {
	type = character_event
	title = commission_epic.6003.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:story.var:epic_approach = flag:writer }
				desc = commission_epic.6003.writer
			}
			triggered_desc = {
				trigger = { scope:story.var:epic_approach = flag:servant }
				desc = commission_epic.6003.servant
			}
			desc = commission_epic.6003.scribes #the triggers above do not work, but defaults to this 
		}
	}
	theme = diplomacy
	override_background = { reference = study }
	left_portrait = {
		character = scope:composer
		animation = chancellor 
	}

	trigger = {
		composer_unavailable_trigger = no
		composer_dead_trigger = no 
	}

	immediate = {
		
		random_character_to_title_neighboring_county = { 
			limit = {
				holder = {
					NOT = {
						is_vassal_of = root 		
					}
				}		
			}
			save_scope_as = neighboring_county_1  
		}

		random_character_to_title_neighboring_county = { 
			limit = {
				NOT = {
					holder = {	is_vassal_of = root }
					this = scope:neighboring_county_1
				}		
			}
			save_scope_as = neighboring_county_2  
		}

		random_character_to_title_neighboring_county = { 
			limit = {
				NOT = {
					holder = {	is_vassal_of = root }
					this = scope:neighboring_county_1
					this = scope:neighboring_county_2
				}		
			}
			save_scope_as = neighboring_county_3 
		}

		create_character = {
			age = { 20 50 }
 			location = root.capital_province
 			gender_female_chance = 50 
  			culture = root.culture
  			faith = root.faith
			dynasty = none 
			save_scope_as = ancestor_1 
		}
	}
	
	option = { # All of it is true!
		name = commission_epic.6003.a
		
		add_unpressed_claim = scope:neighboring_county_1
		add_unpressed_claim = scope:neighboring_county_2
		add_unpressed_claim = scope:neighboring_county_3

		custom_tooltip = commission_epic.paranoid_neighbors  #your neighbors gets really paranoid when they learn about this
		hidden_effect = {
			every_neighboring_realm_same_rank_owner = {
				add_opinion = {
					target = root
					modifier = bizarre_claims_opinion
				}
			}
		}


		stress_impact = {
			family_first = medium_stress_impact_gain
			humble = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = 1
			}
		}
	}

	option = { # county_1 seems good! 
		name = commission_epic.6003.b

		add_unpressed_claim = scope:neighboring_county_1
	}

	option = { # county_2 seems good! 
		name = commission_epic.6003.c

		add_unpressed_claim = scope:neighboring_county_2
	}

	option = { # county_3 seems good! 
		name = commission_epic.6003.d

		add_unpressed_claim = scope:neighboring_county_3
	}
	
	after = {
		scope:ancestor_1 = { silent_disappearance_effect = yes	}

		trigger_event = { #this triggers the final event, where you are supposed to get an artifact as a reward
  			id = commission_epic.6006 
  			days = { 20 40 }
  		}
	}
}

################################
 # Credible Claims
 # By Ola Jentzsch
################################
commission_epic.6004 = {
	type = character_event
	title = commission_epic.6004.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { 
					OR = { #this trigger does not work 
						scope:story.var:epic_approach = flag:writer 
						scope:story.var:epic_approach = flag:servant
					}
				}
				desc = commission_epic.6004.writerservant
			}
			desc = commission_epic.6004.scribes
		}
	}
	theme = diplomacy
	override_background = { reference = study }
	left_portrait = {
		character = scope:composer
		animation = chancellor 
	}

	trigger = {
		composer_unavailable_trigger = no
		composer_dead_trigger = no 
	}


	immediate = {
		
		random_character_to_title_neighboring_county = { 
			limit = {
				holder = {
					NOT = {
						is_vassal_of = root 		
					}
				}		
			}
			save_scope_as = neighboring_county_1  
		}

		random_character_to_title_neighboring_county = { 
			limit = {
				NOT = {
					holder = {	is_vassal_of = root }
					this = scope:neighboring_county_1
				}		
			}
			save_scope_as = neighboring_county_2  
		}

		create_character = {
			age = { 20 50 }
 			location = root.capital_province
 			gender_female_chance = 50 
  			culture = root.culture
  			faith = root.faith
			dynasty = none 
			save_scope_as = ancestor_1 
		}
	}
	
	option = { # Why not both of them? 
		name = commission_epic.6004.a
		
		add_pressed_claim = scope:neighboring_county_1
		add_pressed_claim = scope:neighboring_county_2
		
		custom_tooltip = commission_epic.paranoid_neighbors  #your neighbors gets really paranoid when they learn about this
		hidden_effect = {
			every_neighboring_realm_same_rank_owner = {
				add_opinion = {
					target = root
					modifier = bizarre_claims_opinion
				}
			}
		}


		stress_impact = {
			family_first = medium_stress_impact_gain
			humble = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = 1
			}
		}
	}

	option = { #[County] is certainly part of my inheritance!
		name = commission_epic.6004.b

		add_pressed_claim = scope:neighboring_county_1
	}

	option = { # I have always felt like [neighboring_county_2.GetNameNoTier] should belong to me
		name = commission_epic.6004.c

		add_pressed_claim = scope:neighboring_county_2
	}
	
	after = {
		scope:ancestor_1 = { silent_disappearance_effect = yes	}	

		trigger_event = { #this triggers the final event, where you are supposed to get an artifact as a reward
  			id = commission_epic.6006 
  			days = { 20 40 }
  		}
	}
}


################################
# A Claimless Affair
# By Ola Jentzsch
################################

commission_epic.6005 = { #This is a safeguard event in the case the chain breaks due to changing circumstances. You'll still be rewarded with an artifact, though not any claims.
	type = character_event
	title = commission_epic.6005.t
	desc ={
		first_valid = {
			triggered_desc = {
				trigger = { 
					OR = {
						scope:story.var:epic_approach = flag:writer 
						scope:story.var:epic_approach = flag:servant
					}
				}
				desc = commission_epic.6005.writerservant
			}
			desc = commission_epic.6005.scribes
		}
	}
	theme = diplomacy
	override_background = { reference = study }
	left_portrait = {
		character = scope:composer
		animation = worry
	}

	artifact = {
        target = scope:propaganda_chronicle 
        position = lower_right_portrait
    }

	trigger = {
		composer_unavailable_trigger = no
		composer_dead_trigger = no 
	}

	immediate = {
		
		save_scope_as = owner
		set_artifact_rarity_masterwork = yes 

		if = {
			limit = {
				scope:composer = { artifacts_use_indian_books_trigger = yes }
			}
			if = {
				limit = { has_royal_court = yes }
				create_artifact = {
					name = half_baked_propaganda_chronicle_name
					creator = scope:composer
					description = half_baked_propaganda_chronicle_desc
					visuals = indian_book
					type = book
					modifier = artifact_half_baked_propaganda_chronicle_modifier
					wealth = scope:wealth  # This comes from the scripted effect above
					quality = scope:quality # This comes from the scripted effect above
					save_scope_as = propaganda_chronicle
				}
			}
			else = {
				create_artifact = {
					name = half_baked_propaganda_chronicle_name
					creator = scope:composer
					description = half_baked_propaganda_chronicle_desc
					visuals = indian_book
					type = journal
					modifier = artifact_half_baked_propaganda_chronicle_modifier
					wealth = scope:wealth  # This comes from the scripted effect above
					quality = scope:quality # This comes from the scripted effect above
					save_scope_as = propaganda_chronicle
				}
				scope:propaganda_chronicle = {
					set_artifact_feature_group = book_subject
					set_artifact_feature_group = book_cover_material
				}
			}
		}
		else = {
			if = {
				limit = { has_royal_court = yes }
				create_artifact = {
					name = half_baked_propaganda_chronicle_name
					creator = scope:composer
					description = half_baked_propaganda_chronicle_desc
					visuals = book
					type = book
					modifier = artifact_half_baked_propaganda_chronicle_modifier
					wealth = scope:wealth  # This comes from the scripted effect above
					quality = scope:quality # This comes from the scripted effect above
					save_scope_as = propaganda_chronicle
				}
			}
			else = {
				create_artifact = {
					name = half_baked_propaganda_chronicle_name
					creator = scope:composer
					description = half_baked_propaganda_chronicle_desc
					visuals = book
					type = journal
					modifier = artifact_half_baked_propaganda_chronicle_modifier
					wealth = scope:wealth  # This comes from the scripted effect above
					quality = scope:quality # This comes from the scripted effect above
					save_scope_as = propaganda_chronicle
				}
				scope:propaganda_chronicle = {
					set_artifact_feature_group = book_subject
					set_artifact_feature_group = book_cover_material
				}
			}
		}

		add_prestige = medium_prestige_loss

	}

		
	option = { # To the oubliette you go!
		name = commission_epic.6005.a
		
		trigger = {
			OR = {
				scope:story.var:epic_approach = flag:writer 
				scope:story.var:epic_approach = flag:servant
			}
		}
		
		scope:composer = { 
  			hard_imprison_character_effect = {
  				TARGET = this
  				IMPRISONER = root
   			}
   		}

   		add_tyranny = minor_tyranny_value

		stress_impact = {
			compassionate = medium_stress_impact_gain
			forgiving = medium_stress_impact_gain
			vengeful = minor_stress_impact_loss
			wrathful = minor_stress_impact_loss
			sadistic = minor_stress_impact_loss
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_vengefulness = 1
			}
		}
	}

	option = { # You incompetent fools...
		name = commission_epic.6005.b

		trigger = {	scope:story.var:epic_approach = flag:scribes }

		stress_impact = {
			ambitious = medium_stress_impact_gain 
			august = medium_stress_impact_gain
			arrogant = medium_stress_impact_gain
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = 1
			}
		}
	}

	option = { # Is this HighGod punishing me for my vanity? 
		name = commission_epic.6005.c

		stress_impact = {
			ambitious = medium_stress_impact_gain
			arrogant = medium_stress_impact_gain
			content = minor_stress_impact_loss
			zealous = minor_stress_impact_loss 
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 1
			}
		}
	}

	option = { # At least I got a chronicle... 
		name = commission_epic.6005.d

		stress_impact = {
			arrogant = medium_stress_impact_gain
			wrathful = medium_stress_impact_gain
			vengeful = medium_stress_impact_gain
			calm = minor_stress_impact_loss
			content = minor_stress_impact_loss
			temperate = minor_stress_impact_loss 
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 1
			}
		}
	}

	after = {

		hidden_effect = {
			scope:story = {
				end_story = yes
			}
		}
	}
}

################################
# Potent Propaganda  (final event)
# By Ola Jentzsch
################################

commission_epic.6006 = { 
	type = character_event
	title = commission_epic.6006.t
	desc ={
		first_valid = {
			triggered_desc = {
				trigger = { 
					OR = {
						scope:story.var:epic_approach = flag:writer 
						scope:story.var:epic_approach = flag:servant
					}
				}
				desc = commission_epic.6006.writerservant
			}
			desc = commission_epic.6006.scribes
		}
	}
	theme = diplomacy
	override_background = { reference = study }
	left_portrait = {
		character = scope:composer
		animation = happiness
	}

	artifact = {
        target = scope:propaganda_chronicle 
        position = lower_right_portrait
    }

	trigger = {
		composer_unavailable_trigger = no
		composer_dead_trigger = no 
	}

	immediate = {
		root = { save_scope_as = owner }
		set_artifact_rarity_illustrious = yes 


		if = {
			limit = {
				scope:composer = { artifacts_use_indian_books_trigger = yes }
			}
			if = {
				limit = { has_royal_court = yes }

				create_artifact = {
					name = propaganda_chronicle_name
					creator = scope:composer
					description = propaganda_chronicle_desc
					visuals = indian_book
					type = book
					modifier = artifact_propaganda_chronicle_modifier
					wealth = scope:wealth  # This comes from the scripted effect above
					quality = scope:quality # This comes from the scripted effect above
					save_scope_as = propaganda_chronicle
				}
			}
			else = {
				create_artifact = {
					name = propaganda_chronicle_name
					creator = scope:composer
					description = propaganda_chronicle_desc
					visuals = indian_book
					type = miscellaneous
					modifier = artifact_propaganda_chronicle_modifier
					wealth = scope:wealth  # This comes from the scripted effect above
					quality = scope:quality # This comes from the scripted effect above
					save_scope_as = propaganda_chronicle
				}
				hidden_effect = {
					scope:propaganda_chronicle = {
						set_artifact_feature_group = book_subject
						set_artifact_feature_group = book_cover_material
					}
				}
			}
		}
		else = {
			if = {
				limit = { has_royal_court = yes }

				create_artifact = {
					name = propaganda_chronicle_name
					creator = scope:composer
					description = propaganda_chronicle_desc
					visuals = book
					type = book
					modifier = artifact_propaganda_chronicle_modifier
					wealth = scope:wealth  # This comes from the scripted effect above
					quality = scope:quality # This comes from the scripted effect above
					save_scope_as = propaganda_chronicle
				}
			}
			else = {
				create_artifact = {
					name = propaganda_chronicle_name
					creator = scope:composer
					description = propaganda_chronicle_desc
					visuals = book
					type = journal
					modifier = artifact_propaganda_chronicle_modifier
					wealth = scope:wealth  # This comes from the scripted effect above
					quality = scope:quality # This comes from the scripted effect above
					save_scope_as = propaganda_chronicle
				}
				hidden_effect = {
					scope:propaganda_chronicle = {
						set_artifact_feature_group = book_subject
						set_artifact_feature_group = book_cover_material
					}
				}
			}
		}

	}
		
	option = { # Perfect!
		name = commission_epic.6006.a
	}

	after = {
		hidden_effect = {
			scope:story = {
				end_story = yes
			}
		}
	}			
}

#################################
# Ending & Maintenance Events
# 9000-9999
##################################

#########################################
# The Epic is Complete (Regular Ending)
# by Petter Vilberg
#########################################
commission_epic.9001 = {
	type = character_event
	title = commission_epic.9001.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:story.var:epic_approach = flag:writer }
				desc = commission_epic.9001.writer
			}
			triggered_desc = {
				trigger = { scope:story.var:epic_approach = flag:servant }
				desc = commission_epic.9001.servant
			}
			desc = commission_epic.9001.scribes
		}
		desc = commission_epic.9001.conclusion
	}
	theme = diplomacy
	override_background = { reference = study }
	left_portrait = root
	right_portrait = {
		character = scope:composer
		animation = happiness
	}
	artifact = {
        target = scope:newly_created_artifact
        position = lower_right_portrait
    }

	immediate = {
		if = {
			limit = { has_royal_court = no }
			save_temporary_scope_value_as = {
				name = should_be_trinket
				value = yes
			}
		}
		if = {
			limit = {
				scope:story = {
					OR = {
						has_variable = opinion_artifact
						has_variable = piety_artifact
						has_variable = advantage_artifact
						has_variable = scheme_artifact
						has_variable = sway_artifact
					}
				}
			}
			set_variable = {
				name = commission_epic_quality
				value = {
					add = {
						value = scope:story.var:final_outcome_chance
						divide = 2
					}
					min = 75
				}
			}

			if = {
				limit = { exists = scope:composer }
				scope:composer = {
					save_scope_as = author
					save_scope_as = inspiration_owner
				}
				create_artifact_book_effect = { #using effect to ensure that scope:owner is set properly
					OWNER = root
					CREATOR = scope:author
					SET_SUBJECT = flag:family_epic
					SET_TOPIC = flag:family_epic
				}
			}
			else = {
				hidden_effect = {
					random_dummy_gender_effect = yes
				}
				create_artifact_book_effect = { #using effect to ensure that scope:owner is set properly
					OWNER = root
					CREATOR = scope:dummy_gender
					SET_SUBJECT = flag:family_epic
					SET_TOPIC = flag:family_epic
				}
			}

			#Small boost from perspectives
			hidden_effect_new_object = {
				if = {
					limit = {
						scope:story = { has_variable = prestige_artifact }
					}
					scope:newly_created_artifact = {
						add_artifact_modifier = artifact_monthly_prestige_2_modifier
					}
				}
				if = {
					limit = {
						scope:story = { has_variable = dynasty_prestige_artifact }
					}
					scope:newly_created_artifact = {
						add_artifact_modifier = artifact_monthly_prestige_add_2_modifier #This is renown
					}
				}
				if = {
					limit = {
						scope:story = { has_variable = extra_pious_artifact }
					}
					scope:newly_created_artifact = {
						add_artifact_modifier = artifact_domain_tax_same_faith_mult_2_modifier
					}
				}
			}
		}
	}
	
	option = { # Composer
		name = commission_epic.9001.a
		trigger = {
			exists = scope:composer
		}
		if = {
			limit = {
				scope:story.var:epic_approach = flag:servant
			}
			save_scope_value_as = {
				name = servant_composer
				value = yes
			}
		}
		trigger_event = { # Follow-up for Composer
			id = commission_epic.9000
			days = 10
		}
	}

	option = { # Scribes
		name = commission_epic.9001.a
		trigger = {
			NOT = { exists = scope:composer }	
		}
	}
	
	after = {
		if = {
			limit = { exists = scope:newly_created_artifact }
			show_as_tooltip = {
				scope:newly_created_artifact = { set_owner = root }
			}
		}
		if = {
			limit = {
				scope:story.var:perspective = flag:personal_prestige
			}
			add_prestige = medium_prestige_gain
			dynasty = {
				add_dynasty_prestige = minor_dynasty_prestige_value
			}
		}
		else_if = {
			limit = {
				scope:story.var:perspective = flag:dynasty_prestige
			}
			add_prestige = minor_prestige_gain
			dynasty = {
				add_dynasty_prestige = medium_dynasty_prestige_value
			}
		}
		else_if = {
			limit = {
				scope:story.var:perspective = flag:piety
			}
			add_prestige = medium_prestige_gain
			add_piety = major_piety_gain
		}
		if = {
			limit = { has_variable = commission_epic_quality }
			remove_variable = commission_epic_quality
		}
		hidden_effect = {
			scope:story = {
				end_story = yes
			}
		}
		clear_commission_epic_loc_variables = yes
	}
}


################################
# The Epic is Complete (Great Ending)
# by Petter Vilberg
################################
commission_epic.9002 = {
	type = character_event
	title = commission_epic.9002.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					OR = {
						scope:story.var:epic_approach = flag:writer
					scope:story.var:epic_approach = flag:servant
					}
				}
				desc = commission_epic.9002.writer
			}
			desc = commission_epic.9002.scribes
		}
		desc = commission_epic.9002.conclusion
	}
	theme = diplomacy
	override_background = { reference = study }
	left_portrait = {
		character = root
		animation = happiness
	}
	right_portrait = {
		character = scope:composer
		animation = ecstasy
	}
    artifact = {
        target = scope:newly_created_artifact
        position = lower_right_portrait
    }

	immediate = {
		play_music_cue = mx_cue_positive_effect
		if = {
			limit = { has_royal_court = no }
			save_temporary_scope_value_as = {
				name = should_be_trinket
				value = yes
			}
		}
		set_variable = {
			name = commission_epic_quality
			value = {
				add = {
					value = scope:story.var:final_outcome_chance
					divide = 2
				}
				min = 75
			}
		}
		if = {
			limit = { exists = scope:composer }
			scope:composer = {
				save_scope_as = author
				save_scope_as = inspiration_owner
			}
			create_artifact_book_effect = { #using effect to ensure that scope:owner is set properly
				OWNER = root
				CREATOR = scope:author
				SET_SUBJECT = flag:family_epic_great
				SET_TOPIC = flag:family_epic_great
			}
		}
		else = {
			hidden_effect = {
				random_dummy_gender_effect = yes
			}
			create_artifact_book_effect = { #using effect to ensure that scope:owner is set properly
				OWNER = root
				CREATOR = scope:dummy_gender
				SET_SUBJECT = flag:family_epic_great
				SET_TOPIC = flag:family_epic_great
			}
		}
		#Small boost from perspectives
		hidden_effect_new_object = {
			if = {
				limit = {
					scope:story = { has_variable = prestige_artifact }
				}
				scope:newly_created_artifact = {
					add_artifact_modifier = artifact_monthly_prestige_2_modifier
				}
			}
			if = {
				limit = {
					scope:story = { has_variable = dynasty_prestige_artifact }
				}
				scope:newly_created_artifact = {
					add_artifact_modifier = artifact_monthly_prestige_add_2_modifier #This is renown
				}
			}
			if = {
				limit = {
					scope:story = { has_variable = extra_pious_artifact }
				}
				scope:newly_created_artifact = {
					add_artifact_modifier = artifact_domain_tax_same_faith_mult_2_modifier
				}
			}
		}
	}
	
	
	option = { # Composer
		name = commission_epic.9002.a
		trigger = {
			exists = scope:composer
		}
		if = {
			limit = {
				scope:story.var:epic_approach = flag:servant
			}
			save_scope_value_as = {
				name = servant_composer
				value = yes
			}
		}
		trigger_event = { # Fallback in case something happens
			id = commission_epic.9000
			days = 10
		}
	}

	option = { # Scribes
		name = commission_epic.9002.a
		trigger = {	
			NOT = { exists = scope:composer }
		}
	}

	after = {
		scope:writer ?= {
			if = {	
				limit = {
					is_foreign_court_guest = yes
				}
				return_to_court = yes
			}
		}
		show_as_tooltip = {
			scope:newly_created_artifact = { set_owner = root }
		}
		if = {
			limit = {
				scope:story.var:perspective = flag:personal_prestige
			}
			add_prestige = medium_prestige_gain
			dynasty = {
				add_dynasty_prestige = minor_dynasty_prestige_value
			}
		}
		else_if = {
			limit = {
				scope:story.var:perspective = flag:dynasty_prestige
			}
			add_prestige = minor_prestige_gain
			dynasty = {
				add_dynasty_prestige = medium_dynasty_prestige_value
			}
		}
		else_if = {
			limit = {
				scope:story.var:perspective = flag:piety
			}
			add_prestige = medium_prestige_gain
			add_piety = major_piety_gain
		}
		remove_variable = commission_epic_quality

		hidden_effect = {
			scope:story = {
				end_story = yes
			}
		}
		clear_commission_epic_loc_variables = yes
	}
}



################################
# Writer is about to depart
# by Petter Vilberg
################################
commission_epic.9000 = {
	hidden = yes

	immediate = {
		if = {
			limit = {
				scope:composer = { is_alive = yes }
				NOR = {
					has_relation_friend = scope:composer
					has_relation_nemesis = scope:composer
				}
				scope:composer = {
					opinion = {
						target = root
						value > 0
					}
				}
			}
			if = {
				limit = {
					OR = {
						has_relation_potential_friend = scope:composer
						has_relation_friend = scope:composer
					}
				}
				save_scope_value_as = {
					name = friendship
					value = yes
				}
			}
			else = {
				progress_towards_friend_effect = {
					CHARACTER = scope:composer
					OPINION = 0
					REASON = friend_composer_epic
				}
				random = {
					chance = 50
					save_scope_value_as = {
						name = friendship
						value = yes
					}
				}
			}
		}

		if = {
			limit = {
				scope:composer = {
					OR = {
						is_alive = no
						is_imprisoned = yes
						NOR = {
							is_foreign_court_or_pool_guest_of = root
							is_courtier_of = root
						}
					}
				}
			}
			trigger_event = commission_epic.9104
		}
		else_if = {
			limit = {
				scope:composer = {
					is_foreign_court_or_pool_guest_of = root
				}
			}
			trigger_event = commission_epic.9101
		}
		else_if = {
			limit = {
				exists = scope:servant_composer
				scope:composer = {
					is_courtier_of = root
				}
			}
			trigger_event = commission_epic.9102
		}
		else_if = {
			limit = {
				scope:composer = {
					is_courtier_of = root
				}
			}
			trigger_event = commission_epic.9103
		}
	}
}

# Do you want to keep Composer around?
commission_epic.9101 = {
	type = character_event
	title = commission_epic.9101.t
	desc = commission_epic.9101.desc
	theme = diplomacy
	override_background = { reference = study }
	left_portrait = scope:composer

	option = {
		name = commission_epic.9101.a
		trigger = {
			NOT = { exists = scope:friendship }
		}
		remove_courtier_or_guest = { character = scope:composer }
		ai_chance = {
			base = 200
		}
	}

	option = {
		name = commission_epic.9101.b
		trigger = {
			NOT = { exists = scope:friendship }
		}
		hidden_effect = {
			if = {
				limit = {
					can_set_relation_potential_friend_trigger = { CHARACTER = scope:composer }
				}
				set_relation_potential_friend = scope:composer
			}
		}
		remove_short_term_gold = medium_gold_value
		add_courtier = scope:composer
		ai_chance = {
			base = 100
		}
	}
	
	option = {
		name = commission_epic.9101.c
		trigger = {
			exists = scope:friendship
		}
		if = {
			limit = {
				can_set_relation_friend_trigger = { CHARACTER = scope:composer }
			}
			set_relation_friend = { reason = friend_composer_epic target = scope:composer }
		}
		add_courtier = scope:composer
		ai_chance = {
			base = 100
		}
	}
	
	option = {
		name = commission_epic.9101.d
		trigger = {
			exists = scope:friendship
		}
		if = {
			limit = {
				can_set_relation_friend_trigger = { CHARACTER = scope:composer }
			}
			set_relation_friend = { reason = friend_composer_epic target = scope:composer }
		}
		custom_tooltip = commission_epic.9101.d.tt
		remove_courtier_or_guest = { character = scope:composer }
		ai_chance = {
			base = 200
		}
	}

	after = {
		hidden_effect = {
			scope:composer = {
				remove_character_flag = blocked_from_leaving
			}
		}
		clear_commission_epic_loc_variables = yes
	}
}

# What do you do with the servant?
commission_epic.9102 = {
	type = character_event
	title = commission_epic.9101.t
	desc = commission_epic.9102.desc
	theme = diplomacy
	override_background = { reference = study }
	left_portrait = scope:composer

	option = { # Let go
		name = commission_epic.9102.a
		flavor = commission_epic.9102.a.flavor
		trigger = {
			NOT = { exists = scope:friendship }
		}
		hidden_effect = {
			scope:composer = {
				select_and_move_to_pool_effect = yes
			}
		}
		show_as_tooltip = {
			remove_courtier_or_guest = scope:composer
		}
		ai_chance = {
			base = 200
		}
	}

	option = { # Keep around, obviously
		name = commission_epic.9102.b
		trigger = {
			NOT = { exists = scope:friendship }
		}
		hidden_effect = {
			if = {	
				limit = {
					can_set_relation_potential_friend_trigger = { CHARACTER = scope:composer }
				}
				set_relation_potential_friend = scope:composer
			}
		}
		scope:composer = {
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 30
			}
		}
		ai_chance = {
			base = 100
		}
	}
	
	option = {
		name = commission_epic.9102.c
		trigger = {
			exists = scope:friendship
		}
		if = {
			limit = {
				can_set_relation_friend_trigger = { CHARACTER = scope:composer }
			}
			set_relation_friend = { reason = friend_composer_epic target = scope:composer }
		}
		scope:composer = {
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 30
			}
		}
		ai_chance = {
			base = 100
		}
	}
	
	option = {
		name = commission_epic.9102.a
		name = commission_epic.9102.a.flavor
		trigger = {
			exists = scope:friendship
		}
		if = {
			limit = {
				can_set_relation_friend_trigger = { CHARACTER = scope:composer }
			}
			set_relation_friend = { reason = friend_composer_epic target = scope:composer }
		}
		scope:composer = {
			select_and_move_to_pool_effect = yes
		}
		ai_chance = {
			base = 200
		}
	}

	after = {
		hidden_effect = {
			scope:composer = {
				remove_character_flag = blocked_from_leaving
			}
		}
		clear_commission_epic_loc_variables = yes
	}
}


# Fallback: Courtier but not Servant - Friendship?
commission_epic.9103 = {
	type = character_event
	title = commission_epic.9101.t
	desc = commission_epic.9103.desc
	theme = diplomacy
	override_background = { reference = study }
	left_portrait = scope:composer

	option = { # Let go
		name = commission_epic.9103.a
		if = {
			limit = {
				can_set_relation_friend_trigger = { CHARACTER = scope:composer }
			}
			set_relation_friend = { reason = friend_composer_stories target = scope:composer }
		}
		scope:composer = {
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 30
			}
		}
	}

	after = {
		hidden_effect = {
			scope:composer = {
				remove_character_flag = blocked_from_leaving
			}
		}
		clear_commission_epic_loc_variables = yes
	}
}

# Something has happened to the Composer
commission_epic.9104 = {
	type = character_event
	title = commission_epic.9101.t
	desc = commission_epic.9104.desc
	theme = diplomacy
	override_background = { reference = study }
	left_portrait = scope:composer

	option = {
		name = commission_epic.9104.a
		trigger = {
			scope:composer = {
				is_alive = yes
			}
			any_vassal_or_below = {
				this = scope:composer
			}
		}
		exclusive = yes
		if = {
			limit = {
				can_set_relation_friend_trigger = { CHARACTER = scope:composer }
			}
			set_relation_friend = { reason = friend_composer_epic target = scope:composer }
		}
	}

	option = {
		name = commission_epic.9104.b
		flavor = commission_epic.9104.b.flavor
	}

	after = {
		clear_commission_epic_loc_variables = yes
	}
}

#########################
# The Composer is gone
# by Petter Vilberg
#########################
commission_epic.9998 = {
	type = character_event
	title = commission_epic.9998.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:composer = {
						is_imprisoned = yes
						imprisoner = root
					}
				}
				desc = commission_epic.9998.imprisoned_by_me
			}
			triggered_desc = {
				trigger = {
					scope:composer = {
						is_imprisoned = yes
					}
				}
				desc = commission_epic.9998.imprisoned
			}
			triggered_desc = {
				trigger = {
					scope:composer = {
						OR = {
							has_contagious_deadly_disease_trigger = yes
							has_trait = incapable
							has_trait = wounded_3
						}
					}
				}
				desc = commission_epic.9998.incapacitated
			}
			desc = commission_epic.9998.left_court
		}
		desc = commission_epic.9998.ending
	}
	theme = diplomacy
	override_background = { reference = study }
	left_portrait = scope:composer

	immediate = {
		scope:story = {
			remove_variable = composer
		}
	}

	option = { # The Scribes will be able to finish it
		name = commission_epic.9998.a
		custom_tooltip = commission_epic.9998.tt
		scope:story = {
			set_variable = {
				name = epic_approach
				value = flag:scribes
			}
			change_variable = {
				name = final_outcome_chance
				add = -20
			}
		}
	}

	after = {
		clear_commission_epic_loc_variables = yes
	}
}


#########################
# The Composer has died
# by Petter Vilberg
#########################
commission_epic.9999 = {
	type = character_event
	title = commission_epic.9999.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:composer = {
						is_alive = no
						killer ?= root
					}
				}
				desc = commission_epic.9999.murdered_by_me
			}
			desc = commission_epic.9999.died
		}
	}
	theme = diplomacy
	override_background = { reference = study }
	left_portrait = scope:composer

	immediate = {
		scope:story = {
			remove_variable = composer
		}
	}

	option = { # The Scribes will be able to finish it
		name = commission_epic.9999.a
		custom_tooltip = commission_epic.9998.tt
		scope:story = {
			set_variable = {
				name = epic_approach
				value = flag:scribes
			}
			change_variable = {
				name = final_outcome_chance
				add = -20
			}
		}
	}

	after = {
		clear_commission_epic_loc_variables = yes
	}
}
