task_foreign_affairs = {
	default_task = yes
	position = councillor_chancellor
	task_type = task_type_general
	task_progress = task_progress_infinite

	asset = {
		icon = "gfx/interface/icons/council_task_types/task_foreign_affairs.dds"
		background = "gfx/interface/buttons/button_round_bg.dds"
		frame = "gfx/interface/buttons/button_round_frame.dds"
		glow = "gfx/particles/halo.dds"
	}

	effect_desc = {
		### Prestige tooltip
		desc = task_foreign_affairs_prestige_effect_desc
		# Adaptive Traditions tooltip
		triggered_desc = {
			trigger = { liege = { has_perk = adaptive_traditions_perk } }
			desc = task_foreign_affairs_effect_desc_adaptive_traditions_bonus_prestige
		}
		# Bureaucrats tooltip
		triggered_desc = {
			trigger = {
				councillor_liege_has_erudition_legacy_5_perk = yes
			}
			desc = task_foreign_affairs_effect_desc_bureaucrats_bonus_prestige
		}
		# Family Business tooltip
		triggered_desc = {
			trigger = {
				councillor_liege_has_family_business_bonus = yes
			}
			desc = task_foreign_affairs_effect_desc_family_business_bonus_prestige
		}
		# Fp3 Consulted House Member tooltip
		triggered_desc = {
			trigger = {
				councillor_liege_has_consulted_house_bonus = yes
			}
			desc = task_foreign_affairs_effect_desc_consulted_house_bonus_prestige
		}
		### Opinion tooltip
		first_valid = {
			triggered_desc = {
				trigger = { liege = { top_liege != this } }
				desc = {
					desc = task_foreign_affairs_fallback_effect_desc
					desc = task_foreign_affairs_not_independent_effect_desc
				}
			}
			desc = task_foreign_affairs_independent_effect_desc
		}
		# Adaptive Traditions tooltip
		triggered_desc = {
			trigger = { liege = { has_perk = adaptive_traditions_perk } }
			desc = task_foreign_affairs_effect_desc_adaptive_traditions_bonus_opinion
		}
		# Bureaucrats tooltip
		triggered_desc = {
			trigger = {
				councillor_liege_has_erudition_legacy_5_perk = yes
			}
			desc = task_foreign_affairs_effect_desc_bureaucrats_bonus_opinion
		}
		# Family Business tooltip
		triggered_desc = {
			trigger = {
				councillor_liege_has_family_business_bonus = yes
			}
			desc = task_foreign_affairs_effect_desc_family_business_bonus_opinion
		}
		# Fp3 Consulted House Member tooltip
		triggered_desc = {
			trigger = {
				councillor_liege_has_consulted_house_bonus = yes
			}
			desc = task_foreign_affairs_effect_desc_consulted_house_bonus_opinion
		}
		# Ep3 - The Peak of Elegance event
		triggered_desc = {
			trigger = {
				liege = { has_character_modifier = court_fashion_foreign_modifier }
			}
			desc = task_foreign_affairs_effect_desc_court_fashion_bonus_opinion
		}

		desc = {
			desc = council_task_possible_side_effects
			triggered_desc = {
				trigger = {
					diplomacy > mediocre_skill_rating
				}
				desc = task_foreign_affairs_shorten_truce
			}
			triggered_desc = {
				trigger = {
					diplomacy < high_skill_rating
				}
				desc = task_foreign_affairs_enemy_claim
			}
			triggered_desc = {
				trigger = {
					diplomacy < high_skill_rating
				}
				desc = task_foreign_shorten_enemy_truce
			}
			triggered_desc = {
				trigger = {
					diplomacy < high_skill_rating
				}
				desc = task_foreign_neighbor_opinion_loss
			}
		}
	}

	on_start_task = {
		liege = {
			set_variable = {
				name = chancellor_foreign_affairs_opinion_value
				value = 0
			}
		}
	}

	on_cancel_task = {
		remove_variable = chancellor_foreign_affairs_opinion_value
	}

	# Prestige Gain + Modifiers
	council_owner_modifier = {
		name = task_foreign_affairs_prestige_modifier
		monthly_prestige = 1
		scale = chancellor_foreign_affairs_prestige_total
	}

	# Opinion Gain + Modifiers
	council_owner_modifier = {
		name = task_foreign_affairs_opinion_modifier
		independent_ruler_opinion = 1
		scale = chancellor_foreign_affairs_independent_opinion_scale
	}

	council_owner_modifier = {
		name = task_foreign_affairs_opinion_modifier
		fellow_vassal_opinion = 1
		scale = chancellor_foreign_affairs_realm_opinion_scale
	}

	monthly_on_action = task_foreign_affairs_side_effects

	on_monthly = {
		if = {
			limit = {
				liege = { is_ai = no }
			}
			if = {
				limit = {
					liege = { has_variable = chancellor_foreign_affairs_opinion_value }
				}
				if = {
					limit = {
						liege.var:chancellor_foreign_affairs_opinion_value < chancellor_foreign_affairs_opinion_max
					}
					liege = {
						change_variable = {
							name = chancellor_foreign_affairs_opinion_value
							add = root.chancellor_foreign_affairs_monthly_increase
						}
					}
				}
				if = {
					limit = {
						liege.var:chancellor_foreign_affairs_opinion_value > chancellor_foreign_affairs_opinion_max
					}
					liege = {
						set_variable = {
							name = chancellor_foreign_affairs_opinion_value
							value = root.chancellor_foreign_affairs_opinion_max
						}
					}
				}
			}
			else = {
				liege = {
					set_variable = {
						name = chancellor_foreign_affairs_opinion_value
						value = root.chancellor_foreign_affairs_monthly_increase
					}
				}
			}
		}
	}

	ai_will_do = {
		value = 1 # Always a good backup
		if = {
			limit = { prestige <= minor_prestige_value }
			add = 500
		}
	}
}

task_domestic_affairs = {
	position = councillor_chancellor
	task_type = task_type_general
	task_progress = task_progress_infinite

	asset = {
		icon = "gfx/interface/icons/council_task_types/task_domestic_affairs.dds"
		background = "gfx/interface/buttons/button_round_bg.dds"
		frame = "gfx/interface/buttons/button_round_frame.dds"
		glow = "gfx/particles/halo.dds"
	}

	effect_desc = {
		# Direct Vassal Opinion
		desc = task_domestic_affairs_direct_effect_desc
		triggered_desc = {
			trigger = {
				liege = { has_perk = chains_of_loyalty_perk }
			}
			desc = task_domestic_affairs_chains_of_loyalty_bonus_desc
		}
		triggered_desc = {
			trigger = {
				councillor_liege_has_erudition_legacy_5_perk = yes
			}
			desc = task_domestic_affairs_bureaucrats_bonus_desc
		}
		triggered_desc = {
			trigger = {
				councillor_liege_has_family_business_bonus = yes
			}
			desc = task_domestic_affairs_family_business_bonus_desc
		}
		triggered_desc = {
			trigger = {
				councillor_liege_has_consulted_house_bonus = yes
			}
			desc = task_domestic_affairs_consulted_house_bonus_desc
		}
		triggered_desc = {
			trigger = {
				scope:councillor_liege = {
					has_title = title:c_byzantion
					title:c_byzantion = { has_county_modifier = pandidakterion_university_modifier }
				}
			}
			desc = chancellor_domestic_affairs_opinion_pandidakterion_bonus_desc
		}
		triggered_desc = {
			trigger = {
				scope:councillor_liege = {
					has_character_flag = food_improves_opinion
				}
			}
			desc = chancellor_domestic_affairs_opinion_food_bonus_desc
		}
		# Parochial Vassal Opinion
		desc = task_domestic_affairs_parochial_effect_desc
		triggered_desc = {
			trigger = {
				liege = { has_perk = chains_of_loyalty_perk }
			}
			desc = task_domestic_affairs_chains_of_loyalty_bonus_desc
		}
		triggered_desc = {
			trigger = {
				councillor_liege_has_erudition_legacy_5_perk = yes
			}
			desc = task_domestic_affairs_bureaucrats_bonus_desc
		}
		triggered_desc = {
			trigger = {
				councillor_liege_has_family_business_bonus = yes
			}
			desc = task_domestic_affairs_family_business_bonus_desc
		}
		triggered_desc = {
			trigger = {
				councillor_liege_has_consulted_house_bonus = yes
			}
			desc = task_domestic_affairs_consulted_house_bonus_desc
		}
		triggered_desc = {
			trigger = {
				scope:councillor_liege = {
					has_title = title:c_byzantion
					title:c_byzantion = { has_county_modifier = pandidakterion_university_modifier }
				}
			}
			desc = chancellor_domestic_affairs_opinion_pandidakterion_bonus_desc
		}
		triggered_desc = {
			trigger = {
				scope:councillor_liege = {
					has_character_flag = food_improves_opinion
				}
			}
			desc = chancellor_domestic_affairs_opinion_food_bonus_desc
		}
		# Tyranny Loss
		desc = task_domestic_affairs_tyranny_effect_desc
		triggered_desc = {
			trigger = {
				liege = { has_perk = chains_of_loyalty_perk }
			}
			desc = task_domestic_affairs_tyranny_chains_of_loyalty_bonus_desc
		}
		triggered_desc = {
			trigger = {
				councillor_liege_has_erudition_legacy_5_perk = yes
			}
			desc = task_domestic_affairs_tyranny_bureaucrats_bonus_desc
		}
		triggered_desc = {
			trigger = {
				councillor_liege_has_family_business_bonus = yes
			}
			desc = task_domestic_affairs_tyranny_family_business_bonus_desc
		}
		triggered_desc = {
			trigger = {
				councillor_liege_has_consulted_house_bonus = yes
			}
			desc = task_domestic_affairs_tyranny_consulted_house_bonus_desc
		}
		triggered_desc = {
			trigger = {
				scope:councillor_liege = {
					has_character_flag = food_improves_opinion
				}
			}
			desc = chancellor_domestic_affairs_tyranny_food_bonus_desc
		}
		desc = {
			desc = council_task_possible_side_effects
			triggered_desc = {
				trigger = {
					diplomacy > mediocre_skill_rating
				}
				desc = task_increase_control_improved_vassal_opinion
			}
			triggered_desc = {
				trigger = {
					diplomacy > mediocre_skill_rating
					liege = {
						any_vassal = {
							government_has_flag = government_is_feudal
							primary_title.tier > tier_barony
						}
					}
				}
				desc = task_increase_control_improve_vassal_contract
			}
			triggered_desc = {
				trigger = {
					diplomacy > mediocre_skill_rating
				}
				desc = task_increase_control_end_internal_war
			}
			triggered_desc = {
				trigger = {
					diplomacy > mediocre_skill_rating
				}
				desc = task_increase_control_force_vassal_partition
			}
			triggered_desc = {
				trigger = {
					diplomacy < high_skill_rating
				}
				desc = task_increase_control_lose_vassal_opinion
			}
			triggered_desc = {
				trigger = {
					diplomacy < high_skill_rating
					liege = {
						any_vassal = {
							government_has_flag = government_is_feudal
							primary_title.tier > tier_barony
						}
					}
				}
				desc = task_increase_control_worsen_contract
			}
		}
	}

	on_start_task = {
		liege = {
			set_variable = {
				name = chancellor_domestic_affairs_opinion_value
				value = 0
			}
		}
	}

	on_cancel_task = {
		if = {
			limit = {
				is_alive = yes
				has_variable = chancellor_domestic_affairs_opinion_value
			}
			remove_variable = chancellor_domestic_affairs_opinion_value
		}
	}

	council_owner_modifier = {
		name = task_domestic_affairs_opinion_modifier
		direct_vassal_opinion = 1
		scale = chancellor_domestic_affairs_opinion_scale
	}

	council_owner_modifier = {
		name = task_domestic_affairs_parochial_opinion_modifier
		parochial_opinion = 1
		scale = chancellor_domestic_affairs_opinion_scale
	}

	council_owner_modifier = {
		name = task_domestic_affairs_opinion_modifier
		tyranny_loss_mult = 0.01
		scale = chancellor_domestic_affairs_tyranny_total
	}

	monthly_on_action = task_domestic_affairs_side_effects

	on_monthly = {
		if = {
			limit = {
				liege = { is_ai = no }
			}
			if = {
				limit = {
					liege = {
						has_variable = chancellor_domestic_affairs_opinion_value
					}
				}
				liege = {
					if = {
						limit = {
							var:chancellor_domestic_affairs_opinion_value < root.chancellor_domestic_affairs_opinion_max
						}
						change_variable = {
							name = chancellor_domestic_affairs_opinion_value
							add = root.chancellor_domestic_affairs_monthly_increase
						}
					}
					if = {
						limit = {
							var:chancellor_domestic_affairs_opinion_value > root.chancellor_domestic_affairs_opinion_max
						}
						set_variable = {
							name = chancellor_domestic_affairs_opinion_value
							value = root.chancellor_domestic_affairs_opinion_max
						}
					}
				}
			}
			else = {
				liege = {
					set_variable = {
						name = chancellor_domestic_affairs_opinion_value
						value = 0
					}
				}
			}
		}
	}

	ai_will_do = {
		value = 0
		if = { # Do this if you have a faction against you, every little bit helps
			limit = {
				scope:councillor_liege = {
					any_targeting_faction = {
						OR = {
							faction_is_type = independence_faction
							faction_is_type = nation_fracturing_faction
							faction_is_type = liberty_faction
							faction_is_type = claimant_faction
						}
					}
				}
			}
			add = 1000
		}
		if = { # Get rid of tyranny
			limit = {
				scope:councillor_liege = {
					OR = {
						AND = { # Somewhat rational characters prefer this over the prestige of foreign affairs
							ai_rationality > -25
							NOT = { has_trait = arrogant }
							tyranny >= 5
						}
						AND = { # If you're arrogant or deeply irrational, it'll take a long time for you to realize
							OR = {
								ai_rationality <= -25
								has_trait = arrogant
							}
							tyranny >= 15
						}
					}
				}
			}
			add = 500
		}
	}
}

task_integrate_title = {
	position = councillor_chancellor
	task_type = task_type_county
	county_target = realm
	task_progress = task_progress_value
	task_current_value = scope:councillor_liege.chancellor_integrate_title_current_progress

	task_max_value = define:NTitle|DRIFT_PROGRESS_LIMIT

	asset = {
		icon = "gfx/interface/icons/council_task_types/task_integrate_title.dds"
		background = "gfx/interface/buttons/button_round_bg.dds"
		frame = "gfx/interface/buttons/button_round_frame.dds"
		glow = "gfx/particles/halo.dds"
	}

	effect_desc = {
		desc = task_integrate_title_effect_desc
		desc = {
			desc = council_task_possible_side_effects
			triggered_desc = {
				trigger = {
					diplomacy > mediocre_skill_rating
				}
				desc = task_integrate_title_nobles_support_integration
			}
			triggered_desc = {
				trigger = {
					diplomacy > mediocre_skill_rating
				}
				desc = task_integrate_title_culture_supports_integration
			}
			triggered_desc = {
				trigger = {
					diplomacy < high_skill_rating
				}
				desc = task_integrate_title_nobles_resist_integration
			}
			triggered_desc = {
				trigger = {
					diplomacy < high_skill_rating
				}
				desc = task_integrate_title_culture_resists_integration
			}
		}
	}

	is_valid_showing_failures_only =  {
		liege = {
			custom_description = {
				text = "is_king_or_emperor"
				highest_held_title_tier >= tier_kingdom
			}
		}
		trigger_if = {
			limit = {
				has_tgp_dlc_trigger = yes
				top_liege = {
					top_participant_group:dynastic_cycle ?= {
						participant_group_type = hegemon_ruler
					}
				}
			}
			custom_tooltip = {
				text = dynastic_cycle_locks_title_integration_tt
				top_liege = {
					top_participant_group:dynastic_cycle ?= {
						NOT = { has_participant_group_parameter = dynastic_cycle_locks_title_integration }
					}
				}
			}
		}
	}

	on_finish_task_county = {
		start_default_task = yes
		# Add the title to the Dynastic Cycle core region
		if = {
			limit = {
				scope:councillor_liege = {
					top_participant_group:dynastic_cycle ?= {
						participant_group_type = hegemon_ruler
					} 
				}
			}
			situation:dynastic_cycle.situation_sub_region:core = { add_dejure_title_to_sub_region = scope:county.empire }
		}
	}

	potential_county = {
		scope:county = {
			is_landless_type_title = no
			de_jure_drifting_towards = scope:councillor_liege.primary_title
		}
		# Asturias wants to survive and integrate Castille if possible.
		trigger_if = {
			limit = {
				scope:councillor_liege = {
					has_title = title:k_asturias
					NOT = { has_title = title:k_castille }
					any_sub_realm_county = {
						any_this_title_or_de_jure_above = { this = title:k_castille }
					}
				}
			}
			scope:county = {
				any_this_title_or_de_jure_above = { this = title:k_castille }
			}
		}
	}

	progress = {
		value = 0
		add = {
			value = define:NTitle|DRIFT_MONTHLY_PROGRESS_INCREASE
			desc = PASSIVE_INTEGRATION_PROGRESS_VALUE
		}
		add = {
			value = scope:councillor.chancellor_integrate_title_progress_gain
			desc = SCALED_COUNCILLOR_DIPLOMACY_VALUE
		}
		add = chancellor_integrate_title_contextual_bonuses
	}

	monthly_on_action = task_integrate_title_side_effects

	on_monthly_county = {
		if = {
			# Due to code setup, it might not have invalidated yet if this is not the case
			limit = {
				scope:county = {
					de_jure_drifting_towards = scope:councillor_liege.primary_title
				}
			}
			scope:county = {
				change_de_jure_drift_progress = {
					target = scope:councillor_liege.primary_title
					value = scope:councillor.chancellor_integrate_title_progress_gain
				}
				change_de_jure_drift_progress = {
					target = scope:councillor_liege.primary_title
					value = scope:councillor.chancellor_integrate_title_contextual_bonuses
				}
			}
		}
	}

	ai_will_do = {
		value = 10 # Prefer this if available

		# Asturias wants to survive and integrate Castille if possible.
		if = {
			limit = {
				scope:councillor_liege = {
					has_title = title:k_asturias
					NOT = { has_title = title:k_castille }
					any_sub_realm_county = {
						any_this_title_or_de_jure_above = { this = title:k_castille }
					}
				}
			}
			add = 100000
		}
	}
}

task_bestow_royal_favor = {
	position = councillor_chancellor
	task_type = task_type_court
	task_progress = task_progress_percentage
	restart_on_finish = yes

	asset = {
		icon = "gfx/interface/icons/council_task_types/task_bestow_royal_favor.dds"
		background = "gfx/interface/buttons/button_round_bg.dds"
		frame = "gfx/interface/buttons/button_round_frame.dds"
		glow = "gfx/particles/halo.dds"
	}

	effect_desc = {
		### Prestige effect
		desc = task_bestow_royal_favor_prestige_effect_desc
		# Bureaucrats tooltip
		triggered_desc = {
			trigger = {
				councillor_liege_has_erudition_legacy_5_perk = yes
				scope:councillor.chancellor_bestow_royal_favor_opinion_gain_erudition_bonus >= 1
			}
			desc = task_bestoy_royal_favor_effect_desc_bureaucrats_bonus_prestige
		}
		# Family Business tooltip
		triggered_desc = {
			trigger = {
				councillor_liege_has_family_business_bonus = yes
				scope:councillor.chancellor_bestow_royal_favor_opinion_gain_family_business_bonus >= 1
			}
			desc = task_bestoy_royal_favor_effect_desc_family_business_bonus_prestige
		}
		# Fp3 Consulted House Member tooltip
		triggered_desc = {
			trigger = {
				councillor_liege_has_consulted_house_bonus = yes
				scope:councillor.chancellor_bestow_royal_favor_opinion_gain_consulted_house_bonus >= 1
			}
			desc = task_bestoy_royal_favor_effect_desc_consulted_house_bonus_prestige
		}
		### Opinion effect
		desc = task_bestow_royal_favor_opinion_effect_desc
		# Bureaucrats tooltip
		triggered_desc = {
			trigger = {
				councillor_liege_has_erudition_legacy_5_perk = yes
			}
			desc = task_bestoy_royal_favor_effect_desc_bureaucrats_bonus_opinion
		}
		# Family Business tooltip
		triggered_desc = {
			trigger = {
				councillor_liege_has_family_business_bonus = yes
			}
			desc = task_bestoy_royal_favor_effect_desc_family_business_bonus_opinion
		}
		# Fp3 Consulted House Member tooltip
		triggered_desc = {
			trigger = {
				councillor_liege_has_consulted_house_bonus = yes
			}
			desc = task_bestoy_royal_favor_effect_desc_consulted_house_bonus_opinion
		}
		desc = {
			desc = council_task_possible_side_effects
			triggered_desc = {
				trigger = {
					scope:councillor.diplomacy > mediocre_skill_rating
				}
				desc = task_increase_control_improved_vassal_opinion
			}
			triggered_desc = {
				trigger = {
					scope:councillor.diplomacy > mediocre_skill_rating
				}
				desc = task_increase_control_end_internal_war
			}
			triggered_desc = {
				trigger = {
					scope:councillor.diplomacy < high_skill_rating
				}
				desc = task_increase_control_lose_vassal_opinion
			}
			triggered_desc = {
				trigger = {
					scope:councillor.diplomacy < high_skill_rating
					liege = {
						any_vassal = {
							government_has_flag = government_is_feudal
							primary_title.tier > tier_barony
						}
					}
				}
				desc = task_increase_control_worsen_contract
			}
		}
	}

	is_shown = {
		has_dlc_feature = royal_court
		trigger_if = {
			limit = {
				scope:councillor_liege = { tgp_has_access_to_ministry_trigger = yes }
			}
			has_council_position = minister_personnel
		}
	}

	is_valid_showing_failures_only =  {
		liege = {
			court_grandeur_current_level >= 2
		}
	}

	on_start_task = {
		scope:councillor.councillor_task_target = {
			hidden_effect = {
				send_interface_message = {
					type = msg_chancellor_task_good
					title = task_bestow_royal_favor
					desc = task_bestow_royal_favor_target_message
					left_icon = scope:councillor_liege
					#Two different levels depending on the liege's CGV
					if = {
						limit = {
							scope:councillor_liege = {
								court_grandeur_current_level >= 7
							}
						}
						add_character_modifier = {
							modifier = chancellor_task_bestow_royal_favor_vassal_boosted_modifier
						}
					}
					else = {
						add_character_modifier = {
							modifier = chancellor_task_bestow_royal_favor_vassal_modifier
						}
					}
				}
			}

			# We check that you're still the target of this council task (this event will loop until you're not)
			trigger_event = chancellor_task.0999
		}
	}

	on_cancel_task = {
		if = {
			limit = {
				OR = {
					scope:councillor.councillor_task_target = { has_character_modifier = chancellor_task_bestow_royal_favor_vassal_boosted_modifier }
					scope:councillor.councillor_task_target = { has_character_modifier = chancellor_task_bestow_royal_favor_vassal_modifier }
				}
			}
			scope:councillor.councillor_task_target = {
				send_interface_message = {
					type = msg_chancellor_task_bad
					title = task_bestow_royal_favor
					desc = task_bestow_royal_favor_target_cancel_message
					left_icon = scope:councillor_liege
					if = {
						limit = { has_character_modifier = chancellor_task_bestow_royal_favor_vassal_boosted_modifier }
						remove_character_modifier = chancellor_task_bestow_royal_favor_vassal_boosted_modifier
					}
					else = { remove_character_modifier = chancellor_task_bestow_royal_favor_vassal_modifier }
				}
			}
		}
	}

	council_owner_modifier = {
		name = task_bestow_royal_favor_prestige_modifier
		monthly_prestige = 1
		scale = chancellor_bestow_royal_favor_prestige_total
	}

	monthly_on_action = task_bestow_royal_favor_side_effects

	on_finish_task_court = {
		scope:councillor_liege = {
			trigger_event = chancellor_task.0991
		}
	}

	valid_target_court = {
		scope:target_character = {
			custom_description = {
				text = chancellor_will_not_increase_their_liege_opinion
				this != scope:councillor_liege
			}
			trigger_if = { # For the sake of tooltips
				limit = {
					this != scope:councillor_liege
				}
				is_vassal_or_below_of = scope:councillor_liege
			}
			is_alive = yes
			highest_held_title_tier >= tier_county
			NOT = { is_at_war_with = scope:councillor_liege }
		}
	}

	potential_target_court = {
		scope:target_character = {
			is_alive = yes
			is_playable_character = yes
			highest_held_title_tier >= tier_county
			is_at_war_with_liege = no
			NOT = { is_at_war_with = scope:councillor_liege }
			custom_description = {
				text = chancellor_will_not_increase_their_own_opinion
				this != scope:councillor
			}
			trigger_if = {
				limit = {
					scope:councillor_liege = { is_ai = yes }
				}
				is_powerful_vassal = yes
				is_vassal_of = scope:councillor_liege
				OR = {
					opinion = {
						target = scope:councillor_liege
						value <= 0
					}
					has_any_good_relationship_with_character_trigger = { CHARACTER = scope:councillor_liege }
				}
				NOT = {
					opinion = {
						target = scope:councillor_liege
						value >= 100
					}
				}
			}
		}
	}

	progress = {
		value = 0
		add = {
			value = scope:councillor.chancellor_bestow_royal_favor_progress_gain
			desc = SCALED_COUNCILLOR_DIPLOMACY_VALUE
		}
		# Relation Bonuses/Penalties
		if = {
			limit = {
				exists = scope:councillor_liege
			}
			if = { # Friend
				limit = {
					scope:councillor_liege = {
						has_relation_friend = scope:councillor
						NOT = { has_relation_best_friend = scope:councillor }
					}
				}
				add = {
					value = scope:councillor.chancellor_bestow_royal_favor_monthly_increase_friend_bonus
					desc = COUNCILLOR_IS_YOUR_FRIEND
				}
			}
			if = { # Best Friend
				limit = {
					scope:councillor_liege = {
						has_relation_best_friend = scope:councillor
					}
				}
				add = {
					value = scope:councillor.chancellor_bestow_royal_favor_monthly_increase_best_friend_bonus
					desc = COUNCILLOR_IS_YOUR_BEST_FRIEND
				}
			}
			if = { # Rival
				limit = {
					scope:councillor_liege = {
						has_relation_rival = scope:councillor
						NOT = { has_relation_nemesis = scope:councillor }
					}
				}
				add = {
					value = scope:councillor.chancellor_bestow_royal_favor_monthly_increase_rival_bonus
					desc = COUNCILLOR_IS_YOUR_RIVAL
				}
			}
			if = { # Nemesis
				limit = {
					scope:councillor_liege = {
						has_relation_nemesis = scope:councillor
					}
				}
				add = {
					value = scope:councillor.chancellor_bestow_royal_favor_monthly_increase_nemesis_bonus
					desc = COUNCILLOR_IS_YOUR_NEMESIS
				}
			}
			#other bonuses/penalties, from FP3
			if = {
				limit = {
					councillor_liege_has_khvarenah_legacy_perk = yes
				}
				multiply = {
					value = 1.2
					desc = KHVARENAH_DYNASTY_PERK_BONUS_VALUE
				}
			}
		}
	}

	ai_will_do = {
		value = 1
		if = { # Do this if you only have one vassal that dislike you (if you have more than one we likely want the AI to go for Domestic Affairs instead)
			limit = {
				scope:councillor_liege = {
					any_powerful_vassal = {
						opinion = {
							target = scope:councillor_liege
							value <= 0
						}
						count = 1
					}
				}
			}
			add = 100
		}

		if = { # We want some favoritism to show up
			limit = {
				scope:councillor_liege = {
					NOT = { # But only if the realm is kinda stable
						any_powerful_vassal = {
							opinion = {
								target = scope:councillor_liege
								value <= 0
							}
						}
					}
					any_vassal = {
						has_any_good_relationship_with_character_trigger = { CHARACTER = scope:councillor_liege }
					}
				}
			}
			add = 100
		}

		if = { # If you're already doing Domestic Affairs and multiple powerful vassals dislike you: keep doing what you're doing!
			limit = {
				scope:councillor = {
					is_performing_council_task = task_domestic_affairs
				}
				scope:councillor_liege = {
					any_powerful_vassal = {
						opinion = {
							target = scope:councillor_liege
							value <= 0
						}
						count >= 2
					}
				}
			}
			add = -1000
		}
	}
}
