﻿rk_demand_courtier_interaction = {
	category = interaction_category_vassal
	common_interaction = yes
	icon = request_courtier_interaction
	interface_priority = 45

	desc = rk_demand_courtier_interaction_2
	
	ai_targets = {
		ai_recipients = vassals
	}
	ai_target_quick_trigger = {
		adult = yes
	}
	ai_frequency = 12
	cooldown_against_recipient = { years = 3 }

	greeting = positive
	notification_text = DEMAND_COURTIER_NOTIFICATION

	highlighted_reason = HIGHLIGHTED_SKILLED_COURTIER
	is_highlighted = {
		scope:recipient = {
			any_courtier = {
				is_available_healthy_ai_adult = yes
				NOR = {
					is_consort_of = scope:recipient
					is_heir_of = scope:recipient
					AND = {
						is_female = yes
						patrilinear_marriage = yes
					}
					AND = {
						is_male = yes
						matrilinear_marriage = yes
					}
					is_diarch = yes
					is_designated_diarch = yes
					has_character_flag = has_been_offered_as_concubine
				}
				OR = {
					sum_of_all_skills_value >= sum_of_all_skills_threshold_good
					martial >= monumentally_high_skill_rating
					prowess >= extremely_high_skill_rating
					AND = {
						diplomacy >= monumentally_high_skill_rating
						scope:actor.cp:councillor_chancellor ?= { diplomacy < monumentally_high_skill_rating }
					}
					AND = {
						diplomacy >= monumentally_high_skill_rating
						scope:actor.cp:councillor_steward ?= { stewardship < monumentally_high_skill_rating }
					}
					AND = {
						diplomacy >= monumentally_high_skill_rating
						scope:actor.cp:councillor_spymaster ?= { intrigue < monumentally_high_skill_rating }
					}
					trigger_if = {
						limit = {
							scope:actor = {
								government_has_flag = government_is_nomadic
							}
						}
						OR = {
							aptitude:master_of_hunt_court_position >= 4
							aptitude:keeper_of_the_horses_court_position >= 4
							aptitude:boyan_court_position >= 4
							aptitude:siege_engineer_court_position >= 4
							aptitude:yurtchi_court_position >= 4
							aptitude:cherbi_court_position >= 4
							aptitude:yeke_jarquchi_court_position >= 4
							aptitude:foreign_emissary_court_position >= 4
						}
					}
				}
			}
		}
	}

	needs_recipient_to_open = yes

	populate_actor_list = {
		scope:recipient = {
			every_courtier = {
				limit = {
					is_available_healthy_ai_adult = yes
					NOR = {
						is_consort_of = scope:recipient
						is_heir_of = scope:recipient
						AND = {
							is_female = yes
							patrilinear_marriage = yes
						}
						AND = {
							is_male = yes
							matrilinear_marriage = yes
						}
						is_diarch = yes
						is_designated_diarch = yes
						has_character_flag = has_been_offered_as_concubine
					}
				}
				add_to_list = characters
			}
		}
	}

	is_shown = {
		scope:actor != scope:recipient
		scope:actor = { 
			NOT = { government_has_flag = government_is_nomadic } 
			has_title = title:b_the_red_keep
		}
		scope:recipient = {
			OR = {
				is_vassal_of = scope:actor
			}
		}
	}

	is_valid_showing_failures_only = {

			custom_tooltip = {
				text = rk_demand_courtier_crown_authority_tt
				scope:actor = {
					OR = {
						has_realm_law_flag = title_revocation_allowed
						has_realm_law_flag = vassal_retraction_allowed
						has_realm_law_flag = imprisonment_toggle_on
					}
				}
			}
			custom_tooltip = {
				text = demand_courtier_valid_courtier_tt
				scope:recipient = {
					any_courtier = {
						is_available_healthy_ai_adult = yes
						NOR = {
							is_consort_of = scope:recipient
							is_heir_of = scope:recipient
							AND = {
								is_female = yes
								patrilinear_marriage = yes
							}
							AND = {
								is_male = yes
								matrilinear_marriage = yes
							}
						}
					}
				}
			}
	}

	can_be_picked = {
		is_adult = yes
	}

	can_send = {
	}

	auto_accept = no

	ai_accept = {
		base = 0

		modifier = {
			add = 1000
			scope:recipient = {
				is_obedient_to = scope:actor
			}
			desc = AI_OBEDIENT_REASON
		}

		modifier = {
			add = 100
			scope:actor = {
				government_allows = administrative
			}
			desc = ADMINISTRATIVE_REASON
		}

		modifier = {
			add = 25
			scope:recipient = {
				has_dread_level_towards = {
					target = scope:actor
					level = 1
				}
			}
			desc = INTIMIDATED_REASON
		}

		modifier = {
			add = 50
			scope:recipient = {
				has_dread_level_towards = {
					target = scope:actor
					level = 2
				}
			}
			desc = COWED_REASON
		}

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

		modifier = {
			add = -25
			scope:secondary_actor = {
				OR = {
					is_councillor = yes
					has_any_court_position = yes
				}
			}
			desc = AI_EMPLOYED_COURTIER_REASON
		}

		modifier = {
			add = -15
			scope:secondary_actor = {
				is_knight = yes
			}
			desc = AI_IS_KNIGHT_REASON
		}

		modifier = {
			add = -50
			exists = scope:secondary_actor.inspiration
			desc = AI_INSPIRED_REASON
		}

		modifier = {
			add = -25
			scope:secondary_actor = {
				is_close_or_extended_family_of = scope:recipient
			}
			desc = AI_FAMILY_REASON
		}

		modifier = {
			add = -50
			scope:secondary_actor = {
				has_relation_friend = scope:recipient
			}
			desc = AI_FRIEND_REASON
		}

		modifier = {
			add = 1000
			scope:secondary_actor = {
				has_relation_rival = scope:recipient
			}
			desc = AI_RIVAL_REASON
		}
	}

	ai_potential = {
		ai_greed >= 0
		any_tributary = { }
	}

	ai_will_do = {
		base = 0
	}

	on_send = {
		scope:secondary_actor = { # to block the same character from being offered twice
			add_character_flag = {
				flag = has_been_offered_as_concubine
				days = 5
			}
		}
	}

	on_accept = {
		scope:secondary_actor = {
			add_opinion = {
				target = scope:recipient
				modifier = annoyed_opinion
				opinion = -10
			}
		}
		scope:actor = {
			add_courtier = scope:secondary_actor
			scope:secondary_actor = {
				every_consort = {
					limit = {
						is_courtier_of = scope:recipient
					}
					scope:actor = {
						add_courtier = prev
					}
				}
				every_child = {
					limit = {
						is_adult = no
						is_courtier_of = scope:recipient
					}
					scope:actor = {
						add_courtier = prev
					}
				}
			}
			add_opinion = {
				target = scope:recipient
				modifier = pleased_opinion
				opinion = 20
			}
		}
		scope:recipient = {
			add_opinion = {
				target = scope:actor
				modifier = upset_opinion
				opinion = -15
			}
		}
	}

	on_decline = {
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_bad
				title = msg_courtier_demand_rejected_title
				right_icon = scope:recipient
				left_icon = scope:secondary_actor
				custom_tooltip = msg_courtier_demand_rejected
			}
		}
		scope:actor = {
			add_opinion = {
				target = scope:recipient
				modifier = upset_opinion
				opinion = -15
			}
		}
	}
}


