﻿namespace = gdp_merchant_trade_opportunity

##################################################
# GENERAL SCRIPTED TRIGGERS & EFFECTS

# Syncs stress lost from successfully completing a trade deal scheme.
scripted_effect merchant_base_contract_schemes_acknowledge_success_stress_effect = {
	stress_and_fulfillment_impact = { arrogant = minor_stress_impact_loss }
}

# Syncs stress gained from failing a trade deal scheme.
scripted_effect merchant_base_contract_schemes_acknowledge_failure_stress_effect = {
	if = {
		limit = { scope:task_contract_tier >= 2 }
		stress_and_fulfillment_impact = {
			base = miniscule_stress_impact_gain
			humble = minor_stress_impact_loss
			arrogant = minor_stress_impact_gain
		}
	}
}

scripted_effect save_trade_opportunity_contract_scopes_effect = {
	scope:task_contract = {
		task_contract_target ?= { save_scope_as = task_contract_target }
		task_contract_employer ?= { save_scope_as = associate }
		var:task_contract_trade_good ?= { save_scope_as = trade_good_type }
		var:task_contract_trade_category ?= { save_scope_as = trade_good_category }
		task_contract_location = {
			save_scope_as = task_contract_location
			save_scope_as = destination
			barony ?= {
				save_scope_as = task_contract_title
				trade_market = { save_scope_as = local_market }
			}
		}
	}
}

####
# gdp_merchant_trade_opportunity.0001-0010 - Challenge Competitor
###

gdp_merchant_trade_opportunity.0001 = { # intro
	type = character_event
	title = gdp_merchant_trade_opportunity.0001.t
	desc = gdp_merchant_trade_opportunity.0001.desc
	theme = trade
	left_portrait = {
		character = root
		animation = pondering
	}
	lower_right_portrait = scope:task_contract_target

	trigger = {
		scope:task_contract = {
			has_task_contract_type = challenge_competitor
			exists = task_contract_target
		}
		scope:task_contract.task_contract_target = { is_alive = yes }
	}

	immediate = {
		save_trade_opportunity_contract_scopes_effect = yes
		start_scheme = {
			type = merchant_challenge_competitor_trade_opportunity_scheme
			contract = scope:task_contract
			target_title = scope:task_contract_target.primary_title
		}
		scope:task_contract.scheme = { save_scope_as = task_contract_scheme } # save scheme
	}

	# Go for a balanced agent mix.
	option = {
		name = gdp_merchant_trade_opportunity.0001.d
		reason = give_me_balanced_agents
		flavor = EVENT_WINDOW_OPTION_AGENTS_BALANCED
		scope:task_contract_scheme ?= {
			# Success.
			add_agent_slot = agent_bailiff
			add_agent_slot = agent_muscle
			add_agent_slot = agent_bookkeeper
			# Speed.
			add_agent_slot = agent_overseer
			add_agent_slot = agent_messenger
		}
		# No stress, we're just selecting our starter batch.
		# AI always selects balanced agents.
		ai_chance = { base = 1000 }
	}

	# Focus on success chance agents.
	option = {
		name = gdp_merchant_trade_opportunity.0001.a
		reason = give_me_success_agents
		flavor = EVENT_WINDOW_OPTION_AGENTS_SUCCESS
		scope:task_contract_scheme ?= {
			# Success.
			add_agent_slot = agent_bailiff
			add_agent_slot = agent_muscle
			add_agent_slot = agent_bookkeeper
			add_agent_slot = agent_scribe
			# Speed.
			add_agent_slot = agent_overseer
		}
		# No stress, we're just selecting our starter batch.
		# AI always picks the balanced config.
	}
	
	# Focus on speedy agents.
	option = {
		name = gdp_merchant_trade_opportunity.0001.b
		reason = give_me_speed_agents
		flavor = EVENT_WINDOW_OPTION_AGENTS_SPEED
		scope:task_contract_scheme ?= {
			# Success.
			add_agent_slot = agent_bailiff
			add_agent_slot = agent_bookkeeper
			# Speed.
			add_agent_slot = agent_overseer
			add_agent_slot = agent_messenger
			add_agent_slot = agent_gabbler
		}
		# No stress, we're just selecting our starter batch.
		# AI always picks the balanced config.
	}
	
	# Now show us the panel.
	after = {
		open_view = {
			view = intrigue_window
			player = root
		}
	}
}

gdp_merchant_trade_opportunity.0002 = { # success
	type = character_event
	window = scheme_successful_event
	title = gdp_merchant_trade_opportunity.0002.t
	desc = gdp_merchant_trade_opportunity.0002.desc
	theme = trade
	center_portrait = {
		character = root
		animation = war_over_tie
	}
	right_portrait = {
		character = scope:target_title.holder
		animation = dismissal
	}
	override_background = { reference = sitting_room }

	immediate = {
		merchant_base_trade_opportunity_schemes_set_up_outcome_immediate_effect = yes
	}

	# Diplo
	option = {
		name = gdp_merchant_trade_opportunity.0002.b
		flavor = merchant_base_trade_opportunity_schemes.0000.f.contract_concluded
		trigger = {
			custom_tooltip = {
				text = gdp_merchant_trade_opportunity.0002.b.tt
				OR = {
					has_relation_friend = scope:target_title.holder
					is_spouse_of = scope:target_title.holder
					diplomacy >= high_skill_rating
				}
				NOR = {
					has_any_bad_relationship_with_character_trigger = { CHARACTER = scope:target_title.holder }
					house_has_feud_relation_with_trigger = { TARGET = scope:target_title.holder }
				}
			}
		}
		show_as_unavailable = { always = yes }
		scope:task_contract = { complete_task_contract = success_critical }
		# And wrap things up.
		scope:scheme ?= { end_scheme = yes }
	}

	# Antag
	option = {
		name = gdp_merchant_trade_opportunity.0002.a
		flavor = merchant_base_trade_opportunity_schemes.0000.f.contract_concluded
		scope:task_contract = { complete_task_contract = success_standard }
		# And wrap things up.
		scope:scheme ?= { end_scheme = yes }
	}
}

gdp_merchant_trade_opportunity.0003 = { # failure
	type = character_event
	window = scheme_failed_event
	title = gdp_merchant_trade_opportunity.0003.t
	desc = gdp_merchant_trade_opportunity.0003.desc
	theme = trade
	center_portrait = {
		character = root
		animation = disgust
	}
	right_portrait = {
		character = scope:target_title.holder
		animation = dismissal
	}
	override_background = { reference = courtyard }
	immediate = {
		merchant_base_trade_opportunity_schemes_set_up_outcome_immediate_effect = yes
		scope:task_contract = { complete_task_contract = failure_standard }
		# And wrap things up.
		scope:scheme ?= { end_scheme = yes }
	}

	# Acknowledge.
	option = {
		name = gdp_merchant_trade_opportunity.0003.a
		flavor = merchant_base_trade_opportunity_schemes.0000.f.contract_concluded
		merchant_base_contract_schemes_acknowledge_failure_stress_effect = yes
	}
}

gdp_merchant_trade_opportunity.0004 = { # result roll
	hidden = yes

	immediate = {
		roll_scheme_success_or_failure_effect = {
			SUCCESS_EVENT = gdp_merchant_trade_opportunity.0002
			FAILURE_EVENT = gdp_merchant_trade_opportunity.0003
		}
	}
}

####
# gdp_merchant_trade_opportunity.0011-0020 - Promote Goods
###

gdp_merchant_trade_opportunity.0011 = { # intro
	type = character_event
	title = gdp_merchant_trade_opportunity.0011.t
	desc = gdp_merchant_trade_opportunity.0011.desc
	theme = trade
	left_portrait = {
		character = root
		animation = pondering
	}
	lower_right_portrait = scope:associate

	trigger = {
		scope:task_contract = { has_task_contract_type = promote_goods }
	}

	immediate = {
		save_trade_opportunity_contract_scopes_effect = yes
		start_scheme = {
			type = merchant_promote_goods_trade_opportunity_scheme
			contract = scope:task_contract
			target_title = scope:task_contract_title.duchy
		}
		scope:task_contract.scheme = { save_scope_as = task_contract_scheme } # save scheme
	}

	# Go for a balanced agent mix.
	option = {
		name = gdp_merchant_trade_opportunity.0011.d
		reason = give_me_balanced_agents
		flavor = EVENT_WINDOW_OPTION_AGENTS_BALANCED
		scope:task_contract_scheme ?= {
			# Success.
			add_agent_slot = agent_bailiff
			add_agent_slot = agent_muscle
			add_agent_slot = agent_bookkeeper
			# Speed.
			add_agent_slot = agent_overseer
			add_agent_slot = agent_messenger
		}
		# No stress, we're just selecting our starter batch.
		# AI always selects balanced agents.
		ai_chance = { base = 1000 }
	}

	# Focus on success chance agents.
	option = {
		name = gdp_merchant_trade_opportunity.0011.a
		reason = give_me_success_agents
		flavor = EVENT_WINDOW_OPTION_AGENTS_SUCCESS
		scope:task_contract_scheme ?= {
			# Success.
			add_agent_slot = agent_bailiff
			add_agent_slot = agent_muscle
			add_agent_slot = agent_bookkeeper
			add_agent_slot = agent_scribe
			# Speed.
			add_agent_slot = agent_overseer
		}
		# No stress, we're just selecting our starter batch.
		# AI always picks the balanced config.
	}
	
	# Focus on speedy agents.
	option = {
		name = gdp_merchant_trade_opportunity.0011.b
		reason = give_me_speed_agents
		flavor = EVENT_WINDOW_OPTION_AGENTS_SPEED
		scope:task_contract_scheme ?= {
			# Success.
			add_agent_slot = agent_bailiff
			add_agent_slot = agent_bookkeeper
			# Speed.
			add_agent_slot = agent_overseer
			add_agent_slot = agent_messenger
			add_agent_slot = agent_socialite
		}
		# No stress, we're just selecting our starter batch.
		# AI always picks the balanced config.
	}
	
	# Now show us the panel.
	after = {
		open_view = {
			view = intrigue_window
			player = root
		}
	}
}

gdp_merchant_trade_opportunity.0012 = { # success
	type = character_event
	window = scheme_successful_event
	title = gdp_merchant_trade_opportunity.0012.t
	desc = gdp_merchant_trade_opportunity.0012.desc
	theme = trade
	center_portrait = {
		character = root
		animation = steward
	}
	override_background = { reference = sitting_room }
	immediate = {
		merchant_base_trade_opportunity_schemes_set_up_outcome_immediate_effect = yes
	}

	# Double down.
	option = {
		name = gdp_merchant_trade_opportunity.0012.a
		trigger = { scope:scheme_success_type ?= flag:success_critical }
		flavor = merchant_base_trade_opportunity_schemes.0000.f.contract_concluded
		scope:task_contract = { complete_task_contract = success_critical }
		# And wrap things up.
		scope:scheme ?= { end_scheme = yes }
	}

	# Acknowledge.
	option = {
		name = gdp_merchant_trade_opportunity.0012.b
		trigger = {
			NOT = { scope:scheme_success_type ?= flag:success_critical }
		}
		flavor = merchant_base_trade_opportunity_schemes.0000.f.contract_concluded
		scope:task_contract = { complete_task_contract = success_standard }
		# And wrap things up.
		scope:scheme ?= { end_scheme = yes }
	}
}

gdp_merchant_trade_opportunity.0013 = { # failure
	type = character_event
	window = scheme_failed_event
	title = gdp_merchant_trade_opportunity.0013.t
	desc = gdp_merchant_trade_opportunity.0013.desc
	theme = trade
	center_portrait = {
		character = root
		animation = dismissal
	}
	override_background = { reference = courtyard }
	
	immediate = {
		merchant_base_trade_opportunity_schemes_set_up_outcome_immediate_effect = yes
		scope:task_contract = { complete_task_contract = failure_standard }
		# And wrap things up.
		scope:scheme ?= { end_scheme = yes }
	}

	# Acknowledge.
	option = {
		name = gdp_merchant_trade_opportunity.0013.a
		flavor = merchant_base_trade_opportunity_schemes.0000.f.contract_concluded
		merchant_base_contract_schemes_acknowledge_failure_stress_effect = yes
	}
}

gdp_merchant_trade_opportunity.0014 = { # result roll
	hidden = yes

	immediate = {
		roll_scheme_success_or_failure_effect = {
			SUCCESS_EVENT = gdp_merchant_trade_opportunity.0012
			FAILURE_EVENT = gdp_merchant_trade_opportunity.0013
		}
	}
}

####
# gdp_merchant_trade_opportunity.0021-0030 - Market Investment
###

gdp_merchant_trade_opportunity.0021 = { # intro
	type = character_event
	title = gdp_merchant_trade_opportunity.0021.t
	desc = gdp_merchant_trade_opportunity.0021.desc
	theme = trade
	left_portrait = {
		character = root
		animation = pondering
	}
	right_portrait = {
		character = scope:task_contract_title.county.holder
		animation = idle
	}

	trigger = {
		scope:task_contract = { has_task_contract_type = market_investment }
	}

	immediate = {
		save_trade_opportunity_contract_scopes_effect = yes
		start_scheme = {
			type = merchant_market_investment_trade_opportunity_scheme
			contract = scope:task_contract
			target_title = scope:task_contract_title.duchy
		}
		scope:task_contract.scheme = { save_scope_as = task_contract_scheme } # save scheme
	}

	# Go for a balanced agent mix.
	option = {
		name = gdp_merchant_trade_opportunity.0021.d
		reason = give_me_balanced_agents
		flavor = EVENT_WINDOW_OPTION_AGENTS_BALANCED
		scope:task_contract_scheme ?= {
			# Success.
			add_agent_slot = agent_bailiff
			add_agent_slot = agent_muscle
			add_agent_slot = agent_bookkeeper
			# Speed.
			add_agent_slot = agent_overseer
			add_agent_slot = agent_messenger
		}

		# No stress, we're just selecting our starter batch.
		# AI always selects balanced agents.
		ai_chance = { base = 1000 }
	}

	# Focus on success chance agents.
	option = {
		name = gdp_merchant_trade_opportunity.0021.a
		reason = give_me_success_agents
		flavor = EVENT_WINDOW_OPTION_AGENTS_SUCCESS
		scope:task_contract_scheme ?= {
			# Success.
			add_agent_slot = agent_bailiff
			add_agent_slot = agent_muscle
			add_agent_slot = agent_bookkeeper
			add_agent_slot = agent_scribe
			# Speed.
			add_agent_slot = agent_overseer
		}

		# No stress, we're just selecting our starter batch.
		# AI always picks the balanced config.
	}
	
	# Focus on speedy agents.
	option = {
		name = gdp_merchant_trade_opportunity.0021.b
		reason = give_me_speed_agents
		flavor = EVENT_WINDOW_OPTION_AGENTS_SPEED
		scope:task_contract_scheme ?= {
			# Success.
			add_agent_slot = agent_bailiff
			add_agent_slot = agent_bookkeeper
			# Speed.
			add_agent_slot = agent_overseer
			add_agent_slot = agent_messenger
			add_agent_slot = agent_socialite
		}
		# No stress, we're just selecting our starter batch.
		# AI always picks the balanced config.
	}
	
	# Now show us the panel.
	after = {
		open_view = {
			view = intrigue_window
			player = root
		}
	}
}

gdp_merchant_trade_opportunity.0022 = { # success
	type = character_event
	window = scheme_successful_event
	title = gdp_merchant_trade_opportunity.0022.t
	desc = gdp_merchant_trade_opportunity.0022.desc
	theme = trade
	center_portrait = {
		character = root
		animation = war_over_win
	}
	right_portrait = {
		character = scope:local_ruler
		animation = interested
	}
	override_background = { reference = sitting_room }
	immediate = {
		merchant_base_trade_opportunity_schemes_set_up_outcome_immediate_effect = yes
		scope:task_contract.task_contract_location.county.holder ?= { save_scope_as = local_ruler }
		scope:task_contract = { complete_task_contract = success_critical }
		# And wrap things up.
		scope:scheme ?= { end_scheme = yes }
	}

	# Acknowledge.
	option = {
		name = gdp_merchant_trade_opportunity.0022.a
		flavor = merchant_base_trade_opportunity_schemes.0000.f.contract_concluded
	}
}

gdp_merchant_trade_opportunity.0023 = { # failure
	type = character_event
	window = scheme_failed_event
	title = gdp_merchant_trade_opportunity.0023.t
	desc = gdp_merchant_trade_opportunity.0023.desc
	theme = trade
	center_portrait = {
		character = root
		animation = war_over_loss
	}
	right_portrait = {
		character = scope:target_title.holder
		animation = dismissal
	}
	override_background = { reference = courtyard }
	
	immediate = {
		merchant_base_trade_opportunity_schemes_set_up_outcome_immediate_effect = yes
	}

	# Pay.
	option = {
		name = gdp_merchant_trade_opportunity.0023.a
		flavor = merchant_base_trade_opportunity_schemes.0000.f.contract_concluded
		scope:task_contract = { complete_task_contract = success_standard }
		# And wrap things up.
		scope:scheme ?= { end_scheme = yes }
	}

	# Acknowledge.
	option = {
		name = gdp_merchant_trade_opportunity.0023.b
		flavor = merchant_base_trade_opportunity_schemes.0000.f.contract_concluded
		scope:task_contract = { complete_task_contract = failure_standard }
		merchant_base_contract_schemes_acknowledge_failure_stress_effect = yes
		# And wrap things up.
		scope:scheme ?= { end_scheme = yes }
	}
}

gdp_merchant_trade_opportunity.0024 = { # result roll
	hidden = yes

	immediate = {
		roll_scheme_success_or_failure_effect = {
			SUCCESS_EVENT = gdp_merchant_trade_opportunity.0022
			FAILURE_EVENT = gdp_merchant_trade_opportunity.0023
		}
	}
}

####
# gdp_merchant_trade_opportunity.0031-0040 - Exploit Upheaval
###

gdp_merchant_trade_opportunity.0031 = { # intro
	type = character_event
	title = gdp_merchant_trade_opportunity.0031.t
	desc = gdp_merchant_trade_opportunity.0031.desc
	theme = trade
	left_portrait = {
		character = root
		animation = pondering
	}

	trigger = {
		scope:task_contract = { has_task_contract_type = exploit_upheaval }
	}

	immediate = {
		save_trade_opportunity_contract_scopes_effect = yes
		start_scheme = {
			type = merchant_exploit_upheaval_trade_opportunity_scheme
			contract = scope:task_contract
			target_title = scope:task_contract_title.duchy
		}
		scope:task_contract.scheme = { save_scope_as = task_contract_scheme } # save scheme
	}

	# Go for a balanced agent mix.
	option = {
		name = gdp_merchant_trade_opportunity.0031.d
		reason = give_me_balanced_agents
		flavor = EVENT_WINDOW_OPTION_AGENTS_BALANCED
		scope:task_contract_scheme ?= {
			# Success.
			add_agent_slot = agent_thug
			add_agent_slot = agent_muscle
			add_agent_slot = agent_bodyguard
			# Speed.
			add_agent_slot = agent_footpad
			add_agent_slot = agent_overseer
		}

		# No stress, we're just selecting our starter batch.
		# AI always selects balanced agents.
		ai_chance = { base = 1000 }
	}

	# Focus on success chance agents.
	option = {
		name = gdp_merchant_trade_opportunity.0031.a
		reason = give_me_success_agents
		flavor = EVENT_WINDOW_OPTION_AGENTS_SUCCESS
		scope:task_contract_scheme ?= {
			# Success.
			add_agent_slot = agent_thug
			add_agent_slot = agent_muscle
			add_agent_slot = agent_bodyguard
			add_agent_slot = agent_bailiff
			# Speed.
			add_agent_slot = agent_footpad
		}

		# No stress, we're just selecting our starter batch.
		# AI always picks the balanced config.
	}
	
	# Focus on speedy agents.
	option = {
		name = gdp_merchant_trade_opportunity.0031.b
		reason = give_me_speed_agents
		flavor = EVENT_WINDOW_OPTION_AGENTS_SPEED
		scope:task_contract_scheme ?= {
			# Success.
			add_agent_slot = agent_thug
			add_agent_slot = agent_muscle
			# Speed.
			add_agent_slot = agent_footpad
			add_agent_slot = agent_overseer
			add_agent_slot = agent_messenger
		}
		# No stress, we're just selecting our starter batch.
		# AI always picks the balanced config.
	}
	
	# Now show us the panel.
	after = {
		open_view = {
			view = intrigue_window
			player = root
		}
	}
}

gdp_merchant_trade_opportunity.0032 = { # success
	type = character_event
	window = scheme_successful_event
	title = gdp_merchant_trade_opportunity.0032.t
	desc = gdp_merchant_trade_opportunity.0032.desc
	theme = trade
	center_portrait = {
		character = root
		animation = war_over_win
	}
	override_background = { reference = sitting_room }
	immediate = {
		merchant_base_trade_opportunity_schemes_set_up_outcome_immediate_effect = yes
	}

	# Double down.
	option = {
		name = gdp_merchant_trade_opportunity.0032.a
		trigger = { scope:scheme_success_type ?= flag:success_critical }
		flavor = merchant_base_trade_opportunity_schemes.0000.f.contract_concluded
		scope:task_contract = { complete_task_contract = success_critical }
		# And wrap things up.
		scope:scheme ?= { end_scheme = yes }
	}

	# Acknowledge.
	option = {
		name = gdp_merchant_trade_opportunity.0032.b
		trigger = {
			NOT = { scope:scheme_success_type ?= flag:success_critical }
		}
		flavor = merchant_base_trade_opportunity_schemes.0000.f.contract_concluded
		scope:task_contract = { complete_task_contract = success_standard }
		# And wrap things up.
		scope:scheme ?= { end_scheme = yes }
	}
}

gdp_merchant_trade_opportunity.0033 = { # failure
	type = character_event
	window = scheme_failed_event
	title = gdp_merchant_trade_opportunity.0033.t
	desc = gdp_merchant_trade_opportunity.0033.desc
	theme = trade
	center_portrait = {
		character = root
		animation = disappointed
	}
	override_background = { reference = courtyard }
	
	immediate = {
		merchant_base_trade_opportunity_schemes_set_up_outcome_immediate_effect = yes
		scope:task_contract = { complete_task_contract = failure_standard }
		# And wrap things up.
		scope:scheme ?= { end_scheme = yes }
	}

	# Acknowledge.
	option = {
		name = gdp_merchant_trade_opportunity.0033.a
		flavor = merchant_base_trade_opportunity_schemes.0000.f.contract_concluded
		merchant_base_contract_schemes_acknowledge_failure_stress_effect = yes
	}
}

gdp_merchant_trade_opportunity.0034 = { # result roll
	hidden = yes

	immediate = {
		roll_scheme_success_or_failure_effect = {
			SUCCESS_EVENT = gdp_merchant_trade_opportunity.0032
			FAILURE_EVENT = gdp_merchant_trade_opportunity.0033
		}
	}
}

####
# gdp_merchant_trade_opportunity.0041-0050 - Support Guilds
###

gdp_merchant_trade_opportunity.0041 = { # intro
	type = character_event
	title = gdp_merchant_trade_opportunity.0041.t
	desc = gdp_merchant_trade_opportunity.0041.desc
	theme = trade
	left_portrait = {
		character = root
		animation = steward
	}

	trigger = {
		scope:task_contract = { has_task_contract_type = support_guilds }
	}

	immediate = {
		save_trade_opportunity_contract_scopes_effect = yes
		start_scheme = {
			type = merchant_support_guilds_trade_opportunity_scheme
			contract = scope:task_contract
			target_title = scope:task_contract_title.duchy
		}
		scope:task_contract.scheme = { save_scope_as = task_contract_scheme } # save scheme
	}

	# Go for a balanced agent mix.
	option = {
		name = gdp_merchant_trade_opportunity.0041.d
		reason = give_me_balanced_agents
		flavor = EVENT_WINDOW_OPTION_AGENTS_BALANCED
		scope:task_contract_scheme ?= {
			# Success.
			add_agent_slot = agent_appraiser
			add_agent_slot = agent_bookkeeper
			add_agent_slot = agent_broker
			# Speed.
			add_agent_slot = agent_gabbler
			add_agent_slot = agent_messenger
		}

		# No stress, we're just selecting our starter batch.
		# AI always selects balanced agents.
		ai_chance = { base = 1000 }
	}

	# Focus on success chance agents.
	option = {
		name = gdp_merchant_trade_opportunity.0041.a
		reason = give_me_success_agents
		flavor = EVENT_WINDOW_OPTION_AGENTS_SUCCESS
		scope:task_contract_scheme ?= {
			# Success.
			add_agent_slot = agent_appraiser
			add_agent_slot = agent_bookkeeper
			add_agent_slot = agent_broker
			add_agent_slot = agent_scribe
			# Speed.
			add_agent_slot = agent_gabbler
		}

		# No stress, we're just selecting our starter batch.
		# AI always picks the balanced config.
	}
	
	# Focus on speedy agents.
	option = {
		name = gdp_merchant_trade_opportunity.0041.b
		reason = give_me_speed_agents
		flavor = EVENT_WINDOW_OPTION_AGENTS_SPEED
		scope:task_contract_scheme ?= {
			# Success.
			add_agent_slot = agent_appraiser
			add_agent_slot = agent_bookkeeper
			# Speed.
			add_agent_slot = agent_gabbler
			add_agent_slot = agent_messenger
			add_agent_slot = agent_socialite
		}
		# No stress, we're just selecting our starter batch.
		# AI always picks the balanced config.
	}
	
	# Now show us the panel.
	after = {
		open_view = {
			view = intrigue_window
			player = root
		}
	}
}

gdp_merchant_trade_opportunity.0042 = { # success
	type = character_event
	window = scheme_successful_event
	title = gdp_merchant_trade_opportunity.0042.t
	desc = gdp_merchant_trade_opportunity.0042.desc
	theme = trade
	center_portrait = {
		character = root
		animation = pondering
	}
	right_portrait = {
		character = scope:inspired_artisan
		animation = thinking
	}
	override_background = { reference = sitting_room }
	
	immediate = {
		merchant_base_trade_opportunity_schemes_set_up_outcome_immediate_effect = yes
		scope:task_contract = {
			task_contract_location.duchy = { save_scope_as = contract_duchy }
		}
		# Inspiration
		scope:contract_duchy = {
			every_de_jure_county = {
				every_county_province = {
					save_temporary_scope_as = province_temp
					every_pool_character = {
						province = scope:province_temp
						limit = {
							age >= 20
							is_lowborn = yes
							is_clergy = no
							health >= fine_health
							sum_of_all_skills_value >= 15
							NOR = {
								has_trait = peasant_leader
								has_any_bad_relationship_with_character_trigger = { CHARACTER = root }
 							}
							trigger_if = { # Existing relevant inspiration without sponsor
								limit = { exists = inspiration }
								inspiration = {
									has_inspiration_type = artisan_inspiration
									NOT = { exists = inspiration_sponsor }
								}
							}
						}
						add_to_list = pool_list
					}
				}	
			}
		}
		random_in_list = {
			list = pool_list
			limit = { exists = inspiration }
			alternative_limit = { culture = { has_cultural_parameter = improved_artisan_inspiration } }
			alternative_limit = { always = yes }
			weight = {
				base = 1
				modifier = { add = stewardship }
				modifier = {
					add = {
						value = learning
						divide = 2
					}
				}
			}
			save_scope_as = inspired_artisan
			inspiration ?= { save_scope_as = new_inspiration }
		}
		if = {
			limit = { NOT = { exists = scope:inspired_artisan } }
			create_character = {
				template = local_artisan_template
				location = scope:contract_duchy.title_capital_county.title_province
				gender_female_chance = location_faith_dominant_gender_female_chance
				save_scope_as = inspired_artisan
			}
		}
		if = {
			limit = { NOT = { exists = scope:new_inspiration } }
			hidden_effect = {
				scope:inspired_artisan = {
					# needed for artisan_inspiration on_creation
					add_character_flag = support_guilds_inspiration
					create_inspiration = artisan_inspiration
					remove_character_flag = support_guilds_inspiration
				}
			}
		}
		scope:task_contract = { complete_task_contract = success_standard }
		# And wrap things up.
		scope:scheme ?= { end_scheme = yes }
	}

	# Hire artisan.
	option = {
		name = gdp_merchant_trade_opportunity.0042.b
		flavor = merchant_base_trade_opportunity_schemes.0000.f.contract_concluded
		trigger = {
			exists = scope:inspired_artisan
			exists = scope:new_inspiration
		}
		add_prestige = {
			value = minor_prestige_gain
			multiply = trade_opportunity_contract_tier_value
		}
		add_courtier = scope:inspired_artisan
		hidden_effect = {
			reverse_add_opinion = {
				target = scope:inspired_artisan
				modifier = recruited_me_opinion
				opinion = 50
			}
		}
		sponsor_inspiration = scope:new_inspiration
	}

	# Acknowledge.
	option = {
		name = gdp_merchant_trade_opportunity.0042.a
		flavor = merchant_base_trade_opportunity_schemes.0000.f.contract_concluded
	}
}

gdp_merchant_trade_opportunity.0043 = { # failure
	type = character_event
	window = scheme_failed_event
	title = gdp_merchant_trade_opportunity.0043.t
	desc = gdp_merchant_trade_opportunity.0043.desc
	theme = trade
	center_portrait = {
		character = root
		animation = war_over_loss
	}
	override_background = { reference = courtyard }
	
	immediate = {
		merchant_base_trade_opportunity_schemes_set_up_outcome_immediate_effect = yes
	}

	# Acknowledge.
	option = {
		name = gdp_merchant_trade_opportunity.0043.a
		flavor = merchant_base_trade_opportunity_schemes.0000.f.contract_concluded
		scope:task_contract = { complete_task_contract = failure_standard }
		merchant_base_contract_schemes_acknowledge_failure_stress_effect = yes
		# And wrap things up.
		scope:scheme ?= { end_scheme = yes }
	}
}

gdp_merchant_trade_opportunity.0044 = { # result roll
	hidden = yes

	immediate = {
		roll_scheme_success_or_failure_effect = {
			SUCCESS_EVENT = gdp_merchant_trade_opportunity.0042
			FAILURE_EVENT = gdp_merchant_trade_opportunity.0043
		}
	}
}

####
# gdp_merchant_trade_opportunity.0051-0060 - Seek Debtors
###

gdp_merchant_trade_opportunity.0051 = { # intro
	type = character_event
	title = gdp_merchant_trade_opportunity.0051.t
	desc = gdp_merchant_trade_opportunity.0051.desc
	theme = trade
	left_portrait = {
		character = root
		animation = pondering
	}

	trigger = {
		scope:task_contract = { has_task_contract_type = seek_debtors }
	}

	immediate = {
		save_trade_opportunity_contract_scopes_effect = yes
		start_scheme = {
			type = merchant_seek_debtors_trade_opportunity_scheme
			contract = scope:task_contract
			target_title = scope:task_contract_title.duchy
		}
		scope:task_contract.scheme = { save_scope_as = task_contract_scheme } # save scheme
	}

	# Go for a balanced agent mix.
	option = {
		name = gdp_merchant_trade_opportunity.0051.d
		reason = give_me_balanced_agents
		flavor = EVENT_WINDOW_OPTION_AGENTS_BALANCED
		scope:task_contract_scheme ?= {
			# Success.
			add_agent_slot = agent_broker
			add_agent_slot = agent_bailiff
			add_agent_slot = agent_muscle
			# Speed.
			add_agent_slot = agent_overseer
			add_agent_slot = agent_messenger
		}

		# No stress, we're just selecting our starter batch.
		# AI always selects balanced agents.
		ai_chance = { base = 1000 }
	}

	# Focus on success chance agents.
	option = {
		name = gdp_merchant_trade_opportunity.0051.a
		reason = give_me_success_agents
		flavor = EVENT_WINDOW_OPTION_AGENTS_SUCCESS
		scope:task_contract_scheme ?= {
			# Success.
			add_agent_slot = agent_broker
			add_agent_slot = agent_bailiff
			add_agent_slot = agent_muscle
			add_agent_slot = agent_bookkeeper
			# Speed.
			add_agent_slot = agent_overseer
		}

		# No stress, we're just selecting our starter batch.
		# AI always picks the balanced config.
	}
	
	# Focus on speedy agents.
	option = {
		name = gdp_merchant_trade_opportunity.0051.b
		reason = give_me_speed_agents
		flavor = EVENT_WINDOW_OPTION_AGENTS_SPEED
		scope:task_contract_scheme ?= {
			# Success.
			add_agent_slot = agent_broker
			add_agent_slot = agent_bailiff
			# Speed.
			add_agent_slot = agent_overseer
			add_agent_slot = agent_messenger
			add_agent_slot = agent_gabbler
		}
		# No stress, we're just selecting our starter batch.
		# AI always picks the balanced config.
	}
	
	# Now show us the panel.
	after = {
		open_view = {
			view = intrigue_window
			player = root
		}
	}
}

scripted_trigger gdp_seek_debtors_potential_debtor_trigger = {
	save_temporary_scope_as = debtor_temp
	is_ai = yes
	is_adult = yes
	scope:task_contract.task_contract_taker = {
		OR = {
			can_add_hook = {
				target = scope:debtor_temp
				type = indebted_hook
			}
			has_hook_of_type = {
				target = scope:debtor_temp
				type = indebted_hook
			}
		}
	}
}

scripted_effect gdp_seek_debtors_list_effect = {
	if = {
		limit = { gdp_seek_debtors_potential_debtor_trigger = yes }
		add_to_list = potential_debtors
	}
}

scripted_effect gdp_seek_debtors_find_debtor_effect = {
	scope:task_contract.task_contract_location.duchy ?= {
		holder ?= {
			gdp_seek_debtors_list_effect = yes
			primary_heir ?= { gdp_seek_debtors_list_effect = yes }
		}
		every_in_de_jure_hierarchy = {
			holder ?= {
				gdp_seek_debtors_list_effect = yes
				primary_heir ?= { gdp_seek_debtors_list_effect = yes }
			}
		}
	}
	random_in_list = {
		list = potential_debtors
		limit = {
			OR = {
				highest_held_title_tier >= tier_county
				AND = {
					is_ruler = no
					primary_heir ?= { highest_held_title_tier >= tier_county }
				}
			}
		}
		alternative_limit = { always = yes }
		weight = {
			base = 1
			modifier = {
				add = {
					value = 1
					add = highest_held_title_tier
					multiply = 100
				}
			}
			modifier = {
				is_ruler = no
				add = {
					value = 1
					ordered_heir_title = {
						order_by = tier
						add = tier
					}
					multiply = 75
				}
			}
			modifier = {
				exists = capital_county
				add = capital_county.prosperity_level
			}
			modifier = {
				gold < 0
				factor = 4
			}
			modifier = {
				has_trait = improvident
				add = 50
			}
			modifier = {
				has_trait = profligate
				add = 25
			}
			modifier = {
				is_at_war = yes
				add = 50
			}
		}
		save_scope_as = debtor
		save_scope_as = bg_override_char
	}
}

gdp_merchant_trade_opportunity.0052 = { # success
	type = character_event
	window = scheme_successful_event
	title = gdp_merchant_trade_opportunity.0052.t
	desc = gdp_merchant_trade_opportunity.0052.desc
	theme = trade
	center_portrait = {
		character = root
		animation = steward
	}
	right_portrait = {
		character = scope:debtor
		animation = worry
	}
	override_background = { reference = sitting_room }
	
	immediate = {
		merchant_base_trade_opportunity_schemes_set_up_outcome_immediate_effect = yes
		# Find appropriate debtor
		gdp_seek_debtors_find_debtor_effect = yes
	}

	# Acknowledge.
	option = {
		name = gdp_merchant_trade_opportunity.0052.a
		flavor = merchant_base_trade_opportunity_schemes.0000.f.contract_concluded
		trigger = { exists = scope:debtor }
		scope:task_contract = { complete_task_contract = success_standard }
		# And wrap things up.
		scope:scheme ?= { end_scheme = yes }
		pay_short_term_gold = {
			target = scope:debtor
			gold = scope:debtor.medium_gold_value
		}
		if = {
			limit = {
				can_add_hook = {
					target = scope:debtor
					type = indebted_hook
				}
			}
			add_hook = {
				target = scope:debtor
				type = indebted_hook
			}
		}
		else = {
			hidden_effect = {
				remove_hook = {
					target = scope:debtor
					type = indebted_hook
				}
			}
			add_hook = {
				target = scope:debtor
				type = strong_indebted_hook
			}
		}
	}

	# Renege.
	option = {
		name = gdp_merchant_trade_opportunity.0052.b
		flavor = merchant_base_trade_opportunity_schemes.0000.f.contract_concluded
		scope:task_contract = { complete_task_contract = failure_standard }
		# And wrap things up.
		scope:scheme ?= { end_scheme = yes }
		progress_towards_rival_effect = {
			REASON = rival_refused_credit
			CHARACTER = scope:debtor
			OPINION = 0
		}
		merchant_base_contract_schemes_acknowledge_failure_stress_effect = yes
	}
}

gdp_merchant_trade_opportunity.0053 = { # failure
	type = character_event
	window = scheme_failed_event
	title = gdp_merchant_trade_opportunity.0053.t
	desc = gdp_merchant_trade_opportunity.0053.desc
	theme = trade
	center_portrait = {
		character = root
		animation = stunned
	}
	override_background = { reference = courtyard }
	
	immediate = {
		merchant_base_trade_opportunity_schemes_set_up_outcome_immediate_effect = yes
		scope:task_contract = { complete_task_contract = failure_standard }
		# And wrap things up.
		scope:scheme ?= { end_scheme = yes }
	}

	# Acknowledge.
	option = {
		name = gdp_merchant_trade_opportunity.0053.a
		flavor = merchant_base_trade_opportunity_schemes.0000.f.contract_concluded
		merchant_base_contract_schemes_acknowledge_failure_stress_effect = yes
	}
}

gdp_merchant_trade_opportunity.0054 = { # result roll
	hidden = yes

	immediate = {
		roll_scheme_success_or_failure_effect = {
			SUCCESS_EVENT = gdp_merchant_trade_opportunity.0052
			FAILURE_EVENT = gdp_merchant_trade_opportunity.0053
		}
	}
}

####
# gdp_merchant_trade_opportunity.0061-0070 - Sabotage Competition
###

scripted_trigger trade_opportunity_trader_travelling_to_contract_trigger = {
	current_travel_plan ?= { final_destination_province = scope:task_contract_location }
	location != scope:task_contract_location
}

gdp_merchant_trade_opportunity.0061 = { # intro
	type = character_event
	title = gdp_merchant_trade_opportunity.0061.t
	desc = gdp_merchant_trade_opportunity.0061.desc
	theme = trade
	left_portrait = {
		character = root
		animation = schadenfreude
	}
	right_portrait = {
		trigger = {
			scope:contract_employer ?= { trade_opportunity_trader_travelling_to_contract_trigger = no }
		}
		character = scope:contract_employer
		animation = flirtation
	}
	lower_left_portrait = {
		trigger = {
			scope:contract_employer ?= { trade_opportunity_trader_travelling_to_contract_trigger = yes }
		}
		character = scope:contract_employer
	}
	lower_right_portrait = scope:task_contract_target

	trigger = {
		scope:task_contract = {
			has_task_contract_type = sabotage_competition
			task_contract_target = { is_alive = yes }
		}
	}

	immediate = {
		save_trade_opportunity_contract_scopes_effect = yes
		scope:task_contract.task_contract_employer = { save_scope_as = contract_employer } # Save the employer
		scope:task_contract.task_contract_location.county.holder = { save_scope_as = market_owner }
		scope:task_contract_target = {
			random_trade_route = {
				limit = {
					any_trade_market_on_route = {
						trade_market_owner.title_province = scope:task_contract.task_contract_location
					}
				}
				random_traded_good = { save_scope_as = trade_good_type }
			}
		}
		start_scheme = {
			type = merchant_sabotage_competition_trade_opportunity_scheme
			contract = scope:task_contract
			target_title = scope:task_contract_target.primary_title
		}
		scope:task_contract.scheme = { save_scope_as = task_contract_scheme } # save scheme
	}

	# Go for a balanced agent mix.
	option = {
		name = gdp_merchant_trade_opportunity.0061.d
		reason = give_me_balanced_agents
		flavor = EVENT_WINDOW_OPTION_AGENTS_BALANCED
		scope:task_contract_scheme ?= {
			# Success.
			add_agent_slot = agent_broker
			add_agent_slot = agent_bailiff
			add_agent_slot = agent_muscle
			# Speed.
			add_agent_slot = agent_overseer
			add_agent_slot = agent_messenger
		}

		# No stress, we're just selecting our starter batch.
		# AI always selects balanced agents.
		ai_chance = { base = 1000 }
	}

	# Focus on success chance agents.
	option = {
		name = gdp_merchant_trade_opportunity.0061.a
		reason = give_me_success_agents
		flavor = EVENT_WINDOW_OPTION_AGENTS_SUCCESS
		scope:task_contract_scheme ?= {
			# Success.
			add_agent_slot = agent_broker
			add_agent_slot = agent_bailiff
			add_agent_slot = agent_muscle
			add_agent_slot = agent_bookkeeper
			# Speed.
			add_agent_slot = agent_overseer
		}

		# No stress, we're just selecting our starter batch.
		# AI always picks the balanced config.
	}
	
	# Focus on speedy agents.
	option = {
		name = gdp_merchant_trade_opportunity.0061.b
		reason = give_me_speed_agents
		flavor = EVENT_WINDOW_OPTION_AGENTS_SPEED
		scope:task_contract_scheme ?= {
			# Success.
			add_agent_slot = agent_broker
			add_agent_slot = agent_bailiff
			# Speed.
			add_agent_slot = agent_overseer
			add_agent_slot = agent_messenger
			add_agent_slot = agent_gabbler
		}
		# No stress, we're just selecting our starter batch.
		# AI always picks the balanced config.
	}
	
	# Now show us the panel.
	after = {
		open_view = {
			view = intrigue_window
			player = root
		}
	}
}

gdp_merchant_trade_opportunity.0062 = { # sucess
	type = character_event
	window = scheme_successful_event
	title = gdp_merchant_trade_opportunity.0062.t
	desc = gdp_merchant_trade_opportunity.0062.desc
	theme = trade
	center_portrait = {
		character = root
		animation = war_over_win
	}
	right_portrait = {
		character = scope:target_title.holder
		animation = disbelief
	}
	override_background = { reference = sitting_room }
	immediate = {
		merchant_base_trade_opportunity_schemes_set_up_outcome_immediate_effect = yes
		if = {
			limit = { scope:scheme_success_type ?= flag:success_critical }
			scope:task_contract = { complete_task_contract = success_critical }
		}
		else = {
			scope:task_contract = { complete_task_contract = success_standard }
		}
		# And wrap things up.
		scope:scheme ?= { end_scheme = yes }
	}
	# Acknowledge.
	option = {
		name = gdp_merchant_trade_opportunity.0062.a
		flavor = merchant_base_trade_opportunity_schemes.0000.f.contract_concluded
	}
}

gdp_merchant_trade_opportunity.0063 = { # failure
	type = character_event
	window = scheme_failed_event
	title = gdp_merchant_trade_opportunity.0063.t
	desc = gdp_merchant_trade_opportunity.0063.desc
	theme = trade
	center_portrait = {
		character = root
		animation = dismissal
	}
	right_portrait = {
		character = scope:target_title.holder
		animation = chancellor
	}
	override_background = { reference = courtyard }
	
	immediate = {
		merchant_base_trade_opportunity_schemes_set_up_outcome_immediate_effect = yes
		scope:task_contract = { complete_task_contract = failure_standard }
		# And wrap things up.
		scope:scheme ?= { end_scheme = yes }
	}

	# Acknowledge.
	option = {
		name = gdp_merchant_trade_opportunity.0063.a
		flavor = merchant_base_trade_opportunity_schemes.0000.f.contract_concluded
		merchant_base_contract_schemes_acknowledge_failure_stress_effect = yes
	}
}

gdp_merchant_trade_opportunity.0064 = { # result roll
	hidden = yes

	immediate = {
		roll_scheme_success_or_failure_effect = {
			SUCCESS_EVENT = gdp_merchant_trade_opportunity.0062
			FAILURE_EVENT = gdp_merchant_trade_opportunity.0063
		}
	}	
}

####
# gdp_merchant_trade_opportunity.0071-0080 - Build Connections
###

gdp_merchant_trade_opportunity.0071 = { # intro
	type = character_event
	title = gdp_merchant_trade_opportunity.0071.t
	desc = gdp_merchant_trade_opportunity.0071.desc
	theme = trade
	left_portrait = {
		character = root
		animation = thinking
	}
	right_portrait = {
		trigger = {
			scope:contract_employer ?= { trade_opportunity_trader_travelling_to_contract_trigger = no }
		}
		character = scope:contract_employer
		animation = holding_tally_stick
	}
	lower_left_portrait = {
		trigger = {
			scope:contract_employer ?= { trade_opportunity_trader_travelling_to_contract_trigger = yes }
		}
		character = scope:contract_employer
	}

	trigger = {
		scope:task_contract = { has_task_contract_type = build_category_connections }
	}

	immediate = {
		save_trade_opportunity_contract_scopes_effect = yes
		scope:task_contract.task_contract_employer = { save_scope_as = contract_employer } # Save the employer
		start_scheme = {
			type = merchant_build_category_connections_trade_opportunity_scheme
			contract = scope:task_contract
			target_title = scope:task_contract_title.duchy
		}
		scope:task_contract.scheme = { save_scope_as = task_contract_scheme } # save scheme
	}

	# Go for a balanced agent mix.
	option = {
		name = gdp_merchant_trade_opportunity.0071.d
		reason = give_me_balanced_agents
		flavor = EVENT_WINDOW_OPTION_AGENTS_BALANCED
		scope:task_contract_scheme ?= {
			# Success.
			add_agent_slot = agent_bailiff
			add_agent_slot = agent_muscle
			add_agent_slot = agent_bookkeeper
			# Speed.
			add_agent_slot = agent_overseer
			add_agent_slot = agent_messenger
		}
		# No stress, we're just selecting our starter batch.
		# AI always selects balanced agents.
		ai_chance = { base = 1000 }
	}

	# Focus on success chance agents.
	option = {
		name = gdp_merchant_trade_opportunity.0071.a
		reason = give_me_success_agents
		flavor = EVENT_WINDOW_OPTION_AGENTS_SUCCESS
		scope:task_contract_scheme ?= {
			# Success.
			add_agent_slot = agent_bailiff
			add_agent_slot = agent_muscle
			add_agent_slot = agent_bookkeeper
			add_agent_slot = agent_scribe
			# Speed.
			add_agent_slot = agent_overseer
		}
		# No stress, we're just selecting our starter batch.
		# AI always picks the balanced config.
	}
	
	# Focus on speedy agents.
	option = {
		name = gdp_merchant_trade_opportunity.0071.b
		reason = give_me_speed_agents
		flavor = EVENT_WINDOW_OPTION_AGENTS_SPEED
		scope:task_contract_scheme ?= {
			# Success.
			add_agent_slot = agent_bailiff
			add_agent_slot = agent_bookkeeper
			# Speed.
			add_agent_slot = agent_overseer
			add_agent_slot = agent_messenger
			add_agent_slot = agent_socialite
		}
		# No stress, we're just selecting our starter batch.
		# AI always picks the balanced config.
	}
	
	# Now show us the panel.
	after = {
		open_view = {
			view = intrigue_window
			player = root
		}
	}
}

gdp_merchant_trade_opportunity.0072 = { # sucess
	type = character_event
	window = scheme_successful_event
	title = gdp_merchant_trade_opportunity.0072.t
	desc = gdp_merchant_trade_opportunity.0072.desc
	theme = trade
	center_portrait = {
		character = root
		animation = war_over_win
	}
	right_portrait = {
		character = scope:associate
		animation = holding_tally_stick
	}
	immediate = {
		merchant_base_trade_opportunity_schemes_set_up_outcome_immediate_effect = yes
		save_trade_opportunity_contract_scopes_effect = yes
		scope:task_contract = { complete_task_contract = success_standard }
		# And wrap things up.
		scope:scheme ?= { end_scheme = yes }
	}
	# Acknowledge.
	option = {
		name = gdp_merchant_trade_opportunity.0072.a
		flavor = merchant_base_trade_opportunity_schemes.0000.f.contract_concluded
	}
}

gdp_merchant_trade_opportunity.0073 = { # failure
	type = character_event
	window = scheme_failed_event
	title = gdp_merchant_trade_opportunity.0073.t
	desc = gdp_merchant_trade_opportunity.0073.desc
	theme = trade
	center_portrait = {
		character = root
		animation = dismissal
	}
	right_portrait = {
		character = scope:associate
		animation = shame
	}
	override_background = { reference = market }
	
	immediate = {
		merchant_base_trade_opportunity_schemes_set_up_outcome_immediate_effect = yes
		save_trade_opportunity_contract_scopes_effect = yes
		scope:task_contract = { complete_task_contract = failure_standard }
		# And wrap things up.
		scope:scheme ?= { end_scheme = yes }
	}

	# Acknowledge.
	option = {
		name = gdp_merchant_trade_opportunity.0073.a
		flavor = merchant_base_trade_opportunity_schemes.0000.f.contract_concluded
		merchant_base_contract_schemes_acknowledge_failure_stress_effect = yes
	}
}

gdp_merchant_trade_opportunity.0074 = { # result roll
	hidden = yes

	immediate = {
		roll_scheme_success_or_failure_effect = {
			SUCCESS_EVENT = gdp_merchant_trade_opportunity.0072
			FAILURE_EVENT = gdp_merchant_trade_opportunity.0073
		}
	}	
}

####
# gdp_merchant_trade_opportunity.0081-0090 - Disrupt Charter
###

gdp_merchant_trade_opportunity.0081 = { # intro
	type = character_event
	title = gdp_merchant_trade_opportunity.0081.t
	desc = gdp_merchant_trade_opportunity.0081.desc
	theme = trade
	left_portrait = {
		character = root
		animation = schadenfreude
	}
	right_portrait = {
		trigger = {
			scope:contract_employer ?= { trade_opportunity_trader_travelling_to_contract_trigger = no }
		}
		character = scope:contract_employer
		animation = flirtation
	}
	lower_left_portrait = {
		trigger = {
			scope:contract_employer ?= { trade_opportunity_trader_travelling_to_contract_trigger = yes }
		}
		character = scope:contract_employer
	}
	lower_center_portrait = scope:contract_target
	lower_right_portrait = scope:contract_target.suzerain
	override_background = { reference = study }

	trigger = {
		scope:task_contract = {
			has_task_contract_type = disrupt_charter
			task_contract_target ?= { is_alive = yes }
		}
	}

	immediate = {
		save_trade_opportunity_contract_scopes_effect = yes
		scope:task_contract = {
			task_contract_employer = { save_scope_as = contract_employer } # Save the employer
			task_contract_target = { save_scope_as = contract_target } # Save the target
		}
		start_scheme = {
			type = merchant_disrupt_charter_trade_opportunity_scheme
			contract = scope:task_contract
			target_title = scope:contract_target.primary_title
		}
		scope:task_contract.scheme = { save_scope_as = task_contract_scheme } # save scheme
	}

	# Go for a balanced agent mix.
	option = {
		name = gdp_merchant_trade_opportunity.0081.d
		reason = give_me_balanced_agents
		flavor = EVENT_WINDOW_OPTION_AGENTS_BALANCED
		scope:task_contract_scheme ?= {
			# Success.
			add_agent_slot = agent_broker
			add_agent_slot = agent_bailiff
			add_agent_slot = agent_muscle
			# Speed.
			add_agent_slot = agent_overseer
			add_agent_slot = agent_messenger
		}

		# No stress, we're just selecting our starter batch.
		# AI always selects balanced agents.
		ai_chance = { base = 1000 }
	}

	# Focus on success chance agents.
	option = {
		name = gdp_merchant_trade_opportunity.0081.a
		reason = give_me_success_agents
		flavor = EVENT_WINDOW_OPTION_AGENTS_SUCCESS
		scope:task_contract_scheme ?= {
			# Success.
			add_agent_slot = agent_broker
			add_agent_slot = agent_bailiff
			add_agent_slot = agent_muscle
			add_agent_slot = agent_bookkeeper
			# Speed.
			add_agent_slot = agent_overseer
		}

		# No stress, we're just selecting our starter batch.
		# AI always picks the balanced config.
	}
	
	# Focus on speedy agents.
	option = {
		name = gdp_merchant_trade_opportunity.0081.b
		reason = give_me_speed_agents
		flavor = EVENT_WINDOW_OPTION_AGENTS_SPEED
		scope:task_contract_scheme ?= {
			# Success.
			add_agent_slot = agent_broker
			add_agent_slot = agent_bailiff
			# Speed.
			add_agent_slot = agent_overseer
			add_agent_slot = agent_messenger
			add_agent_slot = agent_gabbler
		}
		# No stress, we're just selecting our starter batch.
		# AI always picks the balanced config.
	}
	
	# Now show us the panel.
	after = {
		open_view = {
			view = intrigue_window
			player = root
		}
	}
}

gdp_merchant_trade_opportunity.0082 = { # sucess
	type = character_event
	window = scheme_successful_event
	title = gdp_merchant_trade_opportunity.0082.t
	desc = gdp_merchant_trade_opportunity.0082.desc
	theme = trade
	center_portrait = {
		character = root
		animation = war_over_win
	}
	right_portrait = {
		character = scope:associate
		animation = schadenfreude
	}
	lower_center_portrait = scope:target_title.holder.suzerain
	lower_right_portrait = scope:target_title.holder
	override_background = { reference = sitting_room }
	immediate = {
		merchant_base_trade_opportunity_schemes_set_up_outcome_immediate_effect = yes
		if = {
			limit = { scope:scheme_success_type ?= flag:success_critical }
			scope:task_contract = { complete_task_contract = success_critical }
		}
		else = {
			scope:task_contract = { complete_task_contract = success_standard }
		}
		# And wrap things up.
		scope:scheme ?= { end_scheme = yes }
	}
	# Acknowledge.
	option = {
		name = gdp_merchant_trade_opportunity.0082.a
		flavor = merchant_base_trade_opportunity_schemes.0000.f.contract_concluded
	}
}

gdp_merchant_trade_opportunity.0083 = { # failure
	type = character_event
	window = scheme_failed_event
	title = gdp_merchant_trade_opportunity.0083.t
	desc = gdp_merchant_trade_opportunity.0083.desc
	theme = trade
	center_portrait = {
		character = root
		animation = dismissal
	}
	right_portrait = {
		character = scope:associate
		animation = chancellor
	}
	lower_center_portrait = scope:target_title.holder.suzerain
	lower_right_portrait = scope:target_title.holder
	override_background = { reference = courtyard }
	
	immediate = {
		merchant_base_trade_opportunity_schemes_set_up_outcome_immediate_effect = yes
		scope:task_contract = { complete_task_contract = failure_standard }
		# And wrap things up.
		scope:scheme ?= { end_scheme = yes }
	}

	# Acknowledge.
	option = {
		name = gdp_merchant_trade_opportunity.0083.a
		flavor = merchant_base_trade_opportunity_schemes.0000.f.contract_concluded
		merchant_base_contract_schemes_acknowledge_failure_stress_effect = yes
	}
}

gdp_merchant_trade_opportunity.0084 = { # result roll
	hidden = yes

	immediate = {
		roll_scheme_success_or_failure_effect = {
			SUCCESS_EVENT = gdp_merchant_trade_opportunity.0082
			FAILURE_EVENT = gdp_merchant_trade_opportunity.0083
		}
	}	
}

####
# gdp_merchant_trade_opportunity.0091-0100 - Alleviate Upheaval
###

gdp_merchant_trade_opportunity.0091 = { # intro
	type = character_event
	title = gdp_merchant_trade_opportunity.0091.t
	desc = gdp_merchant_trade_opportunity.0091.desc
	theme = trade
	left_portrait = {
		character = root
		animation = sadness
	}
	right_portrait = {
		trigger = {
			scope:associate ?= { trade_opportunity_trader_travelling_to_contract_trigger = no }
		}
		character = scope:associate
		animation = worry
	}
	lower_left_portrait = {
		trigger = {
			scope:associate ?= { trade_opportunity_trader_travelling_to_contract_trigger = yes }
		}
		character = scope:associate
	}

	trigger = {
		scope:task_contract = { has_task_contract_type = alleviate_upheaval }
	}

	immediate = {
		save_trade_opportunity_contract_scopes_effect = yes
		start_scheme = {
			type = merchant_alleviate_upheaval_trade_opportunity_scheme
			contract = scope:task_contract
			target_title = scope:task_contract_title.duchy
		}
		scope:task_contract.scheme = { save_scope_as = task_contract_scheme } # save scheme
	}

	# Go for a balanced agent mix.
	option = {
		name = gdp_merchant_trade_opportunity.0091.d
		reason = give_me_balanced_agents
		flavor = EVENT_WINDOW_OPTION_AGENTS_BALANCED
		scope:task_contract_scheme ?= {
			# Success.
			add_agent_slot = agent_scribe
			add_agent_slot = agent_bookkeeper
			add_agent_slot = agent_wrangler
			# Speed.
			add_agent_slot = agent_overseer
			add_agent_slot = agent_messenger
		}

		# No stress, we're just selecting our starter batch.
		# AI always selects balanced agents.
		ai_chance = { base = 1000 }
	}

	# Focus on success chance agents.
	option = {
		name = gdp_merchant_trade_opportunity.0091.a
		reason = give_me_success_agents
		flavor = EVENT_WINDOW_OPTION_AGENTS_SUCCESS
		scope:task_contract_scheme ?= {
			# Success.
			add_agent_slot = agent_scribe
			add_agent_slot = agent_bookkeeper
			add_agent_slot = agent_wrangler
			add_agent_slot = agent_broker
			# Speed.
			add_agent_slot = agent_overseer
		}

		# No stress, we're just selecting our starter batch.
		# AI always picks the balanced config.
	}
	
	# Focus on speedy agents.
	option = {
		name = gdp_merchant_trade_opportunity.0091.b
		reason = give_me_speed_agents
		flavor = EVENT_WINDOW_OPTION_AGENTS_SPEED
		scope:task_contract_scheme ?= {
			# Success.
			add_agent_slot = agent_scribe
			add_agent_slot = agent_bookkeeper
			# Speed.
			add_agent_slot = agent_overseer
			add_agent_slot = agent_messenger
			add_agent_slot = agent_supplier
		}
		# No stress, we're just selecting our starter batch.
		# AI always picks the balanced config.
	}
	
	# Now show us the panel.
	after = {
		open_view = {
			view = intrigue_window
			player = root
		}
	}
}

gdp_merchant_trade_opportunity.0092 = { # success
	type = character_event
	window = scheme_successful_event
	title = gdp_merchant_trade_opportunity.0092.t
	desc = {
		desc = gdp_merchant_trade_opportunity.0092.desc
		random_valid = {
			triggered_desc = {
				trigger = {
					scope:destination.barony.trade_market = {
						OR = {
							has_trade_market_modifier = gdp_market_recently_sieged_capacity_modifier
							has_trade_market_modifier = gdp_market_recently_raided_capacity_modifier
							has_trade_market_modifier = gdp_market_army_movement_capacity_modifier
						}
					}
				}
				desc = gdp_merchant_trade_opportunity.0092.war
			}
			triggered_desc = {
				trigger = {
					scope:destination.barony.trade_market = {
						OR = {
							has_trade_market_modifier = gdp_natural_disaster_1_trade_modifier
							has_trade_market_modifier = gdp_natural_disaster_2_trade_modifier
							has_trade_market_modifier = gdp_natural_disaster_3_trade_modifier
						}
					}
				}
				desc = gdp_merchant_trade_opportunity.0092.disaster
			}
			triggered_desc = {
				trigger = {
					scope:destination.barony.trade_market = {
						OR = {
							has_trade_market_modifier = gdp_epidemic_1_trade_modifier
							has_trade_market_modifier = gdp_epidemic_2_trade_modifier
							has_trade_market_modifier = gdp_epidemic_3_trade_modifier
						}
					}
				}
				desc = gdp_merchant_trade_opportunity.0092.epidemic
			}
		}
		desc = gdp_merchant_trade_opportunity.0092.closing
	}
	theme = trade
	center_portrait = {
		character = root
		animation = war_over_win
	}
	override_background = { reference = market }
	immediate = {
		merchant_base_trade_opportunity_schemes_set_up_outcome_immediate_effect = yes
		scope:task_contract = {
			task_contract_location = { save_scope_as = destination }
		}
		random = {
			chance = {
				value = 5
				add = {
					value = scope:task_contract.scheme.scheme_success_chance
					divide = 2
				}
				add = {
					value = root.stewardship
					multiply = 5
				}
			}
			save_scope_as = critical
		}
	}

	# Double down.
	option = {
		name = gdp_merchant_trade_opportunity.0092.a
		trigger = { exists = scope:critical }
		flavor = merchant_base_trade_opportunity_schemes.0000.f.contract_concluded
		scope:task_contract = { complete_task_contract = success_critical }
		# And wrap things up.
		scope:scheme ?= { end_scheme = yes }
	}

	# Acknowledge.
	option = {
		name = gdp_merchant_trade_opportunity.0092.a
		trigger = {
			NOT = { exists = scope:critical }
		}
		flavor = merchant_base_trade_opportunity_schemes.0000.f.contract_concluded
		scope:task_contract = { complete_task_contract = success_standard }
		# And wrap things up.
		scope:scheme ?= { end_scheme = yes }
	}
}

gdp_merchant_trade_opportunity.0093 = { # failure
	type = character_event
	window = scheme_failed_event
	title = gdp_merchant_trade_opportunity.0093.t
	desc = gdp_merchant_trade_opportunity.0093.desc
	theme = trade
	center_portrait = {
		character = root
		animation = disappointed
	}
	override_background = { reference = market }
	
	immediate = {
		merchant_base_trade_opportunity_schemes_set_up_outcome_immediate_effect = yes
		scope:task_contract = {
			task_contract_location = { save_scope_as = destination }
		}
		scope:task_contract = { complete_task_contract = failure_standard }
		# And wrap things up.
		scope:scheme ?= { end_scheme = yes }
	}

	# Acknowledge.
	option = {
		name = gdp_merchant_trade_opportunity.0093.a
		flavor = merchant_base_trade_opportunity_schemes.0000.f.contract_concluded
		merchant_base_contract_schemes_acknowledge_failure_stress_effect = yes
	}
}

gdp_merchant_trade_opportunity.0094 = { # result roll
	hidden = yes

	immediate = {
		roll_scheme_success_or_failure_effect = {
			SUCCESS_EVENT = gdp_merchant_trade_opportunity.0092
			FAILURE_EVENT = gdp_merchant_trade_opportunity.0093
		}
	}
}

####
# gdp_merchant_trade_opportunity.0101-0110 - Silk Road Network
###

gdp_merchant_trade_opportunity.0101 = { # intro
	type = character_event
	title = gdp_merchant_trade_opportunity.0101.t
	desc = gdp_merchant_trade_opportunity.0101.desc
	theme = trade
	left_portrait = {
		character = root
		animation = trade_deal
	}
	right_portrait = {
		trigger = {
			scope:associate ?= { trade_opportunity_trader_travelling_to_contract_trigger = no }
		}
		character = scope:associate
		animation = thinking
	}
	lower_left_portrait = {
		trigger = {
			scope:associate ?= { trade_opportunity_trader_travelling_to_contract_trigger = yes }
		}
		character = scope:associate
	}

	trigger = {
		scope:task_contract = { has_task_contract_type = silk_road_network }
	}

	immediate = {
		save_trade_opportunity_contract_scopes_effect = yes
		start_scheme = {
			type = merchant_silk_road_network_trade_opportunity_scheme
			contract = scope:task_contract
			target_title = scope:task_contract_title.duchy
		}
		scope:task_contract.scheme = { save_scope_as = task_contract_scheme } # save scheme
	}

	# Go for a balanced agent mix.
	option = {
		name = gdp_merchant_trade_opportunity.0101.d
		reason = give_me_balanced_agents
		flavor = EVENT_WINDOW_OPTION_AGENTS_BALANCED
		scope:task_contract_scheme ?= {
			# Success.
			add_agent_slot = agent_scribe
			add_agent_slot = agent_bookkeeper
			add_agent_slot = agent_wrangler
			# Speed.
			add_agent_slot = agent_overseer
			add_agent_slot = agent_messenger
		}

		# No stress, we're just selecting our starter batch.
		# AI always selects balanced agents.
		ai_chance = { base = 1000 }
	}

	# Focus on success chance agents.
	option = {
		name = gdp_merchant_trade_opportunity.0101.a
		reason = give_me_success_agents
		flavor = EVENT_WINDOW_OPTION_AGENTS_SUCCESS
		scope:task_contract_scheme ?= {
			# Success.
			add_agent_slot = agent_scribe
			add_agent_slot = agent_bookkeeper
			add_agent_slot = agent_wrangler
			add_agent_slot = agent_broker
			# Speed.
			add_agent_slot = agent_overseer
		}

		# No stress, we're just selecting our starter batch.
		# AI always picks the balanced config.
	}
	
	# Focus on speedy agents.
	option = {
		name = gdp_merchant_trade_opportunity.0101.b
		reason = give_me_speed_agents
		flavor = EVENT_WINDOW_OPTION_AGENTS_SPEED
		scope:task_contract_scheme ?= {
			# Success.
			add_agent_slot = agent_scribe
			add_agent_slot = agent_bookkeeper
			# Speed.
			add_agent_slot = agent_overseer
			add_agent_slot = agent_messenger
			add_agent_slot = agent_supplier
		}
		# No stress, we're just selecting our starter batch.
		# AI always picks the balanced config.
	}
	
	# Now show us the panel.
	after = {
		open_view = {
			view = intrigue_window
			player = root
		}
	}
}

gdp_merchant_trade_opportunity.0102 = { # success
	type = character_event
	window = scheme_successful_event
	title = gdp_merchant_trade_opportunity.0102.t
	desc = gdp_merchant_trade_opportunity.0102.desc
	theme = trade
	center_portrait = {
		character = root
		animation = war_over_win
	}
	override_background = { reference = market }
	immediate = {
		merchant_base_trade_opportunity_schemes_set_up_outcome_immediate_effect = yes
		scope:task_contract = {
			task_contract_location = { save_scope_as = destination }
		}
		random = {
			chance = {
				value = 5
				add = {
					value = scope:task_contract.scheme.scheme_success_chance
					divide = 2
				}
				add = {
					value = root.stewardship
					multiply = 5
				}
			}
			save_scope_as = critical
		}
	}

	# Double down.
	option = {
		name = gdp_merchant_trade_opportunity.0102.a
		trigger = { exists = scope:critical }
		flavor = merchant_base_trade_opportunity_schemes.0000.f.contract_concluded
		scope:task_contract = { complete_task_contract = success_critical }
		# And wrap things up.
		scope:scheme ?= { end_scheme = yes }
	}

	# Acknowledge.
	option = {
		name = gdp_merchant_trade_opportunity.0102.a
		trigger = {
			NOT = { exists = scope:critical }
		}
		flavor = merchant_base_trade_opportunity_schemes.0000.f.contract_concluded
		scope:task_contract = { complete_task_contract = success_standard }
		# And wrap things up.
		scope:scheme ?= { end_scheme = yes }
	}
}

gdp_merchant_trade_opportunity.0103 = { # failure
	type = character_event
	window = scheme_failed_event
	title = gdp_merchant_trade_opportunity.0103.t
	desc = gdp_merchant_trade_opportunity.0103.desc
	theme = trade
	center_portrait = {
		character = root
		animation = disappointed
	}
	override_background = { reference = market }
	
	immediate = {
		merchant_base_trade_opportunity_schemes_set_up_outcome_immediate_effect = yes
		scope:task_contract = {
			task_contract_location = { save_scope_as = destination }
		}
		scope:task_contract = { complete_task_contract = failure_standard }
		# And wrap things up.
		scope:scheme ?= { end_scheme = yes }
	}

	# Acknowledge.
	option = {
		name = gdp_merchant_trade_opportunity.0103.a
		flavor = merchant_base_trade_opportunity_schemes.0000.f.contract_concluded
		merchant_base_contract_schemes_acknowledge_failure_stress_effect = yes
	}
}

gdp_merchant_trade_opportunity.0104 = { # result roll
	hidden = yes

	immediate = {
		roll_scheme_success_or_failure_effect = {
			SUCCESS_EVENT = gdp_merchant_trade_opportunity.0102
			FAILURE_EVENT = gdp_merchant_trade_opportunity.0103
		}
	}
}

####
# gdp_merchant_trade_opportunity.0111-0120 - Silk Road Caravan
###

gdp_merchant_trade_opportunity.0111 = { # intro
	type = character_event
	title = gdp_merchant_trade_opportunity.0111.t
	desc = gdp_merchant_trade_opportunity.0111.desc
	theme = trade
	left_portrait = {
		character = root
		animation = trade_deal
	}
	right_portrait = {
		trigger = {
			scope:associate ?= { trade_opportunity_trader_travelling_to_contract_trigger = no }
		}
		character = scope:associate
		animation = thinking
	}
	lower_left_portrait = {
		trigger = {
			scope:associate ?= { trade_opportunity_trader_travelling_to_contract_trigger = yes }
		}
		character = scope:associate
	}

	trigger = {
		scope:task_contract = { has_task_contract_type = silk_road_caravan }
	}

	immediate = {
		save_trade_opportunity_contract_scopes_effect = yes
		start_scheme = {
			type = merchant_silk_road_caravan_trade_opportunity_scheme
			contract = scope:task_contract
			target_title = scope:task_contract_title.duchy
		}
		scope:task_contract.scheme = { save_scope_as = task_contract_scheme } # save scheme
	}

	# Go for a balanced agent mix.
	option = {
		name = gdp_merchant_trade_opportunity.0111.d
		reason = give_me_balanced_agents
		flavor = EVENT_WINDOW_OPTION_AGENTS_BALANCED
		scope:task_contract_scheme ?= {
			# Success.
			add_agent_slot = agent_scribe
			add_agent_slot = agent_bookkeeper
			add_agent_slot = agent_wrangler
			# Speed.
			add_agent_slot = agent_overseer
			add_agent_slot = agent_messenger
		}

		# No stress, we're just selecting our starter batch.
		# AI always selects balanced agents.
		ai_chance = { base = 1000 }
	}

	# Focus on success chance agents.
	option = {
		name = gdp_merchant_trade_opportunity.0111.a
		reason = give_me_success_agents
		flavor = EVENT_WINDOW_OPTION_AGENTS_SUCCESS
		scope:task_contract_scheme ?= {
			# Success.
			add_agent_slot = agent_scribe
			add_agent_slot = agent_bookkeeper
			add_agent_slot = agent_wrangler
			add_agent_slot = agent_broker
			# Speed.
			add_agent_slot = agent_overseer
		}

		# No stress, we're just selecting our starter batch.
		# AI always picks the balanced config.
	}
	
	# Focus on speedy agents.
	option = {
		name = gdp_merchant_trade_opportunity.0111.b
		reason = give_me_speed_agents
		flavor = EVENT_WINDOW_OPTION_AGENTS_SPEED
		scope:task_contract_scheme ?= {
			# Success.
			add_agent_slot = agent_scribe
			add_agent_slot = agent_bookkeeper
			# Speed.
			add_agent_slot = agent_overseer
			add_agent_slot = agent_messenger
			add_agent_slot = agent_supplier
		}
		# No stress, we're just selecting our starter batch.
		# AI always picks the balanced config.
	}
	
	# Now show us the panel.
	after = {
		open_view = {
			view = intrigue_window
			player = root
		}
	}
}

gdp_merchant_trade_opportunity.0112 = { # success
	type = character_event
	window = scheme_successful_event
	title = gdp_merchant_trade_opportunity.0112.t
	desc = gdp_merchant_trade_opportunity.0112.desc
	theme = trade
	center_portrait = {
		character = root
		animation = dromedary_petting
		camera = camera_event_dromedary_leading_left_forward_centered
	}
	override_background = { reference = market }
	immediate = {
		merchant_base_trade_opportunity_schemes_set_up_outcome_immediate_effect = yes
		scope:task_contract = {
			task_contract_location = { save_scope_as = destination }
		}
		random = {
			chance = {
				value = 5
				add = {
					value = scope:task_contract.scheme.scheme_success_chance
					divide = 2
				}
				add = {
					value = root.stewardship
					multiply = 5
				}
			}
			save_scope_as = critical
		}
	}

	# Double down.
	option = {
		name = gdp_merchant_trade_opportunity.0112.a
		flavor = merchant_base_trade_opportunity_schemes.0000.f.contract_concluded
		trigger = { exists = scope:critical }
		scope:task_contract = { complete_task_contract = success_critical }
		# And wrap things up.
		scope:scheme ?= { end_scheme = yes }
	}

	# Acknowledge.
	option = {
		name = gdp_merchant_trade_opportunity.0112.a
		trigger = {
			NOT = { exists = scope:critical }
		}
		flavor = merchant_base_trade_opportunity_schemes.0000.f.contract_concluded
		scope:task_contract = { complete_task_contract = success_standard }
		# And wrap things up.
		scope:scheme ?= { end_scheme = yes }
	}
}

gdp_merchant_trade_opportunity.0113 = { # failure
	type = character_event
	window = scheme_failed_event
	title = gdp_merchant_trade_opportunity.0113.t
	desc = gdp_merchant_trade_opportunity.0113.desc
	theme = trade
	center_portrait = {
		character = root
		animation = disappointed
	}
	override_background = { reference = market }
	
	immediate = {
		merchant_base_trade_opportunity_schemes_set_up_outcome_immediate_effect = yes
		scope:task_contract = {
			task_contract_location = { save_scope_as = destination }
		}
		scope:task_contract = { complete_task_contract = failure_standard }
		# And wrap things up.
		scope:scheme ?= { end_scheme = yes }
	}

	# Acknowledge.
	option = {
		name = gdp_merchant_trade_opportunity.0113.a
		flavor = merchant_base_trade_opportunity_schemes.0000.f.contract_concluded
		merchant_base_contract_schemes_acknowledge_failure_stress_effect = yes
	}
}

gdp_merchant_trade_opportunity.0114 = { # result roll
	hidden = yes

	immediate = {
		roll_scheme_success_or_failure_effect = {
			SUCCESS_EVENT = gdp_merchant_trade_opportunity.0112
			FAILURE_EVENT = gdp_merchant_trade_opportunity.0113
		}
	}
}

####
# gdp_merchant_trade_opportunity.0121-0130 - Entrepot Buy
###

gdp_merchant_trade_opportunity.0121 = { # intro
	type = character_event
	title = gdp_merchant_trade_opportunity.0121.t
	desc = gdp_merchant_trade_opportunity.0121.desc
	theme = trade
	left_portrait = {
		character = root
		animation = trade_deal
	}
	right_portrait = {
		trigger = {
			scope:associate ?= { trade_opportunity_trader_travelling_to_contract_trigger = no }
		}
		character = scope:associate
		animation = thinking
	}
	lower_left_portrait = {
		trigger = {
			scope:associate ?= { trade_opportunity_trader_travelling_to_contract_trigger = yes }
		}
		character = scope:associate
	}

	trigger = {
		scope:task_contract = { has_task_contract_type = entrepot_buy }
	}

	immediate = {
		save_trade_opportunity_contract_scopes_effect = yes
		start_scheme = {
			type = merchant_entrepot_buy_trade_opportunity_scheme
			contract = scope:task_contract
			target_title = scope:task_contract_title.duchy
		}
		scope:task_contract.scheme = { save_scope_as = task_contract_scheme } # save scheme
	}

	# Go for a balanced agent mix.
	option = {
		name = gdp_merchant_trade_opportunity.0121.d
		reason = give_me_balanced_agents
		flavor = EVENT_WINDOW_OPTION_AGENTS_BALANCED
		scope:task_contract_scheme ?= {
			# Success.
			add_agent_slot = agent_scribe
			add_agent_slot = agent_bookkeeper
			add_agent_slot = agent_wrangler
			# Speed.
			add_agent_slot = agent_overseer
			add_agent_slot = agent_messenger
		}

		# No stress, we're just selecting our starter batch.
		# AI always selects balanced agents.
		ai_chance = { base = 1000 }
	}

	# Focus on success chance agents.
	option = {
		name = gdp_merchant_trade_opportunity.0121.a
		reason = give_me_success_agents
		flavor = EVENT_WINDOW_OPTION_AGENTS_SUCCESS
		scope:task_contract_scheme ?= {
			# Success.
			add_agent_slot = agent_scribe
			add_agent_slot = agent_bookkeeper
			add_agent_slot = agent_wrangler
			add_agent_slot = agent_broker
			# Speed.
			add_agent_slot = agent_overseer
		}

		# No stress, we're just selecting our starter batch.
		# AI always picks the balanced config.
	}
	
	# Focus on speedy agents.
	option = {
		name = gdp_merchant_trade_opportunity.0121.b
		reason = give_me_speed_agents
		flavor = EVENT_WINDOW_OPTION_AGENTS_SPEED
		scope:task_contract_scheme ?= {
			# Success.
			add_agent_slot = agent_scribe
			add_agent_slot = agent_bookkeeper
			# Speed.
			add_agent_slot = agent_overseer
			add_agent_slot = agent_messenger
			add_agent_slot = agent_supplier
		}
		# No stress, we're just selecting our starter batch.
		# AI always picks the balanced config.
	}
	
	# Now show us the panel.
	after = {
		open_view = {
			view = intrigue_window
			player = root
		}
	}
}

gdp_merchant_trade_opportunity.0122 = { # success
	type = character_event
	window = scheme_successful_event
	title = gdp_merchant_trade_opportunity.0122.t
	desc = gdp_merchant_trade_opportunity.0122.desc
	theme = trade
	center_portrait = {
		character = root
		animation = holding_tally_stick
	}
	override_background = { reference = market }
	immediate = {
		merchant_base_trade_opportunity_schemes_set_up_outcome_immediate_effect = yes
		scope:task_contract = {
			task_contract_location = { save_scope_as = destination }
		}
		random = {
			chance = {
				value = 5
				add = {
					value = scope:task_contract.scheme.scheme_success_chance
					divide = 2
				}
				add = {
					value = root.stewardship
					multiply = 5
				}
			}
			save_scope_as = critical
		}
	}

	# Double down.
	option = {
		name = gdp_merchant_trade_opportunity.0122.a
		trigger = { exists = scope:critical }
		flavor = merchant_base_trade_opportunity_schemes.0000.f.contract_concluded
		scope:task_contract = { complete_task_contract = success_critical }
		# And wrap things up.
		scope:scheme ?= { end_scheme = yes }
	}

	# Acknowledge.
	option = {
		name = gdp_merchant_trade_opportunity.0122.a
		trigger = {
			NOT = { exists = scope:critical }
		}
		flavor = merchant_base_trade_opportunity_schemes.0000.f.contract_concluded
		scope:task_contract = { complete_task_contract = success_standard }
		# And wrap things up.
		scope:scheme ?= { end_scheme = yes }
	}
}

gdp_merchant_trade_opportunity.0123 = { # failure
	type = character_event
	window = scheme_failed_event
	title = gdp_merchant_trade_opportunity.0123.t
	desc = gdp_merchant_trade_opportunity.0123.desc
	theme = trade
	center_portrait = {
		character = root
		animation = stress
	}
	override_background = { reference = market }
	
	immediate = {
		merchant_base_trade_opportunity_schemes_set_up_outcome_immediate_effect = yes
		scope:task_contract = {
			task_contract_location = { save_scope_as = destination }
		}
		scope:task_contract = { complete_task_contract = failure_standard }
		# And wrap things up.
		scope:scheme ?= { end_scheme = yes }
	}

	# Acknowledge.
	option = {
		name = gdp_merchant_trade_opportunity.0123.a
		flavor = merchant_base_trade_opportunity_schemes.0000.f.contract_concluded
		merchant_base_contract_schemes_acknowledge_failure_stress_effect = yes
	}
}

gdp_merchant_trade_opportunity.0124 = { # result roll
	hidden = yes

	immediate = {
		roll_scheme_success_or_failure_effect = {
			SUCCESS_EVENT = gdp_merchant_trade_opportunity.0122
			FAILURE_EVENT = gdp_merchant_trade_opportunity.0123
		}
	}
}

####
# gdp_merchant_trade_opportunity.0131-0140 - Entrepot Sell
###

gdp_merchant_trade_opportunity.0131 = { # intro
	type = character_event
	title = gdp_merchant_trade_opportunity.0131.t
	desc = gdp_merchant_trade_opportunity.0131.desc
	theme = trade
	left_portrait = {
		character = root
		animation = trade_deal
	}
	right_portrait = {
		trigger = {
			scope:associate ?= { trade_opportunity_trader_travelling_to_contract_trigger = no }
		}
		character = scope:associate
		animation = thinking
	}
	lower_left_portrait = {
		trigger = {
			scope:associate ?= { trade_opportunity_trader_travelling_to_contract_trigger = yes }
		}
		character = scope:associate
	}

	trigger = {
		scope:task_contract = { has_task_contract_type = entrepot_sell }
	}

	immediate = {
		save_trade_opportunity_contract_scopes_effect = yes
		start_scheme = {
			type = merchant_entrepot_sell_trade_opportunity_scheme
			contract = scope:task_contract
			target_title = scope:task_contract_title.duchy
		}
		scope:task_contract.scheme = { save_scope_as = task_contract_scheme } # save scheme
	}

	# Go for a balanced agent mix.
	option = {
		name = gdp_merchant_trade_opportunity.0131.d
		reason = give_me_balanced_agents
		flavor = EVENT_WINDOW_OPTION_AGENTS_BALANCED
		scope:task_contract_scheme ?= {
			# Success.
			add_agent_slot = agent_scribe
			add_agent_slot = agent_bookkeeper
			add_agent_slot = agent_wrangler
			# Speed.
			add_agent_slot = agent_overseer
			add_agent_slot = agent_messenger
		}

		# No stress, we're just selecting our starter batch.
		# AI always selects balanced agents.
		ai_chance = { base = 1000 }
	}

	# Focus on success chance agents.
	option = {
		name = gdp_merchant_trade_opportunity.0131.a
		reason = give_me_success_agents
		flavor = EVENT_WINDOW_OPTION_AGENTS_SUCCESS
		scope:task_contract_scheme ?= {
			# Success.
			add_agent_slot = agent_scribe
			add_agent_slot = agent_bookkeeper
			add_agent_slot = agent_wrangler
			add_agent_slot = agent_broker
			# Speed.
			add_agent_slot = agent_overseer
		}

		# No stress, we're just selecting our starter batch.
		# AI always picks the balanced config.
	}
	
	# Focus on speedy agents.
	option = {
		name = gdp_merchant_trade_opportunity.0131.b
		reason = give_me_speed_agents
		flavor = EVENT_WINDOW_OPTION_AGENTS_SPEED
		scope:task_contract_scheme ?= {
			# Success.
			add_agent_slot = agent_scribe
			add_agent_slot = agent_bookkeeper
			# Speed.
			add_agent_slot = agent_overseer
			add_agent_slot = agent_messenger
			add_agent_slot = agent_supplier
		}
		# No stress, we're just selecting our starter batch.
		# AI always picks the balanced config.
	}
	
	# Now show us the panel.
	after = {
		open_view = {
			view = intrigue_window
			player = root
		}
	}
}

gdp_merchant_trade_opportunity.0132 = { # success
	type = character_event
	window = scheme_successful_event
	title = gdp_merchant_trade_opportunity.0132.t
	desc = gdp_merchant_trade_opportunity.0132.desc
	theme = trade
	center_portrait = {
		character = root
		animation = holding_tally_stick
	}
	override_background = { reference = market }
	immediate = {
		merchant_base_trade_opportunity_schemes_set_up_outcome_immediate_effect = yes
		scope:task_contract = {
			task_contract_location = { save_scope_as = destination }
		}
		random = {
			chance = {
				value = 5
				add = {
					value = scope:task_contract.scheme.scheme_success_chance
					divide = 2
				}
				add = {
					value = root.stewardship
					multiply = 5
				}
			}
			save_scope_as = critical
		}
	}

	# Double down.
	option = {
		name = gdp_merchant_trade_opportunity.0132.a
		trigger = { exists = scope:critical }
		flavor = merchant_base_trade_opportunity_schemes.0000.f.contract_concluded
		scope:task_contract = { complete_task_contract = success_critical }
		# And wrap things up.
		scope:scheme ?= { end_scheme = yes }
	}

	# Acknowledge.
	option = {
		name = gdp_merchant_trade_opportunity.0132.a
		trigger = {
			NOT = { exists = scope:critical }
		}
		flavor = merchant_base_trade_opportunity_schemes.0000.f.contract_concluded
		scope:task_contract = { complete_task_contract = success_standard }
		# And wrap things up.
		scope:scheme ?= { end_scheme = yes }
	}
}

gdp_merchant_trade_opportunity.0133 = { # failure
	type = character_event
	window = scheme_failed_event
	title = gdp_merchant_trade_opportunity.0133.t
	desc = gdp_merchant_trade_opportunity.0133.desc
	theme = trade
	center_portrait = {
		character = root
		animation = stress
	}
	override_background = { reference = market }
	
	immediate = {
		merchant_base_trade_opportunity_schemes_set_up_outcome_immediate_effect = yes
		scope:task_contract = {
			task_contract_location = { save_scope_as = destination }
		}
		scope:task_contract = { complete_task_contract = failure_standard }
		# And wrap things up.
		scope:scheme ?= { end_scheme = yes }
	}

	# Acknowledge.
	option = {
		name = gdp_merchant_trade_opportunity.0133.a
		flavor = merchant_base_trade_opportunity_schemes.0000.f.contract_concluded
		merchant_base_contract_schemes_acknowledge_failure_stress_effect = yes
	}
}

gdp_merchant_trade_opportunity.0134 = { # result roll
	hidden = yes

	immediate = {
		roll_scheme_success_or_failure_effect = {
			SUCCESS_EVENT = gdp_merchant_trade_opportunity.0132
			FAILURE_EVENT = gdp_merchant_trade_opportunity.0133
		}
	}
}

####
# gdp_merchant_trade_opportunity.0141-0150 - Negotiate Tolls
###

gdp_merchant_trade_opportunity.0141 = { # intro
	type = character_event
	title = gdp_merchant_trade_opportunity.0141.t
	desc = gdp_merchant_trade_opportunity.0141.desc
	theme = trade
	left_portrait = {
		character = root
		animation = trade_deal
	}
	right_portrait = {
		trigger = {
			scope:associate ?= { trade_opportunity_trader_travelling_to_contract_trigger = no }
		}
		character = scope:associate
		animation = thinking
	}
	lower_left_portrait = {
		trigger = {
			scope:associate ?= { trade_opportunity_trader_travelling_to_contract_trigger = yes }
		}
		character = scope:associate
	}
	lower_center_portrait = scope:task_contract.task_contract_target

	trigger = {
		scope:task_contract = { has_task_contract_type = negotiate_tolls }
	}

	immediate = {
		save_trade_opportunity_contract_scopes_effect = yes
		start_scheme = {
			type = merchant_negotiate_tolls_trade_opportunity_scheme
			contract = scope:task_contract
			target_character = scope:task_contract_target
		}
		scope:task_contract.scheme = { save_scope_as = task_contract_scheme } # save scheme
	}

	# Go for a balanced agent mix.
	option = {
		name = gdp_merchant_trade_opportunity.0141.d
		reason = give_me_balanced_agents
		flavor = EVENT_WINDOW_OPTION_AGENTS_BALANCED
		scope:task_contract_scheme ?= {
			# Success.
			add_agent_slot = agent_diplomat
			add_agent_slot = agent_bookkeeper
			add_agent_slot = agent_scribe
			# Speed.
			add_agent_slot = agent_socialite
			add_agent_slot = agent_messenger
		}

		# No stress, we're just selecting our starter batch.
		# AI always selects balanced agents.
		ai_chance = { base = 1000 }
	}

	# Focus on success chance agents.
	option = {
		name = gdp_merchant_trade_opportunity.0141.a
		reason = give_me_success_agents
		flavor = EVENT_WINDOW_OPTION_AGENTS_SUCCESS
		scope:task_contract_scheme ?= {
			# Success.
			add_agent_slot = agent_diplomat
			add_agent_slot = agent_bookkeeper
			add_agent_slot = agent_scribe
			add_agent_slot = agent_broker
			# Speed.
			add_agent_slot = agent_socialite
		}

		# No stress, we're just selecting our starter batch.
		# AI always picks the balanced config.
	}
	
	# Focus on speedy agents.
	option = {
		name = gdp_merchant_trade_opportunity.0141.b
		reason = give_me_speed_agents
		flavor = EVENT_WINDOW_OPTION_AGENTS_SPEED
		scope:task_contract_scheme ?= {
			# Success.
			add_agent_slot = agent_diplomat
			add_agent_slot = agent_bookkeeper
			# Speed.
			add_agent_slot = agent_socialite
			add_agent_slot = agent_messenger
			add_agent_slot = agent_supplier
		}
		# No stress, we're just selecting our starter batch.
		# AI always picks the balanced config.
	}
	
	# Now show us the panel.
	after = {
		open_view = {
			view = intrigue_window
			player = root
		}
	}
}

gdp_merchant_trade_opportunity.0142 = { # success
	type = character_event
	window = scheme_successful_event
	title = gdp_merchant_trade_opportunity.0142.t
	desc = gdp_merchant_trade_opportunity.0142.desc
	theme = trade
	center_portrait = {
		character = root
		animation = holding_tally_stick
	}
	override_background = { reference = market }
	immediate = {
		merchant_base_trade_opportunity_schemes_set_up_outcome_immediate_effect = yes
		scope:task_contract = {
			task_contract_location = { save_scope_as = destination }
			task_contract_target ?= { save_scope_as = task_contract_target }
		}
		if = {
			limit = { scope:task_contract.var:task_contract_market.market_toll_level_minus_2_value != scope:task_contract.var:task_contract_market.market_toll_level_minus_1_value }
			random = {
				chance = {
					value = 5
					add = {
						value = scope:task_contract.scheme.scheme_success_chance
						divide = 2
					}
					add = {
						value = root.diplomacy
						multiply = 5
					}
				}
				save_scope_as = critical
			}
		}
	}

	# Double down.
	option = {
		name = gdp_merchant_trade_opportunity.0142.a
		trigger = { exists = scope:critical }
		flavor = merchant_base_trade_opportunity_schemes.0000.f.contract_concluded
		scope:task_contract = { complete_task_contract = success_critical }
		# And wrap things up.
		scope:scheme ?= { end_scheme = yes }
	}

	# Acknowledge.
	option = {
		name = gdp_merchant_trade_opportunity.0142.a
		trigger = {
			NOT = { exists = scope:critical }
		}
		flavor = merchant_base_trade_opportunity_schemes.0000.f.contract_concluded
		scope:task_contract = { complete_task_contract = success_standard }
		# And wrap things up.
		scope:scheme ?= { end_scheme = yes }
	}
}

gdp_merchant_trade_opportunity.0143 = { # failure
	type = character_event
	window = scheme_failed_event
	title = gdp_merchant_trade_opportunity.0143.t
	desc = gdp_merchant_trade_opportunity.0143.desc
	theme = trade
	center_portrait = {
		character = root
		animation = stress
	}
	override_background = { reference = throne_room }
	
	immediate = {
		merchant_base_trade_opportunity_schemes_set_up_outcome_immediate_effect = yes
		scope:task_contract = {
			task_contract_location = { save_scope_as = destination }
			task_contract_target = { save_scope_as = bg_override_char }
		}
		scope:task_contract = { complete_task_contract = failure_standard }
		# And wrap things up.
		scope:scheme ?= { end_scheme = yes }
	}

	# Acknowledge.
	option = {
		name = gdp_merchant_trade_opportunity.0143.a
		flavor = merchant_base_trade_opportunity_schemes.0000.f.contract_concluded
		merchant_base_contract_schemes_acknowledge_failure_stress_effect = yes
	}
}

gdp_merchant_trade_opportunity.0144 = { # result roll
	hidden = yes

	immediate = {
		roll_scheme_success_or_failure_effect = {
			SUCCESS_EVENT = gdp_merchant_trade_opportunity.0142
			FAILURE_EVENT = gdp_merchant_trade_opportunity.0143
		}
	}
}

####
# gdp_merchant_trade_opportunity.0151-0160 - Smuggle Goods
###

gdp_merchant_trade_opportunity.0151 = { # intro
	type = character_event
	title = gdp_merchant_trade_opportunity.0151.t
	desc = gdp_merchant_trade_opportunity.0151.desc
	theme = trade
	left_portrait = {
		character = root
		animation = trade_deal
	}
	right_portrait = {
		trigger = {
			scope:associate ?= { trade_opportunity_trader_travelling_to_contract_trigger = no }
		}
		character = scope:associate
		animation = thinking
	}
	lower_left_portrait = {
		trigger = {
			scope:associate ?= { trade_opportunity_trader_travelling_to_contract_trigger = yes }
		}
		character = scope:associate
	}
	lower_center_portrait = scope:owner

	trigger = {
		scope:task_contract = { has_task_contract_type = smuggle_goods }
	}

	immediate = {
		save_trade_opportunity_contract_scopes_effect = yes
		start_scheme = {
			type = merchant_smuggle_goods_trade_opportunity_scheme
			contract = scope:task_contract
			target_character = scope:task_contract_title.county.holder
		}
		scope:task_contract = {
			scheme = { save_scope_as = task_contract_scheme } # save scheme
			var:task_contract_market = {
				trade_market_owner.county.holder = { save_scope_as = owner }
			}
		}
	}

	# Go for a balanced agent mix.
	option = {
		name = gdp_merchant_trade_opportunity.0151.d
		reason = give_me_balanced_agents
		flavor = EVENT_WINDOW_OPTION_AGENTS_BALANCED
		scope:task_contract_scheme ?= {
			# Success.
			add_agent_slot = agent_muscle
			add_agent_slot = agent_scout
			# Speed.
			add_agent_slot = agent_planner
			add_agent_slot = agent_supplier
			# Secrecy.
			add_agent_slot = agent_lookout
		}
		# No stress, we're just selecting our starter batch.
		# AI always selects balanced agents.
		ai_chance = { base = 1000 }
	}

	# Focus on success chance agents.
	option = {
		name = gdp_merchant_trade_opportunity.0151.a
		reason = give_me_success_agents
		flavor = EVENT_WINDOW_OPTION_AGENTS_SUCCESS
		scope:task_contract_scheme ?= {
			# Success.
			add_agent_slot = agent_muscle
			add_agent_slot = agent_scout
			add_agent_slot = agent_thug
			# Speed.
			add_agent_slot = agent_planner
			# Secrecy.
			add_agent_slot = agent_lookout
		}
		# No stress, we're just selecting our starter batch.
		# AI always picks the balanced config.
	}
	
	# Focus on speedy agents.
	option = {
		name = gdp_merchant_trade_opportunity.0151.b
		reason = give_me_speed_agents
		flavor = EVENT_WINDOW_OPTION_AGENTS_SPEED
		scope:task_contract_scheme ?= {
			# Success.
			add_agent_slot = agent_muscle
			# Speed.
			add_agent_slot = agent_planner
			add_agent_slot = agent_supplier
			add_agent_slot = agent_messenger
			# Secrecy.
			add_agent_slot = agent_lookout
		}
		# No stress, we're just selecting our starter batch.
		# AI always picks the balanced config.
	}

	# Focus on secrecy agents.
	option = {
		name = gdp_merchant_trade_opportunity.0151.c
		reason = give_me_secrecy_agents
		flavor = EVENT_WINDOW_OPTION_AGENTS_SECRECY
		scope:task_contract_scheme ?= {
			# Success.
			add_agent_slot = agent_muscle
			# Speed.
			add_agent_slot = agent_planner
			# Secrecy.
			add_agent_slot = agent_lookout
			add_agent_slot = agent_alibi
			add_agent_slot = agent_decoy
		}
		# No stress, we're just selecting our starter batch.
		# AI always selects balanced agents.
		ai_chance = { base = 1000 }
	}
	
	# Now show us the panel.
	after = {
		open_view = {
			view = intrigue_window
			player = root
		}
	}
}

gdp_merchant_trade_opportunity.0152 = { # success
	type = character_event
	window = scheme_successful_event
	title = gdp_merchant_trade_opportunity.0152.t
	desc = gdp_merchant_trade_opportunity.0152.desc
	theme = trade
	center_portrait = {
		character = root
		animation = lantern
	}
	lower_right_portrait = scope:target
	override_background = { reference = alley_night }
	immediate = {
		merchant_base_trade_opportunity_schemes_set_up_outcome_immediate_effect = yes
		scope:task_contract = {
			task_contract_location = { save_scope_as = destination }
			task_contract_target = { save_scope_as = target }
		}
	}

	# Acknowledge.
	option = {
		name = gdp_merchant_trade_opportunity.0152.a
		flavor = merchant_base_trade_opportunity_schemes.0000.f.contract_concluded
		scope:task_contract = { complete_task_contract = success_standard }
		# And wrap things up.
		scope:scheme ?= { end_scheme = yes }
	}
}

gdp_merchant_trade_opportunity.0153 = { # failure
	type = character_event
	window = scheme_failed_event
	title = gdp_merchant_trade_opportunity.0153.t
	desc = gdp_merchant_trade_opportunity.0153.desc
	theme = trade
	center_portrait = {
		character = root
		animation = stress
	}
	lower_right_portrait = scope:target
	override_background = { reference = market }
	
	immediate = {
		merchant_base_trade_opportunity_schemes_set_up_outcome_immediate_effect = yes
		scope:task_contract = {
			task_contract_location = { save_scope_as = destination }
			task_contract_target = { save_scope_as = target }
		}
		scope:task_contract = { complete_task_contract = failure_standard }
		# And wrap things up.
		scope:scheme ?= { end_scheme = yes }
	}

	# Acknowledge.
	option = {
		name = gdp_merchant_trade_opportunity.0153.a
		flavor = merchant_base_trade_opportunity_schemes.0000.f.contract_concluded
		merchant_base_contract_schemes_acknowledge_failure_stress_effect = yes
	}
}

gdp_merchant_trade_opportunity.0154 = { # result roll
	hidden = yes

	immediate = {
		roll_scheme_success_or_failure_effect = {
			SUCCESS_EVENT = gdp_merchant_trade_opportunity.0152
			FAILURE_EVENT = gdp_merchant_trade_opportunity.0153
		}
	}
}

##################################################
# Trade Opportunity Pool Events
# 1001 - 2000
##################################################

# Local ruler gets in the way
gdp_merchant_trade_opportunity.1001 = {
	type = character_event
	title = gdp_merchant_trade_opportunity.1001.t
	desc = gdp_merchant_trade_opportunity.1001.desc
	theme = trade
	left_portrait = {
		character = root
		animation = pondering
	}
	lower_center_portrait = scope:local_ruler
	lower_right_portrait = scope:other_merchant
	# Scheme Preparations status bar
	widget = {
		gui = "event_window_widget_scheme"
		container = "custom_widgets_container"
	}

	trigger = {
		scope:local_ruler ?= {
			is_available_quick = {
				ai = yes
				alive = yes
				adult = yes
				imprisoned = no
				incapable = no
				in_army = no
			}
			opinion = {
				target = root
				value < 50
			}
		}
		trigger_if = {
			limit = { exists = suzerain }
			suzerain != scope:local_ruler
		}
		NOT = {
			has_any_good_relationship_with_character_trigger = { CHARACTER = scope:local_ruler }
		}
		scope:scheme = {
			scheme_agent_charges > 1
		}
		scope:task_contract ?= {
			NOT = { has_variable = had_event_gdp_merchant_trade_opportunity_1001 }
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			factor = 2
			has_any_bad_relationship_with_character_trigger = { CHARACTER = scope:local_ruler }
		}
	}

	immediate = {
		scope:task_contract ?= { set_variable = had_event_gdp_merchant_trade_opportunity_1001 }
		scope:local_market ?= {
			# Search current market first
			random_character_in_market = {
				limit = {
					is_ai = yes
					government_has_flag = government_is_merchant
					this != root
				}
				save_scope_as = other_merchant
			}
			# Then owners of routes touching market
			if = {
				limit = { NOT = { exists = scope:other_merchant } }
				random_trade_route_in_market = {
					limit = {
						trade_route_owner = {
							is_ai = yes
							government_has_flag = government_is_merchant
							this != root
						}
					}
					trade_route_owner = { save_scope_as = other_merchant }
				}
			}
			# Then nearby global merchants
			if = {
				limit = { NOT = { exists = scope:other_merchant } }
				random_in_global_list = {
					variable = merchants_tally
					limit = {
						holder = {
							is_ai = yes
							this != root
							domicile.domicile_location ?= {
								duchy ?= {
									OR = {
										this = scope:local_market.trade_market_owner.duchy
										any_title_to_title_neighboring_and_across_water_duchy = { this = scope:local_market.trade_market_owner.duchy }
									}
								}
							}
						}
					}
					holder = { save_scope_as = other_merchant }
				}
			}
		}
	}

	option = { # Bribe
		name = gdp_merchant_trade_opportunity.1001.a
		pay_short_term_gold = {
			gold = scope:local_ruler.minor_gold_value
			target = scope:local_ruler
		}
		stress_and_fulfillment_impact = {
			greedy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_rationality = 0.5
			}
			modifier = {
				short_term_gold < scope:local_ruler.medium_gold_value
				factor = 0
			}
		}
	}

	option = { # Sweeten
		name = gdp_merchant_trade_opportunity.1001.b
		duel = {
			target = scope:local_ruler
			skill = diplomacy
			50 = {
				compare_modifier = {
					 value = scope:duel_value
					 multiplier = 3.5
					 min = -49
				}
				min = 10
				desc = gdp_merchant_trade_opportunity.1001.b.good
				send_interface_toast = {
					type = event_toast_effect_good
					title = gdp_merchant_trade_opportunity.1001.b.good
					right_icon = scope:local_ruler
					add_prestige = minor_prestige_gain
					reverse_add_opinion = {
						target = scope:local_ruler
						modifier = friendliness_opinion
						opinion = 20
					}
				}
			}
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				min = 10
				desc = gdp_merchant_trade_opportunity.1001.b.bad
				send_interface_toast = {
					type = event_toast_effect_good
					title = gdp_merchant_trade_opportunity.1001.b.bad
					right_icon = scope:local_ruler
					scope:scheme = { change_opportunities = -2 }
					reverse_add_opinion = {
						target = scope:local_ruler
						modifier = angry_opinion
						opinion = -20
					}
				}
			}
		}
		stress_and_fulfillment_impact = {
			humble = minor_stress_impact_gain
			craven = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_sociability = 0.5
			}
			modifier = {
				diplomacy < scope:local_ruler.diplomacy_double_value
				factor = 0
			}
		}
	}

	option = { # Distract
		name = gdp_merchant_trade_opportunity.1001.c
		trigger = { exists = scope:other_merchant }
		duel = {
			target = scope:local_ruler
			skill = intrigue
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				min = 10
				desc = gdp_merchant_trade_opportunity.1001.c.good
				send_interface_toast = {
					type = event_toast_effect_good
					title = gdp_merchant_trade_opportunity.1001.c.good
					right_icon = scope:local_ruler
					add_intrigue_lifestyle_xp = medium_lifestyle_xp
					scope:other_merchant = {
						pay_short_term_gold = {
							gold = minor_gold_value
							target = scope:local_ruler
						}
					}
				}
			}
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				min = 10
				desc = gdp_merchant_trade_opportunity.1001.c.bad
				send_interface_toast = {
					type = event_toast_effect_good
					title = gdp_merchant_trade_opportunity.1001.c.bad
					right_icon = scope:local_ruler
					pay_short_term_gold = {
						gold = medium_gold_value
						target = scope:local_ruler
					}
					reverse_add_opinion = {
						target = scope:local_ruler
						modifier = angry_opinion
						opinion = -20
					}
				}
			}
		}
		reverse_add_opinion = {
			target = scope:other_merchant
			modifier = angry_opinion
			opinion = -20
		}
		house = {
			change_house_relation_effect = {
				HOUSE = scope:other_merchant.house
				VALUE = house_relation_damage_minor_value
				REASON = trade_opportunity_friction
				CHAR = root
				TARGET_CHAR = scope:other_merchant
				TITLE = scope:dummy_gender
			}
		}
		stress_and_fulfillment_impact = {
			honest = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_honor = -0.25
			}
			modifier = {
				intrigue < scope:local_ruler.intrigue_double_value
				factor = 0
			}
		}
	}

	option = { # Dismiss
		name = gdp_merchant_trade_opportunity.1001.d
		scope:scheme = { change_opportunities = -1 }
		reverse_add_opinion = {
			target = scope:local_ruler
			modifier = angry_opinion
			opinion = -20
		}
		stress_and_fulfillment_impact = {
			impatient = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_boldness = 0.5
			}
		}
	}
}

scripted_trigger gdp_merchant_trade_opportunity_1011_other_merchant_trigger = {
	is_ai = yes
	gdp_profit_potential_rival_trigger = {
		ROUTE_OWNER = root
		MARKET = scope:local_market
	}
	NOR = {
		this = root
		save_temporary_scope_as = other_merchant_temp
		scope:local_market = {
			has_competitiveness_modifier_for_character = {
				modifier = ruler_stifles_company_modifier
				character = scope:other_merchant_temp
			}
		}
	}
}

# Local ruler offers assistance
gdp_merchant_trade_opportunity.1011 = {
	type = character_event
	title = gdp_merchant_trade_opportunity.1011.t
	desc = gdp_merchant_trade_opportunity.1011.desc
	theme = trade
	left_portrait = {
		character = root
		animation = nervous
	}
	right_portrait = {
		character = scope:local_ruler
		animation = war_over_tie
	}
	lower_center_portrait = scope:other_merchant
	override_background = { reference = relaxing_room }
	# Scheme Preparations status bar
	widget = {
		gui = "event_window_widget_scheme"
		container = "custom_widgets_container"
	}

	trigger = {
		scope:local_ruler ?= {
			is_available_quick = {
				ai = yes
				alive = yes
				adult = yes
				imprisoned = no
				incapable = no
				in_army = no
			}
			opinion = {
				target = root
				value > -25
			}
		}
		trigger_if = {
			limit = { exists = suzerain }
			suzerain != scope:local_ruler
		}
		NOR = {
			scope:local_market = {
				has_competitiveness_modifier_for_character = {
					modifier = ruler_stifles_company_modifier
					character = root
				}
			}
			has_any_bad_relationship_with_character_trigger = { CHARACTER = scope:local_ruler }
		}
		scope:task_contract ?= {
			NOT = { has_variable = had_event_gdp_merchant_trade_opportunity_1011 }
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			factor = 2
			has_any_good_relationship_with_character_trigger = { CHARACTER = scope:local_ruler }
		}
	}

	immediate = {
		scope:task_contract ?= { set_variable = had_event_gdp_merchant_trade_opportunity_1011 }
		scope:local_market ?= {
			random_character_in_market = {
				limit = { gdp_merchant_trade_opportunity_1011_other_merchant_trigger = yes }
				save_scope_as = other_merchant
			}
		}
		scope:local_ruler = { save_scope_as = bg_override_char }
	}

	option = { # Request kickbacks
		name = gdp_merchant_trade_opportunity.1011.a
		trigger = { scope:local_ruler.gold > medium_gold_value }
		scope:local_ruler = {
			pay_short_term_gold = {
				gold = root.minor_gold_value
				target = root
			}
			add_opinion = {
				target = root
				modifier = annoyed_opinion
				opinion = -10
			}
		}
		stress_and_fulfillment_impact = {
			greedy = minor_stress_impact_loss
			honest = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = 0.5
			}
			modifier = {
				short_term_gold < medium_gold_value
				factor = 0
			}
		}
	}

	option = { # Attempt to advise
		name = gdp_merchant_trade_opportunity.1011.b
		duel = {
			skill = stewardship
			value = decent_skill_rating
			5 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 2
					min = -49
				}
				min = 10
				desc = gdp_merchant_trade_opportunity.1011.b.good
				send_interface_toast = {
					type = event_toast_effect_good
					title = gdp_merchant_trade_opportunity.1011.b.good
					right_icon = scope:target
					add_prestige = minor_prestige_gain
					scope:task_contract_location.county = {
						add_county_modifier = {
							modifier = merchant_prosperity_advice_modifier
							years = 10
						}
					}
				}
			}
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -2
					min = -49
				}
				min = 10
				desc = gdp_merchant_trade_opportunity.1011.b.bad
				send_interface_toast = {
					type = event_toast_effect_bad
					title = gdp_merchant_trade_opportunity.1011.b.bad
					right_icon = scope:target
					reverse_add_opinion = {
						target = scope:local_ruler
						modifier = disappointed_opinion
						opinion = -15
					}
					scope:task_contract_location.county = { change_prosperity_progress = -15 }
				}
			}
		}
		stress_and_fulfillment_impact = {
			lazy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_energy = 0.5
			}
			modifier = {
				stewardship < extremely_high_skill_rating
				factor = 0
			}
		}
	}

	option = { # Attack competitor
		name = {
			text = gdp_merchant_trade_opportunity.1011.c
			trigger = { exists = scope:other_merchant }
		}
		name = {
			text = gdp_merchant_trade_opportunity.1011.c.fallback
			trigger = {
				NOT = { exists = scope:other_merchant }
			}
		}
		flavor = gdp_merchant_trade_opportunity.1011.c.flavor
		trigger = {
			custom_tooltip = {
				text = gdp_merchant_trade_opportunity.other_merchant_tt
				exists = scope:other_merchant
			}
		}
		show_as_unavailable = { always = yes }
		random_list = {
			100 = {
				modifier = { add = "scope:local_ruler.opinion(root)" }
				modifier = {
					factor = {
						value = diplomacy
						divide = 10
						min = 1
					}
				}
				modifier = {
					add = 25
					has_any_good_relationship_with_character_trigger = { CHARACTER = scope:local_ruler }
				}
				modifier = {
					add = -25
					has_any_bad_relationship_with_character_trigger = { CHARACTER = scope:local_ruler }
				}
				desc = gdp_merchant_trade_opportunity.1011.c.good
				send_interface_toast = {
					type = event_toast_effect_good
					title = gdp_merchant_trade_opportunity.1011.c.good
					left_icon = scope:local_ruler
					right_icon = scope:other_merchant
					scope:local_market = {
						add_competitiveness_modifier_for_character = {
							modifier = ruler_stifles_company_modifier
							character = scope:other_merchant
						}
					}
				}
			}
			100 = {
				modifier = { add = "scope:local_ruler.opinion(scope:other_merchant)" }
				modifier = {
					factor = {
						value = scope:other_merchant.diplomacy
						divide = 10
						min = 1
					}
				}
				modifier = {
					add = 25
					scope:other_merchant = {
						has_any_good_relationship_with_character_trigger = { CHARACTER = scope:local_ruler }
					}
				}
				modifier = {
					add = -25
					scope:other_merchant = {
						has_any_bad_relationship_with_character_trigger = { CHARACTER = scope:local_ruler }
					}
				}
				desc = gdp_merchant_trade_opportunity.1011.c.bad
				send_interface_toast = {
					type = event_toast_effect_bad
					title = gdp_merchant_trade_opportunity.1011.c.bad
					left_icon = scope:local_ruler
					right_icon = scope:other_merchant
					scope:local_market = {
						add_competitiveness_modifier_for_character = {
							modifier = ruler_stifles_company_modifier
							character = root
						}
					}
				}
			}
		}
		reverse_add_opinion = {
			target = scope:other_merchant
			modifier = angry_opinion
			opinion = -10
		}
		house = {
			change_house_relation_effect = {
				HOUSE = scope:other_merchant.house
				VALUE = house_relation_damage_minor_value
				REASON = trade_opportunity_friction
				CHAR = root
				TARGET_CHAR = scope:other_merchant
				TITLE = scope:dummy_gender
			}
		}
		stress_and_fulfillment_impact = {
			forgiving = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_boldness = 0.5
			}
			modifier = {
				diplomacy < scope:other_merchant.diplomacy_double_value
				factor = 0
			}
		}
	}

	option = { # Suck up
		name = gdp_merchant_trade_opportunity.1011.d
		add_prestige = miniscule_prestige_gain
		reverse_add_opinion = {
			target = scope:local_ruler
			modifier = friendliness_opinion
			opinion = 20
		}
		stress_and_fulfillment_impact = {
			deceitful = minor_stress_impact_loss
			arrogant = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_sociability = 0.5
			}
		}
	}
}

scripted_trigger gdp_merchant_trade_opportunity_1021_merchant_trigger = {
	is_ai = yes
	government_has_flag = government_is_merchant
	NOR = {
		this = scope:owner
		trigger_if = {
			limit = {
				scope:scheme ?= { is_scheme_target_type = character }
			}
			scope:scheme.scheme_target_character ?= this
		}
		trigger_if = {
			limit = {
				scope:scheme ?= { is_scheme_target_type = title }
			}
			scope:scheme.scheme_target_title.holder ?= this
		}
	}
}

# Third party family offers assistance
gdp_merchant_trade_opportunity.1021 = {
	type = character_event
	title = gdp_merchant_trade_opportunity.1021.t
	desc = gdp_merchant_trade_opportunity.1021.desc
	theme = trade
	left_portrait = {
		character = scope:owner
		animation = pondering
		camera = camera_event_very_left
	}
	right_portrait = {
		character = scope:other_merchant
		animation = schadenfreude
		camera = camera_event_very_right
	}
	lower_center_portrait = scope:target
	# Scheme Preparations status bar
	widget = {
		gui = "event_window_widget_scheme"
		container = "custom_widgets_container"
	}

	trigger = {
		scope:task_contract ?= {
			NOT = { has_variable = had_event_gdp_merchant_trade_opportunity_1021 }
		}
		scope:local_market ?= {
			OR = {
				# Search current market first
				any_character_in_market = { gdp_merchant_trade_opportunity_1021_merchant_trigger = yes }
				# Then owners of routes touching market
				any_trade_route_in_market = {
					trade_route_owner = { gdp_merchant_trade_opportunity_1021_merchant_trigger = yes }
				}
				# Then nearby global merchants
				any_in_global_list = {
					variable = merchants_tally
					holder = {
						gdp_merchant_trade_opportunity_1021_merchant_trigger = yes
						domicile.domicile_location ?= {
							duchy ?= {
								OR = {
									this = scope:local_market.trade_market_owner.duchy
									any_title_to_title_neighboring_and_across_water_duchy = { this = scope:local_market.trade_market_owner.duchy }
								}
							}
						}
					}
				}
			}
		}
	}

	immediate = {
		scope:task_contract ?= { set_variable = had_event_gdp_merchant_trade_opportunity_1021 }
		scope:local_market ?= {
			# Search current market first
			random_character_in_market = {
				limit = { gdp_merchant_trade_opportunity_1021_merchant_trigger = yes }
				weight = {
					base = 1
					modifier = {
						has_any_bad_relationship_with_character_trigger = { CHARACTER = scope:owner }
						add = -10
					}
					modifier = {
						scope:scheme ?= { is_scheme_target_type = character }
						exists = scope:scheme.scheme_target_character
						has_any_bad_relationship_with_character_trigger = { CHARACTER = scope:scheme.scheme_target_character }
						add = 10
					}
					modifier = {
						scope:scheme ?= { is_scheme_target_type = title }
						exists = scope:scheme.scheme_target_title.holder
						has_any_bad_relationship_with_character_trigger = { CHARACTER = scope:scheme.scheme_target_title.holder }
						add = 10
					}
					modifier = {
						scope:scheme ?= { is_scheme_target_type = character }
						exists = scope:scheme.scheme_target_character
						house = {
							has_better_house_relation_with_target_house_than_other_trigger = {
								TARGET = scope:owner.house
								OTHER = scope:scheme.scheme_target_character.house
							}
						}
						add = 10
					}
					modifier = {
						scope:scheme ?= { is_scheme_target_type = title }
						exists = scope:scheme.scheme_target_title.holder
						house = {
							has_better_house_relation_with_target_house_than_other_trigger = {
								TARGET = scope:owner.house
								OTHER = scope:scheme.scheme_target_title.holder.house
							}
						}
						add = 10
					}
				}
				save_scope_as = other_merchant
			}
			# Then owners of routes touching market
			if = {
				limit = { NOT = { exists = scope:other_merchant } }
				random_trade_route_in_market = {
					limit = {
						trade_route_owner = { gdp_merchant_trade_opportunity_1021_merchant_trigger = yes }
					}
					weight = {
						base = 1
						modifier = {
							trade_route_owner = {
								has_any_bad_relationship_with_character_trigger = { CHARACTER = scope:owner }
							}
							add = -10
						}
						modifier = {
							scope:scheme ?= { is_scheme_target_type = character }
							exists = scope:scheme.scheme_target_character
							trade_route_owner = {
								has_any_bad_relationship_with_character_trigger = { CHARACTER = scope:scheme.scheme_target_character }
							}
							add = 10
						}
						modifier = {
							scope:scheme ?= { is_scheme_target_type = title }
							exists = scope:scheme.scheme_target_title.holder
							trade_route_owner = {
								has_any_bad_relationship_with_character_trigger = { CHARACTER = scope:scheme.scheme_target_title.holder }
							}
							add = 10
						}
						modifier = {
							scope:scheme ?= { is_scheme_target_type = character }
							exists = scope:scheme.scheme_target_character
							trade_route_owner.house = {
								has_better_house_relation_with_target_house_than_other_trigger = {
									TARGET = scope:owner.house
									OTHER = scope:scheme.scheme_target_character.house
								}
							}
							add = 10
						}
						modifier = {
							scope:scheme ?= { is_scheme_target_type = title }
							exists = scope:scheme.scheme_target_title.holder
							trade_route_owner.house = {
								has_better_house_relation_with_target_house_than_other_trigger = {
									TARGET = scope:owner.house
									OTHER = scope:scheme.scheme_target_title.holder.house
								}
							}
							add = 10
						}
					}
					trade_route_owner = { save_scope_as = other_merchant }
				}
			}
			# Then nearby global merchants
			if = {
				limit = { NOT = { exists = scope:other_merchant } }
				random_in_global_list = {
					variable = merchants_tally
					limit = {
						holder = {
							gdp_merchant_trade_opportunity_1021_merchant_trigger = yes
							domicile.domicile_location ?= {
								duchy ?= {
									OR = {
										this = scope:local_market.trade_market_owner.duchy
										any_title_to_title_neighboring_and_across_water_duchy = { this = scope:local_market.trade_market_owner.duchy }
									}
								}
							}
						}
					}
					weight = {
						base = 1
						modifier = {
							holder = {
								has_any_bad_relationship_with_character_trigger = { CHARACTER = scope:owner }
							}
							add = -10
						}
						modifier = {
							scope:scheme ?= { is_scheme_target_type = character }
							exists = scope:scheme.scheme_target_character
							holder = {
								has_any_bad_relationship_with_character_trigger = { CHARACTER = scope:scheme.scheme_target_character }
							}
							add = 10
						}
						modifier = {
							scope:scheme ?= { is_scheme_target_type = title }
							exists = scope:scheme.scheme_target_title.holder
							holder = {
								has_any_bad_relationship_with_character_trigger = { CHARACTER = scope:scheme.scheme_target_title.holder }
							}
							add = 10
						}
						modifier = {
							scope:scheme ?= { is_scheme_target_type = character }
							exists = scope:scheme.scheme_target_character
							holder.house = {
								has_better_house_relation_with_target_house_than_other_trigger = {
									TARGET = scope:owner.house
									OTHER = scope:scheme.scheme_target_character.house
								}
							}
							add = 10
						}
						modifier = {
							scope:scheme ?= { is_scheme_target_type = title }
							exists = scope:scheme.scheme_target_title.holder
							holder.house = {
								has_better_house_relation_with_target_house_than_other_trigger = {
									TARGET = scope:owner.house
									OTHER = scope:scheme.scheme_target_title.holder.house
								}
							}
							add = 10
						}
					}
					holder = { save_scope_as = other_merchant }
				}
			}
		}
	}

	option = { # Accept
		name = gdp_merchant_trade_opportunity.1021.a
		pay_short_term_gold = {
			gold = minor_gold_value
			target = scope:other_merchant
		}
		scope:scheme = { change_opportunities = 1 }
		reverse_add_opinion = {
			target = scope:other_merchant
			modifier = friendliness_opinion
			opinion = 10
		}
		stress_and_fulfillment_impact = {
			greedy = minor_stress_impact_gain
			arrogant = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_rationality = 0.25
			}
			opinion_modifier = {
				opinion_target = scope:other_merchant
				multiplier = 0.25
			}
			modifier = {
				short_term_gold < medium_gold_value
				factor = 0
			}
		}
	}

	option = { # Deal
		name = gdp_merchant_trade_opportunity.1021.b
		duel = {
			skill = intrigue
			target = scope:other_merchant
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 2
					min = -49
				}
				min = 10
				desc = gdp_merchant_trade_opportunity.1021.b.good
				send_interface_toast = {
					type = event_toast_effect_neutral
					title = gdp_merchant_trade_opportunity.1021.b.good
					right_icon = scope:other_merchant
					add_hook = {
						target = scope:other_merchant
						type = favor_hook
					}
					reverse_add_opinion = {
						target = scope:other_merchant
						modifier = respect_opinion
						opinion = 10
					}
				}
			}
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -2
					min = -49
				}
				min = 10
				desc = gdp_merchant_trade_opportunity.1021.b.bad
				send_interface_toast = {
					type = event_toast_effect_neutral
					title = gdp_merchant_trade_opportunity.1021.b.bad
					right_icon = scope:other_merchant
					scope:scheme = { change_opportunities = -1 }
					reverse_add_opinion = {
						target = scope:other_merchant
						modifier = offended_opinion
						opinion = -10
					}
				}
			}
		}
		stress_and_fulfillment_impact = {
			trusting = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_rationality = -0.25
			}
			opinion_modifier = {
				opinion_target = scope:other_merchant
				multiplier = -0.25
			}
			modifier = {
				intrigue < scope:other_merchant.intrigue_double_value
				factor = 0
			}
		}
	}

	option = { # Alliance
		name = gdp_merchant_trade_opportunity.1021.c
		reverse_add_opinion = {
			target = scope:other_merchant
			modifier = friendliness_opinion
			opinion = 20
		}
		scope:local_market = {
			add_competitiveness_modifier_for_character = {
				modifier = trade_cooperation_modifier
				character = root
			}
			add_competitiveness_modifier_for_character = {
				modifier = trade_cooperation_modifier
				character = scope:other_merchant
			}
		}
		house = {
			change_house_relation_effect = {
				HOUSE = scope:other_merchant.house
				VALUE = house_relation_improve_medium_value
				REASON = trade_opportunity_cooperation
				CHAR = root
				TARGET_CHAR = scope:other_merchant
				TITLE = scope:dummy_gender
			}
		}
		stress_and_fulfillment_impact = {
			trusting = minor_stress_impact_loss
			paranoid = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_rationality = -0.25
			}
			opinion_modifier = {
				opinion_target = scope:other_merchant
				multiplier = -0.25
			}
		}
	}

	option = {
		name = gdp_merchant_trade_opportunity.1021.d
		add_prestige = minor_prestige_gain
		progress_towards_rival_effect = {
			REASON = rival_trade_opportunity_friction
			CHARACTER = scope:other_merchant
			OPINION = 0
		}
		reverse_add_opinion = {
			target = scope:other_merchant
			modifier = hate_opinion
			opinion = -30
		}
		house = {
			change_house_relation_effect = {
				HOUSE = scope:other_merchant.house
				VALUE = house_relation_damage_minor_value
				REASON = trade_opportunity_friction
				CHAR = root
				TARGET_CHAR = scope:other_merchant
				TITLE = scope:dummy_gender
			}
		}
		stress_and_fulfillment_impact = {
			forgiving = minor_stress_impact_gain
			ambitious = minor_stress_impact_loss
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_rationality = -0.25
			}
			opinion_modifier = {
				opinion_target = scope:other_merchant
				multiplier = -0.25
			}
		}
	}
}

# Low unity, leverage house member for opportunity
gdp_merchant_trade_opportunity.1031 = {
	type = character_event
	title = gdp_merchant_trade_opportunity.1031.t
	desc = gdp_merchant_trade_opportunity.1031.desc
	theme = trade
	left_portrait = {
		character = root
		animation = pondering
	}
	right_portrait = {
		character = scope:associate
		animation = stress
	}
	# Scheme Preparations status bar
	widget = {
		gui = "event_window_widget_scheme"
		container = "custom_widgets_container"
	}
	override_background = { reference = study }

	trigger = {
		house = {
			OR = {
				has_house_unity_stage = opportunistic_cs
				has_house_unity_stage = rapacious_cs
			}
		}
		any_courtier = {
			is_available_quick = {
				alive = yes
				adult = yes
				imprisoned = no
				incapable = no
			}
		}
		scope:task_contract ?= {
			NOT = { has_variable = had_event_gdp_merchant_trade_opportunity_1031 }
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			factor = 2
			house = { has_house_unity_stage = rapacious_cs }	
		}
	}

	immediate = {
		scope:task_contract ?= { set_variable = had_event_gdp_merchant_trade_opportunity_1031 }
		random_courtier = {
			limit = {
				house ?= root.house
				is_available_quick = {
					alive = yes
					adult = yes
					imprisoned = no
					incapable = no
				}
				num_offered_task_contracts = 0
			}
			alternative_limit = {
				is_available_quick = {
					alive = yes
					adult = yes
					imprisoned = no
					incapable = no
				}
				num_offered_task_contracts = 0
			}
			weight = {
				base = 1
				modifier = {
					add = {
						value = "opinion(root)"
						multiply = -1
					}
				}
			}
			save_scope_as = associate
		}
	}

	option = {
		name = gdp_merchant_trade_opportunity.1031.a
		scope:scheme = { change_opportunities = 1 }
		reverse_add_opinion = {
			target = scope:associate
			modifier = angry_opinion
			opinion = -20
		}
		apply_house_unity_interaction_effect = {
			CHARACTER = root
			TARGET = scope:associate
			DESC = merchant_unity_associate_after_company_desc
			VALUE = minor_unity_loss
			VALUE_REVERSED = no
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_energy = 0.5
			}
		}
	}

	option = {
		name = gdp_merchant_trade_opportunity.1031.b
		pay_short_term_gold = {
			target = scope:associate
			gold = minor_gold_value
		}
		reverse_add_opinion = {
			target = scope:associate
			modifier = pleased_opinion
			opinion = 10
		}
		apply_house_unity_interaction_effect = {
			CHARACTER = root
			TARGET = scope:associate
			DESC = merchant_unity_associate_after_company_desc
			VALUE = minor_unity_gain
			VALUE_REVERSED = no
		}
		stress_and_fulfillment_impact = {
			greedy = minor_stress_impact_gain
			callous = minor_stress_impact_gain
			compassionate = minor_stress_impact_loss
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_compassion = 0.5
			}
			modifier = {
				short_term_gold < medium_gold_value
				factor = 0
			}
		}
	}

	option = {
		name = gdp_merchant_trade_opportunity.1031.c
		trigger = {
			NOR = {
				is_spouse_of = scope:associate
				is_parent_of = scope:associate
			}
		}
		add_prestige = minor_prestige_gain
		scope:associate = { move_to_pool = yes }
		reverse_add_opinion = {
			target = scope:associate
			modifier = fired_opinion
		}
		stress_and_fulfillment_impact = {
			wrathful = minor_stress_impact_loss
			forgiving = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_vengefulness = 0.5
			}
		}
	}
}

# High unity, house member seizes opportunity
gdp_merchant_trade_opportunity.1041 = {
	type = character_event
	title = gdp_merchant_trade_opportunity.1041.t
	desc = gdp_merchant_trade_opportunity.1041.desc
	theme = trade
	left_portrait = {
		character = root
		animation = admiration
		camera = camera_event_very_left
	}
	right_portrait = {
		character = scope:associate
		animation = personality_honorable
		camera = camera_event_very_right
	}
	override_background = { reference = study }
	# Scheme Preparations status bar
	widget = {
		gui = "event_window_widget_scheme"
		container = "custom_widgets_container"
	}

	trigger = {
		house = {
			OR = {
				has_house_unity_stage = grasping_cs
				has_house_unity_stage = ennobled_cs
			}
		}
		any_courtier = {
			is_available_quick = {
				alive = yes
				adult = yes
				imprisoned = no
				incapable = no
			}
		}
		scope:task_contract ?= {
			NOT = { has_variable = had_event_gdp_merchant_trade_opportunity_1041 }
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			factor = 2
			house = { has_house_unity_stage = ennobled_cs }	
		}
	}

	immediate = {
		scope:task_contract ?= { set_variable = had_event_gdp_merchant_trade_opportunity_1041 }
		random_courtier = {
			limit = {
				house ?= root.house
				is_available_quick = {
					alive = yes
					adult = yes
					imprisoned = no
					incapable = no
				}
				NOT = { has_character_modifier = associate_setting_example_modifier }
			}
			alternative_limit = {
				is_available_quick = {
					alive = yes
					adult = yes
					imprisoned = no
					incapable = no
				}
				NOT = { has_character_modifier = associate_setting_example_modifier }
			}
			save_scope_as = associate
		}
	}

	option = {
		name = gdp_merchant_trade_opportunity.1041.a
		scope:scheme = { change_opportunities = 1 }
		reverse_add_opinion = {
			target = scope:associate
			modifier = respect_opinion
			opinion = 10
		}
		stress_and_fulfillment_impact = {
			arrogant = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_rationality = 0.5
			}
		}
	}

	option = {
		name = gdp_merchant_trade_opportunity.1041.b
		scope:scheme = { change_opportunities = 2 }
		reverse_add_opinion = {
			target = scope:associate
			modifier = annoyed_opinion
			opinion = -10
		}
		apply_house_unity_interaction_effect = {
			CHARACTER = root
			TARGET = scope:associate
			DESC = merchant_unity_associate_unappreciated_desc
			VALUE = minor_unity_loss
			VALUE_REVERSED = no
		}
		stress_and_fulfillment_impact = {
			compassionate = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_compassion = -0.25
				ai_greed = 0.25
			}
		}
	}

	option = {
		name = gdp_merchant_trade_opportunity.1041.c
		scope:associate = {
			hidden_effect = {
				if = {
					limit = { has_character_modifier = associate_following_example_modifier }
					remove_character_modifier = associate_following_example_modifier
				}
			}
			add_character_modifier = {
				modifier = associate_setting_example_modifier
				years = 10
			}
		}
		every_courtier = {
			custom = custom.every_other_associate
			limit = {
				NOR = {
					this = scope:associate
					has_character_modifier = associate_following_example_modifier
				}
			}
			hidden_effect = {
				if = {
					limit = { has_character_modifier = associate_setting_example_modifier }
					remove_character_modifier = associate_setting_example_modifier
				}
			}
			add_character_modifier = {
				modifier = associate_following_example_modifier
				years = 10
			}
		}
		apply_house_unity_interaction_effect = {
			CHARACTER = root
			TARGET = scope:associate
			DESC = merchant_unity_associate_example_desc
			VALUE = miniscule_unity_loss
			VALUE_REVERSED = no
		}
		stress_and_fulfillment_impact = {
			just = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_energy = 0.25
				ai_sociability = 0.25
			}
		}
	}
}

# Competitor offers boon to shove off
gdp_merchant_trade_opportunity.1051 = {
	type = character_event
	title = gdp_merchant_trade_opportunity.1051.t
	desc = {
		desc = gdp_merchant_trade_opportunity.1051.desc
		first_valid = {
			triggered_desc = {
				trigger = { scope:competitor_boon = flag:luxury }
				desc = gdp_merchant_trade_opportunity.1051.desc.luxury
			}
			desc = gdp_merchant_trade_opportunity.1051.desc.gold
		}
	}
	theme = trade
	left_portrait = {
		character = root
		animation = war_over_win
		camera = camera_event_very_left
	}
	right_portrait = {
		character = scope:target
		triggered_animation = {
			trigger = {
				NOT = { exists = scope:competitor_boon }
			}
			animation = steward
		}
		triggered_animation = {
			trigger = { exists = scope:competitor_boon }
			animation = debating
		}
		camera = camera_event_very_right
	}
	# Scheme Preparations status bar
	widget = {
		gui = "event_window_widget_scheme"
		container = "custom_widgets_container"
	}

	trigger = {
		scope:scheme.scheme_target_title.holder ?= {
			is_ai = yes
			government_has_flag = government_is_merchant
			short_term_gold >= root.medium_gold_value
		}
		scope:task_contract ?= {
			NOT = { has_variable = had_event_gdp_merchant_trade_opportunity_1051 }
		}
	}

	immediate = {
		scope:scheme ?= { trade_opportunity_scheme_scopes_effect = yes }
		scope:task_contract ?= { set_variable = had_event_gdp_merchant_trade_opportunity_1051 }
		scope:target ?= {
			random_list = {
				# Luxury Contract
				5 = {
					trigger = {
						root = {
							has_realm_law = company_purpose_caravaneer
							NOT = {
								any_character_task_contract = { has_task_contract_group = merchant_luxury_contract_group }
							}
						}
					}
					save_scope_value_as = {
						name = competitor_boon
						value = flag:luxury
					}
				}
				# Gold
				10 = {
					save_scope_value_as = {
						name = competitor_boon
						value = flag:gold
					}
				}
			}
		}
	}

	option = {
		name = gdp_merchant_trade_opportunity.1051.a
		switch = {
			trigger = scope:competitor_boon
			flag:luxury = {
				custom_tooltip = {
					text = trade_opportunity_gain_luxury_contract_tt
					trigger_event = { on_action = spawn_luxury_contract_on_action }
				}
			}
			flag:gold = {
				scope:target = {
					pay_short_term_gold = {
						gold = root.minor_gold_value
						target = root
					}
				}
			}
		}
		reverse_add_opinion = {
			target = scope:target
			modifier = pleased_opinion
			opinion = 10
		}
		house = {
			change_house_relation_effect = {
				HOUSE = scope:target.house
				VALUE = house_relation_improve_minor_value
				REASON = trade_opportunity_cooperation
				CHAR = root
				TARGET_CHAR = scope:target
				TITLE = scope:dummy_gender
			}
		}
		hidden_effect = {
			scope:task_contract = { merchant_trade_opportunity_travel_complete_or_invalidated_effect = yes }
		}
		scope:scheme = { end_scheme = yes }
		stress_and_fulfillment_impact = {
			arrogant = minor_stress_impact_gain
			vengeful = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = 0.25
				ai_vengefulness = -0.25
			}
		}
	}

	# Counter
	option = {
		name = gdp_merchant_trade_opportunity.1051.b
		duel = {
			skills = { diplomacy stewardship }
			target = scope:target
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				min = 10
				desc = gdp_merchant_trade_opportunity.1051.b.good
				send_interface_toast = {
					type = event_toast_effect_good
					title = gdp_merchant_trade_opportunity.1051.b.good
					right_icon = scope:target
					scope:target = {
						pay_short_term_gold = {
							gold = root.medium_gold_value
							target = root
						}
					}
					hidden_effect = {
						scope:task_contract = { merchant_trade_opportunity_travel_complete_or_invalidated_effect = yes }
					}
					scope:scheme = { end_scheme = yes }
				}
			}
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				min = 10
				desc = gdp_merchant_trade_opportunity.1051.b.bad
				send_interface_toast = {
					type = event_toast_effect_bad
					title = gdp_merchant_trade_opportunity.1051.b.bad
					right_icon = scope:target
					reverse_add_opinion = {
						target = scope:target
						modifier = angry_opinion
						opinion = -20
					}
					house = {
						change_house_relation_effect = {
							HOUSE = scope:target.house
							VALUE = house_relation_damage_medium_value
							REASON = trade_opportunity_friction
							CHAR = root
							TARGET_CHAR = scope:target
							TITLE = scope:dummy_gender
						}
					}
				}
			}
		}
		stress_and_fulfillment_impact = {
			content = minor_stress_impact_gain
			just = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = 0.5
				ai_greed = 0.5
			}
			modifier = {
				diplomacy < scope:target.stewardship_double_value
				factor = 0
			}
			modifier = {
				stewardship < scope:target.stewardship_double_value
				factor = 0
			}
		}
	}

 	# Refuse
	option = {
		name = gdp_merchant_trade_opportunity.1051.d
		reverse_add_opinion = {
			target = scope:target
			modifier = angry_opinion
			opinion = -10
		}
		house = {
			change_house_relation_effect = {
				HOUSE = scope:target.house
				VALUE = house_relation_damage_minor_value
				REASON = trade_opportunity_friction
				CHAR = root
				TARGET_CHAR = scope:target
				TITLE = scope:dummy_gender
			}
		}
		stress_and_fulfillment_impact = {
			craven = minor_stress_impact_gain
			fickle = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_rationality = -0.5
				ai_energy = -0.5
			}
			modifier = {
				OR = {
					has_trait = craven
					has_trait = fickle
				}
				factor = 0
			}
		}
	}
}

# Stretched Thin
gdp_merchant_trade_opportunity.1061 = {
	type = character_event
	title = gdp_merchant_trade_opportunity.1061.t
	desc = gdp_merchant_trade_opportunity.1061.desc
	theme = trade
	left_portrait = {
		character = root
		animation = worry
		camera = camera_event_left
	}
	right_portrait = {
		character = scope:associate
		animation = deliberation
	}
	# Scheme Preparations status bar
	widget = {
		gui = "event_window_widget_scheme"
		container = "custom_widgets_container"
	}

	trigger = {
		scope:scheme = { scheme_agent_charges > 1 }
		scope:task_contract ?= {
			NOT = { has_variable = had_event_gdp_merchant_trade_opportunity_1061 }
		}
	}

	immediate = {
		scope:task_contract ?= { set_variable = had_event_gdp_merchant_trade_opportunity_1061 }
		scope:associate ?= { add_stress = minor_stress_gain }
		scope:scheme ?= { change_opportunities = 1 }
	}

	option = { # I'll risk it for another advantage
		name = gdp_merchant_trade_opportunity.1061.a
		custom_tooltip = gdp_merchant_trade_opportunity.1061.already_tt
		duel = {
			skill = stewardship
			value = decent_skill_rating
			5 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				min = 10
				desc = gdp_merchant_trade_opportunity.1061.a.good
				send_interface_toast = {
					type = event_toast_effect_good
					title = gdp_merchant_trade_opportunity.1061.a.good
					left_icon = root
					right_icon = scope:associate
					custom_tooltip = {
						text = gdp_merchant_scheme_advantage_add_1_opportunity_tt
						scope:scheme = { change_opportunities = 1 }
					}
				}
			}
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				min = 10
				desc = gdp_merchant_trade_opportunity.1061.a.bad
				send_interface_toast = {
					type = event_toast_effect_bad
					title = gdp_merchant_trade_opportunity.1061.a.bad
					left_icon = root
					right_icon = scope:associate
					stress_and_fulfillment_impact = { base = minor_stress_impact_gain }
				}
			}
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = 1
			}
			modifier = {
				stewardship < high_skill_rating
				factor = 0
			}
		}
	}

	option = { # I'll take one advantage please
		name = gdp_merchant_trade_opportunity.1061.b
		custom_tooltip = gdp_merchant_trade_opportunity.1061.already_tt
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_energy = 1
			}
		}
	}
}

# Routes over capacity
gdp_merchant_trade_opportunity.1071 = {
	type = character_event
	title = gdp_merchant_trade_opportunity.1071.t
	desc = gdp_merchant_trade_opportunity.1071.desc
	theme = trade
	left_portrait = {
		character = root
		animation = reading
		camera = camera_event_very_left
	}
	right_portrait = {
		character = scope:associate
		animation = worry
		camera = camera_event_very_right
	}
	# Scheme Preparations status bar
	widget = {
		gui = "event_window_widget_scheme"
		container = "custom_widgets_container"
	}
	override_background = { reference = study }

	trigger = {
		any_trade_route = {
			any_trade_market_on_route = { this = scope:local_market }
		}
		NOT = {
			any_trade_route = {
				OR = {
					has_trade_route_modifier = diverted_trade_modifier
					has_trade_route_modifier = focused_trade_modifier
					has_trade_route_modifier = sidelined_trade_modifier
				}
			}
		}
		scope:scheme = { scheme_agent_charges > 1 }
		scope:task_contract ?= {
			NOT = { has_variable = had_event_gdp_merchant_trade_opportunity_1071 }
		}
		any_trade_route = { trader ?= scope:associate }
	}

	immediate = {
		scope:task_contract ?= { set_variable = had_event_gdp_merchant_trade_opportunity_1071 }
	}

	option = { # Trader focus
		name = gdp_merchant_trade_opportunity.1071.d
		scope:associate = {
			add_stress = minor_stress_loss
			add_character_modifier = {
				modifier = gdp_trader_undivided_focus_modifier
				years = 10
			}
		}
		reverse_add_opinion = {
			target = scope:associate
			modifier = pleased_opinion
			opinion = 15
		}
		stress_impact = {
			compassionate = minor_stress_impact_loss
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_compassion = 0.5
			}
		}
	}

	option = { # Scheme focus
		name = gdp_merchant_trade_opportunity.1071.a
		scope:scheme = { change_opportunities = 2 }
		reverse_add_opinion = {
			target = scope:associate
			modifier = annoyed_opinion
			opinion = -10
		}
		stress_and_fulfillment_impact = {
			ambitious = minor_stress_impact_loss
			impatient = minor_stress_impact_loss
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_energy = 0.5
			}
		}
	}
}

# Competent associate
gdp_merchant_trade_opportunity.1081 = {
	type = character_event
	title = gdp_merchant_trade_opportunity.1081.t
	desc = gdp_merchant_trade_opportunity.1081.desc
	theme = trade
	left_portrait = {
		character = root
		animation = admiration
	}
	right_portrait = {
		character = scope:associate
		animation = writing
	}
	# Scheme Preparations status bar
	widget = {
		gui = "event_window_widget_scheme"
		container = "custom_widgets_container"
	}

	trigger = {
		scope:associate ?= {
			is_available_quick = {
				alive = yes
				adult = yes
				imprisoned = no
				incapable = no
			}
			stewardship > medium_skill_rating 
		}
		scope:task_contract ?= {
			NOT = { has_variable = had_event_gdp_merchant_trade_opportunity_1081 }
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = {
				value = scope:associate.stewardship
				subtract = 10
				divide = 10
				round = yes
				max = 1
			}
		}
	}

	immediate = {
		scope:task_contract ?= { set_variable = had_event_gdp_merchant_trade_opportunity_1081 }
	}

	option = { # Encourage
		name = gdp_merchant_trade_opportunity.1081.a
		scope:scheme = { change_opportunities = 1 }
		stress_and_fulfillment_impact = {
			impatient = minor_stress_impact_loss
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_energy = 0.5
			}
		}
	}

	option = { # Reward
		name = gdp_merchant_trade_opportunity.1081.b
		pay_short_term_gold = {
			gold = minor_gold_value
			target = scope:associate
		}
		progress_towards_friend_effect = {
			REASON = friend_rewarded_associate
			CHARACTER = scope:associate
			OPINION = default_friend_opinion
		}
		apply_house_unity_interaction_effect = {
			CHARACTER = root
			TARGET = scope:associate
			DESC = merchant_unity_associate_rewarded_desc
			VALUE = minor_unity_gain
			VALUE_REVERSED = no
		}
		stress_and_fulfillment_impact = {
			greedy = minor_stress_impact_gain
			just = minor_stress_impact_loss
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_compassion = 0.5
			}
			modifier = {
				short_term_gold < medium_gold_value
				factor = 0
			}
		}
	}

	option = { # Example
		name = gdp_merchant_trade_opportunity.1081.c
		trigger = {
			custom_tooltip = {
				text = gdp_merchant_trade_opportunity.1081.c.trigger
				any_courtier = {
					is_available_quick = {
						adult = yes
						imprisoned = no
						incapable = no
					}
					stewardship < medium_skill_rating
					NOT = { this = scope:associate }
				}
			}
		}
		show_as_unavailable = { always = yes }
		random_courtier = {
			limit = {
				is_available_quick = {
					adult = yes
					imprisoned = no
					incapable = no
				}
				stewardship < medium_skill_rating
				NOT = { this = scope:associate }
			}
			weight = {
				base = 1
				modifier = {
					add = {
						value = 10
						subtract = stewardship 
						divide = 5
					}
				}
			}
			save_scope_as = learner
		}
		random = {
			chance = 25
			custom_tooltip = {
				text = gdp_merchant_trade_opportunity.1081.c.tt
				send_interface_toast = {
					type = event_toast_effect_good
					title = gdp_merchant_trade_opportunity.1081.c.title
					left_icon = scope:associate
					right_icon = scope:learner
					scope:learner = { add_stewardship_skill = 1 }
				}
			}
		}
		scope:associate = {
			stress_and_fulfillment_impact = {
				lazy = minor_stress_impact_gain
				shy = minor_stress_impact_gain
			}
		}
		stress_and_fulfillment_impact = {
			content = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_rationality = 0.5
			}
		}
	}

	option = { # Brag
		name = gdp_merchant_trade_opportunity.1081.d
		add_prestige = minor_prestige_gain
		stress_and_fulfillment_impact = {
			humble = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_boldness = 0.5
			}
		}
	}
}

# Incompetent associate
gdp_merchant_trade_opportunity.1091 = {
	type = character_event
	title = gdp_merchant_trade_opportunity.1091.t
	desc = gdp_merchant_trade_opportunity.1091.desc
	theme = trade
	left_portrait = {
		character = root
		animation = eyeroll
	}
	right_portrait = {
		character = scope:associate
		animation = deliberation
	}
	# Scheme Preparations status bar
	widget = {
		gui = "event_window_widget_scheme"
		container = "custom_widgets_container"
	}

	trigger = {
		scope:associate ?= { stewardship <= medium_skill_rating }
		scope:scheme = {
			scheme_agent_charges > 0
		}
		scope:task_contract ?= {
			NOT = { has_variable = had_event_gdp_merchant_trade_opportunity_1091 }
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = {
				value = 10
				subtract = scope:associate.stewardship
				divide = 10
				round = yes
				min = 0
			}
		}
	}

	immediate = {
		scope:task_contract ?= { set_variable = had_event_gdp_merchant_trade_opportunity_1091 }
	}

	option = { # Teach
		name = gdp_merchant_trade_opportunity.1091.b
		duel = {
			target = scope:associate
			skill = stewardship
			5 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 2.5
					min = -49
				}
				min = 10
				send_interface_toast = {
					type = event_toast_effect_good
					title = gdp_merchant_trade_opportunity.1091.b.good
					right_icon = scope:associate
					scope:associate = { add_stewardship_skill = 1 }
				}
			}
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -2.5
					min = -49
				}
				min = 10
				send_interface_toast = {
					type = event_toast_effect_bad
					title = gdp_merchant_trade_opportunity.1091.b.bad
					right_icon = scope:associate
					stress_and_fulfillment_impact = { base = minor_stress_impact_gain }
				}
			}
		}
		scope:associate = {
			stress_and_fulfillment_impact = {
				lazy = minor_stress_impact_gain
			}
		}
		stress_and_fulfillment_impact = {
			impatient = minor_stress_impact_gain
			lazy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			modifier = {
				ai_compassion = 0.5
			}
			modifier = {
				stewardship < scope:associate.stewardship_double_value
				factor = 0
			}
		}
	}

	option = { # Blame others
		name = gdp_merchant_trade_opportunity.1091.c
		scope:associate = {
			add_character_modifier = {
				modifier = associate_taking_assistance_modifier
				years = 10
			}
		}
		every_courtier = {
			custom = custom.every_other_associate
			limit = {
				is_adult = yes
				NOT = { this = scope:associate }
			}
			stress_and_fulfillment_impact = { base = minor_stress_impact_gain }
		}
		apply_house_unity_interaction_effect = {
			CHARACTER = root
			TARGET = scope:associate
			DESC = merchant_unity_associate_busywork_desc
			VALUE = minor_unity_loss
			VALUE_REVERSED = no
		}
		stress_and_fulfillment_impact = {
			just = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			modifier = {
				ai_honor = -0.5
			}
		}
	}

	option = { # Accept
		name = gdp_merchant_trade_opportunity.1091.d
		scope:scheme = { change_opportunities = -1 }
		stress_and_fulfillment_impact = {
			arbitrary = minor_stress_impact_gain
			wrathful = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			modifier = {
				ai_boldness = -0.5
			}
		}
	}
}

scripted_trigger gdp_merchant_trade_opportunity_1101_trigger = {
	is_available_quick = {
		ai = yes
		adult = yes
		imprisoned = no
		incapable = no
		in_army = no
	}
	health >= fine_health
	NOT = { this = root.suzerain }
	highest_held_title_tier < tier_duchy
	gold >= scope:investor_min_gold # root.gdp_seed_capital_investment_value, saved by the caller
	trigger_if = {
		limit = {
			is_landed = no
			is_theocratic_lessee = no
		}
		is_clergy = no
	}
	NOR = {
		government_has_flag = government_is_tribal
		# Knows better
		has_opinion_modifier = {
			target = root
			modifier = investor_scammer_opinion
		}
		any_close_family_member = {
			has_opinion_modifier = {
				target = root
				modifier = investor_scammer_opinion
			}
		}
		any_courtier = {
			has_opinion_modifier = {
				target = root
				modifier = investor_scammer_opinion
			}
		}
		any_relation = {
			type = lover
			type = friend
			has_opinion_modifier = {
				target = root
				modifier = investor_scammer_opinion
			}
		}
		liege ?= {
			has_opinion_modifier = {
				target = root
				modifier = investor_scammer_opinion
			}
		}
		employer ?= {
			has_opinion_modifier = {
				target = root
				modifier = investor_scammer_opinion
			}
		}
		any_vassal = {
			has_opinion_modifier = {
				target = root
				modifier = investor_scammer_opinion
			}
		}
	}
}

scripted_effect gdp_merchant_trade_opportunity_1101_investment_effect = {
	scope:investor = {
		pay_short_term_gold = {
			gold = scope:investment
			target = root
		}
	}
	save_scope_value_as = {
		name = interest
		value = {
			value = scope:investment
			multiply = 1.2
		}
	}
	custom_tooltip = gdp_merchant_trade_opportunity_1101_calling_tt
	trigger_event = {
		id = gdp_merchant_trade_opportunity.1102
		years = 5
	}
}

# A wild investor appears
gdp_merchant_trade_opportunity.1101 = {
	type = character_event
	title = gdp_merchant_trade_opportunity.1101.t
	desc = {
		desc = gdp_merchant_trade_opportunity.1101.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:investor = { government_has_flag = government_is_landless_adventurer }
				}
				desc = gdp_merchant_trade_opportunity.1101.adventurer
			}
			triggered_desc = {
				trigger = {
					scope:investor = { is_ruler = yes }
				}
				desc = gdp_merchant_trade_opportunity.1101.ruler
			}
			triggered_desc = {
				trigger = { exists = scope:investor.liege }
				desc = gdp_merchant_trade_opportunity.1101.courtier
			}
			desc = gdp_merchant_trade_opportunity.1101.fallback
		}
		desc = gdp_merchant_trade_opportunity.1101.end
	}
	theme = trade
	left_portrait = {
		character = root
		animation = interested
	}
	right_portrait = {
		character = scope:investor
		animation = admiration
		camera = camera_event_very_right
	}
	# Scheme Preparations status bar
	widget = {
		gui = "event_window_widget_scheme"
		container = "custom_widgets_container"
	}

	trigger = {
		scope:task_contract ?= {
			NOT = { has_variable = had_event_gdp_merchant_trade_opportunity_1101 }
		}
		NOR = {
			has_character_flag = investor_scammer_cooldown
			scope:task_contract = { has_task_contract_type = seek_debtors }
		}
		save_temporary_scope_value_as = {
			name = investor_min_gold
			value = gdp_seed_capital_investment_value
		}
		scope:task_contract_location.duchy = {
			any_in_de_jure_hierarchy = {
				OR = {
					holder ?= { gdp_merchant_trade_opportunity_1101_trigger = yes }
					lessee ?= { gdp_merchant_trade_opportunity_1101_trigger = yes }
					title_province ?= {
						any_province_domicile = {
							is_domicile_type = camp
							owner = { gdp_merchant_trade_opportunity_1101_trigger = yes }
						}
						any_pool_character = {
							province = scope:task_contract_location
							gdp_merchant_trade_opportunity_1101_trigger = yes
						}
					}
				}
			}
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			factor = 0.2
			has_character_modifier = investor_scammer_modifier
		}
	}

	immediate = {
		scope:task_contract ?= { set_variable = had_event_gdp_merchant_trade_opportunity_1101 }
		primary_title = { save_scope_as = company }
		save_scope_as = trader
		save_temporary_scope_value_as = {
			name = investor_min_gold
			value = gdp_seed_capital_investment_value
		}
		scope:task_contract_location.duchy = {
			every_in_de_jure_hierarchy = {
				holder ?= {
					# A holder of several titles in the hierarchy only needs their court checked once
					if = {
						limit = {
							NOT = { is_in_list = investor_courts_checked }
						}
						add_to_temporary_list = investor_courts_checked
						if = {
							limit = { gdp_merchant_trade_opportunity_1101_trigger = yes }
							add_to_list = investors
						}
						every_courtier = {
							limit = { gdp_merchant_trade_opportunity_1101_trigger = yes }
							add_to_list = investors
						}
					}
				}
				lessee ?= {
					if = {
						limit = { gdp_merchant_trade_opportunity_1101_trigger = yes }
						add_to_list = investors
					}
				}
				title_province ?= {
					every_province_domicile = {
						limit = {
							is_domicile_type = camp
							owner = { gdp_merchant_trade_opportunity_1101_trigger = yes }
						}
						add_to_list = investors
					}
					every_pool_character = {
						province = scope:task_contract_location
						limit = { gdp_merchant_trade_opportunity_1101_trigger = yes }
						add_to_list = investors
					}
				}
			}
		}
		random_in_list = {
			list = investors
			weight = {
				base = 1
				modifier = {
					add = {
						value = gold
						divide = root.minor_gold_value
						min = 0
					}
				}
				is_of_minor_interest_to_weight_up_modifier = { CHARACTER = root }
				is_of_major_interest_to_weight_up_modifier = { CHARACTER = root }
				modifier = {
					factor = 4
					highest_held_title_tier >= tier_county
				}
				modifier = {
					factor = 2
					highest_held_title_tier >= tier_county
				}
			}
			save_scope_as = investor
		}
	}

	option = { # Accept
		name = gdp_merchant_trade_opportunity.1101.a
		save_scope_value_as = {
			name = investment
			value = gdp_seed_capital_investment_value
		}
		gdp_merchant_trade_opportunity_1101_investment_effect = yes
		ai_chance = {
			base = 10
			modifier = {
				ai_honor = 0.25
				ai_energy = 0.25
			}
			modifier = {
				short_term_gold < medium_gold_value
				add = 10
			}
		}
	}

	option = { # Request more for hook
		name = gdp_merchant_trade_opportunity.1101.c
		trigger = {
			scope:investor = { gold >= root.gdp_seed_capital_investment_hook_value }
		}
		save_scope_value_as = {
			name = investment
			value = gdp_seed_capital_investment_hook_value
		}
		scope:investor = {
			add_hook = {
				type = favor_hook
				target = root
			}
		}
		gdp_merchant_trade_opportunity_1101_investment_effect = yes
		stress_and_fulfillment_impact = {
			ambitious = minor_stress_impact_loss
		}
		ai_chance = {
			base = 10
			modifier = {
				ai_honor = 0.25
				ai_rationality = 0.25
			}
		}
	}

	option = { # Refuse
		name = gdp_merchant_trade_opportunity.1101.d
		reverse_add_opinion = {
			target = scope:investor
			modifier = offended_opinion 
			opinion = -10
		}
		stress_and_fulfillment_impact = {
			stubborn = minor_stress_impact_loss
		}
		ai_chance = {
			base = 10
			modifier = {
				short_term_gold < minor_gold_value
				factor = 0.5
			}
		}
	}
}

gdp_merchant_trade_opportunity.1102 = {
	type = letter_event
	opening = gdp_merchant_trade_opportunity.1102.opening
	desc = gdp_merchant_trade_opportunity.1102.desc
	sender = {
		character = scope:investor
		animation = interested
	}

	trigger = {
		scope:investor ?= {
			is_available_quick = {
				ai = yes
				adult = yes
				alive = yes
				imprisoned = no
				incapable = no
			}
		}
		exists = scope:company.holder
		scope:trader ?= scope:company.holder
	}

	on_trigger_fail = {
		scope:company.holder ?= { save_scope_as = trader }
		if = {
			limit = { exists = scope:trader }
			scope:investor ?= {
				if = {
					limit = {
						scope:investor = {
							is_available_quick = {
								ai = yes
								adult = yes
								alive = yes
								incapable = no
							}
						}
					}
					scope:trader = {
						trigger_event = {
							id = gdp_merchant_trade_opportunity.1102
							months = 1
						}
					}
				}
				else_if = {
					limit = {
						any_child = {
							is_available_quick = {
								ai = yes
								adult = yes
								alive = yes
								incapable = no
							}
						}
					}
					random_child = {
						limit = {
							is_available_quick = {
								ai = yes
								adult = yes
								alive = yes
								incapable = no
							}
						}
						save_scope_as = investor
					}
					scope:trader = {
						trigger_event = {
							id = gdp_merchant_trade_opportunity.1102
							days = 1
						}
					}
				}
			}
		}
	}

	option = { # Pay up
		name = gdp_merchant_trade_opportunity.1102.a
		add_prestige = minor_prestige_gain
		reverse_add_opinion = {
			modifier = pleased_opinion
			target = scope:investor
			opinion = 15
		}
		pay_short_term_gold = {
			gold = {
				value = scope:investment
				multiply = 1.2
			}
			target = scope:investor
		}
		stress_and_fulfillment_impact = {
			deceitful = minor_stress_impact_gain
			arbitrary = minor_stress_impact_gain
			greedy = minor_stress_impact_gain
			honest = minor_stress_impact_loss
			just = minor_stress_impact_loss
		}
		ai_chance = {
			base = 10
			modifier = {
				ai_honor = 0.25
				ai_greed = -0.25
			}
			modifier = {
				short_term_gold < scope:investment
				factor = 0.5
			}
			modifier = {
				short_term_gold < major_gold_value
				factor = 0.5
			}
		}
	}

	option = { # Lie
		name = gdp_merchant_trade_opportunity.1102.b
		trigger = {
			NOT = { 
				scope:investor = { has_hook = root }
			}
		}
		pay_short_term_gold = {
			gold = {
				value = scope:investment
				multiply = 0.5
			}
			target = scope:investor
		}
		duel = {
			skill = intrigue
			target = scope:investor
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				min = 10
				desc = gdp_merchant_trade_opportunity.1102.b.good
				send_interface_toast = {
					type = event_toast_effect_good
					title = gdp_merchant_trade_opportunity.1102.b.good
					right_icon = scope:investor
					reverse_add_opinion = {
						target = scope:investor
						modifier = disappointed_opinion 
						opinion = -10
					}
				}
			}
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				min = 10
				desc = gdp_merchant_trade_opportunity.1102.b.bad
				send_interface_toast = {
					type = event_toast_effect_bad
					title = gdp_merchant_trade_opportunity.1102.b.bad
					right_icon = scope:investor
					add_prestige = minor_prestige_loss
					reverse_add_opinion = {
						modifier = angry_opinion
						target = scope:investor
						opinion = -25
					}
				}
			}
		}
		stress_and_fulfillment_impact = {
			honest = medium_stress_impact_gain
			generous = medium_stress_impact_gain
			just = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			modifier = {
				ai_honor = -0.25
				ai_greed = 0.25
			}
			modifier = {
				short_term_gold < scope:investment
				factor = 1.25
			}
			modifier = {
				short_term_gold < major_gold_value
				factor = 1.25
			}
		}
	}

	option = { # Refuse
		name = gdp_merchant_trade_opportunity.1102.d
		trigger = {
			NOT = { 
				scope:investor = { has_hook = root }
			}
		}
		add_prestige = medium_prestige_loss
		progress_towards_rival_effect = {
			REASON = rival_investor_scammer
			CHARACTER = scope:investor
			OPINION = 0
		}
		add_character_modifier = {
			modifier = investor_scammer_modifier
			years = 25
		}
		reverse_add_opinion = {
			modifier = investor_scammer_opinion
			target = scope:investor
		}
		add_character_flag = {
			flag = investor_scammer_cooldown
			years = 5
		}
		stress_and_fulfillment_impact = {
			craven = minor_stress_impact_gain
			just = medium_stress_impact_gain
		}
		ai_chance = {
			base = 10
			modifier = {
				ai_rationality = -0.25
				ai_honor = -0.25
			}
			modifier = {
				short_term_gold < scope:investment
				factor = 1.25
			}
			modifier = {
				short_term_gold < major_gold_value
				factor = 1.25
			}
		}
	}
}

# Piggy back
gdp_merchant_trade_opportunity.9000 = {
	type = character_event
	title = gdp_merchant_trade_opportunity.9000.t
	desc = gdp_merchant_trade_opportunity.9000.desc
	theme = trade
	left_portrait = {
		character = root
		animation = pondering
	}

	trigger = { is_ai = no }

	on_trigger_fail = {
		current_travel_plan ?= {
			if = {
				limit = { is_paused = yes }
				resume_travel_plan = yes
			}
		}
	}

	immediate = {
		hidden_effect = {
			current_travel_plan ?= {
				if = {
					limit = { is_paused = no }
					pause_travel_plan = yes
				}
			}
		}
		every_available_task_contract = {
			limit = {
				has_task_contract_group = merchant_trade_opportunity_group
				task_contract_location = root.location
				NOT = { this = scope:task_contract }
				root = { can_accept_task_contract = prev }
			}
			add_to_list = potential_contracts
		}
		ordered_in_list = {
			list = potential_contracts
			order_by = task_contract_tier
			max = 3
			check_range_bounds = no
			if = {
				limit = { exists = scope:contract_2 }
				save_scope_as = contract_3
			}
			else_if = {
				limit = { exists = scope:contract_1 }
				save_scope_as = contract_2
			}
			else = { save_scope_as = contract_1 }
		}
	}

	option = {
		name = gdp_merchant_trade_opportunity.9000.a
		trigger = {
			exists = scope:contract_1
			can_accept_task_contract = scope:contract_1
		}
		hidden_effect = { accept_task_contract = scope:contract_1 }
		scope:contract_1 = { custom_tooltip = gdp_merchant_trade_opportunity.9000.accept_tt }
		show_as_tooltip = {
			current_travel_plan ?= { pause_travel_plan = yes }
		}
	}

	option = {
		name = gdp_merchant_trade_opportunity.9000.b
		trigger = {
			exists = scope:contract_2
			can_accept_task_contract = scope:contract_2
		}
		hidden_effect = { accept_task_contract = scope:contract_2 }
		scope:contract_2 = { custom_tooltip = gdp_merchant_trade_opportunity.9000.accept_tt }
		show_as_tooltip = {
			current_travel_plan ?= { pause_travel_plan = yes }
		}
	}

	option = {
		name = gdp_merchant_trade_opportunity.9000.c
		trigger = {
			exists = scope:contract_3
			can_accept_task_contract = scope:contract_3
		}
		hidden_effect = { accept_task_contract = scope:contract_3 }
		scope:contract_3 = { custom_tooltip = gdp_merchant_trade_opportunity.9000.accept_tt }
		show_as_tooltip = {
			current_travel_plan ?= { pause_travel_plan = yes }
		}
	}

	option = {
		name = gdp_merchant_trade_opportunity.9000.d
		current_travel_plan ?= {
			if = {
				limit = { is_paused = yes }
				resume_travel_plan = yes
			}
		}
	}
}

scripted_effect trade_opportunity_assign_partner_effect = {
	save_scope_as = partner
	custom_tooltip = gdp_merchant_trade_opportunity.9010.tt.partner_assign
	custom_tooltip = gdp_merchant_trade_opportunity.9010.tt.partner_away
	custom_tooltip = gdp_merchant_trade_opportunity.9010.tt.partner_outcome
	custom_tooltip = gdp_merchant_trade_opportunity.9010.tt.partner_valid
	set_variable = {
		name = partner_contract
		value = scope:task_contract
		months = 9 # max duration is 8
	}
	scope:task_contract = {
		task_contract_location = { save_scope_as = task_contract_location }
		set_variable = {
			name = contract_partner
			value = scope:partner
		}
		task_contract_taker = {
			house = {
				add_unity_value = {
					value = minor_unity_value
					character = scope:task_contract.var:contract_partner
					desc = unity_trade_opportunity_partner_assigned_desc
				}
			}
			trigger_event = {
				id = gdp_merchant_trade_opportunity.9022
				months = { 4 8 }
			}
			hidden_effect = {
				send_interface_toast = {
					type = event_trade_neutral
					title = trade_opportunity_assign_partner_title
					right_icon = scope:partner
					scope:partner ?= {
						set_location = scope:task_contract.task_contract_location
						custom_tooltip = gdp_merchant_trade_opportunity.9010.tt.partner_assigned
					}
				}
			}
		}
	}
}

#	Travel/partner opening.
gdp_merchant_trade_opportunity.9010 = {
	type = character_event
	title = gdp_merchant_trade_opportunity.9010.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:task_contract_location = location }
				desc = gdp_merchant_trade_opportunity.9010.intro
			}
			desc = gdp_merchant_trade_opportunity.9010.intro_elsewhere
		}
		desc = gdp_merchant_trade_opportunity.9010.desc
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:partner_busy }
				desc = gdp_merchant_trade_opportunity.9010.partner_busy
			}
			triggered_desc = {
				trigger = { exists = scope:partner }
				desc = gdp_merchant_trade_opportunity.9010.partner
			}
			triggered_desc = {
				trigger = { exists = scope:candidate }
				desc = gdp_merchant_trade_opportunity.9010.candidate
			}
			desc = gdp_merchant_trade_opportunity.9010.no_partner
		}
	}
	theme = trade
	left_portrait = {
		character = root
		animation = war_over_tie
	}
	right_portrait = {
		trigger = {
			NOT = { exists = scope:partner_busy }
		}
		character = scope:partner
		animation = writing
	}
	lower_left_portrait = scope:partner_busy
	lower_right_portrait = scope:candidate
	override_background = { reference = study }

	trigger = {
		trigger_if = {
			limit = { is_travelling = yes }
			is_ai = no
			scope:task_contract_location != location
		}
	}

	on_trigger_fail = {
		trigger_event = { on_action = trade_opportunity_arrival_events }
	}

	immediate = {
		if = {
			limit = { is_travelling = yes }
			scope:task_contract = { set_variable = accepted_while_traveling_elsewhere }
		}
		court_position:partner_court_position ?= {
			save_scope_as = partner
			if = {
				limit = {
					OR = {
						merchant_trade_opportunity_partner_available_trigger = no
						root = { merchant_trade_opportunity_partner_send_blocked_trigger = yes }
					}
				}
				save_scope_as = partner_busy
			}
		}
		if = {
			limit = {
				NOT = { exists = scope:partner }
				can_employ_court_position_type = partner_court_position
			}
			ordered_courtier = {
				limit = {
					would_be_valid_for_court_position = {
						employer = root
						court_position = partner_court_position
					}
					merchant_trade_opportunity_partner_available_trigger = yes
				}
				order_by = "aptitude(partner_court_position)"
				save_scope_as = candidate
			}
			if = {
				limit = {
					NOT = { exists = scope:candidate }
				}
				ordered_courtier = {
					limit = {
						would_be_valid_for_court_position = {
							employer = root
							court_position = partner_court_position
						}
						merchant_trade_opportunity_partner_candidate_available_trigger = { TAKER = root }
					}
					order_by = "aptitude(partner_court_position)"
					save_scope_as = candidate
				}
			}
		}
	}

	option = { # Travel to take
		name = gdp_merchant_trade_opportunity.9010.a
		trigger = {
			scope:task_contract_location != location
			is_travelling = no
			custom_tooltip = {
				text = has_active_merchant_contract
				any_character_active_contract = {
					count = 0
					NOR = {
						this = scope:task_contract
						exists = var:contract_partner
					}
				}
			}
		}
		show_as_unavailable = { scope:task_contract_location != location }
		custom_tooltip = gdp_merchant_trade_opportunity.9010.tt.destination_list
		start_travel_plan = {
			destination = scope:task_contract_location
			on_arrival_event = gdp_merchant_trade_opportunity.9012
			travel_with_domicile = no
			return_trip = yes
			can_cancel_planning = no
			on_travel_planner_cancel_event = gdp_merchant_trade_opportunity.9011
			players_use_planner = yes
			on_arrival_destinations = all_but_last
		}
		stress_impact = {
			lazy = miniscule_stress_impact_gain
		}
		ai_chance = { base = 100 }
	}

	option = { # Take here
		name = gdp_merchant_trade_opportunity.9010.a
		trigger = {
			scope:task_contract_location = location
			custom_tooltip = {
				text = has_active_merchant_contract
				any_character_active_contract = {
					count = 0
					NOR = {
						this = scope:task_contract
						exists = var:contract_partner
					}
				}
			}
		}
		show_as_unavailable = { scope:task_contract_location = location }
		custom_tooltip = gdp_merchant_trade_opportunity.9010.tt.start
		trigger_event = { on_action = trade_opportunity_arrival_events }
		stress_impact = {
			lazy = miniscule_stress_impact_gain
		}
		ai_chance = { base = 100 }
	}

	option = { # Partner
		name = {
			text = {
				first_valid = {
					triggered_desc = {
						trigger = {
							NOT = { exists = scope:partner }
						}
						desc = gdp_merchant_trade_opportunity.9010.c.no_partner
					}
					desc = gdp_merchant_trade_opportunity.9010.c
				}
			}
		}
		trigger = {
			trigger_if = {
				limit = { exists = scope:partner }
				scope:partner = { merchant_trade_opportunity_partner_available_trigger = yes }
				custom_tooltip = {
					text = gdp_merchant_trade_opportunity.9010.c.involved_other.tt
					NOT = { merchant_trade_opportunity_partner_send_blocked_trigger = yes }
				}
			}
			trigger_else = { employs_court_position = partner_court_position }
		}
		reason = have_partner
		scope:partner ?= { trade_opportunity_assign_partner_effect = yes }
		stress_impact = {
			diligent = miniscule_stress_impact_gain
		}
		ai_chance = { base = 0 }
	}

	option = { # Candidate
		name = {
			text = {
				first_valid = {
					triggered_desc = {
						trigger = { exists = scope:candidate }
						desc = gdp_merchant_trade_opportunity.9010.d
					}
					desc = gdp_merchant_trade_opportunity.9010.d.no_candidate
				}
			}
		}
		trigger = {
			custom_tooltip = {
				text = gdp_merchant_trade_opportunity.9010.d.tt
				exists = scope:candidate
			}
			custom_tooltip = {
				text = gdp_merchant_trade_opportunity.9010.c.involved_other.tt
				NOT = { merchant_trade_opportunity_partner_send_blocked_trigger = yes }
			}
		}
		show_as_unavailable = {
			NOT = { exists = scope:partner }
		}
		if = {
			limit = {
				scope:candidate = { merchant_trade_opportunity_partner_in_entourage_trigger = { TAKER = root } }
			}
			current_travel_plan = { remove_character = scope:candidate }
		}
		appoint_court_position = {
			recipient = scope:candidate
			court_position = partner_court_position
		}
		scope:candidate = {
			add_opinion = {
				opinion = 15
				target = root
				modifier = grateful_opinion
			}
			trade_opportunity_assign_partner_effect = yes
		}
		stress_impact = {
			diligent = miniscule_stress_impact_gain
		}
		ai_chance = { base = 0 }
	}

	option = { # Forget it
		name = gdp_merchant_trade_opportunity.9010.e
		custom_tooltip = gdp_merchant_trade_opportunity.9010.e.tt
		scope:task_contract = { complete_task_contract = failure_standard }
		stress_impact = {
			diligent = miniscule_stress_impact_gain
		}
		ai_chance = { base = 0 }
	}
}

#	Travel invalidation event.
gdp_merchant_trade_opportunity.9011 = {
	hidden = yes

	trigger = { is_alive = yes }

	immediate = {
		random_character_active_contract = { save_scope_as = task_contract }
		send_interface_message = {
			title = contract_invalidated_title
			type = stewardship_contract_scheme_invalidated_message
			desc = contract_invalidated_desc
			right_icon = scope:task_contract.task_contract_employer
			scope:task_contract = { complete_task_contract = failure_standard }
		}
	}
}

#	Travel setup event.
gdp_merchant_trade_opportunity.9012 = {
	type = character_event
	hidden = yes

	immediate = {
		if = {
			limit = {
				has_character_flag = gdp_trade_opportunity_visit_holding_on_arrival
			}
			remove_character_flag = gdp_trade_opportunity_visit_holding_on_arrival
			temporarily_lock_visit_holding_effect = yes
			trigger_event = gdp_visit_holding_decision_event.1000
		}
		else = {
			trigger_event = {
				on_action = trade_opportunity_arrival_events
			}
		}
	}
}

gdp_merchant_trade_opportunity.9050 = {
	type = character_event
	title = gdp_merchant_trade_opportunity.9050.t
	desc = {
		desc = gdp_merchant_trade_opportunity.9050.desc_opening
		first_valid = {
			triggered_desc = {
				trigger = { scope:task_contract.var:trade_opportunity_lost_reason ?= flag:route_destroyed }
				desc = gdp_merchant_trade_opportunity.9050.reason_route_destroyed
			}
			triggered_desc = {
				trigger = { scope:task_contract.var:trade_opportunity_lost_reason ?= flag:market_left_route }
				desc = gdp_merchant_trade_opportunity.9050.reason_market_left_route
			}
			triggered_desc = {
				trigger = { scope:task_contract.var:trade_opportunity_lost_reason ?= flag:trader_changed }
				desc = gdp_merchant_trade_opportunity.9050.reason_trader_changed
			}
			triggered_desc = {
				trigger = { scope:task_contract.var:trade_opportunity_lost_reason ?= flag:upheaval_ended }
				desc = gdp_merchant_trade_opportunity.9050.reason_upheaval_ended
			}
			triggered_desc = {
				trigger = { scope:task_contract.var:trade_opportunity_lost_reason ?= flag:purpose_artisan }
				desc = gdp_merchant_trade_opportunity.9050.reason_purpose_artisan
			}
			triggered_desc = {
				trigger = { scope:task_contract.var:trade_opportunity_lost_reason ?= flag:purpose_creditor }
				desc = gdp_merchant_trade_opportunity.9050.reason_purpose_creditor
			}
			triggered_desc = {
				trigger = { scope:task_contract.var:trade_opportunity_lost_reason ?= flag:competitor_gone }
				desc = gdp_merchant_trade_opportunity.9050.reason_competitor_gone
			}
			triggered_desc = {
				trigger = { scope:task_contract.var:trade_opportunity_lost_reason ?= flag:entrepot_gone }
				desc = gdp_merchant_trade_opportunity.9050.reason_entrepot_gone
			}
			triggered_desc = {
				trigger = { scope:task_contract.var:trade_opportunity_lost_reason ?= flag:tolls_ended }
				desc = gdp_merchant_trade_opportunity.9050.reason_tolls_ended
			}
			triggered_desc = {
				trigger = { scope:task_contract.var:trade_opportunity_lost_reason ?= flag:silk_road }
				desc = gdp_merchant_trade_opportunity.9050.reason_silk_road
			}
			desc = gdp_merchant_trade_opportunity.9050.reason_unknown
		}
		desc = gdp_merchant_trade_opportunity.9050.desc_closing
	}
	theme = trade
	left_portrait = {
		character = root
		animation = disappointed
	}
	override_background = { reference = terrain }

	# Give up on the venture and head home.
	option = {
		name = gdp_merchant_trade_opportunity.9050.a
		
		return_home = yes
		
		ai_chance = {
			base = 100
		}
	}

	# Carry on to the destination anyway and visit the local holding on arrival.
	option = {
		name = gdp_merchant_trade_opportunity.9050.b
		
		custom_tooltip = gdp_merchant_trade_opportunity.9050.b.tt
		add_character_flag = gdp_trade_opportunity_visit_holding_on_arrival
		
		ai_chance = {
			base = 0
		}
	}
}

#	Partner outcome.
gdp_merchant_trade_opportunity.9020 = {
	type = character_event
	title = gdp_merchant_trade_opportunity.9020.t
	desc = {
		desc = gdp_merchant_trade_opportunity.9020.intro
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:contract_success }
				desc = gdp_merchant_trade_opportunity.9020.success
			}
			desc = gdp_merchant_trade_opportunity.9020.failure
		}
	}
	theme = trade
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = { exists = scope:contract_success }
			animation = war_over_tie
		}
		animation = disappointed
	}
	right_portrait = {
		character = scope:partner
		triggered_animation = {
			trigger = { exists = scope:contract_success }
			animation = admiration
		}
		animation = stress
	}
	override_background = { reference = study }

	immediate = {
		if = {
			limit = { exists = scope:contract_success }
			scope:task_contract = { complete_task_contract = success_standard }
			# Add Trait XP to Partner
			if = {
				limit = {
					NOT = { has_trait = lifestyle_merchant }
				}
				add_trait = lifestyle_merchant
			}
			else_if = {
				limit = {
					scope:task_contract = { has_task_contract_type = support_guilds }
				}
				add_trait_xp = {
					trait = lifestyle_merchant
					track = artisan
					value = lifestyle_merchant_xp_gain_minor_value
				}
			}
			else_if = {
				limit = {
					scope:task_contract = { has_task_contract_type = seek_debtors }
				}
				add_trait_xp = {
					trait = lifestyle_merchant
					track = creditor
					value = lifestyle_merchant_xp_gain_minor_value
				}
				merchant_creditor_capstone_prestige_effect = yes
			}
		}
		else = {
			scope:task_contract = { complete_task_contract = failure_standard }
		}
	}

	option = { # Ok
		name = {
			text = {
				first_valid = {
					triggered_desc = {
						trigger = { exists = scope:contract_success }
						desc = gdp_merchant_trade_opportunity.9020.a.success
					}
					desc = gdp_merchant_trade_opportunity.9020.a.failure
				}
			}
		}
	}
}

#	Partner invalidation.
gdp_merchant_trade_opportunity.9021 = {
	type = character_event
	hidden = yes

	immediate = {
		send_interface_toast = {
			type = event_toast_text_and_effect_bad
			title = trade_opportunity_invalidated_title
			desc = trade_opportunity_invalidated_desc
			left_icon = scope:partner
			right_icon = scope:task_contract.task_contract_employer
			scope:task_contract = { complete_task_contract = failure_standard }
		}
	}
}

#	Partner outcome setup.
gdp_merchant_trade_opportunity.9022 = {
	type = character_event
	hidden = yes

	trigger = {
		any_character_active_contract = {
			var:contract_partner ?= {
				this = scope:partner
				has_court_position = partner_court_position
				liege = root
				is_available_quick = {
					imprisoned = no
					incapable = no
				}
			}
		}
	}

	immediate = {
		scope:partner = {
			random_list = {
				10 = {
					modifier = {
						"aptitude(partner_court_position)" >= 3
						add = 5
					}
					modifier = {
						"aptitude(partner_court_position)" >= 4
						add = 5
					}
					save_scope_as = contract_success
				}
				10 = {
					modifier = {
						"aptitude(partner_court_position)" <= 0
						add = 5
					}
					modifier = {
						"aptitude(partner_court_position)" <= 1
						add = 5
					}
				}
			}
		}
		trigger_event = gdp_merchant_trade_opportunity.9020
	}
}
