##################################################
# #Decisions
# diarch_attempt_to_overthrow_liege		Diarch attempts to coup Liege
#

#############################################
# Attempt Overthrow of Liege
# by Ewan Cowhig Croft
#############################################

diarch_attempt_to_overthrow_liege = {
	desc = diarch_attempt_to_overthrow_liege_desc
	confirm_text = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:coup_prowess = yes }
				desc = diarch_attempt_to_overthrow_liege_confirm.prowess
			}
			desc = diarch_attempt_to_overthrow_liege_confirm
		}
	}
	selection_tooltip = diarch_attempt_to_overthrow_liege_tooltip
#	picture = {
#		trigger = {
#			NOR = {
#				government_has_flag = government_is_tribal
#				government_has_flag = government_is_theocracy
#				top_liege ?= { government_has_flag = government_is_tribal }
#				top_liege ?= { government_has_flag = government_is_theocracy }
#			}
#			OR = {
#				culture = { has_cultural_pillar = heritage_byzantine }
#				top_liege ?= {
#					OR = {
#						culture = { has_cultural_pillar = heritage_byzantine }
#						capital_barony ?= title:b_constantinople
#						is_roman_emperor_primary_title_trigger = yes
#					}
#				}
#			}
#		}
#		reference = "gfx/interface/illustrations/decisions/ep3_cerimonial_decision.dds"
#	}
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_knight_kneeling.dds"
	}
	decision_group_type = major

	is_shown = {
		# If you're not in a diarchy, we don't care.
		OR = {
			AND = {
				exists = liege
				is_diarch_of_target = liege
			}
			is_designated_diarch = yes
		}
	}

	is_valid = {
		diarch_coup_attempt_is_valid_trigger = { LIEGE = root.liege }

		# Extra condition for Vizier
		trigger_if = {
			limit = { has_diarchy_active_parameter = diarchy_is_vizierate }
			prestige_level >= very_high_prestige_level
			trigger_if = {
				limit = {
					exists = liege.house
					house ?= liege.house
				}
				house = { has_house_unity_stage = antagonistic }
			}
		}
	}

	is_valid_showing_failures_only = {
		diarch_coup_attempt_is_valid_showing_failure_only_trigger = { DIARCH = root }
	}

	widget = {
		gui = "decision_view_widget_option_list_generic"
		controller = decision_option_list_controller
		decision_to_second_step_button = "diarch_attempt_to_overthrow_liege.second_step"

		# Diplomacy Coup.
		item = {
			value = coup_diplomacy
			current_description = diarch_attempt_to_overthrow_liege.tt.coup_diplomacy_desc
			localization = diarch_attempt_to_overthrow_liege.tt.coup_diplomacy
			icon = "gfx/interface/icons/message_feed/diplomacy.dds"
			is_valid = { always = yes }
			ai_chance = {
				value = 0
				# If this is our highest skill, weight it up.
				if = {
					limit = {
						highest_skill = diplomacy
						diplomacy >= prowess
					}
					add = 100
				}
			}
		}
		# Intrigue Coup.
		item = {
			value = coup_intrigue
			current_description = diarch_attempt_to_overthrow_liege.tt.coup_intrigue_desc
			localization = diarch_attempt_to_overthrow_liege.tt.coup_intrigue
			icon = "gfx/interface/icons/message_feed/intrigue.dds"
			is_valid = { always = yes }
			ai_chance = {
				value = 0
				# If this is our highest skill, weight it up.
				if = {
					limit = {
						highest_skill = intrigue
						intrigue >= prowess
					}
					add = 100
				}
			}
		}
		# Prowess Coup.
		item = {
			value = coup_prowess
			current_description = diarch_attempt_to_overthrow_liege.tt.coup_prowess_desc
			localization = diarch_attempt_to_overthrow_liege.tt.coup_prowess
			icon = "gfx/interface/icons/icon_prowess.dds"
			is_valid = { always = yes }
			ai_chance = {
				value = 0
				# If this is our highest skill, weight it up.
				if = {
					limit = {
						prowess >= diplomacy
						prowess >= martial
						prowess >= stewardship
						prowess >= intrigue
						prowess >= learning
					}
					add = 100
					
				}
			}
		}
	}

	effect = {
		# Save some scopes for loc.
		save_scope_as = usurper
		liege = { save_scope_as = liege }
		# Fire the misc assorted effects we want here & for the AI path.
		diarch_coup_preamble_effects_effect = yes
		# Right, so how does this work?
		custom_tooltip = diarch_attempt_to_overthrow_liege.tt.coup_types
		custom_tooltip = diarch_attempt_to_overthrow_liege.tt.liege_response
		custom_tooltip = diarch_attempt_to_overthrow_liege.tt.liege_response.information_on_converting_councillors
		custom_tooltip = diarch_attempt_to_overthrow_liege.tt.consequences
		# Now, show what's gonna happen.
		random_list = {
			# If scope:liege accepts their fate, this can all end peacefully.
			100 = {
				desc = diarch_attempt_to_overthrow_liege.tt.liege_accepts
				show_chance = no
				# You take all top-tier titles.
				custom_tooltip = diarch_attempt_to_overthrow_liege.tt.liege_accepts.usurp_targets.primary
				# If there's a suitable kingdom title, you'll absorb that too.
				## By suitable, we mean "one that has some lands within the sub-realm".
				if = {
					limit = {
						liege = {
							diarch_coup_attempt_grabbable_kingdom_trigger = { TARGET = root.liege }
						}
					}
					custom_tooltip = diarch_attempt_to_overthrow_liege.tt.liege_accepts.usurp_targets.kingdom
				}
				# If they hold the de jure capital & its duchy, you'll take _those_, thank you.
				if = {
					limit = {
						liege = {
							any_held_title = {
								diarch_coup_attempt_grabbable_capital_and_duchies_trigger = { TARGET = root.liege }
							}
						}
					}
					custom_tooltip = diarch_attempt_to_overthrow_liege.tt.liege_accepts.usurp_targets.capital
				}
				# Remaining lands stay with scope:liege.
				custom_tooltip = diarch_attempt_to_overthrow_liege.tt.liege_accepts.keep_more_titles
				custom_tooltip = diarch_attempt_to_overthrow_liege.tt.liege_accepts.remains_ruling
			}
			# If scope:liege puts up a fight and loses, you bust them down.
			100 = {
				desc = diarch_attempt_to_overthrow_liege.tt.liege_fights_and_loses
				show_chance = no
				# Most lands stay with scope:liege.
				custom_tooltip = diarch_attempt_to_overthrow_liege.tt.liege_fights_and_loses.take_more_titles
				custom_tooltip = diarch_attempt_to_overthrow_liege.tt.liege_fights_and_loses.may_lose_everything
			}
			# And if things go wrong?
			## Diplomacy Coup.
			100 = {
				desc = diarch_attempt_to_overthrow_liege.tt.diplomacy_coup
				show_chance = no
				custom_tooltip = diarch_attempt_to_overthrow_liege.tt.win.liege_lives
				custom_tooltip = diarch_attempt_to_overthrow_liege.tt.win.considered_merciful
				custom_tooltip = diarch_attempt_to_overthrow_liege.tt.lose.usurper_captured
			}
			## Intrigue Coup.
			100 = {
				desc = diarch_attempt_to_overthrow_liege.tt.intrigue_coup
				show_chance = no
				custom_tooltip = diarch_attempt_to_overthrow_liege.tt.win.liege_captured
				custom_tooltip = diarch_attempt_to_overthrow_liege.tt.lose.usurper_captured
			}
			## Prowess Coup.
			100 = {
				desc = diarch_attempt_to_overthrow_liege.tt.prowess_coup
				show_chance = no
				custom_tooltip = diarch_attempt_to_overthrow_liege.tt.win.liege_dies
				custom_tooltip = diarch_attempt_to_overthrow_liege.tt.loss.usurper_dies
			}
		} 
		# Compile our final conspirator list.
		diarch_finalise_conspirators_for_overthrow_list_effect = yes
		# Send out the actual events.
		liege = {
			# Diplomacy.
			if = {
				limit = { scope:coup_diplomacy = yes }
				trigger_event = diarchy.9001
			}
			# Intrigue.
			if = {
				limit = { scope:coup_intrigue = yes }
				trigger_event = diarchy.9011
			}
			# Prowess.
			if = {
				limit = { scope:coup_prowess = yes }
				trigger_event = diarchy.9021
			}
		}
	}

	cost = {
		gold = {
			value = major_gold_value
			if = {
				limit = {
					has_character_flag = laid_coup_groundwork_flag
				}
				multiply = 0.1
			}
		}
		prestige = {
			value = 1000
			if = {
				limit = {
					has_character_flag = laid_coup_groundwork_flag
				}
				multiply = 0.1
			}
		}
	}

	# The AI takes this via interaction, as we need to account for landless characters.
	ai_check_interval = 0

	# Handled via interaction.
	ai_potential = { always = no }
}
