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?
		event_background = 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 = {
				NOT = { has_trait = devoted_trait_group }
				NOT = { has_trait = contubernalis }
			}
			scope:actor = { 
				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 = -50
			}
		}
		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
		}
	}

	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 = {
			carn_had_sex_with_effect = {
				CHARACTER_1 = scope:actor
				CHARACTER_2 = scope:recipient
				C1_PREGNANCY_CHANCE = pregnancy_chance
				C2_PREGNANCY_CHANCE = pregnancy_chance
				STRESS_EFFECTS = yes
				DRAMA = no
			}
		}
		scope:actor = {
			trigger_event = regula_prisoner_event.1003 # Masquerade
		}
	}

	option = { # Pretend to be lover? Become her lover. Also removes rival relationship.  
		name = regula_prisoner_event.1000.d
		flavor = regula_prisoner_event.1000.d.tt
		trigger = {
			scope:actor = { 
				custom_description = {
					text = magister_trait_4_required_trigger
					has_trait_rank = {
						trait = magister_trait_group 
						rank >= 4
					}
				}
				
				NOT = { has_relation_lover = scope:recipient }
			}
			scope:recipient = {
				OR = {
					is_married = yes
					num_of_relation_lover >= 1
				}
				NOT = { is_spouse_of = scope:actor }
			}
		}

		show_as_tooltip = {
			carn_had_sex_with_effect = {
				CHARACTER_1 = scope:actor
				CHARACTER_2 = scope:recipient
				C1_PREGNANCY_CHANCE = pregnancy_chance
				C2_PREGNANCY_CHANCE = pregnancy_chance
				STRESS_EFFECTS = yes
				DRAMA = no
			}
			scope:recipient = {
				if = {
					limit = { num_of_relation_lover >=1 }
					scope:recipient = {
						random_relation = {
							type = lover
							lover_breakup_effect = {
								BREAKER = scope:recipient
								LOVER = this
							}
						}
					}
				}
			}
			scope:actor = {
				set_relation_lover = scope:recipient
			}
		}
		scope:actor = {
			trigger_event = regula_prisoner_event.1004
		}
		# scope:recipient = {  # Better as a cuckhold thing.
		# 	if = {
		# 		limit = {
		# 			OR = {
		# 				is_married = yes
		# 				num_of_relation_lover >= 1
		# 			}
		# 			NOT = { is_spouse_of = scope:actor }
		# 		}
		# 		scope:actor = {
		# 			trigger_event = regula_prisoner_event.1004 # Masquerade
		# 		}
		# 	}
		# 	else = {
		# 		scope:actor = {
		# 			trigger_event = regula_prisoner_event.1005 # Love spell
		# 		}
		# 	}
		# }
	}

	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 = { 
				custom_description = {
					text = magister_trait_4_required_trigger
					has_trait_rank = {
						trait = magister_trait_group 
						rank >= 5
					}
				}
			}
			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 >= 5
					}
				}
			}
			scope:recipient = {
				NOT = { has_trait = contubernalis }
			}
			scope:actor = {
				piety < 500
			}
		}
		
		show_as_tooltip = {  ### UPDATE - Add a note about their relations disliking this?
			scope:recipient = {
				if = {
					limit = {
						is_ruler = yes
					}
					depose = yes
				}
				if = {
					limit = { is_married = yes }
					every_spouse = {
						divorce = scope:recipient
					}
				}
				set_sexuality = bisexual
				add_trait = contubernalis
				set_immortal_age = 20
			}
			carn_had_sex_with_effect = {
				CHARACTER_1 = scope:actor
				CHARACTER_2 = scope:recipient
				C1_PREGNANCY_CHANCE = pregnancy_chance
				C2_PREGNANCY_CHANCE = pregnancy_chance
				STRESS_EFFECTS = yes
				DRAMA = no
			}
			scope:actor = {
				add_piety = -500
				add_dread = medium_dread_gain
				add_tyranny = 10
			}
		}
		scope:actor = {
			trigger_event = regula_prisoner_event.1006
		}
	}

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

	after = {
	}
}

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

	theme = dungeon
	override_background = {
		event_background = regula_cell
	}

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

	immediate = {
		scope:recipient = {
			fascinare_success_effect = { CHARACTER = root }
			# if = {
			# 	limit = {
			# 		NOT = { has_trait = deviant }
			# 	}
			# 	add_trait = deviant ### UPDAGE - Not really appropriate.  Need to make a bondage-specific trait.
			# }
		}
		scope:actor = {
			add_piety = -50
		}
	}

	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 = {
		event_background = 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 = {
		event_background = regula_cell
	}

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

	immediate = {
		carn_had_sex_with_effect = {
			CHARACTER_1 = scope:actor
			CHARACTER_2 = scope:recipient
			C1_PREGNANCY_CHANCE = pregnancy_chance
			C2_PREGNANCY_CHANCE = pregnancy_chance
			STRESS_EFFECTS = yes
			DRAMA = no
		}
	}

	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 = {
		event_background = regula_cell
	}

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


	immediate = {
		if = {
			limit = {
				num_of_relation_lover = 0
			}
			scope:recipient.primary_spouse = {
				save_scope_as = old_lover
			}
		}
		else = {
			scope:relation = {
				random_relation = {
					type = lover
					save_scope_as = old_lover
				}
			}
		}
		carn_had_sex_with_effect = {
			CHARACTER_1 = scope:actor
			CHARACTER_2 = scope:recipient
			C1_PREGNANCY_CHANCE = pregnancy_chance
			C2_PREGNANCY_CHANCE = pregnancy_chance
			STRESS_EFFECTS = yes
			DRAMA = no
		}
		scope:recipient = {
			every_relation = {
				type = lover
				lover_breakup_effect = {
					BREAKER = scope:recipient
					LOVER = this
				}
			}
		}
		scope:recipient = {
			remove_relation_nemesis = scope:actor
			remove_relation_rival = scope:actor
		}
		scope:actor = {
			set_relation_lover = scope:recipient
		}
	}

	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 = {
		event_background = regula_cell
	}

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

	immediate = {
		carn_had_sex_with_effect = {
			CHARACTER_1 = scope:actor
			CHARACTER_2 = scope:recipient
			C1_PREGNANCY_CHANCE = pregnancy_chance
			C2_PREGNANCY_CHANCE = pregnancy_chance
			STRESS_EFFECTS = yes
			DRAMA = no
		}
		scope:recipient = {
			remove_relation_nemesis = scope:actor
			remove_relation_rival = scope:actor
		}
		scope:actor = { # Remove rival flag?
			set_relation_lover = scope:recipient
		}
	}

	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
		}
	}
}

# Contubernalis
regula_prisoner_event.1006 = {
	type = character_event
	title = regula_prisoner_event.1006.t
	desc = regula_prisoner_event.1006.desc

	theme = dungeon
	override_background = {
		event_background = regula_cell
	}

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

	immediate = { ## Warp appearance? (beauty trait or otherwise).
		scope:recipient = {
			every_close_family_member = { # Opinion hits first.
				limit = { NOT = { this = scope:actor } }
				add_to_temporary_list = victim_family_list
			}
			every_spouse = {
				limit = {
					NOR = {
						this = scope:actor
						is_in_list = victim_family_list
					}
				}
				add_to_temporary_list = victim_family_list
			}
			
			if = {
				limit = {
					any_in_list = {
						list = victim_family_list
						count > 0
					}
				}
				if = {
					limit = {
						scope:actor = {
							has_execute_reason = scope:recipient
						}
					}
					every_in_list = {
						list = victim_family_list
						custom = all_close_family_and_spouses
						add_opinion = {
							target = scope:actor
							modifier = regula_contubernalis_close_family_opinion
						}
					}
				}
				else = {
					every_in_list = {
						list = victim_family_list
						custom = all_close_family_and_spouses
						add_opinion = {
							target = scope:actor
							modifier = regula_contubernalis_close_family_crime_opinion
						}
					}
				}
			}

			# Victim's dynasty hates executioner
			if = {
				limit = {
					exists = dynasty
					exists = scope:actor.dynasty
					NOT = { dynasty = scope:actor.dynasty }
					NOT = {
						scope:actor = {
							has_execute_reason = scope:recipient
						}
					}
				}
				dynasty = {
					every_dynasty_member = {
						limit = {
							NOR = {
								this = scope:recipient
								is_in_list = victim_family_list
							}
						}
						custom = all_dynasty_members
						add_to_temporary_list = victim_dynasty_list
						add_opinion = {
							target = scope:actor
							modifier = regula_contubernalis_dynasty_member_opinion
						}
					}
				}
			}
			
			# Victim's friends and lovers
			every_relation = {
				type = friend
				limit = {
					NOR = {
						this = scope:recipient
						is_in_list = victim_family_list
						is_in_list = victim_dynasty_list
					}
				}
				add_to_list = victim_close_relations_list
			}
			every_relation = {
				type = lover
				limit = {
					NOR = {
						this = scope:recipient
						is_in_list = victim_family_list
						is_in_list = victim_dynasty_list
						is_in_list = victim_close_relations_list
					}
				}
				add_to_list = victim_close_relations_list
			}
			if = {
				limit = {
					any_in_list = {
						list = victim_close_relations_list
						always = yes
					}
				}
				every_in_list = {
					list = victim_close_relations_list
					custom = all_friends_and_lovers
					add_opinion = {
						target = scope:actor
						modifier = regula_contubernalis_close_relation_opinion
					}
				}
			}
			# Depose and divorce.
			if = {
				limit = { is_ruler = yes }
				depose = yes
			}
			if = {
				limit = { is_married = yes }
				every_spouse = {
					divorce = scope:recipient
				}
			}
			if = {
				limit = { exists = betrothed }
				break_betrothal = betrothed
			}
			if = {
				limit = { has_trait = mulsa }
				remove_trait = mulsa
			}
			if = {
				limit = { has_trait = paelex }
				remove_trait = paelex
			}
			if = {
				limit = { has_trait = domina }
				remove_trait = domina
			}
			if = {
				limit = { has_trait = orba }
				remove_trait = orba
			}
			add_trait = contubernalis
			set_immortal_age = 20
			set_character_faith = global_var:magister_character.faith
			set_sexuality = bisexual
			carn_increase_beauty_one_step_effect = yes
			carn_remove_all_major_disfigurements_effect = yes
			carn_remove_all_minor_disfigurements_effect = yes
			carn_remove_all_wounds_effect = yes
			carn_had_sex_with_effect = {
				CHARACTER_1 = scope:actor
				CHARACTER_2 = scope:recipient
				C1_PREGNANCY_CHANCE = pregnancy_chance
				C2_PREGNANCY_CHANCE = pregnancy_chance
				STRESS_EFFECTS = yes
				DRAMA = no
			}
		}
		scope:actor = {
			add_piety = -500
			add_dread = medium_dread_gain
			add_tyranny = 10
		}
		# Iterate the Contubernalis counter
		global_var:magister_character = {
			change_variable = {
				name = regula_contubernalis_tally
				add = 1
			}
		}
	}

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

		scope:actor = {
			recruit_courtier = scope:recipient
		}
		scope:recipient = {
			release_from_prison = yes
		}
	}

	option = { # Leave them.
		name = regula_prisoner_event.1000.f

		scope:actor = {
			recruit_courtier = scope:recipient
		}
		scope:recipient = {
			release_from_prison = yes
		}

		scope:recipient = {
			remove_character_flag = is_naked
		}
	}
}