﻿
namespace = stewardship_general

# Normal Events
	#1054		- Accusations of Witchcraft, by Sean Hughes
	#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 = {
		event_background = gallows
	}
	left_portrait = {
		character = scope:witch
		animation = beg
	}
	
	trigger = {
		faith = {
			NOT = { has_doctrine = doctrine_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 = doctrine_witchcraft_crime
			}
		}
		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
		}
		if = {
			limit = {
				is_ai = no
			}
			add_character_flag = {
				flag = had_recent_lifestyle_ongoing_event_stewardship
				years = ongoing_lifestyle_event_delay
			}
		}
		else = {
			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 = mystic_1
							faith = this.faith
							culture = this.culture
							diplomacy = { 10 12 }
							learning = { 8 10 }
							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 = mystic_3
							trait = shrewd
							faith = root.faith
							culture = root.culture
							learning = { 12 14 }
							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 }
							save_scope_as = witch
						}
					}
				}
			}
		}
	}

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

##################################
# 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 = {
		event_background = throne_room
	}
	left_portrait = root
	
	trigger = {
		OR = {
			has_lifestyle = stewardship_lifestyle
			is_adult = yes
			is_ai = no
		}
		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
			}
		}
	}

	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
		}
		if = {
			limit = {
				is_ai = no
			}
			add_character_flag = {
				flag = had_recent_lifestyle_ongoing_event_stewardship
				years = ongoing_lifestyle_event_delay
			}
		}
		else = {
			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

		#Carps can be dangerous...
		hidden_effect = {
			random = {
				modifier = {
					any_courtier_or_guest = { has_trait = dwarf }
					factor = 15
				}
				chance = 2
				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
				}
			}
			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 = 2
				modifier = {
					any_courtier_or_guest = { has_trait = dwarf }
					factor = 15
				}
				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_trigger = { CHARACTER = root } }
		root = { any_child = { NOT = { this = scope:potential_carp_food } } }
	}
}

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

	immediate = {
		if = {
			limit = {
				any_courtier_or_guest = {
					has_trait = dwarf
					stewardship_general_5012_not_heir_or_alternative_exists_trigger = yes
				}
			}
			random_courtier_or_guest = {
				limit = {
					has_trait = dwarf
					stewardship_general_5012_not_heir_or_alternative_exists_trigger = yes
				}
				save_scope_as = carp_food
			}
		}
		else_if = {
			limit = {
				any_courtier = {
					is_adult = no
					age >= 4
					stewardship_general_5012_not_heir_or_alternative_exists_trigger = yes
				}
			}
			random_courtier = {
				limit = {
					is_adult = no
					age >= 4
					stewardship_general_5012_not_heir_or_alternative_exists_trigger = yes
				}
				save_scope_as = carp_food
			}
		}
		else = {
			random_courtier = {
				limit = {
					age >= 4
					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 = {
		event_background = garden
	}
	left_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 = {
					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 = {
		event_background = throne_room
	}
	left_portrait = {
		character = scope:servant_character
		animation = beg
	}
	
	trigger = {
		OR = {
			has_lifestyle = stewardship_lifestyle
			is_adult = yes
			is_ai = no
		}
		is_ai = no # AI characters should avoid creating random characters
		NOT = { has_character_flag = had_event_stewardship_general_5041 }
		any_sub_realm_county = {
			holder = {
				this = root
			}
		}
		has_trait = diligent
	}

	weight_multiplier = {
		base = 1
	}

	immediate = {
		add_character_flag = {
			flag = had_event_stewardship_general_5041
			days = 3650
		}
		if = {
			limit = {
				is_ai = no
			}
			add_character_flag = {
				flag = had_recent_lifestyle_ongoing_event_stewardship
				years = ongoing_lifestyle_event_delay
			}
		}
		else = {
			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
