﻿agotma_buybetrothal_interaction = {
	icon = icon_agotma_buybetrothal
	category = interaction_category_friendly
	desc = agotma_buybetrothal_interaction_desc
	interface_priority = 100
	scheme = agotma_buybetrothal

	send_name = START_SCHEME
	ignores_pending_interaction_block = yes

	ai_targets = {
		ai_recipients = liege
		ai_recipients = dynasty
		ai_recipients = family
		ai_recipients = children
		ai_recipients = councillors
		ai_recipients = spouses
	}
	ai_targets = {
		ai_recipients = neighboring_rulers
		ai_recipients = vassals
		ai_recipients = peer_vassals
		chance = 0.25
	}
	ai_targets = {
		ai_recipients = realm_characters
		chance = 0.10
	}
	ai_frequency = 12

	redirect = {
		scope:recipient = {
			if = {
				limit = {
					is_betrothed = yes
				}
				betrothed = {
					save_scope_as = secondary_recipient
				}
			}
		}
	}


	is_shown = {
		trigger_if = {
			limit = { has_game_rule = agotma_action_restriction_enabled }
			scope:actor.intrigue >= 20
		}
		scope:actor = {
			NOT = {
				has_trait = incapable
				has_character_modifier = agotma_buybetrothal_final_modifier
			}
			any_child = { count >= 1 }
			is_landed = yes
			highest_held_title_tier >= tier_duchy
			is_adult = yes
		}
		scope:recipient = {
			is_betrothed = yes
			OR = {
				AND = {
					is_landed = no
					exists = scope:recipient.top_liege
					is_child_of = scope:recipient.top_liege
				}
				AND = {
					is_landed = yes
					scope:recipient = scope:recipient.top_liege
				}
			}
		}

		scope:recipient.top_liege = {
			is_landed = yes
			highest_held_title_tier = tier_hegemony
		}
		scope:recipient.betrothed.house.house_head = { NOT = { is_at_war_with = scope:recipient.top_liege } }
		scope:actor = { NOT = { has_variable = i_completed_agotma_buybetrothal } }

		OR = {
			scope:secondary_recipient.father = {
				is_landed = yes
				highest_held_title_tier >= tier_duchy
			}
			scope:secondary_recipient.mother = {
				is_landed = yes
				highest_held_title_tier >= tier_duchy
			}
			scope:secondary_recipient = {
				is_landed = yes
				highest_held_title_tier >= tier_duchy
			}
		}
		NOT = {
			scope:recipient = scope:actor
			scope:secondary_recipient.father = scope:recipient.top_liege
			scope:secondary_recipient.mother = scope:recipient.top_liege
			scope:secondary_recipient.house.house_head = scope:recipient.top_liege.house.house_head
		}
		scope:recipient.father = {
			NOT = { has_character_modifier = agotma_buybetrothal_betrothed_modifier }
		}
		scope:recipient.mother = {
			NOT = { has_character_modifier = agotma_buybetrothal_betrothed_modifier }
		}
		scope:recipient.religion = scope:actor.religion
		OR = {
			AND = {
				scope:actor = { is_ai = yes }
				has_game_rule = agotma_buy_betrothal_enabled
			}
			scope:actor = { is_ai = no }
		}
		OR = {
			AND = {
				scope:actor = { is_ai = yes }
				scope:recipient.top_liege.primary_title = { NOT = { has_variable = agotma_buybetrothal_started } }
			}
			scope:actor = { is_ai = no }
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			is_adult = yes
			is_at_home = yes
		}
	}

	cost = {
		# Nothing
	}

	auto_accept = yes

	on_accept = {
		scope:actor = {
			start_scheme = {
				type = agotma_buybetrothal
				target_character = scope:recipient
			}
		}
	}

	ai_potential = {
		has_game_rule = agotma_buy_betrothal_enabled
		NOT = {
			has_trait = incapable
			has_character_modifier = agotma_buybetrothal_final_modifier
		}
		is_landed = yes
		highest_held_title_tier >= tier_duchy
		is_adult = yes
	}

	ai_will_do = {
		base = 0

		opinion_modifier = {
			opinion_target = scope:secondary_recipient
			multiplier = -2
		}

		ai_value_modifier = {
			ai_boldness = 0.25
			ai_rationality = -0.25
			ai_greed = 1
			ai_honor = -0.5
		}

		modifier = {
			factor = 1.1
			scope:actor = {
				has_trait = education_stewardship_3
			}
		}

		modifier = {
			factor = 1.2
			scope:actor = {
				has_trait = education_stewardship_4
			}
		}

		modifier = {
			factor = 1.3
			scope:actor = {
				has_trait = education_stewardship_5
			}
		}

		modifier = {
			factor = 1.1
			scope:actor = {
				has_trait = impatient
			}
		}

		modifier = {
			factor = 1.2
			scope:actor = {
				has_trait = scholar
			}
		}

		modifier = {
			factor = 1.1
			scope:actor = {
				has_trait = deceitful
			}
		}

		modifier = {
			factor = 1.1
			scope:actor = {
				has_trait = diligent
			}
		}

		modifier = {
			factor = 2
			scope:actor = {
				learning >= 15
			}
		}

		modifier = {
			factor = 2
			scope:actor = {
				intrigue >= 30
			}
		}

		modifier = {
			factor = 25
			scope:recipient = {
				highest_held_title_tier = tier_hegemony
			}
		}

		modifier = {
			factor = 20
			scope:actor = {
				dynasty.dynasty_prestige_level >= 8
			}
		}

		modifier = {
			factor = 10
			scope:actor = {
				dynasty.dynasty_prestige_level <= 7
				dynasty.dynasty_prestige_level > 5
			}
		}

		modifier = {
			factor = 25
			scope:recipient.top_liege = scope:recipient.father
		}

		modifier = {
			factor = 25
			scope:recipient.top_liege = scope:recipient.mother
		}

		modifier = {
			factor = 25
			scope:actor = {
				highest_held_title_tier >= tier_kingdom
			}
		}

		modifier = {
			factor = 0
			scope:recipient = scope:actor
		}

		modifier = {
			factor = 0
			NOT = { scope:recipient.faith = scope:actor.faith }
		}

		modifier = {
			factor = 0
			NOT = { scope:recipient.culture = scope:actor.culture }
			NOT = { scope:actor.top_liege = scope:recipient }
			NOT = { scope:actor.top_liege = scope:recipient.father }
			NOT = { scope:actor.top_liege = scope:recipient.mother }
		}

	}

	on_decline = {
		# N/A
	}
}