﻿tribute_mission_decision_generic_trigger = {
	#We're not already either doing a Tribute Mission or are on cooldown
	custom_tooltip = {
		text = tribute_mission_decision.already_on_mission
		is_already_tribute_missioning_trigger = no
	}

	custom_tooltip = {
		text = qualifies_for_tribute_mission_trigger
		OR = { # Must be able to offer something
			has_gold_tribute_trigger = yes
			has_herd_tribute_trigger = yes
			has_artifact_tribute_trigger = yes
		}
	}
}

tribute_mission_decision_concubine_trigger = {
	has_concubine_tribute_trigger = yes
	can_have_concubines_trigger = { CHAR = $OVERLORD$ }
}

tribute_mission_decision_eunuch_trigger = {
	has_eunuch_tribute_trigger = yes
	can_employ_court_eunuchs_trigger = { CHAR = $OVERLORD$ }
}

tribute_mission_decision_ai_potential_trigger = {
	is_at_war = no

	#Pace the AI
	trigger_if = {
		limit = {
			is_tributary = yes
			NOT = { has_variable = requested_tribute_mission }
		}
		suzerain = { NOT = { has_character_flag = pay_tribute_cooldown } }
		NOT = { has_variable = tribute_mission_grace }
		$TARGET$ ?= { NOT = { has_variable = ai_tribute_mission_cooldown } }
	}
	NOR = {
		any_owned_story = {
			OR = {
				story_type = story_mongol_invasion
				story_type = story_greatest_of_khans
			}
		}
		mpo_has_gok_mongol_empire_trigger = yes
		has_trait = conqueror
		has_trait = greatest_of_khans
		is_gurkhan = yes
	}
}

is_tributary_or_independent_neighbor_of_hegemon_trigger = {
	exists = title:$HEGEMON$.holder
	OR = {
		is_tributary_of = title:$HEGEMON$.holder
		AND = {
			is_tributary = no
			is_independent_ruler = yes
			any_neighboring_and_across_water_top_liege_realm_owner = {
				highest_held_title_tier = tier_hegemony
				primary_title = title:$HEGEMON$
			}
		}
		custom_tooltip = { # print nothing, only relevant for AI
			text = null
			AND = {
				title:$HEGEMON$ = title:h_china
				has_variable = wants_to_become_tributary_of_china
			}
		}
	}
}

is_already_tribute_missioning_trigger = {
	# set once we start travelling, if it becomes invalid we should no longer be treated as being on the mission
	exists = var:tribute_mission_target_scope
	# assure we are currently going to our overlord's capital, or else we're no longer on the mission 
	current_travel_plan ?= {
		final_destination_province = prev.var:tribute_mission_target_scope.capital_province
	}
}

has_gold_tribute_trigger = {
	short_term_gold >= small_gold_tribute_value
}

has_herd_tribute_trigger = {
	trigger_if = {
		limit = { government_has_flag = government_is_nomadic }
		domicile ?= { herd >= minor_herd_value }
	}
	trigger_else = {
		government_has_flag = government_is_nomadic
	}
}

is_suitable_artifact_tribute_trigger = {
	NOR = {
		has_variable = 1025_treasure_map
		has_variable = ungiftable
		has_variable = cursed_artifact
		has_variable = gifted_artifact
		has_variable = banner_dynasty
		has_variable = banner_house
		has_variable = bunga_mas_created_by
		rarity = famed
		rarity = illustrious
	}
	is_equipped = no
}

has_artifact_tribute_trigger = {
	custom_tooltip = {
		text = tribute_mission_concubine_interaction.no_valid_artifacts
		any_character_artifact = { is_suitable_artifact_tribute_trigger = yes }
	}
}

has_concubine_tribute_trigger = {
	overlord = { 
		is_adult = yes
		save_temporary_scope_as = overlord_check
	}
	custom_tooltip = {
		text = tribute_mission_concubine_interaction.no_valid_concubines
		any_courtier_or_guest = {
			can_become_concubine_of_character_valid_trigger = { CHARACTER = scope:overlord_check }
		}
	}
}

tribute_mission_is_available_eunuch_trigger = {
	is_available = yes
	is_ruler = no
	is_playable_character = no
	OR = {
		is_eunuch_trigger = yes
		AND = {
			is_female = no
			is_adult = yes
		}		
	}
	NOT = {
		faith = { has_doctrine = doctrine_theocracy_temporal }
	}
	trigger_if = {
		limit = { exists = root.cp:councillor_court_chaplain }
		NOT = { this = root.cp:councillor_court_chaplain }
	}
	has_any_disease_trigger = no
}

has_eunuch_tribute_trigger = {
	custom_tooltip = {
		text = tribute_mission_eunuch_interaction.no_valid_eunuchs
		any_courtier = { tribute_mission_is_available_eunuch_trigger = yes }	
	}
}

has_bunga_mas_tribute_trigger = {
	custom_tooltip = {
		text = tribute_mission_bunga_mas_interaction.no_valid_bunga_mas
		any_character_artifact = { var:bunga_mas_created_by ?= root }
		exists = suzerain
		suzerain = { government_has_flag = government_is_mandala }
	}
}
