﻿loyalist_faction = {
	casus_belli = depose_war

	short_effect_desc = loyalist_faction_short_effect_desc

	sort_order = 1

	show_special_title = no
	multiple_targeting = no
	player_can_join = no

	discontent_progress = {
		base = 0
	}

	power_threshold = {
		base = 0

		# modifier = {
		# 	add = 20 
		# 	faction_target = {
		# 		has_perk = hard_rule_perk
		# 	}
		# 	desc = "FACTION_POWER_HARD_RULE"
		# } 

		#Lower the threshold depending on the state of other factions
		# dynamic_power_threshold_scripted_modifier = {
		# 	FACTION_TYPE1 = liberty_faction
		# 	FACTION_TYPE2 = independence_faction
		# 	FACTION_TYPE3 = populist_faction
		# }
	}

	is_valid = { # If the FACTION itself is valid
		# see also invalidate_claimant_factions_on_death_effect for what happens when the claimant dies
	}

	demand = { # The effect of pressing demand
	}

	on_creation = {
		set_variable = icon_override
		set_variable = loyalist_faction
	}

	update_effect = {
	}

	character_leaves = {
		scope:faction_member = {
			every_character_war = {
				limit = {
					exists = scope:faction.faction_target
					primary_defender = scope:faction.faction_target
					OR = {
						using_cb = independence_faction_war
						using_cb = liberty_faction_war
						using_cb = populist_war
						using_cb = claimant_faction_war
						using_cb = depose_war
						using_cb = refused_liege_demand_war
						using_cb = independence_war
						using_cb = peasant_war
						using_cb = claim_cb
					}
					trigger_if = {
						limit = {
							using_cb = claim_cb
						}
						primary_defender = { is_liege_or_above_of = primary_attacker }
					}
				}
				remove_participant = scope:faction_member
			}
		}
	}

	ai_demand_chance = {
		base = 0
	}

	on_war_start = {}

	is_character_valid = { # Is the character valid to stay in the faction? This is also checked when creating it...
		is_adult = yes
		is_imprisoned = no
	}

	can_character_create = { # If a character is allowed to create the faction. The 'is_character_valid' block is also checked in conjunction with this when creating a faction.
		# common_character_validity_trigger = {
		# 	FACTION_TARGET = scope:target
		# }

		is_adult = yes
	}

	can_character_join = { # Can a character join an existing faction?
		# common_character_validity_trigger = {
		# 	FACTION_TARGET = scope:target
		# }

		is_adult = yes
	}

	can_character_become_leader = {
		is_landed = yes
	}

	can_character_create_ui = {
		is_character_interaction_valid = {
			recipient = scope:target
			interaction = create_claimant_faction_against_interaction
		}
	}

	ai_create_score = { # How likely is an AI to create a faction?
		base = 0

		####
		# BLOCKERS
		####
		modifier = {
			add = -1000
			is_at_war = yes
		}

		####
		# AI modifiers
		####

		intimidated_from_faction_modifier = {
			TARGET = scope:target
			POWER = 0
			THRESHOLD = 100000
		}

		liege_debt_modifier = {
			TARGET = scope:target
			SCORE_PER_DEBT_LEVEL = -10
		}

		modifier = {
			add = LTAF_loyalty
			desc = "LTAF_loyalty"
		}

	}

	ai_join_score = { # How likely is an AI to join an existing faction?
		base = 0

		####
		# BLOCKERS
		####
		modifier = {
			add = -1000
			is_at_war = yes
		}

		####
		# AI modifiers
		####

		intimidated_from_faction_modifier = {
			TARGET = scope:faction.faction_target
			POWER = 0
			THRESHOLD = 100000
		}

		liege_debt_modifier = {
			TARGET = scope:faction.faction_target
			SCORE_PER_DEBT_LEVEL = -10
		}

		modifier = {
			add = LTAF_loyalty
			desc = "LTAF_loyalty"
		}
	}

	is_county_valid = {
		scope:faction.faction_target = holder
	}

	can_county_join = {
	}

	county_join_score =  {
		base = -40 # Needs to be less than the weight set in 00_populist_faction.txt, or counties will never join a claimant faction over a populist faction.

		# Up to +3 join score per negative opinion (+80 at -27 opinion) if different culture. 
		compare_modifier = {
			trigger = {
				OR = {
					scope:faction.faction_target.culture = this.title_province.culture
					this.title_province.culture = { has_same_culture_heritage = scope:faction.faction_target.culture }
				}
			}
			value = county_opinion
			multiplier = 2.0
		}

		legalism_virtue_and_sin_modifier = {
			TARGET = scope:faction.faction_target
			SCORE_PER_TRAIT = -50 # Worth ~12 opinion per virtue.
		}

		# Greatly reduced chance for a character's capital county to form a faction against them (extra -25 opinion needed).
		modifier = {
			add = 40
			this.title_province = scope:faction.faction_target.capital_province
		}
		
		# More likely to support adult claimants when a child is on the throne.
		modifier = {
			add = -10
			exists = scope:faction.faction_target
			scope:faction.faction_target = { is_adult = no }
		}

		# Peasants perfer magnanimous rulers over harsh or cruel ones.
		compare_modifier = {
			factor = {
				# Gets a value between 0 (max greedy/dishonorable/vengeful/cruel) and 800 (max honorable/compassionate/generous/forgiving).
				value = 400
				add = scope:faction.faction_target.ai_honor
				add = scope:faction.faction_target.ai_compassion
				subtract = scope:faction.faction_target.ai_greed
				subtract = scope:faction.faction_target.ai_vengefulness

				# Converts the personality score into a percentage between 0% (will never support) and 100% (really wants to support)
				divide = 800 
			}

			# How big the factor is for supporting this claimant over other factions at max support. 
			multiplier = 2
		}
	}

	leaders_allowed_to_leave = yes
	county_allow_join = yes
	county_allow_create = no
	county_power = county_levies_to_raise

	character_allow_create = yes

	character_allow_join = yes

	multiple_targeting = no

	special_character_title = "FACTIONS_WINDOW_CLAIMANT"

	ignore_soft_block = yes
}