###########################################
#                                         #
# 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
	
	only_playable = yes
	only_capable = yes
	prisoner = no
	has_dlc = "Zeus"
	war = yes
	
	trigger = {
		OR = {
			is_primary_war_attacker = yes
			is_primary_war_defender = yes
		}
		any_allied_character = {
			NOR = {
				AND = {
					is_tributary = yes
					suzerain = {
						OR = {
							character = ROOT
							any_liege = {
								character = ROOT
							}
						}
					}
				}
				AND = {
					ROOT = {
						is_tributary = yes
						suzerain = {
							OR = {
								character = PREV
								any_liege = {
									character = PREV
								}
							}
						}
					}
				}
				AND = {
					is_tribal = yes
					same_realm = ROOT
					ROOT = {
						is_tribal = yes
					}
				}
				AND = {
					is_nomadic = yes
					same_realm = ROOT
					ROOT = {
						is_nomadic = yes
					}
				}
			}
			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)
					}
				}
			}
		}
	}
	
	immediate = {
		random_allied_character = {
			limit = {
				NOR = {
					AND = {
						is_tributary = yes
						suzerain = {
							OR = {
								character = ROOT
								any_liege = {
									character = ROOT
								}
							}
						}
					}
					AND = {
						ROOT = {
							is_tributary = yes
							suzerain = {
								OR = {
									character = PREV
									any_liege = {
										character = PREV
									}
								}
							}
						}
					}
					AND = {
						is_tribal = yes
						same_realm = ROOT
						ROOT = {
							is_tribal = yes
						}
					}
					AND = {
						is_nomadic = yes
						same_realm = ROOT
						ROOT = {
							is_nomadic = yes
						}
					}
				}
				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)
						}
					}
				}
			}
			save_event_target_as = ally_not_active_in_war
		}
	}
	
	option = {
		name = EVTOPTA_ZE_9000  # Send angry letter and break alliance
		event_target:ally_not_active_in_war = {
			reverse_opinion = {
				who = ROOT
				modifier = ally_inactive_in_war
				years = 5
			}
			ROOT = {
				if = {
					limit = {
						is_allied_with = PREV
					}
					break_alliance = PREV
				}
			}
			custom_tooltip = { text = ze_9000_letter_sent }
			hidden_tooltip = { letter_event = { id = ZE.9001 } }
		}
	}
	option = {
		name = EVTOPTB_ZE_9000	# Forgive and forget
		event_target:ally_not_active_in_war = {
			reverse_opinion = {
				who = ROOT
				modifier = opinion_disappointed
				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
	
	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
	only_capable = yes
	prisoner = no
	war = no
	has_dlc = "Zeus"
	
	trigger = {
		is_tributary = no
		any_realm_province = {
			port = yes
		}
		any_independent_ruler = {
			NOR = {
				AND = {
					is_tributary = yes
					suzerain = {
						OR = {
							character = ROOT
							any_liege = {
								character = ROOT
							}
						}
					}
				}
				AND = {
					ROOT = {
						is_tributary = yes
						suzerain = {
							OR = {
								character = PREV
								any_liege = {
									character = PREV
								}
							}
						}
					}
				}
			}
			OR = {
				has_non_aggression_pact_with = ROOT
				is_allied_with = ROOT
			}
			is_within_diplo_range = ROOT
			war = no
			any_realm_province = {
				port = yes
			}
		}
	}
	
	immediate = {
		random_independent_ruler = {
			limit = {
				NOT = { culture = wilderness }
				NOR = {
					AND = {
						is_tributary = yes
						suzerain = {
							OR = {
								character = ROOT
								any_liege = {
									character = ROOT
								}
							}
						}
					}
					AND = {
						ROOT = {
							is_tributary = yes
							suzerain = {
								OR = {
									character = PREV
									any_liege = {
										character = PREV
									}
								}
							}
						}
					}
				}
				OR = {
					has_non_aggression_pact_with = ROOT
					is_allied_with = 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
			hidden_tooltip = {
				event_target:pirate_alliance_friction_ally = {
					letter_event = { id = ZE.9101 }
				}
				any_realm_province = {
					limit = {
						port = 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
		ai_chance = {
			factor = 1
			modifier = {
				factor = 2
				trait = trusting
			}
		}
		prestige = -50
		hidden_tooltip = { FROM = { letter_event = { id = ZE.9110 days = 20 } } }
		custom_tooltip = { text = ze_9101_cordial }
	}
	option = {
		name = EVTOPTB_ZE_9101 # Answer with countersuspicion
		ai_chance = {
			factor = 1
			modifier = {
				factor = 2
				trait = paranoid
			}
		}
		prestige = 50
		hidden_tooltip = { FROM = { letter_event = { id = ZE.9120 days = 20 } } }
		custom_tooltip = { text = ze_9101_angry}
	}
}

# 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
		ai_chance = {
			factor = 1
			modifier = {
				factor = 2
				trait = trusting
			}
		}
		prestige = -50
	}
	option = {
		name = EVTOPTB_ZE_9110 # They are playing dumb. Break pact
		ai_chance = {
			factor = 1
			modifier = {
				factor = 2
				trait = paranoid
			}
		}
		custom_tooltip = { text = ze_9121_break_pact }
		hidden_tooltip = { FROM = { letter_event = { id = ZE.9111 } } }
		if = {
			limit = {
				is_allied_with = FROM
			}
			tooltip = { break_alliance = FROM }
		}
		if = {
			limit = {
				has_non_aggression_pact_with = FROM
			}
			tooltip = {
				reverse_opinion = {
					who = FROM
					years = 5
					modifier = broken_non_aggression_pact
				}
			}
		}
	}
}

# 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 = {
				who = FROM
				years = 5
				modifier = broken_non_aggression_pact
			}
		}
	}
}

# 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
		ai_chance = {
			factor = 1
			modifier = {
				factor = 2
				diplomacy = 15
			}
		}
		prestige = -50
		custom_tooltip = { text = ze_9120_soothing }
		hidden_tooltip = { FROM = { letter_event = { id = ZE.9121 days = 20 } } }
	}
	option = {
		name = EVTOPTB_ZE_9120 # Answer with counter-countersuspicion
		ai_chance = {
			factor = 1
			modifier = {
				factor = 2
				trait = paranoid
			}
		}
		prestige = 50
		custom_tooltip = { text = ze_9101_angry }
		hidden_tooltip = { FROM = { letter_event = { id = ZE.9130 days = 20 } } }
	}
}

# 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
		ai_chance = {
			factor = 1
			modifier = {
				factor = 2
				diplomacy = 15
			}
		}
		prestige = -50
		custom_tooltip = { text = ze_9121_accept_apology }
		hidden_tooltip = { FROM = { letter_event = { id = ZE.9122 } } }
	}
	option = {
		name = EVTOPTB_ZE_9121 # Pact broken
		ai_chance = {
			factor = 1
			modifier = {
				factor = 2
				trait = paranoid
			}
		}
		prestige = 50
		custom_tooltip = { text = ze_9121_break_pact }
		hidden_tooltip = { FROM = { letter_event = { id = ZE.9123 } } }
		if = {
			limit = {
				is_allied_with = FROM
			}
			tooltip = { break_alliance = FROM }
		}
		if = {
			limit = {
				has_non_aggression_pact_with = FROM
			}
			tooltip = {
				reverse_opinion = {
					who = FROM
					years = 5
					modifier = broken_non_aggression_pact
				}
			}
		}
	}
}

# 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 = {
				who = FROM
				years = 5
				modifier = broken_non_aggression_pact
			}
		}
	}
}

# 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
		ai_chance = {
			factor = 1
			modifier = {
				factor = 2
				diplomacy = 15
			}
		}
		prestige = -50
		custom_tooltip = { text = ze_9130_apology }
		hidden_tooltip = { FROM = { letter_event = { id = ZE.9131 } } }
	}
	option = {
		name = EVTOPTB_ZE_9130 # Pact broken
		ai_chance = {
			factor = 1
			modifier = {
				factor = 2
				trait = paranoid
			}
		}
		prestige = 50
		custom_tooltip = { text = ze_9121_break_pact }
		hidden_tooltip = { FROM = { letter_event = { id = ZE.9132 } } }
		if = {
			limit = {
				is_allied_with = FROM
			}
			tooltip = { break_alliance = FROM }
		}
		if = {
			limit = {
				has_non_aggression_pact_with = FROM
			}
			tooltip = {
				reverse_opinion = {
					who = FROM
					years = 5
					modifier = broken_non_aggression_pact
				}
			}
		}
	}
}

# 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 = {
				who = FROM
				years = 5
				modifier = broken_non_aggression_pact
			}
		}
	}
}

