﻿mark_more_legends_as_done = {
    if = { # Terrorizing legends
        limit = {
            legend_property:more_legends_ml_legendary_tactician_flag = flag:started_ml_legendary_tactician
        }
        legend_owner = {
            set_variable = {
                name = ml_legendary_tactician_used
                value = yes
            }
        }
    }
    if = { # Terrorizing legends
        limit = {
            legend_property:more_legends_ml_boundless_terror_flag = flag:started_ml_boundless_terror
        }
        legend_owner = {
            set_variable = {
                name = ml_boundless_terror_used
                value = yes
            }
        }
    }
    if = { # Terrorizing legends
        limit = {
            legend_property:more_legends_ml_mad_ruler_flag = flag:started_ml_mad_ruler
        }
        legend_owner = {
            set_variable = {
                name = ml_mad_ruler_used
                value = yes
            }
        }
    }
	if = { # Cutural legends
		limit = {
			legend_property:more_legends_ml_great_scholar_flag = flag:started_ml_great_scholar
		}
		legend_owner = {
			set_variable = {
				name = ml_great_scholar_used
				value = yes
			}
		}
	}
	if = { # Cutural legends
		limit = {
			legend_property:more_legends_ml_eternal_ascetic_flag = flag:started_ml_eternal_ascetic
		}
		legend_owner = {
			set_variable = {
				name = ml_eternal_ascetic_used
				value = yes
			}
		}
	}
	if = { # Enriching legends
		limit = {
			legend_property:more_legends_midas_touched_flag = flag:started_midas_touched
		}
		legend_owner = {
			set_variable = {
				name = midas_touched_used
				value = yes
			}
		}
	}
	if = { # Enriching legends
	limit = {
		legend_property:more_legends_ml_wise_monarch_flag = flag:started_ml_wise_monarch
	}
	legend_owner = {
		set_variable = {
			name = ml_wise_monarch_used
			value = yes
		}
	}
}
}

#GIVE HAUNTED PALACE
give_legendary_building_location_terrorizing_effect = {
	give_legendary_building_location_standard_effect = yes
	custom_tooltip = {
		text = ml_can_build_haunted_palace_tt
		add_character_flag = haunted_palace_flag
	}
}

#GIVE GRAND LIBRARY
give_legendary_building_location_cultural_effect = {
	give_legendary_building_location_standard_effect = yes
	custom_tooltip = {
		text = ml_can_build_grand_library_tt
		add_character_flag = grand_library_flag
	}
}

#GIVE TAX CENTER
give_legendary_building_location_enriching_effect = {
	give_legendary_building_location_standard_effect = yes
	custom_tooltip = {
		text = ml_can_build_tax_center_tt
		add_character_flag = tax_center_flag
	}
}

give_legendary_building_terrorizing_tooltip_effect = { #50% chance
	# Chance to get legendary building
	if = {
		limit = {
			OR = {
				root = {
					locale_valid_for_legendary_buildings = yes
				}
				capital_province = { has_special_building_slot = no }
				any_sub_realm_barony = {
					title_province = { has_special_building_slot = no }
				}
			}
		}
		random = {
			chance = {
				value = 50
			}
			give_legendary_building_location_terrorizing_effect = yes
		}
	}
	set_variable = {
		name = more_legends_legendary_reward_location
		value = scope:legendary_locale
	}
	set_variable = {
		name = legendary_figure
		value = scope:protagonist
	}
}

give_legendary_building_cultural_tooltip_effect = { #50% chance
	# Chance to get legendary building
	if = {
		limit = {
			OR = {
				root = {
					locale_valid_for_legendary_buildings = yes
				}
				capital_province = { has_special_building_slot = no }
				any_sub_realm_barony = {
					title_province = { has_special_building_slot = no }
				}
			}
		}
		random = {
			chance = {
				value = 50
			}
			give_legendary_building_location_cultural_effect = yes
		}
	}
	set_variable = {
		name = more_legends_legendary_reward_location
		value = scope:legendary_locale
	}
	set_variable = {
		name = legendary_figure
		value = scope:protagonist
	}
}

give_legendary_building_enriching_tooltip_effect = { #50% chance
	# Chance to get legendary building
	if = {
		limit = {
			OR = {
				root = {
					locale_valid_for_legendary_buildings = yes
				}
				capital_province = { has_special_building_slot = no }
				any_sub_realm_barony = {
					title_province = { has_special_building_slot = no }
				}
			}
		}
		random = {
			chance = {
				value = 50
			}
			give_legendary_building_location_enriching_effect = yes
		}
	}
	set_variable = {
		name = more_legends_legendary_reward_location
		value = scope:legendary_locale
	}
	set_variable = {
		name = legendary_figure
		value = scope:protagonist
	}
}

give_legendary_building_mythical_terrorizing_tooltip_effect = {
	if = {
		limit = {
			OR = {
				root = {
					locale_valid_for_legendary_buildings = yes
				}
				capital_province = { has_special_building_slot = no }
				any_sub_realm_barony = {
					title_province = { has_special_building_slot = no }
				}
			}
		}
		give_legendary_building_location_terrorizing_effect = yes
	}
	set_variable = {
		name = more_legends_legendary_reward_location
		value = scope:legendary_locale
	}
	set_variable = {
		name = legendary_figure
		value = scope:protagonist
	}
}

give_legendary_building_mythical_cultural_tooltip_effect = {
	if = {
		limit = {
			OR = {
				root = {
					locale_valid_for_legendary_buildings = yes
				}
				capital_province = { has_special_building_slot = no }
				any_sub_realm_barony = {
					title_province = { has_special_building_slot = no }
				}
			}
		}
		give_legendary_building_location_cultural_effect = yes
	}
	set_variable = {
		name = more_legends_legendary_reward_location
		value = scope:legendary_locale
	}
	set_variable = {
		name = legendary_figure
		value = scope:protagonist
	}
}

give_legendary_building_mythical_enriching_tooltip_effect = {
	if = {
		limit = {
			OR = {
				root = {
					locale_valid_for_legendary_buildings = yes
				}
				capital_province = { has_special_building_slot = no }
				any_sub_realm_barony = {
					title_province = { has_special_building_slot = no }
				}
			}
		}
		give_legendary_building_location_enriching_effect = yes
	}
	set_variable = {
		name = more_legends_legendary_reward_location
		value = scope:legendary_locale
	}
	set_variable = {
		name = legendary_figure
		value = scope:protagonist
	}
}

#Rewards for all Terrorizing Legends
legend_ending_rewards_terrorizing_effect = {
	# Legitimacy gain based on Legend Protagonist
	disburse_legend_protagonist_legitimacy_effect = yes
	# Available decision
	custom_tooltip = more_legends_legend_ending_decision_tt
	hidden_effect = {
		create_character_memory = {
			type = ML_completed_my_terrorizing_legend
			participants = {
				owner = root
				protagonist = scope:legend_protagonist
			}
		}
	}
}

#Rewards for Famed Legends
legend_ending_rewards_famed_terrorizing_effect = {
	add_legitimacy = medium_legitimacy_gain
	if = {
		limit = { exists = promoted_legend }
		set_variable = finished_famed_legend_var
		set_variable = finished_terrorizing_legend_var
	}
}

#Rewards for Illustrious Legends
legend_ending_rewards_illustrious_terrorizing_effect = {
	add_legitimacy = major_legitimacy_gain
	if = {
		limit = { exists = promoted_legend }
		set_variable = finished_illustrious_legend_var
		set_variable = finished_terrorizing_legend_var
	}
}

#Rewards for Mythical Legends
legend_ending_rewards_mythical_terrorizing_effect = {
	add_legitimacy = massive_legitimacy_gain
    #MAYBE ADD CAPABILITY TO GET LIVING LEGEND TRAIT
	if = {
		limit = { exists = promoted_legend }
		set_variable = finished_mythical_legend_var
		set_variable = finished_terrorizing_legend_var
	}
}

#Rewards for all Cultural Legends
legend_ending_rewards_cultural_effect = {
	# Legitimacy gain based on Legend Protagonist
	disburse_legend_protagonist_legitimacy_effect = yes
	# Available decision
	custom_tooltip = more_legends_legend_ending_decision_tt
	hidden_effect = {
		create_character_memory = {
			type = ML_completed_my_cultural_legend
			participants = {
				owner = root
				protagonist = scope:legend_protagonist
			}
		}
	}
}

#Rewards for Famed Legends
legend_ending_rewards_famed_cultural_effect = {
	add_legitimacy = medium_legitimacy_gain
	if = {
		limit = { exists = promoted_legend }
		set_variable = finished_famed_legend_var
		set_variable = finished_cultural_legend_var
	}
}

#Rewards for Illustrious Legends
legend_ending_rewards_illustrious_cultural_effect = {
	add_legitimacy = major_legitimacy_gain
	if = {
		limit = { exists = promoted_legend }
		set_variable = finished_illustrious_legend_var
		set_variable = finished_cultural_legend_var
	}
}

#Rewards for Mythical Legends
legend_ending_rewards_mythical_cultural_effect = {
	add_legitimacy = massive_legitimacy_gain
    #MAYBE ADD CAPABILITY TO GET LIVING LEGEND TRAIT
	if = {
		limit = { exists = promoted_legend }
		set_variable = finished_mythical_legend_var
		set_variable = finished_cultural_legend_var
	}
}

#Rewards for all Enriching Legends
legend_ending_rewards_enriching_effect = {
	# Legitimacy gain based on Legend Protagonist
	disburse_legend_protagonist_legitimacy_effect = yes
	# Available decision
	custom_tooltip = more_legends_legend_ending_decision_tt
	hidden_effect = {
		create_character_memory = {
			type = ML_completed_my_enriching_legend
			participants = {
				owner = root
				protagonist = scope:legend_protagonist
			}
		}
	}
}

#Rewards for Famed Legends
legend_ending_rewards_famed_enriching_effect = {
	add_legitimacy = medium_legitimacy_gain
	if = {
		limit = { exists = promoted_legend }
		set_variable = finished_famed_legend_var
		set_variable = finished_enriching_legend_var
	}
}

#Rewards for Illustrious Legends
legend_ending_rewards_illustrious_enriching_effect = {
	add_legitimacy = major_legitimacy_gain
	if = {
		limit = { exists = promoted_legend }
		set_variable = finished_illustrious_legend_var
		set_variable = finished_enriching_legend_var
	}
}

#Rewards for Mythical Legends
legend_ending_rewards_mythical_enriching_effect = {
	add_legitimacy = massive_legitimacy_gain
    #MAYBE ADD CAPABILITY TO GET LIVING LEGEND TRAIT
	if = {
		limit = { exists = promoted_legend }
		set_variable = finished_mythical_legend_var
		set_variable = finished_enriching_legend_var
	}
}