﻿namespace = te_rel_flavor

te_rel_flavor.1 = {
	type = country_event
	title = "te_rel_flavor.1.t"
	desc = {
		first_valid = {
			triggered_desc = { 
				trigger = {
					NOT = {
						religion = judaism
					}
				}
				desc = "te_rel_flavor.1.desc_1"
			}
			triggered_desc = { # Judea or Samaria
				trigger = { 
						religion = judaism
				}	
				desc = "te_rel_flavor.1.desc_2"
			}
		}	
	}
	picture = te_early_xian_worship

	left_portrait = current_ruler
	#right_portait = scope:pagan_or_jewish_official_priest

	goto_location = scope:early_xian_community_target

	trigger = {
		is_ai = no
		current_date > 856.6.24
		any_owned_province = {
			has_province_modifier = early_christian_community
		}
		NOR = {
			religion = christianity
			religion = manichaeism
			has_variable = early_xian_community_cooldown
		}
		current_ruler = {
			NOR = {
				has_religion = christianity
				has_religion = manichaeism	
				has_variable = xian_tolerant
			}
		}
		any_character = {
			AND = {
				has_any_religious_office_trigger = yes
				has_same_religion_as = root.current_ruler
				is_alive = yes
				prisoner = no
			}	
		}
	}

	immediate = {
		set_variable = {
			name = early_xian_community_cooldown
			days = 1500
		}
		random_character = {
			limit = {
				has_any_religious_office_trigger = yes
				has_same_religion_as = root.current_ruler
			}
			save_scope_as = pagan_or_jewish_official_priest
		}
		random_owned_province = {
			limit = { 
				has_province_modifier = early_christian_community
			}
			save_scope_as = early_xian_community_target
		}
		random_character = {
			limit = {
				has_religion = christianity
				is_alive = yes
			}
			if = {
				limit = {
					exists = THIS
				}
				save_scope_as = xian_character
			}	
		}	
	}

	option = {
		custom_tooltip = "leave_xians_alone"
		name = "te_rel_flavor.1.a"
		current_ruler = {
			add_popularity = -10 
			if = {
				limit = {
					has_variable = xian_community_killer
				}
				change_variable = {
					name = xian_community_killer
					add = -1
				}
				add_trait = arbitrary
			}
			else_if = {
				limit = {
					has_trait = tolerant
				}
				set_variable = xian_tolerant
			}
			else = {
				add_trait = tolerant
			}
			remove_trait = zealous
		}
		add_political_influence = -10
		scope:pagan_or_jewish_official_priest = {
			add_loyalty = spared_xians_hate
		}
		if = {
			limit = {
				exists = scope:xian_character
			}
			scope:xian_character = {
				add_loyalty = spared_xians_sympathy 
			}
		}
	}

	option = {
		custom_tooltip = "destroy_xians"
		name = "te_rel_flavor.1.b"
		current_ruler = {
			add_popularity = 20
			add_trait = harsh
			remove_trait = benefactor
		}
		if = {
			limit = {
				current_ruler = {
					NOT = {
						has_variable = xian_community_killer
					}
				}
			}
			current_ruler = {
				set_variable = {
					name = xian_community_killer
					value = 1
				}
			}
		}
		else = {
			current_ruler = {
				change_variable = {
					name = xian_community_killer
					add = 1
				}
			}
		}
		add_political_influence = 20
		add_tyranny = 5
		scope:pagan_or_jewish_official_priest = {
			add_loyalty = persecuted_xians_glee
		}
		if = {
			limit = {
				exists = scope:xian_character
			}
			scope:xian_character = {
				add_loyalty = persecuted_xians_sorrow
			}
		}
		scope:early_xian_community_target = {
			every_pops_in_province = {
				limit = {
					pop_religion = christianity
				}
				kill_pop = yes
			}
			remove_province_modifier = early_christian_community
			set_variable = {
				name = early_xian_persecution
				days = 3600
			}
		}
		if = {
			limit = {
				any_owned_province = {
					has_province_modifier = early_christian_church
				}	
			}
			trigger_event = {
				id = te_rel_flavor.2
				days = 750
			}
		}
	}

	after = {
		if = {
			limit = {
				current_ruler = {
					has_variable = xian_community_killer
					var:xian_community_killer > 2
				}
			}
			current_ruler = {
				change_variable = {
					name = xian_community_killer
					add = -3
				}
			}
			random_character = {
				limit = {
					is_ruler = no
					is_primary_heir = no
					AND = {
						has_any_religious_office_trigger = no
						has_any_office = yes
					}	
					has_same_religion_as = root.current_ruler
					NOR = {
						has_religion = christianity
						has_religion = manichaeism
						has_character_modifier = switched_char_religion
					}
				}
				trigger_event = {
					id = te_rel_flavor.3
					days = 1
				}
			}
		}
		else_if = {
			limit = {
				current_ruler = {
					has_variable = xian_community_killer
					var:xian_community_killer > 1
				}
			}	
			random_character = {
				limit = {
					is_ruler = no
					is_primary_heir = no
					has_any_religious_office_trigger = no
					OR = {
						in_command = yes
						is_general = yes
						is_admiral = yes
					}	
					NOT = {
						has_character_modifier = switched_char_religion
					}
					prisoner = no
					NOR = {
						has_religion = christianity
						has_religion = manichaeism
						has_character_modifier = switched_char_religion
					}
				}
				trigger_event = {
					id = te_rel_flavor.4
					days = 2
				}
			}
		}
		else_if = {
			limit = {
				current_ruler = {
					has_variable = xian_community_killer
					var:xian_community_killer = 1
				}
			}
			random_character = {
				limit = {
					is_ruler = no
					is_primary_heir = no
					has_any_religious_office_trigger = no
					is_minor_character = no
					NOT = {
						has_character_modifier = switched_char_religion
					}
					NOR = {
						has_religion = christianity
						has_religion = manichaeism
						has_character_modifier = switched_char_religion
					}
				}
				trigger_event = {
					id = te_rel_flavor.5
					days = 3
				}
			}
		}
	}
}

te_rel_flavor.2 = {
	type = country_event
	title = "te_rel_flavor.2.t"
	desc = {
		first_valid = {
			triggered_desc = { 
				trigger = {
					NOT = {
						religion = judaism
					}
				}
				desc = "te_rel_flavor.2.desc_1"
			}
			triggered_desc = { # Judea or Samaria
				trigger = { 
					religion = judaism
				}	
				desc = "te_rel_flavor.2.desc_2"
			}
		}
	}	
	picture = te_early_xian_worship

	goto_location = scope:early_xian_church_target

	left_portrait = current_ruler
	right_portrait = scope:pagan_or_jewish_official_priest

	trigger = {
		is_ai = no
		any_owned_province = {
			has_province_modifier = early_christian_church
		}
		NOR = {
			religion = christianity
			religion = manichaeism
		}
		current_ruler = {
			NOR = {
				has_religion = manichaeism
				has_religion = christianity	
			}
			has_variable = xian_community_killer
		}
		scope:pagan_or_jewish_official_priest = {
			is_alive = yes
			prisoner = no
		}	
	}

	immediate = {
		random_owned_province = {
			limit = {
				has_province_modifier = early_christian_church
			}
			save_scope_as = early_xian_church_target
		}	
	}

	option = {
		name = "te_rel_flavor.2.a"
		custom_tooltip = "spare_xian_church"
		current_ruler = {
			add_popularity = -20 
			add_trait = lapsed
			remove_trait = zealous
			remove_variable = xian_community_killer
			set_variable = xian_tolerant
		}
		add_political_influence = -20
		every_character = {
			limit = {
				has_religion = christianity
				is_alive = yes
			}
			add_loyalty = spared_xians_sympathy 
		}
		every_character = {
			limit = {
				has_same_religion_as = prev.current_ruler
				is_alive = yes
			}
			add_loyalty = spared_xians_hate
		}
	}

	option = {
		name = "te_rel_flavor.2.b"
		custom_tooltip = "destroy_xian_church"
		current_ruler = {
			add_popularity = 40
			add_trait = zealous
			remove_trait = lapsed
		}
		add_political_influence = 40
		add_tyranny = 10
		every_character = {
			limit = {
				has_same_religion_as = prev.current_ruler
				is_alive = yes
			}
			add_loyalty = persecuted_xians_glee
		}
		every_character = {
			limit = {
				has_religion = christianity
				is_alive = yes
			}
			add_loyalty = persecuted_xians_sorrow
		}
		scope:early_xian_church_target = {
			ordered_pops_in_province = {
				limit = {
					pop_religion = christianity
				}
				order_by = pop_hapiness
				max = {
					value = total_population
					divide = 2
				}
				check_range_bounds = no
				kill_pop = yes
			}
			add_city_smoke_effect = yes	
			remove_province_modifier = early_christian_church
			set_variable = {
				name = early_xian_persecution
				days = 3600
			}
		}
	}

	after = {
		random_character = {
			limit = {
				is_ruler = no
				is_primary_heir = no
				AND = {
					has_any_religious_office_trigger = no
					has_any_office = yes
				}	
				has_same_religion_as = root.current_ruler
				NOR = {
					has_religion = christianity
					has_religion = manichaeism
					has_character_modifier = switched_char_religion
				}
			}
			trigger_event = {
				id = te_rel_flavor.3
				days = 1
			}
		}
	}
}

te_rel_flavor.3 = {
	type = character_event
	hidden = yes
	
	trigger = {
		is_ruler = no
		is_primary_heir = no
		AND = {
			has_any_religious_office_trigger = no
			has_any_office = yes
		}	
		has_religion = root.employer.religion
		NOR = {
			has_religion = christianity
			has_religion = manichaeism
			has_character_modifier = switched_char_religion
		}
	}
	
	weight_multiplier = {
		modifier = {
			factor = 1.5
			has_trait = tolerant
		}
		modifier = {
			factor = 1.5
			has_trait = lapsed
		}
		modifier = {
			factor = 0.75
			has_trait = devout
		}
		modifier = {
			factor = 0.75
			has_trait = sceptical
		}
		modifier = {
			factor = 0.75
			has_trait = abrasive
		}
		modifier = {
			factor = 0.75
			has_trait = pious
		}
		modifier = {
			factor = 0.75
			has_trait = zealous
		}
		
	}
	
	immediate = {
		set_character_religion = christianity
		add_character_modifier = {
			name = switched_char_religion
			duration = 1825
		}
		if = {
			limit = {
				has_trait = lapsed
			}
			remove_trait = lapsed
		}
		if = {
			limit = {
				has_loyalty = spared_xians_hate
			}
			remove_loyalty = spared_xians_hate
		}
		if = {
			limit = {
				has_loyalty = persecuted_xians_glee
			}
			remove_loyalty = persecuted_xians_glee
		}
		country = {
			random_character = {
				limit = {
					is_ruler = no
					is_primary_heir = no
					has_any_religious_office_trigger = no
					OR = {
						in_command = yes
						is_general = yes
						is_admiral = yes
					}	
					NOT = {
						has_character_modifier = switched_char_religion
					}
					NOR = {
						has_religion = christianity
						has_religion = manichaeism
						has_character_modifier = switched_char_religion
					}
				}
				trigger_event = {
					id = te_rel_flavor.4
					days = 2
				}
			}
		}
	}
}

te_rel_flavor.4 = {
	type = character_event
	hidden = yes
	
	trigger = {
		is_ruler = no
		is_primary_heir = no
		has_any_religious_office_trigger = no
		OR = {
			in_command = yes
			is_general = yes
			is_admiral = yes
		}	
		NOT = {
			has_character_modifier = switched_char_religion
		}
		NOR = {
			has_religion = christianity
			has_religion = manichaeism
			has_character_modifier = switched_char_religion
		}
	}
	
	weight_multiplier = {
		modifier = {
			factor = 1.5
			has_trait = tolerant
		}
		modifier = {
			factor = 1.5
			has_trait = lapsed
		}
		modifier = {
			factor = 0.75
			has_trait = devout
		}
		modifier = {
			factor = 0.75
			has_trait = sceptical
		}
		modifier = {
			factor = 0.75
			has_trait = abrasive
		}
		modifier = {
			factor = 0.75
			has_trait = pious
		}
		modifier = {
			factor = 0.75
			has_trait = zealous
		}
		
	}
	
	immediate = {
		set_character_religion = christianity
		add_character_modifier = {
			name = switched_char_religion
			duration = 1825
		}
		if = {
			limit = {
				has_trait = lapsed
			}
			remove_trait = lapsed
		}
		if = {
			limit = {
				has_loyalty = spared_xians_hate
			}
			remove_loyalty = spared_xians_hate
		}
		if = {
			limit = {
				has_loyalty = persecuted_xians_glee
			}
			remove_loyalty = persecuted_xians_glee
		}
		country = {
			random_character = {
				limit = {
					is_ruler = no
					is_primary_heir = no
					has_any_religious_office_trigger = no
					is_minor_character = no
					NOT = {
						has_character_modifier = switched_char_religion
					}
					NOR = {
						has_religion = christianity
						has_religion = manichaeism
						has_character_modifier = switched_char_religion
					}
				}
				trigger_event = {
					id = te_rel_flavor.5
					days = 3
				}
			}
		}
	}
}

te_rel_flavor.5 = {
	type = character_event
	hidden = yes
	
	trigger = {
		is_ruler = no
		is_primary_heir = no
		has_any_religious_office_trigger = no
		is_minor_character = no
		NOT = {
			has_character_modifier = switched_char_religion
		}
		NOR = {
			has_religion = christianity
			has_religion = manichaeism
			has_character_modifier = switched_char_religion
		}
	}
	
	weight_multiplier = {
		modifier = {
			factor = 1.5
			has_trait = tolerant
		}
		modifier = {
			factor = 1.5
			has_trait = lapsed
		}
		modifier = {
			factor = 0.75
			has_trait = devout
		}
		modifier = {
			factor = 0.75
			has_trait = sceptical
		}
		modifier = {
			factor = 0.75
			has_trait = abrasive
		}
		modifier = {
			factor = 0.75
			has_trait = pious
		}
		modifier = {
			factor = 0.75
			has_trait = zealous
		}
		
	}
	
	immediate = {
		set_character_religion = christianity
		add_character_modifier = {
			name = switched_char_religion
			duration = 1825
		}
		if = {
			limit = {
				has_trait = lapsed
			}
			remove_trait = lapsed
		}
		if = {
			limit = {
				has_loyalty = spared_xians_hate
			}
			remove_loyalty = spared_xians_hate
		}
		if = {
			limit = {
				has_loyalty = persecuted_xians_glee
			}
			remove_loyalty = persecuted_xians_glee
		}
	}
}

#Manichaean emissaries
te_rel_flavor.6 = {
	type = country_event
	title = "te_rel_flavor.6.t"
	desc = "te_rel_flavor.6.desc"
    picture = te_manichaean_cosmology

	left_portrait = current_ruler

	trigger = {
		current_date > 1035.3.15
		has_global_variable = manichaeism_spreads
        	is_ai = no
		is_tribal = no
        	NOR = {
			has_variable = manichaean_supplication_cooldown
			capital_scope = { has_province_modifier = manichaean_temple }
			AND = {
				has_variable = ban_manichees
				var:ban_manichees >= 3
			}
			country_culture_group = germanic
			country_culture_group = baltic
			country_culture_group = gaelic
			####Invictus v1.8###################
			country_culture_group = finnic_group
			religion = uralic_pantheon
			####################################
			religion = judaism
			religion = christianity
			religion = manichaeism
			religion = matrist_religion
			religion = germanic_religion
        	} 
		any_owned_province = {
			any_pops_in_province = { pop_religion = manichaeism }
		}
		current_ruler = {
			is_adult = yes
			NOR = {
				has_religion = manichaeism
				has_religion = christianity
				has_religion = judaism
				has_religion = matrist_religion
				has_religion = germanic_religion
				####Invictus v1.8#############
				has_religion = uralic_pantheon
				##############################
				has_variable = manichaean_supplication
			}
			OR = {
				has_trait = wise
				has_trait = scholar
				has_trait = polymath
				has_trait = intelligent
				has_trait = generous
				has_trait = tolerant
				has_trait = prominent
				has_trait = good_natured
				has_trait = benefactor
				has_trait = founder
				has_trait = ambitious
				has_trait = trusting
			}
		}
	}

	option = {
		custom_tooltip = "allow_manichaean_temple"
		name = "te_rel_flavor.6.a"
		highlight = yes
		add_treasury = 150
		capital_scope = {
			add_province_modifier = {
				name = "manichaean_temple"
				duration = 21000
			}
		}
		every_character = {
			limit = {
				AND = {
					has_any_religious_office_trigger = yes
					has_same_religion_as = root.current_ruler
					is_alive = yes
					prisoner = no
				}
			}
			add_loyalty = allowed_manichees
		}
		every_character = {
			limit = {
				has_religion = manichaeism
				is_alive = yes
			}
			add_loyalty = manichee_appreciation
		}
	}

	option = {
		custom_tooltip = "disallow_manichaean_temple"
		name = "te_rel_flavor.6.b"
		every_character = {
			limit = {
				AND = {
					has_any_religious_office_trigger = yes
					has_same_religion_as = root.current_ruler
					is_alive = yes
					prisoner = no
				}
			}
			add_loyalty = disallowed_manichees
		}
		every_character = {
			limit = {
				has_religion = manichaeism
				is_alive = yes
			}
			add_loyalty = manichee_resentment
		}
		if = {
			limit = {
				has_variable = ban_manichees
			}
			change_variable = {
				name = ban_manichees
				add = 1
			}
		}
		else = {
			set_variable = {
				name = ban_manichees
				value = 1
			}
		}
	}

	after = {
		current_ruler = {
			set_variable = manichaean_supplication
		}
		set_variable = {
			name = manichaean_supplication_cooldown
			days = 2100
		}	
	}
}

te_rel_flavor.7 = {
	type = country_event
	hidden = yes

	trigger = {
		current_date > 1035.3.15
		has_global_variable = manichaeism_spreads
		is_republic = no
		NOR = {
			has_variable = manichaean_supplication_cooldown
			current_ruler = {
				has_variable = manichaean_supplication
			}
		}
		capital_scope = {
			has_province_modifier = manichaean_temple
		}
	}

	immediate = {
		capital_scope = {
			remove_province_modifier = manichaean_temple
		}
	}
}
