###################################################
##	MPO Decision Events
##
##	0001 	Offer Confederation
##  0200    Study Commander Trait
##  0300    Fertility Dance
##	0400	Pax Mongolica
##	0500	Desperate Stance
##	0060	Invite Shepherds
## 	0120	Adopt the Nomadic Ways

namespace = mpo_decisions_events

scripted_trigger mpo_decisions_events_0001_threat_trigger = {
	save_temporary_scope_as = confederate
	trigger_if = {
		limit = {
			max_military_strength > 0
		}
		confederation_worthy_foe_strength_ratio_value_root <= 0.5
	}
	NOT = { is_allied_to = root }
	OR = {
		highest_held_title_tier >= tier_kingdom
		faith = {
			faith_hostility_level = {
				target = root.faith
				value >= faith_evil_level
			}
		}
		has_trait = conqueror
		has_trait = greatest_of_khans
		is_gurkhan = yes
	}
}

#Confederation planning event
mpo_decisions_events.0001 = {
	type = character_event
	title = mpo_decisions_events.0001.t
	desc = mpo_decisions_events.0001.desc
	theme = vassal
	override_background = { reference = wilderness }
	left_portrait = {
		character = root
		animation = inspect_weapon
	}
	right_portrait = {
		character = scope:warrior
		animation = throne_room_two_handed_passive_shield
		camera = camera_event_right_pointing_left
	}
	lower_right_portrait = scope:threat

	immediate = {
		random_knight = {
			limit = {
				is_imprisoned = no
				is_incapable = no
				is_playable_character = no
			}
			save_scope_as = warrior
			add_character_flag = need_military_outfit
		}
		if = {
			limit = {
				NOT = {
					exists = scope:warrior
				}
			}
			random_courtier = {
				limit = {
					is_available_allow_travelling = yes
					is_adult = yes
					can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root }
					age <= 55
				}
				save_scope_as = warrior
				add_character_flag = need_military_outfit
			}
		}
		if = {
			limit = {
				any_land_neighboring_realm_with_tributaries_owner = {
					mpo_decisions_events_0001_threat_trigger = yes
				}
			}
			ordered_land_neighboring_realm_with_tributaries_owner = {
				order_by = current_military_strength
				limit = {
					mpo_decisions_events_0001_threat_trigger = yes
				}
				save_scope_as = threat
			}
		}
		else_if = {
			limit = {
				NOT = {
					exists = scope:threat
				}
			}
			ordered_land_neighboring_realm_with_tributaries_owner = {
				order_by = current_military_strength
				limit = {
					is_tributary = yes
					suzerain ?= {
						mpo_decisions_events_0001_threat_trigger = yes
					}
				}
				suzerain = {
					save_scope_as = threat
				}
			}
		}
		else_if = {
			limit = {
				NOT = {
					exists = scope:threat
				}
			}
			ordered_land_neighboring_realm_with_tributaries_owner = {
				order_by = current_military_strength
				limit = {
					is_tributary = yes
					top_suzerain ?= {
						mpo_decisions_events_0001_threat_trigger = yes
					}
				}
				top_suzerain = {
					save_scope_as = threat
				}
			}
		}
		else = {
			capital_county = {
				kingdom = { 
					random_de_jure_county = {
						limit = {
							holder.top_liege = {
								mpo_decisions_events_0001_threat_trigger = yes
							}
						}
						holder.top_liege = {
							save_scope_as = threat
						} 
					}
				}
			}
		}
		if = {
			limit = {
				NOT = {
					exists = scope:threat
				}
			}
			ordered_land_neighboring_realm_with_tributaries_owner = {
				order_by = current_military_strength
				limit = {
					NOT = { is_allied_to = root }
				}
				save_scope_as = threat
			}
		}
		if = {
			limit = {
				any_realm_county = {
					is_landless_type_title = no
					kingdom = {
						any_de_jure_county = {
							holder.top_liege = scope:threat
						}
					}
				}
			}
			random_realm_county = {
				limit = {
					is_landless_type_title = no
					kingdom = {
						any_de_jure_county = {
							holder.top_liege = scope:threat
						}
					}
				}
				kingdom = { save_scope_as = home_kingdom }
			}
			
		}
		else = {
			capital_county.kingdom = {
				save_scope_as = home_kingdom
			}
		}
	}

	option = {
		name = mpo_decisions_events.0001.a
		custom_tooltip = enables_offer_confederation_tt
		custom_tooltip = offer_confederation_members_tt
		custom_tooltip = offer_confederation_5_year_warning_tt
		
		add_character_flag = {
			flag = forming_confederation
			years = 5
		}
	}
	#opt out
	option = {
		trigger = {
			is_ai = no
		}
		name = mpo_decisions_events.0001.b
		remove_decision_cooldown = call_for_confederation_decision
	}
	after = {
		scope:warrior ?= {
			remove_character_flag = need_military_outfit
		}
	}
}

#Leave confederation event for leaver
mpo_decisions_events.0002 = {
	type = character_event
	title = mpo_decisions_events.0002.t
	desc = {
		desc = mpo_decisions_events.0002.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:confederation
					scope:confederation = {
						any_confederation_member = {
							count >= 2
							NOT = {
								this = root
							}
						}
					}
				}
				desc = mpo_decisions_events.0002.desc_confederation_survives
			}
			desc = mpo_decisions_events.0002.desc_confederation_done
		}
	}
	theme = vassal
	left_portrait = {
		character = root
		animation = dismissal
	}
	right_portrait = {
		character = scope:other_confederate
		animation = disappointed
		camera = camera_event_right_forward
	}

	immediate = {
		ordered_in_list = {
			order_by = max_military_strength
			list = confederation_members
			save_scope_as = other_confederate
		}
		scope:confederation = {
			#Your confederation will survive, it has more members
			if = {
				limit = {
					any_confederation_member = {
						count >= 2
						NOT = {
							this = root
						}
					}
				}
				remove_confederation_member = root
			}
			#Your confederation is toast
			else = {
				disband_confederation = yes
			}
		}
		if = {
			limit = {
				government_has_flag = government_is_nomadic
			}
			show_as_tooltip = {
				remove_character_modifier = mpo_confederation_member_modifier
			}
		}
		every_in_list = {
			list = confederation_members
			custom = custom.every_confederation_member
			add_opinion = {
				modifier = turncoat_opinion
				target = root
				opinion = -20
			}
		}
	}

	#Bye
	option = {
		name = mpo_decisions_events.0002.a
		every_in_list = {
			list = confederation_members
			trigger_event = mpo_decisions_events.0003
		}
	}
}

#Leave confederation event for other members
mpo_decisions_events.0003 = {
	type = character_event
	title = mpo_decisions_events.0003.t
	desc = {
		desc = mpo_decisions_events.0003.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					is_confederation_member = yes
				}
				desc = mpo_decisions_events.0003.desc_confederation_survives
			}
			desc = mpo_decisions_events.0003.desc_confederation_done
		}
	}
	theme = vassal
	left_portrait = {
		character = root
		animation = war_defender
	}
	right_portrait = {
		character = scope:leaver
		animation = menacing
	}

	immediate = {
		if = {
			limit = {
				is_confederation_member = yes
			}
			custom_tooltip = leaver_left_confederation_tt
		}
		else = {
			custom_tooltip = leaver_destroyed_confederation_tt
		}
	}

	#See ya later, I guess. Douchebag
	option = {
		name = mpo_decisions_events.0003.a
	}
}

#Confederation elevated - vassal
mpo_decisions_events.0004 = {
	type = character_event
	title = mpo_decisions_events.0004.t
	desc = mpo_decisions_events.0004.desc
	theme = vassal
	override_background = { reference = courtyard }
	left_portrait = {
		character = root
		animation = obsequious_bow
		camera = camera_event_horse_left_forward
	}
	right_portrait = {
		character = scope:new_king_ruler
		animation = jockey_wave
		camera = camera_event_horse_right
	}

	immediate = {
		
	}

	option = {
		name = mpo_decisions_events.0004.a
		add_character_modifier = {
			modifier = confederate_vassal_modifier
		}
	}

	option = {
		name = mpo_decisions_events.0004.b
		trigger = {
			is_ai = no
		}
		create_title_and_vassal_change = {
			type = independency
			save_scope_as = change
		}
		becomes_independent = { change = scope:change }
		resolve_title_and_vassal_change = scope:change
	}
}

#Confederation elevated - king
mpo_decisions_events.0005 = {
	type = character_event
	title = mpo_decisions_events.0005.t
	desc = mpo_decisions_events.0005.desc
	theme = crown
	override_background = { reference = courtyard }
	left_portrait = {
		character = scope:new_king_ruler
		animation = standing_horse
		camera = camera_event_standing_with_horse_left
	}
	right_portrait = {
		character = scope:vassal
		animation = throne_room_kneel_1
		camera = camera_event_right_to_the_right
	}

	immediate = {
		ordered_vassal = {
			order_by = "opinion(root)"
			limit = {
				age > 5
				basic_is_available_ai = yes
			}
			save_scope_as = vassal
		}
	}

	option = {
		name = mpo_decisions_events.0005.a
		add_character_modifier = {
			modifier = confederate_king_modifier
			years = 15
		}
		every_sub_realm_county = {
			custom = custom.every_realm_county
			add_county_modifier = {
				modifier = confederate_lands_modifier
				years = 30
			}
		}
	}
}

scripted_effect mpo_decisions_events_0020_bonuses_tooltips_effect = {
	if = {
		limit = {
			is_vassal_of = root
			is_ai = yes
			NOT = { is_obedient_to = root }
		}
		custom_tooltip = friend_heir_target_vassal_tt
		custom_tooltip = friend_heir_target_vassal_obedient_tt
	}
	if = {
		limit = {
			is_allied_to = root
		}
		custom_tooltip = friend_heir_target_ally_tt
	}
	custom_tooltip = friend_heir_success_factors_tt
	
	#Positive option unlocks
	if = {
		limit = {
			number_of_traits_in_common = {
				target = scope:heir
				value = 1
			}
		}
		custom_tooltip = heir_friend_1_common_trait_tt
	}
	if = {
		limit = {
			number_of_traits_in_common = {
				target = scope:heir
				value = 2
			}
		}
		custom_tooltip = heir_friend_2_common_trait_tt
	}
	if = {
		limit = {
			number_of_traits_in_common = {
				target = scope:heir
				value = 3
			}
		}
		custom_tooltip = heir_friend_3_common_trait_tt
	}
	if = {
		limit = {
			number_of_traits_in_common = {
				target = scope:heir
				value = 4
			}
		}
		custom_tooltip = heir_friend_4_common_trait_tt
	}
	if = {
		limit = {
			number_of_traits_in_common = {
				target = scope:heir
				value = 5
			}
		}
		custom_tooltip = heir_friend_5_common_trait_tt
	}
	if = {
		limit = {
			number_of_traits_in_common = {
				target = scope:heir
				value >= 6
			}
		}
		custom_tooltip = heir_friend_6_or_more_common_trait_tt
	}
	if = {
		limit = {
			OR = {
				AND = {
					has_trait = lifestyle_hunter
					scope:heir = { has_trait = lifestyle_hunter }
				}
				AND = {
					has_trait = lifestyle_reveler
					scope:heir = { has_trait = lifestyle_reveler }
				}
				AND = {
					has_trait = lifestyle_traveler
					scope:heir = { has_trait = lifestyle_traveler }
				}
				AND = {
					has_trait = lifestyle_blademaster
					scope:heir = { has_trait = lifestyle_blademaster }
				}
				AND = {
					has_trait = lifestyle_herbalist
					scope:heir = { has_trait = lifestyle_herbalist }
				}
				AND = {
					has_trait = lifestyle_mystic
					scope:heir = { has_trait = lifestyle_mystic }
				}
				AND = {
					has_trait = lifestyle_physician
					scope:heir = { has_trait = lifestyle_physician }
				}
				AND = {
					has_trait = lifestyle_poet
					scope:heir = { has_trait = lifestyle_poet }
				}
				AND = {
					has_trait = lifestyle_gardener
					scope:heir = { has_trait = lifestyle_gardener }
				}
				AND = {
					has_trait = drunkard
					scope:heir = { has_trait = drunkard }
				}
				AND = {
					has_trait = hashishiyah
					scope:heir = { has_trait = hashishiyah }
				}
			}
		}
		custom_tooltip = heir_friend_lifestyle_tt
	}
	if = {
		limit = {
			OR = {
				AND = {
					has_trait = tourney_participant
					has_trait_xp = {
						trait = tourney_participant
						track = foot
						value >= 50
					}
					
					scope:heir = {
						has_trait = tourney_participant
						has_trait_xp = {
							trait = tourney_participant
							track = foot
							value >= 50
						}
					}
				}
				AND = {
					has_trait = tourney_participant
					has_trait_xp = {
						trait = tourney_participant
						track = bow
						value >= 50
					}
					
					scope:heir = {
						has_trait = tourney_participant
						has_trait_xp = {
							trait = tourney_participant
							track = bow
							value >= 50
						}
					}
				}
				AND = {
					has_trait = tourney_participant
					has_trait_xp = {
						trait = tourney_participant
						track = horse
						value >= 50
					}
					
					scope:heir = {
						has_trait = tourney_participant
						has_trait_xp = {
							trait = tourney_participant
							track = horse
							value >= 50
						}
					}
				}
				AND = {
					has_trait = tourney_participant
					has_trait_xp = {
						trait = tourney_participant
						track = wit
						value >= 50
					}
					
					scope:heir = {
						has_trait = tourney_participant
						has_trait_xp = {
							trait = tourney_participant
							track = wit
							value >= 50
						}
					}
				}
			}
		}
		custom_tooltip = heir_friend_sports_tt
	}
	if = {
		limit = {
			has_relation_blood_brother = root
		}
		custom_tooltip = heir_friend_blood_brother_tt
	}
	if = {
		limit = {
			OR = {
				has_relation_friend = root
				has_relation_best_friend = root
				has_relation_soulmate = root
				has_relation_lover = root
			}
		}
		custom_tooltip = heir_friend_positive_relation_tt
	}
	if = {
		limit = {
			AND = {
				exists = house
				exists = scope:heir.house
				house = {
					this = root.house
				}
			}
		}
		custom_tooltip = heir_friend_house_tt
	}
	if = {
		limit = {
			OR = {
				culture = {
					this = scope:heir.culture
				}
				culture = {
					cultural_acceptance = {
						target = scope:heir.culture
						value >= 80
					}
				}
			}
		}
		custom_tooltip = heir_friend_culture_tt
	}

	#Positive bonuses
	if = {
		limit = {
			is_allied_to = root
		}
		custom_tooltip = heir_friend_roots_ally_tt
	}
	if = {
		limit = {
			opinion = {
				target = scope:heir
				value >= 25
			}
		}
		custom_tooltip = heir_friend_likes_heir_tt
	}
	if = {
		limit = {
			age_compared_to_player_heir < 10
			age_compared_to_player_heir > -10
		}
		custom_tooltip = heir_friend_similar_age_tt
	}

	#Negative maluses
	if = {
		limit = {
			opinion = {
				target = scope:heir
				value <= 0
			}
			opinion = {
				target = scope:heir
				value > -40
			}
		}
		custom_tooltip = heir_friend_dislikes_heir_tt
	}
	if = {
		limit = {
			opinion = {
				target = scope:heir
				value <= -40
			}
		}
		custom_tooltip = heir_friend_hates_heir_tt
	}
	if = {
		limit = {
			save_temporary_scope_as = temp_target
			NOR = {
				knows_language_of_culture = scope:heir.culture
				scope:heir = {
					knows_language_of_culture = scope:temp_target.culture
				}
			}
		}
		custom_tooltip = heir_friend_cant_communicate_tt
	}
	if = {
		limit = {
			OR = {
				age_compared_to_player_heir >= 20
				age_compared_to_player_heir <= -20
			}
		}
		custom_tooltip = heir_friend_different_age_tt
	}
	if = {
		limit = {
			highest_held_title_tier = tier_kingdom
		}
		custom_tooltip = heir_friend_high_tier_tt
	}
	if = {
		limit = {
			highest_held_title_tier >= tier_empire
		}
		custom_tooltip = heir_friend_very_high_tier_tt
	}
}

#Introduce Heir (friend matchmaking)
#By Jason Cantalini
mpo_decisions_events.0020 = {
	type = character_event
	title = mpo_decisions_events.0020.t
	desc = {
		desc = mpo_decisions_events.0020.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					any_in_list = {
						list = saved_targets
						count >= 2
					}
				}
				desc = mpo_decisions_events.0020.desc_multiple
			}
			desc = mpo_decisions_events.0020.desc_one
		}
	} 
	theme = nomads
	override_background = { 
		trigger = {
			government_has_flag = government_is_nomadic
		}
		reference = mpo_camp_steppe
	}
	override_background = { 
		trigger = {
			NOT = {
				government_has_flag = government_is_nomadic
			}
		}
		reference = wilderness
	}
	left_portrait = {
		character = root
		animation = standing_horse
		camera = camera_event_standing_with_horse_left
	}
	right_portrait = {
		character = scope:heir
		animation = horse_conversing_left
		camera = camera_event_horse_right_facing_left
	}
	lower_right_portrait = scope:target_1
	lower_center_portrait = scope:target_2
	lower_left_portrait = scope:target_3

	immediate = {
		save_scope_as = root_scope
		player_heir = {
			save_scope_as = heir
			#Yes, I know how stupid this looks
			save_scope_as = loc_heir
		}
		#Save targets
		#Allies will always precede powerful vassals, who precede regular vassals

		#Good relations with root
		every_ally = {
			limit = {
				mpo_valid_heir_friend_trigger = { CHARACTER = root }
				reverse_opinion = {
					target = root
					value >= 0
				}
				OR = {
					has_relation_friend = root
					has_relation_best_friend = root
					has_relation_soulmate = root
					has_relation_blood_brother = root
				}
			}
			add_to_list = saved_targets
		}
		if = {
			limit = {
				list_size = {
					name = saved_targets
					value < 5
				}
			}
			every_powerful_vassal = {
				limit = {
					is_obedient_to = root
					mpo_valid_heir_friend_trigger = { CHARACTER = root }
					reverse_opinion = {
						target = root
						value >= 0
					}
					OR = {
						has_relation_friend = root
						has_relation_best_friend = root
						has_relation_soulmate = root
						has_relation_blood_brother = root
					}
				}
				add_to_list = saved_targets
			}
		}
		if = {
			limit = {
				list_size = {
					name = saved_targets
					value < 5
				}
			}
			every_vassal = {
				limit = {
					is_obedient_to = root
					mpo_valid_heir_friend_trigger = { CHARACTER = root }
					reverse_opinion = {
						target = root
						value >= 0
					}
					OR = {
						has_relation_friend = root
						has_relation_best_friend = root
						has_relation_soulmate = root
						has_relation_blood_brother = root
					}
				}
				add_to_list = saved_targets
			}
		}
		#Take care of blood brothers
		if = {
			limit = {
				list_size = {
					name = saved_targets
					value < 5
				}
			}
			every_relation = {
				type = blood_brother
				limit = {
					mpo_valid_heir_friend_trigger = { CHARACTER = root }
				}
				add_to_list = saved_targets
			}
		}
		#friends
		if = {
			limit = {
				list_size = {
					name = saved_targets
					value < 5
				}
			}
			every_relation = {
				type = friend
				limit = {
					mpo_valid_heir_friend_trigger = { CHARACTER = root }
				}
				add_to_list = saved_targets
			}
		}
		#soulmates
		if = {
			limit = {
				list_size = {
					name = saved_targets
					value < 5
				}
			}
			every_relation = {
				type = soulmate
				limit = {
					mpo_valid_heir_friend_trigger = { CHARACTER = root }
				}
				add_to_list = saved_targets
			}
		}
		#Allied vassal
		if = {
			limit = {
				list_size = {
					name = saved_targets
					value < 5
				}
			}
			every_powerful_vassal = {
				limit = {
					is_obedient_to = root
					mpo_valid_heir_friend_trigger = { CHARACTER = root }
					reverse_opinion = {
						target = root
						value >= 0
					}
					is_allied_to = root
				}
				add_to_list = saved_targets
			}
		}
		if = {
			limit = {
				list_size = {
					name = saved_targets
					value < 5
				}
			}
			every_vassal = {
				limit = {
					is_obedient_to = root
					mpo_valid_heir_friend_trigger = { CHARACTER = root }
					reverse_opinion = {
						target = root
						value >= 0
					}
					is_allied_to = root
				}
				add_to_list = saved_targets
			}
		}
		#Same house as root
		if = {
			limit = {
				list_size = {
					name = saved_targets
					value < 5
				}
			}
			every_ally = {
				limit = {
					mpo_valid_heir_friend_trigger = { CHARACTER = root }
					reverse_opinion = {
						target = root
						value >= 0
					}
					AND = {
						exists = house
						exists = root.house
						house = {
							this = root.house
						}
					}
				}
				add_to_list = saved_targets
			}
		}
		if = {
			limit = {
				list_size = {
					name = saved_targets
					value < 5
				}
			}
			every_powerful_vassal = {
				limit = {
					is_obedient_to = root
					mpo_valid_heir_friend_trigger = { CHARACTER = root }
					reverse_opinion = {
						target = root
						value >= 0
					}
					AND = {
						exists = house
						exists = root.house
						house = {
							this = root.house
						}
					}
				}
				add_to_list = saved_targets
			}
		}
		if = {
			limit = {
				list_size = {
					name = saved_targets
					value < 5
				}
			}
			every_vassal = {
				limit = {
					is_obedient_to = root
					mpo_valid_heir_friend_trigger = { CHARACTER = root }
					reverse_opinion = {
						target = root
						value >= 0
					}
					AND = {
						exists = house
						exists = root.house
						house = {
							this = root.house
						}
					}
				}
				add_to_list = saved_targets
			}
		}
		#Same culture as root
		if = {
			limit = {
				list_size = {
					name = saved_targets
					value < 5
				}
			}
			every_ally = {
				limit = {
					mpo_valid_heir_friend_trigger = { CHARACTER = root }
					reverse_opinion = {
						target = root
						value >= 0
					}
					culture = root.culture
				}
				add_to_list = saved_targets
			}
		}
		if = {
			limit = {
				list_size = {
					name = saved_targets
					value < 5
				}
			}
			every_powerful_vassal = {
				limit = {
					is_obedient_to = root
					mpo_valid_heir_friend_trigger = { CHARACTER = root }
					reverse_opinion = {
						target = root
						value >= 0
					}
					culture = root.culture
				}
				add_to_list = saved_targets
			}
		}
		if = {
			limit = {
				list_size = {
					name = saved_targets
					value < 5
				}
			}
			every_vassal = {
				limit = {
					is_obedient_to = root
					mpo_valid_heir_friend_trigger = { CHARACTER = root }
					reverse_opinion = {
						target = root
						value >= 0
					}
					culture = root.culture
				}
				add_to_list = saved_targets
			}
		}
		#Root likes them
		if = {
			limit = {
				list_size = {
					name = saved_targets
					value < 5
				}
			}
			every_ally = {
				limit = {
					mpo_valid_heir_friend_trigger = { CHARACTER = root }
					reverse_opinion = {
						target = root
						value >= 50
					}
				}
				add_to_list = saved_targets
			}
		}
		if = {
			limit = {
				list_size = {
					name = saved_targets
					value < 5
				}
			}
			every_powerful_vassal = {
				limit = {
					is_obedient_to = root
					mpo_valid_heir_friend_trigger = { CHARACTER = root }
					reverse_opinion = {
						target = root
						value >= 50
					}
				}
				add_to_list = saved_targets
			}
		}
		if = {
			limit = {
				list_size = {
					name = saved_targets
					value < 5
				}
			}
			every_vassal = {
				limit = {
					is_obedient_to = root
					mpo_valid_heir_friend_trigger = { CHARACTER = root }
					reverse_opinion = {
						target = root
						value >= 50
					}
				}
				add_to_list = saved_targets
			}
		}
		#Any vassal/ally
		if = {
			limit = {
				list_size = {
					name = saved_targets
					value < 5
				}
			}
			every_ally = {
				limit = {
					mpo_valid_heir_friend_trigger = { CHARACTER = root }
				}
				add_to_list = saved_targets
			}
		}
		if = {
			limit = {
				list_size = {
					name = saved_targets
					value < 5
				}
			}
			every_powerful_vassal = {
				limit = {
					is_obedient_to = root
					mpo_valid_heir_friend_trigger = { CHARACTER = root }
				}
				add_to_list = saved_targets
			}
		}
		if = {
			limit = {
				list_size = {
					name = saved_targets
					value < 5
				}
			}
			every_vassal = {
				limit = {
					is_obedient_to = root
					mpo_valid_heir_friend_trigger = { CHARACTER = root }
				}
				add_to_list = saved_targets
			}
		}
		
		#Now that we've put top candidates in list, save their scopes
		random_in_list = {
			list = saved_targets
			save_scope_as = target_1
		}
		if = {
			limit = {
				any_in_list = {
					list = saved_targets
					NOT = {
						this = scope:target_1
					}
				}
			}
			random_in_list = {
				list = saved_targets
				limit = {
					NOT = {
						this = scope:target_1
					}
				}
				save_scope_as = target_2
			}
		}
		if = {
			limit = {
				any_in_list = {
					list = saved_targets
					NOR = {
						this = scope:target_1
						this = scope:target_2
					}
				}
			}
			random_in_list = {
				list = saved_targets
				limit = {
					NOR = {
						this = scope:target_1
						this = scope:target_2
					}
				}
				save_scope_as = target_3
			}
		}
		if = {
			limit = {
				any_in_list = {
					list = saved_targets
					NOR = {
						this = scope:target_1
						this = scope:target_2
						this = scope:target_3
					}
				}
			}
			random_in_list = {
				list = saved_targets
				limit = {
					NOR = {
						this = scope:target_1
						this = scope:target_2
						this = scope:target_3
					}
				}
				save_scope_as = target_4
			}
		}
		if = {
			limit = {
				any_in_list = {
					list = saved_targets
					NOR = {
						this = scope:target_1
						this = scope:target_2
						this = scope:target_3
						this = scope:target_4
					}
				}
			}
			random_in_list = {
				list = saved_targets
				limit = {
					NOR = {
						this = scope:target_1
						this = scope:target_2
						this = scope:target_3
						this = scope:target_4
					}
				}
				save_scope_as = target_5
			}
		}
	}
	#Friends with friend-bachelor #1!
	option = {
		name = mpo_decisions_events.0020.a
		scope:target_1 = {
			save_scope_as = friendship_target
			mpo_decisions_events_0020_bonuses_tooltips_effect = yes
		}
		trigger_event = {
			id = mpo_decisions_events.0021
			days = 3
		}
		stress_impact = {
			shy = medium_stress_impact_gain
			callous = minor_stress_impact_gain
			paranoid = medium_stress_impact_gain
		}
		ai_chance = {
			base = 101
			modifier = {
				OR = {
					has_relation_friend = scope:target_1
					has_relation_best_friend = scope:target_1
					has_relation_soulmate = scope:target_1
					has_relation_lover = scope:target_1
					has_relation_blood_brother = scope:target_1
				}
				add = 100
			}
			modifier = {
				scope:target_1 = {
					opinion = {
						target = scope:heir
						value <= 0
					}
				}
				add = -100
			}
			modifier = {
				scope:target_1 = {
					opinion = {
						target = scope:heir
						value < -40
					}
				}
				add = -200
			}
			modifier = {
				scope:target_1 = {
					AND = {
						exists = house
						exists = scope:heir.house
						house = {
							this = root.house
						}
					}
				}
				add = 50
			}
			modifier = {
				scope:target_1 = {
					OR = {
						culture = {
							this = scope:heir.culture
						}
						culture = {
							cultural_acceptance = {
								target = scope:heir.culture
								value >= 80
							}
						}
					}
				}
				add = 50
			}
			modifier = {
				scope:target_1 = {
					opinion = {
						target = scope:heir
						value >= 75
					}
				}
				add = 100
			}
		}
	}
	#Friends with friend-bachelor #2!
	option = {
		trigger = {
			exists = scope:target_2
		}
		name = mpo_decisions_events.0020.b
		scope:target_2 = {
			save_scope_as = friendship_target
			mpo_decisions_events_0020_bonuses_tooltips_effect = yes
		}
		trigger_event = {
			id = mpo_decisions_events.0021
			days = 3
		}
		stress_impact = {
			shy = medium_stress_impact_gain
			callous = minor_stress_impact_gain
			paranoid = medium_stress_impact_gain
		}
		
		ai_chance = {
			base = 101
			modifier = {
				OR = {
					has_relation_friend = scope:target_2
					has_relation_best_friend = scope:target_2
					has_relation_soulmate = scope:target_2
					has_relation_lover = scope:target_2
					has_relation_blood_brother = scope:target_2
				}
				add = 100
			}
			modifier = {
				scope:target_2 = {
					opinion = {
						target = scope:heir
						value <= 0
					}
				}
				add = -100
			}
			modifier = {
				scope:target_2 = {
					opinion = {
						target = scope:heir
						value < -40
					}
				}
				add = -200
			}
			modifier = {
				scope:target_2 = {
					AND = {
						exists = house
						exists = scope:heir.house
						house = {
							this = root.house
						}
					}
				}
				add = 50
			}
			modifier = {
				scope:target_2 = {
					OR = {
						culture = {
							this = scope:heir.culture
						}
						culture = {
							cultural_acceptance = {
								target = scope:heir.culture
								value >= 80
							}
						}
					}
				}
				add = 50
			}
			modifier = {
				scope:target_2 = {
					opinion = {
						target = scope:heir
						value >= 75
					}
				}
				add = 100
			}
		}
	}
	#Friends with friend-bachelor #3!
	option = {
		trigger = {
			exists = scope:target_3
		}
		name = mpo_decisions_events.0020.c
		scope:target_3 = {
			save_scope_as = friendship_target
			mpo_decisions_events_0020_bonuses_tooltips_effect = yes
		}
		trigger_event = {
			id = mpo_decisions_events.0021
			days = 3
		}
		stress_impact = {
			shy = medium_stress_impact_gain
			callous = minor_stress_impact_gain
			paranoid = medium_stress_impact_gain
		}
		
		ai_chance = {
			base = 101
			modifier = {
				OR = {
					has_relation_friend = scope:target_3
					has_relation_best_friend = scope:target_3
					has_relation_soulmate = scope:target_3
					has_relation_lover = scope:target_3
					has_relation_blood_brother = scope:target_3
				}
				add = 100
			}
			modifier = {
				scope:target_3 = {
					opinion = {
						target = scope:heir
						value <= 0
					}
				}
				add = -100
			}
			modifier = {
				scope:target_3 = {
					opinion = {
						target = scope:heir
						value < -40
					}
				}
				add = -200
			}
			modifier = {
				scope:target_3 = {
					AND = {
						exists = house
						exists = scope:heir.house
						house = {
							this = root.house
						}
					}
				}
				add = 50
			}
			modifier = {
				scope:target_3 = {
					OR = {
						culture = {
							this = scope:heir.culture
						}
						culture = {
							cultural_acceptance = {
								target = scope:heir.culture
								value >= 80
							}
						}
					}
				}
				add = 50
			}
			modifier = {
				scope:target_3 = {
					opinion = {
						target = scope:heir
						value >= 75
					}
				}
				add = 100
			}
		}
	}
	#Friends with friend-bachelor #4!
	option = {
		trigger = {
			exists = scope:target_4
		}
		name = mpo_decisions_events.0020.d
		scope:target_4 = {
			save_scope_as = friendship_target
			mpo_decisions_events_0020_bonuses_tooltips_effect = yes
		}
		trigger_event = {
			id = mpo_decisions_events.0021
			days = 3
		}
		stress_impact = {
			shy = medium_stress_impact_gain
			callous = minor_stress_impact_gain
			paranoid = medium_stress_impact_gain
		}
		
		ai_chance = {
			base = 101
			modifier = {
				OR = {
					has_relation_friend = scope:target_4
					has_relation_best_friend = scope:target_4
					has_relation_soulmate = scope:target_4
					has_relation_lover = scope:target_4
					has_relation_blood_brother = scope:target_4
				}
				add = 100
			}
			modifier = {
				scope:target_4 = {
					opinion = {
						target = scope:heir
						value <= 0
					}
				}
				add = -100
			}
			modifier = {
				scope:target_4 = {
					opinion = {
						target = scope:heir
						value < -40
					}
				}
				add = -200
			}
			modifier = {
				scope:target_4 = {
					AND = {
						exists = house
						exists = scope:heir.house
						house = {
							this = root.house
						}
					}
				}
				add = 50
			}
			modifier = {
				scope:target_4 = {
					OR = {
						culture = {
							this = scope:heir.culture
						}
						culture = {
							cultural_acceptance = {
								target = scope:heir.culture
								value >= 80
							}
						}
					}
				}
				add = 50
			}
			modifier = {
				scope:target_4 = {
					opinion = {
						target = scope:heir
						value >= 75
					}
				}
				add = 100
			}
		}
	}
	#Friends with friend-bachelor #5!
	option = {
		trigger = {
			exists = scope:target_5
		}
		name = mpo_decisions_events.0020.e
		scope:target_5 = {
			save_scope_as = friendship_target
			mpo_decisions_events_0020_bonuses_tooltips_effect = yes
		}
		trigger_event = {
			id = mpo_decisions_events.0021
			days = 1
		}
		stress_impact = {
			shy = medium_stress_impact_gain
			callous = minor_stress_impact_gain
			paranoid = medium_stress_impact_gain
		}
		
		ai_chance = {
			base = 101
			modifier = {
				OR = {
					has_relation_friend = scope:target_5
					has_relation_best_friend = scope:target_5
					has_relation_soulmate = scope:target_5
					has_relation_lover = scope:target_5
					has_relation_blood_brother = scope:target_5
				}
				add = 100
			}
			modifier = {
				scope:target_5 = {
					opinion = {
						target = scope:heir
						value <= 0
					}
				}
				add = -100
			}
			modifier = {
				scope:target_5 = {
					opinion = {
						target = scope:heir
						value < -40
					}
				}
				add = -200
			}
			modifier = {
				scope:target_5 = {
					AND = {
						exists = house
						exists = scope:heir.house
						house = {
							this = root.house
						}
					}
				}
				add = 50
			}
			modifier = {
				scope:target_5 = {
					OR = {
						culture = {
							this = scope:heir.culture
						}
						culture = {
							cultural_acceptance = {
								target = scope:heir.culture
								value >= 80
							}
						}
					}
				}
				add = 50
			}
			modifier = {
				scope:target_5 = {
					opinion = {
						target = scope:heir
						value >= 75
					}
				}
				add = 100
			}
		}
	}
	#Yeah... not these bozos
	option = {
		name = mpo_decisions_events.0020.f
		remove_decision_cooldown = mpo_decision_introduce_heir
		add_prestige = mpo_introduce_heir_prestige_cost
		add_piety = mpo_introduce_heir_piety_cost
	}
}

scripted_effect mpo_decisions_events_0021_positive_outcome_effect = {
	scope:friendship_target = {
		show_as_tooltip = {
			set_relation_friend = {
				target = scope:heir
				reason = friend_introduced_heir
			}
			if = {
				limit = {
					is_ai = yes
					is_vassal_of = root
					NOT = { is_obedient_to = root }
				}
				custom_tooltip = friend_heir_may_become_obedient
			}
			if = {
				limit = {
					is_allied_to = root
				}
				custom_tooltip = friend_heir_may_become_blood_brother
			}
		}
	}
}

scripted_effect mpo_decisions_events_0021_negative_outcome_effect = {
	custom_tooltip = friendship_setup_fail_tt
	add_character_flag = {
		flag = heir_friend_failed
		days = 40
	}
}

#Friendship maneuvering event
mpo_decisions_events.0021 = {
	type = character_event
	title = mpo_decisions_events.0021.t
	desc = {
		desc = mpo_decisions_events.0021.desc_intro
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:friendship_target = {
						opinion = {
							target = scope:heir
							value >= 40
						}
					}
				}
				desc = mpo_decisions_events.0021.desc_warm
			}
			desc = mpo_decisions_events.0021.desc_cold
		}
		desc = mpo_decisions_events.0021.desc
	}
	theme = nomads
	override_background = { 
		reference = relaxing_room
	}
	left_portrait = {
		character = scope:heir
		triggered_animation = {
			trigger = {
				scope:friendship_target = {
					opinion = {
						target = scope:heir
						value >= 40
					}
				}
			}
			animation = personality_content
		}
		animation = boredom
	}
	right_portrait = {
		character = scope:friendship_target
		triggered_animation = {
			trigger = {
				scope:heir = {
					reverse_opinion = {
						target = scope:friendship_target
						value >= 40
					}
				}
			}
			animation = hunting_carcass_start
		}
		animation = war_defender
	}

	trigger = {
		is_alive = yes
		scope:heir = {
			is_alive = yes
		}
		scope:friendship_target = {
			is_alive = yes
		}
	}
	immediate = {
		scope:heir = {
			get_quirk_character_effect = yes
		}
		scope:friendship_target = {
			save_scope_as = bg_override_char
			random_list = {
				1 = {
					trigger = {
						has_trait = lifestyle_hunter
						scope:heir = {
							has_trait = lifestyle_hunter
						}
					}
					trait:lifestyle_hunter = {
						save_scope_as = lifestyle_trait
					}
				}
				1 = {
					trigger = {
						has_trait = lifestyle_reveler
					scope:heir = { has_trait = lifestyle_reveler }
					}
					trait:lifestyle_reveler = {
						save_scope_as = lifestyle_trait
					}
				}
				1 = {
					trigger = {
						has_trait = lifestyle_traveler
						scope:heir = { has_trait = lifestyle_traveler }
					}
					trait:lifestyle_traveler = {
						save_scope_as = lifestyle_trait
					}
				}
				1 = {
					trigger = {
						has_trait = lifestyle_blademaster
						scope:heir = { has_trait = lifestyle_blademaster }
					}
					trait:lifestyle_reveler = {
						save_scope_as = lifestyle_trait
					}
				}
				1 = {
					trigger = {
						has_trait = lifestyle_herbalist
						scope:heir = { has_trait = lifestyle_herbalist }
					}
					trait:lifestyle_herbalist = {
						save_scope_as = lifestyle_trait
					}
				}
				1 = {
					trigger = {
						has_trait = lifestyle_mystic
						scope:heir = { has_trait = lifestyle_mystic }
					}
					trait:lifestyle_mystic = {
						save_scope_as = lifestyle_trait
					}
				}
				1 = {
					trigger = {
						has_trait = lifestyle_physician
						scope:heir = { has_trait = lifestyle_physician }
					}
					trait:lifestyle_physician = {
						save_scope_as = lifestyle_trait
					}
				}
				1 = {
					trigger = {
						has_trait = lifestyle_poet
						scope:heir = { has_trait = lifestyle_poet }
					}
					trait:lifestyle_poet = {
						save_scope_as = lifestyle_trait
					}
				}
				1 = {
					trigger = {
						has_trait = lifestyle_gardener
						scope:heir = { has_trait = lifestyle_gardener }
					}
					trait:lifestyle_gardener = {
						save_scope_as = lifestyle_trait
					}
				}
				1 = {
					trigger = {
						has_trait = drunkard
						scope:heir = { has_trait = drunkard }
					}
					trait:drunkard = {
						save_scope_as = lifestyle_trait
					}
				}
				1 = {
					trigger = {
						has_trait = hashishiyah
						scope:heir = { has_trait = hashishiyah }
					}
					trait:hashishiyah = {
						save_scope_as = lifestyle_trait
					}
				}
			}
		}
	}
	#Charm them with your high diplo
	option = {
		trigger = {
			diplomacy >= very_high_skill_rating
		}
		name = mpo_decisions_events.0021.a
		flavor = mpo_decisions_events.0021.a.flavor
		add_character_flag = {
			flag = heir_friend_personal_charm
			days = 40
		}
		if = {
			limit = {
				scope:friendship_target = {
					is_ai = yes
				}
			}
			
			duel = {
				skill = diplomacy
				value = medium_skill_rating
				#Successful - they're friends!
				45 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = 3.5
						min = -44
					}
					modifier = {
						scope:friendship_target = {
							opinion = {
								target = root
								value >= 75
							}
						}
						add = 20
					}
					modifier = {
						scope:friendship_target = {
							opinion = {
								target = root
								value >= 90
							}
						}
						add = 20
					}
					modifier = {
						add = mpo_friendship_setup_positive_modifiers_value
					}
					
					desc = mpo_decisions_events.0021.a.success
					mpo_decisions_events_0021_positive_outcome_effect = yes
					show_as_tooltip = {
						add_diplomacy_lifestyle_xp = minor_lifestyle_xp
					}
				}
				# Fail - they're pretty meh about each other
				55 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = -3.5
						# Limit how low the off-chance can go.
						min = -54
					}
					modifier = {
						add = mpo_friendship_setup_negative_modifiers_value
					}
	
					desc = mpo_decisions_events.0021.a.fail
					mpo_decisions_events_0021_negative_outcome_effect = yes
				}
			}
		}
		else = {
			#Player response
			custom_tooltip = mpo_heir_friend_if_accept_tt
			show_as_tooltip = {
				add_diplomacy_lifestyle_xp = minor_lifestyle_xp
			}
			mpo_decisions_events_0021_positive_outcome_effect = yes
			custom_tooltip = mpo_heir_friend_if_do_not_accept_tt
			custom_tooltip = friendship_setup_fail_tt
		}
		stress_impact = {
			shy = miniscule_stress_impact_gain
			trusting = miniscule_stress_impact_gain
		}
		ai_chance = {
			base = 200
			ai_value_modifier = {
				ai_sociability = 1
				ai_energy = 0.5
			}
			modifier = {
				diplomacy > extremely_high_skill_rating
				add = 100
			}
		}
	}
	#Do their lifestyle traits together
	option = {
		trigger = {
			exists = scope:lifestyle_trait
		}
		name = mpo_decisions_events.0021.b
		flavor = mpo_decisions_events.0021.b.flavor
		add_internal_flag = special
		add_character_flag = {
			flag = heir_friend_lifestyle_trait
			days = 40
		}
		if = {
			limit = {
				scope:friendship_target = {
					is_ai = yes
				}
			}
			duel = {
				skill = diplomacy
				value = average_skill_rating
				#Successful - they're friends!
				65 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = 0.1
						min = -64
					}
					modifier = {
						add = mpo_friendship_setup_positive_modifiers_value
					}
					
					desc = mpo_decisions_events.0021.b.success
					mpo_decisions_events_0021_positive_outcome_effect = yes
					show_as_tooltip = {
						mpo_heir_lifestyle_xp_gain_effect = yes
					}
				}
				# Fail - they're pretty meh about each other
				35 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = -0.1
						min = -34
					}
					modifier = {
						add = mpo_friendship_setup_negative_modifiers_value
					}

					desc = mpo_decisions_events.0021.b.fail
					mpo_decisions_events_0021_negative_outcome_effect = yes
				}
			}
		}
		else = {
			#Player response
			custom_tooltip = mpo_heir_friend_if_accept_tt
			show_as_tooltip = {
				mpo_heir_lifestyle_xp_gain_effect = yes
			}
			mpo_decisions_events_0021_positive_outcome_effect = yes
			custom_tooltip = mpo_heir_friend_if_do_not_accept_tt
			custom_tooltip = friendship_setup_fail_tt
		}
		ai_chance = {
			base = 200
		}
	}
	
	#Do their sports together
	option = {
		trigger = {
			scope:friendship_target = {
				OR = {
					AND = {
						has_trait = tourney_participant
						has_trait_xp = {
							trait = tourney_participant
							track = foot
							value >= 50
						}
						
						scope:heir = {
							has_trait = tourney_participant
							has_trait_xp = {
								trait = tourney_participant
								track = foot
								value >= 50
							}
						}
					}
					AND = {
						has_trait = tourney_participant
						has_trait_xp = {
							trait = tourney_participant
							track = bow
							value >= 50
						}
						
						scope:heir = {
							has_trait = tourney_participant
							has_trait_xp = {
								trait = tourney_participant
								track = bow
								value >= 50
							}
						}
					}
					AND = {
						has_trait = tourney_participant
						has_trait_xp = {
							trait = tourney_participant
							track = horse
							value >= 50
						}
						
						scope:heir = {
							has_trait = tourney_participant
							has_trait_xp = {
								trait = tourney_participant
								track = horse
								value >= 50
							}
						}
					}
					AND = {
						has_trait = tourney_participant
						has_trait_xp = {
							trait = tourney_participant
							track = wit
							value >= 50
						}
						
						scope:heir = {
							has_trait = tourney_participant
							has_trait_xp = {
								trait = tourney_participant
								track = wit
								value >= 50
							}
						}
					}
				}
			}
		}
		name = mpo_decisions_events.0021.c
		flavor = mpo_decisions_events.0021.c.flavor
		reason = tourney_participant
		add_internal_flag = special
		add_character_flag = {
			flag = heir_friend_sports
			days = 40
		}
		if = {
			limit = {
				scope:friendship_target = {
					is_ai = yes
				}
			}
			duel = {
				skill = diplomacy
				value = average_skill_rating
				#Successful - they're friends!
				65 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = 0.1
						min = -64
					}
					modifier = {
						add = mpo_friendship_setup_positive_modifiers_value
					}
					
					desc = mpo_decisions_events.0021.c.success
					mpo_decisions_events_0021_positive_outcome_effect = yes
					show_as_tooltip = {
						mpo_heir_hastiluder_xp_gain_effect = yes
					}
				}
				# Fail - they're pretty meh about each other
				35 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = -0.1
						min = -34
					}
					modifier = {
						add = mpo_friendship_setup_negative_modifiers_value
					}

					desc = mpo_decisions_events.0021.c.fail
					mpo_decisions_events_0021_negative_outcome_effect = yes
				}
			}
		}
		else = {
			#Player response
			custom_tooltip = mpo_heir_friend_if_accept_tt
			show_as_tooltip = {
				mpo_heir_hastiluder_xp_gain_effect = yes
			}
			mpo_decisions_events_0021_positive_outcome_effect = yes
			custom_tooltip = mpo_heir_friend_if_do_not_accept_tt
			custom_tooltip = friendship_setup_fail_tt
		}
		ai_chance = {
			base = 200
			ai_value_modifier = {
				ai_energy = 0.5
				ai_boldness = 0.5
			}
		}
	}
	#Bond over shared traits
	option = {
		trigger = {
			scope:friendship_target = {
				trigger_if = {
					limit = {
						has_trait = nomadic_philosophy
						scope:heir = {
							has_trait = nomadic_philosophy
						}
					}
					number_of_traits_in_common = {
						target = scope:heir
						value >= 2
					}
				}
				trigger_else = {
					number_of_traits_in_common = {
						target = scope:heir
						value >= 1
					}
				}
			}
		}
		name = mpo_decisions_events.0021.d
		flavor = mpo_decisions_events.0021.d.flavor
		add_internal_flag = special
		add_character_flag = {
			flag = heir_friend_shared_traits
			days = 40
		}
		if = {
			limit = {
				scope:friendship_target = {
					is_ai = yes
				}
			}
			duel = {
				skill = diplomacy
				value = average_skill_rating
				#Successful - they're friends!
				45 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = 0.1
						min = -44
					}
					modifier = {
						add = mpo_friendship_setup_positive_modifiers_value
					}
					modifier = {
						scope:friendship_target = {
							number_of_traits_in_common = {
								target = scope:heir
								value >= 3
							}
						}
						add = 40
					}
					modifier = {
						scope:friendship_target = {
							number_of_traits_in_common = {
								target = scope:heir
								value >= 4
							}
						}
						add = 40
					}
					modifier = {
						scope:friendship_target = {
							number_of_traits_in_common = {
								target = scope:heir
								value >= 5
							}
						}
						add = 40
					}
					modifier = {
						scope:friendship_target = {
							number_of_traits_in_common = {
								target = scope:heir
								value >= 6
							}
						}
						add = 40
					}
					
					desc = mpo_decisions_events.0021.d.success
					mpo_decisions_events_0021_positive_outcome_effect = yes
					show_as_tooltip = {
						scope:heir = {
							add_stress = minor_stress_impact_loss
							add_prestige = minor_prestige_gain
						}
					}
				}
				# Fail - they're pretty meh about each other
				55 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = -0.1
						min = -54
					}
					modifier = {
						add = mpo_friendship_setup_negative_modifiers_value
					}
					modifier = {
						scope:friendship_target = {
							number_of_traits_in_common = {
								target = scope:heir
								value <= 1
							}
						}
						add = -40
					}

					desc = mpo_decisions_events.0021.d.fail
					mpo_decisions_events_0021_negative_outcome_effect = yes
				}
			}
		}
		else = {
			#Player response
			custom_tooltip = mpo_heir_friend_if_accept_tt
			show_as_tooltip = {
				scope:heir = {
					add_stress = minor_stress_impact_loss
					add_prestige = minor_prestige_gain
				}
			}
			mpo_decisions_events_0021_positive_outcome_effect = yes
			custom_tooltip = mpo_heir_friend_if_do_not_accept_tt
			custom_tooltip = friendship_setup_fail_tt
		}
		ai_chance = {
			base = 50
			modifier = {
				scope:friendship_target = {
					number_of_traits_in_common = {
						target = scope:heir
						value >= 2
					}
				}
				add = 50
			}
			modifier = {
				scope:friendship_target = {
					number_of_traits_in_common = {
						target = scope:heir
						value >= 4
					}
				}
				add = 100
			}
			modifier = {
				scope:friendship_target = {
					number_of_traits_in_common = {
						target = scope:heir
						value >= 6
					}
				}
				add = 100
			}
		}
	}
	#Let's hang - extra bonus for blood brother/friends/family/culture
	option = {
		name = mpo_decisions_events.0021.e
		flavor = mpo_decisions_events.0021.e.flavor
		add_character_flag = {
			flag = heir_friend_kinship
			days = 40
		}
		if = {
			limit = {
				scope:friendship_target = {
					is_ai = yes
				}
			}
			duel = {
				skill = diplomacy
				value = medium_skill_rating
				#Successful - they're friends!
				35 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = 0.75
						min = -34
					}
					modifier = {
						add = mpo_friendship_setup_positive_modifiers_value
					}
					modifier = {
						has_relation_blood_brother = scope:friendship_target
						add = 120
					}
					modifier = {
						OR = {
							has_relation_best_friend = scope:friendship_target
							has_relation_soulmate = scope:friendship_target
						}
						add = 80
					}
					modifier = {
						OR = {
							has_relation_friend = scope:friendship_target
							has_relation_lover = scope:friendship_target
						}
						add = 60
					}
					modifier = {
						AND = {
							exists = house
							exists = scope:friendship_target.house
							house = scope:friendship_target.house
						}
						add = 60
					}
					modifier = {
						OR = {
							culture = {
								this = scope:friendship_target.culture
							}
							culture = {
								cultural_acceptance = {
									target = scope:friendship_target.culture
									value >= 80
								}
							}
						}
						add = 30
					}
					
					desc = mpo_decisions_events.0021.e.success
					mpo_decisions_events_0021_positive_outcome_effect = yes
					show_as_tooltip = {
						scope:heir = {
							add_piety = minor_piety_gain
						}
					}
				}
				# Fail - they're pretty meh about each other
				65 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = -0.75
						min = -64
					}
					modifier = {
						add = mpo_friendship_setup_negative_modifiers_value
					}

					desc = mpo_decisions_events.0021.e.fail
					mpo_decisions_events_0021_negative_outcome_effect = yes
				}
			}
		}
		else = {
			#Player response
			custom_tooltip = mpo_heir_friend_if_accept_tt
			mpo_decisions_events_0021_positive_outcome_effect = yes
			custom_tooltip = mpo_heir_friend_if_do_not_accept_tt
			custom_tooltip = friendship_setup_fail_tt
		}

		ai_chance = {
			base = 10
			modifier = {
				diplomacy >= medium_skill_rating
				diplomacy < very_high_skill_rating
				add = 40
			}
			modifier = {
				has_relation_blood_brother = scope:friendship_target
				add = 40
			}
			modifier = {
				OR = {
					has_relation_best_friend = scope:friendship_target
					has_relation_soulmate = scope:friendship_target
				}
				add = 20
			}
		}
	}
	#Gift fallback
	option = {
		trigger = {
			diplomacy < very_high_skill_rating
		}
		show_unlock_reason = no
		name = mpo_decisions_events.0021.f
		flavor = mpo_decisions_events.0021.f.flavor
		
		add_character_flag = {
			flag = heir_friend_gift
			days = 40
		}
		show_as_tooltip = {
			pay_short_term_gold = {
				target = scope:friendship_target
				gold = medium_gold_value
			}
			pay_short_term_gold = {
				target = scope:heir
				gold = minor_gold_value
			}
		}
		mpo_decisions_events_0021_positive_outcome_effect = yes
		stress_impact = {
			greedy = miniscule_stress_impact_gain
		}
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_greed = -1
			}
			modifier = {
				gold >= monumental_gold_value
				add = 300
			}
			modifier = {
				short_term_gold < major_gold_value
				factor = 0
			}
		}
	}
	after = {
		if = {
			limit = {
				scope:friendship_target = {
					is_ai = yes
				}
			}
			trigger_event = {
				id = mpo_decisions_events.0023
				days = 1
			}
		}
		else = {
			scope:friendship_target = {
				trigger_event = {
					id = mpo_decisions_events.0022
					days = 1
				}
			}
		}
	}
}

mpo_decisions_events.0022 = {
	type = character_event
	title = mpo_decisions_events.0022.t
	desc = {
		desc = mpo_decisions_events.0022.desc_intro
		triggered_desc = {
			trigger = {
				scope:root_scope = {
					has_character_flag = heir_friend_personal_charm
				}
			}
			desc = mpo_decisions_events.0022.desc_personal_charm
		}
		triggered_desc = {
			trigger = {
				scope:root_scope = {
					has_character_flag = heir_friend_lifestyle_trait
				}
			}
			desc = mpo_decisions_events.0022.desc_lifestyle
		}
		triggered_desc = {
			trigger = {
				scope:root_scope = {
					has_character_flag = heir_friend_sports
				}
			}
			desc = mpo_decisions_events.0022.desc_sports
		}
		triggered_desc = {
			trigger = {
				scope:root_scope = {
					has_character_flag = heir_friend_shared_traits
				}
			}
			desc = mpo_decisions_events.0022.desc_shared_traits
		}
		triggered_desc = {
			trigger = {
				scope:root_scope = {
					has_character_flag = heir_friend_kinship
				}
			}
			desc = mpo_decisions_events.0022.desc_kinship
		}
		triggered_desc = {
			trigger = {
				scope:root_scope = {
					has_character_flag = heir_friend_gift
				}
			}
			desc = mpo_decisions_events.0022.desc_gift
		}
		desc = mpo_decisions_events.0022.desc_outro
	}
	theme = nomads
	override_background = {
		reference = throne_room
	}
	left_portrait = {
		character = scope:root_scope
		animation = interested
	}
	right_portrait = {
		character = scope:heir
		triggered_animation = {
			trigger = {
				root = {
					OR = {
						has_character_flag = heir_friend_lifestyle_trait
						has_character_flag = heir_friend_sports
					}
					NOT = {
						has_character_flag = heir_friend_failed
					}
				}
				OR = {
					scope:lifestyle_trait = trait:lifestyle_hunter
					AND = {
						scope:friendship_target = {
							has_trait = tourney_participant
							has_trait_xp = {
								trait = tourney_participant
								track = bow
								value >= 50
							}
						}
						scope:heir = {
							has_trait = tourney_participant
							has_trait_xp = {
								trait = tourney_participant
								track = bow
								value >= 50
							}
						}
					}
				}
				
			}
			animation = hunting_shortbow_aim_arrow_default
		}
		triggered_animation = {
			trigger = {
				root = {
					OR = {
						has_character_flag = heir_friend_lifestyle_trait
						has_character_flag = heir_friend_sports
					}
					NOT = {
						has_character_flag = heir_friend_failed
					}
				}
				OR = {
					scope:lifestyle_trait = trait:lifestyle_blademaster
					AND = {
						scope:friendship_target = {
							has_trait = tourney_participant
							has_trait_xp = {
								trait = tourney_participant
								track = foot
								value >= 50
							}
						}
						scope:heir = {
							has_trait = tourney_participant
							has_trait_xp = {
								trait = tourney_participant
								track = foot
								value >= 50
							}
						}
					}
				}
				
			}
			animation = sword_coup_degrace
		}
		triggered_animation = {
			trigger = {
				root = {
					OR = {
						has_character_flag = heir_friend_lifestyle_trait
						has_character_flag = heir_friend_sports
					}
					NOT = {
						has_character_flag = heir_friend_failed
					}
				}
				OR = {
					scope:lifestyle_trait = trait:lifestyle_traveler
					AND = {
						scope:friendship_target = {
							has_trait = tourney_participant
							has_trait_xp = {
								trait = tourney_participant
								track = horse
								value >= 50
							}
						}
						scope:heir = {
							has_trait = tourney_participant
							has_trait_xp = {
								trait = tourney_participant
								track = horse
								value >= 50
							}
						}
					}
				}
				
			}
			animation = laugh
		}
		triggered_animation = {
			trigger = {
				root = {
					has_character_flag = heir_friend_lifestyle_trait
					NOT = {
						has_character_flag = heir_friend_failed
					}
				}
				OR = {
					scope:lifestyle_trait = trait:lifestyle_physician
					scope:lifestyle_trait = trait:lifestyle_herbalist
				}
			}
			animation = physician
		}

		triggered_animation = {
			trigger = {
				root = {
					has_character_flag = heir_friend_lifestyle_trait
					NOT = {
						has_character_flag = heir_friend_failed
					}
				}
				OR = {
					scope:lifestyle_trait = trait:lifestyle_reveler
					scope:lifestyle_trait = trait:drunkard
				}
			}
			animation = wedding_drunk
		}
		triggered_animation = {
			trigger = {
				root = {
					has_character_flag = heir_friend_lifestyle_trait
					NOT = {
						has_character_flag = heir_friend_failed
					}
				}
				scope:lifestyle_trait = trait:hashishiyah
			}
			animation = manic
		}
		triggered_animation = {
			trigger = {
				root = {
					has_character_flag = heir_friend_lifestyle_trait
					NOT = {
						has_character_flag = heir_friend_failed
					}
				}
				scope:lifestyle_trait = trait:lifestyle_gardener
			}
			animation = holding_staff
		}

		triggered_animation = {
			trigger = {
				root = {
					has_character_flag = heir_friend_personal_charm
					NOT = {
						has_character_flag = heir_friend_failed
					}
				}
			}
			animation = laugh
		}
		triggered_animation = {
			trigger = {
				root = {
					NOR = {
						has_character_flag = heir_friend_lifestyle_trait
						has_character_flag = heir_friend_failed
					}
				}
			}
			animation = storyteller
		}
	}
	lower_right_portrait = scope:root_scope

	immediate = {
		if = {
			limit = {
				has_character_flag = heir_friend_gift
			}
			show_as_tooltip = {
				scope:root_scope = {
					pay_short_term_gold = {
						target = scope:friendship_target
						gold = medium_gold_value
					}
				}
			}
		}
	}
	#I want this blood brother
	option = {
		trigger = {
			is_allied_to = scope:root_scope
			NOT = {
				has_relation_blood_brother = scope:friendship_target
			}
		}
		name = mpo_decisions_events.0022.a
		show_as_tooltip = {
			set_relation_friend = {
				target = scope:heir
				reason = friend_introduced_heir
			}
			set_relation_blood_brother = {
				target = scope:heir
				reason = blood_brother_introduced_heir
			}
		}
		scope:root_scope = {
			add_character_flag = {
				flag = player_heir_friend_blood_brother
				days = 40
			}
		}
		if = {
			limit = {
				scope:root_scope = {
					highest_held_title_tier > root.highest_held_title_tier
				}
			}
			add_prestige = medium_prestige_gain
		}
		else_if = {
			limit = {
				scope:root_scope = {
					highest_held_title_tier = root.highest_held_title_tier
				}
			}
			add_prestige = minor_prestige_gain
		}
		reverse_add_opinion = {
			modifier = grateful_opinion
			target = scope:root_scope
			opinion = 10
		}
		stress_impact = {
			paranoid = medium_stress_impact_gain
			callous = minor_stress_impact_gain
			arrogant = medium_stress_impact_gain
			fickle = medium_stress_impact_gain
		}
	}

	#I will even be obedient!
	option = {
		trigger = {
			is_ai = yes
			is_vassal_of = scope:root_scope
			NOR = {
				is_obedient_to = scope:root_scope
				has_trait = disloyal
			}
		}
		name = mpo_decisions_events.0022.b
		show_as_tooltip = {
			set_relation_friend = {
				target = scope:heir
				reason = friend_introduced_heir
			}
		}
		scope:root_scope = {
			add_character_flag = {
				flag = player_heir_friend_obedient
				days = 40
			}
		}
		reverse_add_opinion = {
			modifier = grateful_opinion
			target = scope:root_scope
			opinion = 40
		}
		random = {
			chance = 50
			add_trait = loyal
		}
		stress_impact = {
			humble = minor_stress_impact_loss
			trusting = minor_stress_impact_loss
			content = minor_stress_impact_loss
			paranoid = medium_stress_impact_gain
			arrogant = major_stress_impact_gain
			ambitious = major_stress_impact_gain
			arbitrary = major_stress_impact_gain
		}
	}

	#We can be friends
	option = {
		name = mpo_decisions_events.0022.c
		show_as_tooltip = {
			set_relation_friend = {
				target = scope:heir
				reason = friend_introduced_heir
			}
		}
		if = {
			limit = {
				highest_held_title_tier > scope:root_scope.highest_held_title_tier
			}
			add_prestige = minor_prestige_loss
		}
		reverse_add_opinion = {
			modifier = grateful_opinion
			target = scope:root_scope
			opinion = 20
		}
		stress_impact = {
			paranoid = minor_stress_impact_gain
			callous = minor_stress_impact_gain
			arrogant = minor_stress_impact_gain
		}
	}

	#I don't want this friend
	option = {
		name = mpo_decisions_events.0022.d
		scope:root_scope = {
			add_character_flag = {
				flag = heir_friend_failed
				days = 40
			}
		}
		if = {
			limit = {
				scope:root_scope = {
					has_character_flag = heir_friend_lifestyle_trait
				}
			}
			mpo_target_lifestyle_xp_gain_effect = yes
		}
		else_if = {
			limit = {
				scope:root_scope = {
					has_character_flag = heir_friend_sports
				}
			}
			mpo_target_hastiluder_xp_gain_effect = yes
		}
		else_if = {
			limit = {
				scope:root_scope = {
					has_character_flag = heir_friend_personal_charm
				}
			}
			add_diplomacy_lifestyle_xp = medium_lifestyle_xp
		}
		else = {
			add_stress = medium_stress_impact_loss
		}
		stress_impact = {
			trusting = minor_stress_impact_gain
			compassionate = minor_stress_impact_gain
		}
	}
	after = {
		scope:root_scope = {
			trigger_event = mpo_decisions_events.0023
		}
	}
}

mpo_decisions_events.0023 = {
	type = character_event
	title = mpo_decisions_events.0023.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					has_character_flag = heir_friend_failed
				}
				desc = mpo_decisions_events.0023.desc_fail
			}
			desc = mpo_decisions_events.0023.desc
		}
		triggered_desc = {
			trigger = {
				exists = scope:accidental_friend
			}
			desc = mpo_decisions_events.0023.desc_accidental_friend
		}
	}
	theme = nomads
	override_background = { 
		reference = relaxing_room
	}
	left_portrait = {
		character = scope:heir
		triggered_animation = {
			trigger = {
				root = {
					has_character_flag = heir_friend_failed
				}
			}
			animation = personality_content
		}
		triggered_animation = {
			trigger = {
				root = {
					OR = {
						has_character_flag = heir_friend_lifestyle_trait
						has_character_flag = heir_friend_sports
					}
					NOT = {
						has_character_flag = heir_friend_failed
					}
				}
				OR = {
					scope:lifestyle_trait = trait:lifestyle_hunter
					AND = {
						scope:friendship_target = {
							has_trait = tourney_participant
							has_trait_xp = {
								trait = tourney_participant
								track = bow
								value >= 50
							}
						}
						scope:heir = {
							has_trait = tourney_participant
							has_trait_xp = {
								trait = tourney_participant
								track = bow
								value >= 50
							}
						}
					}
				}
				
			}
			animation = hunting_shortbow_aim_arrow_default
		}
		triggered_animation = {
			trigger = {
				root = {
					OR = {
						has_character_flag = heir_friend_lifestyle_trait
						has_character_flag = heir_friend_sports
					}
					NOT = {
						has_character_flag = heir_friend_failed
					}
				}
				OR = {
					scope:lifestyle_trait = trait:lifestyle_blademaster
					AND = {
						scope:friendship_target = {
							has_trait = tourney_participant
							has_trait_xp = {
								trait = tourney_participant
								track = foot
								value >= 50
							}
						}
						scope:heir = {
							has_trait = tourney_participant
							has_trait_xp = {
								trait = tourney_participant
								track = foot
								value >= 50
							}
						}
					}
				}
				
			}
			animation = sword_coup_degrace
		}
		triggered_animation = {
			trigger = {
				root = {
					OR = {
						has_character_flag = heir_friend_lifestyle_trait
						has_character_flag = heir_friend_sports
					}
					NOT = {
						has_character_flag = heir_friend_failed
					}
				}
				OR = {
					scope:lifestyle_trait = trait:lifestyle_traveler
					AND = {
						scope:friendship_target = {
							has_trait = tourney_participant
							has_trait_xp = {
								trait = tourney_participant
								track = horse
								value >= 50
							}
						}
						scope:heir = {
							has_trait = tourney_participant
							has_trait_xp = {
								trait = tourney_participant
								track = horse
								value >= 50
							}
						}
					}
				}
				
			}
			animation = laugh
		}
		triggered_animation = {
			trigger = {
				root = {
					has_character_flag = heir_friend_lifestyle_trait
					NOT = {
						has_character_flag = heir_friend_failed
					}
				}
				OR = {
					scope:lifestyle_trait = trait:lifestyle_physician
					scope:lifestyle_trait = trait:lifestyle_herbalist
				}
			}
			animation = physician
		}

		triggered_animation = {
			trigger = {
				root = {
					has_character_flag = heir_friend_lifestyle_trait
					NOT = {
						has_character_flag = heir_friend_failed
					}
				}
				OR = {
					scope:lifestyle_trait = trait:lifestyle_reveler
					scope:lifestyle_trait = trait:drunkard
				}
			}
			animation = wedding_drunk
		}
		triggered_animation = {
			trigger = {
				root = {
					has_character_flag = heir_friend_lifestyle_trait
					NOT = {
						has_character_flag = heir_friend_failed
					}
				}
				scope:lifestyle_trait = trait:hashishiyah
			}
			animation = manic
		}
		triggered_animation = {
			trigger = {
				root = {
					has_character_flag = heir_friend_lifestyle_trait
					NOT = {
						has_character_flag = heir_friend_failed
					}
				}
				scope:lifestyle_trait = trait:lifestyle_gardener
			}
			animation = holding_staff
		}

		triggered_animation = {
			trigger = {
				root = {
					has_character_flag = heir_friend_personal_charm
					NOT = {
						has_character_flag = heir_friend_failed
					}
				}
			}
			animation = laugh
		}
		triggered_animation = {
			trigger = {
				root = {
					NOR = {
						has_character_flag = heir_friend_lifestyle_trait
						has_character_flag = heir_friend_failed
					}
				}
			}
			animation = storyteller
		}
	}
	right_portrait = {
		character = scope:friendship_target
		triggered_animation ={
			trigger = {
				root = {
					has_character_flag = heir_friend_failed
				}
			}
			animation = interested
		}
		triggered_animation ={
			trigger = {
				root = {
					NOT = { has_character_flag = heir_friend_failed }
				}
			}
			animation = happiness
		}
	}
	lower_right_portrait = scope:accidental_friend
	immediate = {
		if = {
			limit = {
				has_character_flag = heir_friend_failed
			}
			#Random positive outcome
			custom_tooltip = heir_friend_will_not_become_friends_tt
			mpo_decisions_events_friend_fail_effect = yes
		}
		else = {
			play_music_cue = mx_cue_positive_effect
			scope:friendship_target = {
				#Random chance of AI
				random_list = {
					2 = {
						trigger = {
							is_ai = yes
							is_vassal_of = root
						}
						modifier = {
							opinion = {
								target = root
								value = 100
							}
							factor = 2
						}
						modifier = {
							OR = {
								has_relation_best_friend = root
								has_relation_soulmate = root
								has_relation_blood_brother = root
							}
							factor = 2
						}
						modifier = {
							obedience_target = root
							factor = 2
						}
						add_opinion = {
							modifier = obedience_opinion
							target = root
						}
					}
					1 = {
						trigger = {
							is_ai = yes
							is_allied_to = root
						}
						modifier = {
							opinion = {
								target = root
								value = 100
							}
							factor = 2
						}
						modifier = {
							OR = {
								has_relation_best_friend = root
								has_relation_soulmate = root
								has_relation_blood_brother = root
							}
							factor = 2
						}
						set_relation_blood_brother = {
							target = scope:heir
							reason = blood_brother_introduced_heir
						}
					}
					2 = {}
				}
				if = {
					limit = {
						has_character_flag = player_heir_friend_blood_brother
					}
					set_relation_blood_brother = {
						target = scope:heir
						reason = blood_brother_introduced_heir
					}
				}
				else_if = {
					limit = {
						has_character_flag = player_heir_friend_obedient
					}
					set_relation_friend = {
						target = scope:heir
						reason = friend_introduced_heir
					}
					add_opinion = {
						modifier = obedience_opinion
						target = root
					}
				}
				if = {
					limit = {
						NOT = {
							has_relation_blood_brother = scope:heir
						}
					}
					set_relation_friend = {
						target = scope:heir
						reason = friend_introduced_heir
					}
				}
			}
			switch = {
				trigger = has_character_flag
				
				heir_friend_personal_charm = {
					add_diplomacy_lifestyle_xp = minor_lifestyle_xp
				}
				heir_friend_lifestyle_trait = {
					mpo_heir_lifestyle_xp_gain_effect = yes
				}
				heir_friend_sports = {
					mpo_heir_hastiluder_xp_gain_effect = yes
				}
				heir_friend_shared_traits = {
					scope:heir = {
						add_stress = minor_stress_impact_loss
						add_prestige = minor_prestige_gain
					}
				}
				heir_friend_kinship = {
					scope:heir = {
						add_piety = minor_piety_gain
					}
				}
				heir_friend_gift = {
					pay_short_term_gold = {
						target = scope:friendship_target
						gold = medium_gold_value
					}
					pay_short_term_gold = {
						target = scope:heir
						gold = minor_gold_value
					}
				}
			}
		}
	}
	option = {
		name = {
			trigger = {
				NOT = {
					has_character_flag = heir_friend_failed
				}
			}
			text = mpo_decisions_events.0023.a
		}
		name = {
			trigger = {
				has_character_flag = heir_friend_failed
			}
			text = mpo_decisions_events.0023.a_fail
		}
	}
	after = {
		remove_character_flag = heir_friend_failed
		remove_character_flag = heir_friend_personal_charm
		remove_character_flag = heir_friend_sports
		remove_character_flag = heir_friend_gift
		remove_character_flag = heir_friend_kinship
		remove_character_flag = heir_friend_shared_traits
		remove_character_flag = heir_friend_lifestyle_trait
		remove_character_flag = player_heir_friend_blood_brother
		remove_character_flag = player_heir_friend_obedient
	}
}

mpo_decisions_events.0098 = {
	hidden = yes

	immediate = {
		send_interface_toast = {
			title = abused_paiza_authority
			left_icon = root
			right_icon = situation:the_great_steppe.situation_top_herd
			switch = {
				trigger = var:paiza_abuse_stance
				flag:indifferent = { custom_tooltip = mpo_paiza_abuse_counter_effect.indifferent }
				flag:angry = { custom_tooltip = mpo_paiza_abuse_counter_effect.khan_reaction_angry }
				flag:annoyed = { custom_tooltip = mpo_paiza_abuse_counter_effect.khan_reaction_annoyed }
			}
		}	
	}
}

mpo_decisions_events.0099 = {
	type = character_event
	title = mpo_decisions_events.0099.t
	desc = mpo_decisions_events.0099.desc
	theme = vassal

	override_background = { reference = mpo_tent_interior_mongol }
	left_portrait = {
		character = root
		animation = personality_rational
	}
	artifact = {
		target = scope:created_paiza
		position = lower_right_portrait
	}

	immediate = {
		mpo_create_paiza_artifact_effect = {
			PATRON = root
			GRANTEE = root
		}	 
	}

	option = {
		name = mpo_decisions_events.0099.a	
		custom_tooltip = mpo_establish_paiza_system_decision.grant_paiza_interaction_unlocked
        custom_tooltip = mpo_establish_paiza_system_decision.request_paiza_interaction_unlocked
        custom_tooltip = mpo_establish_paiza_system_decision.paiza_obedient
        custom_tooltip = mpo_establish_paiza_system_decision.call_for_merchants_decision_unlocked
        custom_tooltip = mpo_establish_paiza_system_decision.leverage_khan_authority_unlocked
        custom_tooltip = mpo_establish_paiza_system_decision.paiza_abuse_authority_unlocked 
	}
}

#scripted effect to make the merchant go



scripted_effect send_merchant_on_merry_voyage_effect = {
	set_variable = {
		name = merchant_employer
		value = prev
	}
	set_variable = {
		name = merchant_origin
		value = scope:merchant_origin
	}
	start_travel_plan = {
		destination = scope:merchant_origin.title_province
		return_trip = yes
		on_arrival_event = mpo_decisions_events.0102
		on_arrival_destinations = last
	}
}

scripted_effect send_merchant_on_first_voyage_effect = {
	set_variable = merchant_var
	set_variable = {
		name = merchant_employer
		value = prev
	}
	set_variable = {
		name = merchant_origin
		value = scope:merchant_origin
	}
	start_travel_plan = {
		destination = var:merchant_employer.location
		on_arrival_event = mpo_decisions_events.2140
		on_arrival_destinations = first
		return_trip = no
	}
	root = {
		prev = {
			save_scope_as = merchant
		}
		send_interface_toast = {
			type = event_toast_effect_good
			title = paiza_merchant_on_route_tt
			left_icon = scope:merchant_origin
			right_icon = scope:merchant
			custom_tooltip = paiza_merchant_on_route_tt_desc
		}
	}
}



mpo_decisions_events.2139 = {
	hidden = yes

	immediate = {
		mpo_find_suitable_merchant_effect = yes
		scope:paiza_merchant = {
			random_list = {
				1 = {
					add_trait = avaricious
					add_stewardship_skill = 6
					add_learning_skill = 4
					add_intrigue_skill = 2
					add_prowess_skill = 4
					add_diplomacy_skill = 2
				}
				1 = {
					add_trait = diplomat
					add_stewardship_skill = 4
					add_learning_skill = 5
					add_intrigue_skill = 8
					add_prowess_skill = 8
					add_diplomacy_skill = 6
				}
				1 = {
					add_trait = scholar
					add_stewardship_skill = 4
					add_learning_skill = 5
					add_intrigue_skill = 8
					add_prowess_skill = 8
					add_diplomacy_skill = 4
				}
			}
			add_trait = lifestyle_traveler
			add_gold = {
				value = root.tiny_gold_value
				multiply = 21.37
			}
			send_merchant_on_first_voyage_effect = yes
		}
	}
}


mpo_decisions_events.2140 = {
	hidden = yes

	immediate = {
		remove_variable = merchant_var # Used only to send the death notification message
		save_scope_as = paiza_merchant
		var:merchant_origin = {
			save_scope_as = merchant_origin
		}
		#teleport in case merchant_employer has migrated or something
		var:merchant_employer = {
			if = {
				limit = {
					is_alive = yes
				}
				if = {
					limit = {
						NOT = {
							root.location = location
						}
					}
					root = {
						set_location = { location = var:merchant_employer.location }
					}
				}
				if = {
					limit = {
						has_character_flag = established_paiza_system
					}
					trigger_event = mpo_decisions_events.0100
				}
				else = {
					trigger_event = mpo_decisions_events.2141
				}
			}	
		}
	}
}

mpo_decisions_events.2138 = {
	type = character_event
	theme = nomads

	title = mpo_decisions_events.2138.t
	desc = mpo_decisions_events.2138.desc

	override_background = { reference = mpo_camp_steppe }

	left_portrait = {
		character = root
		animation = personality_honorable
	}

	right_portrait = {
		character = scope:paiza_merchant
		animation = personality_greedy
	}

	immediate = {
		add_character_flag = {
			flag = had_herd_trade
			days = 7
		}
		domicile ?= {
			switch = {
				trigger = has_domicile_parameter
				nomad_yurt_paiza_herd_gain_lvl_1 = {
					root = {
						set_variable = {
							name = herd_trade_herd_value
							value = {	
								value = domicile.herd
								multiply = 0.1
							}
						}
						set_variable = {
							name = herd_trade_gold_value
							value = {	
								value = root.var:herd_trade_herd_value
								divide = 10
							}
						}
					}
				}
				nomad_yurt_paiza_herd_gain_lvl_2 = {
					root = {
						set_variable = {
							name = herd_trade_herd_value
							value = {	
								value = domicile.herd
								multiply = 0.15
							}
						}
						set_variable = {
							name = herd_trade_gold_value
							value = {	
								value = root.var:herd_trade_herd_value
								divide = 8
							}
						}
					}
				}
				nomad_yurt_paiza_herd_gain_lvl_3 = {
					root = {
						set_variable = {
							name = herd_trade_herd_value
							value = {	
								value = domicile.herd
								multiply = 0.2
							}
						}
						set_variable = {
							name = herd_trade_gold_value
							value = {	
								value = root.var:herd_trade_herd_value
								divide = 6
							}
						}
					}
				}
			}
		}
	}

	option = {
		name = mpo_decisions_events.2138.a
		domicile ?= {
			switch = {
				trigger = has_domicile_parameter
				nomad_yurt_paiza_herd_gain_lvl_1 = { root = { custom_tooltip = domicile_building_parameter_nomad_merchant_herd_gold_exchange_lvl_1 } }
				nomad_yurt_paiza_herd_gain_lvl_2 = { root = { custom_tooltip = domicile_building_parameter_nomad_merchant_herd_gold_exchange_lvl_2 } }
				nomad_yurt_paiza_herd_gain_lvl_3 = { root = { custom_tooltip = domicile_building_parameter_nomad_merchant_herd_gold_exchange_lvl_3 } }
			}
		}
		hidden_effect = {
			scope:paiza_merchant = {
				add_gold = root.var:herd_trade_gold_value
			}
		}
		scope:paiza_merchant = {
			pay_short_term_gold = {
				target = root
				gold = root.var:herd_trade_gold_value
			}
		}		
		domicile ?= {
			change_herd = {
				value = root.var:herd_trade_herd_value
				multiply = -1
			}
		}
	}

	option = {
		name = mpo_decisions_events.2138.c
		custom_tooltip = mpo_decisions_events.2138.c.desc
	}

	after = {
		if = {
			limit = {
				has_character_flag = smol_herd_trade
			}
			trigger_event = mpo_decisions_events.2141
			remove_character_flag = smol_herd_trade
		}
		else = {
			trigger_event = mpo_decisions_events.0100
		}
		remove_variable = herd_trade_herd_value
		remove_variable = herd_trade_gold_value
	}

}

mpo_decisions_events.2141 = { #mpo_call_for_merchants_smol_decision initial event
	type = character_event
	theme = nomads

	title = mpo_decisions_events.2141.t
	desc = mpo_decisions_events.2141.desc

	override_background = { reference = mpo_campfire_steppe }

	left_portrait = {
		character = root
		animation = personality_honorable
	}

	right_portrait = {
		character = scope:paiza_merchant
		animation = throne_room_bow_3
	}

	trigger = {
		is_available_adult = yes
		scope:paiza_merchant.location = root.location
	}

	on_trigger_fail = {
		scope:paiza_merchant = {
			set_location = { location = root.location }
		}
		trigger_event = {
			id = mpo_decisions_events.2141
			months = { 2 4 }
		}
	}

	option = { #ask for an artifact material
		name = mpo_decisions_events.2141.b

		pay_short_term_gold = {
			target = scope:paiza_merchant
			gold = 400
		}

		scope:paiza_merchant = {
			set_variable = {
				name = requested_merchant_goods
				value = flag:artifact_material
			}
			set_variable = {
				name = paiza_gold_invested
				value = 400
			}
			send_merchant_on_merry_voyage_effect = yes
		}

		custom_tooltip = mpo_decisions_events.2141.upon_merchant_return
		show_as_tooltip = {
			add_character_modifier = {
				modifier = mpo_artifact_material_modifier
			}
			mpo_yurts_paiza_bonuses_tooltip_effect = yes
		}			
		ai_chance = {
			base = 0
		}
	}

	option = { #ask for better armor for ur maa
		name = mpo_decisions_events.2141.c

		show_as_unavailable = {
			gold <= 800
		}

		pay_short_term_gold = {
			target = scope:paiza_merchant
			gold = 800
		}

		scope:paiza_merchant = {
			set_variable = {
				name = requested_merchant_goods
				value = flag:armaments
			}
			set_variable = {
				name = paiza_gold_invested
				value = 800
			}
			send_merchant_on_merry_voyage_effect = yes
		}

		custom_tooltip = mpo_decisions_events.2141.upon_merchant_return
		show_as_tooltip = {
			mpo_paiza_improve_maa_smol_effect = yes
			mpo_yurts_paiza_bonuses_tooltip_effect = yes
		}
	
		ai_chance = { #most safe option for ai 
			base = 100
		}
	}

	option = {
		name = mpo_decisions_events.2141.d
		custom_tooltip = mpo_decisions_events.2141.d.unlocked
		trigger = {
			NOT = {
				has_character_flag = had_herd_trade
			}
			domicile ?= {
				has_domicile_building_or_higher = herd_trade_yurt_01
			}
		}
		add_character_flag = smol_herd_trade
		trigger_event = mpo_decisions_events.2138

		ai_chance = {
			base = 200
		}
	}	

	option = { #actually, give me your gold and get lost
		name = mpo_decisions_events.0100.e
		scope:paiza_merchant = {
			pay_short_term_gold = {
				target = root
				gold = scope:paiza_merchant.gold
			}
			death = {
				killer = root
				death_reason = death_execution
			}
		}
		add_character_modifier = {
			modifier = mpo_paiza_robbed_merchants
			years = { 18 22 }
		}
		custom_tooltip = mpo_decisions_events.0100.e.warning

		ai_chance = {
			base = 50
		}
	}
}

mpo_decisions_events.0100 = { #mpo_call_for_merchants_decision initial event
	type = character_event
	theme = nomads

	title = mpo_decisions_events.0100.t
	desc = mpo_decisions_events.0100.desc

	override_background = { reference = mpo_campfire_steppe }

	left_portrait = {
		character = root
		animation = personality_honorable
	}

	right_portrait = {
		character = scope:paiza_merchant
		animation = throne_room_bow_3
	}

	trigger = {
		is_available_adult = yes
		scope:paiza_merchant.location = root.location
	}

	on_trigger_fail = {
		scope:paiza_merchant = {
			set_location = { location = root.location }
		}
		trigger_event = {
			id = mpo_decisions_events.0100
			months = { 2 4 }
		}
	}

	option = { #give him paiza, ask for innovation progress
		name = mpo_decisions_events.0100.a

		show_as_unavailable = {
			NOT = {
				domicile ?= {
					has_domicile_building_or_higher = innovation_yurt_01
				}
			}
			gold <= 2400
		}
		mpo_create_paiza_artifact_effect = {
			PATRON = root
			GRANTEE = scope:paiza_merchant
		}
		pay_short_term_gold = {
			target = scope:paiza_merchant
			gold = 2400
		}
		scope:paiza_merchant = {
			set_variable = {
				name = paiza_gold_invested
				value = 2400
			}
			set_variable = {
				name = requested_merchant_goods
				value = flag:innovation
			}
			send_merchant_on_merry_voyage_effect = yes
		}
		custom_tooltip = mpo_decisions_events.0100.upon_merchant_return
		show_as_tooltip = {
			domicile ?= {
				mpo_paiza_innovation_reward_effect = yes
			}
			custom_tooltip = paiza_merchant_skill_gold_percent
			mpo_yurts_paiza_bonuses_tooltip_effect = yes							
		}

		ai_chance = {
			base = 0
		}
	}

	option = { #give him paiza, ask for an artifact material
		name = mpo_decisions_events.0100.b

		mpo_create_paiza_artifact_effect = {
			PATRON = root
			GRANTEE = scope:paiza_merchant
		}

		pay_short_term_gold = {
			target = scope:paiza_merchant
			gold = 800
		}
		
		scope:paiza_merchant = {
			set_variable = {
				name = requested_merchant_goods
				value = flag:artifact_material
			}
			set_variable = {
				name = paiza_gold_invested
				value = 800
			}
			send_merchant_on_merry_voyage_effect = yes
		}
		custom_tooltip = mpo_decisions_events.0100.upon_merchant_return
		show_as_tooltip = {
			add_character_modifier = {
				modifier = mpo_artifact_material_modifier
			}
			custom_tooltip = paiza_merchant_skill_gold_percent
			mpo_yurts_paiza_bonuses_tooltip_effect = yes		
		}

		ai_chance = {
			base = 0
		}
	}

	option = { #ask for better armor for ur maa
		name = mpo_decisions_events.0100.c

		show_as_unavailable = {
			gold <= 1600
		}
		mpo_create_paiza_artifact_effect = {
			PATRON = root
			GRANTEE = scope:paiza_merchant
		}
		pay_short_term_gold = {
			target = scope:paiza_merchant
			gold = 1600
		}

		scope:paiza_merchant = {
			set_variable = {
				name = requested_merchant_goods
				value = flag:armaments
			}
			set_variable = {
				name = paiza_gold_invested
				value = 1600
			}
			send_merchant_on_merry_voyage_effect = yes
		}
		custom_tooltip = mpo_decisions_events.0100.upon_merchant_return
		show_as_tooltip = {
			mpo_paiza_improve_maa_effect = yes
			custom_tooltip = paiza_merchant_skill_gold_percent
			mpo_yurts_paiza_bonuses_tooltip_effect = yes
		}

		ai_chance = { #most safe option for ai 
			base = 100
		}
	}

	option = {
		name = mpo_decisions_events.0100.d
		custom_tooltip = mpo_decisions_events.0100.d.unlocked
		trigger = {
			NOT = {
				has_character_flag = had_herd_trade
			}
			domicile ?= {
				has_domicile_building_or_higher = herd_trade_yurt_01
			}
		}
		trigger_event = mpo_decisions_events.2138

		ai_chance = {
			base = 200
		}
	}

	option = { #actually, give me your gold and get lost
		name = mpo_decisions_events.0100.e
		scope:paiza_merchant = {
			pay_short_term_gold = {
				target = root
				gold = scope:paiza_merchant.gold
			}
			death = {
				killer = root
				death_reason = death_execution
			}
		}
		add_character_modifier = {
			modifier = mpo_paiza_robbed_merchants
			years = { 12 16 }
		}
		custom_tooltip = mpo_decisions_events.0100.e.warning

		ai_chance = {
			base = 50
		}
	}
}

mpo_decisions_events.0101 = { #the merchant is back
	type = character_event
	theme = nomads

	title = mpo_decisions_events.0101.t
	desc = mpo_decisions_events.0101.desc

	override_background = { reference = mpo_campfire_steppe }

	left_portrait = {
		character = root
		animation = ecstasy
	}

	right_portrait = {
		character = scope:paiza_merchant
		animation = drink
	}

	trigger = {
		is_available_adult = yes
		scope:paiza_merchant.location = root.location
	}

	on_trigger_fail = {
		scope:paiza_merchant = {
			set_location = { location = root.location }
		}
		trigger_event = {
			id = mpo_decisions_events.0101
			months = { 2 4 }
		}
	}

	immediate = {
		mpo_paiza_deal_grade_effect = yes
		if = {
			limit = {
				domicile ?= {
					OR = {
						has_domicile_building_or_higher = fertility_trade_yurt_01
						has_domicile_building_or_higher = herd_trade_yurt_01
						has_domicile_building_or_higher = knight_trade_yurt_01
						has_domicile_building_or_higher = merchant_yurt_01
						has_domicile_building_or_higher = char_trade_yurt_01
					}
				}
			}
			domicile ?= {
				if = {
					limit = {
						has_domicile_building_or_higher = fertility_trade_yurt_01
					}
					switch = {
						trigger = has_domicile_parameter
						nomad_yurt_paiza_fertility_gain_lvl_1 = {
							root = {
								every_held_county = {
									limit = {
										uses_county_fertility = yes
									}
									add_county_modifier = {
										modifier = paiza_fertility_modifier_1
										years = 2
									}
								}
							}
						}
						nomad_yurt_paiza_fertility_gain_lvl_2 = {
							root = {
								every_held_county = {
									limit = {
										uses_county_fertility = yes
									}
									add_county_modifier = {
										modifier = paiza_fertility_modifier_2
										years = 4
									}
								}
							}
						}
						nomad_yurt_paiza_fertility_gain_lvl_3 = {
							root = {
								every_held_county = {
									limit = {
										uses_county_fertility = yes
									}
									add_county_modifier = {
										modifier = paiza_fertility_modifier_3
										years = 6
									}
								}
							}
						}
					}
				}
				if = {
					limit = {
						has_domicile_building_or_higher = herd_trade_yurt_01
					}
					switch = {
						trigger = has_domicile_parameter
						nomad_yurt_paiza_herd_gain_lvl_1= {
							change_herd = {
								value = root.var:trade_gold_value
								multiply = 0.05
							}
						}
						nomad_yurt_paiza_herd_gain_lvl_2 = {
							change_herd = {
								value = root.var:trade_gold_value
								multiply = 0.05
							}
						}
						nomad_yurt_paiza_herd_gain_lvl_3 = {
							change_herd = {
								value = root.var:trade_gold_value
								multiply = 0.2
							}
						}
					}
				}
				if = {
					limit = {
						has_domicile_building_or_higher = knight_trade_yurt_01
					}
					switch = {
						trigger = has_domicile_parameter
						nomad_yurt_paiza_maa_gain_lvl_1 = {
							root = {
								spawn_army = {
									name = paiza_troops
									men_at_arms = {
										type = accolade_maa_archers
										stacks = 1
									}
									location = root.location
									origin = scope:merchant_origin
									inheritable = yes
								}
							}
						}
						nomad_yurt_paiza_maa_gain_lvl_2 = {
							root = {
								spawn_army = {
									name = paiza_troops
									men_at_arms = {
										type = accolade_maa_archers
										stacks = 4
									}
									location = root.location
									origin = scope:merchant_origin
									inheritable = yes
								}
							}
						}
						nomad_yurt_paiza_maa_gain_lvl_3 = {
							root = {
								spawn_army = {
									name = paiza_troops
									men_at_arms = {
										type = accolade_maa_archers
										stacks = 4
									}
									men_at_arms = {
										type = accolade_maa_vanguards
										stacks = 4
									}
									location = root.location
									origin = scope:merchant_origin
									inheritable = yes
								}
							}
						}
					}
				}
				if = {
					limit = {
						has_domicile_building_or_higher = char_trade_yurt_01
					}
					
					switch = {
						trigger = has_domicile_parameter
						nomad_yurt_paiza_char_gain_lvl_1 = {
							root = {
								hidden_effect = {
									create_character = {
										location = root.location
										culture = scope:merchant_origin.county.culture
										faith = scope:merchant_origin.county.faith
										gender_female_chance = 50
										template = peasant_character
										save_scope_as = yurt_merchant_char
									}
									scope:yurt_merchant_char = {
										add_trait = lifestyle_traveler
									}
									add_courtier = scope:yurt_merchant_char
								}
								
							}
						}
						nomad_yurt_paiza_char_gain_lvl_2 = {
							root = {
								hidden_effect = {
									create_character = {
										location = root.location
										culture = scope:merchant_origin.county.culture
										faith = scope:merchant_origin.county.faith
										gender_female_chance = 50
										template = merchant_template
										save_scope_as = yurt_merchant_char
									}
									scope:yurt_merchant_char = {
										add_trait = lifestyle_traveler
									}
									add_courtier = scope:yurt_merchant_char
								}
							}
						}
						nomad_yurt_paiza_char_gain_lvl_3 = {
							root = {
								hidden_effect = {
									create_character = {
										location = root.location
										culture = scope:merchant_origin.county.culture
										faith = scope:merchant_origin.county.faith
										gender_female_chance = 50
										template = merchant_template
										save_scope_as = yurt_merchant_char
									}
									scope:yurt_merchant_char = {
										add_random_skill_point_effect = yes
										add_random_skill_point_effect = yes
										add_random_skill_point_effect = yes
										add_random_skill_point_effect = yes
										add_random_skill_point_effect = yes
										add_random_skill_point_effect = yes
										random_list = {
											1 = { add_trait = avaricious }
											1 = { add_trait = diplomat }
											1 = { add_trait = overseer }
										}
										add_trait = lifestyle_traveler
									}
									add_courtier = scope:yurt_merchant_char
								}
							}
						}
					}
				}
			}
		}
	}


	option = { #rejoice!
		name = mpo_decisions_events.0101.a
		ai_chance = {
			base = 10
		}
	}

	option = {
		name = mpo_decisions_events.0101.b
		custom_tooltip = mpo_decisions_events.0101.b.desc
		trigger_event = mpo_decisions_events.2137

		ai_chance = {
			base = 0
		}
	}

	after = {
		if = {
			limit = {
				domicile = { has_domicile_building_or_higher = char_trade_yurt_01 }
			}
			show_as_tooltip = { add_courtier = scope:yurt_merchant_char }
		}
		switch = {
			trigger = scope:merchant_goods
			flag:artifact_material = {
				add_character_modifier = {
					modifier = mpo_artifact_material_modifier
					years = 4
				}
			}
			flag:innovation = {
				domicile ?= {
					mpo_paiza_innovation_reward_effect = yes
				}
			}
			flag:armaments = {
				if = {
					limit = {
						scope:paiza_merchant = {
							has_character_flag = established_paiza_system
						}
					}
					mpo_paiza_improve_maa_smol_effect = yes
				}
				else = {
					mpo_paiza_improve_maa_effect = yes
				}
			}
		}
		
		scope:paiza_merchant = {
			hidden_effect = {
				add_gold = root.var:trade_gold_value
			}
			pay_short_term_gold = {
				target = root
				gold = root.var:trade_gold_value
			}
		}	
	}
}

mpo_decisions_events.2137 = {
	type = character_event
	theme = nomads

	title = mpo_decisions_events.0101.t
	desc = {
		desc = mpo_decisions_events.2137.desc_intro
		first_valid = {
			triggered_desc = {
				trigger = { scope:first_story = flag:desc_1 }
				desc = marco_polo_quote_desc_1
			}
			triggered_desc = {
				trigger = { scope:first_story = flag:desc_2 }
				desc = marco_polo_quote_desc_2
			}
			triggered_desc = {
				trigger = { scope:first_story = flag:desc_3 }
				desc = marco_polo_quote_desc_3
			}
			triggered_desc = {
				trigger = { scope:first_story = flag:desc_4 }
				desc = marco_polo_quote_desc_4
			}
			triggered_desc = {
				trigger = { scope:first_story = flag:desc_5 }
				desc = marco_polo_quote_desc_5
			}
			triggered_desc = {
				trigger = { scope:first_story = flag:desc_6 }
				desc = marco_polo_quote_desc_6
			}
			triggered_desc = {
				trigger = { scope:first_story = flag:desc_7 }
				desc = marco_polo_quote_desc_7
			}
		}
		desc = mpo_decisions_events.2137.desc_interludium
		first_valid = {
			triggered_desc = {
				trigger = { scope:second_story = flag:desc_1 }
				desc = marco_polo_quote_desc_1
			}
			triggered_desc = {
				trigger = { scope:second_story = flag:desc_2 }
				desc = marco_polo_quote_desc_2
			}
			triggered_desc = {
				trigger = { scope:second_story = flag:desc_3 }
				desc = marco_polo_quote_desc_3
			}
			triggered_desc = {
				trigger = { scope:second_story = flag:desc_4 }
				desc = marco_polo_quote_desc_4
			}
			triggered_desc = {
				trigger = { scope:second_story = flag:desc_5 }
				desc = marco_polo_quote_desc_5
			}
			triggered_desc = {
				trigger = { scope:second_story = flag:desc_6 }
				desc = marco_polo_quote_desc_6
			}
			triggered_desc = {
				trigger = { scope:second_story = flag:desc_7 }
				desc = marco_polo_quote_desc_7
			}
		}
	}

	override_background = { reference = mpo_campfire_steppe }

	left_portrait = {
		character = root
		animation = disbelief
	}

	right_portrait = {
		character = scope:paiza_merchant
		animation = admiration
	}

	immediate = {
		random_list = { #since the event can happen twice, we are rolling for the first and second paragraph in such way to make sure player sees unique content
			1 = {
				trigger = { NOT = { scope:first_story ?= flag:desc_1 scope:first_story ?= flag:desc_1 } }
				save_scope_value_as = {
					name = first_story
					value = flag:desc_1
				}
			}
			1 = {
				trigger = { NOT = { scope:first_story ?= flag:desc_2 scope:first_story ?= flag:desc_2 } }
				save_scope_value_as = {
					name = first_story
					value = flag:desc_2
				}
			}
			1 = {
				trigger = { NOT = { scope:first_story ?= flag:desc_3 scope:first_story ?= flag:desc_3 } culture = culture:mongol }
				save_scope_value_as = {
					name = first_story
					value = flag:desc_3
				}
			}
			1 = {
				trigger = { NOT = { scope:first_story ?= flag:desc_4 scope:first_story ?= flag:desc_4 } }
				save_scope_value_as = {
					name = first_story
					value = flag:desc_4
				}
			}
			1 = {
				trigger = { NOT = { scope:first_story ?= flag:desc_5 scope:first_story ?= flag:desc_5 } }
				save_scope_value_as = {
					name = first_story
					value = flag:desc_5
				}
			}
			1 = {
				trigger = { NOT = { scope:first_story ?= flag:desc_6 scope:first_story ?= flag:desc_6 } }
				save_scope_value_as = {
					name = first_story
					value = flag:desc_6
				}
			}
			1 = {
				trigger = { NOT = { scope:first_story ?= flag:desc_7 scope:first_story ?= flag:desc_7 } }
				save_scope_value_as = {
					name = first_story
					value = flag:desc_7
				}
			}
		}
		random_list= {
			1 = {
				trigger = { NOT = { scope:second_story ?= flag:desc_1 scope:second_story ?= flag:desc_1 } }
				save_scope_value_as = {
					name = second_story
					value = flag:desc_1
				}
			}
			1 = {
				trigger = { NOT = { scope:second_story ?= flag:desc_2 scope:second_story ?= flag:desc_2 } }
				save_scope_value_as = {
					name = second_story
					value = flag:desc_2
				}
			}
			1 = {
				trigger = { NOT = { scope:second_story ?= flag:desc_3 scope:second_story ?= flag:desc_3 } culture = culture:mongol }
				save_scope_value_as = {
					name = second_story
					value = flag:desc_3
				}
			}
			1 = {
				trigger = { NOT = { scope:second_story ?= flag:desc_4 scope:second_story ?= flag:desc_4 } }
				save_scope_value_as = {
					name = second_story
					value = flag:desc_4
				}
			}
			1 = {
				trigger = { NOT = { scope:second_story ?= flag:desc_5 scope:second_story ?= flag:desc_5 } }
				save_scope_value_as = {
					name = second_story
					value = flag:desc_5
				}
			}
			1 = {
				trigger = { NOT = { scope:second_story ?= flag:desc_6 scope:second_story ?= flag:desc_6 } }
				save_scope_value_as = {
					name = second_story
					value = flag:desc_6
				}
			}
			1 = {
				trigger = { NOT = { scope:second_story ?= flag:desc_7 scope:second_story ?= flag:desc_7 } }
				save_scope_value_as = {
					name = second_story
					value = flag:desc_7
				}
			}
		}
	}

	option = {
		name = mpo_decisions_events.2137.a
	}

	option = {
		name = mpo_decisions_events.2137.b
		trigger_event = mpo_decisions_events.2137
	}

	option = {
		name = mpo_decisions_events.2137.c
		add_courtier = scope:paiza_merchant
	}
}

mpo_decisions_events.0102 = {
	hidden = yes

	immediate = {
		save_scope_as = paiza_merchant
		var:merchant_origin = {
			save_scope_as = merchant_origin
		}
		var:requested_merchant_goods = {
			save_scope_as = merchant_goods
		}

		var:merchant_employer = {
			if = {
				limit = {
					is_alive = yes
				}
				if = {
					limit = {
						NOT = {
							root.location = location
						}
					}
					root = {
						set_location = { location = var:merchant_employer.location }
					}
				}
				trigger_event = mpo_decisions_events.0101
			}
		}
	}
}



mpo_decisions_events.0110 = { #mpo_abuse_authority_paiza_decision initial event
	type = character_event
	theme = nomads

	title = mpo_decisions_events.0110.t
	desc = mpo_decisions_events.0110.desc

	override_background = { reference = mpo_campfire_steppe }

	left_portrait = {
		character = root
		animation = personality_bold
	}

	right_portrait = {
		character = scope:local_boi
		animation = beg
	}

	lower_center_portrait = {
		character = scope:paiza_patron
	}

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

	immediate = {
		random_character_artifact = {
			limit = {
            	root = { can_benefit_from_artifact = prev }
            	exists = var:paiza_patron
            	var:paiza_patron = {
            		is_alive = yes
            		is_gurkhan = yes
            	}
            }
            save_scope_as = paiza_artifact
            var:paiza_patron ?= {
            	save_scope_as = paiza_patron
            }
        }
        location.duchy = {
        	random_de_jure_county = {
				limit = {
					holder = {
						is_ai = yes
					}
				}
				weight = {
					base = 1
					modifier = {
						add = holder.primary_title.tier
					}
				}
        		holder = {
        			save_scope_as = local_boi
        		}
        	}
        }
	}

	option = { #yeah, go for it
		name = mpo_decisions_events.0110.a
		mpo_paiza_abuse_counter_effect = {
			PAIZA_PATRON = scope:paiza_patron
			PAIZA_ABUSER = root
		}
		mpo_abuse_authority_county_effect = yes	
	}

	option = { #try to be sneaky about it
		name = mpo_decisions_events.0110.b

		duel = {
			skill = intrigue
			value = very_high_skill_rating
			50 = {
               	compare_modifier = {
               	    value = scope:duel_value
               	    multiplier = 3.5
               	    min = -49
               	}
               	min = 5
               	mpo_abuse_authority_county_effect = yes
				send_interface_toast = {
					type = event_toast_effect_good
					title = mpo_decisions_events.0110.b.success
					custom_tooltip = mpo_decisions_events.0110.b.success_desc
					left_icon = root
					right_icon = scope:paiza_patron
				}
            }
			50 = {
               	compare_modifier = {
               	    value = scope:duel_value
               	    multiplier = -3.5
               	    min = -49
               	}
               	min = 10
               	send_interface_toast = {
               		type = event_toast_effect_bad
					title = mpo_decisions_events.0110.b.failure
					left_icon = root
					right_icon = scope:paiza_patron
					mpo_paiza_abuse_counter_effect = {
						PAIZA_PATRON = scope:paiza_patron
						PAIZA_ABUSER = root
					}
               	}       	
            }
		}
	}

	option = {
		name = mpo_decisions_events.0110.d
		add_prestige = -200
	}
}

mpo_decisions_events.0111 = { #mpo_abuse_authority_paiza_decision consequences
	type = character_event
	theme = nomads

	title = mpo_decisions_events.0111.t
	desc = mpo_decisions_events.0111.desc

	override_background = { reference = mpo_campfire_steppe }

	left_portrait = {
		character = root
		animation = fear
	}

	right_portrait = {
		character = scope:paiza_patron
		animation = anger
	}

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

	immediate = {
		liege = { save_scope_as = paiza_patron }
		add_character_flag = no_more_paiza_abuse

		random_equipped_character_artifact = {
			limit = {
            	root = { can_benefit_from_artifact = prev }
            	exists = var:paiza_patron
            	var:paiza_patron = {
            		is_alive = yes
            		is_gurkhan = yes
            	}
            }
            save_scope_as = paiza_artifact
            var:paiza_patron ?= {
            	save_scope_as = paiza_patron
            }
        }
	}

	option = { #whoooops
		name = mpo_decisions_events.0111.a
		#what do you mean my actions have consequences
		custom_tooltip = mpo_decisions_events.0111.a.effects
		scope:paiza_patron = {
			add_opinion = {
				target = root
				modifier = abused_paiza_authority
			}
		}
	}

	option = { #its a prank bro
		trigger = {
			scope:paiza_patron = {
				is_ai = yes
			}
		}
		name = mpo_decisions_events.0111.b
		add_prestige_level = -1
		duel = {
			skill = diplomacy
			target = scope:paiza_patron
			30 = {
               	compare_modifier = {
               	    value = scope:duel_value
               	    multiplier = 3.5
               	    min = -49
               	}
               	min = 5
               	custom_tooltip = mpo_decisions_events.0111.a.survived_khans_wrath
               	scope:paiza_patron = {
               		add_opinion = {
               			target = root
               			modifier = angry_opinion
               			opinion = -30
               		}
               	}
            }
            70 = {
                compare_modifier = {
                    value = scope:duel_value
                    multiplier = -3.5
                    min = -49
                }
                min = 10
                custom_tooltip = mpo_decisions_events.0111.a.severe_effects
                scope:paiza_patron = {
					add_opinion = {
						target = root
						modifier = gravely_abused_paiza_authority
					}
				}
				every_close_family_member = {
					limit = {
					 	is_ai = yes
					}
					scope:paiza_patron = {
						add_opinion = {
							target = prev
							modifier = abused_paiza_authority_family
						}
					}
				}
            }
		}
	}
}

mpo_decisions_events.0112 = { #mpo_abuse_authority_paiza_decision consequences decision for a player
	type = character_event
	theme = nomads

	override_background = { reference = mpo_campfire_steppe }

	title = mpo_decisions_events.0112.t
	desc = mpo_decisions_events.0112.desc

	left_portrait = {
		character = scope:paiza_abuser_1
		animation = personality_coward
	}

	right_portrait = {
		character = scope:paiza_abuser
		animation = fear
	}

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

	trigger = {
		NOT = {
			has_character_flag = refused_paiza_abuse_notifications
		}
		scope:paiza_abuser = {
			any_dynasty_member = {
				location = scope:paiza_abuser
				is_ai = yes
				is_adult = yes
			}
		}
	}

	immediate = {
		scope:paiza_abuser = {
			random_dynasty_member = {
				limit = {
					location = scope:paiza_abuser
					is_ai = yes
					is_adult = yes
				}
				save_scope_as = paiza_abuser_1		
			}
			random_equipped_character_artifact = {
				limit = {
        	    	root = { can_benefit_from_artifact = prev }
        	    	exists = var:paiza_patron
        	    	var:paiza_patron = {
        	    		is_alive = yes
        	    		is_gurkhan = yes
        	    	}
        	    }
        	    save_scope_as = paiza_artifact
        	    var:paiza_patron ?= {
        	    	save_scope_as = paiza_patron
        	    }
        	}
		}
	}

	option = { #take action
		name = mpo_decisions_events.0112.a
		custom_tooltip = mpo_decisions_events.0112.a.desc
		reverse_add_opinion = {
			target = scope:paiza_abuser
			modifier = gravely_abused_paiza_authority
		}
		reverse_add_opinion = {
			target = scope:paiza_abuser_1
			modifier = gravely_abused_paiza_authority
		}
	}

	option = { #not for now
		name = mpo_decisions_events.0112.b
		scope:paiza_abuser = {
			send_interface_toast = {
				type = event_toast_effect_good
				title = mpo_paiza_abuse_counter_effect.indifferent
				left_icon = root
			}
		}
		scope:paiza_abuser_1 = {
			send_interface_toast = {
				type = event_toast_effect_good
				title = mpo_paiza_abuse_counter_effect.indifferent
				left_icon = root
			}
		}
	}

	option = { #do not notify me ever again (ever for like, 10 years)
		name = mpo_decisions_events.0112.c

		add_character_flag = {
			flag = refused_paiza_abuse_notifications
			years = 10
		}
	}
}

scripted_effect localize_study_commander_success_chance_change = {
	if = {
        limit = {
            $VALUE$ >= 25
        }
        custom_tooltip = study_commander_trait_current_success_chance_increase_monumental
    }
    else_if = {
        limit = {
            $VALUE$ >= 15
        }
        custom_tooltip = study_commander_trait_current_success_chance_increase_great
    }
    else_if = {
        limit = {
            $VALUE$ >= 1
        }
        custom_tooltip = study_commander_trait_current_success_chance_increase
    }
    else_if = {
        limit = {
            $VALUE$ = 0
        }
        custom_tooltip = study_commander_trait_current_success_chance_none
    }
    else_if = {
        limit = {
            $VALUE$ >= -15
        }
        custom_tooltip = study_commander_trait_current_success_chance_decrease
    }
    else = {
        custom_tooltip = study_commander_trait_current_success_chance_decrease_great
    }
    if = {
        limit = {
            NOT = { has_variable = study_commander_trait_success_chance_var }
        }
        set_variable = {
            name = study_commander_trait_success_chance_var
            value = 0
        }
    }
    change_variable = {
        name = study_commander_trait_success_chance_var
        add = $VALUE$
    }
}
scripted_effect mentor_option_seed_effect = {
	random_list = {
		1 = { save_scope_value_as = { name = mentor_option_seed value = 1 } }
		1 = { save_scope_value_as = { name = mentor_option_seed value = 2 } }
	}
}
scripted_effect trait_weighting_effect = {
	if = {
		limit = {
			can_weigh_trait_trigger = { 
				TRAIT = $WEIGHTED_TRAIT$
			}
		}
		if = {
			limit = {
				NOT = { has_variable = $WEIGHTED_TRAIT$_weight }
			}
			set_variable = {
				name = $WEIGHTED_TRAIT$_weight
				value = 0
			}
		}
		change_variable = {
			name = $WEIGHTED_TRAIT$_weight
			add = $WEIGHT$
		}
		every_trait = {
			limit = {
				this = trait:$WEIGHTED_TRAIT$
			}
			save_scope_as = weighted_trait
		}
		if = {
			limit = {
				$WEIGHT$ > 0
			}
			custom_tooltip = study_commander_trait_weight_tooltip_pos
		}
		else = {
			custom_tooltip = study_commander_trait_weight_tooltip_neg
		}
	}
	else = {
		add_prestige = 10
	}
}
scripted_effect trait_weighting_effect_mentor = {
    if = {
        limit = {
            scope:commander_trait_mentor = { has_trait = $TRAIT$ }
        }
        trait_weighting_effect = {
            WEIGHTED_TRAIT = $TRAIT$
            WEIGHT = 10
        }
    }
}
scripted_trigger can_weigh_trait_trigger = {
	trigger_if = {
		limit = {
			NOT = { has_trait = $TRAIT$ }
		} 
		# Exceptions
		trigger_if = {
			limit = {
				flag:$TRAIT$ = flag:reckless
			}
			NOT = { has_trait = cautious_leader }
		}
		trigger_else_if = {
			limit = {
				flag:$TRAIT$ = flag:cautious_leader
				
			}
			NOT = { has_trait = reckless }
		}
		trigger_else = {
			always = yes
		}
	}
	trigger_else = {
		always = no
	}
}

# Study Commander Trait Events
mpo_decisions_events.0200 = {
	type = character_event
	title = mpo_decisions_events.0200.t
	desc = {
		desc = mpo_decisions_events.0200.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					has_variable = commander_trait_mentor
					var:commander_trait_mentor = scope:commander_trait_mentor
				}
				desc = mpo_decisions_events.0200.desc_my_mentor
			}
			triggered_desc = {
				trigger = {
					scope:commander_trait_mentor = { has_variable = commander_trait_mentor }
				}
				desc = mpo_decisions_events.0200.desc_mentor
			}
		}
	}
	theme = nomads

	left_portrait = {
		character = root
		animation = marshal
	}

	right_portrait = {
		character = scope:commander_trait_mentor
		animation = inspect_weapon
	}

	immediate = {
		stress_impact = {
			base = medium_stress_impact_gain
		}
		add_character_flag = is_learning_commander_trait
		# Find a mentor
		if = {
			limit =  {
				OR = {
					NOT = { has_variable = commander_trait_mentor }
					AND = {
						has_variable = commander_trait_mentor
						var:commander_trait_mentor = { is_available_adult = no }
					}
				}
			}
			every_knight = {
				limit = {
					is_available_adult = yes
				}
				save_scope_as = possible_mentor
				root = {
					add_to_variable_list = {
						name = possible_mentor_list
						target = scope:possible_mentor
					}
				}
			}
			every_vassal_or_below = {
				limit = {
					is_available_adult = yes
				}
				save_scope_as = possible_mentor
				root = {
					add_to_variable_list = {
						name = possible_mentor_list
						target = scope:possible_mentor
					}
				}
			}
			every_councillor = {
				limit = {
					is_available_adult = yes
				}
				save_scope_as = possible_mentor
				root = {
					add_to_variable_list = {
						name = possible_mentor_list
						target = scope:possible_mentor
					}
				}
			}
			ordered_in_list = {
				variable = possible_mentor_list
				limit = {
					martial > decent_skill_rating
				}
				order_by = {
					add = martial
					if = {
						limit = {
							number_of_commander_traits >= 1
						}
						add = 5
					}
				}
				save_scope_as = commander_trait_mentor
			}
			if = {
				limit = {
					NOT = { exists = scope:commander_trait_mentor }
				}
				create_character = {
					random_traits = yes
					dynasty = none
					location = root.location
					culture = root.location.culture
					faith = root.location.faith
					gender_female_chance = root_soldier_female_chance
					random_traits_list = {
						count = 1
						education_martial_2 = {}
						education_martial_3 = {}
						education_martial_4 = {}
					}
					random_traits_list = {
						count = 1
						brave = {}
						just = {}
						gallant = {}
						honest = {}
						gregarious = {}
						generous = {}
						diligent = {}
						wrathful = {}
					}
					prowess = {
						min_template_decent_skill
						min_template_decent_skill
					}
					martial = {
						min_template_high_skill
						max_template_high_skill
					}
					intrigue = {
						min_template_decent_skill
						max_template_medium_skill
					}
					learning = {
						min_template_decent_skill
						max_template_medium_skill
					}
					save_scope_as = commander_trait_mentor
					after_creation = {
						give_random_commander_trait_effect = yes
					}
				}
			}
		}
		else = {
			var:commander_trait_mentor = { save_scope_as = commander_trait_mentor }
		}
		if = {
			limit = {
				debug_only = yes 
			}
			custom_tooltip = study_commander_trait_current_success_chance_debug
		}
		else = {
			custom_tooltip = study_commander_trait_current_success_chance
		}
		set_variable = {
			name = study_commander_trait_success_chance_var
			value = 0
		}
	}

	option = { #Study under mentor
		name = {
			text = {
				first_valid = {
					triggered_desc = {
						trigger = {
							has_variable = commander_trait_mentor
							var:commander_trait_mentor = scope:commander_trait_mentor
						}
						desc = mpo_decisions_events.0200.my_mentor
					}
					desc = mpo_decisions_events.0200.mentor
				}
			}
		}
		trigger = {
			short_term_gold >= scope:commander_trait_mentor.study_commander_trait_mentor_hire_cost	
		}
		show_as_unavailable = { always = yes }
		flavor = mpo_decisions_events.0200.mentor_flavor
		save_scope_value_as = {
			name = training_method
			value = flag:mentor
		}
		pay_short_term_gold = {
			target = scope:commander_trait_mentor
			gold = scope:commander_trait_mentor.study_commander_trait_mentor_hire_cost
		}
		localize_study_commander_success_chance_change = {
			VALUE = 25
		}
		set_variable = {
			name = commander_trait_mentor
			value = scope:commander_trait_mentor
		}
		scope:commander_trait_mentor = {
			add_character_flag = commander_trait_mentor
		}
		if = {
			limit = {
				scope:commander_trait_mentor = { number_of_commander_traits >= 1 }
			}
			custom_tooltip = mpo_decisions_events.0200.mentor_traits
			trait_weighting_effect_mentor = { TRAIT = logistician }
			trait_weighting_effect_mentor = { TRAIT = military_engineer }
			trait_weighting_effect_mentor = { TRAIT = aggressive_attacker }
			trait_weighting_effect_mentor = { TRAIT = unyielding_defender }
			trait_weighting_effect_mentor = { TRAIT = forder }
			trait_weighting_effect_mentor = { TRAIT = flexible_leader }
			trait_weighting_effect_mentor = { TRAIT = desert_warrior }
			trait_weighting_effect_mentor = { TRAIT = jungle_stalker }
			trait_weighting_effect_mentor = { TRAIT = reaver }
			trait_weighting_effect_mentor = { TRAIT = reckless }
			trait_weighting_effect_mentor = { TRAIT = holy_warrior }
			trait_weighting_effect_mentor = { TRAIT = open_terrain_expert }
			trait_weighting_effect_mentor = { TRAIT = rough_terrain_expert }
			trait_weighting_effect_mentor = { TRAIT = forest_fighter }
			trait_weighting_effect_mentor = { TRAIT = cautious_leader }
			trait_weighting_effect_mentor = { TRAIT = organizer }
			trait_weighting_effect_mentor = { TRAIT = winter_soldier }
		}
		stress_impact = {
			greedy = medium_stress_impact_gain
			arrogant = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = 0.1
				ai_energy = 1
			}
			modifier = {
				scope:commander_trait_mentor.martial >= root.martial
				factor = 1.25
			}
			modifier = {
				has_trait = arrogant
				factor = 0
			}
		}
	}

	option = { #Study on your own
		name = mpo_decisions_events.0200.a
		flavor = mpo_decisions_events.0200.alone
		save_scope_value_as = {
			name = training_method
			value = flag:none
		}
		localize_study_commander_success_chance_change = {
			VALUE = 0
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_energy = 0.5
			}
			modifier = {
				has_trait = craven
				factor = 0.5
			}
		}
	}

	option = { #Study on your own - Martial
		name = mpo_decisions_events.0200.martial
		flavor = mpo_decisions_events.0200.martial_flavor
		trigger = {
			martial >= high_skill_rating
		}
		save_scope_value_as = {
			name = training_method
			value = flag:martial
		}
		if = {
			limit = {
				highest_skill = martial
			}
			localize_study_commander_success_chance_change = {
				VALUE = 15
			}
		}
		else = {
			localize_study_commander_success_chance_change = {
				VALUE = 10
			}
		}
		ai_chance = {
			base = 75
			ai_value_modifier = {
				ai_energy = 0.5
			}
			modifier = {
				highest_skill = martial
				factor = 1.5
			}
		}
	}

	option = { #Study on your own - Learning
		name = mpo_decisions_events.0200.learning
		flavor = mpo_decisions_events.0200.learning_flavor
		trigger = {
			learning >= high_skill_rating
		}
		show_as_unavailable = { learning >= low_skill_rating }
		save_scope_value_as = {
			name = training_method
			value = flag:learning
		}
		if = {
			limit = {
				highest_skill = learning
			}
			localize_study_commander_success_chance_change = {
				VALUE = 15
			}
		}
		else = {
			localize_study_commander_success_chance_change = {
				VALUE = 10
			}
		}
		ai_chance = {
			base = 75
			ai_value_modifier = {
				ai_energy = 0.5
			}
			modifier = {
				highest_skill = learning
				factor = 1.5
			}
		}
	}

	option = { #Study on your own - Intrigue
		name = mpo_decisions_events.0200.intrigue
		flavor = mpo_decisions_events.0200.intrigue_flavor
		trigger = {
			intrigue >= high_skill_rating
		}
		show_as_unavailable = { intrigue >= low_skill_rating }
		save_scope_value_as = {
			name = training_method
			value = flag:intrigue
		}
		if = {
			limit = {
				highest_skill = intrigue
			}
			localize_study_commander_success_chance_change = {
				VALUE = 15
			}
		}
		else = {
			localize_study_commander_success_chance_change = {
				VALUE = 10
			}
		}
		ai_chance = {
			base = 75
			ai_value_modifier = {
				ai_energy = 0.5
			}
			modifier = {
				highest_skill = intrigue
				factor = 1.5
			}
		}
	}

	after = {
		if = {
			limit = {
				OR = {
					has_trait = vengeful
					has_trait = wrathful
					has_trait = paranoid
					has_trait = arbitrary
					has_trait = zealous
					has_trait = temperate
					has_trait = gluttonous
					has_trait = greedy
					has_trait = diligent
					has_trait = administrator
					has_trait = architect
				}
			}
			custom_tooltip = study_commander_trait_bonus
			if = {
				limit = {
					OR = {
						has_trait = vengeful
						has_trait = wrathful
					}
				}
				trait_weighting_effect = {
					WEIGHTED_TRAIT = aggressive_attacker
					WEIGHT = 10
				}
			}
			if = {
				limit = {
					has_trait = paranoid
				}
				trait_weighting_effect = {
					WEIGHTED_TRAIT = cautious_leader
					WEIGHT = 10
				}
			}
			if = {
				limit = {
					has_trait = arbitrary
				}
				trait_weighting_effect = {
					WEIGHTED_TRAIT = reckless
					WEIGHT = 10
				}
			}
			if = {
				limit = {
					has_trait = zealous
				}
				trait_weighting_effect = {
					WEIGHTED_TRAIT = holy_warrior
					WEIGHT = 10
				}
			}
			if = {
				limit = {
					has_trait = temperate
				}
				trait_weighting_effect = {
					WEIGHTED_TRAIT = logistician
					WEIGHT = 10
				}
			}
			if = {
				limit = {
					has_trait = gluttonous
				}
				trait_weighting_effect = {
					WEIGHTED_TRAIT = logistician
					WEIGHT = -10
				}
			}
			if = {
				limit = {
					has_trait = greedy
				}
				trait_weighting_effect = {
					WEIGHTED_TRAIT = reaver
					WEIGHT = 10
				}
			}
			if = {
				limit = {
					OR = {
						has_trait = diligent
						has_trait = administrator
					}
				}
				trait_weighting_effect = {
					WEIGHTED_TRAIT = organizer
					WEIGHT = 5
				}
			}
			if = {
				limit = {
					has_trait = architect
				}
				trait_weighting_effect = {
					WEIGHTED_TRAIT = military_engineer
					WEIGHT = 10
				}
			}
		}
		if = {
			limit = {
				NOR = { 
					scope:commander_trait_mentor = { is_courtier_of = root }
					scope:commander_trait_mentor = { is_councillor_of = root }
					scope:commander_trait_mentor = { is_knight_of = root }
					scope:training_method ?= flag:mentor
				}
			}
			scope:commander_trait_mentor = {
				silent_disappearance_effect = yes
			}
		}
		trigger_event = {
			id = mpo_decisions_events.0201
			days = { 5 10 }
		}
	}
}

scripted_effect study_commander_trait_option_mentor = {
	if = {
		limit = {
			$DUEL$ = yes
		}
		duel = {
			skill = $SKILL$
			target = scope:commander_trait_mentor
			desc = study_commander_trait_option_mentor_desc
			60 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
				}
				desc = $SUCCESS_DESC$
				send_interface_toast = {
					type = event_toast_effect_good
					title = $SUCCESS_DESC$
					left_icon = root
					right_icon = scope:commander_trait_mentor
					if = {
						limit = {
							$WOUND_CHANCE$ = yes
						}
						random = {
							chance = 10
							scope:commander_trait_mentor = {
								increase_wounds_effect = { REASON = fight }
							}
						}
					}
					random_list = {
						50 = {
							desc = study_commander_trait_option_success_ok
							show_chance = no
							localize_study_commander_success_chance_change = { VALUE = 10 }
						}
						50 = {
							desc = study_commander_trait_option_success
							show_chance = no
							localize_study_commander_success_chance_change = { VALUE = 20 }
						}
					}
				}
			}
			30 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
				}
				desc = $FAIL_DESC$
				send_interface_toast = {
					type = event_toast_effect_bad
					title = $FAIL_DESC$
					left_icon = root
					right_icon = scope:commander_trait_mentor
					if = {
						limit = {
							$WOUND_CHANCE$ = yes
						}
						random = {
							chance = 10
							increase_wounds_effect = { REASON = fight }
						}
					}
					random_list = {
						50 = {
							desc = study_commander_trait_option_fail_ok
							localize_study_commander_success_chance_change = { VALUE = -10 }
						}
						50 = {
							desc = study_commander_trait_option_fail
							localize_study_commander_success_chance_change = { VALUE = -20 }
						}
					}
				}
			}
		}
	}
	else = {
		duel = {
			skill = $SKILL$
			value = decent_skill_rating
			75 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
				}
				desc = $SUCCESS_DESC$
				send_interface_toast = {
					type = event_toast_effect_good
					title = $SUCCESS_DESC$
					left_icon = root
					right_icon = scope:commander_trait_mentor
					if = {
						limit = {
							$WOUND_CHANCE$ = yes
						}
						random = {
							chance = 10
							scope:commander_trait_mentor = {
								increase_wounds_effect = { REASON = fight }
							}
						}
					}
					random_list = {
						50 = {
							desc = study_commander_trait_option_success_ok
							show_chance = no
							localize_study_commander_success_chance_change = { VALUE = 10 }
						}
						50 = {
							desc = study_commander_trait_option_success
							show_chance = no
							localize_study_commander_success_chance_change = { VALUE = 20 }
						}
					}
				}
			}
			30 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
				}
				desc = $FAIL_DESC$
				send_interface_toast = {
					type = event_toast_effect_bad
					title = $FAIL_DESC$
					left_icon = root
					right_icon = scope:commander_trait_mentor
					if = {
						limit = {
							$WOUND_CHANCE$ = yes
						}
						random = {
							chance = 10
							increase_wounds_effect = { REASON = fight }
						}
					}
					random_list = {
						50 = {
							desc = study_commander_trait_option_fail_ok
							localize_study_commander_success_chance_change = { VALUE = -10 }
						}
						50 = {
							desc = study_commander_trait_option_fail
							localize_study_commander_success_chance_change = { VALUE = -20 }
						}
					}
				}
			}
		}
	}
}

scripted_effect study_commander_trait_option_no_mentor = {
	if = {
		limit = {
			$DUEL$ = yes
		}
		duel = {
			skill = $SKILL$
			value = high_skill_rating
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
				}
				desc = $SUCCESS_DESC$
				send_interface_toast = {
					type = event_toast_effect_good
					title = $SUCCESS_DESC$
					left_icon = root
					random_list = {
						50 = {
							desc = study_commander_trait_option_success_ok
							show_chance = no
							localize_study_commander_success_chance_change = { VALUE = 10 }
						}
						50 = {
							desc = study_commander_trait_option_success
							show_chance = no
							localize_study_commander_success_chance_change = { VALUE = 20 }
						}
					}
				}
			}
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
				}
				desc = $FAIL_DESC$
				send_interface_toast = {
					type = event_toast_effect_bad
					title = $FAIL_DESC$
					left_icon = root
					if = {
						limit = {
							$WOUND_CHANCE$ = yes
						}
						random = {
							chance = 10
							increase_wounds_effect = { REASON = fight }
						}
					}
					random_list = {
						50 = {
							desc = study_commander_trait_option_fail_ok
							localize_study_commander_success_chance_change = { VALUE = -10 }
						}
						50 = {
							desc = study_commander_trait_option_fail
							localize_study_commander_success_chance_change = { VALUE = -20 }
						}
					}
				}
			}
		}
	}
	else = {
		random_list = {
			50 = {
				desc = $SUCCESS_DESC$
				show_chance = no
				localize_study_commander_success_chance_change = { VALUE = 10 }
			}
			50 = {
				desc = $FAIL_DESC$
				show_chance = no
				localize_study_commander_success_chance_change = { VALUE = -10 }
			}
		}
	}
}


mpo_decisions_events.0201 = { # Training Session 1
	type = character_event
	title = mpo_decisions_events.0201.t
	desc = {
		desc = mpo_decisions_events.0201.desc_intro
		triggered_desc = {
			trigger = {
				scope:training_method = flag:mentor 
			}
			desc = mpo_decisions_events.0201.desc_mentor
		}
	}
	theme = nomads

	left_portrait = {
		character = root
		animation = marshal
	}

	right_portrait = {
		trigger = {
			scope:training_method = flag:mentor 
		}
		character = scope:commander_trait_mentor
		animation = personality_honorable
	}

	immediate = {
		stress_impact = {
			base = medium_stress_impact_gain
		}
		if = {
			limit = {
				debug_only = yes 
			}
			custom_tooltip = study_commander_trait_current_success_chance_debug
		}
		else = {
			custom_tooltip = study_commander_trait_current_success_chance
		}
		if = {
			limit = {
				scope:training_method = flag:mentor 
			}
			mentor_option_seed_effect = yes
		}
	}

	option = { # Single Combat
		name = mpo_decisions_events.0201.martial_1
		trigger = {
			OR = {
				scope:training_method = flag:martial 
				scope:mentor_option_seed ?= 1
			}
		}
		flavor = mpo_decisions_events.0201.martial_1_flavor
		if = {
			limit = {
				scope:training_method = flag:mentor
			}
			study_commander_trait_option_mentor = {
				DUEL = yes
				SKILL = martial
				SUCCESS_DESC = mpo_decisions_events.0201.martial_1_mentor_success
				FAIL_DESC = mpo_decisions_events.0201.martial_1_mentor_fail
				WOUND_CHANCE = yes
			}
		}
		else = {
			custom_tooltip = mpo_decisions_events.0201.martial_1_tt
			study_commander_trait_option_no_mentor = {
				DUEL = yes
				SKILL = martial
				SUCCESS_DESC = mpo_decisions_events.0201.martial_1_success
				FAIL_DESC = mpo_decisions_events.0201.martial_1_fail
				WOUND_CHANCE = yes
			}
		}
		trait_weighting_effect = {
			WEIGHTED_TRAIT = aggressive_attacker
			WEIGHT = 15
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 1.5
				highest_skill = martial
			}
			modifier = {
				factor = 0
				has_trait = aggressive_attacker 
			}
		}
	}

	option = { # Small-scale Battle
		name = mpo_decisions_events.0201.martial_2
		trigger = {
			OR = {
				scope:training_method = flag:martial
				scope:mentor_option_seed ?= 2
			}
		}
		flavor = mpo_decisions_events.0201.martial_2_flavor
		custom_tooltip = mpo_decisions_events.0201.martial_2_tt
		if = {
			limit = {
				scope:training_method = flag:mentor
			}
			study_commander_trait_option_mentor = {
				DUEL = yes
				SKILL = martial
				SUCCESS_DESC = mpo_decisions_events.0201.martial_2_success
				FAIL_DESC = mpo_decisions_events.0201.martial_2_fail
				WOUND_CHANCE = no
			}
		}
		else = {
			study_commander_trait_option_no_mentor = {
				DUEL = yes
				SKILL = martial
				SUCCESS_DESC = mpo_decisions_events.0201.martial_2_success
				FAIL_DESC = mpo_decisions_events.0201.martial_2_fail
				WOUND_CHANCE = no
			}
		}
		trait_weighting_effect = {
			WEIGHTED_TRAIT = unyielding_defender
			WEIGHT = 15
		}
		save_scope_value_as = {
			name = last_location_study_commander
			value = flag:battlefield
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 1.5
				highest_skill = martial
			}
			modifier = {
				factor = 1.2
				martial >= decent_skill_rating
			}
			modifier = {
				factor = 0
				has_trait = unyielding_defender 
			}
		}
	}

	option = { # Landscape
		name = mpo_decisions_events.0201.learning_1
		trigger = {
			OR = {
				scope:training_method = flag:learning
				scope:mentor_option_seed ?= 1
			}
		}
		flavor = mpo_decisions_events.0201.learning_1_flavor
		custom_tooltip = mpo_decisions_events.0201.learning_1_tt
		if = {
			limit = {
				scope:training_method = flag:mentor
			}
			custom_tooltip = mpo_decisions_events.0201.learning_1_mentor
			study_commander_trait_option_mentor = {
				DUEL = no
				SKILL = learning
				SUCCESS_DESC = mpo_decisions_events.0201.learning_1_success
				FAIL_DESC = mpo_decisions_events.0201.learning_1_fail
				WOUND_CHANCE = no
			}
		}
		else = {
			study_commander_trait_option_no_mentor = {
				DUEL = yes
				SKILL = learning
				SUCCESS_DESC = mpo_decisions_events.0201.learning_1_success
				FAIL_DESC = mpo_decisions_events.0201.learning_1_fail
				WOUND_CHANCE = no
			}
		}
		if = {
			limit = {
				can_weigh_trait_trigger = { TRAIT = open_terrain_expert }
			}
			trait_weighting_effect = {
				WEIGHTED_TRAIT = open_terrain_expert
				WEIGHT = 15
			}
		}
		else_if = {
			limit = {
				can_weigh_trait_trigger = { TRAIT = rough_terrain_expert }
			}
			trait_weighting_effect = {
				WEIGHTED_TRAIT = rough_terrain_expert
				WEIGHT = 15
			}
		}
		save_scope_value_as = {
			name = last_location_study_commander
			value = flag:terrain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 1.5
				highest_skill = learning
			}
			modifier = {
				factor = 1.2
				learning >= decent_skill_rating
			}
			modifier = {
				factor = 0.5
				has_trait = rough_terrain_expert 
			}
			modifier = {
				factor = 0.5
				has_trait = open_terrain_expert 
			}
		}
	}

	option = { # Study military innovations
		name = mpo_decisions_events.0201.learning_2
		trigger = {
			OR = {
				scope:training_method = flag:learning
				scope:mentor_option_seed ?= 2
			}
		}
		custom_tooltip = mpo_decisions_events.0201.learning_2_tt
		flavor = mpo_decisions_events.0201.learning_2_flavor
		if = {
			limit = {
				scope:training_method = flag:mentor
			}
			custom_tooltip = mpo_decisions_events.0201.learning_2_mentor
			study_commander_trait_option_mentor = {
				DUEL = no
				SKILL = learning
				SUCCESS_DESC = mpo_decisions_events.0201.learning_2_success
				FAIL_DESC = mpo_decisions_events.0201.learning_2_fail
				WOUND_CHANCE = no
			}
		}
		else = {
			study_commander_trait_option_no_mentor = {
				DUEL = yes
				SKILL = learning
				SUCCESS_DESC = mpo_decisions_events.0201.learning_2_success
				FAIL_DESC = mpo_decisions_events.0201.learning_2_fail
				WOUND_CHANCE = no
			}
		}
		trait_weighting_effect = {
			WEIGHTED_TRAIT = military_engineer
			WEIGHT = 15
		}
		save_scope_value_as = {
			name = last_location_study_commander
			value = flag:study
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 1.5
				highest_skill = learning
			}
			modifier = {
				factor = 1.2
				learning >= decent_skill_rating
			}
			modifier = {
				factor = 0
				has_trait = military_engineer 
			}
		}
	}

	option = { # Boost morale / manipulate enemy
		name = mpo_decisions_events.0201.intrigue_1
		trigger = {
			OR = {
				scope:training_method = flag:intrigue
				scope:mentor_option_seed ?= 1
			}
		}
		custom_tooltip = mpo_decisions_events.0201.intrigue_1_tt
		flavor = mpo_decisions_events.0201.intrigue_1_flavor
		if = {
			limit = {
				scope:training_method = flag:mentor
			}
			custom_tooltip = mpo_decisions_events.0201.intrigue_1_mentor
			study_commander_trait_option_mentor = {
				DUEL = no
				SKILL = intrigue
				SUCCESS_DESC = mpo_decisions_events.0201.intrigue_1_success
				FAIL_DESC = mpo_decisions_events.0201.intrigue_1_fail
				WOUND_CHANCE = no
			}
		}
		else = {
			study_commander_trait_option_no_mentor = {
				DUEL = yes
				SKILL = intrigue
				SUCCESS_DESC = mpo_decisions_events.0201.intrigue_1_success
				FAIL_DESC = mpo_decisions_events.0201.intrigue_1_fail
				WOUND_CHANCE = no
			}
		}
		save_scope_value_as = {
			name = last_location_study_commander
			value = flag:town
		}
		trait_weighting_effect = {
			WEIGHTED_TRAIT = flexible_leader
			WEIGHT = 15
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 1.5
				highest_skill = intrigue
			}
			modifier = {
				factor = 1.2
				intrigue >= decent_skill_rating
			}
			modifier = {
				factor = 0
				has_trait = flexible_leader 
			}
		}
	}

	option = { # Negotiate with enemy
		name = mpo_decisions_events.0201.intrigue_2
		trigger = {
			OR = {
				scope:training_method = flag:intrigue
				scope:mentor_option_seed ?= 2
			}
		}
		custom_tooltip = mpo_decisions_events.0201.intrigue_2_tt
		flavor = mpo_decisions_events.0201.intrigue_2_flavor
		if = {
			limit = {
				scope:training_method = flag:mentor
			}
			study_commander_trait_option_mentor = {
				DUEL = no
				SKILL = intrigue
				SUCCESS_DESC = mpo_decisions_events.0201.intrigue_2_success
				FAIL_DESC = mpo_decisions_events.0201.intrigue_2_fail
				WOUND_CHANCE = no
			}
		}
		else = {
			study_commander_trait_option_no_mentor = {
				DUEL = yes
				SKILL = intrigue
				SUCCESS_DESC = mpo_decisions_events.0201.intrigue_2_success
				FAIL_DESC = mpo_decisions_events.0201.intrigue_2_fail
				WOUND_CHANCE = yes
			}
		}
		if = {
			limit = {
				can_weigh_trait_trigger = { TRAIT = cautious_leader }
			}
			trait_weighting_effect = {
				WEIGHTED_TRAIT = cautious_leader
				WEIGHT = 15
			}
		}
		else = {
			trait_weighting_effect = {
				WEIGHTED_TRAIT = organizer
				WEIGHT = 15
			}
		}
		save_scope_value_as = {
			name = last_location_study_commander
			value = flag:town
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 1.5
				highest_skill = intrigue
			}
			modifier = {
				factor = 1.2
				intrigue >= decent_skill_rating
			}
			modifier = {
				factor = 0.5
				has_trait = organizer 
			}
			modifier = {
				factor = 0.5
				has_trait = cautious_leader 
			}
		}
	}

	option = { # Supply Crisis
		name = mpo_decisions_events.0201.none_1
		trigger = {
			OR = {
				scope:mentor_option_seed ?= 1
				scope:training_method = flag:none
			}
		}
		flavor = mpo_decisions_events.0201.none_1_flavor
		trait_weighting_effect = {
			WEIGHTED_TRAIT = logistician
			WEIGHT = 5
		}
		study_commander_trait_option_no_mentor = {
			DUEL = no
			SKILL = intrigue
			SUCCESS_DESC = mpo_decisions_events.0201.none_1_success
			FAIL_DESC = mpo_decisions_events.0201.none_1_fail
			WOUND_CHANCE = yes
		}
		save_scope_value_as = {
			name = last_location_study_commander
			value = flag:town
		}
		ai_chance = {
			base = 50
			modifier = {
				factor = 0
				has_trait = logistician 
			}
		}
	}

	option = { # Simple Training Exercise
		name = mpo_decisions_events.0201.none_2
		trigger = {
			OR = {
				scope:mentor_option_seed ?= 2
				scope:training_method = flag:none
			}
		}
		flavor = mpo_decisions_events.0201.none_2_flavor
		add_prowess_skill = 2
		random = {
			chance = 10
			if = {
				limit = {
					has_trait = craven
				}
				remove_trait = craven
			}
			add_trait = brave
		}
	}

	after = {
		trigger_event = {
			id = mpo_decisions_events.0202
			days = { 15 20 }
		}
	}
}

mpo_decisions_events.0202 = { # Random Situation
	type = character_event
	title = mpo_decisions_events.0202.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:last_location_study_commander ?= flag:battlefield
				}
				desc = mpo_decisions_events.0202.desc_battlefield
			}
			triggered_desc = {
				trigger = {
					scope:last_location_study_commander ?= flag:terrain
				}
				desc = mpo_decisions_events.0202.desc_terrain
			}
			triggered_desc = {
				trigger = {
					scope:last_location_study_commander ?= flag:study
				}
				desc = mpo_decisions_events.0202.desc_study
			}
			triggered_desc = {
				trigger = {
					scope:last_location_study_commander ?= flag:town
				}
				desc = mpo_decisions_events.0202.desc_town
			}
		}
		desc = mpo_decisions_events.0202.desc
		first_valid = {
			triggered_desc = { 
				trigger = { 
					scope:random_situation = 1
				}
				desc = mpo_decisions_events.0202.desc_1_intro
			}
			triggered_desc = { 
				trigger = {
					scope:random_situation = 2
				}
				desc = mpo_decisions_events.0202.desc_2
			}
			triggered_desc = {
				trigger = {
					scope:random_situation = 3
				}
				desc = mpo_decisions_events.0202.desc_3
			}
		}
		first_valid = {
			triggered_desc = { 
				trigger = { 
					scope:random_situation = 1
					scope:situation_1_terrain ?= flag:forest
				}
				desc = terrain_forest
			}
			triggered_desc = { 
				trigger = {
					scope:random_situation = 1
					scope:situation_1_terrain ?= flag:taiga
				}
				desc = terrain_taiga
			}
			triggered_desc = { 
				trigger = {
					scope:random_situation = 1
					scope:situation_1_terrain ?= flag:jungle
				}
				desc = terrain_jungle
			}
			triggered_desc = { 
				trigger = {
					scope:random_situation = 1
					scope:situation_1_terrain ?= flag:wetlands
				}
				desc = terrain_wetlands
			}
			triggered_desc = { 
				trigger = {
					scope:random_situation = 1
					scope:situation_1_terrain ?= flag:floodplains
				}
				desc = terrain_floodplains
			}
			triggered_desc = { 
				trigger = {
					scope:random_situation = 1
					scope:situation_1_terrain ?= flag:desert
				}
				desc = terrain_desert
			}
			triggered_desc = { 
				trigger = {
					scope:random_situation = 1
					scope:situation_1_terrain ?= flag:desert_mountains
				}
				desc = terrain_desert_mountains
			}
			triggered_desc = { 
				trigger = {
					scope:random_situation = 1
					scope:situation_1_terrain ?= flag:oasis
				}
				desc = terrain_oasis
			}
			triggered_desc = { 
				trigger = {
					scope:random_situation = 1
					scope:situation_1_terrain ?= flag:steppe
				}
				desc = terrain_steppe
			}
			triggered_desc = { 
				trigger = {
					scope:random_situation = 1
					scope:situation_1_terrain ?= flag:farmlands
				}
				desc = terrain_farmlands
			}
			triggered_desc = { 
				trigger = {
					scope:random_situation = 1
					scope:situation_1_terrain ?= flag:plains
				}
				desc = terrain_plains
			}
			triggered_desc = { 
				trigger = {
					scope:random_situation = 1
					scope:situation_1_terrain ?= flag:drylands
				}
				desc = terrain_drylands
			}
			triggered_desc = { 
				trigger = {
					scope:random_situation = 1
					scope:situation_1_terrain ?= flag:mountains
				}
				desc = terrain_mountains
			}
			triggered_desc = { 
				trigger = {
					scope:random_situation = 1
					scope:situation_1_terrain ?= flag:hills
				}
				desc = terrain_hills
			}

		}
		random_valid = {
			triggered_desc = { 
				trigger = {
					scope:situation_1_terrain ?= flag:taiga
				}
				desc = terrain_disadvantage_freeze
			}
			triggered_desc = { 
				trigger = {
					OR = {
						scope:situation_1_terrain ?= flag:forest
						scope:situation_1_terrain ?= flag:jungle
					}
				}
				desc = terrain_disadvantage_foliage
			}
			triggered_desc = { 
				trigger = {
					OR = {
						scope:situation_1_terrain ?= flag:forest
						scope:situation_1_terrain ?= flag:jungle
						scope:situation_1_terrain ?= flag:wetlands
						scope:situation_1_terrain ?= flag:floodplains
					}
				}
				desc = terrain_disadvantage_heavy_rain
			}
			triggered_desc = { 
				trigger = {
					OR = {
						scope:situation_1_terrain ?= flag:desert
						scope:situation_1_terrain ?= flag:desert_mountains
					}
				}
				desc = terrain_disadvantage_sand
			}
			triggered_desc = { 
				trigger = {
					OR = {
						scope:situation_1_terrain ?= flag:desert
						scope:situation_1_terrain ?= flag:desert_mountains
						scope:situation_1_terrain ?= flag:oasis
						scope:situation_1_terrain ?= flag:steppe
						scope:situation_1_terrain ?= flag:farmlands
						scope:situation_1_terrain ?= flag:plains 
						scope:situation_1_terrain ?= flag:drylands
					}
				}
				desc = terrain_disadvantage_heat
			}
			triggered_desc = { 
				trigger = {
					OR = {
						scope:situation_1_terrain ?= flag:mountains
						scope:situation_1_terrain ?= flag:hills
					}
				}
				desc = terrain_disadvantage_hike
			}
			triggered_desc = { 
				trigger = {
					OR = {
						scope:situation_1_terrain ?= flag:steppe
						scope:situation_1_terrain ?= flag:farmlands
						scope:situation_1_terrain ?= flag:plains
						scope:situation_1_terrain ?= flag:drylands
					}
				}
				desc = terrain_disadvantage_endless_field
			}
			triggered_desc = { 
				trigger = {
					scope:random_situation = 1
				}
				desc = terrain_disadvantage_difficult
			}
		}
		desc = mpo_decisions_events.0202.desc_outro
	}

	theme = nomads

	override_background = {
		trigger = {
			scope:last_location_study_commander ?= flag:battlefield
		}
		reference = battlefield
	}

	override_background = {
		trigger = {
			scope:last_location_study_commander ?= flag:terrain
		}
		reference = terrain
	}

	override_background = {
		trigger = {
			scope:last_location_study_commander ?= flag:study
		}
		reference = study
	}

	override_background = {
		trigger = {
			scope:last_location_study_commander ?= flag:town
		}
		reference = courtyard
	}

	left_portrait = {
		character = root
		animation = thinking
	}

	right_portrait = {
		character = scope:situation_alerter
		animation = storyteller
	}

	immediate = {
		stress_impact = {
			base = miniscule_stress_impact_gain
		}
		if = {
			limit = {
				debug_only = yes 
			}
			custom_tooltip = study_commander_trait_current_success_chance_debug
		}
		else = {
			custom_tooltip = study_commander_trait_current_success_chance
		}
		if = {
			limit = {
				scope:training_method = flag:mentor 
			}
			mentor_option_seed_effect = yes
		}
		if = {
			limit = {
				NOT = { scope:training_method = flag:mentor }
			}
			if = {
				limit = {
					any_courtier = {
						NOT = {
							this = root
						} 
						is_available_adult = yes
					}
				}
				random_courtier = {
					limit = {
						NOT = {
							this = root
						}
						is_available_adult = yes
					}
					save_scope_as = situation_alerter
				}
			}
			else = {
				create_character = {
					dynasty = none
					template = soldier_friend_character
					location = root.location
					age = { 16 30 }
					save_scope_as = situation_alerter
				}
			}
		}
		else = {
			# For loc
			scope:commander_trait_mentor = { save_scope_as = situation_alerter }
		}
		# Find random situation
		random_list = {
			15 = {
				save_scope_value_as = { # Battlefield/Terrain
					name = random_situation
					value = 1
				}
				random_list = {
					10 = {
						modifier = {
							add = 5
							OR = {
								location = { terrain = drylands }
								location = { terrain = desert }
								location = { terrain = desert_mountains }
								location = { terrain = oasis }
								any_sub_realm_barony = {
									title_province = {
										OR = {
											terrain = drylands 
											terrain = desert 
											terrain = desert_mountains 
											terrain = oasis 
										}
									}
								}
							}
						}
						modifier = {
							add = -100
							NOT = { can_weigh_trait_trigger = { TRAIT = desert_warrior } }
						}
						save_scope_value_as = { name = situation_1_terrain value = flag:desert }
					}
					10 = {
						modifier = {
							add = 5
							OR = {
								location = { terrain = jungle }
								any_sub_realm_barony = {
									title_province = {
										terrain = jungle 
									}
								}
							}
						}
						modifier = {
							add = -100
							NOT = { can_weigh_trait_trigger = { TRAIT = jungle_stalker } }
						}
						save_scope_value_as = { name = situation_1_terrain value = flag:jungle }
					}
					10 = {
						modifier = {
							add = 5
							OR = {
								location = { terrain = forest }
								location = { terrain = taiga }
								any_sub_realm_barony = {
									title_province = {
										OR = {
											terrain = forest 
											terrain = taiga 
										}
									}
								}
							}
						}
						modifier = {
							add = -100
							NOT = { can_weigh_trait_trigger = { TRAIT = forest_fighter } }
						}
						save_scope_value_as = { name = situation_1_terrain value = flag:forest }
					}
					10 = {
						modifier = {
							add = 5
							OR = {
								location = { terrain = farmlands }
								location = { terrain = plains }
								location = { terrain = steppe }
								any_sub_realm_barony = {
									title_province = {
										OR = {
											terrain = farmlands 
											terrain = plains 
											terrain = steppe 
										}
									}
								}
							}
						}
						modifier = {
							add = -100
							NOT = { can_weigh_trait_trigger = { TRAIT = open_terrain_expert } }
						}
						save_scope_value_as = { name = situation_1_terrain value = flag:plains }
					}
					10 = {
						modifier = {
							add = 5
							OR = {
								location = { terrain = hills }
								location = { terrain = mountains }
								location = { terrain = wetlands }
								any_sub_realm_barony = {
									title_province = {
										OR = {
											terrain = hills 
											terrain = mountains 
											terrain = wetlands 
										}
									}
								}
							}
						}
						modifier = {
							add = -100
							NOT = { can_weigh_trait_trigger = { TRAIT = rough_terrain_expert } }
						}
						save_scope_value_as = { name = situation_1_terrain value = flag:mountains }
					}
					20 = {
						trigger = {
							current_season_trigger = { SEASON = winter }
						}
						modifier = {
							add = -100
							NOT = { 
								can_weigh_trait_trigger = { TRAIT = reaver }
								can_weigh_trait_trigger = { TRAIT = winter_soldier }
							}
						}
						save_scope_value_as = { name = situation_1_terrain value = flag:winter_terrain }
					}
				}
			}
			10 = {
				save_scope_value_as = { # Siege
					name = random_situation
					value = 2
				}
			}
			10 = {
				save_scope_value_as = { # Sabotage
					name = random_situation
					value = 3
				}
			}
		}
		
	}

	option = { 
		name = mpo_decisions_events.0202.martial_situation_1
		trigger = {
			scope:random_situation = 1
		}
		flavor = mpo_decisions_events.0202.martial_situation_1_flavor
		if = {
			limit = {
				scope:training_method = flag:mentor
			}
			study_commander_trait_option_mentor = {
				DUEL = yes
				SKILL = martial
				SUCCESS_DESC = mpo_decisions_events.0202.success
				FAIL_DESC = mpo_decisions_events.0202.fail
				WOUND_CHANCE = no
			}
		}
		else = {
			study_commander_trait_option_no_mentor = {
				DUEL = yes
				SKILL = martial
				SUCCESS_DESC = mpo_decisions_events.0202.success
				FAIL_DESC = mpo_decisions_events.0202.fail
				WOUND_CHANCE = no
			}
		}
		switch = {
			trigger = scope:situation_1_terrain
			flag:desert = {
				trait_weighting_effect = {
					WEIGHTED_TRAIT = desert_warrior
					WEIGHT = 20
				}
			}
			flag:jungle = {
				trait_weighting_effect = {
					WEIGHTED_TRAIT = jungle_stalker
					WEIGHT = 20
				}
			}
			flag:forest = {
				trait_weighting_effect = {
					WEIGHTED_TRAIT = forest_fighter
					WEIGHT = 20
				}
			}
			flag:plains = {
				trait_weighting_effect = {
					WEIGHTED_TRAIT = open_terrain_expert
					WEIGHT = 20
				}
			}
			flag:mountains = {
				trait_weighting_effect = {
					WEIGHTED_TRAIT = rough_terrain_expert
					WEIGHT = 20
				}
			}
			flag:winter_terrain = {
				random_list = {
					1 = {
						trigger = { can_weigh_trait_trigger = { TRAIT = reaver } }
						trait_weighting_effect = {
							WEIGHTED_TRAIT = reaver
							WEIGHT = 15
						}
					}
					1 = {
						trigger = { can_weigh_trait_trigger = { TRAIT = winter_soldier } }
						trait_weighting_effect = {
							WEIGHTED_TRAIT = winter_soldier
							WEIGHT = 15
						}
					}
				}
			}
			flag:wetlands = {
				trait_weighting_effect = {
					WEIGHTED_TRAIT = forder
					WEIGHT = 20
				}
			}
			flag:floodplains = {
				trait_weighting_effect = {
					WEIGHTED_TRAIT = forder
					WEIGHT = 20
				}
			}
		}
		ai_chance = {
			base = 150
			modifier = {
				factor = 1.5
				highest_skill = martial
			}
			modifier = {
				factor = 1.2
				martial >= decent_skill_rating
			}
		}
	}

	option = { 
		name = mpo_decisions_events.0202.martial_situation_2
		trigger = {
			scope:random_situation = 2
			OR = {
				scope:training_method = flag:martial 
				scope:mentor_option_seed ?= 1
			}
		}
		flavor = mpo_decisions_events.0202.martial_situation_2_flavor
		if = {
			limit = {
				scope:training_method = flag:mentor
			}
			study_commander_trait_option_mentor = {
				DUEL = yes
				SKILL = martial
				SUCCESS_DESC = mpo_decisions_events.0202.success
				FAIL_DESC = mpo_decisions_events.0202.fail
				WOUND_CHANCE = no
			}
		}
		else = {
			study_commander_trait_option_no_mentor = {
				DUEL = yes
				SKILL = martial
				SUCCESS_DESC = mpo_decisions_events.0202.success
				FAIL_DESC = mpo_decisions_events.0202.fail
				WOUND_CHANCE = no
			}
		}
		trait_weighting_effect = {
			WEIGHTED_TRAIT = aggressive_attacker
			WEIGHT = 20
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 1.5
				highest_skill = martial
			}
			modifier = {
				factor = 1.2
				martial >= decent_skill_rating
			}
			modifier = {
				factor = 0
				has_trait = aggressive_attacker
			}
		}
	}

	option = { 
		name = mpo_decisions_events.0202.martial_situation_3
		trigger = {
			scope:random_situation = 3
			OR = {
				scope:training_method = flag:martial 
				scope:mentor_option_seed ?= 2
			}
		}
		flavor = mpo_decisions_events.0202.martial_situation_3_flavor
		if = {
			limit = {
				scope:training_method = flag:mentor
			}
			study_commander_trait_option_mentor = {
				DUEL = yes
				SKILL = martial
				SUCCESS_DESC = mpo_decisions_events.0202.success
				FAIL_DESC = mpo_decisions_events.0202.fail
				WOUND_CHANCE = no
			}
		}
		else = {
			study_commander_trait_option_no_mentor = {
				DUEL = yes
				SKILL = martial
				SUCCESS_DESC = mpo_decisions_events.0202.success
				FAIL_DESC = mpo_decisions_events.0202.fail
				WOUND_CHANCE = no
			}
		}
		random = {
			chance = 10
			if = {
				limit = {
					has_trait = craven
				}
				remove_trait = craven
			}
			add_trait = brave 
		}
		ai_chance = {
			base = 100
		}
	}

	option = { 
		name = mpo_decisions_events.0202.learning_situation_1
		trigger = {
			scope:random_situation = 1
			OR = {
				scope:training_method = flag:learning 
				scope:mentor_option_seed ?= 2
			}
		}
		flavor = mpo_decisions_events.0202.learning_situation_1_flavor
		if = {
			limit = {
				scope:training_method = flag:mentor
			}
			study_commander_trait_option_mentor = {
				DUEL = yes
				SKILL = learning
				SUCCESS_DESC = mpo_decisions_events.0202.success
				FAIL_DESC = mpo_decisions_events.0202.fail
				WOUND_CHANCE = no
			}
		}
		else = {
			study_commander_trait_option_no_mentor = {
				DUEL = yes
				SKILL = learning
				SUCCESS_DESC = mpo_decisions_events.0202.success
				FAIL_DESC = mpo_decisions_events.0202.fail
				WOUND_CHANCE = no
			}
		}
		trait_weighting_effect = {
			WEIGHTED_TRAIT = flexible_leader
			WEIGHT = 20
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 1.5
				highest_skill = learning
			}
			modifier = {
				factor = 1.2
				learning >= decent_skill_rating
			}
			modifier = {
				factor = 0
				has_trait = flexible_leader
			}
		}
	}

	option = { 
		name = mpo_decisions_events.0202.learning_situation_2
		trigger = {
			scope:random_situation = 2
		}
		flavor = mpo_decisions_events.0202.learning_situation_2_flavor
		if = {
			limit = {
				scope:training_method = flag:mentor
			}
			study_commander_trait_option_mentor = {
				DUEL = yes
				SKILL = learning
				SUCCESS_DESC = mpo_decisions_events.0202.success
				FAIL_DESC = mpo_decisions_events.0202.fail
				WOUND_CHANCE = no
			}
		}
		else = {
			study_commander_trait_option_no_mentor = {
				DUEL = yes
				SKILL = learning
				SUCCESS_DESC = mpo_decisions_events.0202.success
				FAIL_DESC = mpo_decisions_events.0202.fail
				WOUND_CHANCE = no
			}
		}
		trait_weighting_effect = {
			WEIGHTED_TRAIT = military_engineer
			WEIGHT = 20
		}
		ai_chance = {
			base = 150
			modifier = {
				factor = 1.5
				highest_skill = learning
			}
			modifier = {
				factor = 1.2
				learning >= decent_skill_rating
			}
			modifier = {
				factor = 0
				has_trait = military_engineer
			}
		}
	}

	option = { 
		name = mpo_decisions_events.0202.learning_situation_3
		trigger = {
			scope:random_situation = 3
			OR = {
				scope:training_method = flag:learning 
				scope:mentor_option_seed ?= 2
			}
		}
		flavor = mpo_decisions_events.0202.learning_situation_3_flavor
		if = {
			limit = {
				scope:training_method = flag:mentor
			}
			study_commander_trait_option_mentor = {
				DUEL = yes
				SKILL = learning
				SUCCESS_DESC = mpo_decisions_events.0202.success
				FAIL_DESC = mpo_decisions_events.0202.fail
				WOUND_CHANCE = no
			}
		}
		else = {
			study_commander_trait_option_no_mentor = {
				DUEL = yes
				SKILL = learning
				SUCCESS_DESC = mpo_decisions_events.0202.success
				FAIL_DESC = mpo_decisions_events.0202.fail
				WOUND_CHANCE = no
			}
		}
		trait_weighting_effect = {
			WEIGHTED_TRAIT = reckless
			WEIGHT = -5
		}
		ai_chance = {
			base = 75
			modifier = {
				factor = 1.5
				highest_skill = learning
			}
			modifier = {
				factor = 1.2
				learning >= decent_skill_rating
			}
		}
	}

	option = { 
		name = mpo_decisions_events.0202.intrigue_situation_1
		trigger = {
			scope:random_situation = 1
			OR = {
				scope:training_method = flag:intrigue 
				scope:mentor_option_seed ?= 1
			}
		}
		flavor = mpo_decisions_events.0202.intrigue_situation_1_flavor
		if = {
			limit = {
				scope:training_method = flag:mentor
			}
			study_commander_trait_option_mentor = {
				DUEL = yes
				SKILL = intrigue
				SUCCESS_DESC = mpo_decisions_events.0202.success
				FAIL_DESC = mpo_decisions_events.0202.fail
				WOUND_CHANCE = no
			}
		}
		else = {
			study_commander_trait_option_no_mentor = {
				DUEL = yes
				SKILL = intrigue
				SUCCESS_DESC = mpo_decisions_events.0202.success
				FAIL_DESC = mpo_decisions_events.0202.fail
				WOUND_CHANCE = no
			}
		}
		trait_weighting_effect = {
			WEIGHTED_TRAIT = organizer
			WEIGHT = 20
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 1.5
				highest_skill = intrigue
			}
			modifier = {
				factor = 1.2
				intrigue >= decent_skill_rating
			}
			modifier = {
				factor = 0
				has_trait = organizer
			}
		}
	}

	option = { 
		name = mpo_decisions_events.0202.intrigue_situation_2
		trigger = {
			scope:random_situation = 2
			OR = {
				scope:training_method = flag:intrigue 
				scope:mentor_option_seed ?= 2
			}
		}
		flavor = mpo_decisions_events.0202.intrigue_situation_2_flavor
		if = {
			limit = {
				scope:training_method = flag:mentor
			}
			study_commander_trait_option_mentor = {
				DUEL = yes
				SKILL = intrigue
				SUCCESS_DESC = mpo_decisions_events.0202.success
				FAIL_DESC = mpo_decisions_events.0202.fail
				WOUND_CHANCE = no
			}
		}
		else = {
			study_commander_trait_option_no_mentor = {
				DUEL = yes
				SKILL = intrigue
				SUCCESS_DESC = mpo_decisions_events.0202.success
				FAIL_DESC = mpo_decisions_events.0202.fail
				WOUND_CHANCE = no
			}
		}
		trait_weighting_effect = {
			WEIGHTED_TRAIT = reckless
			WEIGHT = 20
		}
		trait_weighting_effect = {
			WEIGHTED_TRAIT = cautious_leader
			WEIGHT = -5
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 1.5
				highest_skill = intrigue
			}
			modifier = {
				factor = 1.2
				intrigue >= decent_skill_rating
			}
			modifier = {
				factor = 0
				has_trait = reckless
			}
		}
	}

	option = { 
		name = mpo_decisions_events.0202.intrigue_situation_3
		trigger = {
			scope:random_situation = 3
		}
		trait_weighting_effect = {
			WEIGHTED_TRAIT = cautious_leader
			WEIGHT = 20
		}
		flavor = mpo_decisions_events.0202.intrigue_situation_3_flavor
		if = {
			limit = {
				scope:training_method = flag:mentor
			}
			study_commander_trait_option_mentor = {
				DUEL = yes
				SKILL = intrigue
				SUCCESS_DESC = mpo_decisions_events.0202.success
				FAIL_DESC = mpo_decisions_events.0202.fail
				WOUND_CHANCE = no
			}
		}
		else = {
			study_commander_trait_option_no_mentor = {
				DUEL = yes
				SKILL = intrigue
				SUCCESS_DESC = mpo_decisions_events.0202.success
				FAIL_DESC = mpo_decisions_events.0202.fail
				WOUND_CHANCE = no
			}
		}
		ai_chance = {
			base = 150
			modifier = {
				factor = 1.5
				highest_skill = intrigue
			}
			modifier = {
				factor = 1.2
				intrigue >= decent_skill_rating
			}
			modifier = {
				factor = 0
				has_trait = cautious_leader
			}
		}
	}

	option = { 
		name = mpo_decisions_events.0202.none_situation_1
		trigger = {
			scope:random_situation = 1
		}
		flavor = mpo_decisions_events.0202.none_situation_1_flavor
		study_commander_trait_option_no_mentor = {
			DUEL = no
			SKILL = martial
			SUCCESS_DESC = mpo_decisions_events.0202.success
			FAIL_DESC = mpo_decisions_events.0202.fail
			WOUND_CHANCE = yes
		}
		trait_weighting_effect = {
			WEIGHTED_TRAIT = unyielding_defender
			WEIGHT = 5
		}
		trait_weighting_effect = {
			WEIGHTED_TRAIT = aggressive_attacker
			WEIGHT = -5
		}
		ai_chance = {
			base = 75
			modifier = {
				factor = 0
				has_trait = unyielding_defender
			}
		}
	}

	option = { 
		name = mpo_decisions_events.0202.none_situation_2
		trigger = {
			scope:random_situation = 2
		}
		flavor = mpo_decisions_events.0202.none_situation_2_flavor
		trait_weighting_effect = {
			WEIGHTED_TRAIT = cautious_leader
			WEIGHT = 20
		}
		study_commander_trait_option_no_mentor = {
			DUEL = no
			SKILL = learning
			SUCCESS_DESC = mpo_decisions_events.0202.success
			FAIL_DESC = mpo_decisions_events.0202.fail
			WOUND_CHANCE = yes
		}
		ai_chance = {
			base = 75
		}
	}

	option = { 
		name = mpo_decisions_events.0202.none_situation_3
		trigger = {
			scope:random_situation = 3
		}
		flavor = mpo_decisions_events.0202.none_situation_3_flavor
		study_commander_trait_option_no_mentor = {
			DUEL = no
			SKILL = intrigue
			SUCCESS_DESC = mpo_decisions_events.0202.success
			FAIL_DESC = mpo_decisions_events.0202.fail
			WOUND_CHANCE = yes
		}
		add_dread = miniscule_dread_gain
		ai_chance = {
			base = 75
		}
	}

	after = {
		trigger_event = {
			id = mpo_decisions_events.0203
			days = { 3 7 }
		}
		if = {
			limit = {
				NOR = { 
					scope:situation_alerter = { is_courtier_of = root }
					scope:commander_trait_mentor ?= scope:situation_alerter
				}
			}
			scope:situation_alerter = {
				silent_disappearance_effect = yes
			}
		}
	}
}

mpo_decisions_events.0203 = { # Reflection
	type = character_event
	title = mpo_decisions_events.0203.t
	desc = {
		desc = mpo_decisions_events.0203.desc_intro
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:training_method = flag:mentor
				}
				desc = mpo_decisions_events.0203.desc_mentor
			}
			desc = mpo_decisions_events.0203.desc
		}
	}
	theme = nomads

	override_background = {
		reference = study
	}

	left_portrait = {
		character = root
		animation = thinking
	}

	right_portrait = {
		trigger = {
			scope:training_method = flag:mentor
		}
		character = scope:commander_trait_mentor
		animation = storyteller
	}

	lower_center_portrait = {
		trigger = {
			exists = scope:heir_person
		}
		character = scope:heir_person
	}

	lower_right_portrait = {
		trigger = {
			exists = scope:love_person
		}
		character = scope:love_person
	}

	lower_left_portrait = {
		trigger = {
			exists = scope:hate_person
		}
		character = scope:hate_person
	}

	immediate = {
		stress_impact = {
			base = miniscule_stress_impact_gain
		}
		if = {
			limit = {
				debug_only = yes 
			}
			custom_tooltip = study_commander_trait_current_success_chance_debug
		}
		else = {
			custom_tooltip = study_commander_trait_current_success_chance
		}
		# Get some people
		# Heir (family member or designated)
		if = {
			limit = {
				any_close_family_member = {
					is_player_heir_of = root
					is_primary_heir_of = root
				}
			}
			random_close_family_member = {
				limit = { 
					OR = {
						is_player_heir_of = root
						is_primary_heir_of = root
					}
				}
				save_scope_as = heir_person
			}
		}
		else_if = {
			limit = {
				exists = designated_heir
			}
			designated_heir = { save_scope_as = heir_person }
		}
		# Lover / Spouse
		if = {
			limit = {
				any_spouse = { count >= 1 }
			}
			ordered_spouse = {
				order_by = {
					value = 10
					if = {
						limit = {
							has_opinion_modifier = {
								modifier = love_opinion
								target = root
							}
						}
						add = 25
					}
				}
				save_scope_as = love_person
			}
		}
		else_if = {
			limit = {
				num_of_relation_lover >= 1
			}
			ordered_relation = {
				type = lover
				order_by = "opinion(root)"
				save_scope_as = love_person
			}
		}
		# Rival(s)
		if = {
			limit = {
				num_of_relation_rival >= 1
			}
			random_relation = {
				type = rival 
				save_scope_as = hate_person
			}
		}
	}

	option = { # Heir (if they're your relative or designated heir)
		name = mpo_decisions_events.0203.a
		trigger = {
			exists = scope:heir_person
		}
		dynasty = {
			add_dynasty_prestige = miniscule_dynasty_prestige_gain
		}
		if = {
			limit = {
				OR = {
					scope:heir_person = {
						has_relation_friend = root
					}
					has_trait = family_first
				}
			}
			stress_impact = {
				base = minor_stress_impact_loss
			}
		}
		if = {
			limit = {
				scope:heir_person = {
					opinion = {
						target = root
						value >= 40
					}
				}
			}
			scope:heir_person = { save_scope_as = target_person } # For loc
			custom_tooltip = mpo_decisions_events.0203.sentiment
			localize_study_commander_success_chance_change = {
				VALUE = 25
			}
		}
		else_if = {
			limit = {
				scope:heir_person = {
					opinion = {
						target = root
						value >= 15
					}
				}
			}
			scope:heir_person = { save_scope_as = target_person } # For loc
			custom_tooltip = mpo_decisions_events.0203.sentiment
			localize_study_commander_success_chance_change = {
				VALUE = 10
			}
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 1.5
				has_trait = family_first
			}
			opinion_modifier = {
				opinion_target = scope:heir_person
				multiplier = 0.5
			}
		}
	}

	option = { # Lover or Spouse
		name = mpo_decisions_events.0203.b
		trigger = {
			exists = scope:love_person
		}
		
		if = {
			limit = {
				scope:love_person = {
					opinion = {
						target = root
						value >= 40
					}
				}
			}
			scope:love_person = { save_scope_as = target_person } # For loc
			custom_tooltip = mpo_decisions_events.0203.sentiment
			localize_study_commander_success_chance_change = {
				VALUE = 25
			}
		}
		else_if = {
			limit = {
				scope:love_person = {
					opinion = {
						target = root
						value >= 15
					}
				}
			}
			scope:love_person = { save_scope_as = target_person } # For loc
			custom_tooltip = mpo_decisions_events.0203.sentiment
			localize_study_commander_success_chance_change = {
				VALUE = 10
			}
		}
		if = {
			limit = {
				scope:love_person = {
					OR = {
						has_opinion_modifier = {
							modifier = love_opinion
							target = root
						}
						has_relation_lover = root
					}
				}
			}
			stress_impact = {
				base = minor_stress_impact_loss
				lustful = minor_stress_impact_loss
			}
		}
		scope:love_person = {
			add_opinion = {
				target = root
				modifier = love_opinion
				opinion = 15
			}
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 1.5
				has_trait = lustful
			}
			opinion_modifier = {
				opinion_target = scope:love_person
				multiplier = 0.5
			}
		}
	}

	option = { # Rival(s) / Enemies
		name = {
			text = {
				triggered_desc = {
					trigger = {
						exists = scope:hate_person
					}
					desc = mpo_decisions_events.0203.c_rival
				}
				desc = mpo_decisions_events.0203.c
			}
		}
		trait_weighting_effect = {
			WEIGHTED_TRAIT = aggressive_attacker
			WEIGHT = 20
		}
		stress_impact = {
			vengeful = minor_stress_impact_loss
		}
		if = {
			limit = {
				exists = scope:hate_person
				scope:hate_person = {
					opinion = {
						target = root
						value <= -40
					}
				}
			}
			scope:hate_person = { save_scope_as = target_person } # For loc
			custom_tooltip = mpo_decisions_events.0203.sentiment
			localize_study_commander_success_chance_change = {
				VALUE = 25
			}
		}
		else_if = {
			limit = {
				exists = scope:hate_person
				scope:hate_person ?= {
					opinion = {
						target = root
						value <= -15
					}
				}
			}
			scope:hate_person = { save_scope_as = target_person } # For loc
			custom_tooltip = mpo_decisions_events.0203.sentiment
			localize_study_commander_success_chance_change = {
				VALUE = 10
			}
		}
		else_if = {
			limit = {
				dread > 40
			}
			custom_tooltip = mpo_decisions_events.0203.dread
			localize_study_commander_success_chance_change = {
				VALUE = 25
			}
		}
		else_if = {
			limit = {
				dread > 15
			}
			custom_tooltip = mpo_decisions_events.0203.dread
			localize_study_commander_success_chance_change = {
				VALUE = 10
			}
		}
		add_dread = miniscule_dread_gain
		ai_chance = {
			base = 100
			modifier = {
				factor = 1.5
				has_trait = vengeful
			}
			modifier = {
				factor = 1.2
				has_trait = wrathful
			}
			modifier = {
				factor = 0 
				NOT = { can_weigh_trait_trigger = { TRAIT = aggressive_attacker } }
			}
		}
	}

	option = { # Title 
		name = {
			text = {
				triggered_desc = {
					trigger = {
						is_landed = no
					}
					desc = mpo_decisions_events.0203.d_landless
				}
				desc = mpo_decisions_events.0203.d
			}
		}
		stress_impact = {
			ambitious = minor_stress_impact_loss
		}
		if = {
			limit = {
				prestige_level >= 4
			}
			custom_tooltip = mpo_decisions_events.0203.prestige
			localize_study_commander_success_chance_change = {
				VALUE = 25
			}
		}
		else_if = {
			limit = {
				prestige_level >= 2
			}
			custom_tooltip = mpo_decisions_events.0203.prestige
			localize_study_commander_success_chance_change = {
				VALUE = 10
			}
		}
		add_prestige = miniscule_prestige_gain
		ai_chance = {
			base = 110
			modifier = {
				factor = 1.25
				has_trait = ambitious
			}
		}
	}

	option = { # Faith
		name = mpo_decisions_events.0203.e
		trigger = {
			NOT = { has_trait = cynical }
		}
		stress_impact = {
			zealous = minor_stress_impact_loss
		}
		trait_weighting_effect = {
			WEIGHTED_TRAIT = holy_warrior
			WEIGHT = 15
		}
		if = {
			limit = {
				piety_level >= 4
			}
			custom_tooltip = mpo_decisions_events.0203.piety
			localize_study_commander_success_chance_change = {
				VALUE = 25
			}
		}
		else_if = {
			limit = {
				piety_level >= 2
			}
			custom_tooltip = mpo_decisions_events.0203.piety
			localize_study_commander_success_chance_change = {
				VALUE = 10
			}
		}
		add_piety = miniscule_piety_gain
		ai_chance = {
			base = 110
			modifier = {
				factor = 1.25
				has_trait = zealous
			}
			modifier = {
				factor = 0 
				NOT = { can_weigh_trait_trigger = { TRAIT = holy_warrior } }
			}
		}
	}

	after = {
		trigger_event = {
			id = mpo_decisions_events.0204
			days = { 3 7 }
		}
	}
}

mpo_decisions_events.0204 = { # Get Trait - Or not!
	type = character_event
	title = mpo_decisions_events.0204.t
	desc = {
		desc = mpo_decisions_events.0204.desc
		triggered_desc = {
			trigger = {
				scope:training_method = flag:mentor
			}
			desc = mpo_decisions_events.0204.desc_mentor
		}
	}
	theme = nomads

	left_portrait = {
		character = root
		animation = marshal
	}

	right_portrait = {
		trigger = {
			scope:training_method = flag:mentor
		}
		character = scope:commander_trait_mentor
		animation = admiration
	}

	option = { # Ok
		name = mpo_decisions_events.0204.a
		if = {
			limit = {
				scope:training_method = flag:mentor
			}
			reverse_add_opinion = {
				modifier = grateful_opinion
				target = scope:commander_trait_mentor
				opinion = 30
			}
		}
		random_list = {
			1 = {
				modifier = {
					always = yes
					add = study_commander_trait_success_chance_value
				}
				custom_tooltip = mpo_decisions_events.0204.a_success
				if = {
					limit = {
						number_of_commander_traits <= 1 # Because otherwise they hit limit and can't actually retry
					}
					custom_tooltip = mpo_decisions_events.0204.a_success_desc
				}
				hidden_effect = {
					random_list = { # A little less likely to get the terrain ones cuz they're more situational
						10 = { 
							trigger = { can_weigh_trait_trigger = { TRAIT = logistician } }
							modifier = { has_variable = logistician_weight add = var:logistician_weight }
							add_trait = logistician
						}
						10 = { 
							trigger = { can_weigh_trait_trigger = { TRAIT = military_engineer } }
							modifier = { has_variable = military_engineer_weight add = var:military_engineer_weight }
							add_trait = military_engineer
						}
						10 = { 
							trigger = { can_weigh_trait_trigger = { TRAIT = aggressive_attacker } }
							modifier = { has_variable = aggressive_attacker_weight add = var:aggressive_attacker_weight }
							add_trait = aggressive_attacker
						}
						10 = { 
							trigger = { can_weigh_trait_trigger = { TRAIT = unyielding_defender } }
							modifier = { has_variable = unyielding_defender_weight add = var:unyielding_defender_weight }
							add_trait = unyielding_defender
						}
						5 = { 
							trigger = { can_weigh_trait_trigger = { TRAIT = forder } }
							modifier = { has_variable = forder_weight add = var:forder_weight }
							add_trait = forder
						}
						10 = { 
							trigger = { can_weigh_trait_trigger = { TRAIT = flexible_leader } }
							modifier = { has_variable = flexible_leader_weight add = var:flexible_leader_weight }
							add_trait = flexible_leader
						}
						5 = { 
							trigger = { can_weigh_trait_trigger = { TRAIT = desert_warrior } }
							modifier = { has_variable = desert_warrior_weight add = var:desert_warrior_weight }
							add_trait = desert_warrior
						}
						5 = { 
							trigger = { can_weigh_trait_trigger = { TRAIT = jungle_stalker } }
							modifier = { has_variable = jungle_stalker_weight add = var:jungle_stalker_weight }
							add_trait = jungle_stalker
						}
						10 = { 
							trigger = { can_weigh_trait_trigger = { TRAIT = reaver } }
							modifier = { has_variable = reaver_weight add = var:reaver_weight }
							add_trait = reaver
						}
						10 = { 
							trigger = { can_weigh_trait_trigger = { TRAIT = reckless } }
							modifier = { has_variable = reckless_weight add = var:reckless_weight }
							add_trait = reckless
						}
						10 = { 
							trigger = { can_weigh_trait_trigger = { TRAIT = holy_warrior } }
							modifier = { has_variable = holy_warrior_weight add = var:holy_warrior_weight }
							modifier = { has_trait = zealous add = 5 }
							modifier = { has_trait = cynical add = -5 }
							add_trait = holy_warrior
						}
						5 = { 
							trigger = { can_weigh_trait_trigger = { TRAIT = open_terrain_expert } }
							modifier = { has_variable = open_terrain_expert_weight add = var:open_terrain_expert_weight }
							add_trait = open_terrain_expert
						}
						5 = { 
							trigger = { can_weigh_trait_trigger = { TRAIT = rough_terrain_expert } }
							modifier = { has_variable = rough_terrain_expert_weight add = var:rough_terrain_expert_weight }
							add_trait = rough_terrain_expert
						}
						5 = { 
							trigger = { can_weigh_trait_trigger = { TRAIT = forest_fighter } }
							modifier = { has_variable = forest_fighter_weight add = var:forest_fighter_weight }
							add_trait = forest_fighter
						}
						10 = { 
							trigger = { can_weigh_trait_trigger = { TRAIT = cautious_leader } }
							modifier = { has_variable = cautious_leader_weight add = var:cautious_leader_weight }
							add_trait = cautious_leader
						}
						10 = { 
							trigger = { can_weigh_trait_trigger = { TRAIT = organizer } }
							modifier = { has_variable = organizer_weight add = var:organizer_weight }
							add_trait = organizer
						}
						10 = { 
							trigger = { can_weigh_trait_trigger = { TRAIT = winter_soldier } }
							modifier = { has_variable = winter_soldier_weight add = var:winter_soldier_weight }
							add_trait = winter_soldier
						}
					}
				}
				add_character_flag = {
					flag = study_commander_trait_cooldown
					years = 10
				}
			}
			100 = {
				modifier = {
					always = yes
					add = study_commander_trait_success_chance_value_neg
				}
				custom_tooltip = mpo_decisions_events.0204.a_fail
				send_interface_toast = {
					title = mpo_decisions_events.0204.a_fail
					type = event_toast_effect_bad
					left_icon = root
					custom_tooltip = mpo_decisions_events.0204.a_fail_desc
				}
				add_character_flag = {
					flag = study_commander_trait_cooldown
					years = 5
				}
			}
		}
	}

	after = {
		if = {
			limit = {
				NOT = { has_variable = study_commander_trait_tally }
			}
			set_variable = {
				name = study_commander_trait_tally
				value = 0
			}
		}
		change_variable = {
			name = study_commander_trait_tally
			add = 1
		}
		if = {
			limit = {
				number_of_commander_traits = commander_trait_limit
			}
			remove_variable = study_commander_trait_tally
		}
		# Remove vars
		remove_variable = winter_soldier_weight
		remove_variable = organizer_weight
		remove_variable = cautious_leader_weight
		remove_variable = forest_fighter_weight
		remove_variable = rough_terrain_expert_weight
		remove_variable = open_terrain_expert_weight
		remove_variable = holy_warrior_weight
		remove_variable = reckless_weight
		remove_variable = reaver_weight
		remove_variable = jungle_stalker_weight
		remove_variable = desert_warrior_weight
		remove_variable = flexible_leader_weight
		remove_variable = forder_weight
		remove_variable = unyielding_defender_weight
		remove_variable = aggressive_attacker_weight
		remove_variable = military_engineer_weight
		remove_variable = logistician_weight
		remove_variable = study_commander_trait_success_chance_var
		remove_character_flag = is_learning_commander_trait
	}
}

#Fertility Dance event
mpo_decisions_events.0300 = {
	type = character_event
	title = mpo_decisions_events.0300.t
	desc = mpo_decisions_events.0300.desc
	theme = nomads
	override_background = { reference = temple }
	
	left_portrait = {
		character = root
		animation = prayer
	}

	right_portrait = {
		character = scope:shaman
		animation = personality_zealous
	}

	immediate = {
		court_position:court_astrologer_court_position = { save_scope_as = shaman }
	}
	
	# Regular option
	option = {
		name = mpo_decisions_events.0300.a
		if = {
			limit = {
				scope:fertility_county = { county_fertility >= 90 }
			}
			scope:fertility_county = {
				change_county_fertility = fertility_dance_bonus_value
			}
		}
		else = {
			scope:fertility_county = {
				add_county_modifier = {
					modifier = mpo_fertility_dance_county_modifier
					years = 5
				}
			}
		}
		if = {
			limit = {
				domicile ?= {
					has_domicile_parameter = nomad_yurt_improved_fertility_dance
				}
			}
			scope:fertility_county = {
				every_neighboring_county = {
					limit = {
						OR = {
							holder = root
							holder = {
								government_has_flag = government_is_herder
							}
						}
					}
					add_county_modifier = {
						modifier = mpo_fertility_dance_county_modifier
						years = 2
					}
				}
			}
		}

		ai_chance = {
			base = 50
		}
	}
}

# Pax Mongolica event
mpo_decisions_events.0400 = {
	type = character_event
	title = mpo_decisions_events.0400.t
	desc = mpo_decisions_events.0400.desc
	theme = nomads
	override_background = { reference = mpo_city_steppe }

	left_portrait = {
		character = root
		animation = horse_archer_idle
		camera = camera_event_horse_left
	}
	
	right_portrait = {
		character = scope:courtier
		animation = obsequious_bow
	}
	
	immediate = {
		if = {
			limit = {
				any_courtier = {
					is_available_ai_adult = yes
				}
			}
			ordered_courtier = {
				limit = {
					is_available_ai_adult = yes
				}
				order_by = stewardship
				save_scope_as = courtier
			}
		}
		else = {
			create_character = {
				location = root.capital_province
				template = merchant_template
				culture = root.location.culture
				faith = root.location.faith
				save_scope_as = merchant
			}
		}
	}
	
	# Happy day
	option = {
		name = mpo_decisions_events.0400.a
		add_character_modifier = {
			modifier = pax_mongolica_ruler_modifier # Forever
		}
		custom_tooltip = pax_mongolica_every_county_in_steppe_tt
		every_realm_county = {
			limit = {
				is_landless_type_title = no
				any_county_situation = { this = situation:the_great_steppe }
				holder.dynasty = root.dynasty
			}
			random_county_province = {
				limit = { has_holding = no }
				set_holding_type = city_holding
			}
		}
		culture = {
			if = {
				limit = { 
					NOT = { has_innovation = innovation_city_planning }
				}
				add_innovation = innovation_city_planning
			}
			else_if = {
				limit = { 
					NOT = { has_innovation = innovation_development_01 }
				}
				add_innovation = innovation_development_01
			}
			else = {
				add_random_innovation = culture_group_civic
			}
		}
		
		ai_chance = {
			base = 50
		}
	}
}

# Desperate Stance event
mpo_decisions_events.0500 = {
	type = character_event
	title = mpo_decisions_events.0500.t
	desc = mpo_decisions_events.0500.desc
	theme = nomads
	override_background = { reference = mpo_campfire_steppe }

	left_portrait = {
		character = root
		animation = worry
	}
	
	right_portrait = {
		character = scope:courtier
		animation = beg
	}
	
	immediate = {
		if = {
			limit = {
				any_spouse = { count >= 1 }
			}
			random_spouse = {
				save_scope_as = courtier
			}
		}
		else_if = {
			limit = {
				any_child = { count >= 1 }
			}
			random_child = {
				save_scope_as = courtier
			}
		}
		else_if = {
			limit = {
				any_courtier_or_guest = { count >= 1 }
			}
			random_courtier_or_guest = {
				limit = { is_available_ai_adult = yes }
				save_scope_as = courtier
			}
		}
		else = {
			create_character = {
				location = root.location
				dynasty = none
				culture = root.location.culture
				faith = root.location.faith
				gender_female_chance = 50
				template = peasant_character
				save_scope_as = courtier
			}
		}
		hidden_effect = {
			scope:courtier = {
				change_current_weight = -50
			}
		}
	}
	
	# Let's get out of here
	option = {
		name = mpo_decisions_events.0500.a
		mpo_decisions_events_0500_effect = yes
		ai_chance = {
			base = 100
		}
	}
}

# Invite Stargazer
scripted_trigger mpo_decisions_events_0070_basic_requirements_trigger = {
	is_adult = yes
	is_imprisoned = no
	is_alive = yes # Because apparently there can be dead characters in the pool (remove when fixed)
	is_claimant = no # We don't want recruiting physicians to be a cheap way of getting claimants
	learning >= low_skill_rating
}

scripted_trigger mpo_decisions_events_0070_low_skill_trigger = {
	mpo_decisions_events_0070_basic_requirements_trigger = yes
	#Empire/kingdom
	trigger_if = {
		limit = {
			root = { highest_held_title_tier >= tier_kingdom }
		}
		learning <= high_skill_rating
		learning >= mediocre_skill_rating # 8
	}
	#Duchy/county
	trigger_else = {
		learning <= decent_skill_rating
		learning >= low_skill_rating # 5
	}
}

scripted_trigger mpo_decisions_events_0070_high_skill_trigger = {
	mpo_decisions_events_0070_basic_requirements_trigger = yes
	#Empire/kingdom
	trigger_if = {
		limit = {
			root = { highest_held_title_tier >= tier_kingdom }
		}
		learning <= extremely_high_skill_rating
		learning >= decent_skill_rating # 12
	}
	#Duchy/county
	trigger_else = {
		learning <= high_skill_rating
		learning >= medium_skill_rating  # 10
	}
}
mpo_decisions_events.0070 = { 
	type = character_event
	title = mpo_decisions_events.0070.t
	desc = mpo_decisions_events.0070.desc
	theme = nomads
	left_portrait = {
		character = scope:great_court_astrologer_option 
		animation = holding_staff
		camera = camera_event_left_forward
	}
	right_portrait = {
		character = scope:good_court_astrologer_option
		animation = personality_zealous
		camera = camera_event_right_forward
	}
	override_background = {
		reference = mpo_temple_steppe
	}
	trigger = {
		exists = capital_province 
	}
	immediate = {
		# Good Character
		if = { # check for a GOOD character in the pool
			limit = {
				any_pool_character = {
					province = root.capital_province
					mpo_decisions_events_0070_low_skill_trigger = yes
					can_be_employed_as = court_astrologer_court_position
				}
			}
			random_pool_character = {
				province = root.capital_province
				limit = {
					mpo_decisions_events_0070_low_skill_trigger = yes
					can_be_employed_as = court_astrologer_court_position
				}
				save_scope_as = good_court_astrologer_option
			}
		}
		else = { # otherwise create one
			create_character = {
				location = root.capital_province
				gender_female_chance = root_faith_clergy_gender_female_chance
				template_character = root
				random_traits = yes
				random_traits_list = {
					count = 1
					education_learning_1 = {}
					education_learning_2 = {}
				}
				age = { 18 50 }
				learning = {
					min_template_medium_skill
					max_template_decent_skill
				}
				save_scope_as = good_court_astrologer_option
			}
			hidden_effect = {
				scope:good_court_astrologer_option = {
					save_scope_as = goodly_created
				}
			}
		}
		# Great Character
		if = { # check for a GREAT character in the pool
			limit = {
				any_pool_character = {
					province = root.capital_province
					mpo_decisions_events_0070_high_skill_trigger = yes
					NOT = { this = scope:good_court_astrologer_option }
					can_be_employed_as = court_astrologer_court_position
				}
			}
			ordered_pool_character = {
				order_by = {
					# Ok, first we group by aptitude.
					value = "aptitude(court_astrologer_court_position)"
					# Then we want to use learning as a tiebreaker...
					## ... so make it a decimal of aptitude...
					multiply = 100
					## ... and _then_ add it.
					add = learning
				}
				province = root.capital_province
				limit = {
					mpo_decisions_events_0070_high_skill_trigger = yes
					NOT = { this = scope:good_court_astrologer_option }
					can_be_employed_as = court_astrologer_court_position
				}
				save_scope_as = great_court_astrologer_option
			}
		}
		else = { # otherwise create one
			create_character = {
				location = root.capital_province
				gender_female_chance = root_faith_clergy_gender_female_chance
				template_character = root
				random_traits = yes
				random_traits_list = {
					count = 1
					education_learning_2 = {}
					education_learning_3 = {}
					education_learning_4 = {}
				}
				age = { 18 50 }
				learning = {
					min_template_high_skill
					max_template_high_skill
				}
				save_scope_as = great_court_astrologer_option
			}
			hidden_effect = {
				scope:great_court_astrologer_option = {
					save_scope_as = greatly_created
					random_list = {
						100 = {}
						20 = {
							add_trait = lifestyle_herbalist
						}
						10 = {
							add_trait = lifestyle_mystic
						}
						10 = {
							add_trait = lifestyle_mystic
							add_trait_xp = {
								trait = lifestyle_mystic
								value = 25
							}
						}
						5 = {
							add_trait = lifestyle_mystic
							add_trait_xp = {
								trait = lifestyle_mystic
								value = 50
							}
						}
						5 = {
							add_trait = lifestyle_mystic
							add_trait_xp = {
								trait = lifestyle_mystic
								value = 75
							}
						}
					}
				}
			}
		}
	}
	#Great option
	option = {
		name = mpo_decisions_events.0070.a
		custom_tooltip = mpo_decisions_events.0070.a.aptitude
		pay_short_term_gold = {
			target = scope:great_court_astrologer_option
			gold = high_skill_court_astrologer_cost
		}
		add_courtier = scope:great_court_astrologer_option
		if = {
			limit = {
				can_employ_court_position_type = court_astrologer_court_position
			}
			appoint_court_position = {
				recipient = scope:great_court_astrologer_option
				court_position = court_astrologer_court_position
			}
		}
		else_if = {
			limit = {
				employs_court_position = court_astrologer_court_position
			}
			random_court_position_holder = {
				type = court_astrologer_court_position
				save_scope_as = current_court_astrologer
			}
			replace_court_position = {
				recipient = scope:great_court_astrologer_option
				holder = scope:current_court_astrologer
				court_position = court_astrologer_court_position
			}
		}
		ai_chance = {
			base = 100
			modifier = {
				gold < high_skill_court_astrologer_cost
			}
		}
	}
	#Good option
	option = {
		name = mpo_decisions_events.0070.b
		custom_tooltip = mpo_decisions_events.0070.b.aptitude
		pay_short_term_gold = {
			target = scope:good_court_astrologer_option
			gold = low_skill_court_astrologer_cost
		}
		add_courtier = scope:good_court_astrologer_option
		if = {
			limit = {
				can_employ_court_position_type = court_astrologer_court_position
			}
			appoint_court_position = {
				recipient = scope:good_court_astrologer_option
				court_position = court_astrologer_court_position
			}
		}
		else_if = {
			limit = {
				employs_court_position = court_astrologer_court_position
			}
			random_court_position_holder = {
				type = court_astrologer_court_position
				save_scope_as = current_court_astrologer
			}
			replace_court_position = {
				recipient = scope:good_court_astrologer_option
				holder = scope:current_court_astrologer
				court_position = court_astrologer_court_position
			}
		}
	}
	#Nah
	option = {
		name = mpo_decisions_events.0070.c
	}
	after = {
		if = {
			limit = {
				exists = scope:goodly_created
				NOT = {
					scope:goodly_created = {
						is_courtier_of = root
					}
				}
			}
			scope:goodly_created = {
				silent_disappearance_effect = yes
			}
		}
		if = {
			limit = {
				exists = scope:greatly_created
				NOT = {
					scope:greatly_created = {
						is_courtier_of = root
					}
				}
			}
			scope:greatly_created = {
				silent_disappearance_effect = yes
			}
		}
	}
}

mpo_decisions_events.0120 = {
	type = character_event
	title = mpo_decisions_events.0120.t
	desc = {
		desc = mpo_decisions_events.0120.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = {
					var:previous_holder = flag:subject
				}
				desc = mpo_decisions_events.0120.desc.subject
			}
		}
	}
			
	theme = nomads
	left_portrait = {
		character = root
    	animation = jockey_idle
  		camera = camera_event_horse_left
	}
	right_portrait = {
		character = scope:herder
		animation = obsequious_bow
	}
	lower_right_portrait = {
		trigger = { exists = scope:nomad }
		character = scope:nomad
	}
	
	immediate = {
		set_variable = adventurer_to_nomad_tributary_var
		location.county.holder = { save_scope_as = herder }
		if = {
			limit = {
				scope:herder = {
					is_independent_ruler = yes
					is_tributary = no
				}
			}
			set_variable = {
				name = previous_holder
				value = flag:independent
			}
		}
		else = {
			set_variable = {
				name = previous_holder
				value = flag:subject
			}
			if = {
				limit = { exists = scope:herder.suzerain }
				scope:herder.suzerain = { save_scope_as = nomad }
			}
			else = {
				scope:herder.liege = { save_scope_as = nomad }
			}
		}
	}
	
	option = { # Become Tributary
		name = mpo_decisions_events.0120.a
		trigger = {
			var:previous_holder = flag:subject
			NOT = { is_tributary_of = scope:nomad } # If you are already a Tributary of overlord
		}
		start_tributary_interaction_effect = {
			TRIBUTARY = this
			SUZERAIN = scope:nomad
		}
		
		stress_impact = {
			ambitious = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = ambitious
				factor = 0
			}
			ai_value_modifier = {
				ai_boldness = -0.5
			}
		}
	}
	
	option = { # Refuse to become Tributary
		name = mpo_decisions_events.0120.b
		trigger = {
			var:previous_holder = flag:subject
			NOT = { is_tributary_of = scope:nomad } # If you are already a Tributary of overlord
		}
		add_prestige_level = -1
		scope:nomad = {
			add_opinion = {
				target = root
				modifier = angry_opinion
				opinion = -50
			}
		}
		
		stress_impact = {
			craven = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = craven
				factor = 0
			}
		}
	}
	
	option = { # Wait, join our court
		name = mpo_decisions_events.0120.c
		trigger = {
			var:previous_holder = flag:independent
		}
		add_courtier = scope:herder
		
		stress_impact = {
			callous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = callous
				factor = 0
			}
			ai_value_modifier = {
				ai_compassion = 1
			}
		}
	}
	
	option = { # We'll take it from here
		name = mpo_decisions_events.0120.d
		trigger = {
			var:previous_holder = flag:independent
		}
		
		stress_impact = {
			compassionate = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = compassionate
				factor = 0
			}
			ai_value_modifier = {
				ai_compassion = 1
			}
		}
	}
	
	after = {
		adopt_nomadic_ways_decision_event_effect = yes
		remove_variable = previous_holder
		remove_variable = previous_provisions
		remove_variable = adventurer_to_nomad_tributary_var
	}
}

# Invite Siege Engineer
scripted_trigger invite_siege_engineer_requirements = {
	can_be_employed_as = siege_engineer_court_position
	is_adult = yes
	is_imprisoned = no
	is_alive = yes # Because apparently there can be dead characters in the pool (remove when fixed)
	is_claimant = no # We don't want recruiting physicians to be a cheap way of getting claimants
	"aptitude(siege_engineer_court_position)" = $APTITUDE$
}

scripted_effect invite_siege_engineer_find_example = {
	if = { # check for a GOOD character in the pool
		limit = {
			any_pool_character = {
				province = root.capital_province
				invite_siege_engineer_requirements = { APTITUDE = $APTITUDE$ }
			}
		}
		random_pool_character = {
			province = root.capital_province
			limit = {
				invite_siege_engineer_requirements = { APTITUDE = $APTITUDE$ }
			}
			save_scope_as = $LEVEL$_siege_engineer_option
		}
	}
	else = { # otherwise create one
		random_independent_ruler = {
			weight = {
				modifier = {
					factor = 100
					culture = {
						has_same_culture_heritage = root.culture
					}
				}
				modifier = {
					factor = 100
					faith.religion = root.faith.religion
				}
				modifier = {
					factor = 1000
					character_is_land_realm_neighbor = root.top_liege
				}
			}
			limit = {
				is_landed = yes
				NOR = {
					government_has_flag = government_is_tribal
					government_has_flag = government_is_nomadic
					government_has_flag = government_is_herder
				}
			}
			save_scope_as = target_character
		}
		create_character = {
			location = root.capital_province
			gender_female_chance = root_soldier_female_chance
			template_character = root
			random_traits = yes
			culture = scope:target_character.culture
			faith = scope:target_character.faith
			random_traits_list = {
				count = 1
				education_learning_$EDUCATION_1$ = {}
				education_learning_$EDUCATION_2$ = {}
			}
			age = { 18 50 }
			learning = {
				min_template_$MAIN_SKILL_MIN$_skill
				max_template_$MAIN_SKILL_MAX$_skill
			}
			martial = {
				min_template_$OTHER_SKILL_MIN$_skill
				max_template_$OTHER_SKILL_MAX$_skill
			}
			stewardship = {
				min_template_$OTHER_SKILL_MIN$_skill
				max_template_$OTHER_SKILL_MAX$_skill
			}
			save_scope_as = $LEVEL$_siege_engineer_option
			after_creation = { 
				save_scope_as = $LEVEL$ly_created 
				add_trait = military_engineer
				add_trait_xp = {
					trait = military_engineer
					value = {
						integer_range = {
							min = $TRAIT_XP_MIN$
							max = $TRAIT_XP_MAX$
						}
					}
				}
			}
		}
	}
}

scripted_effect invite_siege_engineer_appointment = {
	pay_short_term_gold = {
		target = scope:$SCOPE$_siege_engineer_option
		gold = $LEVEL$_skill_siege_engineer_cost
	}
	add_courtier = scope:$SCOPE$_siege_engineer_option
	if = {
		limit = {
			NOT = { employs_court_position = siege_engineer_court_position }
		}
		appoint_court_position = {
			recipient = scope:$SCOPE$_siege_engineer_option
			court_position = siege_engineer_court_position
		}
	}
	else_if = {
		limit = {
			employs_court_position = siege_engineer_court_position
		}
		random_court_position_holder = {
			type = siege_engineer_court_position
			save_scope_as = current_siege_engineer
		}
		replace_court_position = {
			recipient = scope:$SCOPE$_siege_engineer_option
			holder = scope:current_siege_engineer
			court_position = siege_engineer_court_position
		}
	}
	hidden_effect = {
		scope:$SCOPE$_siege_engineer_option = {
			add_opinion = {
				modifier = grateful_opinion
				target = root
				opinion = 25
			}
		}
	}
}

mpo_decisions_events.0080 = { 
	type = character_event
	title = mpo_decisions_events.0080.t
	desc = mpo_decisions_events.0080.desc
	theme = nomads
	
	left_portrait = {
		character = scope:great_siege_engineer_option 
		animation = thinking
	}

	right_portrait = {
		character = scope:good_siege_engineer_option 
		animation = storyteller
	}
	
	override_background = {
		reference = mpo_camp_steppe
	}

	immediate = {
		# Good Character
		invite_siege_engineer_find_example = {
			APTITUDE = 4
			LEVEL = good
			EDUCATION_1 = 1
			EDUCATION_2 = 2
			MAIN_SKILL_MIN = average
			MAIN_SKILL_MAX = medium
			OTHER_SKILL_MIN = low
			OTHER_SKILL_MAX = low
			TRAIT_XP_MIN = 5
			TRAIT_XP_MAX = 25
		}
		# Great Character
		invite_siege_engineer_find_example = {
			APTITUDE = 5
			LEVEL = great
			EDUCATION_1 = 3
			EDUCATION_2 = 4
			MAIN_SKILL_MIN = decent
			MAIN_SKILL_MAX = decent
			OTHER_SKILL_MIN = average
			OTHER_SKILL_MAX = average
			TRAIT_XP_MIN = 33
			TRAIT_XP_MAX = 66
		}

		if = {
			limit = {
				exists = scope:good_siege_engineer_option
				exists = scope:great_siege_engineer_option
				"scope:good_siege_engineer_option.aptitude(siege_engineer_court_position)" > "scope:great_siege_engineer_option.aptitude(siege_engineer_court_position)"
			}
			scope:great_siege_engineer_option = { save_scope_as = temp_scope }
			scope:good_siege_engineer_option = { save_scope_as = great_siege_engineer_option }
			scope:temp_scope = { save_scope_as = good_siege_engineer_option }
		}
	}
	#Great option
	option = {
		name = mpo_decisions_events.0080.a
		custom_tooltip = mpo_decisions_events.0080.a.aptitude
		invite_siege_engineer_appointment = { 
			SCOPE = great 
			LEVEL = high
		}
		ai_chance = {
			base = 100
			modifier = {
				gold < high_skill_court_astrologer_cost
			}
		}
	}
	#Good option
	option = {
		name = mpo_decisions_events.0080.b
		custom_tooltip = mpo_decisions_events.0080.b.aptitude
		invite_siege_engineer_appointment = { 
			SCOPE = good 
			LEVEL = low
		}
	}
	#Nah
	option = {
		name = mpo_decisions_events.0080.c
	}
	after = {
		if = {
			limit = {
				exists = scope:goodly_created
				NOT = {
					scope:goodly_created = {
						is_courtier_of = root
					}
				}
			}
			scope:goodly_created = {
				silent_disappearance_effect = yes
			}
		}
		if = {
			limit = {
				exists = scope:greatly_created
				NOT = {
					scope:greatly_created = {
						is_courtier_of = root
					}
				}
			}
			scope:greatly_created = {
				silent_disappearance_effect = yes
			}
		}
	}
}

# Invite Foreign Emissary
scripted_trigger invite_foreign_emissary_requirements = {
	can_be_employed_as = foreign_emissary_court_position
	is_adult = yes
	is_imprisoned = no
	is_alive = yes # Because apparently there can be dead characters in the pool (remove when fixed)
	is_claimant = no # We don't want recruiting physicians to be a cheap way of getting claimants
	"aptitude(foreign_emissary_court_position)" = $APTITUDE$
}

scripted_effect invite_foreign_emissary_find_example = {
	if = { # check for a GOOD character in the pool
		limit = {
			any_pool_character = {
				province = root.capital_province
				invite_foreign_emissary_requirements = { APTITUDE = $APTITUDE$ }
			}
		}
		random_pool_character = {
			province = root.capital_province
			limit = {
				invite_foreign_emissary_requirements = { APTITUDE = $APTITUDE$ }
			}
			save_scope_as = $LEVEL$_foreign_emissary_option
		}
	}
	else = { # otherwise create one
		random_independent_ruler = {
			weight = {
				modifier = {
					factor = 1000
					government_has_flag = government_is_republic
				}
			}
			limit = {
				is_landed = yes
				NOR = {
					government_has_flag = government_is_tribal
					government_has_flag = government_is_nomadic
					government_has_flag = government_is_herder
				}
			}
			save_scope_as = target_character
		}
		create_character = {
			location = root.capital_province
			gender_female_chance = root_soldier_female_chance
			template_character = root
			random_traits = yes
			culture = scope:target_character.culture
			faith = scope:target_character.faith
			random_traits_list = {
				count = 1
				education_diplomacy_$EDUCATION_1$ = {}
				education_diplomacy_$EDUCATION_2$ = {}
			}
			random_traits_list = {
				count = 1
				diplomat = {}
				lifestyle_reveler = {}
			}
			age = { 18 50 }
			diplomacy = {
				min_template_$MAIN_SKILL_MIN$_skill
				max_template_$MAIN_SKILL_MAX$_skill
			}
			stewardship = {
				min_template_$OTHER_SKILL_MIN$_skill
				max_template_$OTHER_SKILL_MAX$_skill
			}
			save_scope_as = $LEVEL$_foreign_emissary_option
			after_creation = { 
				save_scope_as = $LEVEL$ly_created 
			}
		}
	}
}

scripted_effect invite_foreign_emissary_appointment = {
	pay_short_term_gold = {
		target = scope:$SCOPE$_foreign_emissary_option
		gold = $LEVEL$_skill_foreign_emissary_cost
	}
	add_courtier = scope:$SCOPE$_foreign_emissary_option
	if = {
		limit = {
			NOT = { employs_court_position = foreign_emissary_court_position }
		}
		appoint_court_position = {
			recipient = scope:$SCOPE$_foreign_emissary_option
			court_position = foreign_emissary_court_position
		}
	}
	else_if = {
		limit = {
			employs_court_position = foreign_emissary_court_position
		}
		random_court_position_holder = {
			type = foreign_emissary_court_position
			save_scope_as = current_foreign_emissary
		}
		replace_court_position = {
			recipient = scope:$SCOPE$_foreign_emissary_option
			holder = scope:current_foreign_emissary
			court_position = foreign_emissary_court_position
		}
	}
	hidden_effect = {
		scope:$SCOPE$_foreign_emissary_option = {
			add_opinion = {
				modifier = grateful_opinion
				target = root
				opinion = 25
			}
		}
	}
}

mpo_decisions_events.0090 = { 
	type = character_event
	title = mpo_decisions_events.0090.t
	desc = mpo_decisions_events.0090.desc
	theme = nomads
	
	left_portrait = {
		character = scope:great_foreign_emissary_option 
		animation = debating
	}

	right_portrait = {
		character = scope:good_foreign_emissary_option 
		animation = thinking
	}
	
	override_background = {
		reference = mpo_tent_interior_mongol
	}

	immediate = {
		ordered_courtier_or_guest = {
			order_by = diplomacy
			limit = {
				age >= 10
			}
			save_scope_as = courtier
		}
		# Good Character
		invite_foreign_emissary_find_example = {
			APTITUDE = 4
			LEVEL = good
			EDUCATION_1 = 1
			EDUCATION_2 = 2
			MAIN_SKILL_MIN = average
			MAIN_SKILL_MAX = medium
			OTHER_SKILL_MIN = low
			OTHER_SKILL_MAX = low
		}
		# Great Character
		invite_foreign_emissary_find_example = {
			APTITUDE = 5
			LEVEL = great
			EDUCATION_1 = 3
			EDUCATION_2 = 4
			MAIN_SKILL_MIN = high
			MAIN_SKILL_MAX = high
			OTHER_SKILL_MIN = medium
			OTHER_SKILL_MAX = medium
		}

		if = {
			limit = {
				exists = scope:good_foreign_emissary_option
				exists = scope:great_foreign_emissary_option
				"scope:good_foreign_emissary_option.aptitude(foreign_emissary_court_position)" > "scope:great_foreign_emissary_option.aptitude(foreign_emissary_court_position)"
			}
			scope:great_foreign_emissary_option = { save_scope_as = temp_scope }
			scope:good_foreign_emissary_option = { save_scope_as = great_foreign_emissary_option }
			scope:temp_scope = { save_scope_as = good_foreign_emissary_option }
		}
	}
	#Great option
	option = {
		name = mpo_decisions_events.0090.a
		custom_tooltip = mpo_decisions_events.0090.a.aptitude
		invite_foreign_emissary_appointment = { 
			SCOPE = great 
			LEVEL = high
		}
		ai_chance = {
			base = 100
			modifier = {
				gold < high_skill_court_astrologer_cost
			}
		}
	}
	#Good option
	option = {
		name = mpo_decisions_events.0090.b
		custom_tooltip = mpo_decisions_events.0090.b.aptitude
		invite_foreign_emissary_appointment = { 
			SCOPE = good 
			LEVEL = low
		}
	}
	#Nah
	option = {
		name = mpo_decisions_events.0090.c
	}
	after = {
		if = {
			limit = {
				exists = scope:goodly_created
				NOT = {
					scope:goodly_created = {
						is_courtier_of = root
					}
				}
			}
			scope:goodly_created = {
				silent_disappearance_effect = yes
			}
		}
		if = {
			limit = {
				exists = scope:greatly_created
				NOT = {
					scope:greatly_created = {
						is_courtier_of = root
					}
				}
			}
			scope:greatly_created = {
				silent_disappearance_effect = yes
			}
		}
	}
}
