﻿namespace = sas_faction_demand

##################################################
# Roused Rabble Faction
# 1001 - 1010
##################################################

sas_faction_demand.1001 = {
	type = letter_event
	sender = scope:peasant_leader
	opening = "FACTION_DEMAND_ROUSED_RABBLE"
	desc = FACTION_DEMAND_ROUSED_RABBLE_DESC

	trigger = {
		exists = scope:faction
		exists = scope:peasant_leader
		scope:peasant_leader.joined_faction = scope:faction
	}

	on_trigger_fail = {
		debug_log = "Peasant Faction tried to press claim (probably) without existing peasant_leader"
		debug_log_scopes = yes
		debug_log = "Peasant Faction error reporting complete"
	}

	option = {
		name = "FACTION_DEMAND_ROUSED_RABBLE_REFUSE"

		scope:faction = {
			faction_start_war = {}
			
			# This needs to run after 'faction_start_war' or the troops won't spawn correctly.
			faction_spawn_member_county_armies_effect = {
				FACTION = scope:faction
				ARMY_OWNER = scope:peasant_leader
				PEASANT_ARMY_NAME = peasant_faction_event_troops
			}	
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = 4
			}
			modifier = {
				add = 50
				scope:faction = { faction_power < 90 }
			}
			modifier = {
				add = 50
				scope:faction = { faction_power < 80 }
			}
		}
	}
}

sas_faction_demand.1002 = {
	hidden = yes

	trigger = {
		is_imprisoned = no
	}

	immediate = {
		death = {
			death_reason = death_vanished
		}
	}
}

# Schemer can fund the war effort
sas_faction_demand.1003 = {
	type = character_event
	theme = rouse_rabble_scheme
	title = sas_faction_demand.1003.t
	desc = sas_faction_demand.1003.desc
	right_portrait = {
		character = root
		animation = thinking
	}
	option = {
		name = sas_faction_demand.1003.a
		remove_short_term_gold  = funded_rabble_big
		scope:new_faction = {
			every_faction_county_member = {
				set_variable = {
					name = schemer_funded_rabble
					value = funded_rabble_big
				}
			}
		}
	}
	option = {
		name = sas_faction_demand.1003.b
		remove_short_term_gold  = funded_rabble_medium
		scope:new_faction = {
			every_faction_county_member = {
				set_variable = {
					name = schemer_funded_rabble
					value = funded_rabble_medium
				}
			}
		}
	}
	option = {
		name = sas_faction_demand.1003.c
		remove_short_term_gold  = funded_rabble_small
		scope:new_faction = {
			every_faction_county_member = {
				set_variable = {
					name = schemer_funded_rabble
					value = funded_rabble_small
				}
			}
		}
	}
	option = {
		name = sas_faction_demand.1003.d
	}
}

# Rabble is declaring war
sas_faction_demand.1004 = {
	type = character_event
	theme = rouse_rabble_scheme
	title = sas_faction_demand.1004.t
	desc = sas_faction_demand.1004.desc
	right_portrait = {
		character = scope:peasant_leader
		animation = celebrate_sword
	}
	option = {
		name = sas_faction_demand.1004.a
	}
}

# War ended in victory
sas_faction_demand.1005 = {
	type = character_event
	theme = rouse_rabble_scheme
	title = sas_faction_demand.1005.t
	desc = sas_faction_demand.1005.desc
	right_portrait = {
		character = scope:defender
		animation = disbelief
	}
	option = {
		name = sas_faction_demand.1005.a
	}
}

# War ended in white peace
sas_faction_demand.1006 = {
	type = character_event
	theme = rouse_rabble_scheme
	title = sas_faction_demand.1006.t
	desc = sas_faction_demand.1006.desc
	right_portrait = {
		character = scope:defender
		animation = aggressive_sword
	}
	option = {
		name = sas_faction_demand.1006.a
	}
}

# War ended in defeat
sas_faction_demand.1007 = {
	type = character_event
	theme = rouse_rabble_scheme
	title = sas_faction_demand.1007.t
	desc = sas_faction_demand.1007.desc
	right_portrait = {
		character = scope:defender
		animation = celebrate_sword
	}
	option = {
		name = sas_faction_demand.1007.a
	}
}

##################################################
# Provoked Factions
# 1011 - 1020
##################################################

# Efforts failed no war declared
sas_faction_demand.1011 = {
	type = character_event
	theme = provoke_vassals_scheme
	title = sas_faction_demand.1011.t
	desc = sas_faction_demand.1011.desc
	left_portrait = {
		character = root
		animation = thinking
	}
	right_portrait = {
		character = scope:target
		animation = celebrate_sword
	}
	option = {
		name = sas_faction_demand.1011.a
	}
}

# War ended in victory
sas_faction_demand.1012 = {
	type = character_event
	theme = provoke_vassals_scheme
	title = sas_faction_demand.1012.t
	desc = sas_faction_demand.1012.desc
	right_portrait = {
		character = scope:defender
		animation = disbelief
	}
	option = {
		name = sas_faction_demand.1012.a
	}
}

# War ended in white peace
sas_faction_demand.1013 = {
	type = character_event
	theme = provoke_vassals_scheme
	title = sas_faction_demand.1013.t
	desc = sas_faction_demand.1013.desc
	right_portrait = {
		character = scope:defender
		animation = aggressive_sword
	}
	option = {
		name = sas_faction_demand.1013.a
	}
}

# War ended in defeat
sas_faction_demand.1014 = {
	type = character_event
	theme = provoke_vassals_scheme
	title = sas_faction_demand.1014.t
	desc = sas_faction_demand.1014.desc
	right_portrait = {
		character = scope:defender
		animation = celebrate_sword
	}
	option = {
		name = sas_faction_demand.1014.a
	}
}

# Demands being sent
sas_faction_demand.1015 = {
	type = character_event
	theme = provoke_vassals_scheme
	title = sas_faction_demand.1015.t
	desc = sas_faction_demand.1015.desc
	right_portrait = {
		character = root
		animation = happiness
	}
	option = {
		name = sas_faction_demand.1015.a
	}
}

# War declared
sas_faction_demand.1016 = {
	type = character_event
	theme = provoke_vassals_scheme
	title = sas_faction_demand.1016.t
	desc = sas_faction_demand.1016.desc
	right_portrait = {
		character = root
		animation = scheme
	}
	option = {
		name = sas_faction_demand.1016.a
	}
}