﻿namespace = elope_familyromance

# Elope with your close family lover and become landless adventurers.


elope_familyromance.0001 = {
    type = character_event
    title = fr_elope_familyromance.0001.t

    desc = {
		desc = fr_elope_familyromance.0001.desc
	}

    theme = love

    override_background = {
		reference = bedchamber
	}

    left_portrait = {
		character = scope:recipient
		animation = love
	}	

	right_portrait = {
		character = scope:actor
		animation = stress
	}

     

    immediate = {
        hidden_effect = {
			
			# Creating characters to impersonate as your lover's parents. Both are dead for now.
			create_character = {
				age = {
					  value = scope:recipient.age
					  add = { 16 23 }
				}
				
				template = servant_character
				gender = female
				dynasty = none
				location = scope:recipient.location
				culture = scope:recipient.culture
				faith = scope:recipient.faith
				
				save_scope_as = peasant_mother
			}
			scope:peasant_mother = {
				death = {
					death_reason = death_old_age
				}
			}

			create_character = {
				age = {
					  value = scope:recipient.age
					  add = { 20 33 }
				}
				
				template = servant_character
				gender = male
				dynasty = none
				location = scope:recipient.location
				culture = scope:recipient.culture
				faith = scope:recipient.faith
				
				save_scope_as = peasant_father
			}
			scope:peasant_father = {
				death = {
					death_reason = death_old_age
				}
			}
		}
    }

    # Let's elope, marry and become landless adventurers!
    option = {
        name = fr_elope_familyromance.0001.a
		custom_tooltip = fr_elope_familyromance.0001.tt
                
        play_music_cue = "mx_cue_touching_moment"
		
		scope:actor = {
			add_character_flag = had_elope_with_family_lover
		}
		
		# This will expose your lover secret if it's present and not exposed yet.
		# Here is the way to bypass the secret exposure message window, that we don't really need here.
		
		if = {
			limit = {
				any_secret = {
					secret_type = secret_lover
					secret_target = scope:recipient
				}
			}
			
			# Suffer from consequences of your illegal adultery and incest.
			extramarital_sex_exposure_consequences_with_target_effect = { TARGET = scope:recipient SPOUSE_EVENT = no }
			
			# Your lover will suffer too...
			scope:recipient = {
				extramarital_sex_exposure_consequences_with_target_effect = { TARGET = scope:actor SPOUSE_EVENT = no }
			}
			
			# Now your lover secret is removed, but not exposed.
			random_secret = {
				limit = {
					secret_type = secret_lover
					secret_target = scope:recipient
				}
				remove_secret = yes
			}
		}
		
		
		hidden_effect = {
			
			scope:recipient.real_father = {
				save_scope_as = recip_real_father
			}
			
			scope:recipient.mother = {
				save_scope_as = recip_real_mother
			}
				
			
			# Set new parents to your lover, so you could lose all your family ties with him/her.
			# Real parents are remains the same(if they are known).
			scope:recipient = {					
					if = {
						limit = { exists = scope:recipient.father }
						set_father = scope:peasant_father
					}
					if = {
						limit = { exists = scope:recipient.mother }
						set_mother = scope:peasant_mother
					}				
															
					if = {
						limit = { exists = scope:recipient.father }
						set_real_father = scope:recip_real_father
					}
					if = {
						limit = { exists = scope:recipient.mother }
						set_real_mother = scope:recip_real_mother
					}
					
					add_character_flag = {
						flag = had_escaped_with_family_lover
					}
			}
			
						
			scope:actor = {
				add_character_flag = {
					flag = had_escaped_with_family_lover
				}
				
				# Remember the primary title, which we lose.
				set_global_variable = {
					name = lost_primary_title
					value = primary_title				
				}				
				
			}
			
			# Remember the name of our character, so we colud use it to check who was the parent.
			set_global_variable = {
					name = lost_title_parent
					value = scope:actor
			}
			
			
		}
		
		# Your lover is also punished with uncertain ancestry and disinheritance.
		scope:recipient = {
			add_trait = disinherited
			add_trait = disputed_heritage
		}
		
		# Eloping
		elope_success_effect = {
			OWNER = scope:actor
			TARGET = scope:recipient
		}
		
		# You dinasty will lose a lot of prestige because of your actions.
		if = {
			limit = { exists = dynasty }
			dynasty = {
					add_dynasty_prestige = massive_dynasty_prestige_loss
			}
		}
		
		# You could get a bad nickname for your actions
		random = {
			chance = 15			
			give_nickname = nick_the_depraved			
		}
		
		# Become an adeventurer.
		# Taken from ep3_laamps.0030 and ep3_laamps.0800
		scope:actor = {
			save_scope_as = adventurer
		}
		
		if = {
			limit = {
				player_heir ?= {
					NOT = { this = root }
					is_adult = yes
				}
			}
			player_heir = {
				save_scope_as = laamp_heir
				save_scope_as = laamp_inheritor
				custom_tooltip = become_landless_adventurer_decision_title_scope_tt
			}
		}
		else_if = {
			limit = { is_independent_ruler = no }
			liege = {
				save_scope_as = laamp_liege
				save_scope_as = laamp_inheritor
				custom_tooltip = become_landless_adventurer_decision_title_scope_tt
			}
		}
		else = {
			custom_tooltip = become_landless_adventurer_decision_title_created_tt
			if = {
				limit = {
					NOT = { exists = scope:laamp_inheritor }
				}
				hidden_effect_new_object = {
					create_character = {
						template = laamp_inheritor_template
						culture = root.capital_county.culture
						faith = root.capital_county.faith
						dynasty = generate
						location = root.capital_province
						after_creation = {
							save_scope_as = laamp_inheritor
							add_character_flag = new_laamp_inheritor
						}
					}
				}
			}
		}
		create_landless_adventurer_title_tooltip_effect = yes
		show_as_tooltip = {
			add_prestige = medium_prestige_gain
			add_character_modifier = {
				modifier = ep3_voluntary_laamp_character_modifier
				years = 5
			}
		}
		trigger_event = { id = ep3_laamps.0030 }
		# Debug tracking
		if = {
			limit = {
				is_ai = yes
				debug_only = yes
			}
			if = {
				limit = { exists = global_var:ai_voluntary_laamp_count }
				change_global_variable = {
					name = ai_voluntary_laamp_count
					add = 1
				}
			}
			else = {
				set_global_variable = {
					name = ai_voluntary_laamp_count
					value = 1
				}
			}
			debug_log = "AI became adventurer voluntarily"
			debug_log_scopes = yes
		}
		stress_impact = {
			craven = minor_stress_impact_gain
			content = minor_stress_impact_gain
			lazy = minor_stress_impact_gain
		}
		
		
    }

    # No, I can't do this
    option = {
        name = fr_elope_familyromance.0001.b
    }


}
