﻿#Events related to the Court Chaplain's tasks

namespace = court_chaplain_task


####
#0001-0999: Task outcome events
# by Petter Vilberg
####
# 0201 - County Converted

# 0301 - Fabricate Claim?
# 0302 - Fabricate Claim on a Duchy
## Responses to Claim Fabrication:
# 0311 - County Owner
# 0312 - County Owner Lieges
# 0313 - Duchy Holder Claim
# 0314 - Top Liege - Duchy Claim

####
#1000-1999: Side effects from Religious Relations
# by Petter Vilberg
####
# 1001 - Loss of Piety
# 1002 - Loss of Theocratic Vassal Opinion

# 1101 - Extra Positive Theocratic Vassal Opinion


####
#2000-2999: Side effects from Conversion
# by Petter Vilberg
####
# 2001 - Resistance to conversion
# 2002 - Upset over conversion

# 2101 - Improve County Opinion
# 2102 - Increased County Development
# 2103 - Increased County Levies


####
#3000-3999: Side effects from Fabricate Claim
# by Petter Vilberg
####
# 3001 - Vassals Dislike Claim Fabrication
# 3002 - Loss of Piety
# 3003 - Powerful Vassals upset
# 3004 - Target upset



##################
# Task Outcome Events
# 0001-0999
##################


###########
# Convert Events
# 0201-0299
###########


###########
# Fabricate Claim Events
# 0301-0399
###########

scripted_effect court_chaplain_task_0301_charge_prestige_or_gold_effect = {
	# Either we charge prestige during certain struggle phases...
		if = {
			limit = {
				any_character_struggle = {
					involvement = involved
					is_struggle_parameter_active_secondary_county_trigger = {
						PARAMETER = claims_in_region_cost_prestige_not_gold_for_involved_parties
						COUNTY = scope:county
					}
				}
			}
			add_prestige = {
				value = $COST$
				multiply = -1
			}
		}
		# ... or else gold the rest of the time.
		else = { remove_short_term_gold = $COST$ }
}

#Fabricate Claim?
# by Petter Vilberg
court_chaplain_task.0301 = {
	type = letter_event
	opening = {
		desc = court_chaplain_task.0201.opening
	}
	desc = court_chaplain_task.0301.desc
	sender = scope:councillor

	option = {
		name = court_chaplain_task.0301.a
		court_chaplain_task_0301_charge_prestige_or_gold_effect = { COST = scope:councillor.court_chaplain_fabricate_claim_county_cost }
		add_unpressed_claim = scope:county
		show_as_tooltip = {
			scope:county_holder = {
				add_opinion = {
					target = root
					modifier = court_chaplain_fabricated_claim_opinion
					days = 3650
				}
			}
			if = {
				limit = {
					scope:county_holder = { top_liege != this }
					scope:county_holder.top_liege != root.top_liege
				}
				scope:county_holder.top_liege = {
					add_opinion = {
						target = root
						modifier = court_chaplain_fabricated_claim_on_vassal_opinion
						days = 3650
					}
				}
			}
		}
		hidden_effect = {
			if = {
				limit = {
					scope:councillor = {
						has_council_position = councillor_court_chaplain
					}
				}
				scope:councillor = {
					start_default_task = yes
				}
			}
			scope:county_holder = {
				trigger_event = court_chaplain_task.0311
			}
			if = {
				limit = {
					scope:county_holder = { top_liege != this }
					scope:county_holder.top_liege != root.top_liege
				}
				scope:county_holder.top_liege = {
					trigger_event = court_chaplain_task.0312		
				}
			}
		}
		ai_chance = {
			base = 100
			modifier = {
				add = -80
				short_term_gold < scope:councillor.court_chaplain_fabricate_claim_county_cost
			}	
			modifier = {
				factor = 0
				short_term_gold < 0
			}
		}
	}

	option = {
		name = court_chaplain_task.0301.b
		custom_tooltip = court_chaplain_task.0301.b.tt
		ai_chance = {
			base = 10
		}
	}
}


#Fabricate Claim on a Duchy
court_chaplain_task.0302 = {
	type = letter_event
	opening = {
		desc = court_chaplain_task.0201.opening
	}
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:county = {
						duchy = {
							is_title_created = yes
							exists = holder
							holder.faith != scope:councillor.liege.faith
						}
					}
				}
				desc = court_chaplain_task.0302.desc_heretic_addition
			}
			desc = court_chaplain_task.0302.desc
		}
	}
	sender = scope:councillor

	trigger = {
		scope:county = {
			duchy = {
				is_title_created = yes
				exists = holder
				holder != root
				holder.top_liege = scope:county.holder.top_liege
				save_temporary_scope_as = duchy
				root = {
					NOT = {
						has_claim_on = scope:duchy
					}
					#The recipient of this event must either hold land in the Duchy, or be Duke or above
					OR = {
						any_held_title = {
							title_tier = county
							duchy = scope:duchy
						}
						highest_held_title_tier > tier_county
					}
				}
			}
		}
	}

	weight_multiplier = {
		base = 1
		compare_modifier = {
			target = scope:councillor
			value = learning
			offset = -10
			multiplier = 0.1
		}
		modifier = {
			add = 4
			scope:councillor.liege = {
				top_liege != this
			}
			scope:councillor.liege.faith = scope:councillor.liege.top_liege.faith
			scope:county = {
				duchy = {
					is_title_created = yes
					exists = holder
					holder.faith != scope:councillor.liege.faith
					holder.top_liege = scope:councillor.liege.top_liege
				}
			}
		}
		modifier = {
			add = 1
			scope:county = {
				duchy = {
					is_title_created = yes
					exists = holder
					holder.faith != scope:councillor.liege.faith
				}
			}
		}
	}

	immediate = {
		scope:county = {
			duchy = {
				save_scope_as = duchy
				holder = {
					save_scope_as = duchy_holder
				}
			}
		}
	}

	option = {
		name = court_chaplain_task.0302.a
		court_chaplain_task_0301_charge_prestige_or_gold_effect = { COST = scope:councillor.court_chaplain_fabricate_claim_county_cost }
		add_unpressed_claim = scope:county
		show_as_tooltip = {
			scope:county_holder = {
				add_opinion = {
					target = root
					modifier = court_chaplain_fabricated_claim_opinion
					days = 3650
				}
			}
			if = {
				limit = {
					scope:county_holder = { top_liege != this }
					scope:county_holder.top_liege != root.top_liege
				}
				scope:county_holder.top_liege = {
					add_opinion = {
						target = root
						modifier = court_chaplain_fabricated_claim_on_vassal_opinion
						days = 3650
					}
				}
			}
		}
		hidden_effect = {
			if = {
				limit = {
					scope:councillor = {
						has_council_position = councillor_court_chaplain
					}
				}
				scope:councillor = {
					start_default_task = yes
				}
			}
			scope:county_holder = {
				trigger_event = court_chaplain_task.0311
			}
			if = {
				limit = {
					scope:county_holder = { top_liege != this }
					scope:county_holder.top_liege != root.top_liege
				}
				scope:county_holder.top_liege = {
					trigger_event = court_chaplain_task.0312		
				}
			}
		}
		ai_chance = {
			base = 100
			modifier = {
				add = -90
				short_term_gold < scope:councillor.court_chaplain_fabricate_claim_county_cost
			}	
			modifier = {
				factor = 0
				short_term_gold < 0
			}
		}
	}

	option = {
		name = court_chaplain_task.0302.b
		court_chaplain_task_0301_charge_prestige_or_gold_effect = { COST = scope:councillor.court_chaplain_fabricate_claim_duchy_cost }
		add_unpressed_claim = scope:duchy
		show_as_tooltip = {
			scope:duchy_holder = {
				add_opinion = {
					target = root
					modifier = court_chaplain_fabricated_claim_opinion
					days = 3650
				}
			}
			if = {
				limit = {
					scope:county_holder = { top_liege != this }
					scope:duchy_holder.top_liege != root.top_liege
					scope:duchy_holder.top_liege != scope:duchy_holder
				}
				scope:duchy_holder.top_liege = {
					add_opinion = {
						target = root
						modifier = court_chaplain_fabricated_claim_on_vassal_opinion
						days = 3650
					}
				}
			}
		}
		hidden_effect = {
			if = {
				limit = {
					scope:councillor = {
						has_council_position = councillor_court_chaplain
					}
				}
				scope:councillor = {
					start_default_task = yes
				}
			}
			scope:duchy_holder = {
				trigger_event = court_chaplain_task.0313
			}
			if = {
				limit = {
					scope:county_holder = { top_liege != this }
					scope:duchy_holder.top_liege != root.top_liege
					scope:duchy_holder.top_liege != scope:duchy_holder
				}
				scope:duchy_holder.top_liege = {
					trigger_event = court_chaplain_task.0314		
				}
			}
		}

		# Struggle Catalysts.
		if = {
			limit = {
				any_character_struggle = {
					involvement = involved
					activate_struggle_catalyst_secondary_character_involvement_involved_trigger = {
						CATALYST = catalyst_fabricating_duchy_level_claims
						CHAR = scope:duchy_holder
					}
				}
			}
			every_character_struggle = {
				involvement = involved
				limit = {
					activate_struggle_catalyst_secondary_character_involvement_involved_trigger = {
						CATALYST = catalyst_fabricating_duchy_level_claims
						CHAR = scope:duchy_holder
					}
				}
				activate_struggle_catalyst = {
					catalyst = catalyst_fabricating_duchy_level_claims
					character = scope:councillor_liege
				}
			}
		}

		ai_chance = {
			base = 100
			modifier = {
				add = -95
				short_term_gold < scope:councillor.court_chaplain_fabricate_claim_duchy_cost
			}	
			modifier = {
				factor = 0
				short_term_gold < 0
			}
		}
	}

	option = {
		name = court_chaplain_task.0301.b
		custom_tooltip = court_chaplain_task.0301.b.tt
		ai_chance = {
			base = 10
		}
	}
}



###
# Responses to claim fabrication
# 0311-0314

#County Owner
court_chaplain_task.0311 = {
	type = character_event
	title = court_chaplain_task.0311.t
	desc = {
		desc = court_chaplain_task.0311.opening
		desc = court_chaplain_task.0311.end
	}
	theme = learning
	left_portrait = {
		character = scope:councillor_liege
		animation = schadenfreude
	}
	lower_left_portrait = {
		character = scope:councillor
		animation = scheme
	}

	immediate = {
		show_as_tooltip = {
			scope:councillor_liege = {
				add_unpressed_claim = scope:county
			}
		}
	}
	
	option = {
		name = court_chaplain_task.0311.a
		add_opinion = {
			target = scope:councillor_liege
			modifier = court_chaplain_fabricated_claim_opinion
			days = 3650
		}
	}
}

#County Owner Lieges
court_chaplain_task.0312 = {
	type = character_event
	title = court_chaplain_task.0311.t
	desc = {
		desc = court_chaplain_task.0311.opening
		desc = court_chaplain_task.0311.end
	}
	theme = learning
	left_portrait = {
		character = scope:county_holder
		animation = shock
	}
	right_portrait = {
		character = scope:councillor_liege
		animation = scheme
	}
	lower_right_portrait = scope:councillor

	immediate = {
		show_as_tooltip = {
			scope:councillor_liege = {
				add_unpressed_claim = scope:county
			}
		}
	}
	
	option = {
		name = court_chaplain_task.0312.a
		add_opinion = {
			target = scope:councillor_liege
			modifier = court_chaplain_fabricated_claim_on_vassal_opinion
			days = 3650
		}
	}
}

#Holder receives notification about Duchy claim
court_chaplain_task.0313 = {
	type = character_event
	title = court_chaplain_task.0313.t
	desc = {
		desc = court_chaplain_task.0311.opening
		desc = court_chaplain_task.0311.end
	}
	theme = learning
	left_portrait = {
		character = scope:councillor_liege
		animation = scheme
	}
	lower_left_portrait = {
		character = scope:councillor
		animation = schadenfreude
	}

	immediate = {
		show_as_tooltip = {
			scope:councillor_liege = {
				add_unpressed_claim = scope:duchy
			}
		}
	}
	
	option = {
		name = court_chaplain_task.0311.a
		add_opinion = {
			target = scope:councillor_liege
			modifier = court_chaplain_fabricated_claim_opinion
			days = 3650
		}
	}
}

#Top liege receives notification about Duchy claim
court_chaplain_task.0314 = {
	type = character_event
	title = court_chaplain_task.0313.t
	desc = {
		desc = court_chaplain_task.0311.opening
		desc = court_chaplain_task.0311.end
	}
	theme = learning
	left_portrait = {
		character = scope:duchy_holder
		animation = shock
	}
	right_portrait = {
		character = scope:councillor_liege
		animation = scheme
	}
	lower_right_portrait = scope:councillor

	immediate = {
		show_as_tooltip = {
			scope:councillor_liege = {
				add_unpressed_claim = scope:duchy
			}
		}
	}
	
	option = {
		name = court_chaplain_task.0312.a
		add_opinion = {
			target = scope:councillor_liege
			modifier = court_chaplain_fabricated_claim_on_vassal_opinion
			days = 3650
		}
	}
}


###############
# Side effects from Religious Relations
# 1000-1999
###############

###Bad Side Effects


#Loss of Piety
# by Petter Vilberg
court_chaplain_task.1001 = {
	hidden = yes

	trigger = {
		exists = cp:councillor_court_chaplain
		scope:councillor = cp:councillor_court_chaplain
		scope:councillor = {
			learning < high_skill_rating
		}
	}

	weight_multiplier = {
		base = 1
		compare_modifier = {
			target = scope:councillor
			value = learning
			multiplier = -0.2
			offset = inverted_high_skill_rating
		}
		# Half as likely if you can't replace your councillor
		modifier = {
			factor = 0.5
			faith = {
				has_doctrine_parameter = clerical_appointment_head_of_faith
				has_doctrine_parameter = clerical_appointment_fixed
			}
		}
	}

	immediate = {
		cp:councillor_court_chaplain = {
			save_scope_as = active_councillor
		}
		set_variable = {
			name = had_court_chaplain_task_side_effect
			value = yes
			days = court_chaplain_task_side_effect_cooldown
		}
		send_interface_message = {
			type = msg_court_chaplain_task_bad
			title = court_chaplain_task.1001.notification
			desc = {
				triggered_desc = {
					trigger = {
						scope:active_councillor = { learning <= average_skill_level }
					}
					desc = task_learning_bad_unskilled_notification_tooltip
				}
				triggered_desc = {
					trigger = {
						scope:active_councillor = { learning > average_skill_level }
					}
					desc = task_learning_bad_skilled_notification_tooltip
				}
			}
			tooltip = task_religious_relations_notification_tooltip

			left_icon = scope:councillor
			
			add_piety = minor_piety_loss
		}
	}
}

#Loss of Theocratic Vassal Opinion
# by Petter Vilberg

scripted_trigger court_chaplain_task_1002_vassal_trigger = {
	save_temporary_scope_as = vassal_temp  #Unop: Prevent self-target
	NOR = {
		scope:vassal_temp = scope:councillor
		has_opinion_modifier = {
			target = root
			modifier = bad_religious_relations_opinion
		}
		has_opinion_modifier = {
			target = root
			modifier = bonus_religious_relations_opinion
		}
	}
}

court_chaplain_task.1002 = {
	hidden = yes

	trigger = {
		exists = cp:councillor_court_chaplain
		scope:councillor = cp:councillor_court_chaplain
		scope:councillor = {
			learning < high_skill_rating
		}
		any_theocratic_vassal = {
			court_chaplain_task_1002_vassal_trigger = yes
		}
	}

	weight_multiplier = {
		base = 1
		compare_modifier = {
			target = scope:councillor
			value = learning
			multiplier = -0.2
			offset = inverted_high_skill_rating
		}
	}

	immediate = {
		cp:councillor_court_chaplain = {
			save_scope_as = active_councillor
		}
		set_variable = {
			name = had_court_chaplain_task_side_effect
			value = yes
			days = court_chaplain_task_side_effect_cooldown
		}
		random_theocratic_vassal = {
			limit = {
				court_chaplain_task_1002_vassal_trigger = yes
			}
			save_scope_as = vassal
		}

		send_interface_message = {
			type = msg_court_chaplain_task_bad
			title = court_chaplain_task.1002.notification
			desc = {
				triggered_desc = {
					trigger = {
						scope:active_councillor = { learning <= average_skill_level }
					}
					desc = task_learning_bad_unskilled_notification_tooltip
				}
				triggered_desc = {
					trigger = {
						scope:active_councillor = { learning > average_skill_level }
					}
					desc = task_learning_bad_skilled_notification_tooltip
				}
			}
			tooltip = task_religious_relations_notification_tooltip

			left_icon = scope:vassal
			right_icon = scope:councillor

			scope:vassal = {
				add_opinion = {
					target = root
					modifier = bad_religious_relations_opinion
					days = court_chaplain_task_modifier_duration
				}
			}
		}
	}

}

###GOOD Side Effects

#Gain extra opinion
# by Petter Vilberg
scripted_trigger court_chaplain_task_1101_vassal_trigger = {
	save_temporary_scope_as = vassal_temp
	NOR = {
		scope:vassal_temp = scope:councillor
		has_opinion_modifier = {
			target = root
			modifier = bonus_religious_relations_opinion
		}
		has_opinion_modifier = {
			target = root
			modifier = bad_religious_relations_opinion
		}
	}
}

court_chaplain_task.1101 = {
	hidden = yes

	trigger = {
		exists = cp:councillor_court_chaplain
		scope:councillor = cp:councillor_court_chaplain
		scope:councillor = {
			
			learning > mediocre_skill_rating
		}
		any_theocratic_vassal = {
			court_chaplain_task_1101_vassal_trigger = yes
		}
	}

	weight_multiplier = {
		base = 1
		compare_modifier = {
			target = scope:councillor
			value = learning
			multiplier = 0.2
			offset = inverted_mediocre_skill_rating
		}
	}

	immediate = {
		cp:councillor_court_chaplain = {
			save_scope_as = active_councillor
		}
		set_variable = {
			name = had_court_chaplain_task_side_effect
			value = yes
			days = court_chaplain_task_side_effect_cooldown
		}
		random_theocratic_vassal = {
			limit = {
				court_chaplain_task_1101_vassal_trigger = yes
			}
			save_scope_as = vassal
		}

		send_interface_message = {
			type = msg_court_chaplain_task_good
			title = court_chaplain_task.1101.notification
			desc = {
				triggered_desc = {
					trigger = {
						scope:active_councillor = { learning <= average_skill_level }
					}
					desc = task_learning_good_unskilled_notification_tooltip
				}
				triggered_desc = {
					trigger = {
						scope:active_councillor = { learning > average_skill_level }
					}
					desc = task_learning_good_skilled_notification_tooltip
				}
			}
			tooltip = task_religious_relations_notification_tooltip

			left_icon = scope:vassal
			right_icon = scope:councillor

			scope:vassal = {
				add_opinion = {
					target = root
					modifier = bonus_religious_relations_opinion
					days = court_chaplain_task_modifier_duration
				}
			}
		}
	}
}


###############
# Side effects from Conversion
# 2000-2999
###############

###Bad Side Effects


#Resistance to conversion
# by Petter Vilberg
court_chaplain_task.2001 = {
	hidden = yes

	trigger = {
		exists = cp:councillor_court_chaplain
		scope:councillor = cp:councillor_court_chaplain
		scope:councillor = {
			learning < high_skill_rating
		}
		scope:county = {
			NOT = { has_county_modifier = court_chaplain_resisted_conversion_modifier }
		}
	}

	weight_multiplier = {
		base = 1
		compare_modifier = {
			target = scope:councillor
			value = learning
			multiplier = -0.2
			offset = inverted_high_skill_rating
		}
	}

	immediate = {
		cp:councillor_court_chaplain = {
			save_scope_as = active_councillor
		}
		set_variable = {
			name = had_court_chaplain_task_side_effect
			value = yes
			days = court_chaplain_task_side_effect_cooldown
		}
		send_interface_message = {
			type = msg_court_chaplain_task_bad
			title = court_chaplain_task.2001.notification
			desc = {
				triggered_desc = {
					trigger = {
						scope:active_councillor = { learning <= average_skill_level }
					}
					desc = task_learning_bad_unskilled_notification_tooltip
				}
				triggered_desc = {
					trigger = {
						scope:active_councillor = { learning > average_skill_level }
					}
					desc = task_learning_bad_skilled_notification_tooltip
				}
			}
			tooltip = task_conversion_notification_tooltip
			left_icon = scope:county
			right_icon = scope:councillor
			
			scope:county = {
				add_county_modifier = {
					modifier = court_chaplain_resisted_conversion_modifier
					days = court_chaplain_task_modifier_duration
				}
			}
		}
	}
}

#Upset over conversion
# by Petter Vilberg
court_chaplain_task.2002 = {
	hidden = yes

	trigger = {
		exists = cp:councillor_court_chaplain
		scope:councillor = cp:councillor_court_chaplain
		scope:councillor = {
			learning < high_skill_rating
		}
		scope:county = {
			NOR = {
				has_county_modifier = court_chaplain_county_conversion_upset_modifier
				has_county_modifier = court_chaplain_county_conversion_support_modifier
			}
		}
	}

	weight_multiplier = {
		base = 1
		compare_modifier = {
			target = scope:councillor
			value = learning
			multiplier = -0.2
			offset = inverted_high_skill_rating
		}
	}

	immediate = {
		cp:councillor_court_chaplain = {
			save_scope_as = active_councillor
		}
		set_variable = {
			name = had_court_chaplain_task_side_effect
			value = yes
			days = court_chaplain_task_side_effect_cooldown
		}
		send_interface_message = {
			type = msg_court_chaplain_task_bad
			title = court_chaplain_task.2002.notification
			desc = {
				triggered_desc = {
					trigger = {
						scope:active_councillor = { learning <= average_skill_level }
					}
					desc = task_learning_bad_unskilled_notification_tooltip
				}
				triggered_desc = {
					trigger = {
						scope:active_councillor = { learning > average_skill_level }
					}
					desc = task_learning_bad_skilled_notification_tooltip
				}
			}
			tooltip = task_conversion_notification_tooltip

			left_icon = scope:county
			right_icon = scope:councillor

			scope:county = {
				add_county_modifier = {
					modifier = court_chaplain_county_conversion_upset_modifier
					days = court_chaplain_task_modifier_duration
				}
			}
		}
	}
}


###Good Side Effects



#Improve County opinion
# by Petter Vilberg

court_chaplain_task.2101 = {
	hidden = yes
	
	trigger = {
		exists = cp:councillor_court_chaplain
		scope:councillor = cp:councillor_court_chaplain
		scope:councillor = {
			
			learning > mediocre_skill_rating
		}
		scope:county = {
			NOR = {
				has_county_modifier = court_chaplain_county_conversion_upset_modifier
				has_county_modifier = court_chaplain_county_conversion_support_modifier
			}
		}
	}

	weight_multiplier = {
		base = 1
		compare_modifier = {
			target = scope:councillor
			value = learning
			multiplier = 0.2
			offset = inverted_mediocre_skill_rating
		}
	}

	immediate = {
		cp:councillor_court_chaplain = {
			save_scope_as = active_councillor
		}
		set_variable = {
			name = had_court_chaplain_task_side_effect
			value = yes
			days = court_chaplain_task_side_effect_cooldown
		}
		send_interface_message = {
			type = msg_court_chaplain_task_good
			title = court_chaplain_task.2101.notification
			desc = {
				triggered_desc = {
					trigger = {
						scope:active_councillor = { learning <= average_skill_level }
					}
					desc = task_learning_good_unskilled_notification_tooltip
				}
				triggered_desc = {
					trigger = {
						scope:active_councillor = { learning > average_skill_level }
					}
					desc = task_learning_good_skilled_notification_tooltip
				}
			}
			tooltip = task_conversion_notification_tooltip

			left_icon = scope:county
			right_icon = scope:councillor

			scope:county = {
				add_county_modifier = {
					modifier = court_chaplain_county_conversion_support_modifier
					days = court_chaplain_task_modifier_duration
				}
			}
		}
	}
}


#Increased County Development
# by Petter Vilberg

court_chaplain_task.2102 = {
	hidden = yes
	
	trigger = {
		exists = cp:councillor_court_chaplain
		scope:councillor = cp:councillor_court_chaplain
		scope:councillor = {
			
			learning > mediocre_skill_rating
		}
		scope:county = {
			NOT = { has_county_modifier = court_chaplain_religious_construction_modifier }
		}
	}

	weight_multiplier = {
		base = 1
		compare_modifier = {
			target = scope:councillor
			value = learning
			multiplier = 0.2
			offset = inverted_mediocre_skill_rating
		}
	}

	immediate = {
		cp:councillor_court_chaplain = {
			save_scope_as = active_councillor
		}
		set_variable = {
			name = had_court_chaplain_task_side_effect
			value = yes
			days = court_chaplain_task_side_effect_cooldown
		}
		send_interface_message = {
			type = msg_court_chaplain_task_good
			title = court_chaplain_task.2102.notification
			desc = {
				triggered_desc = {
					trigger = {
						scope:active_councillor = { learning <= average_skill_level }
					}
					desc = task_learning_good_unskilled_notification_tooltip
				}
				triggered_desc = {
					trigger = {
						scope:active_councillor = { learning > average_skill_level }
					}
					desc = task_learning_good_skilled_notification_tooltip
				}
			}
			tooltip = task_conversion_notification_tooltip

			left_icon = scope:county
			right_icon = scope:councillor

			scope:county = {
				add_county_modifier = {
					modifier = court_chaplain_religious_construction_modifier
					days = court_chaplain_task_modifier_duration
				}
			}
		}
	}
}


#Increased County Levies
# by Petter Vilberg

court_chaplain_task.2103 = {
	hidden = yes
	
	trigger = {
		exists = cp:councillor_court_chaplain
		scope:councillor = cp:councillor_court_chaplain
		scope:councillor = {
			
			learning > mediocre_skill_rating
		}
		scope:county = {
			NOT = { has_county_modifier = court_chaplain_religious_fervor_modifier }
		}
	}

	weight_multiplier = {
		base = 1
		compare_modifier = {
			target = scope:councillor
			value = learning
			multiplier = 0.2
			offset = inverted_mediocre_skill_rating
		}
	}

	immediate = {
		cp:councillor_court_chaplain = {
			save_scope_as = active_councillor
		}
		set_variable = {
			name = had_court_chaplain_task_side_effect
			value = yes
			days = court_chaplain_task_side_effect_cooldown
		}
		send_interface_message = {
			type = msg_court_chaplain_task_good
			title = court_chaplain_task.2103.notification
			desc = {
				triggered_desc = {
					trigger = {
						scope:active_councillor = { learning <= average_skill_level }
					}
					desc = task_learning_good_unskilled_notification_tooltip
				}
				triggered_desc = {
					trigger = {
						scope:active_councillor = { learning > average_skill_level }
					}
					desc = task_learning_good_skilled_notification_tooltip
				}
			}
			tooltip = task_conversion_notification_tooltip

			left_icon = scope:county
			right_icon = scope:councillor

			scope:county = {
				add_county_modifier = {
					modifier = court_chaplain_religious_fervor_modifier
					days = court_chaplain_task_modifier_duration
				}
			}
		}
	}
}

####################
# Fabricate Claim Side Effects
# 3000-3999
####################

###BAD Side Effects

#Vassals Dislike Claim Fabrication
# by Petter Vilberg
court_chaplain_task.3001 = {
	type = character_event
	title = court_chaplain_task.3001.t
	desc = court_chaplain_task.3001.desc
	theme = learning
	left_portrait = {
		character = scope:councillor
		animation = shame
	}

	trigger = {
		exists = cp:councillor_court_chaplain
		scope:councillor = cp:councillor_court_chaplain
		scope:councillor = {
			learning < high_skill_rating
		}
		scope:county = {
			holder = {
				target_is_liege_or_above = root
			}
		}
		any_vassal = {
			highest_held_title_tier >= tier_county
		}
		NOT = { has_character_modifier = court_chaplain_vassal_claim_upset_modifier }
	}

	weight_multiplier = {
		base = 1
		compare_modifier = {
			target = scope:councillor
			value = learning
			multiplier = -0.2
			offset = inverted_high_skill_rating
		}
	}

	immediate = {
		set_variable = {
			name = had_court_chaplain_task_side_effect
			value = yes
			days = court_chaplain_task_side_effect_cooldown
		}
	}

	option = {
		name = court_chaplain_task.3001.a
		add_character_modifier = {
			modifier = court_chaplain_vassal_claim_upset_modifier
			days = court_chaplain_task_modifier_duration
		}
	}
}

#Loss of Piety
# by Petter Vilberg
court_chaplain_task.3002 = {
	hidden = yes

	trigger = {
		exists = cp:councillor_court_chaplain
		scope:councillor = cp:councillor_court_chaplain
		scope:councillor = {
			learning < high_skill_rating
		}
	}

	weight_multiplier = {
		base = 1
		compare_modifier = {
			target = scope:councillor
			value = learning
			multiplier = -0.2
			offset = inverted_high_skill_rating
		}
	}

	immediate = {
		cp:councillor_court_chaplain = {
			save_scope_as = active_councillor
		}
		set_variable = {
			name = had_court_chaplain_task_side_effect
			value = yes
			days = court_chaplain_task_side_effect_cooldown
		}
		send_interface_message = {
			type = msg_court_chaplain_task_bad
			title = court_chaplain_task.3002.notification
			desc = {
				triggered_desc = {
					trigger = {
						scope:active_councillor = { learning <= average_skill_level }
					}
					desc = task_learning_bad_unskilled_notification_tooltip
				}
				triggered_desc = {
					trigger = {
						scope:active_councillor = { learning > average_skill_level }
					}
					desc = task_learning_bad_skilled_notification_tooltip
				}
			}
			tooltip = task_fabricate_claim_notification_tooltip

			left_icon = scope:councillor

			add_piety = medium_piety_loss
		}
	}
}


#Powerful Vassals upset
# by Petter Vilberg
scripted_trigger court_chaplain_task_3003_powerful_vassal_trigger = {
	is_powerful_vassal = yes
	this != scope:councillor
	save_temporary_scope_as = vassal
	scope:county = {
		holder != scope:vassal
	}
	NOT = {
		has_opinion_modifier = {
			target = root
			modifier = court_chaplain_upsetting_claim_fabrication_opinion
		}
	}
}

court_chaplain_task.3003 = {
	type = letter_event
	opening = court_chaplain_task.3003.opening
	desc = court_chaplain_task.3003.desc
	sender = scope:vassal

	trigger = {
		exists = cp:councillor_court_chaplain
		scope:councillor = cp:councillor_court_chaplain
		scope:councillor = {
			learning < high_skill_rating
		}
		any_vassal = {
			court_chaplain_task_3003_powerful_vassal_trigger = yes
		}
		NOT = { has_character_modifier = court_chaplain_vassal_claim_upset_modifier }
	}

	weight_multiplier = {
		base = 1
		compare_modifier = {
			target = scope:councillor
			value = learning
			multiplier = -0.2
			offset = inverted_high_skill_rating
		}
		compare_modifier = {
			value = dread
			multiplier = -0.05
		}
	}

	immediate = {
		set_variable = {
			name = had_court_chaplain_task_side_effect
			value = yes
			days = court_chaplain_task_side_effect_cooldown
		}
		random_vassal = {
			limit = {
				court_chaplain_task_3003_powerful_vassal_trigger = yes
			}
			weight = {
				base = 1
				modifier = {
					add = 3
					has_claim_on = scope:county
				}
			}
			if = {
				limit = { root = { is_ai = no }	}
				assign_quirk_effect = yes
			}
			save_scope_as = vassal
		}
	}

	option = {
		name = court_chaplain_task.3003.a
		scope:vassal = {
			add_opinion = {
				target = root
				modifier = court_chaplain_upsetting_claim_fabrication_opinion
				days = court_chaplain_task_modifier_duration
			}
		}
	}

	option = {
		name = court_chaplain_task.3003.b
		trigger = {
			OR = {
				has_trait = arrogant
				has_trait = callous
				dread > 50
			}
		}
		exclusive = yes
		scope:vassal = {
			add_opinion = {
				target = root
				modifier = court_chaplain_upsetting_claim_fabrication_opinion
				days = court_chaplain_task_modifier_duration
			}
		}
	}
}


#Target upset
# by Petter Vilberg
court_chaplain_task.3004 = {
	type = letter_event
	opening = court_chaplain_task.3004.opening
	desc = court_chaplain_task.3004.desc
	sender = scope:target

	trigger = {
		exists = cp:councillor_court_chaplain
		scope:councillor = cp:councillor_court_chaplain
		scope:councillor = {
			learning < high_skill_rating
		}
		scope:county = {
			holder = {
				NOT = {
					has_opinion_modifier = {
						target = root
						modifier = court_chaplain_vassal_claim_target_upset_modifier
					}
				}
				NOT = { target_is_liege_or_above = root }
			}
		}
	}

	weight_multiplier = {
		base = 1
		compare_modifier = {
			target = scope:councillor
			value = learning
			multiplier = 0.2
			offset = inverted_mediocre_skill_rating
		}
	}

	immediate = {
		set_variable = {
			name = had_court_chaplain_task_side_effect
			value = yes
			days = court_chaplain_task_side_effect_cooldown
		}
		scope:county = {
			holder = {
				save_scope_as = target
			}
		}
		if = {
			limit = {
				scope:target = { top_liege != this }
			}
			scope:target.top_liege = {
				save_scope_as = target_liege
			}
		}
	}

	option = {
		name = court_chaplain_task.3004.a
		add_prestige = minor_prestige_loss
		scope:target = {
			add_opinion = {
				target = root
				modifier = court_chaplain_vassal_claim_target_upset_modifier
				days = court_chaplain_task_modifier_duration
			}
		}
		if = {
			limit = { exists = scope:target_liege }
			scope:target_liege = {
				add_opinion = {
					target = root
					modifier = court_chaplain_vassal_claim_target_upset_modifier
					days = court_chaplain_task_modifier_duration
				}
			}
		}
	}
}

# Maintenance for vassal conversion messages

scripted_effect fetch_council_task_affected_vassal_informees_effect = {
	scope:county ?= {
		holder ?= {
			if = {
				limit = {
					is_ai = no
					NOT = { scope:councillor_liege ?= this }
				}
				add_to_list = informees
			}
			every_liege_or_above = {
				limit = {
					is_ai = no
					NOT = { scope:councillor_liege ?= this }
					highest_held_title_tier < scope:councillor_liege.highest_held_title_tier
				}
				add_to_list = informees
			}
		}
	}
}

court_chaplain_task.8000 = { # Started
	scope = none
	hidden = yes

	trigger = {
		# Stop spam if target is changed a lot e.g. on a single tick
		exists = scope:councillor.councillor_task_target
		scope:set_county.title_province ?= scope:councillor.councillor_task_target
	}

	immediate = {
		scope:county.faith ?= { save_scope_as = old_faith }
		fetch_council_task_affected_vassal_informees_effect = yes
		every_in_list = {
			list = informees
			switch = {
				trigger = faith
				scope:councillor_liege.faith = { # Good if same faith as liege
					send_interface_message = {
						type = msg_council_conversion_good
						title = liege_converting_county_title
						desc = liege_converting_county_desc
						left_icon = scope:councillor_liege
						right_icon = scope:county
					}
				}
				scope:old_faith = {
					send_interface_message = { # Bad if same faith as county
						type = msg_council_conversion_bad
						title = liege_converting_county_title
						desc = liege_converting_county_desc
						left_icon = scope:councillor_liege
						right_icon = scope:county
					}
				}
				fallback = {
					send_interface_message = { # Neutral otherwise
						type = msg_council_conversion_neutral
						title = liege_converting_county_title
						desc = liege_converting_county_desc
						left_icon = scope:liege_scope
						right_icon = scope:county
					}
				}
			}
		}
	}
}

court_chaplain_task.8001 = { # Cancelled
	scope = none
	hidden = yes
	cooldown = { days = 1 }

	trigger = {
		NOT = {
			scope:county ?= { has_variable = county_conversion_completed }
		}
	}

	immediate = {
		# Message for vassals
		scope:county.faith ?= { save_scope_as = old_faith }
		fetch_council_task_affected_vassal_informees_effect = yes
		every_in_list = {
			list = informees
			switch = {
				trigger = faith
				scope:old_faith = { # Good if same faith as county
					send_interface_message = {
						type = msg_council_conversion_good
						title = liege_stopped_converting_county_title
						desc = liege_stopped_converting_county_desc
						left_icon = scope:councillor_liege
						right_icon = scope:county
					}
				}
				scope:councillor_liege.faith = { # Bad if same faith as liege
					send_interface_message = {
						type = msg_council_conversion_bad
						title = liege_stopped_converting_county_title
						desc = liege_stopped_converting_county_desc
						left_icon = scope:councillor_liege
						right_icon = scope:county
					}
				}
				fallback = {
					send_interface_message = { # Neutral otherwise
						type = msg_council_conversion_neutral
						title = liege_converting_county_title
						desc = liege_converting_county_desc
						left_icon = scope:liege_scope
						right_icon = scope:county
					}
				}
			}
		}
	}
}

court_chaplain_task.8002 = { # Completed
	scope = none
	hidden = yes

	immediate = {
		scope:county ?= {
			set_variable = {
				name = county_conversion_completed
				weeks = 1
			}
		}
		fetch_council_task_affected_vassal_informees_effect = yes
		every_in_list = {
			list = informees
			switch = {
				trigger = faith
				scope:councillor_liege.faith ?= { # Good if same faith as county
					send_interface_message = {
						type = msg_council_conversion_good
						title = liege_converted_county_title
						desc = liege_converted_county_desc
						left_icon = scope:councillor_liege
						right_icon = scope:county
					}
				}
				scope:old_faith ?= { # Bad if same faith as liege
					send_interface_message = {
						type = msg_council_conversion_bad
						title = liege_converted_county_title
						desc = liege_converted_county_desc
						left_icon = scope:councillor_liege
						right_icon = scope:county
					}
				}
				fallback = {
					send_interface_message = { # Neutral otherwise
						type = msg_council_conversion_neutral
						title = liege_converted_county_title
						desc = liege_converted_county_desc
						left_icon = scope:liege_scope
						right_icon = scope:county
					}
				}
			}
		}
	}
}

