#############################################
#
# Bankruptcy events
#
# Event ID 38000-38099 is reserved
#
#############################################

# Ruler is in the red. Go to the moneylenders.
#character_event = {
#	id = 38000
#	desc = EVTDESC38000
#	picture = GFX_evt_council
#	
#	only_playable = yes
#	
#	trigger = {
#		NOT = { wealth = -50 }
#		NOT = { has_character_flag = loan_taken }
#		OR = {
#			NOT = { has_character_flag = loan_refused }
#			had_character_flag = { flag = loan_refused days = 365 }
#		}
#	}
#
#	# Patch 2.00: disabled
#	is_triggered_only = yes	
#	mean_time_to_happen = {
#		months = 1
#	}
#	
#	option = {
#		name = EVTOPTA38000 # Go to the moneylenders - Favorable terms
#		tooltip_info = stewardship
#		trigger = {
#			stewardship = 8
#		}
#		wealth = 200
#		character_event = { id = 38001 days = 1825 tooltip = EVTTOOLTIP38001 }
#		set_character_flag = loan_taken
#		clr_character_flag = loan_refused
#	}
#	option = {
#		name = EVTOPTB38000 # Go to the moneylenders - Unfavorable terms
#		trigger = {
#			NOT = { stewardship = 8 }
#		}
#		wealth = 200
#		character_event = { id = 38002 days = 1825 tooltip = EVTTOOLTIP38002 }
#		set_character_flag = loan_taken
#		clr_character_flag = loan_refused
#	}
#	option = {
#		name = EVTOPTC38000 # Do not go to the moneylenders
#		set_character_flag = loan_refused
#	}
#}

# Follow-up to favorable loan terms
#character_event = {
#	id = 38001
#	desc = EVTDESC38001
#	picture = GFX_evt_council
#	
#	is_triggered_only = yes
#	
#	option = {
#		name = EVTOPTA38001 # Return the money
#		trigger = {
#			wealth = 250
#		}
#		wealth = -250
#		clr_character_flag = loan_taken
#	}
#	option = {
#		name = EVTOPTB38001 # Cannot afford it
#		trigger = {
#			NOT = { wealth = 250 }
#		}
#		character_event = { id = 38002 days = 365 tooltip = EVTTOOLTIP38002B }
#	}
#	
#}

# Follow-up to unfavorable loan terms
character_event = {
	id = 38002
	desc = EVTDESC38002
	picture = GFX_evt_council
	
	is_triggered_only = yes
	
	option = {
		name = EVTOPTA38002 # Return the money
		trigger = {
			wealth = 300
		}
		wealth = -300
		clr_character_flag = loan_taken
	}
	option = {
		name = EVTOPTB38002 # Cannot afford it
		trigger = {
			NOT = { wealth = 300 }
		}
		
		prestige = -25
		character_event = { id = 38002 days = 365 tooltip = EVTTOOLTIP38002B }
	}
	option = { 
		name = EVTOPTC38002 # Get rid of them!
		#tooltip_info = 
		trigger = {
			OR = {
				trait = wroth
				trait = lunatic
				trait = possessed
			}
		}
		add_character_modifier = {
			name = offended_moneylenders
			duration = 1825
		}
		clr_character_flag = loan_taken
	}
}

#Ruler in red, lean on vassals
character_event = {
	id = 38010
	desc = EVTDESC38010
	picture = GFX_evt_council
	
	only_playable = yes
	prisoner = no
	
	trigger = {
		NOT = { culture = wilderness}
		NOT = { wealth = -50 }
		any_vassal = {
			wealth = 10
			NOT = { has_character_flag = took_extra_tax }
			opinion = { who = ROOT value =  0 }
		}
	}
	
	mean_time_to_happen = {
		months = 60
		modifier = {
			factor = 0.25
			has_character_flag = loan_taken
		}
	}
	
	option = {
		name = EVTOPTA38010 # Ask one vassal for large
		trigger = {
			any_vassal = {
				wealth = 200
				NOT = { has_character_flag = took_extra_tax }
				opinion = { who = ROOT value =  0 }
			}
		}
		ai_chance = {
			factor = 10
		}
		random_vassal = {
			limit = {
				wealth = 200
				NOT = { has_character_flag = took_extra_tax }
			}
			opinion = {
				modifier = got_money_request
				who = ROOT
				years = 2
			}
			set_character_flag = large_payment_from_vassal
			character_event = { id = 38011 days = 1 tooltip = EVTTOOLTIP38013 }
			set_character_flag = took_extra_tax
		}
	}
	option = {
		name = EVTOPTC38010 # ask all vassals for medium
		trigger = {
			any_vassal = {
				wealth = 50
				NOT = { has_character_flag = took_extra_tax }
				opinion = { who = ROOT value =  0 }
			}
		}

		ai_chance = {
			factor = 1
			modifier = {
				factor = 10
				wealth = -100
			}
		}
		random_vassal = {
			limit = {
				wealth = 25
				NOT = { has_character_flag = took_extra_tax }
			}
			opinion = {
				modifier = got_money_request
				who = ROOT
				years = 2
			}
			set_character_flag = medium_payment_from_vassal
			character_event = { id = 38011 days = 1 tooltip = EVTTOOLTIP38012 }
			set_character_flag = took_extra_tax
		}
	}
	option = {
		name = EVTOPTB38010 # ask all vassal for small
		trigger = {
			any_vassal = {
				wealth = 10
				NOT = { has_character_flag = took_extra_tax }
				opinion = { who = ROOT value =  0 }
			}
		}
		ai_chance = {
			factor = 1
		}
		random_vassal = {
			limit = {
				NOT = { has_character_flag = took_extra_tax }
			}
			
			opinion = {
				modifier = got_money_request
				who = ROOT
				years = 2
			}
			character_event = { id = 38011 days = 1 tooltip = EVTTOOLTIP38011 }
			set_character_flag = small_payment_from_vassal
			set_character_flag = took_extra_tax
		}
	}
}

#Request
character_event = {
	id = 38011
	desc = EVTDESC38011
	picture = GFX_evt_council
	
	is_triggered_only = yes

	option = {
		name = EVTOPTA_38011
		trigger = {
			has_dlc = "Zeus"
			has_character_flag = large_payment_from_vassal
			NOT = {
				holds_favor_on = FROM
			}
		}
		ai_chance = {
			factor = 5
			modifier = {
				factor = 1.5
				opinion = { who = from value =  25 }
			}
			modifier = {
				factor = 2
				opinion = { who = from value =  50 }
			}
			modifier = {
				factor = 3
				opinion = { who = from value =  75 }
			}
			modifier = {
				factor = 0
				NOT = { opinion = { who = from value =  0 } }
			}
		}
		custom_tooltip = {
			text = EVTOPTA_38011_TOOLTIP
			hidden_tooltip = {
				add_favor = FROM
				wealth = -250
				FROM = { character_event = { id = 38016 days = 1 } }
			}
		}
	}
	
	option = {
		name = ACCEPT
		ai_chance = {
			factor = 1
			modifier = {
				factor = 1.5
				opinion = { who = from value =  25 }
			}
			modifier = {
				factor = 2
				opinion = { who = from value =  50 }
			}
			modifier = {
				factor = 3
				opinion = { who = from value =  75 }
			}
			modifier = {
				factor = 0
				NOT = { opinion = { who = from value =  0 } }
			}
		}
		if = {
			limit = {
				has_character_flag = large_payment_from_vassal
			}
			wealth = -250
		}
		if = {
			limit = {
				has_character_flag = medium_payment_from_vassal
			}
			wealth = -50
		}
		if = {
			limit = {
				has_character_flag = small_payment_from_vassal
			}
			wealth = -10
		}
		hidden_tooltip = {
			FROM = { character_event = { id = 38015 days = 1 } }
		}
	}
	option = {
		name = DECLINE
		ai_chance = {
			factor = 1
			modifier = {
				factor = 2
				NOT = { opinion = { who = from value =  10 } }
			}
			modifier = {
				factor = 0
				opinion = { who = from value =  90 }
			}
		}
		clr_character_flag = small_payment_from_vassal
		clr_character_flag = medium_payment_from_vassal
		clr_character_flag = large_payment_from_vassal
		
		reverse_opinion = {
			modifier = refused_money_request
			who = FROM
			years = 5
		}		
		hidden_tooltip = {
			FROM = { character_event = { id = 38014 days = 1 } }
		}
	}
}


#Refusal to pay
character_event = {
	id = 38014
	desc = EVTDESC38014
	picture = GFX_evt_council
	
	is_triggered_only = yes
	
	option = {
		name = OK
		prestige = -1
	}
}

#Payment accepted
character_event = {
	id = 38015
	desc = EVTDESC38015
	picture = GFX_evt_council
	
	is_triggered_only = yes
	
	option = {
		name = OK
		if = {
			limit = {
				FROM = { has_character_flag = large_payment_from_vassal }
			}
			wealth = 250
		}
		if = {
			limit = {
				FROM = { has_character_flag = medium_payment_from_vassal }
			}
			wealth = 50
		}
		if = {
			limit = {
				FROM = { has_character_flag = small_payment_from_vassal }
			}
			wealth = 10
		}
		FROM = {
			clr_character_flag = small_payment_from_vassal
			clr_character_flag = medium_payment_from_vassal
			clr_character_flag = large_payment_from_vassal
		}
		prestige = 1
	}
	
}

#Payment accepted, for favor
character_event = {
	id = 38016
	desc = EVTDESC38016
	picture = GFX_evt_council
	
	is_triggered_only = yes
	
	option = {
		name = OK
		custom_tooltip = {
			text = EVTOPT_38016_TOOLTIP
			wealth = 250
		}
		FROM = {
			clr_character_flag = small_payment_from_vassal
			clr_character_flag = medium_payment_from_vassal
			clr_character_flag = large_payment_from_vassal
		}
	}
	
}

#Ruler is in the red. Seize Church Properties
character_event = {
	id = 38020
	desc = EVTDESC38020
	picture = GFX_evt_pope_feast
	
	only_playable = yes
	religion = eternal_fire
	prisoner = no
	
	trigger = {
		NOT = { culture = wilderness}
		NOT = { wealth = -50 }
		NOT = { has_character_flag = stolen_church_properties }
		NOT = { trait = zealous }
		any_vassal = {
			is_theocracy = yes
		}
	}
	
	mean_time_to_happen = {
		months = 48
	}
	
	option = {
		name = EVTOPTA38020 # There are fat bishop, seize them !
		trigger = {
			any_vassal = {
				is_theocracy = yes
				any_demesne_title = {
					tier = baron
					num_of_buildings = 1
				}
			}
		}
		ai_chance = {
			factor = 1
			modifier = {
				factor = 0
				NOT = { trait = cynical }
			}
		}
		random_vassal = {
			limit = {
				is_theocracy = yes
				any_demesne_title = {
					tier = baron
					num_of_buildings = 1
				}
			}
			
			character_event = { id = 38021 days = 1 tooltip = EVTTOOLTIP38021 }
			imprison = yes
		}
		wealth = 300
		add_trait = cruel
		set_character_flag = stolen_church_properties
	}
	option = {
		name = EVTOPTB38020 # Time are harsh, force them to share the costs !
		wealth = 100
		random = {
			chance = 25
			random_vassal = {
				limit = {
					is_theocracy = yes
				}
				character_event = { id = 38021 days = 1 tooltip = EVTTOOLTIP38021 }
			}
		}
		set_character_flag = stolen_church_properties
	}
	option = {
		name = EVTOPTC38020 # Compromise with them to find money !
		wealth = 50
		piety = 25
		prestige = -50
		set_character_flag = stolen_church_properties
	}
	option = {
		name = EVTOPTD38020 # Never ! I will save my Christian soul !
		piety = 50
		if = {
			limit = { 	NOT = { trait = zealous } }
			change_stewardship = -1
			add_trait = zealous
		}
		set_character_flag = stolen_church_properties
	}
}

#If a building is specified, then that one is exempt
character_event = {
	id = 38021
	desc = EVTDESC38021
	picture = GFX_evt_lunatic
	
	is_triggered_only = yes
	
	immediate = {
		random_demesne_title = {
			limit = {
				tier = baron
			}
			destroy_random_building = yes	
		}
		wealth = -100
	}
	
	option = {
		name = EVTOPTA38021 # They are cursed in the eyes of God!
		ai_chance = {
			factor = 1
			modifier = {
				factor = 10
				NOT = { opinion = { who = from value =  50 } }
			}
			modifier = {
				factor = 10
				trait = zealous
			}
			modifier = {
				factor = 100
				prisoner = yes
			}
		}
		FROM = { character_event = { id = 38022 days = 63 tooltip = EVTTOOLTIP38022 } }
	}
	option = {
		name = EVTOPTB38021 # Jesus said to forgive them for their sins.
		ai_chance = {
			factor = 1
			modifier = {
				factor = 2
				trait = kind
			}
			modifier = {
				factor = 1.5
				trait = humble
			}
			modifier = {
				factor = 0
				prisoner = yes
			}			
		}
		opinion = {
			modifier = grudge_from_sin
			who = ROOT
			years = 5
		}
	}
}

#We have been judged in the eyes of God
character_event = {
	id = 38022
	desc = EVTDESC38022
	picture = GFX_evt_bad_news
	
	is_triggered_only = yes
	hide_from = yes
	
	option = {
		name = EVTOPTA38022 
		piety = -100
	}
}
	
#On-Action: Mercs go on a rampage
letter_event = {
	id = 38050
	desc = EVTDESC38050
	
	is_triggered_only = yes
	
	trigger = {
		ai = no
	}
	
	option = {
		name = EVTOPTA38050
	}
}

#On-Action: Mercs leave in disgust
letter_event = {
	id = 38051
	desc = EVTDESC38051
	
	is_triggered_only = yes
	
	trigger = {
		ai = no
	}
	
	option = {
		name = EVTOPTA38051
	}
}

#On-Action: Mercs switch side FROM you
letter_event = {
	id = 38052
	desc = EVTDESC38052
	
	is_triggered_only = yes
	
	trigger = {
		ai = no
	}
	
	option = {
		name = EVTOPTA38052
	}
}

#On-Action: Mercs switch side TO you
letter_event = {
	id = 38053
	desc = EVTDESC38053
	
	is_triggered_only = yes
	
	trigger = {
		ai = no
	}
	
	option = {
		name = EVTOPTA38053
	}
}

#On-Action: Holy Order leaves your service
letter_event = {
	id = 38054
	desc = EVTDESC38054
	border = GFX_event_letter_frame_war
	
	is_triggered_only = yes
	
	trigger = {
		ai = no
	}
	
	option = {
		name = EVTOPTA38054
	}
}


# Offer to buy a title from indebted liege
character_event = {
	id = 38060
	desc = EVTDESC38060
	picture = GFX_evt_council
	
	only_playable = yes
	prisoner = no
	only_capable = yes
	min_age = 16
	
	trigger = {
		NOT = { culture = wilderness}
		independent = no
		NOT = { has_character_flag = offered_to_buy_liege_titles }
		liege = {
			NOT = { character = ROOT }
		}
		liege = {
			NOT = { wealth = -50 }
			any_demesne_title = {
				has_de_jure_pretension = ROOT
				can_be_given_away = yes
				lower_tier_than = PREV
				NOT = {
					AND = {
						tier = count
						location = {
							is_capital = yes
						}						
					}
				}
			}
		}
		wealth = 250
	}
	
	immediate = {
		liege = {
			random_demesne_title = {
				limit = {
					has_de_jure_pretension = ROOT
					can_be_given_away = yes
					lower_tier_than = PREV
					NOT = {
						AND = {
							tier = count
							location = {
								is_capital = yes
							}
						}
					}
				}
				save_event_target_as = title_for_sale
			}
		}
		set_character_flag = offered_to_buy_liege_titles
	}
	
	mean_time_to_happen = {
		months = 60
		
		modifier = {
			factor = 0.75
			liege = { NOT = { wealth = -75 } }
		}
		modifier = {
			factor = 0.75
			liege = { NOT = { wealth = -100 } }
		}
		modifier = {
			factor = 0.75
			liege = { NOT = { wealth = -125 } }
		}
		modifier = {
			factor = 0.75
			liege = { NOT = { wealth = -150 } }
		}
		modifier = {
			factor = 0.75
			wealth = 275
		}
		modifier = {
			factor = 0.75
			wealth = 300
		}
		modifier = {
			factor = 0.75
			wealth = 325
		}
		modifier = {
			factor = 0.75
			wealth = 350
		}
	}
	
	option = {
		trigger = {
			has_dlc = "Zeus"
			NOT = {
				liege = { owes_favor_to = ROOT }
			}
		}
		name = EVTOPTC38060
		ai_chance = { factor = 100 }
		liege = { character_event = { id = 38062 days = 1 tooltip = EVTTOOLTIP38061 } }
		liege = {
			tooltip = {
				event_target:title_for_sale = {
					grant_title = ROOT
				}
				ROOT = {
					wealth = -300
					add_favor = PREV
				}
			}
		}
	}
	
	option = {
		name = EVTOPTA38060
		ai_chance = { factor = 100 }
		liege = { character_event = { id = 38061 days = 1 tooltip = EVTTOOLTIP38061 } }
		liege = {
			tooltip = {
				event_target:title_for_sale = {
					grant_title = ROOT
				}
				ROOT = {
					wealth = -200
				}
			}
		}
	}
	option = {
		name = EVTOPTB38060
		ai_chance = { factor = 0 }
	}
}

# Liege receives offer to sell land
character_event = {
	id = 38061
	desc = EVTDESC38061
	picture = GFX_evt_council
	
	is_triggered_only = yes

	
	option = {
		name = EVTOPTA38061
		ai_chance = { factor = 100 }
		wealth = 200
		if = { 
			limit = { NOT = { has_landed_title = event_target:title_for_sale } } #If the title has been given away in the meantime, or lost.
			random_demesne_title = {
				limit = {
					lower_tier_than = ROOT
					NOT = {
						AND = {
							tier = count
							location = {
								is_capital = yes
							}
						}
					}
				}
				preferred_limit = {
					has_de_jure_pretension = FROM
					can_be_given_away = yes
				}
				preferred_limit = {
					can_be_given_away = yes
				}
				save_event_target_as = title_for_sale
			}
		}
		event_target:title_for_sale = {
			grant_title = FROM
		}
		FROM = {
			wealth = -200
		}
	}
	option = {
		name = EVTOPTB38061
		ai_chance = { factor = 0 }
	}
}

# Liege receives offer to sell land for favor
character_event = {
	id = 38062
	desc = EVTDESC38062
	picture = GFX_evt_council
	
	is_triggered_only = yes
	
	option = {
		name = EVTOPTA38062
		ai_chance = { factor = 100 }
		wealth = 300
		if = { 
			limit = { NOT = { has_landed_title = event_target:title_for_sale } } #If the title has been given away in the meantime, or lost.
			random_demesne_title = {
				limit = {
					lower_tier_than = ROOT
					NOT = {
						AND = {
							tier = count
							location = {
								is_capital = yes
							}
						}
					}
				}
				preferred_limit = {
					has_de_jure_pretension = FROM
					can_be_given_away = yes
				}
				preferred_limit = {
					can_be_given_away = yes
				}
				save_event_target_as = title_for_sale
			}
		}
		event_target:title_for_sale = {
			grant_title = FROM
		}
		FROM = {
			wealth = -300
			add_favor = ROOT
		}
	}
	option = {
		name = EVTOPTB38062
		ai_chance = { factor = 0 }
	}
}