﻿#This is a localized trigger for checking that a character do not have a spouse that's employed or has some other circumstance blocking them from being recruited to a court
can_recruit_character_to_court_trigger = {
	$RECRUITER$ = { save_temporary_scope_as = recruiter }
	$RECRUITEE$ = { save_temporary_scope_as = recruitee }
	scope:recruitee = {
		bp2_valid_for_standard_interactions_trigger = yes
		NOR = {
			#custom_description = {
			#	text = is_not_wandering_child
			#	subject = scope:recruitee
			#	AND = {
			#		is_adult = no
			#		NOT = { is_close_or_extended_family_of = scope:recruiter }
			#	}
			#}
			is_imprisoned = yes
			is_theocratic_lessee = yes
			is_diarch = yes
			trigger_if = {
				limit = {
					exists = host
					host = { is_ai = no }
					NOT = { is_player_heir_of = scope:recruiter }
				}
				is_player_heir_of = host
			}
			trigger_if = {
				limit = {
					exists = host
					host = { is_ai = yes }
					NOT = { is_player_heir_of = scope:recruiter }
				}
				is_primary_heir_of = host
			}
			trigger_if = {
				limit = { exists = host }
				is_consort_of = host
			}
			trigger_if = {
				limit = { exists = host }
				host = {
					pressing_claim_of_character_trigger = { CHARACTER = scope:recruitee }
				}
			}
			trigger_if = {
				limit = { exists = host }
				#Are they employed?
				is_councillor_of = scope:recruitee.host
				is_knight_of = scope:recruitee.host
				any_relation = {
					type = ward
					OR = {
						this = scope:recruitee.host
						is_close_family_of = scope:recruitee.host
					}
				}
				any_relation = {
					type = guardian
					OR = {
						this = scope:recruitee.host
						is_close_family_of = scope:recruitee.host
					}
				}
				any_relation = {
					type = mentor
					OR = {
						this = scope:recruitee.host
						is_close_family_of = scope:recruitee.host
					}
				}
				any_relation = {
					type = student
					OR = {
						this = scope:recruitee.host
						is_close_family_of = scope:recruitee.host
					}
				}
				any_court_position_employer = { this = scope:recruitee.host }
			}
			#trigger_if = {
			#	limit = {
			#		scope:recruiter = { has_government = landless_adventurer_government }
			#	}
			#	custom_tooltip = {
			#		text = can_recruit_character_to_court_trigger.tt.laamps_invitation_restrictions
			#		NOR = {
			#			is_player_heir_of = scope:recruiter
			#			has_relation_soulmate = scope:recruiter
			#			has_relation_best_friend = scope:recruiter
			#			is_consort_of = scope:recruiter
			#			AND = {
			#				is_pool_character = yes
			#				OR = {
			#					has_relation_friend = scope:recruiter
			#					has_relation_lover = scope:recruiter
			#					is_close_family_of = scope:recruiter
			#				}
			#			}
			#		}
			#	}
			#}
			
			#Do they have the "wrong" marriage type and the spouse is employed?
			custom_description = {
				text = is_married_matrilineally_and_spouse_is_dominant_partner
				subject = scope:recruitee
				any_spouse = {
					is_female = yes
					matrilinear_marriage = yes
					host ?= scope:recruitee.host
					save_temporary_scope_as = spouse
					OR = { #Is employed in some way
						is_councillor_of = scope:recruitee.host
						is_knight_of = scope:recruitee.host
						any_relation = {
							type = ward
							OR = {
								this = scope:recruitee.host
								is_close_family_of = scope:recruitee.host
							}
						}
						any_relation = {
							type = guardian
							OR = {
								this = scope:recruitee.host
								is_close_family_of = scope:recruitee.host
							}
						}
						any_relation = {
							type = mentor
							OR = {
								this = scope:recruitee.host
								is_close_family_of = scope:recruitee.host
							}
						}
						any_relation = {
							type = student
							OR = {
								this = scope:recruitee.host
								is_close_family_of = scope:recruitee.host
							}
						}
						scope:spouse = {
							any_court_position_employer = { this = scope:recruitee.host }
						}
					}
				}
			}
			custom_description = {
				text = is_married_patrilineally_and_spouse_is_dominant_partner
				subject = scope:recruitee
				any_spouse = {
					is_male = yes
					patrilinear_marriage = yes
					host ?= scope:recruitee.host
					save_temporary_scope_as = spouse
					OR = { #Is employed in some way
						is_councillor_of = scope:recruitee.host
						is_knight_of = scope:recruitee.host
						any_relation = {
							type = ward
							OR = {
								this = scope:recruitee.host
								is_close_family_of = scope:recruitee.host
							}
						}
						any_relation = {
							type = guardian
							OR = {
								this = scope:recruitee.host
								is_close_family_of = scope:recruitee.host
							}
						}
						any_relation = {
							type = mentor
							OR = {
								this = scope:recruitee.host
								is_close_family_of = scope:recruitee.host
							}
						}
						any_relation = {
							type = student
							OR = {
								this = scope:recruitee.host
								is_close_family_of = scope:recruitee.host
							}
						}
						scope:spouse = {
							any_court_position_employer = { this = scope:recruitee.host }
						}
					}
				}
			}
			custom_description = {
				text = "is_escaped_prisoner"
				subject = scope:recruitee
				OR = {
					has_opinion_modifier = {
						modifier = attempted_imprisonment_opinion
						target = scope:recruiter
					}
					has_opinion_modifier = {
						modifier = treasonous_imprison_refusal
						target = scope:recruiter
					}
					AND = {
						exists = var:escaped_imprisonment_from
						var:escaped_imprisonment_from = scope:recruiter
					}
				}
			}
		}
	}
}