﻿@base_hunter_discontent_progress = 2

hunter_faction = {
	casus_belli = hunter_war

	short_effect_desc = hunter_faction_short_effect_desc

	sort_order = 5

	leaders_allowed_to_leave = no
	player_can_join = no
	power_threshold = 100 

	discontent_progress = {
		base = @base_hunter_discontent_progress
	}

	name = FACTION_HUNTER_NAME

	requires_county = yes
	requires_character = no

	is_valid = {
        faction_target = { 
			POD_light_splat_trigger = no
			trigger_if = { 
				limit = { 
					OR = { 
						has_trait = fae 
						has_trait = changeling 
					}
				}
				NOT = { has_global_variable = fae_is_holy }
			}
        }
		NOT = { has_global_variable = destroyed_masquerade }
    }

	is_county_valid = {
		# Hunters can only join a faction against their direct liege.
		holder = scope:faction.faction_target
	}

	is_character_valid = {
		always = yes
	}

	demand = {
		save_scope_as = faction
		setup_hunter_leader_effect = yes
		special_character = {
			save_scope_as = hunter_leader
		}
		
		get_popular_revolt_target_effect = { FACTION = this }		

		faction_leader = {
			add_opinion = {
				modifier = angry_opinion
				target = root.faction_target
				opinion = -50
			}
		}
		scope:faction.faction_target = {
			trigger_event = pod_factions.1101
		}
	}

	ai_demand_chance = {
		base = 0

		modifier = {
			add = 100
			any_faction_county_member = {}
		}
	}

	on_creation = {
	}

	on_destroy = {
		set_variable = {
			name = hunter_destroying
			value = yes
		}
		if = {
			limit = { exists = special_character }
			special_character = {
				destroy_title = this.var:hunter_title

				if = {
					limit = {
						NOT = {	has_character_flag = hunter_revolt_do_not_kill}
					}
					trigger_event = { # The hunter leader mysteriously vanishes on the next game tick.
						id = pod_factions.1102
						days = 1
					}
				}
			}
		}
	}

	county_join_score =  {
		base = 0

		compare_modifier = {
			trigger = {	
				scope:faction.faction_target = {
					OR = {
						has_trait = vampire
						has_trait = kueijin
					}
				}
			}
			value = county_opinion
			multiplier = -0.1
		}

		compare_modifier = {
			trigger = {	
				scope:faction.faction_target = {
					NOR = {
						has_trait = vampire
						has_trait = kueijin
					}
				}
			}
			value = county_opinion
			multiplier = -1.0
		}

		# The AI has less revolts
		modifier = { 
			add = -500
			scope:faction.faction_target = {
				is_ai = yes
			}
		}
		
		#Already had a revolt
		modifier = {
			add = -500
			
			has_county_modifier = POD_factions_county_loss_modifier
		}
		
		modifier = { 
			add = -20
			scope:faction.faction_target = {
				has_perk = safe_passage_perk
			}
		}	
		
		modifier = { 
			add = 5
			scope:faction.faction_target = {
				has_character_modifier = masquerade1_modifier
			}
		}	

		modifier = { 
			add = 10
			scope:faction.faction_target = {
				has_character_modifier = masquerade2_modifier
			}
		}

		modifier = { 
			add = 15
			scope:faction.faction_target = {
				has_character_modifier = masquerade3_modifier
			}
		}

		modifier = { 
			add = 35
			scope:faction.faction_target = {
				has_character_modifier = masquerade4_modifier
			}
		}

		modifier = { 
			add = 50
			scope:faction.faction_target = {
				has_character_modifier = masquerade5_modifier
			}
		}	

		modifier = {
			add = {
				value = scope:faction.faction_target.dread
				multiply = -0.8
			}
			scope:faction.faction_target = { 
				OR = { 
					faith = { has_doctrine = doctrine_vampirethemasquerade_none }
				}
			}
		}

		# Reduced weight for a character's own capital to join a revolt against them.
		modifier = {
			add = -10
			this.title_province = scope:faction.faction_target.capital_province
		}

		legalism_virtue_and_sin_modifier = {
			TARGET = scope:faction.faction_target
			SCORE_PER_TRAIT = 10 # Worth 10 opinion per virtue.
		}
		
		# Difficulty Settings
		modifier = { # Easy
			add = -50
			has_game_rule = easy_difficulty
			scope:faction.faction_target = {
				is_ai = no
			}
		}
		modifier = { # Very Easy
			add = -150
			has_game_rule = very_easy_difficulty
			scope:faction.faction_target = {
				is_ai = no
			}
		}		
	}

	county_create_score = {
		base = 0

		####
		# AI Modifiers
		####

		compare_modifier = {
			trigger = {	
				scope:target = {
					OR = {
						has_trait = vampire
						has_trait = kueijin
					}
				}
			}
			value = county_opinion
			multiplier = -0.1
		}

		compare_modifier = {
			trigger = {	
				scope:target = {
					NOR = {
						has_trait = vampire
						has_trait = kueijin
					}
				}
			}
			value = county_opinion
			multiplier = -1.0
		}

		# The AI has less revolts
		modifier = { 
			add = -500
			scope:target = {
				is_ai = yes
			}
		}
		#Already had a revolt
		modifier = {
			add = -500
			
			has_county_modifier = POD_factions_county_loss_modifier
		}
		
		modifier = { 
			add = 1000
			scope:target = {
				has_character_flag = exposed_flag
			}
		}
		
		modifier = { 
			add = 5
			scope:target = {
				has_character_modifier = masquerade1_modifier
			}
		}	

		modifier = { 
			add = 10
			scope:target = {
				has_character_modifier = masquerade2_modifier
			}
		}

		modifier = { 
			add = 15
			scope:target = {
				has_character_modifier = masquerade3_modifier
			}
		}

		modifier = { 
			add = 35
			scope:target = {
				has_character_modifier = masquerade4_modifier
			}
		}

		modifier = { 
			add = 50
			scope:target = {
				has_character_modifier = masquerade5_modifier
			}
		}

		modifier = {
			add = {
				value = scope:target.dread
				multiply = -0.8
			}
			scope:target = { 
				OR = { 
					faith = { has_doctrine = doctrine_vampirethemasquerade_none }
				}
			}
		}

		# Reduced weight for a character's own capital to join a revolt against them.
		modifier = {
			add = -20
			this.title_province = scope:target.capital_province
		}

		legalism_virtue_and_sin_modifier = {
			TARGET = scope:target
			SCORE_PER_TRAIT = 10 # Worth 10 opinion per virtue.
		}

		# Difficulty Settings
		modifier = { # Easy
			add = -50
			has_game_rule = easy_difficulty
			scope:target = {
				is_ai = no
			}
		}
		modifier = { # Very Easy
			add = -150
			has_game_rule = very_easy_difficulty
			scope:target = {
				is_ai = no
			}
		}
	}

	ai_join_score = {
	}

	can_character_join = {
		joined_faction = scope:faction
	}

	can_county_join = {
		# Can only join a faction against their direct liege.
		holder = scope:faction.faction_target
	}

	can_county_create = {
		# Peasants can only join a faction against their direct liege.
		holder = scope:target

		####
		# BLOCKERS
		####
		# General Faction immunity
		custom_description = {
			text = character_is_immune_to_factions
			subject = scope:target
			NOT = { scope:target = { immune_to_factions_trigger = yes } }
		}
		
		scope:target = {
			POD_light_splat_trigger = no
			trigger_if = { 
				limit = { 
					OR = { 
						has_trait = fae 
						has_trait = changeling 
					}
				}
				NOT = { has_global_variable = fae_is_holy }
			}
		}
	}

	can_character_become_leader = {
		always = yes
	}

	on_war_start = {
		if = {
			limit = {
				faction_target = {
					highest_held_title_tier > tier_county
				}
			}
			every_faction_county_member = {
				save_scope_as = county
				title_province = {
					save_scope_as = county_location
				}
				root.faction_leader = {
					spawn_army = {
						levies = scope:county.county_levies_to_raise
						men_at_arms = {
							type = teutonic_knights
							stacks = 2
								}	
						location = scope:county_location
						war = root.faction_war
						name = hunter_faction_event_troops
					}
					
				}
			}
		}
		else_if = {
			limit = {
				faction_target = {
					highest_held_title_tier > tier_duchy
				}
			}
			every_faction_county_member = {
				save_scope_as = county
				title_province = {
					save_scope_as = county_location
				}
				root.faction_leader = {
					spawn_army = {
						levies = scope:county.county_levies_to_raise
						men_at_arms = {
							type = teutonic_knights
							stacks = 3
						}	
						location = scope:county_location
						war = root.faction_war
						name = hunter_faction_event_troops
					}
				}
			}
		}
		else = {
			every_faction_county_member = {
				save_scope_as = county
				title_province = {
					save_scope_as = county_location
				}
				root.faction_leader = {
					spawn_army = {
						levies = scope:county.county_levies_to_raise
						location = scope:county_location
						war = root.faction_war
						name = hunter_faction_event_troops
					}
				}
			}
		}
	}

	leader_leaves = {
		# Should only trigger when the leader is captured in battle.
		if = {
			limit = {
				NOT = { has_variable = hunter_destroying }
				exists = faction_war
			}
			faction_war = {
				end_war = defender
			}
		}
	}

	county_power = county_levies_to_raise

	character_allow_create = no

	special_character_title = "FACTIONS_WINDOW_LEADER"

	inherit_membership = no

	county_can_switch_to_other_faction = yes
}
