﻿### EK NOTE: Removed references to vanilla cultures, added our character creation effect and removed trash artifact

#Events for statecraft lifestyle rank up

namespace = stewardship_wealth

# Normal Events
	#1001	 	- I'm Bankrupt?, by Stephen Arthur and Sean Hughes
	#1011		- Mint New Coins!, by Stephen Arthur and Sean Hughes
	#1021		- Paying for War, by Sean Hughes
	#1022		- War profiteering, by Isabella Welch
	#1051		- Freeman's Fortune, by Sean Hughes
	#1061		- New Acquisitions, by Sean Hughes
	#2000 		- Weighting Opportunities, by Krzysztof Lankowski
	#5001 		- Purchase Livestock, by Linnéa Thimrén
	#5002		- Investment advice (wealth friend), by Mathilda Bjarnehed
	#7000		- Rogue Administration by Jason Cantalini

# As it is currently, this event only exists to stop the game from throwing an error.
stewardship_wealth.0001 = {
	hidden = yes
	orphan = yes
	immediate = { add_character_flag = is_in_stewardship_wealth_special_event }
}

##########################################
# Im am Bankrupt!?
# by Stephen Arthur and Sean Hughes
# 1001
##########################################

scripted_trigger stewardship_wealth_1001_wealthy_vassal = {
	is_available_ai = yes
	short_term_gold >= root.medium_gold_value

	NOT = {
		has_hook_of_type = {
			target = root
			type = favor_hook
		}
	}
}

#Pick from several options of alleviating your debts.
stewardship_wealth.1001 = {
	type = character_event
	title = stewardship_wealth.1001.t
	desc = stewardship_wealth.1001.desc
	
	theme = stewardship_wealth_focus
	left_portrait = {
		character = root
		animation = worry
	}
	right_portrait = {
		character = scope:wealthy_vassal
		animation = schadenfreude
	}
	
	trigger = {
		gold < 0

		is_available_adult_or_is_commanding = yes
		NOT = { has_character_flag = had_event_stewardship_wealth_1001 }
	}

	weight_multiplier = {
		base = 1

		#Higher chance of occuring the more in-debt you are.
		modifier = {
			gold < -100
			add = 5
		}
		modifier = {
			gold < -200
			add = 15
		}

		#Additional chance of occuring if you're actively bleeding money.
		modifier = {
			monthly_character_income <= monthly_character_expenses
			factor = 10
		}

		upweight_for_focus_modifier = { FOCUS = stewardship_wealth_focus }
	}

	immediate = {
		add_character_flag = {
			flag = had_event_stewardship_wealth_1001
			years = 5
		}

		#Find a vassal who could help us out of this problem.
		random_vassal = {
			#Prioritize vassals who already owe us a favor which we can call in.
			limit = {
				stewardship_wealth_1001_wealthy_vassal = yes
				save_temporary_scope_as = wealthy_vassal
				root = {
					has_hook_of_type = {
						target = scope:wealthy_vassal
						type = favor_hook
					}	
				}
			}
			#Otherwise prioritize vassals who are at least Counts or above.
			alternative_limit = {
				stewardship_wealth_1001_wealthy_vassal = yes
				highest_held_title_tier >= 2
			}
			#Else just find anyone who we don't already owe a favor to.
			alternative_limit = {
				stewardship_wealth_1001_wealthy_vassal = yes
			}

			#Prefer vassals with whom owing(or being owed) a favor would be consequential.
			weight = {
				base = 100

				modifier = {
					highest_held_title_tier >= 3
					add = 100
				}
				modifier = {
					highest_held_title_tier >= 4
					add = 200
				}
				modifier = {
					is_powerful_vassal_of = root
					add = 300
				}
			}

			save_scope_as = wealthy_vassal
		}
	}

	#Option 1: Stewardship challenge to find some old debts in your ledgers you had forgotten about.
	option = {
		name = stewardship_wealth.1001.a

		add_stewardship_lifestyle_xp = medium_lifestyle_experience

		duel = {
			skill = stewardship
			value = 10

			10 = {
				compare_modifier = {
					value = scope:duel_value
				}
				desc = stewardship_wealth.1001.a.success
				send_interface_toast = {
					type = event_toast_effect_good
					title = stewardship_wealth.1001.a.success
					left_icon = root

					add_gold = medium_gold_value
				}
			}
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -0.5
				}
				desc = stewardship_wealth.1001.a.failure
				send_interface_toast = {
					type = event_toast_effect_bad
					title = stewardship_wealth.1001.a.failure
					left_icon = root
					
					add_stress = minor_stress_gain
				}
			}
		}


		stress_impact = {
			lazy = minor_stress_impact_gain
			dull = minor_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_energy = 1.0
			}

			modifier = {
				add = 100
				stewardship >= 12
			}
		}			
	}

	#Option 2: Exchange a favor with a wealth vassal to get some gold from them.
	option = {
		trigger = {
			exists = scope:wealthy_vassal
			OR = {
				has_usable_hook = scope:wealthy_vassal
				scope:wealthy_vassal = {
					can_add_hook = {
						target = root
						type = favor_hook
					}
				}
			}
		}
		name = {
			text = stewardship_wealth.1001.b.givehook
		}
		name = {
			trigger = {
				has_hook_of_type = {
					target = scope:wealthy_vassal
					type = favor_hook
				}
			}
			text = stewardship_wealth.1001.b.havehook
		}

		if = {
			limit = {
				has_usable_hook = scope:wealthy_vassal
			}
			use_hook = scope:wealthy_vassal
		}
		else = {
			scope:wealthy_vassal = {
				add_hook = {
					target = root
					type = favor_hook
				}
			}
		}

		scope:wealthy_vassal = {
			pay_short_term_gold = {
				target = root
				gold = root.medium_gold_value
			}
		}

		stress_impact = {
			ambitious = minor_stress_impact_gain
			shy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 1.0
				ai_boldness = -1.0
				ai_greed = -1.0
			}
		}	
	}
	
	#Option 3: A tyrannical ruler can spend Dread to receive gold from their vassals, though the move makes them seem weak.
	option = {
		name = stewardship_wealth.1001.c

		trigger = {
			dread >= 40
			any_vassal = {
				count >= 1
			}
		}

		add_dread = medium_dread_loss

		every_vassal = {
			custom = stewardship_wealth.1001.c.tt
			add_opinion = {
				modifier = weak_opinion
				target = root
				opinion = -10
			}
		}

		add_gold = medium_gold_value

		stress_impact = {
			compassionate = minor_stress_impact_gain
			forgiving = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = -2.0
				ai_boldness = 1.0
				ai_greed = 2.0
				ai_vengefulness = 1.0
			}
		}
	}

	#Option 4: Confiscate church property to pay for your debts.
	option = {
		name = stewardship_wealth.1001.d

		add_piety = medium_piety_loss
		add_gold = medium_gold_value

		stress_impact = {
			zealous = medium_stress_impact_gain
			just = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_zeal = -3.0
				ai_greed = 2.0
			}
		}
	}

	#Option 5: Tighten your belt. Earn a small amount of gold for stress
	option = {
		name = stewardship_wealth.1001.e
		add_gold = minor_gold_value

		stress_impact = {
			base = minor_stress_impact_gain
			gluttonous = medium_stress_impact_gain
			arrogant = minor_stress_impact_gain
			greedy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = -3.0
				ai_boldness = -2.0
			}
		}
	}

}

##########################################
# Mint new coins
# by Stephen Arthur and Sean Hughes
# 1011
##########################################

#Decide what methodology you want to use for minting coins.
stewardship_wealth.1011 = {
	type = character_event
	title = stewardship_wealth.1011.t
	desc = stewardship_wealth.1011.desc
	
	theme = stewardship_wealth_focus
	left_portrait = {
		character = root
		animation = personality_rational
	}

	trigger = {
		is_independent_ruler = yes
		is_landed = yes
		NOR = {
			has_character_flag = had_event_stewardship_wealth_1011
			government_has_flag = government_is_nomadic
		}	
	}

	weight_multiplier = {
		base = 1
		upweight_for_focus_modifier = { FOCUS = stewardship_wealth_focus }
	}	

	immediate = {
		add_character_flag = {
			flag = had_event_stewardship_wealth_1011
			years = 5
		}
	}


	#Option 1: Mint new silver coins to encourage commerce.
	option = {
		name = stewardship_wealth.1011.a

		#Add silver coins modifier to realm.
		every_sub_realm_county = {
			custom = stewardship_wealth.1011.custom
			add_county_modifier = {
				modifier = governance_newly_minted_silver_coins_modifier
				days = 1825
			}		
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = 2
			}
		}
	}

	#Option 2: Mint new gold coins to gain prestige.
	option = {
		name = stewardship_wealth.1011.b

		if = {
			limit = {
				highest_held_title_tier >= 3
			}
			add_prestige = major_prestige_gain
		}
		else_if = {
			limit = {
				highest_held_title_tier = 2
			}
			add_prestige = medium_prestige_gain
		}
		else = {
			add_prestige = minor_prestige_gain
		}
		

		stress_impact = {
			humble = minor_stress_impact_gain
			content = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = 2
			}
		}
	}

	#Option 3: Debase the coins to earn a quick buck.
	option = {
		name = stewardship_wealth.1011.c

		add_stewardship_lifestyle_xp = medium_lifestyle_experience

		duel = {
			skill = stewardship
			value = 10

			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
				}
				desc = stewardship_wealth.1011.c.success
				send_interface_toast = {
					type = event_toast_effect_good
					title = stewardship_wealth.1011.c.success
					left_icon = root

					#Add silver coins modifier to realm.
					every_sub_realm_county = {
						custom = stewardship_wealth.1011.custom
						add_county_modifier = {
							modifier = governance_newly_minted_silver_coins_modifier
							days = 1825
						}		
					}

					#Adds gold to the character's treasury.
					add_gold = medium_gold_value
				}
			}
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
				}
				desc = stewardship_wealth.1011.c.failure
				send_interface_toast = {
					type = event_toast_effect_bad
					title = stewardship_wealth.1011.c.failure
					left_icon = root
					
					add_prestige = medium_prestige_loss
				}
			}
		}		


		stress_impact = {
			generous = medium_stress_impact_gain
			honest = medium_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_greed = 3
				ai_honor = -1
			}
		}			
	}
}

##########################################
# War Taxes
# by Sean Hughes
# 1021
##########################################

#Gain several options to help you pay for your war.
stewardship_wealth.1021 = {
	type = character_event
	title = stewardship_wealth.1021.t
	desc = stewardship_wealth.1021.desc
	left_portrait = {
		character = root
		animation = worry
	}
	right_portrait = {
		trigger = {
			exists = root.cp:councillor_steward
			root.cp:councillor_steward = {
				is_available_healthy_ai_adult = yes
			}
		}
		character = cp:councillor_steward
		animation = writing
	}
	theme = stewardship_wealth_focus
	
	trigger = {
		#Must be at war and losing money.
		is_at_war = yes
		is_available_adult_or_is_commanding = yes
		is_landed = yes
		monthly_character_income < monthly_character_expenses
		NOT = { has_character_flag = had_event_stewardship_wealth_1021 }
		OR = {
			government_has_flag = government_is_clan
			government_has_flag = government_is_feudal
			government_has_flag = government_is_administrative
			#EK ADDITION
			government_has_flag = government_is_autocracy
			government_has_flag = government_is_hierocracy
		}
	}

	weight_multiplier = {
		base = 1

		#More likely to occur the less money you have in your treasury.
		modifier = {
			gold < major_gold_value
			add = 0.5
		}
		modifier = {
			gold < medium_gold_value
			add = 1.0
		}
		modifier = {
			gold < minor_gold_value
			add = 2.0
		}

		upweight_for_focus_modifier = { FOCUS = stewardship_wealth_focus }
	}

	immediate = {
		add_character_flag = {
			flag = had_event_stewardship_wealth_1021
			years = 5
		}
		random_character_war = {
			save_scope_as = war_needing_finance
		}
		random_primary_war_enemy = {
			save_scope_as = war_enemy_for_faith_check
		}
		random_character_war = {
			save_scope_as = current_war
		}
	}

	#Option 1: Raise war taxes, gaining a large boost to income but raising unrest in your provinces.
	option = {
		name = stewardship_wealth.1021.a
		every_sub_realm_county = {
			custom = stewardship_wealth.1021.a.custom
			add_county_modifier = {
				modifier = governance_1021_war_taxes_modifier
				years = 3
			}	
		}

		stress_impact = {
			compassionate = minor_stress_impact_gain
			generous = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = 2
				ai_compassion = -1
				ai_honor = 2
			}
		}	
	}

	#Option 2: Reduce the maintenance cost of your armies; Martial challenge to avoid getting a combat penalty.
	option = {
		name = stewardship_wealth.1021.b

		add_stewardship_lifestyle_xp = medium_lifestyle_experience

		duel = {
			skill = martial
			value = 12

			10 = {
				compare_modifier = {
					value = scope:duel_value
				}
				desc = stewardship_wealth.1021.b.success
				send_interface_toast = {
					type = event_toast_effect_good
					title = stewardship_wealth.1021.b.success
					left_icon = root

					#Add maintenance reduction modifier to this character's armies.
					add_character_modifier = {
						modifier = governance_1021_efficiently_supplied_armies_modifer
						years = 3
					}
				}
			}
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -0.5
				}
				desc = stewardship_wealth.1021.b.failure
				send_interface_toast = {
					type = event_toast_effect_bad
					title = stewardship_wealth.1021.b.failure
					left_icon = root
					
					#Add maintenance reduction modifier + combat penalty to this character's armies.
					add_character_modifier = {
						modifier = governance_1021_undersupplied_armies_modifier
						years = 3
					}
				}
			}
		}

		stress_impact = {
			lazy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_energy = 2
				ai_boldness = 1
			}

			#AI is more likely to pick this if they have a good chance of succeeding.
			modifier = {
				martial >= 12
				add = 100
			}
		}		

	}
	
	#Option 3: Gain a bonus to looting enemy lands.
	option = {
		name = stewardship_wealth.1021.c
		custom_tooltip = stewardship_wealth.1021.c.tt
		stress_impact = {
			base = minor_stress_impact_loss
			lazy = minor_stress_impact_loss
			diligent = medium_stress_impact_gain
		}
		hidden_effect = {
			if = {
				limit = {
					scope:war_enemy_for_faith_check.faith = root.faith
				}
				trigger_event = {
					id = stewardship_wealth.1022
					days = { 5 10 }
				}
			}
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = 1
				ai_compassion = -2
				ai_honor = -2
			}
		}	
	}
}
# War Profiteering, by Isabella Welch
# triggers if you chose to ignore the fact you were in debt
stewardship_wealth.1022 = {
	type = character_event
	title = stewardship_wealth.1022.t
	desc = stewardship_wealth.1022.desc
	theme = stewardship_wealth_focus
	right_portrait = {
		character = scope:church_burner
		animation = happiness
	}
	override_background = {
		reference = burning_building
	}
	
	trigger = { 
		ROOT = {
			is_at_war = yes
		}
		any_knight = {
			NOT = { has_trait = devoted }
			has_faith = ROOT.faith
			is_available_ai_adult = yes 
		}
		exists = scope:war_needing_finance
	}

	weight_multiplier = {
		base = 1
	}

	immediate = { #Knight announces they've burnt a church down and looted it
		random_knight = {
			limit = {
				NOT = { has_trait = devoted }
				has_faith = root.faith
				is_available_ai_adult = yes 
			}
			add_gold = minor_gold_value
			weight = {
				base = 1
				compare_modifier = {
   					value = prowess
   					multiplier = -0.3
				}
				modifier = {
					has_trait = wrathful
					factor = 10
				}
			}
			save_scope_as = church_burner
		}
	}

	option = { # Admit you need the money
		name = stewardship_wealth.1022.a
		add_gold = medium_gold_value
		add_piety = major_piety_loss
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = 1
				ai_greed = 1
			}
		}
	}

	option = { # Refuse to use the money, spend it on reparations
		name = stewardship_wealth.1022.b
		add_character_modifier = {
			modifier = war_guilt_modifier
			years = 5
		}
		every_held_county = {
			custom = custom.every_held_county
			add_county_modifier = {
				modifier = liege_discourages_pillaging_modifier
				years = 5
			}
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = -1
				ai_compassion = 2
			}
		}
	}
	
	option = { # I should be able to take whatever I want!
		name = stewardship_wealth.1022.c
		trigger = {
			OR = {
				has_trait = greedy
				has_trait = wrathful
				has_trait = vengeful
				has_trait = overseer
			}
		}
		trait = greedy
		trait = wrathful
		trait = vengeful
		trait = overseer
		add_dread = medium_dread_gain
		add_gold = massive_gold_value
		add_character_modifier = {
			modifier = church_burner_modifier
			years = 5
		}
		add_piety = massive_piety_loss
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = 2
				ai_boldness = 2
			}
		}
	}
}

##########################################
# Freeman's Fortune
# by Sean Hughes
# 1051
##########################################

stewardship_wealth.1051 = {
	type = character_event
	title = stewardship_wealth.1051.t
	desc = stewardship_wealth.1051.desc
	
	theme = stewardship_wealth_focus
	override_background = { reference = garden }
	left_portrait = {
		character = scope:freeman
		animation = bribing
	}
	
	trigger = {
		NOT = { has_character_flag = had_stewardship_wealth_1051_event }

		#Only feudal governments have serfs and freemen.
		government_has_flag = government_is_feudal

		#Must hold a county title.
		any_held_title = {
			tier = tier_county
		}
	}

	weight_multiplier = {
		base = 1
		upweight_for_focus_modifier = { FOCUS = stewardship_wealth_focus }
	}	

	immediate = {
		add_character_flag = {
			flag = had_stewardship_wealth_1051_event
			days = 3650
		}

		#Find one of our owned counties.
		random_held_title = {
			limit = {
				tier = tier_county
			}

			#Save the scope.
			save_scope_as = target_county
			
			#Generate a high stewardship peasant to be our successful farmer.
			root = { random_dummy_gender_landholder_effect = yes }
			create_character = {
				age = { 20 30 }
				location = root.capital_province
				gender = scope:dummy_gender
				trait = education_stewardship_2
				trait = intellect_good_2
				trait = diligent
				faith = this.faith
				culture = this.culture
				dynasty = none
				stewardship = { 10 12 }
				#EK EDIT
				after_creation = {
					ek_character_setup_effect = yes
				}
				#EK EDIT END
				save_scope_as = freeman
			}
		}
	}

	#Recruit the peasant farmer to our court.
	option = {
		name = {
			trigger = {
				NOT = { has_trait = arrogant }
			}
			text = stewardship_wealth.1051.a
		}
		name = {
			trigger = {
				has_trait = arrogant
			}
			text = stewardship_wealth.1051.a.arrogant
		}
		trait = arrogant

		add_courtier = scope:freeman

		if = {
			limit = {
				NOT = { has_trait = arrogant }
			}
			scope:freeman = {
				add_opinion = {
					modifier = grateful_opinion
					target = root
					opinion = 25
				}
			}
		}
		else = {
			scope:freeman = {
				add_opinion = {
					modifier = insult_opinion
					target = root
					opinion = -10
				}
			}
		}

		stress_impact = {
			shy = minor_stress_gain
		}

		ai_chance = {
			base = 0
		}
	}

	#Allow the peasant farmer to buy your lands, gaining a lot of gold but suffering heavy county authority penalties.
	option = {
		name = stewardship_wealth.1051.b
		add_gold = medium_gold_value
		scope:target_county = {
			add_county_modifier = {
				modifier = governance_1051_independent_farmlands_modifier
				days = 1825
			}
		}
		hidden_effect = {
			scope:freeman = {
				death = {
					death_reason = death_disappearance
				}
			}
		}

		stress_impact = {
			paranoid = minor_stress_impact_gain
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 200
				ai_greed = 100
			}
		}
	}

	#Refuse to allow the farmer more land, solidifying your grip on the province.
	option = {
		name = stewardship_wealth.1051.d
		scope:target_county = {
			if = {
				limit = {
					county_control < 100
				}
				change_county_control = 20
			}
			else = {
				add_county_modifier = {
					modifier = stewardship_domain_personal_ownership_modifier
					days = 1825
				}
			}
		}
		hidden_effect = {
			scope:freeman = {
				death = {
					death_reason = death_disappearance
				}
			}
		}

		stress_impact = {
			generous = medium_stress_impact_gain
			humble = minor_stress_impact_gain
			content = minor_stress_impact_gain
			just = minor_stress_impact_gain
		}

		ai_chance = {
			base = 100

			ai_value_modifier = {
				ai_compassion = -200
				ai_boldness = 100
				ai_vengefulness = 100
			}

			#If county authority is already so high this would have no benefit, the AI will avoid it.
			modifier = {
				factor = 0.2

				AND = {
					ai_rationality >= 10
					scope:target_county = {
						county_control >= 90
					}
				}
			}			
		}
	}
}


##################################
# New Acquisitions
# 1061
# by Sean Hughes
##################################

scripted_trigger stewardship_wealth_1061_valid_vassal = {

	# Must not be a Baron.
	trigger_if = {
		limit = {
			is_vassal_or_below_of = root
		}
		highest_held_title_tier > 1
	}
	# Must be available for events.
	is_available_ai_adult = yes

	# Must not hate me.
	opinion = {
		target = root
		value >= -10
	}

	save_temporary_scope_as = temp_vassal
	
	# Must not be me.
	NOT = { root = scope:temp_vassal }
	
	# Neither of us can have a hook on the other.
	NOR = {
		has_hook = root
		root = {
			has_hook = scope:temp_vassal
		}
	}
}

scripted_trigger stewardship_wealth_1061_valid_writer = {
	has_no_particular_noble_roots_trigger = yes
	is_available_healthy_ai_adult = yes
	NOR = {
		exists = inspiration
		has_trait = peasant_leader
	}
}

#Character receives 3 different opportunities, they pick one to follow up on.
stewardship_wealth.1061 = {
	type = character_event
	title = stewardship_wealth.1061.t
	desc = stewardship_wealth.1061.desc
	
	theme = stewardship_wealth_focus
	left_portrait = {
		character = scope:vassal
		animation = idle
	}
	
	trigger = {
		OR = {
			AND = {
				is_landless_adventurer = yes
				any_courtier = {
					stewardship_wealth_1061_valid_vassal = yes					
				}
			}
			any_vassal = {
				stewardship_wealth_1061_valid_vassal = yes
			}
		}
		NOR = { 
			has_character_flag = had_stewardship_wealth_1061_event 
			any_character_artifact = {
				has_artifact_feature = book_topic_stewardship_old_ledger
			}
		}
	}

	weight_multiplier = {
		base = 1

		#More likely to occur if the character has high Diplomacy or Learning (or both).
		compare_modifier = {
			factor = diplomacy
			multiplier = 0.1
		}
		compare_modifier = {
			factor = learning
			multiplier = 0.1
		}

		downweight_for_focus_modifier = { FOCUS = stewardship_domain_focus }
	}

	immediate = {
		add_character_flag = {
			flag = had_stewardship_wealth_1061_event
			days = 3650
		}
		liege = {
			random_vassal_or_below = {
				limit = {
					stewardship < root.stewardship
					stewardship_wealth_1061_valid_vassal = yes
				}
				alternative_limit = {
					stewardship_wealth_1061_valid_vassal = yes
				}

				weight = {
					base = 1

					# Much higher chance to pick low-stewardship vassals.
					modifier = {
						stewardship <= low_skill_rating
						add = 100000
					}
					modifier = {
						stewardship <= mediocre_skill_rating
						add = 10000
					}
					modifier = {
						stewardship <= medium_skill_rating
						add = 1000
					}
					modifier = {
						stewardship <= decent_skill_rating
						add = 100
					}
					modifier = {
						stewardship <= high_skill_rating
						add = 10
					}
					modifier = {
						stewardship <= very_high_skill_rating
						add = 1
					}		

					# But a higher chance to pick higher-tier vassals (with more responsibility).
					compare_modifier = {
						factor = highest_held_title_tier
					}

				}
				save_scope_as = vassal
			}
		}
		if = {
			limit = {
				any_pool_character = {
					province = root.capital_province
					stewardship_wealth_1061_valid_writer = yes
				}
			}
			random_pool_character = {
				province = root.capital_province
				limit = {
					stewardship_wealth_1061_valid_writer = yes
				}
				save_scope_as = anonymous_book_writer
			}
		}
		else = {
			# Artisan Generation
			hidden_effect = {
				create_character = {
					template = local_artisan_template
					location = root.capital_province
					gender_female_chance = root_faith_dominant_gender_adjusted_female_chance
					save_scope_as = anonymous_book_writer
				}
			}
		}
	}

	# Option A: Learning challenge to gain a powerful Stewardship modifier.
	option = {
		name = stewardship_wealth.1061.a

		duel = {
			skill = learning
			value = 10

			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = stewardship_wealth.1061.a.success
				#Make book artifact
				hidden_effect = {
					save_scope_as = author
					#Book is made into trinket if no royal court
					if = {
						limit = {
							has_royal_court = no
						}
						save_temporary_scope_value_as = {
							name = should_be_trinket
							value = yes
						}
					}
					create_artifact_book_effect = { #using effect to ensure that scope:owner is set properly
						OWNER = root
						CREATOR = scope:anonymous_book_writer
						SET_SUBJECT = flag:stewardship
						SET_TOPIC = flag:no
					}
				}
				send_interface_toast = {
					type = event_toast_effect_good
					title = stewardship_wealth.1061.a.success
					left_icon = root
					right_icon = scope:newly_created_artifact
					custom_tooltip = stewardship_wealth.1061.a.success.good
				}
			}
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = stewardship_wealth.1061.a.failure
				hidden_effect = {
					save_scope_as = author
					save_temporary_scope_value_as = {
						name = should_be_trinket
						value = yes
					}
					scope:anonymous_book_writer = {
						add_character_flag = local_artisan #Only set in B since this is what makes it lower quality
					}
					create_artifact_book_effect = { #using effect to ensure that scope:owner is set properly
						OWNER = root
						CREATOR = scope:anonymous_book_writer
						SET_SUBJECT = flag:stewardship
						SET_TOPIC = flag:stewardship_old_ledger
					}
					save_scope_as = low_quality
				}
				send_interface_toast = {
					type = event_toast_effect_good
					title = stewardship_wealth.1061.a.failure
					left_icon = root
					right_icon = scope:newly_created_artifact
					
					#Make book artifact, crummy book is always a trinket
					custom_tooltip = stewardship_wealth.1061.a.success.bad
				}
			}
		}

		stress_impact = {
			dull = minor_stress_impact_gain
		}
		ai_chance = {
			base = 50

			# Rational characters know when they have a good chance of winning the duel
			compare_modifier = {
				trigger = {
					ai_rationality >= 10
				}
				value = {
					value = learning
					add = -10
				}
				multiplier = 1000 # -10,000 at 0 Stewardship, +0 at 10 Stewardship, +10,000 at 20 Stewardship
			}

			ai_value_modifier = {
				ai_rationality = 100
			}
		}
	}

	# Option B: Gain a Favor on a random vassal.
	option = {
		name = stewardship_wealth.1061.b
		trigger = { exists = scope:vassal }
		#Gain a hook on the vassal
		add_hook = {
			target = scope:vassal
			type = favor_hook
		}

		stress_impact = {
			shy = minor_stress_impact_gain
			sadistic = minor_stress_impact_gain
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = 200
				ai_greed = -100
			}
		}
	}
	
	# Option C: Just give me some gold.
	option = {
		name = stewardship_wealth.1061.c

		add_gold = major_gold_value

		stress_impact = {
			compassionate = minor_stress_impact_gain
			generous = minor_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_greed = 200
				ai_compassion = -100
				ai_rationality = -100
			}
		}
	}

	after = {
		if = {
			limit = {
				scope:anonymous_book_writer = {
					is_pool_character = no
				}
			}
			scope:anonymous_book_writer = { death = { death_reason = death_vanished } }
		}
	}
}

##################################
# Purchase Livestock
# 5001
# by Linnéa Thimrén
##################################

stewardship_wealth.5001 = {
	type = character_event
	title = stewardship_wealth.5001.t
	desc = stewardship_wealth.5001.desc
	
	theme = stewardship_wealth_focus
	left_portrait = {
		character = root
		animation = shepherd_with_sheep
	}
	override_background = { reference = market }
	
	trigger = {
		NOT = { has_character_flag = had_purchase_livestock_event }
		exists = capital_county
		capital_county = {
			holder = root
			NOR = {
				has_county_modifier = governance_cattle_herd_county_modifier
				has_county_modifier = governance_large_cattle_herd_county_modifier
			}
		}
	}

	weight_multiplier = {
		base = 1
		downweight_for_focus_modifier = { FOCUS = stewardship_duty_focus }
	}	

	immediate = {
		add_character_flag = {
			flag = had_purchase_livestock_event
			days = 3650
		}
		capital_county = {
			save_scope_as = capital
		}
	}

	option = { #give them to the county
		name = stewardship_wealth.5001.a
		scope:capital = {
			add_county_modifier = {
				modifier = governance_cattle_herd_county_modifier
				years = 15
			}
		}
		if = {
			limit = {
				is_governor = yes
			}
			increase_governance_effect = { VALUE = 2 }
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_rationality = 0.5
			}
		}
	}

	option = { #try to breed them
		name = stewardship_wealth.5001.b
		duel = {
			skill = stewardship
			value = medium_skill_rating
			30 = {		
				compare_modifier = {
					value = scope:duel_value
					multiplier = 1
				}
				desc = stewardship_wealth.5001.b.message_1
				send_interface_toast = {
					type = event_toast_effect_good
					left_icon = scope:capital
					title = stewardship_wealth.5001.b.message_1
					scope:capital = {
						add_county_modifier = {
							modifier = governance_large_cattle_herd_county_modifier
							years = 15
						}
					}
					if = {
						limit = {
							is_governor = yes
						}
						increase_governance_effect = { VALUE = 6 }
					}
				}
			}
			10 = {
				desc = stewardship_wealth.5001.b.message_2
				send_interface_toast = {
					type = event_toast_effect_bad
					left_icon = scope:capital
					title = stewardship_wealth.5001.b.message_2
					add_prestige = miniscule_prestige_loss
					if = {
						limit = {
							is_governor = yes
						}
						increase_governance_effect = { VALUE = -2 }
					}
				}
			}
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_greed = 0.5
			}
		}
	}
	
	option = { #slaughter and sell
		#EK DISABLED: no hinduism
		#trigger = {
		#	NOT = { religion = religion:hinduism_religion }
		#}
		name = stewardship_wealth.5001.c
		add_gold = medium_gold_value
		stress_impact = {
			compassionate = minor_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_vengefulness = 0.5
			}
		}
	}
}


##################################
# Investment advice (wealth friend)
# by Mathilda Bjarnehed
##################################

stewardship_wealth.5002 = { #by Mathilda Bjarnehed
	type = character_event
	title = stewardship_wealth.5002.t
	desc = {
		desc = stewardship_wealth.5002.start.desc
		first_valid = {
			triggered_desc = {
				trigger = { scope:safe_investment = flag:smithy }
				desc = stewardship_wealth.5002.safe_smithy.desc
			}
			triggered_desc = {
				trigger = { scope:safe_investment = flag:mason }
				desc = stewardship_wealth.5002.safe_mason.desc
			}
			triggered_desc = {
				trigger = { scope:safe_investment = flag:religious_sculptor }
				desc = stewardship_wealth.5002.safe_religious_sculptor.desc
			}
			triggered_desc = {
				trigger = { scope:safe_investment = flag:jeweler }
				desc = stewardship_wealth.5002.safe_jeweler.desc
			}
		}
		desc = stewardship_wealth.5002.middle.desc
		first_valid = {
			triggered_desc = {
				trigger = { scope:risky_investment = flag:smithy }
				desc = stewardship_wealth.5002.risky_smithy.desc
			}
			triggered_desc = {
				trigger = { scope:risky_investment = flag:mason }
				desc = stewardship_wealth.5002.risky_mason.desc
			}
			triggered_desc = {
				trigger = { scope:risky_investment = flag:religious_sculptor }
				desc = stewardship_wealth.5002.risky_religious_sculptor.desc
			}
			triggered_desc = {
				trigger = { scope:risky_investment = flag:jeweler }
				desc = stewardship_wealth.5002.risky_jeweler.desc
			}
		}
		desc = stewardship_wealth.5002.end.desc
	}
	
	theme = stewardship_wealth_focus
	override_background = {
		reference = market
	}
	left_portrait = {
		character = root
		animation = personality_rational
	}
	right_portrait = {
		character = scope:investor
		animation = personality_honorable
	}
	
	trigger = {
		NOT = { has_character_flag = had_event_stewardship_wealth_5002 }
		exists = capital_province
		capital_province.monthly_income >= 0.5
		is_landed = yes
	}

	weight_multiplier = {
		base = 1
			upweight_for_focus_modifier = { FOCUS = stewardship_wealth_focus }
	}

	immediate = {
		add_character_flag = {
			flag = had_event_stewardship_wealth_5002
			years = stewardship_wealth_5002_investment_duration
		}
		random_relation = {
			type = friend
			limit = { 
				lifestyle_friend_trigger = { 
					CHARACTER = root FOCUS = stewardship_wealth_focus 
				}
				is_available_ai_adult = yes
			}
			save_scope_as = investor
		}
		if = {
			limit = { NOT = { exists = scope:investor } }
			potential_lifestyle_friend_saving_effect = { FOCUS = stewardship_wealth_focus SCOPE_NAME = investor }
		}

		capital_province = { save_scope_as = capital }

		#Pick safe investment
		random_list = {
			1 = {
				save_scope_value_as = {
					name = safe_investment
					value = flag:smithy
				}
			}
			1 = {
				save_scope_value_as = {
					name = safe_investment
					value = flag:mason
				}
			}
			1 = {
				#EK DISABLED no aniconism
				#trigger = {
					#faith = {
						#NOR = {
							#has_doctrine = tenet_aniconism
							#religion = religion:islam_religion
						#}
					#}
				#}
				save_scope_value_as = {
					name = safe_investment
					value = flag:religious_sculptor
				}
			}
			1 = {
				save_scope_value_as = {
					name = safe_investment
					value = flag:jeweler
				}
			}
		}

		#Pick potential friend suggested option
		random_list = {
			1 = {
				trigger = { NOT = { scope:safe_investment = flag:smithy } }
				save_scope_value_as = {
					name = risky_investment
					value = flag:smithy
				}
			}
			1 = {
				trigger = { NOT = { scope:safe_investment = flag:mason } }
				save_scope_value_as = {
					name = risky_investment
					value = flag:mason
				}
			}
			1 = {
				trigger = {
					NOT = { scope:safe_investment = flag:religious_sculptor }
					#EK DISABLED no aniconism
					#faith = {
						#NOR = {
							#has_doctrine = tenet_aniconism
							#religion = religion:islam_religion
						#}
					#}
				}
				save_scope_value_as = {
					name = risky_investment
					value = flag:religious_sculptor
				}
			}
			1 = {
				trigger = { NOT = { scope:safe_investment = flag:jeweler } }
				save_scope_value_as = {
					name = risky_investment
					value = flag:jeweler
				}
			}
		}
	}

	#Safe investment
	option = {
		name = {
			trigger = { scope:safe_investment = flag:smithy }
			text = stewardship_wealth.5002.a.smithy
		}
		name = {
			trigger = { scope:safe_investment = flag:mason }
			text = stewardship_wealth.5002.a.mason
		}
		name = {
			trigger = {
				scope:safe_investment = flag:religious_sculptor
				#EK DISABLED no aniconism
				#faith = {
					#NOR = {
						#has_doctrine = tenet_aniconism
						#religion = religion:islam_religion
					#}
				#}
			}
			text = stewardship_wealth.5002.a.religious_sculptor
		}
		name = {
			trigger = { scope:safe_investment = flag:jeweler }
			text = stewardship_wealth.5002.a.jeweler
		}

		remove_short_term_gold = stewardship_wealth_5002_payment
		
		capital_province = {
			switch = {
				trigger = scope:safe_investment
				flag:smithy = {
					add_province_modifier = {
						modifier = smithy_investment_modifier
						years = stewardship_wealth_5002_investment_duration
					}
					ROOT = {
						add_character_modifier = {
							modifier = smithy_investment_character_modifier
							years = stewardship_wealth_5002_investment_duration
						}
					}
				}
				flag:mason = {
					add_province_modifier = {
						modifier = mason_investment_modifier
						years = stewardship_wealth_5002_investment_duration
					}
					ROOT = {
						add_character_modifier = {
							modifier = mason_investment_character_modifier
							years = stewardship_wealth_5002_investment_duration
						}
					}
				}
				flag:religious_sculptor = {
					add_province_modifier = {
						modifier = religious_sculptor_investment_modifier
						years = stewardship_wealth_5002_investment_duration
					}
					ROOT = {
						add_character_modifier = {
							modifier = religious_sculptor_investment_character_modifier
							years = stewardship_wealth_5002_investment_duration
						}
					}
				}
				flag:jeweler = {
					add_province_modifier = {
						modifier = jeweler_investment_modifier
						years = stewardship_wealth_5002_investment_duration
					}
					ROOT = {
						add_character_modifier = {
							modifier = jeweler_investment_character_modifier
							years = stewardship_wealth_5002_investment_duration
						}
					}
				}
			}
		}
		
		if = { # Admin governors gain some XP
			limit = {
				is_governor = yes
				has_trait = governor
			}
			increase_governance_effect = { VALUE = 2 }
		}
	}

	#Risky investment
	option = {
		name = {
			trigger = { scope:risky_investment = flag:smithy }
			text = stewardship_wealth.5002.a.smithy
		}
		name = {
			trigger = { scope:risky_investment = flag:mason }
			text = stewardship_wealth.5002.a.mason
		}
		name = {
			trigger = {
				scope:risky_investment = flag:religious_sculptor
				#EK DISABLED no aniconism
				#faith = {
					#NOR = {
						#has_doctrine = tenet_aniconism
						#religion = religion:islam_religion
					#}
				#}
			}
			text = stewardship_wealth.5002.a.religious_sculptor
		}
		name = {
			trigger = { scope:risky_investment = flag:jeweler }
			text = stewardship_wealth.5002.a.jeweler
		}

		remove_short_term_gold = stewardship_wealth_5002_payment

		if = {
			limit = { has_relation_friend = scope:investor }
			capital_province = {
				switch = {
					trigger = scope:risky_investment
					flag:smithy = {
						add_province_modifier = {
							modifier = great_smithy_investment_modifier
							years = stewardship_wealth_5002_investment_duration
						}
						ROOT = {
							add_character_modifier = {
								modifier = great_smithy_investment_character_modifier
								years = stewardship_wealth_5002_investment_duration
							}
						}
					}
					flag:mason = {
						add_province_modifier = {
							modifier = great_mason_investment_modifier
							years = stewardship_wealth_5002_investment_duration
						}
						ROOT = {
							add_character_modifier = {
								modifier = great_mason_investment_character_modifier
								years = stewardship_wealth_5002_investment_duration
							}
						}
					}
					flag:religious_sculptor = {
						add_province_modifier = {
							modifier = great_religious_sculptor_investment_modifier
							years = stewardship_wealth_5002_investment_duration
						}
						ROOT = {
							add_character_modifier = {
								modifier = great_religious_sculptor_investment_character_modifier
								years = stewardship_wealth_5002_investment_duration
							}
						}
					}
					flag:jeweler = {
						add_province_modifier = {
							modifier = great_jeweler_investment_modifier
							years = stewardship_wealth_5002_investment_duration
						}
						ROOT = {
							add_character_modifier = {
								modifier = great_jeweler_investment_character_modifier
								years = stewardship_wealth_5002_investment_duration
							}
						}
					}
				}
			}
			
			if = { # Admin governors gain some XP
				limit = {
					is_governor = yes
					has_trait = governor
				}
				increase_governance_effect = { VALUE = 4 }
			}
		}
		else = {
			random_list = {
				75 = {
					desc = stewardship_wealth.5002.b.success
					send_interface_toast = {
						type = event_toast_effect_good
						title = stewardship_wealth.5002.b.success
						left_icon = scope:investor
						
						set_relation_friend = { reason = friend_bonded_over_good_business_investments target = scope:investor }
						capital_province = {
							switch = {
								trigger = scope:risky_investment
								flag:smithy = {
									add_province_modifier = {
										modifier = great_smithy_investment_modifier
										years = stewardship_wealth_5002_investment_duration
									}
									ROOT = {
										add_character_modifier = {
											modifier = great_smithy_investment_character_modifier
											years = stewardship_wealth_5002_investment_duration
										}
									}
								}
								flag:mason = {
									add_province_modifier = {
										modifier = great_mason_investment_modifier
										years = stewardship_wealth_5002_investment_duration
									}
									ROOT = {
										add_character_modifier = {
											modifier = great_religious_sculptor_investment_character_modifier
											years = stewardship_wealth_5002_investment_duration
										}
									}
								}
								flag:religious_sculptor = {
									add_province_modifier = {
										modifier = great_religious_sculptor_investment_modifier
										years = stewardship_wealth_5002_investment_duration
									}
									ROOT = {
										add_character_modifier = {
											modifier = great_religious_sculptor_investment_character_modifier
											years = stewardship_wealth_5002_investment_duration
										}
									}
								}
								flag:jeweler = {
									add_province_modifier = {
										modifier = great_jeweler_investment_modifier
										years = stewardship_wealth_5002_investment_duration
									}
									ROOT = {
										add_character_modifier = {
											modifier = great_jeweler_investment_character_modifier
											years = stewardship_wealth_5002_investment_duration
										}
									}
								}
							}
						}
						
						if = { # Admin governors gain some XP if successful
							limit = {
								is_governor = yes
								has_trait = governor
							}
							increase_governance_effect = { VALUE = 4 }
						}
					}
				}
				25 = {
					desc = stewardship_wealth.5002.b.failure
					send_interface_toast = {
						type = event_toast_effect_bad
						title = stewardship_wealth.5002.b.failure
						left_icon = scope:investor
						
						if = { # Admin governors lose some XP if unsuccessful
							limit = {
								is_governor = yes
								has_trait = governor
							}
							increase_governance_effect = { VALUE = -2 }
						}

						custom_tooltip = stewardship_wealth.5002.b.failure.tt
					}
				}
			}
		}
	}
	
	#Just trade at the market
	option = {
		name = stewardship_wealth.5002.c
		
		add_gold = stewardship_wealth_5002_one_time_gain
	}
}

stewardship_wealth.6001 = {
	type = character_event
	title = stewardship_wealth.6001.t
	desc = stewardship_wealth.6001.desc
	theme = stewardship_wealth_focus
	left_portrait = {
		character = scope:stall_owner
		animation = happiness
	}

	override_background = {
		reference = market
	}

	trigger = {
		is_at_war = no
		any_held_county = { count >= 1 }
		#EK DISABLED: no iconoclasts
		# NOT = {
			# faith = faith:iconoclast
		# }
		#EK DISABLED: That artifact was disabled further down
		#NOT = {
		#	any_character_artifact = {
		#		has_variable = small_wooden_carving_artifact
		#	}
		#}
		any_held_county = {
			holder = root
			NOT = {
				title_province = {
					has_holding_type = nomad_holding
				}
			}
		}
	}

	weight_multiplier = {
		base = 1
		upweight_for_focus_modifier = { FOCUS = stewardship_wealth_focus }
	}

	immediate = {
		create_character = {
			gender_female_chance = 50
			age = {18 50}
			random_traits = yes
			save_scope_as = stall_owner
			template_character = root
			dynasty = none
			location = root.capital_province
			#EK EDIT
			after_creation = {
				ek_character_setup_effect = yes
				unmourned_blood_traits_effect = yes
			}
			#EK EDIT END
		}

		random_held_county = {
			limit = {
				holder = root
			}
			save_scope_as = stall_county
		}
	}

	option = { #Buy something
		name = stewardship_wealth.6001.a

		remove_short_term_gold = medium_gold_value

		random_list = {
			60 = {
				create_artifact = {	
					name = small_religious_carving
					type = miscellaneous
					creator = scope:stall_owner
					description = small_religious_carving_desc 
					template = small_religious_carving_template
					visuals = pouch
					modifier = artifact_monthly_piety_1_modifier
					wealth = 10
					quality = 20
					save_scope_as = newly_created_artifact
				}
				scope:newly_created_artifact = {
					set_variable = {
						name = relic_religion
						value = scope:stall_owner.faith.religion
					}
					set_variable = small_wooden_carving_artifact
					flag_as_trash_artifact = yes
				}
				desc = stewardship_wealth.6001.a.tt_high
				send_interface_toast = {
					title = stewardship_wealth.6001.a.tt_high
					left_icon = scope:stall_owner
					right_icon = scope:newly_created_artifact
					show_as_tooltip = {
						scope:newly_created_artifact = { set_owner = root }
					}
				}
			}
			40 = {
				desc = stewardship_wealth.6001.a.tt_low
				send_interface_toast = {
					title = stewardship_wealth.6001.a.tt_low
					left_icon = scope:stall_owner
					add_character_modifier = {
						modifier = supported_local_business_modifier
						years = 5
					}
				}
			}
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_greed = -0.5
			}
		}
	}

	option = { #Destroy the Stall
		name = stewardship_wealth.6001.b

		add_gold = minor_gold_value
		add_dread = minor_dread_gain
		scope:stall_county = {
			add_county_modifier = {
				modifier = destroyed_market_stall_modifier
				years = 5
			}
		}

		stress_impact = {
			greedy = miniscule_stress_impact_loss
			generous = minor_stress_impact_gain
			compassionate = minor_stress_impact_gain

		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_greed = 0.5
			}
		}
	}

	option = { #Ask the stall owner for business advice
		name = stewardship_wealth.6001.c

		add_stewardship_lifestyle_xp = medium_lifestyle_xp

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_rationality = 0.5
			}
		}
	}

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


}

##################################
# Rogue Administration
# by Jason Cantalini
##################################

# One of your knights offers to shake down the family/peasants of a rival

scripted_trigger stewardship_wealth_7000_enforcer_trigger = {
	is_available_healthy_ai_adult = yes
	highest_held_title_tier <= tier_barony
	NOR = {
		has_trait = compassionate
		has_trait = just
		has_relation_rival = root
	}
	opinion = {
		target = root
		value > -30
	}
}

scripted_trigger stewardship_wealth_7000_victim_trigger = {
	highest_held_title_tier <= tier_duchy
	exists = capital_county
	NOT = { is_at_war_with = root }
	opinion = {
		target = root
		value < -30
	}
	NOT = { has_character_flag = had_event_sins_of_the_master_7000 }

}

stewardship_wealth.7000 = {
	type = character_event
	title = stewardship_wealth.7000.t
	desc = stewardship_wealth.7000.desc
	theme = stewardship_wealth_focus
	cooldown = { years = 10 }
	left_portrait = {
		character = root
		animation = personality_vengeful
	}
	right_portrait = {
		character = scope:enforcer
		animation = scheme
	}
	lower_right_portrait = scope:victim

	trigger = {
		has_focus = stewardship_wealth_focus
		is_available = yes
		is_landed_or_landless_administrative = yes
		highest_held_title_tier <= tier_duchy
		any_knight = {
			stewardship_wealth_7000_enforcer_trigger = yes
		}
		# target should be a ruler with a realm within reach
		OR = {
			# Check liege's sub-realm if there is one...
			trigger_if = {
				limit = { exists = liege }
				top_liege = {
					any_vassal_or_below = { stewardship_wealth_7000_victim_trigger = yes }
				}
			}
			# ... else abroad.
			trigger_else = {
				any_neighboring_realm_same_rank_owner = { stewardship_wealth_7000_victim_trigger = yes }
			}
		}
	}
	
	weight_multiplier = {
		base = 1
		modifier = {
			add = 0.5
			has_trait = sadistic
		}
		modifier = {
			add = 0.5
			has_trait = vengeful
		}
		modifier = {
			add = 0.5
			has_trait = greedy
		}
	}

	immediate = {
		#Choose knight who approaches you with the offer
		random_knight = {
			limit = {
				stewardship_wealth_7000_enforcer_trigger = yes
				has_relation_best_friend = root
			}
			alternative_limit = {
				stewardship_wealth_7000_enforcer_trigger = yes
				has_relation_friend = root
			}
			alternative_limit = {
				stewardship_wealth_7000_enforcer_trigger = yes
				opinion = {
					target = root
					value >= 0
				}
			}
			alternative_limit = {
				stewardship_wealth_7000_enforcer_trigger = yes
				opinion = {
					target = root
					value >= -40
				}
			}
			save_scope_as = enforcer
		}
		# Choose the target.
		## First, let's assemble a list.
		### Do we want our liege's sub-realm?
		if = {
			limit = { exists = liege }
			top_liege = {
				every_vassal_or_below = {
					limit = { stewardship_wealth_7000_victim_trigger = yes }
					add_to_list = candidates_list
				}
			}
		}
		### Otherwise, grab similar-tiered rulers.
		else = {
			every_neighboring_realm_same_rank_owner = {
				limit = { stewardship_wealth_7000_victim_trigger = yes }
				add_to_list = candidates_list
			}
		}
		## Now, grab someone within the list.
		ordered_in_list = {
			list = candidates_list
			order_by = {
				# Pick someone who'd suck at defending their lands if we can.
				value = 100
				subtract = martial
				# Weight up rivals.
				if = {
					limit = { has_relation_rival = root }
					add = 15
				}
				# And potential rivals.
				else_if = {
					limit = { has_relation_potential_rival = root }
					add = 5
				}
			}
			save_scope_as = victim
		}
		# The target shouldn't be harassed too often
		scope:victim = {
			add_character_flag = {
				flag = had_event_sins_of_the_master_7000
				years = 25
			}
		}
		# save root as scope for future
		root = {
			save_scope_as = thieving_rival
		}
	}

	# Stolen from my rival's peasants, you say? Sounds good.
	option = {
		name = stewardship_wealth.7000.a
		add_gold = minor_gold_value
		if = {
			limit = {
				scope:victim = {
					is_vassal_or_below_of = root
				}
			}
			add_tyranny = minor_tyranny_gain
		}
		scope:victim = { save_scope_as = relationship_reason_involved_character }
		progress_towards_friend_effect = {
			CHARACTER = scope:enforcer
			OPINION = 25
			REASON = friend_stole_from_rival
		}
		clear_saved_scope = relationship_reason_involved_character
		progress_towards_rival_effect = {
			REASON = rival_stole_from_peasants
			CHARACTER = scope:victim
			OPINION = -25
		}
		scope:victim = {
			add_prestige = minor_prestige_loss
			capital_county = {
				add_county_modifier = {
					modifier = stewardship_stolen_taxes_modifier
						years = 2
				}
			}
		}
		create_character_memory = {
			type = stole_from_my_rival
			participants = {
				enforcer = scope:enforcer
				victim = scope:victim
			}
		}
		# mirror event for target
		scope:victim = {
				trigger_event = { id = stewardship_wealth.7001 days = 1 } 
		}
		stress_impact = {
			greedy = minor_stress_impact_loss
			compassionate = major_stress_impact_gain
			forgiving = medium_stress_impact_gain
			content = minor_stress_impact_gain
		}
		if = {
			limit = {
				NOT = { government_has_flag = government_is_tribal }
			}
			stress_impact = {
				just = major_stress_impact_gain
			}
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_greed = 0.5
				ai_honor = -1
				ai_vengefulness = 0.75
				ai_compassion = -0.75
				ai_boldness = 0.25
			}
		}
	}

	# Stewardship skill can make my knight stealing from a vassal seem justified
	option = {
		trigger = {
			stewardship >= high_skill_rating
			scope:victim = {
				is_vassal_or_below_of = root
			}
		}
		name = stewardship_wealth.7000.b
		flavor = stewardship_wealth.7000.b.tt
		add_gold = minor_gold_value
		add_stewardship_lifestyle_xp = medium_lifestyle_xp
		progress_towards_friend_effect = {
			CHARACTER = scope:enforcer
			OPINION = 25
			REASON = friend_taxed_vassals_lands
		}
		progress_towards_rival_effect = {
			REASON = rival_stole_from_peasants
			CHARACTER = scope:victim
			OPINION = default_rival_opinion
		}
		scope:victim = {
			add_prestige = minor_prestige_loss
			capital_county = {
				add_county_modifier = {
					modifier = stewardship_stolen_taxes_modifier
						years = 2
				}
			}
		}
		create_character_memory = {
			type = stole_from_my_rival
			participants = {
				enforcer = scope:enforcer
				victim = scope:victim
			}
		}
		# mirror event for target
		scope:victim = {
				trigger_event = { id = stewardship_wealth.7001 days = 1 } 
		}
		add_character_flag = {
			flag = made_theft_justifications
			days = 30
		}
		stress_impact = {
			greedy = minor_stress_impact_loss
			compassionate = major_stress_impact_gain
			generous = major_stress_impact_gain
			honest = medium_stress_impact_gain
			content = minor_stress_impact_gain
			forgiving = minor_stress_impact_gain
		}
		if = {
			limit = {
				NOT = { government_has_flag = government_is_tribal }
			}
			stress_impact = {
				just = major_stress_impact_gain
			}
		}
		ai_chance = {
			base = 150
			ai_value_modifier = {
				ai_greed = 0.75
				ai_honor = -1
				ai_vengefulness = 0.5
				ai_compassion = -0.75
				ai_boldness = 0.25
			}
		}
	}

	# Stewardship skill inspires a good use for the wealth
	option = {
		trigger = {
			stewardship >= high_skill_rating
			scope:victim = {
				 NOT = { is_vassal_or_below_of = root }
			}
		}
		name = stewardship_wealth.7000.c
		flavor = stewardship_wealth.7000.c.tt
		add_character_modifier = {
			modifier = stewardship_rampaging_knights_modifier
			years = 10
		}
		if = {
			limit = {
				NOT = { has_relation_friend = scope:enforcer }
			}
			set_relation_friend = { reason = friend_taxed_vassals_lands target = scope:enforcer }
		}
		# all knights love the license to go hog wild
 		every_knight = {
 			custom = custom.every_knight	
 			add_opinion = {
				target = root
				modifier = pleased_opinion
				opinion = 20
			}
 		}
		progress_towards_rival_effect = {
			REASON = rival_stole_from_peasants
			CHARACTER = scope:victim
			OPINION = -40
		}
		scope:victim = {
			add_prestige = minor_prestige_loss
			capital_county = {
				add_county_modifier = {
					modifier = stewardship_stolen_taxes_modifier
					years = 2
				}
			}
		}
		add_tyranny = minor_tyranny_gain
		create_character_memory = {
			type = stole_from_my_rival
			participants = {
				enforcer = scope:enforcer
				victim = scope:victim
			}
		}
		# mirror event for target
		scope:victim = {
			trigger_event = { id = stewardship_wealth.7001 days = 1 } 
		}
		add_character_flag = {
			flag = unleashed_knights
			days = 30
		}
		stress_impact = {
			greedy = minor_stress_impact_loss
			compassionate = major_stress_impact_gain
			generous = major_stress_impact_gain
			forgiving = medium_stress_impact_gain
			content = medium_stress_impact_gain
			humble = medium_stress_impact_gain
		}
		if = {
			limit = {
				NOT = { government_has_flag = government_is_tribal }
			}
			stress_impact = {
				just = major_stress_impact_gain
			}
		}
		else = {
			stress_impact = {
				just = medium_stress_impact_gain
			}
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = 1
				ai_honor = -1
				ai_vengefulness = 0.5
				ai_compassion = -1
				ai_boldness = 0.25
			}
		}
	}

	# Stealing is wrong!
	option = {
		name = stewardship_wealth.7000.d
		flavor = stewardship_wealth.7000.d.tt
		# piety gain rquires an appropriate faith
		if = {
			limit = {
				OR = {
 					faith = { trait_is_virtue = forgiving }
 					faith = { trait_is_virtue = just }
 					faith = { trait_is_sin = greedy }
 				}
 			}
			add_piety = medium_piety_gain
		}
		scope:enforcer = {
			add_opinion = {
				modifier = angry_opinion
				target = root
				opinion = -40
			}
		}
		progress_towards_rival_effect = {
			REASON = rival_prevented_stealing_from_peasants
			CHARACTER = scope:enforcer
			OPINION = 0
		}
		scope:victim = {
			add_opinion = {
				modifier = grateful_opinion
				target = root
				opinion = 25
			}
		}
		stress_impact = {
			vengeful = major_stress_impact_gain
			greedy = major_stress_impact_gain
			sadistic = medium_stress_impact_gain
			arbitrary = medium_stress_impact_gain
			callous = minor_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_greed = -1
				ai_honor = 0.75
				ai_vengefulness = -1
				ai_compassion = 0.75
			}
		}
	}
}

# Mirror event for victim
stewardship_wealth.7001 = {
	type = character_event
	title = stewardship_wealth.7001.t
	desc = {
		desc = stewardship_wealth.7001.desc
		# If the thieving rival made justifications for the seizure
		triggered_desc = {
			trigger = {
				scope:thieving_rival = {
					has_character_flag = made_theft_justifications
				}
			}
			desc = stewardship_wealth.7001.justification
		}
		# If the thieving rival has rampaging knights seizing more
		triggered_desc = {
			trigger = {
				scope:thieving_rival = {
					has_character_flag = unleashed_knights
				}
			}
			desc = stewardship_wealth.7001.unleashed_knights
		}
	}
	theme = unfriendly
	override_background = {
 		reference = relaxing_room
	}
	left_portrait = {
		character = scope:messenger
		animation = throne_room_bow_3
	}
	lower_right_portrait = scope:thieving_rival

	immediate = {
		show_as_tooltip = {
			add_prestige = minor_prestige_loss
			capital_county = {
				add_county_modifier = {
					modifier = stewardship_stolen_taxes_modifier
					years = 2
				}
			}
			progress_towards_rival_effect = {
				REASON = rival_stole_from_peasants_corresponding
				CHARACTER = scope:thieving_rival
				OPINION = 0
			}
		}
		create_character_memory = {
			type = abused_my_peasants
			participants = {
				thieving_rival = scope:thieving_rival
			}
		}
		if = {
			limit = {
				exists = cp:councillor_steward
				cp:councillor_steward = { is_available = yes }
			}
			cp:councillor_steward = { save_scope_as = messenger }
		}
		else_if = {
			limit = {
				exists = cp:councillor_marshal
				cp:councillor_marshal = { is_available = yes }
			}
			cp:councillor_marshal = { save_scope_as = messenger }
		}
		else_if = {
			limit = {
				exists = cp:councillor_chancellor
				cp:councillor_chancellor = { is_available = yes }
			}
			cp:councillor_chancellor = { save_scope_as = messenger }
		}
		else_if = {
			limit = {
				exists = cp:councillor_spymaster
				cp:councillor_spymaster = { is_available = yes }
			}
			cp:councillor_spymaster = { save_scope_as = messenger }
		}
		else_if = {
			limit = {
				exists = cp:councillor_court_chaplain
				cp:councillor_court_chaplain = { is_available = yes }
			}
			cp:councillor_court_chaplain = { save_scope_as = messenger }
		}
		else_if = {
			limit = {
				any_courtier = {
					is_available_healthy_ai_adult = yes
					trigger_if = {
						limit = {
							root.faith = { has_doctrine = doctrine_gender_male_dominated }
						}
						is_female = no
					}
					trigger_else = {
						is_female = yes
					}
				}
			}
			random_courtier = {
				limit = {
					is_available_healthy_ai_adult = yes
					trigger_if = {
						limit = {
							root.faith = { has_doctrine = doctrine_gender_male_dominated }
						}
						is_female = no
					}
					trigger_else = {
						is_female = yes
					}
				}
				save_scope_as = messenger
			}
		}
		else_if = {
			limit = {
				any_courtier = {
					is_available_ai_adult = yes
				}
			}
			random_courtier = {
				limit = {
					is_available_ai_adult = yes
				}
				save_scope_as = messenger
			}
		}
		else_if = {
			limit = {
				any_pool_character = {
					province = root.location
					is_available_healthy_ai_adult = yes
					trigger_if = {
						limit = {
							root.faith = { has_doctrine = doctrine_gender_male_dominated }
						}
						is_female = no
					}
					trigger_else = {
						is_female = yes
					}
				}
			}
			random_pool_character = {
				province = root.location
				limit = {
					is_available_healthy_ai_adult = yes
					trigger_if = {
						limit = {
							root.faith = { has_doctrine = doctrine_gender_male_dominated }
						}
						is_female = no
					}
					trigger_else = {
						is_female = yes
					}
				}
				save_scope_as = messenger
			}
		}
		else = {
			random_pool_character = {
				province = root.location
				limit = {
					is_available_ai_adult = yes
				}
				save_scope_as = messenger
			}
		}

		# This is a dire crime!
		scope:thieving_rival = {
			send_interface_toast = {
				title = stewardship_wealth.7001.tt.crime_alert
				right_icon = scope:victim
				reverse_add_opinion = {
					target = scope:victim
					modifier = theft_opinion
				}
			}
		}
	}

	# I still need my taxes!
	option = {
		name = stewardship_wealth.7001.a
		flavor = stewardship_wealth.7001.a.tt
		capital_county = {
			remove_county_modifier = stewardship_stolen_taxes_modifier
			change_development_progress_with_overflow = -20
		}
		add_character_modifier = {
			modifier = stewardship_tax_enforcement_modifier
			years = 5
		}
		stress_impact = {
			compassionate = major_stress_impact_gain
			just = major_stress_impact_gain
			generous = major_stress_impact_gain
			forgiving = medium_stress_impact_gain
			patient = minor_stress_impact_gain
		}
		ai_chance = {
			base = 30
			ai_value_modifier = {
				ai_greed = 1
				ai_honor = -1
				ai_compassion = -1
				ai_rationality = -0.5
				ai_energy = 0.25
			}
			modifier = {
				has_trait = just
				add = -100
			}
			modifier = {
				has_trait = compassionate
				add = -100
			}
			modifier = {
				has_trait = generous
				add = -100
			}
		}
	}

	# I won't make my people suffer
	option = {
		name = stewardship_wealth.7001.b
		flavor = stewardship_wealth.7001.b.tt
		add_character_modifier = {
			modifier = stewardship_tax_exemption_modifier
			years = 5
		}
		stress_impact = {
			stubborn = major_stress_impact_gain
			greedy = major_stress_impact_gain
			arbitrary = major_stress_impact_gain
			arrogant = medium_stress_impact_gain
			sadistic = medium_stress_impact_gain
			fickle = medium_stress_impact_gain
			callous = minor_stress_impact_gain
			eccentric = minor_stress_impact_gain
		}
		ai_chance = {
			base = 30
			ai_value_modifier = {
				ai_greed = -1
				ai_honor = 0.75
				ai_compassion = 1
				ai_energy = -0.25
				ai_boldness = -0.25
			}
			modifier = {
				has_trait = arbitrary
				add = -100
			}
			modifier = {
				has_trait = stubborn
				add = -100
			}
			modifier = {
				has_trait = arbitrary
				add = -100
			}
		}
	}
}

##########################################
# Weighting Opportunities
# by Krzysztof Lankowski
# 2000
##########################################

#ways to increase gold gain from capital county, mostly by embezzling the local trade
stewardship_wealth.2000 = {
	type = character_event
	title = stewardship_wealth.2000.t
	desc = stewardship_wealth.2000.desc

	theme = stewardship_duty_focus
	override_background = { reference = market }

	left_portrait = {
		character = root
		animation = thinking
	}

	right_portrait = {
		character = cp:councillor_steward
		animation = personality_greedy
	}

	immediate = {
		capital_county = {
			save_scope_as = loc_capital_county
		}
		cp:councillor_steward = {
			save_scope_as = loc_steward
		}
	}

	cooldown = { years = 10 }

	trigger = {
		is_landed_or_landless_administrative = yes
		exists = cp:councillor_steward

		cp:councillor_steward = {
			NOT = {
				has_trait = just
				has_trait = honest
			}
		}
		current_gold_value < medium_gold_value
	}

	weight_multiplier = {
		base = 1
		upweight_for_focus_modifier = { FOCUS = stewardship_wealth_focus }

		modifier = {
			add = 0.25
			current_gold_value < 1
		}
	}

	option = { #yeah, go ahead, nobody will notice - intrigue check
		name = stewardship_wealth.2000.a

		duel = {
			skill = intrigue
			value = high_skill_rating

			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				custom_tooltip = stewardship_wealth.2000.a.tt.success
				send_interface_toast = {
					title = stewardship_wealth.2000.a.tt.success
					left_icon = capital_county

					capital_county = {
						add_county_modifier = {
							modifier = optimized_weighting_sucess
							years = 10
						}
					}
				}
			}

			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				custom_tooltip = stewardship_wealth.2000.a.tt.failure
				send_interface_toast = {
					title = stewardship_wealth.2000.a.tt.failure
					left_icon = capital_county

					capital_county = {
						add_county_modifier = {
								modifier = optimized_weighting_failure
								years = 10
							}
					}
				}
			}
		}

		stress_impact = {
			greedy = medium_stress_impact_loss
			deceitful = minor_stress_impact_loss
			just = medium_stress_impact_gain
			honest = medium_stress_impact_gain
		}

		ai_chance = {
			base = 50
			ai_value_modifier = { 
				ai_greed = tiny_chance_impact_positive_ai_value 
			}
			ai_value_modifier = {
				ai_honor = tiny_chance_impact_negative_ai_value
			}
		}

	}

	option = { #we need a better system - stewardship check, less penalty if lost
		name = stewardship_wealth.2000.b
		flavor = stewardship_wealth.2000.b.tt
		duel = {
			skill = stewardship
			value = high_skill_rating

			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				custom_tooltip = stewardship_wealth.2000.b.tt.success
				send_interface_toast = {
					title = stewardship_wealth.2000.b.tt.success
					left_icon = capital_county
					capital_county = {
						add_county_modifier = {
							modifier = new_weighting_system
							years = 10
						}
					}
				}
				add_stewardship_lifestyle_xp = medium_lifestyle_experience
			}

			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				custom_tooltip = stewardship_wealth.2000.b.tt.failure
				send_interface_toast = {
					title = stewardship_wealth.2000.b.tt.failure
					add_prestige = medium_prestige_loss
					add_stewardship_lifestyle_xp = minor_lifestyle_experience
				}
			}
		}

		stress_impact = {
			ambitious = minor_stress_impact_loss
			diligent = minor_stress_impact_loss
			greedy = medium_stress_impact_gain
		}

		ai_chance = {
			base = 75
			ai_value_modifier = { 
				ai_rationality = tiny_chance_impact_positive_ai_value 
			}
			ai_value_modifier = { 
				ai_greed = tiny_chance_impact_negative_ai_value 
			}
		}
	}

	option = { #squeeze money in old fashioned way - straigthforward gold gain
		name = stewardship_wealth.2000.c

		flavor = stewardship_wealth.2000.c.tt
		add_gold = medium_gold_value
		add_tyranny = medium_tyranny_gain

		stress_impact = {
			arbitrary = minor_stress_impact_loss
			impatient = minor_stress_impact_loss
			just = medium_stress_impact_gain
		}

		ai_chance = {
			base = 0
			ai_value_modifier = { 
				ai_boldness = tiny_chance_impact_positive_ai_value 
			}
			ai_value_modifier = { 
				ai_greed = tiny_chance_impact_positive_ai_value 
			}
			ai_value_modifier = {
				ai_honor = tiny_chance_impact_negative_ai_value
			}
		}
	}
}

###########################################################
# Events converted from the old Progress Event system.
# These events are all challenging event chains which should reward a perk point or some other significant benefit for successfully completing them.

namespace = stewardship_wealth_special
