﻿namespace = regula_prisoner_event

regula_prisoner_event.1000 = {  ### UPDATE - Need to remove the bars
	type = character_event
	title = regula_prisoner_event.1000.t

	desc = {
		first_valid = {
			triggered_desc = {  # Add another for lovers?
				trigger = {
					scope:recipient = {
						has_trait = devoted_trait_group
					}
				}
				desc = regula_prisoner_event.1000.desc.devoted
			}
			desc = regula_prisoner_event.1000.desc.standard
		}
	}

	theme = regula_theme
	override_background = {  # Split between house arrest and dungeon?
		reference = regula_cell
	}

	right_portrait = {
		character = scope:recipient
		outfit_tags = { no_cloak no_hat no_pants no_clothes }
    	triggered_animation = {
			trigger = {
				has_trait = devoted_trait_group
			}
			animation = prisonhouse
		}
		triggered_animation = {
			trigger = {
				NOT = { has_trait = devoted_trait_group }
			}
			animation = prisondungeon
		}
	}

	immediate = {
		scope:recipient = {
			add_character_flag = {
				flag = is_naked
				days = 180
			}
		}
	}

	option = { # Charm at half piety cost.
		name = regula_prisoner_event.1000.a
		flavor = regula_prisoner_event.1000.a.tt

		trigger = {
			scope:recipient = {
				is_regula_devoted_trigger = no
			}
			scope:actor = {
				piety >= regula_prisoner_charm_cost_negated
				custom_description = {
					text = magister_trait_2_required_trigger
					has_trait_rank = {
						trait = magister_trait_group
						rank >= 2
					}
				}
			}
		}

		show_as_tooltip = {
			scope:recipient = {
				fascinare_success_effect = { CHARACTER = root }
			}
			scope:actor = {
				add_piety = regula_prisoner_charm_cost_negated
			}
		}
		scope:actor = {
			trigger_event = regula_prisoner_event.1001
		}
	}

	option = { # Puppet at half piety cost.
		name = regula_prisoner_event.1000.b
		flavor = regula_prisoner_event.1000.b.tt
		trigger = {
			scope:recipient = {
				NOT = { has_trait = sigillum }
				has_trait = devoted_trait_group
			}
			scope:actor = {
				custom_description = {
					text = magister_trait_3_required_trigger
					has_trait_rank = {
						trait = magister_trait_group
						rank >= 3
					}
				}
			}
		}

		show_as_tooltip = {
			scope:recipient = {
				add_trait = sigillum
				add_stress = medium_stress_gain
			}
			scope:actor = {
				add_hook = {
					target = scope:recipient
					type = regula_sigillum_hook
				}
				add_piety = -75
			}
		}

		scope:actor = {
			trigger_event = regula_prisoner_event.1002
		}

		stress_impact = {
			vengeful = minor_stress_impact_loss
			callous = minor_stress_impact_loss
			sadistic = minor_stress_impact_loss
			wrathful = minor_stress_impact_loss
			paranoid = minor_stress_impact_loss

			compassionate = medium_stress_impact_gain
			forgiving = medium_stress_impact_gain
			humble = minor_stress_impact_gain
			calm = minor_stress_impact_gain
			trusting = minor_stress_impact_gain
		}
	}

	option = { # Sex interaction.  Overwhelming lust.
		name = regula_prisoner_event.1000.c
		flavor = regula_prisoner_event.1000.c.tt
		trigger = {
			scope:actor = {
				has_trait_rank = {
					trait = magister_trait_group
					rank >= 2
				}
			}
		}
		show_as_tooltip = {
			scope:actor = {
				regula_sex_with_target_normal = { TARGET = scope:recipient }
			}
		}
		scope:actor = {
			trigger_event = regula_prisoner_event.1003 # Masquerade
		}
	}

	option = { # Become her lover. Also removes rival relationship. Remove any existing lovers or divorces old spouse.
		name = regula_prisoner_event.1000.d
		flavor = regula_prisoner_event.1000.d.tt

		trigger = {
			scope:actor = {
				trigger_if = {
					limit = {
						scope:recipient = {
							has_trait = devoted_trait_group
						}
					}
					piety >= regula_prisoner_lover_charm_cost
				}
				trigger_else = {
					piety >= regula_prisoner_lover_charm_devoted_cost_negated
				}
				custom_description = {
					text = magister_trait_4_required_trigger
					has_trait_rank = {
						trait = magister_trait_group
						rank >= 4
					}
				}
				NOR = { 
					has_relation_lover = scope:recipient
					is_spouse_of = scope:recipient
				}
			}
		}

		# Effects are:
		# 1. Charm and create charm memory
		# 2. Have sexy times
		# 3. Removing existing marriage/betrothal/lovers/soulmate for target, if they have any
		# 4. Turn into our lover
		show_as_tooltip = {
			regula_prisoner_love_charm_effect = {
				TARGET = scope:recipient
				CHARMER = scope:actor
			}
		}

		if = {
			limit = {
				scope:recipient = {
					OR = {
						is_married = yes
						num_of_relation_lover >= 1
					}
				}
			}
			scope:actor = {
				trigger_event = regula_prisoner_event.1004
			}
		}
		else = {
			scope:actor = {
				trigger_event = regula_prisoner_event.1005
			}
		}
	}

	option = { # Contubernalis.  High piety cost (500?), and requires level 3 or 4.
		name = regula_prisoner_event.1000.e
		flavor = regula_prisoner_event.1000.e.tt

		trigger = {
			scope:actor.faith = { NOT = { has_doctrine_parameter = contubernalis_realm_benefits } }
			scope:actor = {
				custom_description = {
					text = magister_trait_4_required_trigger
					has_trait_rank = {
						trait = magister_trait_group
						rank >= 4
					}
				}
			}
			scope:recipient = {
				NOT = { has_trait = contubernalis }
			}
			scope:actor = {
				piety >= 500
			}
		}

		show_as_unavailable = {
			scope:actor = {
				custom_description = {
					text = magister_trait_4_required_trigger
					has_trait_rank = {
						trait = magister_trait_group
						rank >= 4
					}
				}
			}
			scope:recipient = {
				NOT = { has_trait = contubernalis }
			}
			scope:actor = {
				piety < 500
			}
		}

		if = {
			limit = {
				NOT = { has_execute_reason = scope:recipient }
				regula_contubernalis_tyranny_gain > 0
			}
			add_internal_flag = dangerous
		}

		show_as_tooltip = {  ### UPDATE - Add a note about their relations disliking this?
			scope:actor = {
				add_piety = -500
				add_dread = medium_dread_gain
				regula_gain_create_contubernalis_tyranny = yes
			}

			regula_turn_into_contubernalis = {
				ACTOR = scope:actor
				VICTIM = scope:recipient
			}
		}
		scope:actor = {
			trigger_event = regula_prisoner_event.1006
		}

		stress_impact = {
			vengeful = minor_stress_impact_loss
			callous = minor_stress_impact_loss
			sadistic = minor_stress_impact_loss
			wrathful = minor_stress_impact_loss

			compassionate = medium_stress_impact_gain
			forgiving = medium_stress_impact_gain
			humble = minor_stress_impact_gain
			calm = minor_stress_impact_gain
		}
	}

	option = { # Contubernalis with sacrifice tenet.
		name = regula_prisoner_event.1000.g
		flavor = regula_prisoner_event.1000.g.tt

		trigger = {
			scope:actor.faith = { has_doctrine_parameter = contubernalis_realm_benefits }

			scope:recipient = {
				NOT = { has_trait = contubernalis }
			}
		}

		show_as_unavailable = {
			scope:recipient = {
				NOT = { has_trait = contubernalis }
			}
		}

		if = {
			limit = {
				NOT = { has_execute_reason = scope:recipient }
				regula_contubernalis_tyranny_gain > 0
			}
			add_internal_flag = dangerous
		}

		show_as_tooltip = {  ### UPDATE - Add a note about their relations disliking this?
			scope:actor = {
				add_dread = medium_dread_gain
				regula_gain_create_contubernalis_tyranny = yes
			}

			regula_turn_into_contubernalis = {
				ACTOR = scope:actor
				VICTIM = scope:recipient
			}
		}
		scope:actor = {
			trigger_event = regula_prisoner_event.1006
		}

		stress_impact = {
			vengeful = medium_stress_impact_loss
			callous = minor_stress_impact_loss
			sadistic = minor_stress_impact_loss
			wrathful = minor_stress_impact_loss
			zealous = minor_stress_impact_loss

			compassionate = minor_stress_impact_gain
			forgiving = minor_stress_impact_gain
			calm = minor_stress_impact_gain
		}
	}

	option = { # Leave them.
		name = regula_prisoner_event.1000.f
		scope:recipient = {
			remove_character_flag = is_naked
		}
	}
}

# Charm
regula_prisoner_event.1001 = {
	type = character_event
	title = regula_prisoner_event.1001.t
	desc = regula_prisoner_event.1001.desc

	theme = dungeon
	override_background = {
		reference = regula_cell
	}

	right_portrait = {
		character = scope:recipient
		outfit_tags = { no_cloak no_hat no_pants no_clothes }
		animation = lunatic
	}

	immediate = {
		scope:recipient = {
			fascinare_success_effect = { CHARACTER = root }
			create_memory_enchanted_in_prison = { CHARACTER = root }
		}
		scope:actor = {
			add_piety = regula_prisoner_charm_cost_negated
		}
	}

	option = { # Back to cell
		name = regula_prisoner_event.1001.a

		scope:actor = {
			trigger_event = regula_prisoner_event.1000
		}
	}

	option = { # Leave them.
		name = regula_prisoner_event.1000.f
		scope:recipient = {
			remove_character_flag = is_naked
		}
	}
}

# Puppet
regula_prisoner_event.1002 = {
	type = character_event
	title = regula_prisoner_event.1002.t
	desc = regula_prisoner_event.1002.desc

	theme = dungeon
	override_background = {
		reference = regula_cell
	}

	right_portrait = {
		character = scope:recipient
		outfit_tags = { no_cloak no_hat no_pants no_clothes }
		animation = sick

	}

	immediate = {
		scope:recipient = {
			add_trait = sigillum
			add_stress = medium_stress_gain
		}
		scope:actor = {
			add_hook = {
				target = scope:recipient
				type = regula_sigillum_hook
			}
		}
	}

	option = { # Back to cell
		name = regula_prisoner_event.1002.a

		scope:actor = {
			trigger_event = regula_prisoner_event.1000
		}
	}

	option = { # Leave them.
		name = regula_prisoner_event.1000.f
		scope:recipient = {
			remove_character_flag = is_naked
		}
	}
}

# Sex
regula_prisoner_event.1003 = {
	type = character_event
	title = regula_prisoner_event.1003.t
	desc = regula_prisoner_event.1003.desc

	theme = dungeon
	override_background = {
		reference = regula_cell
	}

	right_portrait = {
		character = scope:recipient
		outfit_tags = { no_cloak no_hat no_pants no_clothes }
		animation = happiness
	}

	immediate = {
		scope:actor = {
			regula_sex_with_target_normal = { TARGET = scope:recipient }
		}
	}

	option = { # Back to cell
		name = regula_prisoner_event.1003.a

		scope:actor = {
			trigger_event = regula_prisoner_event.1000
		}
	}

	option = { # Leave them.
		name = regula_prisoner_event.1003.b
		scope:recipient = {
			remove_character_flag = is_naked
		}
	}
}

# Love spell - lover
regula_prisoner_event.1004 = {
	type = character_event
	title = regula_prisoner_event.1004.t
	desc = regula_prisoner_event.1004.desc

	theme = dungeon
	override_background = {
		reference = regula_cell
	}

	right_portrait = {
		character = scope:recipient
		outfit_tags = { no_cloak no_hat no_pants no_clothes }
		animation = shock
	}


	immediate = {
		regula_prisoner_love_charm_effect = {
			TARGET = scope:recipient
			CHARMER = scope:actor
		}
	}

	option = { # Back to cell
		name = regula_prisoner_event.1004.a

		scope:actor = {
			trigger_event = regula_prisoner_event.1000
		}
	}

	option = { # Leave them.
		name = regula_prisoner_event.1004.b

		scope:recipient = {
			remove_character_flag = is_naked
		}
	}
}

# Love spell - basic
regula_prisoner_event.1005 = {
	type = character_event
	title = regula_prisoner_event.1005.t
	desc = regula_prisoner_event.1005.desc

	theme = dungeon
	override_background = {
		reference = regula_cell
	}

	right_portrait = {
		character = scope:recipient
		outfit_tags = { no_cloak no_hat no_pants no_clothes }
		animation = beg
	}

	immediate = {
		regula_prisoner_love_charm_effect = {
			TARGET = scope:recipient
			CHARMER = scope:actor
		}
	}

	option = { # Back to cell
		name = regula_prisoner_event.1005.a

		scope:actor = {
			trigger_event = regula_prisoner_event.1000
		}
	}

	option = { # Leave them.
		name = regula_prisoner_event.1005.b

		scope:recipient = {
			remove_character_flag = is_naked
		}
	}
}

# Contubernalis
regula_prisoner_event.1006 = {
	type = character_event
	title = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:actor = {
						has_execute_reason = scope:recipient
					}
				}
				desc = regula_prisoner_event.1006.t_criminal
			}
			triggered_desc = {
				trigger = {
					scope:recipient = {
						is_regula_trigger = yes
					}
				}
				desc = regula_prisoner_event.1006.t_regula
			}
			desc = regula_prisoner_event.1006.t_default
		}
	}

	desc = {
		# Attack
		random_valid = {
			triggered_desc = {
				trigger = { 
					scope:recipient = {
						OR = {
							has_trait = giant
							has_trait = strong
							has_trait = athletic
							has_trait = physique_good
							prowess >= 20
						}
					} 
				}
				desc = regula_prisoner_event.1006.attack_strong
			}
			desc = regula_prisoner_event.1006.attack_default
			desc = regula_prisoner_event.1006.attack_chained
		}

		# Resist
		random_valid = {
			triggered_desc = {
				trigger = { 
					scope:recipient = {
						OR = {
							ai_compassion > 50
							ai_rationality > 50
							has_trait = craven
							has_trait = content
							has_trait = forgiving
							has_trait = shy
							has_trait = trusting
							has_trait = deceitful
						}
					} 
				}
				desc = regula_prisoner_event.1006.resist_beg
			}
			triggered_desc = {
				trigger = { 
					scope:recipient = {
						OR = {
							ai_boldness > 50
							ai_vengefulness > 50
							has_trait = brave
							has_trait = vengeful
							has_trait = wrathful
							has_trait = stubborn
							has_trait = arrogant
						}
					} 
				}
				desc = regula_prisoner_event.1006.resist_angry
			}
			triggered_desc = {
				trigger = { 
					scope:recipient = {
						OR = {
							opinion = {
								target = scope:actor
								value >= 50
							}
							has_trait = lustful
							has_relation_lover = scope:actor
						}
					} 
				}
				desc = regula_prisoner_event.1006.resist_lustful
			}
			desc = regula_prisoner_event.1006.resist_default
		}

		# Succumb
		random_valid = {
			triggered_desc = {
				trigger = { 
					scope:actor = {
						has_trait_rank = {
							trait = magister_trait_group
							rank >= 5
						} 
					}
				}
				desc = regula_prisoner_event.1006.succumb_expert
			}
			triggered_desc = {
				trigger = { 
					scope:actor = {
						OR = {
							has_trait = callous
							has_trait = sadistic
							has_trait = wrathful
						}
					}
				}
				desc = regula_prisoner_event.1006.succumb_mean
			}
			desc = regula_prisoner_event.1006.succumb_default
		}

		# Ending
		random_valid = {
			triggered_desc = {
				trigger = { scope:recipient = { has_trait = intellect_good } }
				desc = regula_prisoner_event.1006.ending_mindbroken
			}
			desc = regula_prisoner_event.1006.ending_default
		}
	}

	theme = dungeon
	override_background = {
		reference = regula_cell
	}

	right_portrait = {
		character = scope:recipient
		outfit_tags = { no_cloak no_hat no_pants no_clothes }
		animation = fear
	}

	immediate = {
		scope:actor = {
			if = {
				limit = { NOT = { faith = { has_doctrine_parameter = contubernalis_realm_benefits } } }
				add_piety = -500
			}
			add_dread = medium_dread_gain
			regula_gain_create_contubernalis_tyranny = yes
		}

		# Remove all criminal reasons since this is a harsh punishment.
		consume_all_criminal_reasons_effect = {
			LIEGE = scope:actor
			CRIMINAL = scope:recipient
		}

		# Iterate the Contubernalis counter
		change_global_variable = {
			name = regula_contubernalis_tally
			add = 1
		}
	}

	option = { # It is done.
		name = regula_prisoner_event.1006.a

		regula_turn_into_contubernalis = {
			ACTOR = scope:actor
			VICTIM = scope:recipient
		}

		scope:recipient = {
			release_from_prison = yes
			remove_character_flag = is_naked
		}
		
		scope:actor = {
			add_courtier = scope:recipient
			make_concubine = scope:recipient
		}
	}
}