﻿namespace = ppr_camp_events

# Purpose-specific events for the Pilgrims camp purpose (ppr_camp_purpose_pilgrims).
# Modelled on the vanilla camp purpose flavour events (ep3_laamp_flavour_ewan_events.txt):
# cooldowns are stored on the primary title so they survive succession.
#
# Camp events  (ppr_yearly_camp_events): 0001 - 0005
# Travel events (ppr_travel_events):     0006 - 0007

######################################################################
# 0001: Night Vigil (camp)
######################################################################
ppr_camp_events.0001 = {
	type = character_event
	title = ppr_camp_events.0001.t
	desc = ppr_camp_events.0001.desc
	theme = faith
	left_portrait = {
		character = root
		animation = prayer
	}
	right_portrait = {
		character = scope:vigil_follower
		animation = sick
	}
	override_background = { reference = ep3_camp_night }

	trigger = {
		is_adult = yes
		is_available_allow_travelling = yes
		is_location_valid_for_travel_event_on_land = yes
		primary_title = {
			NOT = { has_variable = had_ppr_camp_events_0001 }
		}
		has_realm_law = ppr_camp_purpose_pilgrims
		any_courtier = { ppr_camp_events_available_courtier_trigger = yes }
	}

	immediate = {
		primary_title = {
			set_variable = {
				name = had_ppr_camp_events_0001
				value = yes
				years = 6
			}
		}
		random_courtier = {
			limit = { ppr_camp_events_available_courtier_trigger = yes }
			weight = {
				base = 1
				modifier = {
					add = 5
					ppr_camp_events_frail_courtier_trigger = yes
				}
				modifier = {
					add = 2
					has_trait = zealous
				}
			}
			save_scope_as = vigil_follower
		}
	}

	# Keep the vigil until dawn.
	option = {
		name = ppr_camp_events.0001.a
		add_piety = medium_piety_gain
		if = { limit = { has_pam_dlc_trigger = yes } change_spiritual_fulfillment = minor_spiritual_fulfillment_value }
		add_character_modifier = {
			modifier = ppr_vigil_keeper_modifier
			years = 3
		}
		stress_impact = {
			zealous = minor_stress_impact_loss
			lazy = medium_stress_impact_gain
			cynical = medium_stress_impact_gain
			compassionate = minor_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_zeal = 1
				ai_compassion = -0.5
			}
		}
	}

	# Carry the follower to their tent myself.
	option = {
		name = ppr_camp_events.0001.b
		scope:vigil_follower = {
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 25
			}
		}
		add_piety = minor_piety_gain
		stress_impact = {
			compassionate = minor_stress_impact_loss
			callous = minor_stress_impact_gain
			sadistic = minor_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = { ai_compassion = 1 }
		}
	}

	# Enough - everyone to bed.
	option = {
		name = ppr_camp_events.0001.c
		add_piety = minor_piety_loss
		stress_impact = {
			base = minor_stress_impact_loss
			zealous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 20
			ai_value_modifier = {
				ai_zeal = -1
				ai_energy = -0.5
			}
		}
	}
}

######################################################################
# 0002: A Miracle in Camp? (camp)
######################################################################
ppr_camp_events.0002 = {
	type = character_event
	title = ppr_camp_events.0002.t
	desc = {
		desc = ppr_camp_events.0002.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = {
					any_character_artifact = { is_holy_relic_for = root.faith }
				}
				desc = ppr_camp_events.0002.desc.relic
			}
			desc = ppr_camp_events.0002.desc.shrine
		}
		desc = ppr_camp_events.0002.desc.outro
	}
	theme = faith
	left_portrait = {
		character = root
		animation = disbelief
	}
	right_portrait = {
		character = scope:healed_follower
		animation = happiness
	}
	override_background = { reference = ep3_camp }

	trigger = {
		is_adult = yes
		is_available_allow_travelling = yes
		is_location_valid_for_travel_event_on_land = yes
		primary_title = {
			NOT = { has_variable = had_ppr_camp_events_0002 }
		}
		has_realm_law = ppr_camp_purpose_pilgrims
		any_courtier = { ppr_camp_events_sick_courtier_trigger = yes }
	}

	immediate = {
		primary_title = {
			set_variable = {
				name = had_ppr_camp_events_0002
				value = yes
				years = 10
			}
		}
		random_courtier = {
			limit = { ppr_camp_events_sick_courtier_trigger = yes }
			save_scope_as = healed_follower
		}
		# The recovery itself has already happened when the event opens.
		scope:healed_follower = { remove_trait = ill }
		# Is there a physician in camp who could take the credit?
		if = {
			limit = {
				employs_court_position = court_physician_court_position
				any_court_position_holder = {
					type = court_physician_court_position
					NOT = { this = scope:healed_follower }
				}
			}
			random_court_position_holder = {
				type = court_physician_court_position
				limit = {
					NOT = { this = scope:healed_follower }
				}
				save_scope_as = camp_physician
			}
		}
	}

	# A miracle! Let the whole camp know.
	option = {
		name = ppr_camp_events.0002.a
		add_piety = medium_piety_gain
		if = { limit = { has_pam_dlc_trigger = yes } change_spiritual_fulfillment = medium_spiritual_fulfillment_value }
		scope:healed_follower = {
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 20
			}
		}
		random_list = {
			75 = {
				desc = ppr_camp_events.0002.a.believed
			}
			25 = {
				# A cynic's doubt shows on their face, and people notice.
				modifier = {
					add = 50
					has_trait = cynical
				}
				desc = ppr_camp_events.0002.a.doubted
				add_prestige = minor_prestige_loss
			}
		}
		stress_impact = {
			zealous = minor_stress_impact_loss
			cynical = medium_stress_impact_gain
			honest = minor_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_zeal = 1
				ai_rationality = -0.5
			}
		}
	}

	# Credit the camp physician.
	option = {
		name = ppr_camp_events.0002.b
		trigger = { exists = scope:camp_physician }
		scope:camp_physician = {
			add_opinion = {
				target = root
				modifier = respect_opinion
				opinion = 30
			}
		}
		add_learning_lifestyle_xp = minor_lifestyle_xp
		stress_impact = {
			zealous = minor_stress_impact_gain
			cynical = minor_stress_impact_loss
		}
		ai_chance = {
			base = 30
			ai_value_modifier = { ai_rationality = 1 }
		}
	}

	# Give thanks quietly, and say nothing more.
	option = {
		name = ppr_camp_events.0002.c
		add_piety = minor_piety_gain
		if = { limit = { has_pam_dlc_trigger = yes } change_spiritual_fulfillment = minor_spiritual_fulfillment_value }
		stress_impact = {
			humble = minor_stress_impact_loss
			arrogant = minor_stress_impact_gain
		}
		ai_chance = {
			base = 30
			ai_value_modifier = { ai_boldness = -0.5 }
		}
	}
}

######################################################################
# 0003: The Penitent (camp)
######################################################################
ppr_camp_events.0003 = {
	type = character_event
	title = ppr_camp_events.0003.t
	desc = ppr_camp_events.0003.desc
	theme = faith
	left_portrait = {
		character = root
		animation = thinking
	}
	right_portrait = {
		character = scope:penitent
		animation = beg
	}
	override_background = { reference = ep3_campfire }

	trigger = {
		is_ai = no # Avoid piling up unrecruited penitents for AI camps
		is_adult = yes
		is_available_allow_travelling = yes
		is_location_valid_for_travel_event_on_land = yes
		primary_title = {
			NOT = { has_variable = had_ppr_camp_events_0003 }
		}
		has_realm_law = ppr_camp_purpose_pilgrims
		# Don't bloat already crowded camps.
		any_courtier = { count <= 20 }
	}

	immediate = {
		primary_title = {
			set_variable = {
				name = had_ppr_camp_events_0003
				value = yes
				years = 8
			}
		}
		# Created here, as vanilla does, so that options only show add_courtier.
		create_character = {
			template = criminal_thief_bandit_character
			location = root.location
			culture = root.location.culture
			faith = root.faith
			rite = root.rite
			save_scope_as = penitent
		}
		hidden_effect = {
			scope:penitent = { add_character_flag = peasant_outfit }
		}
		location.county = { save_scope_as = current_county }
	}

	# Walk with us, and be forgiven.
	option = {
		name = ppr_camp_events.0003.a
		ppr_camp_events_recruit_effect = {
			CHARACTER = scope:penitent
			OPINION = 40
		}
		add_piety = minor_piety_gain
		stress_impact = {
			forgiving = minor_stress_impact_loss
			compassionate = minor_stress_impact_loss
			paranoid = minor_stress_impact_gain
			vengeful = minor_stress_impact_gain
		}
		ai_chance = {
			base = 40
			ai_value_modifier = {
				ai_compassion = 1
				ai_vengefulness = -1
			}
		}
	}

	# Look into their eyes for the lie.
	option = {
		name = ppr_camp_events.0003.b
		duel = {
			skill = intrigue
			target = scope:penitent
			# They are sincere.
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				min = 5
				desc = ppr_camp_events.0003.b.success
				send_interface_toast = {
					title = ppr_camp_events.0003.b.success
					left_icon = scope:penitent
					ppr_camp_events_recruit_effect = {
						CHARACTER = scope:penitent
						OPINION = 20
					}
					add_piety = medium_piety_gain
				}
			}
			# A thief's tears.
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				min = 5
				desc = ppr_camp_events.0003.b.failure
				send_interface_toast = {
					title = ppr_camp_events.0003.b.failure
					left_icon = scope:penitent
					remove_short_term_gold = tiny_gold_laamps_value
					add_stress = minor_stress_gain
				}
			}
		}
		ai_chance = {
			base = 30
			ai_value_modifier = { ai_rationality = 1 }
		}
	}

	# The road is not a refuge for thieves.
	option = {
		name = ppr_camp_events.0003.c
		stress_impact = {
			compassionate = minor_stress_impact_gain
			forgiving = minor_stress_impact_gain
			just = minor_stress_impact_loss
		}
		ai_chance = {
			base = 20
			ai_value_modifier = {
				ai_vengefulness = 1
				ai_compassion = -1
			}
		}
	}
}

######################################################################
# 0004: Pious Quarrel (camp)
######################################################################
ppr_camp_events.0004 = {
	type = character_event
	title = ppr_camp_events.0004.t
	desc = ppr_camp_events.0004.desc
	theme = faith
	left_portrait = {
		character = scope:quarrel_first
		animation = debating
	}
	right_portrait = {
		character = scope:quarrel_second
		animation = anger
	}
	lower_center_portrait = root
	override_background = { reference = ep3_campfire }

	trigger = {
		is_adult = yes
		is_available_allow_travelling = yes
		is_location_valid_for_travel_event_on_land = yes
		primary_title = {
			NOT = { has_variable = had_ppr_camp_events_0004 }
		}
		has_realm_law = ppr_camp_purpose_pilgrims
		any_courtier = {
			count >= 2
			ppr_camp_events_learned_courtier_trigger = yes
		}
	}

	immediate = {
		primary_title = {
			set_variable = {
				name = had_ppr_camp_events_0004
				value = yes
				years = 6
			}
		}
		ordered_courtier = {
			limit = { ppr_camp_events_learned_courtier_trigger = yes }
			order_by = learning
			save_scope_as = quarrel_first
		}
		random_courtier = {
			limit = {
				ppr_camp_events_learned_courtier_trigger = yes
				this != scope:quarrel_first
			}
			save_scope_as = quarrel_second
		}
	}

	# Side with the first.
	option = {
		name = ppr_camp_events.0004.a
		ppr_camp_events_side_in_quarrel_effect = {
			WINNER = scope:quarrel_first
			LOSER = scope:quarrel_second
		}
		ai_chance = {
			base = 30
			opinion_modifier = {
				opinion_target = scope:quarrel_first
				multiplier = 0.5
			}
		}
	}

	# Side with the second.
	option = {
		name = ppr_camp_events.0004.b
		ppr_camp_events_side_in_quarrel_effect = {
			WINNER = scope:quarrel_second
			LOSER = scope:quarrel_first
		}
		ai_chance = {
			base = 30
			opinion_modifier = {
				opinion_target = scope:quarrel_second
				multiplier = 0.5
			}
		}
	}

	# Settle the question myself, before the whole camp.
	option = {
		name = ppr_camp_events.0004.c
		duel = {
			skill = learning
			target = scope:quarrel_first
			# Victory!
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				min = 5
				desc = ppr_camp_events.0004.c.success
				send_interface_toast = {
					title = ppr_camp_events.0004.c.success
					left_icon = scope:quarrel_first
					right_icon = scope:quarrel_second
					add_piety = medium_piety_gain
					add_learning_lifestyle_xp = minor_lifestyle_xp
					scope:quarrel_first = {
						add_opinion = {
							target = root
							modifier = respect_opinion
							opinion = 15
						}
					}
					scope:quarrel_second = {
						add_opinion = {
							target = root
							modifier = respect_opinion
							opinion = 15
						}
					}
				}
			}
			# Defeat.
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				min = 5
				desc = ppr_camp_events.0004.c.failure
				send_interface_toast = {
					title = ppr_camp_events.0004.c.failure
					left_icon = scope:quarrel_first
					right_icon = scope:quarrel_second
					add_prestige = minor_prestige_loss
					add_stress = minor_stress_gain
				}
			}
		}
		ai_chance = {
			base = 20
			ai_value_modifier = { ai_boldness = 1 }
		}
	}

	# Hold your tongues, both of you!
	option = {
		name = ppr_camp_events.0004.d
		scope:quarrel_first = {
			add_opinion = {
				target = root
				modifier = annoyed_opinion
				opinion = -10
			}
		}
		scope:quarrel_second = {
			add_opinion = {
				target = root
				modifier = annoyed_opinion
				opinion = -10
			}
		}
		stress_impact = {
			wrathful = minor_stress_impact_loss
			patient = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = { ai_sociability = -1 }
		}
	}
}

######################################################################
# 0005: The Relic Peddler (camp, in a settlement)
######################################################################
ppr_camp_events.0005 = {
	type = character_event
	title = ppr_camp_events.0005.t
	desc = ppr_camp_events.0005.desc
	theme = faith
	left_portrait = {
		character = root
		animation = interested
	}
	right_portrait = {
		character = scope:relic_peddler
		animation = admiration
	}
	override_background = { reference = market_scope }

	trigger = {
		# Only players need the peddler; avoids creating characters for the AI.
		is_ai = no
		is_adult = yes
		is_available_allow_travelling = yes
		is_location_valid_for_travel_event_on_land = yes
		primary_title = {
			NOT = { has_variable = had_ppr_camp_events_0005 }
		}
		has_realm_law = ppr_camp_purpose_pilgrims
		# There must be a market nearby.
		location = {
			has_holding = yes
			county = { development_level >= 10 }
		}
	}

	immediate = {
		primary_title = {
			set_variable = {
				name = had_ppr_camp_events_0005
				value = yes
				years = 8
			}
		}
		create_character = {
			template = merchant_template
			location = root.location
			culture = root.location.culture
			faith = root.location.faith
			rite = root.location.rite
			save_scope_as = relic_peddler
		}
		location.county = { save_scope_as = current_county }
		location = { save_scope_as = background_market_scope }
	}

	# Buy the relic.
	option = {
		name = ppr_camp_events.0005.a
		trigger = { short_term_gold >= minor_gold_laamps_value }
		remove_short_term_gold = minor_gold_laamps_value
		add_piety = minor_piety_gain
		if = { limit = { has_pam_dlc_trigger = yes } change_spiritual_fulfillment = minor_spiritual_fulfillment_value }
		stress_impact = {
			greedy = minor_stress_impact_gain
			cynical = minor_stress_impact_gain
			zealous = minor_stress_impact_loss
		}
		ai_chance = {
			base = 20
			ai_value_modifier = { ai_zeal = 1 }
		}
	}

	# Learning duel: examine the relic closely.
	option = {
		name = ppr_camp_events.0005.b
		duel = {
			skill = learning
			target = scope:relic_peddler
			# The fake is exposed.
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				min = 5
				desc = ppr_camp_events.0005.b.success
				send_interface_toast = {
					title = ppr_camp_events.0005.b.success
					left_icon = scope:relic_peddler
					add_piety = medium_piety_gain
					add_learning_lifestyle_xp = minor_lifestyle_xp
				}
			}
			# Fooled.
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				min = 5
				desc = ppr_camp_events.0005.b.failure
				send_interface_toast = {
					title = ppr_camp_events.0005.b.failure
					left_icon = scope:relic_peddler
					add_prestige = minor_prestige_loss
				}
			}
		}
		ai_chance = {
			base = 30
			ai_value_modifier = { ai_rationality = 1 }
		}
	}

	# Intrigue duel: watch the peddler, not the relic.
	option = {
		name = ppr_camp_events.0005.c
		duel = {
			skill = intrigue
			target = scope:relic_peddler
			# Caught red-handed, and made to pay.
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				min = 5
				desc = ppr_camp_events.0005.c.success
				send_interface_toast = {
					title = ppr_camp_events.0005.c.success
					left_icon = scope:relic_peddler
					scope:relic_peddler = {
						pay_short_term_gold = {
							target = root
							gold = tiny_gold_laamps_value
						}
						# Don't actually charge the peddler, as vanilla does.
						hidden_effect = { add_gold = tiny_gold_laamps_value }
					}
					add_piety = minor_piety_gain
				}
			}
			# He slips away into the crowd.
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				min = 5
				desc = ppr_camp_events.0005.c.failure
				send_interface_toast = {
					title = ppr_camp_events.0005.c.failure
					left_icon = scope:relic_peddler
					add_stress = minor_stress_gain
				}
			}
		}
		ai_chance = {
			base = 20
			ai_value_modifier = { ai_boldness = 1 }
		}
	}

	# Walk on.
	option = {
		name = ppr_camp_events.0005.d
		stress_impact = {
			zealous = minor_stress_impact_gain
		}
		ai_chance = {
			base = 20
			ai_value_modifier = { ai_energy = -1 }
		}
	}
}

######################################################################
# 0006: Flagellants on the Road (travel)
######################################################################
ppr_camp_events.0006 = {
	type = character_event
	title = ppr_camp_events.0006.t
	desc = ppr_camp_events.0006.desc
	theme = travel
	left_portrait = {
		character = root
		animation = shock
	}
	right_portrait = {
		character = scope:flagellant_leader
		animation = pain
	}
	override_background = { reference = terrain }

	trigger = {
		is_available_travelling_adult = yes
		is_location_valid_for_travel_event_on_land = yes
		primary_title = {
			NOT = { has_variable = had_ppr_camp_events_0006 }
		}
		has_realm_law = ppr_camp_purpose_pilgrims
	}

	immediate = {
		primary_title = {
			set_variable = {
				name = had_ppr_camp_events_0006
				value = yes
				years = 8
			}
		}
		create_character = {
			template = generic_peasant_character
			location = root.location
			culture = root.location.culture
			faith = root.faith
			rite = root.rite
			save_scope_as = flagellant_leader
		}
		hidden_effect = {
			scope:flagellant_leader = {
				add_trait = flagellant
				add_character_flag = peasant_outfit
			}
		}
	}

	# Take up the scourge and walk with them.
	option = {
		name = ppr_camp_events.0006.a
		add_piety = medium_piety_gain
		if = { limit = { has_pam_dlc_trigger = yes } change_spiritual_fulfillment = medium_spiritual_fulfillment_value }
		add_character_modifier = {
			modifier = ppr_scourged_back_modifier
			years = 1
		}
		stress_impact = {
			zealous = medium_stress_impact_loss
			cynical = medium_stress_impact_gain
			craven = minor_stress_impact_gain
			compassionate = minor_stress_impact_gain
		}
		ai_chance = {
			base = 20
			ai_value_modifier = {
				ai_zeal = 1.5
				ai_boldness = 0.5
			}
		}
	}

	# Share our provisions with them.
	option = {
		name = ppr_camp_events.0006.b
		trigger = {
			domicile ?= { provisions >= minor_provisions_value }
		}
		domicile = { change_provisions = minor_provisions_loss }
		add_piety = minor_piety_gain
		stress_impact = {
			compassionate = minor_stress_impact_loss
			greedy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 40
			ai_value_modifier = {
				ai_compassion = 1
				ai_greed = -0.5
			}
		}
	}

	# Clear the road!
	option = {
		name = ppr_camp_events.0006.c
		add_piety = minor_piety_loss
		stress_impact = {
			compassionate = medium_stress_impact_gain
			zealous = medium_stress_impact_gain
			cynical = minor_stress_impact_loss
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_zeal = -1
				ai_compassion = -1
			}
		}
	}
}

######################################################################
# 0007: The Hermit (travel, in forests or mountains)
######################################################################
ppr_camp_events.0007 = {
	type = character_event
	title = ppr_camp_events.0007.t
	desc = ppr_camp_events.0007.desc
	theme = travel
	left_portrait = {
		character = root
		animation = interested
	}
	right_portrait = {
		character = scope:hermit
		animation = lantern
	}
	override_background = { reference = wilderness }

	trigger = {
		is_available_travelling_adult = yes
		is_location_valid_for_travel_event_on_land = yes
		primary_title = {
			NOT = { has_variable = had_ppr_camp_events_0007 }
		}
		has_realm_law = ppr_camp_purpose_pilgrims
		location = {
			OR = {
				is_wooded_trigger = yes
				is_mountainous_trigger = yes
			}
		}
	}

	immediate = {
		primary_title = {
			set_variable = {
				name = had_ppr_camp_events_0007
				value = yes
				years = 10
			}
		}
		create_character = {
			template = garden_hermit_character
			location = root.location
			culture = root.location.county.culture
			faith = root.faith
			rite = root.rite
			dynasty = none
			save_scope_as = hermit
		}
		hidden_effect = {
			scope:hermit = { add_character_flag = peasant_outfit }
		}
	}

	# Ask for counsel.
	option = {
		name = ppr_camp_events.0007.a
		add_learning_lifestyle_xp = medium_lifestyle_xp
		add_character_modifier = {
			modifier = ppr_hermits_counsel_modifier
			years = 5
		}
		stress_impact = {
			cynical = minor_stress_impact_gain
			arrogant = minor_stress_impact_gain
		}
		ai_chance = {
			base = 40
			ai_value_modifier = { ai_rationality = 1 }
		}
	}

	# Sit with him in silence.
	option = {
		name = ppr_camp_events.0007.b
		add_stress = medium_stress_loss
		if = { limit = { has_pam_dlc_trigger = yes } change_spiritual_fulfillment = minor_spiritual_fulfillment_value }
		stress_impact = {
			gregarious = minor_stress_impact_gain
			impatient = minor_stress_impact_gain
		}
		ai_chance = {
			base = 40
			ai_value_modifier = { ai_sociability = -1 }
		}
	}

	# Invite him to join the camp.
	option = {
		name = ppr_camp_events.0007.c
		trigger = {
			any_courtier = { count <= 20 }
		}
		ppr_camp_events_recruit_effect = {
			CHARACTER = scope:hermit
			OPINION = 20
		}
		add_piety = minor_piety_gain
		stress_impact = {
			paranoid = minor_stress_impact_gain
			shy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 20
			ai_value_modifier = { ai_sociability = 1 }
		}
	}
}
