###########################################
#                                         #
# ZE Alliance Events 2	                  #
# ID ZE.9000-ZE.9999                      #
#                                         #
###########################################

# Written by Tobias Bodlund

namespace = ZE

###########################################
# Ally in war fails to contribute         #
###########################################

character_event = {
	id = ZE.9000
	desc = EVTDESC_ZE_9000
	picture = GFX_evt_large_army
	border = GFX_event_normal_frame_war

	is_triggered_only = yes # on_yearly_pulse

	only_playable = yes
	war = yes
	has_dlc = "Conclave"
	only_capable = yes
	prisoner = no

	trigger = {
		OR = {
			is_primary_war_attacker = yes
			is_primary_war_defender = yes
		}

		any_allied_character = {
			war = yes

			ROOT = {
				any_war = {
					days_since_last_hostile_action = {
						who = PREVPREV	# The character whose activity is being checked
						days >= 1460	# Number of days since last battle participation or offensive siege (4 years)
					}
				}

				trigger_if = {
					limit = { is_tributary = yes }

					suzerain = {
						NOR = {
							character = PREVPREV
							is_vassal_or_below_of = PREVPREV
						}
					}
				}
			}

			trigger_if = {
				limit = { is_tributary = yes }

				suzerain = {
					NOR = {
						character = ROOT
						is_vassal_or_below_of = ROOT
					}
				}
			}

			trigger_if = {
				limit = { same_realm = ROOT }

				NAND = {
					is_tribal = yes
					ROOT = { is_tribal = yes }
				}

				NAND = {
					is_nomadic = yes
					ROOT = { is_nomadic = yes }
				}
			}
		}
	}

	immediate = {
		random_allied_character = {
			limit = {
				war = yes

				ROOT = {
					any_war = {
						days_since_last_hostile_action = {
							who = PREVPREV	# The character whose activity is being checked
							days >= 1460	# Number of days since last battle participation or offensive siege (4 years)
						}
					}

					trigger_if = {
						limit = { is_tributary = yes }

						suzerain = {
							NOR = {
								character = PREVPREV
								is_vassal_or_below_of = PREVPREV
							}
						}
					}
				}

				trigger_if = {
					limit = { is_tributary = yes }

					suzerain = {
						NOR = {
							character = ROOT
							is_vassal_or_below_of = ROOT
						}
					}
				}

				trigger_if = {
					limit = { same_realm = ROOT }

					NAND = {
						is_tribal = yes
						ROOT = { is_tribal = yes }
					}

					NAND = {
						is_nomadic = yes
						ROOT = { is_nomadic = yes }
					}
				}
			}

			save_event_target_as = ally_not_active_in_war
		}
	}

	option = {
		name = EVTOPTA_ZE_9000 # Send angry letter and break alliance

		opinion = {
			name = ally_inactive_in_war
			who = event_target:ally_not_active_in_war
			years = 5
		}

		if = {
			limit = { is_allied_with = event_target:ally_not_active_in_war }
			break_alliance = event_target:ally_not_active_in_war
		}

		event_target:ally_not_active_in_war = {
			show_scope_change = no

			letter_event = {
				id = ZE.9001
				tooltip = ze_9000_letter_sent
			}
		}
	}

	option = {
		name = EVTOPTB_ZE_9000 # Forgive and forget

		opinion = {
			name = opinion_disappointed
			who = event_target:ally_not_active_in_war
			years = 3
		}
	}
}

# If FROM chose to break alliance, failing ally receives alliance-breaking letter
letter_event = {
	id = ZE.9001
	desc = EVTDESC_ZE_9001
	border = GFX_event_letter_frame_war

	is_triggered_only = yes

	ai = no

	option = {
		name = EVTOPTA_ZE_9001

		tooltip = {
			break_alliance = FROM
		}
	}
}

###########################################
# Pirates!						          #
###########################################

# Pirates operate on seas - rumors say other realm's ruler is behind it
character_event = {
	id = ZE.9100
	desc = EVTDESC_ZE_9100
	picture = GFX_evt_large_army
	border = GFX_event_normal_frame_war

	is_triggered_only = yes

	only_independent = yes
	has_dlc = "Conclave"
	only_capable = yes
	prisoner = no
	war = no

	trigger = {
		is_tributary = no

		any_realm_province = {
			is_coastal = yes
			held_under_PREV = yes
		}

		any_independent_ruler = {
			OR = {
				has_non_aggression_pact_with = ROOT
				is_allied_with = ROOT
			}

			any_realm_province = {
				is_coastal = yes
				held_under_PREV = yes
			}

			trigger_if = {
				limit = { is_tributary = yes }

				suzerain = {
					NOR = {
						character = ROOT
						is_vassal_or_below_of = ROOT
					}
				}
			}

			is_within_diplo_range = ROOT
			war = no
		}
	}

	immediate = {
		random_independent_ruler = {
			limit = {
				OR = {
					has_non_aggression_pact_with = ROOT
					is_allied_with = ROOT
				}

				any_realm_province = {
					is_coastal = yes
					held_under_PREV = yes
				}

				trigger_if = {
					limit = { is_tributary = yes }

					suzerain = {
						NOR = {
							character = ROOT
							is_vassal_or_below_of = ROOT
						}
					}
				}

				is_within_diplo_range = ROOT
				war = no
			}

			save_event_target_as = pirate_alliance_friction_ally
		}
	}

	option = {
		name = EVTOPTA_ZE_9100	# Send letter with suspicion

		custom_tooltip = {
			text = EVTOPTA_ZE_9100_TOOLTIP

			event_target:pirate_alliance_friction_ally = {
				letter_event = { id = ZE.9101 }
			}

			any_realm_province = {
				limit = {
					is_coastal = yes
					held_under_PREV = yes
				}

				add_province_modifier = {
					name = marauding_pirates
					years = 5
				}
			}
		}
	}
}

# Ally receives first letter
letter_event = {
	id = ZE.9101
	desc = EVTDESC_ZE_9101
	border = GFX_event_letter_frame_diplomacy

	is_triggered_only = yes

	only_capable = yes

	option = {
		name = EVTOPTA_ZE_9101 # Answer cordially

		prestige = -50

		FROM = {
			show_scope_change = no

			letter_event = {
				id = ZE.9110
				days = 20
				tooltip = ze_9101_cordial
			}
		}

		ai_chance = {
			factor = 1

			mult_modifier = {
				factor = 2
				trait = trusting
			}
		}
	}

	option = {
		name = EVTOPTB_ZE_9101 # Answer with countersuspicion

		prestige = 50

		FROM = {
			show_scope_change = no

			letter_event = {
				id = ZE.9120
				days = 20
				tooltip = ze_9101_angry
			}
		}

		ai_chance = {
			factor = 1

			mult_modifier = {
				factor = 2
				trait = paranoid
			}
		}
	}
}

# A receives cordial answer
letter_event = {
	id = ZE.9110
	desc = EVTDESC_ZE_9110
	border = GFX_event_letter_frame_diplomacy

	is_triggered_only = yes

	only_capable = yes

	option = {
		name = EVTOPTA_ZE_9110 # Accept

		prestige = -50

		ai_chance = {
			factor = 1

			mult_modifier = {
				factor = 2
				trait = trusting
			}
		}
	}

	option = {
		name = EVTOPTB_ZE_9110 # They are playing dumb. Break pact

		FROM = {
			show_scope_change = no

			letter_event = {
				id = ZE.9111
				tooltip = ze_9121_break_pact
			}
		}

		tooltip = {
			if = {
				limit = { is_allied_with = FROM }
				break_alliance = FROM
			}

			if = {
				limit = { has_non_aggression_pact_with = FROM }

				reverse_opinion = {
					name = broken_non_aggression_pact
					who = FROM
					years = 5
				}
			}
		}

		ai_chance = {
			factor = 1

			mult_modifier = {
				factor = 2
				trait = paranoid
			}
		}
	}
}

# Notify ally of broken pact
letter_event = {
	id = ZE.9111
	desc = EVTDESC_ZE_9111
	border = GFX_event_letter_frame_diplomacy

	is_triggered_only = yes

	option = {
		name = EVTOPTA_ZE_9111 # Accept

		prestige = -50

		if = {
			limit = { is_allied_with = FROM }
			break_alliance = FROM
		}

		if = {
			limit = { has_non_aggression_pact_with = FROM }

			opinion = {
				name = broken_non_aggression_pact
				who = FROM
				years = 5
			}
		}
	}
}

# A receives suspicious answer
letter_event = {
	id = ZE.9120
	desc = EVTDESC_ZE_9120
	border = GFX_event_letter_frame_diplomacy

	is_triggered_only = yes

	only_capable = yes

	option = {
		name = EVTOPTA_ZE_9120 # Try to repair it

		prestige = -50

		FROM = {
			show_scope_change = no

			letter_event = {
				id = ZE.9121
				days = 20
				tooltip = ze_9120_soothing
			}
		}

		ai_chance = {
			factor = 1

			mult_modifier = {
				factor = 2
				diplomacy = 15
			}
		}
	}

	option = {
		name = EVTOPTB_ZE_9120 # Answer with counter-countersuspicion

		prestige = 50

		FROM = {
			show_scope_change = no

			letter_event = {
				id = ZE.9130
				days = 20
				tooltip = ze_9101_angry
			}
		}

		ai_chance = {
			factor = 1

			mult_modifier = {
				factor = 2
				trait = paranoid
			}
		}
	}
}

# Ally receives repair attempt
letter_event = {
	id = ZE.9121
	desc = EVTDESC_ZE_9121
	border = GFX_event_letter_frame_diplomacy

	is_triggered_only = yes

	only_capable = yes

	option = {
		name = EVTOPTA_ZE_9121 # Accept

		prestige = -50

		FROM = {
			show_scope_change = no

			letter_event = {
				id = ZE.9122
				tooltip = ze_9121_accept_apology
			}
		}

		ai_chance = {
			factor = 1

			mult_modifier = {
				factor = 2
				diplomacy >= 15
			}
		}
	}

	option = {
		name = EVTOPTB_ZE_9121 # Pact broken

		prestige = 50

		FROM = {
			show_scope_change = no

			letter_event = {
				id = ZE.9123
				tooltip = ze_9121_break_pact
			}
		}

		tooltip = {
			if = {
				limit = { is_allied_with = FROM }
				break_alliance = FROM
			}

			if = {
				limit = { has_non_aggression_pact_with = FROM }

				reverse_opinion = {
					name = broken_non_aggression_pact
					who = FROM
					years = 5
				}
			}
		}

		ai_chance = {
			factor = 1

			mult_modifier = {
				factor = 2
				trait = paranoid
			}
		}
	}
}

# Notify accept repair
letter_event = {
	id = ZE.9122
	desc = EVTDESC_ZE_9122
	border = GFX_event_letter_frame_diplomacy

	is_triggered_only = yes

	option = {
		name = EVTOPTA_ZE_9122

		prestige = 50
	}
}

# Notify broken pact
letter_event = {
	id = ZE.9123
	desc = EVTDESC_ZE_9123
	border = GFX_event_letter_frame_diplomacy

	is_triggered_only = yes

	option = {
		name = EVTOPTA_ZE_9123

		prestige = -50

		if = {
			limit = { is_allied_with = FROM }
			break_alliance = FROM
		}

		if = {
			limit = { has_non_aggression_pact_with = FROM }

			opinion = {
				name = broken_non_aggression_pact
				who = FROM
				years = 5
			}
		}
	}
}

# Ally receives counter-countersuspicion
letter_event = {
	id = ZE.9130
	desc = EVTDESC_ZE_9130
	border = GFX_event_letter_frame_diplomacy

	is_triggered_only = yes

	only_capable = yes

	option = {
		name = EVTOPTA_ZE_9130 # Swallow it and shut up

		prestige = -50

		FROM = {
			show_scope_change = no

			letter_event = {
				id = ZE.9131
				tooltip = ze_9130_apology
			}
		}

		ai_chance = {
			factor = 1

			mult_modifier = {
				factor = 2
				diplomacy = 15
			}
		}
	}

	option = {
		name = EVTOPTB_ZE_9130 # Pact broken

		prestige = 50

		FROM = {
			show_scope_change = no

			letter_event = {
				id = ZE.9132
				tooltip = ze_9121_break_pact
			}
		}

		tooltip = {
			if = {
				limit = { is_allied_with = FROM }
				break_alliance = FROM
			}

			if = {
				limit = { has_non_aggression_pact_with = FROM }

				reverse_opinion = {
					name = broken_non_aggression_pact
					who = FROM
					years = 5
				}
			}
		}

		ai_chance = {
			factor = 1

			mult_modifier = {
				factor = 2
				trait = paranoid
			}
		}
	}
}

# Notify ally swallowed pride
letter_event = {
	id = ZE.9131
	desc = EVTDESC_ZE_9131
	border = GFX_event_letter_frame_diplomacy

	is_triggered_only = yes

	option = {
		name = EVTOPTA_ZE_9131

		prestige = 50
	}
}

# Notify broken pact
letter_event = {
	id = ZE.9132
	desc = EVTDESC_ZE_9132
	border = GFX_event_letter_frame_diplomacy

	is_triggered_only = yes

	option = {
		name = GOOD_RIDDANCE

		prestige = -50

		if = {
			limit = { is_allied_with = FROM }
			break_alliance = FROM
		}

		if = {
			limit = { has_non_aggression_pact_with = FROM }

			opinion = {
				name = broken_non_aggression_pact
				who = FROM
				years = 5
			}
		}
	}
}