﻿namespace = regula_council_event

# 0001-0999 - Maintainence Events
# 1000-1999 - General Events
# 2000-2999 - Harem Manager Task Events
# 3000-3999 - Raid Leader Task Events
# 4000-4999 - High Priestess Task Events
# 5000-5999 - Inquisitor Task Events
# 6000-6999 - Contubernalis Supervisor Task Events

##################
# 0001-0999 Maintainence Events
##################

##################
# 2000-2999 Harem Manager Task Events
#	2000 - task_family_planning Completion
##################

# task_family_planning Completion
# Selects a harem member of the liege and impregnates them.
# root = councillor_harem_manager
# scope:councillor = councillor_harem_manager
# scope:councillor_liege = liege of the councillor_harem_manager
regula_council_event.2000 = {
	hidden = yes
	type = character_event

	trigger = {
		# This should be unnecessary as the task would get canceled.
		# Checking again anyway for sanity.
		scope:councillor_liege = {
			any_consort = {
				is_valid_family_planning_target = yes
			}
		}
	}

	# When finished, select harem member at random (weighted by trait factors) & impregnate by magister.
	immediate = {
		scope:councillor_liege = {
			random_consort = {
				limit = {
					is_valid_family_planning_target = yes
				}

				weight = {
					base = 1
					modifier = { # Strongly prefer devoted group over others.
						factor = 20
						has_trait = devoted_trait_group
					}
					modifier = { # Tropaeum slightly more preferred.
						factor = 1.5
						has_trait = tropaeum
					}
					modifier = { # Paelex more preferred over other devoted.
						factor = 2
						has_trait = paelex
					}
					modifier = { # Domini slightly more preferred over Paelex.
						factor = 2.25
						has_trait = familia_paelex
					}
					modifier = { # Domina more preferred over even Domini.
						factor = 2.5
						has_trait = domina
					}
					modifier = { # Having no alive children gives you a large bonus to be chosen
						factor = 25
						regula_num_children = 0
					}
					modifier = { # Reduce chance based on number of previous children with liege.
						factor = task_family_planning_previous_child_selection_factor
					}
				}

				save_temporary_scope_as = selected_consort
				scope:councillor_liege = {
					send_interface_message = {
						type = event_spouse_good
						title = regula_family_planning_complete_title
						desc = regula_family_planning_complete_desc
						left_icon = scope:councillor
						right_icon = scope:selected_consort

						scope:selected_consort = {
							random_list = {
								75 = {
									make_pregnant = {
										father = scope:councillor_liege
										number_of_children = 1
									}
								}
								20 = {
									make_pregnant = {
										father = scope:councillor_liege
										number_of_children = 2
									}
								}
								5 = {
									make_pregnant = {
										father = scope:councillor_liege
										number_of_children = 3
									}
								}
							}
						}
					}
				}
			}
		}
	}
}

##################
# 3000-3999 Raid Leader Task Events
#	3000 - task_scout_targets Completion
#	3001 - Capture Scouted Targets
#	3100 - task_border_raids Completion
##################

# task_scout_targets Completion
# Selects a skill dependent number of courtiers of the target characters court
# and marks them as investigated for 5 years. If the Magister's army raids the
# marked character's location while they are marked, then they will become the
# Magister's prisoner via `regula_council_event.3001`.
#
# root = councillor_raid_leader
# scope:councillor = councillor_raid_leader
# scope:councillor_liege = liege of the councillor_raid_leader
# scope:province = the capital province of the targeted county
# scope:county = the target county
regula_council_event.3000 = {
	hidden = yes
	type = character_event

	trigger = {
		# This should be unnecessary as the task would get canceled.
		# Checking again anyway for sanity.
		is_valid_scout_targets_county = yes
	}

	immediate = {
		scope:councillor = {
			duel = {
				# In range [0, 100]
				# Base success rate 60%
				# +[0%, 40%] from councillor skill
				# -[0%, 40%] from target skill
				value = task_scout_targets_success_chance
				0 = { # Success
					modifier = {
						add = {
							add = scope:duel_value
						}
					}

					set_while_counter_variable_effect = yes
					while = {
						limit = { var:while_counter < task_scout_targets_num_targets }

						scope:county.holder = {
							random_list = {
								70 = { # Scoutee is scope:county.holder
									trigger = {
										is_valid_scout_targets_scoutee = yes
									}

									regula_scout_target_effect = { MAGISTER = scope:councillor_liege }
								}
								30 = { # Scoutee is scope:county.holder's courtier
									trigger = {
										any_courtier = {
											is_valid_scout_targets_scoutee = yes
										}
									}

									random_courtier = {
										limit = {
											is_valid_scout_targets_scoutee = yes
										}

										weight = {
											base = 1

											# Relation modifiers
											modifier = { # Spouse upweighted.
												factor = 50
												is_spouse_of = scope:county.holder
											}
											modifier = { # Close family upweighted.
												factor = 25
												is_close_family_of = scope:county.holder
											}
											modifier = { # Extended family upweighted.
												factor = 15
												is_extended_family_of = scope:county.holder
											}
											modifier = { # Concubine slightly upweighted.
												factor = 10
												is_concubine_of = scope:county.holder
											}

											# Age modifiers
											modifier = { # Young adult upweighted
												factor = 25
												age <= 25
											}

											modifier = { # Adult slightly upweighted
												factor = 10
												age > 25
												age < 45
											}

											modifier = { # Elder down-weighted
												factor = 0.5
												age >= 45
											}

											# Trait modifiers
											modifier = { # Great Genetic Traits upweighted
												factor = 25
												num_of_good_genetic_traits >= 3
											}

											modifier = { # Great Genetic Traits upweighted
												factor = 15
												num_of_good_genetic_traits = 2
											}

											modifier = { # Great Genetic Traits upweighted
												factor = 10
												num_of_good_genetic_traits = 1
											}

											modifier = { # Bad Genetic Traits downweighted
												factor = 0.5
												num_of_bad_genetic_traits >= 1
											}
										}

										regula_scout_target_effect = { MAGISTER = scope:councillor_liege }
									}
								}
							}
						}
						increase_while_counter_variable_effect = yes
					}
					remove_while_counter_variable_effect = yes
				}
				100 = { # Failure
					modifier = {
						add = {
							subtract = scope:duel_value
						}
					}

					scope:councillor_liege = {
						send_interface_message = {
							type = event_intrigue_bad
							title = regula_scouted_target_failure_title
							left_icon = scope:councillor
							right_icon = scope:county.holder

							scope:county.holder = {
								add_character_modifier = {
									modifier = on_edge_modifier
									years = 5
								}

								add_opinion = {
									modifier = distrustful
									years = 5
									target = scope:councillor_liege
								}
							}
						}
					}
				}
			}
		}
	}
}

# Capture Scouted Targets
# When the Magister's army loots (raid or siege) a location, automatically
# capture any individual at that location for whom the magister knows their
# `regula_scouted_target_secret`.
#
# Note: Called from two different on_action contexts w/ different root scope
# types. As such - root should not be used, and instead all triggers and
# effects should be used in the context of one of the below scopes.
#
# scope:raider is the person owning the raid army
# scope:barony is the barony title that got raided
# scope:county is the county title for the barony
regula_council_event.3001 = {
	hidden = yes
	scope = none # Root unused & ignored.

	trigger = {
		scope:raider = {
			is_ai = no
			has_trait = magister_trait_group
		}
	}

	immediate = {
		scope:raider = {
			every_known_secret = {
				limit = {
					secret_type = regula_scouted_target_secret
					secret_owner = {
						is_at_location = scope:barony.title_province
					}
				}

				secret_owner = { save_scope_as = raid_prisoner }

				scope:raider = {
					send_interface_message = {
						type = event_captured_combatants_good
						title = regula_scouted_target_captured_title
						desc = regula_scouted_target_captured_desc
						right_icon = scope:raid_prisoner

						prisoner_of_war_capture_effect = {
							TARGET = scope:raid_prisoner
							IMPRISONER = scope:raider
						}

						scope:raid_prisoner = {
							add_opinion = {
								modifier = imprisoned_me
								target = scope:raider
							}

							remove_character_modifier = regula_scouted_target_modifier
						}
					}
				}
			}
		}
	}
}

# task_border_raids Completion
# Completion events for the border raids raid leader council task.
# On completion, the councillor_liege gains a small amount of money, a captive
# with high chance, and may anger the liege of the raided land with low chance.
#
# root = councillor_raid_leader
# scope:councillor = councillor_raid_leader
# scope:councillor_liege = liege of the councillor_raid_leader
regula_council_event.3100 = {
	hidden = yes
	type = character_event

	trigger = {
		# This should be unnecessary as the task would get canceled.
		# Checking again anyway for sanity.
		any_valid_border_raids_county = yes
	}

	immediate = {
		regula_border_raids_effect = yes
	}
}

##################
# 4000-4999 High Priestess Task Events
#	4000 - task_generous_welcome - Lavish Feast - Choice
#	4001 - task_generous_welcome - Lavish Feast - Accepted
#	4005 - task_generous_welcome - Academic Seminar - Choice
#	4006 - task_generous_welcome - Academic Seminar - Accepted
#	4010 - task_generous_welcome - Sparring Exhibition - Choice
#	4011 - task_generous_welcome - Sparring Exhibition - Accepted
#	4015 - task_generous_welcome - Charitable Outing - Choice
#	4016 - task_generous_welcome - Charitable Outing - Accepted
#	4020 - task_generous_welcome - Lustful Indulgence - Choice
#	4021 - task_generous_welcome - Lustful Indulgence - Accepted
#	4200 - task_dispatch_missionaries - Completion
#	4250 - task_dispatch_missionaries - Monthly Opinion Change
##################

# task_generous_welcome - Lavish Feast - Choice
# Presents the liege with the option to throw welcome celebrations
# for a small amount of money.
#
# scope:councillor = councillor_high_priestess
# scope:councillor_liege = liege of the councillor_high_priestess
# scope:generous_welcome_location = the province in which the event is held (created by event)
regula_council_event.4000 = {
	type = character_event
	title = regula_council_event.4000.t
	desc = regula_council_event.4000.desc

	theme = regula_council_theme

	left_portrait = {
		character = scope:councillor
		animation = throne_room_conversation_2
	}

	right_portrait = {
		character = scope:councillor_liege
		animation = throne_room_conversation_4
	}

	trigger = {
		scope:councillor_liege = {
			gold >= minor_gold_value
		}
	}

	immediate = {
		scope:councillor_liege = {
			regula_generous_welcome_pick_default_welcome_site_effect = {
				SAVE_AS = generous_welcome_location
			}
		}
	}

	option = { # Host Celebration
		name = regula_council_event.4000.a

		scope:councillor_liege = {
			remove_short_term_gold = minor_gold_value

			stress_impact = {
				ambitious = minor_stress_impact_loss
				gluttonous = major_stress_impact_loss
				gregarious = major_stress_impact_loss
				shy = medium_stress_impact_gain
			}
		}

		scope:generous_welcome_location = {
			county = {
				add_county_modifier = {
					modifier = regula_generous_welcome_modifier
					years = 10
				}
			}
		}

		trigger_event = regula_council_event.4001 # task_generous_welcome - Lavish Feast - Accepted
	}

	option = { # Not Worth My Time
		name = regula_council_event.4000.z

		scope:councillor_liege = {
			stress_impact = {
				ambitious = minor_stress_impact_gain
				gluttonous = medium_stress_impact_gain
				gregarious = medium_stress_impact_gain
				shy = minor_stress_impact_loss
			}
		}
	}
}

# task_generous_welcome - Lavish Feast - Accepted
# Liege hosts a celebratory welcome feast, with different options to
# influence the outcome.
#
# scope:councillor = councillor_high_priestess
# scope:councillor_liege = liege of the councillor_high_priestess
# scope:generous_welcome_location = the province in which the event is held
# scope:attendee_of_interest = a character of interest at the event (created by event)
regula_council_event.4001 = {
	type = character_event
	title = regula_council_event.4001.t
	desc = regula_council_event.4001.desc

	theme = host_dinner
	override_icon = {
		reference = "gfx/interface/icons/event_types/regula_frame.dds"
	}

	left_portrait = {
		character = scope:councillor_liege
		animation = toast_goblet
	}

	right_portrait = {
		character = scope:attendee_of_interest
		animation = flirtation_left
	}

	immediate = {
		regula_generous_welcome_create_character_effect = {
			TEMPLATE = regula_generous_welcome_lavish_feast_attendee
			LOCATION = scope:generous_welcome_location
			SAVE_AS = attendee_of_interest
		}
	}

	option = { # Toast infused with power.
		name = regula_council_event.4001.a
		flavor = regula_council_event.4001.a.tt

		trigger = {
			piety >= medium_piety_value
		}

		show_as_unavailable = {
			always = yes
		}

		scope:councillor_liege = {
			add_piety = medium_piety_loss
			add_prestige = medium_prestige_gain

			stress_impact = {
				ambitious = minor_stress_impact_loss
				gregarious = minor_stress_impact_loss
				shy = minor_stress_impact_gain
			}
		}

		scope:generous_welcome_location = {
			county = {
				change_county_control = medium_county_control_gain
			}
		}

		hidden_effect = { # Clean up unused character.
			scope:attendee_of_interest = {
				death = { death_reason = death_disappearance }
			}
		}
	}

	option = { # Chat up the local beauty.
		name = regula_council_event.4001.b
		flavor = regula_council_event.4001.b.tt

		trigger = {
			piety >= minor_piety_value
		}

		show_as_unavailable = {
			always = yes
		}

		scope:councillor_liege = {
			add_piety = minor_piety_loss
		}

		regula_generous_welcome_charm_attendee_effect = {
			ACTOR = scope:councillor_liege
			TARGET = scope:attendee_of_interest
		}
	}

	option = { # Regular toast.
		name = regula_council_event.4001.z
		flavor = regula_council_event.4001.z.tt

		scope:councillor_liege = {
			add_prestige = minor_prestige_gain

			stress_impact = {
				ambitious = minor_stress_impact_gain
				gregarious = minor_stress_impact_loss
				shy = minor_stress_impact_gain
			}
		}

		hidden_effect = { # Clean up unused character.
			scope:attendee_of_interest = {
				death = { death_reason = death_disappearance }
			}
		}
	}
}

# task_generous_welcome - Academic Seminar - Choice
# Presents the liege with the option to hold scientific discussions
# with new inductees.
#
# scope:councillor = councillor_high_priestess
# scope:councillor_liege = liege of the councillor_high_priestess
# scope:generous_welcome_location = the province in which the event is held (created by event)
regula_council_event.4005 = {
	type = character_event
	title = regula_council_event.4005.t
	desc = regula_council_event.4005.desc

	theme = regula_council_theme

	left_portrait = {
		character = scope:councillor
		animation = throne_room_conversation_2
	}

	right_portrait = {
		character = scope:councillor_liege
		animation = throne_room_conversation_4
	}

	trigger = {
		scope:councillor_liege = {
			prestige >= minor_prestige_value
		}
	}

	immediate = {
		scope:councillor_liege = {
			regula_generous_welcome_pick_default_welcome_site_effect = {
				SAVE_AS = generous_welcome_location
			}
		}
	}

	option = { # Host Celebration
		name = regula_council_event.4005.a

		scope:councillor_liege = {
			add_prestige = minor_prestige_loss

			stress_impact = {
				ambitious = minor_stress_impact_loss
				diligent = medium_stress_impact_loss
				lazy = major_stress_impact_gain
				shy = medium_stress_impact_gain
			}
		}

		scope:generous_welcome_location = {
			county = {
				add_county_modifier = {
					modifier = regula_generous_welcome_modifier
					years = 10
				}
			}
		}

		trigger_event = regula_council_event.4006 # task_generous_welcome - Academic Seminar - Accepted
	}

	option = { # Not Worth My Time
		name = regula_council_event.4005.z

		scope:councillor_liege = {
			stress_impact = {
				ambitious = minor_stress_impact_gain
				diligent = medium_stress_impact_gain
				lazy = minor_stress_impact_loss
				shy = minor_stress_impact_loss
			}
		}
	}
}

# task_generous_welcome - Academic Seminar - Accepted
# Liege hosts an academic seminar, with different options to influence the outcome.
#
# scope:councillor = councillor_high_priestess
# scope:councillor_liege = liege of the councillor_high_priestess
# scope:generous_welcome_location = the province in which the event is held
# scope:attendee_of_interest = a character of interest at the event (created by event)
regula_council_event.4006 = {
	type = character_event
	title = regula_council_event.4006.t
	desc = regula_council_event.4006.desc

	theme = learning
	override_icon = {
		reference = "gfx/interface/icons/event_types/regula_frame.dds"
	}

	left_portrait = {
		character = scope:councillor_liege
		animation = throne_room_conversation_4
	}

	right_portrait = {
		character = scope:attendee_of_interest
		animation = personality_rational
	}

	immediate = {
		regula_generous_welcome_create_character_effect = {
			TEMPLATE = regula_generous_welcome_academic_seminar_attendee
			LOCATION = scope:generous_welcome_location
			SAVE_AS = attendee_of_interest
		}
	}

	option = { # Influence their plans.
		name = regula_council_event.4006.a
		flavor = regula_council_event.4006.a.tt

		trigger = {
			piety >= medium_piety_value
		}

		show_as_unavailable = {
			always = yes
		}

		scope:councillor_liege = {
			add_piety = medium_piety_loss
			regula_generous_welcome_add_lifestyle_xp_effect = {
				AMOUNT = major_lifestyle_xp
			}

			stress_impact = {
				ambitious = minor_stress_impact_loss
				diligent = minor_stress_impact_loss
				lazy = minor_stress_impact_gain
				shy = minor_stress_impact_gain
			}
		}

		# Development increase.
		scope:generous_welcome_location = {
			county = {
				change_development_progress_with_overflow = medium_development_progress_gain
			}
		}

		hidden_effect = { # Clean up unused character.
			scope:attendee_of_interest = {
				death = { death_reason = death_disappearance }
			}
		}
	}

	option = { # Practical anatomy session.
		name = regula_council_event.4006.b
		flavor = regula_council_event.4006.b.tt

		trigger = {
			piety >= minor_piety_value
		}

		show_as_unavailable = {
			always = yes
		}

		scope:councillor_liege = {
			add_piety = minor_piety_loss
		}

		regula_generous_welcome_charm_attendee_effect = {
			ACTOR = scope:councillor_liege
			TARGET = scope:attendee_of_interest
		}
	}

	option = { # Regular discussion.
		name = regula_council_event.4006.z
		flavor = regula_council_event.4006.z.tt

		scope:councillor_liege = {
			regula_generous_welcome_add_lifestyle_xp_effect = {
				AMOUNT = medium_lifestyle_xp
			}

			stress_impact = {
				ambitious = minor_stress_impact_gain
				diligent = minor_stress_impact_loss
				shy = minor_stress_impact_gain
			}
		}

		hidden_effect = { # Clean up unused character.
			scope:attendee_of_interest = {
				death = { death_reason = death_disappearance }
			}
		}
	}
}

# task_generous_welcome - Sparring Exhibition - Choice
# Presents the liege with the option to hold a sparing exhibition with new inductees.
#
# scope:councillor = councillor_high_priestess
# scope:councillor_liege = liege of the councillor_high_priestess
# scope:generous_welcome_location = the province in which the event is held (created by event)
# scope:sparring_knight = a knight who will accompany you to the exhibition (created by event)
regula_council_event.4010 = {
	type = character_event
	title = regula_council_event.4010.t
	desc = regula_council_event.4010.desc

	theme = regula_council_theme

	left_portrait = {
		character = scope:councillor
		animation = throne_room_conversation_2
	}

	right_portrait = {
		character = scope:councillor_liege
		animation = throne_room_conversation_4
	}

	lower_left_portrait = {
		character = scope:sparring_knight
	}

	trigger = {
		scope:councillor_liege = {
			prestige >= minor_prestige_value
			number_of_knights > 0
		}
	}

	immediate = {
		scope:councillor_liege = {
			regula_generous_welcome_pick_default_welcome_site_effect = {
				SAVE_AS = generous_welcome_location
			}

			random_knight = {
				weight = {
					base = 1

					modifier = {
						factor = {
							value = prowess
						}
						prowess > 10
					}

					modifier = {
						factor = 2
						is_acclaimed = yes
					}
				}

				save_scope_as = sparring_knight
			}
		}
	}

	option = { # Host Celebration
		name = regula_council_event.4010.a

		scope:councillor_liege = {
			add_prestige = minor_prestige_loss

			stress_impact = {
				ambitious = minor_stress_impact_loss
				brave = medium_stress_impact_loss
				craven = medium_stress_impact_gain
				shy = medium_stress_impact_gain
			}
		}

		scope:generous_welcome_location = {
			county = {
				add_county_modifier = {
					modifier = regula_generous_welcome_modifier
					years = 10
				}
			}
		}

		trigger_event = regula_council_event.4011 # task_generous_welcome - Sparring Exhibition - Accepted
	}

	option = { # Not Worth My Time
		name = regula_council_event.4010.z

		scope:councillor_liege = {
			stress_impact = {
				ambitious = minor_stress_impact_gain
				brave = minor_stress_impact_gain
				craven = minor_stress_impact_loss
				shy = minor_stress_impact_loss
			}
		}
	}
}

# task_generous_welcome - Sparring Exhibition - Accepted
# Liege hosts a sparring exhibition, with different options to influence the outcome.
#
# scope:councillor = councillor_high_priestess
# scope:councillor_liege = liege of the councillor_high_priestess
# scope:generous_welcome_location = the province in which the event is held
# scope:sparring_knight = a knight who will accompany you to the exhibition
# scope:attendee_of_interest = a character of interest at the event (created by event)
regula_council_event.4011 = {
	type = character_event
	title = regula_council_event.4011.t
	desc = regula_council_event.4011.desc

	theme = martial
	override_icon = {
		reference = "gfx/interface/icons/event_types/regula_frame.dds"
	}

	left_portrait = {
		character = scope:councillor_liege
		animation = marshal
	}

	right_portrait = {
		character = scope:attendee_of_interest
		animation = worry
	}

	lower_left_portrait = {
		character = scope:sparring_knight
	}

	immediate = {
		regula_generous_welcome_create_character_effect = {
			TEMPLATE = regula_generous_welcome_sparring_exhibition_attendee
			LOCATION = scope:generous_welcome_location
			SAVE_AS = attendee_of_interest
		}
	}

	option = { # Show them who's in charge.
		name = regula_council_event.4011.a
		flavor = regula_council_event.4011.a.tt

		trigger = {
			piety >= medium_piety_value
		}

		show_as_unavailable = {
			always = yes
		}

		scope:councillor_liege = {
			add_piety = medium_piety_loss
			add_dread = medium_dread_gain
			regula_generous_welcome_sparring_modifier_effect = yes

			stress_impact = {
				ambitious = minor_stress_impact_loss
				calm = medium_stress_impact_gain
				compassionate = medium_stress_impact_gain
				sadistic = medium_stress_impact_loss
				wrathful = medium_stress_impact_loss
			}
		}

		scope:generous_welcome_location = {
			county = {
				change_county_control = medium_county_control_gain
			}
		}

		hidden_effect = { # Clean up unused character.
			scope:attendee_of_interest = {
				death = { death_reason = death_disappearance }
			}
		}
	}

	option = { # One-on-One Training
		name = regula_council_event.4011.b
		flavor = regula_council_event.4011.b.tt

		trigger = {
			piety >= minor_piety_value
		}

		show_as_unavailable = {
			always = yes
		}

		scope:councillor_liege = {
			add_piety = minor_piety_loss
		}

		regula_generous_welcome_charm_attendee_effect = {
			ACTOR = scope:councillor_liege
			TARGET = scope:attendee_of_interest
		}
	}

	option = { # End things on a high note.
		name = regula_council_event.4011.z
		flavor = regula_council_event.4011.z.tt

		scope:councillor_liege = {
			regula_generous_welcome_sparring_modifier_effect = yes

			stress_impact = {
				ambitious = minor_stress_impact_gain
				calm = minor_stress_impact_loss
				compassionate = minor_stress_impact_loss
				sadistic = minor_stress_impact_gain
				wrathful = minor_stress_impact_gain
			}
		}

		scope:sparring_knight = {
			stress_impact = {
				base = minor_stress_impact_loss
			}
		}

		scope:generous_welcome_location = {
			county = {
				change_county_control = minor_county_control_gain
			}
		}

		hidden_effect = { # Clean up unused character.
			scope:attendee_of_interest = {
				death = { death_reason = death_disappearance }
			}
		}
	}
}

# task_generous_welcome - Charitable Outing - Choice
# Presents the liege with the option to go on a charitable outing,
# donating to those in need.
#
# scope:councillor = councillor_high_priestess
# scope:councillor_liege = liege of the councillor_high_priestess
# scope:generous_welcome_location = the province in which the event is held (created by event)
regula_council_event.4015 = {
	type = character_event
	title = regula_council_event.4015.t
	desc = regula_council_event.4015.desc

	theme = regula_council_theme

	left_portrait = {
		character = scope:councillor
		animation = throne_room_conversation_2
	}

	right_portrait = {
		character = scope:councillor_liege
		animation = throne_room_conversation_4
	}

	trigger = {
		scope:councillor_liege = {
			gold >= minor_gold_value
		}
	}

	immediate = {
		scope:councillor_liege = {
			regula_generous_welcome_pick_default_welcome_site_effect = {
				SAVE_AS = generous_welcome_location
			}
		}
	}

	option = { # Host Event
		name = regula_council_event.4015.a

		scope:councillor_liege = {
			remove_short_term_gold = minor_gold_value

			stress_impact = {
				ambitious = minor_stress_impact_loss
				compassionate = medium_stress_impact_loss
				generous = medium_stress_impact_loss
				greedy = major_stress_impact_gain
				shy = medium_stress_impact_gain
			}
		}

		scope:generous_welcome_location = {
			county = {
				add_county_modifier = {
					modifier = regula_generous_welcome_modifier
					years = 10
				}
			}
		}

		trigger_event = regula_council_event.4016 # task_generous_welcome - Charitable Outing - Accepted
	}

	option = { # Not Worth My Time
		name = regula_council_event.4015.z

		scope:councillor_liege = {
			stress_impact = {
				ambitious = minor_stress_impact_gain
				compassionate = minor_stress_impact_gain
				generous = medium_stress_impact_gain
				greedy = minor_stress_impact_loss
				shy = minor_stress_impact_loss
			}
		}
	}
}

# task_generous_welcome - Charitable Outing - Accepted
# Liege hosts an academic seminar, with different options to influence the outcome.
#
# scope:councillor = councillor_high_priestess
# scope:councillor_liege = liege of the councillor_high_priestess
# scope:generous_welcome_location = the province in which the event is held
# scope:attendee_of_interest = a character of interest at the event (created by event)
regula_council_event.4016 = {
	type = character_event
	title = regula_council_event.4016.t
	desc = regula_council_event.4016.desc

	theme = friendly
	override_icon = {
		reference = "gfx/interface/icons/event_types/regula_frame.dds"
	}

	left_portrait = {
		character = scope:councillor_liege
		animation = personality_compassionate
	}

	right_portrait = {
		character = scope:attendee_of_interest
		animation = scheme
	}

	immediate = {
		regula_generous_welcome_create_character_effect = {
			TEMPLATE = regula_generous_welcome_charitable_outing_attendee
			LOCATION = scope:generous_welcome_location
			SAVE_AS = attendee_of_interest
		}
	}

	option = { # Inspire devotion.
		name = regula_council_event.4016.a
		flavor = regula_council_event.4016.a.tt

		trigger = {
			piety >= medium_piety_value
		}

		show_as_unavailable = {
			always = yes
		}

		scope:councillor_liege = {
			add_piety = medium_piety_loss
			add_tyranny = medium_tyranny_loss

			stress_impact = {
				ambitious = minor_stress_impact_loss
				greedy = minor_stress_impact_loss
				shy = minor_stress_impact_gain
			}
		}

		scope:generous_welcome_location = {
			county = {
				add_county_modifier = {
					modifier = alms_distributed
					years = 10
				}
				add_county_modifier = {
					modifier = regula_generous_welcome_inspired_populace_modifier
					years = 10
				}
			}
		}

		hidden_effect = { # Clean up unused character.
			scope:attendee_of_interest = {
				death = { death_reason = death_disappearance }
			}
		}
	}

	option = { # Recruit the beggar
		name = regula_council_event.4016.b
		flavor = regula_council_event.4016.b.tt

		trigger = {
			piety >= minor_piety_value
		}

		show_as_unavailable = {
			always = yes
		}

		scope:councillor_liege = {
			add_piety = minor_piety_loss
		}

		regula_generous_welcome_charm_attendee_effect = {
			ACTOR = scope:councillor_liege
			TARGET = scope:attendee_of_interest
		}
	}

	option = { # Regular charity.
		name = regula_council_event.4016.z
		flavor = regula_council_event.4016.z.tt

		scope:councillor_liege = {
			add_tyranny = medium_tyranny_loss

			stress_impact = {
				ambitious = minor_stress_impact_gain
				compassionate = minor_stress_impact_loss
				generous = medium_stress_impact_loss
				shy = minor_stress_impact_gain
			}
		}

		scope:generous_welcome_location = {
			county = {
				add_county_modifier = {
					modifier = alms_distributed
					years = 5
				}
			}
		}

		hidden_effect = { # Clean up unused character.
			scope:attendee_of_interest = {
				death = { death_reason = death_disappearance }
			}
		}
	}
}

# task_generous_welcome - Lustful Indulgence - Choice
# Presents the liege with the option to indulge in some lustful activities.
#
# scope:councillor = councillor_high_priestess
# scope:councillor_liege = liege of the councillor_high_priestess
# scope:generous_welcome_location = the province in which the event is held (created by event)
regula_council_event.4020 = {
	type = character_event
	title = regula_council_event.4020.t
	desc = regula_council_event.4020.desc

	theme = regula_council_theme

	left_portrait = {
		character = scope:councillor
		animation = throne_room_conversation_2
	}

	right_portrait = {
		character = scope:councillor_liege
		animation = throne_room_conversation_4
	}

	trigger = {
		scope:councillor_liege = {
			piety >= medium_piety_value
		}
	}

	immediate = {
		scope:councillor_liege = {
			regula_generous_welcome_pick_default_welcome_site_effect = {
				SAVE_AS = generous_welcome_location
			}
		}
	}

	option = { # Host Event
		name = regula_council_event.4020.a

		scope:councillor_liege = {
			add_piety = medium_piety_loss

			stress_impact = {
				base = medium_stress_impact_loss
				ambitious = minor_stress_impact_loss
				lustful = medium_stress_impact_loss
				shy = medium_stress_impact_gain
			}
		}

		scope:generous_welcome_location = {
			county = {
				add_county_modifier = {
					modifier = regula_generous_welcome_modifier
					years = 10
				}
			}
		}

		# Characters created early to allow for using them in immediate of event.
		regula_generous_welcome_create_character_effect = {
			TEMPLATE = regula_generous_welcome_lustful_indulgence_beauty_attendee
			LOCATION = scope:generous_welcome_location
			SAVE_AS = attendee_of_interest_beauty
		}
		regula_generous_welcome_create_character_effect = {
			TEMPLATE = regula_generous_welcome_lustful_indulgence_strong_attendee
			LOCATION = scope:generous_welcome_location
			SAVE_AS = attendee_of_interest_strong
		}
		regula_generous_welcome_create_character_effect = {
			TEMPLATE = regula_generous_welcome_lustful_indulgence_smart_attendee
			LOCATION = scope:generous_welcome_location
			SAVE_AS = attendee_of_interest_smart
		}

		trigger_event = regula_council_event.4021 # task_generous_welcome - Lustful Indulgence - Accepted
	}

	option = { # Not Worth My Time
		name = regula_council_event.4020.z

		scope:councillor_liege = {
			stress_impact = {
				ambitious = minor_stress_impact_gain
				lustful = medium_stress_impact_gain
				shy = minor_stress_impact_loss
			}
		}
	}
}

# task_generous_welcome - Lustful Indulgence - Accepted
# Liege indulges in a an afternoon of lustful activities with the councillor
# and some local women.
#
# scope:councillor = councillor_high_priestess
# scope:councillor_liege = liege of the councillor_high_priestess
# scope:generous_welcome_location = the province in which the event is held
# scope:attendee_of_interest_beauty = a character of interest at the event
# scope:attendee_of_interest_strong = a character of interest at the event
# scope:attendee_of_interest_smart = a character of interest at the event
regula_council_event.4021 = {
	type = character_event
	title = regula_council_event.4021.t
	desc = regula_council_event.4021.desc

	theme = seduction
	override_icon = {
		reference = "gfx/interface/icons/event_types/regula_frame.dds"
	}

	left_portrait = {
		character = scope:councillor_liege
		animation = throne_room_conversation_4
	}

	right_portrait = {
		character = scope:attendee_of_interest_beauty
		animation = ecstasy
	}

	lower_left_portrait = {
		character = scope:councillor
	}

	lower_center_portrait = {
		character = scope:attendee_of_interest_strong
	}

	lower_right_portrait = {
		character = scope:attendee_of_interest_smart
	}

	immediate = {
		scope:councillor_liege = {
			carn_undress_character_effect = yes
		}

		scope:councillor = {
			carn_undress_character_effect = yes
		}

		scope:councillor_liege = {
			regula_sex_with_target_no_stress = { TARGET = scope:councillor }
		}

		scope:attendee_of_interest_beauty = {
			carn_undress_character_effect = yes
		}
		scope:councillor_liege = {
			regula_sex_with_target_no_stress = { TARGET = scope:attendee_of_interest_beauty }
		}

		scope:attendee_of_interest_strong = {
			carn_undress_character_effect = yes
		}
		scope:councillor_liege = {
			regula_sex_with_target_no_stress = { TARGET = scope:attendee_of_interest_strong }
		}

		scope:attendee_of_interest_smart = {
			carn_undress_character_effect = yes
		}
		scope:councillor_liege = {
			regula_sex_with_target_no_stress = { TARGET = scope:attendee_of_interest_smart }
		}
	}

	option = { # Recruit beauty
		name = regula_council_event.4021.a
		flavor = regula_council_event.4021.a.tt

		trigger = {
			piety >= minor_piety_value
		}

		show_as_unavailable = {
			always = yes
		}

		scope:councillor_liege = {
			add_piety = minor_piety_loss
		}

		regula_generous_welcome_charm_attendee_effect = {
			ACTOR = scope:councillor_liege
			TARGET = scope:attendee_of_interest_beauty
		}

		scope:attendee_of_interest_beauty = {
			carn_dress_character_effect = yes
		}

		hidden_effect = { # Clean up unused character.
			scope:attendee_of_interest_strong = {
				death = { death_reason = death_disappearance }
			}
			scope:attendee_of_interest_smart = {
				death = { death_reason = death_disappearance }
			}
		}
	}

	option = { # Recruit strong
		name = regula_council_event.4021.b
		flavor = regula_council_event.4021.b.tt

		trigger = {
			piety >= minor_piety_value
		}

		show_as_unavailable = {
			always = yes
		}

		scope:councillor_liege = {
			add_piety = minor_piety_loss
		}

		regula_generous_welcome_charm_attendee_effect = {
			ACTOR = scope:councillor_liege
			TARGET = scope:attendee_of_interest_strong
		}

		scope:attendee_of_interest_strong = {
			carn_dress_character_effect = yes
		}

		hidden_effect = { # Clean up unused character.
			scope:attendee_of_interest_beauty = {
				death = { death_reason = death_disappearance }
			}
			scope:attendee_of_interest_smart = {
				death = { death_reason = death_disappearance }
			}
		}
	}

	option = { # Recruit smart
		name = regula_council_event.4021.c
		flavor = regula_council_event.4021.c.tt

		trigger = {
			piety >= minor_piety_value
		}

		show_as_unavailable = {
			always = yes
		}

		scope:councillor_liege = {
			add_piety = minor_piety_loss
		}

		regula_generous_welcome_charm_attendee_effect = {
			ACTOR = scope:councillor_liege
			TARGET = scope:attendee_of_interest_smart
		}

		scope:attendee_of_interest_smart = {
			carn_dress_character_effect = yes
		}

		hidden_effect = { # Clean up unused character.
			scope:attendee_of_interest_beauty = {
				death = { death_reason = death_disappearance }
			}
			scope:attendee_of_interest_strong = {
				death = { death_reason = death_disappearance }
			}
		}
	}

	option = { # No recruit
		name = regula_council_event.4021.z
		flavor = regula_council_event.4021.z.tt

		scope:councillor_liege = {
			faith = {
				change_fervor = {
					value = miniscule_fervor_gain
					desc = regula_council_event.4021.fervor_change
				}
			}

			stress_impact = {
				lustful = medium_stress_impact_loss
			}
			scope:councillor_liege = {
				regula_sex_with_target_no_stress = { TARGET = scope:councillor }
				regula_sex_with_target_no_stress = { TARGET = scope:attendee_of_interest_beauty }
				regula_sex_with_target_no_stress = { TARGET = scope:attendee_of_interest_strong }
				regula_sex_with_target_no_stress = { TARGET = scope:attendee_of_interest_smart }
			}
		}

		scope:generous_welcome_location = {
			if = {
				limit = {
					NOT = { faith = scope:councillor_liege.faith }
				}
				faith = {
					change_fervor = {
						value = miniscule_fervor_loss
						desc = regula_council_event.4021.fervor_change
					}
				}
			}
		}

		hidden_effect = { # Clean up unused character.
			scope:attendee_of_interest_beauty = {
				death = { death_reason = death_disappearance }
			}
			scope:attendee_of_interest_strong = {
				death = { death_reason = death_disappearance }
			}
			scope:attendee_of_interest_smart = {
				death = { death_reason = death_disappearance }
			}
		}
	}

	after = {
		scope:councillor_liege = {
			carn_dress_character_effect = yes
		}
		scope:councillor = {
			carn_dress_character_effect = yes
		}
	}
}

# task_dispatch_missionaries - Completion
# Converts the county target of task_dispatch_missionaries and potentially
# applies more effects.
#
# scope:councillor = councillor_high_priestess
# scope:councillor_liege = liege of the councillor_high_priestess
# scope:province = the capital province of the targeted county
# scope:county = the target county
regula_council_event.4200 = {
	hidden = yes
	type = character_event

	trigger = {
		# This should be unnecessary as the task would get canceled.
		# Checking again anyway for sanity.
		is_valid_dispatch_missionaries_county = yes
	}

	immediate = {
		scope:councillor_liege = {
			# Add negative opinion modifier to any minority vassels.
			if = {
				limit = {
					any_vassal = {
						has_vassal_stance = minority
					}
				}
				custom_tooltip = minority_disapproves_conversion
				hidden_effect = {
					every_vassal = {
						limit = {
							has_vassal_stance = minority
						}
						add_opinion = {
							target = scope:councillor_liege
							modifier = minority_disapproves_of_conversion_opinion
						}
					}
				}
			}

			# Actually convert the county.
			send_interface_message = {
				type = event_learning_good_with_text
				title = regula_dispatch_missionaries_complete_title
				desc = regula_dispatch_missionaries_complete_desc
				right_icon = scope:councillor

				scope:county = {
					set_county_faith = scope:councillor.faith
				}
			}
		}
	}
}

# task_dispatch_missionaries - Monthly Opinion Change
# Calculates any opinion modifiers which need to be applied
# to the target county given it's current level of control.
#
# scope:councillor = councillor_high_priestess
# scope:councillor_liege = liege of the councillor_high_priestess
# scope:province = the capital province of the targeted county
# scope:county = the target county
regula_council_event.4250 = {
	hidden = yes
	type = character_event

	trigger = {
		exists = scope:county.holder
	}

	immediate = {
		scope:county = {
			random = {
				chance = {
					value = 5
					multiply = task_dispatch_missionaries_holy_site_factor
				}
				if = {
					limit = {
						NOT = { holder.faith = scope:councillor_liege.faith }
					}

					add_county_modifier = {
						modifier = regula_dispatch_missionaries_liege_religion_disapproval_modifier
						years = 5
					}
					if = {
						limit = {
							county_control < 25
						}
						add_county_modifier = {
							modifier = regula_dispatch_missionaries_liege_religion_disapproval_modifier
							years = 5
						}
					}
				}
				else = {
					add_county_modifier = {
						modifier = regula_dispatch_missionaries_liege_religion_approval_modifier
						years = 5
					}
				}
			}
		}
	}
}

##################
# 5000-5999 Inquisitor Task Events
#	5000 - Heresy Discovered
#	5005 - Heresy Public Opposition
#	5010 - Heresy Ended - Magister Victory
#	5015 - Heresy Ended - White Peace
#	5020 - Heresy Ended - Heretic Victory
#	5100 - task_impromptu_inspections - Identify Heretics
#	5105 - task_impromptu_inspections - Suppress County
#	5200 - task_apprehend_heretics - Completion
##################

# Heresy Discovered
# A heresy conspiracy has been discovered in the Magister's realm.
# The inquisitor comes to inform the magister of this & their options.
#
# scope:councillor = councillor_inquisitor
# scope:councillor_liege = liege of the councillor_inquisitor
# scope:regula_heresy_story = the heresy story discovered
regula_council_event.5000 = {
	type = character_event
	title = regula_council_event.5000.t
	desc = regula_council_event.5000.desc

	theme = regula_council_theme

	left_portrait = {
		character = scope:councillor
		animation = throne_room_conversation_2
	}

	right_portrait = {
		character = scope:councillor_liege
		animation = throne_room_conversation_4
	}

	immediate = {
		scope:councillor = {
			stress_impact = {
				base = minor_stress_impact_gain
				lazy = minor_stress_impact_gain
				paranoid = medium_stress_impact_gain
				zealous = medium_stress_impact_gain
			}
		}
		scope:councillor_liege = {
			stress_impact = {
				base = minor_stress_impact_gain
				craven = minor_stress_impact_gain
				paranoid = medium_stress_impact_gain
			}
		}
	}

	option = {
		name = regula_council_event.5000.a
		flavor = regula_council_event.5000.a.tt
	}
}

# Heresy Public Opposition
# A heresy conspiracy has started to openly oppose the magister.
#
# scope:councillor = councillor_inquisitor
# scope:councillor_liege = liege of the councillor_inquisitor
# scope:regula_heresy_faction = the heresy faction
regula_council_event.5005 = {
	type = character_event
	title = regula_council_event.5005.t
	desc = regula_council_event.5005.desc

	theme = regula_council_theme

	left_portrait = {
		character = scope:councillor
		animation = throne_room_conversation_2
	}

	right_portrait = {
		character = scope:councillor_liege
		animation = throne_room_conversation_4
	}

	immediate = {
		scope:councillor = {
			stress_impact = {
				base = medium_stress_impact_gain
				lazy = minor_stress_impact_gain
				zealous = medium_stress_impact_gain
			}
		}
		scope:councillor_liege = {
			stress_impact = {
				base = medium_stress_impact_gain
				craven = medium_stress_impact_gain
			}
		}
	}

	option = {
		name = regula_council_event.5005.a
		flavor = regula_council_event.5005.a.tt
	}
}

# Heresy Ended - Magister Victory
# The heresy conspiracy has ended, and the inquisitor informs the magister of
# the outcome.
#
# Note: scope:councillor.var:final_heresy_state is used as a temporary variable
# for controlling this event.
#
# scope:councillor = councillor_inquisitor
# scope:councillor_liege = liege of the councillor_inquisitor
regula_council_event.5010 = {
	type = character_event
	title = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:councillor.var:final_heresy_state ?= flag:faction_disband
				}
				desc = regula_council_event.5010.t.faction_disband
			}
			triggered_desc = {
				trigger = {
					scope:councillor.var:final_heresy_state ?= flag:faction_defeat
				}
				desc = regula_council_event.5010.t.faction_defeat
			}
			triggered_desc = {
				trigger = {
					scope:councillor.var:final_heresy_state ?= flag:crushed
				}
				desc = regula_council_event.5010.t.crushed
			}
			triggered_desc = {
				trigger = {
					scope:councillor.var:final_heresy_state ?= flag:disband
				}
				desc = regula_council_event.5010.t.disband
			}
			desc = regula_council_event.5010.t
		}
	}
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:councillor.var:final_heresy_state ?= flag:faction_disband
				}
				desc = regula_council_event.5010.desc.faction_disband
			}
			triggered_desc = {
				trigger = {
					scope:councillor.var:final_heresy_state ?= flag:faction_defeat
				}
				desc = regula_council_event.5010.desc.faction_defeat
			}
			triggered_desc = {
				trigger = {
					scope:councillor.var:final_heresy_state ?= flag:crushed
				}
				desc = regula_council_event.5010.desc.crushed
			}
			triggered_desc = {
				trigger = {
					scope:councillor.var:final_heresy_state ?= flag:disband
				}
				desc = regula_council_event.5010.desc.disband
			}
			desc = regula_council_event.5010.desc
		}
	}

	theme = regula_council_theme

	left_portrait = {
		character = scope:councillor
		animation = throne_room_conversation_2
	}

	right_portrait = {
		character = scope:councillor_liege
		animation = throne_room_conversation_4
	}

	immediate = {
		scope:councillor = {
			stress_impact = {
				base = major_stress_impact_loss
			}
		}
		scope:councillor_liege = {
			stress_impact = {
				base = medium_stress_impact_loss
			}
		}
	}

	option = {
		name = regula_council_event.5010.a
		flavor = regula_council_event.5010.a.tt
	}
}

# Heresy Ended - White Peace
# The heresy conspiracy has ended, and the inquisitor informs the magister of
# the negative outcome.
#
# scope:councillor = councillor_inquisitor
# scope:councillor_liege = liege of the councillor_inquisitor
regula_council_event.5015 = {
	type = character_event
	title = regula_council_event.5015.t
	desc = regula_council_event.5015.desc

	theme = regula_council_theme

	left_portrait = {
		character = scope:councillor
		animation = throne_room_conversation_2
	}

	right_portrait = {
		character = scope:councillor_liege
		animation = throne_room_conversation_4
	}

	immediate = {
		scope:councillor = {
			stress_impact = {
				base = minor_stress_impact_gain
				lazy = minor_stress_impact_gain
				zealous = medium_stress_impact_gain
			}
		}
		scope:councillor_liege = {
			stress_impact = {
				base = miniscule_stress_impact_gain
				ambitious = minor_stress_impact_gain
				arrogant = medium_stress_impact_gain
				paranoid = medium_stress_impact_gain
			}
		}
	}

	option = {
		name = regula_council_event.5015.a
		flavor = regula_council_event.5015.a.tt
	}
}

# Heresy Ended - Heretic Victory
# The heresy conspiracy has ended, and the inquisitor informs the magister of
# the negative outcome.
#
# scope:councillor = councillor_inquisitor
# scope:councillor_liege = liege of the councillor_inquisitor
regula_council_event.5020 = {
	type = character_event
	title = regula_council_event.5020.t
	desc = regula_council_event.5020.desc

	theme = regula_council_theme

	left_portrait = {
		character = scope:councillor
		animation = throne_room_conversation_2
	}

	right_portrait = {
		character = scope:councillor_liege
		animation = throne_room_conversation_4
	}

	immediate = {
		scope:councillor = {
			stress_impact = {
				base = medium_stress_impact_gain
				zealous = medium_stress_impact_gain
			}
		}
		scope:councillor_liege = {
			stress_impact = {
				base = medium_stress_impact_gain
				ambitious = medium_stress_impact_gain
				arrogant = medium_stress_impact_gain
			}
		}
	}

	option = { # Get out of here...
		name = regula_council_event.5020.a
		flavor = regula_council_event.5020.a.tt

		scope:councillor_liege = {
			stress_impact = {
				calm = minor_stress_impact_loss
				compassionate = minor_stress_impact_loss
				forgiving = minor_stress_impact_loss
				sadistic = minor_stress_impact_gain
				vengeful = minor_stress_impact_gain
				wrathful = minor_stress_impact_gain
			}
		}
	}

	option = { # You've failed me!
		name = regula_council_event.5020.b
		flavor = regula_council_event.5020.b.tt

		scope:councillor = {
			stress_impact = {
				base = major_stress_impact_gain
			}
		}
		scope:councillor_liege = {
			imprison = {
				target = scope:councillor
				type = dungeon
			}

			stress_impact = {
				calm = minor_stress_impact_gain
				compassionate = minor_stress_impact_gain
				forgiving = minor_stress_impact_gain
				sadistic = minor_stress_impact_loss
				vengeful = minor_stress_impact_loss
				wrathful = minor_stress_impact_loss
			}
		}
	}
}

# task_impromptu_inspections - Identify Heretics
# Event which handles detection of heretics by the inquisitor in the realm
# while a regula heresy story cylce is in it's hidden growth stage.
#
# scope:councillor = councillor_inquisitor
# scope:councillor_liege = liege of the councillor_inquisitor
regula_council_event.5100 = {
	hidden = yes
	type = character_event

	trigger = {
		scope:councillor_liege = {
			regula_heresy_ongoing_trigger = yes
			regula_heresy_story_against_character_in_secret_state_trigger = yes
			any_targeting_secret = {
				secret_type = regula_heresy_conspirator_secret
				NOT = { is_known_by = scope:councillor_liege }
			}
		}
	}

	immediate = {
		scope:councillor = {
			random = {
				chance = {
					value = task_impromptu_inspections_identify_heretic_chance
					multiply = scope:councillor_liege.regula_heresy_secret_discovery_adjustment_factor
					max = 100
				}

				scope:councillor_liege = {
					random_targeting_secret = {
						limit = {
							secret_type = regula_heresy_conspirator_secret
							NOT = { is_known_by = scope:councillor_liege }
						}

						weight = {
							base = 1

							# Harder to discover the sneakier members of the
							# conspiracy.
							modifier = {
								add = {
									value = 100
									subtract = secret_owner.intrigue
									min = 0
								}
							}
						}

						save_temporary_scope_as = secret
						secret_owner = {
							save_temporary_scope_as = secret_owner
						}

						scope:councillor_liege = {
							send_interface_message = {
								type = event_intrigue_good_with_text
								title = task_impromptu_inspections_heretic_identified_title
								desc = task_impromptu_inspections_heretic_identified_desc
								right_icon = scope:councillor
								left_icon = scope:secret_owner

								scope:secret = {
									reveal_to = scope:councillor_liege
								}
								add_opinion = {
									target = scope:secret_owner
									modifier = regula_heresy_conspirator_opinion
								}
							}
						}
					}

					random_owned_story = {
						limit = {
							story_type = story_regula_heresy
						}
						regula_heresy_check_for_newly_discovered_effect = yes
					}
				}
			}
		}
	}
}

# task_impromptu_inspections - Suppress County
# Event which handles suppression of directly heretical counties in the
# magister's realm.
#
# scope:councillor = councillor_inquisitor
# scope:councillor_liege = liege of the councillor_inquisitor
regula_council_event.5105 = {
	hidden = yes
	type = character_event

	trigger = {
		# Can only happen if heresy is not at war, and there is at least one
		# directly heretical county in the realm.
		scope:councillor_liege = {
			regula_heresy_story_against_character_in_public_state_trigger = no
			any_realm_county = {
				regula_heresy_potential_heresy_county_directly_trigger = yes
			}
		}
	}

	immediate = {
		scope:councillor = {
			random = {
				chance = {
					value = task_impromptu_inspections_county_suppress_chance
				}

				scope:councillor_liege = {
					random_realm_county = {
						limit = {
							regula_heresy_potential_heresy_county_directly_trigger = yes
						}

						weight = {
							base = 1

							# More likely to suppress directly held counties.
							modifier = {
								factor = 10
								holder = scope:councillor_liege
							}
						}

						save_temporary_scope_as = suppressed_county
						scope:councillor_liege = {
							send_interface_message = {
								type = event_intrigue_good_with_text
								title = task_impromptu_inspections_county_suppressed_title
								desc = task_impromptu_inspections_county_suppressed_desc
								right_icon = scope:councillor
								left_icon = scope:suppressed_county

								scope:suppressed_county = {
									add_county_modifier = {
										modifier = regula_impromptu_inspections_county_suppressed_modifier
										years = 5
									}
								}
							}
						}
					}
				}
			}
		}
	}
}

# task_apprehend_heretics - Completion
# Event which handles capturing known heretics based on councillor skill level.
#
# scope:councillor = councillor_inquisitor
# scope:councillor_liege = liege of the councillor_inquisitor
regula_council_event.5200 = {
	hidden = yes
	type = character_event

	trigger = {
		scope:councillor_liege = {
			regula_heresy_ongoing_trigger = yes
			regula_heresy_any_capturable_conspirator_trigger = yes
		}
	}

	immediate = {
		scope:councillor = {
			while = {
				count = task_apprehend_heretics_num_heretics_captured

				scope:councillor_liege = {
					if = { # Only do anything if we know a conspirator.
						limit = {
							regula_heresy_ongoing_trigger = yes
							regula_heresy_any_capturable_conspirator_trigger = yes
						}

						regula_heresy_apprehend_random_capturable_member_effect = {
							SAVE_AS = captured_conspirator
						}

						# Send notification.
						send_interface_message = {
							type = event_captured_combatants_good
							title = task_apprehend_heretics_heretic_captured_title
							desc = task_apprehend_heretics_heretic_captured_desc
							right_icon = scope:councillor
							left_icon = scope:captured_conspirator
						}
					}
				}
			}

			# Evaluate whether story should disband.
			scope:councillor_liege = {
				every_owned_story = {
					limit = {
						story_type = story_regula_heresy
					}

					regula_heresy_check_for_disband_effect = yes
					if = {
						limit = {
							regula_heresy_story_in_terminal_state_trigger = yes
						}
						end_story = yes
					}
				}
			}
		}
	}
}

##################
# 6000-6999 Contubernalis Supervisor Task Events
#	6000 - task_sparring_partners - Side Effects
#	6100 - task_beasts_of_burden - Side Effects
##################
# task_sparring_partners - Side Effects
# Determines which side effects should occur each month while
# task_sparring_partners is being performed by the contubernalis supervisor.
#
# scope:councillor = councillor_contubernalis_supervisor
# scope:councillor_liege = liege of the councillor_contubernalis_supervisor
regula_council_event.6000 = {
	hidden = yes
	type = character_event

	trigger = {
		scope:councillor_liege = {
			any_courtier = {
				is_contubernalis_available_for_supervisor_use = yes
			}
			any_knight = {
				NOT = { has_trait = contubernalis }
			}
		}
	}

	immediate = {
		scope:councillor_liege = {
			# Select contubernalis & knight to be effected.
			random_courtier = {
				limit = {
					is_contubernalis_available_for_supervisor_use = yes
				}

				weight = {
					base = 100

					modifier = {
						factor = 0.1
						has_character_flag = regula_recent_contubernalis_supervisor_side_effect
					}
				}

				save_scope_as = contubernalis_participant
				add_character_flag = { 
					flag = regula_recent_contubernalis_supervisor_side_effect
					years = contubernalis_supervisor_side_effect_reduce_chance_years
				}
			}
			random_knight = {
				limit = {
					NOT = { has_trait = contubernalis }
				}

				weight = {
					base = 100

					modifier = {
						factor = 0.1
						has_character_flag = regula_recent_contubernalis_supervisor_side_effect
					}
				}

				save_scope_as = knight_participant
				add_character_flag = { 
					flag = regula_recent_contubernalis_supervisor_side_effect
					years = contubernalis_supervisor_side_effect_reduce_chance_years
				}
			}

			random_list = {
				0 = { # Positive Effect [60-100% chance]
					modifier = {
						add = {
							value = contubernalis_supervisor_positive_side_effect_chance
						}
					}
					regula_task_sparring_partners_positive_side_effect = yes
				}
				100 = { # Negative Effect [0-40% chance]
					modifier = {
						add = {
							subtract = contubernalis_supervisor_positive_side_effect_chance
						}
					}
					regula_task_sparring_partners_negative_side_effect = yes
				}
			}
		}
	}
}

# task_beasts_of_burden - Side Effects
# Determines which side effects should occur each month while
# task_beasts_of_burden is being performed by the contubernalis supervisor.
#
# scope:councillor = councillor_contubernalis_supervisor
# scope:councillor_liege = liege of the councillor_contubernalis_supervisor
regula_council_event.6100 = {
	hidden = yes
	type = character_event

	trigger = {
		scope:councillor_liege = {
			any_courtier = {
				is_contubernalis_available_for_supervisor_use = yes
			}
		}
	}

	immediate = {
		scope:councillor_liege = {
			# Select contubernalis & knight to be effected.
			random_courtier = {
				limit = {
					is_contubernalis_available_for_supervisor_use = yes
				}

				weight = {
					base = 100

					modifier = {
						factor = 0.1
						has_character_flag = regula_recent_contubernalis_supervisor_side_effect
					}
				}

				save_scope_as = contubernalis_participant
				add_character_flag = { 
					flag = regula_recent_contubernalis_supervisor_side_effect
					years = contubernalis_supervisor_side_effect_reduce_chance_years
				}
			}
			random_sub_realm_county = {
				weight = {
					base = 100

					modifier = { # Domain more likely.
						factor = 5
						holder ?= scope:councillor_liege
					}

					modifier = {
						factor = 0.01
						has_variable = regula_recent_contubernalis_supervisor_side_effect
					}
				}

				save_scope_as = county_participant
				set_variable = { 
					name = regula_recent_contubernalis_supervisor_side_effect
					value = yes
					years = contubernalis_supervisor_side_effect_reduce_chance_years
				}
			}

			random_list = {
				0 = { # Positive Effect [60-100% chance]
					modifier = {
						add = {
							value = contubernalis_supervisor_positive_side_effect_chance
						}
					}
					regula_task_beasts_of_burden_positive_side_effect = yes
				}
				100 = { # Negative Effect [0-40% chance]
					modifier = {
						add = {
							subtract = contubernalis_supervisor_positive_side_effect_chance
						}
					}
					regula_task_beasts_of_burden_negative_side_effect = yes
				}
			}
		}
	}
}
