﻿agotma_instigator_interaction = {
	icon = icon_agotma_instigator
	category = interaction_category_friendly
	desc = agotma_instigator_interaction_desc
	interface_priority = 100
	common_interaction = yes

	ai_targets = {
		ai_recipients = liege
	}
	ai_targets = {
		ai_recipients = councillors
		ai_recipients = neighboring_rulers
		ai_recipients = vassals
		ai_recipients = peer_vassals
		# ai_recipients = top_realm_domicile_owners
		chance = 0.25
	}
	ai_frequency = 12


	is_shown = {
		trigger_if = {
			limit = { scope:actor = { is_ai = yes }	}
			has_game_rule = agotma_instigator_enabled
		}
		trigger_if = {
			limit = { scope:actor = { is_ai = yes }	}
			exists = scope:actor.top_liege.primary_title
			scope:actor.top_liege = {
				primary_title = {
					NOT = { has_variable = agotma_instigator_started_ai }
				}
			}
		}
		scope:actor = {
			NOT = { has_trait = incapable }
			NOT = { has_variable = agotma_instigation_completed }
			NOT = { any_owned_story = { story_type = agotma_instigator_story } }
			is_landed = yes
			highest_held_title_tier >= tier_county
			is_adult = yes
		}
		scope:recipient = {
			is_playable_character = yes
			OR = {
				has_government = lp_feudal_government
				has_government = feudal_government
				government_has_flag = government_is_landless_adventurer
			}
			agot_can_be_ruler = yes
			trigger_if = {
				limit = {
					OR = {
						has_government = lp_feudal_government
						has_government = feudal_government
					}
				}
				highest_held_title_tier >= tier_county
				NOT = { scope:recipient = scope:recipient.top_liege }
				NOT = { scope:recipient = scope:recipient.liege }
			}
			any_claim = {
				count >= 1
				agotma_instigator_valid_claim = { ACTOR = scope:actor RECIPIENT = scope:recipient }
			}
			NOT = { has_trait = content }
			NOT = { has_trait = craven }
			NOT = { has_character_flag = already_instigated }
		}
		NOT = { scope:recipient = scope:actor }
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			is_adult = yes
			is_at_home = yes
			NOT = { has_character_modifier = agotma_instigator_provoked_war }
		}
		scope:recipient = { is_adult = yes }
		scope:actor.top_liege = {
			custom_description = {
				text = agotma_character_blocked_from_instigator
				primary_title = {
					NOT = {
						has_variable = agotma_instigator_started
					}
				}
			}
		}
	}

	cost = {
		# Nothing
	}

	auto_accept = yes

	on_accept = {
		scope:actor.top_liege.primary_title = {
			set_variable = {
				name = agotma_instigator_started
				years = 3
			}
			set_variable = {
				name = agotma_instigator_started_ai
				years = { 4 6 }
			}
		}
		scope:actor = {
			scope:recipient = {
				ordered_claim = {
					order_by = tier
					limit = {
						agotma_instigator_valid_claim = { ACTOR = scope:actor RECIPIENT = scope:recipient }
					}
					scope:actor = {
						set_variable = {
							name = agotma_war_target_temp
							value = prev
						}
					}
				}
			}
			if = {
				limit = { NOT = { any_owned_story = { story_type = agotma_instigator_story } } }
				set_variable = {
					name = agotma_instigated_char_temp
					value = scope:recipient
				}
				create_story = agotma_instigator_story
			}
		}
	}

	ai_potential = {
		has_game_rule = agotma_instigator_enabled
		NOT = { has_trait = incapable }
		NOT = { has_variable = agotma_instigation_completed }
		NOT = { any_owned_story = { story_type = agotma_instigator_story } }
		is_landed = yes
		highest_held_title_tier >= tier_county
		is_adult = yes
		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 = 3
			scope:actor.liege = scope:recipient.liege
		}

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

		modifier = {
			factor = 10
			scope:recipient = {
				highest_held_title_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 = 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 }
		}
	}
}