﻿namespace = gdp_visit_holding_decision_event

scripted_effect gdp_1200_create_fallback_negotiator_effect = {
	if = {
		limit = {
			scope:patron ?= {
				faith_dominant_gender_female_or_equal = yes
				faith_dominant_gender_male_or_equal = no
			}
		}
		create_character = {
			template = pool_repopulate_stewardship
			gender_female_chance = 100
			culture = scope:patron.culture
			faith = scope:patron.faith
			dynasty = none
			location = scope:patron.location
			save_scope_as = negotiator
			after_creation = { add_character_flag = gdp_1200_temp_negotiator }
		}
	}
	else_if = {
		limit = {
			scope:patron ?= {
				faith_dominant_gender_male_or_equal = yes
				faith_dominant_gender_female_or_equal = no
			}
		}
		create_character = {
			template = pool_repopulate_stewardship
			gender_female_chance = 0
			culture = scope:patron.culture
			faith = scope:patron.faith
			dynasty = none
			location = scope:patron.location
			save_scope_as = negotiator
			after_creation = { add_character_flag = gdp_1200_temp_negotiator }
		}
	}
	else = {
		create_character = {
			template = pool_repopulate_stewardship
			gender_female_chance = 50
			culture = scope:patron.culture
			faith = scope:patron.faith
			dynasty = none
			location = scope:patron.location
			save_scope_as = negotiator
			after_creation = { add_character_flag = gdp_1200_temp_negotiator }
		}
	}
}

#Supply duel for your highest skill stat
scripted_effect gdp_1200_highest_skill_duel_effect_a = {
	if = {
		limit = { highest_skill_including_prowess = diplomacy }
		gdp_1200_duel_effect_a = { SKILL = diplomacy }
	}
	else_if = {
		limit = { highest_skill_including_prowess = stewardship }
		gdp_1200_duel_effect_a = { SKILL = stewardship }
	}
	else_if = {
		limit = { highest_skill_including_prowess = intrigue }
		gdp_1200_duel_effect_a = { SKILL = intrigue }
	}
	else_if = {
		limit = { highest_skill_including_prowess = learning }
		gdp_1200_duel_effect_a = { SKILL = learning }
	}
	else_if = {
		limit = { highest_skill_including_prowess = martial }
		gdp_1200_duel_effect_a = { SKILL = martial }
	}
	else = {
		gdp_1200_duel_effect_a = { SKILL = prowess }
	}
}

scripted_effect gdp_1200_highest_skill_duel_effect_b = {
	if = {
		limit = { highest_skill_including_prowess = diplomacy }
		gdp_1200_duel_effect_b = { SKILL = diplomacy }
	}
	else_if = {
		limit = { highest_skill_including_prowess = stewardship }
		gdp_1200_duel_effect_b = { SKILL = stewardship }
	}
	else_if = {
		limit = { highest_skill_including_prowess = intrigue }
		gdp_1200_duel_effect_b = { SKILL = intrigue }
	}
	else_if = {
		limit = { highest_skill_including_prowess = learning }
		gdp_1200_duel_effect_b = { SKILL = learning }
	}
	else_if = {
		limit = { highest_skill_including_prowess = martial }
		gdp_1200_duel_effect_b = { SKILL = martial }
	}
	else = {
		gdp_1200_duel_effect_b = { SKILL = prowess }
	}
}

#Actual patron duel effect
scripted_effect gdp_1200_duel_effect_a = {
	duel = {
		skill = $SKILL$
		target = scope:negotiator
		#Success: Get what you wanted
		50 = {
			compare_modifier = {
				value = scope:duel_value
				multiplier = 3.5
				min = -49
			}
			desc = gdp_visit_holding_decision_event.1200.a_$SKILL$.success
			send_interface_toast = {
				title = gdp_visit_holding_decision_event.1200.a_$SKILL$.success
				left_icon = root
				right_icon = scope:negotiator
				add_character_modifier = {
					modifier = gdp_patron_competitiveness_modifier
					years = 5
				}
				#Cooldown
				set_variable = {
					name = 1200_patron_competitiveness
					value = flag:success
					days = visit_holding_cooldown_days
				}
				visit_holding_refresh_patron_area_tracker_effect = yes
				trigger_event = gdp_visit_holding_decision_event.1200
			}
		}
		#Failure: you get nothing/get a worse deal, patron/steward gets mad
		45 = {
			compare_modifier = {
				value = scope:duel_value
				multiplier = -3.5
				min = -20
			}	
			desc = gdp_visit_holding_decision_event.1200.a_$SKILL$.failure
			send_interface_toast = {
				title = gdp_visit_holding_decision_event.1200.a_$SKILL$.failure
				left_icon = root
				right_icon = scope:negotiator
				visit_holding_set_option_cooldown_patron_effect = { VAR = 1200_patron_competitiveness }
				# they get mad
				progress_towards_rival_effect = {
					REASON = rival_merchant_asked_too_much
					CHARACTER = scope:negotiator
					OPINION = default_rival_opinion
				}
				#Go back to the main event
				trigger_event = gdp_visit_holding_decision_event.1200
			}
		}
		#Critical Failure: The local guards are summoned
		5 = {
			trigger = {
				root = {
					OR = {
						highest_skill = martial 
						highest_skill_including_prowess = prowess
					}
				}			
			}
			compare_modifier = {
				value = scope:duel_value
				multiplier = -3.5
			}	
			min = 5
			desc = gdp_visit_holding_decision_event.1200.a_$SKILL$.critical_failure
			send_interface_toast = {
				title = gdp_visit_holding_decision_event.1200.a_$SKILL$.critical_failure
				left_icon = root
				right_icon = scope:negotiator
				#Set up the cooldown for the convince-ction
				visit_holding_set_option_cooldown_patron_effect = { VAR = 1200_patron_competitiveness }
				#Quite the tussle
				increase_wounds_effect = { REASON = fight }
				#This patron doesn't want to see you again
				progress_towards_rival_effect = {
					REASON = rival_merchant_tried_to_intimidate
					CHARACTER = scope:negotiator
					OPINION = default_rival_opinion
				}
				#And you will not be going back to this patron for a while, but feel free to look at the greyed out option
				visit_holding_set_option_cooldown_patron_effect = { VAR = 1200_guards_summoned }
				#Go back to the main event
				trigger_event = gdp_visit_holding_decision_event.1000
			}
		}
	}
}

scripted_effect gdp_1200_duel_effect_b = {
	duel = {
		skill = $SKILL$
		target = scope:negotiator
		#Success: Get what you wanted
		50 = {
			compare_modifier = {
				value = scope:duel_value
				multiplier = 3.5
				min = -49
			}
			desc = gdp_visit_holding_decision_event.1200.a_$SKILL$.success
			send_interface_toast = {
				title = gdp_visit_holding_decision_event.1200.a_$SKILL$.success
				left_icon = root
				right_icon = scope:negotiator
				pay_short_term_gold = {
					target = scope:negotiator
					gold = medium_gold_value
				}
				add_prestige = medium_prestige_gain	
				visit_holding_set_option_cooldown_patron_effect = { VAR = 1200_patron_prestige }
				trigger_event = gdp_visit_holding_decision_event.1200
			}
			
		}
		#Failure: you get nothing/get a worse deal, patron/steward gets mad
		45 = {
			compare_modifier = {
				value = scope:duel_value
				multiplier = -3.5
				min = -20
			}	
			desc = gdp_visit_holding_decision_event.1200.a_$SKILL$.failure
			send_interface_toast = {
				title = gdp_visit_holding_decision_event.1200.a_$SKILL$.failure
				left_icon = root
				right_icon = scope:negotiator
				visit_holding_set_option_cooldown_patron_effect = { VAR = 1200_patron_prestige }
				add_prestige = minor_prestige_loss
				#Go back to the second event
				trigger_event = gdp_visit_holding_decision_event.1200
			}
		}
		#Critical Failure: The local guards are summoned
		5 = {
			trigger = {
				root = {
					OR = {
						highest_skill = martial 
						highest_skill_including_prowess = prowess
					}
				}			
			}
			compare_modifier = {
				value = scope:duel_value
				multiplier = -3.5
			}	
			min = 5
			desc = gdp_visit_holding_decision_event.1200.a_$SKILL$.critical_failure
			send_interface_toast = {
				title = gdp_visit_holding_decision_event.1200.a_$SKILL$.critical_failure
				left_icon = root
				right_icon = scope:negotiator
				#Set up the cooldown for the convince-ction
				visit_holding_set_option_cooldown_patron_effect = { VAR = 1200_patron_prestige }
				#Quite the tussle
				increase_wounds_effect = { REASON = fight }
				#This patron doesn't want to see you again
				progress_towards_rival_effect = {
					REASON = rival_merchant_tried_to_intimidate
					CHARACTER = scope:negotiator
					OPINION = default_rival_opinion
				}
				#And you will not be going back to this patron for a while, but feel free to look at the greyed out option
				visit_holding_set_option_cooldown_patron_effect = { VAR = 1200_guards_summoned }
				#Go back to the main event
				trigger_event = gdp_visit_holding_decision_event.1000
			}
		}
	}
}

#Visit Patron
gdp_visit_holding_decision_event.1200 = { 
	type = character_event 
	title = gdp_visit_holding_decision_event.1200.t 
	window = visit_settlement_window
	desc = {
		desc = gdp_visit_holding_decision_event.1200.intro_desc
		first_valid = {
			triggered_desc = {
				trigger = { 
					AND = {
						scope:patron = scope:negotiator
						scope:steward ?= { is_available = yes } 
					}
				}
				desc = gdp_visit_holding_decision_event.1200.all_available_desc
			}
			triggered_desc = {
				trigger = { 
					AND = {
						scope:patron = scope:negotiator
						OR = {
							NOT = { exists = scope:steward }
							scope:steward = { is_available = no } 
						}
					}
				}
				desc = gdp_visit_holding_decision_event.1200.patron_available_desc
			}
			triggered_desc = {
				trigger = { scope:steward ?= scope:negotiator }
				desc = gdp_visit_holding_decision_event.1200.steward_available_desc
			}
			triggered_desc = {
				trigger = {
					exists = scope:negotiator
					NOR = {
						scope:negotiator = scope:patron
						scope:steward ?= { this = scope:negotiator }
					}
				}
				desc = gdp_visit_holding_decision_event.1200.representative_desc
			}
			desc = gdp_visit_holding_decision_event.1200.none_available_desc
		}
	}

	theme = stewardship 
	override_sound = { reference = "event:/SFX/Events/Themes/sfx_event_theme_type_generic" }
	override_background = throne_room

	left_portrait = {
		character = root 
		animation = holding_scrolls
		camera = camera_event_scheme_center
	}

	center_portrait = {
		character = scope:steward
		animation = chancellor
		camera = camera_event_scheme_far_right
		trigger = {
			scope:steward ?= {
				this != scope:negotiator
				is_available = yes 
			}
		}
	}

	right_portrait = {
		character = scope:negotiator
		animation = pondering
	}

	immediate = {
		suzerain = { save_scope_as = patron }
		scope:patron.cp:councillor_steward ?= { save_scope_as = steward }
		if = {
			limit = { NOT = { exists = scope:negotiator } }
			if = {
				limit = {
					scope:patron = { is_available = yes }
				}
				scope:patron = { save_scope_as = negotiator }
			}
			else_if = {
				limit = {
					scope:steward ?= { is_available = yes }
				}
				scope:steward = { save_scope_as = negotiator }
			}
			else_if = {
				limit = {
					scope:patron.cp:councillor_chancellor ?= { is_available = yes }
				}
				scope:patron.cp:councillor_chancellor ?= { save_scope_as = negotiator }
			}
			else_if = {
				limit = {
					scope:patron = {
						any_councillor = { is_available = yes }
					}
				}
				scope:patron = {
					random_councillor = {
						limit = { is_available = yes }
						save_scope_as = negotiator
					}
				}
			}
			else_if = {
				limit = {
					scope:patron = {
						any_courtier = {
							is_available = yes
							is_adult = yes
						}
					}
				}
				scope:patron = {
					random_courtier = {
						limit = {
							is_available = yes
							is_adult = yes
						}
						save_scope_as = negotiator
					}
				}
			}
			else_if = {
				limit = {
					scope:patron = {
						any_vassal = {
							is_available = yes
							is_adult = yes
						}
					}
				}
				scope:patron = {
					random_vassal = {
						limit = {
							is_available = yes
							is_adult = yes
						}
						save_scope_as = negotiator
					}
				}
			}
			else = { gdp_1200_create_fallback_negotiator_effect = yes }
		}
	}

	option = { # Ask for Trade Privileges
		trigger = {
			custom_tooltip = {
				text = gdp_visit_holding_decision_event.1200.a.negotiator.tt
				exists = scope:negotiator
			}
			custom_tooltip = {
				text = gdp_visit_holding_decision_event.1200.a.competitiveness_cooldown.tt
				NOT = { has_variable = 1200_patron_competitiveness }
			}
		}
		show_as_unavailable = { always = yes }
		name = gdp_visit_holding_decision_event.1200.a
		custom_tooltip = gdp_visit_holding_decision_event.1200.a.tt 
		trigger_event = gdp_visit_holding_decision_event.1201
	}
	option = { # Look for Investment Opportunities
		trigger = {
			custom_tooltip = {
				text = gdp_visit_holding_decision_event.1200.a.negotiator.tt
				exists = scope:negotiator
			}
			custom_tooltip = {
				text = gdp_visit_holding_decision_event.1200.b.prestige_cooldown.tt
				NOT = { has_variable = 1200_patron_prestige }
			}
			short_term_gold >= medium_gold_value
		}
		reason = add_prestige
		show_as_unavailable = { always = yes }
		name = gdp_visit_holding_decision_event.1200.b
		custom_tooltip = gdp_visit_holding_decision_event.1200.b.tt
		trigger_event = gdp_visit_holding_decision_event.1202
	}

	option = { # Back Out
		name = gdp_visit_holding_decision_event.1200.c
		custom_tooltip = gdp_visit_holding_decision_event.1200.c.tt
		if = {
			limit = { scope:negotiator ?= { has_character_flag = gdp_1200_temp_negotiator } }
			scope:negotiator = { silent_disappearance_effect = yes }
		}
		trigger_event = gdp_visit_holding_decision_event.1000	 	
	}
}

#Visit Patron - Increase Competitiveness
gdp_visit_holding_decision_event.1201 = { 
	type = character_event 
	title = gdp_visit_holding_decision_event.1201.t 
	window = visit_settlement_window
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { 
					AND = {
						scope:patron = scope:negotiator
						scope:steward ?= { is_available = yes } 
					}
				}
				desc = gdp_visit_holding_decision_event.1201.all_available_desc
			}
			triggered_desc = {
				trigger = { 
					AND = {
						scope:patron = { is_available = yes } 
						OR = {
							NOT = { exists = scope:steward }
							scope:steward ?= { is_available = no } 
						}
					}
				}
				desc = gdp_visit_holding_decision_event.1201.patron_available_desc
			}
			triggered_desc = {
				trigger = { scope:steward ?= scope:negotiator }
				desc = gdp_visit_holding_decision_event.1201.steward_available_desc
			}
			triggered_desc = {
				trigger = { exists = scope:negotiator }
				desc = gdp_visit_holding_decision_event.1201.representative_desc
			}
		}
	}

	theme = stewardship 
	override_sound = { reference = "event:/SFX/Events/Themes/sfx_event_theme_type_generic" }
	override_background = throne_room

	left_portrait = {
		character = root 
		animation = personality_dishonorable
		camera = camera_event_group_talking_left_left
	}

	center_portrait = {
		character = scope:steward
		animation = wedding_groom_right
		camera = camera_event_scheme_center_look_semi_right
		trigger = {
			scope:steward ?= {
				this != scope:negotiator
				is_available = yes
			}
		}
	}

	right_portrait = {
		character = scope:negotiator
		animation = zealous_superior
	}

	option = { # You owe me
		trigger = {
			exists = scope:negotiator
			has_usable_hook = scope:negotiator
		}
		show_as_unavailable = { always = yes }
		if = {
			limit = { has_usable_hook = scope:patron }
			use_hook = scope:patron
		}
		else_if = {
			limit = { has_usable_hook = scope:negotiator }
			use_hook = scope:negotiator
		}
		name = gdp_visit_holding_decision_event.1201.b
		send_interface_toast = {
			title = gdp_visit_holding_decision_event.1202.b.success
			left_icon = root
			right_icon = scope:negotiator
			add_character_modifier = {
				modifier = gdp_patron_competitiveness_modifier
				years = 5
			}
			visit_holding_set_option_cooldown_patron_effect = { VAR = 1200_patron_competitiveness }
			trigger_event = gdp_visit_holding_decision_event.1200
		}
		stress_and_fulfillment_impact = {
			deceitful = medium_stress_impact_loss
			just = minor_stress_impact_loss
			honest = medium_stress_impact_gain
		}
	}

	option = { # I want something... more.
		trigger = { exists = scope:negotiator }
		name = gdp_visit_holding_decision_event.1201.a

		gdp_1200_highest_skill_duel_effect_a = yes

		stress_and_fulfillment_impact = {
			deceitful = minor_stress_impact_loss
			greedy = minor_stress_impact_loss
			shy = minor_stress_impact_gain
			lazy = minor_stress_impact_gain
		}
	}

	option = { # Let me rethink that.
		name = gdp_visit_holding_decision_event.1201.c
		trigger_event = gdp_visit_holding_decision_event.1200
		custom_tooltip = gdp_visit_holding_decision_event.1201.c.tt
	}
}

#Visit Patron - Gold for Prestige
gdp_visit_holding_decision_event.1202 = { 
	type = character_event 
	title = gdp_visit_holding_decision_event.1202.t
	window = visit_settlement_window
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { 
					AND = {
						scope:patron = scope:negotiator
						scope:steward ?= { is_available = yes } 
					}
				}
				desc = gdp_visit_holding_decision_event.1202.all_available_desc
			}
			triggered_desc = {
				trigger = { 
					AND = {
						scope:patron = { is_available = yes } 
						OR = {
							NOT = { exists = scope:steward }
							scope:steward ?= { is_available = no } 
						}
					}
				}
				desc = gdp_visit_holding_decision_event.1202.patron_available_desc
			}
			triggered_desc = {
				trigger = { 
					scope:steward ?= { this = scope:negotiator }
				}
				desc = gdp_visit_holding_decision_event.1202.steward_available_desc
			}
			triggered_desc = {
				trigger = { exists = scope:negotiator }
				desc = gdp_visit_holding_decision_event.1202.representative_desc
			}
		}
	}

	theme = stewardship 
	override_sound = { reference = "event:/SFX/Events/Themes/sfx_event_theme_type_generic" }
	override_background = throne_room

	left_portrait = {
		character = root 
		animation = steward
	}

	center_portrait = {
		character = scope:steward
		animation = flirtation_left
		camera = camera_event_right_crowner_crowning
		trigger = {
			scope:steward ?= {
				this != scope:negotiator
				is_available = yes
			}
		}
	}

	right_portrait = {
		character = scope:negotiator
		animation = page_flipping
	}

	option = { # Wait, hear me out.
		trigger = { exists = scope:negotiator }
		name = gdp_visit_holding_decision_event.1202.a
		gdp_1200_highest_skill_duel_effect_b = yes

		stress_and_fulfillment_impact = {
			ambitious = minor_stress_impact_loss
			deceitful = minor_stress_impact_loss
			arrogant = minor_stress_impact_loss
			greedy = minor_stress_impact_loss
			humble = minor_stress_impact_gain
			lazy = minor_stress_impact_gain
		}
	}

	option = { # Simple transaction
		trigger = { exists = scope:negotiator }
		name = gdp_visit_holding_decision_event.1202.b
		send_interface_toast = {
			title = gdp_visit_holding_decision_event.1202.b.success
			left_icon = root
			right_icon = scope:negotiator
			pay_short_term_gold = {
				target = scope:negotiator
				gold = medium_gold_value
			}
			add_prestige = minor_prestige_gain
			visit_holding_set_option_cooldown_patron_effect = { VAR = 1200_patron_prestige }
			trigger_event = gdp_visit_holding_decision_event.1200
		}

		stress_and_fulfillment_impact = {
			trusting = medium_stress_impact_loss
			content = minor_stress_impact_loss
			humble = minor_stress_impact_loss
			greedy = medium_stress_impact_gain
			arrogant = minor_stress_impact_gain
			ambitious = minor_stress_impact_gain
		}
	}

	option = { # Let me rethink that.
		name = gdp_visit_holding_decision_event.1201.c
		trigger_event = gdp_visit_holding_decision_event.1200
		custom_tooltip = gdp_visit_holding_decision_event.1201.c.tt
	}
}

#Events that use this must write loc for tracker 0 and 1
scripted_effect 1505_set_and_check_scene_loc_tracker_scope_effect = {
	if = {
		limit = {
			NOT = { exists = scope:$SCENE$_loc_tracker }	#e.g. scope:weaponsmith_loc_tracker
		}
		save_scope_value_as = {
			name = $SCENE$_loc_tracker
			value = 0
		}
	}
	else_if = {
		limit = { scope:$SCENE$_loc_tracker ?= 1 }
		save_scope_value_as = {
			name = $SCENE$_loc_tracker
			value = 0
		}
	}
	else = {
		save_scope_value_as = {
			name = $SCENE$_loc_tracker
			value = 1
		}			
	}
}

#One of your sick kids who wouldn't fit the visiting_partner trigger
scripted_trigger 1500_sickly_minor_trigger = {
	location = root.location
	is_courtier_of = root
	is_travelling = no
	is_imprisoned = no
	OR = {
		has_treatable_disease_trigger = yes
		has_trait = wounded_1
		has_wounds_trigger = yes
	}
	age < 10
}
#No sickness or wounds for visiting partner
scripted_trigger 1500_has_illness_or_wound_to_treat_trigger = {
	OR = {
		has_treatable_disease_trigger = yes
		has_trait = wounded_1
		has_wounds_trigger = yes
	}
}

#Nothing left for us to do
scripted_trigger 1500_done_with_holy_site_trigger = {
	has_variable = 1500_used_healer_recently
	has_variable = 1500_used_holy_site_recently
	has_variable = 1500_used_garden_recently
	trigger_if = {
		limit = { exists = scope:merchant_physician_recruit }
		exists = scope:merchant_decision_recruited_physician
	}
}
#Find an appropriate visiting partner
scripted_trigger 1500_appropriate_visiting_partner_basic_trigger = {
	is_available = yes
	is_courtier_of = root
	age >= 10
	OR = {
		opinion = {
			target = root
			value >= 25
		}
		has_any_good_relationship_with_character_trigger = { CHARACTER = root }
	}
	NOR = {
		has_relation_potential_rival = root
		has_relation_victim = root
		has_relation_bully = root
	}
}
#Pick Visiting Partner and save scope
scripted_effect 1500_pick_visiting_partner_effect = {
	if = {
		limit = { NOT = { exists = scope:visiting_partner } }
		if = {
			limit = {
				any_courtier = { 1500_appropriate_visiting_partner_basic_trigger = yes }
			}
			random_courtier = {
				limit = { 1500_appropriate_visiting_partner_basic_trigger = yes }
				weight = {
					base = 1
					modifier = {
						add = 1000
						is_close_family_of = root
						1500_has_illness_or_wound_to_treat_trigger = yes
						root.location = {
							OR = {
								has_holding_type = church_holding
								has_holding_type = temple_citadel_holding
							}
						}
					}
					modifier = {
						add = 500
						is_spouse_of = root
						1500_has_illness_or_wound_to_treat_trigger = yes
						root.location = {
							OR = {
								has_holding_type = church_holding
								has_holding_type = temple_citadel_holding
							}
						}
					}
					modifier = {
						add = 100
						has_relation_lover = root
						root.location = {
							OR = {
								has_holding_type = church_holding
								has_holding_type = temple_citadel_holding
							}
						}
					}
					modifier = { add = 20 is_spouse_of = root }
					modifier = { add = 15 is_primary_heir_of = root }
					modifier = {
						add = 10
						has_court_position = bodyguard_court_position
					}
					modifier = { add = 5 is_close_family_of = root }
					modifier = { add = 2 has_trait = ambitious }
					modifier = { add = -5 has_trait = lazy }
				}
				save_scope_as = visiting_partner
			}
		}
	}
}
#Remember character for loc
scripted_effect 1500_remember_character_effect = {
	#Do we already remember them?
	if = {
		limit = {
			has_variable = merchant_remembered_$GUILD$s_list #Notice the 's' right after GUILD (= 'merchants' instead of 'merchant')
			any_in_list = {
				variable = merchant_remembered_$GUILD$s_list
				this = $CHARACTER$
			}
		}
		#Replace old entry with a new one
		remove_list_variable = {
			name = merchant_remembered_$GUILD$s_list
			target = $CHARACTER$
		}
		add_to_variable_list = {
			name = merchant_remembered_$GUILD$s_list
			target = $CHARACTER$
			years = 10
		}
	}
	#Otherwise just add 'em to the list
	else = {
		add_to_variable_list = {
			name = merchant_remembered_$GUILD$s_list
			target = $CHARACTER$
			years = 10
		}
	}
}

#We return to the Holy Site event to peruse other options
scripted_effect 1501_return_to_holy_site_effect = {
	custom_tooltip = return_to_holy_site
	trigger_event = gdp_visit_holding_decision_event.1500
}

#Set up some reusable trait triggers
scripted_trigger 1510_has_friendly_traits = {
	OR = {
		has_trait = gregarious
		has_trait = trusting
		has_trait = compassionate
		has_trait = forgiving
		has_trait = generous
		has_trait = fickle
		has_trait = calm
	}
}

scripted_trigger 1510_has_uninterested_traits = {
	OR = {
		has_trait = callous
		has_trait = cynical
		has_trait = arrogant
		has_trait = fickle
		has_trait = arbitrary
		has_trait = patient
		has_trait = sadistic
	}
}

scripted_trigger 1510_has_commerce_traits = {
	OR = {
		has_trait = greedy
		has_trait = deceitful
		has_trait = ambitious
		has_trait = diligent
		has_trait = impatient
	}
}

scripted_trigger 1510_has_standoffish_traits = {
	OR = {
		has_trait = shy
		has_trait = craven
		has_trait = humble
		has_trait = paranoid
	}
}

scripted_trigger 1510_has_irrational_traits = {
	OR = {
		has_trait = eccentric
		has_trait = lunatic
		has_trait = possessed
	}
}

scripted_trigger 1511_has_no_applicable_traits = {
	1510_has_friendly_traits = no
	1510_has_uninterested_traits = no
	1510_has_commerce_traits = no
	1510_has_standoffish_traits = no
	1510_has_irrational_traits = no
}

#Holy Site: Visit the local Holy Site
gdp_visit_holding_decision_event.1500 = {
	type = character_event
	title = gdp_visit_holding_decision_event.1500.t
	window = visit_settlement_window
	desc = {
		#Intro
		first_valid = {
			#We've returned to this scene, now what
			#RETURN: We've returned from Main Square
			random_valid = {
				triggered_desc = { 
					trigger = { 
						var:return_from_location ?= flag:main_square
						exists = scope:been_to_holy_site
						OR = {
							scope:holy_site_loc_tracker ?= 0
							scope:holy_site_loc_tracker ?= 2
						}
					}
					desc = gdp_visit_holding_decision_event.1500.desc_returned_01
				}
				triggered_desc = { 
					trigger = { 
						var:return_from_location ?= flag:main_square
						scope:holy_site_loc_tracker ?= 1
					}
					desc = gdp_visit_holding_decision_event.1500.desc_returned_02
				}
			}
			#RETURN: We've returned from the Healer
			triggered_desc = {
				trigger = { var:return_from_location ?= flag:healer }
				desc = gdp_visit_holding_decision_event.1500.desc_returned_from_healer
			}
			#RETURN: We've returned from the Church
			triggered_desc = {
				trigger = { var:return_from_location ?= flag:church }
				desc = gdp_visit_holding_decision_event.1500.desc_returned_from_church
			}
			#RETURN: We've returned from the Garden
			triggered_desc = {
				trigger = { var:return_from_location ?= flag:garden }
				desc = gdp_visit_holding_decision_event.1500.desc_returned_from_garden
			}
			#RETURN: We've returned from the Physician
			triggered_desc = {
				trigger = { var:return_from_location ?= flag:physician }
				desc = gdp_visit_holding_decision_event.1500.desc_returned_from_physician
			}
			#FIRST TIME: First time here
			triggered_desc = {
				trigger = { 
					NOT = { exists = scope:been_to_holy_site }
				}
				desc = gdp_visit_holding_decision_event.1500.desc
			}
		}
		#Outro
		first_valid = {
			#FIRST TIME: For some reason, you have both Sickly Minor and Physician
			triggered_desc = {
				trigger = {
					exists = scope:merchant_physician_recruit
					exists = scope:1500_sickly_minor
					NOT = { exists = scope:been_to_holy_site }
				}
				desc = gdp_visit_holding_decision_event.1500.desc_outro_physician_sickly_minor
			}
			#FIRST TIME: First time here, look at the physician
			triggered_desc = {
				trigger = {
					exists = scope:merchant_physician_recruit
					NOT = { exists = scope:been_to_holy_site }
				}
				desc = gdp_visit_holding_decision_event.1500.desc_outro_physician
			}
			#FIRST TIME: First time here, sickly minor
			triggered_desc = {
				trigger = {
					exists = scope:1500_sickly_minor
					NOT = { exists = scope:been_to_church_grounds }
				}
				desc = gdp_visit_holding_decision_event.1500.desc_outro_sickly_minor
			}
			#FIRST TIME: First time here, curious partner
			triggered_desc = {
				trigger = {
					exists = scope:visiting_partner
					NOT = { exists = scope:been_to_holy_site }
				}
				desc = gdp_visit_holding_decision_event.1500.desc_outro_partner
			}
			#FIRST TIME: First time here
			triggered_desc = {
				trigger = {
					NOT = {  exists = scope:been_to_holy_site }
				}
				desc = gdp_visit_holding_decision_event.1500.desc_outro
			}
			#RETURN: Partner - there is nothing left for us here
			triggered_desc = {
				trigger = { 
					exists = scope:visiting_partner
					1500_done_with_holy_site_trigger = yes 
				}
				desc = gdp_visit_holding_decision_event.1500.desc_outro_return_partner_finished
			}
			#RETURN: There is nothing left for us here
			triggered_desc = {
				trigger = { 1500_done_with_holy_site_trigger = yes }
				desc = gdp_visit_holding_decision_event.1500.desc_outro_return_finished
			}
			#RETURN: Physician did not move to their study, yet
			triggered_desc = {
				trigger = {
					exists = scope:merchant_physician_recruit
					NOR = { 
						exists = scope:been_to_physician
						exists = scope:merchant_decision_recruited_physician
					}
				}
				desc = gdp_visit_holding_decision_event.1500.desc_outro_physician_return
			}
			#RETURN: We've been here before
			first_valid = {
				#RETURN: Sickly minor is still at the healer's
				triggered_desc = {
					trigger = {
						exists = scope:1500_sickly_minor
						var:return_from_location ?= flag:healer
						scope:1500_sickly_minor = { has_any_illness = yes }
					}
					desc = gdp_visit_holding_decision_event.1500.desc_outro_sickly_minor_return
				}
				random_valid = {
					#RETURN: Partner flavor
					triggered_desc = {
						trigger = {
							exists = scope:visiting_partner
							exists = scope:been_to_holy_site
							scope:holy_site_loc_tracker ?= 0
						}
						desc = gdp_visit_holding_decision_event.1500.desc_outro_return_partner_01
					}
					triggered_desc = {
						trigger = {
							exists = scope:visiting_partner
							scope:holy_site_loc_tracker ?= 1
						}
						desc = gdp_visit_holding_decision_event.1500.desc_outro_return_partner_02
					}
					triggered_desc = {
						trigger = {
							exists = scope:visiting_partner
							scope:church_grounds_loc_tracker ?= 2
						}
						desc = gdp_visit_holding_decision_event.1500.desc_outro_return_partner_03
					}
					#RETURN: Generics
					triggered_desc = {
						trigger = { 
							exists = scope:been_to_holy_site
							scope:church_grounds_loc_tracker ?= 0
						}
						desc = gdp_visit_holding_decision_event.1500.desc_outro_return_01
					}
					triggered_desc = {
						trigger = { scope:church_grounds_loc_tracker ?= 1 }
						desc = gdp_visit_holding_decision_event.1500.desc_outro_return_02
					}
					triggered_desc = {
						trigger = { scope:church_grounds_loc_tracker ?= 2 }
						desc = gdp_visit_holding_decision_event.1500.desc_outro_return_03
					}
				}
			}
		}
	}
	theme = faith
	override_sound = { reference = "event:/SFX/Events/Themes/sfx_event_theme_type_generic" }
	override_background = { 
		trigger = {
			location = {
				culture = { has_graphical_east_asia_culture_group_trigger = no }
				geographical_region = world_asia_southeast
			}
		}
		reference = holy_site_generic
	}
	override_background = { reference = courtyard_location }
	left_portrait = {
		trigger = { exists = scope:visiting_partner }
		character = scope:visiting_partner
		#Concerned about our kid
		triggered_animation = {
			trigger = {
				exists = scope:1500_sickly_minor
				is_close_family_of = scope:1500_sickly_minor
				OR = {
					AND = {
						var:return_from_location ?= flag:healer
						scope:1500_sickly_minor = { has_any_illness = yes }
					}
					NOT = { exists = scope:been_to_holy_site }
				}
			}
			animation = stress
		}
		#Zealous dudette
		triggered_animation = {
			trigger = {
				scope:visiting_partner = { has_trait = zealous }
			}
			animation = personality_zealous
		}
		#Cynical dude
		triggered_animation = {
			trigger = {
				scope:visiting_partner = { has_trait = cynical }
			}
			animation = personality_cynical
		}
		#Friendly
		triggered_animation = {
			trigger = { 
				scope:visiting_partner = { 
					OR = {
						has_trait = gregarious
						has_trait = trusting
						has_trait = compassionate
						has_trait = forgiving
						has_trait = generous
						has_trait = fickle
						has_trait = calm
					}
				} 
			}
			animation = personality_forgiving
		}
		#Business-minded
		triggered_animation = {
			trigger = { 
				scope:visiting_partner = { 
					OR = {
						has_trait = greedy
						has_trait = deceitful
						has_trait = ambitious
						has_trait = diligent
						has_trait = impatient
					}
				} 
			}
			animation = personality_greedy
		}
		#Uninterested
		triggered_animation = {
			trigger = { 
				scope:visiting_partner = { 
					OR = {
						has_trait = callous
						has_trait = cynical
						has_trait = arrogant
						has_trait = fickle
						has_trait = arbitrary
						has_trait = patient
						has_trait = sadistic
					}
				} 
			}
			animation = personality_callous
		}
		#Irrational
		triggered_animation = {
			trigger = { 
				scope:visiting_partner = { 
					OR = {
						has_trait = eccentric
						has_trait = lunatic
						has_trait = possessed
					}
				} 
			}
			animation = personality_irrational
		}
		#A bit awkward
		triggered_animation = {
			trigger = { 
				scope:visiting_partner = { 
					OR = {
						has_trait = shy
						has_trait = craven
						has_trait = humble
						has_trait = paranoid
					}
				} 
			}
			animation = personality_coward
		}
		animation = survey
	}
	center_portrait = {
		character = root
		#Concerned about our kid
		triggered_animation = {
			trigger = {
				exists = scope:1500_sickly_minor
				OR = {
					AND = {
						var:return_from_location ?= flag:healer
						scope:1500_sickly_minor = { has_any_illness = yes }
					}
					NOT = { exists = scope:been_to_church_grounds }
				}
			}
			animation = worry
		}
		#Bah, humbug
		triggered_animation = {
			trigger = {
				OR = {
					has_trait = cynical
					any_secret = { type = secret_non_believer }
				}
			}
			animation = boredom
		}
		animation = personality_content
	}
	#Do we have a Physician?
	right_portrait = {
		trigger = { 
			exists = scope:1500_third_character
			#If this is root, then that means we have talked to the Physician, so let's disappear the portrait
			scope:1500_third_character != root
		}
		camera = camera_event_scheme_center_forward
		character = scope:1500_third_character
		#Otherwise it's the Physician
		animation = personality_zealous
	}
	#Shove the Physician as long as we've visited them but haven't actioned them
	lower_left_portrait = {
		trigger = {
			exists = scope:1500_fourth_character
			#Unless we've actioned them and overwritten them with ROOT
			scope:1500_fourth_character != root
		}
		character = scope:1500_fourth_character
	}
	#Show the kid here if not actioned
	lower_center_portrait = {
		trigger = { 
			exists = scope:1500_fifth_character
			scope:1500_sickly_minor = { has_any_illness = yes } 
			scope:1500_fifth_character != root
		}
		character = scope:1500_fifth_character
	}	
	immediate = {
		1500_pick_visiting_partner_effect = yes

		#Set up the ancillary portraits to remind the player of the characters
		if = {
			#Physician exists
			limit = {
				#We've been to them at least once
				exists = scope:been_to_physician
				#We're not done with them yet
				AND = {
					exists = scope:merchant_physician_recruit
					NOT = { exists = scope:merchant_decision_recruited_physician }
				}
				#This isn't already the state
				NAND = {
					exists = scope:1500_fourth_character
					scope:1500_fourth_character ?= scope:merchant_physician_recruit
				}
			}
			scope:merchant_physician_recruit = { save_scope_as = 1500_fourth_character }
		}
		#Clear out the ancillary portrait(s)
		if = {
			limit = { 
				exists = scope:1500_fourth_character
				scope:merchant_physician_recruit ?= scope:1500_fourth_character
				exists = scope:merchant_decision_recruited_physician
			}
			#Overwrite with ROOT to hide that portrait
			save_scope_as = 1500_fourth_character
		}
		if = {
			limit = {
				exists = scope:1500_fifth_character
				scope:1500_sickly_minor ?= scope:1500_fifth_character
				has_variable = 1500_used_healer_recently
			}
			#Overwrite with ROOT to hide that portrait
			save_scope_as = 1500_fifth_character
		}
		#Do we have a sick minor we snuck along?
		if = {
			limit = {
				NOT = { exists = scope:1500_sickly_minor }
				any_close_family_member = { 1500_sickly_minor_trigger = yes }
			}
			random_close_family_member = {
				limit = { 1500_sickly_minor_trigger = yes }
				save_scope_as = 1500_sickly_minor
				save_scope_as = 1500_fifth_character
			}
		}
		#Rare: Spawn a spectacular Physician
		if = {
			limit = {
				NOT = { has_variable = merchant_decision_1500_checked_for_physician }
			}
			random_list = {
				80 = {
					#No Physician
				}
				20 = {
					#Has this person been our physician in the past 10 years?
					random_pool_character = {
						province = root.location
						limit = {
							NOT = { 
								has_any_bad_relationship_with_character_trigger = { CHARACTER = root }
							}
							is_available_adult = yes
							save_temporary_scope_as = saved_character_check
						}
						save_scope_as = merchant_physician_recruit
						#Some more loc flavor shenanigans for these saved scopes
						save_scope_as = merchant_recurring_physician
					}
					#Otherwise find a physician in the pool
					if = {
						limit = { 
							NOT = { exists = scope:merchant_physician_recruit }
						}
						random_pool_character = {
							province = root.location
							limit = { 
								NOT = { 
									has_any_bad_relationship_with_character_trigger = { CHARACTER = root }
								}
								is_available_adult = yes
								has_trait = devoted
								learning >= 15
								OR = {
									has_trait = lifestyle_physician
									has_trait = lifestyle_herbalist
									has_trait = lifestyle_mystic
								}
							}
							save_scope_as = merchant_physician_recruit
						}
					}
					#Otherwise create a physician
					if = {
						limit = {
							NOT = { exists = scope:merchant_physician_recruit }
						}
						#Create physician to stuff in pool
						create_character = {
							template = bp1_yearly_2021_learning_person_template
							location = root.location
							dynasty = none
							culture = root.location.culture
							faith = root.location.faith
							learning = { decent_skill_rating high_skill_rating }
							save_scope_as = merchant_physician_recruit
						}
						scope:merchant_physician_recruit ?= {
							#Chance to add a malus trait to this spectacular being
							if = {
								limit = { 
									NOR = { 
										has_trait = possessed_1 
										has_trait = lunatic_1
										has_trait = depressed_1
										has_trait = drunkard
										has_trait = hashishiyah
										has_trait = irritable
										any_secret = { type = secret_witch }
									}
								}
								hidden_effect = {
									random = {
										chance = 20
										random_list = {
											10 = { add_trait = possessed_1 }
											10 = { add_trait = lunatic_1 }
											10 = { add_trait = depressed_1 }
											10 = { add_trait = drunkard }
											10 = { add_trait = hashishiyah }
											10 = { add_trait = irritable }
											10 = { 
												add_secret = { type = secret_witch }
											}
										}
									}
								}
							}
							if = {
								limit = {
									NOT = { has_trait = devoted }
								}
								add_trait = devoted
							}
						}
					}
					scope:merchant_physician_recruit = { save_scope_as = 1500_third_character }
					#Remember the physician
					1500_remember_character_effect = { GUILD = physician CHARACTER = scope:merchant_physician_recruit }
					#Cool down if the physician was spawned
					set_variable = {
						name = merchant_decision_1500_checked_for_physician
						days = visit_holding_cooldown_days
					}
				}
			}
		}
	}
	#Attempt to improve your health // OR // Attempt to cure (curable) illness
	option = {
		name = {
			text = {
				first_valid = {
					#Sickly child is still waiting at the healer's
					triggered_desc = {
						trigger = { 
							exists = scope:been_to_healer
							exists = scope:1500_sickly_minor
							NOT = { has_variable = 1500_used_healer_recently }
						}
						desc = gdp_visit_holding_decision_event.1500.a_second_sickly_minor
					}
					#Return to healer
					triggered_desc = {
						trigger = { exists = scope:been_to_healer }
						desc = gdp_visit_holding_decision_event.1500.a_second
					}
					#We are meeting a sickly child at the healer's
					triggered_desc = {
						trigger = { exists = scope:1500_sickly_minor }
						desc = gdp_visit_holding_decision_event.1500.a_sickly_minor
					}
					#First time going to healer
					desc = gdp_visit_holding_decision_event.1500.a
				}
			}
		}
		trigger = {
			custom_tooltip = {
				text = gdp_visit_holding_decision_event.1500.a.cooldown.tt
				NOT = { has_variable = 1500_used_healer_recently }
			}
		}
		show_as_unavailable = { always = yes }
		reason = visit_healer
		custom_tooltip = gdp_visit_holding_decision_event.1500.a.tt
		#Go to the Healer screen
		trigger_event = gdp_visit_holding_decision_event.1501
		ai_chance = { base = 0 }
	}
	#Visit Holy Site
	option = {
		name = {
			text = {
				first_valid = {
					#Return to Holy Site
					triggered_desc = {
						trigger = { exists = scope:been_to_holy_site }
						desc = gdp_visit_holding_decision_event.1500.b_second
					}
					#First time at Holy Site
					desc = gdp_visit_holding_decision_event.1500.b
				}
			}
		}
		trigger = {
			#You were recently caught stealing from the Holy Site
			trigger_if = {
				limit = { has_variable = 1500_caught_stealing }
				custom_tooltip = {
					text = gdp_caught_stealing.tt
					text = gdp_visit_holding_caught_stealing.tt
					always = no
				}
			}
			trigger_else = {
				custom_tooltip = {
					text = gdp_visit_holding_decision_event.1500.b.cooldown.tt
					NOT = { has_variable = 1500_used_holy_site_recently }
				}
			}
		}
		show_as_unavailable = { always = yes }
		reason = visit_church
		custom_tooltip = gdp_visit_holding_decision_event.1500.b.tt
		#Go to the Church screen
		trigger_event = gdp_visit_holding_decision_event.1503
		ai_chance = {
			base = 100
			modifier = {
				has_trait = zealous
				factor = 2
			}
			modifier = {
				has_trait = pilgrim
				factor = 2
			}
		}
	}
	#Convert to local faith // OR // Contemplate faith
	option = {
		name = {
			text = {
				first_valid = {
					#Convert to faith
					triggered_desc = {
						trigger = { exists = scope:been_to_garden }
						desc = gdp_visit_holding_decision_event.1500.c_second
					}
					#Contemplate faith
					desc = gdp_visit_holding_decision_event.1500.c
				}
			}
		}
		trigger = {
			custom_tooltip = {
				text = gdp_visit_holding_decision_event.1500.c.cooldown.tt
				NOT = { has_variable = 1500_used_garden_recently }
			}
		}
		show_as_unavailable = { always = yes }
		reason = visit_garden
		custom_tooltip = gdp_visit_holding_decision_event.1500.c.tt
		#Go to the Garden screen
		trigger_event = gdp_visit_holding_decision_event.1505
		ai_chance = {
			base = 100
			modifier = {
				stress_level >= 2
				add = 400
			}
		}
	}
	#Rare Option: Hire cheaper, skilled, Physician
	option = {
		name = {
			text = {
				first_valid = {
					#Return to talk to physician
					triggered_desc = {
						trigger = { exists = scope:been_to_physician }
						desc = gdp_visit_holding_decision_event.1500.d_second
					}
					#First time talking to physician
					desc = gdp_visit_holding_decision_event.1500.d
				}
			}
		}
		trigger = {
			exists = scope:merchant_physician_recruit
			NOT = { exists = scope:merchant_decision_recruited_physician }
		}
		reason = recruit_physician
		custom_tooltip = gdp_visit_holding_decision_event.1500.d.tt
		#For the Physician screen
		trigger_event = gdp_visit_holding_decision_event.1507
		ai_chance = {
			base = 1000 #Just do it
		}
	}
	#I want to do something else
	option = {
		name = gdp_visit_holding_decision_event.1500.e
		custom_tooltip = gdp_visit_holding_decision_event.1200.c.tt
	 	trigger_event = gdp_visit_holding_decision_event.1000
		ai_chance = { base = 100 }
	}
}

#Pretty straight forward
scripted_effect 1500_chance_to_buff_item_rarity_effect = {
	random_list = {
		20 = {
			trigger = {
				exists = scope:merchant_healer_character
				$VENDOR$ = scope:merchant_healer_character
			}
			set_artifact_rarity_famed = yes
		}
		80 = {
			set_artifact_rarity_common = yes
		}
	}
}

#Determine the variable effect based on their aptitude, one for the healer and one for the physician-partner
scripted_effect 1500_calculate_aptitude_modifier_effect = {
	if = {
		limit = {
			$CHARACTER$ = {
				aptitude = {
					court_position = court_physician_court_position
					value >= 1
				}
			}	
		}
		change_variable = {
			name = $VARIABLE$
			add = 1
		}
	}
	if = {
		limit = {
			$CHARACTER$ = {
				aptitude = {
					court_position = court_physician_court_position
					value >= 2
				}
			}	
		}
		change_variable = {
			name = $VARIABLE$
			add = 1
		}
	}
	if = {
		limit = {
			$CHARACTER$ = {
				aptitude = {
					court_position = court_physician_court_position
					value >= 3
				}
			}	
		}
		change_variable = {
			name = $VARIABLE$
			add = 1
		}
	}
	if = {
		limit = {
			$CHARACTER$ = {
				aptitude = {
					court_position = court_physician_court_position
					value >= 4
				}
			}	
		}
		change_variable = {
			name = $VARIABLE$
			add = 1
		}
	}
	if = {
		limit = {
			$CHARACTER$ = {
				aptitude = {
					court_position = court_physician_court_position
					value >= 5
				}
			}	
		}
		change_variable = {
			name = $VARIABLE$
			add = 1
		}
	}
}

#Do you feel lucky?
scripted_effect 1500_treatment_roll_effect = {
	random_list = {
		#Failure
		60 = {
			#Some weighting based on the aptitude of the performing party (healer/physician-partner)
			modifier = {
				exists = $VARIABLE$
				$VARIABLE$ >= 5
				add = -15
			}
			modifier = {
				exists = $VARIABLE$
				$VARIABLE$ >= 4
				add = -15
			}
			modifier = {
				exists = $VARIABLE$
				$VARIABLE$ >= 3
				add = -15
			}
			#Notify us about the outcome
			if = {
				limit = { 
					NOT = { $TARGET_CHARACTER$ = root } #If our partner gets treated
				}
				send_interface_toast = {
					type = event_toast_text_bad
					title = gdp_visit_holding_decision_event.1501.treatment_failure.t
					desc = gdp_visit_holding_decision_event.1501.treatment_failure.desc
					left_icon = root
					right_icon = $TARGET_CHARACTER$
				}
			}
			else = {
				send_interface_toast = {
					type = event_toast_text_bad #If we get treated
					title = gdp_visit_holding_decision_event.1501.treatment_failure.t
					desc = gdp_visit_holding_decision_event.1501.treatment_failure.desc
					left_icon = root
				}
			}
			#Nothing happens
		}
		#Success
		40 = {
			modifier = {
				NOT = { $TARGET_CHARACTER$ = root } #The scoped character is either visiting_partner or sickly_minor
				$TARGET_CHARACTER$ = {
					age < 20
					is_child_of = root
				}
				add = 30
			}
			modifier = {
				NOT = { $TARGET_CHARACTER$ = root }
				$TARGET_CHARACTER$ = {
					age < 10
					is_child_of = root
				}
				add = 30
			}
			#If our partner gets treated
			if = {
				limit = { 
					NOT = { $TARGET_CHARACTER$ = root } #The scoped character is either visiting_partner or sickly_minor
				}
				send_interface_toast = {
					type = event_toast_effect_good
					title = gdp_visit_holding_decision_event.1501.treatment_success.t
					left_icon = root
					right_icon = $TARGET_CHARACTER$
					$TARGET_CHARACTER$ = { 1500_remove_illness_or_wound_effect = yes }	
				}
			}
			#If we get treated, automatic toast
			else = { 1500_remove_illness_or_wound_effect = yes }	
		}
	}
}

#The actual removal-of-illness
scripted_effect 1500_remove_illness_or_wound_effect = {
	random_list = {
		100 = {
			trigger = { has_character_modifier = infected_wound_modifier }
			remove_character_modifier = infected_wound_modifier
		}
		100 = {
			trigger = { has_character_modifier = gangrene_modifier }
			remove_character_modifier = gangrene_modifier
		}
		100 = {
			trigger = { has_trait = wounded_1 }
			remove_trait = wounded_1
		}
		100 = {
			trigger = { has_trait = wounded_2 }
			remove_trait = wounded_2
		}
		100 = {
			trigger = { has_trait = wounded_3 }
			remove_trait = wounded_3
		}
		100 = {
			trigger = { has_trait = ill }
			remove_trait = ill
		}
		100 = {
			trigger = { has_trait = pneumonic }
			remove_trait = pneumonic
		}
		50 = {
			trigger = { has_trait = typhus }
			remove_trait = typhus
		}
		50 = {
			trigger = { has_trait = gout_ridden }
			remove_trait = gout_ridden
		}
		50 = {
			trigger = { has_trait = consumption }
			remove_trait = consumption
		}
		50 = {
			trigger = { has_trait = smallpox }
			remove_trait = smallpox
		}
		50 = {
			trigger = { has_trait = great_pox }
			remove_trait = great_pox
		}
		25 = {
			trigger = { has_trait = cancer }
			remove_trait = cancer
		}
		25 = {
			trigger = { has_trait = bubonic_plague }
			remove_trait = bubonic_plague
		}
		25 = {
			trigger = { has_trait = leper }
			remove_trait = leper
		}
	}
}

#What was our last location?
scripted_effect 1500_update_last_location_effect = {
	if = {
		limit = { has_variable = return_from_location }
		remove_variable = return_from_location
		set_variable = {
			name = return_from_location
			value = $LOCATION_FLAG$
		}
	}
	else = {
		set_variable = {
			name = return_from_location
			value = $LOCATION_FLAG$
		}
	}
}

#Return to the holy site from a subsequent event
scripted_effect 1501_been_to_effect = {
	#For desc flavor
	if = {
		limit = {
			NOT = { exists = scope:been_to_$GUILD$ }
		}
		save_scope_as = been_to_$GUILD$
	}
	#Go back to holy site
	if = {
		limit = { var:return_from_location ?= flag:church_grounds }
		1501_return_to_holy_site_effect = yes
	}
}

#Someone learn-y or mystic
scripted_trigger 1501_physician_partner_trigger = {
	OR = {
		learning >= 15
		has_trait = lifestyle_physician
		has_trait = lifestyle_mystic
		has_trait = witch
	}
}

#Visit Healer
gdp_visit_holding_decision_event.1501 = {
	type = character_event
	title = gdp_visit_holding_decision_event.1501.t
	window = visit_settlement_window
	desc = {
		#What are they up to?
		first_valid = {
			#We've returned to this scene, now what
			#RETURN: A sick minor... is still here
			triggered_desc = {
				trigger = {
					exists = scope:1500_sickly_minor
					exists = scope:been_to_healer
				}
				desc = gdp_visit_holding_decision_event.1501.desc_returned_sickly_minor
			}
			#RETURN: Physician partner wants a stab at it
			triggered_desc = {
				trigger = {
					scope:visiting_partner ?= { 
						OR = {
							learning >= 15
							has_trait = lifestyle_physician
							has_trait = lifestyle_mystic
							has_trait = witch
						}
						NOR = {
							has_treatable_disease_trigger = yes
							has_trait = wounded_1
							has_wounds_trigger = yes
						}
					}
					exists = scope:been_to_healer
				}
				desc = gdp_visit_holding_decision_event.1501.desc_returned_physician_partner
			}
			#RETURN: Generics
			random_valid = {
				triggered_desc = { 
					trigger = { 
						exists = scope:been_to_healer
						scope:healer_loc_tracker ?= 0
					}
					desc = gdp_visit_holding_decision_event.1501.desc_returned_01
				}
				triggered_desc = { 
					trigger = { scope:healer_loc_tracker ?= 1 }
					desc = gdp_visit_holding_decision_event.1501.desc_returned_02
				}
			}
			#FIRST TIME: A sick minor was snuck along
			triggered_desc = {
				trigger = {
					exists = scope:1500_sickly_minor
					NOT = { exists = scope:been_to_healer }
				}
				desc = gdp_visit_holding_decision_event.1501.desc_sickly_minor
			}
			#FIRST TIME: Our partner is actually pretty physician-y
			triggered_desc = {
				trigger = {
					scope:visiting_partner ?= { 
						OR = {
							learning >= 15
							has_trait = lifestyle_physician
							has_trait = lifestyle_mystic
							has_trait = witch
						}
						NOR = {
							has_treatable_disease_trigger = yes
							has_trait = wounded_1
							has_wounds_trigger = yes
						}
					}
					NOT = { exists = scope:been_to_healer }
				}
				desc = gdp_visit_holding_decision_event.1501.desc_physician_partner
			}
			#FIRST TIME: We've seen this healer before
			triggered_desc = {
				trigger = {
					exists = scope:merchant_recurring_healer_character
					NOT = { exists = scope:been_to_healer }
				}
				desc = gdp_visit_holding_decision_event.1501.desc_reused_healer
			}
			#FIRST TIME:
			triggered_desc = {
				trigger = {
					NOT = { exists = scope:been_to_healer }
				}
				desc = gdp_visit_holding_decision_event.1501.desc
			}	
		}
		#Describe the artifact
		first_valid = {
			#RETURN: Horn artifact
			triggered_desc = {
				trigger = { 
					exists = scope:been_to_healer
					scope:1500_health_artifact = { has_variable = health_horn }
				}
				desc = gdp_visit_holding_decision_event.1501.desc_outro_return_horn
			}
			#FIRST TIME: Horn artifact
			triggered_desc = {
				trigger = { 
					NOT = { exists = scope:been_to_healer }
					scope:1500_health_artifact = { has_variable = health_horn }
				}
				desc = gdp_visit_holding_decision_event.1501.desc_outro_horn
			}
			#RETURN: Other artifacts
			triggered_desc = {
				trigger = { 
					exists = scope:been_to_healer
					scope:1500_health_artifact = { 
						NOT = { has_variable = health_horn }
					}
				}
				desc = gdp_visit_holding_decision_event.1501.desc_outro_return_artifact
			}
			#FIRST TIME: Other artifacts
			triggered_desc = {
				trigger = { 
					NOT = { exists = scope:been_to_healer }
					scope:1500_health_artifact = { 
						NOT = { has_variable = health_horn }
					}
				}
				desc = gdp_visit_holding_decision_event.1501.desc_outro_artifact
			}
		}
	}
	theme = medicine
	#Someone close to you is sick
	override_sound = { 
		trigger = { 
			OR = {
				scope:visiting_partner ?= { 
					OR = {
						has_treatable_disease_trigger = yes
						has_trait = wounded_1
						has_wounds_trigger = yes
					}
				}
				exists = scope:1500_sickly_minor
			}
		}
		reference = "event:/MUSIC/Cues/Events/Illness/mx_cue_illness"
	}
	override_sound = { reference = "event:/SFX/Events/Themes/sfx_event_theme_type_medicine" }
	override_background = { reference = physicians_study }
	left_portrait = {
		trigger = { exists = scope:visiting_partner }
		character = scope:visiting_partner
		#Concerned about our kid
		triggered_animation = {
			trigger = {
				exists = scope:1500_sickly_minor
				is_close_family_of = scope:1500_sickly_minor
			}
			animation = stress
		}
		#Sick dudette
		triggered_animation = {
			trigger = { 
				OR = {
					has_treatable_disease_trigger = yes
					has_trait = wounded_1
					has_wounds_trigger = yes
				}
			}
			animation = pain
		}
		#Doctor dude
		triggered_animation = {
			trigger = { 
				OR = {
					learning >= 15
					has_trait = lifestyle_physician
					has_trait = lifestyle_mystic
					has_trait = witch
				}
			}
			animation = ecstasy
		}
		animation = thinking
	}
	center_portrait = {
		character = root
		triggered_animation = {
			trigger = { exists = scope:1500_sickly_minor }
			animation = worry
		}
		animation = personality_content
	}
	right_portrait = {
		character = scope:merchant_healer_character
		camera = camera_event_scheme_far_right
		animation = physician
	}
	#Do we have a sick minor?
	lower_left_portrait = {
		trigger = { exists = scope:1500_sickly_minor }
		character = scope:1500_sickly_minor
	}
	artifact = {
		target = scope:1500_health_artifact
		position = lower_right_portrait
	}
	immediate = {
		#Can we _not_ repeat the loc?
		1505_set_and_check_scene_loc_tracker_scope_effect = { SCENE = healer }
		#Find our healer
		if = {
			#Do we already have a healer?
			limit = {
				NOT = { exists = scope:merchant_healer_character }
			}
			#Has this person been our healer in the past 10 years?
			random_pool_character = {
				province = root.location
				limit = {
					NOT = { 
						has_any_bad_relationship_with_character_trigger = { CHARACTER = root }
					}
					is_available_adult = yes
				}
				save_scope_as = merchant_healer_character
				#Some more loc flavor shenanigans for these saved scopes
				save_scope_as = merchant_recurring_healer_character
			}
			#Otherwise find a healer in the pool
			if = {
				limit = { 
					NOT = { exists = scope:merchant_healer_character }
				}
				random_pool_character = {
					province = root.location
					limit = { 
						NOT = { 
							has_any_bad_relationship_with_character_trigger = { CHARACTER = root }
						}
						is_available_adult = yes
						has_trait = lifestyle_physician
					}
					save_scope_as = merchant_healer_character
				}
			}
			#Otherwise create a healer
			if = {
				limit = {
					NOT = { exists = scope:merchant_healer_character }
				}
				#Create healer to stuff in pool
				create_character = {
					template = physician_high_character_template
					location = root.location
					dynasty = none
					culture = root.location.culture
					faith = root.location.faith
					save_scope_as = merchant_healer_character
				}
			}
			#Remember the healer
			1500_remember_character_effect = { GUILD = healer CHARACTER = scope:merchant_healer_character }
			#Find our healing artifact
			if = {
				limit = {
					NOT = { exists = scope:1500_health_artifact }
				}
				scope:merchant_healer_character ?= {
					#Have we created healing artifacts recently, which we can pull?
					if = {
						limit = {
							any_character_artifact ?= { has_variable = 1500_merchant_decision_health_artifact }
						}
						random_character_artifact = {
							limit = { has_variable = 1500_merchant_decision_health_artifact }
							save_scope_as = 1500_health_artifact
						}
					}
					#If we don't have any old healing artifacts; generate a new one!
					hidden_effect_new_object = { #HAZMAT SUIT OF ERROR SUPRESSION
						if = {
							limit = {
								NOT = { exists = scope:1500_health_artifact }
							}
							#Set rarity, maybe
							1500_chance_to_buff_item_rarity_effect = { VENDOR = scope:merchant_healer_character }
							#Generate healing artifact
							generate_health_trinket_effect = yes
							#Finalization
							scope:newly_created_health_artifact ?= {
								set_variable = {
									name = 1500_merchant_decision_health_artifact
									days = visit_holding_cooldown_days
								}
								#Belt & suspenders
								set_variable = 1500_merchant_decision_health_artifact
								#Don't need no notification about this
								set_variable = {
									name = suppress_artifact_notifications
									value = yes
									days = 2
								}
								save_scope_as = 1500_health_artifact
							}
						}
						#Set the value of the health artifact
						scope:1500_health_artifact = { 
							if = {
								limit = { rarity = famed }
								set_variable = {
									name = 1065_accessory_value
									value = {
										value = root.massive_gold_value
										multiply = { 1 1.5 }
									}
								}
							}
							else_if = {
								limit = { rarity = masterwork }
								set_variable = {
									name = 1065_accessory_value
									value = {
										value = root.major_gold_value
										multiply = { 1.25 1.75 }
									}
								}
							}
							else = {
								set_variable = {
									name = 1065_accessory_value
									value = {
										value = root.medium_gold_value
										multiply = { 1 1.5 }
									}
								}
							}
						}
					}
				}
			}
			if = {
				limit = {
					exists = scope:merchant_healer_character
					NOT = { has_variable = 1500_healer_aptitude }
				}
				#Calculate the healer's aptitude
				set_variable = {
					name = 1500_healer_aptitude
					value = 0
				}
				1500_calculate_aptitude_modifier_effect = { CHARACTER = scope:merchant_healer_character VARIABLE = 1500_healer_aptitude }
				#Calculate our physician friend's aptitude
				if = {
					limit = { 
						scope:visiting_partner ?= { 
							OR = {
								learning >= 15
								has_trait = lifestyle_physician
								has_trait = lifestyle_mystic
								has_trait = witch
							}
						}
					}
					set_variable = {
						name = 1500_partner_healer_aptitude
						value = 0
					}
					1500_calculate_aptitude_modifier_effect = { CHARACTER = scope:visiting_partner VARIABLE = 1500_partner_healer_aptitude }
				}
			}
		}
		#For the background
		scope:merchant_healer_character = {
			if = {
				limit = {
					is_ruler = no
					exists = court_owner
				}
				court_owner = { save_scope_as = bg_override_char }
			}
			else = {
				save_scope_as = bg_override_char
			}
		}
	}
	#Attempt to improve your health // OR // Attempt to cure (curable) illness
	option = {
		name = {
			text = {
				first_valid = {
					#We're ill
					triggered_desc = {
						trigger = { 
							OR = {
								has_treatable_disease_trigger = yes
								has_trait = wounded_1
								has_wounds_trigger = yes
							}
						}
						desc = gdp_visit_holding_decision_event.1501.a_ill
					}
					#Just a standard procedure
					desc = gdp_visit_holding_decision_event.1501.a
				}
			}
		}
		trigger = {
			short_term_gold >= minor_gold_value
		}
		show_as_unavailable = { short_term_gold < minor_gold_value }
		#We're ill, roll for some treatment
		if = {
			limit = { 
				OR = {
					has_treatable_disease_trigger = yes
					has_trait = wounded_1
					has_wounds_trigger = yes
				}
			}
			1500_treatment_roll_effect = { TARGET_CHARACTER = root VARIABLE = var:1500_healer_aptitude }
		}
		#Standard procedure health modifier
		else = {
			if = {
				limit = { has_character_modifier = gdp_visit_holding_healer_health_modifier }
				hidden_effect = { remove_character_modifier = gdp_visit_holding_healer_health_modifier }
			}
			add_character_modifier = {
				modifier = gdp_visit_holding_healer_health_modifier
				days = visit_holding_cooldown_days
			}
		}
		pay_short_term_gold = {
			target = scope:merchant_healer_character
			gold = minor_gold_value
		}
		#Set the variables and redirect us back to the Holy Site
		scope:1500_health_artifact = { remove_variable ?= 1065_accessory_value }
		remove_variable ?= 1500_healer_aptitude
		remove_variable ?= 1500_partner_healer_aptitude
		visit_holding_set_option_cooldown_worship_effect = { VAR = 1500_used_healer_recently }
		#Go back to Holy Site
		trigger_event = gdp_visit_holding_decision_event.1500
		ai_chance = {
			base = 100
			modifier = {
				short_term_gold < minor_gold_value
				factor = 0
			}
			modifier = {
				NOR = {
					has_treatable_disease_trigger = yes
					has_trait = wounded_1
					has_wounds_trigger = yes
				}
				has_character_modifier = gdp_visit_holding_healer_health_modifier
				factor = 0
			}
		}
	}
	#Buy the health artifact
	option = {
		name = gdp_visit_holding_decision_event.1501.b
		trigger = {
			short_term_gold >= scope:1500_health_artifact.var:1065_accessory_value
		}
		show_as_unavailable = { short_term_gold < scope:1500_health_artifact.var:1065_accessory_value }
		scope:1500_health_artifact = {
			root = {
				pay_short_term_gold = {
					target = scope:merchant_healer_character
					gold = prev.var:1065_accessory_value
				}
			}
			set_owner = root
		}
		#Set the variables and redirect us back to the Holy Site
		scope:1500_health_artifact = { remove_variable ?= 1065_accessory_value }
		remove_variable ?= 1500_healer_aptitude
		remove_variable ?= 1500_partner_healer_aptitude
		visit_holding_set_option_cooldown_worship_effect = { VAR = 1500_used_healer_recently }
		#Go back to Holy Site
		trigger_event = gdp_visit_holding_decision_event.1500
		ai_chance = {
			base = 50
			modifier = {
				short_term_gold < scope:1500_health_artifact.var:1065_accessory_value
				factor = 0
			}
		}
	}
	#Triggered Option: Your partner wants to try their hand at the procedure
	option = {
		name = gdp_visit_holding_decision_event.1501.c
		trigger = {
			scope:visiting_partner ?= { 
				OR = {
					learning >= 15
					has_trait = lifestyle_physician
					has_trait = lifestyle_mystic
					has_trait = witch
				}
				NOR = {
					has_treatable_disease_trigger = yes
					has_trait = wounded_1
					has_wounds_trigger = yes
				}
			}
			NOT = { exists = scope:1500_sickly_minor }
		}
		flavor = gdp_visit_holding_decision_event.1501.c.flavor
		#We're ill, roll for some treatment
		if = {
			limit = { 
				OR = {
					has_treatable_disease_trigger = yes
					has_trait = wounded_1
					has_wounds_trigger = yes
				}
			}
			1500_treatment_roll_effect = { TARGET_CHARACTER = root VARIABLE = var:1500_partner_healer_aptitude }
		}
		#Standard procedure health modifier
		else = {
			if = {
				limit = { has_character_modifier = gdp_visit_holding_healer_health_partner_modifier }
				hidden_effect = { remove_character_modifier = gdp_visit_holding_healer_health_partner_modifier }
			}
			add_character_modifier = {
				modifier = gdp_visit_holding_healer_health_partner_modifier
				days = visit_holding_cooldown_days
			}
		}
		progress_towards_friend_effect = {
			REASON = friend_allowed_to_treat
			CHARACTER = scope:visiting_partner
			OPINION = default_friend_opinion
		}
		scope:visiting_partner = {
			if = {
				limit = {
					NOT = { has_trait = lifestyle_physician }
				}
				add_trait = lifestyle_physician
			}
			else_if = {
				limit = {
					has_trait = lifestyle_physician
					has_trait_xp = {
						trait = lifestyle_physician
						value < 100
					}
				}
				add_trait_xp = {
					trait = lifestyle_physician
					value = 40
				}
			}
			else = {
				add_learning_skill = 1
			}
		}
		#Set the variables and redirect us back to the Holy Site
		scope:1500_health_artifact = { remove_variable ?= 1065_accessory_value }
		remove_variable ?= 1500_healer_aptitude
		remove_variable ?= 1500_partner_healer_aptitude
		visit_holding_set_option_cooldown_worship_effect = { VAR = 1500_used_healer_recently }
		#Go back to Holy Site
		trigger_event = gdp_visit_holding_decision_event.1500
		ai_chance = { base = 200 }
	}
	#Triggered Option: Your partner or sickly minor is ill
	option = {
		name = {
			text = gdp_visit_holding_decision_event.1501.d
			trigger = { exists = scope:1500_sickly_minor }
		}
		name = {
			text = gdp_visit_holding_decision_event.1501.d.partner
			trigger = { exists = scope:visiting_partner }
		}
		trigger = {
			OR = {
				scope:visiting_partner ?= { 
					OR = {
						has_treatable_disease_trigger = yes
						has_trait = wounded_1
						has_wounds_trigger = yes
					}
				}
				exists = scope:1500_sickly_minor
			}
			short_term_gold >= minor_gold_value
		}
		show_as_unavailable = {
			OR = {
				scope:visiting_partner ?= { 
					OR = {
						has_treatable_disease_trigger = yes
						has_trait = wounded_1
						has_wounds_trigger = yes
					}
				}
				exists = scope:1500_sickly_minor
			}
		}
		if = {
			limit = { exists = scope:1500_sickly_minor }
			1500_treatment_roll_effect = { TARGET_CHARACTER = scope:1500_sickly_minor VARIABLE = var:1500_healer_aptitude }
			progress_towards_friend_effect = {
				REASON = friend_got_treatment
				CHARACTER = scope:1500_sickly_minor
				OPINION = default_friend_opinion
			}
		}
		else = {
			1500_treatment_roll_effect = { TARGET_CHARACTER = scope:visiting_partner VARIABLE = var:1500_healer_aptitude }
			progress_towards_friend_effect = {
				REASON = friend_got_treatment
				CHARACTER = scope:visiting_partner
				OPINION = default_friend_opinion
			}
		}
		pay_short_term_gold = {
			target = scope:merchant_healer_character
			gold = minor_gold_value
		}	
		#Set the variables and redirect us back to the Holy Site
		scope:1500_health_artifact = { remove_variable ?= 1065_accessory_value }
		remove_variable ?= 1500_healer_aptitude
		remove_variable ?= 1500_partner_healer_aptitude
		visit_holding_set_option_cooldown_worship_effect = { VAR = 1500_used_healer_recently }
		#Go back to Holy Site
		trigger_event = gdp_visit_holding_decision_event.1500
		ai_chance = {
			base = 300
			modifier = {
				short_term_gold < minor_gold_value
				factor = 0
			}
		}
	}
	#I want to go back
	option = {
		name = gdp_visit_holding_decision_event.1501.e
		custom_tooltip = return_to_holy_site
		#Sets variables and takes us back to the church grounds screen
		#For desc flavor
		if = {
			limit = {
				NOT = { exists = scope:been_to_holy_site }
			}
			save_scope_as = been_to_holy_site
		}
		#Go back to Holy Site
		trigger_event = gdp_visit_holding_decision_event.1500
		ai_chance = { base = 100 }
	}
	after = {
		#What was our last location
		1500_update_last_location_effect = { LOCATION_FLAG = flag:healer }
	}
}

scripted_effect 1503_return_to_church_grounds_effect = {
	#Go back to church grounds
	hidden_effect = { 1501_return_to_holy_site_effect = yes }
}

scripted_effect 1500_set_holy_site_cooldown_effect = {
	visit_holding_set_option_cooldown_worship_effect = { VAR = 1500_used_holy_site_recently }
	hidden_effect = { 1501_return_to_holy_site_effect = yes }
}

#Not really into religion
scripted_trigger 1503_is_unzealous_trigger = {
	OR = {
		has_trait = cynical
		any_secret = { type = secret_non_believer }
	}
}

#No prisoners. No rivals. No service.
scripted_trigger 1510_basic_checks_trigger = {
	NOT = { 
		has_any_bad_relationship_with_character_trigger = { CHARACTER = root }
	}
	is_available_adult = yes
	#No double-dipping
	#Church
	trigger_if = {
		limit = { exists = scope:merchant_healer_character }
		this != scope:merchant_healer_character
	}
	trigger_if = {
		limit = { exists = scope:merchant_clergy_character }
		this != scope:merchant_clergy_character
	}
	trigger_if = {
		limit = { exists = scope:merchant_physician_recruit }
		this != scope:merchant_physician_recruit
	}
}

#Events that use this must write loc for tracker 0, 1, and 2
scripted_effect 1505_set_and_check_hub_loc_tracker_scope_effect = {
	if = {
		limit = {
			NOT = { exists = scope:$HUB$_loc_tracker }	#e.g. scope:church_grounds_loc_tracker
		}
		save_scope_value_as = {
			name = $HUB$_loc_tracker
			value = 0
		}
	}
	else_if = {
		limit = { scope:$HUB$_loc_tracker ?= 2 }
		save_scope_value_as = {
			name = $HUB$_loc_tracker
			value = 0
		}
	}
	else_if = {
		limit = { scope:$HUB$_loc_tracker ?= 0 }
		save_scope_value_as = {
			name = $HUB$_loc_tracker
			value = 1
		}
	}
	else = {
		save_scope_value_as = {
			name = $HUB$_loc_tracker
			value = 2
		}			
	}
}

#Visit Holy Site
gdp_visit_holding_decision_event.1503 = {
	type = character_event
	title = gdp_visit_holding_decision_event.1503.t
	window = visit_settlement_window
	desc = {
		#What are they up to?
		first_valid = {
			#We've returned to this scene, now what
			#RETURN: Generics
			random_valid = {
				triggered_desc = { 
					trigger = { 
						exists = scope:been_to_holy_site
						scope:holy_site_loc_tracker ?= 0
					}
					desc = gdp_visit_holding_decision_event.1503.desc_returned_01
				}
				triggered_desc = { 
					trigger = { scope:holy_site_loc_tracker ?= 1 }
					desc = gdp_visit_holding_decision_event.1503.desc_returned_02
				}
			}
			#FIRST TIME: We've seen this NunMonk before
			triggered_desc = {
				trigger = {
					exists = scope:merchant_recurring_clergy_character
					NOT = { exists = scope:been_to_holy_site }
				}
				desc = gdp_visit_holding_decision_event.1503.desc_reused_clergy
			}
			#FIRST TIME:
			triggered_desc = {
				trigger = {
					NOT = { exists = scope:been_to_holy_site }
				}
				desc = gdp_visit_holding_decision_event.1503.desc
			}	
		}
		#How about some theft
		first_valid = {
			#RETURN: Longing master thief
			triggered_desc = {
				trigger = {
					scope:visiting_partner ?= { has_court_position = fixer_court_position }
					exists = scope:been_to_holy_site
				}
				desc = gdp_visit_holding_decision_event.1503.desc_return_outro_thief
			}
			#RETURN: Outro
			triggered_desc = {
				trigger = { exists = scope:been_to_holy_site }
				desc = gdp_visit_holding_decision_event.1503.desc_return_outro
			}
			#FIRST TIME: Longing master thief
			triggered_desc = {
				trigger = {
					scope:visiting_partner ?= { has_court_position = fixer_court_position }
					NOT = { exists = scope:been_to_holy_site }
				}
				desc = gdp_visit_holding_decision_event.1503.desc_outro_thief
			}
			#FIRST TIME: Outro
			triggered_desc = {
				trigger = {
					NOT = { exists = scope:been_to_holy_site }
				}
				desc = gdp_visit_holding_decision_event.1503.desc_outro
			}
		}
	}
	theme = faith
	override_sound = { reference = "event:/MUSIC/Cues/Events/Sacral Happening/mx_cue_epic_sacral_moment" }
	override_background = { reference = temple }
	left_portrait = {
		trigger = { exists = scope:visiting_partner }
		character = scope:visiting_partner
		#Master thief
		triggered_animation = {
			trigger = { has_court_position = fixer_court_position }
			animation = scheme
		}
		#Unzealous
		triggered_animation = {
			trigger = { 1503_is_unzealous_trigger = yes }
			animation = personality_cynical
		}
		#Zealous
		triggered_animation = {
			trigger = {
				scope:visiting_partner = { has_trait = zealous }
			}
			animation = ecstasy
		}
		#Friendly
		triggered_animation = {
			trigger = { 
				scope:visiting_partner = { 1510_has_friendly_traits = yes } 
			}
			animation = interested
		}
		#Business-minded
		triggered_animation = {
			trigger = { 
				scope:visiting_partner = { 1510_has_commerce_traits = yes } 
			}
			animation = personality_greedy
		}
		#Uninterested
		triggered_animation = {
			trigger = { 
				scope:visiting_partner = { 1510_has_uninterested_traits = yes } 
			}
			animation = boredom
		}
		#Irrational
		triggered_animation = {
			trigger = { 
				scope:visiting_partner = { 1510_has_irrational_traits = yes } 
			}
			animation = personality_irrational
		}
		#A bit awkward
		triggered_animation = {
			trigger = { 
				scope:visiting_partner = { 1510_has_standoffish_traits = yes } 
			}
			animation = disapproval
		}
		animation = personality_honorable
	}
	center_portrait = {
		character = root
		triggered_animation = {
			trigger = { 1503_is_unzealous_trigger = yes }
			animation = disapproval
		}
		animation = personality_content
	}
	right_portrait = {
		character = scope:merchant_clergy_character
		animation = personality_forgiving
	}
	immediate = {
		#Can we _not_ repeat the loc?
		1505_set_and_check_scene_loc_tracker_scope_effect = { SCENE = holy_site }
		#For the background
		root.location.county.holder = { save_scope_as = bg_override_char }
		#Find our clergy
		if = {
			#Do we already have a clergy?
			limit = {
				NOT = { exists = scope:merchant_clergy_character }
			}
			#Has this person been our clergy in the past 10 years?
			random_pool_character = {
				province = root.location
				limit = {
					1510_basic_checks_trigger = yes
					faith = root.location.faith
					save_temporary_scope_as = saved_character_check
				}
				save_scope_as = merchant_clergy_character
				#Some more loc flavor shenanigans for these saved scopes
				save_scope_as = merchant_recurring_clergy_character
			}
			#Otherwise find a clergy in the pool
			if = {
				limit = { 
					NOT = { exists = scope:merchant_clergy_character }
				}
				random_pool_character = {
					province = root.location
					limit = { 
						1510_basic_checks_trigger = yes
						has_trait = devoted
						faith = root.location.faith
					}
					save_scope_as = merchant_clergy_character
				}
			}
			#Otherwise create a clergy
			if = {
				limit = {
					NOT = { exists = scope:merchant_clergy_character }
				}
				#Create clergy to stuff in pool
				create_character = {
					template = generic_peasant_character
					location = root.location
					dynasty = none
					trait = devoted
					culture = root.location.culture
					faith = root.location.faith
					save_scope_as = merchant_clergy_character
				}
			}
			#Remember the clerger
			1500_remember_character_effect = { GUILD = clergy CHARACTER = scope:merchant_clergy_character }
		}
		#How much gold is in the collect; and how difficult is it?
		if = {
			limit = {
				NOT = { exists = scope:1503_collect_gold_value }
			}
			#Randomize the initial value
			set_variable = {
				name = 1503_collect_gold_difficulty
				value = {
					integer_range = {
						min = 0
						max = 2
					}
				}
			}
			#Then add difficulty based on how much gold is in the collect
			random_list = {
				10 = {
					save_scope_value_as = {
						name = 1503_collect_gold_value
						value = minor_gold_value
					}
					change_variable = {
						name = 1503_collect_gold_difficulty
						add = 1
					}
				}
				10 = {
					save_scope_value_as = {
						name = 1503_collect_gold_value
						value = medium_gold_value
					}
					change_variable = {
						name = 1503_collect_gold_difficulty
						add = 2
					}
				}
				10 = {
					save_scope_value_as = {
						name = 1503_collect_gold_value
						value = major_gold_value
					}
					change_variable = {
						name = 1503_collect_gold_difficulty
						add = 3
					}
				}
			}
			#Did we go robbing a bunch of churches previously?
			if = {
				limit = { 
					has_variable = 1503_heightened_security
					exists = var:1503_collect_gold_difficulty
				}
				change_variable = {
					name = 1503_collect_gold_difficulty
					add = var:1503_heightened_security
				}

			}
			#Set the difficulty
			if = {
				limit = { exists = var:1503_collect_gold_difficulty }
				if = {
					limit = { var:1503_collect_gold_difficulty >= 5 }
					save_scope_value_as = {
						name = 1503_collect_gold_difficulty_rating
						value = monumentally_high_skill_rating
					}
				}
				else_if = {
					limit = { var:1503_collect_gold_difficulty = 4 }
					save_scope_value_as = {
						name = 1503_collect_gold_difficulty_rating
						value = extremely_high_skill_rating
					}
				}
				else_if = {
					limit = { var:1503_collect_gold_difficulty = 3 }
					save_scope_value_as = {
						name = 1503_collect_gold_difficulty_rating
						value = high_skill_rating
					}
				}
				else_if = {
					limit = { var:1503_collect_gold_difficulty = 2 }
					save_scope_value_as = {
						name = 1503_collect_gold_difficulty_rating
						value = medium_skill_rating
					}
				}
				else = {
					save_scope_value_as = {
						name = 1503_collect_gold_difficulty_rating
						value = low_skill_rating
					}
				}
			}
		}
	}
	#Donate some gold for piety
	option = {
		name = gdp_visit_holding_decision_event.1503.a
		trigger = {
			short_term_gold >= minor_gold_value
		}
		show_as_unavailable = { always = yes }
		flavor = {
			first_valid = {
				triggered_desc = {
					trigger = { 1503_is_unzealous_trigger = yes }
					desc = gdp_visit_holding_decision_event.1503.a.flavor_unzealous
				}
			}
		}
		if = {
			limit = { NOT = { exists = var:visit_settlement_holy_site_donation } }
			set_variable = {
				name = visit_settlement_holy_site_donation
				value = 1 
				days = visit_holding_cooldown_days
			}
		}
		else = {
			set_local_variable = {
				name = visit_settlement_holy_site_donation_temp
				value = var:visit_settlement_church_donation
			}
			set_variable = {
				name = visit_settlement_holy_site_donation
				days = visit_holding_cooldown_days
				value = {
					value = local_var:visit_settlement_holy_site_donation_temp
					add = 1
				}
			}
		}
		#Pay gold, feel more pious
		pay_short_term_gold = {
			target = scope:merchant_clergy_character
			gold = minor_gold_value
		}
		add_piety = visit_settlement_piety_gain_value
		#Roll for epiphanous clergy
		hidden_effect = {
			scope:merchant_clergy_character = {
				random_list = {
					95 = {
						modifier = { 
							has_trait = possessed_1
							factor = 0.5
						}
						#Nothing happens
					}
					5 = {
						modifier = {
							piety_level = high_piety_level
							add = 5
						}
						modifier = {
							piety_level = very_high_piety_level
							add = 5
						}
						modifier = {
							piety_level = max_piety_level
							add = 5
						}
						set_variable = 1503_is_epiphanous
					}
				}
			}
		}	
		stress_and_fulfillment_impact = {
			greedy = minor_stress_impact_gain
			zealous = minor_stress_impact_loss
			generous = minor_stress_impact_loss
			improvident = medium_stress_impact_loss #Throw 'em a bone
		}
		trigger_event = gdp_visit_holding_decision_event.1504
		ai_chance = {
			base = 100
			modifier = {
				has_trait = greedy
				factor = 0
			}
			modifier = {
				short_term_gold < minor_gold_value
				factor = 0
			}
		}
	}
	#Ask for blessing
	option = {
		name = gdp_visit_holding_decision_event.1503.b
		trigger = {
			NOR = { 
				has_character_modifier = laamp_decision_church_blessing_stress_loss_modifier
				has_character_modifier = laamp_decision_church_blessing_stress_gain_modifier
				piety_level < low_piety_level
			}
		}
		show_as_unavailable = { always = yes }
		reason = piety
		#Pokémon blue?
		add_character_modifier = {
			modifier = laamp_decision_church_blessing_stress_loss_modifier
			years = 5
		}
		#Set the variables and redirect us back to the Church Grounds
		1500_set_holy_site_cooldown_effect = yes
		ai_chance = {
			base = 200
			modifier = {
				piety_level > medium_piety_level
				add = 300
			}
		}
	}
	#'Borrow' gold from the collect
	option = {
		name = {
			text = {
				first_valid = {
					triggered_desc = {
						trigger = {
							scope:visiting_partner ?= { has_court_position = fixer_court_position }
						}
						desc = gdp_visit_holding_decision_event.1503.c_master_thief
					}
					triggered_desc = {
						trigger = { has_variable = 1503_heightened_security }
						desc = gdp_visit_holding_decision_event.1503.c_guarded
					}
					desc = gdp_visit_holding_decision_event.1503.c
				}
			}
		}
		trigger = { is_ai = no }
		flavor = {
			first_valid = {
				triggered_desc = {
					trigger = { 
						has_variable = 1503_heightened_security
						var:1503_heightened_security != 0
					}
					desc = gdp_visit_holding_decision_event.1503.c.flavor_guarded
				}
				desc = gdp_visit_holding_decision_event.1503.c.flavor
			}
		}
		duel = {
			skill = intrigue
			value = scope:1503_collect_gold_difficulty_rating
			#Success: Coin!
			50 = {
				modifier = {
					scope:visiting_partner ?= { has_court_position = fixer_court_position }
					factor = 2
				}
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				min = 10
				desc = gdp_visit_holding_decision_event.1503.c.thievery_success.desc
				send_interface_toast = {
					title = gdp_visit_holding_decision_event.1503.c.thievery_success.t
					left_icon = root
					add_gold = scope:1503_collect_gold_value
				}
				hidden_effect = {
					#... fool me twice; shame on you.
					if = {
						limit = { has_variable = 1503_heightened_security }
						random_list = {
							50 = {
								#Nothing
							}
							50 = {
								#Save old value as temp
								set_variable = {
									name = 1503_heightened_security_temp
									value = var:1503_heightened_security
								}
								#Remove the variable we'll refresh
								remove_variable ?= 1503_heightened_security
								#Set the new proper variable and add the old value as well
								set_variable = {
									name = 1503_heightened_security
									value = {
										value = var:1503_heightened_security_temp
										add = 1
									}
									days = visit_holding_cooldown_days
								}
								#Then remove the temp
								remove_variable ?= 1503_heightened_security_temp
							}
						}
					}
					#Fool me once, shame on me...
					else = {
						set_variable = {
							name = 1503_heightened_security
							value = 0
							days = visit_holding_cooldown_days
						}
					}
				}
			}
			#Failure: Banished!
			50 = {
				modifier = {
					scope:visiting_partner ?= { has_court_position = fixer_court_position }
					factor = 0.5
				}
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -20
				}
				desc = gdp_visit_holding_decision_event.1503.c.thievery_failure.desc
				send_interface_toast = {
					type = event_toast_text_bad
					title = gdp_visit_holding_decision_event.1503.c.thievery_failure.t
					desc = gdp_visit_holding_decision_event.1503.c.thievery_failure.desc
					left_icon = root
					custom_tooltip = gdp_visit_holding_decision_event.1501.return.tt
					#Shame on you
					add_piety = medium_piety_loss
				}
				#You will not be going back to the church any time soon
				visit_holding_set_option_cooldown_worship_effect = { VAR = 1500_caught_stealing }
			}
			#Critical Failure: The local guards are summoned
			10 = {
				trigger = {
					trigger_if = {
						limit = { exists = scope:visiting_partner }
						NOT = { 
							scope:visiting_partner = { has_court_position = fixer_court_position } 
						}
					}
					trigger_else = { always = yes }
				}
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
				}	
				min = 5
				desc = gdp_visit_holding_decision_event.1503.c.thievery_critical_failure.desc
				send_interface_toast = {
					title = gdp_visit_holding_decision_event.1503.c.thievery_critical_failure.t
					left_icon = root
					#Quite the tussle
					increase_wounds_effect = { REASON = fight }
					#Shame on you
					add_piety = minor_piety_loss
				}	
				#You will not be going back to the church any time soon
				visit_holding_set_option_cooldown_worship_effect = { VAR = 1500_caught_stealing }
			}
		}
		#Super-stressful for honest characters and zealous characters, IF you share faith
		if = {
			limit = { root.location.county.faith = root.faith }
			stress_and_fulfillment_impact = {
				honest = major_stress_impact_gain
				zealous = major_stress_impact_gain
				deceitful = minor_stress_impact_loss
				greedy = minor_stress_impact_loss
			}
		}
		else = {
			stress_and_fulfillment_impact = {
				honest = major_stress_impact_gain
				deceitful = minor_stress_impact_loss
			}
		}
		#Set the variables and redirect us back to the Holy Site
		1503_return_to_church_grounds_effect = yes
	}
	#I want to go back
	option = {
		name = gdp_visit_holding_decision_event.1503.d
		#Sets variables and takes us back to the holy site screen
		#For desc flavor
		if = {
			limit = {
				NOT = { exists = scope:been_to_holy_site }
			}
			save_scope_as = been_to_holy_site
		}
		1501_return_to_holy_site_effect = yes
		ai_chance = { base = 200 }
	}
	after = {
		#What was our last location
		1500_update_last_location_effect = { LOCATION_FLAG = flag:church }
	}
}

#Post-Donation
gdp_visit_holding_decision_event.1504 = {
	type = character_event
	title = gdp_visit_holding_decision_event.1504.t
	window = visit_settlement_window
	desc = {
		first_valid = {
			#Strange person thinks you're a reincarnation or something? Why not.
			triggered_desc = {
				trigger = {
					scope:merchant_clergy_character = { has_variable = 1503_is_epiphanous }
				}
				desc = gdp_visit_holding_decision_event.1504.desc_epiphany
			}
			desc = gdp_visit_holding_decision_event.1504.desc
		}
	}
	theme = faith
	override_sound = {
		trigger = {
			scope:merchant_clergy_character = { has_variable = 1503_is_epiphanous }
		}
		reference = "event:/DLC/FP4/MUSIC/Stingers/mx_stinger_legends_lvl_03" 
	}
	override_sound = { reference = "event:/MUSIC/Cues/Events/Low Key Positive/mx_cue_low_key_postive" }
	override_background = { reference = temple }
	override_effect_2d = {
		trigger = { 
			scope:merchant_clergy_character = { has_variable = 1503_is_epiphanous }
		}
		reference = legend_glow
	}
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = { 
				scope:merchant_clergy_character = { has_variable = 1503_is_epiphanous }
			}
			animation = disbelief
		}
		triggered_animation = {
			trigger = { 1503_is_unzealous_trigger = yes }
			animation = shock
		}
		animation = admiration
	}
	right_portrait = {
		character = scope:merchant_clergy_character
		triggered_animation = {
			trigger = { has_variable = 1503_is_epiphanous }
			animation = shock
		}
		animation = happiness
	}
	#Do we have someone to display?
	lower_left_portrait = {
		trigger = { exists = scope:visiting_partner }
		character = scope:visiting_partner
	}
	immediate = {
		hidden_effect = {
			scope:merchant_clergy_character = {
				if = {
					limit = { has_variable = 1503_is_epiphanous }
					add_trait = loyal
					add_trait = holy_warrior
				}
			}
		}
	}
	#Ask for blessing
	option = {
		name = {
			text = {
				first_valid = {
					triggered_desc = {
						trigger = {
							scope:merchant_clergy_character = { has_variable = 1503_is_epiphanous }
						}
						desc = gdp_visit_holding_decision_event.1504.a_epiphany
					}
					desc = gdp_visit_holding_decision_event.1504.a
				}
			}
		}
		trigger = {
			NOR = { 
				has_character_modifier = laamp_decision_church_blessing_stress_loss_modifier
				has_character_modifier = laamp_decision_church_blessing_stress_gain_modifier
				piety_level < low_piety_level
			}
		}
		show_as_unavailable = { always = yes }
		reason = piety
		#Or Pokémon red?
		add_character_modifier = {
			modifier = laamp_decision_church_blessing_stress_gain_modifier
			years = 5
		}	
		ai_chance = {
			base = 100
			modifier = {
				piety_level > medium_piety_level
				add = 300
			}
		}
	}
	#Triggered Option: Clergy Person wants to join your company
	option = {
		name = gdp_visit_holding_decision_event.1504.b
		trigger = {
			scope:merchant_clergy_character = { has_variable = 1503_is_epiphanous }
		}
		add_courtier = scope:merchant_clergy_character
		hidden_effect = {
			reverse_add_opinion = {
				target = scope:merchant_clergy_character
				modifier = recruited_me_opinion
				opinion = 50
			}
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = paranoid
				factor = 0
			}
		}
	}
	#Nah
	option = {
		name = {
			text = {
				first_valid = {
					triggered_desc = {
						trigger = {
							scope:merchant_clergy_character = { has_variable = 1503_is_epiphanous }
						}
						desc = gdp_visit_holding_decision_event.1504.c_epiphany
					}
					desc = gdp_visit_holding_decision_event.1504.c
				}
			}
		}
		#Tooltip so we know where we're going
		custom_tooltip = gdp_visit_holding_decision_event.1501.return.tt
		ai_chance = {
			base = 100
		}
	}
	after = {
		#Set the variables and redirect us back to the Holy Site
		1500_set_holy_site_cooldown_effect = yes
	}
}

#Set the correct variable to block off the Garden option and remove the desc flavor variable
scripted_effect 1505_gardened_effect = {
	visit_holding_set_option_cooldown_worship_effect = { VAR = 1500_used_garden_recently }
	#Go back to church grounds
	hidden_effect = { 1501_return_to_holy_site_effect = yes }
}

#Right?
scripted_trigger 1505_probably_knows_gardening_trigger = {
	OR = {
		has_trait = lifestyle_gardener
		has_trait = lifestyle_herbalist
		learning > high_skill_rating
	}	
}

scripted_trigger 1505_could_harvest_garden_trigger = {
	OR = {
		trigger_if = {
			limit = { exists = scope:visiting_partner }
			scope:visiting_partner = { 1505_probably_knows_gardening_trigger = yes }
		}
		1505_probably_knows_gardening_trigger = yes
	}
}

#Ditto
scripted_trigger 1505_could_unwind_in_garden_trigger = {
	scope:visiting_partner ?= { 
		OR = {
			AND = {
				has_relation_potential_lover = root
				root = { might_cheat_on_every_partner_trigger = yes }
			}
			has_relation_lover = root 
		}
	}
}


#Visit Garden
gdp_visit_holding_decision_event.1505 = {
	type = character_event
	title = gdp_visit_holding_decision_event.1505.t
	window = visit_settlement_window
	desc = {
		#What's going down in the garden
		first_valid = {
			#We've returned to this scene, now what
			#RETURN: Generics
			random_valid = {
				triggered_desc = { 
					trigger = { 
						exists = scope:been_to_garden
						scope:garden_loc_tracker ?= 0
					}
					desc = gdp_visit_holding_decision_event.1505.desc_returned_01
				}
				triggered_desc = { 
					trigger = { scope:garden_loc_tracker ?= 1 }
					desc = gdp_visit_holding_decision_event.1505.desc_returned_02
				}
			}
			#FIRST TIME:
			triggered_desc = {
				trigger = {
					NOT = { exists = scope:been_to_garden }
				}
				desc = gdp_visit_holding_decision_event.1505.desc
			}	
		}
		#Hey look, some plants
		first_valid = {
			#RETURN: Still partner plants
			triggered_desc = {
				trigger = {
					scope:visiting_partner ?= { 1505_probably_knows_gardening_trigger = yes }
					exists = scope:been_to_garden
				}
				desc = gdp_visit_holding_decision_event.1505.desc_outro_return_partner
			}
			#RETURN: Still plants
			triggered_desc = {
				trigger = {
					1505_probably_knows_gardening_trigger = yes
					exists = scope:been_to_garden
				}
				desc = gdp_visit_holding_decision_event.1505.desc_outro_return_gardener
			}
			#FIRST TIME: Partner PLAAANTSSS
			triggered_desc = {
				trigger = {
					scope:visiting_partner ?= { 1505_probably_knows_gardening_trigger = yes }
					NOT = { exists = scope:been_to_garden }
				}
				desc = gdp_visit_holding_decision_event.1505.desc_outro_partner
			}
			#FIRST TIME: PLAAANTSSS
			triggered_desc = {
				trigger = {
					1505_probably_knows_gardening_trigger = yes
					NOT = { exists = scope:been_to_garden }
				}
				desc = gdp_visit_holding_decision_event.1505.desc_outro_gardener
			}
		}
	}
	theme = faith
	override_sound = { reference = "event:/SFX/Events/Themes/sfx_event_theme_type_health_good" }
	override_background = { reference = garden }
	left_portrait = {
		trigger = { exists = scope:visiting_partner }
		character = scope:visiting_partner
		triggered_animation = {
			trigger = {
				NOT = { has_variable = 1505_has_harvested_recently }
				1505_probably_knows_gardening_trigger = yes 
			}
			animation = survey
		}
		animation = happiness
	}
	center_portrait = {
		character = root
		triggered_animation = {
			trigger = {
				NOT = { has_variable = 1505_has_harvested_recently }
				scope:visiting_partner ?= { 1505_probably_knows_gardening_trigger = yes }
			}
			animation = interested
		}
		triggered_animation = {
			trigger = { 1505_probably_knows_gardening_trigger = yes }
			animation = survey
		}
		triggered_animation = {
			trigger = { faith != root.location.faith }
			animation = stress
		}
		animation = thinking
	}
	immediate = {
		#Can we _not_ repeat the loc?
		1505_set_and_check_scene_loc_tracker_scope_effect = { SCENE = garden }
		#For the background
		root.location.county.holder = { save_scope_as = bg_override_char }
	}
	#Convert / contemplate faith
	option = {
		name = {
			text = {
				first_valid = {
					#Convert to faith
					triggered_desc = {
						trigger = { 
							faith != root.location.faith
						}
						desc = gdp_visit_holding_decision_event.1505.a_convert
					}
					#Contemplate faith
					desc = gdp_visit_holding_decision_event.1505.a
				}
			}
		}
		trigger = {
			custom_tooltip = {
				text = gdp_visit_holding_decision_event.1505.a.cooldown.tt
				NOT = { has_variable = 1505_contemplated_garden_recently }
			}	
		}
		#Convert
		if = {
			limit = { faith != root.location.faith }
			set_character_faith = root.location.faith
			if = {
				limit = {
					root.location.faith = { has_doctrine = doctrine_monotheist }
				}
				custom_description_no_bullet = { text = mandala_monotheist_warning_tt }
			}
			stress_and_fulfillment_impact = {
				base = minor_stress_impact_loss
				zealous = major_stress_impact_gain
			}
		}
		#Contemplate faith
		else = {
			stress_and_fulfillment_impact = {
				base = medium_stress_impact_loss
				content = minor_stress_impact_loss
				zealous = medium_stress_impact_loss
			}
		}
		#Cooldown for the action
		set_variable = {
			name = 1505_contemplated_garden_recently
			days = visit_holding_cooldown_days
		}
		#Set the variables and redirect us back to the Church Grounds
		1505_gardened_effect = yes
		ai_chance = { 
			base = 100
			modifier = {
				faith != root.location.faith
				has_trait = zealous
				factor = 0
			}
			modifier = {
				faith != root.location.faith
				any_secret ?= { secret_type = secret_non_believer }
				add = 300
			}
		}
	}
	#Triggered Option: Those plants look edible
	option = {
		name = {
			text = {
				first_valid = {
					#Gardener friend
					triggered_desc = {
						trigger = { 
							scope:visiting_partner ?= { 1505_probably_knows_gardening_trigger = yes }
						}
						desc = gdp_visit_holding_decision_event.1505.b_partner
					}
					#Gardener self
					desc = gdp_visit_holding_decision_event.1505.b
				}
			}
		}
		trigger = {
			trigger_if = {
				limit = { has_variable = 1505_has_harvested_recently }
				custom_tooltip = {
					text = gdp_visit_holding_decision_event.1505.b.cooldown.tt
					always = no 
				}	
			}
			trigger_else = { 1505_could_harvest_garden_trigger = yes }	
		}
		show_as_unavailable = {
			#Only show it if you could've actually done it
			trigger_if = {
				limit = { 1505_could_harvest_garden_trigger = yes }
				always = yes
			}
			trigger_else = { always = no }
		}
		add_gold = minor_gold_value
		#Probably holy somewhere
		if = {
			limit = {
				faith = {
					OR = {
						has_tenet = tenet_sanctity_of_nature
						trait_is_virtue = lifestyle_gardener
						trait_is_virtue = lifestyle_herbalist					
					}
				}
			}
			add_piety = medium_piety_gain
		}
		#Cooldown for the action
		set_variable = {
			name = 1505_has_harvested_recently
			days = visit_holding_cooldown_days
		}
		#Set the variables and redirect us back to the Church Grounds
		1505_gardened_effect = yes
		ai_chance = {
			base = 1000 #Just do it
		}
	}
	#Triggered Option: Stress relief? Stress relief.
	option = {
		name = gdp_visit_holding_decision_event.1505.c
		trigger = {
			trigger_if = {
				limit = { has_variable = 1505_garden_unwinded_recently }
				custom_tooltip = {
					text = gdp_visit_holding_decision_event.1505.c.cooldown.tt
					always = no 
				}	
			}
			trigger_else = { 1505_could_unwind_in_garden_trigger = yes }	
		}
		show_as_unavailable = {
			#Only show it if you could've actually done it
			trigger_if = {
				limit = { 1505_could_unwind_in_garden_trigger = yes }
				always = yes
			}
			trigger_else = { always = no }
		}
		#Stress relief
		had_sex_with_effect = { CHARACTER = scope:visiting_partner PREGNANCY_CHANCE = pregnancy_chance }
		progress_towards_lover_effect = {
			CHARACTER = scope:visiting_partner
			REASON = lover_contemplative_sex
			OPINION = default_lover_opinion
		}
		#Probably holy to some?
		if = {
			limit = {
				faith = { has_tenet = tenet_carnal_exaltation }
			}
			add_piety = medium_piety_gain
		}
		#Or not
		else_if = {
			limit = {
				faith = {
					OR = {
						trait_is_sin = lustful
						trait_is_sin = rakish
						trait_is_sin = seducer
					}
				}
			}
			add_piety = minor_piety_loss
		}
		#Cooldown for the action
		set_variable = {
			name = 1505_garden_unwinded_recently
			days = visit_holding_cooldown_days
		}
		#Stress loss with some factors
		stress_and_fulfillment_impact = {
			base = medium_stress_impact_loss
			rakish = medium_stress_impact_loss
			seducer = minor_stress_impact_loss
			lustful = minor_stress_impact_loss
			paranoid = minor_stress_impact_gain
			chaste = minor_stress_impact_gain
		}
		#Set the variables and redirect us back to the Church Grounds
		1505_gardened_effect = yes
		ai_chance = {
			base = 100
			modifier = {
				has_trait = lustful
				add = 500
			}
			modifier = {
				has_trait = rakish
				add = 500
			}
			modifier = {
				has_trait = chaste
				factor = 0
			}
		}
	}
	#I want to go back
	option = {
		name = gdp_visit_holding_decision_event.1505.d
		#Everything is on cooldown, I guess
		if = {
			limit = {
				has_variable = 1505_contemplated_garden_recently
				trigger_if = {
					limit = { 1505_could_harvest_garden_trigger = yes }
					has_variable = 1505_has_harvested_recently
				}
				trigger_if = {
					limit = { 1505_could_unwind_in_garden_trigger = yes }
					has_variable = 1505_garden_unwinded_recently
				}
			}
			1505_gardened_effect = yes
		}
		else = {
			#Sets variables and returns us to church grounds screen
			1501_been_to_effect = { GUILD = garden }
			#For desc flavor
			if = {
				limit = {
					NOT = { exists = scope:been_to_garden }
				}
				save_scope_as = been_to_garden
			}
			1501_return_to_holy_site_effect = yes
		}
		ai_chance = { base = 100 }
	}
	after = {
		#What was our last location
		1500_update_last_location_effect = { LOCATION_FLAG = flag:garden }
	}
}

#Hire the Physician, show/set the effects and variables 
scripted_effect 1507_hire_physician_effect = {
	hidden_effect = {
		reverse_add_opinion = {
			target = scope:merchant_physician_recruit
			modifier = recruited_me_opinion
			opinion = 50
		}
	}
	add_courtier = scope:merchant_physician_recruit
	#The actual effect happens in after
	show_as_tooltip = { 
		court_position_grant_effect = {
			EMPLOYER = root
			POS = court_physician
			CANDIDATE = scope:merchant_physician_recruit
		}
	}
	#This 'finished' is different since it changes between flag:yes and flag:no
	save_scope_value_as = {
		name = merchant_decision_recruited_physician
		value = flag:yes
	}
	#Go back to church grounds
	hidden_effect = { 1501_return_to_holy_site_effect = yes }
}


#Visit Physician
gdp_visit_holding_decision_event.1507 = {
	type = character_event
	title = gdp_visit_holding_decision_event.1507.t
	window = visit_settlement_window
	desc = {
		#What're they doing?
		first_valid = {
			#We've returned to this scene, now what
			#RETURN:
			random_valid = {
				triggered_desc = { 
					trigger = { 
						exists = scope:been_to_physician
						scope:physician_loc_tracker ?= 0
					}
					desc = gdp_visit_holding_decision_event.1507.desc_returned_01
				}
				triggered_desc = { 
					trigger = { scope:physician_loc_tracker ?= 1 }
					desc = gdp_visit_holding_decision_event.1507.desc_returned_02
				}
				triggered_desc = { 
					trigger = { scope:physician_loc_tracker ?= 2 }
					desc = gdp_visit_holding_decision_event.1507.desc_returned_03
				}
			}
			#FIRST TIME: We've seen this physician before
			triggered_desc = {
				trigger = {
					exists = scope:merchant_recurring_physician
					NOT = { exists = scope:been_to_physician }
				}
				desc = gdp_visit_holding_decision_event.1507.desc_reused_physician
			}
			#FIRST TIME:
			triggered_desc = {
				trigger = {
					NOT = { exists = scope:been_to_physician }
				}
				desc = gdp_visit_holding_decision_event.1507.desc
			}	
		}
	}
	theme = learning
	override_sound = { reference = "event:/MUSIC/Cues/Events/Positive/mx_cue_postive_effect" }
	override_background = { reference = location_study }
	left_portrait = {
		trigger = { exists = scope:visiting_partner }
		character = scope:visiting_partner
		triggered_animation = {
			trigger = { 1501_physician_partner_trigger = yes }
			animation = interested
		}
		animation = personality_compassionate
	}
	center_portrait = {
		character = root
		animation = personality_rational
	}
	right_portrait = {
		character = scope:merchant_physician_recruit
		camera = camera_event_scheme_far_right
		animation = reading
	}
	immediate = {
		#Can we _not_ repeat the loc?
		1505_set_and_check_hub_loc_tracker_scope_effect = { HUB = physician }
		#Hide the physician from the third portrait, since they have moved to their study
		if = {
			limit = { scope:1500_third_character = scope:merchant_physician_recruit }
			#Overwrite with ROOT to block off the portrait
			save_scope_as = 1500_third_character
			#Remember the bodyguard
			1500_remember_character_effect = { GUILD = physician CHARACTER = scope:merchant_physician_recruit }
		}
	}
	#Pay gold
	option = {
		name = gdp_visit_holding_decision_event.1507.a
		trigger = {
			short_term_gold >= visit_holding_associate_physician_gold_value
		}
		show_as_unavailable = { short_term_gold < visit_holding_associate_physician_gold_value }
		pay_short_term_gold = {
			target = scope:merchant_physician_recruit
			gold = visit_holding_associate_physician_gold_value
		}
		#Wrap effect to hire 'em, set scope & return to church
		1507_hire_physician_effect = yes
		ai_chance = {
			base = 100 
			modifier = {
				short_term_gold < visit_holding_associate_physician_gold_value
				factor = 0
			}
		}
	}
	#Have x piety
	option = {
		name = gdp_visit_holding_decision_event.1507.b
		trigger = { piety >= 1000 }
		show_as_unavailable = { piety < 1000 }
		reason = piety
		#Wrap effect to hire 'em, set scope & return to church
		1507_hire_physician_effect = yes
		ai_chance = {
			base = 1000 #Just do it
		}
	}
	#Learning duel
	option = {
		name = gdp_visit_holding_decision_event.1507.c
		duel = {
			skill = learning
			value = average_skill_rating
			#Success: Hire 'em up
			50 = {		
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				modifier = {
					OR = {
						has_trait = erudite
						has_trait = whole_of_body
						has_trait = crusader_king
					}
					factor = 2
				}
				desc = gdp_visit_holding_decision_event.1507.c.success
				send_interface_toast = {
					title = gdp_visit_holding_decision_event.1507.c.success
					left_icon = root
					right_icon = scope:merchant_physician_recruit
					#Yippee!
					1507_hire_physician_effect = yes
				}
			}
			#Failure: Bye, now
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -20
				}
				modifier = {
					has_trait = zealous
					factor = 0.5
				}
				desc = gdp_visit_holding_decision_event.1507.c.failure
				send_interface_toast = {
					type = event_toast_text_bad
					title = gdp_visit_holding_decision_event.1507.c.failure
					desc = gdp_visit_holding_decision_event.1507.c.failure.tt
					left_icon = root
					right_icon = scope:merchant_physician_recruit
					#Oh well
					custom_tooltip = gdp_visit_holding_decision_event.1507.c.failure.tt
					#This 'finished' is different since it changes between flag:yes and flag:no
					save_scope_value_as = {
						name = merchant_decision_recruited_physician
						value = flag:no
					}
					1501_return_to_holy_site_effect = yes
				}
			}
		}
		ai_chance = {
			base = 100
			modifier = {
				piety >= 1000
				factor = 0
			}
		}
	}
	#I want to go back
	option = {
		name = gdp_visit_holding_decision_event.1507.d
		#Sets variables and returns us to church grounds screen
		1501_been_to_effect = { GUILD = physician }
		1501_return_to_holy_site_effect = yes
		ai_chance = {
			base = 100
			modifier = {
				employs_court_position = court_physician_court_position
				factor = 2
			}
		}
	}
	after = {
		if = {
			limit = { scope:merchant_decision_recruited_physician ?= flag:yes }
			#Appoint them
			if = {
				limit = {
					can_appoint_char_to_court_position = {
						CHAR = scope:merchant_physician_recruit
						COURT_POS = court_physician_court_position
					}
				}
				court_position_grant_effect = {
					EMPLOYER = root
					POS = court_physician
					CANDIDATE = scope:merchant_physician_recruit
				}
			}
		}
		#What was our last location
		1500_update_last_location_effect = { LOCATION_FLAG = flag:physician }
	}
}
