﻿
#Tribute Missions - a set of hidden Character Interactions, triggered by the Pay Tribute decision - what do you send?

tribute_mission_gold_interaction = {
	hidden = yes

	popup_on_receive = yes
	pause_on_receive = yes

	ai_min_reply_days = 0
	ai_max_reply_days = 0

	#Small Tribute
	send_option = {
		flag = small_gold_tribute
		is_valid = { 
			scope:actor = { 
				gold >= {
					value = small_gold_tribute_value
					if = {
						limit = { has_variable = offered_gold_value }
						add = var:offered_gold_value
					}
				}
			}
		}
	}
	#Adequate Tribute
	send_option = {
		flag = adequate_gold_tribute
		is_valid = {
			scope:actor = { 
				gold >= {
					value = adequate_gold_tribute_value
					if = {
						limit = { has_variable = offered_gold_value }
						add = var:offered_gold_value
					}
				}
			}
		}
	}
	#Excessive Tribute
	send_option = {
		flag = excessive_gold_tribute
		is_valid = {
			scope:actor = { 
				gold >= {
					value = excessive_gold_tribute_value
					if = {
						limit = { has_variable = offered_gold_value }
						add = var:offered_gold_value
					}
				}
			}
		}
	}

	on_accept = {
		scope:actor = {
			#Gold
			switch = {
				trigger = yes
				scope:small_gold_tribute ?= {
					#Define how much gold it is
					set_variable = {
						name = tribute_mission_type
						value = flag:small_gold_tribute
					}
					set_or_change_offered_tribute_value_effect = {
						TYPE = gold
						VALUE = small_gold_tribute_value
					}

					custom_tooltip = tribute_mission_gold_interaction.small_reserved_gold
				}
				scope:adequate_gold_tribute ?= {
					#Define how much gold it is
					set_variable = {
						name = tribute_mission_type
						value = flag:adequate_gold_tribute
					}
					set_or_change_offered_tribute_value_effect = {
						TYPE = gold
						VALUE = adequate_gold_tribute_value
					}

					custom_tooltip = tribute_mission_gold_interaction.adequate_reserved_gold
				}
				scope:excessive_gold_tribute ?= {
					#Define how much gold it is
					set_variable = {
						name = tribute_mission_type
						value = flag:excessive_gold_tribute
					}
					set_or_change_offered_tribute_value_effect = {
						TYPE = gold
						VALUE = excessive_gold_tribute_value
					}

					custom_tooltip = tribute_mission_gold_interaction.excessive_reserved_gold
				}
			}

			#Some Mandala piety
			show_as_tooltip = { tribute_mission_mandala_piety_effect = yes }

			#Travel
			tribute_mission_set_up_tribute_travel_effect = yes
		}
	}

	auto_accept = yes

	ai_will_do = {
		base = 50
	}
}

tribute_mission_herd_interaction = {
	hidden = yes

	popup_on_receive = yes
	pause_on_receive = yes

	ai_min_reply_days = 0
	ai_max_reply_days = 0

	#Small Tribute
	send_option = {
		flag = small_herd_tribute

		is_valid = { 
			scope:actor = {
				domicile ?= { 
					herd >= {
						value = {
							add = small_herd_tribute_value
							if = {
								limit = { has_variable = offered_herd_value }
								add = var:offered_herd_value
							}
						}
					}
				}
			}
		}
	}

	#Adequate Tribute
	send_option = {
		flag = adequate_herd_tribute

		is_valid = { 
			scope:actor = {
				domicile ?= { 
					herd >= {
						value = {
							add = adequate_herd_tribute_value
							if = {
								limit = { has_variable = offered_herd_value }
								add = var:offered_herd_value
							}
						}
					}
				}
			}
		}
	}
	#Excessive Tribute
	send_option = {
		flag = excessive_herd_tribute

		is_valid = { 
			scope:actor = {
				domicile ?= { 
					herd >= {
						value = {
							add = excessive_herd_tribute_value
							if = {
								limit = { has_variable = offered_herd_value }
								add = var:offered_herd_value
							}
						}
					}
				}
			}
		}
	}

	on_accept = {
		scope:actor = {
			#Herd
			switch = {
				trigger = yes
				scope:small_herd_tribute ?= {
					#Define how much herd it is
					set_variable = {
						name = tribute_mission_type
						value = flag:small_herd_tribute
					}
					#set_or_change_offered_tribute_value_effect = { #Herd value scale by era shenanigans here
					#	TYPE = herd
					#	VALUE = small_herd_tribute_value
					#}
					set_variable = {
						name = offered_herd_value
						value = domicile.small_herd_tribute_value
					}

					custom_tooltip = tribute_mission_herd_interaction.small_reserved_herd
				}
				scope:adequate_herd_tribute ?= {
					#Define how much herd it is
					set_variable = {
						name = tribute_mission_type
						value = flag:adequate_herd_tribute
					}
					#set_or_change_offered_tribute_value_effect = {
					#	TYPE = herd
					#	VALUE = adequate_herd_tribute_value
					#}
					set_variable = {
						name = offered_herd_value
						value = domicile.adequate_herd_tribute_value
					}

					custom_tooltip = tribute_mission_herd_interaction.adequate_reserved_herd
				}
				scope:excessive_herd_tribute ?= {
					#Define how much herd it is
					set_variable = {
						name = tribute_mission_type
						value = flag:excessive_herd_tribute
					}
					#set_or_change_offered_tribute_value_effect = {
					#	TYPE = herd
					#	VALUE = excessive_herd_tribute_value
					#}
					set_variable = {
						name = offered_herd_value
						value = domicile.excessive_herd_tribute_value
					}

					custom_tooltip = tribute_mission_herd_interaction.excessive_reserved_herd
				}
			}

			#Some Mandala piety
			show_as_tooltip = { tribute_mission_mandala_piety_effect = yes }

			#Travel
			tribute_mission_set_up_tribute_travel_effect = yes
		}
	}

	auto_accept = yes

	ai_will_do = {
		base = 50
	}
}

tribute_mission_artifact_interaction = {
	hidden = yes

	target_type = artifact
	target_filter = actor_artifacts

	ai_min_reply_days = 0
	ai_max_reply_days = 0

	can_be_picked_artifact = {
		scope:target = {
			is_suitable_artifact_tribute_trigger = yes
		}
	}

	on_accept = {
		scope:target = {
			set_variable = is_tribute_mission_artifact
		}
		scope:actor = {
			#Save the Artifact
			set_variable = {
				name = tribute_mission_type
				value = flag:artifact_tribute
			}
			set_variable = {
				name = offered_artifact
				value = scope:target
			}
			custom_tooltip = tribute_mission_artifact_interaction.tooltip
			#Some Mandala piety
			show_as_tooltip = { tribute_mission_mandala_piety_effect = yes }

			#Travel
			tribute_mission_set_up_tribute_travel_effect = yes
		}
	}

	auto_accept = {
		OR = {
			scope:actor = { subject_standing >= 0 }
			scope:recipient = { is_ai = no }
		}
	}
	
	ai_accept = {
		base = 0
		modifier = {
			add = 100
			desc = ARTIFACT_REASON
		}
		modifier = {
			add = -80
			NOT = {
				can_equip_artifact = scope:target
			}
			desc = ARTIFACT_NOT_EQUIPPABLE_REASON
		}
		modifier = {
			add = -40
			NOT = {
				can_benefit_from_artifact = scope:target
			}
			desc = ARTIFACT_NOT_BENEFIT_REASON
		}
		modifier = {
			add = -500
			scope:target = {
				has_variable = unwanted_artifact
			}
			#No harm in reusing the wording
			desc = ARTIFACT_CURSED_REASON
		}
		modifier = {
			add = -1000
			scope:target = {
				has_variable = cursed_artifact
			}
			desc = ARTIFACT_CURSED_REASON
		}
		modifier = {
			add = 100
			exists = scope:target.var:banner_dynasty
			exists = scope:recipient.dynasty
			scope:recipient = scope:target.var:banner_dynasty.dynast
			desc = ARTIFACT_DYNASTY_BANNER_REASON
		}
		modifier = {
			add = -200
			OR = {
				exists = scope:target.var:banner_dynasty
				exists = scope:target.var:banner_house
			}
			exists = scope:recipient.house
			trigger_if = {
				limit = { exists = scope:target.var:banner_dynasty }
				scope:target.var:banner_dynasty != scope:recipient.dynasty
			}
			trigger_else = {
				scope:target.var:banner_house != scope:recipient.house
			}
			desc = ARTIFACT_USELESS_BANNER_REASON
		}
	}
	
	ai_will_do = {
		base = 50
	}
}

tribute_mission_concubine_interaction = {
	hidden = yes

	populate_recipient_list = {
		scope:actor = {
			every_courtier_or_guest = {
				limit = {
					can_be_offered_as_concubine_to_character_trigger = {
						GIVER = scope:actor
						CHARACTER = scope:actor.overlord
					}
					has_any_disease_trigger = no
					has_easily_mocked_physical_attribute_trigger = no
				}
				add_to_list = characters
			}
		}
	}

	ai_min_reply_days = 0
	ai_max_reply_days = 0

	can_be_picked = {
		is_adult = yes
	}

	auto_accept = {
		OR = {
			scope:actor = { subject_standing >= 0 }
			scope:recipient = { is_ai = no }
		}
	}

	on_accept = {
		scope:actor = {
			#Save the concubine
			set_variable = {
				name = tribute_mission_type
				value = flag:concubine_tribute
			}
			set_variable = {
				name = offered_concubine
				value = scope:secondary_recipient
			}
			scope:secondary_recipient = {
				add_character_flag = {
					flag = cannot_be_diarch # just enough to make sure they don't succeed to the diarchy while en route
					years = 2
				}
			}
			custom_tooltip = tribute_mission_concubine_interaction.tooltip
			#Some Mandala piety
			show_as_tooltip = { tribute_mission_mandala_piety_effect = yes }

			#Travel
			tribute_mission_set_up_tribute_travel_effect = yes
		}
	}

	ai_accept = {
		base = 50
		
		modifier = {
			add = {
				value = 50
				multiply = scope:secondary_recipient.num_of_good_genetic_traits
			}
			scope:secondary_recipient = {
				num_of_good_genetic_traits > 0
				trigger_if = {
					limit = {
						is_female = yes
					}
					is_aging_character = no
				}
			}
			desc = AI_POSITIVE_TRAIT_REASON
		}

		modifier = {
			add = {
				value = 50
			}
			scope:secondary_recipient = {
				is_lowborn = no
				trigger_if = {
					limit = {
						is_female = yes
					}
					is_aging_character = no
				}
			}
			desc = AI_DYNASTY_PRESTIGE_REASON_NOBLE
		}

		modifier = {
			add = {
				value = -50
				multiply = scope:secondary_recipient.num_of_bad_genetic_traits
			}
			scope:secondary_recipient = {
				OR = {
					num_of_bad_genetic_traits > 0
				}
				trigger_if = {
					limit = {
						is_female = yes
					}
					is_aging_character = no
				}
			}
			desc = AI_NEGATIVE_TRAIT_REASON
		}

		modifier = {
			add = {
				value = -50
			}
			scope:secondary_recipient = {
				is_lowborn = yes
				num_of_good_genetic_traits = 0
				trigger_if = {
					limit = {
						is_female = yes
					}
					is_aging_character = no
				}
			}
			desc = AI_DYNASTY_PRESTIGE_REASON_LOWBORN_NO_POSITIVE_TRAIT
		}

		opinion_modifier = { # Opinion of you
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 1.0
			desc = AI_OPINION_REASON
		}

		opinion_modifier = { # Opinion of concubine
			who = scope:recipient
			opinion_target = scope:secondary_recipient
			multiplier = 0.25
			desc = AI_OPINION_REASON
		}

		compare_modifier = { # Recipient is reluctant to marry old women (procreation is a key factor)
			trigger = {
				scope:secondary_recipient = {
					is_young_character = no
					is_female = yes
				}
			}
			target = scope:secondary_recipient
			value = age
			multiplier = -5.0
			step = 1
			offset = -29
			desc = MARRY_AGE
		}

		modifier = { # A Recipient is unwilling to take a same-sex concubine if their faith doesn't support it
			add = -1000
			
			scope:recipient = {
				allowed_to_marry_same_sex_trigger = no
				sex_same_as = scope:secondary_recipient
			}
			desc = SAME_SEX_MARRIAGE_FAITH_REASON_RECIPIENT
		}

		modifier = { # Unwilling if they don't have a batch of kids and opposite sex consorts to handle that situation
			add = -200
			scope:recipient = {
				allowed_to_marry_same_sex_trigger = yes
				sex_same_as = scope:secondary_recipient
				trigger_if = {
					limit = {
						NOT = {
							any_consort = {
								can_have_children_with = { CHARACTER = scope:recipient }
								fertility > 0.1
							}
						}
					}
					any_child = { is_player_heir_of = root }
				}
				trigger_else = {
					always = no
				}
			}
			desc = AI_NO_FERTILITY_REASON
		}

		modifier = {
			add = 50
			scope:recipient = {
				is_attracted_to_gender_of = scope:secondary_recipient
			}
			desc = AI_ATTRACTION_REASON
		}

		#More/Less likely based on difference in rank between actor and recipient
		modifier = {
			add = 20
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = 1
				}
			}
			desc = AI_RANK_DIFF
		}
		modifier = {
			add = 30
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = 2
				}
			}
			desc = AI_RANK_DIFF
		}
		modifier = {
			add = 40
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = 3
				}
			}
			desc = AI_RANK_DIFF
		}
		modifier = {
			add = 50
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = 4
				}
			}
			desc = AI_RANK_DIFF
		}
		modifier = {
			add = 60
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = 5
				}
			}
			desc = AI_RANK_DIFF
		}
		modifier = {
			add = -20
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = -1
				}
			}
			desc = AI_RANK_DIFF
		}
		modifier = {
			add = -30
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = -2
				}
			}
			desc = AI_RANK_DIFF
		}
		modifier = {
			add = -40
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = -3
				}
			}
			desc = AI_RANK_DIFF
		}
		modifier = {
			add = -50
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = -4
				}
			}
			desc = AI_RANK_DIFF
		}
		modifier = {
			add = -60
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = -5
				}
			}
			desc = AI_RANK_DIFF
		}
		modifier = {
			add = -250
			scope:secondary_recipient = {
				has_std_trigger = yes
			}
			desc = AI_STD_REASON
		}
		modifier = {
			add = -250
			scope:secondary_recipient = {
				has_epidemic_disease_trigger = yes
			}
			desc = AI_CONTAGIOUS_REASON
		}
		modifier = {
			add = -5000
			scope:secondary_recipient = {
				fertility <= 0
			}
			desc = AI_FERTILITY_REASON
		}

		# Unity modifiers
		evaluate_action_increasing_house_unity = {
			VALUE = 100
		}
	}

	ai_will_do = {
		base = 50
	}
}

tribute_mission_eunuch_interaction = {
	hidden = yes

	populate_recipient_list = {
		scope:actor = {
			every_courtier = {
				limit = { 
					tribute_mission_is_available_eunuch_trigger = yes
					NAND = {
						faith = { has_doctrine = doctrine_theocracy_temporal }
						this = scope:actor.cp:councillor_court_chaplain
					}
				}
				add_to_list = characters
			}
		}
	}

	ai_min_reply_days = 0
	ai_max_reply_days = 0

	can_be_picked = {
		has_any_disease_trigger = no
	}

	auto_accept = {
		OR = {
			scope:actor = { subject_standing >= 0 }
			scope:recipient = { is_ai = no }
		}
	}

	on_accept = {
		scope:actor = {
			#Save the eunuch
			set_variable = {
				name = tribute_mission_type
				value = flag:eunuch_tribute
			}
			set_variable = {
				name = offered_eunuch
				value = scope:secondary_recipient
			}
			custom_tooltip = tribute_mission_eunuch_interaction.tooltip
			stress_impact = {
				compassionate = medium_stress_impact_gain
				sadistic = minor_stress_impact_loss
			}
			#Some Mandala piety
			show_as_tooltip = { tribute_mission_mandala_piety_effect = yes }

			#Travel
			tribute_mission_set_up_tribute_travel_effect = yes
		}
		scope:secondary_recipient = {
			if = {
				limit = { is_eunuch_trigger = no }
				add_opinion = {
					modifier = slated_for_castration_opinion
					target = scope:actor
					opinion = -50
				}
				custom_tooltip = tribute_mission_eunuch_interaction.slated_for_castration
				#Escape or no escape?
				hidden_effect = {
					random_list = {
						30 = {
							modifier = {
								has_trait = brave
								add = 10
							}
							modifier = {
								has_trait = wrathful
								add = 10
							}
							modifier = {
								add = prowess
							}
							#I'm outta here!
							add_character_flag = tribute_mission_attempt_escape
							scope:actor = {
								trigger_event = {
									id = tribute_mission.9760
									days = { 10 20 }
								}
							}
						}
						70 = {
							modifier = {
								has_trait = craven
								add = 10
							}
							modifier = {
								has_trait = lazy
								add = 10
							}
							#No escape
						}
					}
				}
			}
		}
	}

	ai_accept = {
		base = -50
		######### OPINION OF TRIBUTARY
		opinion_modifier = {
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 0.5
			desc = AI_OPINION_REASON
		}
		######### OPINION OF EUNUCH
		opinion_modifier = {
			who = scope:recipient
			opinion_target = scope:secondary_recipient
			multiplier = 0.5
			desc = AI_OPINION_REASON
		}
		######## EUNUCH AGE
		modifier = {
			add = {
				value = 50
				subtract = scope:secondary_recipient.age
			}
			desc = AI_REASON_EUNUCH_AGE
		}
		######## EUNUCH SKILLS
		modifier = {
			add = {
				add = scope:secondary_recipient.diplomacy
				add = scope:secondary_recipient.intrigue
				add = scope:secondary_recipient.stewardship
				add = scope:secondary_recipient.martial
				add = scope:secondary_recipient.learning
			}
			desc = AI_REASON_EUNUCH_SKILLS
		}
		######## EUNUCH SKILLS
		modifier = {
			scope:secondary_recipient = {
				has_trait = beardless_eunuch
			}
			add = 25
			desc = AI_REASON_BEARDLESS_EUNUCH
		}
	}

	ai_will_do = {
		base = 50
	}
}

#Player only
tribute_mission_bunga_mas_interaction = {
	hidden = yes

	target_type = artifact
	target_filter = actor_artifacts

	ai_min_reply_days = 0
	ai_max_reply_days = 0

	can_be_picked_artifact = {
		scope:target = { var:bunga_mas_created_by ?= scope:actor }
	}

	on_accept = {
		scope:target = {
			set_variable = is_tribute_mission_artifact
		}
		scope:actor = {
			#Save the Artifact
			set_variable = {
				name = tribute_mission_type
				value = flag:bunga_mas_tribute
			}
			set_variable = {
				name = offered_bunga_mas
				value = scope:target
			}
			custom_tooltip = tribute_mission_bunga_mas_interaction.tooltip
			#Some Mandala piety
			show_as_tooltip = { tribute_mission_mandala_piety_effect = yes }

			#Travel
			tribute_mission_set_up_tribute_travel_effect = yes
		}
	}

	auto_accept = {
		always = yes
	}
	
	ai_accept = {
		base = 100
	}
	
	ai_will_do = {
		base = 50
	}
}
