
###########################################
# Reincarnation Events
###########################################

namespace = HAMANE_REINCARNATION

# [on_yearly_pulse] I might be a reincarnation
character_event = {
	id = HAMANE_REINCARNATION.1
	desc = EVTDESC_HAMANE_REINCARNATION.1
	picture = GFX_evt_reincarnation
	border = GFX_event_normal_frame_religion
	
	is_triggered_only = yes
	
	only_men = yes
	only_playable = yes
	
	trigger = {
		NOT = { has_character_flag = nonsense_reincarnation }
		any_owned_bloodline = {
			founder = {
				NOT = { character = ROOT }
				is_alive = no
				is_female = no
			}
			NOT = {
				any_bloodline_member = {
					is_reincarnated = yes
				}
    		}
		}
		OR = {
			has_dlc = "Rajas of India"
			has_dlc = "Jade Dragon"
			has_dlc = "Holy Fury"
			has_dlc = "The Sword of Islam"
		}
		OR = {
			diplomacy = 20
			martial = 20
			stewardship = 20
			intrigue = 20
			learning = 20
			trait = genius
			AND = {
				OR = {
					trait = proud
					trait = ambitious
					trait = lunatic
					trait = possessed
				}
				OR = {
					diplomacy = 16
					martial = 16
					stewardship = 16
					intrigue = 16
					learning = 16
				}
				diplomacy = 10
				martial = 10
				stewardship = 10
				intrigue = 10
				learning = 10
			}
		}
		diplomacy = 1
		martial = 1
		stewardship = 1
		intrigue = 1
		learning = 1
		NOT = {
			has_game_rule = {
				name = supernatural_events
				value = off
			}
		}
		OR = {
			ai = no
			has_game_rule = {
				name = supernatural_events
				value = unrestricted
			}
		}
		is_reincarnated = no
		NOT = {
			any_dynasty_member = {
				is_reincarnated = yes
			}
		}
		any_neighbor_independent_ruler = {
			any_owned_bloodline = {
				founder = {
					OR = {
						character = PREVPREV
						ROOT = {
							is_reincarnated = yes
							reincarnation_scope = {
								character = PREVPREV
							}
						}
					}
    			}
			}
		}
	}
	immediate = {
		random_neighbor_independent_ruler = {
			limit = {
				any_owned_bloodline = {
					founder = {
						OR = {
							character = PREVPREV
							ROOT = {
								is_reincarnated = yes
								reincarnation_scope = {
									character = PREVPREV
								}
							}
						}
					}
    			}
			}
			save_event_target_as = neighbor_bloodline
		}
		random_owned_bloodline = {
			limit = {
				founder = {
					NOT = { character = ROOT }
					is_alive = no
					is_female = no
				}
			}
			founder = {
				save_event_target_as = reincarnation_founder
				ROOT = {
					set_reincarnation = PREV
				}
    		}
		}
		log = "[HAMANE_REINCARNATION.1]:My neighbor, [neighbor_bloodline.GetBestName], whose name is known all over the world,but I think I am also a special person comparable to him. Recently, I also felt that my great ancestor, [reincarnation_founder.GetBestName] was born again as me. Shall I declare that I am [reincarnation_founder.GetHerHis] reincarnation?"
	}
	option = {
		name = EVTOPTA_HAMANE_REINCARNATION.1
		ai_chance = {
			factor = 1
		}
		add_trait = reincarnation
		any_neighbor_independent_ruler = {
			character_event = {
				id = HAMANE_REINCARNATION.2
			}
		}
		set_character_flag = nonsense_reincarnation
		log = "[Root.GetBestName] declared that [reincarnation_founder.GetBestName] was reincarnated as him."
	}
	option = {
		name = EVTOPTB_HAMANE_REINCARNATION.10001 # Nonsense!
		ai_chance = {
			factor = 0
		}
		set_character_flag = nonsense_reincarnation
	}
}

#notification events
character_event = {
	id = HAMANE_REINCARNATION.2
	desc = "EVTDESC_HAMANE_REINCARNATION.2"
	picture = GFX_evt_reincarnation
	
	is_triggered_only = yes
	
	option = {
		log = "[Root.GetDynName]([Root.GetID]) [From.GetBestName] declared that [reincarnation_founder.GetBestName] was reincarnated as him!"
		name = "EVTOPTA_HAMANE_REINCARNATION.2" #Interesting...
	}
}
###########################################
# Birth Reincarnation Events
###########################################

# [on_birth] Child might be a reincarnation
character_event = {
	id = HAMANE_REINCARNATION.10000
	hide_window = yes
	
	is_triggered_only = yes
	
	only_men = yes
	
	trigger = {
		any_owned_bloodline = {
			founder = {
				NOT = { character = ROOT }
				is_alive = no
				is_female = no
    		}
			NOT = {
				any_bloodline_member = {
					is_reincarnated = yes
				}
    		}
		}
		OR = {
			has_dlc = "Rajas of India"
			has_dlc = "Jade Dragon"
			has_dlc = "Holy Fury"
			has_dlc = "The Sword of Islam"
		}
		NOT = {
			has_game_rule = {
				name = supernatural_events
				value = off
			}
		}
		OR = {
			father_even_if_dead = {
				is_alive = yes
				OR = {
					ai = no
					has_game_rule = {
						name = supernatural_events
						value = unrestricted
					}
				}
				is_reincarnated = no
				NOT = {
					any_sibling = {
						is_reincarnated = yes
					}
				}
			}
			mother_even_if_dead = {
				is_alive = yes
				OR = {
					ai = no
					has_game_rule = {
						name = supernatural_events
						value = unrestricted
					}
				}
				is_reincarnated = no
				NOT = {
					any_sibling = {
						is_reincarnated = yes
					}
				}
			}
		}
		NOT = {
			any_sibling = {
				is_reincarnated = yes
			}
		}
	}
	
	immediate = {
		random_owned_bloodline = {
			limit = {
				founder = {
					NOT = { character = ROOT }
					is_alive = no
					is_female = no
				}
			}
			founder = {
				save_event_target_as = reincarnation_founder
				ROOT = {
					set_reincarnation = PREV
				}
    		}
		}
		if = {
			limit = {
				father = {
					OR = {
						always = yes
						ai = no
						has_game_rule = {
							name = supernatural_events
							value = unrestricted
						}
					}
				}
			}
			father = {
				character_event = {
					id = HAMANE_REINCARNATION.10001
					days = 3
				}
			}
		}
		else_if = {
			limit = {
				mother = {
					OR = {
						always = yes
						ai = no
						has_game_rule = {
							name = supernatural_events
							value = unrestricted
						}
					}
				}
			}
			mother = {
				character_event = {
					id = HAMANE_REINCARNATION.10001
					days = 3
				}
			}
		}
		else = {
		}
		log = "[Root.GetFirstName] has the same characteristics as our great ancestor, [reincarnation_founder.GetBestName]."
	}
}

# Reincarnation: Player notices the similarities
character_event = {
	id = HAMANE_REINCARNATION.10001
	desc = EVTDESC_HAMANE_REINCARNATION.10001
	picture = GFX_evt_reincarnation
	border = GFX_event_normal_frame_religion
	
	is_triggered_only = yes
	
	immediate = {
		log = "My little [GetFromRelation] [From.GetFirstName] has the same characteristics as our great ancestor, [reincarnation_founder.GetBestName]. Could [reincarnation_founder.GetSubjectPronoun] have been reborn as my [GetFromRelation] in this life?"
	}
	
	option = {
		name = EVTOPTA_HAMANE_REINCARNATION.10001 # Yes, clearly
		ai_chance = {
			factor = 10
		}
		
		hidden_tooltip = {
			FROM = {
				add_trait = reincarnation
				set_character_flag = is_child_of_destiny
				set_character_flag = ai_flag_refuse_concubinage
				set_character_flag = no_court_invites
				child_of_destiny_journey_start_effect = yes
				health = 1
				character_event = {
					id = RoI.10002
					days = 912
				}
				change_variable = { which = global_children_of_destiny_childhood_pulse_player value = 1 }
			}
		}
		log = "[Root.GetBestName] declared that [reincarnation_founder.GetBestName] was reincarnated as his [From.GetRootRelation], [From.GetBestName]."
	}
	
	option = {
		name = EVTOPTB_HAMANE_REINCARNATION.10001 # Nonsense!
		ai_chance = {
			factor = 0
		}
		
		hidden_tooltip = {
			FROM = {
				set_reincarnation = 0
			}
		}
	}
}
