﻿namespace = regula_interrogate_heretic_event

################################
# Heretic Interrogation Events #
################################
# 0001 - Interrogate Heretic
# 0005 - Interrogate Heretic - Magister Torture - Success
# 0006 - Interrogate Heretic - Magister Torture - Failure
# 0010 - Interrogate Heretic - Inquisitor Torture - Success
# 0011 - Interrogate Heretic - Inquisitor Torture - Failure
# 0015 - Interrogate Heretic - Charm
# 0016 - Interrogate Heretic - Devoted

# Interrogate Heretic
# Event used by the magister to select how they will handle interrogating their
# prisoner for more information.
#
# scope:actor = the magister character
# scope:recipient = the heretic being interrogated
regula_interrogate_heretic_event.0001 = {
	type = character_event
	title = regula_interrogate_heretic_event.0001.t
	desc = {
		desc = regula_interrogate_heretic_event.0001.desc.opening
		triggered_desc = {
			trigger = {
				exists = scope:councillor
			}
			desc = regula_interrogate_heretic_event.0001.desc.councillor
		}
		desc = regula_interrogate_heretic_event.0001.desc.closing
	}

	theme = regula_theme
	override_background = {
		reference = regula_cell
	}

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

	right_portrait = {
		character = scope:recipient
		triggered_animation = {
			trigger = {
				is_regula_devoted_trigger = yes
			}
			animation = prisonhouse
		}
		triggered_animation = {
			trigger = {
				is_regula_devoted_trigger = no
			}
			animation = prisondungeon
		}
	}

	lower_center_portrait = {
		character = scope:councillor
		trigger = { exists = scope:councillor }
		animation = personality_rational
	}

	immediate = {
		scope:actor = {
			random_councillor = {
				limit = {
					has_council_position = councillor_inquisitor
				}
				save_scope_as = councillor
			}
		}

		# Pick a conspirator to be revealed if interrogation is successful.
		regula_heresy_interrogation_pick_revealed_conspirator = yes
	}

	option = { # Torture the heretic to find what you need.
		name = regula_interrogate_heretic_event.0001.magister_torture

		scope:recipient = {
			add_character_modifier = {
				modifier = recently_tortured
				years = 5
			}
			stress_impact = {
				base = massive_stress_impact_gain
				craven = medium_stress_impact_gain
				brave = medium_stress_impact_loss
			}
			torture_blind_castrate_disfigure_opinion_effect = { VERB = tortured }
		}

		scope:actor = {
			stress_impact = {
				sadistic = medium_stress_impact_loss
				compassionate = major_stress_impact_gain
				craven = major_stress_impact_gain
				just = medium_stress_impact_gain
				forgiving = medium_stress_impact_gain
				generous = medium_stress_impact_gain
				trusting = minor_stress_impact_gain
				content = minor_stress_impact_gain
			}

			add_dread = torture_interaction_medium_dread_gain

			random_list = {
				0 = { # Success
					modifier = {
						add = {
							value = regula_heresy_torture_success_chance
						}
					}

					custom_tooltip = regula_interrogate_heretic_event_torture_success
					show_as_tooltip = {
						stress_impact = {
							base = medium_stress_impact_loss
						}
					}
					trigger_event = {
						id = regula_interrogate_heretic_event.0005
						days = { 1 7 }
					}
				}
				100 = { # Failure
					modifier = {
						add = {
							subtract = regula_heresy_torture_success_chance
						}
					}

					custom_tooltip = regula_interrogate_heretic_event_torture_failure
					show_as_tooltip = {
						stress_impact = {
							base = medium_stress_impact_gain
						}
					}
					trigger_event = {
						id = regula_interrogate_heretic_event.0006
						days = 7
					}
				}
			}
		}
	}

	option = { # Leave the dirty work to your inquisitor.
		name = regula_interrogate_heretic_event.0001.inquisitor_torture

		trigger = {
			exists = scope:councillor
			scope:actor = {
				prestige >= minor_prestige_value
			}
		}

		show_as_unavailable = {
			exists = scope:councillor
		}

		scope:recipient = {
			add_character_modifier = {
				modifier = recently_tortured
				years = 5
			}
			stress_impact = {
				base = massive_stress_impact_gain
				craven = medium_stress_impact_gain
				brave = medium_stress_impact_loss
			}
			torture_blind_castrate_disfigure_opinion_effect = { VERB = tortured }
		}

		scope:actor = {
			stress_impact = {
				sadistic = minor_stress_impact_gain
				compassionate = major_stress_impact_gain
				forgiving = medium_stress_impact_gain
			}

			add_dread = torture_interaction_minor_dread_gain
			add_prestige = minor_prestige_loss
		}

		scope:councillor = {
			stress_impact = {
				sadistic = medium_stress_impact_loss
				zealous = medium_stress_impact_loss
				craven = major_stress_impact_gain
			}

			add_dread = torture_interaction_medium_dread_gain

			random_list = {
				0 = { # Success
					modifier = {
						add = {
							value = regula_heresy_torture_success_chance
						}
					}

					custom_tooltip = regula_interrogate_heretic_event_torture_success
					scope:actor = {
						show_as_tooltip = {
							stress_impact = {
								base = minor_stress_impact_loss
							}
						}
						trigger_event = {
							id = regula_interrogate_heretic_event.0010
							days = { 1 7 }
						}
					}
				}
				100 = { # Failure
					modifier = {
						add = {
							subtract = regula_heresy_torture_success_chance
						}
					}

					custom_tooltip = regula_interrogate_heretic_event_torture_failure
					scope:actor = {
						show_as_tooltip = {
							stress_impact = {
								base = minor_stress_impact_gain
							}
						}
						trigger_event = {
							id = regula_interrogate_heretic_event.0011
							days = 7
						}
					}
				}
			}
		}
	}

	option = { # Charm the heretic to get the information.
		name = regula_interrogate_heretic_event.0001.charm

		trigger = {
			scope:recipient = {
				is_female = yes
				is_regula_devoted_trigger = no
			}
			scope:actor = {
				piety >= regula_prisoner_charm_cost
			}
		}

		show_as_unavailable = {
			scope:recipient = {
				is_female = yes
				is_regula_devoted_trigger = no
			}
		}

		custom_tooltip = regula_interrogate_heretic_charm_event_success
		scope:actor = {
			stress_impact = {
				sadistic = medium_stress_impact_gain
			}
			add_piety = regula_prisoner_charm_cost_negated
			trigger_event = regula_interrogate_heretic_event.0015
		}
		show_as_tooltip = {
			scope:recipient = {
				fascinare_success_effect = { CHARACTER = scope:actor }
			}
		}
	}

	option = { # Demand the charmed heretic tell you everything.
		name = regula_interrogate_heretic_event.0001.demand

		trigger = {
			scope:recipient = {
				is_regula_devoted_trigger = yes
			}
		}

		custom_tooltip = regula_interrogate_heretic_devoted_event_success
		scope:actor = {
			stress_impact = {
				sadistic = medium_stress_impact_gain
			}

			trigger_event = regula_interrogate_heretic_event.0016
		}
	}

	option = { # Never Mind
		name = regula_interrogate_heretic_event.0001.cancel

		hidden_effect = {
			remove_interaction_cooldown_against = {
				interaction = regula_interrogate_heretic_interaction
				target = scope:recipient
			}
		}
	}
}

# Interrogate Heretic - Magister Torture - Success
# Event which handles successful torture of a heretic by the magister for
# learning more about the ongoing conspiracy.
#
# scope:actor = the magister character
# scope:recipient = the heretic being interrogated
# scope:revealed_conspirator = the revealed coconspirator (may be null)
regula_interrogate_heretic_event.0005 = {
	type = character_event
	title = regula_interrogate_heretic_event.0005.t
	desc = {
		desc = regula_interrogate_heretic_event.0005.desc.opening
		triggered_desc = {
			trigger = {
				scope:actor = {
					has_trait = torturer
				}
			}
			desc = regula_interrogate_heretic_event.0005.desc.torturer
		}
		desc = regula_interrogate_heretic_event.0005.desc.pre_result

		triggered_desc = {
			trigger = {
				scope:interrogate_secret_state ?= flag:none_known
			}
			desc = regula_interrogate_heretic_event.0005.desc.none_known_response
		}
		triggered_desc = {
			trigger = {
				NOT = { scope:interrogate_secret_state ?= flag:none_known }
			}
			desc = regula_interrogate_heretic_event.0005.desc.known_response
		}
		triggered_desc = {
			trigger = {
				scope:interrogate_secret_state ?= flag:already_captured
			}
			desc = regula_interrogate_heretic_event.already_captured_postfix
		}
		triggered_desc = {
			trigger = {
				scope:interrogate_secret_state ?= flag:already_known
			}
			desc = regula_interrogate_heretic_event.already_known_postfix
		}
	}

	theme = regula_theme
	override_background = {
		reference = regula_cell
	}

	left_portrait = {
		character = scope:actor
		animation = schadenfreude
	}

	right_portrait = {
		character = scope:recipient
		animation = prisondungeon
	}

	immediate = {
		# Determine secret state.
		regula_heresy_interrogation_result_effect = {
			SAVE_SCOPE_AS = interrogate_secret_state
		}

		scope:actor = {
			stress_impact = {
				base = medium_stress_impact_loss
			}
		}

		# If we didn't get any information, there is a chance we would have
		# gotten more brutal.
		if = {
			limit = {
				scope:interrogate_secret_state = flag:none_known
			}

			random = {
				chance = 10

				scope:recipient = {
					increase_wounds_effect = { REASON = whipping }
					stress_impact = {
						craven = medium_stress_impact_gain
					}
				}
			}
		}

		# If we've already captured a conspirator but didn't realize they were
		# a heretic, now we know.
		if = {
			limit = {
				scope:interrogate_secret_state = flag:already_captured
				NOT = {
					scope:actor = {
						has_opinion_modifier = {
							target = scope:revealed_conspirator
							modifier = regula_heresy_conspirator_opinion
						}
					}
				}
			}

			scope:actor = {
				add_opinion = {
					target = scope:revealed_conspirator
					modifier = regula_heresy_conspirator_opinion
				}
			}
		}

		# Otherwise, reveal the secret to the magister.
		if = {
			limit = {
				scope:interrogate_secret_state = flag:success
			}

			scope:revealed_conspirator = {
				random_secret = {
					limit = {
						secret_type = regula_heresy_conspirator_secret
						secret_target ?= scope:actor
					}

					reveal_to = scope:actor
				}
			}
		}
	}

	option = {
		name = regula_interrogate_heretic_event.0005.success

		trigger = {
			scope:interrogate_secret_state = flag:success
		}
	}

	option = {
		name = regula_interrogate_heretic_event.0005.no_new_information

		trigger = {
			NOT = {
				scope:interrogate_secret_state = flag:success
			}
		}
	}
}

# Interrogate Heretic - Magister Torture - Failure
# Event which handles unsuccessful torture of a heretic by the magister for
# learning more about the ongoing conspiracy.
#
# scope:actor = the magister character
# scope:recipient = the heretic being interrogated
regula_interrogate_heretic_event.0006 = {
	type = character_event
	title = regula_interrogate_heretic_event.0006.t
	desc = regula_interrogate_heretic_event.0006.desc

	theme = regula_theme
	override_background = {
		reference = regula_cell
	}

	left_portrait = {
		character = scope:actor
		animation = schadenfreude
	}

	right_portrait = {
		character = scope:recipient
		animation = prisondungeon
	}

	immediate = {
		scope:actor = {
			stress_impact = {
				base = medium_stress_impact_gain
			}
		}

		random = {
			chance = 20

			scope:recipient = {
				increase_wounds_effect = { REASON = whipping }
				stress_impact = {
					craven = medium_stress_impact_gain
				}
			}
		}
	}

	option = {
		name = regula_interrogate_heretic_event.0006.finish
	}
}

# Interrogate Heretic - Inquisitor Torture - Success
# Event which handles successful torture of a heretic by the inquisitor for
# learning more about the ongoing conspiracy.
#
# scope:actor = the magister character
# scope:councillor = the inquisitor councillor doing the torture
# scope:recipient = the heretic being interrogated
# scope:revealed_conspirator = the revealed coconspirator (may be null)
regula_interrogate_heretic_event.0010 = {
	type = character_event
	title = regula_interrogate_heretic_event.0010.t
	desc = {
		desc = regula_interrogate_heretic_event.0010.desc.opening
		triggered_desc = {
			trigger = {
				scope:interrogate_secret_state ?= flag:none_known
			}
			desc = regula_interrogate_heretic_event.0010.desc.none_known_response
		}
		triggered_desc = {
			trigger = {
				NOT = { scope:interrogate_secret_state ?= flag:none_known }
			}
			desc = regula_interrogate_heretic_event.0010.desc.known_response
		}
		triggered_desc = {
			trigger = {
				scope:interrogate_secret_state ?= flag:already_captured
			}
			desc = regula_interrogate_heretic_event.already_captured_postfix
		}
		triggered_desc = {
			trigger = {
				scope:interrogate_secret_state ?= flag:already_known
			}
			desc = regula_interrogate_heretic_event.already_known_postfix
		}
	}

	theme = regula_council_theme

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

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

	immediate = {
		# Determine secret state.
		regula_heresy_interrogation_result_effect = {
			SAVE_SCOPE_AS = interrogate_secret_state
		}

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

		# If we didn't get any information, there is a chance we would have
		# gotten more brutal.
		if = {
			limit = {
				scope:interrogate_secret_state = flag:none_known
			}

			random = {
				chance = 10

				scope:recipient = {
					increase_wounds_effect = { REASON = whipping }
					stress_impact = {
						craven = medium_stress_impact_gain
					}
				}
			}
		}

		# If we've already captured a conspirator but didn't realize they were
		# a heretic, now we know.
		if = {
			limit = {
				scope:interrogate_secret_state = flag:already_captured
				NOT = {
					scope:actor = {
						has_opinion_modifier = {
							target = scope:revealed_conspirator
							modifier = regula_heresy_conspirator_opinion
						}
					}
				}
			}

			scope:actor = {
				add_opinion = {
					target = scope:revealed_conspirator
					modifier = regula_heresy_conspirator_opinion
				}
			}
		}

		# Otherwise, reveal the secret to the magister.
		if = {
			limit = {
				scope:interrogate_secret_state = flag:success
			}

			scope:revealed_conspirator = {
				random_secret = {
					limit = {
						secret_type = regula_heresy_conspirator_secret
						secret_target ?= scope:actor
					}

					reveal_to = scope:actor
				}
			}
		}
	}

	option = {
		name = regula_interrogate_heretic_event.0010.success

		trigger = {
			scope:interrogate_secret_state = flag:success
		}
	}

	option = {
		name = regula_interrogate_heretic_event.0010.no_new_information

		trigger = {
			NOT = {
				scope:interrogate_secret_state = flag:success
			}
		}
	}
}

# Interrogate Heretic - Inquisitor Torture - Failure
# Event which handles unsuccessful torture of a heretic by the inquisitor for
# learning more about the ongoing conspiracy.
#
# scope:actor = the magister character
# scope:councillor = the inquisitor councillor doing the torture
# scope:recipient = the heretic being interrogated
regula_interrogate_heretic_event.0011 = {
	type = character_event
	title = regula_interrogate_heretic_event.0011.t
	desc = regula_interrogate_heretic_event.0011.desc

	theme = regula_council_theme

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

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

	immediate = {
		scope:actor = {
			stress_impact = {
				base = minor_stress_impact_gain
			}
		}

		random = {
			chance = 20

			scope:recipient = {
				increase_wounds_effect = { REASON = whipping }
				stress_impact = {
					craven = medium_stress_impact_gain
				}
			}
		}
	}

	option = {
		name = regula_interrogate_heretic_event.0011.finish_kind
	}

	option = {
		name = regula_interrogate_heretic_event.0011.finish

		scope:councillor = {
			stress_impact = {
				base = medium_stress_impact_gain
				craven = minor_stress_impact_gain
			}
		}
	}
}

# Interrogate Heretic - Charm
# Event which handles charming a character to learn what they know about the
# other conspirators.
#
# scope:actor = the magister character
# scope:recipient = the heretic being interrogated
# scope:revealed_conspirator = the revealed coconspirator (may be null)
regula_interrogate_heretic_event.0015 = {
	type = character_event
	title = regula_interrogate_heretic_event.0015.t
	desc = {
		desc = regula_interrogate_heretic_event.0015.desc.opening
		triggered_desc = {
			trigger = {
				scope:interrogate_secret_state ?= flag:none_known
			}
			desc = regula_interrogate_heretic_event.0015.desc.none_known_response
		}
		triggered_desc = {
			trigger = {
				NOT = { scope:interrogate_secret_state ?= flag:none_known }
			}
			desc = regula_interrogate_heretic_event.0015.desc.known_response
		}
		triggered_desc = {
			trigger = {
				scope:interrogate_secret_state ?= flag:already_captured
			}
			desc = regula_interrogate_heretic_event.already_captured_postfix
		}
		triggered_desc = {
			trigger = {
				scope:interrogate_secret_state ?= flag:already_known
			}
			desc = regula_interrogate_heretic_event.already_known_postfix
		}
	}

	theme = regula_theme
	override_background = {
		reference = regula_cell
	}

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

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

	immediate = {
		# Determine secret state.
		regula_heresy_interrogation_result_effect = {
			SAVE_SCOPE_AS = interrogate_secret_state
		}

		# If we've already captured a conspirator but didn't realize they were
		# a heretic, now we know.
		if = {
			limit = {
				scope:interrogate_secret_state = flag:already_captured
				NOT = {
					scope:actor = {
						has_opinion_modifier = {
							target = scope:revealed_conspirator
							modifier = regula_heresy_conspirator_opinion
						}
					}
				}
			}

			scope:actor = {
				add_opinion = {
					target = scope:revealed_conspirator
					modifier = regula_heresy_conspirator_opinion
				}
			}
		}

		# If successful, reveal the secret to the magister.
		if = {
			limit = {
				scope:interrogate_secret_state = flag:success
			}

			scope:revealed_conspirator = {
				random_secret = {
					limit = {
						secret_type = regula_heresy_conspirator_secret
						secret_target ?= scope:actor
					}

					reveal_to = scope:actor
				}
			}
		}

		scope:recipient = {
			fascinare_success_effect = { CHARACTER = scope:actor }
			create_memory_enchanted_in_prison = { CHARACTER = scope:actor }
		}
	}

	option = {
		name = regula_interrogate_heretic_event.0015.success

		trigger = {
			scope:interrogate_secret_state = flag:success
		}
	}

	option = {
		name = regula_interrogate_heretic_event.0015.no_new_information

		trigger = {
			NOT = {
				scope:interrogate_secret_state = flag:success
			}
		}
	}
}

# Interrogate Heretic - Devoted
# Event which handles demanding information on other heretics from a charmed
# heretic.
#
# scope:actor = the magister character
# scope:recipient = the heretic being interrogated
# scope:revealed_conspirator = the revealed coconspirator (may be null)
regula_interrogate_heretic_event.0016 = {
	type = character_event
	title = regula_interrogate_heretic_event.0016.t
	desc = {
		desc = regula_interrogate_heretic_event.0016.desc.opening
		triggered_desc = {
			trigger = {
				scope:interrogate_secret_state ?= flag:none_known
			}
			desc = regula_interrogate_heretic_event.0016.desc.none_known_response
		}
		triggered_desc = {
			trigger = {
				NOT = { scope:interrogate_secret_state ?= flag:none_known }
			}
			desc = regula_interrogate_heretic_event.0016.desc.known_response
		}
		triggered_desc = {
			trigger = {
				scope:interrogate_secret_state ?= flag:already_captured
			}
			desc = regula_interrogate_heretic_event.already_captured_postfix
		}
		triggered_desc = {
			trigger = {
				scope:interrogate_secret_state ?= flag:already_known
			}
			desc = regula_interrogate_heretic_event.already_known_postfix
		}
	}

	theme = regula_theme
	override_background = {
		reference = regula_cell
	}

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

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

	immediate = {
		# Determine secret state.
		regula_heresy_interrogation_result_effect = {
			SAVE_SCOPE_AS = interrogate_secret_state
		}

		# If we've already captured a conspirator but didn't realize they were
		# a heretic, now we know.
		if = {
			limit = {
				scope:interrogate_secret_state = flag:already_captured
				NOT = {
					scope:actor = {
						has_opinion_modifier = {
							target = scope:revealed_conspirator
							modifier = regula_heresy_conspirator_opinion
						}
					}
				}
			}

			scope:actor = {
				add_opinion = {
					target = scope:revealed_conspirator
					modifier = regula_heresy_conspirator_opinion
				}
			}
		}

		# If successful, reveal the secret to the magister.
		if = {
			limit = {
				scope:interrogate_secret_state = flag:success
			}

			scope:revealed_conspirator = {
				random_secret = {
					limit = {
						secret_type = regula_heresy_conspirator_secret
						secret_target ?= scope:actor
					}

					reveal_to = scope:actor
				}
			}
		}
	}

	option = {
		name = regula_interrogate_heretic_event.0016.success

		trigger = {
			scope:interrogate_secret_state = flag:success
		}
	}

	option = {
		name = regula_interrogate_heretic_event.0016.no_new_information

		trigger = {
			NOT = {
				scope:interrogate_secret_state = flag:success
			}
		}
	}
}
