﻿namespace = gdp_merchant_family

###
# gdp_merchant_family.0001 - Runaway Bride/Groom
# gdp_merchant_family.0002 - Thicker Than Water
# gdp_merchant_family.0003 - Suffer No Dishonor
# gdp_merchant_family.0004 - An Auspicious Offer
# gdp_merchant_family.0005 - A Shame Upon the House
# gdp_merchant_family.0010 - Low House Unity causes fighting
# gdp_merchant_family.0015 - A Business Confidant
# gdp_merchant_family.0020 - Talent Exchange
# gdp_merchant_family.0025 - Nothing Personal
# gdp_merchant_family.0030 - House Member(s) loiter instead of working

scripted_effect gdp_merchant_family_0001_marry_and_start_camp_effect = {
	scope:house_member = {
		if = {
			limit = {
				is_female = yes
				is_lowborn = no
				scope:wedding_interest = {
					is_lowborn = yes
				}
			}
			marry_matrilineal = scope:wedding_interest
		}
		else_if = {
			limit = {
				is_male = yes
				is_lowborn = yes
				scope:wedding_interest = {
					is_lowborn = no
				}
			}
			marry_matrilineal = scope:wedding_interest
		}
		else = {
			marry = scope:wedding_interest
		}
		if = {
			limit = { has_playable_adventurer_dlc_trigger = yes }
			create_landless_adventurer_title_effect = {
				REASON = flag:runaway_allowed
				FLAVOR_CHAR = root
			}
			add_courtier = scope:wedding_interest
		}
		else = {
			select_and_move_to_pool_effect = yes
			scope:wedding_interest = { select_and_move_to_pool_effect = yes }
		}
	}
}

# House member of root who is available to run away
scripted_trigger gdp_merchant_family_0001_valid_house_member_trigger = {
	is_available_ai_adult = yes
	NOR = {
		is_married = yes
		has_trait = chaste
		has_trait = celibate
		has_sexuality = asexual
	}
	is_attracted_to_gender_of = $WEDDING_INTEREST$
	is_courtier_of = root
}

# Available to run away
scripted_trigger gdp_merchant_family_0001_valid_wedding_interest_trigger = {
	is_available_ai_adult = yes
	is_house_head = no
	liege ?= {
		is_ai = yes
	}
	NOR = {
		is_married = yes
		has_trait = chaste
		has_trait = celibate
		has_sexuality = asexual
	}
	save_temporary_scope_as = gdp_merchant_family_0001_wedding_interest_check
	root = {
		any_close_family_member = {
			gdp_merchant_family_0001_valid_house_member_trigger = { WEDDING_INTEREST = scope:gdp_merchant_family_0001_wedding_interest_check }
		}
	}
}

# Star-Crossed Lovers
gdp_merchant_family.0001 = {
	type = character_event
	title = gdp_merchant_family.0001.t
	desc = {
		desc = gdp_merchant_family.0001.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:house_member = {
						OR = {
							has_trait = callous
							has_trait = stubborn
							has_trait = arrogant
						}
					}
				}
				desc = gdp_merchant_family.0001.desc.stubborn_outro
			}
			desc = gdp_merchant_family.0001.desc.fallback_outro
		}
	}
	theme = marriage
	override_background = corridor_night
	left_portrait = {
		character = scope:house_member
		triggered_animation = {
			trigger = {
				scope:house_member = {
					OR = {
						has_trait = callous
						has_trait = stubborn
						has_trait = arrogant
					}
				}
			}
			animation = war_over_win
		}
		animation = beg
		camera = camera_event_right
	}
	right_portrait = {
		character = scope:wedding_interest
		animation = worry
	}

	trigger = {
		is_house_head = yes
		government_has_flag = government_is_merchant
		is_available_adult = yes
		# We only want this to happen once in a campaign
		primary_title ?= {
			NOT = { has_variable = had_event_gdp_merchant_family_0001 }
		}
		house ?= {
			OR = {
				has_house_unity_stage = rapacious_cs
				has_house_unity_stage = opportunistic_cs
			}
			any_house_relation = {
				OR = {
					has_house_relation_level = quarrel
					has_house_relation_level = rivalry
					has_house_relation_level = feud
				}
				any_relation_house = {
					this != root.house
					any_house_member = {
						gdp_merchant_family_0001_valid_wedding_interest_trigger = yes
					}
				}
			}
		}
	}

	weight_multiplier = {
		modifier = {
			factor = 2
			house ?= {
				any_house_relation = {
					count >= 2
					OR = {
						has_house_relation_level = quarrel
						has_house_relation_level = rivalry
						has_house_relation_level = feud
					}
				}
			}
		}
	}

	immediate = {
		primary_title ?= {
			set_variable = had_event_gdp_merchant_family_0001
		}
		house ?= {
			random_house_relation = {
				limit = {
					OR = {
						has_house_relation_level = quarrel
						has_house_relation_level = rivalry
						has_house_relation_level = feud
					}
					any_relation_house = {
						this != root.house
						any_house_member = {
							gdp_merchant_family_0001_valid_wedding_interest_trigger = yes
						}
					}
				}
				random_relation_house = {
					limit = {
						this != root.house
						any_house_member = {
							gdp_merchant_family_0001_valid_wedding_interest_trigger = yes
						}
					}
					save_scope_as = wedding_interest_house
					house_head = { save_scope_as = wedding_interest_house_head }
					random_house_member = {
						limit = {
							gdp_merchant_family_0001_valid_wedding_interest_trigger = yes
						}
						save_scope_as = wedding_interest
					}
				}
			}
		}
		random_close_family_member = {
			limit = {
				gdp_merchant_family_0001_valid_house_member_trigger = { WEDDING_INTEREST = scope:wedding_interest }
			}
			save_scope_as = house_member
		}
	}

	option = { # Take the gold, and go with my blessing.
		name = gdp_merchant_family.0001.a
		pay_short_term_gold = {
			target = scope:house_member
			gold = {
				add = scope:wedding_interest.sum_of_all_skills_value
				add = scope:wedding_interest.prowess
			}
		}
		gdp_merchant_family_0001_marry_and_start_camp_effect = yes
		ai_chance = {
			base = 10
			
			modifier = {
				factor = 0
				OR = {
					has_trait = greedy
					gold <= {
						add = scope:wedding_interest.sum_of_all_skills_and_prowess_value
						multiply = 2
					}
				}
			}
		}
	}

	option = { # Convince both to stay.
		name = gdp_merchant_family.0001.b
		skill = intrigue

		duel = {
			skill = intrigue
			value = high_skill_rating
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = gdp_merchant_family.0001.b.success
				send_interface_toast = {
					title = gdp_merchant_family.0001.b.success
					left_icon = scope:house_member
					right_icon = scope:wedding_interest
					gdp_merchant_family_0001_marry_and_start_camp_effect = yes
					scope:house_member = {
						progress_towards_friend_effect = {
							CHARACTER = root
							OPINION = 0
							REASON = friend_helped_me_marry
						}
						add_opinion = {
							target = root
							modifier = grateful_opinion
							opinion = 50
						}
					}
					scope:wedding_interest = { save_scope_as = relationship_reason_involved_character }
					clear_saved_scope = relationship_reason_involved_character
				}
			}
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc =  gdp_merchant_family.0001.b.failure
				send_interface_toast = {
					title =  gdp_merchant_family.0001.b.failure
					left_icon = scope:house_member
					right_icon = scope:wedding_interest
					scope:house_member = {
						add_stress = medium_stress_gain
						add_opinion = {
							target = root
							modifier = disappointed_opinion
							opinion = -30
						}
					}
				}
			}
		}

		stress_and_fulfillment_impact = {
			generous = medium_stress_impact_gain
		}

		ai_chance = {
			base = 10
			
			modifier = {
				factor = 0
				has_trait = generous
			}
		}
	}

	option = { # Refuse them
		name = gdp_merchant_family.0001.c

		stress_and_fulfillment_impact = {
			compassionate = medium_stress_impact_gain
			generous = medium_stress_impact_gain
			callous = minor_stress_impact_loss
			sadistic = minor_stress_impact_loss
			chaste = minor_stress_impact_loss
		}
		scope:house_member = {
			add_opinion = {
				target = root
				modifier = heartbroken_opinion
				opinion = -30
			}
		}
		ai_chance = {
			base = 10
			
			modifier = {
				factor = 0
				OR = {
					has_trait = compassionate
					has_trait = generous
				}
			}
		}
	}
}

scripted_trigger gdp_merchant_family_0002_adopted_trigger = {
	OR = {
		has_character_flag = merchant_adopted
		has_trait = adopted_no_inheritance
	}
}

# Thicker than Water
# water is an adopted house member or associate who outdoes a blood relative
# We weigh this up when they are adopted, since the stakes are clearer
gdp_merchant_family.0002 = {
	type = character_event
	title = gdp_merchant_family.0002.t
	desc = {
		desc = gdp_merchant_family.0002.desc_intro
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:water = { gdp_merchant_family_0002_adopted_trigger = yes }
				}
				desc = gdp_merchant_family.0002.desc_adopted
			}
			desc = gdp_merchant_family.0002.desc_associate
		}
		desc = gdp_merchant_family.0002.desc_outro
	}
	theme = family
	left_portrait = {
		character = root
		animation = stressed_teacher
	}
	right_portrait = {
		character = scope:blood
		animation = debating
	}
	lower_right_portrait = {
		character = scope:water
	}

	trigger = {
		is_house_head = yes
		government_has_flag = government_is_merchant
		# We only want this to happen once in a campaign
		primary_title ?= {
			NOT = { has_variable = had_event_gdp_merchant_family_0002 }
		}
		OR = {
			AND = {
				any_close_family_member = {
					is_available_ai_adult = yes
					is_courtier_of = root
					gdp_merchant_family_0002_adopted_trigger = yes
					save_temporary_scope_as = temp_water_adopted
				}
				any_close_family_member = {
					is_available_ai_adult = yes
					is_courtier_of = root
					NOT = { gdp_merchant_family_0002_adopted_trigger = yes }
					sum_of_all_skills_value < scope:temp_water_adopted.sum_of_all_skills_value
				}
			}
			AND = {
				any_courtier = {
					is_available_ai_adult = yes
					NOR = {
						is_spouse_of = root
						is_close_family_of = root
						gdp_merchant_family_0002_adopted_trigger = yes
					}
					save_temporary_scope_as = temp_water_associate
				}
				any_close_family_member = {
					is_available_ai_adult = yes
					is_courtier_of = root
					NOT = { gdp_merchant_family_0002_adopted_trigger = yes }
					sum_of_all_skills_value < scope:temp_water_associate.sum_of_all_skills_value
				}
			}
		}
	}

	weight_multiplier = {
		modifier = {
			add = 2
			any_close_family_member = {
				is_available_ai_adult = yes
				is_courtier_of = root
				gdp_merchant_family_0002_adopted_trigger = yes
				sum_of_all_skills_value >= sum_of_all_skills_threshold_good
			}
		}
	}

	immediate = {
		primary_title ?= {
			set_variable = had_event_gdp_merchant_family_0002
		}
		# Prefer an adopted house member
		if = {
			limit = {
				any_close_family_member = {
					is_available_ai_adult = yes
					is_courtier_of = root
					gdp_merchant_family_0002_adopted_trigger = yes
					save_temporary_scope_as = temp_water_adopted
				}
				any_close_family_member = {
					is_available_ai_adult = yes
					is_courtier_of = root
					NOT = { gdp_merchant_family_0002_adopted_trigger = yes }
					sum_of_all_skills_value < scope:temp_water_adopted.sum_of_all_skills_value
				}
			}
			random_close_family_member = {
				limit = {
					is_available_ai_adult = yes
					is_courtier_of = root
					gdp_merchant_family_0002_adopted_trigger = yes
					# Only an adopted member who actually outdoes a blood relative, so scope:blood can always be saved
					save_temporary_scope_as = temp_water
					root = {
						any_close_family_member = {
							is_available_ai_adult = yes
							is_courtier_of = root
							NOT = { gdp_merchant_family_0002_adopted_trigger = yes }
							sum_of_all_skills_value < scope:temp_water.sum_of_all_skills_value
						}
					}
				}
				# They better be good
				weight = {
					base = 1
					modifier = {
						add = sum_of_all_skills_value
					}
				}
				save_scope_as = water
			}
		}
		# Fallback to any skilled associate who isn't a house member
		else = {
			random_courtier = {
				limit = {
					is_available_ai_adult = yes
					NOR = {
						is_spouse_of = root
						is_close_family_of = root
						gdp_merchant_family_0002_adopted_trigger = yes
					}
					save_temporary_scope_as = temp_water
					root = {
						any_close_family_member = {
							is_available_ai_adult = yes
							is_courtier_of = root
							NOT = { gdp_merchant_family_0002_adopted_trigger = yes }
							sum_of_all_skills_value < scope:temp_water.sum_of_all_skills_value
						}
					}
				}
				weight = {
					base = 1
					modifier = {
						add = sum_of_all_skills_value
					}
				}
				save_scope_as = water
			}
		}
		random_close_family_member = {
			limit = {
				is_available_ai_adult = yes
				is_courtier_of = root
				NOT = { gdp_merchant_family_0002_adopted_trigger = yes }
				sum_of_all_skills_value < scope:water.sum_of_all_skills_value
			}
			save_scope_as = blood
		}
	}

	# Side with blood relative / family loyalty
	option = {
		name = gdp_merchant_family.0002.a
		house = {
			add_unity_value = {
				value = minor_unity_gain
				character = root
				desc = gdp_merchant_family.0002.a.unity_gain.desc
			}
		}
		add_character_modifier = {
			modifier = gdp_nepotism_modifier
			years = 10
		}
		scope:blood = {
			add_stewardship_skill = 1
		}
		stress_and_fulfillment_impact = {
			arbitrary = minor_stress_impact_loss
			callous = minor_stress_impact_loss
			greedy = minor_stress_impact_gain
		}

		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = medium_chance_impact_negative_ai_value
			}
			modifier = {
				add = 20
				has_trait = arbitrary
			}
			modifier = {
				add = 20
				has_trait = callous
			}
			modifier = {
				add = -15
				has_trait = greedy
			}
		}
	}

	# Side with the higher-performing water candidate
	option = {
		name = gdp_merchant_family.0002.b
		house = {
			add_unity_value = {
				value = minor_unity_loss
				character = root
				desc = gdp_merchant_family.0002.b.unity_loss.desc
			}
		}
		add_character_modifier = {
			modifier = gdp_merit_modifier
			years = 10
		}
		stress_and_fulfillment_impact = {
			cynical = minor_stress_impact_loss
			greedy = minor_stress_impact_loss
		}

		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = medium_chance_impact_positive_ai_value
			}
			modifier = {
				add = 10
				has_trait = cynical
			}
			modifier = {
				add = 10
				has_trait = greedy
			}
		}
	}

	# Figure it out
	option = {
		name = gdp_merchant_family.0002.c
		
		stress_and_fulfillment_impact = {
			base = minor_stress_impact_loss

			lazy = minor_stress_impact_loss
			cynical = minor_stress_impact_loss
			compassionate = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			modifier = {
				add = 25
				has_trait = lazy
			}
			modifier = {
				add = 20
				has_trait = cynical
			}
			modifier = {
				add = -20
				has_trait = compassionate
			}
		}
	}
}

# Suffer no Dishonor
gdp_merchant_family.0003 = {
	type = character_event
	title = gdp_merchant_family.0003.t
	desc = gdp_merchant_family.0003.desc
	theme = family
	left_portrait = {
		character = root
		animation = shock
	}
	right_portrait = {
		character = scope:offended
		animation = anger
	}
	lower_right_portrait = {
		character = scope:offender
	}
	cooldown = { years = 10 }

	trigger = {
		is_house_head = yes
		government_has_flag = government_is_merchant
		house ?= {
			OR = {
				has_house_unity_stage = ennobled_cs
				has_house_unity_stage = grasping_cs
			}
			any_house_relation = {
				OR = {
					has_house_relation_level = quarrel
					has_house_relation_level = rivalry
					has_house_relation_level = feud
				}
				any_relation_house = {
					this != root.house
					any_house_member = {
						is_available_ai_adult = yes
						NOR = {
							has_trait = compassionate
							has_trait = calm
						}
					}
				}
			}
		}
		any_close_family_member = {
			is_available_ai_adult = yes
			is_courtier_of = root
			NOR = {
				has_trait = content
				has_trait = calm
			}
		}
	}

	weight_multiplier = {
		modifier = {
			factor = 2
			house ?= {
				any_house_relation = {
					count >= 2
					OR = {
						has_house_relation_level = quarrel
						has_house_relation_level = rivalry
						has_house_relation_level = feud
					}
				}
			}
		}
	}

	immediate = {
		house ?= {
			random_house_relation = {
				limit = {
					OR = {
						has_house_relation_level = quarrel
						has_house_relation_level = rivalry
						has_house_relation_level = feud
					}
					any_relation_house = {
						this != root.house
						any_house_member = {
							is_available_ai_adult = yes
							NOR = {
								has_trait = compassionate
								has_trait = calm
							}
							save_temporary_scope_as = temp_offender
						}
					}
				}
			}
			scope:temp_offender = { save_scope_as = offender }
		}
		random_close_family_member = {
			limit = {
				is_available_ai_adult = yes
				is_courtier_of = root
				NOR = {
					has_trait = content
					has_trait = calm
				}
			}
			save_scope_as = offended
		}
	}

	# I demand an apology!
	option = {
		name = gdp_merchant_family.0003.a
		house = {
			add_unity_value = {
				value = minor_unity_gain
				character = root
				desc = gdp_merchant_family.0003.a.unity_gain.desc
			}
			change_house_relation_effect = {
				HOUSE = scope:offender.house
				VALUE = house_relation_damage_minor_value
				REASON = gdp_merchant_family.0003.a.relation_damage.desc
				CHAR = root
				TARGET_CHAR = scope:offender.house.house_head
				TITLE = scope:dummy_gender
			}
		}
		add_prestige = minor_prestige_gain
		
		stress_and_fulfillment_impact = {
			brave = minor_stress_impact_loss
			callous = minor_stress_impact_loss
			humble = minor_stress_impact_gain
			shy = minor_stress_impact_gain
		}

		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_sociability = medium_chance_impact_negative_ai_value
			}
			modifier = {
				add = 20
				has_trait = brave
			}
			modifier = {
				add = 20
				has_trait = callous
			}
			modifier = {
				add = -20
				has_trait = humble
			}
			modifier = {
				add = -20
				has_trait = shy
			}
		}
	}

	# that's bait
	option = {
		name = gdp_merchant_family.0003.b
		add_prestige = minor_prestige_loss
		add_character_modifier = {
			modifier = gdp_full_attention_modifier
			years = 10
		}
		house = {
			add_unity_value = {
				value = medium_unity_loss
				character = root
				desc = gdp_merchant_family.0003.b.unity_loss.desc
			}
		}
		
		stress_and_fulfillment_impact = {
			compassionate = minor_stress_impact_gain
			deceitful = minor_stress_impact_loss
			cynical = minor_stress_impact_loss
		}

		ai_chance = {
			base = 10

			ai_value_modifier = {
				ai_greed = medium_chance_impact_positive_ai_value
				ai_sociability = medium_chance_impact_negative_ai_value
			}
			modifier = {
				add = -15
				has_trait = compassionate
			}
			modifier = {
				add = 15
				has_trait = cynical
			}
			modifier = {
				add = 15
				has_trait = deceitful
			}
		}
	}

	# I don't want anything to do with that.
	option = {
		name = gdp_merchant_family.0003.c
		house = {
			add_unity_value = {
				value = minor_unity_loss
				character = root
				desc = gdp_merchant_family.0003.c.unity_loss.desc
			}
		}
		scope:offended = {
			add_stewardship_skill = 1
			add_character_modifier = {
				modifier = gdp_responsible_modifier
				years = 10
			}
		}
		
		stress_and_fulfillment_impact = {
			base = minor_stress_impact_loss

			lazy = minor_stress_impact_loss
			cynical = minor_stress_impact_loss
			compassionate = minor_stress_impact_gain
		}

		ai_chance = {
			base = 10
			modifier = {
				add = 20
				has_trait = lazy
			}
			modifier = {
				add = 15
				has_trait = cynical
			}
			modifier = {
				add = -10
				has_trait = compassionate
			}
		}
	}
}

# Close family member of root who can marry the suitor
scripted_trigger gdp_merchant_family_0004_valid_family_member_trigger = {
	is_available_ai_adult = yes
	is_courtier_of = root
	can_marry_character_trigger = {
		CHARACTER = $OFFER$
	}
}

# Suitor from a friendly house
scripted_trigger gdp_merchant_family_0004_valid_offer_trigger = {
	is_available_ai_adult = yes
	is_ruler = no
	liege ?= {
		is_ai = yes
	}
	can_marry_trigger = yes
	save_temporary_scope_as = gdp_merchant_family_0004_offer_check
	root = {
		any_close_family_member = {
			gdp_merchant_family_0004_valid_family_member_trigger = { OFFER = scope:gdp_merchant_family_0004_offer_check }
		}
	}
}

# An Auspicious Offer
gdp_merchant_family.0004 = {
	type = character_event
	title = gdp_merchant_family.0004.t
	desc = gdp_merchant_family.0004.desc
	theme = family
	left_portrait = {
		character = root
		animation = interested
	}
	right_portrait = {
		character = scope:offer_2
		animation = throne_room_conversation_4
	}
	lower_left_portrait = {
		character = scope:offer
	}
	override_background = {
		reference = alley_day
	}

	cooldown = { years = 10 }

	trigger = {
		is_house_head = yes
		government_has_flag = government_is_merchant
		house ?= {
			OR = {
				has_house_unity_stage = ennobled_cs
				has_house_unity_stage = grasping_cs
			}
			any_house_relation = {
				NOR = {
					has_house_relation_level = quarrel
					has_house_relation_level = rivalry
					has_house_relation_level = feud
				}
				any_relation_house = {
					this != root.house
					any_house_member = {
						gdp_merchant_family_0004_valid_offer_trigger = yes
					}
				}
			}
		}
	}

	immediate = {
		random_dummy_gender_effect = yes
		house ?= {
			random_house_relation = {
				limit = {
					NOR = {
						has_house_relation_level = quarrel
						has_house_relation_level = rivalry
						has_house_relation_level = feud
					}
					any_relation_house = {
						this != root.house
						any_house_member = {
							gdp_merchant_family_0004_valid_offer_trigger = yes
						}
					}
				}
				random_relation_house = {
					limit = {
						this != root.house
						any_house_member = {
							gdp_merchant_family_0004_valid_offer_trigger = yes
						}
					}
					random_house_member = {
						limit = {
							gdp_merchant_family_0004_valid_offer_trigger = yes
						}
						save_scope_as = offer_2
						liege = {
							save_scope_as = foreign_liege
						}
					}
				}
			}
		}
		random_close_family_member = {
			limit = {
				gdp_merchant_family_0004_valid_family_member_trigger = { OFFER = scope:offer_2 }
			}
			save_scope_as = offer
		}
		scope:offer_2 = {
			visit_court_of = root
		}
	}

	# I accept!
	option = {
		name = gdp_merchant_family.0004.a
		if = {
			limit = {
				OR = {
					scope:offer = {
						is_adult = no
					}
					scope:offer_2 = {
						is_adult = no
					}
				}
			}
			betroth_on_realm_law = {
				SPOUSE_1 = scope:offer
				SPOUSE_2 = scope:offer_2
			}
		}
		else = {
			marry_on_realm_law = {
				SPOUSE_1 = scope:offer
				SPOUSE_2 = scope:offer_2
			}
		}
		add_prestige = minor_prestige_gain
		
		stress_and_fulfillment_impact = {
			brave = minor_stress_impact_loss
			humble = minor_stress_impact_loss
			shy = minor_stress_impact_gain
		}

		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_sociability = medium_chance_impact_positive_ai_value
			}
			modifier = {
				add = 25
				has_trait = brave
			}
			modifier = {
				add = -20
				has_trait = humble
			}
			modifier = {
				add = -20
				has_trait = shy
			}
		}
	}

	# TRADE OFFER
	option = {
		name = gdp_merchant_family.0004.b
		scope:offer_2.house.house_head = {
			add_character_modifier = {
				modifier = gdp_cooperation_modifier
				years = 10
			}
		}
		add_character_modifier = {
			modifier = gdp_cooperation_modifier
			years = 10
		}
		house ?= {
			change_house_relation_effect = {
				HOUSE = scope:offer_2.house
				VALUE = house_relation_improve_minor_value
				REASON = gdp_merchant_family.0004.b.relation_improve.desc
				CHAR = root
				TARGET_CHAR = scope:offer_2.house.house_head
				TITLE = scope:dummy_gender
			}
		}
		
		stress_and_fulfillment_impact = {
			greedy = minor_stress_impact_loss
		}

		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = medium_chance_impact_positive_ai_value
			}
			modifier = {
				add = 20
				has_trait = greedy
			}
		}
	}

	# No, thanks.
	option = {
		name = gdp_merchant_family.0004.c
				
		stress_and_fulfillment_impact = {
			base = minor_stress_impact_loss
			lazy = minor_stress_impact_loss
			paranoid = minor_stress_impact_loss
			ambitious = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			modifier = {
				add = -20
				has_trait = ambitious
			}
			modifier = {
				add = 20
				has_trait = lazy
			}
			modifier = {
				add = 20
				has_trait = paranoid
			}
		}
	}
}

# A Shame Upon the House
gdp_merchant_family.0005 = {
	type = character_event
	title = gdp_merchant_family.0005.t
	desc = gdp_merchant_family.0005.desc
	theme = family
	left_portrait = {
		character = root
		animation = anger
	}
	right_portrait = {
		character = scope:wayward
		animation = stress
	}

	cooldown = { years = 10 }

	trigger = {
		is_house_head = yes
		government_has_flag = government_is_merchant
		house ?= {
			has_house_unity_stage = rapacious_cs
		}
		any_close_family_member = {
			is_courtier_of = root
			is_available_ai_adult = yes
		}
	}

	immediate = {
		random_close_family_member = {
			limit = {
				is_courtier_of = root
				is_available_ai_adult = yes
			}
			weight = {
				base = 1
				modifier = {
					factor = 0.5
					OR = {
						has_trait = just
						has_trait = honest
						has_trait = compassionate
						has_trait = ambitious
					}
				}
				modifier = {
					factor = 2
					OR = {
						has_trait = lazy
						has_trait = content
						has_trait = profligate
					}
				}
			}
			save_scope_as = wayward
		}
	}

	# SHAME ON YOU!
	option = {
		name = gdp_merchant_family.0005.a
		add_prestige = minor_prestige_gain

		house = {
			add_unity_value = {
				value = minor_unity_loss
				character = root
				desc = gdp_merchant_family.0005.a.unity_loss.desc
			}
		}

		stress_and_fulfillment_impact = {
			arbitrary = minor_stress_impact_loss
			sadistic = minor_stress_impact_loss
			humble = minor_stress_impact_gain
			shy = minor_stress_impact_gain
			compassionate = minor_stress_impact_gain
		}

		ai_chance = {
			base = 10

			ai_value_modifier = {
				ai_sociability = low_chance_impact_negative_ai_value
			}

			modifier = {
				add = 20
				has_trait = arbitrary
			}
			modifier = {
				add = 20
				has_trait = sadistic
			}
			modifier = {
				add = -25
				has_trait = humble
			}
			modifier = {
				add = -25
				has_trait = shy
			}
			modifier = {
				add = -20
				has_trait = compassionate
			}
		}
	}

	# Family First
	option = {
		name = gdp_merchant_family.0005.b
		add_prestige = minor_prestige_loss
		house = {
			add_unity_value = {
				value = minor_unity_gain
				character = root
				desc = gdp_merchant_family.0005.b.unity_gain.desc
			}
		}
		
		stress_and_fulfillment_impact = {
			content  = minor_stress_impact_loss
			generous = minor_stress_impact_loss
			ambitious = minor_stress_impact_gain
		}

		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = medium_chance_impact_negative_ai_value
			}
			modifier = {
				add = 30
				has_trait = content
			}
			modifier = {
				add = 20
				has_trait = generous
			}
			modifier = {
				add = -15
				has_trait = ambitious
			}
		}
	}

	# No, thanks.
	option = {
		name = gdp_merchant_family.0005.c
				
		stress_and_fulfillment_impact = {
			base = minor_stress_impact_loss
			lazy = minor_stress_impact_loss
			ambitious = minor_stress_impact_gain
		}


		ai_chance = {
			base = 10

			modifier = {
				add = -20
				has_trait = ambitious
			}

			modifier = {
				add = 20
				has_trait = lazy
			}
		}
	}
}

# The Tipping of the Scales
gdp_merchant_family.0010 = {
	type = character_event
	title = gdp_merchant_family.0010.t
	desc = gdp_merchant_family.0010.desc
	theme = merchant
	override_background = { reference = market }
	left_portrait = {
		character = scope:attacker
		animation = aggressive_unarmed
	}
	right_portrait = {
		character = scope:defender
		animation = wrestling_yield_start
	}

	cooldown = { years = 20 }

	trigger = {
		is_house_head = yes
		government_has_flag = government_is_merchant
		house ?= {
			OR = {
				has_house_unity_stage = rapacious_cs
				has_house_unity_stage = opportunistic_cs
			}
		}
		any_courtier = {
			is_available_ai_adult = yes
			save_temporary_scope_as = temp_char
		}
		any_courtier = {
			this != scope:temp_char
			is_available_ai_adult = yes
			can_set_relation_rival_trigger = { CHARACTER = scope:temp_char }
		}
	}

	immediate = {
		ordered_courtier = {
			order_by = prowess
			limit = { is_available_ai_adult = yes }
			save_scope_as = attacker
		}
		scope:attacker = { assign_quirk_effect = yes }
		random_courtier = {
			limit = {
				this != scope:attacker
				is_available_ai_adult = yes
				can_set_relation_rival_trigger = { CHARACTER = scope:attacker }
			}
			save_scope_as = defender
		}
		scope:defender = { assign_quirk_effect = yes }
		# Plus make sure we _definitely_ know who root is, for the after-toasts.
		save_scope_as = og_root
	}

	option = { # Intervene
		name = gdp_merchant_family.0010.a
		duel = {
			skill = diplomacy
			target = scope:attacker
			# Victory!
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				min = 5
				desc = gdp_merchant_family.0010.a.tt.success
				send_interface_toast = {
					title = gdp_merchant_family.0010.a.tt.success
					left_icon = scope:attacker
					right_icon = scope:defender
					add_prestige = minor_prestige_gain
					house ?= {
						add_unity_value = {
							value = medium_unity_gain
							character = root
							desc = merchant_unity_fight_stopped
						}
					}
					reverse_add_opinion = {
						target = scope:attacker
						modifier = respect_opinion
						opinion = 40
					}
					reverse_add_opinion = {
						target = scope:defender
						modifier = respect_opinion
						opinion = 40
					}
				}
			}
			# Defeat.
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				min = 5
				desc = gdp_merchant_family.0010.a.tt.failure
				send_interface_toast = {
					title = gdp_merchant_family.0010.a.tt.failure
					left_icon = scope:attacker
					right_icon = scope:defender
					reverse_add_opinion = {
						target = scope:attacker
						modifier = respect_opinion
						opinion = -20
					}
					reverse_add_opinion = {
						target = scope:defender
						modifier = respect_opinion
						opinion = -20
					}
				}
				scope:attacker = {
					increase_wounds_no_death_effect = { REASON = fight }
				}
				scope:defender = {
					increase_wounds_no_death_effect = { REASON = fight }
				}
			}
		}
		stress_and_fulfillment_impact = {
			arbitrary = minor_stress_impact_gain
			patient = minor_stress_impact_gain
		}
		ai_chance = {
			base = 1
			ai_value_modifier = { ai_compassion = 1 }
			modifier = {
				OR = {
					has_trait = arbitrary
					has_trait = patient
				}
				factor = 0
			}
		}
	}

	# Arrest the attacker
	option = {
		name = gdp_merchant_family.0010.c
		rightfully_imprison_character_effect = {
			TARGET = scope:attacker
			IMPRISONER = root
		}
		reverse_add_opinion = {
			target = scope:defender
			modifier = grateful_opinion
			opinion = 50
		}
		stress_and_fulfillment_impact = {
			just = miniscule_stress_impact_loss
			arbitrary = minor_stress_impact_gain
		}
		ai_chance = {
			base = 1
			ai_value_modifier = { ai_honor = 1 }
		}
	}

	option = { # If you must fight, put on a show!
		name = gdp_merchant_family.0010.b
		trigger = {
			has_realm_law = company_purpose_creditor
		}
		reason = purpose_creditor
		custom_tooltip = gdp_merchant_family.0010.tt.duel
		add_trait_xp = {
			trait = lifestyle_merchant
			track = creditor
			value = lifestyle_merchant_xp_gain_medium_value
		}
		house ?= {
			add_unity_value = {
				value = medium_unity_loss
				character = root
				desc = merchant_unity_fight_promoted
			}
		}
		stress_and_fulfillment_impact = {
			arbitrary = minor_stress_impact_loss
			just = minor_stress_impact_gain
			wrathful = minor_stress_impact_loss
		}
		trigger_event = gdp_merchant_family.0011
		ai_chance = {
			base = 1
			ai_value_modifier = { ai_honor = -2 }
			modifier = {
				has_trait = just
				factor = 0
			}
		}
	}

	option = {	# Let it play out
		name = gdp_merchant_family.0010.d
		trigger = {
			NOT = { has_realm_law = company_purpose_creditor }
		}
		custom_tooltip = gdp_merchant_family.0010.tt.duel
		stress_and_fulfillment_impact = {
			wrathful = miniscule_stress_impact_loss
			arbitrary = miniscule_stress_impact_loss
			just = minor_stress_impact_gain
			calm = minor_stress_impact_gain
		}
		trigger_event = gdp_merchant_family.0011
		ai_chance = {
			base = 1
			ai_value_modifier = { ai_energy = 1 }
		}
	}
}

# Fight outcome & player notice
gdp_merchant_family.0011 = {
	hidden = yes
	immediate = {
		# Let's decide this thing
		scope:attacker = {
			duel = {
				skills = { martial prowess }
				target = scope:defender
				50 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = 3.5
						min = -49
					}
					increase_wounds_no_death_effect = { REASON = fight }
					save_scope_as = winner
					scope:defender = { save_scope_as = loser }
				}
				50 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = -3.5
						min = -49
					}
					scope:defender = {
						increase_wounds_no_death_effect = { REASON = fight }
						save_scope_as = loser
					}
					scope:attacker = { save_scope_as = winner }
				}
			}
		}
		if = {
			limit = { scope:winner = scope:attacker }
			scope:og_root = {
				send_interface_toast = {
					title = gdp_merchant_family.0010.tt.attacker_won
					left_icon = scope:attacker
					right_icon = scope:defender
					custom_tooltip = gdp_merchant_family.0010.tt.attacker_won.tt
					scope:defender = {		
						progress_towards_rival_effect = {
							REASON = rival_low_house_unity_fight
							CHARACTER = scope:attacker
							OPINION = -50
						}
					}
				}
			}
		}
		else = {
			scope:og_root = {
				send_interface_toast = {
					title = gdp_merchant_family.0010.tt.defender_won
					left_icon = scope:defender
					right_icon = scope:attacker
					custom_tooltip = gdp_merchant_family.0010.tt.defender_won.tt
					scope:defender = {		
						progress_towards_rival_effect = {
							REASON = rival_low_house_unity_fight
							CHARACTER = scope:attacker
							OPINION = -50
						}
					}
				}
			}
		}
	}
}

# A Business Confidant
gdp_merchant_family.0015 = {
	type = character_event
	title = gdp_merchant_family.0015.t
	desc = gdp_merchant_family.0015.desc
	theme = merchant
	override_background = market_crowd
	left_portrait = {
		character = root
		animation = page_flipping
	}
	right_portrait = {
		character = scope:tip_giver
		animation = admiration
	}
	artifact = {
		trigger = { exists = scope:newly_created_artifact }
		target = scope:newly_created_artifact
		position = lower_center_portrait
	}
	cooldown = { years = 10 }

	trigger = {
		is_house_head = yes
		government_has_flag = government_is_merchant
		is_available_adult = yes
		domicile.domicile_location.barony.trade_market ?= {
			save_temporary_scope_as = temp_local_market
			OR = {
				any_character_in_market = { this = root }
				root = {
					any_trade_route = {
						any_trade_market_on_route = { this = scope:temp_local_market }
					}
				}
			}
			any_character_in_market = {
				is_ai = yes
				is_adult = yes
				government_has_flag = government_is_merchant
				this != root
				house != root.house
				house ?= {
					any_house_relation = {
						OR = {
							has_house_relation_level = cordial
							has_house_relation_level = friendly
							has_house_relation_level = amity
						}
						any_relation_house = { this = root.house }
					}
				}
				any_trade_route = {
					any_trade_market_on_route = { this = scope:temp_local_market }
				}
			}
		}
	}

	immediate = {
		domicile.domicile_location.barony.trade_market ?= {
			save_scope_as = local_market
		}
		scope:local_market ?= {
			random_character_in_market = {
				limit = {
					is_ai = yes
					is_adult = yes
					government_has_flag = government_is_merchant
					NOT = { this = root }
					NOT = { house = root.house }
					house ?= {
						any_house_relation = {
							OR = {
								has_house_relation_level = cordial
								has_house_relation_level = friendly
								has_house_relation_level = amity
							}
							any_relation_house = { this = root.house }
						}
					}
					any_trade_route = {
						any_trade_market_on_route = { this = scope:local_market }
					}
				}
				save_scope_as = tip_giver
			}
		}
		scope:tip_giver = {
			hidden_effect_new_object = {
				create_artifact = {
					name = gdp_merchant_family.0015.b.artifact
					description = gdp_merchant_family.0015.b.artifact.desc
					type = journal
					visuals = book
					modifier = artifact_placeholder_modifier
					wealth = 50
					quality = 50
					save_scope_as = newly_created_artifact
				}
				scope:newly_created_artifact = {
					remove_artifact_modifier = artifact_placeholder_modifier
					add_artifact_modifier = artifact_trade_category_all_xp_gain_mult_1_modifier
				}
			}
		}
	}
	# Thankful for the tip and future collaboration
	option = {
		name = gdp_merchant_family.0015.a
		hidden_effect = {
			if = {
				limit = { exists = scope:newly_created_artifact }
				destroy_artifact = scope:newly_created_artifact
			}
		}
		scope:local_market = {
			add_competitiveness_modifier_for_character = {
				modifier = trade_cooperation_modifier
				character = root
				years = 10
			}
			add_competitiveness_modifier_for_character = {
				modifier = trade_cooperation_modifier
				character = scope:tip_giver
				years = 10
			}
		}

		house ?= {
			change_house_relation_effect = {
				HOUSE = scope:tip_giver.house
				VALUE = house_relation_improve_minor_value
				REASON = gdp_merchant_family.0015.a.relation_improve.desc
				CHAR = root
				TARGET_CHAR = scope:tip_giver
				TITLE = scope:dummy_gender
			}
		}

		stress_and_fulfillment_impact = {
			trusting = minor_stress_impact_loss
			deceitful = minor_stress_impact_gain
		}

		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_sociability = medium_chance_impact_positive_ai_value
			}
			modifier = {
				add = 20
				OR = {
					has_trait = just
					has_trait = trusting
					has_trait = compassionate
				}
			}
			modifier = {
				factor = 0
				OR = {
					has_trait = deceitful
					has_trait = callous
					has_trait = arbitrary
				}
			}
		}
	}
	# Purchase the ledger
	option = {
		name = gdp_merchant_family.0015.b
		trigger = {
			short_term_gold >= major_gold_value
			exists = scope:newly_created_artifact
		}
		show_as_unavailable = { always = yes }
		pay_short_term_gold = {
			target = scope:tip_giver
			gold = major_gold_value
		}
		scope:newly_created_artifact = { set_owner = root }

		stress_and_fulfillment_impact = {
			ambitious = minor_stress_impact_loss
			greedy = minor_stress_impact_loss
			diligent = minor_stress_impact_loss
		}

		ai_chance = {
			base = 30
			ai_value_modifier = {
				ai_greed = medium_chance_impact_negative_ai_value
				ai_energy = medium_chance_impact_positive_ai_value
			}
			modifier = {
				add = 25
				OR = {
					has_trait = ambitious
					has_trait = greedy
					has_trait = diligent
				}
			}
			modifier = {
				factor = 0
				short_term_gold < major_gold_value
			}
		}
	}
	# Screw them over
	option = {
		name = gdp_merchant_family.0015.c
		hidden_effect = {
			if = {
				limit = { exists = scope:newly_created_artifact }
				destroy_artifact = scope:newly_created_artifact
			}
		}

		scope:local_market = {
			add_competitiveness_modifier_for_character = {
				modifier = friendly_tip_exploit_modifier
				character = root
				years = 10
			}
			add_competitiveness_modifier_for_character = {
				modifier = friendly_tip_betrayed_modifier
				character = scope:tip_giver
				years = 10
			}
		}
		house ?= {
			change_house_relation_effect = {
				HOUSE = scope:tip_giver.house
				VALUE = house_relation_damage_medium_value
				REASON = gdp_merchant_family.0015.c.relation_damage.desc
				CHAR = root
				TARGET_CHAR = scope:tip_giver
				TITLE = scope:dummy_gender
			}
		}

		stress_and_fulfillment_impact = {
			ambitious = minor_stress_impact_loss
			greedy = minor_stress_impact_loss
			diligent = minor_stress_impact_loss
			arbitrary = minor_stress_impact_gain
		}

		ai_chance = {
			base = 5
			ai_value_modifier = {
				ai_greed = medium_chance_impact_positive_ai_value
				ai_honor = medium_chance_impact_negative_ai_value
			}
			modifier = {
				add = 30
				OR = {
					has_trait = deceitful
					has_trait = callous
					has_trait = arbitrary
				}
			}
			modifier = {
				factor = 0
				OR = {
					has_trait = just
					has_trait = compassionate
					has_trait = honest
				}
			}
		}
	}
}

#  Talent Exchange
gdp_merchant_family.0020 = {
	type = character_event
	title = gdp_merchant_family.0020.t
	desc = {
		desc = gdp_merchant_family.0020.desc  
	    first_valid = {
	        triggered_desc = {
	            trigger = {
	                scope:nepo_hire = { highest_skill = diplomacy }
	            }
	            desc = gdp_merchant_family.0020.desc.diplomacy
	        }
	        triggered_desc = {
	            trigger = {
	                scope:nepo_hire = {
	                    OR = {
	                        highest_skill = martial
	                        highest_skill_including_prowess = prowess
	                    }
	                }
	            }
	            desc = gdp_merchant_family.0020.desc.martial
	        }
	        triggered_desc = {
	            trigger = {
	                scope:nepo_hire = { highest_skill = stewardship }
	            }
	            desc = gdp_merchant_family.0020.desc.stewardship
	        }
	        triggered_desc = {
	            trigger = {
	                scope:nepo_hire = { highest_skill = intrigue }
	            }
	            desc = gdp_merchant_family.0020.desc.intrigue
	        }
	        triggered_desc = {
	            trigger = {
	                scope:nepo_hire = { highest_skill = learning }
	            }
	            desc = gdp_merchant_family.0020.desc.learning
	        } 
	    }
	    desc = gdp_merchant_family.0020.desc.outro
	}
	theme = merchant
	left_portrait = {
		character = scope:nepo_hire
	    triggered_animation = {
	        trigger = { highest_skill = diplomacy }
	        animation = debating
	    }
	    triggered_animation = {
	        trigger = {
	            OR = {
	                highest_skill = martial
	                highest_skill_including_prowess = prowess
	            }
	        }
	        animation = war_over_win
	    }
	    triggered_animation = {
	        trigger = { highest_skill = stewardship }
	        animation = holding_scrolls
	    }
	    triggered_animation = {
	        trigger = { highest_skill = intrigue }
	        animation = scheme
	    }
	    triggered_animation = {
	        trigger = { highest_skill = learning }
	        animation = happy_teacher
	    }
	    camera = camera_event_left_forward
	}
	right_portrait = {
		character = scope:house_friend
		animation = flirtation_left
	}
	cooldown = { years = 10 }

	trigger = {
	    is_house_head = yes
	    government_has_flag = government_is_merchant
	    is_available_adult = yes
	    house ?= {
	        any_house_relation = {
	            OR = {
	                has_house_relation_level = friendly
	                has_house_relation_level = amity
	            }
	            any_relation_house = {
	                this != root.house
	                house_head ?= {
	                    is_ai = yes
	                    government_has_flag = government_is_merchant
	                    save_temporary_scope_as = temp_house_friend
	                }
	            }
	        }
	    }
	    scope:temp_house_friend.house ?= {
	        any_house_member = {
	            is_courtier_of = house.house_head
	            is_adult = yes
	            is_available_quick = { adult = yes imprisoned = no incapable = no }
	            NOT = { is_player_heir_of = house.house_head }
	            OR = {
	                is_close_family_of = house.house_head
	                is_child_of = house.house_head
	            }
	            NOT = { this = house.house_head }
	        }
	    }
	}
	immediate = {
	    house ?= {
	        random_house_relation = {
	            limit = {
	                OR = {
	                    has_house_relation_level = friendly
	                    has_house_relation_level = amity
	                }
	                any_relation_house = {
	                    this != root.house
	                    house_head ?= {
	                        is_ai = yes
	                        government_has_flag = government_is_merchant
	                        save_temporary_scope_as = temp_house_friend
	                    }
	                    any_house_member = {
	                        is_courtier_of = scope:temp_house_friend
	                        is_adult = yes
	                        is_available_quick = { adult = yes imprisoned = no incapable = no }
	                        NOT = { is_player_heir_of = scope:temp_house_friend }
	                        OR = {
	                            is_child_of = scope:temp_house_friend
	                            is_close_family_of = scope:temp_house_friend
	                        }
	                        NOT = { this = scope:temp_house_friend }
	                    }
	                }
	            }
	        }
	        scope:temp_house_friend = { save_scope_as = house_friend }
	    }
	    scope:house_friend.house = {
	        random_house_member = {
	            limit = {
	                is_courtier_of = scope:house_friend
	                is_adult = yes
	                is_available_quick = { adult = yes imprisoned = no incapable = no }
	                NOT = { is_player_heir_of = scope:house_friend }
	                OR = {
	                    is_child_of = scope:house_friend
	                    is_close_family_of = scope:house_friend
	                }
	                NOT = { this = scope:house_friend }
	            }
	            save_scope_as = nepo_hire
	        }
	    }
	}
	# Accept the new associate
	option = {
	    name = gdp_merchant_family.0020.a
	    scope:nepo_hire = {
	        add_to_court_and_entourage_effect = yes
	    }
	    house ?= {
			if = {
			    limit = {
			        scope:nepo_hire = {
			            sum_of_all_skills_value < sum_of_all_skills_threshold_terrible
			        }
			    }
		        add_unity_value = {
		            value = medium_unity_loss
		            character = root
		            desc = gdp_merchant_family.0020.a.unity_loss.desc
		        }
			}
			else = {
		        add_unity_value = {
		            value = minor_unity_loss
		            character = root
		            desc = gdp_merchant_family.0020.a.unity_loss.desc
		        }
			}
	        change_house_relation_effect = {
	            HOUSE = scope:house_friend.house
	            VALUE = house_relation_improve_minor_value
	            REASON = gdp_merchant_family.0020.a.relation_improve.desc
	            CHAR = root
	            TARGET_CHAR = scope:house_friend
	            TITLE = scope:dummy_gender
	        }
	    }

	   	stress_and_fulfillment_impact = {
	        ambitious = minor_stress_impact_loss
	        diligent = minor_stress_impact_gain
	        just = minor_stress_impact_gain
	        paranoid = major_stress_impact_gain
	    }

	    ai_chance = {
	        base = 25
	        ai_value_modifier = {
	            ai_sociability = medium_chance_impact_positive_ai_value
	        }
	        modifier = {
	            add = 20
	            scope:nepo_hire = {
	                sum_of_all_skills_value >= sum_of_all_skills_threshold_average
	            }
	        }
	        modifier = {
	            add = -30
	            scope:nepo_hire = {
	                sum_of_all_skills_value < sum_of_all_skills_threshold_terrible
	            }
	        }
	        modifier = {
	            add = -20
	            has_trait = just
	        }
	        modifier = {
	            add = -15
	            has_trait = diligent
	        }
	    }
	}
	# Humbly decline the offer
	option = {
	    name = gdp_merchant_family.0020.b
	    scope:house_friend = {
	        add_opinion = {
	            modifier = respect_opinion
	            target = root
	            opinion = 5
	        }
	    }
    	house = {
			add_unity_value = {
				value = minor_unity_gain
				character = root
				desc = gdp_merchant_family.0020.b.unity_gain.desc
			}
		}
	    stress_and_fulfillment_impact = {
	        humble = minor_stress_impact_loss
	        compassionate = minor_stress_impact_loss
	        ambitious = minor_stress_impact_gain
	    }
	    ai_chance = {
	        base = 15
	        ai_value_modifier = {
	            ai_compassion = medium_chance_impact_positive_ai_value
	        }
	        modifier = {
	            add = 20
	            has_trait = humble
	        }
	        modifier = {
	            add = 15
	            has_trait = compassionate
	        }
	        modifier = {
	            add = 15
	            scope:nepo_hire = {
	                sum_of_all_skills_value < sum_of_all_skills_threshold_terrible
	            }
	        }
	        modifier = {
	            add = -25
	            has_trait = arbitrary
	        }
	    }
	}
	# You are insulted by their incompetence 
	option = {
	    name = gdp_merchant_family.0020.c
	    trigger = {
	        scope:nepo_hire = {
	            sum_of_all_skills_value < sum_of_all_skills_threshold_terrible
	        }
	    }
	    house ?= {
	        change_house_relation_effect = {
	            HOUSE = scope:house_friend.house
	            VALUE = house_relation_damage_minor_value
	            REASON = gdp_merchant_family.0020.c.relation_damage.desc
	            CHAR = root
	            TARGET_CHAR = scope:house_friend
	            TITLE = scope:dummy_gender
	        }
	    }
	    scope:house_friend = {
	        add_opinion = {
	            modifier = insulted_opinion
	            target = root
	            opinion = -20
	        }
	    }
	    add_prestige = minor_prestige_gain
	    stress_and_fulfillment_impact = {
			arrogant = minor_stress_impact_loss
			callous = minor_stress_impact_loss
			compassionate = minor_stress_impact_gain
			just = minor_stress_impact_gain
			humble = minor_stress_impact_gain
	    }
	    ai_chance = {
	        base = 5
	        modifier = {
	            add = 25
	            has_trait = arrogant
	        }
	        modifier = {
	            add = 15
	            has_trait = diligent
	        }
	        modifier = {
	            add = 15
	            has_trait = callous
	        }
	        modifier = {
	            factor = 0
	            OR = {
	                has_trait = humble
	                has_trait = compassionate
	            }
	        }
	    }
	}
}

# Nothing Personal
gdp_merchant_family.0025 = {
	type = character_event
	title = gdp_merchant_family.0025.t
	desc = gdp_merchant_family.0025.desc
	theme = merchant
	override_background = study
	
	widgets = {
		widget = { gui = event_window_widget_vfx_background_flickering_candlelight_dark container = foreground_shader_vfx_container }
		widget = { gui = event_window_widget_vfx_left_character_flickering_candlelight_dark container = foreground_shader_vfx_container }
		widget = { gui = event_window_widget_vfx_right_character_flickering_candlelight_dark container = foreground_shader_vfx_container }
	}
	left_portrait = {
		character = root
		animation = anger
	}
	right_portrait = {
	    character = scope:leaving_associate
	    triggered_animation = {
	        trigger = {
	            has_any_good_relationship_with_character_trigger = { CHARACTER = root }
	        }
	        animation = sadness
	    }
	    triggered_animation = {
	        trigger = {
	            OR = {
	                has_any_bad_relationship_with_character_trigger = { CHARACTER = root }
	                has_trait = callous
	                has_trait = sadistic
	            }
	        }
	        animation = personality_callous
	    }
	    animation = nervous
	}
	lower_left_portrait = {
		character = scope:rival_poacher
	}

	cooldown = { years = 10 }

	trigger = {
	    is_house_head = yes
	    government_has_flag = government_is_merchant
	    is_available_adult = yes
	    house ?= {
	        OR = {
	            has_house_unity_stage = rapacious_cs
	            has_house_unity_stage = opportunistic_cs
	        }
	        any_house_relation = {
	            OR = {
	                has_house_relation_level = quarrel
	                has_house_relation_level = rivalry
	                has_house_relation_level = feud
	            }
	            any_relation_house = {
	                this != root.house
	                house_head ?= {
	                    is_ai = yes
	                    government_has_flag = government_is_merchant
	                    NOT = { this = root }
	                    save_temporary_scope_as = temp_poacher
	                }
	            }
	        }
	    }
	    any_courtier = {
	        is_courtier_of = root
	        is_ai = yes
	        NOT = { this = root }
	        is_available_quick = { adult = yes imprisoned = no incapable = no }
	        NOT = { is_player_heir_of = root }
	    }
	}

	weight_multiplier = {
		modifier = {
			factor = 2
			house ?= {
				any_house_relation = {
					count >= 2
					OR = {
						has_house_relation_level = quarrel
						has_house_relation_level = rivalry
						has_house_relation_level = feud
					}
				}
			}
		}
	}

	immediate = {
	    house ?= {
	        random_house_relation = {
	            limit = {
	                OR = {
	                    has_house_relation_level = quarrel
	                    has_house_relation_level = rivalry
	                    has_house_relation_level = feud
	                }
	                any_relation_house = {
	                    this != root.house
	                    house_head ?= {
	                        is_ai = yes
	                        government_has_flag = government_is_merchant
	                        NOT = { this = root }
	                        save_temporary_scope_as = temp_poacher
	                    }
	                }
	            }
	        }
	        scope:temp_poacher = { save_scope_as = rival_poacher }
	    }
	    random_courtier = {
	        limit = {
	            is_courtier_of = root
	            is_ai = yes
	            NOR = {
	            	this = root
	            	this = scope:rival_poacher
	            }
	            is_available_quick = { adult = yes imprisoned = no incapable = no }
	            NOT = { is_player_heir_of = root }
	        }
	        save_scope_as = leaving_associate
	    }
	}
	#Let them go with your blessing
	option = {
	    name = gdp_merchant_family.0025.a
	    trigger = {
	        has_any_good_relationship_with_character_trigger = { CHARACTER = scope:leaving_associate }
	    }
	    scope:rival_poacher = {
	        add_courtier = scope:leaving_associate
	    }
	    reverse_add_opinion = {
	        target = scope:leaving_associate
	        modifier = grateful_opinion
	        opinion = 40
	    }
	    house ?= {
	        change_house_relation_effect = {
	            HOUSE = scope:rival_poacher.house
	            VALUE = house_relation_improve_minor_value
	            REASON = gdp_merchant_family.0025.a.relation_improve.desc
	            CHAR = root
	            TARGET_CHAR = scope:rival_poacher
	            TITLE = scope:dummy_gender
	        }
	    }
	    stress_and_fulfillment_impact = {
	        generous = minor_stress_impact_loss
	        compassionate = minor_stress_impact_loss
	        forgiving = minor_stress_impact_loss
	        greedy = minor_stress_impact_gain
	        vengeful = minor_stress_impact_gain
	        arbitrary = minor_stress_impact_gain
	    }
	    ai_chance = {
	        base = 10
	        ai_value_modifier = {
	            ai_honor = medium_chance_impact_positive_ai_value
	        }
	        modifier = {
	            add = 20
	            OR = {
	                has_trait = generous
	                has_trait = just
	                has_trait = compassionate
	                has_trait = forgiving
	            }
	        }
	        modifier = {
	            factor = 0
	            OR = {
	                has_trait = wrathful
	                has_trait = vengeful
	            }
	        }
	    }
	}
	#You try to convince your associate to stay
	option = {
		name = gdp_merchant_family.0025.b
		duel = {
			skill = diplomacy
			value = decent_skill_rating
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				modifier = {
					add = 15
					scope:leaving_associate = {
						opinion = { target = root value >= low_positive_opinion }
					}
				}
				modifier = {
					add = 10
					has_any_good_relationship_with_character_trigger = { CHARACTER = scope:leaving_associate }
				}
				desc = gdp_merchant_family.0025.b.success
				send_interface_toast = {
					type = event_toast_effect_good
					title = gdp_merchant_family.0025.b.success
					left_icon = root
					right_icon = scope:leaving_associate
					custom_tooltip = gdp_merchant_family.0025.b.tt
				}
			}
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = gdp_merchant_family.0025.b.fail
				send_interface_toast = {
					type = event_toast_effect_bad
					title = gdp_merchant_family.0025.b.fail
					left_icon = root
					right_icon = scope:leaving_associate
					scope:rival_poacher = {
						add_courtier = scope:leaving_associate
					}
				}
			}
		}
		stress_and_fulfillment_impact = {
			compassionate = minor_stress_impact_loss
			arrogant = minor_stress_impact_gain
			shy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 15
			ai_value_modifier = {
				ai_sociability = medium_chance_impact_positive_ai_value
			}
			modifier = {
				add = 25
				has_any_good_relationship_with_character_trigger = { CHARACTER = scope:leaving_associate }
			}
			modifier = {
				add = 15
				diplomacy >= decent_skill_rating
			}
			modifier = {
				factor = 0
				has_usable_hook = scope:leaving_associate
			}
		}
	}
	#Use a hook to make the associate stay
	option = {
		name = gdp_merchant_family.0025.c
		trigger = {
			has_usable_hook = scope:leaving_associate
		}
		use_hook = scope:leaving_associate
		scope:leaving_associate = {
			add_opinion = {
				modifier = angry_opinion
				target = root
				opinion = -15
			}
		}
		stress_and_fulfillment_impact = {
			compassionate = minor_stress_impact_gain
			just = minor_stress_impact_gain
			deceitful = minor_stress_impact_loss
		}
		ai_chance = {
			base = 10
			modifier = {
				add = 15
				has_trait = deceitful
			}
		}
	}
	#Allow them to leave, with spite
	option = {
		name = {
			text = {
				first_valid = {
					triggered_desc = {
						trigger = {
							OR = {
								has_relation_rival = scope:rival_poacher
								has_relation_nemesis = scope:rival_poacher
							}
						}
						desc = gdp_merchant_family.0025.d.rival
					}
					desc = gdp_merchant_family.0025.d
				}
			}
		}
		scope:rival_poacher = {
			add_courtier = scope:leaving_associate
		}
		house ?= {
			change_house_relation_effect = {
				HOUSE = scope:rival_poacher.house
				VALUE = house_relation_damage_medium_value
				REASON = gdp_merchant_family.0025.d.relation_damage.desc
				CHAR = root
				TARGET_CHAR = scope:rival_poacher
				TITLE = scope:dummy_gender
			}
		}
		progress_towards_rival_effect = {
			REASON = rival_poached_associate
			CHARACTER = scope:rival_poacher
			OPINION = 0
		}
		stress_and_fulfillment_impact = {
			wrathful = minor_stress_impact_loss
			vengeful = minor_stress_impact_loss
			callous = minor_stress_impact_loss
			calm = minor_stress_impact_gain
			humble = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			modifier = {
				add = 25
				OR = {
					has_trait = wrathful
					has_trait = vengeful
					has_trait = arbitrary
					has_trait = callous
				}
			}
			modifier = {
				factor = 0
				has_any_good_relationship_with_character_trigger = { CHARACTER = scope:leaving_associate }
			}
			modifier = {
				factor = 0
				has_usable_hook = scope:leaving_associate
			}
		}
	}
}

# House Member(s) loiter instead of working
gdp_merchant_family.0030 = {
	type = character_event
	title = gdp_merchant_family.0030.t
	desc = gdp_merchant_family.0030.desc

	theme = merchant
	override_background = study

	left_portrait = {
		character = scope:house_member
		animation = toast
	}

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

	cooldown = { years = 10 }

	trigger = {
		is_house_head = yes
		government_has_flag = government_is_merchant
		house ?= {		
			any_house_member = {
				this != root
				is_courtier_of = root
				is_available_ai_adult = yes
				drinks_alcohol_trigger = yes
				save_temporary_scope_as = temp_char
			}
		}
		any_courtier = {
			is_available_ai_adult = yes
			drinks_alcohol_trigger = yes
			NOT = { this = scope:temp_char }
			can_set_relation_friend_trigger = { CHARACTER = scope:temp_char }
		}
	}

	weight_multiplier = {
		modifier = {
			factor = 2
			house ?= {
				OR = {
					has_house_unity_stage = ennobled_cs
					has_house_unity_stage = grasping_cs
				}
			}
		}
	}

	immediate = {
		house ?= {		
			random_house_member = {
				limit = {
					this != root
					is_courtier_of = root
					is_available_ai_adult = yes
					drinks_alcohol_trigger = yes
				}
				weight = {
					base = 1
					modifier = {
						add = ai_sociability
					}
					modifier = {
						factor = 2
						has_trait = gregarious
					}
				}
				save_scope_as = house_member
			}
		}
		random_courtier = {
			limit = {
				is_available_ai_adult = yes
				drinks_alcohol_trigger = yes
				NOT = { this = scope:house_member }
				can_set_relation_friend_trigger = { CHARACTER = scope:house_member }
			}
			save_scope_as = associate
		}
	}

	option = { # Join them
		name = gdp_merchant_family.0030.a
		flavor = gdp_merchant_family.0030.a.flavor
		trigger = { drinks_alcohol_trigger = yes }
		house ?= {
			add_unity_value = {
				value = medium_unity_gain
				character = root
				desc = merchant_unity_breaks_encouraged
			}
		}
		reverse_add_opinion = {
			target = scope:house_member
			modifier = pleased_opinion
			opinion = 15
		}
		reverse_add_opinion = {
			target = scope:associate
			modifier = pleased_opinion
			opinion = 15
		}
		scope:house_member = {		
			if = {
				limit = {
					NOT = { has_trait = lifestyle_reveler }
				}
				random = {
					chance = 5
					add_trait = lifestyle_reveler
				}
			}
		}
		stress_impact = {
			ambitious = medium_stress_impact_gain
			lazy = medium_stress_impact_loss
			gregarious = medium_stress_impact_loss
			lifestyle_reveler = medium_stress_impact_loss
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_sociability = 1
			}
			modifier = {
				factor = 0
				has_trait = ambitious
			}
		}
	}

	option = { # Scold them :whip:
		name = gdp_merchant_family.0030.b
		flavor = gdp_merchant_family.0030.b.flavor
		house ?= {
			add_unity_value = {
				value = medium_unity_loss
				character = root
				desc = merchant_unity_breaks_discouraged
			}
		}
		reverse_add_opinion = {
			target = scope:house_member
			modifier = annoyed_opinion
			opinion = -15
		}
		reverse_add_opinion = {
			target = scope:associate
			modifier = annoyed_opinion
			opinion = -15
		}
		stress_impact = {
			arrogant = medium_stress_impact_loss
			callous = medium_stress_impact_loss
			compassionate = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_sociability = -1
				ai_compassion = -1
			}
			modifier = {
				factor = 0
				has_trait = compassionate
			}
		}
	}
	option = { # encourage the friendship
		name = gdp_merchant_family.0030.c
		scope:house_member = {
			progress_towards_friend_effect = {
				REASON = friend_bonded_over_work_break
				CHARACTER = scope:associate
				OPINION = default_friend_opinion
			}
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 1
			}
		}
	}
}

# Coming of age
gdp_merchant_family.9000 = {
	type = character_event
	title = gdp_merchant_family.9000.t
	desc = {
		desc = gdp_merchant_family.9000.desc
	}
	theme = merchant
	left_portrait = {
		character = root
		animation = holding_scales
	}
	right_portrait = {
		character = scope:portrait
		animation = admiration
	}
	lower_center_portrait = scope:predecessor

	trigger = {
		is_landless_merchant = yes
	}

	immediate = {
		# Scopes
		save_scope_as = merchant
		var:educator ?= {
			if = {
				limit = { court_owner = root }
				save_scope_as = educator
				save_scope_as = portrait
			}
		}
		court_position:partner_court_position ?= {
			save_scope_as = partner
			if = {
				limit = {
					NOT = { exists = scope:portrait }
				}
				save_scope_as = portrait
			}
		}
		primary_title.previous_holder ?= { save_scope_as = predecessor }
		# Trait
		if = {
			limit = {
				NOT = { has_trait = lifestyle_merchant }
			}
			add_trait = lifestyle_merchant
		}
		# Good
		ordered_trade_good_category = {
			limit = {
				has_trade_good_category_xp_track = yes
				save_temporary_scope_as = category_temp
				"scope:merchant.primary_title.trade_good_category_level(scope:category_temp)" > 4
			}
			order_by = "root.primary_title.trade_good_category_level(scope:category_temp)"
			save_scope_as = best_category
		}
		custom_tooltip = gdp_merchant_family.9000.route_hint_tt
		### Childhood boons
		# Trait bonus
		if = {
			limit = {
				NOT = { var:merchant_childhood_purpose ?= flag:caravaneer }
				has_character_flag = merchant_childhood_caravaneer_bonus
			}
			add_trait_xp = {
				trait = lifestyle_merchant
				track = caravaneer
				value = 10
			}
		}
		# Purpose
		if = {
			limit = { exists = var:merchant_childhood_purpose }
			switch = {
				trigger = var:merchant_childhood_purpose
				flag:caravaneer = {
					if = {
						limit = { NOT = { has_realm_law = company_purpose_caravaneer } }
						add_realm_law_skip_effects = company_purpose_caravaneer
					}
					add_trait_xp = {
						trait = lifestyle_merchant
						track = caravaneer
						value = {
							value = 20
							if = {
								limit = {
									root = { has_character_flag = merchant_childhood_caravaneer_bonus }
								}
								add = 10
							}
						}
					}
				}
				flag:artisan = {
					if = {
						limit = { NOT = { has_realm_law = company_purpose_artisan } }
						add_realm_law_skip_effects = company_purpose_artisan
					}
					add_trait_xp = {
						trait = lifestyle_merchant
						track = artisan
						value = 20
					}
				}
				flag:creditor = {
					if = {
						limit = { NOT = { has_realm_law = company_purpose_creditor } }
						add_realm_law_skip_effects = company_purpose_creditor
					}
					add_trait_xp = {
						trait = lifestyle_merchant
						track = creditor
						value = 20
					}
				}
				flag:family = {
					add_trait_xp = {
						trait = lifestyle_merchant
						track = caravaneer
						value = 5
					}
					add_trait_xp = {
						trait = lifestyle_merchant
						track = artisan
						value = 5
					}
					add_trait_xp = {
						trait = lifestyle_merchant
						track = creditor
						value = 5
					}
				}
			}
		}
		# Expertise
		if = {
			limit = {
				exists = var:merchant_childhood_bonus_category
				NOT = { exists = var:merchant_childhood_category }
			}
			var:merchant_childhood_bonus_category ?= { save_scope_as = category }
			primary_title = {
				add_trade_good_category_xp = {
					target = scope:category
					value = 450
				}
			}
		}
		else_if = {
			limit = {
				NOT = { exists = var:merchant_childhood_bonus_category }
				exists = var:merchant_childhood_category
			}
			var:merchant_childhood_category ?= { save_scope_as = category }
			primary_title = {
				add_trade_good_category_xp = {
					target = scope:category
					value = 450
				}
			}
		}
		else_if = {
			limit = {
				exists = var:merchant_childhood_bonus_category
				exists = var:merchant_childhood_category
			}
			if = {
				limit = { var:merchant_childhood_bonus_category ?= var:merchant_childhood_category }
				var:merchant_childhood_bonus_category ?= { save_scope_as = category }
				primary_title = {
					add_trade_good_category_xp = {
						target = scope:category
						value = trade_expertise_xp_monumental_value
					}
				}
			}
			else = {
				primary_title = {
					add_trade_good_category_xp = {
						target = root.var:merchant_childhood_category
						value = 450
					}
				}
				primary_title = {
					add_trade_good_category_xp = {
						target = root.var:merchant_childhood_bonus_category
						value = 450
					}
				}
			}
		}
		# Modifiers
		if = {
			limit = { has_character_flag = merchant_childhood_suzerain_opinion }
			add_character_modifier = {
				modifier = merchant_childhood_suzerain_modifier
				years = 10
			}
		}
	}

	option = { # Appoint educator as partner option
		name = gdp_merchant_family.9000.a
		trigger = {
			exists = scope:educator
			NOT = { employs_court_position = partner_court_position }
			can_employ_court_position_type = partner_court_position
		}
		appoint_court_position = {
			recipient = scope:educator
			court_position = partner_court_position
		}
		scope:educator = { save_temporary_scope_as = candidate }
		custom_tooltip = partner_aptitude_tooltip
		reverse_add_opinion = {
			modifier = respect_opinion
			target = scope:educator
			opinion = 15
		}
		ai_chance = {
			base = 10
		}
	}

	option = {
		name = gdp_merchant_family.9000.b
		ai_chance = {
			base = 10
		}
	}

	after = {
		remove_variable = merchant_childhood_purpose
		remove_variable = merchant_childhood_category
		remove_variable = merchant_childhood_bonus_category
		remove_character_flag = merchant_childhood_caravaneer_bonus
		remove_character_flag = merchant_childhood_suzerain_opinion
	}
}

# Child inheritance
gdp_merchant_family.9010 = {
	type = character_event
	title = gdp_merchant_family.9010.t
	desc = {
		desc = gdp_merchant_family.9010.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:interim ?= { has_character_flag = generated_interim }
				}
				desc = gdp_merchant_family.9010.interim_generated
			}
			triggered_desc = {
				trigger = {
					OR = {
						any_relation = { this = scope:interim }
						is_close_or_extended_family_of = scope:interim
					}
				}
				desc = gdp_merchant_family.9010.interim_relation
			}
			desc = gdp_merchant_family.9010.interim
		}
		desc = gdp_merchant_family.9010.close
	}
	theme = merchant
	left_portrait = {
		character = root
		animation = idle
	}
	right_portrait = {
		character = scope:interim
		animation = worry
	}
	lower_right_portrait = scope:previous_holder

	trigger = {
		is_landless_merchant = yes
		is_adult = no
		OR = {
			employs_court_position = partner_court_position
			can_employ_court_position_type = partner_court_position
		}
	}

	immediate = {
		if = {
			limit = {
				NOT = { employs_court_position = partner_court_position }
			}
			random_courtier = {
				limit = {
					is_available_quick = {
						adult = yes
						incapable = no
						imprisoned = no
					}
					has_relation_guardian = root
				}
				alternative_limit = {
					is_available_quick = {
						adult = yes
						incapable = no
						imprisoned = no
					}
					health >= fine_health
				}
				alternative_limit = {
					is_available_quick = {
						adult = yes
						incapable = no
						imprisoned = no
					}
				}
				weight = {
					base = 1
					modifier = { add = stewardship }
					modifier = {
						has_trait = education_stewardship_3
						add = 5
					}
					modifier = {
						has_trait = education_stewardship_4
						add = 10
					}
					modifier = {
						has_trait = education_stewardship_5
						add = 20
					}
					modifier = {
						has_any_good_relationship_with_character_trigger = { CHARACTER = root }
						add = 25
					}
					modifier = {
						is_close_family_of = root
						add = 10
					}
					modifier = {
						is_extended_family_of = root
						add = 5
					}
					modifier = {
						house ?= root.house
						add = 5
					}
				}
				save_scope_as = interim
			}
			if = {
				limit = {
					NOT = { exists = scope:interim }
				}
				create_character = {
					template = good_merchant_template
					dynasty = none
					employer = root
					save_scope_as = interim
				}
				scope:interim = {
					add_character_flag = {
						flag = generated_interim
						weeks = 1
					}
				}
			}
			if = {
				limit = { can_employ_court_position_type = partner_court_position }
				appoint_court_position = {
					recipient = scope:interim
					court_position = partner_court_position
				}
			}
		}
		else = {
			court_position:partner_court_position = { save_scope_as = interim}
		}
	}

	option = {
		name = gdp_merchant_family.9010.a
		ai_chance = {
			base = 10
		}
	}
}

scripted_trigger shared_merchant_childhood_helper_trigger = {
	is_available_quick = {
		incapable = no
		imprisoned = no
	}
	NOR = {
		has_relation_rival = root
		has_relation_bully = root
	}
}

# Trader help
gdp_merchant_family.9110 = {
	type = character_event
	title = gdp_merchant_family.9110.t
	desc = gdp_merchant_family.9110.desc
	theme = merchant
	left_portrait = {
		character = root
		animation = thinking
	}
	right_portrait = {
		character = scope:trader
		animation = holding_tally_stick
	}
	cooldown = { years = 10 }

	trigger = {
		is_landless_merchant = yes
		is_adult = no
		age > 7
		any_courtier = {
			is_adult = yes
			is_trader = yes
			shared_merchant_childhood_helper_trigger = yes
			assigned_trade_route ?= {
				any_trade_market_on_route = {
					NOT = { this = root.domicile.domicile_location.barony.trade_market }
					save_temporary_scope_as = market_temp
				}
				any_traded_good = {
					save_temporary_scope_as = good_temp
					scope:market_temp = {
						OR = {
							any_trade_good_with_need = { this = scope:good_temp }
							any_trade_good_with_surplus = { this = scope:good_temp }
						}
					}
				}
			}
		}
	}

	immediate = {
		save_scope_as = merchant
		random_courtier = {
			limit = {
				is_adult = yes
				is_trader = yes
				shared_merchant_childhood_helper_trigger = yes
				location = root.location
				NOT = { has_character_flag = merchant_childhood_associate_cooldown }
			}
			alternative_limit = {
				is_adult = yes
				is_trader = yes
				location = root.location
				shared_merchant_childhood_helper_trigger = yes
			}
			alternative_limit = {
				is_adult = yes
				is_trader = yes
				shared_merchant_childhood_helper_trigger = yes
			}
			weight = {
				base = 1
				modifier = { add = stewardship }
				opinion_modifier = {
					opinion_target = root
					multiplier = 0.2
				}
			}
			save_scope_as = trader
		}
		scope:trader ?= {
			add_character_flag = {
				flag = merchant_childhood_associate_cooldown
				years = 3
			}
			assigned_trade_route ?= {
				save_scope_as = route
				random_trade_market_on_route = {
					limit = {
						NOT = { this = scope:merchant.domicile.domicile_location.barony.trade_market }
					}
					weight = {
						base = 1
						modifier = {
							add = "trade_market_owner.title_province.squared_distance(scope:merchant.domicile.domicile_location)"
						}
					}
					save_scope_as = market
				}
				random_traded_good = {
					limit = {
						save_temporary_scope_as = good_temp
						scope:market = {
							OR = {
								any_trade_good_with_need = { this = scope:good_temp }
								any_trade_good_with_surplus = { this = scope:good_temp }
							}
						}
					}
					save_scope_as = good
				}
			}
		}
		scope:good ?= {
			random_trade_category = {
				limit = { has_trade_good_category_xp_track = yes }
				save_scope_as = category
			}
		}
	}

	option = {
		name = gdp_merchant_family.9110.a
		add_stewardship_skill = 1
		stress_and_fulfillment_impact = {
			lazy = minor_stress_impact_gain
			arrogant = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			modifier = {
				has_trait = lazy
				add = -5
			}
			modifier = {
				has_trait = arrogant
				add = -5
			}
		}
	}

	option = {
		name = gdp_merchant_family.9110.b
		progress_towards_friend_effect = {
			REASON = friend_merchant_childhood_bonding
			CHARACTER = scope:trader
			OPINION = default_friend_opinion
		}
		custom_tooltip = gdp_merchant_family.9110.b.tt
		add_character_flag = {
			flag = merchant_childhood_caravaneer_bonus
			years = 10
		}
		stress_and_fulfillment_impact = {
			shy = minor_stress_impact_gain
			craven = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			modifier = {
				has_trait = shy
				add = -5
			}
			modifier = {
				has_trait = craven
				add = -5
			}
		}
	}

	option = {
		name = gdp_merchant_family.9110.c
		trigger = { exists = scope:category }
		custom_tooltip = {
			text = gdp_merchant_family.9110.c.tt
			set_variable = {
				name = merchant_childhood_bonus_category
				value = scope:category
			}
		}
		stress_and_fulfillment_impact = {
			gregarious = minor_stress_impact_gain
			brave = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			modifier = {
				has_trait = gregarious
				add = -5
			}
			modifier = {
				has_trait = brave
				add = -5
			}
		}
	}
}

# Purpose help
gdp_merchant_family.9130 = {
	type = character_event
	title = gdp_merchant_family.9130.t
	desc = {
		desc = gdp_merchant_family.9130.desc
		first_valid = {
			triggered_desc = {
				trigger = { has_realm_law = company_purpose_caravaneer }
				desc = gdp_merchant_family.9130.caravaneer
			}
			triggered_desc = {
				trigger = { has_realm_law = company_purpose_artisan }
				desc = gdp_merchant_family.9130.artisan
			}
			triggered_desc = {
				trigger = { has_realm_law = company_purpose_creditor }
				desc = gdp_merchant_family.9130.creditor
			}
			desc = gdp_merchant_family.9130.fallback
		}
	}
	theme = merchant
	left_portrait = {
		character = root
		animation = thinking
	}
	right_portrait = {
		character = scope:associate
		animation = writing
	}
	cooldown = { years = 10 }

	trigger = {
		is_landless_merchant = yes
		is_adult = no
		age > 7
	}

	immediate = {
		random_courtier = {
			limit = {
				is_adult = yes
				root.court_position:partner_court_position ?= this
				shared_merchant_childhood_helper_trigger = yes
				NOT = { has_character_flag = merchant_childhood_associate_cooldown }
			}
			alternative_limit = {
				is_adult = yes
				root.court_position:partner_court_position ?= this
				shared_merchant_childhood_helper_trigger = yes
			}
			alternative_limit = {
				is_adult = yes
				shared_merchant_childhood_helper_trigger = yes
			}
			weight = {
				base = 1
				modifier = { add = stewardship }
				modifier = {
					is_close_or_extended_family_of = root
					add = 10
				}
				opinion_modifier = {
					opinion_target = root
					multiplier = 0.2
				}
			}
			save_scope_as = associate
		}
		scope:associate ?= {
			add_character_flag = {
				flag = merchant_childhood_associate_cooldown
				years = 3
			}
		}
	}

	option = {
		name = {
			trigger = { has_realm_law = company_purpose_caravaneer }
			text = gdp_merchant_family.9130.a.caravaneer
		}
		name = {
			trigger = { has_realm_law = company_purpose_artisan }
			text = gdp_merchant_family.9130.a.artisan
		}
		name = {
			trigger = { has_realm_law = company_purpose_creditor }
			text = gdp_merchant_family.9130.a.creditor
		}
		name = {
			trigger = { has_realm_law = company_purpose_family }
			text = gdp_merchant_family.9130.a
		}
		add_stewardship_skill = 1
		switch = {
			trigger = has_realm_law
			company_purpose_caravaneer = {
				custom_tooltip = {
					text = gdp_merchant_family.9130.b.tt
					set_variable = {
						name = merchant_childhood_purpose
						value = flag:caravaneer
						years = 10
					}
				}
				stress_and_fulfillment_impact = {
					ambitious = minor_stress_impact_loss
					craven = minor_stress_impact_gain
					content = minor_stress_impact_gain
					curious = miniscule_stress_impact_loss
				}
			}
			company_purpose_artisan = {
				custom_tooltip = {
					text = gdp_merchant_family.9130.c.tt
					set_variable = {
						name = merchant_childhood_purpose
						value = flag:artisan
						years = 10
					}
				}
				stress_and_fulfillment_impact = {
					patient = minor_stress_impact_loss
					lazy = minor_stress_impact_gain
					humble = minor_stress_impact_gain
					pensive = miniscule_stress_impact_loss
				}
			}
			company_purpose_creditor = {
				custom_tooltip = {
					text = gdp_merchant_family.9130.d.tt
					set_variable = {
						name = merchant_childhood_purpose
						value = flag:creditor
						years = 10
					}
				}
				stress_and_fulfillment_impact = {
					trusting = minor_stress_impact_loss
					shy = minor_stress_impact_gain
					impatient = minor_stress_impact_gain
					charming = minor_stress_impact_loss
				}
			}
			company_purpose_family = {
				custom_tooltip = {
					text = gdp_merchant_family.9130.a.tt
					set_variable = {
						name = merchant_childhood_purpose
						value = flag:family
						years = 10
					}
				}
				stress_and_fulfillment_impact = {
					content = minor_stress_impact_loss
					fickle = minor_stress_impact_gain
					arbitrary = minor_stress_impact_gain
					bossy = miniscule_stress_impact_gain
				}
			}
		}
		ai_chance = {
			base = 50
			modifier = {
				has_trait = content
				add = 10
			}
			modifier = {
				has_realm_law = company_purpose_family
				add = -50
			}
		}
	}

	option = {
		name = gdp_merchant_family.9130.b
		trigger = {
			NOT = { has_realm_law = company_purpose_caravaneer }
		}
		add_diplomacy_skill = 1
		custom_tooltip = {
			text = gdp_merchant_family.9130.b.tt
			set_variable = {
				name = merchant_childhood_purpose
				value = flag:caravaneer
				years = 10
			}
		}
		stress_and_fulfillment_impact = {
			ambitious = minor_stress_impact_loss
			craven = minor_stress_impact_gain
			content = minor_stress_impact_gain
			curious = miniscule_stress_impact_loss
		}
		ai_chance = {
			base = 10
			modifier = { add = diplomacy }
			modifier = {
				has_trait = ambitious
				add = 10
			}
			modifier = {
				has_trait = craven
				add = -15
			}
			modifier = {
				has_trait = content
				add = -15
			}
			modifier = {
				has_trait = curious
				add = 10
			}
		}
	}

	option = {
		name = gdp_merchant_family.9130.c
		trigger = {
			NOT = { has_realm_law = company_purpose_artisan }
		}
		add_learning_skill = 1
		custom_tooltip = {
			text = gdp_merchant_family.9130.c.tt
			set_variable = {
				name = merchant_childhood_purpose
				value = flag:artisan
				years = 10
			}
		}
		stress_and_fulfillment_impact = {
			patient = minor_stress_impact_loss
			lazy = minor_stress_impact_gain
			humble = minor_stress_impact_gain
			pensive = miniscule_stress_impact_loss
		}
		ai_chance = {
			base = 10
			modifier = { add = learning }
			modifier = {
				has_trait = diligent
				add = 10
			}
			modifier = {
				has_trait = lazy
				add = -15
			}
			modifier = {
				has_trait = impatient
				add = -15
			}
			modifier = {
				has_trait = pensive
				add = 10
			}
		}
	}

	option = {
		name = gdp_merchant_family.9130.d
		trigger = {
			NOT = { has_realm_law = company_purpose_creditor }
		}
		add_intrigue_skill = 1
		custom_tooltip = {
			text = gdp_merchant_family.9130.d.tt
			set_variable = {
				name = merchant_childhood_purpose
				value = flag:creditor
				years = 10
			}
		}
		stress_and_fulfillment_impact = {
			trusting = minor_stress_impact_loss
			shy = minor_stress_impact_gain
			impatient = minor_stress_impact_gain
			charming = minor_stress_impact_loss
		}
		ai_chance = {
			base = 10
			modifier = { add = intrigue }
			modifier = {
				has_trait = greedy
				add = 10
			}
			modifier = {
				has_trait = shy
				add = -15
			}
			modifier = {
				has_trait = trusting
				add = -15
			}
			modifier = {
				has_trait = charming
				add = 10
			}
		}
	}
}

# Expertise help
gdp_merchant_family.9140 = {
	type = character_event
	title = gdp_merchant_family.9140.t
	desc = gdp_merchant_family.9140.desc
	theme = merchant
	left_portrait = {
		character = root
		animation = boredom
		camera = camera_event_left_wedding
	}
	right_portrait = {
		character = scope:associate
		animation = stressed_teacher
	}
	cooldown = { years = 10 }
	override_background = study

	trigger = {
		is_landless_merchant = yes
		is_adult = no
		age > 7
		save_temporary_scope_as = merchant_temp
		any_trade_good_category = {
			has_trade_good_category_xp_track = yes
			save_temporary_scope_as = category_temp
			"scope:merchant_temp.primary_title.trade_good_category_level(scope:category_temp)" < 100
		}
	}

	immediate = {
		# Scopes
		save_scope_as = merchant
		random_courtier = {
			limit = {
				is_adult = yes
				root.court_position:partner_court_position ?= this
				shared_merchant_childhood_helper_trigger = yes
				NOT = { has_character_flag = merchant_childhood_associate_cooldown }
			}
			alternative_limit = {
				is_adult = yes
				root.court_position:partner_court_position ?= this
				shared_merchant_childhood_helper_trigger = yes
			}
			alternative_limit = {
				is_adult = yes
				shared_merchant_childhood_helper_trigger = yes
			}
			weight = {
				base = 1
				modifier = { add = stewardship }
				modifier = {
					is_close_or_extended_family_of = root
					add = 10
				}
				opinion_modifier = {
					opinion_target = root
					multiplier = 0.2
				}
			}
			save_scope_as = associate
		}
		scope:associate ?= {
			add_character_flag = {
				flag = merchant_childhood_associate_cooldown
				years = 3
			}
		}
		ordered_trade_good_category = {
			limit = {
				has_trade_good_category_xp_track = yes
				save_temporary_scope_as = category_temp
				"scope:merchant.primary_title.trade_good_category_level(scope:category_temp)" > 4
				"scope:merchant.primary_title.trade_good_category_level(scope:category_temp)" < 100
			}
			order_by = "scope:merchant.primary_title.trade_good_category_level(scope:category_temp)"
			max = 3
			check_range_bounds = no
			if = {
				limit = { exists = scope:category_2 }
				save_scope_as = category_3
			}
			else_if = {
				limit = { exists = scope:category_1 }
				save_scope_as = category_2
			}
			else = { save_scope_as = category_1 }
		}
		# Fallback, can be 0 but not max
		hidden_effect = {
			while = {
				count = 3
				if = {
					limit = {
						NOT = { exists = scope:category_3 }
					}
					random_trade_good_category = {
						limit = {
							has_trade_good_category_xp_track = yes
							save_temporary_scope_as = category_temp
							"scope:merchant.primary_title.trade_good_category_level(scope:category_temp)" < 100
							NOR = {
								scope:category_1 ?= this
								scope:category_2 ?= this
								scope:category_3 ?= this
							}
						}
						if = {
							limit = { exists = scope:category_2 }
							save_scope_as = category_3
						}
						else_if = {
							limit = { exists = scope:category_1 }
							save_scope_as = category_2
						}
						else = { save_scope_as = category_1 }
					}
				}
			}
		}
	}

	option = {
		name = gdp_merchant_family.9140.a
		custom_tooltip = gdp_merchant_family.9140.a.tt
		set_variable = {
			name = merchant_childhood_category
			value = scope:category_1
			years = 10
		}
		ai_chance = {
			base = 1
			modifier = {
				exists = scope:category_1
				add = {
					value = "scope:merchant.primary_title.trade_good_category_level(scope:category_1)"
					divide = 5
					floor = yes
				}
			}
			modifier = {
				exists = scope:category_1
				add = {
					value = 0
					every_trade_route = {
						limit = {
							any_traded_good = {
								any_trade_category = { this = scope:category_1 }
							}
						}
						add = 5
					}
				}
			}
		}
	}

	option = {
		name = gdp_merchant_family.9140.b
		trigger = { exists = scope:category_2 }
		custom_tooltip = gdp_merchant_family.9140.b.tt
		set_variable = {
			name = merchant_childhood_category
			value = scope:category_2
			years = 10
		}
		ai_chance = {
			base = 1
			modifier = {
				exists = scope:category_2
				add = {
					value = "scope:merchant.primary_title.trade_good_category_level(scope:category_2)"
					divide = 5
					floor = yes
				}
			}
			modifier = {
				exists = scope:category_2
				add = {
					value = 0
					every_trade_route = {
						limit = {
							any_traded_good = {
								any_trade_category = { this = scope:category_2 }
							}
						}
						add = 5
					}
				}
			}
		}
	}

	option = {
		name = gdp_merchant_family.9140.c
		trigger = { exists = scope:category_3 }
		custom_tooltip = gdp_merchant_family.9140.c.tt
		set_variable = {
			name = merchant_childhood_category
			value = scope:category_3
			years = 10
		}
		ai_chance = {
			base = 1
			modifier = {
				exists = scope:category_3
				add = {
					value = "scope:merchant.primary_title.trade_good_category_level(scope:category_3)"
					divide = 5
					floor = yes
				}
			}
			modifier = {
				exists = scope:category_3
				add = {
					value = 0
					every_trade_route = {
						limit = {
							any_traded_good = {
								any_trade_category = { this = scope:category_3 }
							}
						}
						add = 5
					}
				}
			}
		}
	}
}

# Partner help
gdp_merchant_family.9150 = {
	type = character_event
	title = gdp_merchant_family.9150.t
	desc = {
		desc = gdp_merchant_family.9150.desc
	}
	theme = merchant
	left_portrait = {
		character = root
		animation = biting_coin
	}
	right_portrait = {
		character = scope:partner
		animation = steward
	}
	lower_center_portrait = suzerain
	override_background = { reference = study }
	cooldown = { years = 10 }

	trigger = {
		is_landless_merchant = yes
		is_adult = no
		age > 7
		court_position:partner_court_position ?= { shared_merchant_childhood_helper_trigger = yes }
	}

	immediate = {
		save_scope_as = merchant
		court_position:partner_court_position ?= { save_scope_as = partner }
		scope:partner ?= {
			add_character_flag = {
				flag = merchant_childhood_associate_cooldown
				years = 3
			}
		}
	}

	option = {
		name = gdp_merchant_family.9150.a
		switch = {
			trigger = has_focus
			education_diplomacy = {
				add_diplomacy_skill = 1
				add_diplomacy_lifestyle_xp = massive_lifestyle_xp
			}
			education_martial = {	
				add_martial_skill = 1
				add_martial_lifestyle_xp = massive_lifestyle_xp
			}
			education_stewardship = {
				add_stewardship_skill = 1
				add_stewardship_lifestyle_xp = massive_lifestyle_xp
			}
			education_intrigue = {
				add_intrigue_skill = 1
				add_intrigue_lifestyle_xp = massive_lifestyle_xp
			}
			education_learning = {
				add_learning_skill = 1
				add_learning_lifestyle_xp = massive_lifestyle_xp
			}
			fallback = {
				add_stewardship_skill = 1
				add_diplomacy_lifestyle_xp = medium_lifestyle_xp
				add_martial_lifestyle_xp = medium_lifestyle_xp
				add_stewardship_lifestyle_xp = medium_lifestyle_xp
				add_intrigue_lifestyle_xp = medium_lifestyle_xp
				add_learning_lifestyle_xp = medium_lifestyle_xp
			}
		}
		stress_and_fulfillment_impact = {
			base = minor_stress_impact_gain
			diligent = minor_stress_impact_loss
			lazy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			modifier = {
				has_trait = diligent
				add = 5
			}
			modifier = {
				has_trait = lazy
				add = -5
			}
		}
	}

	option = {
		name = gdp_merchant_family.9150.b
		pay_short_term_gold = {
			gold = minor_gold_value
			target = scope:partner
		}
		progress_towards_friend_effect = {
			REASON = friend_merchant_childhood_bonding
			CHARACTER = scope:partner
			OPINION = default_friend_opinion
		}
		custom_tooltip = gdp_merchant_family.9150.b.tt
		scope:partner = {
			set_variable = {
				name = merchant_childhood_partner_aptitude
				value = root
				years = 10
			}
		}
		stress_and_fulfillment_impact = {
			generous = minor_stress_impact_loss
			greedy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			modifier = {
				has_trait = generous
				add = 5
			}
			modifier = {
				has_trait = greedy
				add = -5
			}
		}
	}

	option = {
		name = gdp_merchant_family.9150.c
		custom_tooltip = {
			text = gdp_merchant_family.9150.c.tt
			add_character_flag = merchant_childhood_suzerain_opinion
		}
		stress_and_fulfillment_impact = {
			humble = minor_stress_impact_loss
			arrogant = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			modifier = {
				has_trait = humble
				add = 5
			}
			modifier = {
				has_trait = arrogant
				add = -5
			}
		}
	}
}
