﻿namespace = regula_change_harem_tenet_event

# Change from Devoted to Scrafice
# Our consorts are being annoying and meddlesome again, change to Contubernalium instead?
# Pick three "bad" consorts and choose whether to turn them into Contunerablis to frighten others
# If we have no "bad" consorts, just generate a pretend noble character
regula_change_harem_tenet_event.1000 = {
	type = character_event
	title = regula_change_harem_tenet_event.1000.t
    desc = {
        desc = regula_change_harem_tenet_event.1000.desc_intro

        triggered_desc = {
			trigger = {
				faith = { exists = scope:consort_lazy_shy_craven }
			}
			desc = regula_change_harem_tenet_event.1000.consort_lazy_shy_craven
		}

		triggered_desc = {
			trigger = {
				faith = { exists = scope:consort_wrathful_callous_sadistic }
			}
			desc = regula_change_harem_tenet_event.1000.consort_wrathful_callous_sadistic
		}

		triggered_desc = {
			trigger = {
				faith = { exists = scope:consort_paranoid_arrogant_deceitful }
			}
			desc = regula_change_harem_tenet_event.1000.consort_paranoid_arrogant_deceitful
		}

		triggered_desc = {
			trigger = {
				faith = { exists = scope:fallback_noble }
			}
			desc = regula_change_harem_tenet_event.1000.fallback_noble
		}
    }
	theme = regula_theme
	override_background = {
		reference = godless_shrine
	}

	left_portrait = {
		trigger = {
			exists = scope:consort_lazy_shy_craven
		}
		character = scope:consort_lazy_shy_craven
		animation = beg
	}

	right_portrait = {
		trigger = {
			exists = scope:consort_wrathful_callous_sadistic
		}
		character = scope:consort_wrathful_callous_sadistic
		animation = anger
	}

	lower_center_portrait = {
		trigger = {
			exists = scope:consort_paranoid_arrogant_deceitful
		}
		character = scope:consort_paranoid_arrogant_deceitful
		animation = fear
	}

	lower_left_portrait = {
		character = scope:fallback_noble
		animation = fear
	}

	immediate = {

		# Try and find consorts that fits the above personalities
		random_consort = {
			limit = {
				OR = {
					ai_boldness <= -30
					ai_sociability <= -30
					has_trait = lazy
					has_trait = shy
					has_trait = craven
				}
			}
			save_scope_as = consort_lazy_shy_craven
		}

		random_consort = {
			limit = {
				OR = {
					ai_vengefulness >= 50
					ai_compassion <= -50
					has_trait = wrathful
					has_trait = callous
					has_trait = sadistic
				}
				NOT = {
					this = scope:consort_lazy_shy_craven
				}
			}
			save_scope_as = consort_wrathful_callous_sadistic
		}

		random_consort = {
			limit = {
				OR = {
					ai_honor <= -30
					ai_zeal <= -30
					ai_rationality <= -30
					has_trait = paranoid
					has_trait = arrogant
					has_trait = deceitful
				}
				NOT = {
					this = scope:consort_lazy_shy_craven
					this = scope:consort_wrathful_callous_sadistic
				}
			}
			save_scope_as = consort_paranoid_arrogant_deceitful
		}

		# Cop out target, just a random "minor" noble aka created character
		create_character = {
			template = regula_annoying_minor_noble_harem_tenet_character
			location = root.location
			faith = root.faith
			culture = root.culture
			save_scope_as = fallback_noble
		}
	}

	# Choose a sacrafice to turn into Contubernalis
	# Also change doctrine for Regula religion

	# "Lazy" consort
	option = {
		trigger = {
			exists = scope:consort_lazy_shy_craven
		}

		name = regula_change_harem_tenet_event.1000.a

		show_as_tooltip = {
			regula_turn_into_contubernalis = {
				ACTOR = root
				VICTIM = scope:consort_lazy_shy_craven
			}
			make_concubine = scope:consort_lazy_shy_craven
			add_courtier = scope:consort_lazy_shy_craven
		}

		scope:consort_lazy_shy_craven = {
			save_scope_as = victim
		}

		hidden_effect = {
			scope:fallback_noble = {
				death = { death_reason = death_vanished }
			}
		}

		trigger_event = regula_change_harem_tenet_event.1001
	}

	# "Sadistic" consort
	option = {
		trigger = {
			exists = scope:consort_wrathful_callous_sadistic
		}

		name = regula_change_harem_tenet_event.1000.b

		show_as_tooltip = {
			regula_turn_into_contubernalis = {
				ACTOR = root
				VICTIM = scope:consort_wrathful_callous_sadistic
			}
			make_concubine = scope:consort_wrathful_callous_sadistic
			add_courtier = scope:consort_wrathful_callous_sadistic
		}

		scope:consort_wrathful_callous_sadistic = {
			save_scope_as = victim
		}

		hidden_effect = {
			scope:fallback_noble = {
				death = { death_reason = death_vanished }
			}
		}

		trigger_event = regula_change_harem_tenet_event.1001
	}

	# "Paranoid" consort
	option = {
		trigger = {
			exists = scope:consort_paranoid_arrogant_deceitful
		}
		name = regula_change_harem_tenet_event.1000.c

		show_as_tooltip = {
			regula_turn_into_contubernalis = {
				ACTOR = root
				VICTIM = scope:consort_paranoid_arrogant_deceitful
			}
			make_concubine = scope:consort_paranoid_arrogant_deceitful
			add_courtier = scope:consort_paranoid_arrogant_deceitful
		}

		scope:consort_paranoid_arrogant_deceitful = {
			save_scope_as = victim
		}

		hidden_effect = {
			scope:fallback_noble = {
				death = { death_reason = death_vanished }
			}
		}

		trigger_event = regula_change_harem_tenet_event.1001
	}

	# Pick the "minor" noble character
	# Cop out for players who dont want to sac an actual character
	option = {
		name = regula_change_harem_tenet_event.1000.d

		show_as_tooltip = {
			regula_turn_into_contubernalis = {
				ACTOR = root
				VICTIM = scope:fallback_noble
			}
			make_concubine = scope:fallback_noble
			add_courtier = scope:fallback_noble
		}

		scope:fallback_noble = {
			save_scope_as = victim
		}

		trigger_event = regula_change_harem_tenet_event.1001
	}

	option = { # Cancel
		name = regula_change_harem_tenet_event.1000.cancel
		add_piety_no_experience = regula_change_harem_tenet_piety_cost
		hidden_effect = {
			remove_decision_cooldown = regula_change_harem_tenet_decision
		}

		hidden_effect = {
			scope:fallback_noble = {
				death = { death_reason = death_vanished }
			}
		}
	}
}

# Turn victim into Contubernalis and change tenet doctrine
regula_change_harem_tenet_event.1001 = {
	type = character_event
	title = regula_change_harem_tenet_event.1001.t
	desc = regula_change_harem_tenet_event.1001.desc
	theme = regula_theme
	override_background = {
		reference = godless_shrine
	}

	left_portrait = {
		character = root
		animation = rage
	}

	right_portrait = {
		character = scope:victim
		animation = lunatic
	}

	# Turn vicitm into Contubernalis
	immediate = {
		regula_turn_into_contubernalis = {
			ACTOR = root
			VICTIM = scope:victim
		}

		add_courtier = scope:victim
		make_concubine = scope:victim
	}

	option = {
		name = regula_change_harem_tenet_event.1001.a

		faith = {
			remove_doctrine = tenet_regula_devoted
			add_doctrine = tenet_regula_sacrifice
		}
	}

	after = {
		# Refresh modifiers
		trigger_event = regula_initialize_event.0015
		trigger_event = regula_initialize_event.0016
	}
}

# Change from Scrafice to Devoted
# We have a change of heart, and decide to free our Contubernalis
# This "kills" all of our current Contubnernalis consorts
regula_change_harem_tenet_event.2000 = {
	type = character_event
	title = regula_change_harem_tenet_event.2000.t
	desc = regula_change_harem_tenet_event.2000.desc
	theme = regula_theme
	override_background = {
		reference = godless_shrine
	}

	left_portrait = {
		character = root
		animation = personality_rational
	}

	right_portrait = {
		character = scope:contubernalis
		animation = throne_room_bow_1
	}

	# Grab a Contubernalis for desc
	immediate = {
		# As part of decision we will need at least one contubernalis to "Free"
		faith = {
			random_faith_character = {
				limit = {
					has_trait = contubernalis
					is_consort_of = root
				}
				save_scope_as = contubernalis
			}
		}

		# If we don't have any contubernalis (or can't find a consort that is one), make one
		if = {
			limit = { NOT = { exists = scope:contubernalis }}
			regula_create_random_lowborn_woman_effect = {
				SAVE_AS = contubernalis
				LOCATION = root.location
				CULTURE = root.culture
				FAITH = root.faith
			}
			scope:contubernalis = {
				add_trait = contubernalis
			}
		}
	}

	# "Free" all Contubernalis (they will die!)
	# Also change doctrine for Regula religion
	option = {
		name = regula_change_harem_tenet_event.2000.a

		show_as_tooltip = {
			faith = {
				add_doctrine = tenet_regula_devoted
				every_faith_character = {
					limit = {
						has_trait = contubernalis
						NOT = { this = scope:contubernalis }
					}
					death = {
						death_reason = death_contubernalis_cutoff_from_magister
					}
				}
			}
		}

		trigger_event = regula_change_harem_tenet_event.2001
	}

	option = { # Cancel
		name = regula_change_harem_tenet_event.2000.cancel
		add_piety_no_experience = regula_change_harem_tenet_piety_cost
		hidden_effect = {
			remove_decision_cooldown = regula_change_harem_tenet_decision
		}
	}
}

# Free all Contubernalis
regula_change_harem_tenet_event.2001 = {
	type = character_event
	title = regula_change_harem_tenet_event.2001.t
	desc = regula_change_harem_tenet_event.2001.desc
	theme = regula_theme
	override_background = {
		reference = godless_shrine
	}

	left_portrait = {
		character = root
		animation = sadness
	}

	right_portrait = {
		character = scope:contubernalis
		animation = dead
	}

	# Change Tenet and kill all Contubernalis
	immediate = {
		# Kill all Contubernalis
		faith = {
			every_faith_character = {
				limit = {
					has_trait = contubernalis
					NOT = { this = scope:contubernalis }
				}
				death = {
					death_reason = death_contubernalis_cutoff_from_magister
				}
			}
		}
	}

	option = {
		name = regula_change_harem_tenet_event.2001.a

		faith = {
			remove_doctrine = tenet_regula_sacrifice
			add_doctrine = tenet_regula_devoted
		}

		scope:contubernalis = {
			death = {
				death_reason = death_contubernalis_cutoff_from_magister
			}
		}
	}

	after = {
		# Refresh modifiers
		trigger_event = regula_initialize_event.0015
		trigger_event = regula_initialize_event.0016
	}
}