namespace = ep3_governor_yearly

##################################################
#	EP3 Governor Events
#	by  Joe Parkin

scripted_trigger ep3_governor_involved_with_root_or_liege_trigger = {
	OR = {
		trigger_if = {
			limit = { exists = house }
			OR = {
				root.house ?= house
				root.top_liege.house ?= house
			}
		}
		is_close_family_of = root
		is_close_family_of = root.top_liege
		is_consort_of = root
		is_consort_of = root.top_liege
		has_any_scripted_relation = root
		has_any_scripted_relation = root.top_liege
	}
}

#####################################
# Scratching Backs					#
# by Joe Parkin						#
# 8010	 							#
#####################################

scripted_trigger ep3_governor_8010_governor_trigger = {
	this != root
	is_available_adult = yes
	is_governor = yes
	is_ai = yes
	ep3_governor_involved_with_root_or_liege_trigger = no
	NOR = {
		house_has_feud_relation_with_trigger = { TARGET = root }
		has_trait = content
		has_trait = honest
		has_trait = humble
	}
}

scripted_effect ep3_governor_8010_offer_demand_effect = {
	switch = {
		trigger = $FLAG_SCOPE$
		flag:hook = {
			$RECEIVER$ = {
				add_hook = {
					target = $GIVER$
					type = obligation_hook
				}
			}
		}
		flag:candidacy = {
			$TITLE$ = {
				change_appointment_investment = {
					target = $TITLE_RECEIVER$
					value = appointment_score_minor_value
				}
			}
		}
		flag:influence = {
			$RECEIVER$ = { change_influence = medium_influence_gain }
		}
		flag:gold = {
			$GIVER$ = {
				pay_short_term_gold = {
					gold = medium_gold_value
					target = $RECEIVER$
				}
			}
		}
	}
}

ep3_governor_yearly.8010 = {
	type = letter_event
	opening = ep3_governor_yearly.8010.opening
	desc = {
		desc = ep3_governor_yearly.8010.desc
		first_valid = {
			triggered_desc = {
				trigger = { scope:governor_request = flag:hook }
				desc = ep3_governor_yearly.8010.hook
			}
			triggered_desc = {
				trigger = { scope:governor_request = flag:candidacy }
				desc = ep3_governor_yearly.8010.candidacy
			}
			triggered_desc = {
				trigger = { scope:governor_request = flag:influence }
				desc = ep3_governor_yearly.8010.influence
			}
			desc = ep3_governor_yearly.8010.gold
		}
		desc = ep3_governor_yearly.8010.end
	}
	sender = {
		character = scope:governor
		animation = schadenfreude
	}

	cooldown = { years = 10 }

	trigger = {
		is_available_adult = yes
		is_governor = yes
		top_liege = {
			any_vassal = { ep3_governor_8010_governor_trigger = yes }
		}
	}

	immediate = {
		top_liege = {
			random_vassal = {
				limit = {
					ep3_governor_8010_governor_trigger = yes
					OR = {
						has_trait = ambitious
						has_trait = arrogant
						has_trait = deceitful
					}
					any_neighboring_realm_same_rank_owner = { this = root }
				}
				alternative_limit = {
					ep3_governor_8010_governor_trigger = yes
					OR = {
						has_trait = ambitious
						has_trait = arrogant
						has_trait = deceitful
					}
				}
				alternative_limit = { ep3_governor_8010_governor_trigger = yes }
				weight = {
					base = 100
					modifier = { add = ai_energy }
					modifier = { add = ai_boldness }
					is_of_major_interest_to_weight_up_modifier = { CHARACTER = root }
					is_of_minor_interest_to_weight_up_modifier = { CHARACTER = root }
				}
				save_scope_as = governor
				ordered_heir_title = {
					limit = {
						has_order_of_succession = appointment
						tier >= tier_duchy
					}
					order_by = "place_in_line_of_succession(root)"
					save_scope_as = their_title
				}
				save_scope_as = their_title_receiver
				if = {
					limit = {
						NOR = {
							exists = scope:their_title
							primary_heir ?= root.top_liege
						}
					}
					primary_heir ?= {
						ordered_heir_title = {
							limit = {
								has_order_of_succession = appointment
								tier >= tier_duchy
							}
							order_by = "place_in_line_of_succession(scope:governor.primary_heir)"
							save_scope_as = their_title
						}
						save_scope_as = their_title_receiver
					}
				}
				if = {
					limit = {
						NOT = { exists = scope:their_title }
					}
					top_liege.primary_title = { save_scope_as = their_title }
				}
				if = {
					limit = {
						NOT = { exists = scope:title_receiver }
					}
					save_scope_as = title_receiver
				}
			}
		}
		ordered_heir_title = {
			limit = {
				has_order_of_succession = appointment
				tier >= tier_duchy
			}
			order_by = "place_in_line_of_succession(root)"
			save_scope_as = title
		}
		save_scope_as = title_receiver
		if = {
			limit = {
				NOR = {
					exists = scope:title
					primary_heir ?= root.top_liege
				}
			}
			primary_heir ?= {
				ordered_heir_title = {
					limit = {
						has_order_of_succession = appointment
						tier >= tier_duchy
					}
					order_by = "place_in_line_of_succession(root.primary_heir)"
					save_scope_as = title
				}
				save_scope_as = title_receiver
			}
		}
		if = {
			limit = {
				NOT = { exists = scope:title }
			}
			top_liege.primary_title = { save_scope_as = title }
		}
		if = {
			limit = {
				NOT = { exists = scope:title_receiver }
			}
			save_scope_as = title_receiver
		}
		hidden_effect = {
			random_list = {
				10 = {
					trigger = {
						NOT = {
							scope:governor = { has_hook = root }
						}
					}
					modifier = { add = scope:governor.intrigue }
					save_scope_value_as = {
						name = governor_request
						value = flag:hook
					}
				}
				10 = {
					trigger = {
						exists = scope:their_title
						exists = scope:their_title_receiver
						scope:their_title = { has_order_of_succession = appointment }
					}
					modifier = {
						add = 10
						scope:governor = { has_trait = ambitious }
					}
					modifier = {
						add = 10
						scope:governor = { has_claim_on = root.top_liege.primary_title }
					}
					save_scope_value_as = {
						name = governor_request
						value = flag:candidacy
					}
				}
				10 = {
					save_scope_value_as = {
						name = governor_request
						value = flag:influence
					}
				}
				10 = {
					trigger = { root.gold > root.major_gold_value }
					modifier = {
						add = {
							value = scope:governor.ai_greed
							multiply = 0.25
						}
					}
					save_scope_value_as = {
						name = governor_request
						value = flag:gold
					}
				}
			}
			random_list = {
				5 = {
					trigger = {
						NOR = {
							scope:governor_request ?= flag:hook
							has_hook = scope:governor
						}
					}
					modifier = { add = scope:governor.intrigue }
					save_scope_value_as = {
						name = governor_offer
						value = flag:hook
					}
				}
				10 = {
					trigger = {
						NOT = { scope:governor_request ?= flag:candidacy }
						exists = scope:title
						exists = scope:title_receiver
						scope:their_title = { has_order_of_succession = appointment }
					}
					modifier = {
						add = 10
						has_trait = ambitious
					}
					modifier = {
						add = 10
						has_claim_on = root.top_liege.primary_title
					}
					save_scope_value_as = {
						name = governor_offer
						value = flag:candidacy
					}
				}
				10 = {
					trigger = {
						NOT = { scope:governor_request ?= flag:influence }
					}
					save_scope_value_as = {
						name = governor_offer
						value = flag:influence
					}
				}
				10 = {
					trigger = {
						NOT = { scope:governor_request ?= flag:gold }
						scope:governor.gold > scope:governor.major_gold_value
					}
					modifier = {
						gold < minor_gold_value
						add = 10
					}
					modifier = {
						gold < 0
						add = 10
					}
					save_scope_value_as = {
						name = governor_offer
						value = flag:gold
					}
				}
			}
		}
	}

	option = { # Accept
		name = ep3_governor_yearly.8010.a
		ep3_governor_8010_offer_demand_effect = {
			FLAG_SCOPE = scope:governor_offer
			GIVER = scope:governor
			RECEIVER = root
			TITLE = scope:title
			TITLE_RECEIVER = scope:title_receiver
		}
		ep3_governor_8010_offer_demand_effect = {
			FLAG_SCOPE = scope:governor_request
			GIVER = root
			RECEIVER = scope:governor
			TITLE = scope:their_title
			TITLE_RECEIVER = scope:their_title_receiver
		}
		reverse_add_opinion = {
			target = scope:governor
			modifier = pleased_opinion
			opinion = 10
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = 2
				ai_boldness = 1
				ai_honor = -2
				ai_energy = 1
			}
		}
	}

	option = { # Reverse
		name = ep3_governor_yearly.8010.b
		duel = {
			skills = { intrigue diplomacy }
			target = scope:governor
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = 1
				}
				desc = ep3_governor_yearly.8010.b.success
				send_interface_toast = {
					type = event_toast_effect_good
					title = ep3_governor_yearly.8010.b.success
					right_icon = scope:governor
					ep3_governor_8010_offer_demand_effect = {
						FLAG_SCOPE = scope:governor_offer
						GIVER = root
						RECEIVER = scope:governor
						TITLE = scope:their_title
						TITLE_RECEIVER = scope:their_title_receiver
					}
					ep3_governor_8010_offer_demand_effect = {
						FLAG_SCOPE = scope:governor_request
						GIVER = scope:governor
						RECEIVER = root
						TITLE = scope:title
						TITLE_RECEIVER = scope:title_receiver
					}
				}
			}
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = 1
				}
				desc = ep3_governor_yearly.8010.b.failure
				send_interface_toast = {
					type = event_toast_effect_bad
					title = ep3_governor_yearly.8010.b.failure
					right_icon = scope:governor
					reverse_add_opinion = {
						target = scope:governor
						modifier = annoyed_opinion
						opinion = -15
					}
				}
			}
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = 1
				ai_boldness = 1
				ai_honor = -1
			}
		}
	}

	option = { # Refuse
		name = ep3_governor_yearly.8010.c
		reverse_add_opinion = {
			target = scope:governor
			modifier = disappointed_opinion
			opinion = -10
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = -1
				ai_boldness = -1
				ai_honor = 1
			}
		}
	}
}

#####################################
# Provincial Leverage				#
# by Joe Parkin						#
# 8020	 							#
#####################################

scripted_trigger ep3_governor_8020_estate_holder_trigger = {
	this != root
	is_ai = yes
	domicile ?= {
		is_domicile_type = estate
		OR = {
			domicile_location.county.holder ?= root
			domicile_location.county.holder.liege ?= root
			domicile_location.county.holder.liege.liege ?= root
		}
		num_domicile_buildings >= 3
	}
	is_available_adult = yes
	ep3_governor_involved_with_root_or_liege_trigger = no
}

scripted_effect ep3_governor_8020_fail_effect = {
	send_interface_toast = {
		type = event_toast_effect_bad
		title = ep3_governor_yearly.8020.failure
		right_icon = scope:estate_owner
		
		scope:estate_owner = { save_scope_as = recipient } # For loc reasons
		custom_tooltip = {
			text = raid_estate_destroy_buildings_tt
			scope:other_estate = {
				destroy_random_estate_building_variable_effect = yes
				destroy_random_estate_building_effect = yes
			}
		}
	}
}

ep3_governor_yearly.8020 = {
	type = character_event
	title = ep3_governor_yearly.8020.t
	desc = {
		desc = ep3_governor_yearly.8020.desc
	}
	theme = administrative
	override_background = { reference = estate }
	left_portrait = {
		character = root
		animation = schadenfreude
	}
	right_portrait = {
		character = scope:estate_owner
		animation = disapproval
	}

	cooldown = { years = 10 }

	trigger = {
		has_ep3_dlc_trigger = yes
		is_available_adult = yes
		is_governor = yes
		domicile ?= { is_domicile_type = estate }
		top_liege = {
			any_vassal_or_below = { ep3_governor_8020_estate_holder_trigger = yes }
		}
	}

	immediate = {
		domicile = { save_scope_as = my_estate }
		top_liege = {
			random_vassal_or_below = {
				limit = { ep3_governor_8020_estate_holder_trigger = yes }
				save_scope_as = estate_owner
				domicile = { save_scope_as = other_estate }
			}
		}
	}

	option = { # Extort
		name = ep3_governor_yearly.8020.a
		flavor = ep3_governor_yearly.8020.reason
		reverse_add_opinion = {
			target = scope:estate_owner 
			modifier = extorted_me_opinion
			opinion = -20
		}
		save_scope_value_as = {
			name = extort_chance
			value = {
				value = 0
				add = {
					value = scope:estate_owner.ai_greed
					multiply = 0.25
				}
			}
		}
		save_scope_value_as = {
			name = gold_value
			value = {
				value = 0
				add = {
					value = scope:estate_owner.minor_gold_value
					multiply = root.stewardship
					divide = 2
				}
			}
		}
		save_scope_as = extorted
		duel = {
			skill = stewardship
			value = decent_skill_rating
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = 1
				}
				modifier = { add = scope:extort_chance }
				modifier = {
					scope:estate_owner.short_term_gold < scope:gold_value
					factor = 0.1
				}
				send_interface_toast = {
					type = event_toast_effect_good
					title = ep3_governor_yearly.8020.success
					right_icon = scope:estate_owner
					scope:estate_owner = {
						pay_short_term_gold = {
							target = root
							gold = scope:gold_value
						}
					}
				}
			}
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = 1
				}
				ep3_governor_8020_fail_effect = yes
			}
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = 1
				ai_boldness = 1
				ai_honor = -2
				ai_energy = 1
			}
		}
	}

	option = { # Favor
		name = ep3_governor_yearly.8020.b
		flavor = ep3_governor_yearly.8020.reason
		reverse_add_opinion = {
			target = scope:estate_owner 
			modifier = extorted_me_opinion
			opinion = -20
		}
		save_scope_as = extorted
		save_scope_value_as = {
			name = extort_chance
			value = {
				value = 50
				add = {
					value = scope:estate_owner.ai_honor
					multiply = 0.25
				}
				max = 75
				min = 25
			}
		}
		duel = {
			skill = intrigue
			value = decent_skill_rating
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = 1
				}
				modifier = { add = scope:extort_chance }
				send_interface_toast = {
					type = event_toast_effect_good
					title = ep3_governor_yearly.8020.success
					right_icon = scope:estate_owner
					add_hook = {
						target = scope:estate_owner
						type = obligation_hook
					}
				}
			}
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = 1
				}
				ep3_governor_8020_fail_effect = yes
			}
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = 1
				ai_boldness = 1
				ai_honor = -1
			}
		}
	}

	option = { # Good word
		name = ep3_governor_yearly.8020.c
		flavor = ep3_governor_yearly.8020.reason
		reverse_add_opinion = {
			target = scope:estate_owner 
			modifier = extorted_me_opinion
			opinion = -20
		}
		save_scope_as = extorted
		save_scope_value_as = {
			name = extort_chance
			value = {
				value = 50
				add = {
					value = scope:estate_owner.ai_energy
					multiply = 0.25
				}
				max = 75
				min = 25
			}
		}
		save_scope_value_as = {
			name = influence_value
			value = {
				value = minor_influence_gain
				multiply = diplomacy
				divide = 2
			}
		}
		duel = {
			skill = diplomacy
			value = decent_skill_rating
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = 1
				}
				modifier = { add = scope:extort_chance }
				send_interface_toast = {
					type = event_toast_effect_good
					title = ep3_governor_yearly.8020.success
					right_icon = scope:estate_owner
					change_influence = scope:influence_value
					scope:estate_owner = { change_influence = minor_influence_loss }
				}
			}
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = 1
				}
				ep3_governor_8020_fail_effect = yes
			}
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = -1
				ai_boldness = -1
				ai_honor = 1
			}
		}
	}

	option = { # Friendly
		name = ep3_governor_yearly.8020.d
		reverse_add_opinion = {
			target = scope:estate_owner 
			modifier = friendliness_opinion
			opinion = 15
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = -1
				ai_boldness = -1
				ai_honor = 1
			}
		}
	}
}

#####################################
# Accidental Grace					#
# by Joe Parkin						#
# 8030 								#
#####################################

scripted_trigger ep3_governor_yearly_8030_informer_trigger = {
	is_available_adult = yes
	OR = {
		is_courtier = yes
		AND = {
			highest_held_title_tier = tier_barony
			has_government = republic_government
		}
	}
	ep3_governor_involved_with_root_or_liege_trigger = no
}

ep3_governor_yearly.8030 = {
	type = character_event
	title = ep3_governor_yearly.8030.t
	desc = {
		desc = ep3_governor_yearly.8030.desc
		random_valid = {
			triggered_desc = {
				trigger = {
					scope:estate = {
						OR = {
							has_domicile_building_or_higher = barracks_01
							has_domicile_building_or_higher = watchtower_01
							has_domicile_building_or_higher = guardhouse_01
						}
					}
				}
				desc = ep3_governor_yearly.8030.martial
			}
			triggered_desc = {
				trigger = {
					scope:estate = {
						OR = {
							has_domicile_building_or_higher = garden_01
							has_domicile_building_or_higher = grazing_land_01
							has_domicile_building_or_higher = grain_field_01
							has_domicile_building_or_higher = vineyard_01
							has_domicile_building_or_higher = olive_01
						}
					}
				}
				desc = ep3_governor_yearly.8030.agriculture
			}
			triggered_desc = {
				trigger = {
					scope:estate = {
						OR = {
							has_domicile_building_or_higher = market_01
							has_domicile_building_or_higher = workshop_01
							has_domicile_building_or_higher = guardhouse_01
						}
					}
				}
				desc = ep3_governor_yearly.8030.commerce
			}
			desc = ep3_governor_yearly.8030.fallback
		}
	}
	theme = administrative
	override_background = { reference = estate }
	left_portrait = {
		character = root
		animation = admiration
	}

	cooldown = { years = 10 }

	trigger = {
		is_available_adult = yes
		is_governor = yes
		domicile ?= {
			is_domicile_type = estate
			num_domicile_buildings >= 3
			domicile_location.county = {
				OR = {
					holder = root
					holder = { is_vassal_of = root }
				}
			}
		}
		NOT = {
			any_sub_realm_county = {	
				OR = {
					has_county_modifier = ep3_governor_yearly_8030_stifled_modifier
					has_county_modifier = ep3_governor_yearly_8030_benign_modifier
				}
			}
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = {
				value = governor_efficiency
				divide = 100
			}
		}
	}

	immediate = {
		domicile = { save_scope_as = estate }
	}

	option = { # Tax it
		name = ep3_governor_yearly.8030.a
		add_treasury_or_gold = medium_treasury_or_gold_value
		stress_impact = {
			generous = minor_stress_impact_gain
			compassionate = minor_stress_impact_gain
			just = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = 1
				ai_boldness = 0.5
			}
		}
	}

	option = { # Encourage it
		name = ep3_governor_yearly.8030.b
		increase_governance_effect = { VALUE = 5 }
		add_character_modifier = {
			modifier = ep3_governor_yearly_8030_benign_char_modifier
			years = 10
		}
		scope:estate.domicile_location.county = {
			add_county_modifier = {
				modifier = ep3_governor_yearly_8030_benign_modifier
				years = 10
			}
		}
		stress_impact = {
			greedy = medium_stress_impact_gain
			callous = minor_stress_impact_gain
			arrogant = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = -1
				ai_compassion = 0.5
			}
		}
	}

	option = { # Leave it
		name = ep3_governor_yearly.8030.c
		stress_impact = {
			diligent = minor_stress_impact_gain
			greedy = minor_stress_impact_gain
			arbitrary = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = -0.5
				ai_energy = -1
			}
		}
	}
}

#####################################
# Dynastic Distractions				#
# by Joe Parkin						#
# 8040 								#
#####################################

scripted_trigger ep3_governor_yearly_8040_complainant_trigger = {
	is_available_adult = yes
	is_ai = yes
	highest_held_title_tier <= tier_county
	ep3_governor_involved_with_root_or_liege_trigger = no
	capital_county.duchy = root.domicile.domicile_location.duchy
}

ep3_governor_yearly.8040 = {
	type = character_event
	title = ep3_governor_yearly.8040.t
	desc = ep3_governor_yearly.8040.desc
	theme = administrative
	override_background = { reference = relaxing_room }
	left_portrait = {
		character = root
		animation = boredom
	}
	right_portrait = {
		character = scope:complainant
		animation = debating
	}

	cooldown = { years = 10 }

	trigger = {
		is_available_adult = yes
		is_governor = yes
		domicile ?= {
			is_domicile_type = estate
			num_domicile_buildings >= 3
		}
		any_vassal_or_below = { ep3_governor_yearly_8040_complainant_trigger = yes }
		NOT = {
			any_sub_realm_county = {	
				OR = {
					has_county_modifier = ep3_governor_yearly_8030_stifled_modifier
					has_county_modifier = ep3_governor_yearly_8030_benign_modifier
				}
			}
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = {
				value = governor_efficiency
				divide = 100
				multiply = -1
			}
		}
	}

	immediate = {
		domicile = { save_scope_as = estate }
		random_vassal_or_below = {
			limit = { ep3_governor_yearly_8040_complainant_trigger = yes }
			weight = {
				base = 1
				modifier = {
					add = 1
					government_has_flag = government_is_republic
				}
				modifier = {
					add = -1
					OR = {
						government_has_flag = government_is_feudal
						government_has_flag = government_is_clan
					}
				}
				modifier = {
					add = -2
					government_has_flag = government_is_theocracy
				}
				modifier = {
					add = 10
					liege ?= root
				}
			}
			save_scope_as = complainant
		}
	}

	option = { # Focus on province
		name = ep3_governor_yearly.8040.a
		increase_governance_effect = { VALUE = 5 }
		add_character_modifier = {
			modifier = ep3_governor_yearly_8040_province_development_modifier
			years = 10
		}
		reverse_add_opinion = {
			target = scope:complainant
			modifier = respect_opinion
			opinion = 15
		}
		stress_impact = {
			greedy = minor_stress_impact_gain
			lazy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_energy = 1
				ai_greed = -1
			}
		}
	}

	option = { # Focus on estate
		name = ep3_governor_yearly.8040.b
		add_character_modifier = {
			modifier = ep3_governor_yearly_8040_domicile_development_modifier
			years = 10
		}
		reverse_add_opinion = {
			target = scope:complainant
			modifier = annoyed_opinion
			opinion = -15
		}
		stress_impact = {
			generous = minor_stress_impact_gain
			diligent = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_energy = 1
				ai_greed = -1
			}
		}
	}

	option = { # Try to do both
		name = ep3_governor_yearly.8040.d
		duel = {
			skill = stewardship
			value = decent_skill_rating
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = 1
				}
				desc = ep3_governor_yearly.8040.d.success
				send_interface_toast = {
					type = event_toast_effect_good
					title = ep3_governor_yearly.8040.d.success
					add_character_modifier = {
						modifier = ep3_governor_yearly_8040_across_things_modifier
						years = 10
					}
					reverse_add_opinion = {
						target = scope:complainant
						modifier = impressed_opinion
						opinion = 15
					}
				}
			}
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = 1
				}
				desc = ep3_governor_yearly.8040.d.failure
				send_interface_toast = {
					type = event_toast_effect_bad
					title = ep3_governor_yearly.8040.d.failure
					add_character_modifier = {
						modifier = ep3_governor_yearly_8040_overwhelmed_modifier
						years = 10
					}
				}
			}
		}
		stress_impact = {
			base = minor_stress_impact_gain
			humble = minor_stress_impact_gain
			calm = minor_stress_impact_gain
			lazy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = -0.5
				ai_energy = -1
			}
		}
	}

	option = { # Defer
		name = ep3_governor_yearly.8040.c
		reverse_add_opinion = {
			target = scope:complainant
			modifier = angry_opinion
			opinion = -30
		}
		add_character_modifier = {
			modifier = ep3_governor_yearly_8040_shirker_modifier
			years = 5
		}
		stress_impact = {
			compassionate = minor_stress_impact_gain
			just = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = 1
				ai_compassion = -0.5
				ai_honor = -0.5
			}
		}
	}
}

#####################################
# Enemy at the Gates				#
# by Joe Parkin						#
# 8050	 							#
#####################################

scripted_trigger ep3_governor_8050_war_trigger = {
	primary_defender = root.top_liege
	casus_belli = {
		any_target_title = { is_de_jure_liege_or_above_target = root.primary_title }
	}
	NOT = {
		any_war_participant = { this = root }
	}
}

ep3_governor_yearly.8050 = {
	type = character_event
	title = ep3_governor_yearly.8050.t
	desc = {
		desc = ep3_governor_yearly.8050.desc
		first_valid = {
			triggered_desc = {
				trigger = { always = yes }
				desc = ep3_governor_yearly.8050.kingdom
			}
			desc = ep3_governor_yearly.8050.neighbour
		}
		desc = ep3_governor_yearly.8050.end
	}
	theme = administrative
	override_background = { reference = ep3_city_gate }
	left_portrait = {
		character = root
		animation = worry
	}
	lower_left_portrait = scope:war_liege
	lower_right_portrait = scope:war_attacker

	cooldown = { years = 10 }

	trigger = {
		has_ep3_dlc_trigger = yes
		government_has_flag = government_is_administrative
		is_available_adult = yes
		is_governor = yes
		top_liege = {
			is_at_war = yes
			any_character_war = { ep3_governor_8050_war_trigger = yes }
		}
		NOT = {
			is_at_war_with = top_liege
		}
	}

	immediate = {
		top_liege = {
			save_scope_as = war_liege
			random_character_war = {
				limit = { ep3_governor_8050_war_trigger = yes }
				save_scope_as = war
				primary_attacker = { save_scope_as = war_attacker }
				casus_belli = {
					ordered_target_title = {
						limit = { is_de_jure_liege_or_above_target = root.primary_title }
						order_by = tier
						save_scope_as = target_title
					}
				}
			}
		}
	}

	option = { # Send soldiers
		name = ep3_governor_yearly.8050.a
		scope:war = { add_defender = root }
		top_liege.primary_title = {
			change_appointment_investment = {
				target = root
				value = appointment_score_minor_value
			}
		}
		add_character_modifier = {
			modifier = ep3_governor_yearly_8050_imperial_recruiter_modifier
			years = 10
		}
		stress_impact = {
			craven = medium_stress_impact_gain
			content = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = -1
				ai_boldness = 1
				ai_energy = 1
			}
		}
	}

	option = { # Request reinforcements
		name = ep3_governor_yearly.8050.b
		add_character_modifier = {
			modifier = ep3_governor_yearly_8050_imperial_fortification_modifier
			years = 10
		}
		stress_impact = {
			brave = minor_stress_impact_gain
			arrogant = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_rationality = 1
				ai_boldness = -1
				ai_greed = -1
			}
		}
	}

	option = { # Request gold
		name = ep3_governor_yearly.8050.c
		add_treasury_or_gold = top_liege.medium_treasury_or_gold_value
		change_influence = medium_influence_loss
		add_character_modifier = {
			modifier = ep3_governor_yearly_8050_imperial_resources_modifier
			years = 10
		}
		stress_impact = {
			generous = minor_stress_impact_gain
			humble = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_honor = -1
				ai_greed = 1
			}
		}
	}

	option = { # Nothing
		name = ep3_governor_yearly.8050.d
		stress_impact = {
			greedy = minor_stress_impact_gain
			ambitious = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_boldness = -1
				ai_honor = 1
			}
		}
	}
}

#####################################
# Provincial Rackets				#
# by Joe Parkin						#
# 8060	 							#
#####################################

scripted_trigger ep3_governor_yearly_8060_complainant_trigger = {
	is_available_adult = yes
	OR = {
		is_courtier = yes
		AND = {
			highest_held_title_tier = tier_barony
			has_government = republic_government
		}
	}
	ep3_governor_involved_with_root_or_liege_trigger = no
}

scripted_effect ep3_governor_yearly_8060_success_effect = {
	add_short_term_gold = scope:gold
	custom_tooltip = {
		text = ep3_governor_yearly.8060.efficiency_tt
		add_character_flag = {
			flag = ep3_8060_efficiency_drop
			years = 10
		}
	}
}

ep3_governor_yearly.8060 = {
	type = character_event
	title = ep3_governor_yearly.8060.t
	desc = ep3_governor_yearly.8060.desc
	theme = administrative
	override_background = { reference = relaxing_room }
	left_portrait = {
		character = root
		animation = steward
	}

	cooldown = { years = 10 }

	trigger = {
		is_available_adult = yes
		is_governor = yes
		OR = {
			any_vassal_or_below = { ep3_governor_yearly_8060_complainant_trigger = yes }
			any_courtier = { ep3_governor_yearly_8060_complainant_trigger = yes }
		}
	}

	option = { # Take gold
		name = ep3_governor_yearly.8060.a
		save_scope_as = intrigue
		save_scope_value_as = {
			name = gold
			value = {
				value = minor_gold_value
				multiply = {
					value = intrigue
					divide = 3
				}
				add = { 1 2 }
				min = 50
			}
		}
		duel = {
			skill = intrigue
			value = decent_skill_rating
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = 1
				}
				desc = ep3_governor_yearly.8060.a.success
				show_as_tooltip = { ep3_governor_yearly_8060_success_effect = yes }
				trigger_event = {
					id = ep3_governor_yearly.8061
					days = 5
				}
			}
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = 1
				}
				desc = ep3_governor_yearly.8060.a.failure
				custom_tooltip = ep3_governor_yearly.8060.a.failure_tt
				trigger_event = {
					id = ep3_governor_yearly.8062
					days = 5
				}
			}
		}
		stress_impact = {
			honest = medium_stress_impact_gain
			diligent = medium_stress_impact_gain
			just = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = 1
				ai_honor = -1
			}
		}
	}

	option = { # Cook books
		name = ep3_governor_yearly.8060.b
		save_scope_as = stewardship
		save_scope_value_as = {
			name = gold
			value = {
				value = tiny_gold_value
				multiply = {
					value = stewardship
					divide = 3
				}
				add = { 1 2 }
				min = 25
			}
		}
		duel = {
			skill = stewardship
			value = decent_skill_rating
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = 1
				}
				desc = ep3_governor_yearly.8060.a.success
				show_as_tooltip = { ep3_governor_yearly_8060_success_effect = yes }
				trigger_event = {
					id = ep3_governor_yearly.8061
					days = 5
				}
			}
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = 1
				}
				desc = ep3_governor_yearly.8060.a.failure
				custom_tooltip = ep3_governor_yearly.8060.a.failure_tt
				trigger_event = {
					id = ep3_governor_yearly.8062
					days = 5
				}
			}
		}
		stress_impact = {
			honest = medium_stress_impact_gain
			diligent = medium_stress_impact_gain
			just = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = 1
				ai_rationality = 0.5
			}
		}
	}

	option = { # Bolster treasury
		name = ep3_governor_yearly.8060.c
		remove_short_term_gold = medium_gold_value
		increase_governance_effect = { VALUE = 5 }
		add_character_modifier = {
			modifier = ep3_bolstered_governor_treasury_modifier 
			years = 10
		}
		stress_impact = {
			arbitrary = minor_stress_impact_gain
			greedy = medium_stress_impact_gain
			arrogant = medium_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_compassion = 1
				ai_honor = 1
			}
		}
	}

	option = { # Do nothing
		name = ep3_governor_yearly.8060.d
		stress_impact = {
			fickle = minor_stress_impact_gain
			arbitrary = medium_stress_impact_gain
			ambitious = minor_stress_impact_gain
			greedy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = -1
				ai_boldness = -1
			}
		}
	}
}

ep3_governor_yearly.8061 = {
	hidden = yes
	type = character_event

	immediate = {
		send_interface_toast = {
			type = event_toast_effect_good
			title = ep3_governor_yearly.8060.embezzle_tt
			ep3_governor_yearly_8060_success_effect = yes
		}
	}
}

ep3_governor_yearly.8062 = {
	type = character_event
	title = ep3_governor_yearly.8060.t
	desc = ep3_governor_yearly.8062.desc
	theme = administrative
	override_background = { reference = relaxing_room }
	left_portrait = {
		character = root
		animation = thinking
	}
	right_portrait = {
		character = scope:complainant
		animation = chancellor
	}

	cooldown = { years = 10 }

	trigger = {
		is_available_adult = yes
		is_governor = yes
		has_domicile = yes
	}

	immediate = {
		every_courtier = {
			limit = { ep3_governor_yearly_8060_complainant_trigger = yes }
			add_to_list = complainants
		}
		domicile = { save_scope_as = estate }
		every_vassal_or_below = {
			limit = {
				ep3_governor_yearly_8060_complainant_trigger = yes
				primary_title.title_capital_county = scope:estate.domicile_location.county
			}
			alternative_limit = {
				ep3_governor_yearly_8060_complainant_trigger = yes
				primary_title.title_capital_county.duchy = scope:estate.domicile_location.duchy
			}
			alternative_limit = { ep3_governor_yearly_8060_complainant_trigger = yes }
			add_to_list = complainants
		}
		random_in_list = {
			list = complainants
			weight = {
				base = 1
				modifier = {
					add = {
						value = ai_energy
						multiply = 0.25
					}
				}
				modifier = {
					add = {
						value = ai_honor
						multiply = 0.25
					}
				}
				modifier = { add = stewardship }
			}
			save_scope_as = complainant
		}
		ep3_governor_yearly_8060_success_effect = yes
	}

	option = { # Convince
		name = ep3_governor_yearly.8062.a
		duel = {
			skill = diplomacy
			value = decent_skill_rating
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = 1
				}
				desc = ep3_governor_yearly.8062.a.success
				send_interface_toast = {
					type = event_toast_effect_good
					title = ep3_governor_yearly.8062.a.success
					left_icon = scope:complainant
				}
			}
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = 1
				}
				desc = ep3_governor_yearly.8062.a.failure
				send_interface_toast = {
					type = event_toast_effect_bad
					title = ep3_governor_yearly.8062.a.failure
					left_icon = scope:complainant
					change_influence = medium_influence_loss
					reverse_add_opinion = {
						target = scope:complainant
						modifier = insulted_opinion
						opinion = -15
					}
				}
			}
		}
		stress_impact = {
			honest = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_sociability = 1
			}
		}
	}

	option = { # Threaten
		name = ep3_governor_yearly.8062.b
		random_list = {
			100 = {
				modifier = { add = dread }
				opinion_modifier = {
					who = scope:complainant
					opinion_target = root
					multiplier = 0.5
				}
				modifier = {
					add = {
						value = scope:complainant.ai_energy
						min = 0
					}
				}
				modifier = {
					add = {
						value = scope:complainant.ai_boldness
						min = 0
					}
				}
				min = 20
				desc = ep3_governor_yearly.8062.b.success
				send_interface_toast = {
					type = event_toast_effect_good
					title = ep3_governor_yearly.8062.b.success
					left_icon = scope:complainant
					scope:complainant = {
						add_hook = {
							target = root
							type = favor_hook
						}
					}
				}
			}
			100 = {
				modifier = {
					add = {
						value = scope:complainant.ai_energy
						max = 0
					}
				}
				modifier = {
					add = {
						value = scope:complainant.ai_boldness
						max = 0
					}
				}
				min = 20
				desc = ep3_governor_yearly.8062.b.failure
				send_interface_toast = {
					type = event_toast_effect_bad
					title = ep3_governor_yearly.8062.b.failure
					left_icon = scope:complainant
					change_influence = medium_influence_loss
					reverse_add_opinion = {
						target = scope:complainant
						modifier = threatened_opinion
						opinion = -15
					}
				}
			}
		}
		stress_impact = {
			compassionate = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_honor = -1
			}
		}
	}

	option = { # Bribe
		name = ep3_governor_yearly.8062.c
		random_list = {
			100 = {
				modifier = {
					add = {
						value = scope:complainant.ai_greed
						min = 0
					}
				}
				modifier = {
					add = {
						value = scope:complainant.ai_honor
						max = 0
					}
				}
				min = 1
				desc = ep3_governor_yearly.8062.c.success
				send_interface_toast = {
					type = event_toast_effect_good
					title = ep3_governor_yearly.8062.c.success
					left_icon = scope:complainant
					pay_short_term_gold = {
						target = scope:complainant
						gold = minor_gold_value
					}
				}
			}
			100 = {
				modifier = {
					add = {
						value = scope:complainant.ai_greed
						max = 0
					}
				}
				modifier = {
					add = {
						value = scope:complainant.ai_honor
						min = 0
					}
				}
				min = 1
				desc = ep3_governor_yearly.8062.c.failure
				send_interface_toast = {
					type = event_toast_effect_bad
					title = ep3_governor_yearly.8062.c.failure
					left_icon = scope:complainant
					change_influence = medium_influence_loss
					reverse_add_opinion = {
						target = scope:complainant
						modifier = disgusted_opinion
						opinion = -15
					}
				}
			}
		}
		stress_impact = {
			greedy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_energy = -1
			}
		}
	}

	option = { # Give it back
		name = ep3_governor_yearly.8062.d
		remove_short_term_gold = scope:gold
		reverse_add_opinion = {
			target = scope:complainant
			modifier = suspicious_opinion
			opinion = -10
		}
		stress_impact = {
			greedy = medium_stress_impact_gain
			stubborn = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = -0.5
				ai_boldness = -0.5
				ai_honor = 0.5
			}
		}
	}
}

#####################################
# A Governor's Work					#
# by Joe Parkin						#
# 8070	 							#
#####################################

ep3_governor_yearly.8070 = {
	type = character_event
	title = ep3_governor_yearly.8070.t
	desc = ep3_governor_yearly.8070.desc
	theme = administrative
	override_background = { reference = relaxing_room }
	left_portrait = {
		character = root
		animation = boredom
	}

	cooldown = { years = 10 }

	trigger = {
		is_available_adult = yes
		is_governor = yes
		NOT = {
			has_trait = ambitious
			has_trait = diligent 
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = {
				value = governor_efficiency
				divide = 100
				multiply = -1
			}
		}
	}

	option = { # Work hard
		name = ep3_governor_yearly.8070.a
		increase_governance_effect = { VALUE = 10 }
		add_stewardship_skill = 1
		stress_impact = {
			base = medium_stress_impact_gain
			lazy = medium_stress_impact_gain
			impatient = medium_stress_impact_gain
			arrogant = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_energy = 1
				ai_honor = 0.5
			}
		}
	}

	option = { # Find someone to help
		name = ep3_governor_yearly.8070.b
		remove_short_term_gold = medium_gold_value
		stress_impact = {
			lazy = major_stress_impact_loss
			stubborn = minor_stress_impact_gain
			greedy = minor_stress_impact_gain
			honest = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_energy = -1
				ai_honor = -0.5
			}
		}
	}

	option = { # Ignore work
		name = ep3_governor_yearly.8070.c
		add_character_modifier = {
			modifier = ep3_governor_yearly_8070_ignore_modifier
			years = 5
		}
		stress_impact = {
			base = medium_stress_impact_loss
			lazy = massive_stress_impact_loss
			diligent = minor_stress_impact_gain
			humble = minor_stress_impact_gain
			just = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_energy = -1
				ai_honor = -0.5
			}
		}
	}
}

#####################################
# Malignant Magistrate				#
# by Joe Parkin						#
# 8080	 							#
#####################################

ep3_governor_yearly.8080 = {
	type = character_event
	title = ep3_governor_yearly.8080.t
	desc = ep3_governor_yearly.8080.desc
	theme = administrative
	override_background = { reference = relaxing_room }
	left_portrait = {
		character = root
		animation = war_over_win
	}
	right_portrait = {
		character = scope:magistrate
		animation = beg
	}

	cooldown = { years = 10 }

	trigger = {
		is_available_adult = yes
		is_governor = yes
		NOR = {
			has_character_modifier = ep3_governor_yearly_8080_tense_bureaucracy_modifier
			has_character_modifier = ep3_governor_yearly_8080_jumpy_bureaucracy_modifier
			has_character_modifier = ep3_governor_yearly_8080_corrupt_bureaucracy_modifier
		}
	}

	immediate = {
		create_character = {
			template = ep3_magistrate_character
			location = root.capital_province
			culture = root.capital_county.culture
			faith = root.capital_county.faith
			dynasty = none
			save_scope_as = magistrate
		}
	}

	option = { # Punish
		name = ep3_governor_yearly.8080.a
		increase_governance_effect = { VALUE = 5 }
		add_character_modifier = {
			modifier = ep3_governor_yearly_8080_tense_bureaucracy_modifier
			years = 10
		}
		stress_impact = {
			arbitrary = minor_stress_impact_gain
			greedy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_compassion = 1
				ai_honor = 1
			}
		}
	}

	option = { # Execute
		name = ep3_governor_yearly.8080.b
		add_dread = minor_dread_gain
		add_character_modifier = {
			modifier = ep3_governor_yearly_8080_jumpy_bureaucracy_modifier
			years = 10
		}
		scope:magistrate = {
			death = {
				death_reason = death_execution
				killer = root
			}
		}
		stress_impact = {
			compassionate = minor_stress_impact_gain
			forgiving = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_compassion = -1
				ai_honor = 1
			}
		}
	}

	option = { # Embezzle
		name = ep3_governor_yearly.8080.c
		add_short_term_gold = medium_gold_value
		add_character_modifier = {
			modifier = ep3_governor_yearly_8080_corrupt_bureaucracy_modifier
			years = 10
		}
		scope:magistrate = { silent_disappearance_effect = yes }
		stress_impact = {
			honest = minor_stress_impact_gain
			generous = minor_stress_impact_gain
			diligent = minor_stress_impact_gain
			humble = minor_stress_impact_gain
			just = medium_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = 1
				ai_honor = -1
			}
		}
	}

	option = { # Recruit
		name = ep3_governor_yearly.8080.d
		add_courtier = scope:magistrate
		add_hook = {
			target = scope:magistrate
			type = loyalty_hook
		}
		add_character_modifier = {
			modifier = ep3_governor_yearly_8080_corrupt_bureaucracy_modifier
			years = 10
		}
		reverse_add_opinion = {
			target = scope:magistrate
			modifier = grateful_opinion
			opinion = 15
		}
		stress_impact = {
			callous = minor_stress_impact_gain
			vengeful = minor_stress_impact_gain
			sadistic = minor_stress_impact_gain
			just = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_boldness = 1
				ai_honor = -1
			}
		}
	}
	after = {
		scope:magistrate = {
			silent_disappearance_ai_effect = yes
		}
	}
}

#####################################
# Politics of Spite					#
# by Joe Parkin						#
# 8090	 							#
#####################################

scripted_trigger ep3_governor_yearly_8090_title_trigger = {
	OR = {
		tier = tier_duchy
		tier = tier_kingdom
	}
	save_temporary_scope_as = title_temp
	any_past_holder = {
		ep3_governor_yearly_8090_past_holder_trigger = { TITLE = scope:title_temp }
	}
}

scripted_trigger ep3_governor_yearly_8090_past_holder_trigger = {
	house ?= {
		NOR = {
			$TITLE$.holder.house ?= this
			$TITLE$.holder.top_liege.house ?= this
		}
		any_house_member = { ep3_governor_yearly_8090_house_member_trigger = yes }
	}
}

scripted_trigger ep3_governor_yearly_8090_house_member_trigger = {
	is_ai = yes
	is_adult = yes
	is_healthy = yes
	is_landed = no
	any_held_title = { is_noble_family_title = yes }
	ep3_governor_involved_with_root_or_liege_trigger = no
}

ep3_governor_yearly.8090 = {
	type = character_event
	title = ep3_governor_yearly.8090.t
	desc = ep3_governor_yearly.8090.desc
	theme = administrative
	override_background = { reference = relaxing_room }
	left_portrait = {
		character = root
		animation = worry
	}
	lower_right_portrait = scope:old_holder

	cooldown = { years = 15 }

	trigger = {
		is_available_adult = yes
		is_governor = yes
		any_held_title = { ep3_governor_yearly_8090_title_trigger = yes }
	}

	immediate = {
		ordered_held_title = {
			limit = { ep3_governor_yearly_8090_title_trigger = yes }
			save_scope_as = disputed_title
			random_past_holder = {
				limit = {
					ep3_governor_yearly_8090_past_holder_trigger = { TITLE = scope:disputed_title }
				}
				house = {
					random_house_member = {
						limit = { ep3_governor_yearly_8090_house_member_trigger = yes }
						save_scope_as = old_holder
					}
				}
			}
		}
	}

	option = { # Antagonize
		name = ep3_governor_yearly.8090.a
		set_relation_rival = {
			target = scope:old_holder
			reason = rival_ep3_province_claim
		}
		duel = {
			skills = { stewardship intrigue }
			value = decent_skill_rating
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = 1
				}
				desc = ep3_governor_yearly.8090.a.success
				send_interface_toast = {
					type = event_toast_effect_good
					title = ep3_governor_yearly.8090.a.success
					right_icon = scope:old_holder
					scope:old_holder = { change_influence = minor_influence_loss }
					primary_title = {
						change_appointment_investment = {
							target = scope:old_holder
							value = appointment_score_medium_loss_value
						}
					}
				}
			}
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = 1
				}
				desc = ep3_governor_yearly.8090.a.failure
				send_interface_toast = {
					type = event_toast_effect_bad
					title = ep3_governor_yearly.8090.a.failure
					right_icon = scope:old_holder
					change_influence = minor_influence_loss
					primary_title = {
						change_appointment_investment = {
							target = scope:old_holder
							value = appointment_score_medium_value
						}
					}
				}
			}
		}
		stress_impact = {
			honest = minor_stress_impact_gain
			just = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_honor = -1
			}
		}
	}

	option = { # Placate
		name = ep3_governor_yearly.8090.b
		duel = {
			skill = diplomacy
			value = decent_skill_rating
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = 1
				}
				min = 5
				opinion_modifier = {
					who = scope:old_holder
					opinion_target = root
					multiplier = 0.5
				}
				change_influence = minor_influence_gain
				reverse_add_opinion = {
					target = scope:old_holder
					modifier = friendliness_opinion
					opinion = 15
				}
			}
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = 1
				}
				min = 5
				primary_title = {
					change_appointment_investment = {
						target = scope:old_holder
						value = appointment_score_minor_value
					}
				}
			}
		}
		stress_impact = {
			arrogant = minor_stress_impact_gain
			shy = minor_stress_impact_gain
			vengeful = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_sociability = 0.5
				ai_compassion = 0.5
			}
		}
	}

	option = { # Compensate
		name = ep3_governor_yearly.8090.c
		pay_short_term_gold = {
			target = scope:old_holder
			gold = minor_gold_value
		}
		random = {
			chance = 25
			modifier = {
				add = {
					value = scope:old_holder.ai_greed
					multiply = -0.5
				}
			}
			progress_towards_rival_effect = {
				REASON = rival_ep3_province_claim
				CHARACTER = scope:old_holder
				OPINION = default_rival_opinion
			}
		}
		stress_impact = {
			honest = minor_stress_impact_gain
			generous = minor_stress_impact_gain
			diligent = minor_stress_impact_gain
			humble = minor_stress_impact_gain
			just = medium_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = -0.5
				ai_honor = 0.5
			}
		}
	}

	option = { # Do nothing
		name = ep3_governor_yearly.8090.d
		primary_title = {
			change_appointment_investment = {
				target = scope:old_holder
				value = appointment_score_minor_value
			}
		}
		random = {
			chance = 25
			modifier = {
				add = {
					value = scope:old_holder.ai_vengefulness
					multiply = 0.5
				}
			}
			progress_towards_rival_effect = {
				REASON = rival_ep3_province_claim
				CHARACTER = scope:old_holder
				OPINION = default_rival_opinion
			}
		}
		stress_impact = {
			callous = minor_stress_impact_gain
			vengeful = minor_stress_impact_gain
			sadistic = minor_stress_impact_gain
			just = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_energy = -1
			}
		}
	}
}

#####################################
# Nefarious Neighbor				#
# by Joe Parkin						#
# 8100	 							#
#####################################

scripted_trigger ep3_governor_yearly_8100_governor_trigger = {
	is_ai = yes
	ep3_governor_involved_with_root_or_liege_trigger = no
	is_available_adult = yes
	is_governor = yes
	highest_held_title_tier = root.highest_held_title_tier
	opinion = {
		target = root
		value < 25
	}
	any_close_family_member = {
		can_appoint_for_title = root.primary_title
		is_adult = yes
	}
}

ep3_governor_yearly.8100 = {
	type = character_event
	title = ep3_governor_yearly.8100.t
	desc = ep3_governor_yearly.8100.desc
	theme = administrative
	override_background = { reference = relaxing_room }
	left_portrait = {
		character = root
		animation = disbelief
	}
	right_portrait = {
		character = scope:target_family_member
		animation = thinking
	}
	lower_center_portrait = scope:governor
	lower_right_portrait = scope:neighboring_promoted_char

	cooldown = { years = 15 }

	trigger = {
		has_ep3_dlc_trigger = yes
		is_available_adult = yes
		is_governor = yes
		any_neighboring_realm_same_rank_owner = {
			ep3_governor_yearly_8100_governor_trigger = yes
			save_temporary_scope_as = temp_governor
			any_close_family_member = {
				can_appoint_for_title = root.primary_title
				is_adult = yes
			}
		}
		any_close_family_member = {
			can_appoint_for_title = scope:temp_governor.primary_title
			is_adult = yes
			house ?= root.house
		}
	}

	immediate = {
		random_neighboring_realm_same_rank_owner = {
			limit = { ep3_governor_yearly_8100_governor_trigger = yes }
			weight = {
				base = 1
				modifier = {
					has_relation_rival = root
					add = 1 
				}
				modifier = {
					add = {
						value = "opinion(root)"
						multiply = -0.25
						max = 0
					}
				}
			}
			save_scope_as = governor
			random_close_family_member = {
				limit = {
					can_appoint_for_title = root.primary_title
					is_adult = yes
				}
				save_scope_as = neighboring_promoted_char
			}
		}
		primary_title = {
			change_appointment_investment = {
				target = scope:neighboring_promoted_char
				value = appointment_score_medium_value
			}
		}
		random_close_family_member = {
			limit = {
				can_appoint_for_title = scope:governor.primary_title
				is_adult = yes
				house ?= root.house
			}
			save_scope_as = target_family_member
		}
	}

	option = { # Do same
		name = ep3_governor_yearly.8100.a
		scope:governor.primary_title = {
			change_appointment_investment = {
				target = scope:target_family_member
				value = appointment_score_minor_value
			}
		}
		progress_towards_rival_effect = {
			REASON = rival_ep3_governor_friction
			CHARACTER = scope:governor
			OPINION = default_rival_opinion
		}
		stress_impact = {
			calm = minor_stress_impact_gain
			forgiving = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_compassion = 1
				ai_honor = 1
			}
		}
	}

	option = { # Denounce
		name = ep3_governor_yearly.8100.b
		change_influence = minor_influence_loss
		primary_title = {
			change_appointment_investment = {
				target = scope:neighboring_promoted_char
				value = appointment_score_minor_loss_value
			}
		}
		progress_towards_rival_effect = {
			REASON = rival_ep3_governor_friction
			CHARACTER = scope:governor
			OPINION = default_rival_opinion
		}
		stress_impact = {
			arrogant = minor_stress_impact_gain
			ambitious = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_compassion = -1
				ai_honor = 1
			}
		}
	}

	option = { # Governor
		name = ep3_governor_yearly.8100.c
		trigger = {
			has_trait = governor
			NOT = {
				scope:governor = { has_trait = governor }
			}
		}
		primary_title = {
			change_appointment_investment = {
				target = scope:neighboring_promoted_char
				value = appointment_score_major_loss_value
			}
		}
		progress_towards_rival_effect = {
			REASON = rival_ep3_governor_friction
			CHARACTER = scope:governor
			OPINION = default_rival_opinion
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_compassion = -1
				ai_honor = 1
			}
		}
	}

	option = { # Ignore
		name = ep3_governor_yearly.8100.d
		stress_impact = {
			vengeful = minor_stress_impact_gain
			wrathful = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = 1
				ai_honor = -1
			}
		}
	}
}

#####################################
# Pugnacious Peers					#
# by Joe Parkin						#
# 8110	 							#
#####################################

scripted_trigger ep3_governor_yearly_8110_governor_trigger = {
	is_ai = yes
	ep3_governor_involved_with_root_or_liege_trigger = no
	is_available_adult = yes
	is_governor = yes
	highest_held_title_tier = root.highest_held_title_tier
}

scripted_trigger ep3_governor_yearly_8110_second_trigger = {
	opinion = {
		target = $FIRST$
		value < 50
	}
	reverse_opinion = {
		target = $FIRST$
		value < 50
	}
	ep3_governor_involved_with_root_or_liege_trigger = no
	NOR = {
		this = $FIRST$
		is_close_family_of = $FIRST$
		is_consort_of = $FIRST$
		has_relation_friend = $FIRST$
		has_relation_lover = $FIRST$
		house ?= $FIRST$.house
	}
}

ep3_governor_yearly.8110 = {
	type = character_event
	title = ep3_governor_yearly.8110.t
	desc = ep3_governor_yearly.8110.desc
	theme = administrative
	override_background = { reference = relaxing_room }
	left_portrait = {
		character = root
		animation = scheme
	}
	lower_center_portrait = scope:governor_1
	lower_right_portrait = scope:governor_2

	cooldown = { years = 15 }

	trigger = {
		has_ep3_dlc_trigger = yes
		is_available_adult = yes
		is_governor = yes
		any_neighboring_realm_same_rank_owner = {
			ep3_governor_yearly_8100_governor_trigger = yes
			save_temporary_scope_as = governor_1_temp
		}
		any_neighboring_realm_same_rank_owner = { 
			ep3_governor_yearly_8100_governor_trigger = yes
			ep3_governor_yearly_8110_second_trigger = { FIRST = scope:governor_1_temp }
		}
	}

	immediate = {
		random_neighboring_realm_same_rank_owner = {
			limit = { ep3_governor_yearly_8100_governor_trigger = yes }
			weight = {
				base = 1
				modifier = {
					primary_title.kingdom = root.primary_title.kingdom
					add = 1
				}
			}
			save_scope_as = governor_1
		}
		random_neighboring_realm_same_rank_owner = {
			limit = {
				ep3_governor_yearly_8100_governor_trigger = yes
				ep3_governor_yearly_8110_second_trigger = { FIRST = scope:governor_1 }
			}
			weight = {
				base = 1
				modifier = {
					primary_title.kingdom = root.primary_title.kingdom
					add = 1
				}
			}
			save_scope_as = governor_2
		}
		scope:governor_1 = {
			progress_towards_rival_effect = {
				REASON = rival_ep3_governor_friction
				CHARACTER = scope:governor_2
				OPINION = default_rival_opinion
			}
		}
	}

	option = { # Try to escalate
		name = ep3_governor_yearly.8110.a
		change_influence = minor_influence_loss
		duel = {
			skill = intrigue
			value = decent_skill_rating
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = 1
				}
				desc = ep3_governor_yearly.8110.a.success
				send_interface_toast = {
					type = event_toast_effect_good
					title = ep3_governor_yearly.8110.a.success
					left_icon = scope:governor_1
					right_icon = scope:governor_2
					scope:governor_1 = {
						progress_towards_rival_effect = {
							REASON = rival_ep3_governor_friction
							CHARACTER = scope:governor_2
							OPINION = default_rival_opinion
						}
						add_merit_if_relevant_effect = {
							MERIT = minor_merit_loss
						}
					}
					scope:governor_2 = {
						add_merit_if_relevant_effect = {
							MERIT = minor_merit_loss
						}
					}
				}
			}
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = 1
				}
				desc = ep3_governor_yearly.8110.a.failure
				send_interface_toast = {
					type = event_toast_effect_bad
					title = ep3_governor_yearly.8110.a.failure
					left_icon = scope:governor_1
					right_icon = scope:governor_2
					add_merit_if_relevant_effect = {
						MERIT = minor_merit_loss
					}
					custom_tooltip = {
						text = ep3_governor_yearly.8110.a.failure_tt
						reverse_add_opinion = {
							target = scope:governor_1
							modifier = angry_opinion
							opinion = -25
						}
						reverse_add_opinion = {
							target = scope:governor_2
							modifier = angry_opinion
							opinion = -25
						}
					}
				}
			}
		}
		stress_impact = {
			honest = minor_stress_impact_gain
			content = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_compassion = -1
				ai_honor = 1
			}
		}
	}

	option = { # Side with 1
		name = ep3_governor_yearly.8110.b
		reverse_add_opinion = {
			target = scope:governor_1
			modifier = friendliness_opinion
			opinion = 15
		}
		reverse_add_opinion = {
			target = scope:governor_2
			modifier = unfriendly_opinion
			opinion = -15
		}
		stress_impact = {
			vengeful = minor_stress_impact_gain
			wrathful = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = 1
				ai_honor = -1
			}
		}
	}

	option = { # Side with 2
		name = ep3_governor_yearly.8110.c
		reverse_add_opinion = {
			target = scope:governor_2
			modifier = friendliness_opinion
			opinion = 15
		}
		reverse_add_opinion = {
			target = scope:governor_1
			modifier = unfriendly_opinion
			opinion = -15
		}
		stress_impact = {
			vengeful = minor_stress_impact_gain
			wrathful = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = 1
				ai_honor = -1
			}
		}
	}

	option = { # Call for unity
		name = ep3_governor_yearly.8110.d
		change_influence = minor_influence_gain
		add_merit_if_relevant_effect = {
			MERIT = miniscule_merit_value
		}
		custom_tooltip = {
			text = ep3_governor_yearly.8110.d.tt
			reverse_add_opinion = {
				target = scope:governor_1
				modifier = annoyed_opinion
				opinion = -15
			}
			reverse_add_opinion = {
				target = scope:governor_2
				modifier = annoyed_opinion
				opinion = -15
			}
		}
		stress_impact = {
			calm = minor_stress_impact_gain
			forgiving = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_compassion = 1
				ai_honor = 1
			}
		}
	}
}

#####################################
# An Act of God						#
# by Joe Parkin						#
# 8120	 							#
#####################################

scripted_trigger ep3_governor_yearly_8120_county_trigger = {
	county_control >= 75
	OR = {
		ep3_governor_yearly_8120_earthquake_trigger = yes
		ep3_governor_yearly_8120_storm_trigger = yes
		ep3_governor_yearly_8120_flood_trigger = yes
	}
	NOT = {
		any_county_province_epidemic = {}
	}
}

scripted_trigger ep3_governor_yearly_8120_earthquake_trigger = {
	any_county_province = {
		geographical_region = world_asia_minor
		OR = {
			terrain = mountains
			terrain = desert_mountains
		}
	}
}

scripted_trigger ep3_governor_yearly_8120_storm_trigger = {
	is_coastal_county = yes
}

scripted_trigger ep3_governor_yearly_8120_flood_trigger = {
	OR = {
		is_riverside_county = yes
		any_county_province = {
			terrain = wetlands
			OR = {
				is_coastal = yes
				is_riverside_province = yes
			}
		}
	}
}

ep3_governor_yearly.8120 = {
	type = character_event
	title = ep3_governor_yearly.8120.t
	desc = {
		desc = ep3_governor_yearly.8120.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:disaster_county = { is_coastal_county = yes }
				}
				desc = ep3_governor_yearly.8120.storm
			}
			desc = ep3_governor_yearly.8120.storm
		}
		desc = ep3_governor_yearly.8120.ending
	}
	theme = administrative
	override_background = { reference = relaxing_room }
	left_portrait = {
		character = root
		animation = worry
	}

	cooldown = { years = 15 }

	trigger = {
		is_available_adult = yes
		is_governor = yes
		any_sub_realm_county = { ep3_governor_yearly_8120_county_trigger = yes }
		NOR = {
			has_character_modifier = ep3_governor_yearly_8120_relief_leader_modifier
			has_character_modifier = ep3_governor_yearly_8120_relief_botched_modifier
			any_sub_realm_county = { has_county_modifier = ep3_governor_yearly_8120_relief_aid_modifier }
		}
	}

	immediate = {
		random_sub_realm_county = {
			limit = { ep3_governor_yearly_8120_county_trigger = yes }
			weight = {
				base = 1
				modifier = {
					holder = root
					add = 1
				}
			}
			save_scope_as = disaster_county
			change_county_control = -30
			change_development_progress_with_overflow = -50
		}
	}

	option = { # Oversee recovery
		name = ep3_governor_yearly.8120.a
		duel = {
			skill = stewardship
			value = decent_skill_rating
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = 1
				}
				min = 3
				desc = ep3_governor_yearly.8120.a.success
				send_interface_toast = {
					type = event_toast_effect_good
					title = ep3_governor_yearly.8120.a.success
					right_icon = scope:disaster_county
					increase_governance_effect = { VALUE = 5 }
					scope:disaster_county = {
						change_county_control = 20
						change_development_progress_with_overflow = 40
					}
					add_character_modifier = {
						modifier = ep3_governor_yearly_8120_relief_leader_modifier
						years = 10
					}
				}
			}
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = 1
				}
				min = 3
				desc = ep3_governor_yearly.8120.a.failure
				send_interface_toast = {
					type = event_toast_effect_bad
					title = ep3_governor_yearly.8120.a.failure
					right_icon = scope:disaster_county
					add_character_modifier = {
						modifier = ep3_governor_yearly_8120_relief_botched_modifier
						years = 10
					}
				}
			}
		}
		stress_impact = {
			base = minor_stress_impact_gain
			lazy = minor_stress_impact_gain
			callous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_compassion = -1
				ai_honor = 1
			}
		}
	}

	option = { # Offer aid
		name = ep3_governor_yearly.8120.b
		remove_treasury_or_gold = minor_treasury_or_gold_value
		scope:disaster_county = {
			add_county_modifier = {
				modifier = ep3_governor_yearly_8120_relief_aid_modifier
				years = 5
			}
		}
		stress_impact = {
			greedy = minor_stress_impact_gain
			callous = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = 1
				ai_honor = -1
			}
			modifier = {
				treasury_or_gold < medium_treasury_or_gold_value
				factor = 0
			}
		}
	}

	option = { # Ignore
		name = ep3_governor_yearly.8120.c
		add_piety = minor_piety_gain
		add_character_modifier = {
			modifier = ep3_governor_yearly_8120_relief_rejected_modifier
			years = 10
		}
		stress_impact = {
			cynical = minor_stress_impact_gain
			compassionate = minor_stress_impact_gain
			generous = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = 1
				ai_honor = -1
			}
		}
	}
}

#####################################
# Avarice and Opportunity			#
# by Joe Parkin						#
# 8130	 							#
#####################################

ep3_governor_yearly.8130 = {
	type = character_event
	title = ep3_governor_yearly.8130.t
	desc = {
		desc = ep3_governor_yearly.8130.desc
			
	}
	theme = administrative
	override_background = { reference = relaxing_room }
	left_portrait = {
		character = root
		animation = steward
	}
	lower_center_portrait = scope:governor_1
	lower_right_portrait = scope:governor_2

	cooldown = { years = 15 }

	trigger = {
		is_available_adult = yes
		is_governor = yes
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = 1
			gold < 0
		}
		modifier = {
			add = 1
			gold < minor_gold_value
		}
	}

	option = { # Harsh tax
		name = ep3_governor_yearly.8130.a
		add_character_modifier = {
			modifier = ep3_governor_yearly_8130_raised_taxes_modifier
			years = 5
		}
		stress_impact = {
			generous = medium_stress_impact_gain
			honest = medium_stress_impact_gain
			just = medium_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = 1
				ai_honor = -1
			}
		}
	}

	option = { # Minor tax
		name = ep3_governor_yearly.8130.b
		add_treasury_or_gold = minor_treasury_or_gold_value
		add_character_modifier = {
			modifier = ep3_governor_yearly_8130_special_levy_modifier
			years = 5
		}
		stress_impact = {
			generous = minor_stress_impact_gain
			honest = minor_stress_impact_gain
			just = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = 0.5
				ai_rationality = 0.5
				ai_honor = -0.5
			}
		}
	}

	option = { # Invest into province
		name = ep3_governor_yearly.8130.c
		change_influence = medium_influence_loss
		increase_governance_effect = { VALUE = 5 }
		add_character_modifier = {
			modifier = ep3_governor_yearly_8130_raised_almonage_modifier
			years = 5
		}
		stress_impact = {
			callous = medium_stress_impact_gain
			arrogant = medium_stress_impact_gain
			arbitrary = medium_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = 0.5
				ai_rationality = 0.5
				ai_honor = -0.5
			}
		}
	}

	option = { # Do nothing
		name = ep3_governor_yearly.8130.d
		stress_impact = {
			greedy = medium_stress_impact_gain
			generous = minor_stress_impact_gain
			arrogant = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = -1
				ai_honor = 1
			}
		}
	}
}

#####################################
# Checking the House				#
# by Joe Parkin						#
# 8140	 							#
#####################################

scripted_trigger ep3_governor_8140_estate_holder_trigger = {
	domicile ?= {
		is_domicile_type = estate
		OR = {
			domicile_location.county.holder ?= root
			domicile_location.county.holder.liege ?= root
			domicile_location.county.holder.liege.liege ?= root
		}
		num_domicile_buildings >= 3
	}
	this != root
	is_ai = yes
	is_available_adult = yes
	ep3_governor_involved_with_root_or_liege_trigger = no
}

ep3_governor_yearly.8140 = {
	type = character_event
	title = ep3_governor_yearly.8140.t
	desc = ep3_governor_yearly.8140.desc
	theme = administrative
	override_background = { reference = relaxing_room }
	left_portrait = {
		character = root
		animation = war_over_win
	}
	right_portrait = {
		character = scope:peasant
		animation = beg
	}
	lower_center_portrait = scope:estate_owner

	cooldown = { years = 15 }

	trigger = {
		has_ep3_dlc_trigger = yes
		is_available_adult = yes
		is_governor = yes
		top_liege = {
			any_vassal_or_below = { ep3_governor_8140_estate_holder_trigger = yes }
		}
	}

	immediate = {
		top_liege = {
			random_vassal_or_below = {
				limit = { ep3_governor_8140_estate_holder_trigger = yes }
				save_scope_as = estate_owner
				domicile = {
					save_scope_as = estate
					domicile_location.county = { save_scope_as = estate_county }
				}
			}
		}
		create_character = {
			template = peasant_character
			location = root.capital_province
			dynasty = none
			culture = scope:estate.domicile_location.county.culture
			faith = scope:estate.domicile_location.county.faith
			gender_female_chance = {
				if = {
					limit = { scope:estate_county.faith = { has_doctrine = doctrine_gender_male_dominated } }
					add = 0
				}
				else_if = {
					limit = { scope:estate_county.faith = { has_doctrine = doctrine_gender_female_dominated } }
					add = 100
				}
				else = { add = 50 }
			}
			save_scope_as = peasant
		}
		scope:estate_county = { change_development_progress_with_overflow = -50 }
	}

	option = { # Fine family
		name = ep3_governor_yearly.8140.a
		change_influence = minor_influence_loss
		increase_governance_effect = { VALUE = 5 }
		remove_treasury_or_gold = medium_treasury_or_gold_value
		progress_towards_rival_effect = {
			REASON = rival_family_estate_fined
			CHARACTER = scope:estate_owner
			OPINION = default_rival_opinion
		}
		stress_impact = {
			arbitrary = minor_stress_impact_gain
			arrogant = minor_stress_impact_gain
			greedy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_compassion = 1
				ai_honor = 1
			}
			modifier = {
				treasury_or_gold < major_treasury_or_gold_value
				factor = 0
			}
		}
	}

	option = { # Reason with family
		name = ep3_governor_yearly.8140.b
		change_influence = medium_influence_loss
		duel = {
			skill = diplomacy
			value = decent_skill_rating
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = 1
				}
				reverse_add_opinion = {
					target = scope:estate_owner
					modifier = respect_opinion
					opinion = 15
				}
				scope:estate_county = {
					add_county_modifier = {
						modifier = ep3_governor_yearly_8140_negotiated_modifier
						years = 10
					}
				}
			}
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = 1
				}
				reverse_add_opinion = {
					target = scope:estate_owner
					modifier = contempt_opinion
					opinion = -15
				}
				scope:estate_county = {
					add_county_modifier = {
						modifier = ep3_governor_yearly_8140_ignored_modifier
						years = 10
					}
				}
			}
		}
		stress_impact = {
			arbitrary = minor_stress_impact_gain
			arrogant = minor_stress_impact_gain
			greedy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_compassion = 1
				ai_honor = 1
			}
		}
	}

	option = { # Side with family
		name = ep3_governor_yearly.8140.c
		change_influence = minor_influence_gain
		progress_towards_friend_effect = {
			REASON = friend_family_estate_permission
			CHARACTER = scope:estate_owner
			OPINION = default_friend_opinion
		}
		scope:estate_county = {
			add_county_modifier = {
				modifier = ep3_governor_yearly_8140_defended_modifier
				years = 10
			}
		}
		stress_impact = {
			just = minor_stress_impact_gain
			humble = minor_stress_impact_gain
			generous = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_sociability = 0.5
				ai_honor = -0.5
			}
		}
	}

	option = { # Ignore
		name = ep3_governor_yearly.8140.d
		scope:estate_county = {
			add_county_modifier = {
				modifier = ep3_governor_yearly_8140_ignored_modifier
				years = 10
			}
		}
		stress_impact = {
			generous = minor_stress_impact_gain
			compassionate = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_honor = -1
			}
		}
	}

	after = {
		scope:peasant = { silent_disappearance_effect = yes }
	}
}

#####################################
# End of the Tether					#
# by Joe Parkin						#
# 8150	 							#
#####################################

scripted_trigger ep3_governor_yearly_8150_county_trigger = {
	OR = {
		ep3_governor_yearly_8150_create_faction_chance_trigger = { TYPE = populist }
		ep3_governor_yearly_8150_create_faction_chance_trigger = { TYPE = peasant }
	}
}

scripted_trigger ep3_governor_yearly_8150_create_faction_chance_trigger = {
	county_opinion < -25
	title_create_faction_type_chance = {
		type = $TYPE$_faction
		target = root
		value >= 10
	}
}

scripted_trigger ep3_governor_yearly_8150_existing_faction_trigger = {
	OR = {
		faction_is_type = peasant_faction
		faction_is_type = populist_faction
	}
	NOT = { has_variable = ep3_governor_yearly_8150_ignored }
}

scripted_effect ep3_governor_yearly_8150_create_faction_effect = {
	title_create_faction  = {
		type = $TYPE$_faction
		target = root
	}
	add_to_list = rebel_counties
	random_title_joined_faction = {
		limit = { faction_is_type = $TYPE$_faction }
		save_scope_as = targeting_faction
	}
}

scripted_effect ep3_governor_yearly_8150_county_modifier_effect = {
	every_in_list = {
		list = rebel_counties
		custom = ep3_governor_yearly.8150.county_tt
		add_county_modifier = {
			modifier = ep3_governor_yearly_8150_$MODIFIER$_modifier
			years = 10
		}
	}
	hidden_effect = {
		every_in_list = {
			list = potential_rebel_counties
			add_county_modifier = {
				modifier = ep3_governor_yearly_8150_$MODIFIER$_modifier
				years = 10
			}
		}
	}
}

ep3_governor_yearly.8150 = {
	type = character_event
	title = ep3_governor_yearly.8150.t
	desc = {
		desc = ep3_governor_yearly.8150.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:targeting_faction = { faction_is_type = populist_faction }
					scope:marshal.culture != scope:targeting_faction.var:faction_culture
				}
				desc = ep3_governor_yearly.8150.culture
			}
			triggered_desc = {
				trigger = {
					scope:targeting_faction = { faction_is_type = populist_faction }
					scope:marshal.faith != scope:targeting_faction.var:faction_faith
				}
				desc = ep3_governor_yearly.8150.faith
			}
			desc = ep3_governor_yearly.8150.peasant
		}
		desc = ep3_governor_yearly_8150.end
	}
	theme = administrative
	override_background = { reference = relaxing_room }
	left_portrait = {
		character = root
		animation = disapproval
	}
	right_portrait = {
		character = scope:marshal
		animation = worry
	}
	lower_right_portrait = scope:rebel_leader

	cooldown = { years = 15 }

	trigger = {
		is_available_adult = yes
		is_governor = yes
		OR = {
			any_targeting_faction = { ep3_governor_yearly_8150_existing_faction_trigger = yes }
			any_held_county = { ep3_governor_yearly_8150_county_trigger = yes }
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = {
				value = governor_efficiency
				divide = 100
				multiply = -1
			}
		}
	}

	immediate = {
		# A military character
		cp:councillor_marshal ?= { save_scope_as = marshal }
		if = {
			limit = { NOT = { exists = scope:marshal } }
			ordered_knight = {
				order_by = age
				save_scope_as = marshal
			}
		}
		if = {
			limit = { NOT = { exists = scope:marshal } }
			ordered_courtier = {
				limit = { can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root } }
				order_by = age
				save_scope_as = marshal
			}
		}
		if = {
			limit = {
				any_targeting_faction = { ep3_governor_yearly_8150_existing_faction_trigger = yes }
			}
			random_targeting_faction = {
				limit = { ep3_governor_yearly_8150_existing_faction_trigger = yes }
				weight = {
					base = 1
					modifier = {
						add = {
							value = faction_discontent
							multiply = 0.25
						}
					}
				}
				save_scope_as = targeting_faction
				every_faction_county_member = { add_to_list = rebel_counties }
			}
		}
		else = {
			random_held_county = {
				limit = { ep3_governor_yearly_8150_county_trigger = yes }
				weight = {
					base = 1
					modifier = {
						add = {
							value = county_opinion
							multiply = -1
						}
					}
				}
				if = {
					limit = { ep3_governor_yearly_8150_create_faction_chance_trigger = { TYPE = populist } }
					ep3_governor_yearly_8150_create_faction_effect = { TYPE = populist }
				}
				else = { ep3_governor_yearly_8150_create_faction_effect = { TYPE = peasant } }
			}
		}
		ordered_in_list = {
			list = rebel_counties
			order_by = {
				value = 0
				subtract = county_opinion
			}
			save_scope_as = rebel_county
		}
		if = { # Error suppression
			limit = { exists = scope:targeting_faction }
			root = {
				every_held_county = {
					limit = {
						NOT = { any_title_joined_faction = { this = scope:targeting_faction } }
						can_title_join_faction = scope:targeting_faction
					}
					add_to_list = potential_rebel_counties
				}
			}
		}
		save_scope_value_as = {
			name = potential_rebel_count
			value = {
				value = 0
				every_in_list = {
					list = potential_rebel_counties
					add = 1
				}
				divide = 10
				ceiling = yes
			}
		}
	}

	option = { # Placate leaders
		name = ep3_governor_yearly.8150.a
		remove_treasury_or_gold = minor_treasury_or_gold_value
		duel = {
			skill = diplomacy
			value = decent_skill_rating
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = 1
				}
				desc = ep3_governor_yearly.8150.a.success
				send_interface_toast = {
					type = event_toast_effect_good
					title = ep3_governor_yearly.8150.a.success
					right_icon = scope:rebel_county
					increase_governance_effect = { VALUE = 5 }
					ep3_governor_yearly_8150_county_modifier_effect = { MODIFIER = placated }
				}
			}
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = 1
				}
				desc = ep3_governor_yearly.8150.a.failure
				send_interface_toast = {
					type = event_toast_effect_bad
					title = ep3_governor_yearly.8150.a.failure
					right_icon = scope:rebel_county
					ep3_governor_yearly_8150_county_modifier_effect = { MODIFIER = insulted }
				}
			}
		}
		stress_impact = {
			honest = medium_stress_impact_gain
			just = minor_stress_impact_gain
			greedy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_sociability = 0.5
				ai_honor = -0.5
				ai_greed = -0.5
				ai_energy = 0.5
			}
			modifier = {
				treasury_or_gold < medium_treasury_or_gold_value
				factor = 0
			}
		}
	}

	option = { # Grant requests
		name = ep3_governor_yearly.8150.b
		remove_treasury_or_gold = medium_treasury_or_gold_value
		ep3_governor_yearly_8150_county_modifier_effect = { MODIFIER = concession }
		stress_impact = {
			arrogant = medium_stress_impact_gain
			stubborn = minor_stress_impact_gain
			wrathful = minor_stress_impact_gain
			arbitrary = medium_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_compassion = 1
				ai_greed = -0.5
			}
			modifier = {
				treasury_or_gold < major_treasury_or_gold_value
				factor = 0
			}
		}
	}

	option = { # Crackdown
		name = ep3_governor_yearly.8150.c
		change_influence = minor_influence_gain
		if = {
			limit = {
				scope:targeting_faction = { faction_is_type = populist_faction }
				culture != scope:targeting_faction.var:faction_culture
			}
			culture = {
				change_cultural_acceptance = {
					target = scope:targeting_faction.var:faction_culture
					value = medium_cultural_acceptance_loss
					desc = cultural_acceptance_ep3_governor_yearly_8150_crackdown
				}
			}
			add_character_modifier = {
				modifier = ep3_governor_yearly_8150_minority_crackdown_modifier
				years = 10
			}
		}
		else_if = {
			limit = {
				scope:targeting_faction = { faction_is_type = populist_faction }
				faith != scope:targeting_faction.var:faction_faith
			}
			add_character_modifier = {
				modifier = ep3_governor_yearly_8150_minority_crackdown_modifier
				years = 10
			}
		}
		else = {
			add_character_modifier = {
				modifier = ep3_governor_yearly_8150_peasant_crackdown_modifier
				years = 10
			}
		}
		reverse_add_opinion = {
			target = scope:marshal
			modifier = pleased_opinion
			opinion = 15
		}
		ep3_governor_yearly_8150_county_modifier_effect = { MODIFIER = crackdown }
		scope:targeting_faction = {
			add_faction_discontent = { -10 -20 }
		}
		stress_impact = {
			compassionate = medium_stress_impact_gain
			just = minor_stress_impact_gain
			forgiving = medium_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_compassion = -1
				ai_boldness = 0.5
				ai_energy = 0.5
			}
		}
	}

	option = { # Ignore
		name = ep3_governor_yearly.8150.d
		scope:targeting_faction = {
			add_faction_discontent = { 8 18 }
			custom_tooltip = {
				text = ep3_governor_yearly.8150.d.tt
				set_variable = ep3_governor_yearly_8150_ignored
			}
		}
		ordered_in_list = {
			list = potential_rebel_counties
			max = scope:potential_rebel_count
			check_range_bounds = no
			order_by = {
				value = 0
				subtract = county_opinion
			}
			title_join_faction = scope:targeting_faction
		}
		stress_impact = {
			diligent = medium_stress_impact_gain
			craven = minor_stress_impact_gain
			impatient = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_boldness = -1
				ai_energy = -1
			}
		}
	}
}

#####################################
# Equitable Access					#
# by Joe Parkin						#
# 8160	 							#
#####################################

scripted_trigger ep3_governor_yearly_8160_culture_trigger = {
	culture = {
		NOR = {
			this = root.culture
			this = root.top_liege.culture
		}
		cultural_acceptance = {
			target = root.top_liege.culture
			value < 75
		}
	}
}

scripted_trigger ep3_governor_yearly_8160_faith_trigger = {
	faith = {
		NOR = {
			this = root.faith
			this = root.top_liege.faith
		}
		faith_hostility_level = {
			target = root.top_liege.faith
			value > 1
		}
	}
}

ep3_governor_yearly.8160 = {
	type = character_event
	title = ep3_governor_yearly.8160.t
	desc = {
		desc = ep3_governor_yearly.8160.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:minority_county = { ep3_governor_yearly_8160_culture_trigger = yes }
					culture = top_liege.culture
					scope:councillor.culture != top_liege.culture
				}
				desc = ep3_governor_yearly.8160.culture_councillor
			}
			triggered_desc = {
				trigger = {
					scope:minority_county = { ep3_governor_yearly_8160_culture_trigger = yes }
					culture != top_liege.culture
					scope:councillor.culture = top_liege.culture
				}
				desc = ep3_governor_yearly.8160.culture_self
			}
			triggered_desc = {
				trigger = {
					scope:minority_county = { ep3_governor_yearly_8160_culture_trigger = yes }
				}
				desc = ep3_governor_yearly.8160.culture
			}
			desc = ep3_governor_yearly.8160.faith
		}
		first_valid = {
			triggered_desc = {
				trigger = { scope:minority_county = { ep3_governor_yearly_8160_culture_trigger = yes } }
				desc = ep3_governor_yearly.8160.culture_end
			}
			desc = ep3_governor_yearly.8160.faith_end
		}
	}
	theme = administrative
	override_background = { reference = relaxing_room }
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = { OR = { religion = religion:eastern_orthodox_religion religion = religion:catholic_religion religion = religion:protestant_religion } }
			animation = acknowledging # anim uses crucifix scepter
		}
		animation = war_over_tie
	}
	right_portrait = {
		character = scope:councillor
		animation = dismissal
	}
	lower_center_portrait = scope:administrator

	cooldown = { years = 15 }

	trigger = {
		has_ep3_dlc_trigger = yes
		is_available_adult = yes
		is_governor = yes
		any_sub_realm_county = {
			OR = {
				ep3_governor_yearly_8160_culture_trigger = yes
				ep3_governor_yearly_8160_faith_trigger = yes
			}
		}
	}

	immediate = {
		random_sub_realm_county = {
			limit = {
				ep3_governor_yearly_8160_culture_trigger = yes
				ep3_governor_yearly_8160_faith_trigger = no
			}
			alternative_limit = { ep3_governor_yearly_8160_culture_trigger = yes }
			alternative_limit = { ep3_governor_yearly_8160_faith_trigger = yes }
			weight = {
				base = 1
				modifier = { add = development_level }
				modifier = {
					holder = root
					factor = 2
				}
			}
			save_scope_as = minority_county
		}
		if = {
			limit = { scope:minority_county = { ep3_governor_yearly_8160_culture_trigger = yes } }
			if = {
				limit = {
					cp:councillor_steward ?= {
						NOR = {
							culture = scope:minority_county.culture
							has_trait = humble
							has_trait = compassionate
						}
					}
				}
				cp:councillor_steward = { save_scope_as = councillor }
			}
			if = {
				limit = { NOT = { exists = scope:councillor } }
				ordered_courtier = {
					limit = {
						NOR = {
							culture = scope:minority_county.culture
							has_trait = humble
							has_trait = compassionate
						}
					}
					order_by = stewardship
					save_scope_as = councillor
				}
			}
			save_scope_as = culture
		}
		else = {
			cp:councillor_court_chaplain = { save_scope_as = councillor }
			if = {
				limit = { NOT = { exists = scope:councillor } }
				random_courtier = {
					limit = {
						faith = root.faith
						is_clergy = yes
					}
					alternative_limit = { faith = root.faith }
					weight = {
						base = 1
						modifier = { add = learning }
						modifier = {
							has_trait = zealous
							add = 10
						}
					}
					save_scope_as = councillor
				}
			}
		}
		create_character = {
			template = pool_repopulate_stewardship
			culture = scope:minority_county.culture
			faith = scope:minority_county.faith
			location = root.location
			gender_female_chance = {
				if = {
					limit = { scope:minority_county.faith = { has_doctrine = doctrine_gender_male_dominated } }
					add = 0
				}
				else_if = {
					limit = { scope:minority_county.faith = { has_doctrine = doctrine_gender_female_dominated } }
					add = 100
				}
				else = {
					add = 50
				}
			}
			save_scope_as = administrator
		}
	}

	option = { # Encourage access
		name = ep3_governor_yearly.8160.a
		remove_treasury_or_gold = minor_treasury_or_gold_value
		change_influence = minor_influence_loss
		increase_governance_effect = { VALUE = 5 }
		reverse_add_opinion = {
			target = scope:councillor
			modifier = angry_opinion
			opinion = -25
		}
		add_courtier = scope:administrator
		reverse_add_opinion = {
			target = scope:administrator
			modifier = grateful_opinion
			opinion = 50
		}
		if = {
			limit = { exists = scope:culture }
			culture = {
				change_cultural_acceptance = {
					target = scope:minority_county.culture
					value = minor_cultural_acceptance_gain
					desc = cultural_acceptance_promoted_bureaucrats
				}
			}
			stress_impact = {
				callous = minor_stress_impact_gain
				arrogant = minor_stress_impact_gain
				arbitrary = minor_stress_impact_gain
				lazy = minor_stress_impact_gain
			}
		}
		else = {
			add_piety = minor_piety_gain
			every_sub_realm_county = {
				limit = { faith = scope:minority_county.faith }
				custom = ep3_governor_yearly.8160.faith_county_tt
				add_county_modifier = {
					modifier = ep3_governor_yearly_8160_promoted_modifier
					years = 10
				}
			}
			stress_impact = {
				callous = minor_stress_impact_gain
				arbitrary = minor_stress_impact_gain
				lazy = minor_stress_impact_gain
				zealous = minor_stress_impact_gain
			}
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_compassion = 1
				ai_honor = 1
			}
			modifier = {
				treasury_or_gold < medium_treasury_or_gold_value
				factor = 0
			}
		}
	}

	option = { # Suppress
		name = ep3_governor_yearly.8160.b
		add_dread = medium_dread_gain
		if = {
			limit = { exists = scope:culture }
			culture = {
				change_cultural_acceptance = {
					target = scope:minority_county.culture
					value = minor_cultural_acceptance_loss
					desc = cultural_acceptance_promoted_bureaucrats
				}
			}
			every_sub_realm_county = {
				limit = { culture = scope:minority_county.culture }
				custom = ep3_governor_yearly.8160.culture_county_tt
				add_county_modifier = {
					modifier = ep3_governor_yearly_8160_suppressed_modifier
					years = 10
				}
			}
			stress_impact = {
				compassionate = medium_stress_impact_gain
				humble = minor_stress_impact_gain
				just = minor_stress_impact_gain
				diligent = minor_stress_impact_gain
			}
		}
		else = {
			every_sub_realm_county = {
				limit = { faith = scope:minority_county.faith }
				custom = ep3_governor_yearly.8160.faith_county_tt
				add_county_modifier = {
					modifier = ep3_governor_yearly_8160_suppressed_modifier
					years = 10
				}
			}
			stress_impact = {
				compassionate = medium_stress_impact_gain
				cynical = minor_stress_impact_gain
				just = minor_stress_impact_gain
				diligent = minor_stress_impact_gain
			}
		}
		reverse_add_opinion = {
			target = scope:councillor
			modifier = pleased_opinion
			opinion = 25
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_boldness = 1
				ai_honor = -1
			}
		}
	}

	option = { # Dismiss
		name = ep3_governor_yearly.8160.d
		ai_chance = {
			base = 100
		}
	}
	after = {
		scope:administrator = {
			silent_disappearance_ai_effect = yes
		}
	}
}

#####################################
# Local Defense						#
# by Joe Parkin						#
# 8170	 							#
#####################################

scripted_trigger ep3_governor_yearly_8170_raider_trigger = {
	save_temporary_scope_as = raider_temp
	trigger_if = {
		limit = {
			root = {
				any_character_to_title_neighboring_county = { holder.top_liege = scope:raider_temp.top_liege }
			}
		}
		can_raid_trigger = yes
	}
	trigger_else = { can_raid_across_water_trigger = yes }
	ep3_governor_involved_with_root_or_liege_trigger = no
	NOR = {
		root.top_liege ?= top_liege
		any_ally = {
			OR = {
				this = root
				target_is_liege_or_above = root
			}
		}
		any_war_enemy = {
			OR = {
				this = root
				target_is_liege_or_above = root
			}
		}
		any_truce_target = {
			OR = {
				this = root
				target_is_liege_or_above = root
			}
		}
	}
}

ep3_governor_yearly.8170 = {
	type = character_event
	title = {
		desc = {
			first_valid = {
				triggered_desc = {
					trigger = {
						any_character_to_title_neighboring_county = { holder.top_liege = scope:raider.top_liege }
					}
					desc = ep3_governor_yearly.8170.t.land
				}
				desc = ep3_governor_yearly.8170.t.sea
			}
		}
	}
	desc = {
		desc = ep3_governor_yearly.8170.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					any_character_to_title_neighboring_county = { holder.top_liege = scope:raider.top_liege }
				}
				desc = ep3_governor_yearly.8170.land
			}
			desc = ep3_governor_yearly.8170.sea
		}
		desc = ep3_governor_yearly.8170.ending
	}
	theme = administrative
	override_background = { reference = relaxing_room }
	left_portrait = {
		character = root
		animation = thinking
	}
	right_portrait = {
		character = root.cp:councillor_marshal
		animation = debating
	}
	lower_center_portrait = scope:raider

	cooldown = { years = 15 }

	trigger = {
		is_available_adult = yes
		is_governor = yes
		any_character_to_title_neighboring_and_across_water_county = {
			holder = {
				OR = {
					ep3_governor_yearly_8170_raider_trigger = yes
					any_liege_or_above = { ep3_governor_yearly_8170_raider_trigger = yes }
				}
			}
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			any_character_to_title_neighboring_and_across_water_county = {
				holder = {
					OR = {
						AND = {
							ep3_governor_yearly_8170_raider_trigger = yes
							reverse_has_opinion_modifier = {
								target = root
								modifier = raided_me_opinion
							}
						}
						any_liege_or_above = {
							ep3_governor_yearly_8170_raider_trigger = yes
							reverse_has_opinion_modifier = {
								target = root
								modifier = raided_me_opinion
							}
						}
					}
				}
			}
			add = 1
		}
	}

	immediate = {
		save_scope_as = governor
		# A military character
		cp:councillor_marshal ?= { save_scope_as = marshal }
		if = {
			limit = { NOT = { exists = scope:marshal } }
			ordered_knight = {
				order_by = age
				save_scope_as = marshal
			}
		}
		if = {
			limit = { NOT = { exists = scope:marshal } }
			ordered_courtier = {
				limit = { can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root } }
				order_by = age
				save_scope_as = marshal
			}
		}
		scope:marshal = { add_to_list = threatened_vassals }
		# A raiding neighbour
		every_character_to_title_neighboring_and_across_water_county = {
			limit = {
				holder = {
					OR = {
						ep3_governor_yearly_8170_raider_trigger = yes
						any_liege_or_above = { ep3_governor_yearly_8170_raider_trigger = yes }
					}
				}
			}
			holder = {
				if = {
					limit = {
						any_liege_or_above = { ep3_governor_yearly_8170_raider_trigger = yes }
					}
					ordered_liege_or_above = {
						limit = { ep3_governor_yearly_8170_raider_trigger = yes }
						order_by = highest_held_title_tier
						add_to_list = potential_raiders
					}
				}
				else = { add_to_list = potential_raiders }
			}
		}
		random_in_list = {
			list = potential_raiders
			weight = {
				base = 1
				modifier = {
					reverse_has_opinion_modifier = {
						target = root
						modifier = raided_me_opinion
					}
					add = 10
				}
			}
			save_scope_as = raider
			every_character_to_title_neighboring_and_across_water_county = {
				limit = {
					save_temporary_scope_as = neighbour_county_temp
					root = { any_sub_realm_county = { this = scope:neighbour_county_temp } }
				}
				add_to_list = threatened_counties
				if = {
					limit = { holder != root }
					holder = {
						add_to_list = threatened_vassals
						every_liege_or_above = {
							limit = {
								NOR = {
									this = root
									highest_held_title_tier < root.highest_held_title_tier
								}
							}
							add_to_list = threatened_vassals
						}
					}
				}
			}
		}
		random_in_list = {
			list = threatened_counties
			weight = {
				base = 1
				modifier = {
					any_county_province = { has_province_modifier = recently_looted_modifier }
					add = 10
				}
				modifier = {
					add = {
						value = 5
						subtract = title_province.fort_level
					}
				}
				modifier = {
					add = {
						value = title_province.available_loot
						multiply = 0.1
					}
				}
			}
			save_scope_as = raid_county
		}
		set_variable = {
			name = threatened_counties_count
			value = {
				value = 0
				every_in_list = {
					list = threatened_counties
					add = 1
				}
			}
			months = 1
		}
	}

	option = { # A
		name = ep3_governor_yearly.8170.a
		remove_treasury_or_gold = {
			value = {
				value = minor_treasury_or_gold_value
				multiply = var:threatened_counties_count
				max = 100
			}
		}
		increase_governance_effect = { VALUE = 5 }
		every_in_list = {
			list = threatened_counties
			custom = ep3_governor_yearly.8170.modifier_tt
			add_county_modifier = {
				modifier = ep3_governor_yearly_8170_warning_system_modifier
				years = 10
			}
		}
		every_in_list = {
			list = threatened_vassals
			custom = ep3_governor_yearly.8170.opinion_tt
			add_opinion = {
				target = root
				modifier = respect_opinion
				opinion = 10
			}
		}
		stress_impact = {
			greedy = medium_stress_impact_gain
			callous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = -1
				ai_rationality = 1
				ai_honor = 1
			}
			modifier = {
				treasury_or_gold < major_treasury_or_gold_value
				factor = 0
			}
		}
	}

	option = { # Own ideas
		name = ep3_governor_yearly.8170.b
		remove_treasury_or_gold = medium_treasury_or_gold_value
		duel = {
			skill = martial
			value = decent_skill_rating
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = 1
				}
				desc = ep3_governor_yearly.8170.b.success
				send_interface_toast = {
					type = event_toast_effect_good
					title = ep3_governor_yearly.8170.b.success
					change_influence = minor_influence_gain
					increase_governance_effect = { VALUE = 10 }
					every_in_list = {
						list = threatened_counties
						custom = ep3_governor_yearly.8170.modifier_tt
						add_county_modifier = {
							modifier = ep3_governor_yearly_8170_success_modifier
							years = 10
						}
					}
					every_in_list = {
						list = threatened_vassals
						custom = ep3_governor_yearly.8170.opinion_tt
						add_opinion = {
							target = root
							modifier = respect_opinion
							opinion = 20
						}
					}
				}
			}
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = 1
				}
				desc = ep3_governor_yearly.8170.b.failure
				send_interface_toast = {
					type = event_toast_effect_bad
					title = ep3_governor_yearly.8170.b.failure
					every_in_list = {
						list = threatened_counties
						custom = ep3_governor_yearly.8170.modifier_tt
						add_county_modifier = {
							modifier = ep3_governor_yearly_8170_failure_modifier
							years = 10
						}
					}
					every_in_list = {
						list = threatened_vassals
						custom = ep3_governor_yearly.8170.opinion_tt
						add_opinion = {
							target = root
							modifier = angry_opinion
							opinion = -20
						}
					}
				}
			}
		}
		stress_impact = {
			greedy = minor_stress_impact_gain
			callous = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = -0.5
				ai_boldness = 1
				ai_energy = 1
			}
			modifier = {
				treasury_or_gold < major_treasury_or_gold_value
				factor = 0
			}
		}
	}

	option = { # Diplomacy
		name = ep3_governor_yearly.8170.c
		duel = {
			skill = diplomacy
			value = decent_skill_rating
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 5
					min = 3
				}
				desc = ep3_governor_yearly.8170.c.success
				send_interface_toast = {
					type = event_toast_effect_good
					title = ep3_governor_yearly.8170.c.success
					left_icon = scope:marshal
					right_icon = scope:raider
					scope:raider = {
						add_opinion = {
							target = root
							modifier = respect_opinion
							opinion = 15
						}
						add_truce_one_way = {
							character = root
							years = 10
							name = ep3_governor_yearly_8170_truce
						}
					}
				}
			}
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -5
					min = 3
				}
				desc = ep3_governor_yearly.8170.c.failure
				send_interface_toast = {
					type = event_toast_effect_bad
					title = ep3_governor_yearly.8170.c.failure
					left_icon = scope:marshal
					right_icon = scope:raider
					change_influence = minor_influence_loss
					reverse_add_opinion = {
						target = scope:raider
						modifier = contempt_opinion
						opinion = -25
					}
				}
			}
		}
		stress_impact = {
			wrathful = minor_stress_impact_gain
			vengeful = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_sociability = 1
				ai_compassion = 1
			}
		}
	}

	option = { # Refuse
		name = ep3_governor_yearly.8170.d
		reverse_add_opinion = {
			target = scope:marshal
			modifier = annoyed_opinion
			opinion = -15
		}
		stress_impact = {
			generous = minor_stress_impact_gain
			compassionate = minor_stress_impact_gain
			diligent = minor_stress_impact_gain
			just = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = 1
				ai_compassion = 1
				ai_honor = -1
			}
		}
	}
}
