﻿namespace = ce1_decision_events

#Legend Book Commision
ce1_decision_events.0001 = { #by Veronica Pazos
	type = character_event
	title = ce1_decision_events.0001.t
	desc = ce1_decision_events.0001.desc
	theme = legend
	override_background = { reference = study }
	left_portrait = {
		character = root
		animation = personality_honorable
	}
	right_portrait = {
		character = scope:chronicler
		animation = writing
	}
	artifact = {
		target = scope:newly_created_artifact
		position = lower_center_portrait
	}
	override_effect_2d = {
		reference = legend_glow
	}

	immediate = {
		play_music_cue = "mx_cue_positive_effect"
		hidden_effect_new_object = {
			if = {
				limit = {
					has_variable = finished_mythical_legend_var
				}
				if = {
					limit = {
						artifacts_use_indian_books_trigger = yes
					}
					create_artifact = {
						name = legend_book
						type = chronicle
						creator = scope:chronicler
						description = legend_book_desc 
						visuals = indian_book
						modifier = artifact_diplomacy_3_modifier
						modifier = artifact_monthly_prestige_add_8_modifier
						save_scope_as = newly_created_artifact
						wealth = 400
						quality = 400
					}
				}
				else = {
					create_artifact = {
						name = legend_book
						type = chronicle
						creator = scope:chronicler
						description = legend_book_desc 
						visuals = chronicle
						modifier = artifact_diplomacy_3_modifier
						modifier = artifact_monthly_prestige_add_8_modifier
						save_scope_as = newly_created_artifact
						wealth = 400
						quality = 400
					}
				}
			}
			else_if = {
				limit = {
					has_variable = finished_illustrious_legend_var
				}
				if = {
					limit = {
						artifacts_use_indian_books_trigger = yes
					}
					create_artifact = {
						name = legend_book
						type = chronicle
						creator = scope:chronicler
						description = legend_book_desc 
						visuals = indian_book
						modifier = artifact_diplomacy_2_modifier
						modifier = artifact_monthly_prestige_add_6_modifier
						save_scope_as = newly_created_artifact
						wealth = 200
						quality = 200
					}
				}
				else = {
					create_artifact = {
						name = legend_book
						type = chronicle
						creator = scope:chronicler
						description = legend_book_desc 
						visuals = chronicle
						modifier = artifact_diplomacy_2_modifier
						modifier = artifact_monthly_prestige_add_6_modifier
						save_scope_as = newly_created_artifact
						wealth = 200
						quality = 200
					}
				}
			}
			else = { #famed
				if = {
					limit = {
						artifacts_use_indian_books_trigger = yes
					}
					create_artifact = {
						name = legend_book
						type = miscellaneous
						creator = scope:chronicler
						description = legend_book_desc 
						visuals = indian_book
						modifier = artifact_diplomacy_1_modifier
						modifier = artifact_monthly_prestige_add_4_modifier
						save_scope_as = newly_created_artifact
						wealth = 80
						quality = 80
					}
				}
				else = {
					create_artifact = {
						name = legend_book
						type = miscellaneous
						creator = scope:chronicler
						description = legend_book_desc 
						visuals = chronicle
						modifier = artifact_diplomacy_1_modifier
						modifier = artifact_monthly_prestige_add_4_modifier
						save_scope_as = newly_created_artifact
						wealth = 80
						quality = 80
					}
				}
			}
		}
		hidden_effect = {
			scope:newly_created_artifact = {
				if = {
					limit = {
						root = {
							has_variable = finished_heroic_legend_var
						}
					}
					if = {
						limit = {
							root = {
								has_variable = finished_mythical_legend_var
							}
						}
						add_artifact_modifier = artifact_martial_3_modifier
					}
					else_if = {
						limit = {
							root = {
								has_variable = finished_illustrious_legend_var
							}
						}
						add_artifact_modifier = artifact_martial_2_modifier
						add_artifact_modifier = artifact_monthly_prestige_add_6_modifier
					}
					else = {
						add_artifact_modifier = artifact_martial_1_modifier
					}
				}
				else_if = {
					limit = {
						root = {
							has_variable = finished_holy_legend_var
						}
					}
					if = {
						limit = {
							root = {
								has_variable = finished_mythical_legend_var
							}
						}
						add_artifact_modifier = artifact_learning_3_modifier
					}
					else_if = {
						limit = {
							root = {
								has_variable = finished_illustrious_legend_var
							}
						}
						add_artifact_modifier = artifact_learning_2_modifier
					}
					else = {
						add_artifact_modifier = artifact_learning_1_modifier
					}
				}
				else_if = {
					limit = {
						root = {
							has_variable = finished_legitimizing_legend_var
						}
					}
					if = {
						limit = {
							root = {
								has_variable = finished_mythical_legend_var
							}
						}
						add_artifact_modifier = artifact_stewardship_3_modifier
					}
					else_if = {
						limit = {
							root = {
								has_variable = finished_illustrious_legend_var
							}
						}
						add_artifact_modifier = artifact_stewardship_2_modifier
					}
					else = {
						add_artifact_modifier = artifact_stewardship_1_modifier
					}
				}
			}
		}
	}

	option = { #nice
		name = ce1_decision_events.0001.a
		show_as_tooltip = {
			scope:newly_created_artifact = { set_owner = root }
		}
	}
	
	after = {
		remove_variable ?= finished_legend_var
		remove_variable ?= finished_famed_legend_var
		remove_variable ?= finished_illustrious_legend_var
		remove_variable ?= finished_mythical_legend_var
		remove_variable ?= finished_heroic_legend_var
		remove_variable ?= finished_holy_legend_var
		remove_variable ?= finished_legitimizing_legend_var
	}
}

#Legendary Kingdom Integration
#by James Beaumont
scripted_effect ce1_dec_1000_integrate = {
	# Empires are simple, just de-jure shift the kingdom
	if = {
		limit = {
			root.primary_title.tier = tier_empire
		}
		$KINGDOM$ = {
			set_de_jure_liege_title = root.primary_title
		}
	}
	# Hegemonies suck, find an empire within your hegemony that borders the kingdom
	else_if = {
		limit = {
			root.primary_title = {
				tier = tier_hegemony
				any_in_de_jure_hierarchy = {
					tier = tier_empire
					any_title_to_title_neighboring_and_across_water_kingdom = { this = $KINGDOM$ }
				}
			}
		}
		root.primary_title = {
			random_in_de_jure_hierarchy = {
				limit = {
					tier = tier_empire
					any_title_to_title_neighboring_and_across_water_kingdom = { this = $KINGDOM$ }
				}
				$KINGDOM$ = {
					set_de_jure_liege_title = prev
				}
			}
		}
	}
	# Kingdoms, de jure shift all duchies into your kingdom
	else = {
		$KINGDOM$ = {
			every_in_de_jure_hierarchy = {
				limit = { tier = tier_duchy }
				set_de_jure_liege_title = root.primary_title
			}
		}
	}
}
scripted_effect ce1_dec_1010_integrate = {
	# Kingdoms are simple, just de-jure shift the duchy
	if = {
		limit = {
			root.primary_title.tier = tier_kingdom
		}
		$DUCHY$ = {
			set_de_jure_liege_title = root.primary_title
		}
	}
	# Empires suck, find a kingdom within your empire that borders the duchy
	else_if = {
		limit = {
			root.primary_title = {
				any_in_de_jure_hierarchy = {
					tier = tier_kingdom
					any_title_to_title_neighboring_and_across_water_duchy = {
						this = $DUCHY$
					}
				}
			}
		}
		root.primary_title = {
			random_in_de_jure_hierarchy = {
				limit = {
					tier = tier_kingdom
					any_title_to_title_neighboring_and_across_water_duchy = {
						this = $DUCHY$
					}
				}
				$DUCHY$ = {
					set_de_jure_liege_title = prev
				}
			}
		}
	}
	# Empires suck, de-jure shift to your capital's kingdom
	else = {
		$DUCHY$ = {
			set_de_jure_liege_title = root.capital_county.kingdom
		}
	}
}
scripted_effect ce1_dec_1015_integrate = {
	# Hegemonies are simple, just de-jure shift the empire
	if = {
		limit = {
			root.primary_title.tier = tier_hegemony
		}
		$EMPIRE$ = {
			set_de_jure_liege_title = root.primary_title
		}
	}
	# Empires, de jure shift all kingdoms into your empire
	else = {
		$EMPIRE$ = {
			every_in_de_jure_hierarchy = {
				limit = { tier = tier_kingdom }
				set_de_jure_liege_title = root.primary_title
			}
		}
	}
}
ce1_decision_events.1000 = {
	type = character_event
	title = ce1_decision_events.1000.t
	desc = ce1_decision_events.1000.desc
	theme = legend
	left_portrait = {
		character = root
		animation = personality_honorable
	}
	override_background = { reference = throne_room }

	immediate = {
		play_music_cue = "mx_cue_positive_effect"
		ordered_realm_de_jure_kingdom = {
			limit = {
				valid_for_legendary_integration_k = yes
			}
			max = 6
			check_range_bounds = no
			if = {
				limit = { exists = scope:kingdom_05 }
				save_scope_as = kingdom_06
			}
			else_if = {
				limit = { exists = scope:kingdom_04 }
				save_scope_as = kingdom_05
			}
			else_if = {
				limit = { exists = scope:kingdom_03 }
				save_scope_as = kingdom_04
			}
			else_if = {
				limit = { exists = scope:kingdom_02 }
				save_scope_as = kingdom_03
			}
			else_if = {
				limit = { exists = scope:kingdom_01 }
				save_scope_as = kingdom_02
			}
			else = { save_scope_as = kingdom_01 }
		}
	}

	option = { #Kingdom 1 please
		name = {
			text = {
				first_valid = {
					triggered_desc = {
						trigger = {
							primary_title.tier = tier_empire
						}
						desc = ce1_decision_events.1000.a.empire
					}
					desc = ce1_decision_events.1000.a.kingdom
				}
			}
		}
		trigger = {
			exists = scope:kingdom_01
		}
		ce1_dec_1000_integrate = {
			KINGDOM = scope:kingdom_01
		}
		ai_chance = {
			base = 10
		}
	}

	option = { #Kingdom 2 please
		name = {
			text = {
				first_valid = {
					triggered_desc = {
						trigger = {
							primary_title.tier = tier_empire
						}
						desc = ce1_decision_events.1000.b.empire
					}
					desc = ce1_decision_events.1000.b.kingdom
				}
			}
		}
		trigger = {
			exists = scope:kingdom_02
		}
		ce1_dec_1000_integrate = {
			KINGDOM = scope:kingdom_02
		}
		ai_chance = {
			base = 10
		}
	}

	option = { #Kingdom 3 please
		name = {
			text = {
				first_valid = {
					triggered_desc = {
						trigger = {
							primary_title.tier = tier_empire
						}
						desc = ce1_decision_events.1000.c.empire
					}
					desc = ce1_decision_events.1000.c.kingdom
				}
			}
		}
		trigger = {
			exists = scope:kingdom_03
		}
		ce1_dec_1000_integrate = {
			KINGDOM = scope:kingdom_03
		}
		ai_chance = {
			base = 10
		}
	}

	option = { #Kingdom 4 please
		name = ce1_decision_events.1000.d
		trigger = {
			exists = scope:kingdom_04
		}
		ce1_dec_1000_integrate = {
			KINGDOM = scope:kingdom_04
		}
		ai_chance = {
			base = 10
		}
	}

	option = { #Kingdom 5 please
		name = ce1_decision_events.1000.e
		trigger = {
			exists = scope:kingdom_05
		}
		ce1_dec_1000_integrate = {
			KINGDOM = scope:kingdom_05
		}
		ai_chance = {
			base = 10
		}
	}

	option = { #Kingdom 6 please
		name = ce1_decision_events.1000.f
		trigger = {
			exists = scope:kingdom_06
		}
		ce1_dec_1000_integrate = {
			KINGDOM = scope:kingdom_06
		}
		ai_chance = {
			base = 10
		}
	}
}

ce1_decision_events.1010 = {
	type = character_event
	title = ce1_decision_events.1010.t
	desc = ce1_decision_events.1010.desc
	theme = legend
	left_portrait = {
		character = root
		animation = personality_honorable
	}
	override_background = { reference = throne_room }

	immediate = {
		play_music_cue = "mx_cue_positive_effect"
		ordered_realm_de_jure_duchy = {
			limit = {
				valid_for_legendary_integration_d = yes
			}
			max = 6
			check_range_bounds = no
			if = {
				limit = { exists = scope:duchy_05 }
				save_scope_as = duchy_06
			}
			else_if = {
				limit = { exists = scope:duchy_04 }
				save_scope_as = duchy_05
			}
			else_if = {
				limit = { exists = scope:duchy_03 }
				save_scope_as = duchy_04
			}
			else_if = {
				limit = { exists = scope:duchy_02 }
				save_scope_as = duchy_03
			}
			else_if = {
				limit = { exists = scope:duchy_01 }
				save_scope_as = duchy_02
			}
			else = { save_scope_as = duchy_01 }
		}
	}

	option = { #Duchy 1 please
		name = ce1_decision_events.1010.a
		trigger = {
			exists = scope:duchy_01
		}
		ce1_dec_1010_integrate = {
			DUCHY = scope:duchy_01
		}
		ai_chance = {
			base = 10
		}
	}

	option = { #Duchy 2 please
		name = ce1_decision_events.1010.b
		trigger = {
			exists = scope:duchy_02
		}
		ce1_dec_1010_integrate = {
			DUCHY = scope:duchy_02
		}
		ai_chance = {
			base = 10
		}
	}

	option = { #Duchy 3 please
		name = ce1_decision_events.1010.c
		trigger = {
			exists = scope:duchy_03
		}
		ce1_dec_1010_integrate = {
			DUCHY = scope:duchy_03
		}
		ai_chance = {
			base = 10
		}
	}

	option = { #Duchy 4 please
		name = ce1_decision_events.1010.d
		trigger = {
			exists = scope:duchy_04
		}
		ce1_dec_1010_integrate = {
			DUCHY = scope:duchy_04
		}
		ai_chance = {
			base = 10
		}
	}

	option = { #Duchy 5 please
		name = ce1_decision_events.1010.e
		trigger = {
			exists = scope:duchy_05
		}
		ce1_dec_1010_integrate = {
			DUCHY = scope:duchy_05
		}
		ai_chance = {
			base = 10
		}
	}

	option = { #Duchy 6 please
		name = ce1_decision_events.1010.f
		trigger = {
			exists = scope:duchy_06
		}
		ce1_dec_1010_integrate = {
			DUCHY = scope:duchy_06
		}
		ai_chance = {
			base = 10
		}
	}
}

ce1_decision_events.1015 = {
	type = character_event
	title = ce1_decision_events.1015.t
	desc = ce1_decision_events.1015.desc
	theme = legend
	left_portrait = {
		character = root
		animation = personality_honorable
	}
	override_background = { reference = throne_room }

	immediate = {
		play_music_cue = "mx_cue_positive_effect"
		ordered_realm_de_jure_empire = {
			limit = {
				valid_for_legendary_integration_e = yes
			}
			max = 6
			check_range_bounds = no
			if = {
				limit = { exists = scope:empire_05 }
				save_scope_as = empire_06
			}
			else_if = {
				limit = { exists = scope:empire_04 }
				save_scope_as = empire_05
			}
			else_if = {
				limit = { exists = scope:empire_03 }
				save_scope_as = empire_04
			}
			else_if = {
				limit = { exists = scope:empire_02 }
				save_scope_as = empire_03
			}
			else_if = {
				limit = { exists = scope:empire_01 }
				save_scope_as = empire_02
			}
			else = { save_scope_as = empire_01 }
		}
	}

	option = { #Empire 1 please
		name = ce1_decision_events.1015.a
		trigger = {
			exists = scope:empire_01
		}
		ce1_dec_1015_integrate = {
			EMPIRE = scope:empire_01
		}
		ai_chance = {
			base = 10
		}
	}

	option = { #Empire 2 please
		name = ce1_decision_events.1015.b
		trigger = {
			exists = scope:empire_02
		}
		ce1_dec_1015_integrate = {
			EMPIRE = scope:empire_02
		}
		ai_chance = {
			base = 10
		}
	}

	option = { #Empire 3 please
		name = ce1_decision_events.1015.c
		trigger = {
			exists = scope:empire_03
		}
		ce1_dec_1015_integrate = {
			EMPIRE = scope:empire_03
		}
		ai_chance = {
			base = 10
		}
	}

	option = { #Empire 4 please
		name = ce1_decision_events.1015.d
		trigger = {
			exists = scope:empire_04
		}
		ce1_dec_1015_integrate = {
			EMPIRE = scope:empire_04
		}
		ai_chance = {
			base = 10
		}
	}

	option = { #Empire 5 please
		name = ce1_decision_events.1015.e
		trigger = {
			exists = scope:empire_05
		}
		ce1_dec_1015_integrate = {
			EMPIRE = scope:empire_05
		}
		ai_chance = {
			base = 10
		}
	}

	option = { #Empire 6 please
		name = ce1_decision_events.1015.f
		trigger = {
			exists = scope:empire_06
		}
		ce1_dec_1015_integrate = {
			EMPIRE = scope:empire_06
		}
		ai_chance = {
			base = 10
		}
	}
}

# Pacifist conversion
ce1_decision_events.1020 = {
	type = character_event
	title = ce1_decision_events.1020.t
	desc = ce1_decision_events.1020.desc
	theme = learning
	left_portrait = {
		character = root
		animation = personality_honorable
	}
	right_portrait = {
		character = scope:legendary_character
		animation = personality_zealous
	}

	immediate = {
		scope:legendary_character.faith = { save_scope_as = leg_faith }
		save_scope_as = liege_convert
	}

	option = { # Convert I shall!
		name = ce1_decision_events.1020.a
		every_vassal_or_below = {
			custom = every_same_faith_vassal
			limit = {
				faith = root.faith
				NOT = { any_held_title = { is_head_of_faith = yes } }
			}
			if = {
				limit = {
					is_ai = yes
				}
				set_character_faith = scope:leg_faith
			}
			else = {
				trigger_event = ce1_decision_events.1021 # Give players a choice
			}
		}
		every_sub_realm_county = {
			custom = every_same_faith_county_in_realm
			limit = {
				faith = root.faith
			}
			
			E_kCAFG_convert_faith_in_all_county_provinces = {
				FACTOR = 0.25
				VARIANCE = 0.4
				FAITH = scope:leg_faith
				MAX = 0.9
			}
		}
		scope:legendary_character = {
			send_interface_toast = {
				title = ce1_decision_events.1020.conversion
				left_icon = scope:legendary_character
				right_icon = scope:liege_convert
				scope:liege_convert = {
					set_character_faith = scope:leg_faith
					if = {
						limit = { 
							scope:leg_faith = { has_doctrine = doctrine_monotheist }
						}
						custom_description_no_bullet = { text = mandala_monotheist_warning_tt }
					}
				}
			}
		}
		ai_chance = {
			base = 350 # Should be high, this is a reward for a massive investment
			ai_value_modifier = {
				ai_zeal = -2
				ai_honor = 0.5
				ai_compassion = 2 # Pacifism is epic
				ai_vengefulness = -0.5
				ai_rationality = -0.75
			}
			opinion_modifier = {
				opinion_target = scope:legendary_character
				multiplier = 1
			}
		}
	}

	option = { # Pacifism is cringe
		name = ce1_decision_events.1020.b
		trigger = {
			NOT = {
				has_character_flag = guarantee_conversion
			}
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_zeal = 2
				ai_honor = -0.5
				ai_compassion = -2
				ai_vengefulness = 0.5
				ai_rationality = 0.75
			}
		}
	}

	after = {
		if = {
			limit = {
				has_character_flag = guarantee_conversion
			}
			remove_character_flag = guarantee_conversion
		}
	}
}
ce1_decision_events.1021 = {
	type = character_event
	title = ce1_decision_events.1021.t
	desc = ce1_decision_events.1021.desc
	theme = learning
	left_portrait = {
		character = root
		animation = personality_honorable
	}
	right_portrait = {
		character = scope:legendary_character
		animation = personality_zealous
	}

	option = { # Convert I shall!
		name = ce1_decision_events.1021.a
		set_character_faith = scope:leg_faith
		if = {
			limit = { 
				scope:leg_faith = { has_doctrine = doctrine_monotheist }
			}
			custom_description_no_bullet = { text = mandala_monotheist_warning_tt }
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_zeal = -2
				ai_honor = 0.5
				ai_compassion = 2 # Pacifism is epic
				ai_vengefulness = -0.5
				ai_rationality = -0.75
			}
		}
	}

	option = { # Pacifism is cringe
		name = ce1_decision_events.1021.b
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_zeal = 2
				ai_honor = -0.5
				ai_compassion = -2
				ai_vengefulness = 0.5
				ai_rationality = 0.75
			}
		}
	}
}
