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

############################
# General Faction Triggers #
############################
############################
immune_to_factions_trigger = {
	OR = {
		# 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
		}
	}
	
	# You cannot start a faction against your bloc members
	trigger_if = {
		limit = {
			government_is_japanese_trigger = yes
			$FACTION_TARGET$ = { government_is_japanese_trigger = yes }
			exists = house.house_confederation
			exists = $FACTION_TARGET$.house.house_confederation
		}
		custom_tooltip = {
			text = house_confederation_faction_blocker_tt
			house.house_confederation != $FACTION_TARGET$.house.house_confederation
		}
	}
	
	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
	}
	
	# You cannot join a faction against your bloc members
	trigger_if = {
		limit = {
			government_is_japanese_trigger = yes
			$FACTION_TARGET$ = { government_is_japanese_trigger = yes }
			exists = house.house_confederation
			exists = $FACTION_TARGET$.house.house_confederation
		}
		custom_tooltip = {
			text = house_confederation_join_faction_blocker_tt
			house.house_confederation != $FACTION_TARGET$.house.house_confederation
		}
	}
}

common_can_character_create_trigger = {
	NOT = { has_truce = $FACTION_TARGET$ }
	common_character_validity_trigger = {
		FACTION_TARGET = $FACTION_TARGET$
	}
	trigger_if = {
		limit = {
			government_has_flag = government_has_house_blocs
			$FACTION_TARGET$ = top_liege
			is_confederation_member = yes
		}
		custom_tooltip = {
			text = is_house_head_of_noble_family_tt
			OR = {
				joined_faction ?= {
					any_faction_member = {
						OR = {
							this = root.house.house_confederation.leading_house.house_head
							is_ai = no
						}
					}
				}
				AND = {
					is_house_head = yes
					any_held_title = { is_noble_family_title = yes }
				}
				AND = {
					house.house_confederation.leading_house.house_head ?= {
						tgp_is_ceremonial_liege_trigger = yes
					}
					joined_faction.faction_leader ?= {
						is_leading_faction_type = restore_ceremonial_liege_faction
					}
				}
			}
		}
		custom_tooltip = {
			text = must_be_leading_house_of_bloc_trigger
			OR = {
				joined_faction ?= {
					any_faction_member = {
						OR = {
							this = root.house.house_confederation.leading_house.house_head
							is_ai = no
						}
					}
				}
				house.house_confederation.leading_house ?= house
				AND = {
					house.house_confederation.leading_house.house_head ?= {
						tgp_is_ceremonial_liege_trigger = yes
					}
					joined_faction.faction_leader ?= {
						is_leading_faction_type = restore_ceremonial_liege_faction
					}
				}
			}
		}
	}
	####
	# 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 = { }
			}
		}
	}
}

############################
# Liberty Faction Triggers #
############################

has_valid_realm_laws_for_liberty_faction_trigger = {
	trigger_if = {
		limit = { $TARGET$ = { realm_law_use_imperial_bureaucracy = yes } }
		custom_description = {
			text = has_lowest_imperial_bureaucracy
			subject = $TARGET$
			$TARGET$ = {
				OR = {
					has_realm_law = imperial_bureaucracy_1
					has_realm_law = imperial_bureaucracy_2
					has_realm_law = imperial_bureaucracy_3
				}
			}
		}
	}
	trigger_else_if = {
		limit = { $TARGET$ = { government_has_flag = government_is_tribal } }
		custom_description = {
			text = has_lowest_tribal_authority
			subject = $TARGET$
			$TARGET$ = {
				OR = {
					has_realm_law = tribal_authority_1
					has_realm_law = tribal_authority_2
					has_realm_law = tribal_authority_3
				}
			}
		}
	}
	trigger_else_if = {
		limit = { $TARGET$ = { realm_law_use_celestial_bureaucracy = yes } }
		custom_description = {
			text = has_lowest_celestial_bureaucracy
			subject = $TARGET$
			$TARGET$ = {
				OR = {
					has_realm_law = celestial_bureaucracy_1
					has_realm_law = celestial_bureaucracy_2
					has_realm_law = celestial_bureaucracy_3
				}
			}
		}
	}
	trigger_else_if = {
		limit = { $TARGET$ = { realm_law_use_meritocratic_bureaucracy = yes } }
		custom_description = {
			text = has_lowest_meritocratic_bureaucracy
			subject = $TARGET$
			$TARGET$ = {
				OR = {
					has_realm_law = meritocratic_bureaucracy_1
					has_realm_law = meritocratic_bureaucracy_2
					has_realm_law = meritocratic_bureaucracy_3
				}
			}
		}
	}
	trigger_else_if = {
		limit = { $TARGET$ = { realm_law_use_japanese_bureaucracy = yes } }
		custom_description = {
			text = has_lowest_japanese_bureaucracy
			subject = $TARGET$
			$TARGET$ = {
				OR = {
					has_realm_law = japanese_bureaucracy_1
					has_realm_law = japanese_bureaucracy_2
					has_realm_law = japanese_bureaucracy_3
				}
			}
		}
	}
	trigger_else = {
		custom_description = {
			text = has_lowest_crown_authority
			subject = $TARGET$
			$TARGET$ = {
				OR = {
					has_realm_law = crown_authority_1
					has_realm_law = crown_authority_2
					has_realm_law = crown_authority_3
				}
			}
		}
	}
}

#############################
# Japanese Faction Triggers #
#############################
can_become_leader_of_faction_trigger = {
	is_playable_character = yes
	tgp_is_ceremonial_liege_trigger = no
	trigger_if = {
		limit = {
			government_has_flag = government_has_house_blocs
		}
		OR = {
			is_confederation_member = no
			house.house_confederation.leading_house ?= house
			AND = {
				house.house_confederation.leading_house.house_head ?= {
					tgp_is_ceremonial_liege_trigger = yes
				}
				joined_faction.faction_leader ?= {
					is_leading_faction_type = restore_ceremonial_liege_faction
				}
			}
			NOT = { exists = faction_leader }
		}
	}
}
