﻿
### TRIGGER LIST ###
# General Triggers:
#	-
#
# Popular Faction Triggers:
#	-
#

############################
# General Faction Triggers #
############################
#EK DISABLED: Genghis Khan doesn't exist
#EK TODO: possibly add our own immune characters here
immune_to_factions_trigger = {
	OR = {
		always = no
		#EK DISABLED
		# Genghis Khan is immune to factions
		#has_character_flag = is_temujin
		# Seljuk leader is immune to factions too
		#has_character_flag = is_seljuk
	}
}

character_has_faction_disabling_modifier_trigger = {
	NOR = {
		has_character_modifier = yearly_close_watch_modifier
		#Add any subsequent character modifiers above this line.
	}
}

common_character_validity_trigger = {
	NOR = { #No prince-bishop can ever join
		government_has_flag = government_is_theocracy
		trigger_if = {
			limit = { exists = cp:councillor_court_chaplain }
			this = cp:councillor_court_chaplain
		}
	}
	OR = {
		$FACTION_TARGET$ = liege
		any_character_active_contract = {
			task_contract_target = $FACTION_TARGET$
		}
	}
	highest_held_title_tier > tier_barony

	#Not blocked through events
	custom_description = {
		text = character_blocked_from_joining
		NOT = {
			has_character_flag = joining_faction_block
		}
	}
	
	NOT = { has_relation_blood_brother = $FACTION_TARGET$ }
}

common_can_character_join_trigger = {
	common_character_validity_trigger = {
		FACTION_TARGET = $FACTION_TARGET$
	}
	is_adult = yes
	NOT = { has_truce = $FACTION_TARGET$ }
	$FACTION_TARGET$ = {
		NOT = { has_strong_hook = root }
		NOT = { is_allied_to = root }
	}

	OR = {
		is_ai = no
		NOR = {
			has_relation_lover = $FACTION_TARGET$ 
			has_relation_friend = $FACTION_TARGET$ 
		}
	}

	$FACTION_TARGET$.highest_held_title_tier > tier_county

	custom_description = {
		text = character_has_faction_disabling_modifier
		character_has_faction_disabling_modifier_trigger = yes
	}
}

common_can_character_create_trigger = {
	NOT = { has_truce = $FACTION_TARGET$ }
	common_character_validity_trigger = {
		FACTION_TARGET = $FACTION_TARGET$
	}
	####
	# BLOCKERS
	####
	# General Faction immunity
	custom_description = {
		text = character_is_immune_to_factions
		subject = $FACTION_TARGET$
		NOT = { $FACTION_TARGET$ = { immune_to_factions_trigger = yes } }
	}
}

base_faction_trigger = {
	NOT = { has_truce = scope:target }
	can_join_or_create_faction_against = {
		who = scope:target
		faction = $FACTION_TYPE$
	}
	scope:target = { NOT = { has_strong_hook = root } }
	trigger_if = {
		limit = {
			exists = scope:recipient
		}
		scope:recipient = {
			NOT = { is_at_war_with = scope:actor }
			NOT = { has_trait = incapable }
		}
	}
}


############################
# Popular Faction Triggers #
############################

character_can_join_popular_faction_trigger = {
	OR = {
		NOT = { faith = $FACTION$.faction_target.faith }
		NOT = { culture = $FACTION$.faction_target.culture }
	}	
}

county_can_join_popular_faction_trigger = {
	OR = {
		NOT = { faith = $FACTION$.faction_target.faith }
		NOT = { culture = $FACTION$.faction_target.culture }
	}	
}

has_active_diarch_for_factions_trigger = {
	exists = $TARGET$.diarch
	NOT = { $TARGET$.faith = $TARGET$.diarch.faith }
}

#factions with only landless adventurers cannot exist
has_valid_faction_members_trigger = {
	trigger_if = {
		limit = {
			is_landless_adventurer = yes
		}
		scope:faction = {
			OR = {
				any_faction_member = {
					is_landless_adventurer = no
					is_forced_into_faction = no
				}
				any_faction_county_member = {
					count >= 1
				}
			}
		}
	}
}
