﻿namespace = achaemenid_legend_event

achaemenid_legend_event.0001 = {
	type = character_event
	window = fullscreen_event
	title = achaemenid_legend_event.0001.t
	desc = achaemenid_legend_event.0001.desc
	
	theme = legend
	override_background = { reference = ce1_fullscreen_legitimizing_legend }
	
	immediate = {
		promoted_legend = { set_variable = my_legend_var }
	}
	
	option = {
		name = achaemenid_legend_event.0001.a
		custom_tooltip = { 
			text = achaemenid_legend_darius_complete_custom_tooltip
			add_darius_tradition_to_culture = yes
		}
	}
}

achaemenid_legend_event.0002 = {
	type = character_event
	window = fullscreen_event
	title = achaemenid_legend_event.0002.t
	desc = achaemenid_legend_event.0002.desc
	
	theme = legend
	override_background = { reference = ce1_fullscreen_heroic_legend }
	
	immediate = {
		promoted_legend = { set_variable = my_legend_var }
	}
	
	option = {
		name = achaemenid_legend_event.0002.a
		custom_tooltip = { 
			text = achaemenid_legend_immortals_complete_custom_tooltip
			add_immortal_tradition_to_culture = yes
		}
	}
}

achaemenid_legend_event.0003 = {
	type = character_event
	window = fullscreen_event
	title = achaemenid_legend_event.0003.t
	desc = achaemenid_legend_event.0003.desc
	
	theme = legend
	override_background = { reference = ce1_fullscreen_holy_legend }

	immediate = {
		promoted_legend = { set_variable = my_legend_var }
	}

	option = {
		name = achaemenid_legend_event.0003.a
		custom_tooltip = { 
			text = achaemenid_legend_zoroaster_complete_custom_tooltip
			add_zoroaster_tradition_to_culture = yes
		}
	}
}

achaemenid_legend_event.0004 = {
	type = character_event
	window = fullscreen_event
	title = achaemenid_legend_event.0004.t
	desc = achaemenid_legend_event.0004.desc
	
	theme = legend
	override_background = { reference = ce1_fullscreen_legitimizing_legend }

	immediate = {
		promoted_legend = { set_variable = my_legend_var }
	}

	option = {
		name = achaemenid_legend_event.0004.a
		custom_tooltip = { 
			text = achaemenid_legend_amastris_complete_custom_tooltip
			add_amastris_tradition_to_culture = yes
		}
	}
}

achaemenid_legend_event.0005 = {
	type = character_event
	window = fullscreen_event
	title = achaemenid_legend_event.0005.t
	desc = achaemenid_legend_event.0005.desc
	
	theme = legend
	override_background = { reference = ce1_fullscreen_legitimizing_legend }

	immediate = {
		promoted_legend = { set_variable = my_legend_var }
	}

	option = {
		name = achaemenid_legend_event.0005.a
		custom_tooltip = { 
			text = achaemenid_legend_cyrus_complete_custom_tooltip
			add_cyrus_tradition_to_culture = yes
		}
	}
}

achaemenid_legend_event.0006 = {
	type = character_event
	title = achaemenid_legend_event.0006.t
	desc = achaemenid_legend_event.0006.desc
	left_portrait = root
	right_portrait = cp:councillor_marshal

	theme = battle

	immediate = {
		every_courtier = { #permanent prowess increase
			limit = {
				is_knight_of = root
			}
			add_prowess_skill = 2
		}

		every_courtier = {
			limit = {
				is_knight_of = root
				prowess >= 12
				NOT = { has_trait = lifestyle_blademaster}
			}
			add_trait = lifestyle_blademaster
		}

		every_courtier = {
			limit = {
				is_knight_of = root
				has_trait = lifestyle_blademaster
				NOT = { has_trait_xp = {
						trait = lifestyle_blademaster
						value >= 100
					}
				}
			}
			add_trait_xp = {
			trait = lifestyle_blademaster
			value = 25
		}
	}

		every_vassal = {
			limit = {
				is_knight_of = root
			}
			add_prowess_skill = 2
		}

		every_vassal = {
			limit = {
				is_knight_of = root
				prowess >= 12
				NOT = { has_trait = lifestyle_blademaster}
			}
			add_trait = lifestyle_blademaster
		}

		every_vassal = {
			limit = {
				is_knight_of = root
				has_trait = lifestyle_blademaster
				NOT = { has_trait_xp = {
					trait = lifestyle_blademaster
					value >= 100
					}
				}
			}
			add_trait_xp = {
				trait = lifestyle_blademaster
				value = 25
			}
		}
	
		add_character_modifier = {
			modifier = immortal_illustrious_decision_modifier
			years = 5
		}
	
		add_trait = immortal_commander_trait
	

		every_courtier = {
			limit = {
				has_council_position = councillor_marshal
			}
			add_trait = immortal_commander_trait
			add_martial_skill = 3
		}
	
		every_vassal = {
			limit = {
				has_council_position = councillor_marshal
			}
			add_trait = immortal_commander_trait
			add_martial_skill = 3
		}
	}

	option = {
		name = achaemenid_legend_event.0006.a
	}
}

#############################################################################################
################### Darius Legend Random Events #############################################
#############################################################################################

achaemenid_legend_event.0007 = { #Darius Legend Event: Recruit Great Commander
	type = character_event
	title = achaemenid_legend_event.0007.t
	desc = achaemenid_legend_event.0007.desc
	left_portrait = root
	right_portrait = scope:great_commander
	lower_right_portrait = scope:exile_liege

	theme = legend

	trigger = {
		any_neighboring_and_across_water_top_liege_realm_owner = {
			OR = {
				AND = {
					NOT = { has_trait = lazy }
					NOT = { has_trait = craven }
					NOT = { has_trait = content }
				}
				has_relation_rival = root
			}
		}
		OR = {
			root.culture = {
				has_cultural_tradition = tradition_darius_legacy
			}
			AND = {
				exists = promoted_legend
				is_adult = yes
				promoted_legend = {
					legend_owner = root
					legend_type = legend_type:darius
				}
			}
		}
		NOT = { has_character_flag = recent_darius_legend_event }
		NOT = {
			any_courtier_or_guest = {
				has_character_flag = great_commander
			}
		}
	}

	immediate = {
		create_character = {
			save_scope_as = great_commander
			age = { 21 35 }
			random_traits_list = {
				count = 1
				education_martial_2 = {}
				education_martial_3 = {}
				education_martial_4 = {}
			}
			random_traits = yes
			trait = achaemenid_historian
			trait = immortal_commander_trait
	
			faith = root.faith
			culture = root.culture
			gender_female_chance = {
				if = {
					limit = { root.faith = { has_doctrine = doctrine_gender_male_dominated } }
					add = 0
				}
				else_if = {
					limit = { root.faith = { has_doctrine = doctrine_gender_female_dominated } }
						add = 100
				}
				else = {
					add = 50
				}
			}
			martial = { 8 14 }
			prowess = { 12 20 }
			employer = root

			after_creation = {
				add_character_flag = {
					flag = great_commander
				}
				add_character_flag = {
					flag = can_unite_persia
				}
				add_trait_xp = {
					trait = achaemenid_historian
					track = darius
					value = 100
				}
				add_character_flag = blocked_from_leaving
			}
		}
		random_neighboring_and_across_water_top_liege_realm_owner = {
			limit = {
				OR = {
					AND = {
						NOT = { has_trait = lazy }
						NOT = { has_trait = craven }
						NOT = { has_trait = content }
					}
					has_relation_rival = root
				}
			}
			weight = {
				base = 1
				modifier = {
					add = 1000
					has_relation_rival = root
				}
			}
			save_scope_as = exile_liege
		}
		root = {
			add_character_flag = {
				flag = recent_darius_legend_event
				years = 2
			}
		}
	}

	option = { #recruit the general, and pay him for loyalty
		name = achaemenid_legend_event.0007.a

		pay_short_term_gold = {
			gold = 500
			target = scope:great_commander
		}

		add_hook = {
			target = scope:great_commander
			type = loyalty_hook
		}

		scope:great_commander = {
			add_trait = loyal
		}
	}

	option = { #recruit the general
		name = achaemenid_legend_event.0007.b

		root = {
			add_courtier = scope:great_commander
		}
	}

	option = { #scorn him
		name = achaemenid_legend_event.0007.c

		scope:exile_liege = {
			add_courtier = scope:great_commander
			add_character_modifier = {
				modifier = great_commander_inspiration_modifier
				years = 20
			}
		}
		scope:great_commander = {
			set_relation_rival = {
				target = root
				reason = scorned_commander_rival
			}
		}
	}

	option = { #MURDER TIME
		name = achaemenid_legend_event.0007.d
		scope:great_commander = {
			death = {
				killer = root
				death_reason = death_execution
			}
		}
		add_character_modifier = {
			modifier = executed_great_commander
			years = 5
		}
	}
}

achaemenid_legend_event.0008 = { #Darius Legend Event: Commander Demands
	type = character_event
	title = achaemenid_legend_event.0008.t
	desc = achaemenid_legend_event.0008.desc
	left_portrait = root
	right_portrait = {
		character = scope:great_commander
		animation = aggressive_dagger
	}
	lower_right_portrait = scope:exile_liege

	theme = realm

	trigger = {
		NOT = { has_character_flag = recent_darius_legend_event}
		any_courtier_or_guest = {
			has_character_flag = great_commander
			NOT = { has_trait = loyal }
			OR = {
				has_trait = greedy
				has_trait = wrathful
				has_trait = diligent
				has_trait = forgiving
				has_trait = arrogant
			}
		}
	}

	immediate = {
		random_neighboring_and_across_water_top_liege_realm_owner = {
			limit = {
				OR = {
					AND = {
						NOT = { has_trait = lazy }
						NOT = { has_trait = craven }
						NOT = { has_trait = content }
					}
					has_relation_rival = root
				}
			}
			weight = {
				base = 1
				modifier = {
					add = 1000
					has_relation_rival = root
				}
			}
			save_scope_as = exile_liege
		}
		random_courtier_or_guest = {
			limit = {
				has_character_flag = great_commander
				NOT = {
					has_trait = loyal
				}
				OR = {
					has_trait = greedy
					has_trait = wrathful
					has_trait = diligent
					has_trait = forgiving
					has_trait = arrogant
				}
			}
			save_scope_as = great_commander
		}
		random_courtier_or_guest = {
			limit = {
				is_knight_of = root
			}
			save_scope_as = knight_to_kill
		}
		root = {
			add_character_flag = {
				flag = recent_darius_legend_event
				years = 2
			}
			save_scope_as = root_duelist
		}
	}

	option = { #he demands gold
		name = achaemenid_legend_event.0008.greedy

		trigger = {
			scope:great_commander = {
				has_trait = greedy
			}
		}

		exclusive = yes
		add_internal_flag = special

		pay_short_term_gold = {
			gold = 500
			target = scope:great_commander
		}

		custom_tooltip = darius_commander_demand_personality_tooltip
	}

	option = { #execute a random knight
		name = achaemenid_legend_event.0008.wrathful

		trigger = {
			scope:great_commander = {
				has_trait = wrathful
			}
		}
		exclusive = yes
		add_internal_flag = special

		scope:knight_to_kill = {
			death = {
				death_reason = death_execution
				killer = root
			}
		}

		custom_tooltip = darius_commander_demand_personality_tooltip
	}

	option = { #take on stress
		name = achaemenid_legend_event.0008.diligent

		trigger = {
			scope:great_commander = {
				has_trait = diligent
			}
		}

		exclusive = yes
		add_internal_flag = special

		root = {
			stress_impact = {
				base = major_stress_impact_gain
				lazy = major_stress_impact_gain
			}
		}

		custom_tooltip = darius_commander_demand_personality_tooltip
	}

	option = { #lose dread
		name = achaemenid_legend_event.0008.forgiving

		trigger = {
			scope:great_commander = {
				has_trait = forgiving
			}
		}

		exclusive = yes
		add_internal_flag = special

		root = {
			add_dread = {
				value = medium_dread_gain
				multiply = -1
			}
		}
		custom_tooltip = darius_commander_demand_personality_tooltip
	}

	option = { #lose prestige
		name = achaemenid_legend_event.0008.arrogant

		trigger = {
			scope:great_commander = {
				has_trait = arrogant
			}
		}

		exclusive = yes
		add_internal_flag = special

		root = {
			add_prestige = {
				value = medium_prestige_gain
				multiply = -2
			}
		}
		scope:great_commander = {
			add_prestige = {
				value = medium_prestige_gain
				multiply = 2
			}
		}
		custom_tooltip = darius_commander_demand_personality_tooltip
	}

	option = { #tell him to frick off
		name = achaemenid_legend_event.0008.b

		exclusive = yes

		scope:great_commander = {
			add_opinion = {
				target = root
				opinion = -25
				modifier = disappointed_opinion
			}
			add_character_modifier = {
				modifier = disappointed_commander
				years = 10
			}
		}
		custom_tooltip = disappointed_commander_consequences_tooltip
	}

	option = { #scorn him
		name = achaemenid_legend_event.0008.c

		exclusive = yes

		scope:exile_liege = {
			add_courtier = scope:great_commander
			add_character_modifier = {
				modifier = great_commander_inspiration_modifier
			}
			if = {
				limit = {
					NOT = { has_relation_rival = root }
				}
				set_relation_rival = {
					target = root
					reason = scorned_commander_liege_rival
				}
			}
		}
		scope:great_commander = {
			set_relation_rival = {
				target = root
				reason = scorned_commander_rival
			}
		}
	}

	option = { #duel him to put him in his place
		name = achaemenid_legend_event.0008.d

		exclusive = yes

		configure_start_single_combat_effect = {
			SC_INITIATOR = root
			SC_ATTACKER = root
			SC_DEFENDER = scope:great_commander
			FATALITY = no
			FIXED = no
			LOCALE = army_camp
			OUTPUT_EVENT = achaemenid_legend_event.0009
			INVALIDATION_EVENT = perk_interaction.0102
		}
		show_as_tooltip = {
			custom_tooltip = possible_duel_commander_outcomes_tooltip
		}
	}
}

achaemenid_legend_event.0009 = { #aftermath of duel
	type = character_event
	title = achaemenid_legend_event.0009.t
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = {
				root = scope:sc_loser
			}
			animation = severelywounded
		}
	}
	right_portrait = {
		character = scope:great_commander
		triggered_animation = {
			trigger = {
				root = scope:sc_victor
			}
			animation = severelywounded
		}
	}

	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { this = scope:sc_victor }
				desc = achaemenid_legend_event.0009.victor.desc
			}
			triggered_desc = {
				trigger = { this = scope:sc_loser }
				desc = achaemenid_legend_event.0009.loser.desc
			}
		}
	}
	theme = battle

	immediate = {
		random_held_title = {
			limit = {
				tier <= tier_duchy
				NOT = { this = root.capital_county }
			}
			save_scope_as = stolen_title
		}
	}

	option = { #if you won
		name = achaemenid_legend_event.0009.a
		trigger = { this = scope:sc_victor }
		scope:sc_victor = {
			add_prestige = 350
			add_trait = lifestyle_blademaster
			if = {
				limit = {
					has_trait = lifestyle_blademaster
				}
				add_trait_xp = {
					trait = lifestyle_blademaster
					value = 20
				}
			}
		}

		scope:sc_loser = {
			add_trait = loyal
		}
	}

	option = { #if you lost
		name = achaemenid_legend_event.0009.b
		trigger = { this = scope:sc_loser }

		scope:sc_loser = {
			add_prestige = {
				value = minor_prestige_gain
				multiply = -1
			}
		}
		create_title_and_vassal_change = {
			type = usurped
			save_scope_as = change
			add_claim_on_loss = yes
		}
		scope:stolen_title = {
			change_title_holder_include_vassals = {
				holder = scope:great_commander
				change = scope:change
			}
		}
		resolve_title_and_vassal_change = scope:change

		scope:great_commander = {
			trigger_event = {
				id = achaemenid_legend_event.0013
				days = 3
			}
		}
	}
}

achaemenid_legend_event.0010 = { #vision of Darius
	type = character_event
	title = achaemenid_legend_event.0010.t
	desc = achaemenid_legend_event.0010.desc
	left_portrait = root
	right_portrait = {
		character = scope:darius_vision_duelist
		animation = personality_zealous
	}

	theme = legend

	trigger = {
		NOT = { has_character_flag = recent_darius_legend_event}
		OR = {
			root.culture = {
				has_cultural_tradition = tradition_darius_legacy
			}
			AND = {
				exists = promoted_legend
				is_adult = yes
				promoted_legend = {
					legend_owner = root
					legend_type = legend_type:darius
				}
			}
		}
	}

	immediate = {
		root = {
			add_character_flag = {
				flag = recent_darius_legend_event
				years = 2
			}
		}
		create_character = {
			save_scope_as = darius_vision_duelist
			age = { 21 35 }
			random_traits_list = {
				count = 1
				education_martial_2 = {}
				education_martial_3 = {}
				education_martial_4 = {}
			}
			random_traits_list = {
				count = 1
				education_martial_prowess_2 = {}
				education_martial_prowess_3 = {}
				education_martial_prowess_4 = {}
			}
			random_traits = yes
			trait = achaemenid_historian
			trait = lifestyle_blademaster
			trait = devoted
	
			faith = root.faith
			culture = root.culture
			gender_female_chance = {
				if = {
					limit = { root.faith = { has_doctrine = doctrine_gender_male_dominated } }
					add = 0
				}
				else_if = {
					limit = { root.faith = { has_doctrine = doctrine_gender_female_dominated } }
						add = 100
				}
				else = {
					add = 50
				}
			}
			martial = { 4 10 }
			prowess = { 4 10 }
			employer = root

			after_creation = {
				add_character_flag = {
					flag = darius_vision_duelist_flag
				}
				add_trait_xp = {
					trait = lifestyle_blademaster
					value = 100
				}
				add_trait_xp = {
					trait = achaemenid_historian
					track = darius
					value = 100
				}
				add_character_flag = blocked_from_leaving
			}
		}
	}

	option = { #Take on a task to prove yourself
		name = achaemenid_legend_event.0010.a
		add_character_modifier = {
			modifier = darius_vision_accepted
			years = 2
		}
		custom_tooltip = {
			text = agree_to_fight_darius_vision
		}
	}
	option = { #Refuse the task
		name = achaemenid_legend_event.0010.b
		add_prestige = -200
		promoted_legend = {
			add_legend_owner_modifier = {
				modifier = darius_vision_decline_legend_modifier
			}
		}

		scope:darius_vision_duelist = {
			death = {
				death_reason = death_vanished
			}
		}
	}
}

achaemenid_legend_event.0011 = { #Egypt Campaign/if you own egypt, gain dev there
	type = character_event
	title = achaemenid_legend_event.0011.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { 
					completely_controls_region = ghw_region_egypt
				}
				desc = achaemenid_legend_event.0011.control
			}
			triggered_desc = {
				trigger = {
					NOT = {
						completely_controls_region = ghw_region_egypt
					}
				}
				desc = achaemenid_legend_event.0011.conquer
			}
		}
	}
	right_portrait = {
		character = root
		animation = chancellor
	}

	theme = legend

	trigger = {
		OR = {
			root.culture = {
				has_cultural_tradition = tradition_darius_legacy
			}
			AND = {
				exists = promoted_legend
				is_adult = yes
				promoted_legend = {
					legend_owner = root
					legend_type = legend_type:darius
				}
			}
		}
		NOT = { has_character_flag = recent_darius_legend_event }
		NOT = {
			has_global_variable = darius_legend_egypt_claimed
		}
	}

	immediate = {
		add_character_flag = {
			flag = recent_darius_legend_event
			years = 2
		}
		set_global_variable = {
			name = darius_legend_egypt_claimed
			value = yes
		}
	}

	option = { #If you don't already control all of Egypt
		name = achaemenid_legend_event.0011.a
		trigger = {
			NOT = {
				completely_controls_region = ghw_region_egypt
			}
		}
		add_pressed_claim = title:k_egypt
		add_pressed_claim = title:d_cyrenaica
		add_pressed_claim = title:d_alexandria
		add_pressed_claim = title:d_delta
		add_pressed_claim = title:d_cairo
		add_pressed_claim = title:d_al-wahat
		add_pressed_claim = title:d_al-said
		add_pressed_claim = title:d_eastern_desert
		add_pressed_claim = title:d_sinai
		add_character_modifier = {
			modifier = conquer_egypt_ambition_modifier
			years = 20
		}
		custom_tooltip = {
			text = conquer_egypt_motivation_tooltip
		}
	}

	option = { #If you do already control all of Egypt - Exploit Egypt
		name = achaemenid_legend_event.0011.b
		trigger = {
			completely_controls_region = ghw_region_egypt
		}
		exclusive = yes
		title:k_egypt = {
			change_development_level = -3
		}
		title:c_cairo = {
			change_development_level = -8
		}
		root.capital_county = {
			change_development_level = 15
			add_county_modifier = {
				modifier = egyptian_treasures_modifier
				years = 150
			}
		}
		add_gold = 750
		add_prestige = -500
	}
	option = { #If you do already control all of Egypt - develop Egypt
		name = achaemenid_legend_event.0011.c
		trigger = {
			completely_controls_region = ghw_region_egypt
		}
		exclusive = yes
		title:k_egypt = {
			change_development_level = 8
		}
		add_prestige = 1000
		add_gold = 300
	}
	option = { #If you do already control all of Egypt - move in
		name = achaemenid_legend_event.0011.d
		trigger = {
			completely_controls_region = ghw_region_egypt
		}
		exclusive = yes
		title:k_egypt = {
			change_development_level = 8
			add_county_modifier = {
				modifier = egypt_revitalized
				years = 25
			}
		}
		title:c_cairo = {
			change_development_level = 8
			add_county_modifier = {
				modifier = new_egyptian_capital
				years = 150
			}
			set_county_culture = root.culture
			set_county_faith = root.faith
		}
		set_realm_capital = title:c_cairo
	}
}

achaemenid_legend_event.0012 = { #Egypt Campaign: Conquest
	type = character_event
	title = achaemenid_legend_event.0012.t
	desc = achaemenid_legend_event.0012.desc
	left_portrait = {
		character = root
		animation = happiness
	}

	theme = legend

	trigger = {
		OR = {
			root.culture = {
				has_cultural_tradition = tradition_darius_legacy
			}
			AND = {
				exists = promoted_legend
				is_adult = yes
				promoted_legend = {
					legend_owner = root
					legend_type = legend_type:darius
				}
			}
		}
		has_character_modifier = conquer_egypt_ambition_modifier
		completely_controls_region = ghw_region_egypt
	}

	immediate = {
		remove_character_modifier = conquer_egypt_ambition_modifier
		add_character_flag = {
			flag = recent_darius_legend_event
			years = 2
		}
	}

	option = { #Colonize
		name = achaemenid_legend_event.0012.a
		add_character_modifier = {
			modifier = successful_egypt_conquest
			years = 30
		}
		custom_tooltip = {
			text = resettle_egypt_tooltip
			every_county_in_region = {
				region = ghw_region_egypt
				limit = {
					NOT = {
						culture = root.culture
					}
				}
				random = {
					chance = 33
					set_county_culture = root.culture
					set_county_faith = root.faith
				}
			}
		}
		add_prestige = 2000
	}
	option = { #Exploit
		name = achaemenid_legend_event.0012.b
		title:k_egypt = {
			change_development_level = -3
		}
		title:c_cairo = {
			change_development_level = -8
		}
		root.capital_county = {
			change_development_level = 15
			add_county_modifier = {
				modifier = egyptian_treasures_modifier
				years = 150
			}
		}
		add_gold = 750
		add_prestige = -500
	}
	option = { #develop
		name = achaemenid_legend_event.0012.c
		title:k_egypt = {
			change_development_level = 8
		}
		add_prestige = 1000
		add_gold = 300
	}
	option = { # Move in
		name = achaemenid_legend_event.0012.d
		title:k_egypt = {
			change_development_level = 8
			add_county_modifier = {
				modifier = egypt_revitalized
				years = 25
			}
			random = {
				chance = 33
				set_county_culture = root.culture
				set_county_faith = root.faith
			}
		}
		create_title_and_vassal_change = {
			type = usurped
			save_scope_as = change
			add_claim_on_loss = no
		}
		title:c_cairo = {
			change_development_level = 8
			add_county_modifier = {
				modifier = new_egyptian_capital
				years = 150
			}
			set_county_culture = root.culture
			set_county_faith = root.faith
			change_title_holder = {
				holder = root
				change = scope:change
			}
		}
		resolve_title_and_vassal_change = scope:change
		set_realm_capital = title:c_cairo
		add_prestige = 250
	}
}

achaemenid_legend_event.0013 = { #spawn army for great commander
	type = character_event
	title = achaemenid_legend_event.0013.t
	left_portrait = root
	desc = achaemenid_legend_event.0013.desc

	option = {
		name = achaemenid_legend_event.0013.a
		spawn_army = {
		location = root.capital_province
		name = great_commander_spawned_army
		men_at_arms = {
			type = immortals
			stacks = 10
		}
		men_at_arms = {
			type = composite_bowmen
			stacks = 10
		}
		men_at_arms = {
			type = mangonel
			stacks = 8
		}
		men_at_arms = {
			type = asawira
			stacks = 10
		}
		men_at_arms = {
			type = tarkhan
			stacks = 10
		}
		levies = 2000
		uses_supply = yes
		inheritable = no
		}
	}
}

achaemenid_legend_event.0014 = { #Darius vision duel outcome
	type = character_event
	title = achaemenid_legend_event.0014.t
	desc = achaemenid_legend_event.0014.desc
	left_portrait = root

	theme = battle

	immediate = {
		remove_character_modifier = darius_vision_accepted
	}

	option = { #if you won
		name = achaemenid_legend_event.0014.a
		trigger = {
			scope:sc_winner = {
				this = root
			}
		}

		scope:darius_vision_duelist = {
			death = {
				death_reason = death_vanished
			}
		}

		promoted_legend = {
			add_legend_province_modifier = {
				modifier = darius_vision_legend_modifier_reward
			}
		}
		add_prestige = 1000
	}

	option = { #if you lost
		name = achaemenid_legend_event.0014.b
		trigger = {
			scope:sc_loser = {
				this = root
			}
		}

		promoted_legend = {
			add_legend_province_modifier = {
				modifier = darius_vision_legend_modifier_reward_effort
			}
		}
		scope:darius_vision_duelist = {
			death = {
				death_reason = death_vanished
			}
		}
		add_prestige = 100
	}
}

achaemenid_legend_event.0015 = { #decision to confront the Darius Vision
	type = character_event
	title = achaemenid_legend_event.0015.t
	desc = achaemenid_legend_event.0015.desc
	left_portrait = {
		character = root
		animation = aggressive_sword
	}
	right_portrait = {
		character = scope:darius_vision_duelist
		animation = aggressive_sword
	}

	theme = battle

	immediate = {
		random_courtier_or_guest = {
			limit = {
				has_character_flag = darius_vision_duelist_flag
			}
			save_scope_as = darius_vision_duelist
		}
	}

	option = { #begin the duel
		name = achaemenid_legend_event.0015.a
		configure_start_single_combat_effect = {
			SC_INITIATOR = root
			SC_ATTACKER = root
			SC_DEFENDER = scope:darius_vision_duelist
			FATALITY = no
			FIXED = no
			LOCALE = army_camp
			OUTPUT_EVENT = achaemenid_legend_event.0014
			INVALIDATION_EVENT = perk_interaction.0102
		}
	}

	option = { #wimp
		name = achaemenid_legend_event.0015.b
		scope:darius_vision_duelist = {
			death = {
				death_reason = death_vanished
			}
		}
		promoted_legend = {
			add_legend_owner_modifier = {
				modifier = darius_vision_decline_legend_modifier
			}
		}
		add_prestige = -250
	}
}

################################################################################################
######################### IMMORTAL LEGEND RANDOM EVENTS ########################################
################################################################################################

achaemenid_legend_event.0016 = { #an immortal spear
	type = character_event
	title = achaemenid_legend_event.0016.t
	desc = achaemenid_legend_event.0016.desc
	left_portrait = {
		character = root
		animation = thinking
	}
	right_portrait = {
		character = cp:councillor_marshal
		animation = marshal
	}

	theme = legend

	trigger = {
		OR = {
			root.culture = {
				has_cultural_tradition = tradition_immortals
			}
			AND = {
				exists = promoted_legend
				is_adult = yes
				promoted_legend = {
					legend_owner = root
					legend_type = legend_type:immortal
				}
			}
		}
		NOT = { has_character_flag = recent_immortal_legend_event }
		prowess >= 12
	}

	immediate = {
		add_character_flag = {
			flag = recent_immortal_legend_event
			years = 2
		}
		create_artifact = {
			name = legendary_immortal_spear
			description = legendary_immortal_spear_desc
			type = spear
			visuals = spear
			creator = root
			rarity = illustrious
			modifier = legendary_immortal_spear_modifier
			save_scope_as = immortal_spear_artifact
		}
	}

	option = { #take the spear
		name = achaemenid_legend_event.0016.a

		scope:immortal_spear_artifact = {
			set_owner = root
		}

		custom_tooltip = {
			text = warning_immortal_spear_tooltip
			scope:immortal_spear_artifact = {
				set_variable = { name = unique_achaemenid_artifact value = yes }
			}
		}

		promoted_legend = {
			add_legend_owner_modifier = {
				modifier = immortal_spear_legend_owner_modifier
				years = 10
			}
		}
	}
	option = { #give the spear to the marshall
		name = achaemenid_legend_event.0016.b

		trigger = {
			OR = {
				any_courtier = {
					has_council_position = councillor_marshal
				}
				any_vassal = {
					has_council_position = councillor_marshal
				}
			}
		}

		every_courtier = {
			limit = {
				has_council_position = councillor_marshal
			}
			scope:immortal_spear_artifact = {
				set_owner = prev
			}
		}
		every_vassal = {
			limit = {
				has_council_position = councillor_marshal
			}
			scope:immortal_spear_artifact = {
				set_owner = prev
			}
		}
		scope:immortal_spear_artifact = {
			set_variable = { name = unique_achaemenid_artifact value = yes }
		}

		promoted_legend = {
			add_legend_owner_modifier = {
				modifier = donated_spear_to_marshal_legend_modifier
				years = 10
			}
		}
	}
}

achaemenid_legend_event.0017 = { #a challenger for the spear
	type = character_event
	title = achaemenid_legend_event.0017.t
	desc = achaemenid_legend_event.0017.desc
	left_portrait = {
		character = root
		animation = fear
	}
	right_portrait = {
		character = scope:immortal_spear_challenger
		animation = aggressive_sword
	}

	theme = court

	trigger = {
		any_artifact = {
			artifact_owner = root
			has_variable = unique_achaemenid_artifact
		}
		NOT = { has_character_flag = recent_immortal_legend_event }
		NOT = { has_character_modifier = defended_the_spear }
	}

	immediate = {
		create_character = {
			save_scope_as = immortal_spear_challenger
			age = { 21 35 }
			random_traits_list = {
				count = 1
				education_martial_2 = {}
				education_martial_3 = {}
				education_martial_4 = {}
			}
			random_traits_list = {
				count = 1
				education_martial_prowess_2 = {}
				education_martial_prowess_3 = {}
				education_martial_prowess_4 = {}
			}
			random_traits = yes
			trait = achaemenid_historian
			trait = lifestyle_blademaster
			trait = lunatic
	
			faith = root.faith
			culture = root.culture
			gender_female_chance = {
				if = {
					limit = { root.faith = { has_doctrine = doctrine_gender_male_dominated } }
					add = 0
				}
				else_if = {
					limit = { root.faith = { has_doctrine = doctrine_gender_female_dominated } }
						add = 100
				}
				else = {
					add = 50
				}
			}
			martial = { 4 10 }
			prowess = { 4 10 }
			employer = root

			after_creation = {
				add_character_flag = {
					flag = immortal_spear_challenger
				}
				add_trait_xp = {
					trait = achaemenid_historian
					track = darius
					value = 100
				}
				add_character_flag = blocked_from_leaving
			}
		}
		random_artifact = {
			limit = {
				has_variable = unique_achaemenid_artifact
			}
			save_scope_as = immortal_spear_artifact
		}
	}

	option = { #defend your right to the spear
		name = achaemenid_legend_event.0017.a

		custom_tooltip = {
			text = initiate_lethal_duel_tooltip
			configure_start_single_combat_effect = {
				SC_INITIATOR = root
				SC_ATTACKER = root
				SC_DEFENDER = scope:immortal_spear_challenger
				FATALITY = always
				FIXED = no
				LOCALE = court
				OUTPUT_EVENT = achaemenid_legend_event.0018
				INVALIDATION_EVENT = perk_interaction.0102
			}
		}
		add_internal_flag = dangerous
	}

	option = { #give up the spear
		name = achaemenid_legend_event.0017.b

		scope:immortal_spear_artifact = {
			set_owner = scope:immortal_spear_challenger
		}
		root = {
			add_prestige = -500
			add_trait = craven
			if = {
				limit = {
					has_trait = brave
				}
				remove_trait = brave
			}
			add_personal_artifact_claim = scope:immortal_spear_artifact
		}
		scope:immortal_spear_challenger = {
			move_to_pool = yes
		}
		promoted_legend = {
			remove_legend_owner_modifier = immortal_spear_legend_owner_modifier
		}
	}

	option = { #unworthy
		name = achaemenid_legend_event.0017.c

		promoted_legend = {
			add_legend_owner_modifier = {
				modifier = cowardly_spear_keeper
				years = 10
			}
			remove_legend_owner_modifier = immortal_spear_legend_owner_modifier
		}
		scope:immortal_spear_challenger = {
			death = {
				killer = root
				death_reason = death_execution
			}
		}
		scope:root = {
			add_prestige = -250
			add_tyranny = 25
			add_dread = 40
		}
	}
}

achaemenid_legend_event.0018 = { #spear challenger duel outcome
	type = character_event
	title = achaemenid_legend_event.0018.t
	desc = achaemenid_legend_event.0018.desc
	left_portrait = root

	theme = battle

	option = { #if you win
		name = achaemenid_legend_event.0018.a
		trigger = {
			scope:sc_victor = root
		}
		add_prestige = 250
		add_character_modifier = {
			modifier = defended_the_spear
			years = 15
		}
		custom_tooltip = {
			text = no_more_challengers_tooltip
		}
	}

	option = { #if you lose
		name = achaemenid_legend_event.0018.b
		trigger = {
			scope:sc_loser = root
		}
		add_prestige = -250
		scope:immortal_spear_artifact = {
			set_owner = scope:sc_victor
		}
		root = {
			add_personal_artifact_claim = scope:immortal_spear_artifact
		}
	}
}

achaemenid_legend_event.0019 = { #inspire the troops with your legend
	type = character_event
	title = achaemenid_legend_event.0019.t
	desc = achaemenid_legend_event.0019.desc
	left_portrait = {
		character = root
		animation = chancellor
	}

	theme = martial
	
	trigger = {
		OR = {
			root.culture = {
				has_cultural_tradition = tradition_immortals
			}
			AND = {
				exists = promoted_legend
				is_adult = yes
				promoted_legend = {
					legend_owner = root
					legend_type = legend_type:immortal
				}
			}
		}
		NOT = { has_character_flag = recent_immortal_legend_event }
		NOT = { has_character_modifier = successful_immortal_speech }
	}

	option = { #give a speech
		name = achaemenid_legend_event.0019.a

		duel = {
			skill = diplomacy
			value = 20
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = achaemenid_legend_event.0019.a.duel.success
				send_interface_toast = {
					title = achaemenid_legend_event.0019.a.duel.success
					left_icon = root
					add_prestige = medium_prestige_gain
					add_character_modifier = {
						modifier = successful_immortal_speech
						years = 5
					}
				}
			}
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = achaemenid_legend_event.0019.a.duel.failure
				send_interface_toast = {
					title = achaemenid_legend_event.0019.a.duel.failure
					left_icon = root
					add_prestige = {
						value = medium_prestige_gain
						multiply = -1
					}
				}
			}
		}
	}
	option = {
		name = achaemenid_legend_event.0019.b
		add_prestige = {
			value = 50
			multiply = -1
		}
	}
}

achaemenid_legend_event.0020 = { #temporary access to ceremonial war
	type = character_event
	title = achaemenid_legend_event.0020.t
	desc = achaemenid_legend_event.0020.desc
	left_portrait = {
		character = root
		animation = marshal
	}

	theme = legend

	trigger = {
		AND = {
			exists = promoted_legend
			is_adult = yes
			promoted_legend = {
				legend_owner = root
				legend_type = legend_type:immortal
			}
		}
		NOT = { has_character_flag = recent_immortal_legend_event }
		NOT = { has_character_modifier = access_ceremonial_war }
		is_at_war = no
	}

	option = { #prepare for ceremonial war
		name = achaemenid_legend_event.0020.a

		add_character_modifier = {
			modifier = access_ceremonial_war
			years = 5
		}

		custom_tooltip = {
			text = potential_for_reward_if_winner_ceremonial_war_tooltip
			add_character_flag = {
				flag = prepared_for_ceremonial_war
				years = 20
			}	
		}
	}
}

achaemenid_legend_event.0021 = { #reward for succeeding ceremonial war
	type = character_event
	title = achaemenid_legend_event.0021.t
	desc = achaemenid_legend_event.0021.desc
	left_portrait = {
		character = root
		animation = sword_coup_degrace
	}
	right_portrait = {
		character = scope:defender
		animation = beg
	}

	theme = battle

	option = { #demand a tribute from the enemy
		name = achaemenid_legend_event.0021.a
		scope:defender = {
			pay_short_term_gold = {
				gold = {
					value = massive_gold_value
					multiply = 4
				}
				target = root
			}
		}
	}

	option = { #demand development
		name = achaemenid_legend_event.0021.b
		scope:defender.capital_county = {
			change_development_level = -5
		}
		scope:attacker.capital_county = {
			change_development_level = 5
		}	
	}

	option = { #demand humiliation
		name = achaemenid_legend_event.0021.c
		scope:attacker = {
			add_prestige = 5000
		}
		scope:defender = {
			add_prestige = -2500
		}
	}
}

####################################################################################################
############################# Amastris Legend Random Events ########################################
####################################################################################################

achaemenid_legend_event.0022 = { #female empowerment - changing martial custom
	type = character_event
	title = achaemenid_legend_event.0022.t
	desc = achaemenid_legend_event.0022.desc
	left_portrait = {
		character = root
		animation = thinking
	}
	right_portrait = {
		character = scope:new_heiress
		animation = personality_honorable
	}

	theme = legend

	trigger = {
		AND = {
			exists = promoted_legend
			is_adult = yes
			promoted_legend = {
				legend_owner = root
				legend_type = legend_type:amastris
			}
		}
		NOT = { has_character_flag = recent_amastris_legend_event }
		culture = { has_cultural_parameter = martial_custom_male_only_combatant }
		any_child = {
			is_female = yes
			is_adult = yes
		}
	}

	immediate = {
		random_child = {
			limit = {
				is_female = yes
				is_adult = yes
			}
			save_scope_as = new_heiress
		}
		add_character_flag = {
			flag = recent_amastris_legend_event
			years = 2
		}
	}

	option = { #welcome women into the army, and set new heir
		name = achaemenid_legend_event.0022.a

		custom_tooltip = {
			text = set_pillar_equal_martial_custom_tooltip
			root.culture = {
				set_culture_pillar = martial_custom_equal
			}
		}

		root = {
			add_character_modifier = {
				modifier = allowed_women_in_the_army_amastris_legend
				years = 30
			}
			set_designated_heir = scope:new_heiress
		}
	}

	option = { #women don't belong in the army
		name = achaemenid_legend_event.0022.b

		promoted_legend = {
			add_legend_owner_modifier = {
				modifier = refused_women_in_army_amastris_legend
				years = 25
			}
		}
	}
}

achaemenid_legend_event.0023 = { #tyranny and dread event
	type = character_event
	title = achaemenid_legend_event.0023.t
	desc = achaemenid_legend_event.0023.desc
	left_portrait = {
		character = root
		animation = assassin
	}

	theme = legend

	trigger = {
		AND = {
			exists = promoted_legend
			is_adult = yes
			promoted_legend = {
				legend_owner = root
				legend_type = legend_type:amastris
			}
		}
		NOT = { has_character_flag = recent_amastris_legend_event }
	}

	immediate = {
		add_character_flag = {
			flag = recent_amastris_legend_event
			years = 2
		}
	}

	option = { #positive modifier 1
		name = achaemenid_legend_event.0023.a

		promoted_legend = {
			add_legend_owner_modifier = {
				modifier = amastris_legend_positive_dread_1_modifier
				years = 5
			}
		}
	}

	option = { #positive modifier 2
		name = achaemenid_legend_event.0023.b

		promoted_legend = {
			add_legend_owner_modifier = {
				modifier = amastris_legend_positive_dread_2_modifier
				years = 5
			}
		}
	}
}

achaemenid_legend_event.0024 = { #terrify a brave vassal into being craven
	type = character_event
	title = achaemenid_legend_event.0024.t
	desc = achaemenid_legend_event.0024.desc
	left_portrait = {
		character = root
		animation = thinking
	}
	right_portrait = {
		character = scope:brave_vassal
		animation = personality_bold
	}

	theme = legend

	trigger = {
		AND = {
			exists = promoted_legend
			is_adult = yes
			promoted_legend = {
				legend_owner = root
				legend_type = legend_type:amastris
			}
		}
		NOT = { has_character_flag = recent_amastris_legend_event }
		any_vassal = {
			has_trait = brave
		}
	}
	immediate = {
		add_character_flag = {
			flag = recent_amastris_legend_event
			years = 2
		}
		random_vassal = {
			limit = {
				has_trait = brave
			}
			save_scope_as = brave_vassal
		}
	}

	option = { #intrigue check to scare vassal
		name = achaemenid_legend_event.0024.a

		duel = {
			skill = intrigue
			value = 10
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = achaemenid_legend_event.0024.a.duel.success
				send_interface_toast = {
					title = achaemenid_legend_event.0024.a.duel.success
					left_icon = root
					root = {
						add_dread = 60
					}
					scope:brave_vassal = {
						add_trait = craven
						remove_trait = brave
					}
				}
			}
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = achaemenid_legend_event.0024.a.duel.failure
				send_interface_toast = {
					title = achaemenid_legend_event.0024.a.duel.failure
					left_icon = root
					scope:brave_vassal = {
						set_relation_rival = root
					}
				}
			}
		}
	}

	option = { #nah it's a bad idea
		name = achaemenid_legend_event.0024.b

		add_dread = 25
	}
}


#####################################################################
################### Zoroaster Legend Random Events ##################
#####################################################################

achaemenid_legend_event.0025 = { #remarry sibling
	type = character_event
	title = achaemenid_legend_event.0025.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					NOT = {
						root.faith = {
							has_doctrine = doctrine_consanguinity_unrestricted
						}
					}
				}
				desc = achaemenid_legend_event.0025.desc
			}
			triggered_desc = {
				trigger = {
					root.faith = {
						has_doctrine = doctrine_consanguinity_unrestricted
					}
				}
				desc = achaemenid_legend_event.0025.b.desc
			}
		}	
	}
	left_portrait = {
		character = root
		animation = thinking
	}
	right_portrait = {
		character = scope:new_sibling_spouse
		animation = disgust
	}
	lower_left_portrait = scope:replaced_spouse

	theme = legend

	trigger = {
		AND = {
			exists = promoted_legend
			is_adult = yes
			promoted_legend = {
				legend_owner = root
				legend_type = legend_type:zoroaster
			}
		}
		NOT = { has_character_flag = recent_zoroaster_legend_event }
		is_married = yes
		NOT = {
			any_spouse = {
				is_close_family_of = root
			}
		}
		NOT = {
			root.faith = {
				has_doctrine = doctrine_consanguinity_unrestricted
			}
		}
	}

	immediate = {
		add_character_flag = {
			flag = recent_zoroaster_legend_event
			years = 2
		}
		random_spouse = {
			save_scope_as = replaced_spouse
		}
		random_sibling = {
			limit = {
				age > 16
				trigger_if = {
					limit = {
						root = {
							is_male = yes
						}
					}
					is_female = yes
				}
				trigger_if = {
					limit = {
						root ={
							is_female = yes
						}
					}
					is_male = yes
				}
			}
			save_scope_as = new_sibling_spouse
		}
	}

	option = { #marry your sibling GIGACHAD
		name = achaemenid_legend_event.0025.a
		scope:new_sibling_spouse = {
			every_spouse = {
				divorce = scope:new_sibling_spouse
			}
		}

		root = {
			divorce = scope:replaced_spouse
			marry = scope:new_sibling_spouse
		}

		promoted_legend = {
			add_legend_owner_modifier = {
				modifier = zoroaster_consanguinuity_fertiliy_modifier
			}
		}
	}

	option = { #nah, that's gross
		name = achaemenid_legend_event.0025.b
	}
}

achaemenid_legend_event.0026 = { #something sky-burial related
	type = character_event
	title = achaemenid_legend_event.0026.t
	desc = achaemenid_legend_event.0026.desc
	left_portrait = {
		character = root
		animation = hunting_falcon
	}

	theme = legend

	trigger = {
		AND = {
			exists = promoted_legend
			is_adult = yes
			promoted_legend = {
				legend_owner = root
				legend_type = legend_type:zoroaster
			}
		}
		NOT = { has_character_flag = recent_zoroaster_legend_event }
		NOT = {
			root.faith = {
				has_doctrine_parameter = sky_burials_active
			}
		}
	}

	immediate = {
		add_character_flag = {
			flag = recent_zoroaster_legend_event
			years = 2
		}
	}

	option = { #try to feed the birds
		name = achaemenid_legend_event.0026.a

		random_list = {
			75 = {
				send_interface_toast = {
					title = achaemenid_legend_event.0026.duel.success
					left_icon = root
					root.capital_county = {
						add_county_modifier = {
							modifier = zoroaster_sky_burial_attempt_legend_modifier
							years = 10
						}
					}
				}
			}
			25 = {
				send_interface_toast = {
					title = achaemenid_legend_event.0026.duel.failure
					left_icon = root
					root.capital_county = {
						add_county_modifier = {
							modifier = zoroaster_sky_burial_attempt_legend_modifier_fail
							years = 10
						}
					}
				}
				hidden_effect = { #bird poops on you haha
					random = {
						chance = 25
						give_nickname = nick_the_achaemenid0003
					}
				}
			}
		}
	}

	option = { #keep to traditional burials
		name = achaemenid_legend_event.0026.b

		add_piety = 50
	}
}

achaemenid_legend_event.0027 = { #Mazdayasna conversion event chain start
	type = character_event
	title = achaemenid_legend_event.0027.t
	desc = achaemenid_legend_event.0027.desc
	left_portrait = {
		character = root
		animation = thinking
	}
	right_portrait = {
		character = cp:councillor_court_chaplain
		animation = chaplain
	}

	theme = legend

	trigger = {
		OR = {
			AND = {
				AND = {
					exists = promoted_legend
					is_adult = yes
					promoted_legend = {
						legend_owner = root
						legend_type = legend_type:zoroaster
					}
				}
				NOT = { has_character_flag = recent_zoroaster_legend_event }
				NOT = { 
					root.religion = religion:zoroastrianism_religion
				}
				any_realm_county = {
					NOT = { faith = faith:mazdayasna }
				}
				NOT = {
					has_character_flag = ineligible_for_mazdayasna_conversion_events
				}
			}
			root.culture = {
				has_cultural_tradition = tradition_zoroaster_blessing
			}
		}
	}

	immediate = {
		add_character_flag = {
			flag = recent_zoroaster_legend_event
			years = 2
		}
		random_realm_county = {
			limit = {
				NOT = { faith = faith:mazdayasna }
			}
			set_county_faith = faith:mazdayasna
			save_scope_as = converted_county
		}
	}

	option = { #a county converts to Mazdayasna: leave it alone, accepting the quest
		#this outcome begins the event chain for conversion
		name = achaemenid_legend_event.0027.a
		scope:converted_county = {
			add_county_modifier = {
				modifier = zoroastrian_scholar_county_modifier
				years = 25
			}
		}
		root = {
			custom_tooltip = {
				text = potential_for_mazdayasna_conversion_tooltip
				add_character_flag = eligible_for_mazdayasna_conversion_events
			}
		}
	}

	option = { #a county converts to Mazdayasna: discriminate them, quest remains open, but unaccepted
		#this outcome leaves the event open to fire again, so you can still try and become Mazdayasna
		name = achaemenid_legend_event.0027.b
		scope:converted_county = {
			add_county_modifier = {
				modifier = zoroastrian_scholar_county_modifier_forced_conversion
				years = 10
			}
		}
	}

	option = { #a county converts to Mazdayasna: genocide them, declining the quest
		#this outcome makes it impossible to get this event again
		name = achaemenid_legend_event.0027.c
		scope:converted_county = {
			add_county_modifier = {
				modifier = zoroastrian_scholar_county_modifier_forced_conversion_extreme
				years = 10
			}
			set_county_faith = root.faith
		}
		add_character_flag = {
			flag = ineligible_for_mazdayasna_conversion_events
			years = 100
		}
	}
}

achaemenid_legend_event.0028 = { #Allow the opening of a fire temple in the capital
	type = character_event
	title = achaemenid_legend_event.0028.t
	desc = achaemenid_legend_event.0028.desc
	left_portrait = {
		character = root
		animation = thinking
	}
	right_portrait = {
		character = cp:councillor_court_chaplain
		animation = rage
	}

	theme = legend

	trigger = {
		has_character_flag = eligible_for_mazdayasna_conversion_events
		NOT = {
			faith = faith:mazdayasna
		}
	}

	immediate = {
		root.capital_county = {
			set_county_faith = faith:mazdayasna
			save_scope_as = converted_county
		}
	}

	option = { #accept the conversion, and embrace them
		name = achaemenid_legend_event.0028.a

		scope:converted_county = {
			change_development_level = 2
			add_county_modifier = {
				modifier = zoroastrian_scholar_county_modifier_powerful
				years = 25
			}
		}

		root = {
			add_trait = lifestyle_mystic
			add_piety = -250
			set_character_faith_with_conversion = faith:mazdayasna
			add_character_modifier = {
				modifier = embraced_zoroastrianism_event_chain_modifier
				years = 10
			}
		}

		promoted_legend = {
			add_legend_owner_modifier = pro_zoroastrian_administration_legend
		}
	}

	option = { #accept the conversion, but embrace them secretly
		name = achaemenid_legend_event.0028.b

		scope:converted_county = {
			change_development_level = 1
			add_county_modifier = {
				modifier = zoroastrian_scholar_county_modifier
				years = 25
			}
		}

		root = {
			set_character_secret_faith = faith:mazdayasna
		}
	}

	option = { #End the event chain, asserting your faith's dominance
		name = achaemenid_legend_event.0028.c

		scope:converted_county = {
			add_county_modifier = {
				modifier = zoroastrian_scholar_county_modifier_forced_conversion
				years = 3
			}
			set_county_faith = root.faith
		}

		root = {
			add_trait = zealous
			add_piety = 500
		}

		promoted_legend = {
			add_legend_owner_modifier = anti_zoroastrian_sentiment_legend_modifier
		}
	}
}

#######################################################################################
############################# Cyrus Legend Random Events ##############################
#######################################################################################

achaemenid_legend_event.0029 = { #Conquer Jerusalem for the Jews
	type = character_event
	title = achaemenid_legend_event.0029.t
	desc = achaemenid_legend_event.0029.desc
	left_portrait = root
	lower_right_portrait = scope:jewish_leader
	lower_left_portrait = scope:samaritan_leader

	theme = legend

	trigger = {
		exists = promoted_legend
		is_adult = yes
		promoted_legend = {
			legend_owner = root
			legend_type = legend_type:cyrus
		}
		NOT = {
			completely_controls = title:k_jerusalem
		}
		NOT = {
			has_character_flag = recent_cyrus_legend_event
		}
	}

	immediate = {
		religion:judaism_religion = {
			random_faith = {
				limit = {
					OR = {
						has_doctrine = temple_authority_rabbinic_doctrine
						has_doctrine = temple_authority_toric_doctrine
						has_doctrine = temple_authority_kohanim_doctrine
					}
				}
				save_scope_as = random_jewish_faith
			}
		}
		religion:judaism_religion = {
			random_faith = {
				limit = {
					has_doctrine = temple_authority_samaritan_torah_doctrine
				}
				save_scope_as = random_samaritan_faith
			}
		}
		create_character = { #rabbinic leader
			save_scope_as = jewish_leader
			age = { 21 35 }
			random_traits_list = {
				count = 1
				education_martial_5 = {}
				education_stewardship_5 = {}
				education_learning_5 = {}
				education_intrigue_5 = {}
				education_diplomacy_5 = {}
			}
			random_traits = yes
			trait = achaemenid_historian
			trait = zealous
			faith = scope:random_jewish_faith
			culture = culture:bavlim
			gender_female_chance = {
				if = {
					limit = { scope:random_jewish_faith = { has_doctrine = doctrine_gender_male_dominated } }
					add = 0
				}
				else_if = {
					limit = { scope:random_jewish_faith = { has_doctrine = doctrine_gender_female_dominated } }
						add = 100
				}
				else = {
					add = 50
				}
			}
			martial = { 4 9 }
			diplomacy = { 4 9 }
			stewardship = { 4 9 }
			intrigue = { 4 9 }
			learning = { 4 9 }
			employer = root

			after_creation = {
				add_trait_xp = {
					trait = achaemenid_historian
					track = cyrus
					value = 100
				}
				add_character_flag = blocked_from_leaving
			}
		}

		create_character = { #samaritan leader
			save_scope_as = samaritan_leader
			age = { 21 35 }
			random_traits_list = {
				count = 1
				education_martial_5 = {}
				education_stewardship_5 = {}
				education_learning_5 = {}
				education_intrigue_5 = {}
				education_diplomacy_5 = {}
			}
			random_traits = yes
			trait = achaemenid_historian
			trait = zealous
			faith = scope:random_samaritan_faith
			culture = culture:bavlim
			gender_female_chance = {
				if = {
					limit = { scope:random_samaritan_faith = { has_doctrine = doctrine_gender_male_dominated } }
					add = 0
				}
				else_if = {
					limit = { scope:random_samaritan_faith = { has_doctrine = doctrine_gender_female_dominated } }
						add = 100
				}
				else = {
					add = 50
				}
			}
			martial = { 4 9 }
			diplomacy = { 4 9 }
			stewardship = { 4 9 }
			intrigue = { 4 9 }
			learning = { 4 9 }
			employer = root

			after_creation = {
				add_trait_xp = {
					trait = achaemenid_historian
					track = cyrus
					value = 100
				}
				add_character_flag = blocked_from_leaving
			}
		}
		add_character_flag = recent_cyrus_legend_event
	}

	option = { #side with the Rabbinic leader
		name = achaemenid_legend_event.0029.a

		add_pressed_claim = title:k_jerusalem
		add_pressed_claim = title:d_palestine
		add_pressed_claim = title:d_urdunn
		add_pressed_claim = title:d_oultrejourdain

		scope:samaritan_leader = {
			move_to_pool = yes
			set_relation_rival = root
		}

		scope:jewish_leader = {
			set_relation_friend = root
			add_character_flag = favored_leader
		}

		promoted_legend = {
			add_legend_owner_modifier = favoring_jewish_zionism
		}
	}

	option = { #side with the Samaritan leader
		name = achaemenid_legend_event.0029.b

		add_pressed_claim = title:k_jerusalem
		add_pressed_claim = title:d_palestine
		add_pressed_claim = title:d_urdunn
		add_pressed_claim = title:d_oultrejourdain

		scope:jewish_leader = {
			move_to_pool = yes
			set_relation_rival = root
		}

		scope:samaritan_leader = {
			set_relation_friend = root
			add_character_flag = favored_leader
		}

		promoted_legend = {
			add_legend_owner_modifier = favoring_samaritan_zionism
		}
	}
}

achaemenid_legend_event.0030 = { #you've taken Jerusalem for the Jews
	type = character_event
	title = achaemenid_legend_event.0030.t
	desc = achaemenid_legend_event.0030.desc
	left_portrait = {
		character = root
		animation = sword_coup_degrace
	}
	right_portrait = {
		character = scope:usurper_jerusalem
		animation = happiness
	}

	theme = legend

	trigger = {
		exists = promoted_legend
		is_adult = yes
		promoted_legend = {
			legend_owner = root
			legend_type = legend_type:cyrus
		}
		completely_controls = title:d_oultrejourdain 
        completely_controls = title:d_palestine
        completely_controls = title:d_urdunn
		NOT = {
			has_global_variable = cyrus_legend_jerusalem_reclaimed
		}
	}

	immediate = {
		IF = {
			limit = {
				any_courtier_or_guest = {
					has_character_flag = favored_leader
				}
			}
			random_courtier_or_guest = {
				limit = {
					has_character_flag = favored_leader
				}
				save_scope_as = usurper_jerusalem
			}
		}
		IF = { #if you circumvented the previous event, this is a fallback
			limit = {
				NOT = {
					any_courtier_or_guest = {
						has_character_flag = favored_leader
					}
				}
			}
			religion:judaism_religion = {
				random_faith = {
					limit = {
						OR = {
							has_doctrine = temple_authority_rabbinic_doctrine
							has_doctrine = temple_authority_toric_doctrine
							has_doctrine = temple_authority_kohanim_doctrine
						}
					}
					save_scope_as = random_jewish_faith
				}
			}
			religion:judaism_religion = {
				random_faith = {
					limit = {
						has_doctrine = temple_authority_samaritan_torah_doctrine
					}
					save_scope_as = random_samaritan_faith
				}
			}
			create_character = { #rabbinic leader
				save_scope_as = jewish_leader
				age = { 21 35 }
				random_traits_list = {
					count = 1
					education_martial_5 = {}
					education_stewardship_5 = {}
					education_learning_5 = {}
					education_intrigue_5 = {}
					education_diplomacy_5 = {}
				}
				random_traits = yes
				trait = achaemenid_historian
				trait = zealous
				faith = scope:random_jewish_faith
				culture = culture:bavlim
				gender_female_chance = {
					if = {
						limit = { scope:jewish_leader.faith = { has_doctrine = doctrine_gender_male_dominated } }
						add = 0
					}
					else_if = {
						limit = { scope:jewish_leader.faith = { has_doctrine = doctrine_gender_female_dominated } }
							add = 100
					}
					else = {
						add = 50
					}
				}
				martial = { 4 9 }
				diplomacy = { 4 9 }
				stewardship = { 4 9 }
				intrigue = { 4 9 }
				learning = { 4 9 }
				employer = root

				after_creation = {
					add_trait_xp = {
						trait = achaemenid_historian
						track = cyrus
						value = 100
					}
					save_scope_as = usurper_jerusalem
					add_character_flag = blocked_from_leaving
				}
			}
			root = {
				save_scope_as = new_messiah
			}
			set_global_variable = {
				name = cyrus_legend_jerusalem_reclaimed
				value = yes
			}
		}
	}

	option = { #give it to them, they make you their HoF
		name = achaemenid_legend_event.0030.a

		custom_tooltip = {
			text = make_cyrus_messiah_tooltip
			religion:judaism_religion = {
				create_dynamic_temporal_hof_title_cyrus_legend = yes
			}
		}

		create_title_and_vassal_change = {
			type = usurped
			save_scope_as = change
			add_claim_on_loss = no
		}

		title:k_jerusalem = {
			change_title_holder = {
				holder = scope:usurper_jerusalem
				change = scope:change
			}
		}
		title:d_palestine = {
			change_title_holder = {
				holder = scope:usurper_jerusalem
				change = scope:change
			}
		}
		title:d_oultrejourdain = {
			change_title_holder = {
				holder = scope:usurper_jerusalem
				change = scope:change
			}
		}
		title:d_urdunn = {
			change_title_holder = {
				holder = scope:usurper_jerusalem
				change = scope:change
			}
		}
		title:c_jerusalem = {
			set_county_faith = scope:usurper_jerusalem.faith
			change_title_holder = {
				holder = scope:usurper_jerusalem
				change = scope:change
			}
		}
		title:c_kerak = {
			change_title_holder = {
				holder = scope:usurper_jerusalem
				change = scope:change
			}
		}
		title:c_negev = {
			change_title_holder = {
				holder = scope:usurper_jerusalem
				change = scope:change
			}
		}
		title:c_ghazza = {
			change_title_holder = {
				holder = scope:usurper_jerusalem
				change = scope:change
			}
		}
		title:c_jaffa = {
			change_title_holder = {
				holder = scope:usurper_jerusalem
				change = scope:change
			}
		}
		title:c_tiberias = {
			change_title_holder = {
				holder = scope:usurper_jerusalem
				change = scope:change
			}
		}
		title:c_acre = {
			change_title_holder = {
				holder = scope:usurper_jerusalem
				change = scope:change
			}
		}
		title:c_irbid = {
			change_title_holder = {
				holder = scope:usurper_jerusalem
				change = scope:change
			}
		}
		scope:usurper_jerusalem = {
			change_liege_or_become_independent = {
				CHANGE = scope:change
				VASSAL = this
			}
		}
		resolve_title_and_vassal_change = scope:change

		custom_tooltip = {
			text = jerusalem_conversion_cyrus_legend_tooltip
			title:k_jerusalem = {
				every_in_de_jure_hierarchy = {
					random = {
						chance = 33
						set_county_culture = culture:bavlim
						set_county_faith = scope:usurper_jerusalem.faith
					}
				}
			}
		}
	}

	option = { #give it to them, but don't become the messiah
		name = achaemenid_legend_event.0030.b

		title:k_jerusalem = {
			change_title_holder = {
				holder = scope:usurper_jerusalem
				change = scope:change
			}
		}
		title:d_palestine = {
			change_title_holder = {
				holder = scope:usurper_jerusalem
				change = scope:change
			}
		}
		title:d_oultrejourdain = {
			change_title_holder = {
				holder = scope:usurper_jerusalem
				change = scope:change
			}
		}
		title:d_urdunn = {
			change_title_holder = {
				holder = scope:usurper_jerusalem
				change = scope:change
			}
		}
		title:c_jerusalem = {
			set_county_faith = scope:usurper_jerusalem.faith
			change_title_holder = {
				holder = scope:usurper_jerusalem
				change = scope:change
			}
		}
		title:c_kerak = {
			change_title_holder = {
				holder = scope:usurper_jerusalem
				change = scope:change
			}
		}
		title:c_negev = {
			change_title_holder = {
				holder = scope:usurper_jerusalem
				change = scope:change
			}
		}
		title:c_ghazza = {
			change_title_holder = {
				holder = scope:usurper_jerusalem
				change = scope:change
			}
		}
		title:c_jaffa = {
			change_title_holder = {
				holder = scope:usurper_jerusalem
				change = scope:change
			}
		}
		title:c_tiberias = {
			change_title_holder = {
				holder = scope:usurper_jerusalem
				change = scope:change
			}
		}
		title:c_acre = {
			change_title_holder = {
				holder = scope:usurper_jerusalem
				change = scope:change
			}
		}
		title:c_irbid = {
			change_title_holder = {
				holder = scope:usurper_jerusalem
				change = scope:change
			}
		}
		scope:usurper_jerusalem = {
			change_liege_or_become_independent = {
				CHANGE = scope:change
				VASSAL = this
			}
		}
		resolve_title_and_vassal_change = scope:change

		custom_tooltip = {
			text = jerusalem_conversion_cyrus_legend_tooltip
			title:k_jerusalem = {
				every_in_de_jure_hierarchy = {
					random = {
						chance = 33
						set_county_culture = culture:bavlim
						set_county_faith = scope:usurper_jerusalem.faith
					}
				}
			}
		}
	}

	option = { #keep jerusalem, but become Jewish
		name = achaemenid_legend_event.0030.c

		custom_tooltip = {
			text = jerusalem_conversion_keep_cyrus_legend_tooltip
			title:k_jerusalem = {
				every_in_de_jure_hierarchy = {
					random = {
						chance = 33
						set_county_culture = culture:bavlim
						set_county_faith = scope:usurper_jerusalem.faith
					}
				}
			}
		}
		set_character_faith_with_conversion = scope:usurper_jerusalem.faith
	}

	option = { #betray the Jews
		name = achaemenid_legend_event.0030.d

		scope:usurper_jerusalem = {
			set_relation_rival = root
			add_pressed_claim = title:k_jerusalem
			add_pressed_claim = title:d_palestine
			add_pressed_claim = title:d_urdunn
			add_pressed_claim = title:d_oultrejourdain
			move_to_pool = yes
		}
	}
}

achaemenid_legend_event.0031 = { #recruiting a jewish minority
	type = character_event
	title = achaemenid_legend_event.0031.t
	desc = achaemenid_legend_event.0031.desc
	left_portrait = scope:jewish_minority_steward
	right_portrait = scope:jewish_minority_diplomat
	lower_left_portrait = scope:jewish_minority_marshall
	lower_center_portrait = scope:jewish_minority_scholar
	lower_right_portrait = scope:jewish_minority_spymaster

	theme = court

	immediate = { #generate characters
		create_character = { #diplomat 
			save_scope_as = jewish_minority_diplomat
			age = { 21 35 }
			random_traits_list = {
				count = 1
				education_diplomacy_5 = {}
			}
			random_traits = yes
			trait = achaemenid_historian
			faith = title:c_jerusalem.faith
			culture = title:c_jerusalem.culture
			gender_female_chance = {
				if = {
					limit = { title:c_jerusalem.faith = { has_doctrine = doctrine_gender_male_dominated } }
					add = 0
				}
				else_if = {
					limit = { title:c_jerusalem.faith = { has_doctrine = doctrine_gender_female_dominated } }
						add = 100
				}
				else = {
					add = 50
				}
			}
			martial = { 4 9 }
			diplomacy = { 4 9 }
			stewardship = { 4 9 }
			intrigue = { 4 9 }
			learning = { 4 9 }
			trait = loyal
			employer = root
		}
		create_character = { #marshall
			save_scope_as = jewish_minority_marshall
			age = { 21 35 }
			random_traits_list = {
				count = 1
				education_martial_5 = {}
			}
			random_traits = yes
			trait = achaemenid_historian
			faith = title:c_jerusalem.faith
			culture = title:c_jerusalem.culture
			gender_female_chance = {
				if = {
					limit = { title:c_jerusalem.faith = { has_doctrine = doctrine_gender_male_dominated } }
					add = 0
				}
				else_if = {
					limit = { title:c_jerusalem.faith = { has_doctrine = doctrine_gender_female_dominated } }
						add = 100
				}
				else = {
					add = 50
				}
			}
			martial = { 4 9 }
			diplomacy = { 4 9 }
			stewardship = { 4 9 }
			intrigue = { 4 9 }
			learning = { 4 9 }
			trait = loyal
			employer = root
		}
		create_character = { #steward
			save_scope_as = jewish_minority_steward
			age = { 21 35 }
			random_traits_list = {
				count = 1
				education_stewardship_5 = {}
			}
			random_traits = yes
			trait = achaemenid_historian
			faith = title:c_jerusalem.faith
			culture = title:c_jerusalem.culture
			gender_female_chance = {
				if = {
					limit = { title:c_jerusalem.faith = { has_doctrine = doctrine_gender_male_dominated } }
					add = 0
				}
				else_if = {
					limit = { title:c_jerusalem.faith = { has_doctrine = doctrine_gender_female_dominated } }
						add = 100
				}
				else = {
					add = 50
				}
			}
			martial = { 4 9 }
			diplomacy = { 4 9 }
			stewardship = { 4 9 }
			intrigue = { 4 9 }
			learning = { 4 9 }
			trait = loyal
			employer = root
		}
		create_character = { #intrigue
			save_scope_as = jewish_minority_spymaster
			age = { 21 35 }
			random_traits_list = {
				count = 1
				education_intrigue_5 = {}
			}
			random_traits = yes
			trait = achaemenid_historian
			faith = title:c_jerusalem.faith
			culture = title:c_jerusalem.culture
			gender_female_chance = {
				if = {
					limit = { title:c_jerusalem.faith = { has_doctrine = doctrine_gender_male_dominated } }
					add = 0
				}
				else_if = {
					limit = { title:c_jerusalem.faith = { has_doctrine = doctrine_gender_female_dominated } }
						add = 100
				}
				else = {
					add = 50
				}
			}
			martial = { 4 9 }
			diplomacy = { 4 9 }
			stewardship = { 4 9 }
			intrigue = { 4 9 }
			learning = { 4 9 }
			trait = loyal
			employer = root
		}
		create_character = { #scholar 
			save_scope_as = jewish_minority_scholar
			age = { 21 35 }
			random_traits_list = {
				count = 1
				education_learning_5 = {}
			}
			random_traits = yes
			trait = achaemenid_historian
			faith = title:c_jerusalem.faith
			culture = title:c_jerusalem.culture
			gender_female_chance = {
				if = {
					limit = { title:c_jerusalem.faith = { has_doctrine = doctrine_gender_male_dominated } }
					add = 0
				}
				else_if = {
					limit = { title:c_jerusalem.faith = { has_doctrine = doctrine_gender_female_dominated } }
						add = 100
				}
				else = {
					add = 50
				}
			}
			martial = { 4 9 }
			diplomacy = { 4 9 }
			stewardship = { 4 9 }
			intrigue = { 4 9 }
			learning = { 4 9 }
			trait = loyal
			employer = root
		}
	}

	option = { #recruit the diplomat
		name = achaemenid_legend_event.0031.a

		custom_tooltip = {
			text = recruit_diplomat_jewish_event_tooltip
			scope:jewish_minority_marshall = {
				death = {
					death_reason = death_vanished
				}
			}
			scope:jewish_minority_scholar = {
				death = {
					death_reason = death_vanished
				}
			}
			scope:jewish_minority_spymaster = {
				death = {
					death_reason = death_vanished
				}
			}
			scope:jewish_minority_steward = {
				death = {
					death_reason = death_vanished
				}
			}
		}
	}

	option = { #recruit the marshall
		name = achaemenid_legend_event.0031.b

		custom_tooltip = {
			text = recruit_marshall_jewish_event_tooltip
			scope:jewish_minority_diplomat = {
				death = {
					death_reason = death_vanished
				}
			}
			scope:jewish_minority_scholar = {
				death = {
					death_reason = death_vanished
				}
			}
			scope:jewish_minority_spymaster = {
				death = {
					death_reason = death_vanished
				}
			}
			scope:jewish_minority_steward = {
				death = {
					death_reason = death_vanished
				}
			}
		}
	}

	option = { #recruit the steward
		name = achaemenid_legend_event.0031.c

		custom_tooltip = {
			text = recruit_steward_jewish_event_tooltip
			scope:jewish_minority_diplomat = {
				death = {
					death_reason = death_vanished
				}
			}
			scope:jewish_minority_scholar = {
				death = {
					death_reason = death_vanished
				}
			}
			scope:jewish_minority_spymaster = {
				death = {
					death_reason = death_vanished
				}
			}
			scope:jewish_minority_marshall = {
				death = {
					death_reason = death_vanished
				}
			}	
		}
	}

	option = { #recruit the spymaster
		name = achaemenid_legend_event.0031.d

		custom_tooltip = {
			text = recruit_spymaster_jewish_event_tooltip
			scope:jewish_minority_diplomat = {
				death = {
					death_reason = death_vanished
				}
			}
			scope:jewish_minority_scholar = {
				death = {
					death_reason = death_vanished
				}
			}
			scope:jewish_minority_steward = {
				death = {
					death_reason = death_vanished
				}
			}
			scope:jewish_minority_marshall = {
				death = {
					death_reason = death_vanished
				}
			}
		}
	}

	option = { #recruit the scholar
		name = achaemenid_legend_event.0031.e

		custom_tooltip = {
			text = recruit_scholar_jewish_event_tooltip
			scope:jewish_minority_diplomat = {
				death = {
					death_reason = death_vanished
				}
			}
			scope:jewish_minority_spymaster = {
				death = {
					death_reason = death_vanished
				}
			}
			scope:jewish_minority_steward = {
				death = {
					death_reason = death_vanished
				}
			}
			scope:jewish_minority_marshall = {
				death = {
					death_reason = death_vanished
				}
			}
		}
	}
}
