#################################
#
# THE REPUBLIC
# - dynasty Feud Events
#
#################################

# Written by Henrik Eklund

namespace = REP

# The Great Ball
narrative_event = {
	id = REP.101
	title = EVTNAME_REP_101
	desc = EVTDESC_REP_101
	picture = GFX_evt_courtiers_talking
	portrait = event_target:feuding_patrician

	is_triggered_only = yes # on_bi_yearly_pulse, random_events, republic_dynastic_feud_events

	ai = no
	is_patrician = yes
	has_dlc = "The Republic"
	min_age = 16
	only_capable = yes
	prisoner = no
	in_command = no

	trigger = {
		is_inaccessible_trigger = no

		NOR = {
			has_dynasty_flag = the_victims
			has_character_flag = the_grand_ball
		}

		trigger_if = {
			limit = { is_merchant_republic = yes }

			any_vassal = {
				is_patrician = yes
				ai = yes
				in_command = no
				block_general_event_trigger = no
				NOT = { has_dynasty_flag = the_feuders }

				opinion = {
					who = ROOT
					value < 0
				}
			}
		}
		trigger_else = {
			liege = {
				any_vassal = {
					is_patrician = yes
					ai = yes
					in_command = no
					block_general_event_trigger = no
					NOT = { has_dynasty_flag = the_feuders }

					opinion = {
						who = ROOT
						value < 0
					}
				}
			}
		}
	}

	immediate = {
		set_character_flag = the_grand_ball

		if = {
			limit = { is_merchant_republic = yes }

			random_vassal = {
				limit = {
					is_patrician = yes
					ai = yes
					in_command = no
					block_general_event_trigger = no
					NOT = { has_dynasty_flag = the_feuders }

					opinion = {
						who = ROOT
						value < 0
					}
				}

				save_event_target_as = feuding_patrician
			}
		}
		else = {
			liege = {
				random_vassal = {
					limit = {
						is_patrician = yes
						ai = yes
						in_command = no
						block_general_event_trigger = no
						NOT = { has_dynasty_flag = the_feuders }

						opinion = {
							who = ROOT
							value < 0
						}
					}
				}

				save_event_target_as = feuding_patrician
			}
		}
	}

	option = {
		name = EVTOPTA_REP_101

		event_target:feuding_patrician = {
			set_dynasty_flag = the_feuders
		}

		set_dynasty_flag = the_victims

		narrative_event = {
			id = REP.102
			days = 15
			tooltip = EVTTOOLTIP_REP_102
		}
	}

	option = {
		name = EVTOPTB_REP_101

		prestige = -60

		custom_tooltip = {
			text = no_ball_tooltip
			clr_character_flag = the_grand_ball
		}
	}
}

# Arriving at the Ball...
narrative_event = {
	id = REP.102
	title = EVTNAME_REP_102
	desc = EVTDESC_REP_102
	picture = GFX_evt_scandal

	is_triggered_only = yes
	hide_from = yes

	option = {
		name = EVTOPTA_REP_102

		set_character_flag = shamed_at_ball
		prestige = -100

		event_target:feuding_patrician = {
			show_scope_change = no

			prestige = 100
			set_character_flag = shamed_player_at_ball
		}

		custom_tooltip = { text = feud_begins_tooltip }

		character_event = { id = REP.109 } # AI gets Feuding opinion modifier

		narrative_event = {
			id = REP.104
			months = 40
			random = 2400 # 80 months
		}
	}
}

# The Even Greater Ball
narrative_event = {
	id = REP.104
	title = EVTNAME_REP_104
	desc = EVTDESC_REP_104
	picture = GFX_evt_courtiers_talking

	is_triggered_only = yes

	ai = no
	is_patrician = yes
	has_dlc = "The Republic"
	has_character_flag = shamed_at_ball

	trigger = {
		is_inaccessible_trigger = no

		trigger_if = {
			limit = { is_merchant_republic = yes }

			any_vassal = {
				has_character_flag = shamed_player_at_ball
				is_patrician = yes
				ai = yes
				in_command = no
				block_general_event_trigger = no
				NOT = { trait = infirm }

				opinion = {
					who = ROOT
					value < 0
				}
			}
		}
		trigger_else = {
			liege = {
				any_vassal = {
					has_character_flag = shamed_player_at_ball
					is_patrician = yes
					ai = yes
					in_command = no
					block_general_event_trigger = no
					NOT = { trait = infirm }

					opinion = {
						who = ROOT
						value < 0
					}
				}
			}
		}
	}

	fail_trigger_effect = {
		if = {
			limit = {
				ai = no
				is_patrician = yes
				has_character_flag = shamed_at_ball

				trigger_if = {
					limit = { is_merchant_republic = yes }

					any_vassal = {
						has_character_flag = shamed_player_at_ball
						is_patrician = yes
						ai = yes
						NOT = { trait = infirm }

						opinion = {
							who = ROOT
							value < 0
						}
					}
				}
				trigger_else = {
					liege = {
						any_vassal = {
							has_character_flag = shamed_player_at_ball
							is_patrician = yes
							ai = yes
							NOT = { trait = infirm }

							opinion = {
								who = ROOT
								value < 0
							}
						}
					}
				}
			}

			repeat_event = {
				id = REP.104
				months = 2
			}
		}
	}

	immediate = {
		clr_character_flag = shamed_at_ball

		if = {
			limit = { is_merchant_republic = yes }

			random_vassal = {
				limit = {
					is_patrician = yes
					has_dynasty_flag = the_feuders
					ai = yes
					in_command = no
					block_general_event_trigger = no
				}

				save_event_target_as = feuding_patrician
				clr_character_flag = shamed_player_at_ball
			}
		}
		else = {
			liege = {
				random_vassal = {
					limit = {
						is_patrician = yes
						has_dynasty_flag = the_feuders
						ai = yes
						in_command = no
						block_general_event_trigger = no
					}
				}

				save_event_target_as = feuding_patrician
				clr_character_flag = shamed_player_at_ball
			}
		}
	}

	option = {
		name = EVTOPTA_REP_104

		wealth = -100

		narrative_event = {
			id = REP.105
			days = 14
			tooltip = EVTTOOLTIP_REP_105
		}
	}

	option = {
		name = EVTOPTB_REP_104

		prestige = -20

		custom_tooltip = { text = no_own_ball_tooltip }
	}
}

# The Day of the Ball
narrative_event = {
	id = REP.105
	title = EVTNAME_REP_105
	desc = EVTDESC_REP_105
	picture = GFX_evt_family_feud_republic

	is_triggered_only = yes
	hide_from = yes

	option = {
		name = EVTOPTA_REP_105

		prestige = 150

		event_target:feuding_patrician = {
			show_scope_change = no

			prestige = -100
		}
	}
}

# AI gets Feuding opinion modifier (AI only) # TODO: should the player's dynasty also dislike the feuding dynasty head?
character_event = {
	id = REP.109

	is_triggered_only = yes # above; on_chronicle_owner_change
	hide_window = yes

	ai = no
	is_patrician = yes
	has_dlc = "The Republic"

	trigger = { has_dynasty_flag = the_victims }

	immediate = {
		# Find feuding patrician house
		if = {
			limit = { is_merchant_republic = yes }

			random_vassal = {
				limit = {
					is_patrician = yes
					has_dynasty_flag = the_feuders
					ai = yes
				}

				save_event_target_as = feuding_dynasty_head
			}
		}
		else = {
			liege = {
				random_vassal = {
					limit = {
						is_patrician = yes
						has_dynasty_flag = the_feuders
						ai = yes
					}

					save_event_target_as = feuding_dynasty_head
				}
			}
		}

		# Apply missing opinion modifiers towards player
		event_target:feuding_dynasty_head = {
			if = {
				limit = {
					NOT = {
						has_opinion_modifier = {
							name = opinion_feuding_family
							who = ROOT
						}
					}
				}

				opinion = {
					name = opinion_feuding_family
					who = ROOT
				}
			}

			any_dynasty_member = {
				limit = {
					NOR = {
						has_opinion_modifier = {
							name = opinion_feuding_family_light
							who = ROOT
						}

						character = PREV
					}
				}

				opinion = {
					name = opinion_feuding_family_light
					who = ROOT
				}
			}
		}

		repeat_event = {
			id = REP.109
			days = 1
		}
	}
}

### The Flagship

# The New Flagship
narrative_event = {
	id = REP.151
	title = EVTNAME_REP_151
	desc = EVTDESC_REP_151
	picture = GFX_evt_busy_trading_dock_republic

	is_triggered_only = yes # on_bi_yearly_pulse, random_events, republic_dynastic_feud_events

	ai = no
	is_patrician = yes
	has_dlc = "The Republic"
	min_age = 16
	prisoner = no
	in_command = no

	trigger = {
		has_dynasty_flag = the_victims

		NOR = {
			has_dynasty_flag = flagship_feud
			trait = infirm
		}

		trigger_if = {
			limit = { is_merchant_republic = yes }

			any_vassal = {
				is_patrician = yes
				has_dynasty_flag = the_feuders
				ai = yes
				in_command = no
				block_general_event_trigger = no

				NOR = {
					trait = infirm
					has_job_title = job_spymaster
				}
			}
		}
		trigger_else = {
			liege = {
				any_vassal = {
					is_patrician = yes
					has_dynasty_flag = the_feuders
					ai = yes
					in_command = no
					block_general_event_trigger = no
					NOT = { trait = infirm }
				}
			}
		}
	}

	immediate = {
		set_dynasty_flag = flagship_feud

		if = {
			limit = {
				any_vassal = {
					is_patrician = yes
				}
			}

			random_vassal = {
				limit = { has_dynasty_flag = the_feuders }

				save_event_target_as = feuding_patrician
			}
		}
		else = {
			liege = {
				random_vassal = {
					limit = { has_dynasty_flag = the_feuders }

					save_event_target_as = feuding_patrician
				}
			}
		}
	}

	option = {
		name = EVTOPTA_REP_151

		custom_tooltip = {
			text = flagship_plan_approved_tooltip

			random_list = {
				70 = {
					if = {
						limit = {
							liege = {
								has_landed_title = k_venice
								religion = catholic
								religion = ROOT
							}
						}

						narrative_event = {
							id = REP.152
							days = 46
						}
					}
					else = {
						narrative_event = {
							id = REP.153
							days = 46
						}
					}
				}

				30 = {
					narrative_event = {
						id = REP.155
						days = 46
					}
				}
			}
		}

	}

	option = {
		name = EVTOPTB_REP_151

		narrative_event = {
			id = REP.154
			days = 46
			tooltip = flagship_plan_refused_tooltip
		}
	}
}

# Marriage of the Sea (Venice Only)
narrative_event = {
	id = REP.152
	title = EVTNAME_REP_152
	desc = EVTDESC_REP_152
	picture = GFX_evt_merchant_ship_at_sea_republic

	is_triggered_only = yes
	hide_from = yes

	option = {
		name = EVTOPTA_REP_152

		set_dynasty_flag = feud_phase_two
		prestige = 50

		event_target:feuding_patrician = {
			show_scope_change = no

			prestige = -100
		}

		religion_head = {
			show_scope_change = no

			opinion = {
				name = opinion_furious
				who = event_target:feuding_patrician
				years = 5
			}
		}
	}
}

# The Ship is Launched
narrative_event = {
	id = REP.153
	title = EVTNAME_REP_153
	desc = EVTDESC_REP_153
	picture = GFX_evt_merchant_ship_at_sea_republic

	is_triggered_only = yes
	hide_from = yes

	option = {
		name = EVTOPTA_REP_152

		set_dynasty_flag = feud_phase_two
		prestige = 50

		event_target:feuding_patrician = {
			show_scope_change = no

			prestige = -100
		}
	}
}

# The Lion of the Sea
narrative_event = {
	id = REP.154
	title = EVTNAME_REP_154
	desc = EVTDESC_REP_154
	picture = GFX_evt_merchant_ship_at_sea_republic

	is_triggered_only = yes
	hide_from = yes

	option = {
		name = EVTOPTA_REP_154

		set_dynasty_flag = feud_phase_two
		prestige = -50

		event_target:feuding_patrician = {
			show_scope_change = no

			prestige = 100
		}
	}
}

# You Are Cordially Invited...
narrative_event = {
	id = REP.155
	title = EVTNAME_REP_155
	desc = EVTDESC_REP_155
	picture = GFX_evt_family_feud_republic

	is_triggered_only = yes
	hide_from = yes

	option = {
		name = EVTOPTA_REP_155

		set_dynasty_flag = feud_phase_two
		prestige = -50

		event_target:feuding_patrician = {
			show_scope_change = no

			prestige = 100
		}
	}
}

### Romeo & Juliet

# A Nightly Visit...
narrative_event = {
	id = REP.161
	title = EVTNAME_REP_161
	picture = GFX_evt_family_feud_republic

	desc = {
		text = EVTDESC_REP_161
		trigger = {
			event_target:my_kid = { is_female = yes }
		}
	}
	desc = {
		text = EVTDESC_REP_163
		trigger = {
			event_target:my_kid = { is_female = no }
		}
	}

	is_triggered_only = yes # on_bi_yearly_pulse, random_events, republic_dynastic_feud_events

	ai = no
	is_patrician = yes
	has_dlc = "The Republic"
	only_capable = yes
	prisoner = no
	in_command = no

	trigger = {
		has_dynasty_flag = the_victims
		has_dynasty_flag = feud_phase_two
		NOT = { has_dynasty_flag = romeo_juliet_feud }
		is_inaccessible_trigger = no

		any_child = {
			is_married = no
			is_adult = yes
			practical_age < 30
			is_inaccessible_or_incapable_trigger = no

			NOR = {
				trait = homosexual
				trait = infirm
				trait = eunuch
			}

			ROOT = {
				trigger_if = {
					limit = { is_merchant_republic = yes }

					any_vassal = {
						has_dynasty_flag = the_feuders
						is_patrician = yes
						in_command = no
						is_inaccessible_or_incapable_trigger = no

						any_child = {
							is_opposite_sex = PREVPREVPREV
							is_married = no
							has_dynasty_flag = the_feuders
							is_adult = yes
							practical_age < 30
							in_command = no
							is_inaccessible_or_incapable_trigger = no

							NOR = {
								trait = homosexual
								trait = infirm
								trait = eunuch
							}
						}
					}
				}
				trigger_else = {
					liege = {
						any_vassal = {
							has_dynasty_flag = the_feuders
							is_patrician = yes
							in_command = no
							is_inaccessible_or_incapable_trigger = no

							any_child = {
								is_opposite_sex = PREVPREVPREVPREV
								is_married = no
								has_dynasty_flag = the_feuders
								is_adult = yes
								practical_age < 30
								in_command = no
								is_inaccessible_or_incapable_trigger = no

								NOR = {
									trait = homosexual
									trait = infirm
									trait = eunuch
								}
							}
						}
					}
				}
			}
		}
	}

	immediate = {
		set_dynasty_flag = romeo_juliet_feud

		random_child = {
			limit = {
				is_married = no
				is_adult = yes
				practical_age < 30
				is_inaccessible_or_incapable_trigger = no

				NOR = {
					trait = infirm
					trait = homosexual
					trait = eunuch
				}

				ROOT = {
					trigger_if = {
						limit = { is_merchant_republic = yes }

						any_vassal = {
							has_dynasty_flag = the_feuders
							is_patrician = yes
							in_command = no
							is_inaccessible_or_incapable_trigger = no

							any_child = {
								is_opposite_sex = PREVPREVPREV
								is_married = no
								has_dynasty_flag = the_feuders
								is_adult = yes
								practical_age < 30
								in_command = no
								is_inaccessible_or_incapable_trigger = no

								NOR = {
									trait = homosexual
									trait = infirm
									trait = eunuch
								}
							}
						}
					}
					trigger_else = {
						liege = {
							any_vassal = {
								has_dynasty_flag = the_feuders
								is_patrician = yes
								in_command = no
								is_inaccessible_or_incapable_trigger = no

								any_child = {
									is_opposite_sex = PREVPREVPREVPREV
									is_married = no
									has_dynasty_flag = the_feuders
									is_adult = yes
									practical_age < 30
									in_command = no
									is_inaccessible_or_incapable_trigger = no

									NOR = {
										trait = homosexual
										trait = infirm
										trait = eunuch
									}
								}
							}
						}
					}
				}
			}

			if = {
				limit = { is_female = yes }
				save_event_target_as = julia
			}
			else = {
				save_event_target_as = romeo
			}

			save_event_target_as = my_kid
		}

		if = {
			limit = { is_merchant_republic = yes }

			random_vassal = {
				limit = {
					has_dynasty_flag = the_feuders
					is_patrician = yes
					in_command = no
					is_inaccessible_or_incapable_trigger = no

					any_child = {
						is_opposite_sex = event_target:my_kid
						is_married = no
						has_dynasty_flag = the_feuders
						is_adult = yes
						practical_age < 30
						in_command = no
						is_inaccessible_or_incapable_trigger = no

						NOR = {
							trait = homosexual
							trait = infirm
							trait = eunuch
						}
					}
				}

				random_child = {
					limit = {
						is_opposite_sex = event_target:my_kid
						is_married = no
						has_dynasty_flag = the_feuders
						is_adult = yes
						practical_age < 30
						in_command = no
						is_inaccessible_or_incapable_trigger = no

						NOR = {
							trait = homosexual
							trait = infirm
							trait = eunuch
						}
					}

					if = {
						limit = { is_female = yes }
						save_event_target_as = julia
					}
					else = {
						save_event_target_as = romeo
					}

					save_event_target_as = rival_kid
				}
			}
		}
		else = {
			liege = {
				random_vassal = {
					limit = {
						has_dynasty_flag = the_feuders
						is_patrician = yes
						in_command = no
						is_inaccessible_or_incapable_trigger = no

						any_child = {
							is_opposite_sex = event_target:my_kid
							is_married = no
							has_dynasty_flag = the_feuders
							is_adult = yes
							practical_age < 30
							in_command = no
							is_inaccessible_or_incapable_trigger = no

							NOR = {
								trait = homosexual
								trait = infirm
								trait = eunuch
							}
						}
					}

					random_child = {
						limit = {
							is_opposite_sex = event_target:my_kid
							is_married = no
							has_dynasty_flag = the_feuders
							is_adult = yes
							practical_age < 30
							in_command = no
							is_inaccessible_or_incapable_trigger = no

							NOR = {
								trait = homosexual
								trait = infirm
								trait = eunuch
							}
						}

						if = {
							limit = { is_female = yes }
							save_event_target_as = julia
						}
						else = {
							save_event_target_as = romeo
						}

						save_event_target_as = rival_kid
					}
				}
			}
		}
	}

	option = {
		name = EVTOPTA_REP_161

		trigger = {
			event_target:my_kid = { is_female = yes }
		}

		show_portrait = event_target:julia
		show_portrait = event_target:romeo

		custom_tooltip = {
			text = forbid_daughter_tooltip

			random = {
				chance = 80

				narrative_event = {
					id = REP.164
					days = 46
				}
			}
		}
	}

	option = {
		name = EVTOPTA_REP_163

		trigger = {
			event_target:my_kid = { is_female = no }
		}

		show_portrait = event_target:julia
		show_portrait = event_target:romeo

		custom_tooltip = {
			text = forbid_son_tooltip

			random = {
				chance = 80

				narrative_event = {
					id = REP.165
					days = 46
				}
			}
		}
	}

	option = {
		name = EVTOPTB_REP_161

		show_portrait = event_target:julia
		show_portrait = event_target:romeo

		custom_tooltip = {
			text = permit_love_tooltip

			random_list = {
				60 = {
					if = {
						limit = {
							event_target:my_kid = { is_female = yes }
						}

						narrative_event = { id = REP.164 days = 46 }
					}
					else = {
						narrative_event = { id = REP.165 days = 46 }
					}
				}

				40 = { narrative_event = { id = REP.166 days = 46 } }
			}
		}
	}
}

# Never Was a Story of More Woe... (Daughter)
narrative_event = {
	id = REP.164
	title = EVTNAME_REP_164
	desc = EVTDESC_REP_164
	picture = GFX_evt_family_feud_republic

	is_triggered_only = yes
	hide_from = yes

	option = {
		name = EVTOPTA_REP_164

		event_target:romeo = {
			show_scope_change = no

			death = { death_reason = death_suicide_poison }
		}

		event_target:julia = {
			show_scope_change = no

			death = { death_reason = death_suicide_poison }
		}

		custom_tooltip = {
			text = end_feud_tooltip

			narrative_event = {
				id = REP.168
				days = 14
			}
		}
	}

	option = {
		name = EVTOPTB_REP_164

		event_target:romeo = {
			show_scope_change = no

			death = { death_reason = death_suicide_poison }
		}

		event_target:julia = {
			show_scope_change = no

			death = { death_reason = death_suicide_poison }
		}

		custom_tooltip = { text = continue_feud_tooltip }
	}
}

# Never Was a Story of More Woe... (Son)
narrative_event = {
	id = REP.165
	title = EVTNAME_REP_164
	desc = EVTDESC_REP_165
	picture = GFX_evt_family_feud_republic

	is_triggered_only = yes
	hide_from = yes

	option = {
		name = EVTOPTA_REP_164

		event_target:julia = {
			show_scope_change = no

			death = { death_reason = death_suicide_poison }
		}

		event_target:romeo = {
			show_scope_change = no

			death = { death_reason = death_suicide_poison }
		}

		custom_tooltip = {
			text = end_feud_tooltip

			narrative_event = {
				id = REP.168
				days = 14
			}
		}
	}

	option = {
		name = EVTOPTB_REP_165

		event_target:julia = {
			show_scope_change = no

			death = { death_reason = death_suicide_poison }
		}

		event_target:romeo = {
			show_scope_change = no

			death = { death_reason = death_suicide_poison }
		}

		custom_tooltip = { text = continue_feud_tooltip }
	}
}

# Wedding Bells
narrative_event = {
	id = REP.166
	title = EVTNAME_REP_166
	desc = EVTDESC_REP_166
	picture = GFX_evt_marriage

	is_triggered_only = yes
	hide_from = yes

	option = {
		name = EVTOPTA_REP_166

		event_target:my_kid = {
			show_scope_change = no

			add_spouse = event_target:rival_kid
		}

		prestige = 100
		clr_dynasty_flag = the_victims

		event_target:rival_kid = {
			show_scope_change = no

			show_portrait = yes

			father = {
				show_scope_change = no

				prestige = 100
				clr_dynasty_flag = the_feuders

				hidden_effect = {
					any_dynasty_member = {
						remove_opinion = {
							name = opinion_feuding_family
							who = ROOT
						}

						remove_opinion = {
							name = opinion_feuding_family_light
							who = ROOT
						}
					}
				}
			}
		}
	}
}

# Two Funerals and a Truce
narrative_event = {
	id = REP.168
	title = EVTNAME_REP_168
	desc = EVTDESC_REP_168
	picture = GFX_evt_death

	is_triggered_only = yes

	option = {
		name = EVTOPTA_REP_168

		clr_dynasty_flag = the_victims

		hidden_effect = {
			event_target:rival_kid = {
				father = {
					clr_dynasty_flag = the_feuders

					remove_opinion = {
						name = opinion_feuding_family
						who = ROOT
					}

					any_dynasty_member = {
						remove_opinion = {
							name = opinion_feuding_family_light
							who = ROOT
						}
					}
				}
			}
		}
	}
}

### The Smugglers

# The Smugglers
narrative_event = {
	id = REP.182
	title = EVTNAME_REP_182
	desc = EVTDESC_REP_182
	picture = GFX_evt_family_feud_republic

	is_triggered_only = yes # on_bi_yearly_pulse, random_events, republic_dynastic_feud_events

	ai = no
	is_patrician = yes
	has_dlc = "The Republic"
	only_capable = yes
	prisoner = no

	trigger = {
		has_dynasty_flag = the_victims

		any_child = {
			is_female = no
			practical_age < 35
			in_command = no
			block_general_event_trigger = no

			NOR = {
				trait = infirm
				trait = blinded
				trait = craven
			}
		}

		trigger_if = {
			limit = { is_merchant_republic = yes }

			any_vassal = {
				is_patrician = yes
				has_dynasty_flag = the_feuders
				age >= 30
				wealth >= 200
				in_command = no
				prisoner = no
				is_incapable = no
				NOT = { has_dynasty_flag = smugglers_feud }
			}
		}
		trigger_else = {
			liege = {
				any_vassal = {
					is_patrician = yes
					has_dynasty_flag = the_feuders
					age >= 30
					wealth >= 200
					in_command = no
					prisoner = no
					is_incapable = no
					NOT = { has_dynasty_flag = smugglers_feud }
				}
			}
		}
	}

	immediate = {
		set_dynasty_flag = smugglers_feud

		random_child = {
			limit = {
				is_female = no
				practical_age < 35
				in_command = no
				block_general_event_trigger = no

				NOR = {
					trait = infirm
					trait = blinded
					trait = craven
				}
			}

			save_event_target_as = ambushing_son
		}

		if = {
			limit = { is_merchant_republic = yes }

			random_vassal = {
				limit = {
					is_patrician = yes
					has_dynasty_flag = the_feuders
					age >= 30
					wealth >= 200
					in_command = no
					prisoner = no
					is_incapable = no
					NOT = { has_dynasty_flag = smugglers_feud }
				}

				save_event_target_as = feuding_patrician
			}
		}
		else = {
			liege = {
				random_vassal = {
					limit = {
						is_patrician = yes
						has_dynasty_flag = the_feuders
						age >= 30
						wealth >= 200
						in_command = no
						prisoner = no
						is_incapable = no
						NOT = { has_dynasty_flag = smugglers_feud }
					}

					save_event_target_as = feuding_patrician
				}
			}
		}
	}

	option = {
		name = EVTOPTA_REP_182

		custom_tooltip = {
			text = approve_plan_tooltip

			random_list = {
				60 = {
					narrative_event = { id = REP.185 days = 26 }
				}

				40 = {
					narrative_event = { id = REP.186 days = 26 }
				}
			}
		}
	}

	option = {
		name = EVTOPTB_REP_182

		custom_tooltip = { text = refuse_plan_tooltip }
	}
}

# The Only Good Smuggler...
narrative_event = {
	id = REP.185
	title = EVTNAME_REP_185
	desc = EVTDESC_REP_185
	picture = GFX_evt_family_feud_republic

	is_triggered_only = yes

	option = {
		name = EVTOPTA_REP_185

		set_dynasty_flag = feud_phase_two
		wealth = 200
		prestige = 100

		event_target:feuding_patrician = {
			show_scope_change = no

			wealth = -200
			prestige = -100
		}
	}
}

# The Ultimate Sacrifice
narrative_event = {
	id = REP.186
	title = EVTNAME_REP_186
	desc = EVTDESC_REP_186
	picture = GFX_evt_family_feud_republic

	is_triggered_only = yes

	immediate = {
		set_dynasty_flag = feud_phase_two
	}

	option = {
		name = EVTOPTA_REP_186

		trigger = { wealth < 200 }

		event_target:ambushing_son = {
			show_scope_change = no

			death = {
				death_reason = death_murder_beheading
				killer = event_target:feuding_patrician
			}
		}
	}

	option = {
		name = EVTOPTB_REP_186

		trigger = { wealth >= 200 }

		wealth = -200
	}

	option = {
		name = EVTOPTC_REP_186

		event_target:ambushing_son = {
			show_scope_change = no

			death = {
				death_reason = death_murder_beheading
				killer = event_target:feuding_patrician
			}
		}
	}
}

### The Battle

# The Right of Way
narrative_event = {
	id = REP.191
	title = EVTNAME_REP_191
	desc = EVTDESC_REP_191
	picture = GFX_evt_busy_trading_dock_republic

	is_triggered_only = yes # on_bi_yearly_pulse, random_events, republic_dynastic_feud_events

	ai = no
	is_patrician = yes
	has_dlc = "The Republic"
	min_age = 16
	only_capable = yes
	prisoner = no
	in_command = no

	trigger = {
		has_dynasty_flag = the_victims
		has_dynasty_flag = feud_phase_two

		NOR = {
			has_dynasty_flag = pirate_feud
			trait = infirm
			trait = blinded
		}

		trigger_if = {
			limit = { is_merchant_republic = yes }

			any_vassal = {
				is_patrician = yes
				ai = yes
				has_dynasty_flag = the_feuders
				in_command = no
				block_general_event_trigger = no

				NOR = {
					trait = infirm
					trait = blinded
				}
			}
		}
		trigger_else = {
			liege = {
				any_vassal = {
					is_patrician = yes
					ai = yes
					has_dynasty_flag = the_feuders
					in_command = no
					block_general_event_trigger = no

					NOR = {
						trait = infirm
						trait = blinded
					}
				}
			}
		}
	}

	immediate = {
		set_dynasty_flag = pirate_feud

		if = {
			limit = { is_merchant_republic = yes }

			random_vassal = {
				limit = {
					is_patrician = yes
					ai = yes
					has_dynasty_flag = the_feuders
					in_command = no
					block_general_event_trigger = no

					NOR = {
						trait = infirm
						trait = blinded
					}
				}

				save_event_target_as = feuding_patrician
			}
		}
		else = {
			liege = {
				random_vassal = {
					limit = {
						is_patrician = yes
						ai = yes
						has_dynasty_flag = the_feuders
						in_command = no
						block_general_event_trigger = no

						NOR = {
							trait = infirm
							trait = blinded
						}
					}

					save_event_target_as = feuding_patrician
				}
			}
		}
	}

	option = {
		name = EVTOPTA_REP_191

		custom_tooltip = {
			text = battle_tooltip

			narrative_event = {
				id = REP.192
				days = 5
			}
		}
	}

	option = {
		name = EVTOPTB_REP_191

		custom_tooltip = { text = no_battle_tooltip }

		prestige = -100

		event_target:feuding_patrician = {
			show_scope_change = no

			prestige = 100
		}
	}
}

# Battle is Joined!
narrative_event = {
	id = REP.192
	title = EVTNAME_REP_192
	desc = EVTDESC_REP_192
	picture = GFX_evt_kraken

	is_triggered_only = yes

	option = {
		name = EVTOPTA_REP_192

		custom_tooltip = {
			text = flotsam_tooltip

			narrative_event = { id = REP.194 }
		}
	}
}

# Days of Toil and Hardship
narrative_event = {
	id = REP.194
	title = EVTNAME_REP_194
	desc = EVTDESC_REP_194
	picture = GFX_evt_trade_post_republic

	is_triggered_only = yes

	option = {
		name = EVTOPTA_REP_194

		event_target:feuding_patrician = {
			show_scope_change = no

			death = { death_reason = death_dungeon }
		}

		custom_tooltip = { text = flee_ship_tooltip }
	}

	option = {
		name = EVTOPTB_REP_194

		custom_tooltip = {
			text = rescue_rival_tooltip

			narrative_event = { id = REP.195 }
		}
	}
}

# The Mutiny
narrative_event = {
	id = REP.195
	title = EVTNAME_REP_195
	desc = EVTDESC_REP_195
	picture = GFX_evt_merchant_ship_at_sea_republic

	is_triggered_only = yes

	option = {
		name = EVTOPTA_REP_195

		custom_tooltip = { text = feud_over_tooltip }

		clr_dynasty_flag = the_victims

		event_target:feuding_patrician = {
			show_scope_change = no

			clr_dynasty_flag = the_feuders

			remove_opinion = {
				name = opinion_feuding_family
				who = ROOT
			}

			any_dynasty_member = {
				show_scope_change = no

				remove_opinion = {
					name = opinion_feuding_family_light
					who = FROM
				}
			}
		}
	}

	option = {
		name = EVTOPTB_REP_195

		custom_tooltip = { text = feud_continues_tooltip }
	}
}

### Rival Dynasty Rules the Republic

# Rival Dynasty Rules the Republic
narrative_event = {
	id = REP.201
	title = EVTNAME_REP_201
	desc = EVTDESC_REP_201
	picture = GFX_evt_doge_republic

	is_triggered_only = yes # on_bi_yearly_pulse, random_events, republic_dynastic_feud_events

	ai = no
	is_patrician = yes
	has_dlc = "The Republic"
	prisoner = no
	only_capable = yes

	trigger = {
		has_dynasty_flag = the_victims
		NOT = { has_dynasty_flag = evil_ruler_feud }

		liege = {
			has_dynasty_flag = the_feuders
			is_merchant_republic = yes
			ai = yes
			prisoner = no
			is_incapable = no
		}
	}

	immediate = {
		set_dynasty_flag = evil_ruler_feud

		liege = {
			save_event_target_as = merchant_republic_leader
		}
	}

	option = {
		name = EVTOPTA_REP_201

		prestige = -100

		liege = {
			show_scope_change = no

			prestige = 50
		}
	}
}

### Player Dynasty Rules the Republic

# Player Dynasty Rules the Republic
narrative_event = {
	id = REP.203
	title = EVTNAME_REP_201
	desc = EVTDESC_REP_203
	picture = GFX_evt_doge_republic

	is_triggered_only = yes # on_bi_yearly_pulse, random_events, republic_dynastic_feud_events

	ai = no
	is_patrician = yes
	has_dlc = "The Republic"
	min_age = 16
	prisoner = no
	only_capable = yes

	trigger = {
		has_dynasty_flag = the_victims
		NOT = { has_dynasty_flag = player_ruler_feud }

		any_vassal = {
			is_patrician = yes
			has_dynasty_flag = the_feuders
			ai = yes
			is_adult = yes
			prisoner = no
			is_incapable = no
		}
	}

	immediate = {
		set_dynasty_flag = player_ruler_feud
		save_event_target_as = merchant_republic_leader

		random_vassal = {
			limit = {
				is_patrician = yes
				has_dynasty_flag = the_feuders
				ai = yes
				is_adult = yes
				prisoner = no
				is_incapable = no
			}

			save_event_target_as = feuding_patrician
		}
	}

	option = {
		name = EVTOPTA_REP_203

		prestige = 50

		event_target:feuding_patrician = {
			show_scope_change = no

			prestige = -100
		}
	}
}

### Riots

# Riots
narrative_event = {
	id = REP.206
	title = EVTNAME_REP_206
	desc = EVTDESC_REP_206
	picture = GFX_evt_family_feud_republic

	is_triggered_only = yes # on_bi_yearly_pulse, random_events, republic_dynastic_feud_events

	ai = no
	is_patrician = yes
	has_dlc = "The Republic"

	trigger = {
		has_dynasty_flag = the_victims

		trigger_if = {
			limit = { is_merchant_republic = yes }

			any_vassal = {
				is_patrician = yes
				has_dynasty_flag = the_feuders
				ai = yes
			}
		}
		trigger_else = {
			liege = {
				any_vassal = {
					is_patrician = yes
					has_dynasty_flag = the_feuders
					ai = yes
				}
			}
		}
	}

	immediate = {
		if = {
			limit = { is_merchant_republic = yes }

			random_vassal = {
				limit = {
					is_patrician = yes
					has_dynasty_flag = the_feuders
					ai = yes
				}

				save_event_target_as = feuding_patrician
			}
		}
		else = {
			liege = {
				random_vassal = {
					limit = {
						is_patrician = yes
						has_dynasty_flag = the_feuders
						ai = yes
					}

					save_event_target_as = feuding_patrician
				}
			}
		}
	}

	option = {
		name = EVTOPTA_REP_206

		prestige = -100

		event_target:feuding_patrician = {
			show_scope_change = no

			prestige = -100
		}
	}
}