#########################################
#
# Adventurers negotiation
#
# ADV.1-30
#
#########################################

#Mathilda Bjarnehed

namespace = ADV

character_event = {
	id = ADV.1

	is_triggered_only = yes
	hide_window = yes

	immediate = {
		FROM = { save_event_target_as = raiding_adventurer }
		if = {
			limit = {
				event_target:adventurer_decision_target_override = {
					is_alive = yes
				}
			}
			event_target:adventurer_decision_target_override = {
				save_event_target_as = raiding_adventurer
			}
		}
		save_event_target_as = adventurer_target
		if = {
			limit = {
				event_target:adventurer_decision_taker_override = {
					is_alive = yes
				}
			}
			event_target:adventurer_decision_taker_override = {
				save_event_target_as = adventurer_target
			}
		}

		#Stores how much money adventurer has
		event_target:raiding_adventurer = { export_to_variable = { which = adventurer_treasury value = treasury } }

		#Picks out a province to sell 
		random_demesne_province = {
			limit = {
				is_capital = no 
				num_of_settlements = 1
				NOT = {
					has_province_modifier = nomad_agitation
				}
				OR = {
					AND = {
						event_target:raiding_adventurer = { is_seafarer = yes }
						port = yes
					}
					event_target:raiding_adventurer = { is_seafarer = no }
					AND = {
						holder_scope = {
							top_liege = {
								NOT = { any_demesne_province = { port = yes } }
							}
						}
						NOT = {
							port = yes
						}
					}
				}
			}

			set_variable = { which = price value = 100 }

			trigger_switch = {
				on_trigger = num_of_settlements
				7 = { change_variable = { which = price value = 700 } }
				6 = { change_variable = { which = price value = 600 } }
				5 = { change_variable = { which = price value = 500 } }
				4 = { change_variable = { which = price value = 400 } }
				3 = { change_variable = { which = price value = 300 } }
				2 = { change_variable = { which = price value = 200 } }
				1 = { change_variable = { which = price value = 100 } }
			}

			trigger_switch = {
				on_trigger = num_of_empty_holdings
				6 = { change_variable = { which = price value = 150 } }
				5 = { change_variable = { which = price value = 125 } }
				4 = { change_variable = { which = price value = 100 } }
				3 = { change_variable = { which = price value = 75 } }
				2 = { change_variable = { which = price value = 50 } }
				1 = { change_variable = { which = price value = 25 } }
			}

			set_variable = { which = haggle_price which = price }
			multiply_variable = { which = haggle_price value = 0.7 }


			#Checks that the adventurer has enough money to haggle
			if = {
				limit = {
					OR = {
						event_target:adventurer_target = {
							has_character_flag = peaceful_negotiation
						}
						event_target:raiding_adventurer = { check_variable = { which = adventurer_treasury which = haggle_price which = PREV } }
					}
				}
				save_event_target_as = selling_province
			}
		}

   		#If they can't afford your province, pick a vassal province (also a big chance to happen even if they can afford it)
		random_list = {
			80 = { 
				random_vassal = {
					limit = {
						any_demesne_province = {
							is_capital = no 
							num_of_settlements = 1
							NOT = {
								has_province_modifier = nomad_agitation
							}
							OR = {
								AND = {
									event_target:raiding_adventurer = { is_seafarer = yes }
									port = yes
								}
								event_target:raiding_adventurer = { is_seafarer = no }
								NOT = { any_demesne_province = { port = yes } }
							}
						}
					}
					random_demesne_province = {
						limit = { 
							is_capital = no 
							num_of_settlements = 1
							NOT = {
								has_province_modifier = nomad_agitation
							}
							OR = {
								AND = {
									event_target:raiding_adventurer = { is_seafarer = yes }
									port = yes
								}
								event_target:raiding_adventurer = { is_seafarer = no }
								AND = {
									holder_scope = {
										top_liege = {
											NOT = { any_demesne_province = { port = yes } }
										}
									}
									NOT = {
										port = yes
									}
								}
							}
						}

						set_variable = { which = price value = 100 }

						trigger_switch = {
							on_trigger = num_of_settlements
							7 = { change_variable = { which = price value = 400 } }
							6 = { change_variable = { which = price value = 350 } }
							5 = { change_variable = { which = price value = 300 } }
							4 = { change_variable = { which = price value = 250 } }
							3 = { change_variable = { which = price value = 200 } }
							2 = { change_variable = { which = price value = 150 } }
							1 = { change_variable = { which = price value = 100 } }
						}

						trigger_switch = {
							on_trigger = num_of_empty_holdings
							6 = { change_variable = { which = price value = 60 } }
							5 = { change_variable = { which = price value = 50 } }
							4 = { change_variable = { which = price value = 40 } }
							3 = { change_variable = { which = price value = 30 } }
							2 = { change_variable = { which = price value = 20 } }
							1 = { change_variable = { which = price value = 10 } }
						}

						set_variable = { which = haggle_price which = price }
						multiply_variable = { which = haggle_price value = 0.7 }

						save_event_target_as = selling_province
					}
				}
			}
			20 = {
				modifier = {
					NOT = { event_target:selling_province = { always = yes } }
					factor = 0
				}
				#Empty, your demesne province is kept as selling_province
			}
		}

		if = {
			limit = { event_target:raiding_adventurer = { is_married = no } }
			random_child = {
				limit = {	
					OR = {
						AND = {
							event_target:raiding_adventurer = { is_female = yes }
							is_female = no
						}
						AND = {
							event_target:raiding_adventurer = { is_female = no }
							is_female = yes
						}
					}
					is_adult = yes
					is_alive = yes
					is_married = no
					can_marry = yes
					NOT = { is_primary_heir = ROOT }
					is_ruler = no
					NOR = {
						is_dumb_trigger = yes
						character_disease_trigger = yes
						has_disability_trigger = yes
						has_mental_disorder_trigger = yes
						trait = homosexual
						trait = celibate
						trait = ugly
					}
					OR = {
						is_smart_trigger = yes
						has_attractive_trait_trigger = yes
						has_pleasant_personality_trigger = yes
						stewardship = 13
						martial = 13
						diplomacy = 13
						intrigue = 13
						learning = 15
					}
				}
				save_event_target_as = marriage_child
			}
		}

		#If a suitable deal can be made, fire the negotiation
		if = {
			limit = {
				OR = {
					event_target:selling_province = { always = yes }
					event_target:marriage_child = { always = yes }
				}
			}
			event_target:raiding_adventurer = { character_event = { id = ADV.2 } }
			break = yes
		}

		#Adventurer declares war
		raiding_adventurer_war_declaration_effect = yes

		#Logging for displaced prince...
		if = {
			limit = { event_target:raiding_adventurer = { has_character_flag = is_displaced_prince } }
			log = "Displaced royal: [raiding_adventurer.GetBestName] declared war over the province [selling_province.GetName], currently held by [Root.GetBestName]."
		}
	}
}

#Ping event
character_event = {
	id = ADV.2
	hide_window = yes
	is_triggered_only = yes
	immediate = { FROM = { letter_event = { id = ADV.3 } } }
}

#Negotiation start
letter_event = {
	id = ADV.3
	border = GFX_event_letter_frame_war

	desc = {
		trigger = {
			event_target:selling_province = { always = yes }
			event_target:marriage_child = { always = yes }
		}
		text = EVTDESC_ADV_3_A
	}
	desc = {
		trigger = {
			event_target:selling_province = { always = yes }
			NOT = { event_target:marriage_child = { always = yes } }
		}
		text = EVTDESC_ADV_3_B
	}
	desc = {
		trigger = {
			NOT = { event_target:selling_province = { always = yes } }
			event_target:marriage_child = { always = yes }
		}
		text = EVTDESC_ADV_3_C
	}

	is_triggered_only = yes

  
	#Sell your province 
	option = {
		trigger = { 
			event_target:selling_province = { 
				always = yes 
				owner = { character = ROOT }
			} 
		}
		name = EVTOPTA_ADV_3
		custom_tooltip = { text = EVTOPTA_ADV_3_TT }

		hidden_effect = {
			event_target:raiding_adventurer = { character_event = { id = ADV.10 days = 5 } }
		}

		ai_chance = {
			factor = 20
			modifier = { trait = craven factor = 2 }
			modifier = { trait = greedy factor = 1.3 }
			modifier = { event_target:raiding_adventurer = { realm_levy_diff = { who = ROOT value = 1500 } } factor = 1.3 }
			modifier = { event_target:raiding_adventurer = { realm_levy_diff = { who = ROOT value = 3000 } } factor = 1.5 }
			modifier = { event_target:raiding_adventurer = { realm_levy_diff = { who = ROOT value = 5000 } } factor = 1.5 }
		}
	}

	#Sell vassal province
	option = {
		trigger = { 
			event_target:selling_province = { 
				always = yes 
				NOT = { owner = { character = ROOT } }
			} 
		}
		name = EVTOPTA_ADV_3
		custom_tooltip = { text = EVTOPTB_ADV_3_TT }

		tooltip = {
			prestige = -50
			event_target:selling_province = {
				owner = {
					opinion = {
						who = ROOT
						modifier = sold_my_province
						years = 100
					}
				}
			}
			if = {
				limit = { any_vassal = { NOT = { any_demesne_province = { province = event_target:selling_province } } } }
				custom_tooltip = { text = EVTOPTA_ADV_5_tooltip }
			}
			hidden_effect = {
				any_vassal = {
					limit = { NOT = { any_demesne_province = { province = event_target:selling_province } } }
					opinion = {
						who = ROOT
						modifier = sold_vassal_province
						years = 5
					}
				}
			}
		}

		hidden_effect = {
			event_target:raiding_adventurer = { character_event = { id = ADV.10 days = 5 } }
		}

		ai_chance = {
			factor = 30
			modifier = { trait = craven factor = 2 }
			modifier = { trait = greedy factor = 2 }
			modifier = { event_target:raiding_adventurer = { realm_levy_diff = { who = ROOT value = 1500 } } factor = 1.3 }
			modifier = { event_target:raiding_adventurer = { realm_levy_diff = { who = ROOT value = 3000 } } factor = 1.5 }
			modifier = { event_target:raiding_adventurer = { realm_levy_diff = { who = ROOT value = 5000 } } factor = 1.5 }
		}
	}
	
	#Agree to marriage
	option = {
		trigger = { event_target:marriage_child = { always = yes } }
		name = EVTOPTC_ADV_3
		custom_tooltip = { text = EVTOPTC_ADV_3_TT }

		event_target:marriage_child = {
			if = {
				limit = { is_female = no }
				add_spouse_matrilineal = event_target:raiding_adventurer
			}
			 if = {
				limit = { is_female = yes }
				add_spouse = event_target:raiding_adventurer
			}
		}

		hidden_effect = {
			clr_character_flag = adventurer_unsafe_duchy_war
			clr_character_flag = adventurer_safe_duchy_war
			clr_character_flag = negotiating_with_adventurer
			set_looter_hostility_days = {
				who = event_target:raiding_adventurer
				days = 0
			}
			event_target:raiding_adventurer = {
				set_looter_hostility_days = {
					who = ROOT
					days = 0
				}
			}
		}
		
		log = "Raiding adventurer [raiding_adventurer.GetBestName]([raiding_adventurer.GetID]) got married to [marriage_child.GetBestName]([marriage_child.GetID]) after negotiations"

		#Logging for displaced prince...
		if = {
			limit = { event_target:raiding_adventurer = { has_character_flag = is_displaced_prince } }
			log = "Displaced royal: [raiding_adventurer.GetBestName] ([raiding_adventurer.GetID]) got married to [marriage_child.GetBestName]([marriage_child.GetID]) after negotiations"
		}


		ai_chance = {
			factor = 100
			modifier = { trait = craven factor = 2 }
			modifier = { is_rival = event_target:marriage_child factor = 2 }
			modifier = { is_friend = event_target:marriage_child factor = 0.5 }
			modifier = { num_of_children = 5 factor = 1.3 }
			modifier = { event_target:raiding_adventurer = { realm_levy_diff = { who = ROOT value = 1500 } } factor = 1.3 }
			modifier = { event_target:raiding_adventurer = { realm_levy_diff = { who = ROOT value = 3000 } } factor = 1.5 }
			modifier = { event_target:raiding_adventurer = { realm_levy_diff = { who = ROOT value = 5000 } } factor = 1.5 }
		}
	}
	
	#No deal
	option = {
		name = EVTOPTD_ADV_3
		custom_tooltip = { text = EVTOPTD_ADV_3_TT }
		
		trigger = {
			event_target:adventurer_target = {
				NOT = {
					has_character_flag = peaceful_negotiation
				}
			}
		}

		#Adventurer declares war
		raiding_adventurer_war_declaration_effect = yes

		#Logging for displaced prince...
		if = {
			limit = { event_target:raiding_adventurer = { has_character_flag = is_displaced_prince } }
			log = "Displaced royal: [raiding_adventurer.GetBestName] had their negotiation turned down, and instead declared war over the province [selling_province.GetName], currently held by [Root.GetBestName]."
		}

		ai_chance = {
			factor = 20
			modifier = { realm_levy_diff = { who = event_target:raiding_adventurer value = 1000 } factor = 1.3 }
			modifier = { realm_levy_diff = { who = event_target:raiding_adventurer value = 2500 } factor = 1.3 }
			modifier = { trait = brave factor = 2 }
			modifier = { trait = wroth factor = 1.5 }
			modifier = { trait = ambitious factor = 1.5 }
		}
	}
	
	#No deal - peaceful
	option = {
		name = EVTOPTE_ADV_3
		custom_tooltip = { text = EVTOPTE_ADV_3_TT }
		
		trigger = {
			event_target:adventurer_target = {
				has_character_flag = peaceful_negotiation
			}
		}
		
		clr_character_flag = peaceful_negotiation

		#Logging for displaced prince...
		if = {
			limit = { event_target:raiding_adventurer = { has_character_flag = is_displaced_prince } }
			log = "Displaced royal: [raiding_adventurer.GetBestName] had their negotiation turned down, no war was declared as the event was fired via a player-only decision"
		}

		ai_chance = {
			factor = 20
			modifier = { realm_levy_diff = { who = event_target:raiding_adventurer value = 1000 } factor = 1.3 }
			modifier = { realm_levy_diff = { who = event_target:raiding_adventurer value = 2500 } factor = 1.3 }
			modifier = { trait = brave factor = 2 }
			modifier = { trait = wroth factor = 1.5 }
			modifier = { trait = ambitious factor = 1.5 }
		}
	}
}


#Raiding adventurer evaluates 
character_event = {
	id = ADV.10
	hide_window = yes
	is_triggered_only = yes
	immediate = { 
		#If they can afford the price, see if they haggle or not
		export_to_variable = { which = adventurer_treasury value = treasury }
		subtract_variable = { which = adventurer_treasury which = price which = event_target:selling_province }
		
		if = {
			limit = {
				NOT = { check_variable = { which = adventurer_treasury value = 0 } }
			}
			log = "Adventurer [This.GetBestName]([This.GetID]) is forced to haggle since [This.GetSheHe] can't afford the province."
		}
			
		random_list = {
			50 = { #Deal
				trigger = { check_variable = { which = adventurer_treasury value = 0 } }
				modifier = { NOT = { stewardship = 8 } factor = 2 }
				modifier = { age = 50 factor = 2 }
				modifier = { trait = craven factor = 2 }
				modifier = { trait = content factor = 2 }
				modifier = { trait = charitable factor = 2 }
				modifier = { trait = just factor = 2 }
				event_target:adventurer_target = { letter_event = { id = ADV.4 } }
				break = yes
			}
			50 = { #Haggle
				modifier = { stewardship = 14 factor = 2 }
				modifier = { trait = greedy factor = 2 }
				modifier = { trait = ambitious factor = 2 }
				modifier = { trait = arbitrary factor = 2 }

				export_to_variable = { which = adventurer_treasury value = treasury }
				subtract_variable = { which = adventurer_treasury which = haggle_price which = event_target:selling_province }

				if = {
					limit = { check_variable = { which = adventurer_treasury value = 0 } }
					set_variable = { which = province_offer value = 0 }
					change_variable = { which = province_offer which = haggle_price which = event_target:selling_province }
					set_character_flag = haggle_price
				}

				if = {
					limit = {
						NOT = { check_variable = { which = adventurer_treasury value = 0 } }
						NOT = {
							wealth = 100
						}
					}
					set_character_flag = no_haggling
					log = "[This.GetBestName]([This.GetID]) can't even afford the reduced haggle price."
				}
				
				if = {
					limit = {
						NOT = { check_variable = { which = adventurer_treasury value = 0 } }
						wealth = 100
					}
					set_variable = { which = province_offer value = 0 }
					export_to_variable = { which = province_offer value = treasury }
					set_character_flag = haggle_price
					log = "[This.GetBestName]([This.GetID]) can't even afford the reduced haggle price - they are offering what they have instead."
				}

				event_target:adventurer_target = { letter_event = { id = ADV.5 } }
			}
		}
	}
}

#They accept the offer
letter_event = {
	id = ADV.4
	desc = EVTDESC_ADV_4
	border = GFX_event_letter_frame_diplomacy

	is_triggered_only = yes

	immediate = { 
		hidden_effect = {
			set_variable = { which = transfer_money value = 0 }
			change_variable = { which = transfer_money which = price which = event_target:selling_province }

			event_target:raiding_adventurer = {
				set_variable = { which = transfer_money value = 0 }
				change_variable = { which = transfer_money which = price which = event_target:selling_province }
				multiply_variable = { which = transfer_money value = -1 }
			}
		}
	}

	option = { 
		name = EVTOPTA_ADV_4

		#Transfers the price of the selling province
		wealth = transfer_money

		hidden_effect = {
			event_target:raiding_adventurer = {
				wealth = transfer_money
				clr_character_flag = raiding_adventurer #flag set in hl_raiding_adventurers_events.txt
			}

			#Non-Aggression Pact
			opinion = {
				modifier = in_non_aggression_pact
				years = 3
				who = FROM
				origin_description = EVTTITLE_ADV_4
			}
			FROM = {
				opinion = {
					modifier = in_non_aggression_pact
					years = 3
					who = ROOT
					origin_description = EVTTITLE_ADV_4
				}
			}
		} 
	   
		#Changes opinions/prestige if not your province 
		if = {
			limit = { NOT = { event_target:selling_province = { owner = { character = ROOT } } } }

			prestige = -50

			event_target:selling_province = {
				owner = {
					opinion = {
						who = ROOT
						modifier = sold_my_province
						years = 100
					}
				}
			}
			if = {
				limit = { any_vassal = { NOT = { any_demesne_province = { province = event_target:selling_province } } } }
				custom_tooltip = { text = EVTOPTA_ADV_5_tooltip }
			}
			hidden_effect = {
				any_vassal = {
					limit = { NOT = { any_demesne_province = { province = event_target:selling_province } } }
					opinion = {
						who = ROOT
						modifier = sold_vassal_province
						years = 5
					}
				}
			}
		}
		
		#Government switch
		if = {
			limit = {
				event_target:raiding_adventurer = { is_nomadic = yes }
				is_nomadic = no
			}
			event_target:raiding_adventurer = {
				if = {
					limit = {
						religion_group = muslim
					}
					set_government_type = muslim_government
				}
				else_if = {
					limit = {
						culture_group = tibetan_group
						OR = {
							religion = bon
							religion = buddhist
							religion = tibetan_pagan
						}
					}
					set_government_type = theocratic_feudal_government
				}
				else = {
					set_government_type = feudal_government
				}
			}
		}

		#Grants province and sets liege 
		event_target:selling_province = {
			county = { grant_title = event_target:raiding_adventurer } 
		}
		event_target:raiding_adventurer = { set_defacto_liege = ROOT }
		
		#Logging for displaced prince...
		if = {
			limit = { event_target:raiding_adventurer = { has_character_flag = is_displaced_prince } }
			log = "Displaced royal: [raiding_adventurer.GetBestName] settled after buying the province [selling_province.GetName] to the price of [transfer_money.GetValue] ducats, from [Root.GetBestName]."
		}
		else = {
		  log = "Adventurer [raiding_adventurer.GetBestName] settled after buying the province [selling_province.GetName] to the price of [transfer_money.GetValue] ducats."
		}

		#Chance to convert to your religion (unless it's a Chinese royal...)
		hidden_effect = {
			if = {
				limit = { 
					event_target:raiding_adventurer = { 
						NOR = {
							has_character_flag = is_displaced_prince
							religion = ROOT
						}
					} 
				}
				event_target:raiding_adventurer = { character_event = { id = ADV.20 } }
			}
		}

		#Make country safe
		hidden_effect = {
			any_realm_province = {
				add_province_modifier = {
					name = settled_adventurer
					years = 10
				}
			}
			event_target:raiding_adventurer = {
				any_unit = {
					set_can_toggle_looting = yes
					set_looting = no
				}
				set_looter_hostility_days = {
					who = ROOT
					days = 0
				}
			}
			set_looter_hostility_days = {
				who = event_target:raiding_adventurer
				days = 0
			}
		}
	}

	after = {
		clr_character_flag = adventurer_unsafe_duchy_war
		clr_character_flag = adventurer_safe_duchy_war
		clr_character_flag = negotiating_with_adventurer
	}
}

#They have a counter-offer
letter_event = {
	id = ADV.5
	desc = {
		trigger = { FROM = { has_character_flag = haggle_price } } #They have enough money and offer to haggle
		text = EVTDESC_ADV_5
	}
	desc = {
		trigger = { FROM = { has_character_flag = no_haggling } } #They do not have enough money to haggle and demand it for free
		text = EVTDESC_ADV_5_B
	}
	border = GFX_event_letter_frame_diplomacy

	is_triggered_only = yes

	immediate = { 
		#Calculates your gain before option so tooltips are correct
		hidden_effect = {
			set_variable = { which = transfer_money value = 0 }
			change_variable = { which = transfer_money which = province_offer which = event_target:raiding_adventurer }
		}
	} 
	

	#Accept
	option = {
		name = EVTOPTA_ADV_5

		#Transfers the province offer made by the adventurer.
		if = {
			limit = { FROM = { has_character_flag = haggle_price } }
			wealth = transfer_money
		}

		hidden_effect = {
			if = {
				limit = { FROM = { has_character_flag = haggle_price } }
				event_target:raiding_adventurer = {
			   	multiply_variable = { which = province_offer value = -1 }
			   	wealth = province_offer
			   	clr_character_flag = raiding_adventurer #flag set in hl_raiding_adventurers_events.txt
			   }	
			}

			#Non-Aggression Pact
			opinion = {
				modifier = in_non_aggression_pact
				years = 3
				who = FROM
				origin_description = EVTTITLE_ADV_4
			}
			FROM = {
				opinion = {
					modifier = in_non_aggression_pact
					years = 3
					who = ROOT
					origin_description = EVTTITLE_ADV_4
				}
			}
		}

		#Changes opinions/prestige if not your province 
		if = {
			limit = { NOT = { event_target:selling_province = { owner = { character = ROOT } } } }

			prestige = -50

			event_target:selling_province = {
				owner = {
					opinion = {
						who = ROOT
						modifier = sold_my_province
						years = 100
					}
				}
			}
			if = {
				limit = { any_vassal = { NOT = { any_demesne_province = { province = event_target:selling_province } } } }
				custom_tooltip = { text = EVTOPTA_ADV_5_tooltip }
			}
			hidden_effect = {
				any_vassal = {
					limit = { NOT = { any_demesne_province = { province = event_target:selling_province } } }
					opinion = {
						who = ROOT
						modifier = sold_vassal_province
						years = 5
					}
				}
			}
		}
		
		#Government switch
		if = {
			limit = {
				event_target:raiding_adventurer = { is_nomadic = yes }
				is_nomadic = no
			}
			event_target:raiding_adventurer = {
				if = {
					limit = {
						religion_group = muslim
					}
					set_government_type = muslim_government
				}
				else_if = {
					limit = {
						culture_group = tibetan_group
						OR = {
							religion = bon
							religion = buddhist
							religion = tibetan_pagan
						}
					}
					set_government_type = theocratic_feudal_government
				}
				else = {
					set_government_type = feudal_government
				}
			}
		}

		#Gives province and sets liege
		event_target:selling_province = {
			county = { grant_title = event_target:raiding_adventurer } 
		}
		event_target:raiding_adventurer = { set_defacto_liege = ROOT }

		#Logging for displaced prince...
		if = {
			limit = { event_target:raiding_adventurer = { has_character_flag = is_displaced_prince } }
			log = "Displaced royal: [raiding_adventurer.GetBestName] settled after buying the province [selling_province.GetName] to the price of [transfer_money.GetValue] ducats, from [Root.GetBestName]."
		}		
		if = {
			limit = {
				NOT = { FROM = { has_character_flag = no_haggling } }
			}
			log = "Adventurer [raiding_adventurer.GetBestName]([raiding_adventurer.GetID]) settled after buying the province [selling_province.GetName] to the haggle price of [transfer_money.GetValue] ducats."
		}
		if = {
			limit = {
				FROM = { has_character_flag = no_haggling }
			}
			log = "Adventurer [raiding_adventurer.GetBestName]([raiding_adventurer.GetID]) was given the province of [selling_province.GetName] after [raiding_adventurer.GetSheHe] couldn't afford to buy it."
		}

		#Chance to convert to your religion (unless it's a Chinese royal...)
		hidden_effect = {
			if = { 
				limit = { 
					event_target:raiding_adventurer = { 
						NOR = {
							has_character_flag = is_displaced_prince
							religion = ROOT
						}
					} 
				}
				event_target:raiding_adventurer = { character_event = { id = ADV.20 } }
			}
		}

		#Make country safe
		hidden_effect = {
			any_realm_province = {
				add_province_modifier = {
					name = settled_adventurer
					years = 10
				}
			}
			event_target:raiding_adventurer = {
				any_unit = {
					set_can_toggle_looting = yes
					set_looting = no
				}
				set_looter_hostility_days = {
					who = ROOT
					days = 0
				}
			}
			set_looter_hostility_days = {
				who = event_target:raiding_adventurer
				days = 0
			}
		}

		ai_chance = {
			factor = 50
			modifier = { trait = craven factor = 2 }
			modifier = { trait = greedy factor = 1.3 }
			modifier = { event_target:raiding_adventurer = { realm_levy_diff = { who = ROOT value = 1500 } } factor = 1.3 }
			modifier = { event_target:raiding_adventurer = { realm_levy_diff = { who = ROOT value = 3000 } } factor = 1.5 }
			modifier = { event_target:raiding_adventurer = { realm_levy_diff = { who = ROOT value = 5000 } } factor = 1.5 }
		}
	}

	#Decline
	option = {
		name = EVTOPTD_ADV_5
		custom_tooltip = { text = EVTOPTD_ADV_3_TT }
		
		trigger = {
			event_target:adventurer_target = {
				NOT = {
					has_character_flag = peaceful_negotiation
				}
			}
		}

		#Adventurer declares war
		raiding_adventurer_war_declaration_effect = yes

		ai_chance = {
			factor = 50
			modifier = { realm_levy_diff = { who = event_target:raiding_adventurer value = 1000 } factor = 1.3 }
			modifier = { realm_levy_diff = { who = event_target:raiding_adventurer value = 2500 } factor = 1.3 }
			modifier = { trait = brave factor = 2 }
			modifier = { trait = wroth factor = 1.5 }
			modifier = { trait = ambitious factor = 1.5 }
			modifier = { event_target:raiding_adventurer = { NOT = { has_character_flag = haggle_price } } factor = 5 }
			modifier = { event_target:selling_province = { holder_scope = { character = ROOT } } factor = 1.5 }
		}
	}
	
	#Decline - peaceful
	option = {
		name = EVTOPTE_ADV_5
		custom_tooltip = { text = EVTOPTE_ADV_3_TT }
		
		trigger = {
			event_target:adventurer_target = {
				has_character_flag = peaceful_negotiation
			}
		}
		
		clr_character_flag = peaceful_negotiation

		ai_chance = {
			factor = 50
			modifier = { realm_levy_diff = { who = event_target:raiding_adventurer value = 1000 } factor = 1.3 }
			modifier = { realm_levy_diff = { who = event_target:raiding_adventurer value = 2500 } factor = 1.3 }
			modifier = { trait = brave factor = 2 }
			modifier = { trait = wroth factor = 1.5 }
			modifier = { trait = ambitious factor = 1.5 }
			modifier = { event_target:raiding_adventurer = { NOT = { has_character_flag = haggle_price } } factor = 5 }
			modifier = { event_target:selling_province = { holder_scope = { character = ROOT } } factor = 1.5 }
		}
	}

	after = {
		hidden_effect = {
			clr_character_flag = adventurer_unsafe_duchy_war
			clr_character_flag = adventurer_safe_duchy_war
			clr_character_flag = negotiating_with_adventurer
			event_target:raiding_adventurer = { clr_character_flag = haggle_price }
		}
	}
}

#Change religion etc. of settled adventurer
character_event = {
	id = ADV.20
	hide_window = yes
	is_triggered_only = yes
	trigger = {
		NOT = { liege = { religion = ROOT } }
	}

	immediate = { 
		random_list = {
			80 = {
				modifier = { trait = cynical factor = 5 }
				modifier = { trait = content factor = 5 }
				modifier = { trait = craven factor = 5 }
				liege = {
					ROOT = { religion = PREV }
					character_event = { id = ADV.21 days = 7 }
				}
				any_courtier = {
					limit = { is_landed = no }
					religion = ROOT
				}
			}
			20 = {
				modifier = { trait = zealous factor = 5 }
				#Does not convert
			}
		}
	}
}

letter_event = { # Religion flip notification event
	id = ADV.21
	desc = EVTDESC_ADV_21
	
	is_triggered_only = yes
	
	option = {	 
		name = EXCELLENT
	}
}


#Testing event for adventurer negotiation
#character_event = {
#	id = ADV.30
#	hide_window = yes
#	is_triggered_only = yes

#	immediate = {
#		random_list = {
#			10 = {
#				wealth = 300
#			}
#			10 = {
#				wealth = 400
#			}
#			10 = {
#				wealth = 500
#			}
#			10 = {
#				wealth = 60
#			}
#			10 = {
#				wealth = 70
#			}
#			10 = {
#				wealth = 250
#			}
#			10 = {
#				wealth = 300
#			}
#			10 = {
#				wealth = 150
#			}
#		}

#		random_independent_ruler = {
#			limit = {
#				NOT = { has_character_flag = negotiating_with_adventurer }
#				ai = no
#			
#			}
#			character_event = {
#				id = ADV.1
#			}
#		}
#	}
#}