﻿namespace = succession_crisis_vassal


succession_crisis_vassal.0001 = {
	type = character_event
	title = succession_crisis_vassal.0001.t
	desc = succession_crisis_vassal.0001.desc
	theme = realm

	trigger = {
		NOT = { has_character_flag = crisis_heir_flag }
		NOT = { has_character_flag = active_crisis_rebel }
	}

	immediate = {
		save_scope_as = pledger
		set_variable = {
			name = current_liege
			value = liege
		}
	}

	left_portrait = scope:current_ruler
	right_portrait = scope:warleader

	# OPTION A: PLEDGE TO THE CURRENT RULER
	option = {
		name = succession_crisis_vassal.0001.a
		
		trigger = {
			NOT = {
				is_at_war_with = scope:current_ruler
			}
		}
		
		ai_chance = {
			base = 50
			
			# Forced Loyalty: Current Ruler's Diarch (if close family)
			modifier = {
				add = 1000
				scope:current_ruler = {
					has_active_diarchy = yes
					diarch = {
						this = root
						is_close_family_of = scope:current_ruler
					}
				}
			}

			# Hook Logic: Current Ruler
			modifier = {
				add = 150
				scope:current_ruler = { has_strong_hook = root }
			}
			modifier = {
				add = 75
				scope:current_ruler = { has_weak_hook = root }
			}

			# Forced Loyalty: Nemesis of the opponent
			modifier = {
				add = 1000
				has_relation_nemesis = scope:warleader
			}

			# Blocked: If they are the Warleader's Diarch
			modifier = {
				factor = 0
				scope:warleader = {
					has_active_diarchy = yes
					diarch = { this = root }
				}
			}

			# Blocked: Allies, Friends, Best Friends, Lovers, and Soulmates should never pledge against each other
			modifier = {
				factor = 0
				OR = {
					is_allied_to = scope:warleader
					has_relation_friend = scope:warleader
					has_relation_best_friend = scope:warleader
					has_relation_lover = scope:warleader
					has_relation_soulmate = scope:warleader
				}
			}

			# Blocked: High opinion of the opponent
			modifier = {
				factor = 0.2
				opinion = {
					target = scope:warleader
					value > 50
				}
			}

			# Blocked: Nemesis will always go against
			modifier = {
				factor = 0
				has_relation_nemesis = scope:current_ruler
			}

			# Blocked: If they have less than -99 opinion they should never pledge to that side
			modifier = {
				factor = 0
				opinion = {
					target = scope:current_ruler
					value < -99
				}
			}

			# Family Loyalty: Same families should ally with each other if not competing
			modifier = {
				add = 50
				house = scope:current_ruler.house
				NOT = { has_relation_rival = scope:current_ruler }
			}
			
			modifier = {
				add = -30
				scope:current_ruler = { sc_personality_check = yes }
			}

			# Trait Modifiers: Ambitious/Greedy characters want to be on the winning side
			modifier = {
				add = 50
				OR = {
					has_trait = ambitious
					has_trait = greedy
				}
			}
		}

		add_character_flag = pledged_to_ruler_flag
		
		# Notify Ruler - Filtered to reduce spam
		if = {
			limit = {
				OR = {
					# Hegemony/Empire only care about Kingdom tier pledges with significant strength
					AND = {
						scope:current_ruler = { highest_held_title_tier >= tier_empire }
						highest_held_title_tier >= tier_kingdom
						max_military_strength >= 3000
					}
					# Kingdoms only care about Duchy tier pledges with significant strength
					AND = {
						scope:current_ruler = { highest_held_title_tier = tier_kingdom }
						highest_held_title_tier >= tier_duchy
						max_military_strength >= 1000
					}
				}
			}
			scope:current_ruler = {
				trigger_event = {
					id = succession_crisis_misc.0007
					days = { 30 120 }
				}
			}
		}
	}

	# OPTION B: PLEDGE TO THE WARLEADER
	option = {
		name = succession_crisis_vassal.0001.b

		trigger = {
			NOT = {
				is_at_war_with = scope:warleader
			}
		}

		ai_chance = {
			base = 50

			# Forced Loyalty: Warleader's Diarch
			modifier = {
				add = 1000
				scope:warleader = {
					has_active_diarchy = yes
					diarch = { this = root }
				}
			}

			# Hook Logic: Warleader
			modifier = {
				add = 150
				scope:warleader = { has_strong_hook = root }
			}
			modifier = {
				add = 75
				scope:warleader = { has_weak_hook = root }
			}

			# Forced Loyalty: Nemesis of the opponent
			modifier = {
				add = 1000
				has_relation_nemesis = scope:current_ruler
			}

			# Blocked: If they are the Ruler's Diarch (and close family)
			modifier = {
				factor = 0
				scope:current_ruler = {
					has_active_diarchy = yes
					diarch = {
						this = root
						is_close_family_of = scope:current_ruler
					}
				}
			}

			# Blocked: Allies, Friends, Best Friends, Lovers, and Soulmates should never pledge against each other
			modifier = {
				factor = 0
				OR = {
					is_allied_to = scope:current_ruler
					has_relation_friend = scope:current_ruler
					has_relation_best_friend = scope:current_ruler
					has_relation_lover = scope:current_ruler
					has_relation_soulmate = scope:current_ruler
				}
			}

			# Blocked: High opinion of the opponent
			modifier = {
				factor = 0.2
				opinion = {
					target = scope:current_ruler
					value > 50
				}
			}

			# Blocked: Nemesis will always go against
			modifier = {
				factor = 0
				has_relation_nemesis = scope:warleader
			}

			# Blocked: If they have less than -99 opinion they should never pledge to that side
			modifier = {
				factor = 0
				opinion = {
					target = scope:warleader
					value < -99
				}
			}

			# Strategic Modifiers
			modifier = {
				add = -500
				NOT = {
					scope:warleader = {
						is_vassal_of = scope:current_ruler
					}
				}
			}
			
			# House Loyalty: Counter-act the non-vassal penalty if they are kin
			modifier = {
				add = 500
				scope:warleader.house = scope:current_ruler.house
			}

			# Family Loyalty: Same families should ally with each other if not competing
			modifier = {
				add = 50
				house = scope:warleader.house
				NOT = { has_relation_rival = scope:warleader }
			}
			
			modifier = {
				add = -30
				scope:warleader = { sc_personality_check = yes }
			}

			# Trait Modifiers: Ambitious/Greedy characters want to be on the winning side
			modifier = {
				add = 50
				OR = {
					has_trait = ambitious
					has_trait = greedy
				}
			}
		}

		add_character_flag = pledged_to_warleader_flag
		
		# Notify Warleader - Filtered to reduce spam
		if = {
			limit = {
				OR = {
					# Hegemony/Empire only care about Kingdom tier pledges with significant strength
					AND = {
						scope:warleader = { highest_held_title_tier >= tier_empire }
						highest_held_title_tier >= tier_kingdom
						max_military_strength >= 3000
					}
					# Kingdoms only care about Duchy tier pledges with significant strength
					AND = {
						scope:warleader = { highest_held_title_tier = tier_kingdom }
						highest_held_title_tier >= tier_duchy
						max_military_strength >= 1000
					}
				}
			}
			scope:warleader = {
				trigger_event = {
					id = succession_crisis_misc.0007
					days = { 30 120 }
				}
			}
		}
	}

	# OPTION C: STAY OUT OF THE CONFLICT
	option = {
		name = succession_crisis_vassal.0001.c
		
		ai_chance = {
			base = 100

			# Forced: If someone is allied with both participants, they should stay out of war
			modifier = {
				add = 500
				is_allied_to = scope:current_ruler
				is_allied_to = scope:warleader
			}

			# Forced: If someone has high-tier relations with both, they should stay out
			modifier = {
				add = 500
				OR = {
					has_relation_friend = scope:current_ruler
					has_relation_best_friend = scope:current_ruler
					has_relation_lover = scope:current_ruler
					has_relation_soulmate = scope:current_ruler
				}
				OR = {
					has_relation_friend = scope:warleader
					has_relation_best_friend = scope:warleader
					has_relation_lover = scope:warleader
					has_relation_soulmate = scope:warleader
				}
			}

			# Forced: If they have very negative relation with both like rivals and nemesis they will also stay out
			modifier = {
				add = 250
				OR = {
					has_relation_rival = scope:current_ruler
					has_relation_nemesis = scope:current_ruler
				}
				OR = {
					has_relation_rival = scope:warleader
					has_relation_nemesis = scope:warleader
				}
			}

			# Forced: If they have -60 opinion of both
			modifier = {
				add = 250
				opinion = {
					target = scope:current_ruler
					value <= -60
				}
				opinion = {
					target = scope:warleader
					value <= -60
				}
			}

			# Blocked: If the current ruler has a strong hook, the vassal is unlikely to stay neutral
			modifier = {
				factor = 0.5
				scope:current_ruler = { has_strong_hook = root }
			}

			# Blocked: If the warleader has a strong hook, the vassal is unlikely to stay neutral
			modifier = {
				factor = 0.5
				scope:warleader = { has_strong_hook = root }
			}

			modifier = {
				add = 40
				has_trait = craven
			}
			modifier = {
				add = 40
				has_trait = lazy
			}
			modifier = {
				add = 20
				has_trait = calm
			}
			modifier = {
				add = 20
				has_trait = paranoid
			}
			
			# Neutral Opinion check
			modifier = {
				add = 20
				opinion = {
					target = scope:current_ruler
					value < 10
					value > -10
				}
				opinion = {
					target = scope:warleader
					value < 10
					value > -10
				}
			}

			# Ambitious/Brave characters are less likely to stay out
			modifier = {
				factor = 0.5
				OR = {
					has_trait = ambitious
					has_trait = brave
				}
			}
		}
	}
}


# ============================================================
# EVENT: PLAYER STANCE
# ============================================================
succession_crisis_vassal.0002 = {
	type = character_event
	title = succession_crisis_vassal.0002.t
	desc = succession_crisis_vassal.0002.desc
	theme = diplomacy

	left_portrait = {
		character = root
		animation = interested
	}
	right_portrait = {
		character = scope:asker
		animation = lantern
	}

	option = {
		name = succession_crisis_vassal.0002.a
		scope:asker = {
			trigger_event = { id = sc_power_consolidation.0002 }
		}
	}

	option = {
		name = succession_crisis_vassal.0002.b
		scope:asker = {
			trigger_event = { id = sc_power_consolidation.0003 }
		}
	}
}
# ============================================================
# EVENT: NEGOTIATIONS
# ============================================================
# Diplomacy-based Negotiation
succession_crisis_vassal.0003 = {
	type = character_event
	title = succession_crisis_vassal.0003.t
	desc = succession_crisis_vassal.0003.desc
	theme = diplomacy

	left_portrait = {
		character = root
		animation = thinking
	}
	right_portrait = {
		character = scope:asker
		animation = debating
	}

	option = {
		name = succession_crisis_vassal.0003.a
		ai_chance = {
			base = 30
			modifier = {
				add = scope:asker.diplomacy
			}
			modifier = {
				add = 50
				house = scope:asker.house
			}
		}
		if = {
			limit = {
				scope:asker = scope:current_ruler.primary_heir
			}
			add_character_flag = pledged_to_heir
		}
		else = {
			add_character_flag = pledged_to_claimant
		}
		scope:asker = { trigger_event = { id = sc_power_consolidation.0005 } }
		trigger_event = { id = succession_crisis_vassal.0006 }
	}

	option = {
		name = succession_crisis_vassal.0003.b
		ai_chance = {
			base = 70
			modifier = {
				add = 20
				OR = {
					has_trait = greedy
					has_trait = callous
				}
			}
		}
		trigger_event = { id = succession_crisis_vassal.0008 }
	}

	option = {
		name = succession_crisis_vassal.0003.c
		ai_chance = {
			base = 0
			modifier = {
				add = 50
				OR = {
					opinion = { target = scope:asker value <= -50 }
					has_relation_rival = scope:asker
					has_relation_nemesis = scope:asker
				}
			}
		}
		scope:asker = { trigger_event = { id = sc_power_consolidation.0006 } }
		trigger_event = { id = succession_crisis_vassal.0007 }
	}
}
# ============================================================
# EVENT: NEGOTIATIONS
# ============================================================
# Prestige-based Negotiation
succession_crisis_vassal.0004 = {
	type = character_event
	title = succession_crisis_vassal.0004.t
	desc = succession_crisis_vassal.0004.desc
	theme = diplomacy

	left_portrait = {
		character = root
		animation = thinking
	}
	right_portrait = {
		character = scope:asker
		animation = debating
	}

	option = {
		name = succession_crisis_vassal.0004.a
		ai_chance = {
			base = 30
			modifier = {
				add = {
					value = scope:asker.prestige_level
					multiply = 5
				}
			}
			modifier = {
				add = 50
				house = scope:asker.house
			}
		}
		if = {
			limit = {
				scope:asker = scope:current_ruler.primary_heir
			}
			add_character_flag = pledged_to_heir
		}
		else = {
			add_character_flag = pledged_to_claimant
		}
		scope:asker = { trigger_event = { id = sc_power_consolidation.0005 } }
		trigger_event = { id = succession_crisis_vassal.0006 }
	}

	option = {
		name = succession_crisis_vassal.0004.b
		ai_chance = {
			base = 70
			modifier = {
				add = 20
				OR = {
					has_trait = greedy
					has_trait = callous
				}
			}
		}
		trigger_event = { id = succession_crisis_vassal.0008 }
	}

	option = {
		name = succession_crisis_vassal.0004.c
		ai_chance = {
			base = 0
			modifier = {
				add = 50
				OR = {
					opinion = { target = scope:asker value <= -50 }
					has_relation_rival = scope:asker
					has_relation_nemesis = scope:asker
				}
			}
		}
		scope:asker = { trigger_event = { id = sc_power_consolidation.0006 } }
		trigger_event = { id = succession_crisis_vassal.0007 }
	}
}

# Piety-based Negotiation
succession_crisis_vassal.0005 = {
	type = character_event
	title = succession_crisis_vassal.0005.t
	desc = succession_crisis_vassal.0005.desc
	theme = diplomacy

	left_portrait = {
		character = root
		animation = thinking
	}
	right_portrait = {
		character = scope:asker
		animation = prayer
	}

	option = {
		name = succession_crisis_vassal.0005.a
		ai_chance = {
			base = 30
			modifier = {
				add = {
					value = scope:asker.piety_level
					multiply = 5
				}
			}
			modifier = {
				add = 50
				house = scope:asker.house
			}
		}
		if = {
			limit = {
				scope:asker = scope:current_ruler.primary_heir
			}
			add_character_flag = pledged_to_heir
		}
		else = {
			add_character_flag = pledged_to_claimant
		}
		scope:asker = { trigger_event = { id = sc_power_consolidation.0005 } }
		trigger_event = { id = succession_crisis_vassal.0006 }
	}

	option = {
		name = succession_crisis_vassal.0005.b
		ai_chance = {
			base = 70
			modifier = {
				add = 20
				OR = {
					has_trait = greedy
					has_trait = callous
				}
			}
		}
		trigger_event = { id = succession_crisis_vassal.0008 }
	}

	option = {
		name = succession_crisis_vassal.0005.c
		ai_chance = {
			base = 0
			modifier = {
				add = 50
				OR = {
					opinion = { target = scope:asker value <= -50 }
					has_relation_rival = scope:asker
					has_relation_nemesis = scope:asker
				}
			}
		}
		scope:asker = { trigger_event = { id = sc_power_consolidation.0006 } }
		trigger_event = { id = succession_crisis_vassal.0007 }
	}
}

succession_crisis_vassal.0006 = {
	type = character_event
	title = succession_crisis_vassal.0006.t
	desc = succession_crisis_vassal.0006.desc
	theme = diplomacy

	left_portrait = {
		character = root
		animation = toast
	}
	right_portrait = {
		character = scope:asker
		animation = toast
	}

	option = {
		name = succession_crisis_vassal.0006.a
	}
}
# ============================================================
# EVENT: NEGOTIATIONS FAIL
# ============================================================
succession_crisis_vassal.0007 = {
	type = character_event
	title = succession_crisis_vassal.0007.t
	desc = succession_crisis_vassal.0007.desc
	theme = diplomacy

	left_portrait = {
		character = root
		animation = dismissal
	}
	right_portrait = {
		character = scope:asker
		animation = anger
	}

	option = {
		name = succession_crisis_vassal.0007.a
	}
}
# ============================================================
# EVENT: BARGAIN
# ============================================================
succession_crisis_vassal.0008 = {
	type = character_event
	title = succession_crisis_vassal.0008.t
	desc = succession_crisis_vassal.0008.desc
	theme = diplomacy

	left_portrait = {
		character = root
		animation = thinking
	}
	right_portrait = {
		character = scope:asker
		animation = personality_greedy
	}

	option = {
		name = succession_crisis_vassal.0008.a
		scope:asker = {
			trigger_event = {
				id = sc_power_consolidation.0007
				days = 3
			}
		}
	}

	option = {
		name = succession_crisis_vassal.0008.b
		scope:asker = {
			trigger_event = {
				id = sc_power_consolidation.0008
				days = 3
			}
		}
	}

	option = {
		name = succession_crisis_vassal.0008.c
		scope:asker = {
			trigger_event = {
				id = sc_power_consolidation.0009
				days = 3
			}
		}
	}
}
# ============================================================
# EVENT: BARGAIN ACCEPT
# ============================================================
succession_crisis_vassal.0009 = {
	type = character_event
	title = succession_crisis_vassal.0009.t
	desc = succession_crisis_vassal.0009.desc
	theme = diplomacy

	left_portrait = {
		character = root
		animation = drink_goblet
	}
	right_portrait = {
		character = scope:asker
		animation = toast_goblet
	}

	option = {
		name = succession_crisis_vassal.0009.a
	}
}
# ============================================================
# EVENT: BARGAIN REJECT
# ============================================================
succession_crisis_vassal.0010 = {
	type = character_event
	title = succession_crisis_vassal.0010.t
	desc = succession_crisis_vassal.0010.desc
	theme = diplomacy

	left_portrait = {
		character = root
		animation = disapproval
	}
	right_portrait = {
		character = scope:asker
		animation = dismissal
	}

	option = {
		name = succession_crisis_vassal.0010.a
	}
}