namespace = Plus

#reserved Plus.4000 to Plus.4049
#reserved Plus.4551 to Plus 4599

#######################################
# TRIBUTARY EVENTS
# Written by Vukica
#######################################

## DEMAND TRIBUTARY EVENT CHAIN
#Bounce event, to place Attacker in FROM scope
character_event = {
	id = Plus.4000
	hide_window = yes
	
	is_triggered_only = yes
	
	immediate = {
		FROM = { letter_event = { id = Plus.4001 } }
	}
}

# FROM: Attacker, ROOT: Defender
# Demand tribute event
letter_event = {
	id = Plus.4001
	desc = "EVTDESC_Plus_4000"
	border = GFX_event_letter_frame_war
	
	is_triggered_only = yes

	option = { # Accept becoming tributary
		name = EVTOPT_Plus_4000A
		FROM = { letter_event = { id = Plus.4002 days = 3 } }
		if = {
			limit = {
				host = {
					character = FROM
				}
				prisoner = yes
			}
			prisoner = no
		}
		ai_chance = {
			factor = 20
			modifier = { #lunatic goes to war
				factor = 0
				OR = {
					trait = lunatic
					trait = rabies
				}
			}
			modifier = { #brave goes to war
				factor = 0
				trait = brave
			}
			modifier = { #pride goeth before fall
				factor = 0
				OR = {
					has_nickname = nick_the_hammer
					has_nickname = nick_the_conqueror
					has_nickname = nick_the_victorious
					has_nickname = nick_the_brave
					has_nickname = nick_the_fearless
					has_nickname = nick_the_glorious
					has_nickname = nick_the_ruthless
					has_nickname = nick_the_destroyer
					has_nickname = nick_the_strong
					has_nickname = nick_the_magnanimous
					has_nickname = nick_the_ironside
					has_nickname = nick_the_lion
					has_nickname = nick_the_lionheart
					has_nickname = nick_the_great
					trait = proud
					trait = ambitious
				}
			}
			modifier = { #have less than half strength of attacker
				factor = 2
				NOT = { relative_power_including_allies_defender = { who = FROM power = 0.5 } }
			}
			modifier = { #have less than third strength of attacker
				factor = 2
				NOT = { relative_power_including_allies_defender = { who = FROM power = 0.33 } }
			}
			modifier = { #have less than tenth strength of attacker
				factor = 2
				NOT = { relative_power_including_allies_defender = { who = FROM power = 0.1 } }
			}
			modifier = { #craven
				factor = 2
				trait = craven
			}
			modifier = { #already defending
				factor = 2
				is_primary_war_defender = yes
			}
			modifier = { #I'm an emperor
				factor = 0.1
				tier = EMPEROR
			}
			modifier = { #I'm a king
				factor = 0.1
				tier = KING
			}
			modifier = {
				factor = 0.5
				is_nomadic = yes
			}
			modifier = {
				factor = 0.5
				is_tribal = yes
			}
			modifier = {
				factor = 2
				NOT = { wealth = 50 }
				is_republic = yes
			}
		}
	}
	
	option = { # Refuse, go to war
		name = EVTOPT_Plus_4000B
		trigger = {
			NOT = { prisoner = no }
			host = {
				NOT = { character = FROM }
			}
		}
		FROM = { letter_event = { id = Plus.4003 days = 3 } }
		ai_chance = {
			factor = 70
			modifier = { #craven
				factor = 0.5
				trait = craven
			}
			modifier = { #attacker is craven
				factor = 2
				FROM = { trait = craven }
			}
			modifier = { # similar power
				factor = 2
				relative_power_including_allies_defender = { who = FROM power = 0.75 }
			}
			modifier = {
				factor = 4
				NOT = { religion_group = FROM }
			}
			modifier = {
				factor = 2
				NOT = { de_jure_liege = FROM }
			}
		}
	}
	
	option = { # Can't we make a deal?
		name = EVTOPT_Plus_4000C
		trigger = {
			wealth = 50
			NAND = {
				prisoner = no
				host = {
					character = FROM
				}
			}
		}
		FROM = { letter_event = { id = Plus.4004 days = 3 } }
		ai_chance = {
			factor = 10
			modifier = { #we can pay
				factor = 10
				is_republic = yes
			}
			modifier = { #you look too big
				factor = 4
				wealth = 200
				NOT = { relative_power_including_allies_defender = { who = FROM power = 0.5 }}
			}
		}
	}
}

# FROM: Defender, ROOT: Attacker
# Accepted tributary status
letter_event = {
	id = Plus.4002
	desc = "EVTDESC_Plus_4002"
	border = GFX_event_letter_frame_war
	
	is_triggered_only = yes
	
	immediate = {
		FROM = {
			save_event_target_as = target_loser
			if = {
				limit = { tier = count }
				prestige = -50
			}
			if = {
				limit = { tier = duke }
				prestige = -100
			}
			if = {
				limit = { tier = king }
				prestige = -150
			}
			if = {
				limit = { tier = emperor }
				prestige = -200
			}
			imperial_decadence_plus_1_effect = yes
			pf_glory_minus2_effect = yes
			custom_tooltip = {
				text = "REMOVE_PREVIOUS_SUZERAIN"
				hidden_tooltip = {
					any_suzerain = {
						event_target:target_loser = {
							remove_tributary = PREV
						}
					}
				}
			}
		}
		
		if = {
			limit = { FROM = { tier = count } }
			prestige = 50
		}
		if = {
			limit = { FROM = { tier = duke } }
			prestige = 100
		}
		if = {
			limit = { FROM = { tier = king } }
			prestige = 150
		}
		if = {
			limit = { FROM = { tier = emperor } }
			prestige = 200
		}
		add_character_modifier = { name = victory_timer duration = 1 hidden = yes }
		pf_glory_plus2_effect = yes
		if = {
			limit = { is_nomadic = yes}
			make_tributary = {
				who = FROM
				tributary_type = nomadic
			}
		}
		else = {
			make_tributary = {
				who = FROM
				tributary_type = voluntary
			}
		}
		
		if  = {
			limit = {
				ROOT = {
					uses_decadence = yes
				}
			}
			ROOT = {
				decadence = -10
			}
		}
		if  = {
			limit = {
				ROOT = {
					is_nomadic = yes
				}
			}
			ROOT = {
				clan_title = {
					ROOT = {
						any_vassal = {
							limit = { is_nomadic = yes }
							clan_title = {
								clan_opinion = {
									who = PREVPREVPREV
									modifier = won_tributary_war
									years = 5
								}
							}
						}
					}
				}
			}
		}
		
		if  = {
			limit = {
				ROOT = {
					is_tribal = yes
				}
			}
			ROOT = {
				any_vassal = {
					limit = { is_tribal = yes }
					opinion = {
						who = PREV
						modifier = won_tributary_war
						years = 5
					}
				}
			}
		}
	}
	
	option = { #Excellent
		name = EVTOPT_Plus_4002A
		clr_character_flag = trying_to_gain_tributary
		hidden_tooltip = {
			add_character_modifier = {
				name = tributary_timer
				duration = 365
				hidden = yes
			}
		}
	}
}

# FROM: Defender, ROOT: Attacker
# Go to war!
letter_event = {
	id = Plus.4003
	desc = "EVTDESC_Plus_4003"
	border = GFX_event_letter_frame_war
	
	is_triggered_only = yes
	
	option = { #Declare war!
		name = EVTOPT_Plus_4003A
		ai_chance = {
			factor = 80
			modifier = {
				factor = 0.2
				trait = craven
			}
		}
		war = {
			target = FROM
			casus_belli = tributary_cb
		}
		clr_character_flag = trying_to_gain_tributary
		hidden_tooltip = {
			add_character_modifier = {
				name = tributary_timer
				duration = 365
				hidden = yes
			}
		}
	}
	
	option = { #I was bluffing.
		name = EVTOPT_Plus_4003B
		ai_chance = {
			factor = 20
			modifier = {
				factor = 2
				trait = craven
			}
			modifier = { #already defending
				factor = 2
				is_primary_war_defender = yes
			}
		}
		prestige = -100
		if = {
			limit = { NOT = { trait = craven } }
			random = {
				chance = 25
				add_trait = craven
			}
		}
		clr_character_flag = trying_to_gain_tributary
		hidden_tooltip = {
			add_character_modifier = {
				name = tributary_timer
				duration = 3650
				hidden = yes
			}
		}
		FROM = { letter_event = {id = Plus.4005 days = 3 } }
	}
}

# FROM: Defender, ROOT: Attacker
# Offered money instead
letter_event = {
	id = Plus.4004
	desc = "EVTDESC_Plus_4004"
	border = GFX_event_letter_frame_war
	
	is_triggered_only = yes
	
	option = { #Agreed
		name = EVTOPT_Plus_4004A
		ai_chance = {
			factor = 75
			modifier = { #lunatic goes to war
				factor = 0
				OR = {
					trait = lunatic
					trait = rabies
				}
			}
			modifier = { #brave goes to war
				factor = 0
				trait = brave
			}
			modifier = { #pride goeth before fall
				factor = 0
				OR = {
					has_nickname = nick_the_hammer
					has_nickname = nick_the_conqueror
					has_nickname = nick_the_victorious
					has_nickname = nick_the_brave
					has_nickname = nick_the_fearless
					has_nickname = nick_the_glorious
					has_nickname = nick_the_ruthless
					has_nickname = nick_the_destroyer
					has_nickname = nick_the_strong
					has_nickname = nick_the_magnanimous
					has_nickname = nick_the_ironside
					has_nickname = nick_the_lion
					has_nickname = nick_the_lionheart
					has_nickname = nick_the_great
					trait = proud
					trait = ambitious
				}
			}
			modifier = { #craven
				factor = 2
				trait = craven
			}
			modifier = { #already defending
				factor = 2
				is_primary_war_defender = yes
			}
		}
		FROM = { transfer_scaled_wealth = { to = ROOT value = 0.75 min = 25 } }
		FROM = { letter_event = {id = Plus.4006 days = 3 } }
		prestige = 100
		FROM = { 
			opinion = { 
			modifier = opinion_paid_tribute 
			who = ROOT 
			years = 5
			}
		}
		hidden_tooltip = {
			add_character_modifier = {
				name = tributary_timer
				duration = 365
				hidden = yes
			}
		}
		clr_character_flag = trying_to_gain_tributary
	}
	
	option = { #Nice try.
		name = EVTOPT_Plus_4004B
		ai_chance = { # have more than twice the strength
			factor = 25
			modifier = {
				factor = 2
				FROM = { relative_power_including_allies_defender = { who = ROOT power = 0.5 } }
			}
			modifier = { # have three times the strength
				factor = 2
				FROM = { relative_power_including_allies_defender = { who = ROOT power = 0.33 } }
			}
			modifier = { # get it while it's hots
				factor = 2
				FROM = { is_primary_war_defender = yes }
			}
		}
		war = {
			target = FROM
			casus_belli = tributary_cb
		}
		clr_character_flag = trying_to_gain_tributary
		hidden_tooltip = {
			add_character_modifier = {
				name = tributary_timer
				duration = 365
				hidden = yes
			}
		}
	}
}

# FROM: Attacker, ROOT: Defender
# Attacker decides not to declare war after all.
letter_event = {
	id = Plus.4005
	desc = "EVTDESC_Plus_4005"
	border = GFX_event_letter_frame_war
	
	is_triggered_only = yes

	option = { #Excellent
		name = EVTOPT_Plus_4005A
	}
}

# FROM: Attacker, ROOT: Defender
# Attacker decides to accept the deal
letter_event = {
	id = Plus.4006
	desc = "EVTDESC_Plus_4006"
	border = GFX_event_letter_frame_war
	
	is_triggered_only = yes

	option = { #Excellent
		name = EVTOPT_Plus_4006A
	}
}

# Tributes for AI
character_event = {
	id = Plus.4010
	
	hide_window = yes
	is_triggered_only = yes
	
	only_independent = yes
	only_playable = yes
	has_dlc = "Horse Lords"
	war = no
	prisoner = no
	ai = yes
	
	trigger = {
		#lets limit this for ai to kings and duke
		higher_real_tier_than = DUKE
		#limit to large realms
		realm_size = 100
		NOT = { has_character_modifier = holy_truce_timer }
		NOT = { has_character_modifier = tributary_timer }
		mercenary = no
		is_tributary = no
		NOT = { has_character_flag = trying_to_gain_tributary }
		has_regent = no
		NOT = {
			any_war = {
				using_cb = tributary_cb
			}
		}
	}
	
	immediate = {
		random_list =  {
			90 = {
				#Nothing
			}
			10 = {
				modifier = {
					factor = 3
					is_nomadic = yes
				}
				modifier = {
					factor = 4
					ROOT = { trait = greedy }
				}
				modifier = {
					factor = 0.1
					trait = content
				}
				modifier = {
					factor = 0
					ROOT = {
						is_tribal = yes
						NOR = {
							trait = ambitious
							martial = 15
						}
					}
				}
				modifier = {
					factor = 0
					ROOT = {
						is_tribal = yes
						OR = {
							trait = content
							NOT = { martial = 8 }
						}
					}
				}
				random_independent_ruler = {
					limit = {
						NOT = { relative_power_including_allies_defender = { who = ROOT power = 0.2} }
						NOT = { realm_size = 25 }
						realm_size = 8
						NAND = {
							holy_order = yes
							religion = ROOT
						}
						NOR = {
							higher_tier_than = ROOT
							pays_tribute_to = ROOT
							any_liege = {
								pays_tribute_to = ROOT
							}
							is_tributary = no
						}
						NOT = {
							any_war = {
								using_cb = tributary_cb
							}
						}
						ROOT = {
							NOT = {
								rightful_religious_head_scope = {
									character = PREVPREV
								}
							}
						}
						ROOT = {
							OR = {
								is_nomadic = yes
								religion_group = PREV
							}
						}
						# The AI will not target nomads or tribals (they have no money anyhow)
						is_nomadic = no
						is_tribal = no
						NOT = { has_non_aggression_pact_with = ROOT }
						NOT = { reverse_has_truce = ROOT }
						any_realm_province = {
							any_neighbor_province = {
								owner = {
									same_realm = ROOT
								}
							}
						}
						NAND = {
							is_pagan_religion = yes
							religion = ROOT
						}
						yearly_income = 50
					}
					log = "Tributary event chain started, attacker is [Root.GetBestName], defender is [This.GetBestName]"
					letter_event = { id = Plus.4001 days = 3}
				}
				set_character_flag = trying_to_gain_tributary
			}
		}
			
	}
}

## VASSALISE TRIBUTARY EVENT CHAIN

#Bounce event, to place Attacker in FROM scope
character_event = {
	id = Plus.4020
	hide_window = yes
	
	is_triggered_only = yes
	
	immediate = {
		FROM = { letter_event = { id = Plus.4021 } }
	}
}

# FROM: Attacker, ROOT: Defender
# Demand vassalization
letter_event = {
	id = Plus.4021
	desc = "EVTDESC_Plus_4021"
	border = GFX_event_letter_frame_war
	
	is_triggered_only = yes

	option = { # Accept being vassalized
		name = EVTOPT_Plus_4000A
		FROM = { letter_event = { id = Plus.4022 days = 3 } }
		if = {
			limit = {
				host = {
					character = FROM
				}
				prisoner = yes
			}
			prisoner = no
		}
		ai_chance = {
			factor = 20
			modifier = { #lunatic goes to war
				factor = 0
				OR = {
					trait = lunatic
					trait = rabies
				}
			}
			modifier = { #brave goes to war
				factor = 0
				trait = brave
			}
			modifier = { #pride goeth before fall
				factor = 0
				OR = {
					has_nickname = nick_the_hammer
					has_nickname = nick_the_conqueror
					has_nickname = nick_the_victorious
					has_nickname = nick_the_brave
					has_nickname = nick_the_fearless
					has_nickname = nick_the_glorious
					has_nickname = nick_the_ruthless
					has_nickname = nick_the_destroyer
					has_nickname = nick_the_strong
					has_nickname = nick_the_magnanimous
					has_nickname = nick_the_ironside
					has_nickname = nick_the_lion
					has_nickname = nick_the_lionheart
					has_nickname = nick_the_great
					trait = proud
					trait = ambitious
				}
			}
			modifier = { #have less than half strength of attacker
				factor = 2
				NOT = { relative_power_including_allies_defender = { who = FROM power = 0.5 } }
			}
			modifier = { #have less than third strength of attacker
				factor = 2
				NOT = { relative_power_including_allies_defender = { who = FROM power = 0.33 } }
			}
			modifier = { #have less than tenth strength of attacker
				factor = 2
				NOT = { relative_power_including_allies_defender = { who = FROM power = 0.1 } }
			}
			modifier = { #craven
				factor = 2
				trait = craven
			}
			modifier = { #already defending
				factor = 2
				is_primary_war_defender = yes
			}
			modifier = { #I'm an emperor
				factor = 0.1
				tier = EMPEROR
			}
			modifier = { #I'm a king
				factor = 0.1
				tier = KING
			}
			modifier = {
				factor = 0.5
				is_nomadic = yes
			}
			modifier = {
				factor = 0.5
				is_tribal = yes
			}
			modifier = {
				factor = 2
				NOT = { wealth = 50 }
				is_republic = yes
			}
			modifier = {
				factor = 0.5
				NOT = { primary_title = { check_variable = { which = "tributary_years" value = 50 } } }
			}
			modifier = {
				factor = 1.1
				primary_title = { check_variable = { which = "tributary_years" value = 50 } }
			}
			modifier = {
				factor = 1.1
				primary_title = { check_variable = { which = "tributary_years" value = 60 } }
			}
			modifier = {
				factor = 1.1
				primary_title = { check_variable = { which = "tributary_years" value = 70 } }
			}
			modifier = {
				factor = 1.1
				primary_title = { check_variable = { which = "tributary_years" value = 80 } }
			}
			modifier = {
				factor = 1.1
				primary_title = { check_variable = { which = "tributary_years" value = 90 } }
			}
			modifier = {
				factor = 1.1
				primary_title = { check_variable = { which = "tributary_years" value = 100 } }
			}
		}
	}
	
	option = { # Refuse, go to war
		name = EVTOPT_Plus_4000B
		trigger = {
			NOT = { prisoner = no }
			host = {
				NOT = { character = FROM }
			}
		}
		FROM = { letter_event = { id = Plus.4023 days = 3 } }
		ai_chance = {
			factor = 70
			modifier = { #craven
				factor = 0.5
				trait = craven
			}
			modifier = { #attacker is craven
				factor = 2
				FROM = { trait = craven }
			}
			modifier = { # similar power
				factor = 2
				relative_power_including_allies_defender = { who = FROM power = 0.75 }
			}
			modifier = {
				factor = 4
				NOT = { religion_group = FROM }
			}
			modifier = {
				factor = 2
				NOT = { de_jure_liege = FROM }
			}
		}
	}
	
	option = { # Can't we make a deal?
		name = EVTOPT_Plus_4000C
		trigger = {
			wealth = 50
			NAND = {
				prisoner = no
				host = {
					character = FROM
				}
			}
		}
		FROM = { letter_event = { id = Plus.4024 days = 3 } }
		ai_chance = {
			factor = 10
			modifier = { #we can pay
				factor = 10
				is_republic = yes
			}
			modifier = { #you look too big
				factor = 4
				wealth = 200
				NOT = { relative_power_including_allies_defender = { who = FROM power = 0.5 }}
			}
			#not ready yet for this
			modifier = {
				factor = 2
				NOT = { primary_title = { check_variable = { which = "tributary_years" value = 50 } } }
			}
		}
	}
}

# FROM: Defender, ROOT: Attacker
# Accepted vassalization
letter_event = {
	id = Plus.4022
	desc = "EVTDESC_Plus_4022"
	border = GFX_event_letter_frame_war
	
	is_triggered_only = yes
	
	immediate = {
		remove_tributary = FROM
		FROM = {
			save_event_target_as = target_loser
			prestige = -100
			imperial_decadence_plus_1_effect = yes
			pf_glory_minus2_effect = yes
			set_defacto_liege = PREV
		}		
		
		prestige = 100
		add_character_modifier = { name = victory_timer duration = 1 hidden = yes }
		pf_glory_plus2_effect = yes
		
		
		if  = {
			limit = {
				ROOT = {
					uses_decadence = yes
				}
			}
			ROOT = {
				decadence = -10
			}
		}
	}
	
	option = { #Excellent
		name = EVTOPT_Plus_4002A
		clr_character_flag = trying_to_vassalize_tributary
	}
}

# FROM: Defender, ROOT: Attacker
# Go to war!
letter_event = {
	id = Plus.4023
	desc = "EVTDESC_Plus_4003"
	border = GFX_event_letter_frame_war
	
	is_triggered_only = yes
	
	option = { #Declare war!
		name = EVTOPT_Plus_4003A
		ai_chance = {
			factor = 50
			modifier = {
				factor = 0.2
				trait = craven
			}
		}
		remove_tributary = FROM
		war = {
			target = FROM
			casus_belli = force_vassalization
		}
		clr_character_flag = trying_to_vassalize_tributary
		hidden_tooltip = {
			add_character_modifier = {
				name = tributary_timer
				duration = 365
				hidden = yes
			}
		}
	}
	
	option = { #I was bluffing.
		name = EVTOPT_Plus_4003B
		ai_chance = {
			factor = 50
			modifier = {
				factor = 2
				trait = craven
			}
			modifier = { #already defending
				factor = 2
				is_primary_war_defender = yes
			}
		}
		prestige = -100
		if = {
			limit = { NOT = { trait = craven } }
			random = {
				chance = 5
				add_trait = craven
			}
		}
		clr_character_flag = trying_to_vassalize_tributary
		hidden_tooltip = {
			add_character_modifier = {
				name = tributary_timer
				duration = 730
				hidden = yes
			}
		}
		FROM = { letter_event = {id = Plus.4025 days = 3 } }
	}
}

# FROM: Defender, ROOT: Attacker
# Offered money instead
letter_event = {
	id = Plus.4024
	desc = "EVTDESC_Plus_4004"
	border = GFX_event_letter_frame_war
	
	is_triggered_only = yes
	
	option = { #Agreed
		name = EVTOPT_Plus_4004A
		ai_chance = {
			factor = 75
			modifier = { #lunatic goes to war
				factor = 0
				OR = {
					trait = lunatic
					trait = rabies
				}
			}
			modifier = { #brave goes to war
				factor = 0
				trait = brave
			}
			modifier = { #pride goeth before fall
				factor = 0
				OR = {
					has_nickname = nick_the_hammer
					has_nickname = nick_the_conqueror
					has_nickname = nick_the_victorious
					has_nickname = nick_the_brave
					has_nickname = nick_the_fearless
					has_nickname = nick_the_glorious
					has_nickname = nick_the_ruthless
					has_nickname = nick_the_destroyer
					has_nickname = nick_the_strong
					has_nickname = nick_the_magnanimous
					has_nickname = nick_the_ironside
					has_nickname = nick_the_lion
					has_nickname = nick_the_lionheart
					has_nickname = nick_the_great
					trait = proud
					trait = ambitious
				}
			}
			modifier = { #craven
				factor = 2
				trait = craven
			}
			modifier = { #already defending
				factor = 2
				is_primary_war_defender = yes
			}
		}
		FROM = { transfer_scaled_wealth = { to = ROOT value = 0.75 min = 25 } }
		FROM = { letter_event = {id = Plus.4026 days = 3 } }
		prestige = 100
		FROM = { 
			opinion = { 
				modifier = opinion_paid_tribute 
				who = ROOT 
				years = 5
			}
		}
		hidden_tooltip = {
			add_character_modifier = {
				name = tributary_timer
				duration = 365
				hidden = yes
			}
		}
		clr_character_flag = trying_to_vassalize_tributary
	}
	
	option = { #Nice try.
		name = EVTOPT_Plus_4004B
		ai_chance = { # have more than twice the strength
			factor = 25
			modifier = {
				factor = 2
				FROM = { relative_power_including_allies_defender = { who = ROOT power = 0.5 } }
			}
			modifier = { # have three times the strength
				factor = 2
				FROM = { relative_power_including_allies_defender = { who = ROOT power = 0.33 } }
			}
			modifier = { # get it while it's hots
				factor = 2
				FROM = { is_primary_war_defender = yes }
			}
		}
		remove_tributary = FROM
		war = {
			target = FROM
			casus_belli = force_vassalization
		}
		clr_character_flag = trying_to_vassalize_tributary
		hidden_tooltip = {
			add_character_modifier = {
				name = tributary_timer
				duration = 365
				hidden = yes
			}
		}
	}
}

# FROM: Attacker, ROOT: Defender
# Attacker decides not to declare war after all.
letter_event = {
	id = Plus.4025
	desc = "EVTDESC_Plus_4005"
	border = GFX_event_letter_frame_war
	
	is_triggered_only = yes

	option = { #Excellent
		name = EVTOPT_Plus_4005A
	}
}

# FROM: Attacker, ROOT: Defender
# Attacker decides to accept the deal
letter_event = {
	id = Plus.4026
	desc = "EVTDESC_Plus_4006"
	border = GFX_event_letter_frame_war
	
	is_triggered_only = yes

	option = { #Excellent
		name = EVTOPT_Plus_4006A
	}
}

# Vassalization for AI
character_event = {
	id = Plus.4030
	
	hide_window = yes
	is_triggered_only = yes
	
	only_independent = yes
	only_playable = yes
	has_dlc = "Horse Lords"
	war = no
	prisoner = no
	ai = yes
	
	trigger = {
		#lets limit this for ai to kings and emperors
		higher_real_tier_than = DUKE
		#limit to large realms
		realm_size = 100
		NOT = { has_character_modifier = holy_truce_timer }
		NOT = { has_character_modifier = tributary_timer }
		mercenary = no
		is_tributary = no
		NOT = { has_character_flag = trying_to_vassalize_tributary }
		has_regent = no
		NOT = {
			any_war = {
				using_cb = force_vassalization
			}
		}
		any_tributary = {
			OR = {
				is_tributary = { type = forced }
				is_tributary = { type = voluntary }
			}
			primary_title = {
				lower_tier_than = ROOT
				check_variable = { which = "tributary_years" value = 50 } #AI won't try this before 50 years have passed
			}
		}
	}
	
	immediate = {
		random_list =  {
			90 = {
				#Nothing
			}
			10 = {
				modifier = {
					factor = 4
					ROOT = { trait = greedy }
				}
				modifier = {
					factor = 0.1
					trait = content
				}
				modifier = {
					factor = 0
					ROOT = {
						is_tribal = yes
						NOR = {
							trait = ambitious
							martial = 15
						}
					}
				}
				modifier = {
					factor = 0
					ROOT = {
						is_tribal = yes
						OR = {
							trait = content
							NOT = { martial = 8 }
						}
					}
				}
				random_tributary = {
					limit = {
						OR = {
							is_tributary = { type = forced }
							is_tributary = { type = voluntary }
						}
						primary_title = {
							lower_tier_than = ROOT
							check_variable = { which = "tributary_years" value = 50 } #AI won't try this before 50 years have passed
						}
					}
					log = "Vassalization event chain started, attacker is [Root.GetBestName], defender is [This.GetBestName]"
					letter_event = { id = Plus.4021 days = 3}
				}
				set_character_flag = trying_to_vassalize_tributary
			}
		}
			
	}
}

## SEEK PROTECTION EVENT CHAIN

#Bounce event, to place Seeker in FROM scope
character_event = {
	id = Plus.4040
	hide_window = yes
	
	is_triggered_only = yes
	
	immediate = {
		FROM = { letter_event = { id = Plus.4041 } }
	}
}

# FROM: Seeker, ROOT: Protector
# Seek protection event
letter_event = {
	id = Plus.4041
	desc = "EVTDESC_Plus_4041"
	border = GFX_event_letter_frame_diplomacy
	
	is_triggered_only = yes

	option = { # Accept tribute
		name = EVTOPT_Plus_4041A
		FROM = { letter_event = { id = Plus.4042 days = 3 } }
		ai_chance = {
			factor = 45
			modifier = {
				factor = 0.2
				FROM = { de_jure_liege = ROOT }
			}
		}
	}
	
	option = { # You're not worth it!
		name = EVTOPT_Plus_4003B
		FROM = { letter_event = { id = Plus.4043 days = 3 } }
		ai_chance = {
			factor = 15
			modifier = {
				factor = 5
				relative_power = { who = FROM power = 10 } # i.e. someone who can't defend themselves
			}
		}
	}
	
	option = { # No, but if you pay me now I can offer you a NAP.
		name = EVTOPT_Plus_4041C
		FROM = { letter_event = { id = Plus.4044 days = 3 } }
		ai_chance = {
			factor = 25
			modifier = {
				factor = 2
				NOT = { wealth = 100 }
			}
		}
	}
}

# FROM: Protecor, ROOT: Seeker
# Accepted tributary
letter_event = {
	id = Plus.4042
	desc = "EVTDESC_Plus_4042"
	border = GFX_event_letter_frame_diplomacy
	
	is_triggered_only = yes
	
	immediate = {
		FROM = {
			make_tributary = {
				who = ROOT
				tributary_type = protectorate
			}
		}
	}
	
	option = { #Excellent
		name = EVTOPT_Plus_4002A
		clr_character_flag = seeking_protection
	}
}

# FROM: Protecor, ROOT: Seeker
# Declined tributary
letter_event = {
	id = Plus.4043
	desc = "EVTDESC_Plus_4043"
	border = GFX_event_letter_frame_diplomacy
	
	is_triggered_only = yes

	option = { #CURSEEEES!
		name = EVTOPT_Plus_4005A
		clr_character_flag = seeking_protection
	}
}

# FROM: Protecor, ROOT: Seeker
# Offered NAP instead
letter_event = {
	id = Plus.4044
	desc = "EVTDESC_Plus_4044"
	border = GFX_event_letter_frame_diplomacy
	
	is_triggered_only = yes

	option = { #That works too
		name = EVTOPT_Plus_4004A
		tooltip = {
			transfer_scaled_wealth = { to = FROM value = 0.75 min = 25 }
			opinion = { 
				modifier = opinion_paid_tribute 
				who = FROM
				years = 5
			}
		}
		FROM = { letter_event = { id = Plus.4045 days = 3 } }
		ai_chance = {
			factor = 10
			modifier = {
				factor = 0
				has_character_modifier = ai_austerity
			}
			modifier = {
				factor = 0
				NOT = { scaled_wealth = 0.80 }
			}
			modifier = {
				factor = 0
				NOT = { wealth = 30 }
			}
			modifier = {
				factor = 5
				FROM = { relative_power = { who = ROOT power = 5 } } #strong neighbour, we better protect ourselves
			}
			modifier = {
				factor = 5
				FROM = { relative_power = { who = ROOT power = 10 } } #strong neighbour, we better protect ourselves
			}
		}
	}
	
	option = { #Not good enough
		name = EVTOPT_Plus_4004B
		FROM = { letter_event = { id = Plus.4046 days = 3 } }
		ai_chance = {
			factor = 75
		}
	}
}

# FROM: Seeker, ROOT: Protecor
# Protection seeker accepted NAP
letter_event = {
	id = Plus.4045
	desc = "EVTDESC_Plus_4045"
	border = GFX_event_letter_frame_diplomacy
	
	is_triggered_only = yes
	
	immediate = {
		FROM = { clr_character_flag = seeking_protection }
		FROM = { transfer_scaled_wealth = { to = ROOT value = 0.75 min = 25 } }
		FROM = { 
			opinion = { 
				modifier = opinion_paid_tribute 
				who = ROOT 
				years = 5
			}
		}
	}

	option = { #Excellent
		name = EVTOPT_Plus_4002A
	}
}

# FROM: Seeker, ROOT: Protecor
# Protection seeker rejected NAP
letter_event = {
	id = Plus.4046
	desc = "EVTDESC_Plus_4046"
	border = GFX_event_letter_frame_diplomacy
	
	is_triggered_only = yes
	
	immediate = {
		FROM = { clr_character_flag = seeking_protection }
	}

	option = { #Too bad.
		name = EVTOPTA_Plus_1327
	}
}

## RELEASE VASSAL AS PROTECTORATE EVENT CHAIN
#Bounce event, to place Liege in FROM scope
character_event = {
	id = Plus.4551
	hide_window = yes
	
	is_triggered_only = yes
	
	immediate = {
		FROM = { letter_event = { id = Plus.4552 } }
	}
}

# FROM: Liege, ROOT: Vassal
# Offer release.
letter_event = {
	id = Plus.4552
	desc = "EVTDESC_Plus_4552"
	border = GFX_event_letter_frame_diplomacy
	
	is_triggered_only = yes

	option = { # Accept to become protectorate
		name = EVTOPT_Plus_4041A
		FROM = { letter_event = { id = Plus.4553 days = 3 } }
		ai_chance = {
			factor = 100
			modifier = {
				factor = 2
				tier = KING
			}
			modifier = {
				factor = 2
				tier = DUKE
				num_of_duke_titles = 2
			}
			modifier = {
				factor = 4
				num_of_king_titles = 2
			}
		}
	}
	
	option = { # Reject
		name = EVTOPTB_Plus_4552
		FROM = { letter_event = { id = Plus.4554 days = 3 } }
		ai_chance = {
			factor = 20
			modifier = {
				factor = 5
				NOT = { num_of_duke_titles = 2 }
			}
		}
	}
}

# FROM: Vassal, ROOT: Liege
# Accepted becoming protectorate
letter_event = {
	id = Plus.4553
	desc = "EVTDESC_Plus_4553"
	border = GFX_event_letter_frame_diplomacy
	
	is_triggered_only = yes
	
	immediate = {
		FROM = {
			set_defacto_liege = THIS
			opinion = { modifier = opinion_granted_independence who = FROM years = 5 }
		}
		make_tributary = {
			who = FROM
			tributary_type = protectorate
		}
		hidden_tooltip = {
			add_character_modifier = {
				name = tributary_timer
				duration = 730
				hidden = yes
			}
		}
	}
	
	option = { #Excellent
		name = EVTOPT_Plus_4002A
	}
}

# FROM: Vassal, ROOT: Liege
# Rejected becoming protectorate
letter_event = {
	id = Plus.4554
	desc = "EVTDESC_Plus_4554"
	border = GFX_event_letter_frame_diplomacy
	
	is_triggered_only = yes
	
	immediate = {
		hidden_tooltip = {
			add_character_modifier = {
				name = tributary_timer
				duration = 365
				hidden = yes
			}
		}
	}
	
	option = { #CURSES
		name = EVTOPT_Plus_4005A
	}
}