﻿############################
# Damage Legitimacy Scheme
# (Only for Governors against the Emperor)
############################

damage_legitimacy_scheme = {
	# Basic Setup
	skill = intrigue
	desc = damage_legitimacy_scheme_desc_general
	success_desc = "DAMAGE_LEGITIMACY_SUCCESS_DESC"
	discovery_desc = "DAMAGE_LEGITIMACY_DISCOVERY_DESC"
	icon = icon_scheme_damage_legitimacy
	illustration = "gfx/interface/illustrations/event_scenes/corridor.dds"
	target_type = character
	category = political
	is_secret = yes
	maximum_breaches = 5
	is_basic = yes
	cooldown = { years = 5 }
	
	# Parameters
	speed_per_skill_point = -2.5
	spymaster_speed_per_skill_point = 0	
	uses_resistance = no
	base_progress_goal = 180
	base_maximum_success = 95
	minimum_success = 5

	freeze_scheme_when_traveling = yes
	freeze_scheme_when_traveling_target = no
	
	# Only for Governors against the Emperor
	allow = {
		is_adult = yes
		is_imprisoned = no
		is_governor = yes
		scope:target = {
			this = root.liege
		}
	}
	
	# Core Triggers
	valid = {
		is_alive = yes
		is_adult = yes
		is_imprisoned = no
		is_incapable = no
		scope:target = {
			is_alive = yes
		}
	}

	odds_prediction = {
		add = base_odds_prediction_target_is_char_value
		add = odds_skill_contribution_intrigue_value
		min = 0
	}

	# Base Chances
	base_success_chance = {
		base = 0
		
		# Skill
		compare_modifier = {
			desc = "SCHEME_YOUR_INTRIGUE"
			value = scope:owner.intrigue
			multiplier = 2
		}
		compare_modifier = {
			desc = "SCHEME_LIEGE_INTRIGUE"
			value = scope:target.intrigue
			multiplier = -0.5
		}
		
		# Countermeasures
		apply_political_scheme_success_chance_adjustments_modifier = yes
		
		# Popular Opinion of Target's Capital
		compare_modifier = {
			desc = "SCHEME_LIEGE_POPULAR_OPINION"
			value = scope:target.capital_county.county_opinion
			multiplier = -1
		}
		
		# Traits
		modifier = {
			add = 10
			desc = overseer_trait_desc
			scope:owner = {
				has_trait = schemer
			}
		}
		# house_head_request_interaction
		modifier = {
			add = political_scheme_variable_list_value
			scope:owner = {
				has_variable_list = supporting_political_schemes
			}
			desc = HOUSE_HEAD_SCHEME_SUPPORT_DESC
		}
		modifier = {
			add = -10
			scope:owner = { has_character_modifier = political_schemes_distracted_modifier }
			desc = political_schemes_distracted_modifier
		}
		modifier = {
			scope:owner = {
				has_character_modifier = united_political_agents_modifier
				is_vassal_of = scope:target
			}
			desc = united_political_agents_modifier
			add = 15
		}

		# Distance Penalty
		ttd_medium_distance_success_chance_modifier = yes
	}
	base_secrecy = {
		add = secrecy_base_value
		add = countermeasure_apply_secrecy_maluses_value
		add = eparch_scheme_secrecy_bonus_value
	}
	
	# On Actions
	on_start = {
		set_variable = {
			name = apply_countermeasures
			value = flag:political
		}
	}
	on_phase_completed = {
		save_scope_as = scheme
		scope:scheme = {
			scheme_target_character = { save_scope_as = target }
			scheme_owner = {
				save_scope_as = owner

				#SUCCESS ROLL
				random = {
					chance = scope:scheme.scheme_success_chance 

					save_scope_value_as = {
						name = scheme_successful
						value = yes
					}
				}

				if = {
					limit = {
						exists = scope:scheme_successful
					}
					trigger_event = {
						id = scheme_critical_moments.4011
						days = 1
					}
				}
				else = {
					trigger_event = {
						id = scheme_critical_moments.4012
						days = 1
					}	
				}
			}
		}
	}
	on_monthly = {
		hostile_scheme_monthly_discovery_chance_effect = yes
	}
	on_invalidated = {
		scheme_target_character = {
			save_scope_as = target
		}
		scheme_owner = {
			save_scope_as = owner
		}
		# Invalidation due to death
		if = {
			limit = {
				scope:target = { is_alive = no }
				scope:owner = { is_alive = yes }
			}
			scope:owner = {
				send_interface_toast = {
					title = damage_legitimacy_scheme_invalidated_title
					left_icon = scope:target
					custom_description_no_bullet = {
						object = scope:target
						text = scheme_target_died
					}
				}
			}
		}
		# They're not your liege anymore
		else_if = {
			limit = {
				scope:target = {
					this != scope:owner.liege
				}
			}
			scope:owner = {
				send_interface_toast = {
					title = damage_legitimacy_scheme_invalidated_title
					left_icon = scope:target
					custom_description_no_bullet = {
						object = scope:target
						text = scheme_target_not_liege
					}
				}
			}
		}
		# You're not a governor
		else_if = {
			limit = {
				scope:target = {
					this = scope:owner.liege
				}
			}
			scope:owner = {
				send_interface_toast = {
					title = damage_legitimacy_scheme_invalidated_title
					left_icon = scope:target
					custom_description_no_bullet = {
						object = scope:target
						text = scheme_owner_not_governor
					}
				}
			}
		}
	}
}
