﻿
#Triggers for Shunned and Criminal Secret Types


# SECRET DEVIANT
secret_deviant_is_valid_trigger = {
	$OWNER$ = {
		NOT = {
			has_trait = deviant
		}
	}
}

secret_deviant_is_shunned_trigger = {
	$OWNER$ = {
		OR = {
			faith = { has_doctrine_parameter = deviancy_shunned }
			any_liege_or_above = { faith = { has_doctrine_parameter = deviancy_shunned } }
		}
	}
}

secret_deviant_is_criminal_trigger = {
	$OWNER$ = {
		OR = {
			faith = { has_doctrine_parameter = deviancy_illegal }
			any_liege_or_above = { faith = { has_doctrine_parameter = deviancy_illegal } }
		}
	}
}
# SECRET DEVIANT - END

# SECRET HOMOSEXUAL
secret_homosexual_is_valid_trigger = {
	$OWNER$ = {
		NOT = {
			has_trait = sodomite
		}
		is_male = yes #Only for men since it is localized as Sodomite and also because female homosexuality historically hasn't been "a big deal" in most cultures
	}
}

secret_homosexual_is_shunned_trigger = {
	$OWNER$ = {
		OR = {
			faith = { has_doctrine_parameter = homosexuality_shunned }
			any_liege_or_above = { faith = { has_doctrine_parameter = homosexuality_shunned } }
		}
	}
}

secret_homosexual_is_criminal_trigger = {
	$OWNER$ = {
		OR = {
			faith = { has_doctrine_parameter = homosexuality_illegal }
			any_liege_or_above = { faith = { has_doctrine_parameter = homosexuality_illegal } }
		}
	}
}
# SECRET HOMOSEXUAL - END

# SECRET MURDER ATTEMPT
secret_murder_attempt_is_valid_trigger = {
	NOT = { $OWNER$ = $TARGET$ } # Murder requires two people

	trigger_if = { # If the target is dead, check that the killer isn't the owner since then the attempt isn't really an attempt...
		limit = {
			$TARGET$ = { is_alive = no }
			exists = $TARGET$.killer
		}
		NOT = {
			$TARGET$.killer = $OWNER$
		}
	}
}

secret_murder_attempt_is_shunned_trigger = {
	$TARGET$ = {
		save_temporary_scope_as = attempted_murder_target
	}
	$OWNER$ = {
		OR = {
			NOT = { exists = liege }
			any_liege_or_above = {
				NOR = {
					this = scope:attempted_murder_target
					is_spouse_of = scope:attempted_murder_target
					is_close_family_of = scope:attempted_murder_target
				}
			}
			#You are your own liege (independent) or have no liege (pool)
			liege = this
		}
	}
}

secret_murder_attempt_is_criminal_trigger = {
	$TARGET$ = {
		save_temporary_scope_as = attempted_murder_target
	}
	$OWNER$ = {
		any_liege_or_above = {
			NOR = {
				this = scope:attempted_murder_target
				is_spouse_of = scope:attempted_murder_target
				is_close_family_of = scope:attempted_murder_target
			}
		}
	}
}
#SECRET MURDER ATTEMPT - END

# SECRET CANNIBAL
secret_cannibal_is_valid_trigger = {
	$OWNER$ = {
		NOT = { has_trait = cannibal }
	}
}

secret_cannibal_is_shunned_trigger = {
	$OWNER$ = { always = no }
}

secret_cannibal_is_criminal_trigger = {
	$OWNER$ = {
		OR = {
			faith = {
				NOT = { has_doctrine_parameter = cannibalism_legal }
			}
			any_liege_or_above = {
				faith = {
					NOT = { has_doctrine_parameter = cannibalism_legal }
				}
			}
		}
	}
}
# SECRET CANNIBAL - END

# SECRET LOVER
secret_lover_is_valid_trigger = {
	$TARGET$ = {
		save_temporary_scope_as = target
	}
	$OWNER$ = {
		has_relation_lover = scope:target
		NOT = { is_consort_of = scope:target }
	}
}

#Placed ahead of the Shunned trigger, so that the shunned trigger can refer back to this
secret_lover_is_criminal_trigger = {
	$TARGET$ = { save_temporary_scope_as = criminal_partner } #Different name to the scope in the shunned trigger, to prevent issues
	$OWNER$ = {
		OR = {
			#Female adultery criminal
			AND = {
				is_female = yes
				OR = {
					faith = { has_doctrine_parameter = adultery_female_crime }
					any_liege_or_above = { faith = { has_doctrine_parameter = adultery_female_crime } }
				}
			}
			#Male adultery criminal
			AND = {
				is_male = yes
				OR = {
					faith = { has_doctrine_parameter = adultery_male_crime }
					any_liege_or_above = { faith = { has_doctrine_parameter = adultery_male_crime } }
				}
			}
			#Sodomy criminal
			AND = {
				is_male = yes
				scope:criminal_partner = { is_male = yes }
				OR = {
					faith = { has_doctrine_parameter = homosexuality_illegal }
					any_liege_or_above = { faith = { has_doctrine_parameter = homosexuality_illegal } }
				}
			}
		}
	}	
}

secret_lover_is_shunned_trigger = {
	$TARGET$ = { save_temporary_scope_as = partner }
	$OWNER$ = {
		save_temporary_scope_as = lover_owner
		OR = {
			#Female adultery shunned
			AND = {
				is_female = yes
				OR = {
					faith = { has_doctrine_parameter = adultery_female_shunned }
					any_liege_or_above = { faith = { has_doctrine_parameter = adultery_female_shunned } }
				}
			}
			#Male adultery shunned
			AND = {
				is_male = yes
				OR = {
					faith = { has_doctrine_parameter = adultery_male_shunned }
					any_liege_or_above = { faith = { has_doctrine_parameter = adultery_male_shunned } }
				}
			}
			#Sodomy shunned
			AND = {
				is_male = yes
				scope:partner = { is_male = yes }
				OR = {
					faith = { has_doctrine_parameter = homosexuality_shunned }
					any_liege_or_above = { faith = { has_doctrine_parameter = homosexuality_shunned } }
				}
			}
			#Incest is shunned
			relation_with_character_is_incestuous_in_faith_trigger = { CHARACTER = scope:partner FAITH = scope:lover_owner.faith }
			any_liege_or_above = {
				save_temporary_scope_as = liege_or_above
				scope:lover_owner = {
					relation_with_character_is_incestuous_in_faith_trigger = { CHARACTER = scope:partner FAITH = scope:liege_or_above.faith }
				}
			}
		}
		#And it doesn't fulfill the criminal conditions
		NOT = {
			secret_lover_is_criminal_trigger = {
				OWNER = scope:lover_owner
				TARGET = scope:partner
			}	
		}
	}	
}
# SECRET LOVER - END

# SECRET MURDER
secret_murder_is_trivial_trigger = {
	#Is the murderer important enough to get away with it?
	$OWNER$ = { highest_held_title_tier >= tier_county }
	#Is it a murder that people might care about?
	OR = {
		#Independent rulers have little fear in terms of legal consequences for their actions.
		$OWNER$ = { is_independent_ruler = yes }
		#Otherwise, certain victims are just not worth a strong hook.
		$TARGET$ = {
			NOR = {
				#If landless or a baron, must have no important landed family.
				AND = {
					OR = {
						is_ruler = no
						highest_held_title_tier = tier_barony
					}
					any_close_or_extended_family_member = { highest_held_title_tier >= $OWNER$.primary_title.tier }
				}
				#Otherwise, characters who are two tiers lower than you arguably aren't nearly as much of a concern (again, providing they lack important family).
				AND = {
					tier_difference = {
						target = $OWNER$
						value >= -1
					}
					#Be a bit harsher with this, as these characters are the most likely to be relatives of the $OWNER$'s piers.
					any_close_or_extended_family_member = {
						tier_difference = {
							target = $OWNER$
							value >= -1
						}
					}
				}
			}
		}
	}
}

secret_murder_is_valid_trigger = {
	$TARGET$ = {
		is_alive = no
		killer = $OWNER$
	}
}

#Murder attempts again unimportant characters are considered less serious.
secret_murder_is_shunned_trigger = {
	$OWNER$ = {
		secret_murder_is_trivial_trigger = {
			OWNER = $OWNER$
			TARGET = $TARGET$
		}
	}
}

#If any of the get-out-if-imprisonment free clauses don't apply, then the murder is criminal
secret_murder_is_criminal_trigger = {
	$OWNER$ = {
		NOT = {
			$OWNER$ = {
				secret_murder_is_trivial_trigger = {
					OWNER = $OWNER$
					TARGET = $TARGET$
				}
			}
		}
	}
}
# SECRET MURDER - END

# SECRET NON-BELIEVER
secret_non_believer_is_valid_trigger = {
	$OWNER$ = {
		NOT = {
			has_character_modifier = known_non_believer
		}
	}
}

secret_non_believer_is_shunned_trigger = {
	$OWNER$ = { is_clergy = no 	}
}

secret_non_believer_is_criminal_trigger = {
	$OWNER$ = { is_clergy = yes }
}
# SECRET NON-BELIEVER - END

# SECRET INCEST
secret_incest_is_valid_trigger = {
	$OWNER$ = {
		NOT = {
			has_trait = incestuous
		}
	}
}

secret_incest_is_shunned_trigger = {
	$OWNER$ = {
		OR = {
			faith = { NOT = { has_doctrine_parameter = allows_unrestricted_marriage } }
			any_liege_or_above = { faith = { NOT = { has_doctrine_parameter = allows_unrestricted_marriage } } }
		}
	}
}

secret_incest_is_criminal_trigger = {
	$OWNER$ = { always = no }
}
# SECRET INCEST - END

# SECRET WITCH
secret_witch_is_valid_trigger = {
	$OWNER$ = {
		NOT = {
			has_trait = witch
		}
	}
}

secret_witch_is_shunned_trigger = {
	$OWNER$ = {
		OR = {
			faith = { has_doctrine_parameter = witchcraft_shunned }
			any_liege_or_above = { faith = { has_doctrine_parameter = witchcraft_shunned } }
		}
	}
}

secret_witch_is_criminal_trigger = {
	$OWNER$ = {
		OR = {
			faith = { has_doctrine_parameter = witchcraft_illegal }
			any_liege_or_above = { faith = { has_doctrine_parameter = witchcraft_illegal } }
		}
	}
}
# SECRET WITCH - END

# SECRET CRYPTO-RELIGIONIST
# Don't add the crypto-religionist trait if they practice that faith in the open
secret_crypto_religionist_is_valid_trigger = {
	$OWNER$ = {
		AND = {
			exists = secret_faith
			NOT = { secret_faith = $OWNER$.faith }
		}
	}
}

# Same as secret non-believer
secret_crypto_religionist_is_shunned_trigger = {
	$OWNER$ = { is_clergy = no 	}
}

secret_crypto_religionist_is_criminal_trigger = {
	$OWNER$ = { is_clergy = yes }
}
# SECRET CRYPTO-RELIGIONIST - END

# SECRET EMBEZZLER
secret_embezzler_is_valid_trigger = {
	# Can't embezzle from yourself.
	## Well, you can.
	### That's honestly even a fairly common white collar crime.
	#### You just can't in-game.
	##### One rule for the wealthy, another for the rest of us [sigh].
	NOT = { $OWNER$ = $TARGET$ }
}

# Embezzler is only criminal if the target is your liege _and_ the amount is very high.

secret_embezzler_is_criminal_trigger = {
	$OWNER$ = {
		any_secret = {
			secret_type = secret_embezzler
			secret_target ?= $OWNER$.liege
			var:embezzlement_stake >= {
				value = $OWNER$.monumental_gold_value
				multiply = 1.5
			}
		}
	}
	
}
# SECRET EMBEZZLER - END

# SECRET COUP_LEADER
secret_coup_plotter_is_valid_trigger = {
	# Can't coup yourself
	NOT = { $OWNER$ = $TARGET$ }
	# Both of y'all must still be admin
	$OWNER$ = { has_government = administrative_government }
	$TARGET$ = { has_government = administrative_government }
}

secret_coup_plotter_is_criminal_trigger = {
	always = yes 
}
# SECRET COUP_LEADER - END

secret_raid_estate_is_valid_trigger = {
	NOT = { $OWNER$ = $TARGET$ }
}

secret_raid_estate_is_criminal_trigger = {
	NOT = {
		$OWNER$.var:raid_estate_permission ?= $TARGET$.house
	}
}
