##############################
# LORD SPIRITUAL
#
# Job: action_inquisition
# 	900: County Religion Converted
# 	901: Subject Religion Converted
# 	902: Heathens Attack the Lord Spiritual
# 	903: Heretic Noble
#
# Job: action_improve_rel_relations
# 	906: The Lord Spiritual attempts to improve relations with a priest
# 	907: The Lord Spiritual attempts to sabotage the relations of a priest towards the official head of the religion
#
# Job: action_advance_cul_tech
# 	926: A Great Inventor offers his help: Random Culture Tech increases
# 	927: Lord Spiritual = heretic
#
##############################


##############################
# LORD SPIRITUAL
# JOB: action_inquisition
##############################

# 900: The Lord Spiritual converts a province!

# 20000: The Lord Spiritual informs his liege of the conversion

# 20001: Informs top liege

# 901: The Lord Spiritual converts a subject character

# 20010: Inform the target character about this

# 20011: Inform Lord Spiritual's Liege about this

# 20012: Inform character's Liege about this

# 902: The Lord Spiritual is attacked by heathens (Gets away, Is wounded, Is killed)

# 20020: Lord Spiritual gets away

# 20021: Lord Spiritual gets wounded

# 20022: Inform the Liege about wounding

# 20023: Inform the Liege about death

# 903: The Lord Spiritual suspects a subject character of heresy

# 20030: Noble reacts to the accusations

# 20032: Liege: The noble complains

# 20033: Noble: Noble isn't heretic

# 20034: Lord Spiritual: Noble isn't heretic

# 20035: Noble: Noble is heretic

# 901: The Lord Spiritual converts a subject character

# 20010: Inform the target character about this
# letter_event = {


# 20011: Inform Lord Spiritual's Liege about this
# letter_event = {


# 20012: Inform character's Liege about this
# letter_event = {



# 902: The Lord Spiritual is attacked by heathens (Gets away, Is wounded, Is killed)
# character_event = {


# 20020: Lord Spiritual gets away
# character_event = {


# 20021: Lord Spiritual gets wounded
# character_event = {


# 20022: Inform the Liege about wounding
# letter_event = {


# 20023: Inform the Liege about death
# character_event = {



# 903: The Lord Spiritual suspects a subject character of heresy
# character_event = {


# 20030: Noble reacts to the accusations
# character_event = {


# 20032: Liege: The noble complains
# letter_event = {


# 20033: Noble: Noble isn't heretic
# letter_event = {


# 20034: Lord Spiritual: Noble isn't heretic
# letter_event = {


# 20035: Noble: Noble is heretic
# letter_event = {


# 20036: Lord Spiritual: Noble is heretic
# letter_event = {


# 20037: Increased revolt risk
# character_event = {


# 20038: Inform province lords
# character_event = {


# 20039: Inform liege
# letter_event = {


# Chaplain arrives at Pagan capital
# character_event = {


# Chaplain has a chance of converting the Pagan lord
# character_event = {


# Chaplain converts Pagan courtier
# character_event = {


# Chaplain squabbles with other chaplain
# character_event = {


# Clear preacher_arrives flag
# character_event = {




##############################
# LORD SPIRITUAL
# JOB: action_improve_rel_relations
##############################

# 906: The Lord Spiritual improves relations between the liege and a bishop
character_event = {
	id = 906
	title = "EVTNAME906"
	desc = "EVTDESC906"
	picture = GFX_evt_bishop
	border = GFX_event_normal_frame_religion

	min_age = 16
	capable_only = yes
	prisoner = no
	has_job_title = yes
	
	trigger = {
		has_job_action = action_improve_rel_relations
		NOT = { has_character_modifier = in_seclusion }
		NOT = { has_character_modifier = bedridden_illness }
		NOT = { trait = incapable }
		location = { 
			any_province_lord = {
				NOT = { character = ROOT }
				is_priest = yes
				religion = ROOT
				NOT = { is_liege_of = ROOT }
			}
		}
	}
	
	mean_time_to_happen = { 
		months = 240
		
		job_event_mtth_modifier_learning_score = yes

		modifier = {
			factor = 2.0
			NOT = { religion_authority = 0.4 }
		}
		modifier = {
			factor = 2.0
			NOT = { religion_authority = 0.2 }
		}
		modifier = {
			factor = 0.75
			religion_authority = 0.6
		}
		modifier = {
			factor = 0.75
			religion_authority = 0.8
		}
	}
	
	option = {
		name = "EVTOPTA906"
		hidden_tooltip = {
			location = {
				random_province_lord = {
					limit = {
						is_priest = yes
						religion = ROOT
						NOT = { is_liege_of = ROOT }
					}
					character_event = { id = 20060 days = 7 }
				}
			}
		}
	}
}

# 20060: Inform the bishop
character_event = {
	id = 20060
	desc = "EVTDESC20060"
	picture = GFX_evt_bishop
	border = GFX_event_normal_frame_religion
	
	is_triggered_only = yes
	
	option = {
		name = "EVTOPTA20060"
		hidden_tooltip = {
			FROM = {
				liege = { letter_event = { id = 20061 } }
			}
		}
	}
}

# 20061: The liege is informed of the success
letter_event = {
	id = 20061
	desc = "EVTDESC20061"
	border = GFX_event_letter_frame_religion
	
	show_from_from = yes
	
	is_triggered_only = yes
	
	option = {
		name = "EVTOPTA20061"
		FROM = {
			opinion = {
				modifier = opinion_improved_relations
				who = ROOT
				years = 2
			}
		}
	}
}


# 907: The Lord Spiritual attempts to sabotage the relations of a subject priest towards the official head of the religion
character_event = {
	id = 907
	title = "EVTNAME907"
	desc = "EVTDESC907"
	picture = GFX_evt_pope_feast
	border = GFX_event_normal_frame_religion

	min_age = 16
	capable_only = yes
	prisoner = no
	has_job_title = yes
	
	trigger = {
		has_job_action = action_improve_rel_relations
		NOT = { has_character_modifier = in_seclusion }
		NOT = { has_character_modifier = bedridden_illness }
		NOT = { trait = incapable }
		religion_head = {
			NOT = { character = liege }
		}
		location = { 
			any_province_lord = {
				NOT = { character = ROOT }
				is_priest = yes
				NOT = { is_liege_of = ROOT }
				same_realm = ROOT
				religion = ROOT
				religion_head = {
					NOT = { character = PREV }
				}
			}
		}
	}
	
	mean_time_to_happen = {
		months = 240
		job_event_mtth_modifier_learning_score = yes
	}
	
	option = {
		name = "EVTOPTA907"
		hidden_tooltip = {
			location = {
				random_province_lord = {
					limit = {
						is_priest = yes
						NOT = { is_liege_of = ROOT }
						same_realm = ROOT
						religion = ROOT
						religion_head = {
							NOT = { character = PREV }
						}
					}
					character_event = { id = 20070 days = 7 }
				}
			}
		}
	}
}

# 20070: Inform the bishop
character_event = {
	id = 20070
	desc = "EVTDESC20070"
	picture = GFX_evt_spymaster
	border = GFX_event_normal_frame_religion
	
	is_triggered_only = yes
	
	option = {
		name = "EVTOPTA20070"
		hidden_tooltip = {
			FROM = {
				liege = { letter_event = { id = 20071 } }
			}
		}
	}
}

# 20071: The liege is informed of the success
letter_event = {
	id = 20071
	desc = "EVTDESC20071"
	border = GFX_event_letter_frame_religion
	
	show_from_from = yes
	
	is_triggered_only = yes

	option = {
		name = "EVTOPTA20071"
		FROM = {
			religion_head = {
				reverse_opinion = {
					modifier = opinion_head_of_religion_negative
					who = PREV
					years = 2
				}
			}
		}
	}
}


##############################
# LORD SPIRITUAL
# JOB: action_advance_cul_tech
##############################

# 926: A Great Inventor offers his help: Random Culture Tech increases
character_event = {
	id = 926
	title = "EVTNAME926"
	desc = "EVTDESC926"
	picture = GFX_evt_emissary
	border = GFX_event_normal_frame_religion
	
	min_age = 16
	capable_only = yes
	prisoner = no
	has_job_title = yes
	
	trigger = {
		has_job_action = action_advance_cul_tech
		NOT = { has_character_modifier = in_seclusion }
		NOT = { has_character_modifier = bedridden_illness }
		NOT = { trait = incapable }
	}
	
	mean_time_to_happen = {
		months = 1000
		
		modifier = {
			factor = 0.5
			OR = {
				has_focus = focus_scholarship
				liege = { has_focus = focus_scholarship }
			}
		}
		modifier = {
			factor = 2
			has_religion_feature = religion_dogmatic
		}
		modifier = {
			factor = 0.75
			has_religion_feature = religion_cosmopolitan
		}

		job_event_mtth_modifier_learning_score = yes

		modifier = {
			factor = 0.5
			liege = {
				any_owned_bloodline = {
					has_bloodline_flag = bloodline_more_philosophers
					bloodline_is_active_for = PREV
				}
			}
		}
		modifier = {
			factor = 0.5
			#If chaplain is also your relative.
			any_owned_bloodline = {
				has_bloodline_flag = bloodline_more_philosophers
				bloodline_is_active_for = PREV
			}
		}
	}
	
	option = {
		name = "EVTOPTA926"
		liege = { letter_event = { id = 20260 tooltip = "EVTTOOLTIP20260" } }
	}
}

# 20260: The liege is informed of the success
letter_event = {
	id = 20260
	desc = "EVTDESC20260"
	border = GFX_event_letter_frame_religion
	
	is_triggered_only = yes
	
	option = {
		name = "EVTOPTA20260"
		scaled_wealth = -0.5
		culture_techpoints = 50
		if = {
			limit = {
				has_dlc = "Reapers"
			}
			custom_tooltip = {
				text = increase_prosperity_custom_tooltip
				hidden_tooltip = {
					FROM = {
						location = {
							change_variable = { which = prosperity_value value = 6 }
						}
					}
				}
			}
		}
	}
	option = {
		name = "EVTOPTB20260"
	}
}

# 927: Lord Spiritual = heretic
# character_event = {


# 20270: Liege get a letter
# letter_event = {

##############################
# MUSLIM LORD SPIRITUAL (Mufti)
# JOB: action_charity
##############################

# 20040: The Mufti improves relations between the liege and a vassal
character_event = {
	id = 20040
	desc = "EVTDESC20040"
	title = "EVTNAME20040"
	picture = GFX_evt_bishop
	border = GFX_event_normal_frame_religion

	min_age = 16
	capable_only = yes
	prisoner = no
	has_job_title = yes
	
	trigger = {
		has_job_action = action_charity
		NOT = { has_character_modifier = in_seclusion }
		NOT = { has_character_modifier = bedridden_illness }
		NOT = { trait = incapable }
		location = { 
			any_province_lord = {
				religion = ROOT
				NOT = { is_liege_of = ROOT }
			}
		}
	}
	
	mean_time_to_happen = { 
		months = 220
		
		job_event_mtth_modifier_learning_score = yes

		modifier = {
			factor = 2.0
			NOT = { religion_authority = 0.4 }
		}
		modifier = {
			factor = 2.0
			NOT = { religion_authority = 0.2 }
		}
		modifier = {
			factor = 0.75
			religion_authority = 0.6
		}
		modifier = {
			factor = 0.75
			religion_authority = 0.8
		}
	}
	
	option = {
		name = "EVTOPTA20040"
		hidden_tooltip = {
			location = {
				random_province_lord = {
					limit = {
						religion = ROOT
						NOT = { is_liege_of = ROOT }
					}
					character_event = { id = 20041 days = 7 }
				}
			}
		}
	}
}

# 20041: Inform the vassal
character_event = {
	id = 20041
	desc = "EVTDESC20041"
	picture = GFX_evt_bishop
	border = GFX_event_normal_frame_religion
	
	is_triggered_only = yes
	
	option = {
		name = "EVTOPTA20041"
		hidden_tooltip = {
			FROM = {
				liege = { character_event = { id = 20042 days = 7 } }
			}
		}
	}
}

# 20042: The liege is informed of the success
character_event = {
	id = 20042
	desc = "EVTDESC20042"
	picture = GFX_evt_bishop
	border = GFX_event_normal_frame_religion
	
	show_from_from = yes
	
	is_triggered_only = yes
	
	option = {
		name = "EVTOPTA20042"
		FROM = {
			opinion = {
				modifier = opinion_improved_relations
				who = ROOT
				years = 2
			}
		}
	}
}

# 20043: The Mufti is trampled by a peasant mob (Gets away, Is wounded, Is killed)
character_event = {
	id = 20043
	desc = "EVTDESC20043"
	title = "EVTNAME20043"
	picture = GFX_evt_peasants
	border = GFX_event_normal_frame_religion

	min_age = 16
	capable_only = yes
	prisoner = no
	has_job_title = yes
	
	trigger = {
		has_job_action = action_charity
		NOT = { has_character_modifier = in_seclusion }
		NOT = { has_character_modifier = bedridden_illness }
		NOT = { trait = incapable }
		location = {
			religion = ROOT
			owner = { same_realm = ROOT }
		}
	}
	
	mean_time_to_happen = {
		months = 120
	
		job_event_mtth_modifier_inverted_learning_score = yes

		modifier = {
			factor = 0.75
			NOT = { religion_authority = 0.4 }
		}
		modifier = {
			factor =0.75
			NOT = { religion_authority = 0.2 }
		}
		modifier = {
			factor = 2.0
			religion_authority = 0.6
		}
		modifier = {
			factor = 2.0
			religion_authority = 0.8
		}
	}
	
	option = {
		name = "EVTOPTA20043"
		random_list = {
			50 = { character_event = { id = 20044 tooltip = "EVTTOOLTIP20020" } }
			40 = { character_event = { id = 20045 tooltip = "EVTTOOLTIP20021" } }
			10 = {
				if = {
					limit = { NOT = { has_character_modifier = protection_spell } }
					hidden_tooltip = {
						liege = { character_event = { id = 20047 } }
					}
					death = {
						death_reason = death_rabble
					}
				}
				if = {
					limit = { has_character_modifier = protection_spell }
					character_event = { id = 20045 tooltip = "EVTTOOLTIP20021" } 
				}
			}
		}
	}
}

# 20044: Mufti gets away
character_event = {
	id = 20044
	desc = "EVTDESC20044"
	picture = GFX_evt_peasants
	border = GFX_event_normal_frame_religion
	
	is_triggered_only = yes
	
	option = {
		name = "EVTOPTA20044"
		prestige = -30
	}
}

# 20045: Mufti gets wounded
character_event = {
	id = 20045
	desc = "EVTDESC20045"
	picture = GFX_evt_bloody_man
	border = GFX_event_normal_frame_religion
	
	is_triggered_only = yes
	
	option = {
		name = "EVTOPTA20045"
		add_trait = wounded
		hidden_tooltip = {
			liege = { character_event = { id = 20046 days = 7 } }
		}
	}
}

# 20046: Inform the Liege about wounding
character_event = {
	id = 20046
	desc = "EVTDESC20046"
	picture = GFX_evt_bloody_man
	border = GFX_event_normal_frame_religion
	
	is_triggered_only = yes
	
	option = {
		name = "EVTOPTA20046"
		prestige = -10
	}
}

# 20047: Inform the Liege about death
character_event = {
	id = 20047
	desc = "EVTDESC20047"
	picture = GFX_evt_death
	border = GFX_event_normal_frame_religion
	
	is_triggered_only = yes
	
	option = {
		name = "EVTOPTA20047"
		prestige = -15
	}
}

# 20048: The Mufti pockets money meant for the poor 
character_event = {
	id = 20048
	desc = "EVTDESC20048"
	title = "EVTNAME20048"
	picture = GFX_evt_bishop
	border = GFX_event_normal_frame_religion
	
	min_age = 16
	capable_only = yes
	prisoner = no
	has_job_title = yes
	
	trigger = {
		has_job_action = action_charity
		NOT = { has_character_modifier = in_seclusion }
		NOT = { has_character_modifier = bedridden_illness }
		NOT = { trait = incapable }
	}
	
	mean_time_to_happen = {
		months = 1000
		
		modifier = {
			factor = 1.5
			trait = charitable
		}
		modifier = {
			factor = 1.25
			trait = just
		}
		modifier = {
			factor = 0.50
			trait = greedy
		}
		modifier = {
			factor = 0.75
			trait = envious
		}
	}
	
	option = {
		name = "EVTOPTA20048"
		ai_chance = { factor = 80 }
		wealth = 35
		hidden_tooltip = {
			liege = { character_event = { id = 20049 days = 2 } }
		}
	}
	option = {
		name = "EVTOPTB20048"
		ai_chance = { factor = 20 }
		piety = 30
	}
}

# 20049: Liege informed about Mufti's theft
character_event = {
	id = 20049
	desc = "EVTDESC20049"
	picture = GFX_evt_bishop
	border = GFX_event_normal_frame_religion
	
	is_triggered_only = yes
	
	option = {
		name = "EVTOPTA20049"
		wealth = 35
		decadence = 10
	}
	option = {
		name = "EVTOPTB20049"
		FROM = { imprison = yes }
		piety = 20
	}
}

# 20050: Mullah gains piety for the liege
character_event = {
	id = 20050
	desc = "EVTDESC20050"
	title = "EVTNAME20050"
	picture = GFX_evt_bishop
	border = GFX_event_normal_frame_religion
	
	min_age = 16
	capable_only = yes
	prisoner = no
	has_job_title = yes
	
	trigger = {
		has_job_action = action_charity
		NOT = { has_character_modifier = in_seclusion }
		NOT = { has_character_modifier = bedridden_illness }
		NOT = { trait = incapable }
	}
	
	mean_time_to_happen = {
		months = 180

		job_event_mtth_modifier_learning_score = yes
	}
	
	option = {
		name = "EVTOPTA20050"
		liege = { character_event = { id = 20051 days = 2 tooltip = "EVTTOOLTIP20051" } }
	}
}

# 20051: Liege gains piety
character_event = {
	id = 20051
	desc = "EVTDESC20051"
	picture = GFX_evt_bishop
	border = GFX_event_normal_frame_religion
	
	is_triggered_only = yes
	
	option = {
		name = "EVTOPTA20051"
		piety = 15
	}
}

##############################
# COURT CHAPLAIN
# JOB: action_build_zeal
##############################

# 20218: The Court Priest has managed to raise an eager force of holy warriors
character_event = {
	id = 20218
	title = EVTNAME20218
	desc = EVTDESC20218
	picture = GFX_evt_battle
	border = GFX_event_normal_frame_war

	min_age = 16
	capable_only = yes
	prisoner = no
	has_job_title = yes
	
	trigger = {
		has_job_action = action_build_zeal
		NOT = { has_character_modifier = in_seclusion }
		NOT = { has_character_modifier = bedridden_illness }
		NOT = { trait = incapable }
		liege = {
			OR = { # The AI pretty much always just let their warriors stand around, getting a piety hit when they disband
				war = yes
				ai = no
			}
			is_adult = yes
			prisoner = no
			piety = 10
			NOT = { trait = incapable }
			OR = {
				NOT = { has_character_flag = tribal_build_zeal_troops }
				had_character_flag = { flag = tribal_build_zeal_troops days = 1825 }
			}
			OR = {
				war = no
				any_war = {
					OR = {
						using_cb = religious_revolt
						using_cb = pagan_holy_war
						using_cb = manifest_destiny_invasion
					}
				}
			}
		}
		location = {
			county = {
				is_occupied = no
			}
			ROOT = {
				liege = {
					is_capital = PREVPREV
				}
			}
		}
	}
	
	mean_time_to_happen = {
		months = 120
		
		modifier = {
			factor = 3.0
			liege = {
				tier = count
			}
		}
		
		job_event_mtth_modifier_learning_score = yes

	}
	
	option = {
		name = EVTOPTA20218
		
		piety = 25
		hidden_tooltip  = {
			liege = { character_event = { id = 20219 } }
		}
	}
}

# 20219: The liege is informed
character_event = {
	id = 20219
	desc = EVTDESC20219
	picture = GFX_evt_battle
	border = GFX_event_normal_frame_war
	
	is_triggered_only = yes
	
	immediate = {
		capital_scope = {
			ROOT = {
				spawn_unit = {
					province = PREV
					home = PREV
					owner = THIS
					#leader = none
					match_character = THIS
					match_mult = 0.075
					match_min = 100
					match_max = 3000
					attrition = 1.0
					earmark = tribal_build_zeal
					disband_on_peace = yes
					can_toggle_looting = no
				}
				spawn_unit = {
					province = PREV
					home = PREV
					owner = THIS
					#leader = none
					match_character = THIS
					match_mult = 0.075
					match_min = 100
					match_max = 3000
					attrition = 1.0
					earmark = tribal_build_zeal
					disband_on_peace = yes
					can_toggle_looting = no
				}
				spawn_unit = {
					province = PREV
					home = PREV
					owner = THIS
					#leader = none
					match_character = THIS
					match_mult = 0.075
					match_min = 100
					match_max = 3000
					attrition = 1.0
					earmark = tribal_build_zeal
					disband_on_peace = yes
					can_toggle_looting = no
				}
			}
		}
		
		clr_character_flag = tribal_build_zeal_troops
		set_character_flag = tribal_build_zeal_troops
		
		character_event = { id = 20220 days = 365 random = 90 }
	}
	
	option = {
		name = EVTOPTA20219
		opinion = {
			who = FROM
			modifier = opinion_grateful
			months = 60
		}
	}
}

# 20220: The men are displeased and disband
character_event = {
	id = 20220
	desc = EVTDESC20220
	picture = GFX_evt_battle
	border = GFX_event_normal_frame_war
	
	is_triggered_only = yes
	
	trigger = {
		has_earmarked_regiments = tribal_build_zeal
		
		NOR = {
			any_war = {
				defender = { character = ROOT }
				attacker = {
					NOT = {
						religion = ROOT
					}		
				}
			}
			any_war = {
				attacker = { character = ROOT }
				defender = {
					NOT = {
						religion = ROOT
					}				
				}
			}
		}
	}
	
	option = {
		name = EVTOPTA20220
		piety = -25
		clr_character_flag = tribal_build_zeal_troops
		disband_event_forces = tribal_build_zeal
	}
}
