namespace = Plus

#reserved: Plus.2500 to Plus.2599

#######################################
# MUSLIM DECADENCE EVENTS
#######################################

# Add decadent dynasty trait
character_event = {
	id = Plus.2500
	picture = GFX_evt_throne_room
	
	desc = {
		text = EVTDESC_Plus_2500_low
		trigger = { trait = dynasty_decadence_low }
	}
	desc = {
		text = EVTDESC_Plus_2500_med
		trigger = { trait = dynasty_decadence_med }
	}
	desc = {
		text = EVTDESC_Plus_2500_high
		trigger = { trait = dynasty_decadence_high }
	}
	
	is_triggered_only = yes
	
	only_playable = yes
	religion_group = muslim
	
	notification = yes
	
	trigger = {
		dynasty_head = { character = ROOT }
		num_of_dynasty_members = 10 #does not apply to tiny dynasties
		OR = {
			independent = yes
 			NOT = { any_dynasty_member = { is_vassal_or_below = ROOT } }
 		}
 		OR = {
			trait = decadent
			any_dynasty_member = { trait = decadent is_liege_or_above = ROOT count = 3 }
		}
		NOR = {
			trait = dynasty_decadence_low
			trait = dynasty_decadence_med
			trait = dynasty_decadence_high
		}
	}
	
	immediate = {
		set_character_flag = has_dynasty_decadence
		if = {
			limit = {
				OR = {
					AND = {
						trait = decadent
						any_dynasty_member = { trait = decadent is_liege_or_above = ROOT count = 8 }
					}
					AND = {
						NOT = { trait = decadent }
						any_dynasty_member = { trait = decadent is_liege_or_above = ROOT count = 15 }
					}
				}
			}
			add_trait = dynasty_decadence_high
		}
		if = {
			limit = {
				OR = {
					AND = {
						trait = decadent
						any_dynasty_member = { trait = decadent is_liege_or_above = ROOT count = 3 }
					}
					AND = {
						NOT = { trait = decadent }
						any_dynasty_member = { trait = decadent is_liege_or_above = ROOT count = 8 }
					}
				}
				NOR = {
					AND = {
						trait = decadent
						any_dynasty_member = { trait = decadent is_liege_or_above = ROOT count = 8 }
					}
					AND = {
						NOT = { trait = decadent }
						any_dynasty_member = { trait = decadent is_liege_or_above = ROOT count = 15 }
					}
				}
			}
			add_trait = dynasty_decadence_med
		}
		if = {
			limit = {
				OR = {
					trait = decadent
					any_dynasty_member = { trait = decadent is_liege_or_above = ROOT count = 3 }
				}
				NOR = {
					AND = {
						trait = decadent
						any_dynasty_member = { trait = decadent is_liege_or_above = ROOT count = 3 }
					}
					AND = {
						NOT = { trait = decadent }
						any_dynasty_member = { trait = decadent is_liege_or_above = ROOT count = 8 }
					}
				}
			}
			add_trait = dynasty_decadence_low
		}
	}
	
	option = {
		name = OK
	}
}

# Lower decadent dynasty trait
character_event = {
	id = Plus.2501
	desc = EVTDESC_Plus_2501
	picture = GFX_evt_throne_room
	
	only_playable = yes
	religion_group = muslim
	has_character_flag = has_dynasty_decadence
	
	trigger = {
		OR = {
 			independent = yes
			NOT = { any_dynasty_member = { is_vassal_or_below = ROOT } }
		}
		OR = {
			AND = {
				trait = dynasty_decadence_low
				NOT = { trait = decadent }
				NOT = { any_dynasty_member = { trait = decadent is_liege_or_above = ROOT count = 3 } }
			}
			AND = {
				trait = dynasty_decadence_med
				NOT = { trait = decadent }
				NOT = { any_dynasty_member = { trait = decadent is_liege_or_above = ROOT count = 8 } }
			}
			AND = {
				trait = dynasty_decadence_med
				trait = decadent
				NOT = { any_dynasty_member = { trait = decadent is_liege_or_above = ROOT count = 3 } }
			}
			AND = {
				trait = dynasty_decadence_high
				NOT = { trait = decadent }
				NOT = { any_dynasty_member = { trait = decadent is_liege_or_above = ROOT count = 15 } }
			}
			AND = {
				trait = dynasty_decadence_high
				trait = decadent
				NOT = { any_dynasty_member = { trait = decadent is_liege_or_above = ROOT count = 8 } }
			}
		}
	}
	
	mean_time_to_happen = {
		months = 60
		modifier = {
			factor = 1.5
			trait = dynasty_decadence_med
		}
		modifier = {
			factor = 2
			trait = dynasty_decadence_high
		}
	}
	
	option = {
		name = EVTOPTA_Plus_2501
		if = {
			limit = { trait = dynasty_decadence_low }
			remove_trait = dynasty_decadence_low
		}
		if = {
			limit = { trait = dynasty_decadence_med }
			remove_trait = dynasty_decadence_med
		}
		if = {
			limit = { trait = dynasty_decadence_high }
			remove_trait = dynasty_decadence_high
		}
		if = {
			limit = {
				NOR = {
					trait = decadent
					any_dynasty_member = { trait = decadent is_liege_or_above = ROOT count = 3 }
				}
			}
			clr_character_flag = has_dynasty_decadence
		}
		if = {
			limit = {
				OR = {
					trait = decadent
					any_dynasty_member = { trait = decadent is_liege_or_above = ROOT count = 3 }
				}
				NOR = {
					AND = {
						trait = decadent
						any_dynasty_member = { trait = decadent is_liege_or_above = ROOT count = 3 }
					}
					AND = {
						NOT = { trait = decadent }
						any_dynasty_member = { trait = decadent is_liege_or_above = ROOT count = 8 }
					}
				}
			}
			add_trait = dynasty_decadence_low
		}
		if = {
			limit = {
				OR = {
					AND = {
						trait = decadent
						any_dynasty_member = { trait = decadent is_liege_or_above = ROOT count = 3 }
					}
					AND = {
						NOT = { trait = decadent }
						any_dynasty_member = { trait = decadent is_liege_or_above = ROOT count = 8 }
					}
				}
			}
			add_trait = dynasty_decadence_med
		}
	}
}

# Raise decadent dynasty trait
character_event = {
	id = Plus.2502
	desc = EVTDESC_Plus_2502
	picture = GFX_evt_throne_room
	
	is_triggered_only = yes
	
	only_playable = yes
	religion_group = muslim
	has_character_flag = has_dynasty_decadence
	
	trigger = {
		OR = {
 			independent = yes
 			NOT = { any_dynasty_member = { is_vassal_or_below = ROOT } }
 		}
		OR = {
			AND = {
				trait = dynasty_decadence_low
				NOT = { trait = decadent }
				any_dynasty_member = { trait = decadent is_liege_or_above = ROOT count = 8 }
			}
			AND = {
				trait = dynasty_decadence_low
				trait = decadent
				any_dynasty_member = { trait = decadent is_liege_or_above = ROOT count = 3 }
			}
			AND = {
				trait = dynasty_decadence_med
				NOT = { trait = decadent }
				any_dynasty_member = { trait = decadent is_liege_or_above = ROOT count = 15 }
			}
			AND = {
				trait = dynasty_decadence_med
				trait = decadent
				any_dynasty_member = { trait = decadent is_liege_or_above = ROOT count = 8 }
			}
		}
	}

	option = {
		name = EVTOPTA_Plus_2502
		if = {
			limit = { trait = dynasty_decadence_low }
			remove_trait = dynasty_decadence_low
		}
		if = {
			limit = { trait = dynasty_decadence_med }
			remove_trait = dynasty_decadence_med
		}
		if = {
			limit = { trait = dynasty_decadence_high }
			remove_trait = dynasty_decadence_high
		}
		if = {
			limit = {
				OR = {
					AND = {
						trait = decadent
						any_dynasty_member = { trait = decadent is_liege_or_above = ROOT count = 3 }
					}
					AND = {
						NOT = { trait = decadent }
						any_dynasty_member = { trait = decadent is_liege_or_above = ROOT count = 8 }
					}
				}
				NOR = {
					AND = {
						trait = decadent
						any_dynasty_member = { trait = decadent is_liege_or_above = ROOT count = 8 }
					}
					AND = {
						NOT = { trait = decadent }
						any_dynasty_member = { trait = decadent is_liege_or_above = ROOT count = 15 }
					}
				}
			}
			add_trait = dynasty_decadence_med
		}
		if = {
			limit = {
				OR = {
					AND = {
						trait = decadent
						any_dynasty_member = { trait = decadent is_liege_or_above = ROOT count = 8 }
					}
					AND = {
						NOT = { trait = decadent }
						any_dynasty_member = { trait = decadent is_liege_or_above = ROOT count = 15 }
					}
				}
			}
			add_trait = dynasty_decadence_high
		}
	}
}

# Remove decadent dynasty trait
character_event = {
	id = Plus.2503
	
	hide_window = yes
	
	has_character_flag = has_dynasty_decadence
	
	trigger = {
		OR = {
			NOT = { religion_group = muslim }
			NOR = {
				independent = yes
				NOT = { any_dynasty_member = { is_vassal_or_below = ROOT } }
			}
			NOT = { num_of_dynasty_members = 10 }
			is_playable = no
		}
	}
	
	mean_time_to_happen = {
		days = 1
	}
	
	immediate = {
		clr_character_flag = has_dynasty_decadence
		if = {
			limit = { trait = dynasty_decadence_low }
			remove_trait = dynasty_decadence_low
		}
		if = {
			limit = { trait = dynasty_decadence_med }
			remove_trait = dynasty_decadence_med
		}
		if = {
			limit = { trait = dynasty_decadence_high }
			remove_trait = dynasty_decadence_high
		}
	}
}

# Decadent character loses money
character_event = {
	id = Plus.2505
	
	hide_window = yes
	
	min_age = 16
	capable_only = yes
	religion_group = muslim
	only_men = yes
	prisoner = no
	ai = yes
	
	trigger = {
		trait = decadent
		wealth = -50
		NOR = {
			stewardship = 16
			trait = genius
			has_character_modifier = planning_claimant_adventure
			has_character_modifier = planning_duchy_adventure
			has_character_flag = claimant_adventurer
		}
	}
	
	mean_time_to_happen = {
		months = 60
		modifier = {
			factor = 0.75
			NOT = { stewardship = 2 }
		}
		modifier = {
			factor = 0.75
			NOT = { stewardship = 4 }
		}
		modifier = {
			factor = 1.25
			stewardship = 8
		}		
		modifier = {
			factor = 1.25
			stewardship = 10
		}
		modifier = {
			factor = 1.25
			stewardship = 12
		}
		modifier = {
			factor = 1.25
			stewardship = 14
		}
		modifier = {
			factor = 2
			OR = {
				trait = quick
				trait = shrewd
			}
		}
		modifier = {
			factor = 1.5
			trait = temperate
		}
		modifier = {
			factor = 1.5
			trait = greedy
		}
		modifier = {
			factor = 0.25
			trait = imbecile
		}
		modifier = {
			factor = 0.75
			trait = charitable
		}
		modifier = {
			factor = 0.5
			OR = {
				trait = slow
				trait = dull
			}
		}
		modifier = {
			factor = 0.5
			trait = depressed
		}
		modifier = {
			factor = 0.5
			trait = stressed
		}
		modifier = {
			factor = 0.5
			trait = drunkard
		}
		modifier = {
			factor = 0.5
			trait = hedonist
		}
	}
	
	immediate = {
		wealth = -25
	}
}

# Decadent character asks dynasty member for money
character_event = {
	id = Plus.2506
	
	hide_window = yes
	
	min_age = 16
	capable_only = yes
	religion_group = muslim
	only_men = yes
	prisoner = no
	ai = yes
	
	trigger = {
		trait = decadent
		OR = {
			NOT = { wealth = 25 }
			trait = greedy
		}
		any_dynasty_member = {
			war = no
			religion = ROOT
			is_close_relative = ROOT
			same_realm = ROOT
			wealth = 100
			reverse_opinion = { who = ROOT value = -25 }
			opinion = { who = ROOT value = -25 }
			NOR = {
				liege = { war = yes }
				distance = { who = ROOT value = 75 }
				reverse_has_opinion_modifier = { who = ROOT modifier = negotiated_to_drop_decadence }
				reverse_has_opinion_modifier = { who = ROOT modifier = grievously_offended }
				reverse_has_opinion_modifier = { who = ROOT modifier = opinion_angry }
				reverse_has_opinion_modifier = { who = ROOT modifier = opinion_grateful }
				has_opinion_modifier = { who = ROOT modifier = opinion_takfir }
				has_character_modifier = decadent_request_timer
			}
		}
		NOR = {
			trait = proud
			trait = humble
			has_character_modifier = planning_claimant_adventure
			has_character_modifier = planning_duchy_adventure
			has_character_flag = claimant_adventurer
		}
	}
	
	mean_time_to_happen = {
		months = 60
		modifier = {
			factor = 1.2
			has_character_modifier = estates_1
		}
		modifier = {
			factor = 1.4
			has_character_modifier = estates_2
		}
		modifier = {
			factor = 1.6
			has_character_modifier = estates_3
		}
		modifier = {
			factor = 1.8
			has_character_modifier = estates_4
		}
		modifier = {
			factor = 2
			has_character_modifier = estates_5
		}
		modifier = {
			factor = 0.5
			NOT = { wealth = 0 }
		}
		modifier = {
			factor = 0.5
			trait = greedy
			NOT = { wealth = 25 }
		}
		modifier = {
			factor = 0.5
			trait = ambitious
		}
		modifier = {
			factor = 0.75
			trait = gluttonous
		}
		modifier = {
			factor = 0.75
			trait = envious
		}
		modifier = {
			factor = 0.75
			trait = gregarious
		}
		modifier = {
			factor = 2
			trait = charitable
		}
		modifier = {
			factor = 2
			trait = content
		}
		modifier = {
			factor = 1.5
			trait = temperate
		}
		modifier = {
			factor = 1.5
			trait = shy
		}
	}

	immediate = {
		random_dynasty_member = {
			limit = {
				war = no
				religion = ROOT
				is_close_relative = ROOT
				same_realm = ROOT
				wealth = 100
				reverse_opinion = { who = ROOT value = -25 }
				opinion = { who = ROOT value = -25 }
				NOR = {
					liege = { war = yes }
					distance = { who = ROOT value = 75 }
					reverse_has_opinion_modifier = { who = ROOT modifier = negotiated_to_drop_decadence }
					reverse_has_opinion_modifier = { who = ROOT modifier = grievously_offended }
					reverse_has_opinion_modifier = { who = ROOT modifier = opinion_angry }
					reverse_has_opinion_modifier = { who = ROOT modifier = opinion_grateful }
					has_opinion_modifier = { who = ROOT modifier = opinion_takfir }
					has_character_modifier = decadent_request_timer
				}
			}
			if = {
				limit = { ai = no }
				add_character_modifier = {
					name = decadent_request_timer
					hidden = yes
					duration = 730
				}
			}
			if = {
				limit = { ai = yes }
				add_character_modifier = {
					name = decadent_request_timer
					hidden = yes
					duration = 180
				}
			}
			opinion = { who = ROOT modifier = opinion_disgusted months = 24 }
			character_event = { id = Plus.2507 }
		}
	}
}

# Relative is asked for money
character_event = {
	id = Plus.2507
	desc = EVTDESC_Plus_2507
	picture = GFX_evt_emissary
	
	is_triggered_only = yes
	
	option = {
		name = EVTOPTA_Plus_2507 #Give him money
		ai_chance = {
			factor = 50
			modifier = {
				factor = 1.5
				opinion = { who = FROM value = 25 }
			}
			modifier = {
				factor = 1.5
				opinion = { who = FROM value = 50 }
			}
			modifier = {
				factor = 1.5
				opinion = { who = FROM value = 75 }
			}
			modifier = {
				factor = 2
				trait = charitable
			}
			modifier = {
				factor = 1.5
				trait = kind
			}
			modifier = {
				factor = 1.25
				wealth = 200
			}
		}
		wealth = -50
		FROM = {
			wealth = 50
			opinion = { who = ROOT modifier = opinion_grateful months = 24 }
		}
	}
	option = {
		name = EVTOPTB_Plus_2507 #Send him away
		ai_chance = {
			factor = 50
			modifier = {
				factor = 2
				NOT = { opinion = { who = FROM value = 0 } }
			}
			modifier = {
				factor = 2
				NOT = { opinion = { who = FROM value = -25 } }
			}
			modifier = {
				factor = 4
				trait = greedy
			}
			modifier = {
				factor = 2
				trait = cruel
			}
			modifier = {
				factor = 2
				NOT = { is_child_of = ROOT }
			}
		}
		FROM = {
			if = {
				limit = {
					OR = {
						trait = lunatic
						trait = possessed
						trait = wroth
						trait = cruel
					}
				}
				opinion = { who = ROOT modifier = grievously_offended months = 60 }
			}
			if = {
				limit = {
					NOR = {
						trait = lunatic
						trait = possessed
						trait = wroth
						trait = cruel
					}
				}
				opinion = { who = ROOT modifier = opinion_angry months = 60 }
			}
		}
	}
}

