﻿force_onto_council = {
	category = interaction_category_vassal
	interface_priority = 120
	icon = council

	desc = force_onto_council_desc
	notification_text = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:actor = { has_strong_hook = scope:recipient }
				}
				desc = force_onto_council.notification.strong_hook
			}
			desc = force_onto_council.notification.fallback
		}
	}

	special_interaction = force_onto_council_interaction
	interface = council_task_interaction

	should_use_extra_icon = {
		scope:actor = { has_usable_hook = scope:recipient }
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"

	is_shown = {
		scope:recipient != scope:actor
		scope:actor = {
			liege = scope:recipient
			NOT = {
				is_councillor = yes
			}
			# Merit based realms cannot force themselves onto the council - they should compete with merit and score instead
			NOT = { government_allows = merit }
		}

		trigger_if = {
			limit = {
				exists = scope:target.councillor
			}
			scope:target = { can_fire_position = yes }
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			custom_description = {
				text = "has_usable_hook_or_council_rights_through_vassal_contract"
				subject = scope:actor
				OR = {
					has_usable_hook = scope:recipient
					vassal_contract_has_flag = can_demand_council_seat
					vassal_contract_has_flag = can_demand_kurultai_seat
				}
			}
			is_adult = yes
			NOT = {
				is_at_war_with = scope:recipient
			}
			NAND = {
				has_council_position = councillor_court_chaplain
				faith = {
					OR = {
						has_doctrine = doctrine_clerical_succession_temporal_fixed_appointment
						has_doctrine = doctrine_clerical_succession_spiritual_fixed_appointment
					}
				}
			}
		}
	}

	has_valid_target_showing_failures_only = {
		trigger_if = {
			limit = {
				exists = scope:target.councillor
			}
			scope:target.councillor = {
				NOT = {
					is_blocked_from_being_fired_from_council_trigger = {
						COURT_OWNER = scope:recipient
					}
				}
			}
		}
	}

	on_accept = {
		scope:target = {
			save_scope_as = council_task
		}
		scope:actor = {
			if = {
				limit = {
					NOR = {
						vassal_contract_has_flag = can_demand_council_seat
						vassal_contract_has_flag = can_demand_kurultai_seat
					}
				}
				save_scope_value_as = {
					name = used_hook
					value = yes
				}
			}
			block_firing_councillor_effect = { COURT_OWNER = scope:recipient }
			#And notify exactly which councillor type they've become.
			hidden_effect = {
				send_interface_toast = {
					type = event_toast_effect_good
					title = force_onto_council.actor.tt
					left_icon = scope:recipient
					custom_tooltip = force_onto_council.actor.tt.duration
				}
			}
			stress_impact = { content = minor_stress_impact_gain }
		}
		scope:recipient = {
			assign_council_task = {
				target = scope:actor
				council_task = scope:council_task
			}
			custom_tooltip = force_onto_council.desc.tt
			#And notify exactly which councillor type they've become.
			hidden_effect = {
				send_interface_toast = {
					type = event_toast_effect_neutral
					title = force_onto_council.recipient.tt
					left_icon = scope:actor
					if = {
						limit = { exists = scope:used_hook }
						show_as_tooltip = { scope:actor = { use_hook = scope:recipient } }
					}
					custom_tooltip = force_onto_council.recipient.tt.duration
				}
			}
		}
		#Done in the end so that all tooltips will show correct information
		scope:actor = {
			if = {
				limit = {
					exists = scope:used_hook
				}
				use_hook = scope:recipient
			}
		}

		# If we're a clan this interaction affects unity
		add_clan_unity_interaction_effect = {
			CHARACTER = scope:actor
			TARGET = scope:recipient
			VALUE = medium_unity_loss
			DESC = clan_unity_forced_unto_council.desc
			REVERSE_NON_HOUSE_TARGET = no
		}
	}

	ai_set_target = {
		scope:actor = {
			random_list = {
				10 = {
					trigger = {
						exists = scope:recipient.council_task:councillor_chancellor
						can_be_chancellor_trigger = { COURT_OWNER = scope:recipient }
						scope:recipient = {
							NOT = { vassal_contract_has_flag = can_demand_kurultai_seat }
						}
					}
					modifier = {
						factor = diplomacy
					}
					modifier = {
						trigger = { highest_skill = diplomacy }
						factor = 10
					}
					scope:recipient.council_task:councillor_chancellor = {
						save_scope_as = target
					}
				}
				10 = {
					trigger = {
						exists = scope:recipient.council_task:councillor_steward
						can_be_steward_trigger = { COURT_OWNER = scope:recipient }
						scope:recipient = {
							NOT = { vassal_contract_has_flag = can_demand_kurultai_seat }
						}
					}
					modifier = {
						factor = stewardship
					}
					modifier = {
						trigger = { highest_skill = stewardship }
						factor = 10
					}
					scope:recipient.council_task:councillor_steward = {
						save_scope_as = target
					}
				}
				10 = {
					trigger = {
						exists = scope:recipient.council_task:councillor_marshal
						can_be_marshal_trigger = { COURT_OWNER = scope:recipient }
						scope:recipient = {
							NOT = { vassal_contract_has_flag = can_demand_kurultai_seat }
						}
					}
					modifier = {
						factor = martial
					}
					modifier = {
						trigger = { highest_skill = martial }
						factor = 10
					}
					scope:recipient.council_task:councillor_marshal = {
						save_scope_as = target
					}
				}
				10 = {
					trigger = {
						exists = scope:recipient.council_task:councillor_spymaster
						can_be_spymaster_trigger = { COURT_OWNER = scope:recipient }
						scope:recipient = {
							NOT = { vassal_contract_has_flag = can_demand_kurultai_seat }
						}
					}
					modifier = {
						factor = intrigue
					}
					modifier = {
						trigger = { highest_skill = intrigue }
						factor = 10
					}
					scope:recipient.council_task:councillor_spymaster = {
						save_scope_as = target
					}
				}
				10 = {
					trigger = {
						exists = scope:recipient.council_task:councillor_court_chaplain
						can_be_court_chaplain_trigger = { COURT_OWNER = scope:recipient }
						scope:recipient = {
							NOT = { vassal_contract_has_flag = can_demand_kurultai_seat }
						}
					}
					modifier = {
						factor = learning
					}
					modifier = {
						trigger = { highest_skill = learning }
						factor = 10
					}
					scope:recipient.council_task:councillor_court_chaplain = {
						save_scope_as = target
					}
				}
				# Kurultai Demanded
				10 = {
					trigger = {
						exists = scope:recipient.council_task:councillor_kurultai_1
						can_be_kurultai_trigger = {
							COURT_OWNER = scope:actor.liege_or_court_owner
							CP1 = councillor_kurultai_2
							CP2 = councillor_kurultai_3
							CP3 = councillor_kurultai_4
						}
						scope:recipient = {
							NOT = { vassal_contract_has_flag = can_demand_council_seat }
						}
					}
					modifier = {
						factor = martial
					}
					modifier = {
						trigger = { highest_skill = martial }
						factor = 10
					}
					scope:recipient.council_task:councillor_kurultai_1 = {
						save_scope_as = target
					}
				}
				# Repeated so they don't always demand the same position
				10 = {
					trigger = {
						exists = scope:recipient.council_task:councillor_kurultai_2
						can_be_kurultai_trigger = {
							COURT_OWNER = scope:actor.liege_or_court_owner
							CP1 = councillor_kurultai_1
							CP2 = councillor_kurultai_3
							CP3 = councillor_kurultai_4
						}
						scope:recipient = {
							NOT = { vassal_contract_has_flag = can_demand_council_seat }
						}
					}
					modifier = {
						factor = martial
					}
					modifier = {
						trigger = { highest_skill = martial }
						factor = 10
					}
					scope:recipient.council_task:councillor_kurultai_2 = {
						save_scope_as = target
					}
				}
				10 = {
					trigger = {
						exists = scope:recipient.council_task:councillor_kurultai_3
						can_be_kurultai_trigger = {
							COURT_OWNER = scope:actor.liege_or_court_owner
							CP1 = councillor_kurultai_1
							CP2 = councillor_kurultai_2
							CP3 = councillor_kurultai_4
						}
						scope:recipient = {
							NOT = { vassal_contract_has_flag = can_demand_council_seat }
						}
					}
					modifier = {
						factor = martial
					}
					modifier = {
						trigger = { highest_skill = martial }
						factor = 10
					}
					scope:recipient.council_task:councillor_kurultai_3 = {
						save_scope_as = target
					}
				}
				10 = {
					trigger = {
						exists = scope:recipient.council_task:councillor_kurultai_4
						can_be_kurultai_trigger = {
							COURT_OWNER = scope:actor.liege_or_court_owner
							CP1 = councillor_kurultai_1
							CP2 = councillor_kurultai_2
							CP3 = councillor_kurultai_3
						}
						scope:recipient = {
							NOT = { vassal_contract_has_flag = can_demand_council_seat }
						}
					}
					modifier = {
						factor = martial
					}
					modifier = {
						trigger = { highest_skill = martial }
						factor = 10
					}
					scope:recipient.council_task:councillor_kurultai_4 = {
						save_scope_as = target
					}
				}
			}
		}
	}

	ai_potential = {
		top_liege != this
		is_councillor = no
	}

	ai_targets = {
		ai_recipients = liege
	}
	ai_frequency_by_tier = {
		barony = 0
		county = 48
		duchy = 36
		kingdom = 24
		empire = 24
		hegemony = 0
	}

	auto_accept = yes
	force_notification = yes

	ai_will_do = {
		base = 0
		
		modifier = {
			add = 100
			scope:actor = {
			NOR = {
					has_trait = craven
					has_trait = content
					has_trait = humble
					has_trait = lazy
					has_trait = loyal
					has_relation_friend = scope:recipient
					has_relation_lover = scope:recipient
					has_relation_best_friend = scope:recipient
					has_relation_soulmate = scope:recipient
			}
			calc_true_if = {
				amount >= 1
					diplomacy > high_skill_rating
					martial > high_skill_rating
					stewardship > high_skill_rating
					learning > high_skill_rating
					intrigue > high_skill_rating
				}
			}
		}

		modifier = {
			add = 100
			scope:actor = {
			OR = {
					has_trait = ambitious
					has_trait = arrogant
					has_trait = impatient
					has_trait = stubborn
					has_trait = disloyal
			}
			calc_true_if = {
				amount >= 1
					diplomacy > medium_skill_rating
					martial > medium_skill_rating
					stewardship > medium_skill_rating
					learning > medium_skill_rating
					intrigue > medium_skill_rating
				}
			}
		}

		
		modifier = {
			factor = 0
			is_councillor = yes
		}
	}
}
