﻿namespace = loaa_legitimist_support_events

scripted_effect loaa_legitimist_support_add_effect = {
	spawn_army = {
		men_at_arms = {
			type = accolade_maa_vanguards
			stacks = {
				value = 2
				multiply = var:legitimist_support
				multiply = capital_development_legitimist_value
			}
		}
		men_at_arms = {
			type = accolade_maa_archers
			stacks = {
				value = 2
				multiply = var:legitimist_support
				multiply = capital_development_legitimist_value
			}
		}
		men_at_arms = {
			type = accolade_maa_lancers
			stacks = {
				value = var:legitimist_support
				multiply = capital_development_legitimist_value
				min = 1
			}
		}
		inheritable = no
		uses_supply = no
		location = root.location
		name = ep3_legitimist_army
	}
	scope:petitioned_ruler = {
		if = {
			limit = { scope:petitioned_ruler = { has_character_flag = strong_hook_yes } }
			add_hook = {
				type = strong_favor_hook
				target = scope:claimant
			}
		}
		else = {
			add_hook = {
				target = scope:claimant
				type = favor_hook
			}
		}

	}
}

scripted_effect loaa_legitimist_nomad_support_add_effect = {
	spawn_army = {
		men_at_arms = {
			type = horse_archers
			stacks = {
				value = 3
				multiply = var:legitimist_support
				multiply = capital_development_legitimist_value
			}
		}
		men_at_arms = {
			type = heavy_horse_archers
			stacks = {
				value = 2
				multiply = var:legitimist_support
				multiply = capital_development_legitimist_value
			}
		}
		men_at_arms = {
			type = nomad_lancers
			stacks = {
				value = var:legitimist_support
				multiply = capital_development_legitimist_value
				min = 1
			}
		}
		inheritable = no
		uses_supply = no
		location = root.location
		name = ep3_legitimist_army
	}
	scope:petitioned_ruler = {
		if = {
			limit = { scope:petitioned_ruler = { has_character_flag = strong_hook_yes } }
			add_hook = {
				type = strong_favor_hook
				target = scope:claimant
			}
		}
		else = {
			add_hook = {
				target = scope:claimant
				type = favor_hook
			}
		}

	}
}

scripted_effect legitimist_support_add_tt_effect = {
	scope:petitioned_ruler = {
		remove_short_term_gold = {
			value = 0
			switch = {
				trigger = $SUPPORT$
				1 = {
					add = 200
				}
				5 = {
					add = 750
				}
				10 = {
					add = 1500
				}
			}
			multiply = capital_development_legitimist_value
		}
		add_prestige = {
			value = -1
			multiply = capital_development_legitimist_value
			multiply = 100
			multiply = $SUPPORT$
			divide = 2
		}
	}

	spawn_army = {
		men_at_arms = {
			type = accolade_maa_vanguards
			stacks = {
				value = 2
				multiply = $SUPPORT$
				multiply = capital_development_legitimist_value
			}
		}
		men_at_arms = {
			type = accolade_maa_archers
			stacks = {
				value = 2
				multiply = $SUPPORT$
				multiply = capital_development_legitimist_value
			}
		}
		men_at_arms = {
			type = accolade_maa_lancers
			stacks = {
				value = $SUPPORT$
				multiply = capital_development_legitimist_value
				min = 1
			}
		}
		inheritable = no
		uses_supply = no
		location = root.location
		name = ep3_legitimist_army
	}
}

scripted_effect loaa_ep3_laamps_8106_designate_targets_effect = {
	if = {
		limit = {
			NOT = { exists = scope:target_1 }
		}
		save_scope_as = target_1
	}
	else_if = {
		limit = {
			NOT = { exists = scope:target_2 }
		}
		save_scope_as = target_2
	}
	else_if = {
		limit = {
			NOT = { exists = scope:target_3 }
		}
		save_scope_as = target_3
	}
	else_if = {
		limit = {
			NOT = { exists = scope:target_4 }
		}
		save_scope_as = target_4
	}
	else_if = {
		limit = {
			NOT = { exists = scope:target_5 }
		}
		save_scope_as = target_5
	}
	else_if = {
		limit = {
			NOT = { exists = scope:target_6 }
		}
		save_scope_as = target_6
	}
	else_if = {
		limit = {
			NOT = { exists = scope:target_7 }
		}
		save_scope_as = target_7
	}
	else_if = {
		limit = {
			NOT = { exists = scope:target_8 }
		}
		save_scope_as = target_8
	}
	else_if = {
		limit = {
			NOT = { exists = scope:target_9 }
		}
		save_scope_as = target_9
	}
	else_if = {
		limit = {
			NOT = { exists = scope:target_10 }
		}
		save_scope_as = target_10
	}
}

# Claimant - Choose your title for support
loaa_legitimist_support_events.1 = {
	type = character_event
	title = loaa_legitimist_support_events.1.t
	desc = loaa_legitimist_support_events.1.desc

	theme = diplomacy

	override_background = { reference = throne_room }

	left_portrait = {
		character = root
		animation = debating
	}

	right_portrait = {
		character = scope:petitioned_ruler
		animation = admiration
	}

	trigger = {
		any_claim = {
			count > 1
			tier >= tier_kingdom
		}
		NOT = {
			has_variable = legitimist_claimed_title
		}
	}

	immediate = {
		ordered_claim = {
			limit = {
				tier >= tier_kingdom
			}
			order_by = tier
			max = 4

			# First title.
			if = {
				limit = {
					NOT = { exists = scope:title_1 }
				}
				save_scope_as = title_1
			}
			# Second title.
			else_if = {
				limit = {
					NOT = {
						this = scope:title_1
						exists = scope:title_2
					}
				}
				save_scope_as = title_2
			}
			# Third title.
			else_if = {
				limit = {
					NOT = {
						this = scope:title_1
						this = scope:title_2
						exists = scope:title_3
					}
				}
				save_scope_as = title_3
			}
			# Fourth title
			else_if = {
				limit = {
					NOT = {
						this = scope:title_1
						this = scope:title_2
						this = scope:title_3
						exists = scope:title_4
					}
				}
				save_scope_as = title_4
			}
		}
	}

	on_trigger_fail = {
		scope:petitioned_ruler = {
			trigger_event = loaa_legitimist_support_events.2
		}
	}

	option = {
		name = ep3_laamps.8101.a
		custom_tooltip = ep3_laamps.8101.a.desc
		trigger = {
			exists = scope:title_1
		}
		scope:title_1 = {
			save_scope_as = claimed_title
		}

		ai_chance = {
			base = 100
		}
	}

	option = {
		name = ep3_laamps.8101.b
		custom_tooltip = ep3_laamps.8101.a.desc
		trigger = {
			exists = scope:title_2
		}
		scope:title_2 = {
			save_scope_as = claimed_title
		}
	}

	option = {
		name = ep3_laamps.8101.c
		custom_tooltip = ep3_laamps.8101.a.desc
		trigger = {
			exists = scope:title_3
		}
		scope:title_3 = {
			save_scope_as = claimed_title
		}
	}

	option = {
		name = ep3_laamps.8101.d
		custom_tooltip = ep3_laamps.8101.a.desc
		trigger = {
			exists = scope:title_4
		}
		scope:title_4 = {
			save_scope_as = claimed_title
		}
	}

	after = {
		scope:petitioned_ruler = {
			trigger_event = loaa_legitimist_support_events.2
		}
	}
}

# Ruler - The Price of a Throne: Offers
loaa_legitimist_support_events.2 = {
    type = character_event
	title = loaa_legitimist_support_events.2.t
	desc = {
		desc = loaa_legitimist_support_events.2.desc
	}
	theme = diplomacy

	override_background = { reference = throne_room }

    trigger = {
        exists = scope:claimant
    }

	left_portrait = {
		character = root
		animation = thinking
	}

	right_portrait = {
		character = scope:claimant
        animation = chancellor
	}

	lower_right_portrait = {
		character = scope:usurper
	}

    immediate = {
        if = {
            limit = {
                NOT = { exists = scope:petitioned_ruler }
            }
            save_scope_as = petitioned_ruler
        }
		#save the claim
        scope:claimant = {
            if = {
                limit = {
                    NOT = {
                        exists = scope:claimed_title
                        has_variable = legitimist_claimed_title
                    }
                }
                random_claim = {
                    limit = {
                        tier >= tier_kingdom
                    }
                    save_scope_as = claimed_title
                }
            }
        }

		scope:claimed_title.holder.capital_barony = { save_scope_as = capital_barony }
        scope:claimant = {
            if = {
                limit = {
                    NOT = {
                        has_variable = legitimist_claimed_title
                    }
                }
                set_variable = {
                    name = legitimist_claimed_title
                    value = scope:claimed_title
                }
            }
            else = {
                var:legitimist_claimed_title = {
                    save_scope_as = claimed_title
                }
            }

        }

        #setup support and obligations level
        scope:claimant = {
            set_variable = {
                name = legitimist_support
                value = 0
            }

            set_variable = {
                name = legitimist_obligations
                value = 0
            }
        }

		scope:claimed_title.holder = {
			save_scope_as = usurper
		}
	}

    option = {
        name = loaa_legitimist_support_events.2.a
        scope:claimant = {
            set_variable = {
                name = legitimist_support
                value = 1
            }
        }
		custom_description_no_bullet = {
			text = loaa_legitimist_support_events_results_tt
		}
		show_as_tooltip = {
			scope:claimant = { legitimist_support_add_tt_effect = { SUPPORT = 1 } }
		}
		trigger_event = loaa_legitimist_support_events.3

		ai_chance = {
			base = 10
		}
    }

    option = {
        name = loaa_legitimist_support_events.2.b
		trigger_event = loaa_legitimist_support_events.3
        scope:claimant = {
            set_variable = {
                name = legitimist_support
                value = 5
            }
        }
		custom_description_no_bullet = {
			text = loaa_legitimist_support_events_results_tt
		}
		show_as_tooltip = {
			scope:claimant = { legitimist_support_add_tt_effect = { SUPPORT = 5 } }
		}
		ai_chance = {
			base = 20
		}
    }

    option = {
        name = loaa_legitimist_support_events.2.c
		trigger_event = loaa_legitimist_support_events.3
        scope:claimant = {
            set_variable = {
                name = legitimist_support
                value = 10
            }
        }
		custom_description_no_bullet = {
			text = loaa_legitimist_support_events_results_tt
		}
		show_as_tooltip = {
			scope:claimant = { legitimist_support_add_tt_effect = { SUPPORT = 10 } }
		}
		ai_chance = {
			base = 10
		}
    }

    option = {
        name = loaa_legitimist_support_events.2.d
        flavor = ep3_laamps.8103.d.desc
		hidden_effect = {
			scope:task_contract = {
				complete_task_contract = failure_standard
			}
		}
		scope:claimant = {
			send_interface_toast = {
				type = event_generic_bad
				title = loaa_legitimist_support_events.13.t
				desc = loaa_legitimist_support_events.17.desc
				custom_tooltip = { text = loaa_legitimist_support_events.17.desc }
				left_icon = this
				right_icon = scope:petitioned_ruler
			}
			add_opinion = {
				target = scope:petitioned_ruler
				opinion = -50
				modifier = humiliated_opinion
			}
		}

		trigger_event = loaa_legitimist_support_events.16
		ai_chance = {
			base = 0
		}
    }
}

# Ruler - The Price of a Throne: Demands
loaa_legitimist_support_events.3 = {
    type = character_event
	title = loaa_legitimist_support_events.3.t
	desc = {
		desc = loaa_legitimist_support_events.3.desc_intro
		desc = loaa_legitimist_support_events.3.desc
		desc = loaa_legitimist_support_events_offer_t
		triggered_desc = {
			trigger = { scope:claimant = { var:legitimist_support ?= { this > 0 } } }
			desc = loaa_legitimist_support_events_offer_troops
		}
		desc = loaa_legitimist_support_events_demand_t
		triggered_desc = {
			trigger = { scope:claimant = { var:legitimist_obligations ?= 1 } }
			desc = loaa_legitimist_support_events_demand_1
		}
		triggered_desc = {
			trigger = { scope:claimant = { var:legitimist_obligations ?= 2 } }
			desc = loaa_legitimist_support_events_demand_2
		}
		triggered_desc = {
			trigger = { scope:claimant = { var:legitimist_obligations ?= 3 } }
			desc = loaa_legitimist_support_events_demand_3
		}
		triggered_desc = {
			trigger = { scope:petitioned_ruler = { has_character_flag = strong_hook_yes } }
			desc = loaa_legitimist_support_events_demand_4
		}
	}
	theme = diplomacy

	override_background = { reference = throne_room }

    trigger = {
        exists = scope:claimant
    }

	left_portrait = {
		character = root
		animation = thinking
	}

	right_portrait = {
		character = scope:claimant
		animation = throne_room_bow_1
	}

	lower_right_portrait = {
		character = scope:usurper
	}

    option = {
        name = loaa_legitimist_support_events.3.a
		custom_description_no_bullet = {
			text = loaa_legitimist_support_events_results_tt
		}
		custom_tooltip = loaa_legitimist_support_events_obligations_increase_tt
		trigger = {
			scope:claimant = {
				var:legitimist_obligations ?= { this = 0 }
			}
		}
		scope:claimant = {
			set_variable = {
				name = legitimist_obligations
				value = 1
			}
		}

		if = {
			limit = { is_ai = no }
			trigger_event = loaa_legitimist_support_events.3
		}
		else = {
			scope:claimant = { trigger_event = loaa_legitimist_support_events.4 }
		}

		ai_chance = {
			base = 10
		}
    }

    option = {
        name = loaa_legitimist_support_events.3.b
		custom_description_no_bullet = {
			text = loaa_legitimist_support_events_results_tt
		}
		custom_tooltip = loaa_legitimist_support_events_obligations_increase_tt
		trigger = {
			scope:claimant = {
				var:legitimist_obligations ?= { this = 0 }
			}
		}
		scope:claimant = {
			set_variable = {
				name = legitimist_obligations
				value = 2
			}
		}
		if = {
			limit = { is_ai = no }
			trigger_event = loaa_legitimist_support_events.3
		}
		else = {
			scope:claimant = { trigger_event = loaa_legitimist_support_events.4 }
		}
		ai_chance = {
			base = 20
		}
    }

    option = {
        name = loaa_legitimist_support_events.3.c
		custom_description_no_bullet = {
			text = loaa_legitimist_support_events_results_tt
		}
		custom_tooltip = loaa_legitimist_support_events_obligations_increase_tt
		trigger = {
			scope:claimant = {
				var:legitimist_obligations ?= { this = 0 }
			}
		}
		scope:claimant = {
			set_variable = {
				name = legitimist_obligations
				value = 3
			}
		}

		if = {
			limit = { is_ai = no }
			trigger_event = loaa_legitimist_support_events.3
		}
		else = {
			scope:claimant = { trigger_event = loaa_legitimist_support_events.4 }
		}

		ai_chance = {
			base = 10
		}
    }

	option = {
        name = loaa_legitimist_support_events.3.d
		custom_description_no_bullet = {
			text = loaa_legitimist_support_events_results_tt
		}
		show_as_tooltip = {
			add_hook = {
				type = strong_favor_hook
				target = scope:claimant
			}
		}
		trigger = {
			NOT = { scope:petitioned_ruler = { has_character_flag = strong_hook_yes } }
		}
		add_character_flag = strong_hook_yes
		trigger_event = loaa_legitimist_support_events.3
		ai_chance = {
			base = 0
		}
    }

    option = {
        name = loaa_legitimist_support_events.3.f
		trigger = {
			scope:claimant = {
				var:legitimist_support ?= { this > 0 }
				OR = {
					var:legitimist_obligations ?= { this > 0 }
					scope:petitioned_ruler = { has_character_flag = strong_hook_yes }
				}
			}
		}
		scope:claimant = {
			trigger_event = loaa_legitimist_support_events.4
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				scope:claimant = { var:legitimist_obligations <= 0 }
			}
		}
    }

}

# Claimant - Claimant Reaction
loaa_legitimist_support_events.4 = {
	type = character_event
	title = loaa_legitimist_support_events.4.t
	desc = {
		desc = loaa_legitimist_support_events.4.desc_intro
		triggered_desc = {
			trigger = { scope:claimant = { var:legitimist_support ?= 1 } }
			desc = loaa_legitimist_support_events.4.desc_support_1
		}
		triggered_desc = {
			trigger = { scope:claimant = { var:legitimist_support ?= 5 } }
			desc = loaa_legitimist_support_events.4.desc_support_2
		}
		triggered_desc = {
			trigger = { scope:claimant = { var:legitimist_support ?= 10 } }
			desc = loaa_legitimist_support_events.4.desc_support_3
		}
		desc = loaa_legitimist_support_events.4.desc_debt
		triggered_desc = {
			trigger = { scope:claimant = { var:legitimist_obligations ?= 1 } }
			desc = loaa_legitimist_support_events.4.desc_debt_1
		}
		triggered_desc = {
			trigger = { scope:claimant = { var:legitimist_obligations ?= 2 } }
			desc = loaa_legitimist_support_events.4.desc_debt_2
		}
		triggered_desc = {
			trigger = { scope:claimant = { var:legitimist_obligations ?= 3 } }
			desc = loaa_legitimist_support_events.4.desc_debt_3
		}
		triggered_desc = {
			trigger = { scope:petitioned_ruler = { has_character_flag = strong_hook_yes } }
			desc = loaa_legitimist_support_events.4.desc_debt_hook
		}
		desc = loaa_legitimist_support_events.4.desc_4_years
		first_valid = {
			triggered_desc = {
				trigger = { scope:petitioned_ruler = { has_character_flag = answer_given } }
				desc = loaa_legitimist_support_events.4.desc_outro_final
			}
			desc = loaa_legitimist_support_events.4.desc_outro
		}
	}

	theme = diplomacy
	override_background = { reference = throne_room }

	left_portrait = {
		character = root
		animation = throne_room_bow_1
	}

	right_portrait = {
		character = scope:petitioned_ruler
		animation = thinking
	}

	# Ask for less obligations
	option = {
		name = loaa_legitimist_support_events.4.b
		trigger = {
			OR = {
				scope:claimant = {
					var:legitimist_obligations > 1
				}
				scope:petitioned_ruler = { has_character_flag = strong_hook_yes }
			}

			NOT = { exists = scope:asking_for_less_obligations }
		}
		scope:claimant = { save_scope_as = asking_for_less_obligations }
		scope:petitioned_ruler = { trigger_event = loaa_legitimist_support_events.5 }
		ai_chance = {
			base = 0
			modifier = {
				add = {
					value = scope:claimant.var:legitimist_obligations
					multiply = 10
				}
			}
			modifier = {
				has_trait = arrogant
				add = 10
			}
			modifier = {
				has_trait = ambitious
				add = 10
			}
			modifier = {
				has_trait = brave
				add = 10
			}
			modifier = {
				NOT = { has_trait = content }
				add = 10
			}
			modifier = {
				scope:petitioned_ruler = { has_character_flag = strong_hook_yes }
				add = 150
			}
		}
	}

	option = {
		name = loaa_legitimist_support_events.4.c
		custom_tooltip = ep3_laamps.8105.invalidations_reasons
		custom_tooltip = ep3_laamps.8105.b.desc
		if = {
			limit = {
				 is_ai = yes
			}
			trigger_event = {
				id = loaa_legitimist_support_events.7
				months = 2
			}
		}
		else = {
			trigger_event = {
				id = loaa_legitimist_support_events.7
				years = 4
			}
		}

		scope:petitioned_ruler = {
			set_variable = {
				name = legitimist_obligations_left
				value = root.var:legitimist_obligations
			}
		}
		add_prestige = medium_prestige_gain

		# If courtier, then become an adventurer
		if = {
			limit = { is_courtier = yes }
			create_landless_adventurer_title_effect = {
				REASON = flag:voluntary
				FLAVOR_CHAR = scope:petitioned_ruler
			}
			if = {
				limit = { NOT = { has_realm_law = camp_purpose_legitimists } }
				add_realm_law_skip_effects = camp_purpose_legitimists
			}
		}

		if = {
			limit = {
				NOT = { exists = global_var:AGOT_is_loaded }
				scope:petitioned_ruler = { mpo_can_recruit_nomad_maa_trigger = yes }
			}
			loaa_legitimist_nomad_support_add_effect = yes
		}
		else = {
			loaa_legitimist_support_add_effect = yes
		}


		add_to_variable_list = { #used to handle root death
			name = loaa_legitimist_supporters
			target = scope:petitioned_ruler
		}
		hidden_effect = {
			scope:task_contract = {
				complete_task_contract = success_standard
			}
		}
		scope:petitioned_ruler = {
			trigger_event = loaa_legitimist_support_events.6
		}
		ai_chance = {
			base = 0
			modifier = {
				add = {
					value = scope:claimant.var:legitimist_support
					multiply = 10
				}
			}
			modifier = {
				add = {
					value = scope:claimant.var:legitimist_obligations
					multiply = -10
				}
			}
			modifier = {
				has_trait = trusting
				add = 10
			}
			modifier = {
				has_trait = humble
				add = 10
			}
			modifier = {
				has_trait = content
				add = 10
			}
			modifier = {
				scope:petitioned_ruler = { has_character_flag = strong_hook_yes }
				add = -50
			}
		}
	}

	option = {
		name = ep3_laamps.8105.c
		custom_tooltip = ep3_laamps.8105.c.desc
		show_as_tooltip = {
			if = {
				limit = {
					NOT = {
						has_relation_rival = scope:petitioned_ruler
					}
				}
				set_relation_rival = {
					target = scope:petitioned_ruler
					reason = rival_nithing
				}
			}
		}

		scope:petitioned_ruler = {
			remove_variable = legitimist_obligations_left
			remove_character_flag = legitimist_supporter
		}
		add_to_variable_list = {
			name = legitimist_payed_supporters
			target = scope:petitioned_ruler
		}
		hidden_effect = {
			scope:task_contract = {
				complete_task_contract = failure_standard
			}
		}
		scope:petitioned_ruler = { trigger_event = loaa_legitimist_support_events.13 }
		ai_chance = {
			base = 0
			modifier = {
				add = {
					value = scope:claimant.var:legitimist_support
					multiply = -10
				}
			}
			modifier = {
				add = {
					value = scope:claimant.var:legitimist_obligations
					multiply = 10
				}
			}
			modifier = {
				scope:petitioned_ruler = { has_character_flag = strong_hook_yes }
				add = 50
			}
			modifier = {
				scope:petitioned_ruler = {
					has_character_flag = strong_hook_yes
					has_character_flag = answer_given
				}
				add = 30
			}
		}
	}

}

# Ruler - Claimant Reaction
loaa_legitimist_support_events.5 = {
	type = character_event
	title = loaa_legitimist_support_events.5.t
	desc = {
		triggered_desc = {
			trigger = { exists = scope:asking_for_less_obligations }
			desc = loaa_legitimist_support_events.5.desc_obligations
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:claimant = {
						OR = {
							has_trait = brave
							has_trait = ambitious
							has_trait = arrogant
						}
					}
				 }
				desc = loaa_legitimist_support_events.5.desc_outro_proud
			}
			desc = loaa_legitimist_support_events.5.desc_outro
		}

		desc = loaa_legitimist_support_events_offer_t
		triggered_desc = {
			trigger = { scope:claimant = { var:legitimist_support ?= { this > 0 } } }
			desc = loaa_legitimist_support_events_offer_troops
		}
		desc = loaa_legitimist_support_events_demand_t
		triggered_desc = {
			trigger = { scope:claimant = { var:legitimist_obligations ?= 1 } }
			desc = loaa_legitimist_support_events_demand_1
		}
		triggered_desc = {
			trigger = { scope:claimant = { var:legitimist_obligations ?= 2 } }
			desc = loaa_legitimist_support_events_demand_2
		}
		triggered_desc = {
			trigger = { scope:claimant = { var:legitimist_obligations ?= 3 } }
			desc = loaa_legitimist_support_events_demand_3
		}
		triggered_desc = {
			trigger = { scope:petitioned_ruler = { has_character_flag = strong_hook_yes } }
			desc = loaa_legitimist_support_events_demand_4
		}
	}

	theme = diplomacy

	override_background = { reference = throne_room }

	left_portrait = {
		character = scope:petitioned_ruler
		animation = thinking
	}

	right_portrait = {
		character = scope:claimant
		triggered_animation = {
			trigger = {
				scope:claimant = {
					OR = {
						has_trait = brave
						has_trait = ambitious
						has_trait = arrogant
					}
				}
			}
			animation = personality_bold
		}
		animation = beg
	}

	# Such are the terms
	option = {
		name = loaa_legitimist_support_events.5.a
		stress_impact = {
			stubborn = minor_stress_impact_loss
		}
		custom_description_no_bullet = {
			text = loaa_legitimist_support_events_results_tt
		}
		custom_tooltip = loaa_legitimist_support_events_terms_unchanged_tt
		add_character_flag = answer_given
		scope:claimant = {
			trigger_event = loaa_legitimist_support_events.4
		}

		ai_chance = {
			base = 60
		}
	}

	# Very well
	option = {
		name = loaa_legitimist_support_events.5.b
		add_character_flag = answer_given
		custom_description_no_bullet = {
			text = loaa_legitimist_support_events_results_tt
		}
		# Obligations
		if = {
			limit = { exists = scope:asking_for_less_obligations }
			if = {
				limit = { scope:petitioned_ruler = { has_character_flag = strong_hook_yes } }
				custom_tooltip = loaa_legitimist_support_events_no_strong_hook_tt
				remove_character_flag = strong_hook_yes
			}
			else = {
				custom_tooltip = loaa_legitimist_support_events_obligations_decrease_tt
				change_variable = {
					name = legitimist_obligations
					subtract = 1
				}
			}
		}
		scope:claimant = {
			trigger_event = loaa_legitimist_support_events.4
		}
		stress_impact = {
			greedy = minor_stress_impact_gain
			stubborn = minor_stress_impact_gain
			generous = minor_stress_impact_loss
			compassionate = minor_stress_impact_loss
		}
		ai_chance = {
			base = 20
			modifier = {
				has_trait = compassionate
				add = 20
			}
			modifier = {
				has_trait = generous
				add = 20
			}
			modifier = {
				has_trait = stubborn
				add = -20
			}
			modifier = {
				has_trait = greedy
				add = -20
			}
			modifier = {
				has_trait = arrogant
				add = -20
			}
		}
	}

	# The terms just got worse
	option = {
		name = loaa_legitimist_support_events.5.c
		stress_impact = {
			sadistic = minor_stress_impact_loss
			arbitrary = minor_stress_impact_loss
			wrathful = minor_stress_impact_loss
			generous = minor_stress_impact_gain
		}
		custom_description_no_bullet = {
			text = loaa_legitimist_support_events_results_tt
		}
		add_character_flag = answer_given
		trigger = {
			OR = {
				has_trait = wrathful
				has_trait = sadistic
				has_trait = arbitrary
			}
			scope:claimant = {
				OR = {
					var:legitimist_obligations ?= { this < 3 }
					NOT = { scope:petitioned_ruler = { has_character_flag = strong_hook_yes } }
				}
			}
		}
		scope:claimant = {
			switch = {
				trigger = var:legitimist_obligations
				0 = {
					custom_tooltip = loaa_legitimist_support_events_obligations_increase_tt
					change_variable = {
						name = legitimist_obligations
						add = 1
					}
				}
				1 = {
					custom_tooltip = loaa_legitimist_support_events_obligations_increase_tt
					change_variable = {
						name = legitimist_obligations
						add = 1
					}
				}
				2 = {
					custom_tooltip = loaa_legitimist_support_events_obligations_increase_tt
					change_variable = {
						name = legitimist_obligations
						add = 1
					}
				}
				3 = {
					show_as_tooltip = {
						add_hook = {
							type = strong_favor_hook
							target = scope:claimant
						}
					}
					if = {
						limit = { NOT = { scope:petitioned_ruler = { has_character_flag = strong_hook_yes } } }
						add_character_flag = strong_hook_yes
					}
				}
			}
		}
		scope:claimant = {
			trigger_event = loaa_legitimist_support_events.4
		}

		ai_chance = {
			base = 0
			modifier = {
				has_trait = compassionate
				add = -20
			}
			modifier = {
				has_trait = generous
				add = -20
			}
			modifier = {
				has_trait = sadistic
				add = 20
			}
			modifier = {
				has_trait = wrathful
				add = 20
			}
		}
	}

	# Throw him out
	option = {
		name = loaa_legitimist_support_events.5.d
		flavor = ep3_laamps.8103.d.desc
		trigger_event = loaa_legitimist_support_events.16
		hidden_effect = {
			scope:task_contract = {
				complete_task_contract = failure_standard
			}
		}
		scope:claimant = {
			send_interface_toast = {
				type = event_generic_bad
				title = loaa_legitimist_support_events.13.t
				desc = loaa_legitimist_support_events.17.desc
				custom_tooltip = { text = loaa_legitimist_support_events.17.desc }
				left_icon = this
				right_icon = scope:petitioned_ruler
			}
			add_opinion = {
				target = scope:petitioned_ruler
				opinion = -50
				modifier = humiliated_opinion
			}
		}
		ai_chance = {
			base = 0
		}
	}
}

# Ruler = Unleash the Hounds of War
loaa_legitimist_support_events.6 = {
	type = character_event
	title = loaa_legitimist_support_events.6.t_deal
	desc = loaa_legitimist_support_events.6.desc_deal

	theme = war

	override_background = { reference = army_camp }

	immediate = {
		scope:claimant = {
			add_character_flag = need_military_outfit
		}
		remove_short_term_gold = legitimist_invested_gold_value
		add_prestige = legitimist_invested_prestige_value
		show_as_tooltip = { scope:claimant = { loaa_legitimist_support_add_effect = yes } }
	}

	left_portrait = {
		character = scope:petitioned_ruler
		animation = war_over_win
	}

	right_portrait = {
		character = scope:claimant
		animation = celebrate_sword
	}

	option = {
		name = loaa_legitimist_support_events.6.a

		custom_tooltip = loaa_legitimist_support_events.6.tt

		ai_chance = {
			base = 100
		}
	}

	after = {
		trigger_event = loaa_legitimist_support_events.16
	}
}

# Claimant - Reminder about the timer!
loaa_legitimist_support_events.7 = {
	type = character_event
	title = ep3_laamps.8106.t
	desc = ep3_laamps.8106.desc

	theme = diplomacy
	override_background = { reference = army_camp }

	left_portrait = {
		character = root
		animation = personality_rational
	}

	right_portrait = {
		character = scope:petitioned_ruler
		animation = personality_vengeful
	}

	trigger = {
		government_has_flag = government_is_landless_adventurer
		has_realm_law = camp_purpose_legitimists
		NOT = {
			is_at_war = yes
			any_held_title = {
				this = scope:claimed_title
			}
		}
		scope:petitioned_ruler = {
			is_alive = yes
			is_landed = yes
			NOR = {
				is_imprisoned_by = root
				AND = {
					is_at_war = yes
					any_character_war = {
						OR = {
							primary_attacker = root
							primary_defender = root
						}
					}
				}
			}
		}
	}

	on_trigger_fail = {
		if = {
			limit = {
				is_at_war = yes
			}
			trigger_event = { #let us try again later
				id = loaa_legitimist_support_events.7
				months = { 2 4 }
			}
		}
		else_if = {
			limit = {
				any_held_title = {
					this = scope:claimed_title
				}
			}
			trigger_event = { #payup buddy boi
				id = loaa_legitimist_support_events.12
				months = { 18 20 }
			}
		}
		else_if = {
			limit = {
				scope:petitioned_ruler = {
					OR = {
						is_alive = no
						is_landed = no
						is_imprisoned_by = root
						AND = {
							is_at_war = yes
							any_character_war = {
								OR = {
									primary_attacker = root
									primary_defender = root
								}
							}
						}
					}
				}
			}
			trigger_event = {
				id = ep3_laamps.8110
			}
		}
		else = {
			trigger_event = { #you failed
				id = ep3_laamps.8107
				months = { 1 2 }
			}
		}
	}

	option = { #go to war
		name = ep3_laamps.8106.a
		flavor = ep3_laamps.8106.a.desc
		#it is ugly, but it seems there is no other way
		every_claim = {
			limit = {
				OR = {
					holder = scope:claimed_title.holder
					holder.top_liege = scope:claimed_title.holder
				}
			}
			loaa_ep3_laamps_8106_designate_targets_effect = yes
		}

		# Ugly war targeting.
			## 10 targets.
			if = {
				limit = { exists = scope:target_10 }
				start_war = {
					casus_belli = claim_cb
					target = scope:claimed_title.holder
					claimant = root
					target_title = scope:target_1
					target_title = scope:target_2
					target_title = scope:target_3
					target_title = scope:target_4
					target_title = scope:target_5
					target_title = scope:target_6
					target_title = scope:target_7
					target_title = scope:target_8
					target_title = scope:target_9
					target_title = scope:target_10
				}
			}
			## 09 targets.
			else_if = {
				limit = { exists = scope:target_9 }
				start_war = {
					casus_belli = claim_cb
					target = scope:claimed_title.holder
					claimant = root
					target_title = scope:target_1
					target_title = scope:target_2
					target_title = scope:target_3
					target_title = scope:target_4
					target_title = scope:target_5
					target_title = scope:target_6
					target_title = scope:target_7
					target_title = scope:target_8
					target_title = scope:target_9
				}
			}
			## 08 targets.
			else_if = {
				limit = { exists = scope:target_8 }
				start_war = {
					casus_belli = claim_cb
					target = scope:claimed_title.holder
					claimant = root
					target_title = scope:target_1
					target_title = scope:target_2
					target_title = scope:target_3
					target_title = scope:target_4
					target_title = scope:target_5
					target_title = scope:target_6
					target_title = scope:target_7
					target_title = scope:target_8
				}
			}
			## 07 targets.
			else_if = {
				limit = { exists = scope:target_7 }
				start_war = {
					casus_belli = claim_cb
					target = scope:claimed_title.holder
					claimant = root
					target_title = scope:target_1
					target_title = scope:target_2
					target_title = scope:target_3
					target_title = scope:target_4
					target_title = scope:target_5
					target_title = scope:target_6
					target_title = scope:target_7
				}
			}
			## 06 targets.
			else_if = {
				limit = { exists = scope:target_6 }
				start_war = {
					casus_belli = claim_cb
					target = scope:claimed_title.holder
					claimant = root
					target_title = scope:target_1
					target_title = scope:target_2
					target_title = scope:target_3
					target_title = scope:target_4
					target_title = scope:target_5
					target_title = scope:target_6
				}
			}
			## 05 targets.
			else_if = {
				limit = { exists = scope:target_5 }
				start_war = {
					casus_belli = claim_cb
					target = scope:claimed_title.holder
					claimant = root
					target_title = scope:target_1
					target_title = scope:target_2
					target_title = scope:target_3
					target_title = scope:target_4
					target_title = scope:target_5
				}
			}
			## 04 targets.
			else_if = {
				limit = { exists = scope:target_4 }
				start_war = {
					casus_belli = claim_cb
					target = scope:claimed_title.holder
					claimant = root
					target_title = scope:target_1
					target_title = scope:target_2
					target_title = scope:target_3
					target_title = scope:target_4
				}
			}
			## 03 targets.
			else_if = {
				limit = { exists = scope:target_3 }
				start_war = {
					casus_belli = claim_cb
					target = scope:claimed_title.holder
					claimant = root
					target_title = scope:target_1
					target_title = scope:target_2
					target_title = scope:target_3
				}
			}
			## 02 targets.
			else_if = {
				limit = { exists = scope:target_2 }
				start_war = {
					casus_belli = claim_cb
					target = scope:claimed_title.holder
					claimant = root
					target_title = scope:target_1
					target_title = scope:target_2
				}
			}
			## 01 targets.
			else_if = {
				limit = { exists = scope:target_1 }
				start_war = {
					casus_belli = claim_cb
					target = scope:claimed_title.holder
					claimant = root
					target_title = scope:target_1
				}
			}

		ai_chance = {
			base = 100
		}

		trigger_event = {
			id = loaa_legitimist_support_events.7
			months = { 11 13 }
		}
	}

	option = { #actually, nvm, I have other plans now
		name = ep3_laamps.8106.c
		custom_tooltip = ep3_laamps.8106.c.desc

		trigger_event = {
			id = loaa_legitimist_support_events.8
			months = { 1 2 }
		}

		ai_chance = {
			base = 0
			modifier = {
				add = 50
				martial >= 15
				diplomacy >= 15
				ai_honor < -20
			}
			modifier = {
				factor = 0
				OR = {
					has_relation_best_friend = scope:petitioned_ruler
					has_relation_friend = scope:petitioned_ruler
					has_relation_lover = scope:petitioned_ruler
					has_relation_soulmate = scope:petitioned_ruler
					has_relation_blood_brother = scope:petitioned_ruler
					has_trait = loyal
				}
			}
		}
	}
}

# Claimant - Invalidation upon changing the camp type or becoming landed
loaa_legitimist_support_events.8 = {
	type = letter_event
	opening = ep3_laamps.8107.t
	desc = ep3_laamps.8107.desc
	sender = scope:petitioned_ruler

	option = { #well, fate had another things in mind
		name = ep3_laamps.8107.a
		add_prestige_level = -1
		if = {
			limit = {
				NOT = {
					has_relation_rival = scope:petitioned_ruler
				}
			}
			set_relation_rival = {
				target = scope:petitioned_ruler
				reason = rival_nithing
			}
		}
		remove_list_variable = {
			name = loaa_legitimist_supporters
			target = scope:petitioned_ruler
		}
		save_scope_as = sender
		scope:petitioned_ruler = {
			remove_variable = legitimist_obligations_left
			remove_character_flag = legitimist_supporter

			trigger_event = loaa_legitimist_support_events.10
		}
		add_to_variable_list = {
			name = legitimist_payed_supporters
			target = scope:petitioned_ruler
		}
		scope:petitioned_ruler = {
			remove_hook = {
				target = root
			}
		}
	}

}

# Claimant - Obligations payment
loaa_legitimist_support_events.9 = {
	type = character_event
	title = ep3_laamps.8108.t
	desc = ep3_laamps.8108.desc

	theme = stewardship
	override_background = { reference = study }

	left_portrait = {
		character = root
		animation = personality_rational
	}

	right_portrait = {
		character = scope:petitioned_ruler
		animation = personality_greedy
	}

	trigger = {
		scope:petitioned_ruler = {
			is_alive = yes
			is_landed = yes
			NOR = {
				is_imprisoned_by = root
				AND = {
					is_at_war = yes
					any_character_war = {
						OR = {
							primary_attacker = root
							primary_defender = root
						}
					}
				}
			}
		}
	}

	immediate = {
		add_to_variable_list = { #error suppresion
			name = loaa_legitimist_supporters
			target = root
		}
	}

	on_trigger_fail = {
		trigger_event = {
			id = ep3_laamps.8110
			days = { 1 2 }
		}
	}

	option = {
		name = ep3_laamps.8108.a

		if = {
			limit = {
				scope:petitioned_ruler.var:legitimist_obligations_left > 1
			}
			custom_tooltip = ep3_laamps.8108.payments_left
		}
		else = {
			custom_tooltip = ep3_laamps.8108.no_payments_left
			scope:petitioned_ruler = {
				remove_variable = legitimist_obligations_left
				remove_character_flag = legitimist_supporter
			}
			add_to_variable_list = {
				name = legitimist_payed_supporters
				target = scope:petitioned_ruler
			}
			scope:petitioned_ruler = {
				if = {
					limit = {
						NOT = {
							has_hook_of_type = {
								target = root
								type = strong_favor_hook
							}
						}
					}
					remove_hook = {
						target = root
					}
				}
			}
		}

		if = {
			limit = {
				monthly_character_income <= 50
			}
			custom_tooltip = ep3_laamps.8108.legitimist_too_poor
		}

		add_legitimacy = medium_legitimacy_gain
		scope:petitioned_ruler = {
			change_variable = {
				name = legitimist_obligations_left
				subtract = 1
			}
			send_interface_toast = {
				type = event_toast_effect_good
				title = loaa_legitimist_support_events.9.t_payment_received
				left_icon = scope:claimant
				scope:claimant = { save_temporary_scope_as = sender }
				scope:claimant = {
					pay_short_term_gold = {
						target = scope:petitioned_ruler
						gold = {
							value = monthly_character_income
							multiply = 6
							min = 300
						}
					}
				}
				if = {
					limit = { this.var:legitimist_obligations_left ?= { this > 0 } }
					custom_tooltip = loaa_legitimist_support_events.15.a.tt
				}
				else = {
					custom_tooltip = loaa_legitimist_support_events.15.a.last_payment_tt
				}
			}

		}

		if = {
			limit = {
				scope:petitioned_ruler.var:legitimist_obligations_left > 1
			}
			trigger_event = {
				id = loaa_legitimist_support_events.12
				months = { 18 20 }
			}
		}

		ai_chance = {
			base = 30
			# Opinion
			opinion_modifier = {
				opinion_target = scope:petitioned_ruler
				multiplier = 1.0
			}
		}
	}

	# option = { #Alas, I cannot pay you now, but I will in the future
	# 	name = ep3_laamps.8108.b
	# 	custom_tooltip = ep3_laamps.8108.b.desc

	# 	duel = {
	# 		target = scope:petitioned_ruler
	# 		skill = stewardship

	# 		50 = {
	# 			compare_modifier = {
	# 				value = scope:duel_value
	# 				multiplier = 3.5
	# 				min = -49
	# 			}
	# 			desc = ep3_laamps.8108.b.success
	# 			send_interface_toast = {
	# 				title = ep3_laamps.8108.b.success
	# 				left_icon = scope:petitioned_ruler
	# 			}
	# 		}
	# 		50 = {
	# 			compare_modifier = {
	# 				value = scope:duel_value
	# 				multiplier = -3.5
	# 				min = -49
	# 			}
	# 			desc = ep3_laamps.8108.b.failure
	# 			send_interface_toast = {
	# 				title = ep3_laamps.8108.b.failure
	# 				left_icon = scope:petitioned_ruler
	# 				add_legitimacy = medium_legitimacy_loss
	# 			}
	# 		}
	# 	}
	# 	trigger_event = {
	# 		id = ep3_laamps.8111
	# 		months = { 6 7 }
	# 	}
	# 	if = {
	# 		limit = {
	# 			scope:petitioned_ruler.var:legitimist_obligations_left > 1
	# 		}
	# 		custom_tooltip = ep3_laamps.8108.payments_left
	# 	}
	# 	else = {
	# 		custom_tooltip = ep3_laamps.8108.no_payments_left
	# 	}
	# }

	option = {
		name = ep3_laamps.8108.c
		custom_tooltip = ep3_laamps.8108.c.desc
		trigger = {
			scope:petitioned_ruler = {
				NOT = {
					has_hook_of_type = {
						target = root
						type = strong_favor_hook
					}
				}
			}
			# OR = {
			# 	scope:petitioned_ruler = {
			# 		NOT = {
			# 			has_hook_of_type = {
			# 				target = root
			# 				type = strong_favor_hook
			# 			}
			# 		}
			# 	}
			# 	AND = {
			# 		scope:petitioned_ruler = {
			# 			has_hook_of_type = {
			# 				target = root
			# 				type = strong_favor_hook
			# 			}
			# 		}
			# 		has_trait = arbitrary
			# 	}
			# }
		}
		add_legitimacy = massive_legitimacy_loss
		add_prestige_level = -1
		trigger_event = {
			id = loaa_legitimist_support_events.8
			months = { 1 2 }
		}
		ai_chance = {
			base = 0
			# Opinion
			opinion_modifier = {
				opinion_target = scope:petitioned_ruler
				multiplier = -1.0
			}
		}
	}
}

# Ruler - Claimant Breaks Agreement (Letter)
loaa_legitimist_support_events.10 = {
	type = letter_event
	sender = scope:sender
	desc = loaa_legitimist_support_events.10.desc

	opening = {
		desc = feast.1501.opening
	}

	immediate = {
		show_as_tooltip = {
			scope:claimant = {
				if = {
					limit = {
						NOT = {
							has_relation_rival = scope:petitioned_ruler
						}
					}
					set_relation_rival = {
						target = scope:petitioned_ruler
						reason = rival_nithing
					}
				}
			}
		}
	}

	option = {
		name = loaa_legitimist_support_events.10.a
		scope:claimant = { clear_saved_scope = sender }
	}
}

# Ruler - Claimant Refusal (Letter)
loaa_legitimist_support_events.11 = {
	type = letter_event
	sender = scope:sender
	desc = loaa_legitimist_support_events.11.desc

	opening = {
		desc = feast.1501.opening
	}


	option = {
		name = feast.0010.a
		add_prestige = -100
	}
}

# Payment Info
loaa_legitimist_support_events.12 = {
	hidden = yes

	immediate = {
		trigger_event = {
			id = loaa_legitimist_support_events.9
			months = 6
		}
		save_scope_value_as = {
			name = incoming_payment_value
			value = {
				value = monthly_character_income
				multiply = 6
				min = 300
			}
		}
		send_interface_toast = {
			type = event_toast_effect_bad
			title = ep3_laamps.8111.t
			left_icon = scope:petitioned_ruler
			custom_tooltip = ep3_laamps.8111.desc
		}
		save_scope_as = sender
		scope:petitioned_ruler = {
			send_interface_toast = {
				type = event_toast_effect_good
				title = ep3_laamps.8111.t
				left_icon = scope:sender
				custom_tooltip = loaa_legitimist_support_events.12.desc
				custom_tooltip = loaa_legitimist_support_events.15.a.tt
			}
		}
		clear_saved_scope = sender

	}
}

# Ruler - No Deal
loaa_legitimist_support_events.13 = {
	type = character_event
	title = loaa_legitimist_support_events.13.t
	desc = loaa_legitimist_support_events.13.desc

	theme = diplomacy

	override_background = { reference = throne_room }

	left_portrait = {
		character = scope:petitioned_ruler
		animation = anger
	}

	right_portrait = {
		character = scope:claimant
		animation = dismissal
	}

	immediate = {
		scope:claimant = {
			if = {
				limit = {
					NOT = {
						has_relation_rival = scope:petitioned_ruler
					}
				}
				set_relation_rival = {
					target = scope:petitioned_ruler
					reason = rival_nithing
				}
			}
		}
	}

	option = {
		name = loaa_legitimist_support_events.13.a
	}

	after = {
		trigger_event = loaa_legitimist_support_events.16
	}
}

# Claimant - you have died, but you still have obligations to pay - reminder - ???
loaa_legitimist_support_events.14 = {
	type = letter_event
	opening = ep3_laamps.8109.t
	desc = ep3_laamps.8109.desc
	sender = scope:petitioned_ruler

	option = { #gulp
		name = ep3_laamps.8109.a
		custom_tooltip = ep3_laamps.8109.a.desc

		trigger_event = {
			id = loaa_legitimist_support_events.12
			months = { 6 7 }
		}
	}
}

# Ruler - Title taken by the Claimant (Letter)
loaa_legitimist_support_events.15 = {
	type = letter_event
	opening = {
		desc = feast.1501.opening
	}
	desc = loaa_legitimist_support_events.15.desc
	sender = scope:sender

	option = {
		name = loaa_legitimist_support_events.15.a
		flavor = loaa_legitimist_support_events.15.a.tt
		#custom_tooltip = loaa_legitimist_support_events.15.a.desc
	}
	after = {
		clear_saved_scope = sender
	}
}

# Cleanup event
loaa_legitimist_support_events.16 = {
	hidden = yes
	immediate = {
		if = {
			limit = { exists = scope:asking_for_less_obligations }
			clear_saved_scope = asking_for_less_obligations
		}
		scope:petitioned_ruler = {
			if = {
				limit = { has_character_flag = strong_hook_yes }
				remove_character_flag = strong_hook_yes
			}
			if = {
				limit = { has_character_flag = answer_given }
				remove_character_flag = answer_given
			}
		}

		scope:claimant = {
			remove_variable = legitimist_support
			remove_variable = legitimist_obligations
			if = {
				limit = { has_variable = potential_legitimist_supporter }
				remove_variable = potential_legitimist_supporter
			}
			if = {
				limit = { has_character_flag = need_military_outfit}
				remove_character_flag = need_military_outfit
			}
		}
	}
}