﻿agotma_instigator_interaction = {
	icon = icon_agotma_instigator
	category = interaction_category_friendly
	desc = agotma_instigator_interaction_desc
	interface_priority = 100
	scheme = agotma_instigator

	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


	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_instigator_final_modifier
			}
			is_landed = yes
			highest_held_title_tier >= tier_county
			is_adult = yes
		}
		scope:recipient = {
			OR = {
				AND = {
					is_landed = yes
					OR = {
						has_government = lp_feudal_government
						has_government = feudal_government
					}
					agot_can_be_ruler = yes
					highest_held_title_tier >= tier_county
				}
				AND = {
					NOT = { is_landed = yes }
					any_claim = {
						count >= 1
						exists = holder
						tier = tier_hegemony
						holder = {
							NOT = { is_vassal_or_below_of = scope:recipient }
							scope:recipient = {
								save_temporary_opinion_value_as = {
									name = opinion_of_holder
									target = prev
								}
							}
							scope:opinion_of_holder < 25
						}
						NOT = { holder = scope:recipient.father }
						NOT = { holder = scope:recipient.mother }
					}
					OR = {
						has_trait = ambitious
						has_trait = brave
						has_trait = education_diplomacy_4
						has_trait = education_diplomacy_5
						has_trait = education_martial_4
						has_trait = education_martial_5
						has_trait = education_stewardship_4
						has_trait = education_stewardship_5
						has_trait = education_intrigue_4
						has_trait = education_intrigue_5
						has_trait = education_learning_4
						has_trait = education_learning_5
					}
				}
			}
			NOT = {
				has_trait = content
				has_trait = craven
			}
			is_adult = yes
			is_claimant = yes
			any_claim = {
				count >= 1
				exists = holder
				tier >= tier_duchy
				holder = {
					NOT = { is_vassal_or_below_of = scope:recipient }
					NOT = { is_parent_of = scope:recipient }
					NOT = { is_spouse_of = scope:recipient }
					scope:recipient = {
						save_temporary_opinion_value_as = {
							name = opinion_of_holder
							target = prev
						}
					}
					scope:opinion_of_holder < 25
				}
			}
		}
		NOT = { scope:recipient = scope:actor }
		OR = {
			AND = {
				scope:actor = { is_ai = yes }
				has_game_rule = agotma_instigator_enabled
			}
			scope:actor = { is_ai = no }
		}
		OR = {
			AND = {
				scope:actor = { is_ai = yes }
				scope:recipient.top_liege.primary_title = { NOT = { has_variable = agotma_instigator_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_instigator
				target_character = scope:recipient
			}
		}
	}

	ai_potential = {
		has_game_rule = agotma_instigator_enabled
		is_adult = yes
		is_landed = yes
		highest_held_title_tier >= tier_county
		NOT = {
			has_trait = incapable
			has_character_modifier = agotma_instigator_final_modifier
		}
		top_liege.primary_title = { NOT = { has_variable = agotma_instigator_started } }
	}

	ai_will_do = {
		base = 0

		ai_value_modifier = {
			ai_boldness = 0.4
			ai_rationality = -2
			ai_greed = 0.2
			ai_honor = -1.4
		}

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

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

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

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

		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 = 5
			scope:actor.location = scope:recipient.location
		}

		modifier = {
			factor = 0.5
			scope:recipient = {
				highest_held_title_tier < tier_duchy
			}
		}

		modifier = {
			factor = 25
			scope:recipient = {
				highest_held_title_tier >= tier_duchy
			}
		}

		modifier = {
			factor = 0.2
			scope:recipient = {
				any_claim = {
					count >= 1
					exists = holder
					tier = tier_duchy
				}
			}
		}

		modifier = {
			factor = 50
			scope:recipient = {
				any_claim = {
					count >= 1
					exists = holder
					tier > tier_duchy
				}
			}
		}

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

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

		modifier = {
			factor = 0.4
			scope:recipient = {
				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 = 100
			scope:recipient = {
				has_character_modifier = agotma_claimant_final_modifier
			}
		}

		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
	}
}