﻿### EK NOTE: Added our character creation effects

namespace = stewardship_general

# Normal Events
	#1054		- Accusations of Witchcraft, by Sean Hughes
	#2001 		- Visited by a Peddler, by Filippa Gannholm
	#5011 		- Fish pond!, by Linnéa Thimrén
	#5041 		- Servant caught stealing from the household, by Linnéa Thimrén

##########################################
# Accusations of Witchcraft
# by Sean Hughes
# 1054
##########################################

stewardship_general.1054 = {
	type = character_event
	title = stewardship_general.1054.t
	desc = stewardship_general.1054.desc
	
	theme = stewardship
	override_background = {
		reference = gallows
	}
	left_portrait = {
		character = root
		animation = interested_left
	}
	right_portrait = {
		character = scope:witch
		animation = beg
	}
	
	trigger = {
		faith = {
			NOT = { has_doctrine_parameter = witchcraft_accepted }
		}
		NOT = { has_character_flag = had_event_stewardship_strategist054 }
		any_held_title = {
			tier = tier_county
		}
		exists = root.capital_province
	}

	weight_multiplier = {
		base = 0.5

		modifier = {
			add = 1
			faith = {
				has_doctrine_parameter = witchcraft_illegal
			}
		}
		modifier = { #Since it creates such a GOOD character we don't want the ai to get it too often
			add = -0.9
			is_ai = yes
		}	
	}

	immediate = {
		add_character_flag = {
			flag = had_event_stewardship_strategist054
			years = 10
		}
		add_character_flag = {
			flag = had_recent_lifestyle_ongoing_event
			years = ongoing_lifestyle_event_delay
		}
		#Find one of our owned counties.
		random_held_title = {
			limit = {
				tier = tier_county
			}

			#Save the scope.
			save_scope_as = target_county

			#Create a witch/sorcerer from the province.
			random_dummy_gender_mystic_effect = yes
			#Several possible archetypes can be generated.
			hidden_effect = {
				random_list = {
					33 = {
						#Beguilling young woman/man
						create_character = {
							location = root.capital_province
							age = { 16 25 }
							gender = scope:dummy_mystic_gender
							trait = education_diplomacy_2
							trait = beauty_good_2
							trait = lifestyle_mystic
							faith = this.faith
							culture = this.culture
							diplomacy = { 10 12 }
							learning = { 8 10 }
							#EK EDIT
							after_creation = {
								ek_character_setup_effect = yes
							}
							#EK EDIT END
							save_scope_as = witch
						}
					}
					33 = {
						#Wise old woman/man
						create_character = {
							location = root.capital_province
							age = { 55 65 }
							gender = scope:dummy_mystic_gender
							trait = education_learning_3
							trait = lifestyle_mystic
							trait = shrewd
							faith = root.faith
							culture = root.culture
							learning = { 12 14 }
							#EK EDIT
							after_creation = {
								ek_character_setup_effect = yes
							}
							#EK EDIT END
							save_scope_as = witch
						}
					}
					33 = {
						#Eccentric hermit
						create_character = {
							location = root.capital_province
							age = { 35 45 }
							gender = scope:dummy_mystic_gender
							trait = education_learning_2
							trait = shy
							trait = lunatic_1
							trait = intellect_good_3
							faith = root.faith
							culture = root.culture
							learning = { 10 12 }
							diplomacy = { 2 4 }
							martial = { 6 8 }
							intrigue = { 4 6 }
							stewardship = { 6 8 }
							#EK EDIT
							after_creation = {
								ek_character_setup_effect = yes
							}
							#EK EDIT END
							save_scope_as = witch
						}
					}
				}
				scope:witch = {
					add_random_tiered_trait_xp_effect = {
						TRAIT = lifestyle_mystic
						LEVEL_1 = no
						LEVEL_3 = yes
					}
				}
			}
		}
	}

	# Option A: Evidence is circumstantial, release them!
	option = {
		name = stewardship_general.1054.a

		#Gain focus progress.
			add_stewardship_lifestyle_xp = major_lifestyle_experience

		#Witch disappears after the event.
		hidden_effect = {
			scope:witch = {
				death = {
					death_reason = death_disappearance
				}
			}
		}

		# County dislikes the holder.
		scope:target_county = {
			add_county_modifier = {
				modifier = governance_1054_upset_peasants_modifier
				years = 5
			}
		}

		stress_impact = {
			zealous = medium_stress_impact_gain
			sadistic = minor_stress_impact_gain
			vengeful = minor_stress_impact_gain
		}
		ai_chance = {
			base = 50

			ai_value_modifier = {
				ai_honor = 100
				ai_compassion = 100
				ai_zeal = -200
			}
		}
	}

	# Option B: Execute the witch by burning
	option = {
		name = stewardship_general.1054.b

		#Witch killed by the event.
		scope:witch = {
			death = {
				death_reason = death_execution
				killer = root
			}
		}

		#Gain piety for publicly executing the witch.
		add_piety = medium_piety_gain

		# County approves of the execution.
		scope:target_county = {
			add_county_modifier = {
				modifier = governance_1054_satisfied_peasants_modifier
				years = 5
			}
		}

		stress_impact = {
			just = medium_stress_impact_gain
			forgiving = medium_stress_impact_gain
			cynical = minor_stress_impact_gain
			compassionate = minor_stress_impact_gain
		}
		ai_chance = {
			base = 50

			ai_value_modifier = {
				ai_compassion = -100
				ai_honor = 100
				ai_zeal = 500
			}
		}
	}
	
	# Option C: Recruit the witch into your court.
	option = {
		name = stewardship_general.1054.c

		# Lose piety for openly recruiting a witch.
		add_piety = medium_piety_loss

		#Witch joins your court and is grateful to you for saving their life.
		add_courtier = scope:witch
		reverse_add_opinion = {
			modifier = grateful_opinion
			target = scope:witch
			opinion = 50
		}

		# The witch has a chance to gain a witch secret
		hidden_effect = {
			random_list = {
				25 = {
					scope:witch = {
						add_secret = {
							type = secret_witch
						}
					}	
				}
				75 = {
					# Nothing Happens
				}
			}
		}

		# County dislikes the holder.
		scope:target_county = {
			add_county_modifier = {
				modifier = governance_1054_upset_peasants_modifier
				years = 5
			}
		}

		stress_impact = {
			zealous = major_stress_impact_gain
			paranoid = medium_stress_impact_gain
		}
		ai_chance = {
			base = 50

			ai_value_modifier = {
				ai_honor = -300
				ai_zeal = -500
				ai_compassion = 200
				ai_greed = 200
			}
		}
	}

	# Option D (Special): Secretly recruit the witch to your court while pretending to kill them.
	option = {
		name = stewardship_general.1054.d
		flavor = stewardship_general.1054.d.flavor
		trigger = {
			intrigue >= very_high_skill_rating
		}
		skill = intrigue

		add_piety = medium_piety_gain

		#Witch joins your court and is grateful to you for saving their life.
		add_courtier = scope:witch
		reverse_add_opinion = {
			modifier = grateful_opinion
			target = scope:witch
			opinion = 50
		}

		# The witch has a chance to gain a witch secret
		hidden_effect = {
			random_list = {
				25 = {
					scope:witch = {
						add_secret = {
							type = secret_witch
						}
					}	
				}
				75 = {
					# Nothing Happens
				}
			}
		}

		# County approves of the 'execution'.
		scope:target_county = {
			add_county_modifier = {
				modifier = governance_1054_satisfied_peasants_modifier
				years = 5
			}
		}

		stress_impact = {
			zealous = major_stress_impact_gain
			paranoid = medium_stress_impact_gain
			honest = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100

			ai_value_modifier = {
				ai_honor = -300
				ai_zeal = -500
				ai_compassion = 200
				ai_greed = 500
			}
		}
	}
}

##########################################
# Visited by a Peddler
# by Filippa Gannholm
# 2001
##########################################
#	A salesperson turns up at your doorstep peddling shiny trinkets and baubles. Do you have the stewardship skill to land a good quality trinket?

scripted_effect stewardship_general_2001_free_outcome = {
	#If we got help, the councillor is not impressed/insulted
	if = {
		limit = {
			exists = scope:helpful_councillor
			has_character_flag = helpful_option_stewardship_general.2001
		}
		send_interface_toast = {
			type = event_toast_text_and_effect_good 
			left_icon = root
			right_icon = scope:helpful_councillor
			title = stewardship_general_2001_success_msg.t
			desc = stewardship_general_2001_free_msg.desc

			add_stewardship_lifestyle_xp = medium_lifestyle_experience	
		}
	}
	#But if we didn't get help, they are impressed
	else_if = {
		limit = { 
			exists = scope:helpful_councillor
			scope:helpful_councillor = { has_council_position = councillor_steward }
		}
		send_interface_toast = {
			type = event_toast_text_and_effect_good 
			left_icon = root
			right_icon = scope:helpful_councillor
			title = stewardship_general_2001_success_msg.t
			desc = stewardship_general_2001_free_msg.desc

			add_stewardship_lifestyle_xp = medium_lifestyle_experience	
		}
		#Setup for the follow-up event
		##Our steward is impressed with our haggling skillz	
		add_character_flag = { flag = very_impressed_councillor_stewardship_general.2001 }
	}
	#If the councillor doesn't exist, they can't get impressed/insulted
	else = {
		send_interface_toast = {
			type = event_toast_text_and_effect_good 
			left_icon = root
			title = stewardship_general_2001_success_msg.t
			desc = stewardship_general_2001_free_msg.desc

			add_stewardship_lifestyle_xp = medium_lifestyle_experience
		}
	}
	add_character_flag = {
		flag = free_outcome_stewardship_general.2001
	}
}

scripted_effect stewardship_general_2001_tiny_outcome = {
	#If we got help, the councillor is not impressed/insulted
	if = { 
		limit = { 
			exists = scope:helpful_councillor
			has_character_flag = helpful_option_stewardship_general.2001
		}
		send_interface_toast = {
			type = event_toast_text_and_effect_good 
			left_icon = root
			right_icon = scope:helpful_councillor
			title = stewardship_general_2001_success_msg.t
			desc = stewardship_general_2001_tiny_msg.desc

			remove_short_term_gold = tiny_gold_value
			add_stewardship_lifestyle_xp = minor_lifestyle_experience	
		}
	}
	#But if we didn't get help, they are impressed
	else_if = {
		limit = { 
			exists = scope:helpful_councillor
			scope:helpful_councillor = { has_council_position = councillor_steward }
		}
		send_interface_toast = {
			type = event_toast_text_and_effect_good 
			left_icon = root
			right_icon = scope:helpful_councillor
			title = stewardship_general_2001_success_msg.t
			desc = stewardship_general_2001_tiny_msg.desc

			remove_short_term_gold = tiny_gold_value
			add_stewardship_lifestyle_xp = minor_lifestyle_experience	
		}
		#Setup for the follow-up event
		##Our steward is impressed with our haggling skillz
		add_character_flag = { flag = impressed_councillor_stewardship_general.2001 }
	}
	#If the councillor doesn't exist, they can't get impressed/insulted
	else = {
		send_interface_toast = {
			type = event_toast_text_and_effect_good 
			left_icon = root
			title = stewardship_general_2001_success_msg.t
			desc = stewardship_general_2001_tiny_msg.desc

			remove_short_term_gold = tiny_gold_value
			add_stewardship_lifestyle_xp = minor_lifestyle_experience
		}
	}
}

scripted_effect stewardship_general_2001_minor_outcome = {
	#If we got help, the councillor is not impressed/insulted
	if = {
		limit = { 
			has_character_flag = helpful_option_stewardship_general.2001
			exists = scope:helpful_councillor
		}
		send_interface_toast = {
			type = event_toast_text_and_effect_bad
			left_icon = root
			right_icon = scope:helpful_councillor
			title = stewardship_general_2001_failure_msg.t
			desc = stewardship_general_2001_minor_msg.desc

			remove_short_term_gold = minor_gold_value
		}
	}
	#But if we didn't get help, they are insulted
	else_if = {
		limit = { exists = scope:helpful_councillor }
		send_interface_toast = {
			type = event_toast_text_and_effect_bad
			left_icon = root
			right_icon = scope:helpful_councillor
			title = stewardship_general_2001_failure_msg.t
			desc = stewardship_general_2001_minor_msg.desc

			remove_short_term_gold = minor_gold_value
		}
		#Setup for the follow-up event
		##Our steward/chaplain is insulted that we didn't listen to them AND failed at haggling
		add_character_flag = { flag = insulted_councillor_stewardship_general.2001 }
	}
	#If the councillor doesn't exist, they can't get impressed/insulted
	else = {
		send_interface_toast = {
			type = event_toast_text_and_effect_bad
			left_icon = root
			title = stewardship_general_2001_failure_msg.t
			desc = stewardship_general_2001_minor_msg.desc

			remove_short_term_gold = minor_gold_value
		}
	}
}

scripted_effect stewardship_general_2001_expensive_outcome = {
	#If we got help, the councillor is not impressed/insulted
	if = { 
		limit = { 
			has_character_flag = helpful_option_stewardship_general.2001
			exists = scope:helpful_councillor 
		}
		send_interface_toast = {
			type = event_toast_text_and_effect_bad
			left_icon = root
			right_icon = scope:helpful_councillor
			title = stewardship_general_2001_failure_msg.t
			desc = stewardship_general_2001_expensive_msg.desc

			remove_short_term_gold = medium_gold_value
		}
	}
	#But if we didn't get help, they are insulted
	else_if = {
		limit = { exists = scope:helpful_councillor }
		send_interface_toast = {
			type = event_toast_text_and_effect_bad
			left_icon = root
			right_icon = scope:helpful_councillor
			title = stewardship_general_2001_failure_msg.t
			desc = stewardship_general_2001_expensive_msg.desc

			remove_short_term_gold = medium_gold_value
		}
		#Setup for the follow-up event
		##Our steward/chaplain is insulted that we didn't listen to them AND failed at haggling
		add_character_flag = { flag = very_insulted_councillor_stewardship_general.2001 }
	}
	else = {
	#If the councillor doesn't exist, they can't get impressed/insulted
		send_interface_toast = {
			type = event_toast_text_and_effect_bad
			left_icon = root
			title = stewardship_general_2001_failure_msg.t
			desc = stewardship_general_2001_expensive_msg.desc

			remove_short_term_gold = medium_gold_value
		}
	}
}

stewardship_general.2001 = {
	type = character_event
	title = stewardship_general.2001.t
	desc = {
		desc = stewardship_general.2001.desc_intro
		first_valid = { 
			#Steward flavor
			triggered_desc = {
				trigger = { 
						exists = scope:helpful_councillor
						scope:helpful_councillor = { has_council_position = councillor_steward }
					}
				desc = stewardship_general.2001.desc_steward
			}
			#Chaplain flavor
			triggered_desc = {
				trigger = { 
						exists = scope:helpful_councillor
						scope:helpful_councillor = { has_council_position = councillor_court_chaplain }
					}
				desc = stewardship_general.2001.desc_chaplain
			}
			#Decent stewardship skill flavor
			triggered_desc = {
				trigger = { 
					NOT = { exists = scope:helpful_councillor }
					stewardship >= decent_skill_rating 
				}
				desc = stewardship_general.2001.desc_high_skill
			}
			#Fallback
			desc = stewardship_general.2001.desc
		}
	}
	theme = stewardship
	override_background = {
		reference = market
	}
	left_portrait = {
		character = root
		#Add some flavor if we're greedy and prone to anger
		triggered_animation = {
			trigger = { 
				has_trait = greedy
				OR = {
					has_trait = wrathful
					has_trait = irritable
					has_trait = impatient
				}
			}
  			animation = disapproval
  		}
  		#Otherwise default to
		animation = worry
	}
	right_portrait = {
		character = scope:peddler
		animation = flirtation
	}
	#Let's include our steward/chaplain if they match the criteria
	lower_center_portrait = {
		trigger = { exists = scope:helpful_councillor }
		character = scope:helpful_councillor
		animation = admiration	
	}
	#Standard checks
	trigger = {
		is_available_adult = yes
		is_playable_character = yes
		NOT = {
			government_has_flag = government_is_nomadic
		}
	}
	#Set up our cooldowns
	cooldown = { years = 10 }

	weight_multiplier = {
		base = 1
		#More likely if you're a human player with few items in your inventory
		modifier = {
			factor = 1.5
			any_character_artifact = { count < 10 }
			is_ai = no
		}
		#Let's not bloat the AI with these trinkets
		modifier = {
			factor = 0.5
			is_ai = yes
		}
	}
	immediate = {
		#Standard flags
		add_character_flag = {
			flag = had_recent_lifestyle_ongoing_event
			years = ongoing_lifestyle_event_delay
		}
		#Set up scopes
		random_pool_character = {
			province = root.capital_province
			limit = {
				stewardship >= decent_skill_rating
				has_trait = greedy
				has_dynasty = no
				is_available_adult = yes
			}
			alternative_limit = {
				stewardship >= decent_skill_rating
				is_available_adult = yes
			}
			save_scope_as = peddler
		}
		#If there's no suitable peddler, let's create one
		if = {
			limit = {
				NOT = { exists = scope:peddler }
			}
			create_character = {
				location = root.capital_province
				template = merchant_template
				trait = greedy
				save_scope_as = peddler
			}
			scope:peddler = {
				add_character_flag = { flag = is_created_character_stewardship_general.2001 }
			}
		}
		#Our steward pitches in to help if we have a good enough relationship, they're nearby, and they have enough stewardship skill - they could help us out
		if = {										
			limit = {
  				exists = cp:councillor_steward
  				cp:councillor_steward = {
					opinion = {
						target = root
						value >= medium_positive_opinion
					}
					stewardship >= decent_skill_rating
					is_available_ai_adult = yes
				}
  			}
			cp:councillor_steward = { save_scope_as = helpful_councillor }
		}
		#If we don't have a suitable steward, but a good relationship with our learned chaplain and they're nearby - they might have heard something about one of the trinkets
		else_if = {
			limit = {
				NOT = { exists = scope:helpful_councillor }
				exists = cp:councillor_court_chaplain
				cp:councillor_court_chaplain = {
					opinion = {
						target = root
						value >= medium_positive_opinion
					}
					learning >= decent_skill_rating
					is_available_ai_adult = yes
				}
			}
			cp:councillor_court_chaplain = { save_scope_as = helpful_councillor }
		}
		#Add our stewardship together with their stewardship or learning
		hidden_effect = {
			if = {
				limit = { 
					exists = scope:helpful_councillor
					scope:helpful_councillor = { has_council_position = councillor_steward }
				}
				save_scope_value_as = {
					name = stewardship_value
					value = {
						value = stewardship
						add = scope:helpful_councillor.stewardship
					}
				}
				#Setting this up for the trinket generation
				add_character_flag = { flag = has_helpful_steward_stewardship_general.2001 }
			}
			else_if = {
				limit = { 
					exists = scope:helpful_councillor
					scope:helpful_councillor = { has_council_position = councillor_court_chaplain }
				}
				save_scope_value_as = {
					name = stewardship_value
					value = {
						value = stewardship
						add = scope:helpful_councillor.learning
					}
				}
				#Setting this up for the trinket generation
				add_character_flag = { flag = has_helpful_chaplain_stewardship_general.2001 }
			}
			else = {
				save_scope_value_as = {
					name = stewardship_value
					value = stewardship
				}
			}
		}
		#If we have enough cumulated stewardship, let's flag ourselves
		if = {
			limit = { scope:stewardship_value >= extremely_high_skill_rating }	#20~
			add_character_flag = has_extremely_high_stewardship_skill_stewardship_general.2001
		}
	}

	#I'll pick my own CHEAP trinket
	option = {
		name = {
			text = {
				first_valid = {
					triggered_desc = {
						trigger = { exists = scope:helpful_councillor }
						desc = stewardship_general.2001.a.ignore_help
					}
					#Fallback
					triggered_desc = {
						desc = stewardship_general.2001.a
					}
				}
			}
		}
		#If we're greedy, we get a lil' bit of stress for wasting gold on a trinket
		stress_impact = {
			greedy = miniscule_stress_impact_gain
			arbitrary = miniscule_stress_impact_loss
		}
		duel = {
			skill = stewardship
			target = scope:peddler
			localization = stewardship_haggle_cheap_trinket_tt
			
			#Free
			2 = {		
				compare_modifier = {
					value = scope:duel_value
					multiplier = 2
					min = 1
				}
				desc = stewardship_general.2001.free
				stewardship_general_2001_free_outcome = yes
			}
			#Tiny cost
			4 = {		
				compare_modifier = {
					value = scope:duel_value
					multiplier = 2
					min = 1
				}
				desc = stewardship_general.2001.tiny_cost
				stewardship_general_2001_tiny_outcome = yes	
			}
			#Expensive cost
			2 = {		
				compare_modifier = {
					value = scope:duel_value
					multiplier = 1
					min = 1
				}
				desc = stewardship_general.2001.expensive_cost
				stewardship_general_2001_expensive_outcome = yes				
			}
		}
		add_character_flag = { flag = cheap_option_stewardship_general.2001 }
		ai_chance = {
			base = 75
			compare_modifier = {
				trigger = {
					ai_rationality >= 10
				}
				value = {
					value = stewardship
					add = -10
				}
				multiplier = 1000 # -10,000 at 0 Stewardship, +0 at 10 Stewardship, +10,000 at 20 Stewardship
			}
			ai_value_modifier = {
				ai_rationality = medium_chance_impact_positive_ai_value
				ai_greed = low_chance_impact_positive_ai_value
			}
		}
	}
	#I'll pick my own EXPENSIVE trinket
	option = {
		name = {
			text = {
				first_valid = {
					triggered_desc = {
						trigger = { exists = scope:helpful_councillor }
						desc = stewardship_general.2001.b.ignore_help
					}
					#Fallback
					triggered_desc = {
						desc = stewardship_general.2001.b
					}
				}
			}
		}
		trigger = {
			#Only available if we have high stewardship skill
			stewardship >= decent_skill_rating
		}
		#If we're greedy, we get a lil' bit of stress for wasting gold on a trinket
		stress_impact = {
			greedy = minor_stress_impact_gain
			arbitrary = miniscule_stress_impact_loss
		}
		duel = {
			skill = stewardship
			target = scope:peddler
			localization = stewardship_haggle_expensive_trinket_tt
			
			#Tiny cost
			3 = {		
				compare_modifier = {
					value = scope:duel_value
					multiplier = 2
					min = 1
				}
				desc = stewardship_general.2001.tiny_cost
				stewardship_general_2001_tiny_outcome = yes
			}
			#Minor cost
			5 = {		
				compare_modifier = {
					value = scope:duel_value
					multiplier = 1
					min = 1
				}
				desc = stewardship_general.2001.minor_cost
				stewardship_general_2001_minor_outcome = yes				
			}
		}
		add_character_flag = { flag = expensive_option_stewardship_general.2001 }
		ai_chance = {
			base = 75
			compare_modifier = {
				trigger = {
					ai_rationality >= 10
				}
				value = {
					value = stewardship
					add = -10
				}
				multiplier = 1000 # -10,000 at 0 Stewardship, +0 at 10 Stewardship, +10,000 at 20 Stewardship
			}
			ai_value_modifier = {
				ai_rationality = medium_chance_impact_positive_ai_value
				ai_greed = low_chance_impact_positive_ai_value
			}
		}
	}
	#I guess I'll listen to my steward/chaplain
	option = {
		trigger = { 
			exists = scope:helpful_councillor
		}
		name = {
			text = {
				first_valid = {
					#Steward description
					triggered_desc = {
						trigger = { 
							exists = scope:helpful_councillor
							scope:helpful_councillor = { has_council_position = councillor_steward }
						}
						desc = stewardship_general.2001.c.steward
					}
					#Chaplain description
					triggered_desc = {
						trigger = { 
							exists = scope:helpful_councillor
							scope:helpful_councillor = { has_council_position = councillor_court_chaplain }
						}
						desc = stewardship_general.2001.c.chaplain
					}
				}
			}
		}
		#If we're greedy, we get a lil' bit of stress for wasting gold on a trinket
		stress_impact = {
			greedy = miniscule_stress_impact_gain
		}
		#Flag to determine if you listened to the councillor or not
		add_character_flag = { flag = helpful_option_stewardship_general.2001 }
		#Let's Steward it out!
		duel = {
			skill = stewardship
			target = scope:peddler
			localization = stewardship_haggle_helpful_trinket_tt
		
			#Free
			3 = {		
				compare_modifier = {
					value = scope:duel_value
					multiplier = 2
					min = 1
				}
				desc = stewardship_general.2001.free
				stewardship_general_2001_free_outcome = yes	
			}
			#Tiny cost
			3 = {		
				compare_modifier = {
					value = scope:duel_value
					multiplier = 2
					min = 1
				}
				desc = stewardship_general.2001.tiny_cost
				stewardship_general_2001_tiny_outcome = yes	
			}
			#Minor cost
			1 = {		
				compare_modifier = {
					value = scope:duel_value
					multiplier = 0.5
					min = 1
				}
				desc = stewardship_general.2001.minor_cost
				stewardship_general_2001_minor_outcome = yes
			}
		}
		ai_chance = {
			base = 100
			compare_modifier = {
				trigger = {
					ai_rationality >= 10
				}
				value = {
					value = stewardship
					add = -10
				}
				multiplier = 1000 # -10,000 at 0 Stewardship, +0 at 10 Stewardship, +10,000 at 20 Stewardship
			}
			ai_value_modifier = {
				ai_rationality = medium_chance_impact_positive_ai_value
				ai_greed = low_chance_impact_positive_ai_value
			}
		}
	}
	#Not interested
	option = {
		name = {
			text = {
				first_valid = {
					#Add some flavor if we're greedy and prone to anger
					triggered_desc = {
						trigger = { 
							has_trait = greedy
							OR = {
								has_trait = wrathful
								has_trait = irritable
								has_trait = impatient
							}
						}
						desc = stewardship_general.2001.d.irritable
					}
					#Fallback
					triggered_desc = {
						desc = stewardship_general.2001.d
					}
				}
			}
		}
		#Phew, we didn't spend anything!
		stress_impact = {
			greedy = miniscule_stress_impact_loss
		}
		if = { 
			limit = { 
				has_trait = greedy
				OR = {
					has_trait = wrathful
					has_trait = irritable
					has_trait = impatient
				}
			}
			reverse_add_opinion = { 
				target = scope:peddler
				modifier = scared_opinion
				opinion = -20
			}
		}
		else = {
			reverse_add_opinion = { 
				target = scope:peddler
				modifier = dismissive_opinion
				opinion = -10
			}
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = medium_chance_impact_positive_ai_value
			}
		}
	}
	after = { 
		hidden_effect = {
			#Don't want to flood the character pool with newly created peddlers
			scope:peddler = {
				if = {
					limit = {
						has_character_flag = is_created_character_stewardship_general.2001
					}
					death = { death_reason = death_vanished }
				}
			}
			#Let's make you the owner of your new artifact!
			if = { 
				limit = { 
					OR = { 
						has_character_flag = cheap_option_stewardship_general.2001
						has_character_flag = expensive_option_stewardship_general.2001
						has_character_flag = helpful_option_stewardship_general.2001 
					}
				}
				#Set up for the generate_trinket_effect
				add_character_flag = { flag = used_in_stewardship_general.2001 }
				if = { 
					limit = { learning <= decent_skill_rating }
					add_character_flag = { flag = less_than_decent_learning_stewardship_general.2001 }
				}
				#Generate a trinket
				generate_trinket_effect = {
					TRINKET_RECEIVER = root
					TRINKET_GIVER = scope:peddler
					GRAB_ALL_TRINKETS = no
					HISTORY_TYPE = given_unknown
				}
				#Inform the player about their new trinket!
				send_interface_toast = {
					title = stewardship_general.2001.tt
					left_icon = scope:new_trinket
					show_as_tooltip = {
						scope:new_trinket = { set_owner = root }
					}
				}
				#Clean up the flags
				remove_character_flag = cheap_option_stewardship_general.2001
				remove_character_flag = expensive_option_stewardship_general.2001
				remove_character_flag = helpful_option_stewardship_general.2001
				remove_character_flag = has_extremely_high_stewardship_skill_stewardship_general.2001
				remove_character_flag = has_helpful_steward_stewardship_general.2001
				remove_character_flag = has_helpful_chaplain_stewardship_general.2001
				remove_character_flag = free_outcome_stewardship_general.2001
				remove_character_flag = used_in_stewardship_general.2001
				remove_character_flag = less_than_decent_learning_stewardship_general.2001
			}
			if = {
				limit = { 
					OR = { 
						has_character_flag = impressed_councillor_stewardship_general.2001
						has_character_flag = very_impressed_councillor_stewardship_general.2001
						has_character_flag = insulted_councillor_stewardship_general.2001
						has_character_flag = very_insulted_councillor_stewardship_general.2001
					}
					is_ai = no
				}
				scope:new_trinket = {
					set_variable = peddler_trinket
				}
				trigger_event = { id = stewardship_general.2002 }
			}
		}
	}
}


scripted_effect apply_impressivity_effect = {
	#Very Impressed
	if = {
		limit = { has_character_flag = impressed_councillor_stewardship_general.2001 }
		reverse_add_opinion = { 
			target = scope:helpful_councillor
			modifier = impressed_opinion
			opinion = 10
		}
	}
	#Impressed
	else_if = {
		limit = { has_character_flag = very_impressed_councillor_stewardship_general.2001 }
		reverse_add_opinion = { 
			target = scope:helpful_councillor
			modifier = impressed_opinion
			opinion = 20
		}
	}
	#Insulted
	else_if = {
		limit = { has_character_flag = insulted_councillor_stewardship_general.2001 }
		#We don't like people disliking us
		stress_impact = {
			gregarious = miniscule_stress_impact_gain
		}
		reverse_add_opinion = { 
			target = scope:helpful_councillor
			modifier = dismissed_me_opinion
			opinion = -10
		}
	}
	#Very Insulted
	else = {
		#We don't like people disliking us
		stress_impact = {
			gregarious = minor_stress_impact_gain
		}
		reverse_add_opinion = { 
			target = scope:helpful_councillor
			modifier = dismissed_me_opinion
			opinion = -20
		}
	}
}

#Follow-up to handle the helpful councillor's feelings
stewardship_general.2002 = {
	type = character_event
	title = {
		first_valid = {
			triggered_desc = {
				trigger = { 
					OR = { 
						has_character_flag = insulted_councillor_stewardship_general.2001
						has_character_flag = very_insulted_councillor_stewardship_general.2001 
					}
				}
				desc = stewardship_general.2002.t_insulting
			}
			triggered_desc = {
				desc = stewardship_general.2002.t
			}
		}
	}
	desc = {
		desc = stewardship_general.2002.desc.intro
		first_valid = {
			#Steward flavor impressed
			triggered_desc = {
				trigger = { 
						has_character_flag = impressed_councillor_stewardship_general.2001
					}
				desc = stewardship_general.2002.desc_impressed
			}
			#Steward flavor very impressed
			triggered_desc = {
				trigger = { 
						has_character_flag = very_impressed_councillor_stewardship_general.2001
					}
				desc = stewardship_general.2002.desc_very_impressed
			}
			#Councillor flavor insulted
			triggered_desc = {
				trigger = { 
						has_character_flag = insulted_councillor_stewardship_general.2001
					}
				desc = stewardship_general.2002.desc_insulted
			}
			#Councillor flavor very insulted
			triggered_desc = {
				trigger = { 
						has_character_flag = very_insulted_councillor_stewardship_general.2001
					}
				desc = stewardship_general.2002.desc_very_insulted
			}
		}
	}
	theme = stewardship
	override_background = {
		reference = market
	}
	left_portrait = {
		character = root
		#Add some flavor if they are insulted and we're annoyable
		triggered_animation = {
			trigger = {
				AND = {
					OR = {
						has_character_flag = insulted_councillor_stewardship_general.2001
						has_character_flag = very_insulted_councillor_stewardship_general.2001
					}
					OR = {
						has_trait = wrathful
						has_trait = irritable
						has_trait = impatient
					}
				}
			}
  			animation = boredom
  		}
  		#And some flavor if they're impressed and we're not humble or shy
  		triggered_animation = {
  			trigger = {
  				OR = {
					has_character_flag = impressed_councillor_stewardship_general.2001
					has_character_flag = very_impressed_councillor_stewardship_general.2001
				}
				NOR = {
					has_trait = humble
					has_trait = shy
				}
  			}
  			animation = schadenfreude
  		}
  		#Otherwise default to
		animation = shame
	}
	right_portrait = {
		character = scope:helpful_councillor
		#We're insulted
		triggered_animation = {
			trigger = { has_character_flag = insulted_councillor }
  			animation = disapproval
  		}
  		#Otherwise we're impressed
		animation = happiness
	}
	#Let's showcase our pièce de résistance (as it were...)
	artifact = {
		target = scope:bought_trinket
		position = lower_center_portrait
	}

	immediate = {
	#We need to find our bought trinket in our inventory
		random_character_artifact = { 
			limit = { has_variable = peddler_trinket }
			save_scope_as = bought_trinket
		}
		#Want to setup our animation appropriately
		if = {
			limit = { 
				OR = {
					has_character_flag = insulted_councillor_stewardship_general.2001
					has_character_flag = very_insulted_councillor_stewardship_general.2001
				}
			}
			scope:helpful_councillor = {
				add_character_flag = insulted_councillor
			}
		}
	}
	
	#Teach them a thing or two about Stewardship
	option = {
		name = stewardship_general.2002.a.high_stewardship
		#Trigger if impressed and high stewardship
		trigger = { 
			stewardship >= decent_skill_rating
			OR = {
				has_character_flag = impressed_councillor_stewardship_general.2001
				has_character_flag = very_impressed_councillor_stewardship_general.2001
			}
		}
		#If we're humble or shy, this is stressful - but if we like it, it's soothing
		stress_impact = {
			humble = miniscule_stress_impact_gain
			shy = miniscule_stress_impact_gain
			arrogant = miniscule_stress_impact_loss
			ambitious = miniscule_stress_impact_loss
		}
		duel = {
			skill = stewardship
			value = 10
			#You talk bartering strategies
			5 = {		
				compare_modifier = {
					value = scope:duel_value
					multiplier = 2
					min = 1
				}
				desc = stewardship_general.2002.mentor_success

				send_interface_toast = {
					type = event_toast_text_and_effect_good 
					left_icon = root
					right_icon = scope:helpful_councillor
					title = stewardship_general.2002.t_success
					desc = stewardship_general.2002.mentor_success

					add_stewardship_lifestyle_xp = medium_lifestyle_experience
					scope:helpful_councillor = {
						add_character_modifier = { 
							modifier = stewardship_general_bartering_strategies_modifier
							years = 5
						}
					}	
				}		
			}
			#They weren't quite convinced
			5 = {		
				compare_modifier = {
					value = scope:duel_value
					multiplier = 1
					min = 1
				}
				desc = stewardship_general.2002.mentor_failure

				send_interface_toast = {
					type = event_toast_text_and_effect_good 
					left_icon = root
					right_icon = scope:helpful_councillor
					title = stewardship_general.2002.t_failure
					desc = stewardship_general.2002.mentor_failure

					reverse_add_opinion = { 
						target = scope:helpful_councillor
						modifier = disapproving_opinion
						opinion = -10
					}	
				}
			}
		}
	}
	#Attempt to convince them you made a steal
	option = {
		name = stewardship_general.2002.b.high_stewardship
		#Trigger if insulted and high stewardship
		trigger = { 
			stewardship >= decent_skill_rating
			OR = {
				has_character_flag = insulted_councillor_stewardship_general.2001
				has_character_flag = very_insulted_councillor_stewardship_general.2001
			}
		}
		#If we're honest, just or compassionate we get a lil' bit of stress for fabricating the truth
		stress_impact = {
			honest = miniscule_stress_impact_gain
			just = miniscule_stress_impact_gain
			compassionate = miniscule_stress_impact_gain
		}
		duel = {
			skill = stewardship
			value = 10
			
			#You managed to convince them
			5 = {		
				compare_modifier = {
					value = scope:duel_value
					multiplier = 2
					min = 1
				}
				desc = stewardship_general.2002.convince_success

				send_interface_toast = {
					type = event_toast_text_and_effect_good 
					left_icon = root
					right_icon = scope:helpful_councillor
					title = stewardship_general.2002.t_success
					desc = stewardship_general.2002.convince_success

					add_stewardship_lifestyle_xp = medium_lifestyle_experience
					reverse_add_opinion = { 
						target = scope:helpful_councillor
						modifier = impressed_opinion
						opinion = 30
					}	
				}	
			}
			#They didn't buy it
			5 = {		
				compare_modifier = {
					value = scope:duel_value
					multiplier = 1
					min = 1
				}
				desc = stewardship_general.2002.convince_failure

				send_interface_toast = {
					type = event_toast_text_and_effect_good 
					left_icon = root
					right_icon = scope:helpful_councillor
					title = stewardship_general.2002.t_failure
					desc = stewardship_general.2002.convince_failure

					reverse_add_opinion = { 
						target = scope:helpful_councillor
						modifier = insult_opinion
						opinion = -30
					}	
				}	
			}
		}
	}
	#Why yes, that was a good purchase / Oh well, what's done is done
	option = {
		name = {
			text = {
				first_valid = {
					#Impressed / Very impressedAdd some flavor if we're greedy and prone to anger
					triggered_desc = {
						trigger = { 
							OR = {
								has_character_flag = impressed_councillor_stewardship_general.2001
								has_character_flag = very_impressed_councillor_stewardship_general.2001
							}
						}
						desc = stewardship_general.2002.impressed
					}
					#Insulted / very insulted
					triggered_desc = {
						desc = stewardship_general.2002.insulted
					}
				}
			}
		}
		apply_impressivity_effect = yes
	}

	after = {
		scope:bought_trinket = { 
			remove_variable = peddler_trinket 
		}
		remove_character_flag = insulted_councillor_stewardship_general.2001
		remove_character_flag = very_insulted_councillor_stewardship_general.2001
		remove_character_flag = impressed_councillor_stewardship_general.2001
		remove_character_flag = very_impressed_councillor_stewardship_general.2001
		scope:helpful_councillor = {
			remove_character_flag = insulted_councillor
		}
	}
}

##################################
# Fish pond!
# 5011-5013
# by Linnéa Thimrén
##################################

stewardship_general.5011 = {
	type = character_event
	title = stewardship_general.5011.t
	desc = stewardship_general.5011.desc
	
	theme = stewardship
	override_background = {
		reference = throne_room
	}
	left_portrait = {
		character = root
		animation = interested_left
	}
	
	trigger = {
		has_lifestyle = stewardship_lifestyle
		is_landed = yes
		OR = {
			is_ai = no
			short_term_gold >= medium_gold_value
		}
		NOT = { has_character_flag = had_fish_pond_event }
		any_courtier = {
			is_ai = yes
			count >= 2
			opinion = {
				target = root
				value <= -10
			}
		}
		NOR = {
			government_has_flag = government_is_tribal
			government_has_flag = government_is_nomadic
		}
	}

	weight_multiplier = { #More likely if a lot of courtiers dislike you
		base = 1
		modifier = {
			add = 1
			any_courtier = {
				is_ai = yes
				count >= 2
				opinion = {
					target = root
					value <= -20
				}
			}
		}
		modifier = {
			add = 1
			any_courtier = {
				is_ai = yes
				count >= 4
				opinion = {
					target = root
					value <= -20
				}
			}
		}
	}

	immediate = {
		add_character_flag = {
			flag = had_fish_pond_event
			days = 3650
		}
		add_character_flag = {
			flag = had_recent_lifestyle_ongoing_event
			years = ongoing_lifestyle_event_delay
		}
	}

	option = { #I'll build the best pond!
		name = stewardship_general.5011.a
		every_courtier = {
			custom = stewardship_general.5011.every_courtier
			add_opinion = {
				target = root
				modifier = governance_fish_pond
			}
		}
		remove_short_term_gold = medium_gold_value
		add_prestige = medium_prestige_gain

		#Carps can be dangerous...
		hidden_effect = {
			random = {
				chance = 3
				trigger_event = {
					id = stewardship_general.5012
					days = { 200 400 }
				}
			}
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_energy = 0.5
				ai_boldness = 0.25
			}
		}
	}

	option = { #Let's haggle!
		name = stewardship_general.5011.b

		add_stewardship_lifestyle_xp = medium_lifestyle_experience
		every_courtier = {
			custom = stewardship_general.5011.every_courtier
			add_opinion = {
				target = root
				modifier = governance_fish_pond
			}
		}

		duel = {
			skill = stewardship
			value = 10
			20 = {		
				compare_modifier = {
					value = scope:duel_value
					multiplier = 1
				}
				desc = stewardship_general.5011.b.message_1
				send_interface_toast = {
					type = event_toast_effect_good
					title = stewardship_general.5011.b.message_1
					left_icon = root
					remove_short_term_gold = minor_gold_value
					add_prestige = medium_prestige_gain
				}
			}
			10 = {		
				compare_modifier = {
					value = scope:duel_value
					multiplier = -0.5
				}
				desc = stewardship_general.5011.b.message_2
				send_interface_toast = {
					type = event_toast_effect_bad
					title = stewardship_general.5011.b.message_2
					left_icon = root
					remove_short_term_gold = medium_gold_value
					add_prestige = minor_prestige_loss
				}
			}
		}

		#Carps can be dangerous...
		hidden_effect = {
			random = {
				chance = 3
				trigger_event = {
					id = stewardship_general.5012
					days = { 200 400 }
				}
			}
		}

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

	option = { #nah
		name = stewardship_general.5011.c

		add_stress = minor_stress_loss

		every_courtier = {
			custom = stewardship_general.5011.every_courtier
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -5
			}
		}

		ai_chance = {
			base = 0
		}
	}
}

scripted_trigger stewardship_general_5012_not_heir_or_alternative_exists_trigger = {
	save_temporary_scope_as = potential_carp_food
	OR = {
		NOT = { is_player_heir_of = root }
		root = { any_child = { NOT = { this = scope:potential_carp_food } } }
	}
}

#Carp victim finder
stewardship_general.5012 = {
	hidden = yes

	immediate = {
		random_courtier_or_guest = {
			limit = {
				age >= 4
				OR = {
					has_trait = dwarf
					age <= 12
				}						
				stewardship_general_5012_not_heir_or_alternative_exists_trigger = yes
			}
			save_scope_as = carp_food
		}

		if = {
			limit = { exists = scope:carp_food }
			trigger_event = stewardship_general.5013
		}
	}
}

#Beasts Of The Deep (by Mathilda Bjarnehed)
stewardship_general.5013 = {
	type = character_event
	title = stewardship_general.5013.t
	desc = stewardship_general.5013.desc
	
	theme = death
	override_background = {
		reference = garden
	}
	left_portrait = {
		character = root
		animation = stunned
	}
	right_portrait = {
		character = scope:carp_food
		animation = shock
	}
	
	option = {
		name = stewardship_general.5013.a
	
		scope:carp_food = {
			death = {
				death_reason = death_carp_accident
			}
		}
	}
}



##################################
# Servant caught stealing from the household
# 5041
# by Linnéa Thimrén
##################################

stewardship_general.5041 = {
	type = character_event
	title = stewardship_general.5041.t
	desc = {
		desc = stewardship_general.5041.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					always = no #EK DISABLED: Removed reference to vanilla religions
					# faith = {
						# OR = {
							# religion_tag = islam_religion
							# religion_tag = christianity_religion
						# }
					# }
				}
				desc = stewardship_general.5041.desc_highgod
			}
			desc = stewardship_general.5041.desc_other
		}
		desc = stewardship_general.5041.desc_ending
	}
	
	theme = stewardship
	override_background = {
		reference = throne_room
	}
	left_portrait = {
		character = root
		animation = anger
	}
	right_portrait = {
		character = scope:servant_character
		animation = beg
	}
	
	trigger = {
		is_ai = no # AI characters should avoid creating random characters
		NOT = { has_character_flag = had_event_stewardship_general_5041 }
		has_trait = diligent
	}

	weight_multiplier = {
		base = 1
	}

	immediate = {
		add_character_flag = {
			flag = had_event_stewardship_general_5041
			days = 3650
		}
		add_character_flag = {
			flag = had_recent_lifestyle_ongoing_event
			years = ongoing_lifestyle_event_delay
		}
		create_character = {
			gender_female_chance = 50
			location = root.capital_province
			template = servant_character
			intrigue = { 8 18 }
			save_scope_as = servant_character
			dynasty = none
		}
		hidden_effect = {
			scope:servant_character = { set_employer = root }
			add_opinion = {
				modifier = theft_opinion
				target = scope:servant_character
			}
		}
	}

	option = { #kill them and reclaim all they stole
		name = stewardship_general.5041.a
		add_gold = tiny_gold_value
		
		execute_prisoner_effect = {
			VICTIM = scope:servant_character
			EXECUTIONER = root
		}

		stress_impact = {
			forgiving = major_stress_impact_gain
			compassionate = major_stress_impact_gain
			content = medium_stress_impact_gain
			trusting = medium_stress_impact_gain
			generous = medium_stress_impact_gain
			greedy = minor_stress_impact_loss
			wrathful = minor_stress_impact_loss
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_vengefulness = 0.75
			}
		}
	}

	option = { #throw them in the dungeon
		name = stewardship_general.5041.b
		add_gold = tiny_gold_value

		imprison_character_effect = {
			TARGET = scope:servant_character
			IMPRISONER = root
		}
		

		stress_impact = {
			forgiving = minor_stress_impact_gain
			compassionate = minor_stress_impact_gain
			trusting = minor_stress_impact_gain
			generous = minor_stress_impact_gain
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_greed = 0.5
				ai_boldness = 0.25
				ai_energy = 0.25
			}
		}
	}
	
	option = { #make them loyal to you
		name = stewardship_general.5041.c
		
		add_hook = {
			target = scope:servant_character
			type = loyalty_hook
		}
		scope:servant_character = {
			add_opinion = {
				modifier = kindness_opinion
				opinion = 30
				target = root
			}
		}

		stress_impact = {
			wrathful = minor_stress_impact_gain
			vengeful = medium_stress_impact_gain
			paranoid = medium_stress_impact_gain
			greedy = medium_stress_impact_gain
		}

		hidden_effect = {
			remove_opinion = {
				target = scope:servant_character
				modifier = theft_opinion
			}
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_greed = 0.5
				ai_boldness = 0.25
				ai_energy = 0.25
			}
		}
	}
}

###########################################################
# 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_general_special
