﻿namespace = court_events

# High court fashion: foreign rulers admire and envy you as the peak of class and elegance, can you capitalize on this reputation?
court_events.3000 = {
	type = court_event
	title = court_events.3000.t
	desc = court_events.3000.desc
	theme = court
	cooldown = { years = 25 }
	court_scene = {
		button_position_character = scope:chancellor
		roles = {
			scope:chancellor = {
				group = event_group
				animation = debating
			}
			root = {
				group = event_group
				triggered_animation = {
					trigger = { OR = { religion = religion:eastern_orthodox_religion religion = religion:catholic_religion religion = religion:protestant_religion } }
					animation = acknowledging # anim uses crucifix scepter
				}
				animation = war_over_tie
			}
			scope:steward = {
				group = event_group
				animation = personality_content
			}
		}
	}

	trigger = {
		exists = cp:councillor_chancellor
		exists = cp:councillor_steward
		amenity_level = {
 			target = court_fashion
 			value >= 4
 		}
 		NOT = {
 			any_neighboring_top_liege_realm_owner = {
 				has_royal_court = yes
 				amenity_level = {
 					target = court_fashion
 					value > 4
 				}
 			}
 		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			amenity_level = {
 				target = court_fashion
 				value = 5
 			}
 			add = 0.5
		}
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_diplomatic }
	}

	immediate = {
		court_event_character_flag_effect = yes
		cp:councillor_chancellor = {
		 	court_event_character_flag_effect = yes
		 	save_scope_as = chancellor
		}
		cp:councillor_steward = {
			court_event_character_flag_effect = yes
		 	save_scope_as = steward
		}
	}

	# Option A: Increase opinion abroad
	option = {
		name = court_events.3000.a
		add_character_modifier = {
			modifier = court_fashion_foreign_modifier
			years = 20
		}
		stress_impact = {
			arrogant = minor_stress_impact_gain
			shy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_energy = 0.5
				ai_sociability = 0.5
			}
		}
	}

	# Option B: Spread culture
	option = {
		name = court_events.3000.b
		add_character_modifier = {
			modifier = court_fashion_culture_modifier
			years = 20
		}
		stress_impact = {
			gregarious = minor_stress_impact_gain
			humble = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_sociability = -0.5
				ai_boldness = -0.5
			}
		}
	}

	# Option C: sell fashion
	option = {
		name = court_events.3000.c
		add_character_modifier = {
			modifier = court_fashion_sell_modifier
			years = 20
		}
		stress_impact = {
			generous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = -1
			}
		}
	}
	after = {
		clear_court_event_participation = yes
		scope:chancellor = { clear_court_event_participation = yes }
		scope:steward = { clear_court_event_participation = yes }
	}
}

# Low court food: Someone complains that it's always the same soup every day
court_events.3010 = {
	type = court_event
	title = court_events.3010.t
	desc = court_events.3010.desc
	theme = court
	cooldown = { years = 20 }
	court_scene = {
		button_position_character = scope:courtier
		roles = {
			scope:courtier = {
				group = event_group
				animation = beg
			}
			root = {
				group = event_group
				animation = thinking
			}
		}
	}

	trigger = {
		amenity_level = {
 			target = court_food_quality
 			value <= 2
 		}
 		any_courtier_or_guest = {
 			is_available_ai_adult = yes
 			is_of_major_or_minor_interest_trigger = { CHARACTER = root }
 		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			amenity_level = {
 				target = court_food_quality
 				value <= 1
 			}
 			add = 0.5
		}
		modifier = {
			any_courtier_or_guest = {
 				is_available_ai_adult = yes
 				is_of_major_or_minor_interest_trigger = { CHARACTER = root }
 				has_trait = gluttonous
 			}
 			add = 0.5
 		}
 		modifier = {
			any_courtier_or_guest = {
 				is_available_ai_adult = yes
 				is_of_major_or_minor_interest_trigger = { CHARACTER = root }
 				has_trait = comfort_eater
 			}
 			add = 0.5
 		}
	}

	immediate = {
		court_event_character_flag_effect = yes
		random_courtier_or_guest = {
			limit = {
				is_available_ai_adult = yes
 				is_of_major_or_minor_interest_trigger = { CHARACTER = root }
 				OR = {
 					has_trait = gluttonous
					has_trait = comfort_eater
 				}
			}
			alternative_limit = {
				is_available_ai_adult = yes
 				is_of_major_or_minor_interest_trigger = { CHARACTER = root }
			}
			save_scope_as = courtier
		}
		scope:courtier = { court_event_character_flag_effect = yes }
	}

	# Option A: Hire chefs
	option = {
		name = court_events.3010.a
		trigger = {
			NOT = { government_has_flag = government_is_tribal }
		}
		remove_short_term_gold = minor_gold_value
		set_amenity_level = { type = court_food_quality value = 3 }
		custom_tooltip = cheaper_food_for_15_years
		add_character_flag = {
			flag = court_cheaper_food
			years = 15
		}
		stress_impact = {
			greedy = medium_stress_impact_gain
			paranoid = medium_stress_impact_gain
			humble = medium_stress_impact_gain
			temperate = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = -1
			}
			modifier = {
				has_trait = paranoid
				factor = 0
			}
		}
	}

	# Option B: it's healthy and pious!
	option = {
		name = court_events.3010.b
		add_character_modifier = {
			modifier = healthy_and_modest_diet_modifier
			years = 15
		}
		stress_impact = {
			arrogant = medium_stress_impact_gain
			gluttonous = major_stress_impact_gain
			comfort_eater = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_zeal = 0.5
			}
			modifier = {
				has_trait = lifestyle_physician
				add = 50
			}
			modifier = {
				has_trait = whole_of_body
				add = 50
			}
			modifier = {
				has_trait = paranoid
				factor = 0.5
			}
		}
	}
	# Option C: it's for my safety
	option = {
		name = court_events.3010.c
		flavor = court_events.3010.c.tt
		add_character_modifier = {
			modifier = cant_poison_soup_modifier
			years = 15
		}
		stress_impact = {
			gregarious = medium_stress_impact_gain
			trusting = major_stress_impact_gain
			gluttonous = major_stress_impact_gain
			comfort_eater = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_sociability = -0.5
			}
			modifier = {
				has_trait = paranoid
				add = 200
			}
			modifier = {
				has_trait = trusting
				factor = 0
			}
		}
	}
	after = {
		clear_court_event_participation = yes
		scope:courtier = { clear_court_event_participation = yes }
	}
}

# Low court lodgings: crappy living conditions increase the spread of sickness, what do you do?
court_events.3020 = {
	type = court_event
	title = court_events.3020.t
	desc = {
		desc = court_events.3020.desc
		triggered_desc = {
			trigger = {
				exists = scope:physician
			}
			desc = court_events.3020.desc_physician
		}
		triggered_desc = {
			trigger = {
				exists = scope:architect
			}
			desc = court_events.3020.desc_architect
		}
	}
	theme = court
	cooldown = { years = 20 }
	court_scene = {
		button_position_character = scope:courtier
		roles = {
			scope:courtier = {
				group = event_group
				animation = beg
			}
			root = {
				group = event_group
				animation = thinking
			}
			scope:physician ?= {
				group = event_group
				animation = physician
			}
		}
	}

	trigger = {
		amenity_level = {
 			target = court_lodging_standards
 			value <= 2
 		}
 		any_courtier_or_guest = {
 			is_available_ai_adult = yes
 			is_of_major_or_minor_interest_trigger = { CHARACTER = root }
 			NOR = {
 				has_court_position = court_physician_court_position
 				has_court_position = royal_architect_court_position
 			}
 		}
	}

	weight_multiplier = {
		base = 0.5
		modifier = {
			add = 0.5
			amenity_level = {
 				target = court_lodging_standards
 				value <= 1
 			}
		}
		modifier = {
			add = 0.5
			court_position:court_physician_court_position ?= {
				aptitude = {
					court_position = court_physician_court_position
					value >= 3
				}
			}
		}
		modifier = {
			add = 1
			capital_province = {
				any_province_epidemic = { }
			}
		}
		modifier = {
			add = 0.5
			capital_county = {
				any_neighboring_county = {
					has_province_with_epidemic = { intensity = any }
				}
			}
		}
	}

	immediate = {
		court_event_character_flag_effect = yes
		if = {
			limit = {
				employs_court_position = court_physician_court_position
				court_position:court_physician_court_position = {
					is_available_ai_adult = yes
					NOT = { has_court_position = royal_architect_court_position }
				}
			}
			court_position:court_physician_court_position = {
				save_scope_as = physician
				court_event_character_flag_effect = yes
			}
		}
		if = {
			limit = {
				employs_court_position = royal_architect_court_position
				court_position:royal_architect_court_position = {
					is_available_ai_adult = yes
					NOT = { has_court_position = court_physician_court_position }
				}
			}
			court_position:royal_architect_court_position = {
				save_scope_as = architect
				court_event_character_flag_effect = yes
			}
		}
		random_courtier_or_guest = {
 			limit = {
 				is_available_ai_adult = yes
 				is_of_major_or_minor_interest_trigger = { CHARACTER = root }
 				NOR = {
 					has_court_position = court_physician_court_position
 					has_court_position = royal_architect_court_position
 				}
 			}
 			save_scope_as = courtier
 			court_event_character_flag_effect = yes
 		}
 		if = {
 			limit = {
 				exists = scope:physician
 				NOT = { exists = scope:architect }
 			}
 			scope:physician = { save_scope_as = expert }
 		}
 		if = {
 			limit = {
 				exists = scope:architect
 				NOT = { exists = scope:physician }
 			}
 			scope:architect = { save_scope_as = expert }
 		}
	}

	# Option A: improve lodgings and epidemics resistance
	option = {
		name = court_events.3020.a
		trigger = {
			NOR = {
				government_has_flag = government_is_tribal
				employs_court_position = court_physician_court_position
				employs_court_position = royal_architect_court_position
			}
		}
		remove_short_term_gold = minor_gold_value
		if = {
			limit = {
				NOT = { government_has_flag = government_is_tribal }
			}
			set_amenity_level = { type = court_lodging_standards value = 3 }
		}
		capital_province = {
			add_province_modifier = {
				modifier = lodgings_epidemics_resistance_modifier
				years = 15
			}
		}
		stress_impact = {
			arrogant = minor_stress_impact_gain
			humble = minor_stress_impact_gain
			greedy = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = 0.5
				ai_compassion = 1
			}
		}
	}

	# Option B: physician or architect - improve lodgings and epidemics resistance better
	option = {
		name = court_events.3020.b
		trigger = {
			NOT = { government_has_flag = government_is_tribal }
			OR = {
				employs_court_position = court_physician_court_position
				employs_court_position = royal_architect_court_position
			}
			NAND = {
				employs_court_position = court_physician_court_position
				employs_court_position = royal_architect_court_position
			}
		}
		remove_short_term_gold = minor_gold_value
		if = {
			limit = {
				NOT = { government_has_flag = government_is_tribal }
			}
			set_amenity_level = { type = court_lodging_standards value = 3 }
			custom_tooltip = cheaper_lodgings_for_15_years
		}
		capital_province = {
			add_province_modifier = {
				modifier = lodgings_epidemics_resistance_modifier_1
				years = 15
			}
		}
		stress_impact = {
			arrogant = minor_stress_impact_gain
			humble = minor_stress_impact_gain
			greedy = medium_stress_impact_gain
		}
		ai_chance = {
			base = 200
			ai_value_modifier = {
				ai_rationality = 1
				ai_compassion = 0.5
			}
		}
	}

	# Option C: physician and architect - improve lodgings and epidemics resistance cheaper and better
	option = {
		name = court_events.3020.c
		trigger = {
			employs_court_position = court_physician_court_position
			employs_court_position = royal_architect_court_position
		}
		if = {
			limit = {
				NOT = { government_has_flag = government_is_tribal }
			}
			set_amenity_level = { type = court_lodging_standards value = 3 }
			custom_tooltip = cheaper_lodgings_for_15_years_1
		}
		capital_province = {
			add_province_modifier = {
				modifier = lodgings_epidemics_resistance_modifier_2
				years = 15
			}
		}
		stress_impact = {
			arrogant = minor_stress_impact_gain
			humble = minor_stress_impact_gain
		}
		ai_chance = {
			base = 200
			ai_value_modifier = {
				ai_rationality = 1
				ai_compassion = 0.5
			}
		}
	}

	# Option D: it's fiiiine
	option = {
		name = court_events.3020.d
		capital_province = {
			add_province_modifier = {
				modifier = lodgings_epidemics_no_resistance_modifier
				years = 15
			}
		}
		stress_impact = {
			base = minor_stress_impact_loss
			paranoid = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = 1
				ai_rationality = -0.5
			}
		}
	}
	after = {
		clear_court_event_participation = yes
		scope:physician ?= { clear_court_event_participation = yes }
		scope:architect ?= { clear_court_event_participation = yes }
		scope:courtier = { clear_court_event_participation = yes }
	}
}

# High court lodgings: an inspired character improves their inspiration
court_events.3030 = {
	type = court_event
	title = court_events.3030.t
	desc = court_events.3030.desc
	theme = court
	cooldown = { years = 10 }
	court_scene = {
		button_position_character = scope:inspiration_owner
		roles = {
			scope:inspiration_owner = {
				group = event_group
				animation = ecstasy
			}
			root = {
				group = event_group
				animation = happiness
			}
		}
	}

	trigger = {
		has_royal_court = yes
		exists = scope:inspiration
		scope:inspiration_owner = {
			is_available_ai_adult = yes
			inspiration = { #Since they're away adventuring
				NOT = { has_inspiration_type = adventure_inspiration }
			}
			NOR = {
				has_character_flag = fund_weapon_inspiration_event_cooldown
				has_character_flag = fund_armor_inspiration_event_cooldown
				has_character_flag = fund_book_inspiration_event_cooldown
				has_character_flag = fund_weaver_inspiration_event_cooldown
				has_character_flag = fund_adventure_inspiration_event_cooldown
				has_character_flag = fund_artisan_inspiration_event_cooldown
				has_character_flag = fund_smith_inspiration_event_cooldown
				has_character_flag = fund_alchemy_inspiration_event_cooldown
				has_character_flag = fund_research_inspiration_event_cooldown
				has_character_flag = fund_bow_inspiration_event_cooldown
			}
		}
		amenity_level = {
 			target = court_lodging_standards
 			value >= 4
 		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = 1
			amenity_level = {
 				target = court_lodging_standards
 				value >= 5
 			}
		}
	}

	immediate = {
		court_event_character_flag_effect = yes
		scope:inspiration_owner = {
			if = {
				limit = {
					inspiration = { has_inspiration_type = weapon_inspiration }
				}
				add_character_flag = {
					flag = fund_weapon_inspiration_event_cooldown
					days = { 30 60 }
				}
			}
			else_if = {
				limit = {
					inspiration = { has_inspiration_type = armor_inspiration }
				}
				add_character_flag = {
					flag = fund_armor_inspiration_event_cooldown
					days = { 30 60 }
				}
			}
			else_if = {
				limit = {
					inspiration = { has_inspiration_type = book_inspiration }
				}
				add_character_flag = {
					flag = fund_book_inspiration_event_cooldown
					days = { 30 60 }
				}
			}
			else_if = {
				limit = {
					inspiration = { has_inspiration_type = weaver_inspiration }
				}
				add_character_flag = {
					flag = fund_weaver_inspiration_event_cooldown
					days = { 30 60 }
				}
			}
			else_if = {
				limit = {
					inspiration = { has_inspiration_type = adventure_inspiration }
				}
				add_character_flag = {
					flag = fund_adventure_inspiration_event_cooldown
					days = { 30 60 }
				}
			}
			else_if = {
				limit = {
					inspiration = { has_inspiration_type = artisan_inspiration }
				}
				add_character_flag = {
					flag = fund_artisan_inspiration_event_cooldown
					days = { 30 60 }
				}
			}
			else_if = {
				limit = {
					inspiration = { has_inspiration_type = smith_inspiration }
				}
				add_character_flag = {
					flag = fund_smith_inspiration_event_cooldown
					days = { 30 60 }
				}
			}
			else_if = {
				limit = {
					inspiration = { has_inspiration_type = alchemy_inspiration }
				}
				add_character_flag = {
					flag = fund_alchemy_inspiration_event_cooldown
					days = { 30 60 }
				}
			}
			else_if = {
				limit = {
					inspiration = { has_inspiration_type = research_inspiration }
				}
				add_character_flag = {
					flag = fund_research_inspiration_event_cooldown
					days = { 30 60 }
				}
			}
			court_event_character_flag_effect = yes
		}
	}

	# Option A:
	option = {
		name = court_events.3030.a
		trigger = {
			has_royal_court = yes
			amenity_level = {
 				target = court_lodging_standards
 				value < 5
 			}
		}
		set_amenity_level = { type = court_lodging_standards value = 5 }
		scope:inspiration_owner = {
			change_artifact_quality_effect = { AMOUNT = 4 }
			inspiration = { change_inspiration_progress = 2 }
		}
		stress_impact = {
			base = minor_stress_impact_loss
			greedy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = -0.5
			}
		}
	}

	# Option B:
	option = {
		name = court_events.3030.b
		scope:inspiration_owner = {
			change_artifact_quality_effect = { AMOUNT = 2 }
			inspiration = { change_inspiration_progress = 1 }
		}
		stress_impact = {
			base = minor_stress_impact_loss
		}
		ai_chance = {
			base = 100
		}
	}

	after = {
		clear_court_event_participation = yes
		scope:inspiration_owner = { clear_court_event_participation = yes }
	}
}

# Low court servants: the current war in X has displaced many refugees, so you can hire them at court as higher-level servants for cheaper
court_events.3040 = {
	type = court_event
	title = court_events.3040.t
	desc = court_events.3040.desc
	theme = court
	cooldown = { years = 20 }
	court_scene = {
		button_position_character = scope:steward
		roles = {
			scope:steward = {
				group = event_group
				animation = thinking
			}
			root = {
				group = event_group
				triggered_animation = {
					trigger = { OR = { religion = religion:eastern_orthodox_religion religion = religion:catholic_religion religion = religion:protestant_religion } }
					animation = acknowledging # anim uses crucifix scepter
				}
				animation = war_over_tie
			}
		}
	}

	trigger = {
		exists = cp:councillor_steward
		amenity_level = {
 			target = court_servants
 			value <= 2
 		}
 		is_at_war = no
 		any_neighboring_top_liege_realm_owner = {
 			is_at_war = yes
 			any_realm_county = {
 				any_county_province = {
 					is_occupied = yes
 				}
 			}
 		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			amenity_level = {
 				target = court_servants
 				value <= 1
 			}
 			add = 1
		}
		modifier = {
			any_neighboring_top_liege_realm_owner = {
				is_at_war = yes
				any_realm_border_county = {
					any_neighboring_county = {
						holder.top_liege = root
					}
					any_county_province = {
						is_occupied = yes
					}
				}
			}
			add = 1
		}
	}

	immediate = {
		court_event_character_flag_effect = yes
		cp:councillor_steward = {
			save_scope_as = steward
			court_event_character_flag_effect = yes
		}
		random_neighboring_top_liege_realm_owner = {
			limit = {
				is_at_war = yes
 				any_realm_county = {
 					any_county_province = {
 						is_occupied = yes
 					}
 				}
			}
			save_scope_as = neighbor
			random_realm_county = {
				limit = {
					any_county_province = {
 						is_occupied = yes
 					}
				}
				random_county_province = {
					limit = {
						is_occupied = yes
					}
					save_scope_as = occupied_prov
				}
			}
		}
		scope:neighbor.primary_title = { save_scope_as = war_realm }
	}

	# Option A: let them in
	option = {
		name = court_events.3040.a
		every_realm_border_county = {
			limit = {
				any_neighboring_county = {
					holder.top_liege = scope:neighbor
				}
			}
			add_county_modifier = {
				modifier = court_war_immigration_modifier
				years = 15
			}
		}
		stress_impact = {
			paranoid = minor_stress_impact_gain
			callous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 0.5
			}
		}
	}

	# Option B: hire them as servants
	option = {
		name = court_events.3040.b
		trigger = {
			NOT = { government_has_flag = government_is_tribal }
		}
		set_amenity_level = { type = court_servants value = 3 }
		custom_tooltip = cheaper_servants_for_15_years
		add_character_flag = court_cheaper_servants
		stress_impact = {
			content = minor_stress_impact_gain
			paranoid = medium_stress_impact_gain
			humble = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				add = -25
				has_trait = content
			}
			modifier = {
				add = -50
				has_trait = paranoid
			}
			modifier = {
				add = -50
				has_trait = humble
			}
		}
	}

	# Option C: no thanks
	option = {
		name = court_events.3040.c
		stress_impact = {
			compassionate = medium_stress_impact_gain
		}
		ai_chance = {
			base = 75
			ai_value_modifier = {
				ai_compassion = -1
			}
		}
	}
	after = {
		clear_court_event_participation = yes
		scope:steward = { clear_court_event_participation = yes }
	}
}

# High court food: everyone wants to eat at your court
court_events.3050 = {
	type = court_event
	title = court_events.3050.t
	desc = court_events.3050.desc
	theme = court
	cooldown = { years = 20 }
	court_scene = {
		button_position_character = scope:chancellor
		roles = {
			scope:chancellor = {
				group = event_group
				animation = happiness
			}
			root = {
				group = event_group
				animation = thinking
			}
		}
	}

	trigger = {
		exists = cp:councillor_chancellor
		amenity_level = {
 			target = court_food_quality
 			value >= 5
 		}
	}

	weight_multiplier = {
		base = 1
	}

	immediate = {
		court_event_character_flag_effect = yes
		cp:councillor_chancellor = {
			court_event_character_flag_effect = yes
			save_scope_as = chancellor
		}
	}

	# Option A: improve domestic affairs
	option = {
		name = court_events.3050.a
		custom_tooltip = court_events.3050.a.tt
		add_character_flag = {
			flag = food_improves_opinion
			years = 15
		}
		stress_impact = {
			gregarious = minor_stress_impact_gain
			generous = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = 1
			}
		}
	}

	# Option B: improve your feasts
	option = {
		name = court_events.3050.b
		custom_tooltip = court_events.3050.b.tt
		add_character_flag = {
			flag = food_improves_feasts
			years = 15
		}
		stress_impact = {
			shy = minor_stress_impact_gain
			greedy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_sociability = 1
			}
		}
	}

	after = {
		clear_court_event_participation = yes
		scope:chancellor = { clear_court_event_participation = yes }
	}
}

# High court servants: can't keep track of who is who
court_events.3060 = {
	type = court_event
	title = court_events.3060.t
	desc = court_events.3060.desc
	theme = court
	cooldown = { years = 15 }
	court_scene = {
		button_position_character = scope:spymaster
		roles = {
			scope:spymaster = {
				group = event_group
				animation = spymaster
			}
			root = {
				group = event_group
				animation = scheme
			}
		}
	}

	trigger = {
		exists = cp:councillor_spymaster
		amenity_level = {
 			target = court_servants
 			value >= 5
 		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			has_lifestyle = intrigue_lifestyle
			add = 1
		}
		modifier = {
			has_trait = education_intrigue
			add = 1
		}
	}

	immediate = {
		court_event_character_flag_effect = yes
		cp:councillor_spymaster = {
			court_event_character_flag_effect = yes
			save_scope_as = spymaster
		}
	}

	# Option A: So much potential
	option = {
		name = court_events.3060.a
		flavor = court_events.3060.a.tt
		add_character_modifier = {
			modifier = spies_behind_every_corner_modifier
			years = 15
		}
		stress_impact = {
			honest = medium_stress_impact_gain
			paranoid = medium_stress_impact_gain
			trusting = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_vengefulness = 0.5
				ai_boldness = 0.5
			}
		}
	}

	# Option B: Put them to work instead
	option = {
		name = court_events.3060.b
		add_character_modifier = {
			modifier = servants_aplenty_cleaning_modifier
			years = 15
		}
		stress_impact = {
			deceitful = medium_stress_impact_gain
			humble = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = 1
			}
		}
	}

	after = {
		clear_court_event_participation = yes
		scope:spymaster = { clear_court_event_participation = yes }
	}
}

# Low court fashion: A foreign ruler that is traveling through your capital complains about your courtiers and yourself looking like commoners
court_events.3070 = {
	type = court_event
	title = court_events.3070.t
	desc = court_events.3070.desc
	theme = court
	cooldown = { years = 20 }
	court_scene = {
		button_position_character = scope:guest
		roles = {
			scope:guest = {
				group = event_group
				animation = dismissal
			}
			root = {
				group = event_group
				animation = eyeroll
			}
		}
	}

	immediate = {
		court_event_character_flag_effect = yes
		scope:guest = { court_event_character_flag_effect = yes }
	}

	# Option A: Accept advise
	option = {
		name = court_events.3070.a
		trigger = {
			NOT = { government_has_flag = government_is_tribal }
		}
		remove_short_term_gold = minor_gold_value
		set_amenity_level = { type = court_fashion value = 3 }
		custom_tooltip = cheaper_fashion_for_15_years
		add_character_flag = {
			flag = court_cheaper_fashion
			years = 15
		}
		stress_impact = {
			arrogant = major_stress_impact_gain
			greedy = medium_stress_impact_gain
			humble = medium_stress_impact_gain
			eccentric = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = -1
				ai_boldness = 0.5
				ai_vengefulness = 0.5
			}
		}
	}

	# Option B: Embrace humility
	option = {
		name = court_events.3070.b
		add_character_modifier = {
			modifier = humble_appearance_modifier
			years = 15
		}
		stress_impact = {
			arrogant = medium_stress_impact_gain
			eccentric = minor_stress_impact_loss
			humble = minor_stress_impact_loss
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = -1
			}
		}
	}

	#Option C: how dare you??
	option = {
		name = court_events.3070.c
		if = {
			limit = {
				NOT = {
					amenity_level = {
 						target = court_fashion
 						value = 2
 					}
				}
			}
			set_amenity_level = { type = court_fashion value = 2 }
		}
		custom_tooltip = free_fashion_for_15_years
		add_character_flag = {
			flag = court_free_fashion
			years = 15
		}
		stress_impact = {
			humble = major_stress_impact_gain
		}
		ai_chance = {
			base = 75
			ai_value_modifier = {
				ai_boldness = 1
			}
		}
	}
	after = {
		clear_court_event_participation = yes
		scope:guest = { clear_court_event_participation = yes }
	}
}

# Event triggered by the traveler
court_events.3071 = {
	type = character_event
	hidden = yes

	trigger = {
		is_landed = yes
		is_ai = yes
		is_adult = yes
		is_location_valid_for_travel_event_on_land = yes
		OR = {
			has_royal_court = yes
			top_liege ?= { has_royal_court = yes }
		}
		location.county.holder.top_liege.capital_province = root.location
		location.county.holder.top_liege = {
			has_royal_court = yes
			is_adult = yes
			amenity_level = {
 				target = court_fashion
 				value <= 2
 			}
		}
		trigger_if = {
			limit = {
				has_royal_court = yes
			}
			amenity_level = {
 				target = court_fashion
 				value > 2
 			}
		}
		trigger_else_if = {
			limit = {
				top_liege ?= { has_royal_court = yes }
			}
			top_liege = {
				amenity_level = {
 					target = court_fashion
 					value > 2
 				}
			}
		}
		trigger_else = {
			always = no
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			location.county.holder.top_liege = {
				amenity_level = {
 					target = court_fashion
 					value <= 1
 				}
 			}
 			add = 0.5
		}
		modifier = {
			has_royal_court = yes
			add = 0.5
		}
		modifier = {
			top_liege ?= {
				amenity_level = {
 					target = court_fashion
 					value > 3
 				}
			}
			add = 0.5
		}
		modifier = {
			top_liege ?= {
				amenity_level = {
 					target = court_fashion
 					value > 4
 				}
			}
			add = 0.5
		}
	}

	immediate = {
		root = { save_scope_as = guest }
		location.county.holder.top_liege = {
			trigger_event = {
				id = court_events.3070
				days = 1
			}
		}
	}
}

# Diplo court: A famous poet comes to your court offering their services
scripted_trigger 3080_valid_poet_trigger = {
	is_available_ai_adult = yes
	OR = {
		has_trait = lifestyle_poet
		AND = {
			has_trait = tourney_participant
			has_trait_xp = {
				trait = tourney_participant
				track = wit
				value >= 80
			}
		}
		diplomacy >= 18
	}
}

court_events.3080 = {
	type = court_event
	title = court_events.3080.t
	desc = court_events.3080.desc
	theme = court
	cooldown = { years = 30 }
	court_scene = {
		button_position_character = scope:poet
		roles = {
			scope:poet = {
				group = event_group
				animation = obsequious_bow
			}
			root = {
				group = event_group
				animation = thinking
			}
		}
	}

	trigger = {
		has_court_type = court_diplomatic
		NOT = { employs_court_position = court_poet_court_position }
		can_employ_court_position_type = court_poet_court_position
		court_grandeur_current_level > court_grandeur_minimum_expected_level
	}

	weight_multiplier = {
		base = 1
		modifier = {
			court_grandeur_current_level >= 2_levels_above_expected_level
			add = 0.5
		}
		modifier = {
			court_grandeur_current_level >= 3_levels_above_expected_level
			add = 0.5
		}
		modifier = {
			court_grandeur_current_level >= 4_levels_above_expected_level
			add = 0.5
		}
		modifier = {
			court_grandeur_current_level >= 5_levels_above_expected_level
			add = 0.5
		}
		modifier = {
			court_grandeur_current_level >= 6_levels_above_expected_level
			add = 0.5
		}
	}

	immediate = {
		court_event_character_flag_effect = yes
		random_pool_character = {
			province = root.location
			limit = {
				3080_valid_poet_trigger = yes
			}
			save_scope_as = poet
		}
		if = {
			limit = {
				NOT = { exists = scope:poet }
			}
			location.county = {
				random_neighboring_county = {
					culture = {
						save_scope_as = poet_culture
					}
				}
			}
			create_character = {
				location = root.location
				template = ep3_poet_toned_down_template
				culture = scope:poet_culture
				save_scope_as = poet
			}
		}
		hidden_effect = {
			scope:poet = {
				court_event_character_flag_effect = yes
				if = {
					limit = {
						NOT = { has_trait = lifestyle_poet }
					}
					add_trait = lifestyle_poet
				}
				if = {
					limit = {
						NOT = { has_trait = eccentric }
					}
					add_trait = eccentric
				}
			}
			add_courtier = scope:poet
		}
	}

	# Option A: hire for speeches
	option = {
		name = court_events.3080.a
		court_position_grant_effect = {
			POS = court_poet
			CANDIDATE = scope:poet
			EMPLOYER = root
		}
		add_character_modifier = {
			modifier = ghost_writer_at_court_modifier
			years = 20
		}
		stress_impact = {
			humble = medium_stress_impact_gain
			deceitful = medium_stress_impact_gain
			honest = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = 1
			}
		}
	}

	# Option B: hire for diplo schemes
	option = {
		name = court_events.3080.b
		court_position_grant_effect = {
			POS = court_poet
			CANDIDATE = scope:poet
			EMPLOYER = root
		}
		add_character_modifier = {
			modifier = poet_for_diplo_schemes_modifier
			years = 20
		}
		stress_impact = {
			honest = medium_stress_impact_gain
			content = medium_stress_impact_gain
			loyal = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = 1
			}
			modifier = {
				has_trait = deceitful
				add = 50
			}
		}
	}

	# Option C: hire for seduction
	option = {
		name = court_events.3080.c
		court_position_grant_effect = {
			POS = court_poet
			CANDIDATE = scope:poet
			EMPLOYER = root
		}
		add_character_modifier = {
			modifier = poet_for_seduction_schemes_modifier
			years = 20
		}
		stress_impact = {
			chaste = major_stress_impact_gain
			shy = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = 0.5
				ai_honor = -0.5
			}
			modifier = {
				has_trait = lustful
				factor = 2
			}
			modifier = {
				has_trait = rakish
				factor = 3
			}
			modifier = {
				has_trait = chaste
				factor = 0
			}
		}
	}

	# Option D: no thanks
	option = {
		name = court_events.3080.d
		scope:poet = { select_and_move_to_pool_effect = yes }
		stress_impact = {
			lifestyle_poet = massive_stress_impact_gain
			generous = medium_stress_impact_gain
			gregarious = medium_stress_impact_gain
			ambitious = medium_stress_impact_gain
		}
		ai_chance = {
			base = 75
			ai_value_modifier = {
				ai_greed = 1
			}
		}
	}

	after = {
		clear_court_event_participation = yes
		scope:poet = {
			clear_court_event_participation = yes
			if = {
				limit = {
					NOT = { has_court_position = court_poet_court_position }
					root = { is_ai = yes }
				}
				silent_disappearance_effect = yes
			}
		}
	}
}

# Martial court: One of your young children dreams of being a great warrior and wants you to teach them to ride a horse
scripted_trigger 3090_valid_child_trigger = {
	is_available_ai_child = yes
	age >= 6
	age <= 12
	NOR = {
		any_owned_story = {
			type = story_cycle_martial_lifestyle_warhorse
		}
		has_trait = craven
		has_trait = shy
		has_trait = lazy
		has_trait = content
	}
	OR = {
		has_trait = rowdy
		has_trait = bossy
	}
	location = root.location
	is_landed = no
}

court_events.3090 = {
	type = court_event
	title = court_events.3090.t
	desc = court_events.3090.desc
	theme = court
	cooldown = { years = 25 }
	court_scene = {
		button_position_character = scope:child
		roles = {
			scope:child = {
				group = event_group
				animation = beg
			}
			root = {
				group = event_group
				animation = thinking
			}
		}
	}

	trigger = {
		has_court_type = court_warlike
		any_child = {
			3090_valid_child_trigger = yes
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			any_child = {
				3090_valid_child_trigger = yes
				is_heir_of = root
			}
			add = 1
		}
		modifier = {
			any_child = {
				3090_valid_child_trigger = yes
				has_trait = ambitious
			}
			add = 0.5
		}
		modifier = {
			any_child = {
				3090_valid_child_trigger = yes
				has_trait = brave
			}
			add = 0.5
		}
		modifier = {
			any_child = {
				3090_valid_child_trigger = yes
				has_focus = education_martial
			}
			add = 0.5
		}

		modifier = {
			any_owned_story = {
				type = story_cycle_martial_lifestyle_warhorse
			}
			add = 1
		}
		modifier = {
			has_trait_xp = {
				trait = tourney_participant
				track = horse
				value >= 50
			}
			add = 1
		}
		modifier = {
			has_trait_xp = {
				trait = tourney_participant
				track = horse
				value > 0
			}
			has_trait_xp = {
				trait = tourney_participant
				track = horse
				value < 50
			}
			add = 0.5
		}
		modifier = {
			has_trait = family_first
			add = 1
		}
		modifier = {
			has_trait = callous
			factor = 0
		}
		modifier = {
			has_trait = sadistic
			factor = 0
		}
	}

	immediate = {
		random_child = {
			limit = {
				3090_valid_child_trigger = yes
			}
			weight = {
				base = 1
				modifier = {
					is_heir_of = root
					add = 50
				}
				modifier = {
					has_trait = ambitious
					add = 15
				}
				modifier = {
					has_trait = brave
					add = 15
				}
				modifier = {
					has_focus = education_martial
					add = 15
				}
			}
			save_scope_as = child
			court_event_character_flag_effect = yes
		}
		court_event_character_flag_effect = yes
	}

	# Option A: teach
	option = {
		name = court_events.3090.a
		scope:child = {
			if = {
				limit = {
					has_focus = education_martial
				}
				education_point_acquisition_additional_points_effect = { LEVEL = low }
			}
			add_prowess_skill = 1
			add_character_modifier = {
				modifier = court_confident_rider_modifier
				years = 50
			}
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 25
			}
		}
		stress_impact = {
			lazy = medium_stress_impact_gain
			callous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_energy = 1
				ai_sociability = 0.5
			}
			modifier = {
				has_trait_xp = {
					trait = tourney_participant
					track = horse
					value >= 50
				}
				add = 100
			}
		}
	}

	# Option B: when you grow up
	option = {
		name = court_events.3090.b
		flavor = court_events.3090.b.tt
		custom_tooltip = court_events.3090.b.tt_effect
		scope:child = {
			add_stewardship_skill = 1
			set_variable = {
				name = promised_me_a_pony
				value = root
			}
			if = {
				limit = {
					NOT = {
						has_focus = education_martial
					}
				}
				education_point_acquisition_additional_points_effect = { LEVEL = low }
			}
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 10
			}
		}
		stress_impact = {
			impatient = medium_stress_impact_gain
			greedy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = 1
			}
			modifier = {
				has_trait = impatient
				add = -50
			}
		}
	}

	# Option C: no
	option = {
		name = court_events.3090.c
		scope:child = {
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -20
			}
		}
		stress_impact = {
			brave = minor_stress_impact_gain
		}
		ai_chance = {
			base = 75
			ai_value_modifier = {
				ai_energy = -1
			}
			modifier = {
				has_trait = brave
				add = -25
			}
		}
	}
	after = {
		clear_court_event_participation = yes
		scope:child = { clear_court_event_participation = yes }
	}
}

court_events.3091 = {
	type = character_event
	title = court_events.3090.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:parent = { is_alive = no }
				}
				desc = court_events.3091.desc_no_parent
			}
			desc = court_events.3091.desc
		}
	}
	theme = family
	override_background = { reference = garden }

	left_portrait = {
		character = root
		triggered_animation = {
			trigger = {
				scope:parent = { is_alive = yes }
			}
			animation = jockey_victory
		}
		animation = jockey_walk
		camera = camera_event_horse_right
	}
	right_portrait = {
		character = scope:parent
		triggered_animation = {
			trigger = {
				scope:parent = { is_alive = yes }
			}
			animation = admiration
		}
		animation = dead
	}

	trigger = {
		has_variable = promised_me_a_pony
	}

	immediate = {
		var:promised_me_a_pony = { save_scope_as = parent }
		root = { save_scope_as = child }
		scope:parent = {
			if = {
				limit = {
					is_alive = yes
				}
				trigger_event = court_events.3092
			}
		}
		create_story = story_cycle_martial_lifestyle_warhorse
	}

	option = {
		name = court_events.3091.a
	}
}

court_events.3092 = {
	type = character_event
	title = court_events.3090.t
	desc = court_events.3092.desc
	theme = family
	override_background = { reference = garden }

	left_portrait = {
		character = root
		animation = admiration
	}
	right_portrait = {
		character = scope:child
		animation = jockey_victory
		camera = camera_event_horse_right
	}

	immediate = {
		show_as_tooltip = {
			scope:child = {
				create_story = story_cycle_martial_lifestyle_warhorse
			}
		}
	}

	option = {
		name = court_events.3092.a
		scope:child = {
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 15
			}
		}
	}
}

# Boost to learning your court language if you don't know it
court_events.3100 = {
	type = court_event
	title = court_events.3100.t
	desc = court_events.3100.desc
	theme = court
	cooldown = { years = 25 }
	court_scene = {
		button_position_character = scope:chancellor
		roles = {
			scope:chancellor = {
				group = event_group
				animation = chancellor
			}
			root = {
				group = event_group
				animation = personality_cynical
			}
		}
	}

	trigger = {
		NOT = { knows_court_language_of = root }
		has_royal_court = yes
		OR = {
			any_courtier = {
				knows_court_language_of = root
				root = {
					has_court_language_of_culture = prev.culture
				}
				is_available_ai_adult = yes
			}
			cp:councillor_chancellor ?= {
				knows_court_language_of = root
				root = {
					has_court_language_of_culture = prev.culture
				}
				is_available_ai_adult = yes
			}
		}
		is_available_healthy_adult = yes
		NOT = {
			any_scheme = { type = learn_language }
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			any_courtier = {
				has_character_flag = court_linguist_flag
				root = {
					has_court_language_of_culture = prev.culture
				}
			}
			add = 1
		}
		modifier = {
			add = {
				value = {
					every_close_family_member = {
						limit = {
							NOT = { knows_court_language_of = root }
						}
						add = 1
					}
				}
			}
		}
	}

	immediate = {
		random_courtier = {
			limit = {
				has_character_flag = court_linguist_flag
				knows_court_language_of = root
				root = {
					has_court_language_of_culture = prev.culture
				}
				is_available_ai_adult = yes
			}
			save_scope_as = chancellor
		}
		if = {
			limit = {
				NOT = { exists = scope:chancellor }
				cp:councillor_chancellor ?= {
					knows_court_language_of = root
					root = {
						has_court_language_of_culture = prev.culture
					}
					is_available_ai_adult = yes
				}
			}
			cp:councillor_chancellor = { save_scope_as = chancellor }
		}
		else = {
			random_courtier = {
				limit = {
					knows_court_language_of = root
					root = {
						has_court_language_of_culture = prev.culture
					}
					is_available_ai_adult = yes
				}
				weight = {
					base = 1
					modifier = {
						has_court_position = court_tutor_court_position
						add = 20
					}
					modifier = {
						is_close_family_of = root
						add = 10
					}
					modifier = {
						has_trait = scholar
						add = 10
					}
					modifier = {
						has_trait = loyal
						add = 5
					}
					modifier = {
						has_trait = diligent
						add = 5
					}
					modifier = {
						has_trait = gregarious
						add = 5
					}
				}
				save_scope_as = chancellor
			}
		}
		scope:chancellor = { court_event_character_flag_effect = yes }
		if = {
			limit = {
				employs_court_position = court_tutor_court_position
				court_position:court_tutor_court_position = {
					knows_court_language_of = root
					root = {
						has_court_language_of_culture = prev.culture
					}
				}
			}
			court_position:court_tutor_court_position = { save_scope_as = linguist }
		}
		else_if = {
			limit = {
				any_courtier = {
					knows_court_language_of = root
					root = {
						has_court_language_of_culture = prev.culture
					}
				}
			}
			random_courtier = {
				limit = {
					knows_court_language_of = root
					root = {
						has_court_language_of_culture = prev.culture
					}
				}
				save_scope_as = linguist
			}
		}
		court_event_character_flag_effect = yes
	}

	# Option A: start studying
	option = {
		name = court_events.3100.a
		custom_tooltip = {
			text = court_events.3100.a.tt
			start_scheme = {
				type = learn_language
				target_character = scope:chancellor
			}
			random_scheme = {
				type = learn_language
				add_scheme_modifier = { type = pressured_to_learn_court_language_modifier }
			}
		}
		start_scheme = {
			type = learn_language
			target_character = scope:chancellor
		}
		random_scheme = {
			type = learn_language
			add_scheme_modifier = { type = pressured_to_learn_court_language_modifier }
		}
		stress_impact = {
			arrogant = medium_stress_impact_gain
			lazy = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = humble
				add = 25
			}
			modifier = {
				has_trait = diligent
				add = 25
			}
		}
	}

	# Option B: has linguist/tutor - teach the whole family/faster
	option = {
		name = court_events.3100.b
		trigger = {
			exists = scope:linguist
		}
		start_scheme = {
			type = learn_language
			target_character = scope:linguist
		}
		random_scheme = {
			type = learn_language
			add_scheme_modifier = { type = linguist_help_for_court_language_modifier }
		}
		every_close_family_member = {
			limit = {
				NOT = { knows_court_language_of = root }
				location = root.location
				is_adult = yes
				is_ai = yes
			}
			start_scheme = {
				type = learn_language
				target_character = scope:linguist
			}
			random_scheme = {
				type = learn_language
				add_scheme_modifier = { type = linguist_help_for_court_language_modifier }
			}
		}
		every_close_family_member = {
			limit = {
				NOT = { knows_court_language_of = root }
				location = root.location
				is_adult = no
				is_ai = yes
			}
			learn_court_language_of = root
		}
		stress_impact = {
			arrogant = minor_stress_impact_gain
			lazy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 250
		}
	}

	# Option C: it's not the time for this
	option = {
		name = court_events.3100.c
		add_prestige = medium_prestige_gain
		stress_impact = {
			humble = minor_stress_impact_gain
			diligent = minor_stress_impact_gain
		}
		ai_chance = {
			base = 75
			modifier = {
				has_trait = arrogant
				add = 50
			}
			modifier = {
				has_trait = humble
				add = -25
			}
			modifier = {
				has_trait = diligent
				add = -25
			}
		}
	}

	after = {
		clear_court_event_participation = yes
		scope:chancellor = { clear_court_event_participation = yes }
	}
}

# Stewardship court: a vassal's construction program is challenging you
scripted_trigger court_3110_valid_vassal_trigger = {
	is_landed = yes
	is_available_ai_adult = yes
	capital_county.title_province = {
		OR = {
			combined_building_level > root.capital_county.title_province.combined_building_level
			num_buildings > root.capital_county.title_province.num_buildings
		}
		has_ongoing_construction = yes
	}
	OR = {
		has_trait = arrogant
		has_trait = architect
		has_trait = honest
		has_trait = gregarious
		has_trait = disloyal
		has_focus = stewardship_domain_focus
	}
	highest_held_title_tier >= tier_county
}

court_events.3110 = {
	type = court_event
	title = court_events.3110.t
	desc = court_events.3110.desc
	theme = court
	cooldown = { years = 25 }
	court_scene = {
		button_position_character = scope:steward
		roles = {
			scope:steward = {
				group = event_group
				animation = worry
			}
			root = {
				group = event_group
				animation = disapproval
			}
		}
	}

	trigger = {
		has_royal_court = yes
		has_court_type = court_administrative
		OR = {
			has_focus = stewardship_wealth_focus
			has_focus = stewardship_domain_focus
			has_focus = stewardship_duty_focus
		}
		any_vassal = {
			court_3110_valid_vassal_trigger = yes
		}
		exists = cp:councillor_steward
		NOT = { has_character_flag = had_court_events_3115 }
	}

	weight_multiplier = {
		base = 1
		modifier = {
			has_focus = stewardship_domain_focus
			add = 0.5
		}
		modifier = {
			capital_county.title_province = {
				has_ongoing_construction = yes
			}
			add = 1
		}
		modifier = {
			employs_court_position = royal_architect_court_position
			add = 1
		}
	}

	immediate = {
		add_character_flag = {
			flag = had_court_events_3110
			years = 25
		}
		court_event_character_flag_effect = yes
		random_vassal = {
			limit = {
				court_3110_valid_vassal_trigger = yes
			}
			save_scope_as = vassal
		}
		if = {
			limit = {
				employs_court_position = royal_architect_court_position
			}
			court_position:royal_architect_court_position = {
				save_scope_as = steward
				save_scope_as = architect
			}
		}
		else = {
			cp:councillor_steward = {
				save_scope_as = steward
			}
		}
		scope:steward = { court_event_character_flag_effect = yes }
	}

	# Option A: Build MORE!
	option = {
		name = court_events.3110.a
		if = {
			limit = {
				exists = scope:architect
			}
			custom_tooltip = court_events.3110.architect
			capital_county = {
				add_county_modifier = {
					modifier = architect_building_program_county_modifier
					years = 20
				}
			}
		}
		else = {
			duel = {
				skill = stewardship
				value = average_skill_rating
				50 = {
					desc = court_events.3110.a.success
					compare_modifier = {
						value = scope:duel_value
						multiplier = 3.5
					}
					modifier = {
						has_trait = architect
						add = 50
					}
					modifier = {
						has_trait = diligent
						add = 10
					}
					modifier = {
						has_trait = ambitious
						add = 10
					}
					send_interface_toast = {
						type = event_toast_effect_good
						title = court_events.3110.a.success.tt
						left_icon = root
						capital_county = {
							add_county_modifier = {
								modifier = building_program_county_modifier
								years = 20
							}
						}
					}
				}
				50 = {
					desc = court_events.3110.a.failure
					compare_modifier = {
						value = scope:duel_value
						multiplier = -3.5
					}
					modifier = {
						has_trait = greedy
						add = 20
					}
					modifier = {
						has_trait = lazy
						add = 10
					}
					modifier = {
						has_trait = humble
						add = 10
					}
					send_interface_toast = {
						type = event_toast_effect_bad
						title = court_events.3110.a.failure.tt
						left_icon = root
						add_prestige = medium_prestige_loss
						add_stewardship_lifestyle_xp = medium_lifestyle_xp
					}
				}
			}
		}
		stress_impact = {
			greedy = major_stress_impact_gain
			humble = medium_stress_impact_gain
			lazy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = -1
				ai_boldness = 0.5
			}
			modifier = {
				has_trait = humble
				add = -50
			}
			modifier = {
				has_trait = lazy
				add = -25
			}
			modifier = {
				has_trait = architect
				add = 100
			}
		}
	}

	# Option B: Tax MORE!
	option = {
		name = court_events.3110.b
		flavor = court_events.3110.b.tt
		duel = {
			skill = diplomacy
			target = scope:vassal
			50 = {
				desc = court_events.3110.b.success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
				}
				send_interface_toast = {
					type = event_toast_effect_good
					title = court_events.3110.b.success.tt
					left_icon = scope:vassal
					scope:vassal = {
						pay_short_term_gold = {
							target = root
							gold = medium_gold_value
						}
					}
					if = {
						limit = {
							government_allows = administrative
						}
						scope:vassal = {
							change_influence = medium_influence_loss
						}
						change_influence = medium_influence_gain
					}
					else = {
						scope:vassal = {
							add_prestige = medium_prestige_loss
						}
						add_prestige = medium_prestige_gain
					}
				}
			}
			50 = {
				desc = court_events.3110.b.failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
				}

				send_interface_toast = {
					type = event_toast_effect_bad
					title = court_events.3110.b.failure.tt
					left_icon = scope:vassal
					if = {
						limit = {
							government_allows = administrative
						}
						scope:vassal = {
							change_influence = medium_influence_gain
						}
						change_influence = medium_influence_loss
					}
					else = {
						scope:vassal = {
							add_prestige = medium_prestige_gain
						}
						add_prestige = medium_prestige_loss
					}
				}
			}
		}
		stress_impact = {
			generous = medium_stress_impact_gain
			architect = medium_stress_impact_gain
			compassionate = minor_stress_impact_gain
			zealous = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = 1
				ai_compassion = -0.5
			}
			modifier = {
				has_trait = zealous
				add = -25
			}
		}
	}

	# Option C: I don't care
	option = {
		name = court_events.3110.c
		add_prestige = miniscule_prestige_loss
		stress_impact = {
			ambitious = major_stress_impact_gain
			arrogant = medium_stress_impact_gain
			architect = medium_stress_impact_gain
		}
		ai_chance = {
			base = 75
			ai_value_modifier = {
				ai_energy = -0.5
				ai_boldness = -0.5
			}
			modifier = {
				has_trait = ambitious
				add = -75
			}
			modifier = {
				has_trait = arrogant
				add = -50
			}
		}
	}

	after = {
		clear_court_event_participation = yes
		scope:steward = { clear_court_event_participation = yes }
	}
}

# Admin court version: a vassal's construction program intheir estate is challenging you
scripted_trigger court_3115_valid_vassal_trigger = {
	government_allows = administrative
	this = house.house_head
	domicile ?= {
		is_domicile_type = estate
		num_domicile_buildings > root.domicile.num_domicile_buildings
		external_domicile_building_slots >= root.domicile.external_domicile_building_slots
		free_external_domicile_building_slots < root.domicile.free_external_domicile_building_slots
	}
	is_available_ai_adult = yes
	OR = {
		has_trait = arrogant
		has_trait = architect
		has_trait = honest
		has_trait = gregarious
		has_trait = disloyal
		has_focus = stewardship_domain_focus
		has_trait_xp = {
			trait = governor
			value >= 60
		}
	}
}

court_events.3115 = {
	type = court_event
	title = court_events.3110.t
	desc = court_events.3115.desc
	theme = court
	cooldown = { years = 25 }
	court_scene = {
		button_position_character = scope:relative
		roles = {
			scope:relative = {
				group = event_group
				animation = worry
			}
			root = {
				group = event_group
				animation = disapproval
			}
		}
	}

	trigger = {
		has_royal_court = yes
		government_allows = administrative
		this = house.house_head
		domicile ?= { is_domicile_type = estate }
		OR = {
			has_focus = stewardship_wealth_focus
			has_focus = stewardship_domain_focus
			has_focus = stewardship_duty_focus
		}
		any_vassal = {
			court_3110_valid_vassal_trigger = yes
		}
		any_courtier_or_guest = {
			house = root.house
			location = root.location
			is_available_ai_adult = yes
		}
		NOT = { has_character_flag = had_court_events_3110 }
	}

	weight_multiplier = {
		base = 1
		modifier = {
			has_focus = stewardship_domain_focus
			add = 0.5
		}
		modifier = {
			any_vassal = {
				court_3110_valid_vassal_trigger = yes
				house = { is_dominant_family = yes }
			}
			add = 1
		}
		modifier = {
			any_vassal = {
				court_3110_valid_vassal_trigger = yes
				house = { is_powerful_family = yes }
			}
			add = 0.5
		}
		modifier = {
			house = {
				is_powerful_family = no
			}
			add = 0.5
		}
	}

	immediate = {
		add_character_flag = {
			flag = had_court_events_3115
			years = 25
		}
		court_event_character_flag_effect = yes
		random_vassal = {
			limit = {
				court_3110_valid_vassal_trigger = yes
			}
			save_scope_as = vassal
		}

		random_courtier_or_guest = {
			limit = {
				house = root.house
				location = root.location
				is_available_ai_adult = yes
			}
			save_scope_as = relative
		}
		scope:relative = { court_event_character_flag_effect = yes }
	}

	# Option A: Build MORE!
	option = {
		name = court_events.3110.a
		duel = {
			skill = stewardship
			value = average_skill_rating
			50 = {
				desc = court_events.3110.a.success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
				}
				modifier = {
					has_trait = architect
					add = 50
				}
				modifier = {
					has_trait = diligent
					add = 10
				}
				modifier = {
					has_trait = ambitious
					add = 10
				}
				send_interface_toast = {
					type = event_toast_effect_good
					title = court_events.3110.a.success.tt
					left_icon = root
					add_character_modifier = {
						modifier = estate_building_program_modifier
						years = 20
					}
				}
			}
			50 = {
				desc = court_events.3110.a.failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
				}
				modifier = {
					has_trait = greedy
					add = 20
				}
				modifier = {
					has_trait = lazy
					add = 10
				}
				modifier = {
					has_trait = humble
					add = 10
				}
				send_interface_toast = {
					type = event_toast_effect_bad
					title = court_events.3110.a.failure.tt
					left_icon = root
					change_influence = medium_influence_loss
				}
			}
		}
		stress_impact = {
			greedy = major_stress_impact_gain
			humble = medium_stress_impact_gain
			lazy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = -1
				ai_boldness = 0.5
			}
			modifier = {
				has_trait = humble
				add = -50
			}
			modifier = {
				has_trait = lazy
				add = -25
			}
			modifier = {
				has_trait = architect
				add = 100
			}
		}
	}

	# Option B: Tax MORE!
	option = {
		name = court_events.3110.b
		flavor = court_events.3110.b.tt
		duel = {
			skill = diplomacy
			target = scope:vassal
			50 = {
				desc = court_events.3110.b.success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
				}
				send_interface_toast = {
					type = event_toast_effect_good
					title = court_events.3110.b.success.tt
					left_icon = scope:vassal
					scope:vassal = {
						pay_short_term_gold = {
							target = root
							gold = medium_gold_value
						}
					}
					scope:vassal = {
						change_influence = major_influence_loss
					}
					change_influence = major_influence_gain
				}
			}
			50 = {
				desc = court_events.3110.b.failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
				}

				send_interface_toast = {
					type = event_toast_effect_bad
					title = court_events.3110.b.failure.tt
					left_icon = scope:vassal
					scope:vassal = {
						change_influence = medium_influence_gain
					}
					change_influence = medium_influence_loss
				}
			}
		}
		stress_impact = {
			generous = medium_stress_impact_gain
			architect = medium_stress_impact_gain
			compassionate = minor_stress_impact_gain
			zealous = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = 1
				ai_compassion = -0.5
			}
		}
	}

	# Option C: I don't care
	option = {
		name = court_events.3110.c
		change_influence = miniscule_influence_loss
		stress_impact = {
			ambitious = major_stress_impact_gain
			arrogant = medium_stress_impact_gain
			architect = medium_stress_impact_gain
		}
		ai_chance = {
			base = 75
			ai_value_modifier = {
				ai_energy = -0.5
				ai_boldness = -0.5
			}
			modifier = {
				has_trait = ambitious
				add = -75
			}
			modifier = {
				has_trait = arrogant
				add = -50
			}
		}
	}

	after = {
		clear_court_event_participation = yes
		scope:steward = { clear_court_event_participation = yes }
	}
}

# An inspired person is cringing at your crappy common artifact
scripted_trigger 3120_valid_artifact_to_improve_trigger = {
	NOR = {
		has_variable = banner_house
		has_variable = banner_dynasty
		rarity = illustrious
		rarity = famed
	}
}

scripted_trigger 3120_smithsy_artifact_trigger = {
	OR = {
		artifact_type = necklace_pedestal
		artifact_type = brooch
		artifact_type = brooch_pedestal
		artifact_type = necklace
		artifact_type = helmet
		artifact_slot_type = primary_armament
		artifact_slot_type = armor
		artifact_type = regalia
		artifact_type = goblet
		artifact_type = wall_shield
	}
}

scripted_trigger 3120_artisan_artifact_trigger = {
	OR = {
		artifact_type = sculpture
		artifact_type = box
		artifact_type = chest
		artifact_type = cabinet
		artifact_type = throne
	}
}

court_events.3120 = {
	type = court_event
	title = court_events.3120.t
	desc = court_events.3120.desc
	theme = court
	cooldown = { years = 25 }
	court_scene = {
		button_position_character = scope:inspired
		roles = {
			scope:inspired = {
				group = event_group
				animation = disgust
			}
			root = {
				group = event_group
				animation = worry
			}
		}
	}

	trigger = {
		has_royal_court = yes
		any_courtier_or_guest = {
			is_available = yes
			OR = {
				AND = {
					inspiration ?= {
						NOR = {
							has_inspiration_type = adventure_inspiration
							has_inspiration_type = alchemy_inspiration
							has_inspiration_type = book_inspiration
						}
					}
				}
				AND = {
					has_completed_inspiration = yes
					var:created_artifact_type ?= {
						NOR = {
							this = flag:adventure
							this = flag:alchemy
							this = flag:book
						}
					}
				}
			}
			trigger_if = {
				limit = {
					OR = {
						inspiration ?= {
							OR = {
								has_inspiration_type = weapon_inspiration
								has_inspiration_type = armor_inspiration
								has_inspiration_type = smith_inspiration
							}
						}
						var:created_artifact_type ?= {
							OR = {
								this = flag:weapon
								this = flag:armor
								this = flag:smith
							}
						}
					}
				}
				root = {
					any_character_artifact = {
						3120_valid_artifact_to_improve_trigger = yes
						3120_smithsy_artifact_trigger = yes
					}
				}
			}
			trigger_else_if = {
				limit = {
					OR = {
						inspiration ?= { has_inspiration_type = weaver_inspiration }
						var:created_artifact_type ?= { this = flag:weaver }
					}
				}
				root = {
					any_character_artifact = {
						3120_valid_artifact_to_improve_trigger = yes
						artifact_type = tapestry
					}
				}
			}
			trigger_else_if = {
				limit = {
					OR = {
						inspiration ?= { has_inspiration_type = artisan_inspiration }
						var:created_artifact_type ?= { this = flag:artisan }
					}
				}
				root = {
					any_character_artifact = {
						3120_valid_artifact_to_improve_trigger = yes
						3120_artisan_artifact_trigger = yes
					}
				}
			}
			trigger_else = {
				always = no
			}
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			any_courtier_or_guest = {
				has_court_position = court_artificer_court_position
			}
			add = 1
		}
	}

	immediate = {
		court_event_character_flag_effect = yes
		random_courtier = {
			limit = {
				is_available = yes
				OR = {
					AND = {
						exists = inspiration
						inspiration ?= {
							NOR = {
								has_inspiration_type = adventure_inspiration
								has_inspiration_type = alchemy_inspiration
								has_inspiration_type = book_inspiration
							}
						}
					}
					AND = {
						has_completed_inspiration = yes
						var:created_artifact_type ?= {
							NOR = {
								this = flag:adventure
								this = flag:alchemy
								this = flag:book
							}
						}
					}
				}
			}
			weight = {
				base = 1
				modifier = {
					has_court_position = court_artificer_court_position
					add = 100
				}
			}
			save_scope_as = inspired
		}
		if = {
			limit = {
				scope:inspired = {
					OR = {
						inspiration ?= {
							OR = {
								has_inspiration_type = weapon_inspiration
								has_inspiration_type = armor_inspiration
								has_inspiration_type = smith_inspiration
							}
						}
						var:created_artifact_type ?= {
							OR = {
								this = flag:weapon
								this = flag:armor
								this = flag:smith
							}
						}
					}
				}
			}
			random_character_artifact = {
				limit = {
					3120_valid_artifact_to_improve_trigger = yes
					3120_smithsy_artifact_trigger = yes
				}
				weight = {
					base = 1
					modifier = {
						rarity = common
						add = 20
					}
				}
				save_scope_as = artifact
			}
		}
		else_if = {
			limit = {
				scope:inspired = {
					OR = {
						inspiration ?= { has_inspiration_type = weaver_inspiration }
						var:created_artifact_type ?= { this = flag:weaver }
					}
				}
			}
			random_character_artifact = {
				limit = {
					3120_valid_artifact_to_improve_trigger = yes
					artifact_type = tapestry
				}
				weight = {
					base = 1
					modifier = {
						rarity = common
						add = 20
					}
				}
				save_scope_as = artifact
			}
		}
		else = {
			random_character_artifact = {
				limit = {
					3120_valid_artifact_to_improve_trigger = yes
					3120_artisan_artifact_trigger = yes
				}
				weight = {
					base = 1
					modifier = {
						rarity = common
						add = 20
					}
				}
				save_scope_as = artifact
			}
		}
		scope:inspired = { court_event_character_flag_effect = yes }
	}

	# Option A: do it
	option = {
		name = court_events.3120.a
		pay_short_term_gold = {
			target = scope:inspired
			gold = minor_gold_value
		}
		scope:artifact = {
			custom_tooltip = court_events.3120.a.tt
			hidden_effect = {
				random_list = {
					pick = 2
					unique = yes
					10 = {
						root = {
							send_interface_toast = {
								type = event_toast_effect_good
								title = artifact_improved_tt
								left_icon = scope:artifact
								hidden_effect = {
									scope:artifact = { add_artifact_modifier = artifact_monthly_minor_prestige_6_modifier }
								}
							}
						}
					}
					10 = {
						root = {
							send_interface_toast = {
								type = event_toast_effect_good
								title = artifact_improved_tt
								left_icon = scope:artifact
								hidden_effect = {
									scope:artifact = { add_artifact_modifier = artifact_monthly_prestige_6_modifier }
								}
							}
						}
					}
					10 = {
						root = {
							send_interface_toast = {
								type = event_toast_effect_good
								title = artifact_improved_tt
								left_icon = scope:artifact
								hidden_effect = {
									scope:artifact = { add_artifact_modifier = artifact_short_reign_duration_mult_4_modifier }
								}
							}
						}
					}
					10 = {
						root = {
							send_interface_toast = {
								type = event_toast_effect_good
								title = artifact_improved_tt
								left_icon = scope:artifact
								hidden_effect = {
									scope:artifact = { add_artifact_modifier = artifact_court_grandeur_baseline_add_4_modifier }
								}
							}
						}
					}
					10 = {
						root = {
							send_interface_toast = {
								type = event_toast_effect_good
								title = artifact_improved_tt
								left_icon = scope:artifact
								hidden_effect = {
									scope:artifact = { add_artifact_modifier = artifact_dynasty_opinion_5_modifier }
								}
							}
						}
					}
					10 = {
						root = {
							send_interface_toast = {
								type = event_toast_effect_good
								title = artifact_improved_tt
								left_icon = scope:artifact
								hidden_effect = {
									scope:artifact = { add_artifact_modifier = artifact_monthly_prestige_add_5_modifier }
								}
							}
						}
					}
					10 = {
						root = {
							send_interface_toast = {
								type = event_toast_effect_good
								title = artifact_improved_tt
								left_icon = scope:artifact
								hidden_effect = {
									scope:artifact = { add_artifact_modifier = artifact_vassal_limit_1_modifier }
								}
							}
						}
					}
					10 = {
						root = {
							send_interface_toast = {
								type = event_toast_effect_good
								title = artifact_improved_tt
								left_icon = scope:artifact
								hidden_effect = {
									scope:artifact = { add_artifact_modifier = artifact_courtier_and_guest_opinion_5_modifier }
								}
							}
						}
					}
					10 = {
						root = {
							send_interface_toast = {
								type = event_toast_effect_good
								title = artifact_improved_tt
								left_icon = scope:artifact
								hidden_effect = {
									scope:artifact = { add_artifact_modifier = artifact_domain_tax_mult_2_modifier }
								}
							}
						}
					}
					20 = {
						trigger = {
							artifact_durability < define:NInventory|ARTIFACT_LOW_DURABILITY
						}
						root = {
							send_interface_toast = {
								type = event_toast_effect_good
								title = artifact_improved_tt
								left_icon = scope:artifact
								scope:artifact = {
									add_durability = {
										value = {
											value = scope:artifact.artifact_max_durability
											subtract = scope:artifact.artifact_durability
										}
									}
								}
							}
						}
					}
					20 = {
						root = {
							send_interface_toast = {
								type = event_toast_effect_good
								title = artifact_improved_tt
								left_icon = scope:artifact
								scope:artifact = {
									set_max_durability = {
										value = {
											value = scope:artifact.artifact_max_durability
											add = {
												value = scope:artifact.artifact_max_durability
												divide = 100
												multiply = 20
											}
										}
									}
								}
							}
						}
					}
					10 = {
						root = {
							send_interface_toast = {
								type = event_toast_effect_good
								title = artifact_improved_tt
								left_icon = scope:artifact
								scope:artifact = {
									set_max_durability = {
										value = {
											value = scope:artifact.artifact_max_durability
											add = {
												value = scope:artifact.artifact_max_durability
												divide = 100
												multiply = 35
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
		stress_impact = {
			greedy = medium_stress_impact_gain
			humble = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = -0.5
			}
			modifier = {
				has_trait = humble
				add = -25
			}
			modifier = {
				gold <= minor_gold_value
				factor = 0
			}
		}
	}

	# Option B: think about your own stuff
	option = {
		name = court_events.3120.b
		trigger = { exists = scope:inspired.inspiration }
		scope:inspired = {
			if = {
				limit = {
					NOT = { inspiration.inspiration_sponsor = root }
				}
				root = { sponsor_inspiration = scope:inspired.inspiration }
			}
			change_artifact_quality_effect = { AMOUNT = 5 }
			inspiration = { change_inspiration_progress = 2 }
		}
		stress_impact = {
			compassionate = minor_stress_impact_gain
			ambitious = medium_stress_impact_gain
			gregarious = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_sociability = -0.5
				ai_compassion = -0.5
			}
		}
	}

	# Option C: show me you can still do better
	option = {
		name = court_events.3120.c
		trigger = {
			scope:inspired = {
				has_completed_inspiration = yes
				NOT = { exists = inspiration }
			}
		}
		scope:inspired = {
			if = {
				limit = {
					var:created_artifact_type ?= {
						OR = {
							this = flag:weapon
							this = flag:armor
							this = flag:smith
						}
					}
				}
				random_list = {
					30 = {
						create_inspiration = { type = weapon_inspiration }
						custom_tooltip = gains_weapon_inspiration_tt
					}
					30 = {
						create_inspiration = { type = armor_inspiration }
						custom_tooltip = gains_armor_inspiration_tt
					}
					30 = {
						create_inspiration = { type = smith_inspiration }
						custom_tooltip = gains_smith_inspiration_tt
					}
				}
			}
			else_if = {
				limit = {
					var:created_artifact_type ?= {
						this = flag:weaver
					}
				}
				create_inspiration = { type = weaver_inspiration }
				custom_tooltip = gains_weaver_inspiration_tt
			}
			else = {
				create_inspiration = { type = artisan_inspiration }
				custom_tooltip = gains_artisan_inspiration_tt
			}
		}
		stress_impact = {
			shy = minor_stress_impact_gain
			callous = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = 0.5
				ai_sociability = 0.5
			}
			modifier = {
				has_trait = shy
				add = -25
			}
			modifier = {
				has_trait = callous
				add = -25
			}
		}
	}

	# Option D: nevermind
	option = {
		name = court_events.3120.d
		add_prestige = miniscule_prestige_loss
		stress_impact = {
			ambitious = medium_stress_impact_gain
			arrogant = medium_stress_impact_gain
			generous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 75
			ai_value_modifier = {
				ai_energy = -1
			}
			modifier = {
				has_trait = ambitious
				add = -50
			}
			modifier = {
				has_trait = arrogant
				add = -50
			}
			modifier = {
				has_trait = generous
				add = -50
			}
		}
	}
	after = {
		clear_court_event_participation = yes
		scope:inspired = { clear_court_event_participation = yes }
	}
}
