namespace = cuckold_event

# ---------------------------------------------------------
# Event 1: Universal Discovery & Notification
# ---------------------------------------------------------
cuckold_event.1 = {
	type = character_event
	title = cuckold_event.1.t
	desc = cuckold_event.1.desc
	theme = intrigue
	
	left_portrait = { character = root animation = worry }
	
	trigger = {
		is_male = yes 
		is_married = yes 
		NOT = { has_trait = cuckold } 
		NOT = { has_trait = bull_trait } 
		NOT = { has_trait = eunuch_1 } 
		
		NOT = {
			has_relation_flag = {
				target = primary_spouse
				flag = married_known_adulterer
			}
		}
		
		primary_spouse = {
			is_female = yes
			has_trait = adulterer
			is_imprisoned = no
		}
	}
	
	immediate = {
		primary_spouse = { save_scope_as = cheating_wife }
	}
	
	option = {
		name = cuckold_event.1.a
		
		add_trait = cuckold
		add_trait_xp = {
			trait = cuckold
			track = cuckold
			value = 5
		}
		
		scope:cheating_wife = {
			add_trait = hotwife_trait
		}
		# HOOK REMOVED: Now handled centrally by Event 4
		
		stress_impact = {
			forgiving = -10
			lustful = -10
			craven = -10
			arrogant = 20
			brave = 20
			chaste = 20
		}
	}
}

# ---------------------------------------------------------
# Event 2: Active Infidelity Penalty (Hidden)
# ---------------------------------------------------------
cuckold_event.2 = {
	type = character_event
	hidden = yes 
	
	trigger = {
		has_trait = cuckold
		is_married = yes
		primary_spouse = { 
			has_trait = hotwife_trait
			is_imprisoned = no 
			any_relation = {
				type = lover
				NOT = { this = root }
			}
		}
	}
	
	immediate = {
		add_trait_xp = {
			trait = cuckold
			track = cuckold
			value = 5
		}
	}
}

# ---------------------------------------------------------
# Event 3: Passive XP Gain (Hidden)
# ---------------------------------------------------------
cuckold_event.3 = {
	type = character_event
	hidden = yes 
	
	trigger = {
		has_trait = cuckold
		is_married = yes
		primary_spouse = { 
			has_trait = hotwife_trait
			is_imprisoned = no 
		}
	}
	
	immediate = {
		add_trait_xp = {
			trait = cuckold
			track = cuckold
			value = 5 
		}
	}
}

# ---------------------------------------------------------
# Event 4: The Central Hook Engine (Hidden)
# ---------------------------------------------------------
cuckold_event.4 = {
	type = character_event
	hidden = yes 
	
	trigger = {
		is_male = yes
		has_trait = cuckold
		is_married = yes
		
		primary_spouse = {
			has_trait = hotwife_trait
			is_alive = yes
		}
	}
	
	immediate = {
		primary_spouse = {
			# 1. The Hotwife automatically gains/refreshes her Strong Hook on him
			add_hook = {
				target = root
				type = strong_hook
			}
			
			# 2. Scopes to ALL of her Bull lovers
			every_relation = {
				type = lover
				limit = {
					has_trait = bull_trait
					is_alive = yes
				}
				
				# 3. Every Bull automatically gains/refreshes a Weak Hook on him
				add_hook = {
					target = root # 'root' still refers to the Cuckold husband here
					type = favor_hook
				}
			}
		}
	}
}

# ---------------------------------------------------------
# Event 5: Becoming the Bull (The Decision Pop-up)
# ---------------------------------------------------------
cuckold_event.5 = {
	type = character_event
	title = cuckold_event.5.t
	desc = cuckold_event.5.desc
	theme = seduction
	
	left_portrait = { character = root animation = prideful }
	
	trigger = {
		is_male = yes
		is_adult = yes
		is_alive = yes 
		NOT = { has_trait = cuckold }
		NOT = { has_trait = bull_trait } 
		NOT = { has_character_flag = rejected_bull_lifestyle } 
		
		# NEW: Logical and psychological blocks
		NOT = { has_trait = eunuch_1 }
		NOT = { has_trait = loyal }
		
		any_relation = {
			type = lover
			is_alive = yes
			has_trait = hotwife_trait
			NOT = { is_spouse_of = root }
		}
	}
	
	immediate = {}
	
	option = {
		name = cuckold_event.5.a
		add_trait = bull_trait
		
		# Be sure this value matches your new custom XP rates!
		add_trait_xp = {
			trait = bull_trait
			track = bull_trait
			value = 5 
		}
		
		stress_impact = {
			sadistic = -20
			arrogant = -20
			lustful = -20
		}
	}
	
	option = {
		name = cuckold_event.5.b
		
		add_character_flag = {
			flag = rejected_bull_lifestyle
			years = 3 
		}
		
		stress_impact = {
			sadistic = 20
			arrogant = 20
			lustful = 20
		}
	}
}

# ---------------------------------------------------------
# Event 6: Bull Yearly XP Engine (Hidden)
# ---------------------------------------------------------
cuckold_event.6 = {
	type = character_event
	hidden = yes 
	
	trigger = {
		has_trait = bull_trait
		
		any_relation = {
			type = lover
			is_alive = yes
			has_trait = hotwife_trait
			NOT = { is_spouse_of = root }
		}
	}
	
	immediate = {
		add_trait_xp = {
			trait = bull_trait
			track = bull_trait
			value = 5
		}
	}
}

# ---------------------------------------------------------
# Event 7: The Ultimate Surrender (Level 3 Castration or Bloodline Surrender)
# ---------------------------------------------------------
cuckold_event.7 = {
	type = character_event
	title = cuckold_event.7.t   
	desc = cuckold_event.7.desc 
	theme = physical_health
	
	left_portrait = { character = root animation = fear }
	right_portrait = { character = scope:hotwife_wife animation = arrogant }
	
	trigger = {
		is_male = yes
		has_trait = cuckold
		NOT = { has_trait = eunuch_1 }
		NOT = { has_character_flag = rejected_castration } 
		
		has_trait_xp = {
			trait = cuckold
			track = cuckold
			value >= 100
		}
		
		primary_spouse = {
			has_trait = hotwife_trait
			is_alive = yes
			is_imprisoned = no
		}
	}
	
	immediate = {
		primary_spouse = { save_scope_as = hotwife_wife }
	}
	
	# Option A: Accept the physical castration
	option = {
		name = cuckold_event.7.a
		
		remove_trait = cuckold
		add_trait = eunuch_1
		
		add_prestige = -500
		add_piety = -250
		
		stress_impact = {
			arrogant = 20
		}
	}
	
	# Option B: Keep his manhood, but surrender his bloodline
	option = {
		name = cuckold_event.7.b
		
		add_character_flag = rejected_castration
	}
}

# ---------------------------------------------------------
# Event 8: The Bloodline Hijack Engine (Hidden)
# ---------------------------------------------------------
cuckold_event.8 = {
	type = character_event
	hidden = yes 
	
	trigger = {
		has_trait = bull_trait
		
		# The Bull must have a Hotwife lover...
		any_relation = {
			type = lover
			is_alive = yes
			has_trait = hotwife_trait
			
			# ...who has a legitimized bastard legally claimed by someone else
			any_child = {
				has_trait = legitimized_bastard
				NOT = { father = root } # CRITICAL: Ensures the Bull is not the legal father
				NOT = { has_character_flag = bull_harvested_child_xp } # Prevents infinite farming
			}
		}
	}
	
	immediate = {
		# Safely lock onto the specific hijacked child
		random_relation = {
			type = lover
			limit = {
				is_alive = yes
				has_trait = hotwife_trait
				any_child = {
					has_trait = legitimized_bastard
					NOT = { father = root } 
					NOT = { has_character_flag = bull_harvested_child_xp }
				}
			}
			random_child = {
				limit = {
					has_trait = legitimized_bastard
					NOT = { father = root } 
					NOT = { has_character_flag = bull_harvested_child_xp }
				}
				save_scope_as = hijacked_heir
			}
		}
		
		# The Engine: Flag the child and reward the Bull
		if = {
			limit = { exists = scope:hijacked_heir }
			
			scope:hijacked_heir = {
				add_character_flag = bull_harvested_child_xp
			}
			
			# Massive XP bump for successfully corrupting a dynasty
			add_trait_xp = {
				trait = bull_trait
				track = bull_trait
				value = 5 
			}
			
			# The Bull quietly gains prestige knowing his blood sits on a rival throne
			add_prestige = 100
		}
	}
}

# ---------------------------------------------------------
# Event 9: The Whispers of the Realm (Hidden Nickname Engine)
# ---------------------------------------------------------
cuckold_event.9 = {
	type = character_event
	hidden = yes 
	
	trigger = {
		OR = {
			has_trait = cuckold
			has_trait = bull_trait
			has_trait = hotwife_trait
		}
	}
	
	immediate = {
		# -------------------------------------
		# CUCKOLD NICKNAMES
		# -------------------------------------
		# Level 1 (33+ XP) - The rumors become public jokes immediately
		if = {
			limit = {
				has_trait = cuckold
				has_trait_xp = { trait = cuckold track = cuckold value >= 33 }
				NOT = { has_trait_xp = { trait = cuckold track = cuckold value >= 100 } }
				NOT = { has_nickname = nick_the_cuck }
			}
			random = {
				chance = 30 
				give_nickname = nick_the_cuck
			}
		}
		
		# Level 3 (100+ XP) - Absolute defeat is cemented in history
		if = {
			limit = {
				has_trait = cuckold
				has_trait_xp = { trait = cuckold track = cuckold value >= 100 }
				NOT = { has_nickname = nick_the_broken }
			}
			give_nickname = nick_the_broken 
		}
		
		# -------------------------------------
		# BULL NICKNAMES
		# -------------------------------------
		# Level 1 (50+ XP)
		if = {
			limit = {
				has_trait = bull_trait
				has_trait_xp = { trait = bull_trait track = bull_trait value >= 50 }
				NOT = { has_nickname = nick_the_brazen }
			}
			random = {
				chance = 30
				give_nickname = nick_the_brazen
			}
		}
		
		# -------------------------------------
		# HOTWIFE NICKNAME
		# -------------------------------------
		if = {
			limit = {
				has_trait = hotwife_trait
				NOT = { has_nickname = nick_the_insatiable }
				any_relation = {
					type = lover
					count >= 3
				}
			}
			random = {
				chance = 25
				give_nickname = nick_the_insatiable
			}
		}
	}
}