﻿namespace = council_plot

#######################
# Council Plot Events #
#######################
# Petition Events: 1-49
#######################
# Maintenance Events
# council_plot.50	You Now Support A New Candidate
# council_plot.51	A Former Sponsor Has Betrayed You!
#######################
# New Sponsor Events
#######################
# council_plot.52	You Support A Friend On Your Liege's Council
# council_plot.53	A Friend Supports You!
#######################

# Prompt AI characters to scheme
council_plot.198 = {
	type = character_event
	
	hidden = yes

	trigger = {
		is_pool_character = no
		is_foreign_court_or_pool_guest = no
		
		is_available_ai_adult = yes
		is_councillor = no
		exists = liege_or_court_owner
		NOT = { this = liege_or_court_owner }
		OR = {
			is_ruler = yes
			liege_or_court_owner = { #dont bother with lower ranks
				OR = {
					is_ai = no
					highest_held_title_tier >= tier_duchy
				}
			}
		}
		NAND = { #exclude lowborn barons in higher tier realms
			highest_held_title_tier = tier_barony
			is_lowborn = yes
			liege = { highest_held_title_tier >= tier_kingdom }
		}
		
		NOT = { has_trait = content }
		ai_greed >= 0
		
		NOT = {
			any_scheme = {
				OR = {
					scheme_type = murder
					scheme_type = abduct
					scheme_type = claim_throne
					scheme_type = fabricate_hook
					
					scheme_type = replace_councillor
				}
			}
		}
	}

	immediate = {
		save_scope_as = actor
		liege_or_court_owner = {
			random_councillor = {
				limit = {
					save_temporary_scope_as = target_councillor
					scope:actor = {
						can_start_scheme = {
							target = prev
							type = replace_councillor
						}
					}
					reverse_opinion = { target = scope:actor value < high_positive_opinion }
					trigger_if = {
						limit = { scope:actor = { is_powerful_vassal = yes } }
						always = yes
					}
					trigger_else_if = {
						limit = { has_council_position = councillor_chancellor }
						scope:actor = { diplomacy >= 12 }
					}
					trigger_else_if = {
						limit = { has_council_position = councillor_steward }
						scope:actor = { stewardship >= 12 }
					}
					trigger_else_if = {
						limit = { has_council_position = councillor_marshal }
						scope:actor = { martial >= 12 }
					}
					trigger_else_if = {
						limit = { has_council_position = councillor_spymaster }
						scope:actor = { intrigue >= 12 }
					}
					trigger_else_if = {
						limit = { has_council_position = councillor_court_chaplain }
						scope:actor = { learning >= 12 }
					}
					trigger_else = {
						scope:actor = { stewardship >= 12 }
					}
					
					##Motives##
					scope:actor = {
						OR = {
							is_powerful_vassal = yes
							superior_councillor_trigger = { COUNCILLOR = scope:target_councillor }
							is_close_or_extended_family_of = liege_or_court_owner
							is_spouse_of = liege_or_court_owner
							trigger_if = {
								limit = { #If liege has many vassals, tighten conditions to reduce spam
									liege = {
										highest_held_title_tier >= tier_kingdom
										any_vassal = {
											count >= 30
										}
									}
								}
								ai_greed >= 90
							}
							trigger_else = {
								ai_greed >= high_positive_ai_value
							}
						}
					}	
				}
				weight = {
					base = 0
					modifier = {
						add = 1000
						scope:actor = { superior_councillor_trigger = { COUNCILLOR = scope:target_councillor } }
					}
					modifier = {
						add = -100
						scope:actor = { has_attribute_for_councillor_trigger = { COUNCILLOR = scope:target_councillor OPERATOR = less VALUE = 10 } }
					}
					modifier = {
						add = 100
						scope:actor = { has_attribute_for_councillor_trigger = { COUNCILLOR = scope:target_councillor OPERATOR = greater VALUE = 15 } }
					}
				}
				save_scope_as = recipient
				random = {
					chance = 0
					
					modifier = { #If councillor is much better, only irrational characters/powerful vassals target them						
						add = {
							if = {
								limit = { has_council_position = councillor_chancellor }
								value = scope:actor.diplomacy
								subtract = scope:recipient.diplomacy
							}	
							else_if = {
								limit = { has_council_position = councillor_steward }
								value = scope:actor.stewardship
								subtract = scope:recipient.stewardship
							}
							else_if = {
								limit = { has_council_position = councillor_marshal }
								value = scope:actor.martial
								subtract = scope:recipient.martial
							}
							else_if = {
								limit = { has_council_position = councillor_spymaster }
								value = scope:actor.intrigue
								subtract = scope:recipient.intrigue
							}
							else_if = {
								limit = { has_council_position = councillor_court_chaplain }
								value = scope:actor.learning
								subtract = scope:recipient.learning
							}
							add = 5
							multiply = 1000
							max = 0
							min = -1000
						}	
						scope:actor = {
							is_powerful_vassal = no
							ai_rationality >= medium_negative_ai_value
						}
					}
					modifier = {
						add = 30
						scope:actor = { is_powerful_vassal = yes }
					}
					#AI personality
					modifier = { 
						add = { 
							value = scope:actor.ai_greed
							min = -75
							max = 75
						}
					}
					modifier = { 
						add = { 
							value = scope:actor.ai_energy
							multiply = 0.5
							min = -35
							max = 35
						}
					}
					
					##Skill
					modifier = {
						add = 40
						scope:actor = { superior_councillor_trigger = { COUNCILLOR = scope:recipient } }
					}
					modifier = {
						add = -15
						scope:actor = { has_attribute_for_councillor_trigger = { COUNCILLOR = scope:recipient OPERATOR = less VALUE = 6 } }
					}
					modifier = {
						add = -10
						scope:actor = { has_attribute_for_councillor_trigger = { COUNCILLOR = scope:recipient OPERATOR = less VALUE = 10 } }
					}
					modifier = {
						add = 5
						scope:actor = { has_attribute_for_councillor_trigger = { COUNCILLOR = scope:recipient OPERATOR = greater VALUE = 11 } }
					}
					modifier = {
						add = 5
						scope:actor = { has_attribute_for_councillor_trigger = { COUNCILLOR = scope:recipient OPERATOR = greater VALUE = 13 } }
					}
					modifier = {
						add = 10
						scope:actor = { has_attribute_for_councillor_trigger = { COUNCILLOR = scope:recipient OPERATOR = greater VALUE = 15 } }
					}
					modifier = {
						add = 10
						scope:actor = { has_attribute_for_councillor_trigger = { COUNCILLOR = scope:recipient OPERATOR = greater VALUE = 17 } }
					}
					
					##Relevent traits
					#diplomacy
					modifier = {
						add = 15
						scope:recipient = { has_council_position = councillor_chancellor }
						scope:actor = { has_diplomacy_lifestyle_trait_trigger = yes }
					}
					modifier = {
						add = 15
						scope:recipient = { has_council_position = councillor_chancellor }
						scope:actor = { has_education_diplomacy_trigger = yes }
					}

					modifier = {
						add = 15
						scope:recipient = { has_council_position = councillor_steward }
						scope:actor = { has_stewardship_lifestyle_trait_trigger = yes }
					}
					modifier = {
						add = 15
						scope:recipient = { has_council_position = councillor_steward }
						scope:actor = { has_education_stewardship_trigger = yes }
					}
					
					modifier = {
						add = 15
						scope:recipient = { has_council_position = councillor_marshal }
						scope:actor = { has_martial_lifestyle_trait_trigger = yes }
					}
					modifier = {
						add = 15
						scope:recipient = { has_council_position = councillor_marshal }
						scope:actor = { has_education_martial_trigger = yes }
					}
					
					modifier = {
						add = 15
						scope:recipient = { has_council_position = councillor_spymaster }
						scope:actor = { has_intrigue_lifestyle_trait_trigger = yes }
					}
					modifier = {
						add = 15
						scope:recipient = { has_council_position = councillor_spymaster }
						scope:actor = { has_education_intrigue_trigger = yes }
					}
					
					modifier = {
						add = 15
						scope:recipient = { has_council_position = councillor_court_chaplain }
						scope:actor = { has_learning_lifestyle_trait_trigger = yes }
					}
					modifier = {
						add = 15
						scope:recipient = { has_council_position = councillor_court_chaplain }
						scope:actor = { has_education_learning_trigger = yes }
					}
					
					root = {
						start_scheme = {
							type = replace_councillor
							target = prev
						}
					}
				}
			}
		}
	}
}

#Scheme is ready notification event
council_plot.199 = {
	type = character_event
	title = council_plot.199.t
	desc = council_plot.199.desc
	theme = diplomacy
	left_portrait = scope:target
	right_portrait = scope:council_owner
	widget = {
		gui = "event_window_widget_scheme"
		container = "custom_widgets_container"
	}

	immediate = {
		liege_or_court_owner = { save_scope_as = council_owner	}
	}

	option = {
		name = council_plot.199.a
		hidden_effect = {
			#calculate scheme success chance
			random = {
				chance = scope:scheme.scheme_success_chance
				save_scope_value_as = {
					name = scheme_successful
					value = yes
				}
			}
		}
		#if = { #TODO: RGENCY HANDLING
			#limit = { has_regent = no }	
			custom_tooltip = TOOLTIPcouncil_plot.1
			scope:council_owner = { trigger_event = { id = council_plot.1 } }
		#}
		#if = { #Regent decides
			# limit = { has_regent = yes }
			# regent = { 
				# if = {
					# limit = {
						# ROOT = { plot_target_char = { character = PREVPREV } }
					# }
					# FROM = { clr_character_flag = flag_plot_replace_councillor_decision }
					# break = yes
				# }	
				# letter_event = { id = council_plot.1 }					
			# } 
		# }
		ai_chance = { # The AI should generally not back out of a planned Scheme
			base = 100
		}
	}

	option = {
		name = council_plot.199.b
		custom_tooltip = do_not_execute_replace_councillor_tooltip
		hidden_effect = {
			scope:scheme = { add_scheme_progress = -50 }
		}
		ai_chance = {
			base = 0
		}
		stress_impact = {
			ambitious = major_stress_impact_gain
			arrogant = medium_stress_impact_gain
			impatient = medium_stress_impact_gain
			stubborn = medium_stress_impact_gain
		}
	}
}


# New Councillor Petition
council_plot.1 = {
	type = letter_event
	opening = council_plot.1.opening
	desc = council_plot.1.desc
	sender = {
		character = scope:owner
		animation = admiration
	}
	
	immediate = {
	}

	option = {
		name = council_plot.1.a #Agree
		trigger = {
			OR = {
				exists = scope:scheme_successful
				is_ai = no
			}
		}
		
		#TODO: Regent handling
		# if = {
			# limit = {
				# FROM = {
					# OR = {
						# liege = { regent = { character = PREVPREV } }
						# any_plot_backer = {
							# liege = { character = ROOT }
							# liege = { regent = { character = PREVPREV } }
						# }
					# }
				# }
			# }
			# custom_tooltip = { text = REGENT_DEMAND }
		# }

		#If this is regent's decision, add opinions to liege as well
		# hidden_tooltip = {
			# if = {
				# limit = { NOT = { character = FROM } }
				# liege = {
					# FROMFROM = {
						# any_plot_backer = {
							# opinion = { target = PREVPREV modifier = opinion_approved_council_candidate }
						# }
						# plot_target_char = {
							# opinion = { target = PREVPREV modifier = opinion_fired_from_council }
							# liege = {
								# any_realm_character = {
									# limit = { 
										# reverse_has_opinion_modifier = { target = PREVPREV modifier = opinion_council_sponsor }
										# NOT = { any_backed_character = { character = FROMFROM } }						
									# }
									# if = {
										# limit = { has_opinion_modifier = { target = PREV modifier = opinion_approved_council_candidate } }
										# remove_opinion = { target = PREV modifier = opinion_approved_council_candidate }
									# }	
									# opinion = { target = PREV modifier = opinion_replaced_council_candidate }
								# }
							# }
						# }
					# }
				# }
			# }
		# }
		
		#Supporters
		scope:owner = {
			show_as_tooltip = {
				add_opinion = {
					target = ROOT
					modifier = opinion_ambition_fulfilled
					months = 120
				}
			}	
			hidden_effect = { 
				trigger_event = { id = council_plot.2 days = 1 }
			}
		}	
		scope:scheme = {
			every_scheme_agent = {
				add_opinion = { target = ROOT modifier = opinion_approved_council_candidate }
				hidden_effect = { trigger_event = { id = council_plot.3 days = 1 } }
			}
		}
		
		# Show opponents
		scope:target = {
			# set_character_flag = flag_replaced_by_plot_event			
			# if = {
				# limit = { has_character_modifier = negotiated_council_postion }
				# opinion = { target = ROOT modifier = opinion_fired_from_council multiplier = 3 }
			# }
			# else = {
				show_as_tooltip = { add_opinion = { target = ROOT modifier = fired_from_council_opinion } }
			#}
			hidden_effect = { trigger_event = { id = council_plot.4 days = 1 } }
		}
		every_courtier_or_guest = {
			limit = { 
				reverse_has_opinion_modifier = { target = scope:target modifier = opinion_council_sponsor }
				NOT = { scope:scheme = { scheme_is_character_agent = prev } }					
			}
			if = {
				limit = { has_opinion_modifier = { target = ROOT modifier = opinion_approved_council_candidate } }
				remove_opinion = { target = ROOT modifier = opinion_approved_council_candidate }
			}	
			add_opinion = { target = ROOT modifier = opinion_replaced_council_candidate }
			hidden_effect = { trigger_event = { id = council_plot.5 } }
		}
		every_vassal = {
			limit = { 
				reverse_has_opinion_modifier = { target = scope:target modifier = opinion_council_sponsor }
				NOT = { scope:scheme = { scheme_is_character_agent = prev } }							
			}
			if = {
				limit = { has_opinion_modifier = { target = ROOT modifier = opinion_approved_council_candidate } }
				remove_opinion = { target = ROOT modifier = opinion_approved_council_candidate }
			}	
			add_opinion = { target = ROOT modifier = opinion_replaced_council_candidate }
			hidden_effect = { trigger_event = { id = council_plot.5 } }
		}
		# Actually make the change
		
		scope:target = {		
			if = {
				limit = { has_council_position = councillor_chancellor }			
				root = { 
					fire_councillor = prev
					assign_councillor_type = { type = councillor_chancellor target = scope:owner fire_on_actions = yes }
				}
			}
			else_if = {
				limit = { has_council_position = councillor_steward }			
				root = { 
					fire_councillor = prev
					assign_councillor_type = { type = councillor_steward target = scope:owner fire_on_actions = yes  }
				}
			}
			else_if = {
				limit = { has_council_position = councillor_marshal }			
				root = { 
					fire_councillor = prev
					assign_councillor_type = { type = councillor_marshal target = scope:owner fire_on_actions = yes } 
				}
			}
			else_if = {
				limit = { has_council_position = councillor_spymaster }			
				root = { 
					fire_councillor = prev
					assign_councillor_type = { type = councillor_spymaster target = scope:owner fire_on_actions = yes  }
				}
			}
			else_if = {
				limit = { has_council_position = councillor_court_chaplain }			
				root = { 
					fire_councillor = prev
					assign_councillor_type = { type = councillor_court_chaplain target = scope:owner fire_on_actions = yes } 
				}
			}
		}	
		
		# #Regent inform liege
		# hidden_effect = {
			# if = {
				# limit = { NOT = { character = FROM } }
				# FROM = { trigger_event = { id = council_plot.10 } }
			# }
		# }
		
	}
	
	option = {
		name = council_plot.1.b #Refuse
		trigger = {
			OR = {
				NOT = { exists = scope:scheme_successful }
				is_ai = no
			}
		}
		scope:owner = {
			add_opinion = { target = ROOT modifier = opinion_refused_council }
			hidden_effect = { trigger_event = { id = council_plot.6 } }
		}	
		scope:scheme = {
			every_scheme_agent = {
				add_opinion = { target = ROOT modifier = opinion_rejected_council_candidate }
				hidden_effect = { trigger_event = { id = council_plot.7 } }
			}
		}
		
		scope:target = {
			add_opinion = { target = ROOT modifier = opinion_rejected_rival_council_candidate }
			hidden_effect = { trigger_event = { id = council_plot.8 } }
		}
		every_courtier_or_guest = {
			limit = { 
				reverse_has_opinion_modifier = { target = scope:target modifier = opinion_council_sponsor }
				NOT = { scope:scheme = { scheme_is_character_agent = prev } }						
			}
			hidden_effect = { trigger_event = { id = council_plot.9 } }
			add_opinion = { target = ROOT modifier = opinion_rejected_rival_council_candidate }
		}
		every_vassal = {
			limit = { 
				reverse_has_opinion_modifier = { target = scope:target modifier = opinion_council_sponsor }
				NOT = { scope:scheme = { scheme_is_character_agent = prev } }								
			}
			hidden_effect = { trigger_event = { id = council_plot.9 } }
			add_opinion = { target = ROOT modifier = opinion_rejected_rival_council_candidate }
		}
	}
}

#Approved - Inform New Councillor
council_plot.2 = {
	type = character_event
	#title = council_plot.2.t
	desc = council_plot.2.desc
	theme = diplomacy
	
	left_portrait = {
		character = scope:owner
		animation = happiness
	}	
	right_portrait = {
		character = scope:target
		animation = anger
	}	
	lower_center_portrait = scope:council_owner
	
	immediate = {
		scope:scheme = {
			if = {
				limit = { scheme_type = replace_councillor }
				every_scheme_agent = {
					reverse_add_opinion = { target = scope:owner modifier = opinion_council_sponsor }
				}
				end_scheme = yes
			}	
		}
	}

	option = {
		name = council_plot.2.a
	}
}	
#Approved - Inform New Councillor's Supporters
council_plot.3 = {
	type = character_event
	#title = council_plot.3.t
	desc = council_plot.3.desc
	theme = diplomacy
	
	left_portrait = {
		character = scope:owner
		animation = happiness
	}	
	right_portrait = {
		character = scope:target
		animation = anger
	}	
	lower_center_portrait = scope:council_owner
	
	option = {
		name = council_plot.3.a
	}
}
	
#Approved - Inform Old Councillor
council_plot.4 = {
	type = character_event
	#title = council_plot.4.t
	desc = council_plot.4.desc
	theme = diplomacy
	
	left_portrait = {
		character = scope:owner
		animation = happiness
	}	
	right_portrait = {
		character = scope:council_owner
	}	

	option = {
		name = council_plot.4.a 
		ai_chance = { 
			base = 50 
			ai_value_modifier = {
				ai_compassion = 0.75
				ai_honor = 0.25
			}
		}
		stress_impact = {
			vengeful = medium_stress_impact_gain
			ambitious = medium_stress_impact_gain
		}
	}
	option = {
		name = council_plot.4.b #rival chance
		ai_chance = { 
			base = 50
			ai_value_modifier = {
				ai_vengefulness = 0.5
				ai_boldness = 0.25
				ai_compassion = -0.25
			}
			
			modifier = {
				add = -100
				has_trait = forgiving
			}
			modifier = {
				add = 100
				has_trait = vengeful
			}
			modifier = {
				add = -100
				has_trait = content
			}
			modifier = {
				add = 100
				has_trait = ambitious
			}
		}
		if = {
			limit = {
				OR = {
					can_set_relation_potential_rival_trigger = { CHARACTER = scope:owner }
					can_set_relation_rival_trigger = { CHARACTER = scope:owner }
				}
			}
			progress_towards_rival_effect = {
				CHARACTER = scope:owner
				OPINION = no
			}
		}
		else = {
			scope:owner = {
				add_opinion = {
					target = root
					modifier = angry_opinion
					opinion = -20
				}
			}
		}
		stress_impact = {
			forgiving = medium_stress_impact_gain
			content = medium_stress_impact_gain
		}
	}
}
#Approved - Inform Old Councillor's Supporters
council_plot.5 = {
	type = character_event
	#title = council_plot.5.t
	desc = council_plot.5.desc
	theme = diplomacy
	
	left_portrait = {
		character = scope:owner
		animation = happiness
	}	
	right_portrait = {
		character = scope:target
		animation = anger
	}	
	lower_center_portrait = scope:council_owner
	
	option = {
		name = council_plot.5.a
	}
}
#Rejected - Inform Petitioner
council_plot.6 = {
	type = character_event
	#title = council_plot.6.t
	desc = council_plot.6.desc
	theme = diplomacy
	
	left_portrait = {
		character = scope:owner
		animation = anger		
	}	
	right_portrait = {
		character = scope:target
		animation = happiness
	}	
	lower_center_portrait = scope:council_owner
	
	immediate = {
		scope:scheme = {
			if = {
				limit = { scheme_type = replace_councillor }
				end_scheme = yes
			}
		}
	}
	
	option = {
		name = council_plot.6.a 
		ai_chance = { 
			base = 50 
			ai_value_modifier = {
				ai_compassion = 0.75
				ai_honor = 0.25
			}
		}
		stress_impact = {
			vengeful = medium_stress_impact_gain
			ambitious = medium_stress_impact_gain
		}
	}
	option = {
		name = council_plot.6.b #rival chance
		ai_chance = { 
			base = 50
			ai_value_modifier = {
				ai_vengefulness = 0.5
				ai_boldness = 0.25
				ai_compassion = -0.25
			}
			
			modifier = {
				add = -100
				has_trait = forgiving
			}
			modifier = {
				add = 100
				has_trait = vengeful
			}
			modifier = {
				add = -100
				has_trait = content
			}
			modifier = {
				add = 100
				has_trait = ambitious
			}
		}
		if = {
			limit = {
				OR = {
					can_set_relation_potential_rival_trigger = { CHARACTER = scope:target }
					can_set_relation_rival_trigger = { CHARACTER = scope:target }
				}
			}
			progress_towards_rival_effect = {
				CHARACTER = scope:target
				OPINION = no
			}
		}
		else = {
			scope:target = {
				add_opinion = {
					target = root
					modifier = angry_opinion
					opinion = -20
				}
			}
		}
		stress_impact = {
			forgiving = medium_stress_impact_gain
			content = medium_stress_impact_gain
		}
	}
}
#Rejected - Inform Petitioner's Supporters
council_plot.7 = {
	type = character_event
	#title = council_plot.7.t
	desc = council_plot.7.desc
	theme = diplomacy
	
	left_portrait = {
		character = scope:owner
		animation = anger		
	}	
	right_portrait = {
		character = scope:target
		animation = happiness
	}	
	lower_center_portrait = scope:council_owner
	
	option = {
		name = council_plot.7.a
	}
}
#Rejected - Inform Old Councillor
council_plot.8 = {
	type = character_event
	#title = council_plot.8.t
	desc = council_plot.8.desc
	theme = diplomacy
	
	left_portrait = {
		character = scope:owner
		animation = anger		
	}	
	right_portrait = {
		character = scope:council_owner
	}	

	option = {
		name = council_plot.8.a
	}
}
#Rejected - Inform Old Councillor's Supporters
council_plot.9 = {
	type = character_event
	#title = council_plot.9.t
	desc = council_plot.9.desc
	theme = diplomacy
	
	left_portrait = {
		character = scope:owner
		animation = anger		
	}	
	right_portrait = {
		character = scope:target
		animation = happiness
	}	
	lower_center_portrait = scope:council_owner
	
	option = {
		name = council_plot.9.a
	}
}
# #Approved - Inform Liege
# character_event = {
	# id = council_plot.10
	# desc = "EVTDESCCOUNCILPLOT10"
	# picture = GFX_evt_spymaster
	# show_from_from_from = yes
	# is_triggered_only = yes
	
	# option = { name = "EVTOPTACOUNCILPLOT10" }
# }


# NEW SPONSOR EVENTS
#You Support A Friend On Your Liege's Council
council_plot.52 = {
	hidden = yes

	trigger = {
		is_independent_ruler = no
		is_councillor = yes
		any_relation = {
			type = friend
			
			liege_or_court_owner = root.liege_or_court_owner
			is_independent_ruler = no
			save_temporary_scope_as = supporting_friend
			NOT = {
				root = {
					any_targeting_scheme = {
						scheme_type = replace_councillor
						OR = {
							any_scheme_agent = { this = scope:supporting_friend }
							scheme_owner = scope:supporting_friend
						}	
					}
				}	
			}
			NOT = { reverse_has_opinion_modifier = { target = ROOT modifier = opinion_council_sponsor } }
		}
	}
	
	immediate = {
		random_relation = {
			type = friend
			limit = {
				liege_or_court_owner = root.liege_or_court_owner
				is_independent_ruler = no
				save_temporary_scope_as = supporting_friend
				NOT = {
					root = {
						any_targeting_scheme = {
							scheme_type = replace_councillor
							OR = {
								any_scheme_agent = { this = scope:supporting_friend }
								scheme_owner = scope:supporting_friend
							}	
						}
					}	
				}
				NOT = { reverse_has_opinion_modifier = { target = ROOT modifier = opinion_council_sponsor } }
			}
			save_scope_as = councillor_friend
			
		}
		
		send_interface_message = {
			title = council_plot.52.title
			desc = council_plot.52.notification
			left_icon = scope:councillor_friend
			scope:councillor_friend = {
				reverse_add_opinion = { target = root modifier = opinion_council_sponsor }
			}	
		}
		scope:councillor_friend = {
			send_interface_message = {
				title = council_plot.52.title_B
				desc = council_plot.52.notification_B
				left_icon = root
				show_as_tooltip = {
					reverse_add_opinion = { target = root modifier = opinion_council_sponsor }
				}	
			}
		}
	}
}


##Sponsored Candidate removed from council##
council_plot.54 = {
	type = character_event
	desc = council_plot.54.desc
	theme = diplomacy
	
	left_portrait = {
		character = scope:fired_councillor
		animation = anger
	}	
	lower_center_portrait = scope:sponsor_1
	lower_left_portrait = scope:sponsor_2
	lower_right_portrait = scope:sponsor_3
	
	trigger = {
		scope:fired_councillor = {
			is_imprisoned = no
			is_incapable = no
			liege = root
		}
	}
	
	immediate = {
		random_courtier_or_guest = {
			limit = { 
				reverse_has_opinion_modifier = { target = scope:fired_councillor modifier = opinion_council_sponsor } 
			}
			save_scope_as = sponsor_1	
		}
		random_courtier_or_guest = {
			limit = { 
				reverse_has_opinion_modifier = { target = scope:fired_councillor modifier = opinion_council_sponsor } 
				NOT = { this = scope:sponsor_1 }
			}
			save_scope_as = sponsor_2
		}
		random_courtier_or_guest = {
			limit = { 
				reverse_has_opinion_modifier = { target = scope:fired_councillor modifier = opinion_council_sponsor } 
				NOT = { this = scope:sponsor_1 }
				NOT = { this = scope:sponsor_2 }
			}
			save_scope_as = sponsor_3
		}
		random_vassal = {
			limit = { 
				reverse_has_opinion_modifier = { target = scope:fired_councillor modifier = opinion_council_sponsor } 
				NOT = { this = scope:sponsor_1 }
				NOT = { this = scope:sponsor_2 }
				NOT = { this = scope:sponsor_3 }
			}
			save_scope_as = sponsor_1	
		}
		random_vassal = {
			limit = { 
				reverse_has_opinion_modifier = { target = scope:fired_councillor modifier = opinion_council_sponsor } 
				NOT = { this = scope:sponsor_1 }
				NOT = { this = scope:sponsor_2 }
				NOT = { this = scope:sponsor_3 }
			}
			save_scope_as = sponsor_2
		}
		random_vassal = {
			limit = { 
				reverse_has_opinion_modifier = { target = scope:fired_councillor modifier = opinion_council_sponsor } 
				NOT = { this = scope:sponsor_1 }
				NOT = { this = scope:sponsor_2 }
				NOT = { this = scope:sponsor_3 }
			}
			save_scope_as = sponsor_3
		}
	}
	
	option = {
		name = council_plot.54.a 
		save_scope_as = council_owner
		every_courtier_or_guest = {
			limit = { 
				reverse_has_opinion_modifier = { target = scope:fired_councillor modifier = opinion_council_sponsor } 
			}
			add_opinion = { target = ROOT modifier = opinion_replaced_council_candidate }
			hidden_effect = {
				remove_opinion = { target = ROOT modifier = opinion_approved_council_candidate }
				scope:fired_councillor = { remove_opinion = { target = PREV modifier = opinion_council_sponsor } }
				reverse_add_opinion = { target = scope:fired_councillor modifier = opinion_former_council_sponsor }
				if = {
					limit = { is_ai = no }
					trigger_event = { id = council_plot.55 }
				}
			}	
		}
		every_vassal = {
			limit = { 
				reverse_has_opinion_modifier = { target = scope:fired_councillor modifier = opinion_council_sponsor } 
			}
			add_opinion = { target = ROOT modifier = opinion_replaced_council_candidate }
			hidden_effect = {
				remove_opinion = { target = ROOT modifier = opinion_approved_council_candidate }
				scope:fired_councillor= { remove_opinion = { target = PREV modifier = opinion_council_sponsor } }
				reverse_add_opinion = { target = scope:fired_councillor modifier = opinion_former_council_sponsor }
				if = {
					limit = { is_ai = no }
					trigger_event = { id = council_plot.55 }
				}
			}	
		}
	}
}
	
council_plot.55 = { #inform sponsor
	type = character_event
	desc = council_plot.55.desc
	theme = diplomacy
	
	left_portrait = {
		character = scope:fired_councillor
		animation = anger
	}	
	right_portrait = scope:council_owner
	lower_center_portrait = scope:sponsor_1
	lower_left_portrait = scope:sponsor_2
	lower_right_portrait = scope:sponsor_3
	
	option = {
		name = council_plot.55.a 
	}
}

###################
#Invalidation Messages
###################

council_plot.9999 = {
	type = character_event
	hidden = yes
	
	immediate = {
		if = { # Target has died
			limit = {
				scope:target = { is_alive = no }
			}
			send_interface_toast = {
				title = replace_councillor_invalidated
				type = event_toast_effect_neutral
				left_icon = scope:target
				custom_tooltip = replace_councillor_target_died_tt
			}
		}
		else_if = { # Target is no shared liege
			limit = {
				NOT = { liege_or_court_owner = scope:target.liege_or_court_owner }
			}
			send_interface_toast = {
				title = replace_councillor_invalidated
				type = event_toast_effect_neutral
				left_icon = scope:target
				custom_tooltip = replace_councillor_target_no_longer_liege_tt
			}
		}
		else_if = { # Target is no longer councillor
			limit = {
				scope:target = { is_councillor = no }
			}
			send_interface_toast = {
				title = replace_councillor_invalidated
				type = event_toast_effect_neutral
				left_icon = scope:target
				custom_tooltip = replace_councillor_target_not_councillor_tt
			}
		}		
		else = { # Fallback
			send_interface_toast = {
				title = replace_councillor_invalidated
				type = event_toast_effect_neutral
				left_icon = scope:target
				custom_tooltip = replace_councillor_invalidate_fallback_tt
			}
		}
	}
}