﻿ttd_visit_nearby_realm = {
	category = interaction_category_diplomacy
	desc = ttd_visit_nearby_realm_desc
	icon = travel_leader_court_position
	common_interaction = yes
	interface_priority = 1000
	
	ai_frequency = 0 # Never
	use_diplomatic_range = yes

 #	cooldown = { years = 10 }

	ai_min_reply_days = 0
	ai_max_reply_days = 0

 #	auto_accept = yes

	is_shown = {
		NOT = { scope:recipient = scope:actor }
		scope:actor = {
			is_ai = no
		 	is_landed = yes
			highest_held_title_tier >= 2
			NOT = { has_variable = ttd_far_off_location }
		 #	NOT = { government_has_flag = government_is_administrative }
		}
		scope:recipient = {
			is_landed = yes
		 	is_independent_ruler = yes
		 #	government_has_flag = government_is_administrative
			highest_held_title_tier >= 5
		}
	}
	is_valid_showing_failures_only = {
		scope:actor = {
			is_available_adult = yes
			is_at_war = no
			custom_tooltip = {
				text = pdi_is_in_debt
				gold >= 0
			}
			custom_tooltip = {
				text = activity_pilgrimage.serving_diarch
				bannable_serving_diarch_trigger = no
			}
			NOT = { has_trait = pregnant }
			health >= 1.5
			NOT = { is_vassal_or_below_of = scope:recipient }
			NOT = { highest_held_title_tier >= 5 }
		}
		scope:recipient = {
			capital_province.county = { development_level >= 25 }
		}
	}

	on_accept = {
		scope:actor = {
			custom_tooltip = { text = gpt_visit_tip_0 }
			custom_tooltip = { text = gpt_visit_tip_00 }
			custom_tooltip = { text = gpt_visit_tip_1 }
			custom_tooltip = { text = gpt_visit_tip_2 }
			custom_tooltip = { text = gpt_visit_tip_3 }
			custom_tooltip = { text = gpt_visit_tip_00 }
			custom_tooltip = { text = gpt_visit_tip_4 }
			stress_impact = {
				shy = 20
				craven = 20
				lazy = 10
				honest = 10
			}
		}
		scope:actor = {
		 #	add_character_flag = gpt_lifetime_visit
			add_character_flag = {
				flag = ttd_nearby_realm
				years = 5 # So it will eventually go away if travel plan somehow gets cancelled
			}
			set_variable = {
				name = ttd_far_off_target
				value = scope:recipient
				years = 5 # So it will eventually go away if travel plan somehow gets cancelled
			}
			set_variable = {
				name = ttd_far_off_location
				value = scope:recipient.capital_province
				years = 5 # So it will eventually go away if travel plan somehow gets cancelled
			}
			start_travel_plan = {
				destination = var:ttd_far_off_location
				on_travel_planner_cancel_event = tdd_visit_far_off_realm_events.1001
				on_arrival_event = tdd_visit_far_off_realm_events.1002
				on_arrival_destinations = all_but_last
			}
		}
	}

	ai_accept = {
		base = 25
		
		opinion_modifier = { # Opinion Factor
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 1
			desc = AI_OPINION_REASON
		}

		modifier = { #Faith compatibility
			scope:recipient.faith = {
				faith_hostility_level = {
					target = scope:actor.faith
					value > faith_fully_accepted_level
				}
			}
			add = {
				value = 0
				if = {
					limit = {
						scope:recipient.faith = {
							faith_hostility_level = {
								target = scope:actor.faith
								value >= faith_astray_level
							}
						}
					}
					subtract = 10
				}
				if = {
					limit = {
						scope:recipient.faith = {
							faith_hostility_level = {
								target = scope:actor.faith
								value >= faith_hostile_level
							}
						}
					}
					subtract = 10
				}
				if = {
					limit = {
						scope:recipient.faith = {
							faith_hostility_level = {
								target = scope:actor.faith
								value >= faith_evil_level
							}
						}
					}
					subtract = 10
				}
			}
			desc = MARRY_DIFFERENT_FAITH_REASON
		}

		modifier = { # Shared Court Language (non-spoken)
			add = 15
			desc = foreign_realm_court_language_non_spoken_interaction_reason
			trigger = {
				scope:actor = {
					has_royal_court = yes
					NOT = { knows_court_language_of = this }
				}
				NOT = {
					scope:actor.top_liege = scope:recipient.top_liege
				}
				OR = {
					AND = {
						scope:recipient = {
							has_royal_court = yes
						}
						scope:actor = { # You share Court Language
							has_same_court_language = scope:recipient
						}
					}
					
					scope:recipient = { # The recipient doesn't have a royal court, but their liege does
						is_independent_ruler = no
						has_royal_court = no
						liege = {
							has_royal_court = yes
							has_same_court_language = scope:actor
						}
					}
					scope:recipient = { # The recipient doesn't have a royal court, but their liege's liege does, while their liege doesn't have a royal court
						is_independent_ruler = no
						has_royal_court = no
						exists = liege.liege
						liege = {
							is_independent_ruler = no
							has_royal_court = no
						}
						liege.liege = {
							has_royal_court = yes
							has_same_court_language = scope:actor
						}
					}
					scope:recipient = { # The recipient doesn't have a royal court, but their liege's liege's liege does, while their liege doesn't have a royal court
						is_independent_ruler = no
						has_royal_court = no
						exists = liege.liege
						exists = liege.liege.liege
						liege = {
							is_independent_ruler = no
							has_royal_court = no
						}
						liege.liege = {
							is_independent_ruler = no
							has_royal_court = no
						}
						liege.liege.liege = {
							has_royal_court = yes
							has_same_court_language = scope:actor
						}
					}
					scope:recipient = { # The recipient doesn't have a royal court, but their liege's liege's liege's liege does, while their liege doesn't have a royal court
						is_independent_ruler = no
						has_royal_court = no
						exists = liege.liege
						exists = liege.liege.liege
						exists = liege.liege.liege.liege
						liege = {
							is_independent_ruler = no
							has_royal_court = no
						}
						liege.liege = {
							is_independent_ruler = no
							has_royal_court = no
						}
						liege.liege.liege = {
							is_independent_ruler = no
							has_royal_court = no
						}
						liege.liege.liege.liege = {
							has_royal_court = yes
							has_same_court_language = scope:actor
						}
					}
				}
			}
		}
		
		modifier = { # Shared Court Language (spoken)
			add = 30
			desc = foreign_realm_court_language_spoken_interaction_reason
			trigger = {
				scope:actor = {
					has_royal_court = yes
					knows_court_language_of = this
				}
				NOT = {
					scope:actor.top_liege = scope:recipient.top_liege
				}
				OR = {
					AND = {
						scope:recipient = {
							has_royal_court = yes
						}
						scope:actor = { # You share Court Language
							has_same_court_language = scope:recipient
						}
					}
					
					scope:recipient = { # The recipient doesn't have a royal court, but their liege does
						is_independent_ruler = no
						has_royal_court = no
						liege = {
							has_royal_court = yes
							has_same_court_language = scope:actor
						}
					}
					scope:recipient = { # The recipient doesn't have a royal court, but their liege's liege does, while their liege doesn't have a royal court
						is_independent_ruler = no
						has_royal_court = no
						exists = liege.liege
						liege = {
							is_independent_ruler = no
							has_royal_court = no
						}
						liege.liege = {
							has_royal_court = yes
							has_same_court_language = scope:actor
						}
					}
					scope:recipient = { # The recipient doesn't have a royal court, but their liege's liege's liege does, while their liege doesn't have a royal court
						is_independent_ruler = no
						has_royal_court = no
						exists = liege.liege
						exists = liege.liege.liege
						liege = {
							is_independent_ruler = no
							has_royal_court = no
						}
						liege.liege = {
							is_independent_ruler = no
							has_royal_court = no
						}
						liege.liege.liege = {
							has_royal_court = yes
							has_same_court_language = scope:actor
						}
					}
					scope:recipient = { # The recipient doesn't have a royal court, but their liege's liege's liege's liege does, while their liege doesn't have a royal court
						is_independent_ruler = no
						has_royal_court = no
						exists = liege.liege
						exists = liege.liege.liege
						exists = liege.liege.liege.liege
						liege = {
							is_independent_ruler = no
							has_royal_court = no
						}
						liege.liege = {
							is_independent_ruler = no
							has_royal_court = no
						}
						liege.liege.liege = {
							is_independent_ruler = no
							has_royal_court = no
						}
						liege.liege.liege.liege = {
							has_royal_court = yes
							has_same_court_language = scope:actor
						}
					}
				}
			}
		}
	}
}

ttd_visit_far_off_realm = {
	category = interaction_category_diplomacy
	desc = ttd_visit_far_off_realm_desc
	icon = travel_leader_court_position
	common_interaction = yes
	interface_priority = 1000
	
	ai_frequency = 0 # Never
	use_diplomatic_range = no

 #	cooldown = { years = 20 }

	auto_accept = yes

	is_shown = {
		NOT = { scope:recipient = scope:actor }
		scope:actor = {
			is_ai = no
		 	is_landed = yes
			highest_held_title_tier >= 2
			NOT = { has_variable = ttd_far_off_location }
		 #	NOT = { government_has_flag = government_is_administrative }
		}
		scope:recipient = {
			NOT = { in_diplomatic_range = scope:actor }
			is_landed = yes
		 	is_independent_ruler = yes
		 #	government_has_flag = government_is_administrative
			highest_held_title_tier >= 5
		}
	}
	is_valid_showing_failures_only = {
		scope:actor = {
			is_available_adult = yes
			is_at_war = no
			custom_tooltip = {
				text = pdi_is_in_debt
				gold >= 0
			}
			custom_tooltip = {
				text = activity_pilgrimage.serving_diarch
				bannable_serving_diarch_trigger = no
			}
			NOT = { has_trait = pregnant }
			health >= 1.5
		}
		scope:recipient = {
			capital_province.county = { development_level >= 25 }
		}
	}

	on_accept = {

		scope:actor = {
			custom_tooltip = { text = gpt_visit_tip_0 }
			custom_tooltip = { text = gpt_visit_tip_00 }
			custom_tooltip = { text = gpt_visit_tip_1 }
			custom_tooltip = { text = gpt_visit_tip_2 }
			custom_tooltip = { text = gpt_visit_tip_3 }
			custom_tooltip = { text = gpt_visit_tip_00 }
			custom_tooltip = { text = gpt_visit_tip_4 }
			stress_impact = {
				shy = 20
				craven = 20
				lazy = 10
				honest = 10
			}
		}

		scope:actor = {
			set_variable = {
				name = ttd_far_off_target
				value = scope:recipient
				years = 5 # So it will eventually go away if travel plan somehow gets cancelled
			}
			set_variable = {
				name = ttd_far_off_location
				value = scope:recipient.capital_province
				years = 5 # So it will eventually go away if travel plan somehow gets cancelled
			}
			start_travel_plan = {
				destination = var:ttd_far_off_location
				on_travel_planner_cancel_event = tdd_visit_far_off_realm_events.1001
				on_arrival_event = tdd_visit_far_off_realm_events.1002
				on_arrival_destinations = all_but_last
			}
		}
	}
}

ttd_leave_realm = {
	category = interaction_category_diplomacy
	desc = ttd_leave_realm_desc
	icon = travel_leader_court_position
	common_interaction = yes
	interface_priority = 1000
	
	ai_frequency = 0 # Never
	use_diplomatic_range = no

	auto_accept = yes

	is_shown = {
		NOT = { scope:recipient = scope:actor }
		scope:actor.var:ttd_far_off_host ?= scope:recipient
	}

	on_accept = {
		custom_tooltip = ttd_leave_realm.tt
		scope:actor = { trigger_event = tdd_visit_far_off_realm_events.1011 }
	}
}