################################################
#
# Events for Dynasty requests
#
# ID 66000 - 66999 are reserved
#
##################################################
# Written by Johan Andersson

# Ask for claim on title if a dynasty member is older and is childless
# character_event = {
#	id = 66000
#	desc = EVTDESC66000
#	picture = GFX_evt_emissary
#
#	is_triggered_only = yes # on_yearly_pulse
#
#	only_men = yes
#	min_age = 16
#
#	trigger = {
#		OR = {
#			diplomacy >= 12
#			intrigue >= 12
#		}
#
#		has_children = yes
#		is_landed = no
#		NOT = { trait = eunuch }
#		is_ascetic_trigger = no
#
#		any_dynasty_member = {
#			is_landed = yes
#			has_living_children = no
#			practical_age >= 35
#
#			OR = {
#				is_feudal = yes
#				is_tribal = yes
#				is_nomadic = yes
#			}
#
#			NOR = {
#				has_law = succ_feudal_elective
#
#				any_demesne_title = {
#					claimed_by = ROOT
#				}
#			}
#		}
#	}
#
#	weight_multiplier = {
#		factor = 1
#
#		mult_modifier = {
#			factor = 10
#			trait = ambitious
#		}
#
#		mult_modifier = {
#			factor = 5
#			trait = proud
#		}
#
#		mult_modifier = {
#			factor = 0.8
#			trait = stressed
#		}
#
#		mult_modifier = {
#			factor = 0.8
#			trait = depressed
#		}
#
#		mult_modifier = {
#			factor = 0.75
#			trait = lunatic
#		}
#
#		mult_modifier = {
#			factor = 0.75
#			trait = possessed
#		}
#
#		mult_modifier = {
#			factor = 0.9
#			is_ill = yes
#		}
#
#		mult_modifier = {
#			factor = 0.8
#			trait = pneumonic
#		}
#
#		mult_modifier = {
#			factor = 0.8
#			trait = great_pox
#		}
#
#		mult_modifier = {
#			factor = 0.5
#			trait = leper
#		}
#
#		mult_modifier = {
#			factor = 0.9
#			trait = wounded
#		}
#
#		mult_modifier = {
#			factor = 0.8
#			is_maimed_trigger = yes
#		}
#
#		mult_modifier = {
#			factor = 0.5
#			trait = infirm
#		}
#
#		mult_modifier = {
#			factor = 0.4
#			is_incapable = yes
#		}
#
#		mult_modifier = {
#			factor = 0.5
#			trait = drunkard
#		}
#
#		mult_modifier = {
#			factor = 0.5
#			trait = consumption
#		}
#
#		mult_modifier = {
#			factor = 0.5
#			trait = slow_fever
#		}
#
#		mult_modifier = {
#			factor = 0.5
#			trait = camp_fever
#		}
#
#		mult_modifier = {
#			factor = 0.5
#			trait = bubonic_plague
#		}
#
#		mult_modifier = {
#			factor = 0.5
#			trait = measles
#		}
#
#		mult_modifier = {
#			factor = 0.5
#			trait = smallpox
#		}
#
#	}
#
#	option = {
#		name = EVTOPTA66000 # Ask for a claim
#
#		random_dynasty_member = {
#			show_scope_change = no
#
#			limit = {
#				is_landed = yes
#				has_living_children = no
#				practical_age >= 35
#
#				OR = {
#					is_feudal = yes
#					is_tribal = yes
#					is_nomadic = yes
#				}
#
#				NOR = {
#					has_law = succ_feudal_elective
#
#					any_demesne_title = {
#						claimed_by = ROOT
#					}
#				}
#			}
#
#			character_event = {
#				id = 66010
#				days = 17
#				tooltip = EVTTOOLTIP66010
#			}
#		}
#
#		ai_chance = { factor = 1 }
#	}
#
#	option = {
#		name = EVTOPTB66000 # Ask for the actual title
#
#		trigger = {
#			any_dynasty_member = {
#				demesne_size >= 2
#				has_living_children = no
#				practical_age >= 35
#
#				OR = {
#					is_feudal = yes
#					is_tribal = yes
#					is_nomadic = yes
#				}
#
#				NOR = {
#					has_law = succ_feudal_elective
#
#					any_demesne_title = {
#						claimed_by = ROOT
#					}
#				}
#			}
#		}
#
#		random_dynasty_member = {
#			show_scope_change = no
#
#			limit = {
#				demesne_size >= 2
#				has_living_children = no
#				practical_age >= 35
#
#				OR = {
#					is_feudal = yes
#					is_tribal = yes
#					is_nomadic = yes
#				}
#
#				NOR = {
#					has_law = succ_feudal_elective
#
#					any_demesne_title = {
#						claimed_by = ROOT
#					}
#				}
#			}
#
#			character_event = {
#				id = 66020
#				tooltip = EVTTOOLTIP66020
#			}
#		}
#
#		ai_chance = { factor = 1000 }
#	}
# }

# Dynasty member asks for a claim
# character_event = {
#	id = 66010
#	desc = EVTDESC66010
#	picture = GFX_evt_emissary
#
#	is_triggered_only = yes
#
#	# No need for notifactions back, landless character gets it anyway.
#	option = {
#		name = EVTOPTA66010 # Accept demand for claim
#
#		prestige = -5
#
#		random_demesne_title = {
#			show_scope_change = no
#
#			add_claim = FROM
#		}
#
#		ai_chance = {
#			factor = 1
#
#			mult_modifier = {
#				factor = 2
#				FROM = { diplomacy >= 14 }
#			}
#
#			mult_modifier = {
#				factor = 2
#				FROM = { martial >= 14 }
#			}
#
#			mult_modifier = {
#				factor = 2
#				FROM = { intrigue >= 14 }
#			}
#
#			mult_modifier = {
#				factor = 1.5
#
#				opinion = {
#					who = FROM
#					value >= 25
#				}
#			}
#
#			mult_modifier = {
#				factor = 2
#
#				opinion = {
#					who = FROM
#					value >= 50
#				}
#			}
#
#			mult_modifier = {
#				factor = 3
#
#				opinion = {
#					who = FROM
#					value >= 75
#				}
#			}
#		}
#
#		prestige = -5
#
#		random_demesne_title = {
#			show_scope_change = no
#
#			add_claim = FROM
#		}
#	}
#
#	option = {
#		name = EVTOPTB66010 # Refuse outrageous demands
#
#		reverse_opinion = {
#			name = dynastic_refused_claim
#			who = FROM
#			years = 5
#		}
#
#		ai_chance = {
#			factor = 2
#
#			trigger = {
#				opinion = {
#					who = FROM
#					value < 80
#				}
#			}
#		}
#	}
# }

# Dynasty member asks for a title
# character_event = {
# 	id = 66020
# 	desc = EVTDESC66020
# 	picture = GFX_evt_emissary
#
# 	is_triggered_only = yes
#
# 	# No need for notifactions back, landless character gets it anyway.
# 	option = {
# 		name = EVTOPTA66020 # Accept demand for title
#
# 		prestige = -5
#
# 		random_demesne_title = {
#			show_scope_change = no
#
# 			limit = { lower_real_tier_than = DUKE }
#
# 			grant_title = FROM
# 		}
#
# 		ai_chance = {
# 			factor = 1
#
# 			mult_modifier = {
# 				factor = 2
# 				FROM = { diplomacy >= 14 }
# 			}
#
# 			mult_modifier = {
# 				factor = 2
# 				FROM = { martial >= 14 }
# 			}
#
# 			mult_modifier = {
# 				factor = 2
# 				FROM = { intrigue >= 14 }
# 			}
#
# 			mult_modifier = {
# 				factor = 1.5
#
# 				opinion = {
#					who = FROM
#					value >= 25
#				}
# 			}
#
# 			mult_modifier = {
# 				factor = 2
#
#				opinion = {
#					who = FROM
#					value >= 50
#				}
# 			}
#
# 			mult_modifier = {
# 				factor = 3
#
#				opinion = {
#					who = FROM
#					value >= 75
#				}
# 			}
# 		}
# 	}
#
# 	option = {
# 		name = EVTOPTB66020 # Refuse outrageous demands
#
# 		reverse_opinion = {
# 			name = dynastic_refused_title
# 			who = FROM
# 			years = 5
# 		}
# 	}
# }

# Landless claimants can ask the Dynasty head to fight a war for your claim.
# Fired from 'on_yearly_pulse'
character_event = {
	id = 66100
	desc = evt_CK2_66110_desc
	picture = GFX_evt_emissary

	is_triggered_only = yes # on_yearly_pulse, random_events

	only_playable = yes
	min_age = 16
	only_capable = yes
	prisoner = no
	war = no

	trigger = {
		has_regent = no
		is_tributary = no
		is_nomadic = no

		trigger_if = {
			limit = { independent = no }

			has_liege_enforced_peace = no
			will_liege_enforce_peace = no
			NOT = { has_law = vassal_wars_law_2 }
			liege = { NOT = { has_law = vassal_wars_law_2 } }
		}

		trigger_if = {
			limit = { has_character_flag = event_66099 }

			had_character_flag = {
				flag = event_66099
				years >= 5
			}
		}

		any_dynasty_member = {
			is_vassal_or_below_of = ROOT
			is_adult = yes
			is_landed = no
			is_incapable = no
			is_offmap_ruler = no

			OR = {
				martial >= 12
				diplomacy >= 12
			}

			any_claim = {
				has_holder = yes

				holder_scope = {
					is_nomadic = no
					in_revolt = no
					ai = yes # No notification, so not against players

					trigger_if = {
						limit = { is_tributary = yes }

						suzerain = {
							NOR = {
								character = ROOT
								is_vassal_or_below_of = ROOT
							}
						}
					}

					NOR = {
						same_realm = ROOT
						has_non_aggression_pact_with = ROOT
						is_allied_with = ROOT
					}

					trigger_if = {
						limit = { independent = no }

						top_liege = {
							is_nomadic = no
							in_revolt = no

							trigger_if = {
								limit = { is_tributary = yes }

								suzerain = {
									NOR = {
										character = ROOT
										is_vassal_or_below_of = ROOT
									}
								}
							}

							NOR = {
								has_non_aggression_pact_with = ROOT
								is_allied_with = ROOT
							}
						}
					}
				}
			}
		}
	}

	weight_multiplier = {
		factor = 1
	}

	immediate = {
		set_character_flag = event_66099

		random_dynasty_member = {
			limit = {
				is_vassal_or_below_of = ROOT
				is_adult = yes
				is_landed = no
				is_incapable = no
				is_offmap_ruler = no

				OR = {
					martial = 12
					diplomacy = 12
				}

				any_claim = {
					has_holder = yes

					holder_scope = {
						is_nomadic = no
						in_revolt = no
						ai = yes # No notification, so not against players

						trigger_if = {
							limit = { is_tributary = yes }

							suzerain = {
								NOR = {
									character = ROOT
									is_vassal_or_below_of = ROOT
								}
							}
						}

						NOR = {
							same_realm = ROOT
							has_non_aggression_pact_with = ROOT
							is_allied_with = ROOT
						}

						trigger_if = {
							limit = { independent = no }

							top_liege = {
								is_nomadic = no
								in_revolt = no

								trigger_if = {
									limit = { is_tributary = yes }

									suzerain = {
										NOR = {
											character = ROOT
											is_vassal_or_below_of = ROOT
										}
									}
								}

								NOR = {
									has_non_aggression_pact_with = ROOT
									is_allied_with = ROOT
								}
							}
						}
					}
				}
			}

			save_event_target_as = claimant

			random_claim = {
				limit = {
					has_holder = yes

					holder_scope = {
						is_nomadic = no
						in_revolt = no
						ai = yes # No notification, so not against players

						trigger_if = {
							limit = { is_tributary = yes }

							suzerain = {
								NOR = {
									character = ROOT
									is_vassal_or_below_of = ROOT
								}
							}
						}

						NOR = {
							same_realm = ROOT
							has_non_aggression_pact_with = ROOT
							is_allied_with = ROOT
						}

						trigger_if = {
							limit = { independent = no }

							top_liege = {
								is_nomadic = no
								in_revolt = no

									trigger_if = {
									limit = { is_tributary = yes }

									suzerain = {
										NOR = {
											character = ROOT
											is_vassal_or_below_of = ROOT
										}
									}
								}

								NOR = {
									has_non_aggression_pact_with = ROOT
									is_allied_with = ROOT
								}
							}
						}
					}
				}

				save_event_target_as = claimant_claim
			}
		}
	}

	option = {
		name = EVTOPTA66110 # Go to war!

		event_target:claimant_claim = {
			show_scope_change = no

			reverse_unsafe_war = {
				target = event_target:claimant
				casus_belli = other_claim
				thirdparty = ROOT
			}

			log = "66110: [Root.GetBestName] starts war for [event_target:claimant.GetBestName]'s claim on [This.GetName]"
		}

		ai_chance = {
			factor = 1

			trigger = {
				opinion = {
					who = event_target:claimant
					value >= 80
				}
			}

			mult_modifier = {
				factor = 2
				event_target:claimant = { diplomacy >= 14 }
			}

			mult_modifier = {
				factor = 2
				event_target:claimant = { martial >= 14 }
			}

			mult_modifier = {
				factor = 2
				event_target:claimant = { intrigue >= 14 }
			}

		#	mult_modifier = {
		#		factor = 1.5
		#
		#		opinion = {
		#			who = event_target:claimant
		#			value >= 25
		#		}
		#	}
		#
		#	mult_modifier = {
		#		factor = 2
		#
		#		opinion = {
		#			who = event_target:claimant
		#			value >= 50
		#		}
		#	}
		#
		#	mult_modifier = {
		#		factor = 3
		#
		#		opinion = {
		#			who = event_target:claimant
		#			value >= 75
		#		}
		#	}
		}
	}

	option = {
		name = EVTOPTB66110 # Refuse outrageous demands

		reverse_opinion = {
			name = dynastic_refused_war
			who = event_target:claimant
			years = 5
		}

		prestige = -10

		ai_chance = {
			factor = 2

		#	trigger = {
		#		opinion = {
		#			who = event_target:claimant
		#			value < 80
		#		}
		#	}
		}
	}
}