﻿################
# SECRET FAITH EVENTS #
################

namespace = secret_faith

#secret_faith.1001-1999 - Guardian converts ward

##########################
# GUARDIAN CONVERTS WARD #
##########################

secret_faith.1001 = {
	hidden = yes
	
	trigger = {
		any_relation = {
			type = guardian
			exists = secret_faith
			save_temporary_scope_as = guardian
		}
		NOR = {
			exists = secret_faith
			faith = scope:guardian.secret_faith
		}
	}

	immediate = {
		save_scope_as = child
		#If guardian and child is AI, immediately convert them
		if = {
			limit = {
				is_ai = yes
				any_relation = {
					type = guardian
					is_ai = yes
					has_trait = zealous
				}
			}
			random_relation = {
				type = guardian
				save_scope_as = guardian
			}
			child_secret_faith_conversion_success_effect = yes
		}
		else = {
			random_relation = {
				type = guardian 
				trigger_event = secret_faith.1002 
			}
		}
	}
}

scripted_trigger secret_faith_1002_allow_reveal_outcome_trigger = {
	exists = scope:child.liege
	scope:guardian = {
		this != scope:child.liege
		any_secret = {
			type = secret_crypto_religionist
			OR = {
				NOT = { is_known_by = scope:child }
				NOT = { is_known_by = scope:child.liege }
			}
		}
	}
}

#Guardian: convert this child?
secret_faith.1002 = {
	type = character_event
	title = secret_faith.1002.t
	desc = secret_faith.1002.desc
	theme = education
	left_portrait = scope:child

	#So that we don't abandon our secret_faith inbetween the hidden event and this event triggering
	trigger = {
		exists = secret_faith
		scope:child = {
			NOR = {
				exists = secret_faith
				faith = root.secret_faith
			}
		}
	}

	immediate = { save_scope_as = guardian }
	
	#Convert them
	option = {
		name = secret_faith.1002.a

		#Duel if child is AI
		if = {
			limit = { scope:child = { is_ai = yes } }
			duel = {
				skill = learning
				target = scope:child
				50 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = 2.5
					}
					opinion_modifier = {
						who = scope:child
						opinion_target = scope:guardian
						multiplier = 0.25
						step = 5
					}
					modifier = {
						scope:child = { has_trait = ambitious }
						add = 20
					}
					modifier = {
						scope:child = { has_trait = curious }
						add = 20
					}
					desc = child_secret_faith_conversion_success_effect.desc
					child_secret_faith_conversion_success_effect = yes
				}
				35 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = -2.5
					}
					opinion_modifier = {
						who = scope:child
						opinion_target = scope:guardian
						multiplier = -0.25
						step = 5
					}
					modifier = {
						scope:child = { has_trait = craven }
						add = 30
					}
					desc = child_secret_faith_conversion_failure_effect.desc
					child_secret_faith_conversion_failure_effect = yes
				}
				15 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = -2.5
					}
					opinion_modifier = {
						who = scope:child
						opinion_target = scope:guardian
						multiplier = -0.25
						step = 5
					}
					modifier = {
						scope:child = { has_trait = zealous }
						add = 150
					}
					trigger = {
						secret_faith_1002_allow_reveal_outcome_trigger = yes
					}
					desc = child_secret_faith_conversion_critical_failure_effect.desc
					child_secret_faith_conversion_critical_failure_effect = yes
				}
			}
		}
		else = {
			show_as_tooltip = {
				random_list = {
					1 = {
						show_chance = no
						desc = child_secret_faith_conversion_success_effect.desc
						child_secret_faith_conversion_success_effect = yes
					}
					1 = {
						show_chance = no
						desc = child_secret_faith_conversion_failure_effect.desc
						child_secret_faith_conversion_failure_effect = yes
					}
					1 = {
						show_chance = no
						trigger = {
							secret_faith_1002_allow_reveal_outcome_trigger = yes
						}
						desc = child_secret_faith_conversion_critical_failure_effect.desc
						child_secret_faith_conversion_critical_failure_effect = yes
					}
				}
			}

			scope:child = {
				trigger_event = secret_faith.1003
			}
		}
		
		ai_chance = {
			base = 100

			ai_boldness_target_modifier = { VALUE = 50 }
		}
	}

	#Don't risk it
	option = {
		name = secret_faith.1002.b

		ai_chance = {
			base = 0

			ai_boldness_target_modifier = { VALUE = -100 }
		}
	}
}

secret_faith.1003 = {
	type = character_event
	title = secret_faith.1003.t
	desc = secret_faith.1003.desc
	theme = education
	left_portrait = {
		character = scope:guardian
		animation = personality_dishonorable
	}



	#Yes
	option = {
		name = secret_faith.1003.a
		
		child_secret_faith_conversion_success_effect = yes
	}

	#No...
	option = {
		name = secret_faith.1003.b

		child_secret_faith_conversion_failure_effect = yes
	}
	
	#I will tell someone!
	option = {
		trigger = {
			secret_faith_1002_allow_reveal_outcome_trigger = yes
		}
		name = secret_faith.1003.c

		child_secret_faith_conversion_critical_failure_effect = yes
	}
}
