﻿namespace = ep2_locale_events

# You flex to impress someone
# by Veronica Pazos

scripted_trigger ep2_locale_events_5020_valid_lover = {
	this != root
	is_ai = yes
	is_alive = yes
	OR = {
		has_relation_lover = root
		is_spouse_of = root
	}
	activity_is_valid_tournament_contestant = no
}

ep2_locale_events.5020 = {
	type = activity_event
	title = ep2_locale_events.5020.t
	desc = ep2_locale_events.5020.desc
	theme = tournament_grounds
	left_portrait = {
		character = root
		animation = marshal
	}
	right_portrait = {
		character = scope:impressed_lover
		animation = flirtation
	}
	lower_center_portrait = scope:impressed_rival
	cooldown = { years = 1 }

	trigger = {
		activity_is_competing_trigger = yes
		scope:activity = { 
			has_active_locale = tournament_locale_tournament_grounds
			any_attending_character = { # lover
				ep2_locale_events_5020_valid_lover = yes
			}
			any_guest_subset_current_phase = { # rival
				name = contestant
				is_ai = yes
				is_healthy = yes
				this != root
			}
		}
		activity_tournament_prowess_contest_trigger = yes
	}

	immediate = {
		if = {
			limit = {
				has_activity_intent = woo_attendee_intent
				intent_target ?= { is_alive = yes }
			}
			intent_target = { save_scope_as = impressed_lover }
		}
		else = {
			scope:activity = {
				random_attending_character = {
					limit = { ep2_locale_events_5020_valid_lover = yes }
					weight = {
						base = 1
						modifier = {
							add = 100
							is_spouse_of = root
						}
						modifier = {
							add = 2
							has_relation_soulmate = root
						}
					}
					save_scope_as = impressed_lover
				}
			}
		}
		scope:activity = {
			random_guest_subset_current_phase = {
				name = contestant
				limit = {
					is_ai = yes
					is_healthy = yes
					this != root
					activity_is_competing_trigger = yes
				}
				weight = {
					base = 1
					modifier = {
						add = 100
						has_relation_rival = root
					}
					activity_recurring_character_weight_modifier = { VALUE = 50 }
				}		
				save_scope_as = impressed_rival
			}
		}
	}
	
	weight_multiplier = {
		base = 1
		modifier = {
			factor = 2
			OR = {
				has_activity_intent = win_contest_intent
				has_activity_intent = woo_attendee_intent
			}
		}
	}

	# Impress your lover
	option = {
		name = ep2_locale_events.5020.a 
		duel = {
			skill = prowess
			value = average_skill_rating
			50 = {
				desc = ep2_locale_events.5020.a.success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
				}
				send_interface_toast = {
					title = ep2_locale_events.5020.a.success
					left_icon = root
					right_icon = scope:impressed_lover
					if = {
						limit = {
							NOT = { has_relation_wedding_good_fertility = scope:impressed_lover }
						}
						custom_tooltip = {
							text = ep2_locale_events.5020.a.success.tt
							set_relation_wedding_good_fertility = scope:impressed_lover
						}
					}
					else = {
						add_character_modifier = { 
							modifier = tournament_ground_flexing
							years = 10
						}
					}
				}
			}
			50 = {
				desc = ep2_locale_events.5020.a.failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
				}
				send_interface_toast = {
					title = ep2_locale_events.5020.a.failure
					left_icon = root
					right_icon = scope:impressed_lover
				}
			}
		}
		stress_impact = {
			humble = medium_stress_impact_gain
			callous = medium_stress_impact_gain
			vengeful = medium_stress_impact_gain
			sadistic = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = humble
					has_trait = callous
					has_trait = vengeful
					has_trait = sadistic
				}
			}
		}
	}

	# Impress your rival
	option = {
		name = ep2_locale_events.5020.b
		duel = {
			skill = prowess
			target = scope:impressed_rival
			50 = {
				desc = ep2_locale_events.5020.b.success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
				}
				send_interface_toast = {
					title = ep2_locale_events.5020.b.success
					left_icon = root
					right_icon = scope:impressed_rival
					scope:impressed_rival = {
						activity_tournament_change_contestant_score_effect = { SCORE = decrease_major }
					}
				}
			}
			50 = {
				desc = ep2_locale_events.5020.b.failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
				}
				send_interface_toast = {
					title = ep2_locale_events.5020.b.failure
					left_icon = root
					right_icon = scope:impressed_rival
					add_prestige = minor_prestige_loss
				}
			}
		}
		stress_impact = {
			calm = medium_stress_impact_gain
			humble = medium_stress_impact_gain
			lustful = medium_stress_impact_gain
			forgiving = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = humble
					has_trait = calm
					has_trait = forgiving
					has_trait = lustful
				}
			}
		}
	}
	
	# I'm doing this for MYSELF
	option = {
		name = ep2_locale_events.5020.c
		trigger = { activity_is_competing_trigger = yes }
		activity_tournament_change_contestant_score_effect = { SCORE = increase_minor }
		stress_impact = {
			arrogant = medium_stress_impact_gain
			vengeful = medium_stress_impact_gain
			lustful = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = arrogant
					has_trait = vengeful
					has_trait = lustful
				}
			}
		}
	}
}

# Two moons appear in the sky, based on the accounts of John of Worcester 1106
# by Veronica Pazos

scripted_effect ep2_locale_events_1520_superstitious_effect = {
	if = {
		limit = {
			NOT = { has_character_modifier = bp1_superstition_modifier }
			is_ai = no
		}
		random = {
			chance = 50
			send_interface_toast = {
				title = ep2_locale_events.1520.superstitious
				left_icon = root
				add_character_modifier = bp1_superstition_modifier
			}
		}
	}
}

ep2_locale_events.1520 = {
	type = activity_event
	title = ep2_locale_events.1520.t
	desc = ep2_locale_events.1520.desc
	theme = tournament_locale_temple
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = { has_trait = cynical }
			animation = disbelief
		}
		animation = admiration
	}
	right_portrait = {
		character = scope:tournament_priest
		animation = shock
	}
	cooldown = { years = 5 }
	override_background = { reference = temple }

	trigger = {
		scope:activity = { 
			has_active_locale = tournament_locale_religious_building
		}
		NOT = { has_variable = had_1520_var } #once in a lifetime
	}

	immediate = {
		set_variable = had_1520_var
		if = {
			limit = {
				scope:activity = {
					exists = var:tournament_priest
					var:tournament_priest = { is_alive = yes }
				}
			}
			scope:activity = {
				var:tournament_priest = { save_scope_as = tournament_priest }
			}
		}
		else = {
			scope:activity = {
				random_attending_character = {
					limit = {
						this != root
						is_ai = yes
						is_adult = yes
						NOT = { has_trait = cynical }
					}
					weight = {
						base = 1
						modifier = {
							add = 5
							has_trait = zealous
						}
						modifier = {
							add = 5
							has_trait = paranoid
						}
					}
					save_scope_as = tournament_priest
				}
			}					
		}
	}
	
	weight_multiplier = {
		base = 1
		modifier = {
			factor = 2
			OR = {
				has_trait = paranoid
				has_trait = zealous
			}
		}
	}

	# It means that I'll win
	option = {
		name = ep2_locale_events.1520.a 
		if = {
			limit = { activity_is_competing_trigger = yes }
			activity_tournament_change_contestant_score_effect = { SCORE = increase_major }
		}
		else = {
			add_martial_lifestyle_xp = major_lifestyle_xp
		}
		ep2_locale_events_1520_superstitious_effect = yes
		stress_impact = {
			humble = medium_stress_impact_gain
			cynical = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 2
				OR = {
					has_lifestyle = martial_lifestyle
					has_activity_intent = win_contest_intent
				}
			}
			modifier = {
				factor = 0
				OR = {
					has_trait = humble
					has_trait = cynical
				}
			}
		}
	}

	# It means that I'm gonna get money - round as a coin!
	option = {
		name = ep2_locale_events.1520.b
		add_stewardship_lifestyle_xp = major_lifestyle_xp
		ep2_locale_events_1520_superstitious_effect = yes
		stress_impact = {
			generous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 2
				OR = {
					has_trait = greedy
					has_trait = avaricious
					has_lifestyle = stewardship_lifestyle
				}
			}
			modifier = {
				factor = 0
				has_trait = generous
			}
		}
	}
	
	# It's two beheaded people
	option = {
		name = ep2_locale_events.1520.c 
		add_intrigue_lifestyle_xp = major_lifestyle_xp
		ep2_locale_events_1520_superstitious_effect = yes
		stress_impact = {
			compassionate = medium_stress_impact_gain
			gregarious = medium_stress_impact_gain
			calm = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 2
				OR = {
					has_trait = callous
					has_trait = sadistic
					has_lifestyle = intrigue_lifestyle
				}
			}
			modifier = {
				factor = 0
				OR = {
					has_trait = compassionate
					has_trait = gregarious
					has_trait = calm
				}
			}
		}
	}
	
	# I know what this is
	option = {
		name = ep2_locale_events.1520.d
		trigger = {
			learning >= high_skill_rating 
		}
		show_as_unavailable = {
			learning < high_skill_rating
		}
		add_character_modifier = tournament_astronomy_modifier #forever
		stress_impact = {
			ambitious = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 2
				learning >= high_skill_rating 
			}
			modifier = {
				factor = 0
				has_trait = ambitious
			}
		}
	}
	
	# It means nothing 
	option = {
		name = ep2_locale_events.1520.e
		stress_impact = {
			base = medium_stress_impact_loss
			cynical = major_stress_impact_loss
			paranoid = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 2
				has_trait = cynical
			}
			modifier = {
				factor = 0
				has_trait = paranoid
			}
		}
	}
}

# People at the camp are falling ill
# by Veronica Pazos

ep2_locale_events.3010 = {
	type = activity_event
	title = ep2_locale_events.3010.t
	desc = ep2_locale_events.3010.desc
	theme = tournament_locale_camp
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = {
				OR = {
					has_trait = cynical
					has_trait = callous
					has_trait = sadistic
				}
			}
			animation = schadenfreude
		}
		animation = disbelief
	}
	right_portrait = {
		character = scope:alerted_physician
		animation = disgust
	}
	cooldown = { years = 1 }
	override_background = { reference = army_camp }

	trigger = {
		scope:activity = { 
			has_active_locale = tournament_locale_visitor_camp
			any_attending_character = {
				this != root
				activity_is_valid_tournament_contestant = yes
				count >= 2 #there's someone to investigate, and someone to approve in the follow up
			}
		}
	}

	immediate = {
		if = {
			limit = {
				scope:activity = {
					any_attending_character = {
						this != ROOT
						has_court_position = court_physician_court_position
					}
				}
			}
			scope:activity = {
				random_attending_character = {
					limit = {
						this != ROOT
						has_court_position = court_physician_court_position
					}
					save_scope_as = alerted_physician
				}
			}
		}
		else = {
			scope:activity = {
				ordered_attending_character = {
					limit = {
						this != root
					}
					order_by = {
						value = learning
						if = {
							limit = {
								has_trait = lifestyle_physician
							}
							add = 15
						}
						if = {
							limit = {
								has_trait = whole_of_body
							}
							add = 10
						}
						if = {
							limit = {
								has_trait = lifestyle_herbalist
							}
							add = 5
						}
					}
					save_scope_as = alerted_physician
				}
			}
		}
	}
	
	weight_multiplier = {
		base = 1
		modifier = {
			factor = 2
			scope:activity = {
				any_attending_character = {
					this != ROOT
					has_court_position = court_physician_court_position
				}
			}
		}
	}

	# There must be an explanation
	option = {
		name = ep2_locale_events.3010.a 
		scope:alerted_physician = {
			duel = {
				skill = learning
				value = average_skill_rating
				50 = {
					desc = ep2_locale_events.3010.a.success
					compare_modifier = {
						value = scope:duel_value
						multiplier = 3.5
					}
					root = {
						send_interface_toast = {
							title = ep2_locale_events.3010.a.success
							right_icon = scope:alerted_physician
							custom_tooltip = {
								text = ep2_locale_events.3010.a.success.tt
								trigger_event = ep2_locale_events.3011
							}
						}
					}
				}
				50 = {
					desc = ep2_locale_events.3010.a.failure
					compare_modifier = {
						value = scope:duel_value
						multiplier = -3.5
					}
					root = {
						send_interface_toast = {
							title = ep2_locale_events.3010.a.failure
							right_icon = scope:alerted_physician
						}
					}
				}
			}
		}
		stress_impact = {
			callous = medium_stress_impact_gain
			sadistic = medium_stress_impact_gain
			paranoid = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = callous
					has_trait = sadistic
					has_trait = paranoid
				}
			}
		}
	}

	# It's a curse!
	option = {
		name = ep2_locale_events.3010.b
		flavor = ep2_locale_events.3010.b.flavor
		if = {
			limit = { activity_is_competing_trigger = yes }
			activity_tournament_change_contestant_score_effect = { SCORE = increase_medium }
		}
		else = {
			add_character_modifier = {
				modifier = tournament_not_cursed_modifier
				years = 10
			}
		}
		add_piety = minor_piety_loss
		stress_impact = {
			cynical = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = cynical
					has_trait = compassionate
				}
			}
			modifier = {
				factor = 0.5
				OR = {
					has_trait = calm
					has_trait = paranoid
				}
			}
		}
	}
	
	# If paranoid you think someone is sabotaging the tournament and coming for you
	option = {
		name = ep2_locale_events.3010.c 
		trigger = { has_trait = paranoid }
		add_character_modifier = {
			modifier = tournament_not_cursed_modifier
			years = 10
		}
		stress_impact = {
			paranoid = major_stress_impact_loss #you caught them
			calm = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = calm
					has_trait = cynical
				}
			}
		}
	}
	
	# Well, not my problem
	option = {
		name = ep2_locale_events.3010.d
		if = {
			limit = {
				OR = {
					has_trait = callous
					has_trait = sadistic
				}
			}
			add_dread = minor_dread_gain
		}
		stress_impact = {
			base = minor_stress_impact_loss
			callous = major_stress_impact_loss
			sadistic = major_stress_impact_loss
			gregarious = medium_stress_impact_gain
			compassionate = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = compassionate
					has_trait = gregarious
				}
			}
		}
	}
}

#You discover people dumping their waste into the stream

scripted_effect ep2_locale_events_3011_warning_effect = {
	if = {
		limit = {
			scope:activity = {
				any_attending_character = {
					this != root
					activity_is_valid_tournament_contestant = yes
				}
			}
		}
		scope:activity = {
			random_attending_character = {
				limit = {
					this != root
					activity_is_valid_tournament_contestant = yes
				}
				weight = {
					base = 1
					modifier = {
						add = 100
						is_powerful_vassal_of = root
					}
					modifier = {
						add = 50
						is_vassal_of = root
					}
				}
				add_opinion = {
					target = root
					modifier = grateful_opinion
					opinion = 25
				}
				save_scope_as = vassal_1
			}
		}
	}
	if = {
		limit = {
			scope:activity = {
				any_attending_character = {
					this != root
					activity_is_valid_tournament_contestant = yes
					this != scope:vassal_1
				}
			}
		}
		scope:activity = {
			random_attending_character = {
				limit = {
					this != root
					activity_is_valid_tournament_contestant = yes
					this != scope:vassal_1
				}
				weight = {
					base = 1
					modifier = {
						add = 100
						is_powerful_vassal_of = root
					}
					modifier = {
						add = 50
						is_vassal_of = root
					}
				}
				add_opinion = {
					target = root
					modifier = grateful_opinion
					opinion = 25
				}
				save_scope_as = vassal_2
			}
		}
	}
	if = {
		limit = {
			scope:activity = {
				any_attending_character = {
					this != root
					activity_is_valid_tournament_contestant = yes
					this != scope:vassal_1
					this != scope:vassal_2
				}
			}
		}
		scope:activity = {
			random_attending_character = {
				limit = {
					this != root
					activity_is_valid_tournament_contestant = yes
					this != scope:vassal_1
					this != scope:vassal_2
				}
				weight = {
					base = 1
					modifier = {
						add = 100
						is_powerful_vassal_of = root
					}
					modifier = {
						add = 50
						is_vassal_of = root
					}
				}
				add_opinion = {
					target = root
					modifier = grateful_opinion
					opinion = 25
				}
				save_scope_as = vassal_3
			}
		}
	}
}

ep2_locale_events.3011 = {
	type = activity_event
	title = ep2_locale_events.3011.t
	desc = ep2_locale_events.3011.desc
	theme = tournament_locale_camp
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = {
				OR = {
					has_trait = callous
					has_trait = sadistic
				}
			}
			animation = schadenfreude
		}
		animation = disgust
	}
	right_portrait = {
		character = scope:alerted_physician
		animation = laugh
	}
	override_background = { reference = army_camp }

	# Tell them to stop
	option = {
		name = ep2_locale_events.3011.a 
		ep2_locale_events_3011_warning_effect = yes
		stress_impact = {
			ambitious = medium_stress_impact_gain
			callous = medium_stress_impact_gain
			sadistic = medium_stress_impact_gain
			just = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = ambitious
					has_trait = callous
					has_trait = sadistic
					has_trait = just
				}
			}
		}
	}

	# Let them go on so you can win
	option = {
		name = {
			trigger = {
				scope:activity = {
					any_guest_subset_current_phase = { #participating
						name = contestant
						this = root					
					}
				}
			}
			text = ep2_locale_events.3011.b.contestant
		}
		name = {
			trigger = { exists = scope:contest_champion }
			text = ep2_locale_events.3011.b.champion
		}
		name = {
			trigger = {
				scope:activity = {
					NOT = {
						any_guest_subset_current_phase = {
							name = contestant
							this = root					
						}
					}
				}
				NOT = { exists = scope:contest_champion }
			}
			text = ep2_locale_events.3011.b
		}
		if = {
			limit = { activity_is_competing_trigger = yes }
			activity_tournament_change_contestant_score_effect = { SCORE = increase_medium }
		}
		else_if = {
			limit = {
				exists = scope:contest_champion
				scope:contest_champion = { activity_is_competing_trigger = yes }
			}
			scope:contest_champion = {
				activity_tournament_change_contestant_score_effect = { SCORE = increase_medium }
			}
		}
		else = {
			if = {
				limit = { has_lifestyle = intrigue_lifestyle }
				add_intrigue_lifestyle_xp = medium_lifestyle_xp
			}
			add_character_modifier = {
				modifier = tournament_not_cursed_modifier
				years = 20
			}
		}			
		stress_impact = {
			compassionate = medium_stress_impact_gain
			gregarious = medium_stress_impact_gain
			ambitious = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = compassionate
					has_trait = gregarious
					has_trait = ambitious
				}
			}
			modifier = {
				factor = 1.5
				has_trait = arrogant
			}
		}
	}
}

# Do you wanna buy new horseshoes?
# by Veronica Pazos

ep2_locale_events.3510 = {
	type = activity_event
	title = ep2_locale_events.3510.t
	desc = ep2_locale_events.3510.desc
	theme = tournament_locale_forge
	left_portrait = {
		character = root
		animation = thinking
	}
	right_portrait = {
		character = scope:farrier
		animation = marshal
	}
	artifact = {
		target = scope:horseshoe_artifact
		position = lower_center_portrait
	}
	cooldown = { years = 1 }
	override_background = { reference = armory }

	trigger = {
		scope:activity = { 
			has_active_locale = tournament_locale_artisans
			OR = {
				has_current_phase = tournament_phase_joust
				has_current_phase = tournament_phase_melee
				has_current_phase = tournament_phase_horse_race
			}
			exists = var:tournament_farrier
			var:tournament_farrier = { is_alive = yes }
		}
	}

	immediate = {
		scope:activity = {
			var:tournament_farrier = { save_scope_as = farrier }
		}
		hidden_effect = {
			scope:farrier = {
				create_artifact = {
					name = good_luck_horseshoe_artifact
					description = good_luck_horseshoe_artifact_desc
					type = miscellaneous
					visuals = small_box
					modifier = artifact_stress_gain_2_modifier
					save_scope_as = horseshoe_artifact
				}
			}
		}
	}
	
	weight_multiplier = {
		base = 1
		modifier = {
			factor = 2
			scope:activity = {
				any_guest_subset_current_phase = { #you're participating
					name = contestant
					this = root					
				}
			}
		}
	}

	# Buy them for you
	option = {
		name = ep2_locale_events.3510.a 
		if = {
			limit = { activity_is_competing_trigger = yes }
			activity_tournament_change_contestant_score_effect = { SCORE = increase_major }
		}
		else = {
			add_martial_lifestyle_xp = medium_lifestyle_xp
			if = {
				limit = { is_ai = no }
				random_list = {
					10 = {
						send_interface_toast = {
							title = ep2_locale_events.3510.a.prowess
							left_icon = root
							add_prowess_skill = 1
						}
					}
					5 = {
						send_interface_toast = {
							title = ep2_locale_events.3510.a.martial
							left_icon = root
							add_martial_skill = 1
						}
					}
					10 = {
						send_interface_toast = {
							title = ep2_locale_events.3510.a.prestige
							left_icon = root
							add_prestige = minor_prestige_gain
						}
					}
				}
			}
		}
		pay_short_term_gold = {
			target = scope:farrier
			gold = {
				value = minor_gold_value
				max = 15
			}
		}
		stress_impact = {
			humble = medium_stress_impact_gain
			greedy = medium_stress_impact_gain
			generous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = humble
					has_trait = greedy
					has_trait = generous
				}
			}
		}
	}

	# Buy them for your knights
	option = {
		name = ep2_locale_events.3510.b
		add_character_modifier = {
			modifier = tournament_new_horseshoes_modifier
			years = 20
		}
		every_active_accolade = {
			custom = custom.every_acclaimed_knight
			add_glory = minor_glory_gain
		}
		if = {
			limit = { activity_is_competing_trigger = yes }
			activity_tournament_change_contestant_score_effect = { SCORE = decrease_medium }
		}
		pay_short_term_gold = {
			target = scope:farrier
			gold = {
				value = medium_gold_value
				max = 25
			}
		}
		stress_impact = {
			ambitious = medium_stress_impact_gain
			arrogant = medium_stress_impact_gain
			greedy = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = ambitious
					has_trait = arrogant
					has_trait = greedy
				}
			}
			modifier = {
				factor = 1.5
				OR = {
					has_trait = generous
					has_trait = gregarious
				}
			}
		}
	}
	
	# They're good luck!
	option = {
		name = ep2_locale_events.3510.c 
		scope:horseshoe_artifact = { set_owner = root }
		pay_short_term_gold = {
			target = scope:farrier
			gold = {
				value = minor_gold_value
				max = 5
			}
		}
		stress_impact = {
			paranoid = medium_stress_impact_loss
			cynical = medium_stress_impact_gain
			ambitious = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = cynical
					has_trait = ambitious
				}
			}
			modifier = {
				factor = 1.5
				OR = {
					has_trait = paranoid
					has_trait = arrogant
				}
			}
		}
	}
	
	# Nah
	option = {
		name = ep2_locale_events.3510.d
		stress_impact = {
			paranoid = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				has_trait = paranoid
			}
			modifier = {
				factor = 0.5
				OR = {
					has_trait = arrogant
					has_trait = ambitious
				}
			}
		}
	}
}

# Visit to the local churchyard
# by Veronica Pazos

ep2_locale_events.1530 = {
	type = activity_event
	title = ep2_locale_events.1530.t
	desc = {
		desc = ep2_locale_events.1530.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = {
					age <= 25
				}
				desc = ep2_locale_events.1530.desc.young
			}
			triggered_desc = {
				trigger = {
					age >= 26
					age <= 40
				}
				desc = ep2_locale_events.1530.desc.middle
			}
			triggered_desc = {
				trigger = {
					age > 40
				}
				desc = ep2_locale_events.1530.desc.old
			}
		}
	}
	theme = tournament_locale_temple
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = {
				OR = {
					has_trait = cynical
					has_trait = callous
				}
			}
			animation = boredom
		}
		triggered_animation = {
			trigger = {
				has_trait = deviant
			}
			animation = flirtation_left
		}
		animation = personality_honorable
	}
	cooldown = { years = 1 }
	override_background = { reference = temple }

	trigger = {
		scope:activity = { 
			has_active_locale = tournament_locale_religious_building
		}
	}
	
	weight_multiplier = {
		base = 1
		modifier = {
			factor = 2
			learning >= high_skill_rating
		}
		modifier = {
			factor = 2
			scope:activity = { has_current_phase = tournament_phase_recital }
		}
		modifier = {
			factor = 1.5
			piety_level >= medium_piety_level
		}
	}

	# Try to find an ancestor
	option = {
		name = ep2_locale_events.1530.a
		trigger = { exists = dynasty }
		random_list = {
			10 = { #you find someone
				desc = ep2_locale_events.1530.a.success
				show_chance = no
				modifier = {
					factor = 2
					location.culture = root.culture
				}
				modifier = {
					factor = 2
					exists = dynasty
					dynasty.dynasty_prestige_level <= low_dynasty_prestige_level
				}
				send_interface_toast = {
					title = ep2_locale_events.1530.a.success
					left_icon = root
					dynasty ?= { add_dynasty_prestige = medium_dynasty_prestige_value }
				}
			}
			20 = { #you don't
				desc = ep2_locale_events.1530.a.failure
				show_chance = no
				modifier = {
					factor = 2
					dynasty.dynasty_prestige_level >= high_dynasty_prestige_level
				}
				send_interface_toast = {
					title = ep2_locale_events.1530.a.failure
					left_icon = root
					add_prestige = minor_prestige_loss
				}
			}
		}
		stress_impact = {
			zealous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {	
				factor = 0
				has_trait = zealous
			}
			modifier = {
				factor = 0 
				prestige <= minor_prestige_value
			}
		}
	}

	# Reflect
	option = {
		name = {
			trigger = { OR = { religion = religion:eastern_orthodox_religion religion = religion:catholic_religion religion = religion:protestant_religion } }
			text = ep2_locale_events.1530.b.christian
		}
		name = {
			trigger = { NOT = { OR = { religion = religion:eastern_orthodox_religion religion = religion:catholic_religion religion = religion:protestant_religion } } }
			text = ep2_locale_events.1530.b.fallback
		}
		add_piety = medium_piety_gain
		stress_impact = {
			cynical = medium_stress_impact_gain
			arrogant = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = cynical
					has_trait = arrogant
				}
			}
			modifier = {
				factor = 2
				piety_level >= medium_piety_level
			}
		}
	}
	
	# Practice for a recital
	option = {
		name = ep2_locale_events.1530.c 
		trigger = {
			scope:activity = { has_current_phase = tournament_phase_recital }
			activity_is_competing_trigger = yes
		}
		activity_tournament_change_contestant_score_effect = { SCORE = increase_major }
		stress_impact = {
			lifestyle_poet = medium_stress_impact_loss
			zealous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 2
				OR = {
					has_trait = ambitious
					has_trait = arrogant
					has_trait = lifestyle_poet
				}
			}
			modifier = {
				factor = 0
				has_trait = zealous
			}
		}
	}
	
	# If you're a deviant you... well
	option = {
		name = ep2_locale_events.1530.d
		trigger = { has_trait = deviant }
		stress_impact = {
			base = major_stress_impact_loss
			zealous = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				has_trait = zealous
			}
			modifier = {
				factor = 2
				has_trait = deviant
			}
			modifier = {
				factor = 0.5
				OR = {
					has_trait = compassionate
					has_trait = calm
					has_trait = ambitious
				}
			}
		}
	}
}

# Ask the weaponsmith to improve your weapon
# by Veronica Pazos

ep2_locale_events.4540 = {
	type = activity_event
	title = ep2_locale_events.4540.t
	desc = {
		desc = ep2_locale_events.4540.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:activity = {
						any_guest_subset_current_phase = { #you're participating
							name = contestant
							this = root					
						}
					}
				}
				desc = ep2_locale_events.4540.desc.contestant
			}
			triggered_desc = {
				trigger = {
					scope:activity = {
						NOT = {
							any_guest_subset_current_phase = {
								name = contestant
								this = root					
							}
						}
					}
				}
				desc = ep2_locale_events.4540.desc.fallback
			}
		}
		desc = ep2_locale_events.4540.desc.outro
	}
	theme = tournament_locale_forge
	left_portrait = {
		character = root
		animation = personality_honorable
	}
	right_portrait = {
		character = scope:weaponsmith
		animation = marshal
	}
	artifact = {
		target = scope:my_weapon
		position = lower_center_portrait
	}
	cooldown = { years = 1 }
	override_background = { reference = armory }

	trigger = {
		scope:activity = {
			has_active_locale = tournament_locale_artisans
			exists = var:tournament_weaponsmith
			var:tournament_weaponsmith = { is_alive = yes }
		}
		any_character_artifact = { #you have a weapon
			artifact_slot_type = primary_armament
		}
	}

	immediate = {
		scope:activity = {
			var:tournament_weaponsmith = { save_scope_as = weaponsmith }
		}
		if = {
			limit = { #equipped artifacts first
				any_equipped_character_artifact = {
					artifact_slot_type = primary_armament
				}
			}
			random_equipped_character_artifact = {
				limit = {
					artifact_slot_type = primary_armament
				}
				save_scope_as = my_weapon
			}
		}
		else_if = { #then unequipped but illustrious
			limit = {
				any_character_artifact = {
					artifact_slot_type = primary_armament
					rarity = illustrious
				}
			}
			random_character_artifact = {
				limit = {
					artifact_slot_type = primary_armament
					rarity = illustrious
				}
				save_scope_as = my_weapon
			}
		}
		else = { #then random
			random_character_artifact = {
				limit = { artifact_slot_type = primary_armament }
				save_scope_as = my_weapon
			}
		}
	}
	
	weight_multiplier = {
		base = 1
		modifier = {
			factor = 2
			scope:activity = {
				any_guest_subset_current_phase = { #you're participating
					name = contestant
					this = root					
				}
			}
		}
	}

	# Sharpen sword
	option = {
		name = ep2_locale_events.4540.a 
		custom_tooltip = ep2_locale_events.4540.a.tt
		pay_short_term_gold = {
			target = scope:weaponsmith
			gold = {
				value = medium_gold_value
				max = 20
			}
		}
		scope:my_weapon = {
			set_artifact_description = ep2_locale_events_artifact_sharp_desc
			add_artifact_modifier = artifact_tournament_sharpened_blade_modifier
		}
		stress_impact = {
			greedy = medium_stress_impact_gain
			zealous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = zealous
					has_trait = greedy
				}
			}
		}
	}

	# Inscribe a carving - prayer
	option = {
		name = {
			trigger = { OR = { religion = religion:eastern_orthodox_religion religion = religion:catholic_religion religion = religion:protestant_religion } }
			text = ep2_locale_events.4540.b.christian
		}
		name = {
			trigger = {
				NOT = { OR = { religion = religion:eastern_orthodox_religion religion = religion:catholic_religion religion = religion:protestant_religion } }
			}
			text = ep2_locale_events.4540.b.fallback
		}
		pay_short_term_gold = {
			target = scope:weaponsmith
			gold = {
				value = medium_gold_value
				max = 20
			}
		}
		scope:my_weapon = {
			set_artifact_description = ep2_locale_events_artifact_prayer_desc
			add_artifact_modifier = artifact_monthly_piety_7_modifier
		}
		stress_impact = {
			cynical = medium_stress_impact_gain
			greedy = medium_stress_impact_gain
			arrogant = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = cynical
					has_trait = greedy
					has_trait = arrogant
				}
			}
		}
	}
	
	# Inscribe your motto
	option = {
		name = ep2_locale_events.4540.c 
		pay_short_term_gold = {
			target = scope:weaponsmith
			gold = {
				value = medium_gold_value
				max = 20
			}
		}
		scope:my_weapon = {
			set_artifact_description = ep2_locale_events_artifact_motto_desc
			add_artifact_modifier = artifact_monthly_prestige_7_modifier
		}
		stress_impact = {
			greedy = medium_stress_impact_gain
			humble = medium_stress_impact_gain
			zealous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = greedy
					has_trait = zealous
					has_trait = humble
				}
			}
		}
	}
	
	# Nah Im fine
	option = {
		name = ep2_locale_events.4540.d
		stress_impact = {
			ambitious = medium_stress_impact_gain
			arrogant = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = ambitious
					has_trait = arrogant
				}
			}
		}
	}
}

# Bet on a game of cards, based on a 15th c. card game / Repeatable
# by Veronica Pazos

scripted_trigger ep2_locale_events_1060_valid_gambler = {
	this != ROOT
	is_physically_able_ai_adult = yes
	NOT = { has_trait = temperate }
}

scripted_effect ep2_locale_events_1060_betting_effect = {
	random_list = {
		50 = {
			desc = ep2_locale_events.1060.a.success
			show_chance = no
			send_interface_toast = {
				title = ep2_locale_events.1060.a.success
				left_icon = root
				add_gold = {
					value = tiny_gold_value
					max = 5
					multiply = 2
				}
			}
		}
		50 = {
			desc = ep2_locale_events.1060.a.failure
			show_chance = no
			send_interface_toast = {
				title = ep2_locale_events.1060.a.failure
				left_icon = root
			}
		}
	}
	pay_short_term_gold = {
		target = scope:tournament_gambler
		gold = {
			value = tiny_gold_value
			max = 5
		}
	}
}

ep2_locale_events.1060 = {
	type = activity_event
	title = ep2_locale_events.1060.t
	desc = ep2_locale_events.1060.desc
	theme = tournament_locale_tavern
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = {
				OR = {
					has_trait = diligent
					has_trait = temperate
					has_trait = zealous
				}
			}
			animation = dismissal
		}
		animation = laugh
	}
	right_portrait = {
		character = scope:tournament_gambler
		animation = chess_cocky
	}
	override_background = { reference = tavern }

	trigger = {
		scope:activity = {
			has_active_locale = tournament_locale_tavern
			any_attending_character = {
				ep2_locale_events_1060_valid_gambler = yes
			}
		}
	}

	immediate = {
		scope:activity = {
			random_attending_character = {
				limit = {
					ep2_locale_events_1060_valid_gambler = yes
				}
				weight = {
					base = 1
					modifier = {
						add = 5
						has_trait = arbitrary
					}
					modifier = {
						add = 2
						has_trait = profligate
					}
				}
				save_scope_as = tournament_gambler
			}
		}
	}
	
	weight_multiplier = {
		base = 1
		modifier = {
			factor = 2
			has_trait = arbitrary
		}
		modifier = {
			factor = 2
			has_activity_intent = reduce_stress_intent
		}
	}

	# Bet that you have a higher card
	option = {
		name = ep2_locale_events.1060.a 
		ep2_locale_events_1060_betting_effect = yes
		stress_impact = {
			base = medium_stress_impact_loss
			arbitrary = medium_stress_impact_loss
			greedy = medium_stress_impact_gain
			temperate = medium_stress_impact_gain
			zealous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = temperate
					has_trait = greedy
					has_trait = zealous
					can_make_expensive_purchase_trigger = { PRICE = minor_gold_value }
				}
			}
		}
	}

	# Bet that you have a lower card
	option = {
		name = ep2_locale_events.1060.b
		ep2_locale_events_1060_betting_effect = yes
		stress_impact = {
			base = medium_stress_impact_loss
			arbitrary = medium_stress_impact_loss
			greedy = medium_stress_impact_gain
			temperate = medium_stress_impact_gain
			zealous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = temperate
					has_trait = greedy
					has_trait = zealous
					can_make_expensive_purchase_trigger = { PRICE = minor_gold_value }
				}
			}
		}
	}
	
	# Don't bet
	option = {
		name = ep2_locale_events.1060.c 
		add_piety = minor_piety_gain
		stress_impact = {
			arbitrary = medium_stress_impact_gain
			profligate = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = greedy
					has_trait = zealous
					has_trait = humble
				}
			}
		}
	}
}
