﻿# Faction invitation events

namespace = faction_invitation

# Join Claimant Faction as Claimant Invitation
# by Ismael Serrano
faction_invitation.0001 = {
	type = letter_event
	opening = {
		desc = FACTION_CLAIMANT_INVITE
	}
	desc = FACTION_CLAIMANT_INVITE_DESC
	sender = scope:faction_invite_from

	trigger = {
		exists = scope:faction
	}

	option = {
		name = "FACTION_CLAIMANT_INVITE_ACCEPT"
		trigger = {
			can_join_faction = scope:faction
		}
		ai_chance = {
			base = 100
		}

		if = { # Extra safeguard for players who might do something while the invitation is active
			limit = {
				exists = scope:faction
				can_join_faction = scope:faction
			}
			
			join_faction = scope:faction
			
			save_scope_as = faction_claimant
			scope:faction_invite_from = {
				trigger_event = faction_invitation.0002
			}
		}
		else = {
			if = {
				limit = {
					is_a_faction_member = yes
				}
				custom_tooltip = WARNING_I_HAVE_ALREADY_JOINED_A_FACTION
			}
			else_if = {
				limit = {
					is_at_war_with = scope:faction.faction_target
				}
				custom_tooltip = WARNING_I_AM_ALREADY_AT_WAR_WITH_TARGET
			}
			else = {
				custom_tooltip = WARNING_INVITE_CANNOT_JOIN
			}

			save_scope_as = faction_claimant
			scope:faction_invite_from = {
				trigger_event = faction_invitation.0003
			}
		}
	}

	option = {
		name = FACTION_CLAIMANT_INVITE_REFUSE
		
		save_scope_as = faction_claimant
		scope:faction_invite_from = {
			trigger_event = faction_invitation.0003
		}
	}
}

# Join Claimant Faction as Claimant Accepted
# by Ismael Serrano
faction_invitation.0002 = {
	type = letter_event
	opening = {
		desc = FACTION_CLAIMANT_INVITE_ACCEPTED
	}
	desc = FACTION_CLAIMANT_INVITE_ACCEPTED_DESC
	sender = scope:faction_claimant

	option = {
		name = FACTION_CLAIMANT_INVITE_ACCEPTED_OPT
	}
}

# Join Claimant Faction as Claimant Refused
# by Ismael Serrano
faction_invitation.0003 = {
	type = letter_event
	opening = {
		desc = FACTION_CLAIMANT_INVITE_REFUSED
	}
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:faction.faction_target = { has_strong_hook = scope:faction_claimant }
				}
				desc = FACTION_CLAIMANT_INVITE_REFUSED_HOOK_DESC
			}
			triggered_desc = {
				trigger = {
					scope:faction_claimant = { age < 14 }
				}
				desc = FACTION_CLAIMANT_INVITE_REFUSED_CHILD_DESC
			}
			triggered_desc = {
				trigger = {
					scope:faction_claimant = {
						OR = {
							is_imprisoned = yes
							has_trait = incapable
							AND = {
								is_landed = yes
								liege != scope:faction.faction_target
							}
						}
					}
				}
				desc = FACTION_CLAIMANT_INVITE_REFUSED_PREDICAMENT_DESC
			}
			triggered_desc = {
				trigger = {
					scope:faction_claimant = {
						OR = {
							is_landed = no
							highest_held_title_tier < tier_county
						}
					}
				}
				desc = FACTION_CLAIMANT_INVITE_REFUSED_INSIGNIFICANT_DESC
			}
			desc = FACTION_CLAIMANT_INVITE_REFUSED_DESC
		}
	}
	sender = scope:faction_claimant

	option = {
		name = FACTION_CLAIMANT_INVITE_REFUSED_OPT
	}
}
