﻿namespace = regula_faction_demand

# Servitude Faction Demand
regula_faction_demand.0001 = { 
	type = letter_event
	sender = scope:faction_leader
	opening = {
		desc = "REGULA_FACTION_DEMAND_SERVITUDE"
	}
	desc = "REGULA_FACTION_DEMAND_SERVITUDE_DESC"
	
	trigger = {
		exists = scope:faction # May have ceased to exist by the time this triggers
	}

	option = {
		name = "FACTION_DEMAND_ACCEPT"

		root = {
			save_scope_as = faction_target
			add_dread = medium_dread_loss
		}
		
		create_title_and_vassal_change = {
			type = swear_fealty
			save_scope_as = change
			add_claim_on_loss = no
		}
		scope:faction = {
			every_faction_member = {
				change_liege = {
					liege = global_var:magister_character
					CHANGE = scope:change
				}
				trigger_event = faction_demand.0002

			}			
		}
		resolve_title_and_vassal_change = scope:change
		global_var:magister_character = {
			send_interface_message = {  # Let the MC know the war is won.
			type = event_war_good
			title = regula_servitude_faction_victory_notification.t	
			desc = regula_servitude_faction_victory_notification.desc
			right_icon = scope:attacker
			left_icon = scope:defender
			}
			add_prestige = major_prestige_value
		}
		add_prestige = {
			value = medium_prestige_value
			multiply = -1
		}


		ai_chance = {
			base = 1
			modifier = {
				add = 99
				scope:faction = { faction_power >= 100 }
			}
			modifier = {
				add = 50
				scope:faction = { faction_power >= 125 }
			}
			modifier = {
				add = 50
				scope:faction = { faction_power >= 150 }
			}
			modifier = {
				add = 50
				scope:faction = { faction_power >= 200 }
			}
			modifier = {
				factor = 0.1
				any_ally = {
					NOR = {
						target_is_liege_or_above = root
						target_is_vassal_or_below = root
					}
					max_military_strength > root.max_military_strength
				}
			}
			compare_modifier = {
				value = debt_level
				multiplier = 25
			}
		}
	}

	option = {
		name = "FACTION_DEMAND_REFUSE"

		show_as_tooltip = {
			scope:faction = {
				faction_start_war = {}
			}
		}
		
		root = {
			save_scope_as = faction_target
		}
		
		scope:faction_leader = {
			trigger_event = regula_faction_demand.0003
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = 4.0
			}
			modifier = {
				add = 50
				scope:faction = { faction_power < 80 }
			}
			modifier = {
				add = 100
				scope:faction = { faction_power < 60 }
			}
			modifier = {
				add = 1000
				scope:faction = { faction_power < 40 }
			}
			compare_modifier = {
				value = debt_level
				multiplier = -25
			}
		}
	}
}

# Independence Faction Demand Accepted
regula_faction_demand.0002 = {
	type = letter_event
	sender = scope:faction_target
	opening = {
		desc = "FACTION_DEMAND_INDEPENDENCE_ACCEPTED"
	}
	desc = "FACTION_DEMAND_INDEPENDENCE_ACCEPTED_DESC"

	option = {
		name = "FACTION_DEMAND_ACCEPTED_OPT"
		custom_tooltip = faction_demand.0002.tt
	}
}

# Independence Faction Demand Refused
regula_faction_demand.0003 = {
	type = letter_event
	sender = scope:faction_target
	opening = {
		desc = "FACTION_DEMAND_INDEPENDENCE_REFUSED"
	}
	desc = "FACTION_DEMAND_INDEPENDENCE_REFUSED_DESC"

	option = {
		name = "FACTION_DEMAND_REFUSED_OPT"
		scope:faction = {
			faction_start_war = {}
			
			every_faction_member = {
				limit = { NOT = { this = scope:faction.faction_leader } }
				trigger_event = regula_faction_demand.0004
			}
		}
	}
}

# Independence Faction Demand Refused Member Notice
regula_faction_demand.0004 = {
	type = letter_event
	sender = scope:faction_target
	opening = {
		desc = "FACTION_DEMAND_INDEPENDENCE_REFUSED"
	}
	desc = "FACTION_DEMAND_INDEPENDENCE_REFUSED_DESC"

	option = {
		name = "FACTION_DEMAND_REFUSED_OPT"	
	}
}

# Independence Faction Demand Send Notice
regula_faction_demand.0005 = {
	type = letter_event
	sender = scope:faction_leader
	opening = {
		desc = "FACTION_DEMAND_INDEPENDENCE_SEND_DEMAND_NOTIFICATION"
	}
	desc = "FACTION_DEMAND_INDEPENDENCE_SEND_DEMAND_NOTIFICATION_DESC"

	option = {
		name = "FACTION_DEMAND_SEND_DEMAND_NOTIFICATION_OPT"	
	}
}

# Independence Faction Demand Send Notice to Magister
regula_faction_demand.0006 = {
	type = letter_event
	sender = {
		character = scope:faction_leader
		animation = happiness 
	}
	opening = {
		desc = "REGULA_FACTION_DEMAND_SERVITUDE_INFORM_MAGISTER_NOTIFICATION"
	}
	desc = "REGULA_FACTION_DEMAND_SERVITUDE_INFORM_MAGISTER_DESC"

	option = {
		name = "REGULA_FACTION_DEMAND_SERVITUDE_INFORM_MAGISTER_OPT"	
	}
}