# Supported types:
# character, spouse, rivals, friends, liege_titles, vassal_titles, realm_titles, realm_characters, realm_characters_plus, independent_rulers

###############
# AMBITIONS
###############

#Create a treasury
obj_create_treasury = {
	type = character
	
	
	potential = {
		NOR = {
			has_character_flag = created_treasury
			any_artifact = { 
				quality = 2
			}
			trait = incapable
		}
		is_landed = yes
		higher_tier_than = BARON
		has_dlc = "Holy Fury"
	}
	
	allow = {
		NOT = {
			is_inaccessible_trigger = yes
		}
		is_adult = yes
	}
	
	success = {
		custom_tooltip = {
			text = create_treasury_condition_tooltip
			any_artifact = { 
				count = 3 
				quality = 2
			}
		} 
	}	
	
	abort = {
		trait = incapable
	}
	
	abort_effect = {

	}
	
	effect = {
		change_stewardship = 1
		set_character_flag = created_treasury
		add_character_modifier = {
			name = impressive_treasury
			years = 5
		}
	}
}

#Make a friend
obj_make_friends = {
	type = character
	
	potential = {
		NOR = {
			num_of_friends = 1
			has_character_flag = made_friends
			trait = shy
			trait = incapable
		}
		is_landed = yes
		higher_tier_than = BARON
		has_dlc = "Holy Fury"
	}
	
	allow = {
		NOT = {
			is_inaccessible_trigger = yes
		}
		is_adult = yes
	}
	
	success = {
		custom_tooltip = {
			text = obj_make_friends_condition_tooltip
			num_of_friends = 1
		} 
	}	
	
	abort = {
		trait = incapable
	}
	
	abort_effect = {

	}
	
	effect = {
		change_diplomacy = 1
		set_character_flag = made_friends
		add_character_modifier = {
			name = popular_modifier
			years = 5
		}
	}
}


obj_forge_bloodline = {
	type = character
	can_cancel = no

	creation_effect = {
		if = {
			limit = {
				NOT = { check_variable = { which = bloodline_murdered_people value = 1 } } # Set variables immediately so that the 0s show in the tooltip.
			}
			set_variable = { which = bloodline_murdered_people value = 0 }
		}
		if = {
			limit = {
				NOT = { check_variable = { which = bloodline_won_wars value = 1 } } # Set variables immediately so that the 0s show in the tooltip.
			}
			set_variable = { which = bloodline_won_wars value = 0 }
		}
		if = {
			limit = {
				NOT = { check_variable = { which = bloodline_built_holdings value = 1 } } # Set variables immediately so that the 0s show in the tooltip.
			}
			set_variable = { which = bloodline_built_holdings value = 0 }
		}
		if = {
			limit = {
				NOT = { check_variable = { which = bloodline_built_cities value = 1 } } # Set variables immediately so that the 0s show in the tooltip.
			}
			set_variable = { which = bloodline_built_cities value = 0 }
		}
		if = {
			limit = {
				NOT = { check_variable = { which = bloodline_built_castles value = 1 } } # Set variables immediately so that the 0s show in the tooltip.
			}
			set_variable = { which = bloodline_built_castles value = 0 }
		}
		if = {
			limit = {
				NOT = { check_variable = { which = bloodline_built_temples value = 1 } } # Set variables immediately so that the 0s show in the tooltip.
			}
			set_variable = { which = bloodline_built_temples value = 0 }
		}
		if = {
			limit = {
				NOT = { age = 12 }
			}
			set_character_flag = flag_forge_bloodline_was_child # Checked to unlock special flavor.
		}
		if = {
			limit = {
				check_variable = { which = bloodline_murdered_people value = 30 }
			}
			set_character_flag = flag_about_to_murder_bloodline
			character_event = { id = HF.24025 days = 25 random = 25 } #If you already fulfilled one of the paths, fire event immediately.
		}
		else_if = {
			limit = {
				check_variable = { which = bloodline_won_wars value = 15 }
			}
			set_character_flag = flag_about_to_war_bloodline
			character_event = { id = HF.24031 days = 25 random = 25 } #If you already fulfilled one of the paths, fire event immediately.
		}
		else_if = {
			limit = {
				check_variable = { which = bloodline_built_holdings value = 24 }
			}
			set_character_flag = flag_about_to_builder_bloodline
			character_event = { id = HF.24047 days = 25 random = 25 } #If you already fulfilled one of the paths, fire event immediately.
		}
		else_if = {
			limit = {
				check_variable = { which = bloodline_built_cities value = 10 }
			}
			set_character_flag = flag_about_to_builder_bloodline
			character_event = { id = HF.24042 days = 25 random = 25 } #If you already fulfilled one of the paths, fire event immediately.
		}
		else_if = {
			limit = {
				check_variable = { which = bloodline_built_castles value = 10 }
			}
			set_character_flag = flag_about_to_builder_bloodline
			character_event = { id = HF.24043 days = 25 random = 25 } #If you already fulfilled one of the paths, fire event immediately.
		}
		else_if = {
			limit = {
				check_variable = { which = bloodline_built_temples value = 10 }
			}
			set_character_flag = flag_about_to_builder_bloodline
			character_event = { id = HF.24044 days = 25 random = 25 } #If you already fulfilled one of the paths, fire event immediately.
		}
		else_if = {
			limit = {
				higher_real_tier_than = DUKE
				ai = no
			}
			character_event = { id = HF.24052 days = 800 random = 800 } #Otherwise delayed fire of event bloodlines chain.
		}
		#Finally, set counter for years at peace.
		set_variable = { which = bloodline_peaceful_years value = 0 }
		character_event = { id = HF.24020 days = 365 } #And start increasing it. on_started_war actions will reset it.
	}
	
	potential = {
		has_dlc = "Holy Fury"
		NOT = {
			any_owned_bloodline = { # Should not already have a created bloodline.
				has_bloodline_flag = created_bloodline
			}
		}
		NAND = { # The AI shouldn't create bloodlines when they already have a historical one
			ai = yes
			any_owned_bloodline = {
				has_bloodline_flag = historical_bloodline
			}
		}
		OR = {
			AND = {
				has_dynasty_flag = flag_dynasty_forged_bloodline
				OR = {
					prestige = 20000 #Adults
					AND = { #Child facilitation
						prestige = 15000
						is_adult = no
						OR = {
							trait = willful
							trait = proud
							trait = ambitious
							trait = quick
							trait = genius 
						}
					}
				}
			}
			AND = {
				NOT = { has_dynasty_flag = flag_dynasty_forged_bloodline }
				OR = {
					prestige = 5000 #Adults
					AND = { #Child facilitation
						prestige = 2500
						is_adult = no
						OR = {
							trait = willful
							trait = proud
							trait = ambitious
							trait = quick
							trait = genius 
						}
					}
				}
			}
		}
		is_landed = yes
		is_playable = yes
		higher_tier_than = COUNT
		#independent = yes
	}
	
	allow = {
		#independent = yes
		NOT = { trait = content }
		NOT = { trait = incapable }
		age = 6
	}
	
	chance = {
		factor = 100
		
		modifier = {
			factor = 0
			NOR = {
				trait = ambitious
				trait = proud
				trait = willful
			}
		}
		modifier = {
			factor = 0
			OR = {
				trait = content
				trait = humble
				trait = timid
			}
		}
		modifier = {
			factor = 100
			trait = ambitious
		}
		modifier = {
			factor = 0
			any_owned_bloodline = { #Founders of historical Bloodlines tend to spawn with enough prestige and troops to have an easy time achieving this ambition. Fine for the player, but the AI should not do it.
				founder = {
					character = ROOT
				}
			}
		}
		modifier = {
			factor = 0
			any_dynasty_member = { ai = no } #Don't step on the player's dreams, AI.
		}
	}
	success = {
		custom_tooltip = {
			text = obj_forge_bloodline_condition_tooltip		
			hidden_tooltip = { 
				any_owned_bloodline = { # Could be either one of the Bloodlines tied to this ambition or one of the other earned bloodlines scattered throughout the game.
					has_bloodline_flag = created_bloodline
				}
				# Possible Bloodlines specifically tied to this ambition:
				# Murder Bloodline (assassinate 30 people) 	---> 	(Little Killer/Dreaded/Feast Macabre/Silent)		
				# War Bloodline (win 15 wars) 				---> 	(Young Warrior/Knight/Warlord/Warrior Philosopher)	
				# Peace Bloodline (ruled 30 years at peace)	--->	(protector/munificent/angel)						
				# Architect Bloodline (built 10 cities)																	
				# Castellan Bloodline (built 10 castles)																
				# Monumental Bloodline (built 10 temples)																

				# Hybrid (Murder + War) (20 kills + 10 wars)															
				# Hybrid (Murder + Peace) (20 kills + 10 years)															
				# Hybrid (Architect + Castellan + Monumental) (24 holdings)												
				# Hybrid (Murder + Architect/Castellan/Monumental) (20 kills + 15 holdings)								
				# Hybrid (Peace + Architect) (15 years + 5 cities)														
				# Hybrid (Peace + Castellan) (15 years + 5 castles)														
				# Hybrid (Peace + Monumental) (15 years + 5 temples)													


				# Event Bloodlines (event chain, with several variations)
					#Family
					#Technology
					#Religion - Open
					#Religion - Fanatical
					#Benevolent
					#Ruthless

				# Alexander/Ashoka (event chain)
			}
		}
	}	
	abort = {
		trait = incapable
	}
	
	abort_effect = {
		prestige = -1000
	}
	
	effect = {
		prestige = 1000
		set_dynasty_flag = flag_dynasty_forged_bloodline
	}
}