#################################################
# TRIGGER LIST 									#
#################################################
# ep1_is_valid_character_for_inspiration_trigger 	- Is the character valid to be used within the inspiration system? Character movement may break if these conditions are not true.

ep1_is_valid_character_for_inspiration_trigger = {
	is_adult = yes
	is_imprisoned = no
	NOT = { exists = inspiration }

	trigger_if = {
		limit = {
			OR = {
				is_pool_guest = yes
				is_in_pool_at = location
			}
		}
		# For simplicity, inspired characters travel solo for now.
		any_traveling_family_member = {
			count = 1
		}
	}
}

ep1_spare_courtier_trigger = { #Used for picking out courtiers in your own court.
	is_available_healthy_ai_adult = yes
	is_councillor = no
	NOR = {
		is_close_or_extended_family_of = root
		is_spouse_of = root
	}
}

# Court type trait 1 is unlocked by court_grandeur_level 5
ep1_courtier_valid_for_court_trait_1_trigger = {
	scope:cgv_value >= cgv_level_threshold_court_type_trait_1
	NOT = { has_trait = $TYPE$_court }
	is_adult = yes
}

# Court type trait 2 is unlocked by court_grandeur_level 8
ep1_courtier_valid_for_court_trait_2_trigger = {
	scope:cgv_value >= cgv_level_threshold_court_type_trait_2
	NOT = { has_trait = $TYPE$_court_2 }
	has_trait = $TYPE$_court_1
	is_adult = yes
}

##############
# INSPIRATION/ARTIFACT TRIGGERS
##############

ep1_can_sponsor_inspiration_basic = {
	scope:inspiration_owner = {
		is_imprisoned = no
	}
}

ep1_is_sponsor_valid_inspiration_basic = {
	trigger_if = {
		limit = {
			exists = scope:inspiration_sponsor
		}
		scope:inspiration_owner = {
			is_courtier_of = scope:inspiration_sponsor
			is_imprisoned = no
		}
	}
}

ep1_character_had_or_has_inspiration_type_trigger = {
	OR = {
		AND = {
			exists = var:created_artifact_type
			var:created_artifact_type = flag:$TYPE$
		}
		inspiration ?= { has_inspiration_type = $TYPE$_inspiration }
	}
}

ep1_no_artifact_decorations_trigger = {
	OR = {
		scope:wealth < 40
		AND = {
			exists = scope:inspiration_owner
			scope:inspiration_owner = {	has_trait = humble }
		}
	}
}

ep1_simple_artifact_decorations_trigger = {
	scope:wealth >= 5
	scope:wealth < 70
}

ep1_advanced_artifact_decorations_trigger = {
	scope:wealth >= 40
	scope:wealth < 90
}

ep1_extravagant_artifact_decorations_trigger = {
	scope:wealth >= 70
}

ep1_artifact_durability_lower_equal_percent_trigger = {
	$PERCENT$ > {
	 	value = 0
	 	add = artifact_durability
	 	divide = artifact_max_durability
	}
}

ep1_artifact_durability_higher_equal_percent_trigger = {
	$PERCENT$ < {
	 	value = 0
	 	add = artifact_durability
	 	divide = artifact_max_durability
	}
}

ep1_character_has_court_artifact_trigger = {
	any_character_artifact = {
		ep1_artifact_is_court_artifact_trigger = yes
	}
}

ep1_artifact_is_court_artifact_trigger = {
	OR = {
		artifact_slot_type = wall_big
		artifact_slot_type = wall_small
		artifact_slot_type = sculpture
		artifact_slot_type = book
		artifact_slot_type = throne
		artifact_slot_type = pedestal
	}
}


##############
# COURT POSITION TRIGGERS
##############

#Used to see if the scoped character has ANY court position that CHARACTER can hold
character_can_be_employed_in_a_court_position_trigger = {
	OR = {
		AND = {
			can_employ_court_position_type = court_physician_court_position
			$CHARACTER$ = { can_be_employed_as = court_physician_court_position }
		}
		AND = {
			can_employ_court_position_type = master_of_horse_court_position
			$CHARACTER$ = { can_be_employed_as = master_of_horse_court_position }
		}
		AND = {
			can_employ_court_position_type = master_of_hunt_court_position
			$CHARACTER$ = { can_be_employed_as = master_of_hunt_court_position }
		}
		AND = {
			can_employ_court_position_type = keeper_of_swans_court_position
			$CHARACTER$ = { can_be_employed_as = keeper_of_swans_court_position }
		}
		AND = {
			can_employ_court_position_type = travel_leader_court_position
			$CHARACTER$ = { can_be_employed_as = travel_leader_court_position }
		}
		AND = {
			can_employ_court_position_type = court_jester_court_position
			$CHARACTER$ = { can_be_employed_as = court_jester_court_position }
		}
		AND = {
			can_employ_court_position_type = high_almoner_court_position
			$CHARACTER$ = { can_be_employed_as = high_almoner_court_position }
		}
		AND = {
			can_employ_court_position_type = seneschal_court_position
			$CHARACTER$ = { can_be_employed_as = seneschal_court_position }
		}
		AND = {
			can_employ_court_position_type = court_tutor_court_position
			$CHARACTER$ = { can_be_employed_as = court_tutor_court_position }
		}
		AND = {
			can_employ_court_position_type = court_guru_court_position
			$CHARACTER$ = { can_be_employed_as = court_guru_court_position }
		}
		AND = {
			can_employ_court_position_type = cupbearer_court_position
			$CHARACTER$ = { can_be_employed_as = cupbearer_court_position }
		}
		AND = {
			can_employ_court_position_type = chief_eunuch_court_position
			$CHARACTER$ = { can_be_employed_as = chief_eunuch_court_position }
		}
		AND = {
			can_employ_court_position_type = antiquarian_court_position
			$CHARACTER$ = { can_be_employed_as = antiquarian_court_position }
		}
		AND = {
			can_employ_court_position_type = royal_architect_court_position
			$CHARACTER$ = { can_be_employed_as = royal_architect_court_position }
		}
		AND = {
			can_employ_court_position_type = lady_in_waiting_court_position
			$CHARACTER$ = { can_be_employed_as = lady_in_waiting_court_position }
		}
		AND = {
			can_employ_court_position_type = court_poet_court_position
			$CHARACTER$ = { can_be_employed_as = court_poet_court_position }
		}
		AND = {
			can_employ_court_position_type = court_musician_court_position
			$CHARACTER$ = { can_be_employed_as = court_musician_court_position }
		}
		AND = {
			can_employ_court_position_type = bodyguard_court_position
			$CHARACTER$ = { can_be_employed_as = bodyguard_court_position }
		}
		AND = {
			can_employ_court_position_type = champion_court_position
			$CHARACTER$ = { can_be_employed_as = champion_court_position }
		}
		AND = {
			can_employ_court_position_type = food_taster_court_position
			$CHARACTER$ = { can_be_employed_as = food_taster_court_position }
		}
		AND = {
			can_employ_court_position_type = executioner_court_position
			$CHARACTER$ = { can_be_employed_as = executioner_court_position }
		}
		AND = {
			can_employ_court_position_type = garuda_court_position
			$CHARACTER$ = { can_be_employed_as = garuda_court_position }
		}
		AND = {
			can_employ_court_position_type = wet_nurse_court_position
			$CHARACTER$ = { can_be_employed_as = wet_nurse_court_position }
		}
		AND = {
			can_employ_court_position_type = akolouthos_court_position
			$CHARACTER$ = { can_be_employed_as = akolouthos_court_position }
		}
	}
}


#Used to check if the scoped character can hold any court position
can_be_employed_in_any_court_position_trigger = {
	OR = {
		can_be_employed_as = court_physician_court_position
		can_be_employed_as = master_of_horse_court_position
		can_be_employed_as = master_of_hunt_court_position
		can_be_employed_as = keeper_of_swans_court_position
		can_be_employed_as = court_jester_court_position
		can_be_employed_as = high_almoner_court_position
		can_be_employed_as = seneschal_court_position
		can_be_employed_as = court_tutor_court_position
		can_be_employed_as = court_guru_court_position
		can_be_employed_as = cupbearer_court_position
		can_be_employed_as = chief_eunuch_court_position
		can_be_employed_as = antiquarian_court_position
		can_be_employed_as = royal_architect_court_position
		can_be_employed_as = lady_in_waiting_court_position
		can_be_employed_as = court_poet_court_position
		can_be_employed_as = court_musician_court_position
		can_be_employed_as = bodyguard_court_position
		can_be_employed_as = champion_court_position
		can_be_employed_as = food_taster_court_position
		can_be_employed_as = executioner_court_position
		can_be_employed_as = garuda_court_position
		can_be_employed_as = travel_leader_court_position
		can_be_employed_as = wet_nurse_court_position
		can_be_employed_as = akolouthos_court_position
	}
}

##### Hold court

hold_court_8010_county_trigger = {
	any_title_to_title_neighboring_county = {
		holder.top_liege = {
			NOR = {
				THIS = ROOT
				is_allied_to = ROOT
				is_at_war_with = ROOT
				is_close_or_extended_family_of = ROOT
				max_military_strength < hold_court_8010_75_strength_value # 75% of ROOT's soldiers
			}
		}
	}
}

target_of_powerful_faction_trigger = {
	exists = yes
	OR = {
		faction_is_type = liberty_faction
		faction_is_type = claimant_faction
	}
	OR = {
		faction_power >= faction_power_threshold
		faction_is_at_war = yes
	}
	trigger_if = {
		limit = { exists = special_character }
		special_character != faction_target.liege
	}
}

province_has_no_holding_trigger = { # province has no holding
	has_ongoing_construction = no
	NOR = {
		has_holding_type = castle_holding
		has_holding_type = tribal_holding
		has_holding_type = city_holding
		has_holding_type = church_holding
		has_holding_type = herder_holding
		has_holding_type = nomad_holding
		has_holding_type = temple_citadel_holding
	}
}

county_has_all_holding_types = { # county has all three holding types
	any_county_province = { has_holding_type = castle_holding }
	any_county_province = { has_holding_type = city_holding }
	any_county_province = { has_holding_type = church_holding }
}

county_has_empty_province_trigger = {
	tier = tier_county
	any_county_province = { province_has_no_holding_trigger = yes }
}

county_has_no_city_trigger = { # No city in a county
	NOT = {
		any_county_province = { has_holding_type = city_holding }
	}
}

county_has_no_church_trigger = { # No church in a county
	NOT = {
		any_county_province = { has_holding_type = church_holding }
	}
}

##############
# DECISION TRIGGERS
##############

order_mass_eviction_decision_evictable_courtier_trigger = {
	NOR = {
		is_of_major_or_minor_interest_trigger = { CHARACTER = root }
		any_close_family_member = {
			host = root
			is_of_major_or_minor_interest_trigger = { CHARACTER = root }
		}
	}
}

# For technical reasons, this trigger can't be the same as ep1_decision_0111_list_builder_guts_trigger, but maintains (almost) technical parity with it.
exoticise_a_grand_hall_decision_list_builder_guts_trigger = {
	# Is the title presently active?
	exists = holder
	# Can the two communicate?
	holder = {
		# Filter out anyone who has the right rank but lacks a mechanical royal court.
		has_royal_court = yes
		has_dlc_feature = royal_court
		# Can the two communicate?
		in_diplomatic_range = root
	}
}

##############
# CHARACTER INTERACTIONS TRIGGERS
##############

indebt_guest_interaction_basic_checks_trigger = {
	$ACTOR$ = {
		# Gotta have a royal court.
		has_royal_court = yes
		has_dlc_feature = royal_court
		# Gotta have maxed servants to help.
		amenity_level = {
			target = court_servants
			value >= max_amenity_level
		}
	}
}

##############
# BANNER TRIGGERS
##############

artifact_house_not_owns_or_claims_trigger = {
	exists = scope:familial_banner
	NOR = {
		this = scope:familial_banner.artifact_owner.house
		has_house_artifact_claim = scope:familial_banner
	}
	trigger_if = {
		limit = { exists = scope:familial_banner.var:banner_dynasty }
		house_head.dynasty = scope:familial_banner.var:banner_dynasty
	}
}

is_composite_bow_culture_trigger = {
	OR = {
		has_cultural_tradition = tradition_horse_lords
		has_cultural_pillar = heritage_byzantine
		has_cultural_pillar = heritage_caucasian
		has_cultural_pillar = heritage_turkic
		has_cultural_pillar = heritage_mongolic
		has_innovation = innovation_advanced_bowmaking
	}
}
