namespace = CK2

###################################
#
# CHARLEMAGNE
# - Councillor events
#
###################################

# Written by Henrik "Groogy" Hansson

# Councillor proposes to liege to handle his titles for him
character_event = {
	id = CK2.18000
	picture = GFX_evt_council
	border = GFX_event_normal_frame_diplomacy

	desc = {
		text = evt_18000_desc_a
		trigger = { FROM = { has_job_title = job_chancellor } }
	}
	desc = {
		text = evt_18000_desc_b
		trigger = { FROM = { has_job_title = job_treasurer } }
	}
	desc = {
		text = evt_18000_desc_c
		trigger = { FROM = { has_job_title = job_spiritual } }
	}

	is_triggered_only = yes # help_liege_manage_titles, councillor_decisions.txt

	option = {
		name = evt_18000_option_a # Yes I would appreciate some help.

		set_character_flag = getting_help_with_titles

		FROM = {
			character_event = { id = CK2.18003 } # Start handing out titles
			character_event = { id = CK2.18001 } # Notify
		}
	}

	option = {
		name = evt_18000_option_b # No thanks, I'm fine!

		FROM = {
			character_event = { id = CK2.18002 } # Notify
		}

		ai_chance = { factor = 0 }
	}

	option = {
		name = evt_18000_option_c # Stop bothering me about this nonsense!

		custom_tooltip = { text = evt_18000_option_c_tooltip }

		set_character_flag = refused_any_help_with_titles

		FROM = {
			character_event = { id = CK2.18002 } # Notify
		}

		ai_chance = { factor = 0 }
	}
}

# Councillor receives a positive response from his liege
character_event = {
	id = CK2.18001
	desc = evt_18001_desc
	picture = GFX_evt_council
	border = GFX_event_normal_frame_diplomacy

	is_triggered_only = yes

	ai = no

	option = {
		name = OK
	}
}

# Councillor receives a negative response from his liege
character_event = {
	id = CK2.18002
	desc = evt_18002_desc
	picture = GFX_evt_council
	border = GFX_event_normal_frame_diplomacy

	is_triggered_only = yes

	ai = no

	option = {
		name = OK
	}
}

# Councillor is approved to help liege with titles
character_event = {
	id = CK2.18003

	hide_window = yes
	is_triggered_only = yes

	immediate = {
		character_event = { id = CK2.18004 } # Give away title

		if = {
			limit = {
				liege = {
					has_newly_acquired_titles = yes
					over_max_demesne_size >= 1
				}
			}

			if = {
				limit = { ai = yes }
				repeat_event = {
					id = CK2.18003
					days = 1 # Don't hand it all out instantly
				}
			}
			else = {
				repeat_event = {
					id = CK2.18003
					days = 3 # Don't overwhelm player with events
				}
			}
		}
	}
}

# Councillor gets event to give away title
character_event = {
	id = CK2.18004
	desc = evt_18004_desc
	picture = GFX_evt_council
	border = GFX_event_normal_frame_diplomacy

	is_triggered_only = yes

	option = {
		name = evt_18004_option_a # Give title to the best candidate

		trigger = {
			liege = {
				title_to_get_rid_of = {
					num_fitting_characters_for_title >= 1
				}
			}
		}

		liege = {
			show_scope_change = no

			title_to_get_rid_of = {
				show_scope_change = no

				best_fit_character_for_title = {
					title = PREV			# The Title we are looking at
					perspective = ROOT		# From whose perspective we are viewing the title
					index = 1				# The index of the character in the list

					grant_title = PREV
				}
			}
		}

		ai_chance = { factor = 15 }
	}

	option = {
		name = evt_18004_option_b # Give title to the second best candidate

		trigger = {
			liege = {
				title_to_get_rid_of = {
					num_fitting_characters_for_title >= 1
				}
			}
		}

		liege = {
			show_scope_change = no

			title_to_get_rid_of = {
				show_scope_change = no

				best_fit_character_for_title = {
					title = PREV			# The Title we are looking at
					perspective = ROOT		# From whose perspective we are viewing the title
					index = 2				# The index of the character in the list

					grant_title = PREV
				}
			}
		}

		ai_chance = { factor = 10 }
	}

	option = {
		name = evt_18004_option_c # Give title to the third best candidate

		trigger = {
			NOR = {
				trait = greedy
				trait = ambitious
				trait = envious
				trait = deceitful
				trait = arbitrary
			}

			liege = {
				title_to_get_rid_of = {
					num_fitting_characters_for_title >= 1
				}
			}
		}

		liege = {
			show_scope_change = no

			title_to_get_rid_of = {
				show_scope_change = no

				best_fit_character_for_title = {
					title = PREV			# The Title we are looking at
					perspective = ROOT		# From whose perspective we are viewing the title
					index = 3				# The index of the character in the list

					grant_title = PREV
				}
			}
		}

		ai_chance = { factor = 5 }
	}

	option = {
		name = evt_18004_option_d # Give title to an unknown noble

		trigger = {
			liege = {
				title_to_get_rid_of = {
					num_fitting_characters_for_title < 3
				}
			}
		}

		liege = {
			show_scope_change = no

			create_random_steward = {
				random_traits = yes
				dynasty = random
				female = no
			}

			new_character = {
				show_scope_change = no

				hidden_effect = {
					if = {
						limit = { has_dharmic_religion_trigger = yes }

						add_trait = kshatriya
						character_event = { id = RoI.30121 }
					}
				}

				liege = {
					show_scope_change = no

					title_to_get_rid_of = {
						show_scope_change = no

						grant_title = PREVPREV
					}
				}
			}
		}

		ai_chance = { factor = 5 }
	}

	option = {
		name = evt_18004_option_e # Give title to someone close to you

		trigger = {
			OR = {
				trait = greedy
				trait = ambitious
				trait = envious
				trait = deceitful
				trait = arbitrary
			}
		}

		liege = {
			show_scope_change = no

			title_to_get_rid_of = {
				show_scope_change = no

				grant_title = ROOT
			}
		}

		ai_chance = {
			factor = 1

			mult_modifier = {
				factor = 2
				trait = greedy
			}
			mult_modifier = {
				factor = 2
				trait = ambitious
			}
			mult_modifier = {
				factor = 2
				trait = envious
			}
			mult_modifier = {
				factor = 2
				trait = deceitful
			}
			mult_modifier = {
				factor = 2
				trait = arbitrary
			}
		}
	}
}