﻿#Events related to the Marshal's tasks

namespace = chancellor_task

####
# 0001-0999: Reserved for Task outcome events and maintenance
###

####
# 1000-1999: Side effects from Foreign Affairs
# by Petter Vilberg
####
# 1001 - Neighbor gets County claim
# 1002 - Truce against you is shortened
# 1003 - Neighbor opinion loss
# 1102 - Shorten a truce against someone else
# 1103-1104 - Increase neighbor opinion


###
# 2000-2999: Side effects from Integrate Duchy
# by Petter Vilberg
###
# 2001 - Local nobles resist integration
# 2002 - Local culture resists integration
# 2101 - Local nobles endorse integration
# 2102 - Local culture embraces new kingdom
# 2103 - Gain development or integration progress


###
# 3000-3999: Side effects from Domestic Affairs
# by Petter Vilberg
###
# 3001 - Powerful Vassal opinion loss
# 3002 - Worsen Vassal Contract
# 3003 - Prestige loss
# 3101 - Stop vassal infighting
# 3102 - Improve vassal contract
# 3103 - Powerful Vassal Opinion gain
# 3104 - Force vassal into partition


#####



##################
# Task outcome events and maintenance
# 0001-0999
##################

# Bestow Royal favor success
chancellor_task.0991 = {
	hidden = yes

	immediate = {
		scope:target_character = {
			add_opinion = {
				target = scope:councillor_liege
				modifier = chancellor_bestow_royal_favor_opinion
				opinion = chancellor_bestow_royal_favor_opinion_increase_per_success
			}
		}

		#If you've increased their opinion as high as it'll go we end the task here
		if = {
			limit = {
				scope:target_character = {
					opinion = {
						target = scope:councillor_liege
						value >= 100
					}
				}
			}
			send_interface_message = {
				type = msg_chancellor_task_good
				title = task_bestow_royal_favor
				desc = chancellor_task.0991_end_desc
				left_icon = scope:target_character
				right_icon = scope:chancellor
				show_as_tooltip = {
					scope:target_character = {
						add_opinion = {
							target = scope:councillor_liege
							modifier = chancellor_bestow_royal_favor_opinion
							opinion = chancellor_bestow_royal_favor_opinion_increase_per_success
						}
					}
				}
				scope:councillor = {
					start_default_task = yes
				}
			}
		}
		else = {
			send_interface_message = {
				type = msg_chancellor_task_good
				title = task_bestow_royal_favor
				desc = chancellor_task.0991_increase_desc
				left_icon = scope:target_character
				show_as_tooltip = {
					scope:target_character = {
						add_opinion = {
							target = scope:councillor_liege
							modifier = chancellor_bestow_royal_favor_opinion
							opinion = chancellor_bestow_royal_favor_opinion_increase_per_success
						}
					}
				}
			}
		}
	}
}


# Check that you're still the target of Bestow Royal Favor task (this event will loop until you're not)
chancellor_task.0999 = {
	hidden = yes

	immediate = {
		if = {
			limit = {
				exists = scope:councillor_liege
				exists = scope:councillor
				scope:councillor = {
					is_performing_council_task = task_bestow_royal_favor
					councillor_task_target = root
				}
			}
			if = { # If the liege has improved their court you get a better modifier
				limit = {
					scope:councillor_liege = {
						court_grandeur_current_level >= 7
					}
					has_character_modifier = chancellor_task_bestow_royal_favor_vassal_modifier
				}
				remove_character_modifier = chancellor_task_bestow_royal_favor_vassal_modifier
				add_character_modifier = {
					modifier = chancellor_task_bestow_royal_favor_vassal_boosted_modifier
				}
			}
			else_if = {
				limit = {
					scope:councillor_liege = {
						court_grandeur_current_level < 7
					}
					has_character_modifier = chancellor_task_bestow_royal_favor_vassal_boosted_modifier
				}
				remove_character_modifier = chancellor_task_bestow_royal_favor_vassal_boosted_modifier
				add_character_modifier = {
					modifier = chancellor_task_bestow_royal_favor_vassal_modifier
				}
			}
			trigger_event = {
				id = chancellor_task.0999
				days = 30
			}
		}
		else = {
			if = {
				limit = {
					has_character_modifier = chancellor_task_bestow_royal_favor_vassal_modifier
				}
				remove_character_modifier = chancellor_task_bestow_royal_favor_vassal_modifier
			}
			if = {
				limit = {
					has_character_modifier = chancellor_task_bestow_royal_favor_vassal_boosted_modifier
				}
				remove_character_modifier = chancellor_task_bestow_royal_favor_vassal_boosted_modifier
			}
		}
	}
}


##################
# Side Effects from Foreign Affairs
# 1001-1999
##################

###
#Bad Side Effects
###

#Someone gets a Claim on you
scripted_trigger chancellor_task_1001_new_claim_trigger = {
	save_temporary_scope_as = target_county
	scope:neighboring_ruler = {
		is_governor = no
		NOT = {
			has_claim_on = scope:target_county
		}
		any_character_to_title_neighboring_county = {
			this = scope:target_county
		}
	}
}

scripted_trigger chancellor_task_1001_neighboring_ruler_trigger = {
	save_temporary_scope_as = neighboring_ruler
	root = {
		any_sub_realm_county = {
			chancellor_task_1001_new_claim_trigger = yes
		}		
	}
}

chancellor_task.1001 = {
	type = character_event
	title = chancellor_task.1001.t
	desc = chancellor_task.1001.desc
	theme = diplomacy
	left_portrait = {
		character = scope:councillor
		animation = shame
	}
	lower_left_portrait = scope:neighboring_ruler
	
	trigger = {
		NOT = {
			has_character_flag = had_msg_chancellor_task_1001
		}
		exists = cp:councillor_chancellor
		scope:councillor = cp:councillor_chancellor
		scope:councillor = {
			diplomacy < high_skill_rating
		}
		any_neighboring_realm_same_rank_owner = {
			chancellor_task_1001_neighboring_ruler_trigger = yes
		}
	}

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

	immediate = {
		add_character_flag = {
			flag = had_msg_chancellor_task_1001
			years = 5
		}
		set_variable = {
			name = had_chancellor_task_side_effect
			value = yes
			days = chancellor_task_side_effect_cooldown
		}
		random_neighboring_realm_same_rank_owner = {
			limit = {
				chancellor_task_1001_neighboring_ruler_trigger = yes
			}
			save_scope_as = neighboring_ruler
		}
		random_sub_realm_county = {
			limit = {
				chancellor_task_1001_new_claim_trigger = yes
			}
			save_scope_as = target_county
		}
	}

	option = {
		name = chancellor_task.1001.a
		scope:neighboring_ruler = {
			add_unpressed_claim = scope:target_county

			hidden_effect = {
				send_interface_message = {
					type = msg_chancellor_task_good
					title = chancellor_task.1001.title_message
					desc = chancellor_task.1001.message
					left_icon = scope:councillor
					add_unpressed_claim = scope:target_county
				}
			}
		}
	}
}


#Shorten a truce against you
# by Petter Vilberg

scripted_trigger chancellor_task_1002_target_trigger = {
	is_landed = yes
	NOT = {
		scope:councillor ?= this #Unop: Use the councillor scope since now nomadic can use this task with a kurultai member and not a chancellor (was: root.cp:councillor_chancellor)
	}
}

chancellor_task.1002 = {
	type = character_event
	title = chancellor_task.1002.t
	desc = chancellor_task.1002.desc
	theme = diplomacy
	left_portrait = {
		character = cp:councillor_chancellor
		animation = shame
	}
	right_portrait = {
		character = scope:target
		animation = schadenfreude
	}
	
	trigger = {
		NOT = { has_character_flag = had_msg_chancellor_task_1002 }
		exists = cp:councillor_chancellor
		scope:councillor = cp:councillor_chancellor
		scope:councillor = {
			diplomacy < high_skill_rating
		}
		any_truce_holder = {
			chancellor_task_1002_target_trigger = yes
		}
	}

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

	immediate = {
		add_character_flag = {
			flag = had_msg_chancellor_task_1002
			years = 5
		}
		set_variable = {
			name = had_chancellor_task_side_effect
			value = yes
			days = chancellor_task_side_effect_cooldown
		}
		random_truce_holder = {
			limit = {
				chancellor_task_1002_target_trigger = yes
			}
			save_scope_as = target
		}
	}

	option = {
		name = chancellor_task.1002.a
		scope:target = {
			cancel_truce_one_way = root
		}
	}
}

#Decrease Neighbor opinion
# by Petter Vilberg
scripted_trigger chancellor_task_1003_neighbor_trigger = {
	is_available = yes
	NOT = {
		scope:councillor ?= this #Unop: Use the councillor scope since now nomadic can use this task with a kurultai member and not a chancellor (was: root.cp:councillor_chancellor)
	}
	NOR = {
		is_at_war_with = root
		is_at_war_with = scope:councillor
	}
	NOR = {
		has_opinion_modifier = {
			target = root
			modifier = chancellor_task_neighbor_increased_opinion
		}
		has_opinion_modifier = {
			target = root
			modifier = chancellor_task_neighbor_decreased_opinion
		}
	}
}

chancellor_task.1003 = {
	hidden = yes
	
	trigger = {
		NOT = { has_character_flag = had_msg_chancellor_task_1003 }
		exists = cp:councillor_chancellor
		scope:councillor = cp:councillor_chancellor
		OR = {
			AND = {
				top_liege = this
				any_neighboring_top_liege_realm = {
					holder = {
						chancellor_task_1003_neighbor_trigger = yes
					}
				}
			}
			AND = {
				top_liege != this
				any_neighboring_realm_same_rank_owner = {
					chancellor_task_1003_neighbor_trigger = yes
				}
			}
		}
		scope:councillor = {
			diplomacy < high_skill_rating
		}
	}

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

	immediate = {
		cp:councillor_chancellor = {
			save_scope_as = active_councillor
		}
		set_variable = {
			name = had_chancellor_task_side_effect
			value = yes
			days = chancellor_task_side_effect_cooldown
		}
		add_character_flag = {
			flag = had_msg_chancellor_task_1003
			years = 5
		}
		if = {
			limit = {
				top_liege = this
			}
			random_neighboring_top_liege_realm = {
				limit = {
					holder = {
						chancellor_task_1003_neighbor_trigger = yes
					}
				}
				holder = {
					save_scope_as = neighbor
				}
			}
		}
		else = {
			random_neighboring_realm_same_rank_owner = {
				limit = {
					chancellor_task_1003_neighbor_trigger = yes
				}
				save_scope_as = neighbor
			}
		}

		if = {
			limit = {
				scope:neighbor = {
					OR = { #Either independent same rank -1, or same rank
						AND = {
							top_liege = this
							highest_held_title_tier >= root.highest_held_title_tier_minus_one
						}
						highest_held_title_tier >= root.highest_held_title_tier
					}
				}
			}
			trigger_event = chancellor_task.1004
		}
		else = {
			send_interface_message = {
				type = msg_chancellor_task_bad
				title = chancellor_task.1003.message
				desc = {
					triggered_desc = {
						trigger = {
							scope:active_councillor = { diplomacy <= average_skill_level }
						}
						desc = task_diplomacy_bad_unskilled_notification_tooltip
					}
					triggered_desc = {
						trigger = {
							scope:active_councillor = { diplomacy > average_skill_level }
						}
						desc = task_diplomacy_bad_skilled_notification_tooltip
					}
				}
				tooltip = task_foreign_affairs_notification_tooltip

				left_icon = scope:neighbor
				right_icon = scope:councillor

				scope:neighbor = {
					add_opinion = {
						target = root
						modifier = chancellor_task_neighbor_decreased_opinion
						days = chancellor_task_modifier_duration
					}
				}
			}
		}
	}
}

#Send an event if the neighbor is interesting enough
chancellor_task.1004 = {
	type = letter_event
	opening = {
		desc = chancellor_task.1003.opening
	}
	desc = chancellor_task.1003.desc
	sender = scope:neighbor

	option = {
		name = chancellor_task.1003.a
		scope:neighbor = {
			add_opinion = {
				target = root
				modifier = chancellor_task_neighbor_decreased_opinion
				days = chancellor_task_modifier_duration
			}
		}
	}
}


####
# Good Side Effects
####

#Shorten a truce
# by Petter Vilberg

scripted_trigger chancellor_task_1102_target_trigger = {
	is_landed = yes
	is_available_adult = yes
	NOR = {
		scope:councillor ?= this #Unop: Use the councillor scope since now nomadic can use this task with a kurultai member and not a chancellor (was: root.cp:councillor_chancellor)
		AND = { #Hmm don't go breaking truces for our subdued tributaries
			root = { government_has_flag = government_is_mandala }
			is_tributary_of = root
		}
	}
}

chancellor_task.1102 = {
	type = character_event
	title = chancellor_task.1102.t
	desc = chancellor_task.1102.desc
	theme = diplomacy
	left_portrait = {
		character = cp:councillor_chancellor
		animation = dismissal
	}
	right_portrait = {
		character = scope:target
		animation = shock
	}
	
	trigger = {
		is_available_adult = yes
		NOT = {
			has_character_flag = had_msg_chancellor_task_1102
		}
		exists = cp:councillor_chancellor
		scope:councillor = cp:councillor_chancellor
		scope:councillor = {
			
			diplomacy > mediocre_skill_rating
		}
		any_truce_target = {
			chancellor_task_1102_target_trigger = yes
		}
	}

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

	immediate = {
		add_character_flag = {
			flag = had_msg_chancellor_task_1102
			years = 5
		}
		set_variable = {
			name = had_chancellor_task_side_effect
			value = yes
			days = chancellor_task_side_effect_cooldown
		}
		random_truce_target = {
			limit = {
				chancellor_task_1102_target_trigger = yes
			}
			save_scope_as = target
		}
	}

	option = {
		name = chancellor_task.1102.a
		cancel_truce_one_way = scope:target
	}
}

#Increase Neighbor opinion
# by Petter Vilberg
scripted_trigger chancellor_task_1103_neighbor_trigger = {
	is_available = yes
	NOR = {
		has_opinion_modifier = {
			target = root
			modifier = chancellor_task_neighbor_increased_opinion
		}
		has_opinion_modifier = {
			target = root
			modifier = chancellor_task_neighbor_decreased_opinion
		}
		has_relation_friend = root
	}
	NOR = {
		is_at_war_with = root
		is_at_war_with = scope:councillor
	}
	NOT = {
		scope:councillor ?= this #Unop: Use the councillor scope since now nomadic can use this task with a kurultai member and not a chancellor (was: root.cp:councillor_chancellor)
	}
}

chancellor_task.1103 = {
	hidden = yes
	
	trigger = {
		NOT = { has_character_flag = had_msg_chancellor_task_1103}
		exists = cp:councillor_chancellor
		scope:councillor = cp:councillor_chancellor
		cp:councillor_chancellor = {
			
			diplomacy > mediocre_skill_rating
		}
		OR = {
			AND = { #If you're independent, find an independent neighbor
				top_liege = this
				any_neighboring_top_liege_realm = {
					holder = {
						chancellor_task_1103_neighbor_trigger = yes
					}
				}
			}
			AND = { #If a vassal, find a neighboring ruler of same rank
				top_liege != this
				any_neighboring_realm_same_rank_owner = {
					chancellor_task_1103_neighbor_trigger = yes
				}
			}
		}
	}

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

	immediate = {
		add_character_flag = {
			flag = had_msg_chancellor_task_1103
			years = 5
		}
		set_variable = {
			name = had_chancellor_task_side_effect
			value = yes
			days = chancellor_task_side_effect_cooldown
		}
		cp:councillor_chancellor = {
			save_scope_as = chancellor
		}
		cp:councillor_chancellor = {
			save_scope_as = active_councillor
		}
		if = {
			limit = {
				top_liege = this
			}
			random_neighboring_top_liege_realm = {
				limit = {
					holder = {
						chancellor_task_1103_neighbor_trigger = yes
					}
				}
				holder = {
					save_scope_as = neighbor
				}
			}
		}
		else = {
			random_neighboring_realm_same_rank_owner = {
				limit = {
					chancellor_task_1103_neighbor_trigger = yes
				}
				save_scope_as = neighbor
			}
		}

		if = {
			limit = {
				scope:neighbor = {
					OR = { #Either independent same rank -1, or same rank
						AND = {
							top_liege = this
							highest_held_title_tier >= root.highest_held_title_tier_minus_one
						}
						highest_held_title_tier >= root.highest_held_title_tier
					}
				}
			}
			trigger_event = chancellor_task.1104
		}
		else = {
			send_interface_message = {
				type = msg_chancellor_task_good
				title = chancellor_task.1103.message
				desc = {
					triggered_desc = {
						trigger = {
							scope:active_councillor = { diplomacy <= average_skill_level }
						}
						desc = task_diplomacy_good_unskilled_notification_tooltip
					}
					triggered_desc = {
						trigger = {
							scope:active_councillor = { diplomacy > average_skill_level }
						}
						desc = task_diplomacy_good_skilled_notification_tooltip
					}
				}
				tooltip = task_foreign_affairs_notification_tooltip

				left_icon = scope:neighbor
				right_icon = scope:councillor

				scope:neighbor = {
					add_opinion = {
						target = root
						modifier = chancellor_task_neighbor_increased_opinion
						days = chancellor_task_modifier_duration
					}
				}
			}
		}
	}
}


chancellor_task.1104 = {
	type = letter_event
	opening = {
		desc = chancellor_task.1103.opening
	}
	desc = chancellor_task.1103.desc
	sender = scope:neighbor

	option = {
		name = chancellor_task.1103.a
		scope:neighbor = {
			add_opinion = {
				target = root
				modifier = chancellor_task_neighbor_increased_opinion
				days = chancellor_task_modifier_duration
			}
		}
	}
}

##################
# Side Effects from Integrate Duchy
# 2000-2999
##################

###
# Bad Side Effects
###

#Local Nobles Resist Integration
# by Petter Vilberg
scripted_trigger chancellor_task_2001_duchy_trigger = {
	de_jure_drift_progress = {
		target = root.primary_title
		value >= 25
	}
	de_jure_drift_progress = {
		target = root.primary_title
		value <= 85
	}
}

chancellor_task.2001 = {
	hidden = yes

	trigger = {
		NOT = {
			has_character_flag = had_msg_chancellor_task_2001
		}
		exists = cp:councillor_chancellor
		scope:councillor = cp:councillor_chancellor
		scope:councillor = {
			diplomacy < high_skill_rating
		}
		OR = {
			AND = {
				highest_held_title_tier = tier_kingdom
				scope:county.duchy = {
					chancellor_task_2001_duchy_trigger = yes
				}
			}
			AND = {
				highest_held_title_tier = tier_empire
				scope:county.kingdom = {
					chancellor_task_2001_duchy_trigger = yes
				}
			}
		}
	}

	immediate = {
		cp:councillor_chancellor = {
			save_scope_as = active_councillor
		}
		add_character_flag = {
			flag = had_msg_chancellor_task_2001
			years = 5
		}
		set_variable = {
			name = had_chancellor_task_side_effect
			value = yes
			days = chancellor_task_side_effect_cooldown
		}
		if = {
			limit = {
				highest_held_title_tier = tier_empire
			}
			scope:county.kingdom = {
				save_scope_as = title
			}
		}
		else = {
			scope:county.duchy = {
				save_scope_as = title
			}
		}
		send_interface_message = {
			type = msg_chancellor_task_bad
			title = chancellor_task_2001.message
			desc = {
				triggered_desc = {
					trigger = {
						scope:active_councillor = { diplomacy <= average_skill_level }
					}
					desc = task_diplomacy_bad_unskilled_notification_tooltip
				}
				triggered_desc = {
					trigger = {
						scope:active_councillor = { diplomacy > average_skill_level }
					}
					desc = task_diplomacy_bad_skilled_notification_tooltip
				}
			}
			tooltip = task_integrate_title_notification_tooltip

			left_icon = scope:title
			right_icon = scope:councillor

			scope:title = {
				change_de_jure_drift_progress = {
					target = root.primary_title
					value = medium_de_jure_drift_progress_loss
				}
			}
		}
	}
}

#Local Culture Resists Integration
# by Petter Vilberg
scripted_trigger chancellor_task_2002_duchy_trigger = {
	any_in_de_jure_hierarchy = {
		continue = {
			tier >= tier_duchy
		}
		tier = tier_county
		holder = {
			OR = {
				this = root
				target_is_liege_or_above = root
			}
		}
		culture != root.culture
	}
	de_jure_drift_progress = {
		target = root.primary_title
		value >= 25
	}
	de_jure_drift_progress = {
		target = root.primary_title
		value <= 85
	}
}

chancellor_task.2002 = {
	hidden = yes

	trigger = {
		NOT = {
			has_character_flag = had_msg_chancellor_task_2002
		}
		exists = cp:councillor_chancellor
		scope:councillor = cp:councillor_chancellor
		scope:councillor = {
			diplomacy < high_skill_rating
		}
		OR = {
			AND = {
				highest_held_title_tier = tier_kingdom
				scope:county.duchy = {
					chancellor_task_2002_duchy_trigger = yes
				}
			}
			AND = {
				highest_held_title_tier = tier_empire
				scope:county.kingdom = {
					chancellor_task_2002_duchy_trigger = yes
				}
			}
		}
	}

	immediate = {
		cp:councillor_chancellor = {
			save_scope_as = active_councillor
		}
		add_character_flag = {
			flag = had_msg_chancellor_task_2002
			years = 5
		}
		set_variable = {
			name = had_chancellor_task_side_effect
			value = yes
			days = chancellor_task_side_effect_cooldown
		}
		if = {
			limit = {
				highest_held_title_tier = tier_empire
			}
			scope:county.kingdom = {
				save_scope_as = title
			}
		}
		else = {
			scope:county.duchy = {
				save_scope_as = title
			}
		}
		scope:title = {
			random_in_de_jure_hierarchy = {
				continue = {
					tier >= tier_duchy
				}
				limit = {
					tier = tier_county
					holder = {
						OR = {
							this = root
							target_is_liege_or_above = root
						}
					}
					culture != root.culture
				}
				culture = {
					save_scope_as = resisting_culture
				}
			}
			every_in_de_jure_hierarchy = {
				continue = {
					tier >= tier_duchy
				}
				limit = {
					tier = tier_county
					culture = scope:resisting_culture
					NOT = { is_in_list = potential_counties }
				}
				add_to_list = potential_counties
			}
		}
		ordered_in_list = {
			list = potential_counties
			order_by = {
				add = development_level
			}
			max = 2
			check_range_bounds = no
			
			add_to_list = resisting_counties
		}
		send_interface_message = {
			type = msg_chancellor_task_bad
			title = chancellor_task_2002.message
			desc = {
				triggered_desc = {
					trigger = {
						scope:active_councillor = { diplomacy <= average_skill_level }
					}
					desc = task_diplomacy_bad_unskilled_notification_tooltip
				}
				triggered_desc = {
					trigger = {
						scope:active_councillor = { diplomacy > average_skill_level }
					}
					desc = task_diplomacy_bad_skilled_notification_tooltip
				}
			}
			tooltip = task_integrate_title_notification_tooltip

			left_icon = scope:title
			right_icon = scope:councillor

			scope:title = {
				change_de_jure_drift_progress = {
					target = root.primary_title
					value = medium_de_jure_drift_progress_loss
				}
			}

			every_in_list = {
				list = resisting_counties
				add_county_modifier = {
					modifier = chancellor_task_county_resisting_integration_modifier
					years = 10
				}
			}
		}
	}
}


###
# Good Side Effects
###

#Local Nobles Endorse Integration
# by Petter Vilberg
scripted_trigger chancellor_task_2101_duchy_trigger = {
	de_jure_drift_progress = {
		target = root.primary_title
		value >= 25
	}
	de_jure_drift_progress = {
		target = root.primary_title
		value <= 85
	}
}

chancellor_task.2101 = {
	hidden = yes

	trigger = {
		NOT = { has_character_flag = had_msg_chancellor_task_2101 }
		exists = cp:councillor_chancellor
		scope:councillor = cp:councillor_chancellor
		scope:councillor = {
			diplomacy > mediocre_skill_rating
		}
		OR = {
			AND = {
				highest_held_title_tier = tier_kingdom
				scope:county.duchy = {
					chancellor_task_2101_duchy_trigger = yes
				}
			}
			AND = {
				highest_held_title_tier = tier_empire
				scope:county.kingdom = {
					chancellor_task_2101_duchy_trigger = yes
				}
			}
		}
	}

	immediate = {
		cp:councillor_chancellor = {
			save_scope_as = active_councillor
		}
		add_character_flag = {
			flag = had_msg_chancellor_task_2101
			years = 5
		}
		set_variable = {
			name = had_chancellor_task_side_effect
			value = yes
			days = chancellor_task_side_effect_cooldown
		}
		if = {
			limit = {
				highest_held_title_tier = tier_empire
			}
			scope:county.kingdom = {
				save_scope_as = title
			}
		}
		else = {
			scope:county.duchy = {
				save_scope_as = title
			}
		}
		send_interface_message = {
			type = msg_chancellor_task_good
			title = chancellor_task_2101.message
			desc = {
				triggered_desc = {
					trigger = {
						scope:active_councillor = { diplomacy <= average_skill_level }
					}
					desc = task_diplomacy_good_unskilled_notification_tooltip
				}
				triggered_desc = {
					trigger = {
						scope:active_councillor = { diplomacy > average_skill_level }
					}
					desc = task_diplomacy_good_skilled_notification_tooltip
				}
			}
			tooltip = task_integrate_title_notification_tooltip

			left_icon = scope:title
			right_icon = scope:councillor

			scope:county.duchy = {
				every_in_de_jure_hierarchy = {
					continue = {
						tier >= tier_duchy
					}
					limit = {
						tier = tier_county
						#Be in the same realm as the Duchy
						exists = scope:county.duchy.holder.top_liege
						holder.top_liege = scope:county.duchy.holder.top_liege
					}
					change_county_control = medium_county_control_gain
				}
			}

			scope:title = {
				change_de_jure_drift_progress = {
					target = root.primary_title
					value = medium_de_jure_drift_progress_gain
				}
			}
		}
	}
}


#Local Culture Embraces New Kingdom
# by Petter Vilberg
scripted_trigger chancellor_task_2102_duchy_trigger = {
	any_in_de_jure_hierarchy = {
		continue = {
			tier >= tier_duchy
		}
		tier = tier_county
		culture = root.culture
	}
}

chancellor_task.2102 = {
	hidden = yes

	trigger = {
		NOT = { has_character_flag = had_msg_chancellor_task_2102 }
		exists = cp:councillor_chancellor
		scope:councillor = cp:councillor_chancellor
		scope:councillor = {
			diplomacy > mediocre_skill_rating
		}
		scope:county.duchy = {
			chancellor_task_2102_duchy_trigger = yes
		}
	}

	immediate = {
		cp:councillor_chancellor = {
			save_scope_as = active_councillor
		}
		add_character_flag = {
			flag = had_msg_chancellor_task_2102
			years = 5
		}
		set_variable = {
			name = had_chancellor_task_side_effect
			value = yes
			days = chancellor_task_side_effect_cooldown
		}
		if = {
			limit = {
				highest_held_title_tier = tier_empire
			}
			scope:county.kingdom = {
				save_scope_as = title
			}
		}
		else = {
			scope:county.duchy = {
				save_scope_as = title
			}
		}
		scope:county.duchy = {
			random_in_de_jure_hierarchy = {
				continue = {
					tier >= tier_duchy
				}
				limit = {
					tier = tier_county
				}
				culture = {
					save_scope_as = supporting_culture
				}
			}
		}
		send_interface_message = {
			type = msg_chancellor_task_good
			title = chancellor_task_2102.message
			desc = {
				triggered_desc = {
					trigger = {
						scope:active_councillor = { diplomacy <= average_skill_level }
					}
					desc = task_diplomacy_good_unskilled_notification_tooltip
				}
				triggered_desc = {
					trigger = {
						scope:active_councillor = { diplomacy > average_skill_level }
					}
					desc = task_diplomacy_good_skilled_notification_tooltip
				}
			}
			tooltip = task_integrate_title_notification_tooltip

			left_icon = scope:title
			right_icon = scope:councillor

			scope:title = {
				change_de_jure_drift_progress = {
					target = root.primary_title
					value = medium_de_jure_drift_progress_gain
				}
				every_in_de_jure_hierarchy = {
					continue = {
						tier >= tier_duchy
					}
					limit = {
						tier = tier_county
						culture = scope:supporting_culture
					}
					custom = chancellor_task_every_county_of_culture_in_title
					add_county_modifier = {
						modifier = chancellor_task_county_endorsing_integration_modifier
						years = 10
					}
				}
			}
		}
	}
}


####
# Choose Development or Integration
# by Petter Vilberg
####
scripted_trigger chancellor_task_2103_duchy_trigger = {
	NOT = {
		has_variable = was_target_of_chancellor_task_2103
	}
	any_in_de_jure_hierarchy = {
		continue = {
			tier >= tier_duchy
		}
		tier = tier_county
		development_level < max_development_level
	}
}

chancellor_task.2103 = {
	type = letter_event
	opening = chancellor_task.2103.opening
	desc = chancellor_task.2103.desc
	sender = scope:councillor
	
	trigger = {
		NOT = {
			has_character_flag = had_msg_chancellor_task_2103
		}
		exists = cp:councillor_chancellor
		scope:councillor = cp:councillor_chancellor
		scope:councillor = {
			diplomacy > mediocre_skill_rating
		}
		scope:county.duchy = {
			chancellor_task_2103_duchy_trigger = yes
		}
	}

	immediate = {
		add_character_flag = {
			flag = had_msg_chancellor_task_2103
			years = 5
		}
		set_variable = {
			name = had_chancellor_task_side_effect
			value = yes
			days = chancellor_task_side_effect_cooldown
		}
		if = {
			limit = {
				highest_held_title_tier = tier_empire
			}
			scope:county.kingdom = {
				save_scope_as = title
			}
		}
		else = {
			scope:county.duchy = {
				save_scope_as = title
			}
		}
		scope:county.duchy = {
			set_variable = {
				name = was_target_of_chancellor_task_2103
				value = yes
				years = 25
			}
		}
	}

	option = { #Gain Integration
		name = chancellor_task.2103.a

		if = {
			limit = {	
				scope:title = {
					de_jure_drifting_towards = scope:councillor_liege.primary_title
				}
			}
			scope:title = {
				change_de_jure_drift_progress = {
					target = root.primary_title
					value = medium_de_jure_drift_progress_gain
				}
			}
		}
		scope:county.duchy = {
			random_in_de_jure_hierarchy = {
				continue = {
					tier >= tier_duchy
				}
				limit = {
					tier = tier_county
				}
				change_development_level = -1
			}
		}
	}

	option = { #Gain Development
		name = chancellor_task.2103.b
		if = {
			limit = {	
				scope:title = {
					de_jure_drifting_towards = scope:councillor_liege.primary_title
				}
			}
			scope:title = {
				change_de_jure_drift_progress = {
					target = root.primary_title
					value = medium_de_jure_drift_progress_loss
				}
			}
		}
		scope:county.duchy = {
			every_in_de_jure_hierarchy = {
				limit = {
					tier = tier_county
				}
				change_development_level = 1
			}
		}
	}
	
	option = { #Neither
		name = chancellor_task.2103.c
		add_prestige = minor_prestige_gain
	}
}



##################
# Side Effects from Domestic Affairs
# 3001-3999
##################

###
#Bad Side Effects
###

#Decrease Powerful vassal opinion
# by Petter Vilberg
scripted_trigger chancellor_task_3001_vassal_trigger = {
	trigger_if = { #For directed efforts it has to be the target vassal
		limit = {
			scope:councillor = {
				is_performing_council_task = task_bestow_royal_favor
			}
		}
		this = scope:councillor.councillor_task_target 
	}
	trigger_else = {
		is_of_major_interest_to_root_trigger = yes
		is_imprisoned = no
		NOT = { has_trait = incapable }
		NOR = {
			has_opinion_modifier = {
				target = root
				modifier = chancellor_task_powerful_vassal_increased_opinion
			}
			has_opinion_modifier = {
				target = root
				modifier = chancellor_task_powerful_vassal_decreased_opinion
			}
		}
		NOT = {
			scope:councillor ?= this #Unop: Use the councillor scope since now nomadic can use this task with a kurultai member and not a chancellor (was: root.cp:councillor_chancellor)
		}
	}
}

chancellor_task.3001 = {
	type = letter_event
	opening = {
		desc = chancellor_task.3001.opening
	}
	desc = chancellor_task.3001.desc
	sender = scope:vassal
	
	trigger = {
		NOT = { has_character_flag = had_msg_chancellor_task_3001 }
		OR = {
			AND = {
				exists = cp:councillor_chancellor
				scope:councillor = cp:councillor_chancellor
			}
			scope:councillor = {
				is_kurultai_trigger = yes
			}
		}
		any_vassal = {
			chancellor_task_3001_vassal_trigger = yes
		}
		scope:councillor = {
			diplomacy < high_skill_rating
		}
	}

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

	immediate = {
		add_character_flag = {
			flag = had_msg_chancellor_task_3001
			years = 5
		}
		set_variable = {
			name = had_chancellor_task_side_effect
			value = yes
			days = chancellor_task_side_effect_cooldown
		}
		scope:councillor = {
			save_scope_as = active_councillor
		}
		random_vassal = {
			limit = {
				chancellor_task_3001_vassal_trigger = yes
			}
			save_scope_as = vassal
		}
	}

	option = {
		name = chancellor_task.3001.a
		scope:vassal = {
			add_opinion = {
				target = root
				modifier = chancellor_task_powerful_vassal_decreased_opinion
				days = chancellor_task_modifier_duration
			}
		}
	}
}


#Worsen vassal contract
# by Petter Vilberg

scripted_trigger chancellor_task_3002_vassal_trigger = {
	vassal_contract_obligation_level_can_be_decreased = feudal_government_taxes
	is_ai = yes
	trigger_if = { #For directed efforts it has to be the target vassal
		limit = {
			scope:councillor = {
				is_performing_council_task = task_bestow_royal_favor
			}
		}
		this = scope:councillor.councillor_task_target
	}
	trigger_else = {
		NOR = { 
			has_variable = chancellor_task_improved_contract 
			has_variable = chancellor_task_worsened_contract 
		}
		NOT = {
			scope:councillor ?= this #Unop: Use the councillor scope since now nomadic can use this task with a kurultai member and not a chancellor (was: root.cp:councillor_chancellor)
		}
	}
}

chancellor_task.3002 = {
	type = letter_event
	opening = {
		desc = chancellor_task.3002.opening
	}
	desc = chancellor_task.3002.desc
	sender = scope:councillor
	
	trigger = {
		NOT = { has_character_flag = had_msg_chancellor_task_3002 }
		OR = {
			AND = {
				exists = cp:councillor_chancellor
				scope:councillor = cp:councillor_chancellor
			}
			scope:councillor = {
				is_kurultai_trigger = yes
			}
		}
		any_vassal = {
			chancellor_task_3002_vassal_trigger = yes
		}
		scope:councillor = {
			diplomacy < high_skill_rating
		}
	}

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

	immediate = {
		add_character_flag = {
			flag = had_msg_chancellor_task_3002
			years = 5
		}
		set_variable = {
			name = had_chancellor_task_side_effect
			value = yes
			days = chancellor_task_side_effect_cooldown
		}
		scope:councillor = {
			save_scope_as = active_councillor
		}
		random_vassal = {
			limit = {
				chancellor_task_3002_vassal_trigger = yes
			}
			set_variable = {
				name = chancellor_task_worsened_contract
				value = yes
				days = 7300
			}
			save_scope_as = vassal
		}
	}

	option = { #Reduce the contract
		name = chancellor_task.3002.a
		scope:vassal = {
			vassal_contract_decrease_obligation_level = feudal_government_taxes
		}
		ai_chance = {
			base = 100
		}
	}

	option = { #Give the vassal a Hook instead
		trigger = {
			scope:vassal = {
				can_add_hook = {
					target = root
					type = favor_hook
				}
			}
		}
		name = chancellor_task.3002.c
		scope:vassal = {
			add_hook = {
				target = root
				type = favor_hook
			}
		}
	}

	option = { #Spend a Hook instead
		trigger = {
			has_usable_hook = scope:vassal
		}
		name = chancellor_task.3002.d
		use_hook = scope:vassal
	}
}


#Loss of Prestige
# by Petter Vilberg
chancellor_task.3003 = {
	hidden = yes
	
	trigger = {
		NOT = { has_character_flag = had_msg_chancellor_task_3003 }
		OR = {
			AND = {
				exists = cp:councillor_chancellor
				scope:councillor = cp:councillor_chancellor
			}
			scope:councillor = {
				is_kurultai_trigger = yes
			}
		}
		scope:councillor = {
			diplomacy < high_skill_rating
		}
	}

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

	immediate = {
		add_character_flag = {
			flag = had_msg_chancellor_task_3003
			years = 5
		}
		set_variable = {
			name = had_chancellor_task_side_effect
			value = yes
			days = chancellor_task_side_effect_cooldown
		}
		scope:councillor = {
			save_scope_as = active_councillor
		}
		send_interface_message = {
			type = msg_chancellor_task_bad
			title = chancellor_task.3003.notification
			desc = {
				triggered_desc = {
					trigger = {
						scope:active_councillor = { diplomacy <= average_skill_level }
					}
					desc = task_diplomacy_bad_unskilled_notification_tooltip
				}
				triggered_desc = {
					trigger = {
						scope:active_councillor = { diplomacy > average_skill_level }
					}
					desc = task_diplomacy_bad_skilled_notification_tooltip
				}
			}
			tooltip = task_domestic_affairs_notification_tooltip

			left_icon = scope:active_councillor
			right_icon = root.primary_title

			add_prestige = medium_prestige_loss
		}
	}

}


####
# Good Side Effects
####

#Stop vassal infighting
# by Petter Vilberg

scripted_trigger chancellor_task_3101_defender_vassal = {
	is_ai = yes
	is_at_war_as_defender = yes
	save_temporary_scope_as = defender_vassal
	NOT = {
		this = scope:councillor #Unop: Use the councillor scope since now nomadic can use this task with a kurultai member and not a chancellor (was: root.cp:councillor_chancellor)
	}
	trigger_if = { #For directed efforts one of the vassals has to be the target
		limit = {
			scope:councillor = {
				is_performing_council_task = task_bestow_royal_favor
			}
		}
		save_temporary_scope_as = vassal_1
	}
}

scripted_trigger chancellor_task_3101_attacker_vassal = {	
	is_ai = yes
	is_at_war_as_attacker = yes
	save_temporary_scope_as = attacker_vassal
	any_character_war = {
		primary_attacker = scope:attacker_vassal
		primary_defender = scope:defender_vassal
	}
	NOT = {
		this = scope:councillor #Unop: Use the councillor scope since now nomadic can use this task with a kurultai member and not a chancellor (was: root.cp:councillor_chancellor)
	}
	trigger_if = { #For directed efforts one of the vassals has to be the target
		limit = {
			scope:councillor = {
				is_performing_council_task = task_bestow_royal_favor
			}
		}
		save_temporary_scope_as = vassal_2
	}
}

chancellor_task.3101 = {
	type = letter_event
	opening = {
		desc = chancellor_task.3101.opening
	}
	desc = chancellor_task.3101.desc
	sender = scope:active_councillor
	
	trigger = {
		NOT = { has_character_flag = had_msg_chancellor_task_3101 }
		OR = {
			AND = {
				exists = cp:councillor_chancellor
				scope:councillor = cp:councillor_chancellor
			}
			scope:councillor = {
				is_kurultai_trigger = yes
			}
		}
		is_at_war = no
		any_vassal = {
			chancellor_task_3101_defender_vassal = yes
		}
		any_vassal = {
			chancellor_task_3101_attacker_vassal = yes
		}
		trigger_if = { #For directed efforts one of the vassals has to be the target
			limit = {
				scope:councillor = {
					is_performing_council_task = task_bestow_royal_favor
				}
			}
			OR = {
				scope:target_character = scope:vassal_1
				scope:target_character = scope:vassal_2
			}
		}
		
		scope:councillor = {
			
			diplomacy > mediocre_skill_rating
		}
	}

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

	immediate = {
		add_character_flag = {
			flag = had_msg_chancellor_task_3101
			years = 5
		}
		scope:councillor = {
			save_scope_as = active_councillor
		}
		set_variable = {
			name = had_chancellor_task_side_effect
			value = yes
			days = chancellor_task_side_effect_cooldown
		}
		random_vassal = {
			limit = {
				chancellor_task_3101_defender_vassal = yes
				root = {
					any_vassal = {
						chancellor_task_3101_attacker_vassal = yes
					}
				}
			}
			save_scope_as = defender_vassal
		}
		random_vassal = {
			limit = {
				chancellor_task_3101_attacker_vassal = yes
			}
			save_scope_as = attacker_vassal
			random_character_war = {
				limit = {
					primary_attacker = scope:attacker_vassal
					primary_defender = scope:defender_vassal
				}
				save_scope_as = war
			}
		}
	}

	option = {
		name = chancellor_task.3101.a
		remove_treasury_or_gold = medium_treasury_or_gold_value
		scope:war = {
			end_war = white_peace
		}
		ai_chance = {
			base = 10
			modifier = {
				factor = 0
				short_term_treasury_or_gold <= medium_treasury_or_gold_value
			}
		}
	}

	option = {
		name = chancellor_task.3101.b
		add_prestige = medium_prestige_loss
		scope:war = {
			end_war = white_peace
		}
		ai_chance = {
			base = 100
		}
	}

	option = {
		name = chancellor_task.3101.c
		custom_tooltip = chancellor_task.3101.c.tt
		ai_chance = {
			base = 10
		}
	}
}

#Improve vassal contract
# by Petter Vilberg

scripted_trigger chancellor_task_3102_vassal_trigger = {
	is_ai = yes
	vassal_contract_obligation_level_can_be_increased = feudal_government_taxes
	trigger_if = { #For directed efforts it has to be the target vassal
		limit = {
			scope:councillor = {
				is_performing_council_task = task_bestow_royal_favor
			}
		}
		this = scope:councillor.councillor_task_target
	}
	trigger_else = {
		NOR = { 
			has_variable = chancellor_task_improved_contract 
			has_variable = chancellor_task_worsened_contract 
		}
		NOT = {
			this = scope:councillor #Unop: Use the councillor scope since now nomadic can use this task with a kurultai member and not a chancellor (was: root.cp:councillor_chancellor)
		}
	}
}

chancellor_task.3102 = {
	type = letter_event
	opening = {
		desc = chancellor_task.3002.opening
	}
	desc = chancellor_task.3102.desc
	sender = scope:councillor
	
	trigger = {
		NOT = { has_character_flag = had_msg_chancellor_task_3102 }
		OR = {
			AND = {
				exists = cp:councillor_chancellor
				scope:councillor = cp:councillor_chancellor
			}
			scope:councillor = {
				is_kurultai_trigger = yes
			}
		}
		any_vassal = {
			chancellor_task_3102_vassal_trigger = yes
		}
		scope:councillor = {
			
			diplomacy > mediocre_skill_rating
		}
	}

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

	immediate = {
		add_character_flag = {
			flag = had_msg_chancellor_task_3102
			years = 5
		}
		set_variable = {
			name = had_chancellor_task_side_effect
			value = yes
			days = chancellor_task_side_effect_cooldown
		}
		scope:councillor = {
			save_scope_as = active_councillor
		}
		random_vassal = {
			limit = {
				chancellor_task_3102_vassal_trigger = yes
			}
			set_variable = {
				name = chancellor_task_improved_contract
				value = yes
				days = 7300
			}
			save_scope_as = vassal
		}
	}

	option = {
		name = chancellor_task.3102.a
		scope:vassal = {
			vassal_contract_increase_obligation_level = feudal_government_taxes
		}
		ai_chance = {
			base = 100
		}
	}

	option = {
		name = chancellor_task.3102.c
		trigger = {
			can_add_hook = {
				target = scope:vassal
				type = favor_hook
			}
		}
		add_hook = {
			target = scope:vassal
			type = favor_hook
		}
	}
}

#Improve Powerful vassal opinion
# by Petter Vilberg
scripted_trigger chancellor_task_3103_vassal_trigger = {
	trigger_if = { #For directed efforts it has to be the target vassal
		limit = {
			scope:councillor = {
				is_performing_council_task = task_bestow_royal_favor
			}
		}
		this = scope:councillor.councillor_task_target
	}
	trigger_else = {
		is_of_major_interest_to_root_trigger = yes
		is_imprisoned = no
		NOT = { has_trait = incapable }
		NOR = {
			has_opinion_modifier = {
				target = root
				modifier = chancellor_task_powerful_vassal_increased_opinion
			}
			has_opinion_modifier = {
				target = root
				modifier = chancellor_task_powerful_vassal_decreased_opinion
			}
		}
		NOT = {
			this = scope:councillor #Unop: Use the councillor scope since now nomadic can use this task with a kurultai member and not a chancellor (was: root.cp:councillor_chancellor)
		}
	}
}

chancellor_task.3103 = {
	type = letter_event
	opening = {
		desc = chancellor_task.3001.opening
	}
	desc = chancellor_task.3103.desc
	sender = scope:vassal
	
	trigger = {
		NOT = { has_character_flag = had_msg_chancellor_task_3103 }
		OR = {
			AND = {
				exists = cp:councillor_chancellor
				scope:councillor = cp:councillor_chancellor
			}
			scope:councillor = {
				is_kurultai_trigger = yes
			}
		}
		any_vassal = {
			chancellor_task_3103_vassal_trigger = yes
		}
		scope:councillor = {
			
			diplomacy > mediocre_skill_rating
		}
	}

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

	immediate = {
		add_character_flag = {
			flag = had_msg_chancellor_task_3103
			years = 5
		}
		set_variable = {
			name = had_chancellor_task_side_effect
			value = yes
			days = chancellor_task_side_effect_cooldown
		}
		scope:councillor = {
			save_scope_as = active_councillor
		}
		random_vassal = {
			limit = {
				chancellor_task_3103_vassal_trigger = yes
			}
			save_scope_as = vassal
		}
	}

	option = {
		name = chancellor_task.3103.a
		scope:vassal = {
			add_opinion = {
				target = root
				modifier = chancellor_task_powerful_vassal_increased_opinion
				days = chancellor_task_modifier_duration
			}
		}
	}
}


#Force a Vassal into Partition
# by Petter Vilberg

scripted_trigger chancellor_task_3104_vassal_trigger = {
	
	highest_held_title_tier >= tier_duchy
	is_ai = yes
	primary_title = {
		title_can_reduce_partition_law_trigger = yes
	}
	NOT = {
		has_variable = chancellor_task_forced_partition
	}
	NOT = {
		this = scope:councillor #Unop: Use the councillor scope since now nomadic can use this task with a kurultai member and not a chancellor (was: root.cp:councillor_chancellor)
	}
	root = {
		can_add_hook = {
			target = prev
			type = favor_hook
		}
	}
}

chancellor_task.3104 = {
	type = letter_event
	opening = {
		desc = chancellor_task.3002.opening
	}
	desc = chancellor_task.3104.desc
	sender = scope:councillor
	
	trigger = {
		NOT = { has_character_flag = had_msg_chancellor_task_3104 }
		OR = {
			AND = {
				exists = cp:councillor_chancellor
				scope:councillor = cp:councillor_chancellor
			}
			scope:councillor = {
				is_kurultai_trigger = yes
			}
		}
		any_vassal = {
			chancellor_task_3104_vassal_trigger = yes
		}
		scope:councillor = {
			
			diplomacy > mediocre_skill_rating
		}
	}

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

	immediate = {
		add_character_flag = {
			flag = had_msg_chancellor_task_3104
			years = 5
		}
		set_variable = {
			name = had_chancellor_task_side_effect
			value = yes
			days = chancellor_task_side_effect_cooldown
		}
		scope:councillor = {
			save_scope_as = active_councillor
		}
		random_vassal = {
			limit = {
				chancellor_task_3104_vassal_trigger = yes
			}
			set_variable = {
				name = chancellor_task_forced_partition
				value = yes
				days = 7300
			}
			save_scope_as = vassal
			primary_title = {
				save_scope_as = primary_title
			}
		}
	}

	option = {
		name = chancellor_task.3104.a
		scope:vassal = {
			reduce_partition_succession_law_effect = yes
		}
		ai_chance = {
			base = 100
		}
	}

	option = {
		name = chancellor_task.3104.b
		trigger = {
			can_add_hook = {
				target = scope:vassal
				type = favor_hook
			}
		}
		add_hook = {
			target = scope:vassal
			type = favor_hook
		}
		ai_chance = {
			base = 20
		}
	}

	option = {
		name = chancellor_task.3104.c
		trigger = {
			NOT = {
				can_add_hook = {
					target = scope:vassal
					type = favor_hook
				}
			}
		}
		ai_chance = {
			base = 20
		}
	}
}
