﻿spawn_darius_legend_effect = {
	send_interface_toast = {
		title = darius_legend_spawn_toast
		left_icon = scope:root
		create_legend_seed = {
			type = darius
			quality = famed
			chronicle = darius_chronicle
			properties = {
				ancestor_flag = flag:darius
				title = root.capital_county
			}
		}
	}
}

darius_legend_complete_effect_famed = {
	add_character_modifier = supposed_achaemenid_modifier
}

darius_legend_complete_effect_illustrious = {
	add_character_modifier = proposed_achaemenid_modifier
}

darius_legend_complete_effect_mythical = {
	add_character_modifier = definite_achaemenid_modifier
}

add_darius_tradition_to_culture = {
	root.culture = {
		add_culture_tradition = tradition_darius_legacy
	}
}

mythical_achaemenid_decision_scripted_effect = {
	spawn_army = {
		location = root.capital_province
		name = darius_summoned_army
		men_at_arms = {
			type = immortals
			stacks = 5
		}
		men_at_arms = {
			type = composite_bowmen
			stacks = 10
		}
		men_at_arms = {
			type = mangonel
			stacks = 5
		}
		uses_supply = yes
		inheritable = no
	}
	create_character = {
		save_scope_as = legendary_general_achaemenid
		age = { 21 42 }
		random_traits = yes
		trait = education_martial_5
		trait = immortal_commander_trait
		culture = root.culture
		faith = root.faith
		gender = male
		employer = root
		martial = { 16 24 }
		prowess = { 12 20 }

		after_creation = {
			random = {
				chance = 50
				add_trait = physique_good_2
			}
		}
	}
	send_interface_toast = {
		title = legendary_general_achaemenid_toast
		left_icon = scope:legendary_general_achaemenid
	}
}

spawn_immortal_legend_effect = {
	send_interface_toast = {
		title = immortal_legend_spawn_toast
		left_icon = scope:root
		create_legend_seed = {
			type = cyrus
			quality = famed
			chronicle = immortal_chronicle
			properties = {
				ancestor_flag = flag:immortal
			}
		}
	}
}

immortal_legend_famed_scripted_effect = {
	add_character_modifier = immortal_famed_maa_recruitment_modifier
}

add_immortal_tradition_to_culture = {
	root.culture = {
		add_culture_tradition = tradition_immortals
	}
}
immortal_legend_illustrious_scripted_effect = {
	add_character_modifier = immortal_illustrious_maa_recruitment_modifier
}
immortal_legend_mythical_scripted_effect = {
	add_character_modifier = immortal_mythical_maa_recruitment_modifier
}

illustrious_immortal_decision_scripted_effect = {
#incerase prowess of knights, gain knight capacity, add blademaster, and blademaster XP
#add custom commander trait to ruler + highest prowess knight maybe martial instead knight_limit
#this effect was moved to the event instead, but is here for reference
#	every_courtier = { #permanent prowess increase
#		limit = {
#			is_knight_of = root
#		}
#		add_prowess_skill = 2
#	}
#
#	every_courtier = {
#		limit = {
#			is_knight_of = root
#			prowess >= 12
#		}
#		add_trait = lifestyle_blademaster
#	}
#
#	every_courtier = {
#		limit = {
#			is_knight_of = root
#			has_trait = lifestyle_blademaster
#		}
#		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
#		}
#		add_trait = lifestyle_blademaster
#	}
#
#	every_vassal = {
#		limit = {
#			is_knight_of = root
#			has_trait = lifestyle_blademaster
#		}
#		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
#	}
#	
#	every_vassal = {
#		limit = {
#			has_council_position = councillor_marshal
#		}
#		add_trait = immortal_commander_trait
#	}
#	
	#councillor_marshal = {
	#	add_trait = immortal_commander_trait
	#}
}

spawn_zoroaster_legend_effect = {
	send_interface_toast = {
		title = zoroaster_legend_spawn_toast
		left_icon = scope:root
		create_legend_seed = {
			type = zoroaster
			quality = famed
			chronicle = zoroaster_chronicle
			properties = {
				ancestor_flag = flag:zoroaster
				religion = religion:zoroastrianism_religion
			}
		}
	}
}

zoroaster_legend_complete_effect_famed = {
	add_character_modifier = zoroaster_legend_famed_complete_modifier
}

zoroaster_legend_complete_effect_illustrious = {
	add_character_modifier = zoroaster_legend_illustrious_complete_modifier
}

zoroaster_legend_complete_effect_mythical = {
	add_character_modifier = zoroaster_legend_mythical_complete_modifier
}

zoroaster_legend_complete_mystic_trait_add = {
	add_trait = lifestyle_mystic
	add_trait_xp = {
		trait = lifestyle_mystic
		value = 25
	}
}

zoroaster_legend_complete_mystic_trait_add_illustrious = {
	add_trait = lifestyle_mystic
	add_trait_xp = {
		trait = lifestyle_mystic
		value = 50
	}
}

zoroaster_legend_complete_mystic_trait_add_mythical = {
	add_trait = lifestyle_mystic
	add_trait_xp = {
		trait = lifestyle_mystic
		value = 100
	}
}

zoroaster_legend_complete_pure_blooded_add_effect_mythical = {
	add_trait = pure_blooded
	random = {
		chance = {
			value = 33
		}
		add_trait = beauty_good_3
	}
	random = {
		chance = {
			value = 33
		}
		add_trait = intellect_good_3
	}
	random = {
		chance = {
			value = 34
		}
		add_trait = physique_good_3
	}
	every_child = {
		limit = {
			dynasty = root.dynasty
		}
		add_trait = pure_blooded
		random = {
			chance = {
				value = 33
			}
			add_trait = beauty_good_3
		}
		random = {
			chance = {
				value = 33
			}
			add_trait = intellect_good_3
		}
		random = {
			chance = {
				value = 34
			}
			add_trait = physique_good_3
		}
	}
}

add_zoroaster_tradition_to_culture = {
	root.culture = {
		add_culture_tradition = tradition_zoroaster_blessing
	}
}

spawn_amastris_legend_effect = {
	send_interface_toast = {
		title = amastris_legend_spawn_toast
		left_icon = scope:root
		create_legend_seed = {
			type = amastris
			quality = famed
			chronicle = amastris_chronicle
			properties = {
				ancestor_flag = flag:amastris
			}
		}
	}
}

amastris_legend_complete_famed_reward = {
	add_character_modifier = amastris_legend_complete_famed_reward_modifier
}

amastris_legend_complete_add_trait_effect_reward = {
	add_trait = overseer
}

amastris_legend_complete_illustrious_reward = {
	add_character_modifier = amastris_legend_complete_illustrious_reward_modifier
}

amastris_legend_complete_illustrious_reward_decision = {
	add_character_flag = can_use_amastris_decision
}

amastris_legend_complete_mythical_reward = {
	add_character_modifier = amastris_legend_complete_mythical_reward_modifier
}

amastris_legend_complete_add_trait_effect_reward_mythical = {
	add_trait = overseer
	every_child = {
		limit = {
			dynasty = root.dynasty
		}
		add_trait = overseer
	}
}

amastris_legend_complete_mythical_reward_iranian_assimilation = {
	root.dynasty = {
		add_dynasty_modifier = is_assimilated_to_iranian_heritage_modifier
	}
}

add_amastris_tradition_to_culture = {
	root.culture = {
		add_culture_tradition = tradition_amastris_legacy
	}
}

spawn_cyrus_legend_effect = {
	send_interface_toast = {
		title = cyrus_legend_spawn_toast
		left_icon = scope:root
		create_legend_seed = {
			type = cyrus
			quality = famed
			chronicle = cyrus_chronicle
			properties = {
				ancestor_flag = flag:cyrus
				title = root.capital_county
			}
		}
	}
}

cyrus_legend_complete_effect_famed = {
	add_character_modifier = cyrus_legend_complete_effect_famed_modifier
}

cyrus_legend_complete_effect_illustrious = {
	add_character_modifier = cyrus_legend_complete_effect_illustrious_modifier
}

cyrus_legend_complete_illustrious_trait_reward = {
	add_trait = avaricious
}

cyrus_legend_complete_effect_mythical = {
	add_character_modifier = cyrus_legend_complete_effect_mythical_modifier
}

cyrus_legend_mythical_vassal_trait_reward = {
	every_vassal = {
		add_trait = loyal
		remove_trait = disloyal
		every_child = {
			add_trait = loyal
			remove_trait = disloyal
		}
	}
}

add_cyrus_tradition_to_culture = {
	root.culture = {
		add_culture_tradition = tradition_personalized_taxation
	}
}

#offer_satrap_status_effect = {
#	change_government = satrap
#}

mark_historical_legend_as_done_achaemenid = {
	if = {
		limit = {
			legend_property:ancestor_flag = flag:darius_achaemenid
		}
		set_global_variable = {
			name = darius_legend
			value = yes
		}
	}
	else_if = {
		limit = {
			legend_property:ancestor_flag = flag:immortal_achaemenid
		}
		set_global_variable = {
			name = immortal_legend
			value = yes
		}
	}
	else_if = {
		limit = {
			legend_property:ancestor_flag = flag:zoroaster
		}
		set_global_variable = {
			name = zoroaster_legend
			value = yes
		}
	}
	else_if = {
		limit = {
			legend_property:ancestor_flag = flag:amastris
		}
		set_global_variable = {
			name = amastris_legend
			value = yes
		}
	}
	else_if = {
		limit = {
			legend_property:ancestor_flag = flag:cyrus
		}
		set_global_variable = {
			name = cyrus_legend
			value = yes
		}
	}
}
		
create_dynamic_temporal_hof_title_cyrus_legend = {
	create_dynamic_title = {
		tier = kingdom
		name = the_messiah_hof_title
	}
	create_title_and_vassal_change = {
		type = created
		save_scope_as = change
		add_claim_on_loss = no
	}
	scope:new_title = {
		set_destroy_if_invalid_heir = yes
		set_definitive_form = yes
		set_landless_title = yes
		change_title_holder = {
			holder = root
			change = scope:change
		}
		generate_coa = religious_title
	}
	resolve_title_and_vassal_change = scope:change
	root.faith = {
		add_doctrine = special_doctrine_messiah_tolerance_doctrine_judaism_target
	}
	scope:usurper_jerusalem.faith = {
		if = {
			limit = {
				has_doctrine = special_doctrine_not_allowed_to_hof
			}
			remove_doctrine = special_doctrine_not_allowed_to_hof
		}
		remove_doctrine = doctrine_no_head
		remove_doctrine = doctrine_theocracy_temporal
		remove_doctrine = doctrine_clerical_succession_spiritual_appointment
		add_doctrine = doctrine_temporal_head
		add_doctrine = doctrine_theocracy_lay_clergy
		add_doctrine = doctrine_clerical_succession_temporal_fixed_appointment
		add_doctrine = special_doctrine_messiah_tolerance_doctrine_judaism
		set_religious_head_title = scope:new_title
	}
	every_faith = {
		limit = {
			has_doctrine = special_doctrine_is_jewish_faith
			NOT = {
				has_doctrine = temple_authority_samaritan_torah_doctrine
			}
		}
		if = {
			limit = {
				has_doctrine = special_doctrine_not_allowed_to_hof
			}
			remove_doctrine = special_doctrine_not_allowed_to_hof
		}
		remove_doctrine = doctrine_no_head
		remove_doctrine = doctrine_theocracy_temporal
		remove_doctrine = doctrine_clerical_succession_spiritual_appointment
		add_doctrine = doctrine_temporal_head
		add_doctrine = doctrine_theocracy_lay_clergy
		add_doctrine = doctrine_clerical_succession_temporal_fixed_appointment
		add_doctrine = special_doctrine_messiah_tolerance_doctrine_judaism
		set_religious_head_title = scope:new_title
	}
}

create_dynamic_temporal_hof_title_cyrus_legend_samaritan = {
	create_dynamic_title = {
		tier = kingdom
		name = the_messiah_hof_title
	}
	create_title_and_vassal_change = {
		type = created
		save_scope_as = change
		add_claim_on_loss = no
	}
	scope:new_title = {
		set_destroy_if_invalid_heir = yes
		set_definitive_form = yes
		set_landless_title = yes
		change_title_holder = {
			holder = scope:new_messiah
			change = scope:change
		}
		generate_coa = religious_title
	}
	resolve_title_and_vassal_change = scope:change
	root.faith = {
		add_doctrine = special_doctrine_messiah_tolerance_doctrine_judaism_target
	}
	scope:usurper_jerusalem.faith = {
		if = {
			limit = {
				has_doctrine = special_doctrine_not_allowed_to_hof
			}
			remove_doctrine = special_doctrine_not_allowed_to_hof
		}
		remove_doctrine = doctrine_no_head
		remove_doctrine = doctrine_theocracy_temporal
		remove_doctrine = doctrine_clerical_succession_spiritual_appointment
		add_doctrine = doctrine_temporal_head
		add_doctrine = doctrine_theocracy_lay_clergy
		add_doctrine = doctrine_clerical_succession_temporal_fixed_appointment
		add_doctrine = special_doctrine_messiah_tolerance_doctrine_judaism
		set_religious_head_title = scope:new_title
	}
	every_faith = {
		limit = {
			has_doctrine = temple_authority_samaritan_torah_doctrine
		}
		if = {
			limit = {
				has_doctrine = special_doctrine_not_allowed_to_hof
			}
			remove_doctrine = special_doctrine_not_allowed_to_hof
		}
		remove_doctrine = doctrine_no_head
		remove_doctrine = doctrine_theocracy_temporal
		remove_doctrine = doctrine_clerical_succession_spiritual_appointment
		add_doctrine = doctrine_temporal_head
		add_doctrine = doctrine_theocracy_lay_clergy
		add_doctrine = doctrine_clerical_succession_temporal_fixed_appointment
		add_doctrine = special_doctrine_messiah_tolerance_doctrine_judaism
		set_religious_head_title = scope:new_title
	}
}
	
	
	
	