﻿teach_governor = {
	# Basic Setup
	skill = stewardship
	desc = "teach_governor_desc_general"
	success_desc = "TEACH_GOVERNOR_SUCCESS_DESC"
	icon =	icon_teach_governor
	illustration = "gfx/interface/illustrations/event_scenes/corridor.dds"
	category = political
	target_type = character

	is_secret = no
	is_basic = yes

	# Parameters
	speed_per_skill_point = -2.5
	spymaster_speed_per_skill_point = 0	
	uses_resistance = no
	base_progress_goal = 365
	base_maximum_success = 95
	minimum_success = 10

	# Core Triggers
	allow = {
		is_adult = yes
		is_imprisoned = no
		custom_tooltip = {
			text = governor_or_governor_trait_tt
			OR = {
				this = scope:target.top_liege
				is_governor = yes
				has_trait = governor
			}
		}
		NOT = { has_trait = incapable }
	}

	valid = {
		scope:owner = {
			custom_tooltip = {
				text = teach_governor_office_building_tt
				domicile ?= { has_domicile_parameter = estate_unlock_teach_governor_interaction }
			}
			is_imprisoned = no
			custom_tooltip = {
				text = governor_or_governor_trait_tt
				OR = {
					this = scope:target.top_liege
					is_governor = yes
					has_trait = governor
				}
			}
			NOT = { has_trait = incapable }
			NOT = { is_at_war_with = scope:target }
		}
		scope:target = {
			age >= 12
			is_imprisoned = no
			top_liege = scope:owner.top_liege
			in_diplomatic_range = scope:owner
			NOT = { has_relation_rival = scope:owner }
		}
	}

	odds_prediction = {
		add = base_odds_prediction_target_is_char_value
		add = odds_skill_contribution_stewardship_value
		add = odds_ep3_teach_governor_scheme_misc_value
		min = 0
	}

	# Base Chances
	base_success_chance = {
		base = 0
		# Skill
		compare_modifier = {
			desc = "SCHEME_MY_STEWARDSHIP"
			value = scope:owner.stewardship
			multiplier = 2
		}
		modifier = {
			desc = "THEIR_STEWARDSHIP"
			add = scope:target.stewardship
		}
		# Diarchs are better at schemes within their liege's realm
		diarch_scheming_within_realm_bonus_modifier = yes
		# Opinion
		opinion_modifier = {
			who = scope:target
			opinion_target = scope:owner
			multiplier = 0.5
		}
		# Relative XP
		modifier = {
			desc = "OWNER_GOVERNOR_XP"
			add = {
				value = 0
				scope:owner = {
					if = {
						limit = {
							NOT = { has_trait = governor }
						}
						add = -10
					}
					else_if = {
						limit = { has_trait_xp = { trait = governor value < 25 } }
						add = -5
					}
					else = {
						add = 5
						if = {
							limit = { has_trait_xp = { trait = governor value >= 50 } }
							add = 5
						}
						if = {
							limit = { has_trait_xp = { trait = governor value >= 75 } }
							add = 5
						}
						if = {
							limit = { has_trait_xp = { trait = governor value >= 100 } }
							add = 5
						}
					}
				}
			}
		}
		modifier = {
			desc = TARGET_GOVERNOR_XP
			add = {
				value = 0
				scope:target = {
					if = {
						limit = {
							NOT = { has_trait = governor }
							scope:owner = { has_trait = governor }
						}
						add = 10
					}
					else_if = {
						limit = { has_trait_xp = { trait = governor value < 25 } }
						add = 5
					}
					else = {
						if = {
							limit = { has_trait_xp = { trait = governor value >= 25 } }
							add = -5
						}
						if = {
							limit = { has_trait_xp = { trait = governor value >= 50 } }
							add = -5
						}
						if = {
							limit = { has_trait_xp = { trait = governor value >= 75 } }
							add = -5
						}
						if = {
							limit = { has_trait_xp = { trait = governor value >= 100 } }
							add = -5
						}
					}
				}
			}
		}
		# Age
		modifier = {
			desc = AGE_DIFFERENCE
			add = {
				value = scope:owner.age
				add = {
					value = scope:target.age
					multiply = -1
				}
			}
		}
		modifier = {
			add = 10
			scope:owner = { has_relation_friend = scope:target }
			desc = AI_YOUR_FRIEND
		}
		# Personality
		modifier = {
			add = -5
			scope:target = { has_trait = lazy }
			desc = SCHEME_TARGET_LAZY
		}
		modifier = {
			add = -10
			scope:owner = { has_trait = lazy }
			desc = SCHEME_OWNER_LAZY
		}
		modifier = {
			add = -5
			scope:target = { has_trait = diligent }
			desc = SCHEME_TARGET_DILIGENT
		}
		modifier = {
			add = -10
			scope:owner = { has_trait = diligent }
			desc = SCHEME_OWNER_DILIGENT
		}
		# Fam
		modifier = {
			add = 10
			scope:owner = { is_parent_of = scope:target }
			desc = SCHEME_TARGET_CHILD
		}
		modifier = {
			add = 5
			scope:owner = { is_close_family_of = scope:target }
			NOT = { scope:owner = { is_parent_of = scope:target } }
			desc = SCHEME_TARGET_CLOSE_FAMILY
		}
		modifier = {
			add = 5
			scope:owner.house = scope:target.house
			desc = SCHEME_TARGET_SAME_HOUSE
		}
		# Trait Compatibility
		modifier = {
			scope:owner = {
				trait_compatibility = { target = scope:target value >= low_positive_trait_compatibility }
			}
			desc = TRAIT_COMPATIBILITY
			add = {
				value = 5
				scope:owner = {
					if = {
						limit = {
							trait_compatibility = { target = scope:target value >= medium_positive_trait_compatibility }
						}
						add = 5
						if = {
							limit = {
								trait_compatibility = { target = scope:target value >= high_positive_trait_compatibility }
							}
							add = 5
						}
					}
				}
			}
		}
		modifier = {
			scope:owner = {
				trait_compatibility = { target = scope:target value <= low_negative_trait_compatibility }
			}
			desc = TRAIT_COMPATIBILITY
			add = {
				value = -5
				scope:owner = {
					if = {
						limit = {
							trait_compatibility = { target = scope:target value <= medium_negative_trait_compatibility }
						}
						add = -5
						if = {
							limit = {
								trait_compatibility = { target = scope:target value <= high_negative_trait_compatibility }
							}
							add = -5
						}
					}
				}
			}
		}
		# 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
		}

		# Distance Penalty
		ttd_medium_distance_success_chance_modifier = yes
	}

	# On Actions
	on_phase_completed = {
		scheme_owner = { trigger_event = scheme_critical_moments.8041 }
	}

	## Invalidation
	on_invalidated = {
		scheme_target_character = { save_scope_as = target }
		scheme_owner = {
			save_scope_as = owner
			send_interface_toast = {
				type = event_toast_effect_neutral
				title = teach_governor_invalidated_title
				left_icon = scope:target
				if = { # Invalidation due to death
					limit = {
						scope:target = { is_alive = no }
						NOT = { block_death_event_trigger = { DEAD = scope:target } }
					}
					custom_tooltip = scheme_target_died
				}
				else_if = { # Diplo range: is it relevant here?
					limit = {
						scope:target = { 
							NOT = { in_diplomatic_range = scope:owner } 
						}
					}
					custom_tooltip = scheme_target_not_in_diplomatic_range
				}
				else_if = {
					limit = {
						scope:target = { is_governor = no }
					}
					custom_tooltip = scheme_target_not_a_governor
				}
				else_if = {
					limit = {
						scope:target = { is_governor = no }
					}
					custom_tooltip = scheme_target_not_a_governor
				}
				scope:target = {
					if = {
						limit = {
							is_alive = yes
							is_ai = yes
						}
						remove_opinion = {
							target = scope:owner
							modifier = mentoring_governor_opinion
						}
					}
				}
			}
		}
	}
}
