# -*- ck2.objectives -*-

# Character plots to lower skill of a councillor whose job they want
plot_discredit_councillor = {
	type = realm_characters # All characters in the same realm, plus rivals and relatives of self, parents, children and spouse
	intrigue_plot = yes

	# Plotter scope
	potential = {
		prisoner = no
		independent = no
		is_adult = yes
		is_incapable = no
		OR = {
			diplomacy = 10
			stewardship = 10
			intrigue = 10
			martial = 10
			learning = 10
		}
		NOT = { has_opinion_modifier = { who = liege modifier = opinion_refused_council } }
		NOT = { trait = in_hiding }
	}

	# Target scope
	target_potential = {
		same_liege = FROM
		is_councillor = yes
		NOT = { trait = in_hiding }
	}

	# Target scope
	allow = {
		NOT = { liege = { is_married = FROM } }
		OR = {
			#chancellor
			AND = {
				has_job_title = job_chancellor
				NOT = {
					attribute_diff = {
						character = FROM
						attribute = diplomacy
						value = 5
					}
				}
				FROM = {
					diplomacy = 10
					can_be_chancellor_trigger = yes
				}
			}
			#steward
			AND = {
				has_job_title = job_treasurer
				NOT = {
					attribute_diff = {
						character = FROM
						attribute = stewardship
						value = 5
					}
				}
				FROM = {
					stewardship = 10
					can_be_treasurer_trigger = yes
				}
			}
			#spymaster
			AND = {
				has_job_title = job_spymaster
				NOT = {
					attribute_diff = {
						character = FROM
						attribute = intrigue
						value = 5
					}
				}
				FROM = {
					intrigue = 10
					can_be_spymaster_trigger = yes
				}
			}
			#marshal
			AND = {
				has_job_title = job_marshal
				NOT = {
					attribute_diff = {
						character = FROM
						attribute = martial
						value = 5
					}
				}
				FROM = {
					martial = 10
					can_be_marshal_trigger = yes
				}
			}
			#court chaplain
			AND = {
				has_job_title = job_spiritual
				NOT = {
					attribute_diff = {
						character = FROM
						attribute = learning
						value = 5
					}
				}
				FROM = {
					learning = 10
					can_be_spiritual_trigger = yes
				}
			}
		}
	}

	chance = {
		factor = 1
		modifier = {
			factor = 10
			FROM = {
				OR = {
					has_ambition = obj_become_chancellor
					has_ambition = obj_become_marshal
					has_ambition = obj_become_treasurer
					has_ambition = obj_become_spymaster
					has_ambition = obj_become_spiritual
				}
			}
		}
		modifier = {
			factor = 10
			is_rival = FROM
		}
		modifier = {
			factor = 0
			FROM = {
				OR = {
					NOT = { ai_ambition = -39 }
					trait = honest
					trait = kind
					trait = just
					trait = charitable
				}
			}
		}
		modifier = {
			factor = 0.5
			FROM = { is_close_relative = ROOT }
		}
		modifier = {
			factor = 0
			FROM = { opinion = { who = ROOT value = 50 } }
		}
		modifier = {
			factor = 0.25
			FROM = { opinion = { who = ROOT value = 25 } }
		}
		modifier = {
			factor = 1.5
			FROM = { NOT = { opinion = { who = ROOT value = -25 } } }
		}
		modifier = {
			factor = 1.5
			FROM = { NOT = { opinion = { who = ROOT value = -50 } } }
		}
		modifier = {
			factor = 2.0
			FROM = { NOT = { opinion = { who = ROOT value = -75 } } }
		}
		modifier = {
			factor = 0.5
			FROM = { NOT = { intrigue = 5 } }
		}
		modifier = {
			factor = 0.5
			FROM = { NOT = { intrigue = 10 } }
		}
		modifier = {
			factor = 2
			FROM = { intrigue = 15 }
		}
		modifier = {
			factor = 2
			FROM = { intrigue = 20 }
		}
		modifier = {
			factor = 2.0
			FROM = { trait = envious }
		}
		modifier = {
			factor = 2.0
			FROM = { ai_ambition = 20 }
		}
		modifier = {
			factor = 2.0
			FROM = { ai_ambition = 40 }
		}
	}

	success = {
		hidden_tooltip = { FROM = { has_flag = plot_success } }
		custom_tooltip = { text = TARGET_DISCREDITED }
	}

	abort = {
		OR = {
			FROM = { emf_is_voter = yes }
			AND = {
				emf_is_voter = no
				FROM = { NOT = { has_flag = plot_success } }
			}
			is_alive = no
			FROM = { has_flag = abort_plot }
			FROM = { prisoner = yes }
			FROM = { is_incapable = yes }
		}
	}

	abort_effect = {
		FROM = {
			# Clear flags
			hidden_tooltip = {
				clr_flag = event7040
				clr_flag = allow_plotting
				clr_flag = plot_in_action
				clr_flag = abort_plot
			}
			emf_remove_plot_assisted_spying = yes
		}
	}

	effect = {
		FROM = {
			any_plot_backer = {
				reverse_opinion = {
					modifier = opinion_grateful
					who = FROM
					years = 5
				}
			}
			emf_remove_plot_assisted_spying = yes
			# Clear flags
			hidden_tooltip = {
				clr_flag = event7040
				clr_flag = plot_success
				clr_flag = allow_plotting
				clr_flag = plot_in_action
				clr_flag = abort_plot
			}
		}
	}
}

