﻿# EK NOTE: removed vanilla references, added content for the arcane clash
namespace = tournament_events

#######################################
#######################################
### 	ACTIVITY - 0001-0999		###
#######################################
#######################################

##################################################
# Tournament Arrival
# by Nick Meredith
# 0050
##################################################

tournament_events.0050 = { # Start
	type = activity_event
	title = tournament_events.0050.t
	desc = {
		desc = tournament_events.0050.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					has_activity_intent = murder_attendee_intent
				}
				desc = tournament_events.0050.murder
			}
			triggered_desc = {
				trigger = {
					has_activity_intent = woo_attendee_intent
				}
				desc = tournament_events.0050.seduce
			}
			triggered_desc = {
				trigger = {
					has_activity_intent = befriend_attendee_intent
				}
				desc = tournament_events.0050.befriend
			}
			triggered_desc = {
				trigger = {
					has_activity_intent = win_contest_intent
				}
				desc = tournament_events.0050.win
			}
			triggered_desc = {
				trigger = {
					has_activity_intent = recruit_knights_intent
				}
				desc = tournament_events.0050.recruit
			}
			triggered_desc = {
				trigger = {
					NOR = {
						has_activity_intent = murder_attendee_intent
						has_activity_intent = befriend_attendee_intent
						has_activity_intent = win_contest_intent
						has_activity_intent = recruit_knights_intent
						has_activity_intent = woo_attendee_intent

					}
				}
				desc = tournament_events.0050.relax
			}
		}
	}
	theme = tournament_grounds
	left_portrait = {
		character = root
		animation = admiration
	}
	right_portrait = {
		trigger = {
			NOT = {
				scope:host = root
			}
		}
		character = scope:host
		animation = ecstasy
	}

	trigger = {
		#DLC check.
		#has_ep2_dlc_trigger = yes
		
		#Standard checks.
		exists = scope:host
		exists = scope:activity
		is_participant_in_activity = scope:activity
		NOT = { has_activity_state = travel }
	}

	immediate = {
		if = {
			limit = { exists = intent_target }
			intent_target = { save_scope_as = starting_intent }
		}
	}

	option = { # Option A
		name = tournament_events.0050.a

		add_character_flag = arrived_at_tournament_flag
	}
}

##################################################
# Tournament Opening
# by Joe Parkin
# 0100
##################################################

tournament_events.0100 = { # Start
	type = activity_event
	title = tournament_events.0100.t
	desc = {
		desc = tournament_events.0100.desc
		first_valid = {
			triggered_desc = {
				trigger = { this = scope:host }
				desc = tournament_events.0100.host
			}
			triggered_desc = {
				trigger = { activity_is_valid_tournament_contestant = yes }
				desc = tournament_events.0100.contestant
			}
			desc = tournament_events.0100.spectator
		}
		triggered_desc = {
			trigger = { activity_is_valid_tournament_contestant = yes }
			desc = tournament_events.0100.closing
		}
	}
	theme = tournament_grounds
	left_portrait = {
		character = root
	}
	cooldown = { months = 1 }

	trigger = {
		#Standard checks.
		exists = scope:host
		exists = scope:activity
		is_participant_in_activity = scope:activity
		is_ai = no
		NOT = { has_activity_state = travel }
	}

	option = { # Option A
		name = tournament_events.0100.a
	}
}

scripted_effect tournament_arrival_prestige_tier_effect = {
	if = {
		limit = {
			any_in_list = {
				variable = new_prestige_arrival
				highest_held_title_tier = tier_$TIER$
			}
		}
		random_in_list = {
			variable = new_prestige_arrival
			limit = { highest_held_title_tier = tier_$TIER$ }
			save_scope_as = example_$TIER$
		}
		set_variable = {
			name = prestige_arrival_$TIER$
			value = {
				root = {
					every_in_list = {
						variable = new_prestige_arrival
						limit = { highest_held_title_tier = tier_$TIER$ }
						add = 1
					}
				}
			}
		}
	}
}

tournament_events.0200 = { # Prestige Arrival maintenance 
	type = character_event
	hidden = yes

	trigger = {
		#DLC check.
		has_ep2_dlc_trigger = yes
		
		#Standard checks.
		scope:host = this
		has_character_flag = prestige_arrival_toast
		any_in_list = { variable = new_prestige_arrival }
	}

	immediate = {
		# Count number of arrivals from each tier
		tournament_arrival_prestige_tier_effect = { TIER = duchy }
		tournament_arrival_prestige_tier_effect = { TIER = kingdom }
		tournament_arrival_prestige_tier_effect = { TIER = empire }
		# Save two scopes for toast
		ordered_in_list = {
			variable = new_prestige_arrival
			order_by = highest_held_title_tier
			max = 2
			check_range_bounds = no
			if = {
				limit = {
					NOT = { exists = scope:tournament_arrival_1 }
				}
				save_scope_as = tournament_arrival_1
			}
			else = { save_scope_as = tournament_arrival_2 }
		}
		# Send toast
		send_interface_toast = {
			type = toast_tournament_arrival_prestige
			title = tournament_arrival_prestige_toast
			if = {
				limit = {
					exists = var:prestige_arrival_duchy
					exists = var:prestige_arrival_kingdom
					exists = var:prestige_arrival_empire
				}
				custom_tooltip = tournament_arrival_prestige_dukes_kingdom_empire
			}
			else_if = {
				limit = {
					exists = var:prestige_arrival_duchy
					exists = var:prestige_arrival_kingdom
				}
				custom_tooltip = tournament_arrival_prestige_dukes_kingdom
			}
			else_if = {
				limit = {
					exists = var:prestige_arrival_duchy
					exists = var:prestige_arrival_empire
				}
				custom_tooltip = tournament_arrival_prestige_dukes_empire
			}
			else_if = {
				limit = {
					exists = var:prestige_arrival_kingdom
					exists = var:prestige_arrival_empire
				}
				custom_tooltip = tournament_arrival_prestige_kingdom_empire
			}
			else_if = {
				limit = { exists = var:prestige_arrival_empire }
				custom_tooltip = tournament_arrival_prestige_empire
			}
			else_if = {
				limit = { exists = var:prestige_arrival_kingdom }
				custom_tooltip = tournament_arrival_prestige_kingdom
			}
			else = { custom_tooltip = tournament_arrival_prestige_duchy }
			left_icon = scope:tournament_arrival_1
			right_icon = scope:tournament_arrival_2
			add_prestige = {
				value = {
					value = 0
					if = {
						limit = { exists = var:prestige_arrival_duchy }
						add = {
							value = 10 # per Duke
							multiply = var:prestige_arrival_duchy
						}
					}
					if = {
						limit = { exists = var:prestige_arrival_kingdom }
						add = {
							value = 50 # per King
							multiply = var:prestige_arrival_kingdom
						}
					}
					if = {
						limit = { exists = var:prestige_arrival_empire }
						add = {
							value = 100 # per Emperor
							multiply = var:prestige_arrival_empire
						}
					}
				}
			}
		}
		remove_character_flag = prestige_arrival_toast
		clear_variable_list = new_prestige_arrival
		remove_variable = prestige_arrival_duchy
		remove_variable = prestige_arrival_kingdom
		remove_variable = prestige_arrival_empire
	}
}

tournament_events.0700 = { # AI Accidental Death
	type = character_event
	hidden = yes

	trigger = {
		#DLC check.
		#has_ep2_dlc_trigger = yes
		
		#Standard checks.
		is_ai = yes
		scope:activity = {
			any_guest_subset_current_phase = {
				name = qualified
				this = root
			}
			trigger_if = {
				limit = { exists = var:accident_death_count }
				var:accident_death_count < 3
			}
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = {
				value = 0
				subtract = prowess
			}
		}
		modifier = {
			factor = 0.5
			is_landed = yes
		}
		# Reduce chance proportionally for each previous accident
		modifier = {
			exists = scope:activity.var:accident_death_count
			factor = {
				value = 1
				divide = scope:activity.var:accident_death_count
			}
		}
	}

	immediate = {
		save_scope_as = accident_victim
		# Chance for there to be a specific culprit
		random = {
			chance = 50
			scope:activity = {
				random_guest_subset_current_phase = {
					name = qualified
					limit = {
						is_ai = yes
						NOT = { this = root }
					}
					weight = {
						base = 1
						modifier = { add = prowess }
						modifier = {
							factor = 0.5
							is_landed = yes
						}
						activity_tournament_violent_modifier = yes
					}
					save_scope_as = accident_killer
				}
			}
		}
		tournament_accidental_death_effect = yes
	}
}

tournament_events.0701 = { # AI Accidental Death ping
	type = activity_event
	title = tournament_events.0701.t
	desc = tournament_events.0701.desc
	theme = tournament_contest
	left_portrait = {
		character = scope:accident_victim
		animation = pain
	}
	right_portrait = {
		trigger = { exists = scope:accident_killer }
		character = scope:accident_killer
		triggered_animation = {
			trigger = {	has_trait = callous }
			animation = stress	
		}
		triggered_animation = {
			trigger = {
				NOT = { has_trait = callous }
			}
			animation = sadness
		}
	}

	trigger = {
		#DLC check.
		#has_ep2_dlc_trigger = yes
	}

	immediate = {
		show_as_tooltip = {
			if = {
				limit = { exists = scope:accident_killer }
				scope:accident_victim = {
					death = {
						death_reason = death_contest_melee_accident
						killer = scope:accident_killer
					}
				}
			}
			else = {
				scope:accident_victim = {
					death = { death_reason = death_contest_melee_accident }
				}
			}
		}
		scope:accident_victim = {
			add_character_flag = wear_armor
		}
		scope:accident_killer = {
			add_character_flag = wear_armor
		}
	}

	option = { # Option A
		name = tournament_events.0701.a
	}
	after = {
		scope:accident_victim = {
			remove_character_flag = wear_armor
		}
		scope:accident_killer = {
			remove_character_flag = wear_armor
		}
	}
}

tournament_events.0800 = { # No Longer Valid Contestant
	type = activity_event
	title = tournament_events.0800.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					has_trait_rank = {
						trait = wounded
						rank >= 2
					}
				}
				desc = tournament_events.0800.wounded
			}
			triggered_desc = {
				trigger = { has_contagious_deadly_disease_trigger = yes }
				desc = tournament_events.0800.disease
			}
			triggered_desc = {
				trigger = { health < fine_health }
				desc = tournament_events.0800.health
			}
		}
	}
	theme = tournament_grounds
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = {
				has_trait_rank = {
					trait = wounded
					rank >= 2
				}
			}
			animation = pain
		}
		triggered_animation = {
			trigger = { has_trait = incapable }
			animation = worry
		}
		triggered_animation = {
			trigger = {
				OR = {
					health < fine_health
					has_contagious_deadly_disease_trigger = yes
				}
			}
			animation = sick
		}
	}

	trigger = {
		#DLC check.
		#has_ep2_dlc_trigger = yes
		
		#Standard checks.
		is_alive = yes
		exists = var:contest_aptitude
		NOT = {
			scope:activity = { has_current_phase = tournament_phase_horse_race }
		}
		activity_is_valid_tournament_contestant = no
		NOT = { has_character_flag = tournament_not_competing }
		save_temporary_scope_as = withdrawer_temp
		NOT = {
			scope:activity = {
				any_guest_subset_current_phase = {
					name = contestant
					this = scope:withdrawer_temp
				}
			}
		}
	}

	immediate = {
		save_scope_as = contest_withdrawal
	}

	option = { # Success
		name = tournament_events.0800.a
		remove_variable = contest_aptitude
		scope:activity = {
			add_activity_log_entry = {
				key = tournament_contest_withdrawal_log
				tags = { contest bad }
				score = 10
				character = scope:contest_withdrawal

				custom_description = {
					text = tournament_contest_withdraw_tt
					subject = scope:contest_withdrawal
				}
			}
		}
	}

	option = {
		name = tournament_events.0800.b
	}

	after = {
		scope:activity = {
			every_attending_character = {
				limit = {
					is_ai = no
					OR = {
						has_any_scripted_relation = scope:contest_withdrawal
						is_close_family_of = scope:contest_withdrawal
						is_consort_of = scope:contest_withdrawal
						scope:host = scope:contest_withdrawal
						trigger_if = {
							limit = { exists = intent_target }
							intent_target = scope:contest_withdrawal
						}
					}
				}
				trigger_event = tournament_events.0801
			}
		}
	}
}

tournament_events.0801 = { # No Longer Valid Contestant Ping
	type = activity_event
	title = tournament_events.0801.t
	desc = {
		desc = tournament_events.0801.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:contest_withdrawal = {
						has_trait_rank = {
							trait = wounded
							rank >= 2
						}
					}
				}
				desc = tournament_events.0801.wounded
			}
			triggered_desc = {
				trigger = {
					scope:contest_withdrawal = { has_contagious_deadly_disease_trigger = yes }
				}
				desc = tournament_events.0801.disease
			}
			triggered_desc = {
				trigger = {
					scope:contest_withdrawal = { health < fine_health }
				}
				desc = tournament_events.0801.health
			}
		}		
	}
	theme = tournament_grounds
	left_portrait = {
		character = scope:contest_withdrawal
		triggered_animation = {
			trigger = {
				has_trait_rank = {
					trait = wounded
					rank >= 2
				}
			}
			animation = pain
		}
		triggered_animation = {
			trigger = { has_trait = incapable }
			animation = worry
		}
		triggered_animation = {
			trigger = {
				OR = {
					health < fine_health
					has_contagious_deadly_disease_trigger = yes
				}
			}
			animation = sick
		}
	}

	cooldown = { years = 1 }

	trigger = {
		#DLC check.
		#has_ep2_dlc_trigger = yes
		
		#Standard checks.
		NOT = { this = scope:contest_withdrawal }
	}

	immediate = {
		custom_description = {
			text = tournament_contest_withdraw_tt
			subject = scope:contest_withdrawal
		}
	}

	option = { # Success
		name = tournament_events.0801.a
	}
}

tournament_events.0999 = { # Debug Bin
	type = activity_event
	title = LOREM_IPSUM_TITLE
	desc = debug_tournament_population_count_tt
	theme = realm
	orphan = yes

	trigger = {
		#DLC check.
		#has_ep2_dlc_trigger = yes
		
		#Standard checks.
		# To stop errors
		OR = {
			var:contest_type ?= flag:tournament_phase_duel
			var:contest_type ?= flag:tournament_phase_joust
			var:contest_type ?= flag:tournament_phase_melee
			var:contest_type ?= flag:tournament_phase_wrestling
			var:contest_type ?= flag:tournament_phase_board_game
			var:contest_type ?= flag:tournament_phase_recital
			var:contest_type ?= flag:tournament_phase_archery
			var:contest_type ?= flag:tournament_phase_horse_race
			#EK ADDITION
			var:contest_type ?= flag:tournament_phase_arcane_clash
			#EK ADDITION END
		}
	}

	immediate = {
		involved_activity = {
			save_scope_as = activity
			activity_host = { save_scope_as = host }
		}
	}

	option = {
		name = LOREM_IPSUM_TITLE
	}
}

##################################################
# Tournament Close
# by Nick Meredith
# 0150
##################################################

# Tournament Ends
tournament_events.0150 = {
	type = activity_event
	title = tournament_events.0150.t
	desc = {
		desc = tournament_events.0150.desc
		triggered_desc = {
			trigger = { exists = scope:melee_winner }
			desc ={
				first_valid = {
					triggered_desc = {
						trigger = { this = scope:melee_winner }
						desc = tournament_events.0150.melee_self
					}
					desc = tournament_events.0150.melee
				}
			}
		}
		triggered_desc = {
			trigger = { exists = scope:archery_winner }
			desc = {
				first_valid = {
					triggered_desc = {
						trigger = { this = scope:archery_winner }
						desc = tournament_events.0150.archery_self
					}
					desc = tournament_events.0150.archery
				}
			}
		}
		triggered_desc = {
			trigger = { exists = scope:horse_race_winner }
			desc = {
				first_valid = {
					triggered_desc = {
						trigger = { this = scope:horse_race_winner }
						desc = tournament_events.0150.horse_race_self
					}
					desc = tournament_events.0150.horse_race
				}
			}
		}
		triggered_desc = {
			trigger = { exists = scope:recital_winner }
			desc = {
				first_valid = {
					triggered_desc = {
						trigger = { this = scope:recital_winner }
						desc = tournament_events.0150.recital_self
					}
					desc = tournament_events.0150.recital
				}
			}
		}
		triggered_desc = {
			trigger = { exists = scope:joust_winner }
			desc = {
				first_valid = {
					triggered_desc = {
						trigger = { this = scope:joust_winner }
						desc = tournament_events.0150.joust_self
					}
					desc = tournament_events.0150.joust
				}
			}
		}
		triggered_desc = {
			trigger = { exists = scope:wrestling_winner }
			desc = {
				first_valid = {
					triggered_desc = {
						trigger = { this = scope:wrestling_winner }
						desc = tournament_events.0150.wrestling_self
					}
					desc = tournament_events.0150.wrestling
				}
			}
		}
		triggered_desc = {
			trigger = { exists = scope:duel_winner }
			desc = {
				first_valid = {
					triggered_desc = {
						trigger = { this = scope:duel_winner }
						desc = tournament_events.0150.duel_self
					}
					desc = tournament_events.0150.duel
				}
			}
		}
		triggered_desc = {
			trigger = { exists = scope:board_game_winner }
			desc = {
				first_valid = {
					triggered_desc = {
						trigger = { this = scope:board_game_winner }
						desc = tournament_events.0150.board_game_self
					}
					desc = tournament_events.0150.board_game
				}
			}
		}
		#EK ADDITION
		triggered_desc = {
			trigger = { exists = scope:arcane_clash_winner }
			desc = {
				first_valid = {
					triggered_desc = {
						trigger = { this = scope:arcane_clash_winner }
						desc = tournament_events.0150.arcane_clash_self
					}
					desc = tournament_events.0150.arcane_clash
				}
			}
		}
		#EK ADDITION END
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:finishing_intent
					has_completed_activity_intent = { type = murder_attendee_intent target = scope:finishing_intent }
				}
				desc = tournament_events.0150.murdersuccess
			}
			triggered_desc = {
				trigger = { has_activity_intent = murder_attendee_intent }
				desc = tournament_events.0150.murderfailure
			}
			triggered_desc = {
				trigger = {
					exists = scope:finishing_intent
					has_completed_activity_intent = { type = woo_attendee_intent target = scope:finishing_intent }
				}
				desc = tournament_events.0150.seducesuccess
			}
			triggered_desc = {
				trigger = { has_activity_intent = woo_attendee_intent }
				desc = tournament_events.0150.seducefailure
			}
			triggered_desc = {
				trigger = {
					exists = scope:finishing_intent
					has_completed_activity_intent = { type = befriend_attendee_intent target = scope:finishing_intent }
				}
				desc = tournament_events.0150.seducesuccess
			}
			triggered_desc = {
				trigger = { has_activity_intent = befriend_attendee_intent }
				desc = tournament_events.0150.befriendfailure
			}
			triggered_desc = {
				trigger = { 
					has_activity_intent = win_contest_intent 
					scope:activity = {
						any_guest_subset = {
							name = winner
							this = root
						}
					}
				}
				desc = tournament_events.0150.winsuccess
			}
			triggered_desc = { #CE1 legend seed drop
				trigger = {
					has_activity_intent = win_contest_intent 
					scope:activity = {
						any_guest_subset = {
							name = winner
							this = root
						}
					}
					AND = {
						has_variable = tournaments_won_count
						var:tournaments_won_count = 3
					}
				}
				desc = tournament_events.0150.legendseeddrop
			}
			triggered_desc = {
				trigger = { has_activity_intent = win_contest_intent }
				desc = tournament_events.0150.winfailure
			}
			triggered_desc = {
				trigger = {
					has_completed_activity_intent = { type = recruit_knights_intent }
				}
				desc = tournament_events.0150.knightsuccess
			}
			triggered_desc = {
				trigger = { has_activity_intent = recruit_knights_intent }
				desc = tournament_events.0150.knightfailure
			}
		}
		desc = tournament_events.0150.end
	}
	theme = tournament_grounds
	left_portrait = {
		character = scope:host
		animation = war_over_win
	}
	right_portrait = {
		character = root
		trigger = {
			NOT = { this = scope:host }
		}
	}
	artifact = {
		position = lower_left_portrait
		target = scope:contest_prize_1
	}
	artifact = {
		position = lower_center_portrait
		target = scope:contest_prize_2
	}
	artifact = {
		position = lower_right_portrait
		target = scope:contest_prize_3
	}

	immediate = {
		# Save intent target for loc
		if = {
			limit = { exists = intent_target }
			intent_target = { save_scope_as = finishing_intent }
		}
		if = {
			limit = {
				exists = scope:activity.special_guest:special_guest_champion
			}
			scope:activity.special_guest:special_guest_champion = {
				save_scope_as = tournament_champion
			}
		}
		tournament_disburse_contest_prize_tooltip_effect = yes
		show_as_tooltip = {
			scope:host = { disburse_tournament_activity_rewards = yes }
		}
		disburse_xp_and_liege_prestige_effect = yes
		if = { # Add Spectator modifier if did not compete
			limit = {
				scope:activity = {
					NOT = {
						any_guest_subset = {
							name = qualified
							this = root
						}
					}
				}
			}
			add_character_modifier = { modifier = tournament_contest_spectator_modifier years = 5 }
		}
		if = { #win tracker for legend seeds
			limit = {
				has_activity_intent = win_contest_intent 
				scope:activity = {
					any_guest_subset = {
						name = winner
						this = root
					}
				}
			}
			if = {
				limit = {
					has_variable = tournaments_won_count
				}
				change_variable = {
					name = tournaments_won_count
					add = 1
				}
			}
			else = {
				set_variable = {
					name = tournaments_won_count
					value = 1
				}
			}
		}
		if = { #CE1 legend seed drop
			limit = {
				has_variable = tournaments_won_count
				var:tournaments_won_count = 3
				NOT = { has_character_flag = tournament_won_legend }
				has_dlc_feature = legends
				NOT = { has_game_rule = historical_legends_only }
			}
			create_legend_seed = {
				type = heroic
				quality = famed
				chronicle = tournament_won

				properties = {
					winner = root
					location = root.location
				}
			}
			add_character_flag = tournament_won_legend
		}
		# We change your extra cool thing to be a Tournament Win
		if = {
			limit = {
				has_legend_chapter_trigger = { CHAPTER = extra_deed }	
				NOT = {
					promoted_legend = { has_legend_chronicle = tournament_won }
				}
				NOT = {
					promoted_legend ?= {
						has_legend_chapter = {
							name = extra_deed
							localization_key = legend_chapter_extra_deed_recent_tournament
						}
					}
				}
			}
			random = {
				chance = 50
				send_interface_toast = {
					title = legend_chapter_change_toast
					left_icon = root
					promoted_legend = {
						set_legend_chapter = {
							name = extra_deed
							localization_key = legend_chapter_extra_deed_recent_tournament
						}
					}
				}
			}
		}
		# LEGITIMACY GAIN FOR GRAND ACTIVITY PARTICIPATION - TOURNAMENT
		grand_activity_participation_legitimacy_effect = yes
	}

	option = { #Celebrate the end 
		name = tournament_events.0150.a

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = -0.5
				ai_greed = 1
			}
		}
	}

	option = { #Give a speech
		name = tournament_events.0150.b

		trigger = {
			this = scope:activity.activity_host 
		}

		duel = {
			skill = diplomacy
			value = medium_skill_rating
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 2
					min = -49
				}

				desc = tournament_events.0150.b.success
				
				send_interface_toast = {
					type = event_toast_effect_good
					title = tournament_events.0150.b.success
					left_icon = root
					
					add_prestige = minor_prestige_gain

					every_vassal_or_below = {
						limit = {
							has_vassal_stance = courtly 
							is_participant_in_activity = scope:activity
						}
						custom = every_participating_courtly_vassal
						add_opinion = {
							modifier = impressed_opinion
							target = root
							opinion = 15
						}
					}
				}
			}
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -2
					min = -49
				}

				desc = tournament_events.0150.b.failure
				
				send_interface_toast = {
					type = event_toast_effect_bad
					title = tournament_events.0150.b.failure
					left_icon = root
					
					add_prestige = minor_prestige_loss
				}
			}
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = 1
				ai_honor = 1
			}
		}
	}

	option = { #Give your champion a bonus
		name = tournament_events.0150.c

		trigger = {
			exists = scope:tournament_champion
			scope:tournament_champion.liege = this
			OR = {
				scope:melee_winner ?= scope:tournament_champion
				scope:archery_winner  ?= scope:tournament_champion
				scope:horse_race_winner ?= scope:tournament_champion
				scope:recital_winner ?= scope:tournament_champion
				scope:joust_winner ?= scope:tournament_champion
				scope:wrestling_winner ?= scope:tournament_champion
				scope:duel_winner ?= scope:tournament_champion
				scope:board_game_winner ?= scope:tournament_champion
				#EK ADDITION
				scope:arcane_clash_winner ?= scope:tournament_champion
				#EK ADDITION END
			}
		}

		pay_short_term_gold = {
			target = scope:tournament_champion
			gold = minor_gold_value
		}

		reverse_add_opinion = {
			target = scope:tournament_champion
			modifier = respect_opinion
			opinion = 40
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = 0.5
				ai_greed = -1
				ai_honor = 0.5
			}
		}
	}

	after = {
		# Marriage prize event
		if = {
			limit = { this = scope:host }
			trigger_event = {
				id = tournament_events.0160
				days = 3
			}
		}
	}
}

# Container for end of tournament effects so they can be run on a delay
tournament_events.0151 = {
	type = character_event
	hidden = yes

	immediate = {
		# Save winner scopes for loc
		tournament_save_contest_winner_scopes_effect = yes
		# Create log entry and hand out rewards
		scope:activity = {
			add_activity_log_entry = {
				key = tournament_complete_log
				character = scope:host
				score = 100
				show_in_conclusion = yes

				#Effect
				scope:host = { disburse_tournament_activity_rewards = yes }
			}
			# Hand out prize artifacts
			scope:host = { tournament_disburse_contest_prize_effect = yes }
			every_attending_character = {
				# Trigger summary event
				trigger_event = tournament_events.0150
			}
		}
	}
}

##################################################
# Marriage Prize Follow Up
# by Joe Parkin
# 0160
##################################################

scripted_effect tournament_marriage_prize_effect = {
	save_scope_as = marriage_winner
	scope:host = {
		send_interface_toast = {
			type = toast_tournament_marriage_prize
			title = tournament_marriage_prize_toast
			left_icon = scope:marriage_prize
			right_icon = scope:marriage_winner
			scope:marriage_winner = {
				if = {
					limit = {
						OR = {
							is_adult = no
							scope:marriage_prize = { is_adult = no }
						}
					}
					create_betrothal = scope:marriage_prize
				}
				else = { marry = scope:marriage_prize }
				add_opinion = {
					target = root
					modifier = grateful_opinion
					opinion = 10
				}
			}
			if = {
				limit = {
					NOT = { scope:host = scope:marriage_winner }
				}
				scope:host = { add_prestige = medium_prestige_gain }
			}
		}
	}
	if = {
		limit = {
			NOT = { scope:host = scope:marriage_winner }
		}
		every_in_list = {
			list = bachelors
			limit = {
				NOR = {
					this = scope:marriage_winner
					this = scope:host
				}
			}
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -10
			}
		}
		scope:host = {
			if = {
				limit = { is_in_list = bachelors }
				stress_impact = {
					arbitrary = minor_stress_impact_gain
					greedy = minor_stress_impact_gain
					arrogant = minor_stress_impact_gain
				}
			}
		}
	}
	else = {
		every_in_list = {
			list = bachelors
			limit = {
				NOT = { this = scope:host }
			}
			add_opinion = {
				target = root
				modifier = angry_opinion
				opinion = -20
			}
		}
		scope:host = {
			if = {
				limit = { exists = scope:bachelor_2 }
				stress_impact = {
					just = minor_stress_impact_gain
					generous = minor_stress_impact_gain
					humble = minor_stress_impact_gain
				}
			}
		}		
	}
}

scripted_effect tournament_marriage_prize_winner_scope_effect = {
	if = {
		limit = {
			scope:$CONTEST$_winner ?= { can_marry_character_trigger = { CHARACTER = scope:marriage_prize } }
		}
		scope:$CONTEST$_winner = { add_to_list = bachelors }
	}
}

tournament_events.0160 = {
	type = activity_event
	title = tournament_events.0160.t
	desc = {
		desc = tournament_events.0160.desc
		first_valid = {
			triggered_desc = { # Host is only option
				trigger = {
					any_in_list = { list = bachelors count = 1 }
					any_in_list = { list = bachelors this = root }
				}
				desc = contest_events_closing_marriage_valid_host_only
			}
			triggered_desc = { # Host is one among options
				trigger = {
					any_in_list = { list = bachelors count > 1 }
					any_in_list = { list = bachelors this = root }
				}
				desc = contest_events_closing_marriage_host
			}
			triggered_desc = { # 3 options
				trigger = {
					any_in_list = { list = bachelors count = 3 }
				}
				desc = contest_events_closing_marriage_three
			}
			triggered_desc = { # 2 options
				trigger = {
					any_in_list = { list = bachelors count = 2 }
				}
				desc = contest_events_closing_marriage_two
			}
			triggered_desc = { # 1 option
				trigger = {
					any_in_list = { list = bachelors count = 1 }
				}
				desc = contest_events_closing_marriage_one
			}
			desc = contest_events_closing_marriage_none # No options
		}
		triggered_desc = {
			trigger = {
				any_in_list = {
					list = bachelors
					NOT = { this = root }
				}
			}
			desc = contest_events_closing_marriage_valid
		}
	}
	theme = tournament_grounds
	left_portrait = {
		character = scope:host
		animation = thinking
	}
	right_portrait = {
		character = scope:marriage_prize
		animation = war_over_win
	}
	lower_left_portrait = scope:bachelor_1
	lower_center_portrait = scope:bachelor_2
	lower_right_portrait = scope:bachelor_3

	trigger = {
		scope:activity.var:tournament_marriage_prize ?= {
			is_alive = yes
			NOT = { has_trait_with_flag = can_not_marry }
			trigger_if = {
				limit = { exists = primary_title }
				NOR = {
					# Block Mercenaries from marrying or showing up in marriage interactions
					primary_title = { is_mercenary_company = yes }
				}
				NOR = {
					is_leading_faction_type = peasant_faction
					is_leading_faction_type = populist_faction
				}
			}
			trigger_if = {
				limit = { is_clergy = yes }
				faith = { has_doctrine_parameter = clergy_can_marry }
			}
		} 		
	}

	immediate = {
		scope:activity.var:tournament_marriage_prize = { save_scope_as = marriage_prize }
		tournament_marriage_prize_winner_scope_effect = { CONTEST = joust }
		tournament_marriage_prize_winner_scope_effect = { CONTEST = wrestling }
		tournament_marriage_prize_winner_scope_effect = { CONTEST = duel }
		tournament_marriage_prize_winner_scope_effect = { CONTEST = board_game }
		tournament_marriage_prize_winner_scope_effect = { CONTEST = recital }
		tournament_marriage_prize_winner_scope_effect = { CONTEST = archery }
		tournament_marriage_prize_winner_scope_effect = { CONTEST = horse_race }
		#EK ADDITION
		tournament_marriage_prize_winner_scope_effect = { CONTEST = arcane_clash }
		#EK ADDITION END
		while = {
			limit = {
				any_in_list = { list = bachelors }
				AND = {
					any_in_list = {
						list = bachelors
						NOR = {
							scope:bachelor_1 ?= this
							scope:bachelor_2 ?= this
							scope:bachelor_3 ?= this
						}
					}
					NOT = { exists = scope:bachelor_3 }
				}
			}
			random_in_list = {
				list = bachelors
				limit = {
					this = scope:host
					NOR = {
						scope:bachelor_1 ?= this
						scope:bachelor_2 ?= this
						scope:bachelor_3 ?= this
					}
				}
				alternative_limit = {
					is_landed = yes
					is_lowborn = no
					NOR = {
						scope:bachelor_1 ?= this
						scope:bachelor_2 ?= this
						scope:bachelor_3 ?= this
					}
				}
				alternative_limit = {
					NOR = {
						scope:bachelor_1 ?= this
						scope:bachelor_2 ?= this
						scope:bachelor_3 ?= this
					}
				}
				weight = {
					base = 1
					modifier = { add = highest_held_title_tier }
				}
				if = {
					limit = { NOT = { exists = scope:bachelor_1 } }
					save_scope_as = bachelor_1
				}
				else_if = {
					limit = { NOT = { exists = scope:bachelor_2 } }
					save_scope_as = bachelor_2
				}
				else = { save_scope_as = bachelor_3 }
			}
		}
	}

	option = { # Award to self
		name = tournament_events.0160.a
		trigger = { scope:bachelor_1 ?= this }
		tournament_marriage_prize_effect = yes
		ai_chance = {
			base = 75
			modifier = {
				OR = {
					has_relation_crush = scope:marriage_prize
					has_relation_lover = scope:marriage_prize
				}
				add = 100
			}
			opinion_modifier = {
				opinion_target = scope:marriage_prize
				multiplier = 0.5
			}
			ai_value_modifier = {
				ai_boldness = 1
				ai_greed = 0.5
				ai_honor = -1
			}
		}
	}

	option = { # Award to 1st
		name = tournament_events.0160.b
		trigger = {
			exists = scope:bachelor_1
			NOT = { is_in_list = bachelors }
		}
		scope:bachelor_1 = { tournament_marriage_prize_effect = yes }
		ai_chance = {
			base = 75
			opinion_modifier = {
				opinion_target = scope:bachelor_1
				multiplier = 0.5
			}
			ai_value_modifier = {
				ai_honor = 0.5
			}
		}
	}

	option = { # Award to 2nd
		name = tournament_events.0160.c
		trigger = { exists = scope:bachelor_2 }
		scope:bachelor_2 = { tournament_marriage_prize_effect = yes }
		ai_chance = {
			base = 75
			opinion_modifier = {
				opinion_target = scope:bachelor_2
				multiplier = 0.5
			}
			ai_value_modifier = {
				ai_honor = 0.5
			}
		}
	}

	option = { # Award to 3rd
		name = tournament_events.0160.d
		trigger = { exists = scope:bachelor_3 }
		scope:bachelor_3 = { tournament_marriage_prize_effect = yes }
		ai_chance = {
			base = 75
			opinion_modifier = {
				opinion_target = scope:bachelor_3
				multiplier = 0.5
			}
			ai_value_modifier = {
				ai_honor = 0.5
			}
		}
	}

	option = { # Change mind and renege
		name = tournament_events.0160.e
		trigger = {
			any_in_list = {
				list = bachelors
				NOT = { this = root }
			}
		}
		add_prestige = medium_prestige_loss
		every_in_list = {
			list = bachelors
			add_opinion = {
				target = scope:host
				modifier = tournament_reneged_marriage_prize_opinion
				opinion = -20
			}
		}
		stress_impact = {
			just = minor_stress_impact_gain
			honest = minor_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_honor = -1
				ai_boldness = 0.5
			}
		}
	}

	option = { # Refuse as only suitor
		name = tournament_events.0160.f
		trigger = {
			any_in_list = { list = bachelors this = root }
			any_in_list = { list = bachelors count = 1 }
		}
		add_prestige = minor_prestige_gain
		stress_impact = {
			arrogant = minor_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_honor = 0.5
				ai_compassion = 0.5
				ai_boldness = -0.5
			}
		}
	}

	option = { # No suitors
		name = tournament_events.0160.g
		trigger = {
			NOT = {
				any_in_list = { list = bachelors }
			}
		}
	}

	after = {
		scope:activity = {
			every_attending_character = {
				limit = {
					NOT = { this = scope:host }
				}
				trigger_event = tournament_events.0161
			}
		}
	}
}

tournament_events.0161 = {
	type = activity_event
	title = tournament_events.0160.t
	desc = {
		desc = tournament_events.0161.desc
		first_valid = { # Marriage prize outcomes
			triggered_desc = {
				trigger = {
					scope:marriage_winner ?= scope:host
					scope:marriage_winner ?= { is_spouse_of = scope:marriage_prize }
				}
				desc = contest_events_closing_marriage_wedding_host
			}
			triggered_desc = {
				trigger = {
					scope:marriage_winner ?= scope:host
					scope:marriage_winner = { is_betrothed = yes }
					scope:marriage_prize = { is_betrothed = yes }
				}
				desc = contest_events_closing_marriage_betrothal_host
			}
			triggered_desc = {
				trigger = {
					scope:marriage_winner ?= { is_betrothed = yes }
					scope:marriage_prize = { is_betrothed = yes }
				}
				desc = contest_events_closing_marriage_betrothal
			}
			triggered_desc = {
				trigger = {
					scope:marriage_winner ?= { is_spouse_of = scope:marriage_prize }
				}
				desc = contest_events_closing_marriage_wedding
			}
			triggered_desc = {
				trigger = {
					any_in_list = {
						list = bachelors
						has_opinion_modifier = {
							target = scope:host
							modifier = tournament_reneged_marriage_prize_opinion
						}
					}
				}
				desc = contest_events_closing_marriage_reneged_winner
			}
			triggered_desc = {
				trigger = {
					NOT = {
						any_in_list = { list = bachelors }
					}
				}
				desc = contest_events_closing_marriage_invalid
			}
			desc = contest_events_closing_marriage_host_refused
		}
	}
	theme = realm
	override_background = {
		# TODO_CD_CU: change to something fitting
		reference = army_camp
	}

	left_portrait = {
		character = root
		triggered_animation = {
			trigger = { this = scope:marriage_winner }
			animation = happiness
		}
		animation = thinking
	}
	right_portrait = {
		character = scope:marriage_prize
		animation = war_over_win
	}

	trigger = { is_ai = no }

	immediate = {
		show_as_tooltip = {
			scope:marriage_winner = {
				if = {
					limit = {
						OR = {
							is_adult = no
							scope:marriage_prize = { is_adult = no }
						}
					}
					create_betrothal = scope:marriage_prize
				}
				else = { marry = scope:marriage_prize }
			}
		}
	}

	option = {
		name = tournament_events.0161.a
		trigger = { scope:marriage_winner ?= this }
	}

	option = {
		name = tournament_events.0161.b
		trigger = {
			any_in_list = {
				list = bachelors
				has_opinion_modifier = {
					target = scope:host
					modifier = tournament_reneged_marriage_prize_opinion
				}
			}
		}
	}

	option = {
		name = tournament_events.0161.c
		trigger = {
			NOT = {
				any_in_list = { list = bachelors }
			}
		}
	}
}

###################################
###################################
### 	FLAVOR - 1000-2999		###
###################################
###################################

##################################################
# Place Your Bets
# by Joe Parkin
# 1000
##################################################

tournament_events.1000 = { # Select wager
	type = activity_event
	title = tournament_events.1000.t
	desc = {
		desc = tournament_events.1000.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:activity = { has_current_phase = tournament_phase_horse_race }
				}
				desc = tournament_events.1000.horse_race
			}
			desc = tournament_events.1000.fallback
		}
	}
	theme = tournament_grounds
	window = widget_activity_locale_fullscreen_event
	left_portrait = {
		character = root
		animation = worry
	}
	right_portrait = {
		character = scope:wager_portrait
		trigger = { exists = scope:wager_portrait }
	}
	lower_right_portrait = {
		character = scope:wager_underdog_contestant
		trigger = {
			exists = scope:wager_underdog_contestant
			NOT = { root = scope:wager_underdog_contestant}
		}
	}
	lower_left_portrait = {
		character = scope:wager_top_contestant
		trigger = {
			NOT = { root = scope:wager_top_contestant}
		}
	}

	cooldown = { months = 1 }

	trigger = {
		#DLC check.
		#has_ep2_dlc_trigger = yes
		
		#Standard checks.
		
	}

	immediate = {
		save_scope_as = wagerer
		scope:activity = { tournament_generate_wager_scope_effect = yes }
		if = {
			limit = { exists = scope:wager_flavor_contestant }
			scope:wager_flavor_contestant = { save_scope_as = wager_portrait }
		}
		else_if = {
			limit = { exists = scope:wager_champion_contestant }
			scope:wager_champion_contestant = { save_scope_as = wager_portrait }
		}
		else_if = {
			limit = { exists = scope:mysterious_stranger }
			scope:mysterious_stranger = { save_scope_as = wager_portrait }
		}
		else_if = {
			limit = { exists = scope:wager_second_contestant }
			scope:wager_second_contestant = { save_scope_as = wager_portrait }
		}
		if = {
			limit = { exists = var:contest_aptitude }
			tournament_horse_race_fetch_horse_effect = yes
		}
	}

	option = { # Bet on self
		name = {
			trigger = {
				scope:activity = { has_current_phase = tournament_phase_horse_race }
				root = scope:wager_top_contestant
			}
			text = tournament_events.1000.a.best_horse
		}
		name = {
			trigger = {
				scope:activity = { has_current_phase = tournament_phase_horse_race }
				NOT = { root = scope:wager_top_contestant }
			}
			text = tournament_events.1000.a.horse
		}
		name = {
			trigger = {
				NOT = {
					scope:activity = { has_current_phase = tournament_phase_horse_race }
				}
			}
			text = tournament_events.1000.a
		}
		trigger = { 
			exists = var:contest_aptitude 
			exists = var:progress_to_victory_score
			scope:activity = {
				any_guest_subset = {
					name = qualified
					this = root
				}
			}
		}
		tournament_place_wager_effect = { CONTENDER = root }
		tournament_contest_maysir_effect = yes
		stress_impact = {
			humble = medium_stress_impact_gain
			greedy = minor_stress_impact_gain
			profligate = minor_stress_impact_loss
		}
		ai_chance = {
			base = 5
			ai_value_modifier = {
				ai_boldness = 1
				ai_honor = -0.5
			}
			modifier = {
				has_trait = arrogant
				factor = 2
			}
		}
	}

	option = { # Bet on favorite
		name = {
			trigger = {
				scope:activity = { has_current_phase = tournament_phase_horse_race }
			}
			text = tournament_events.1000.b.horse
		}
		name = {
			trigger = {
				NOT = {
					scope:activity = { has_current_phase = tournament_phase_horse_race }
				}
			}
			text = tournament_events.1000.b
		}
		trigger = {
			NOT = { this = scope:wager_top_contestant }
		}
		highlight_portrait = scope:wager_top_contestant
		tournament_place_wager_effect = { CONTENDER = scope:wager_top_contestant }
		tournament_bet_on_other_stress_effect = yes
		tournament_contest_maysir_effect = yes
		ai_chance = {
			base = 20
			activity_tournament_wager_ai_option_modifier = { TARGET = scope:wager_top_contestant }
		}
	}

	option = { # Bet on second favorite
		name = {
			trigger = {
				scope:activity = { has_current_phase = tournament_phase_horse_race }
			}
			text = tournament_events.1000.c.horse
		}
		name = {
			trigger = {
				NOT = {
					scope:activity = { has_current_phase = tournament_phase_horse_race }
				}
			}
			text = tournament_events.1000.c
		}
		trigger = {
			exists = scope:wager_second_contestant
			NOT = { this = scope:wager_second_contestant }
		}
		highlight_portrait = scope:wager_second_contestant
		tournament_place_wager_effect = { CONTENDER = scope:wager_second_contestant }
		tournament_contest_maysir_effect = yes
		tournament_bet_on_other_stress_effect = yes
		ai_chance = {
			base = 10
			activity_tournament_wager_ai_option_modifier = { TARGET = scope:wager_second_contestant }
		}
	}

	option = { # Bet on champion
		name = tournament_events.1000.d
		trigger = {
			exists = scope:wager_champion_contestant
			NOT = { this = scope:wager_champion_contestant }
		}
		highlight_portrait = scope:wager_champion_contestant
		tournament_place_wager_effect = { CONTENDER = scope:wager_champion_contestant }
		tournament_contest_maysir_effect = yes
		tournament_bet_on_other_stress_effect = yes
		ai_chance = {
			base = 10
			activity_tournament_wager_ai_option_modifier = { TARGET = scope:wager_champion_contestant }
		}
	}

	option = { # Bet on underdog
		name = {
			trigger = {
				scope:activity = { has_current_phase = tournament_phase_horse_race }
			}
			text = tournament_events.1000.e.horse
		}
		name = {
			trigger = {
				NOT = {
					scope:activity = { has_current_phase = tournament_phase_horse_race }
				}
			}
			text = tournament_events.1000.e
		}
		trigger = {
			exists = scope:wager_underdog_contestant
			NOT = { this = scope:wager_underdog_contestant }
		}
		highlight_portrait = scope:wager_underdog_contestant
		tournament_place_wager_effect = { CONTENDER = scope:wager_underdog_contestant }
		tournament_contest_maysir_effect = yes
		tournament_bet_on_other_stress_effect = yes
		ai_chance = {
			base = 10
			activity_tournament_wager_ai_option_modifier = { TARGET = scope:wager_underdog_contestant }
		}
	}

	option = { # Bet on flavor
		name = {
			trigger = {
				scope:activity = { has_current_phase = tournament_phase_horse_race }
			}
			text = tournament_events.1000.f.horse
		}
		name = {
			trigger = {
				NOT = {
					scope:activity = { has_current_phase = tournament_phase_horse_race }
				}
			}
			text = tournament_events.1000.f
		}
		trigger = {
			exists = scope:wager_flavor_contestant
			NOT = { this = scope:wager_flavor_contestant }
		}
		highlight_portrait = scope:wager_flavor_contestant
		tournament_place_wager_effect = { CONTENDER = scope:wager_flavor_contestant }
		tournament_contest_maysir_effect = yes
		tournament_bet_on_other_stress_effect = yes
		ai_chance = {
			base = 10
			activity_tournament_wager_ai_option_modifier = { TARGET = scope:wager_flavor_contestant }
		}
	}

	option = { # Bet on mysterious stranger
		name = {
			trigger = {
				scope:activity = { has_current_phase = tournament_phase_horse_race }
			}
			text = tournament_events.1000.g.horse
		}
		name = {
			trigger = {
				NOT = {
					scope:activity = { has_current_phase = tournament_phase_horse_race }
				}
			}
			text = tournament_events.1000.g
		}
		trigger = {
			exists = scope:mysterious_stranger
			NOT = { this = scope:mysterious_stranger }
			scope:mysterious_stranger = {
				trigger_if = {
					limit = {
						scope:activity = { has_current_phase = tournament_phase_horse_race }
					}
					has_character_flag = horse_race_mysterious_stranger
				}
				trigger_else = {
					NOT = { has_character_flag = horse_race_mysterious_stranger }
				}
			}
		}
		highlight_portrait = scope:mysterious_stranger
		tournament_place_wager_effect = { CONTENDER = scope:mysterious_stranger }
		tournament_contest_maysir_effect = yes
		tournament_bet_on_other_stress_effect = yes
		ai_chance = {
			base = 10
			activity_tournament_wager_ai_option_modifier = { TARGET = scope:mysterious_stranger }
		}
	}

	option = { # Don't bet
		name = tournament_events.1000.h
		#EK DISABLED no islam
		#if = {
		#	limit = {
		#		religion = religion:islam_religion
		#		scope:activity = {
		#			NOR = {
		#				has_current_phase = tournament_phase_archery
		#				has_current_phase = tournament_phase_horse_race
		#			}
		#		}
		#	}
		#	stress_impact = {
		#		cynical = minor_stress_impact_gain
		#	}
		#}
		if = {
			limit = { exists = var:contest_aptitude }
			stress_impact = {
				arrogant = medium_stress_impact_gain
			}
		}
		stress_impact = {
			base = miniscule_stress_impact_gain
			greedy = minor_stress_impact_gain
			brave = minor_stress_impact_gain
			profligate = medium_stress_impact_loss
			fickle = minor_stress_impact_loss
			arbitrary = minor_stress_impact_loss
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_boldness = -1
				ai_energy = -1
			}
			modifier = {
				has_trait = craven
				factor = 2
			}
		}
	}
}

##################################################
# Pas d'armes
# by Joe Parkin
# 1100-1151
##################################################

scripted_trigger tournament_pas_darmes_era_trigger = {
	scope:host = {
		NOR = {
			government_has_flag = government_is_tribal
			government_has_flag = government_is_nomadic
		}
	}
	culture = { has_cultural_era_or_later = culture_era_early_medieval }
}

scripted_trigger tournament_pas_darmes_instigator_trigger = {
	is_landed = no
	is_lowborn = no
	NOR = {
		has_trait = humble
		has_trait = craven
	}
	activity_is_valid_tournament_contestant = yes
	tournament_pas_darmes_era_trigger = yes
	NOT = {
		this = scope:activity.special_guest:special_guest_champion
	}
}

tournament_events.1100 = { # Start - Alone
	type = activity_event
	title = tournament_events.1100.t
	desc = tournament_events.1100.desc
	theme = tournament_grounds
	left_portrait = {
		character = scope:pas_darmes_instigator
		animation = marshal
	}
	
	override_background = {
		trigger = {
			scope:activity.activity_location = { geographical_region = graphical_western }
		}
		reference = terrain_travel
	}
	override_background = {
		trigger = { always = yes }
		reference = terrain_activity
	}

	cooldown = { years = 5 }

	trigger = {
		#DLC check.
		#has_ep2_dlc_trigger = yes
		
		#Standard checks.
		tournament_pas_darmes_era_trigger = yes
		scope:activity = {
			NOT = {
				any_in_list = { variable = pas_darmes_instigators }
			}
			any_attending_character = {
				tournament_pas_darmes_instigator_trigger = yes
				NOT = { scope:host = this }
			}
		}
	}

	weight_multiplier = {
		base = 1
		tournament_pas_darmes_culture_tradition_modifier = yes
	}

	immediate = {
		scope:activity = {
			random_attending_character = {
				limit = { tournament_pas_darmes_instigator_trigger = yes }
				weight = {
					base = 0
					activity_tournament_pas_darmes_modifier = yes
					activity_recurring_character_weight_modifier = { VALUE = 100 }
				}
				save_scope_as = pas_darmes_instigator
				add_prestige = minor_prestige_value
				set_variable = {
					name = pas_darmes_victories
					value = 0
				}
				try_to_create_recurring_character_effect = { CHARACTER = root }
			}
			add_to_variable_list = {
				name = pas_darmes_instigators
				target = scope:pas_darmes_instigator
			}
		}
		scope:pas_darmes_instigator = {
			add_character_flag = wear_armor
		}
	}

	option = { # Encourage
		name = tournament_events.1100.a
		scope:pas_darmes_instigator = {
			accolade_minimal_glory_gain_with_checks_effect = yes
		}
		stress_impact = {
			arbitrary = medium_stress_impact_gain
			craven = medium_stress_impact_gain
		}
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_boldness = 0.5
				ai_sociability = 0.5
				ai_honor = 0.5
			}
		}
	}

	option = { # Seduction
		name = tournament_events.1100.c
		trigger = {
			is_attracted_to_gender_of = scope:pas_darmes_instigator
			can_start_scheme = {
				type = seduce
				target_character = scope:pas_darmes_instigator
			}
		}
		start_scheme = {
			type = seduce
			target_character = scope:pas_darmes_instigator
		}
		random_scheme ={
			limit = {
				scheme_type = seduce
				scheme_target_character = scope:pas_darmes_instigator
			}
			add_scheme_modifier = { type = tournament_pas_darmes_seduce_modifier }
		}
		stress_impact = {
			lustful = minor_stress_impact_loss
			chaste = medium_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_sociability = 1
				ai_energy = 1
			}
		}
	}

	option = { # Forbid
		name = tournament_events.1100.d
		reverse_add_opinion = {
			target = scope:pas_darmes_instigator
			modifier = tournament_pas_darmes_forbidden_opinion
			opinion = -10
		}
		add_prestige = medium_prestige_loss
		custom_tooltip = tournament_pas_darmes_forbidden_tt
		stress_impact = {
			brave = medium_stress_impact_gain
			arrogant = medium_stress_impact_gain
			just = medium_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_boldness = 1
				ai_sociability = -1
				ai_energy = -1
			}
		}
	}
	after = {
		scope:pas_darmes_instigator = {
			remove_character_flag = wear_armor
		}
	}
}

scripted_trigger tournament_exotic_pas_darmes_county_trigger = {
	NOT = {
		culture = { has_same_culture_heritage = scope:host.culture }
	}
	tournament_pas_darmes_era_trigger = yes
	holder = { in_diplomatic_range = scope:host }
}

tournament_events.1101 = { # Start - Exotic
	type = activity_event
	title = tournament_events.1101.t
	desc = tournament_events.1101.desc
	theme = tournament_grounds
	left_portrait = {
		character = scope:pas_darmes_instigator
		animation = marshal
	}
	
	override_background = {
		trigger = {
			scope:activity.activity_location = { geographical_region = graphical_western }
		}
		reference = terrain_travel
	}
	override_background = {
		trigger = { always = yes }
		reference = terrain_activity
	}

	cooldown = { years = 5 }

	trigger = {
		#DLC check.
		#has_ep2_dlc_trigger = yes
		scope:activity = {
			any_attending_character = {
				count < 240 #Max is 250, leaving some space for stragglers
			}
		}
		
		#Standard checks.
		tournament_pas_darmes_era_trigger = yes
		NOR = {
			government_has_flag = government_is_tribal
			government_has_flag = government_is_nomadic
		}
		NOT = {
			scope:activity = {
				any_in_list = { variable = pas_darmes_instigators }
			}
		}
		any_empire = {
			NOT = {
				any_title_to_title_neighboring_and_across_water_empire = { this = root.primary_title.empire }
			}
			any_de_jure_county = { tournament_exotic_pas_darmes_county_trigger = yes }
		}
		scope:host = this
	}

	weight_multiplier = {
		base = 1
		tournament_pas_darmes_culture_tradition_modifier = yes
	}

	immediate = {
		random_empire = {
			limit = {
				NOT = {
					any_title_to_title_neighboring_and_across_water_empire = { this = root.primary_title.empire }
				}
				any_de_jure_county = { tournament_exotic_pas_darmes_county_trigger = yes }
			}
			save_scope_as = exotic_empire
			random_de_jure_county = {
				limit = { tournament_exotic_pas_darmes_county_trigger = yes }
				weight = {
					base = 1
					modifier = {
						factor = 10
						holder = {
							OR = {
								government_has_flag = government_is_feudal
								government_has_flag = government_is_clan
							}
						}
					}
					tournament_pas_darmes_culture_tradition_modifier = yes
				}
				save_scope_as = exotic_origin
			}
		}
		create_character = {
			template = tournament_foot_character
			location = scope:activity.activity_location
			culture = scope:exotic_origin.culture
			faith = scope:exotic_origin.faith
			dynasty = generate
			save_scope_as = pas_darmes_instigator
		}
		scope:host = { add_courtier = scope:pas_darmes_instigator }
		scope:pas_darmes_instigator = {
			set_variable = {
				name = pas_darmes_victories
				value = 0
			}
			hidden_effect = { add_trait = adventurer }
			try_to_create_recurring_character_effect = { CHARACTER = root }
		}
		scope:activity = {
			add_to_variable_list = {
				name = pas_darmes_instigators
				target = scope:pas_darmes_instigator
			}
		}
		scope:pas_darmes_instigator = {
			add_character_flag = wear_armor
		}
	}

	option = { # Allow
		name = tournament_events.1101.a
		add_character_modifier = {
			modifier = tournament_allow_foreign_pas_darmes_modifier
			years = 5
		}
		scope:pas_darmes_instigator = {
			hidden_effect = {
				add_to_activity = scope:activity
			}
		}
		culture = {
			change_cultural_acceptance = {
				target = scope:pas_darmes_instigator.culture
				value = minor_cultural_acceptance_gain
				desc = cultural_acceptance_accepted_contestant
			}
		}
		scope:pas_darmes_instigator = {
			accolade_minimal_glory_gain_with_checks_effect = yes
		}
		stress_impact = {
			arbitrary = medium_stress_impact_gain
			craven = medium_stress_impact_gain
		}
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_boldness = 0.5
				ai_sociability = 0.5
				ai_honor = 0.5
			}
		}
	}

	option = { # Disallow
		name = tournament_events.1101.b
		every_knight = {
			custom = custom.every_knight
			add_opinion = {
				target = root
				modifier = tournament_ejected_interloper_opinion
				opinion = 5
			}
		}
		reverse_add_opinion = {
			target = scope:pas_darmes_instigator
			modifier = tournament_ejected_opinion
			opinion = -10
		}
		add_prestige = minor_prestige_loss
		culture = {
			change_cultural_acceptance = {
				target = scope:pas_darmes_instigator.culture
				value = minor_cultural_acceptance_loss
				desc = cultural_acceptance_expelled_contestant
			}
		}
		scope:pas_darmes_instigator = { move_to_pool_at = scope:exotic_origin.title_province }
		stress_impact = {
			just = medium_stress_impact_gain
			brave = medium_stress_impact_gain
		}
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_boldness = -0.5
				ai_sociability = -0.5
				ai_honor = -0.5
			}
		}
	}
	
	option = { # You're impressed
		name = tournament_events.1101.c
		if = {
			limit = { activity_is_competing_trigger = yes }
			activity_tournament_change_contestant_score_effect = { SCORE = increase_minor }
		}
		scope:pas_darmes_instigator = {
			accolade_minor_glory_gain_with_checks_effect = yes
		}
		stress_impact = {
			craven = medium_stress_impact_gain
			callous = medium_stress_impact_gain
			lazy = medium_stress_impact_gain
		}
		ai_chance = {
			base = 25
			modifier = {
				factor = 0
				OR = {
					has_trait = craven
					has_trait = callous
					has_trait = lazy
				}
			}
		}
	}
	after = {
		scope:pas_darmes_instigator = {
			remove_character_flag = wear_armor
		}
	}
}

tournament_events.1102 = { # Start - Band
	type = activity_event
	title = tournament_events.1102.t
	desc = tournament_events.1102.desc
	theme = tournament_grounds
	left_portrait = {
		character = scope:pas_darmes_instigator
		animation = marshal
	}
	right_portrait = {
		character = scope:pas_darmes_2
		animation = throne_room_one_handed_passive_1
		trigger = { exists = scope:pas_darmes_2 }
	}
	
	override_background = {
		trigger = {
			scope:activity.activity_location = { geographical_region = graphical_western }
		}
		reference = terrain_travel
	}
	override_background = {
		trigger = { always = yes }
		reference = terrain_activity
	}

	cooldown = { years = 5 }

	trigger = {
		#DLC check.
		#has_ep2_dlc_trigger = yes

		scope:activity = {
			any_attending_character = {
				count < 240 #Max is 250, leaving some space for stragglers
			}
		}
		
		#Standard checks.
		tournament_pas_darmes_era_trigger = yes
		this = scope:host
		NOT = {
			scope:activity = {
				any_in_list = { variable = pas_darmes_instigators }
			}
		}
		scope:activity = {
			any_attending_character = {
				tournament_pas_darmes_instigator_trigger = yes
				save_temporary_scope_as = band_leader_temp
			}
			any_attending_character = {
				NOT = { this = scope:band_leader_temp }
				tournament_pas_darmes_instigator_trigger = yes
				OR = {
					has_relation_friend = scope:band_leader_temp
					can_set_relation_friend_trigger = { CHARACTER = scope:band_leader_temp }
				}
				OR = {
					culture = scope:band_leader_temp.culture
					faith = scope:band_leader_temp.faith
					liege = scope:band_leader_temp.liege
					has_any_good_relationship_with_character_trigger = { CHARACTER = scope:band_leader_temp }
				}
			}
		}
	}

	weight_multiplier = {
		base = 1
		tournament_pas_darmes_culture_tradition_modifier = yes
	}

	immediate = {
		scope:activity = {
			random_attending_character = {
				limit = {
					tournament_pas_darmes_instigator_trigger = yes
					save_temporary_scope_as = band_leader_temp
					scope:activity = {
						any_attending_character = {
							NOT = { this = scope:band_leader_temp }
							tournament_pas_darmes_instigator_trigger = yes
							OR = {
								has_relation_friend = scope:band_leader_temp
								can_set_relation_friend_trigger = { CHARACTER = scope:band_leader_temp }
							}
							OR = {
								culture = scope:band_leader_temp.culture
								faith = scope:band_leader_temp.faith
								liege = scope:band_leader_temp.liege
								has_any_good_relationship_with_character_trigger = { CHARACTER = scope:band_leader_temp }
							}
						}
					}
				}
				weight = {
					base = 1
					activity_tournament_pas_darmes_modifier = yes
					activity_recurring_character_weight_modifier = { VALUE = 100 }
				}
				save_scope_as = pas_darmes_instigator
				add_prestige = minor_prestige_value
				set_variable = {
					name = pas_darmes_victories
					value = 0
				}
				try_to_create_recurring_character_effect = { CHARACTER = root }
				scope:activity = {
					add_to_variable_list = {
						name = pas_darmes_instigators
						target = scope:pas_darmes_instigator
					}
				}
			}
			random_attending_character = {
				limit = {
					NOT = { this = scope:pas_darmes_instigator }
					tournament_pas_darmes_instigator_trigger = yes
					OR = {
						has_relation_friend = scope:pas_darmes_instigator
						can_set_relation_friend_trigger = { CHARACTER = scope:pas_darmes_instigator }
					}
					OR = {
						culture = scope:pas_darmes_instigator.culture
						faith = scope:pas_darmes_instigator.faith
						liege = scope:pas_darmes_instigator.liege
						has_any_good_relationship_with_character_trigger = { CHARACTER = scope:pas_darmes_instigator }
					}
				}
				weight = {
					base = 1
					activity_tournament_pas_darmes_modifier = yes
				}
				save_scope_as = pas_darmes_2
				add_prestige = minor_prestige_value
				scope:activity = {
					add_to_variable_list = {
						name = pas_darmes_instigators
						target = scope:pas_darmes_2
					}
				}
				set_variable = {
					name = pas_darmes_victories
					value = 0
				}
				hidden_effect = {
					progress_towards_friend_effect = {
						REASON = friend_pas_darmes_band
						CHARACTER = scope:pas_darmes_instigator
						OPINION = default_friend_opinion
					}
				}
			}
		}
		scope:pas_darmes_instigator = {
			add_character_flag = wear_armor
		}
		scope:pas_darmes_2 = {
			add_character_flag = wear_armor
		}
	}

	option = { # Oh?
		name = tournament_events.1102.a

		custom_tooltip = tournament_events.1102.a.tt
		scope:pas_darmes_instigator = {
			accolade_minimal_glory_gain_with_checks_effect = yes
		}
		scope:pas_darmes_2 = {
			accolade_minimal_glory_gain_with_checks_effect = yes
		}
		stress_impact = {
			arbitrary = medium_stress_impact_gain
			craven = medium_stress_impact_gain
		}
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_boldness = 0.5
				ai_sociability = 0.5
				ai_honor = 0.5
			}
		}
	}

	option = { # Forbid it
		name = tournament_events.1102.b
		reverse_add_opinion = {
			target = scope:pas_darmes_instigator
			modifier = tournament_pas_darmes_forbidden_opinion
			opinion = -10
		}
		reverse_add_opinion = {
			target = scope:pas_darmes_2
			modifier = tournament_pas_darmes_forbidden_opinion
			opinion = -10
		}
		add_prestige = medium_prestige_loss
		custom_tooltip = tournament_pas_darmes_forbidden_tt
		scope:activity = { clear_variable_list = pas_darmes_instigators }
		stress_impact = {
			brave = medium_stress_impact_gain
			arrogant = medium_stress_impact_gain
		}
		stress_impact = {
			just = medium_stress_impact_gain
			brave = medium_stress_impact_gain
		}
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_boldness = -0.5
				ai_sociability = -0.5
				ai_honor = -0.5
			}
		}
	}
	after = {
		scope:pas_darmes_instigator = {
			remove_character_flag = wear_armor
		}
		scope:pas_darmes_2 = {
			remove_character_flag = wear_armor
		}
	}
}

tournament_events.1110 = { # Bout - AI Travel
	type = character_event
	hidden = yes

	cooldown = { years = 5 }

	trigger = {
		#Standard checks.
		is_adult = yes
		is_clergy = no
		is_healthy = yes
		OR = {
			is_landed = no
			is_lowborn = yes
			primary_title.tier < tier_county
		}
		OR = {
			is_knight = yes
			AND = {
				NOT = {
					can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:activity.activity_host } 
				}
				trigger_if = {
					limit = { exists = primary_spouse.involved_activity }
					NOT = { primary_spouse.involved_activity = root.involved_activity }
				}
			}
		}
		scope:activity = {
			any_in_list = {
				variable = pas_darmes_instigators
				activity_is_valid_tournament_contestant = yes
				NOR = {
					this = root
					has_any_good_relationship_with_character_trigger = { CHARACTER = root }
					is_close_or_extended_family_of = root
					is_vassal_of = root
					is_consort_of = root
				}
			}
			NOT = { has_variable = tournament_1110_cooldown }
		}
	}

	immediate = {
		scope:activity = {
			set_variable = {
				name = tournament_1110_cooldown
				months = 1
			}
			activity_location = { save_scope_as = location }
			random_in_list = {
				variable = pas_darmes_instigators
				limit = {
					activity_is_valid_tournament_contestant = yes
					NOR = {
						this = root
						has_any_good_relationship_with_character_trigger = { CHARACTER = root }
						is_close_or_extended_family_of = root
						is_vassal_of = root
						is_consort_of = root
					}
				}
				save_scope_as = pas_darmes_instigator
			}
		}
		save_scope_as = pas_darmes_victim
		if = {
			limit = { is_knight = yes }
			random_list = {
				1 = {
					modifier = { add = prowess }
					modifier = {
						has_trait = brave
						add = 5
					}
					modifier = {
						has_trait = arrogant
						add = 3
					}
					modifier = {
						has_trait = ambitious
						add = 3
					}
					modifier = {
						has_trait = wrathful
						add = 3
					}
					modifier = {
						has_trait = vengeful
						add = 3
					}
					modifier = {
						has_any_bad_relationship_with_character_trigger = { CHARACTER = scope:pas_darmes_instigator }
						add = 3
					}
					duel = {
						target = scope:pas_darmes_instigator
						skill = prowess
						40 = {
							compare_modifier = {
								value = scope:duel_value
								multiplier = 2
								min = -49
							}
							add_prestige = medium_prestige_value
							scope:pas_darmes_instigator = {
								add_prestige = minor_prestige_loss
								random_list = {
									10 = {}
									5 = {
										increase_wounds_effect = { REASON = tournament_pas_darmes_defend }
									}
									1 = {
										death = {
											death_reason = death_tournament_pas_darmes_defend
											killer = scope:pas_darmes_victim
										}
									}
								}
								if = {
									limit = {
										OR = {
											is_alive = no
											activity_is_valid_tournament_contestant = no
										}
									}
									scope:activity = {
										every_attending_character = {
											limit = { is_ai = no }
											trigger_event = tournament_events.1120
										}
									}
								}
							}
							scope:activity = {
								add_activity_log_entry = {
									key = tournament_pas_darmes_spurs_lost_log
									tags = { pas_darmes bad }
									score = 10
									character = scope:pas_darmes_instigator
									target = scope:pas_darmes_victim

									# Effects
									scope:pas_darmes_instigator = {
										if = {
											limit = { is_alive = yes }	
											add_prestige = medium_prestige_value
											accolade_minor_glory_gain_with_checks_effect = yes
										}
									}
									scope:pas_darmes_victim = {
										add_prestige = minor_prestige_loss
										random_list = {
											10 = {}
											5 = {
												increase_wounds_effect = { REASON = tournament_pas_darmes_defend }
											}
											1 = {
												death = {
													death_reason = death_tournament_pas_darmes_defend
													killer = scope:pas_darmes_victim
												}
											}
										}
										accolade_minimal_glory_loss_with_checks_effect = yes
									}
								}
							}
						}
						40 = {
							compare_modifier = {
								value = scope:duel_value
								multiplier = -2
								min = -49
							}
							create_artifact_pas_darmes_spurs_effect = {
								WINNER = scope:pas_darmes_instigator
								LOSER = scope:pas_darmes_victim
							}
							add_personal_artifact_claim = scope:newly_created_artifact
							add_prestige = minor_prestige_loss
							random_list = {
								10 = {}
								5 = { 
									increase_wounds_effect = { REASON = tournament_pas_darmes_challenge }
								}
								1 = {
									death = {
										death_reason = death_tournament_pas_darmes_challenge
										killer = scope:pas_darmes_instigator
									}
								}
							}
							scope:pas_darmes_instigator = {
								add_prestige = minor_prestige_value
								change_variable = {
									name = pas_darmes_victories
									add = 1
								}
							}
							scope:activity = {
								add_activity_log_entry = {
									key = tournament_pas_darmes_spurs_won_log
									score = 25
									tags = { pas_darmes good }
									character = scope:pas_darmes_instigator
									target = scope:pas_darmes_victim

									# Effect
									scope:pas_darmes_instigator = { add_prestige = minor_prestige_value }
									scope:pas_darmes_instigator = {
										accolade_minor_glory_gain_with_checks_effect = yes
									}
									scope:pas_darmes_victim = {
										random_list = {
											10 = {}
											5 = { 
												increase_wounds_effect = { REASON = tournament_pas_darmes_challenge }
											}
											1 = {
												death = {
													death_reason = death_tournament_pas_darmes_challenge
													killer = scope:pas_darmes_instigator
												}
											}
										}
										if = {
											limit = { is_alive = yes }
											add_prestige = minor_prestige_loss
											accolade_minimal_glory_loss_with_checks_effect = yes
										}
									}
								}
							}
						}
					}
					scope:pas_darmes_victim = {
						if = {
							limit = { 
								is_alive = yes 
								scope:pas_darmes_instigator = { is_alive = yes }
							}
							random = {
								chance = 50
								progress_towards_rival_effect = {
									REASON = rival_challenged_pas_darmes
									CHARACTER = scope:pas_darmes_instigator
									OPINION = 0
								}
							}	
						}
					}
				}
				10 = {
					modifier = {
						has_trait = craven
						add = -5
					}
					modifier = {
						has_trait = humble
						add = -3
					}
					modifier = {
						has_trait = content
						add = -3
					}
					modifier = {
						has_trait = calm
						add = -3
					}
					modifier = {
						has_trait = forgiving
						add = -3
					}
					modifier = {
						has_any_good_relationship_with_character_trigger = { CHARACTER = scope:pas_darmes_instigator }
						add = 3
					}
					scope:activity = {
						add_activity_log_entry = {
							key = tournament_pas_darmes_refused_log
							score = 25
							tags = { pas_darmes bad }
							character = scope:pas_darmes_instigator
							target = scope:pas_darmes_victim

							# Effects
							scope:pas_darmes_victim = { add_prestige = medium_prestige_loss }
							scope:pas_darmes_victim = {
								accolade_minor_glory_loss_with_checks_effect = yes
							}
						}
					}
				}
			}
		}
		else_if = {
			limit = {
				NOT = {
					can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:activity.activity_host }
				}
			}
			create_artifact_pas_darmes_token_effect = {
				OWNER = scope:pas_darmes_victim
				WINNER = scope:pas_darmes_instigator
			}
			if = {
				limit = { is_married = yes }
				every_spouse = { add_to_list = pas_darmes_ping_list }
			}
			if = {
				limit = {
					any_parent = { is_alive = yes }
				}
				every_parent = { add_to_list = pas_darmes_ping_list }
			}
			if = {
				limit = {
					any_child = {
						is_alive = yes
						is_adult = yes
					}
				}
				every_child = { add_to_list = pas_darmes_ping_list }
			}
			if = {
				limit = {
					any_relation = { type = lover }
				}
				every_relation = {
					type = lover
					add_to_list = pas_darmes_ping_list
				}
			}
			if = {
				limit = {
					any_relation = { type = friend }
				}
				every_relation = {
					type = friend
					add_to_list = pas_darmes_ping_list
				}
			}
			every_in_list = {
				list = pas_darmes_ping_list
				custom = pas_darmes_token_claim_tt
				if = {
					limit = {
						OR = {
							is_spouse_of = scope:pas_darmes_victim
							is_parent_of = scope:pas_darmes_victim
							is_child_of = scope:pas_darmes_victim
						}
					}
					add_personal_artifact_claim = scope:newly_created_artifact
				}
				trigger_event = tournament_events.1130
			}
			scope:activity = {
				add_activity_log_entry = {
					key = tournament_pas_darmes_token_taken_log
					score = 25
					tags = { pas_darmes bad }
					character = scope:pas_darmes_instigator
					target = scope:pas_darmes_victim

					# Effects
					scope:pas_darmes_victim = { add_personal_artifact_claim = scope:newly_created_artifact }
				}
			}
		}
	}
}

tournament_events.1120 = { # Challenger Injured/Invalid Ping
	type = activity_event
	title = tournament_events.1120.t
	desc = tournament_events.1120.desc
	theme = tournament_grounds
	left_portrait = {
		character = scope:pas_darmes_instigator
		animation = loss_1
	}
	right_portrait = {
		character = scope:pas_darmes_victim
		animation = war_over_win
		trigger = { exists = scope:pas_darmes_victim }
	}
	
	# TODO_CD_EP2: replace with proper art
	override_background = {
		trigger = {
			scope:activity.activity_location = { geographical_region = graphical_western }
		}
		reference = terrain_travel
	}
	override_background = {
		trigger = { always = yes }
		reference = terrain_activity
	}

	cooldown = { years = 5 }

	trigger = {
		#DLC check.
		#has_ep2_dlc_trigger = yes
		
		#Standard checks.
	}

	immediate = {
		show_as_tooltip = {
			scope:pas_darmes_instigator = {
				if = {
					limit = { is_alive = no }
					if = {
						limit = { exists = killer }
						death = {
							death_reason = death_tournament_pas_darmes_defend
							killer = scope:pas_darmes_instigator.killer
						}
					}
					else = {
						death = { death_reason = death_tournament_pas_darmes_defend }
					}
				}
				else = {
					if = {
						limit = { has_trait = wounded_2 }
						add_trait_force_tooltip = wounded_2
					}
					else_if = {
						limit = { has_trait = wounded_3 }
						add_trait_force_tooltip = wounded_3
					}
				}
			}
		}
		scope:pas_darmes_instigator = {
			add_character_flag = wear_armor
		}
		scope:pas_darmes_victim = {
			add_character_flag = wear_armor
		}
	}

	option = { # Oh no
		name = {
			trigger = {
				scope:pas_darmes_victim = { is_alive = no }
			}
			text = tournament_events.1120.a.dead
		}
		name = {
			trigger = {
				scope:pas_darmes_victim = { is_alive = yes }
			}
			text = tournament_events.1120.a
		}
	}
	after = {
		scope:pas_darmes_instigator = {
			remove_character_flag = wear_armor
		}
		scope:pas_darmes_victim = {
			remove_character_flag = wear_armor
		}
	}
}

tournament_events.1130 = { # Keepsake claim ping
	type = letter_event
	opening = tournament_events.1130.opening
	desc = {
		desc = tournament_events.1130.desc
	}
	sender = scope:pas_darmes_victim

	trigger = {
		#DLC check.
		#has_ep2_dlc_trigger = yes
		
		#Standard checks.
		is_ai = no
	}


	immediate = {
		show_as_tooltip = {
			if = {
				limit = { has_personal_artifact_claim = scope:newly_created_artifact }
				add_personal_artifact_claim = scope:newly_created_artifact
			}
		}
	}

	option = { # Oh?
		name = tournament_events.1130.a

	}
}

tournament_events.1140 = { # Host Challenge - Start
	type = activity_event
	title = tournament_events.1140.t
	desc = {
		desc = tournament_events.1140.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:pas_darmes_instigator = { martial >= medium_skill_rating }
				}
				desc = tournament_events.1140.skilled
			}
			desc = tournament_events.1140.unskilled
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:pas_darmes_instigator = { has_trait = wounded }
				}
				desc = tournament_events.1140.wounded
			}
			desc = tournament_events.1140.fallback
		}
		
	}
	theme = tournament_grounds
	left_portrait = {
		character = scope:pas_darmes_instigator
		animation = happiness
	}
	override_background = {
		trigger = {
			scope:activity.activity_location = { geographical_region = graphical_western }
		}
		reference = terrain_travel
	}
	override_background = {
		trigger = { always = yes }
		reference = terrain_activity
	}

	cooldown = { years = 5 }

	trigger = {
		#DLC check.
		#has_ep2_dlc_trigger = yes
		
		#Standard checks.
		this = scope:host
		activity_is_valid_tournament_contestant = yes
		scope:activity = {
			any_in_list = {
				variable = pas_darmes_instigators
				count >= 1
				activity_is_valid_tournament_contestant = yes
				NOR = {
					is_close_family_of = root
					is_spouse_of = root
					AND = {
						exists = liege
						liege = root
					}
				}
				NOT = {
					any_character_artifact = {
						save_temporary_scope_as = artifact_temp
						root = { has_personal_artifact_claim = scope:artifact_temp }
					}
				}
			}
		}
	}

	immediate = {
		scope:activity = {
			activity_location = { save_scope_as = location }
			random_in_list = {
				variable = pas_darmes_instigators
				limit = {
					activity_is_valid_tournament_contestant = yes
					NOR = {
						is_close_family_of = root
						is_spouse_of = root
						AND = {
							exists = liege
							liege = root
						}
					}
				}
				save_scope_as = pas_darmes_instigator
			}
		}
		scope:pas_darmes_instigator = {
			add_character_flag = wear_armor
		}
		random_neighboring_and_across_water_top_liege_realm = { save_scope_as = border_realm }
	}

	option = { # Come at me
		name = {
			trigger = {
				scope:pas_darmes_instigator = {
					NOT = { has_trait = wounded }
				}
			}
			text = tournament_events.1140.a
		}
		name = {
			trigger = {
				scope:pas_darmes_instigator = { has_trait = wounded }
			}
			text = tournament_events.1140.a.wounded
		}
		trigger = {
			NOT = { exists = scope:claimed_artifact }
		}
		show_as_tooltip = {
			if = {
				limit = {
					scope:pas_darmes_instigator = { has_trait = wounded }
				}
				add_prestige = minor_prestige_gain
			}
			else = { add_prestige = medium_prestige_gain }
			reverse_add_opinion = {
				target = scope:pas_darmes_instigator
				modifier = tournament_host_pas_darmes_opinion
				opinion = 10
			}
		}
		duel = {
			skill = prowess
			target = scope:pas_darmes_instigator
			25 = {
				desc = tournament_events.1140.a.success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 1.5
					min = -49
				}
				scope:pas_darmes_instigator = {
					show_as_tooltip = {
						random = {
							chance = 25
							increase_wounds_effect = { REASON = tournament_pas_darmes_defend }
						}
						random = {
							chance = 5
							death = {
								death_reason = death_tournament_pas_darmes_defend
								killer = root
							}
						}
					}
				}
				save_scope_as = pas_darmes_win
			}
			25 = {
				desc = tournament_events.1140.a.failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -1.5
					min = -49
				}
				show_as_tooltip = {
					random = {
						chance = 25
						increase_wounds_effect = { REASON = tournament_pas_darmes_defend }
					}
					random = {
						chance = 5
						death = {
							death_reason = death_tournament_pas_darmes_challenge
							killer = scope:pas_darmes_instigator
						}
					}
				}
			}
		}
		trigger_event = tournament_events.1141
		stress_impact = {
			arbitrary = medium_stress_impact_gain
			craven = medium_stress_impact_gain
		}
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_rationality = -1
				ai_boldness = 1
				ai_sociability = 0.5
				ai_honor = 0.5
			}
		}
	}


	option = { # Together, we will rule the galaxy
		name = tournament_events.1140.b
		trigger = {
			NOT = { scope:pas_darmes_instigator.liege = root }
		}
		duel = {
			skill = diplomacy
			value = medium_skill_rating
			10 = {
				desc = tournament_events.1140.b.success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 1.5
					min = -49
				}
				modifier = {
					add = 2
					exists = scope:pas_darmes_instigator.liege
					primary_title.tier > scope:pas_darmes_instigator.liege.primary_title.tier
				}
				modifier = {
					add = 2
					NOT = { exists = scope:pas_darmes_instigator.liege }
				}
				pay_short_term_gold = {
					target = scope:pas_darmes_instigator
					gold = minor_gold_value
				}
				add_courtier = scope:pas_darmes_instigator
				if = {
					limit = {
						exists = scope:pas_darmes_instigator.liege
						NOT = { this = scope:pas_darmes_instigator.liege }
					}
					reverse_add_opinion = {
						modifier = tournament_stole_knight_opinion
						target = scope:pas_darmes_instigator.liege
						opinion = -10
					}
				}
			}
			15 = {
				desc = tournament_events.1140.b.failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -1.5
					min = -49
				}
			}
		}
		stress_impact = {
			arrogant = medium_stress_impact_gain
			greedy = medium_stress_impact_gain
		}
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_rationality = 0.5
				ai_greed = -1
				ai_sociability = 1
			}
		}
	}

	option = { # That's enough
		name = tournament_events.1140.c
		if = {
			limit = { activity_is_competing_trigger = yes }
			activity_tournament_change_contestant_score_effect = { SCORE = increase_medium }
		}
		add_prestige = minor_prestige_loss
		reverse_add_opinion = {
			target = scope:pas_darmes_instigator
			modifier = tournament_pas_darmes_forbidden_opinion
			opinion = -10
		}
		custom_tooltip = tournament_pas_darmes_forbidden_tt
		scope:activity = { clear_variable_list = pas_darmes_instigators }
		stress_impact = {
			brave = medium_stress_impact_gain
			just = medium_stress_impact_gain
			eccentric = medium_stress_impact_gain
		}
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_honor = -0.5
				ai_boldness = -0.5
				ai_sociability = -0.5
			}
		}
	}

	option = { # Well done
		name = tournament_events.1140.d
		custom_tooltip = tournament_events.1102.a.tt
		scope:pas_darmes_instigator = {
			accolade_minor_glory_gain_with_checks_effect = yes
		}
		stress_impact = {
			craven = medium_stress_impact_gain
			shy = medium_stress_impact_gain
			eccentric = medium_stress_impact_gain
		}
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_honor = 0.5
				ai_boldness = 0.5
				ai_sociability = 0.5
			}
		}
	}
	after = {
		scope:pas_darmes_instigator = {
			remove_character_flag = wear_armor
		}
	}
}

tournament_events.1141 = { # Host Challenge - Outcome
	type = activity_event
	title = tournament_events.1141.t
	desc = {
		desc = tournament_events.1141.desc
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:pas_darmes_win }
				desc = tournament_events.1141.win
			}
			desc = tournament_events.1141.lose
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:pas_darmes_win
					scope:pas_darmes_instigator = { is_alive = no }
				}
				desc = tournament_events.1141.kill_them
			}
			triggered_desc = {
				trigger = { exists = scope:pas_darmes_win }
				desc = tournament_events.1141.beat_them
			}
			triggered_desc = {
				trigger = { is_alive = no }
				desc = tournament_events.1141.kill_me
			}
			desc = tournament_events.1141.beat_me
		}
	}
	theme = tournament_grounds
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = { exists = scope:pas_darmes_win }
			animation = jockey_lance_tilted
		}
		triggered_animation = {
			trigger = {
				NOT = { exists = scope:pas_darmes_win }
			}
			animation = loss_1
		}
	}
	right_portrait = {
		character = scope:pas_darmes_instigator
		triggered_animation = {
			trigger = { exists = scope:pas_darmes_win }
			animation = loss_1
		}
		triggered_animation = {
			trigger = {
				NOT = { exists = scope:pas_darmes_win }
			}
			animation = jockey_lance_tilted
		}
	}
	artifact = {
		target = scope:newly_created_artifact
		position = lower_right_portrait
	}
	# TODO_CD_EP2: replace with proper art
	override_background = {
		trigger = {
			scope:activity.activity_location = { geographical_region = graphical_western }
		}
		reference = bp1_crossroads_inn
	}
	override_background = {
		trigger = { always = yes }
		reference = terrain_activity
	}

	cooldown = { years = 5 }

	trigger = {
		#DLC check.
		#has_ep2_dlc_trigger = yes
		
		#Standard checks.
	}

	immediate = {
		if = {
			limit = { exists = scope:pas_darmes_win }
			create_artifact_pas_darmes_spurs_effect = {
				WINNER = scope:host
				LOSER = scope:pas_darmes_instigator
			}
			scope:pas_darmes_instigator = {
				accolade_minimal_glory_loss_with_checks_effect = yes
			}
			hidden_effect = {
				random = {
					chance = 25
					increase_wounds_effect = { REASON = tournament_pas_darmes_defend }
				}
				random = {
					chance = 5
					death = {
						death_reason = death_tournament_pas_darmes_defend
						killer = root
					}
				}
			}
			save_scope_as = pas_darmes_victim
			scope:pas_darmes_instigator = { add_personal_artifact_claim = scope:newly_created_artifact }
		}
		else = {
			scope:pas_darmes_instigator = {
				create_artifact_pas_darmes_spurs_effect = {
					WINNER = scope:pas_darmes_instigator
					LOSER = scope:host
				}
				accolade_minor_glory_gain_with_checks_effect = yes
				hidden_effect = {
					random = {
						chance = 25
						increase_wounds_effect = { REASON = tournament_pas_darmes_challenge }
					}
					random = {
						chance = 5
						death = {
							death_reason = death_tournament_pas_darmes_challenge
							killer = scope:pas_darmes_instigator
						}
					}
				}
			}
		}
		show_as_tooltip = {
			if = {
				limit = { is_alive = no }
				death = {
					death_reason = death_tournament_pas_darmes_challenge
					killer = scope:pas_darmes_instigator
				}
			}
			else_if = {
				limit = { has_character_flag = agency_wound }
				switch = {
					trigger = has_trait
					wounded_1 = { add_trait_force_tooltip = wounded_1 }
					wounded_2 = { add_trait_force_tooltip = wounded_2 }
					wounded_3 = { add_trait_force_tooltip = wounded_3 }
				}
			}
		}
		scope:pas_darmes_instigator = {
			show_as_tooltip = {
				if = {
					limit = { is_alive = no }
					death = {
						death_reason = death_tournament_pas_darmes_defend
						killer = root
					}
				}
				else_if = {
					limit = { has_character_flag = agency_wound }
					switch = {
						trigger = has_trait
						wounded_1 = { add_trait_force_tooltip = wounded_1 }
						wounded_2 = { add_trait_force_tooltip = wounded_2 }
						wounded_3 = { add_trait_force_tooltip = wounded_3 }
					}
				}
			}
		}
		if = {
			limit = {
				is_alive = yes
				scope:pas_darmes_instigator = {
					OR = {
						has_trait = wounded_2
						has_trait = wounded_3
					}
				}
			}
			add_prestige = minor_prestige_gain
		}
		else_if = {
			limit = { is_alive = yes }
			add_prestige = medium_prestige_gain
		}
		if = {
			limit = {
				is_alive = yes
				scope:pas_darmes_instigator = { is_alive = yes }
			}
			reverse_add_opinion = {
				target = scope:pas_darmes_instigator
				modifier = tournament_host_pas_darmes_opinion
				opinion = 10
			}
		}
		scope:pas_darmes_instigator = {
			add_character_flag = wear_armor
		}
		add_character_flag = wear_armor
	}

	option = { # 
		name = {
			text = tournament_events.1141.a
			trigger = { is_alive = yes }
		}
		name = {
			text = tournament_events.1141.a.death
			trigger = { is_alive = no }
		}
		trigger = {
			NOT = { exists = scope:pas_darmes_win }
		}
		if = {
			limit = { is_alive = yes }
			add_personal_artifact_claim = scope:newly_created_artifact
		}
		else_if = {
			limit = {
				NOT = { primary_heir = scope:pas_darmes_instigator }
			}
			primary_heir = { add_personal_artifact_claim = scope:newly_created_artifact }
		}
	}

	option = { # 
		name = {
			text = tournament_events.1141.b
			trigger = {
				scope:pas_darmes_instigator = { is_alive = yes }
			}
		}
		name = {
			text = tournament_events.1141.b.death
			trigger = {
				scope:pas_darmes_instigator = { is_alive = no }
			}
		}
		trigger = { exists = scope:pas_darmes_win }
		scope:pas_darmes_instigator = { add_personal_artifact_claim = scope:newly_created_artifact }
	}

	after = {
		scope:pas_darmes_instigator = {
			remove_character_flag = wear_armor
		}
		remove_character_flag = wear_armor
	}
}

##################################################
# Restoring Honor
# by Joe Parkin
# 1150-1151
##################################################

tournament_events.1150 = { # Keepsake Claim Challenge - Start
	type = activity_event
	title = tournament_events.1150.t
	desc = {
		desc = tournament_events.1150.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:pas_darmes_instigator = { martial >= medium_skill_rating }
				}
				desc = tournament_events.1150.skilled
			}
			desc = tournament_events.1150.unskilled
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:pas_darmes_instigator = { has_trait = wounded }
				}
				desc = tournament_events.1150.wounded
			}
			desc = tournament_events.1150.fallback
		}
	}
	theme = tournament_grounds
	left_portrait = {
		character = scope:pas_darmes_instigator
		animation = happiness
	}
	# TODO_CD_EP2: replace with proper art
	artifact = {
		target = scope:claimed_artifact
		position = lower_right_portrait
	}
	override_background = {
		trigger = {
			scope:activity.activity_location = { geographical_region = graphical_western }
		}
		reference = terrain_travel
	}
	override_background = {
		trigger = { always = yes }
		reference = terrain_activity
	}

	cooldown = { years = 5 }

	trigger = {
		#DLC check.
		#has_ep2_dlc_trigger = yes
		
		#Standard checks.
		this = scope:host
		activity_is_valid_tournament_contestant = yes
		scope:activity = {
			any_in_list = {
				variable = pas_darmes_instigators
				count >= 1
				activity_is_valid_tournament_contestant = yes
				any_character_artifact = {
					artifact_type = pas_darmes_token
					save_temporary_scope_as = artifact_temp
					root = { has_personal_artifact_claim = scope:artifact_temp }
				}
				NOT = {
					any_character_artifact = {
						save_temporary_scope_as = artifact_temp
						root = { has_personal_artifact_claim = scope:artifact_temp }
					}
				}
			}
		}
	}

	immediate = {
		scope:activity = {
			random_in_list = {
				variable = pas_darmes_instigators
				limit = {
					activity_is_valid_tournament_contestant = yes
					NOR = {
						is_close_family_of = root
						is_spouse_of = root
						AND = {
							exists = liege
							liege = root
						}
					}
				}
				save_scope_as = pas_darmes_instigator
			}
		}
		random_neighboring_and_across_water_top_liege_realm = { save_scope_as = border_realm }
		every_claimed_artifact = {
			limit = {
				artifact_owner = scope:pas_darmes_instigator
				artifact_type = pas_darmes_token
			} 
			add_to_list = pas_darmes_reclaims
		}
		random_in_list = {
			list = pas_darmes_reclaims
			save_scope_as = claimed_artifact
		}
		scope:pas_darmes_instigator = {
			add_character_flag = wear_armor
		}
	}

	option = { # Come at me
		name = {
			trigger = {
				scope:pas_darmes_instigator = {
					NOT = { has_trait = wounded }
				}
			}
			text = tournament_events.1150.a
		}
		name = {
			trigger = {
				scope:pas_darmes_instigator = { has_trait = wounded }
			}
			text = tournament_events.1150.a.wounded
		}
		if = {
			limit = {
				scope:pas_darmes_instigator = {
					OR = {
						has_trait = wounded_2
						has_trait = wounded_3
					}
				}
			}
			add_prestige = minor_prestige_gain
		}
		else = { add_prestige = medium_prestige_gain }
		duel = {
			skill = prowess
			target = scope:pas_darmes_instigator
			25 = {
				desc = tournament_events.1150.a.success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 1.5
					min = -49
				}
				every_in_list = {
					list = pas_darmes_reclaims
					set_owner = root
				}
				scope:pas_darmes_instigator = {
					show_as_tooltip = {
						random = {
							chance = 25
							increase_wounds_effect = { REASON = tournament_pas_darmes_defend }
						}
						random = {
							chance = 5
							death = {
								death_reason = death_tournament_pas_darmes_defend
								killer = root
							}
						}
					}
				}
				save_scope_as = pas_darmes_win
			}
			25 = {
				desc = tournament_events.1150.a.failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -1.5
					min = -49
				}
				every_in_list = {
					list = pas_darmes_reclaims
					save_scope_as = claimed_artifact
					root = { remove_personal_artifact_claim = scope:claimed_artifact }
					var:token_owner = {
						if = {
							limit = {
								NOT = { this = root }
							}
							add_opinion = {
								target = root
								modifier = tournament_failed_pas_darmes_reclaim_opinion
								opinion = -10
							}
						}
					}
				}
				show_as_tooltip = {
					random = {
						chance = 25
						increase_wounds_effect = { REASON = tournament_pas_darmes_defend }
					}
					random = {
						chance = 5
						death = {
							death_reason = death_tournament_pas_darmes_challenge
							killer = scope:pas_darmes_instigator
						}
					}
				}
			}
		}
		reverse_add_opinion = {
			target = scope:pas_darmes_instigator
			modifier = tournament_host_pas_darmes_opinion
			opinion = 10
		}
		trigger_event = tournament_events.1151
		stress_impact = {
			craven = medium_stress_impact_gain
			arbitrary = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = 0.5
				ai_boldness = 1
				ai_energy = 1
			}
		}
	}

	option = { # Keep your trinket
		name = tournament_events.1150.b
		add_prestige = medium_prestige_loss
		every_in_list = {
			list = pas_darmes_reclaims
			var:token_owner = {
				if = {
					limit = {
						NOT = { this = root }
					}
					add_opinion = {
						target = root
						modifier = tournament_failed_pas_darmes_reclaim_opinion
						opinion = -10
					}
				}
			}
		}
		stress_impact = {
			brave = medium_stress_impact_gain
			just = medium_stress_impact_gain
			stubborn = medium_stress_impact_gain
			wrathful = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = -0.5
				ai_boldness = -1
				ai_energy = -1
			}
		}
	}
	after = {
		scope:pas_darmes_instigator = {
			remove_character_flag = wear_armor
		}
	}
}

tournament_events.1151 = { # Keepsake Claim Challenge - Outcome
	type = activity_event
	title = tournament_events.1150.t
	desc = {
		desc = tournament_events.1141.desc
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:pas_darmes_win }
				desc = tournament_events.1141.win
			}
			desc = tournament_events.1141.lose
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:pas_darmes_win
					scope:pas_darmes_instigator = { is_alive = no }
				}
				desc = tournament_events.1141.kill_them
			}
			triggered_desc = {
				trigger = { exists = scope:pas_darmes_win }
				desc = tournament_events.1141.beat_them
			}
			triggered_desc = {
				trigger = { is_alive = no }
				desc = tournament_events.1141.kill_me
			}
			desc = tournament_events.1141.beat_me
		}
	}
	theme = tournament_grounds
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = { exists = scope:pas_darmes_win }
			animation = war_over_win
		}
		triggered_animation = {
			trigger = {
				NOT = { exists = scope:pas_darmes_win }
			}
			animation = loss_1
		}
	}
	right_portrait = {
		character = scope:pas_darmes_instigator
		triggered_animation = {
			trigger = { exists = scope:pas_darmes_win }
			animation = loss_1
		}
		triggered_animation = {
			trigger = {
				NOT = { exists = scope:pas_darmes_win }
			}
			animation = war_over_win
		}
	}
	artifact = {
		target = scope:claimed_artifact
		position = lower_right_portrait
	}
	# TODO_CD_EP2: replace with proper art
	override_background = {
		trigger = {
			scope:activity.activity_location = { geographical_region = graphical_western }
		}
		reference = terrain_travel
	}
	override_background = {
		trigger = { always = yes }
		reference = terrain_activity
	}

	cooldown = { years = 5 }

	trigger = {
		#DLC check.
		#has_ep2_dlc_trigger = yes
		
		#Standard checks.
	}

	immediate = {
		if = {
			limit = { exists = scope:pas_darmes_win }
			every_in_list = {
				list = pas_darmes_reclaims
				set_owner = root
			}
			scope:pas_darmes_instigator = {
				random = {
					chance = 25
					increase_wounds_effect = { REASON = tournament_pas_darmes_defend }
				}
				random = {
					chance = 5
					death = {
						death_reason = death_tournament_pas_darmes_defend
						killer = root
					}
				}
				accolade_minimal_glory_loss_with_checks_effect = yes
			}
		}
		else = {
			scope:pas_darmes_instigator = {
				accolade_minor_glory_gain_with_checks_effect = yes
			}
			random = {
				chance = 25
				increase_wounds_effect = { REASON = tournament_pas_darmes_challenge }
			}
			random = {
				chance = 5
				death = {
					death_reason = death_tournament_pas_darmes_challenge
					killer = scope:pas_darmes_instigator
				}
			}
			every_in_list = {
				list = pas_darmes_reclaims
				save_scope_as = claimed_artifact
				root = { remove_personal_artifact_claim = scope:claimed_artifact }
			}
		}
		if = {
			limit = {
				scope:pas_darmes_instigator = { is_alive = yes }
			}
			reverse_add_opinion = {
				target = scope:pas_darmes_instigator
				modifier = tournament_host_pas_darmes_opinion
				opinion = 10
			}
		}
		scope:pas_darmes_instigator = {
			add_character_flag = wear_armor
		}
		add_character_flag = wear_armor
	}

	option = { # 
		name = {
			text = tournament_events.1141.a
			trigger = { is_alive = yes }
		}
		name = {
			text = tournament_events.1141.a.death
			trigger = { is_alive = no }
		}
		trigger = {
			NOT = { exists = scope:pas_darmes_win }
		}
	}

	option = { # 
		name = {
			text = tournament_events.1141.b
			trigger = {
				scope:pas_darmes_instigator = { is_alive = yes }
			}
		}
		name = {
			text = tournament_events.1141.b.death
			trigger = {
				scope:pas_darmes_instigator = { is_alive = no }
			}
		}
		trigger = { exists = scope:pas_darmes_win }
	}
	after = {
		scope:pas_darmes_instigator = {
			remove_character_flag = wear_armor
		}
		remove_character_flag = wear_armor
	}
}

##################################################
# Religious Reproach
# by Joe Parkin
# 1200
##################################################

tournament_events.1200 = {
	type = activity_event
	title = tournament_events.1200.t
	desc = tournament_events.1200.desc
	theme = tournament_grounds
	left_portrait = {
		character = scope:angry_clergy
		animation = chaplain
	}
	cooldown = { years = 5 }

	trigger = {
		#DLC check.
		#has_ep2_dlc_trigger = yes
		
		#Standard checks.
		this = scope:host
		is_adult = yes
		faith = {
			NOR = {
				has_doctrine = tenet_warmonger
				has_doctrine = tenet_unrelenting_faith
				trait_is_virtue = arrogant
			}
		}
		OR = {
			AND = {
				exists = cp:councillor_court_chaplain
				cp:councillor_court_chaplain = { activity_adult_available_or_attending_same_activity_trigger = yes }
			}
			any_vassal = {
				government_has_flag = government_is_theocracy
				faith = root.faith
				activity_adult_available_or_attending_same_activity_trigger = yes
			}
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			factor = 2
			faith = { has_doctrine = tenet_pacifism }
		}
	}

	immediate = {
		random_list = {
			10 = {
				trigger = {
					exists = cp:councillor_court_chaplain
					activity_adult_available_or_attending_same_activity_trigger = yes
				}
				cp:councillor_court_chaplain = {
					save_scope_as = angry_clergy
					try_to_create_recurring_character_effect = { CHARACTER = root }
				}
			}
			10 = {
				trigger = {
					any_vassal = {
						government_has_flag = government_is_theocracy
						faith = root.faith
						activity_adult_available_or_attending_same_activity_trigger = yes
					}
				}
				ordered_vassal = {
					limit = { 
						government_has_flag = government_is_theocracy
						faith = root.faith
						activity_adult_available_or_attending_same_activity_trigger = yes
					}
					order_by = primary_title.tier
					save_scope_as = angry_clergy
					try_to_create_recurring_character_effect = { CHARACTER = root }
				}
			}
		}
	}

	option = { # Soldiers need practice
		name = tournament_events.1200.a
		skill = martial
		trigger = { martial >= medium_skill_rating }
		duel = {
			skill = martial
			target = scope:angry_clergy
			60 = {
				desc = tournament_events.1200.a.success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 1.5
					min = -49
				}
				send_interface_toast = {
					type = event_toast_effect_good
					title = tournament_events.1200.a.success
					left_icon = scope:angry_clergy
					reverse_add_opinion = {
						target = scope:angry_clergy
						modifier = tournament_convinced_priest_opinion
						opinion = 5
					}
					add_piety = minor_piety_value
				}
			}
			40 = {
				desc = tournament_events.1200.a.failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -1.5
					min = -49
				}
				send_interface_toast = {
					type = event_toast_effect_bad
					title = tournament_events.1200.a.failure
					left_icon = scope:angry_clergy
					reverse_add_opinion = {
						target = scope:angry_clergy
						modifier = tournament_unconvinced_priest_opinion
						opinion = -10
					}
					add_piety = medium_piety_loss
				}
			}
		}
		stress_impact = {
			craven = medium_stress_impact_gain
			fickle = medium_stress_impact_gain
			humble = medium_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_boldness = 1
				ai_sociability = 1
				ai_zeal = -1
				ai_energy = 1
			}
		}
	}

	option = { # Let me persuade you
		name = tournament_events.1200.b
		if = {
			limit = { activity_is_competing_trigger = yes }
			activity_tournament_change_contestant_score_effect = { SCORE = increase_minor }
		}
		random_list = {
			10 = {
				modifier = {
					add = {
						value = diplomacy
						divide = 2
					}
				}
				modifier = {
					scope:angry_clergy = { has_trait = arrogant }
					add = 5 
				}
				modifier = {
					scope:angry_clergy = { has_trait = greedy }
					add = 5 
				}
				modifier = {
					scope:angry_clergy = { has_trait = fickle }
					add = 5 
				}
				modifier = {
					scope:angry_clergy = { has_trait = arbitrary }
					add = 5 
				}
				modifier = {
					scope:angry_clergy = { has_trait = ambitious }
					add = 5 
				}
				modifier = {
					scope:angry_clergy = { has_trait = gregarious }
					add = 5 
				}
				modifier = {
					scope:angry_clergy = { has_trait = cynical }
					add = 5 
				}
				modifier = {
					scope:angry_clergy = { has_trait = gluttonous }
					add = 5 
				}
				desc = tournament_events.1200.b.success
				send_interface_toast = {
					type = event_toast_effect_good
					title = tournament_events.1200.b.success
					left_icon = scope:angry_clergy
					reverse_add_opinion = {
						target = scope:angry_clergy
						modifier = tournament_convinced_priest_opinion
						opinion = 5
					}
				}
			}
			10 = {
				modifier = {
					scope:angry_clergy = { has_trait = humble }
					add = 5 
				}
				modifier = {
					scope:angry_clergy = { has_trait = stubborn }
					add = 5 
				}
				modifier = {
					scope:angry_clergy = { has_trait = content }
					add = 5 
				}
				modifier = {
					scope:angry_clergy = { has_trait = shy }
					add = 5 
				}
				modifier = {
					scope:angry_clergy = { has_trait = zealous }
					add = 5 
				}
				modifier = {
					scope:angry_clergy = { has_trait = temperate }
					add = 5 
				}
				desc = tournament_events.1200.b.failure
				send_interface_toast = {
					type = event_toast_effect_bad
					title = tournament_events.1200.b.failure
					left_icon = scope:angry_clergy
					reverse_add_opinion = {
						target = scope:angry_clergy
						modifier = tournament_unconvinced_priest_opinion
						opinion = -10
					}
				}
			}
		}
		stress_impact = {
			shy = medium_stress_impact_gain
			arrogant = medium_stress_impact_gain
			lazy = medium_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_boldness = 0.5
				ai_sociability = -0.5
				ai_zeal = -0.5
				ai_energy = -0.5
			}
		}
	}

	option = { # I won't compete
		name = tournament_events.1200.c
		trigger = {
			is_adult = yes
			NOT = { has_character_flag = tournament_not_competing }
			can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root }
			is_healthy = yes
			NOT = { has_activity_intent = win_contest_intent }
		}
		show_as_unavailable = { has_activity_intent = win_contest_intent }
		add_piety = medium_piety_value
		add_character_flag = tournament_not_competing
		custom_tooltip = tournament_not_competing_tt
		reverse_add_opinion = {
			target = scope:angry_clergy
			modifier = tournament_not_competing_opinion
			opinion = 10
		}
		stress_impact = {
			cynical = medium_stress_impact_gain
			stubborn = medium_stress_impact_gain
			arrogant = medium_stress_impact_gain
			brave = medium_stress_impact_gain
			gregarious = medium_stress_impact_gain
		}
		ai_chance = {
			base = 5
			ai_value_modifier = {
				ai_sociability = -1
				ai_zeal = 1
			}
		}
	}

	option = { # Oh give it a rest
		name = tournament_events.1200.d
		add_prestige = miniscule_prestige_value
		reverse_add_opinion = {
			target = scope:angry_clergy
			modifier = tournament_dismissed_priest_opinion
			opinion = -10
		}
		stress_impact = {
			zealous = medium_stress_impact_gain
			stubborn = medium_stress_impact_gain
			brave = medium_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_boldness = 1
				ai_sociability = 1
				ai_zeal = -1
			}
		}
	}
}

##################################################
# Rags to Maile
# by Joe Parkin
# 1230
##################################################

tournament_events.1230 = {
	type = activity_event
	title = tournament_events.1230.t
	desc = tournament_events.1230.desc
	theme = tournament_grounds
	left_portrait = {
		character = root
		animation = happiness
	}
	right_portrait = {
		character = scope:battle_peasant
		animation = throne_room_bow_1
	}
	lower_right_portrait = { character = scope:old_holder }
	cooldown = { years = 10 }

	trigger = {
		#DLC check.
		#has_ep2_dlc_trigger = yes
		scope:activity = {
			NOR = {
				has_current_phase = tournament_phase_recital
				has_current_phase = tournament_phase_board_game
				has_current_phase = tournament_phase_horse_race
			}
		}
		this = scope:host
	}

	weight_multiplier = {
		base = 1
		modifier = {
			factor = 2
			has_activity_intent = recruit_knights_intent
		}
	}

	immediate = {
		scope:activity = {
			random_attending_character = {
				culture = { save_scope_as = attending_culture }
			}
		}
		scope:attending_culture = {
			random_culture_county = {
				faith = { save_scope_as = attending_faith }
			}
		}
		create_character = {
			template = tournament_foot_character
			location = scope:activity.activity_location
			culture = scope:attending_culture
			faith = scope:attending_faith
			dynasty = none
			save_scope_as = battle_peasant
		}
		if = {
			limit = { employs_court_position = champion_court_position }
			random_court_position_holder = {
				type = champion_court_position
				save_scope_as = old_holder
			}
		}
	}

	option = { # Make champion
		name = tournament_events.1230.a
		trigger = {
			has_royal_court = yes
			OR = {
				can_employ_court_position_type = champion_court_position
				employs_court_position = champion_court_position
			}
		}
		remove_short_term_gold = {
			value = minor_gold_value
			max = 20
		}
		hidden_effect = { add_courtier = scope:battle_peasant }
		scope:battle_peasant = {
			hidden_effect = {
				add_to_activity = scope:activity
			}
			add_character_modifier = {
				modifier = tournament_battle_peasant_modifier
				years = 10
			}
			try_to_create_recurring_character_effect = { CHARACTER = root }
		}
		if = {
			limit = { exists = scope:old_holder }
			reverse_add_opinion = {
				modifier = tournament_replaced_champion_opinion
				target = scope:old_holder
				opinion = -20
			}
			scope:activity = {
				add_activity_log_entry = {
					key = tournament_champion_battle_peasant_log
					character = root
					target = scope:battle_peasant

					#Effect
					root = {
						replace_court_position = {
							recipient = scope:battle_peasant
							holder = scope:old_holder
							court_position = champion_court_position
						}
					}
				}
			}
			stress_impact = {
				just = minor_stress_impact_gain
			}
		}
		else = {
			scope:activity = {
				add_activity_log_entry = {
					key = tournament_champion_battle_peasant_log
					character = root
					target = scope:battle_peasant

					#Effect
					root = {
						court_position_grant_effect = {
							EMPLOYER = root
							POS = champion
							CANDIDATE = scope:battle_peasant
						}
					}
				}
			}
		}
		reverse_add_opinion = {
			modifier = grateful_opinion
			target = scope:battle_peasant
			opinion = 20
		}
		scope:activity.activity_location.county = {
			add_county_modifier = {
				modifier = tournament_battle_peasant_county_modifier
				years = 10
			}
		}
		stress_impact = {
			greedy = medium_stress_impact_gain
			arrogant = medium_stress_impact_gain
		}
		ai_chance = {
			base = 5
			ai_value_modifier = {
				ai_compassion = 1.5
				ai_greed = -1.5
			}
		}
	}

	option = { # Recruit
		name = tournament_events.1230.b
		trigger = {
			number_of_knights < max_number_of_knights
			scope:battle_peasant = {
				can_be_knight_trigger = { ARMY_OWNER = root }
			}
		}
		every_knight = {
			custom = custom.every_knight
			add_opinion = {
				modifier = tournament_elevated_peasant_knight_opinion
				target = root
				opinion = -10
			}
		}
		scope:activity = {
			add_activity_log_entry = {
				key = tournament_recruited_battle_peasant_log
				character = root
				target = scope:battle_peasant

				#Effect
				root = {
					remove_short_term_gold = {
						value = minor_gold_value
						max = 20
					}
				}
			}
		}
		scope:battle_peasant = {
			hidden_effect = {
				set_employer = root
				set_knight_status = force
				add_to_activity = scope:activity
				scope:activity = {
					add_to_guest_subset = {
						name = contestant
						target = scope:battle_peasant						
					}
				}		
			}
			custom_tooltip = tournament_events.1230.b.tt
			custom_tooltip = tournament_events.1230.c.tt
			add_character_modifier = {
				modifier = tournament_battle_peasant_modifier
				years = 10
			}
			try_to_create_recurring_character_effect = { CHARACTER = root }
		}
		hidden_effect = { current_travel_plan = { add_companion = scope:battle_peasant } }
		reverse_add_opinion = {
			modifier = grateful_opinion
			target = scope:battle_peasant
			opinion = 10
		}
		scope:activity.activity_location.county = {
			add_county_modifier = {
				modifier = tournament_battle_peasant_county_modifier
				years = 10
			}
		}
		stress_impact = {
			greedy = medium_stress_impact_gain
			arrogant = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_compassion = 1
				ai_greed = -1
			}
		}
	}

	option = { # Sponsor
		name = tournament_events.1230.c
		scope:activity = {
			add_activity_log_entry = {
				key = tournament_sponsored_battle_peasant_log
				character = root
				target = scope:battle_peasant

				#Effect
				root = { 
					remove_short_term_gold = {
						value = tiny_gold_value 
						max = 10
					}
				}
			}
		}
		hidden_effect = { add_courtier = scope:battle_peasant }
		scope:battle_peasant = {
			hidden_effect = {
				add_to_activity = scope:activity
				scope:activity = {
					add_to_guest_subset = {
						name = contestant
						target = scope:battle_peasant						
					}
				}
			}
			custom_tooltip = tournament_events.1230.c.tt
			try_to_create_recurring_character_effect = { CHARACTER = root }
		}
		reverse_add_opinion = {
			modifier = grateful_opinion
			target = scope:battle_peasant
			opinion = 5
		}
		stress_impact = {
			greedy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 20
			ai_value_modifier = {
				ai_compassion = 0.5
				ai_greed = -0.5
			}
		}
	}

	option = { # Do nothing 
		name = tournament_events.1230.d
		custom_tooltip = tournament_events.1230.d.tt
		if = {
			limit = { activity_is_competing_trigger = yes } activity_tournament_change_contestant_score_effect = { SCORE = increase_miniscule }
		}
		hidden_effect = {
			scope:battle_peasant = {
				death = { death_reason = death_disappearance }
			}
		}
		stress_impact = {
			humble = medium_stress_impact_gain
			ambitious = medium_stress_impact_gain
			generous = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain
		}
		ai_chance = {
			base = 20
			ai_value_modifier = {
				ai_boldness = 1
				ai_rationality = -1
				ai_compassion = -1
				ai_greed = 1
			}
		}
	}
}

##################################################
# Worth Fighting For
# by Joe Parkin
# 1240
##################################################

scripted_trigger tournament_1240_prize_child_trigger = {
	liege = root
	is_landed = no
	age >= 12
	is_betrothed = no
	is_married = no
	NOT = {
		can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root }
	}
}

scripted_effect tournament_1240_prize_child_effect = {
	save_scope_as = marriage_prize
	if = {
		limit = {
			exists = mother
			mother = root
			father = {
				is_alive = yes
				liege = root
			}
		}
		father = { add_to_list = prize_child_parents }
	}
	if = {
		limit = {
			exists = mother
			mother = {
				is_alive = yes
				liege = root
			}
		}
		mother = { add_to_list = prize_child_parents }
	}
	if = {
		limit = { is_adult = no }
		custom_tooltip = tournament_events.1240.betrothal_tt
	}
	else = { custom_tooltip = tournament_events.1240.marry_tt }
	add_opinion = {
		modifier = tournament_marriage_prize_opinion
		target = root
		opinion = -10
	}
	if = {
		limit = {
			any_in_list = { list = prize_child_parents }
		}
		every_in_list = {
			list = prize_child_parents
			add_opinion = {
				modifier = tournament_marriage_prize_parent_opinion
				target = root
				opinion = -15
			}
		}
	}
	scope:activity = {
		set_variable = {
			name = tournament_marriage_prize
			value = scope:marriage_prize
		}
	}
}

tournament_events.1240 = {
	type = activity_event
	title = tournament_events.1240.t
	desc = tournament_events.1240.desc
	theme = tournament_grounds
	left_portrait = {
		character = root
		animation = worry
	}
	lower_right_portrait = { character = scope:prize_child_1 }
	lower_center_portrait = { character = scope:prize_child_2 }
	lower_left_portrait = { character = scope:prize_child_3 }
	cooldown = { years = 10 }

	trigger = {
		#DLC check.
		#has_ep2_dlc_trigger = yes
		
		#Standard checks.
		this = scope:host
		OR = {
			any_child = { tournament_1240_prize_child_trigger = yes }
			AND = {
				this = house.house_head
				any_courtier_or_guest = {
					house = root.house
					tournament_1240_prize_child_trigger = yes
				}
			}
		}
		# Only if we have at least 1 non-team phase
		scope:activity = {
			OR = {
				has_phase = tournament_phase_joust
				has_phase = tournament_phase_recital
				has_phase = tournament_phase_wrestling
				has_phase = tournament_phase_duel
				has_phase = tournament_phase_board_game
				has_phase = tournament_phase_archery
				has_phase = tournament_phase_horse_race
				#EK ADDITION
				has_phase = tournament_phase_arcane_clash
				#EK ADDITION END
			}
		}
	}

	immediate = {
		every_child = {
			limit = { tournament_1240_prize_child_trigger = yes }
			add_to_list = marriage_prize_list
		}
		if = {
			limit = { this = this.house.house_head }
			every_courtier_or_guest = {
				limit = {
					house = root.house
					tournament_1240_prize_child_trigger = yes
					NOT = {
						any_spouse = {
							count >= 1
							even_if_dead = yes
						}
					}
					age <= 35
				}
				add_to_list = marriage_prize_list
			}
		}
		hidden_effect = {
			while = {
				count = 3
				ordered_in_list = {
					list = marriage_prize_list
					limit = {
						NAND = {
							exists = scope:prize_child_1
							this = scope:prize_child_1
						}
						NAND = {
							exists = scope:prize_child_2
							this = scope:prize_child_2
						}
					}
					order_by = age
					if = {
						limit = {
							NOT = { exists = scope:prize_child_1 }
						}
						save_scope_as = prize_child_1
					}
					else_if = {
						limit = {
							NOT = { exists = scope:prize_child_2 }
						}
						save_scope_as = prize_child_2
					}
					else = { save_scope_as = prize_child_3 }
				}
			}
		}
	}

	option = { # First child
		name = tournament_events.1240.a
		scope:prize_child_1 = { tournament_1240_prize_child_effect = yes }
		stress_impact = {
			greedy = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain
		}
		ai_chance = {
			base = 5
			ai_value_modifier = {
				ai_boldness = 1
				ai_sociability = 1
				ai_rationality = -1
				ai_compassion = -1
				ai_honor = -1
			}
		}
	}

	option = { # Second child
		name = tournament_events.1240.b
		trigger = { exists = scope:prize_child_2 }
		scope:prize_child_2 = { tournament_1240_prize_child_effect = yes }
		stress_impact = {
			greedy = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain
		}
		ai_chance = {
			base = 5
			ai_value_modifier = {
				ai_boldness = 1
				ai_sociability = 1
				ai_rationality = -1
				ai_compassion = -1
				ai_honor = -1
			}
		}
	}

	option = { # Third child
		name = tournament_events.1240.c
		trigger = { exists = scope:prize_child_3 }
		scope:prize_child_3 = { tournament_1240_prize_child_effect = yes }
		stress_impact = {
			greedy = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain
		}
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_boldness = -1
				ai_sociability = -1
				ai_rationality = 1
				ai_honor = 1
				ai_compassion = 1
			}
		}
	}

	option = { # No
		name = tournament_events.1240.d
		if = {
			limit = { activity_is_competing_trigger = yes }
			activity_tournament_change_contestant_score_effect = { SCORE = increase_miniscule }
		}
		stress_impact = {
			generous = medium_stress_impact_gain
			arbitrary = medium_stress_impact_gain
		}
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_boldness = -1
				ai_sociability = -1
				ai_rationality = 1
				ai_honor = 1
				ai_compassion = 1
			}
		}
	}
}

##################################################
# Token of Favor
# by Joe Parkin
# 1250-1251
##################################################

scripted_trigger tournament_events_1250_favor_trigger = {
	is_participant_in_activity = root.involved_activity
	activity_is_valid_tournament_contestant = yes
	NAND = {
		exists = scope:favor_recipient_1
		this = scope:favor_recipient_1
	}
	NAND = {
		exists = scope:favor_recipient_2
		this = scope:favor_recipient_2
	}
	NAND = {
		exists = scope:favor_recipient_3
		this = scope:favor_recipient_3
	}
	NOT = {
		any_character_artifact = {
			artifact_type = tournament_favor
			creator = root
		}
	}
	NOT = {
		is_target_in_variable_list = {
			name = tournament_favor_offers
			target = root
		}
	}
}

scripted_effect tournament_events_1250_scope_effect = {
	if = {
		limit = {
			NOT = { exists = scope:favor_recipient_1 }
		}
		save_scope_as = favor_recipient_1
	}
	else_if = {
		limit = {
			NOT = { exists = scope:favor_recipient_2 }
		}
		save_scope_as = favor_recipient_2
	}
	else_if = {
		limit = {
			NOT = { exists = scope:favor_recipient_3 }
		}
		save_scope_as = favor_recipient_3
	}
}

scripted_effect tournament_favor_gift_effect = {
	save_scope_as = favor_recipient
	add_to_variable_list = {
		name = tournament_favor_offers
		target = scope:favor_giver
	}
	if = {
		limit = {
			is_scheming_against = { target = scope:favor_recipient }
		}
		random_scheme = {
			limit = { scheme_target_character = scope:favor_recipient }
			save_scope_as = favor_scheme
		}
	}
	custom_tooltip = tournament_events.1251.favor_tt
	custom_tooltip = tournament_events.1250.favor_tt
	show_as_tooltip = {
		random_list = {
			10 = {
				show_chance = no
				desc = tournament_favor_accepted_desc
				custom_tooltip = tournament_events_equip_favor_tt
				if = {
					limit = { is_ai = yes }
					add_opinion = {
						target = scope:favor_giver
						modifier = tournament_received_favor_opinion
						opinion = 10
					}
				}
				if = {
					limit = { exists = scope:favor_scheme }
					scope:favor_scheme = {
						add_scheme_modifier = { type = tournament_favor_scheme_modifier }
					}
				}
			}
			10 = {
				show_chance = no
				desc = tournament_favor_rejected_desc
				custom_tooltip = tournament_events_destroy_favor_tt
				if = {
					limit = { exists = scope:favor_scheme }
					scope:favor_scheme = {
						add_scheme_modifier = { type = tournament_favor_rejected_scheme_modifier }
					}
				}
			}
		}
	}
	trigger_event = {
		id = tournament_events.1251
		days = { 3 5 }
	}
}

tournament_events.1250 = {
	type = activity_event
	title = tournament_events.1250.t
	desc = tournament_events.1250.desc
	theme = tournament_grounds
	left_portrait = {
		character = root
		animation = flirtation_left
	}
	lower_right_portrait = { character = scope:favor_recipient_1 }
	lower_center_portrait = { character = scope:favor_recipient_2 }
	lower_left_portrait = { character = scope:favor_recipient_3 }
	cooldown = { years = 5 }

	trigger = {
		#DLC check.
		#has_ep2_dlc_trigger = yes
		
		#Standard checks.
		OR = {
			any_relation = {
				type = lover
				save_temporary_scope_as = favor_recipient_temp
			}
			AND = {
				has_activity_intent = woo_attendee_intent
				intent_target = { save_temporary_scope_as = favor_recipient_temp }
			}
			any_scheme = {
				scheme_type = seduce
				scheme_target_character = { save_temporary_scope_as = favor_recipient_temp }
			}
			any_scheme = {
				scheme_type = courting
				scheme_target_character = { save_temporary_scope_as = favor_recipient_temp }
			}
		}
		scope:favor_recipient_temp = { tournament_events_1250_favor_trigger = yes }
	}

	immediate = {
		save_scope_as = favor_giver
		hidden_effect = {
			while = {
				limit = {
					OR = {
						any_relation = {
							type = lover
							tournament_events_1250_favor_trigger = yes
						}
						AND = {
							has_activity_intent = woo_attendee_intent
							intent_target = { tournament_events_1250_favor_trigger = yes }
						}
						any_scheme = {
							scheme_type = seduce
							scheme_target_character = { tournament_events_1250_favor_trigger = yes }
						}
						any_scheme = {
							scheme_type = courting
							scheme_target_character = { tournament_events_1250_favor_trigger = yes }
						}
					}
					NAND = {
						exists = scope:favor_recipient_1
						exists = scope:favor_recipient_2
						exists = scope:favor_recipient_3
					}
				}
				random_list = {
					10 = {
						trigger = {
							any_relation = {
								type = lover
								tournament_events_1250_favor_trigger = yes
							}
						}
						random_relation = {
							type = lover
							limit = { tournament_events_1250_favor_trigger = yes }
							tournament_events_1250_scope_effect = yes
						}
					}
					10 = {
						trigger = {
							has_activity_intent = woo_attendee_intent
							intent_target = { tournament_events_1250_favor_trigger = yes }
						}
						intent_target = { tournament_events_1250_scope_effect = yes }
					}
					10 = {
						trigger = {
							any_scheme = {
								scheme_type = seduce
								scheme_target_character = { tournament_events_1250_favor_trigger = yes }
							}
						}
						random_scheme = {
							limit = {
								scheme_type = seduce
								scheme_target_character = { tournament_events_1250_favor_trigger = yes }
							}
							scheme_target_character = { tournament_events_1250_scope_effect = yes }
						}
					}
					10 = {
						trigger = {
							any_scheme = {
								scheme_type = courting
								scheme_target_character = { tournament_events_1250_favor_trigger = yes }
							}
						}
						random_scheme = {
							limit = {
								scheme_type = courting
								scheme_target_character = { tournament_events_1250_favor_trigger = yes }
							}
							scheme_target_character = { tournament_events_1250_scope_effect = yes }
						}
					}
				}
			}
		}
	}

	option = { # 1st
		name = tournament_events.1250.a
		trigger = {
			exists = scope:favor_recipient_1
			NOT = { root = scope:favor_recipient_1 }
		}
		scope:favor_recipient_1 = { tournament_favor_gift_effect = yes }
		if = {
			limit = {
				scope:favor_recipient_1 = {
					is_acclaimed = yes
				}
				scope:favor_recipient_1.accolade = {
					is_accolade_active = yes
				}
			}
			if = {
				limit = {
					highest_held_title_tier >= tier_kingdom
				}
				scope:favor_recipient_1.accolade = {
					add_glory = major_glory_gain
				}
			}
			else_if = {
				limit = {
					highest_held_title_tier >= tier_county
				}
				scope:favor_recipient_1.accolade = {
					add_glory = medium_glory_gain
				}
			}
			else_if = {
				limit = {
					highest_held_title_tier >= tier_county
				}
				scope:favor_recipient_1.accolade = {
					add_glory = minimal_glory_gain
				}
			}
		}
		ai_chance = {
			base = 10
			modifier = {
				factor = 1.5
				scope:favor_recipient_1 = { is_ai = no }
			}
			opinion_modifier = {
				opinion_target = scope:favor_recipient_1
				multiplier = 1
			}
		}
	}

	option = { # 2nd
		name = tournament_events.1250.b
		trigger = { exists = scope:favor_recipient_2 }
		scope:favor_recipient_2 = { tournament_favor_gift_effect = yes }
		if = {
			limit = {
				scope:favor_recipient_2 = {
					is_acclaimed = yes
				}
				scope:favor_recipient_2.accolade = {
					is_accolade_active = yes
				}
			}
			if = {
				limit = {
					highest_held_title_tier >= tier_kingdom
				}
				scope:favor_recipient_2.accolade = {
					add_glory = major_glory_gain
				}
			}
			else_if = {
				limit = {
					highest_held_title_tier >= tier_county
				}
				scope:favor_recipient_2.accolade = {
					add_glory = medium_glory_gain
				}
			}
			else_if = {
				limit = {
					highest_held_title_tier >= tier_county
				}
				scope:favor_recipient_2.accolade = {
					add_glory = minimal_glory_gain
				}
			}
		}
		ai_chance = {
			base = 10
			modifier = {
				factor = 1.5
				scope:favor_recipient_2 = { is_ai = no }
			}
			opinion_modifier = {
				opinion_target = scope:favor_recipient_2
				multiplier = 1
			}
		}
	}

	option = { # 3rd
		name = tournament_events.1250.c
		trigger = { exists = scope:favor_recipient_3 }
		scope:favor_recipient_3 = { tournament_favor_gift_effect = yes }
		if = {
			limit = {
				scope:favor_recipient_2 = {
					is_acclaimed = yes
				}
				scope:favor_recipient_2.accolade = {
					is_accolade_active = yes
				}
			}
			if = {
				limit = {
					highest_held_title_tier >= tier_kingdom
				}
				scope:favor_recipient_2.accolade = {
					add_glory = major_glory_gain
				}
			}
			else_if = {
				limit = {
					highest_held_title_tier >= tier_county
				}
				scope:favor_recipient_2.accolade = {
					add_glory = medium_glory_gain
				}
			}
			else_if = {
				limit = {
					highest_held_title_tier >= tier_county
				}
				scope:favor_recipient_2.accolade = {
					add_glory = minimal_glory_gain
				}
			}
		}
		ai_chance = {
			base = 10
			modifier = {
				factor = 1.5
				scope:favor_recipient_3 = { is_ai = no }
			}
			opinion_modifier = {
				opinion_target = scope:favor_recipient_3
				multiplier = 1
			}
		}
	}

	option = { # Nah
		name = tournament_events.1250.d
		ai_chance = {
			base = 0
		}
	}
}

tournament_events.1251 = {
	type = activity_event
	title = tournament_events.1251.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					OR = {
						AND = {
							is_male = yes
							faith = {
								NOT = { has_doctrine_parameter = adultery_male_accepted }
							}
						}
						AND = {
							is_female = yes
							faith = {
								NOT = { has_doctrine_parameter = adultery_female_accepted }
							}
						}
					}
					NOT = { is_consort_of = scope:favor_giver }
					OR = {
						is_married = yes
						scope:favor_giver = { is_married = yes }
					}
				}
				desc = tournament_events.1251.discrete
			}
			desc = tournament_events.1251.open
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					any_character_artifact = {
						count > 2
						artifact_type = tournament_favor
					}
				}
				desc = tournament_events.1251.many
			}
			triggered_desc = {
				trigger = {
					any_character_artifact = {
						count = 2
						artifact_type = tournament_favor
					}
				}
				desc = tournament_events.1251.two
			}
			desc = tournament_events.1251.one
		}
	}
	theme = tournament_grounds
	override_background = {
		trigger = {
			OR = {
				AND = {
					is_male = yes
					faith = {
						NOT = { has_doctrine_parameter = adultery_male_accepted }
					}
				}
				AND = {
					is_female = yes
					faith = {
						NOT = { has_doctrine_parameter = adultery_female_accepted }
					}
				}
			}
			NOT = { is_consort_of = scope:favor_giver }
			OR = {
				is_married = yes
				scope:favor_giver = { is_married = yes }
			}
		}
		reference = alley_day
	}
	left_portrait = {
		character = root
		animation = war_over_win
	}
	right_portrait = {
		character = scope:favor_giver
		animation = flirtation
	}
	artifact = {
		target = scope:newly_created_artifact
		position = lower_right_portrait
	}

	trigger = {
		#DLC check.
		#has_ep2_dlc_trigger = yes
		
		#Standard checks.
		exists = scope:favor_giver
		exists = scope:favor_recipient
	}

	immediate = {
		hidden_effect = {
			create_artifact_tournament_favor_effect = {
				OWNER = scope:favor_giver
				RECIPIENT = scope:favor_recipient
			}
		}
	}

	option = { # Thank you
		name = {
			text = tournament_events.1251.a.spouse
			trigger = { is_spouse_of = scope:favor_giver }
		}
		name = {
			text = tournament_events.1251.a.consort
			trigger = {
				NOT = { is_spouse_of = scope:favor_giver }
				is_consort_of = scope:favor_giver
			}
		}
		name = {
			text = tournament_events.1251.a.lover
			trigger = { has_relation_lover = scope:favor_giver }
		}
		name = {
			text = tournament_events.1251.a
			trigger = {
				NOR = {
					is_spouse_of = scope:favor_giver
					is_consort_of = scope:favor_giver
					has_relation_lover = scope:favor_giver
				}
			}
		}
		scope:activity = {
			add_activity_log_entry = {
				key = tournament_favor_given_log
				score = 25
				tags = { favors good }
				character = scope:favor_recipient

				# Effects
				show_as_tooltip = {
					scope:newly_created_artifact = { set_owner = scope:favor_recipient }
				}
			}
		}
		custom_tooltip = tournament_events.1251.favor_tt
		scope:favor_giver = {
			send_interface_toast = {
				type = event_toast_effect_good
				title = tournament_favor_accepted_title
				left_icon = scope:favor_recipient
				right_icon = scope:newly_created_artifact
				if = {
					limit = {
						scope:favor_recipient = { is_ai = yes }
					}
					scope:favor_recipient = {
						add_opinion = {
							target = scope:favor_giver
							modifier = tournament_received_favor_opinion
							opinion = 10
						}
					}
				}
				hidden_effect = {
					if = {
						limit = { exists = scope:favor_scheme }
						scope:favor_scheme = {
							add_scheme_modifier = { type = tournament_favor_scheme_modifier }
						}
					}
				}
			}
		}
		hidden_effect = {
			scope:newly_created_artifact = { equip_artifact_to_owner_replace = yes }
		}
	}

	option = { # Ew
		name = tournament_events.1251.b
		scope:favor_giver = {
			send_interface_toast = {
				type = event_toast_effect_bad
				title = tournament_favor_rejected_title
				left_icon = scope:favor_recipient
				scope:favor_recipient = { destroy_artifact = scope:newly_created_artifact }
				hidden_effect = {
					if = {
						limit = { exists = scope:favor_scheme }
						scope:favor_scheme = {
							add_scheme_modifier = { type = tournament_favor_rejected_scheme_modifier }
						}
					}
				}
			}
		}
		reverse_add_opinion = {
			target = scope:favor_giver
			modifier = tournament_spurned_favor_opinion
			opinion = -10
		}
	}
}

##################################################
# A Familiar Favor
# by Joe Parkin
# 1252-1253
##################################################

scripted_trigger tournament_familiar_favor_artifact_trigger = {
	artifact_type = tournament_favor
	trigger_if = {
		limit = { exists = var:favor_giver }
		var:favor_giver = {
			OR = {
				is_consort_of = root
				has_relation_lover = root
			}
		}
	}
	trigger_else = { always = no }
}

tournament_events.1252 = {
	type = activity_event
	title = tournament_events.1252.t
	desc = {
		desc = tournament_events.1252.desc
	}
	theme = tournament_locale_camp
	left_portrait = {
		character = root
		animation = worry
	}
	right_portrait = { character = scope:favor_giver }
	lower_right_portrait = scope:favor_recipient
	artifact = {
		target = scope:favor_artifact
		position = lower_center_portrait
	}
	cooldown = { years = 10 }

	trigger = {
		#DLC check.
		#has_ep2_dlc_trigger = yes
		
		#Standard checks.#
		scope:activity = {
			any_attending_character = {
				NOT = { this = root }
				OR = {
					is_consort_of = root
					has_relation_lover = root
				}
				save_temporary_scope_as = favor_giver_temp
			}
			any_attending_character = {
				NOR = {
					this = root
					is_consort_of = root
					has_relation_lover = root
				}
				any_equipped_character_artifact = { artifact_type = tournament_favor }
				OR = {
					is_consort_of = scope:favor_giver_temp
					has_relation_lover = scope:favor_giver_temp
					can_set_relation_lover_trigger = { CHARACTER = scope:favor_giver_temp }
				}
				save_temporary_scope_as = favor_recipient_temp
			}
		}
		NOT = {
			any_known_secret = {
				secret_type = secret_lover
				OR = {
					secret_owner = scope:favor_giver_temp
					secret_owner = scope:favor_recipient_temp
				}
				OR = {
					secret_target = scope:favor_giver_temp
					secret_target = scope:favor_recipient_temp
				}
			}
		}
		trigger_if = {
			limit = {
				scope:favor_giver_temp = { is_female = yes }
			}
			NOT = {
				faith = { has_doctrine_parameter = adultery_female_accepted }
			}
		}
		trigger_else = {
			NOT = {
				faith = { has_doctrine_parameter = adultery_male_accepted }
			}
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			factor = 0.5
			has_trait = dull
		}
		modifier = {
			factor = 0.5
			has_trait = intellect_bad
		}
		modifier = {
			factor = 0.5
			has_trait = trusting
		}
		modifier = {
			add = 1
			has_trait = paranoid
		}
		modifier = {
			factor = 2
			scope:activity = {
				any_attending_character = {
					NOR = {
						this = root
						is_consort_of = root
						has_relation_lover = root
					}
					any_character_artifact = { tournament_familiar_favor_artifact_trigger = yes }
				}
			}
		}
	}

	immediate = {
		save_scope_as = favor_investigator
		scope:activity = {
			hidden_effect = {
				random_list = {
					# Actual suspicious favor
					30 = {
						trigger = {
							any_attending_character = {
								NOR = {
									this = root
									is_consort_of = root
									has_relation_lover = root
								}
								any_equipped_character_artifact = { tournament_familiar_favor_artifact_trigger = yes }
							}
						}
						random_attending_character = {
							limit = {
								NOR = {
									this = root
									is_consort_of = root
									has_relation_lover = root
								}
								any_equipped_character_artifact = { tournament_familiar_favor_artifact_trigger = yes }
							}
							save_scope_as = favor_recipient
							random_equipped_character_artifact = {
								limit = { tournament_familiar_favor_artifact_trigger = yes }
								save_scope_as = favor_artifact
								var:favor_giver = { save_scope_as = favor_giver }
							}
						}
					}
					# Red herring favor
					10 = {
						random_attending_character = {
							limit = {
								NOR = {
									this = root
									is_consort_of = root
									has_relation_lover = root
								}
								any_equipped_character_artifact = { artifact_type = tournament_favor }
							}
							save_scope_as = favor_recipient
							random_equipped_character_artifact = {
								limit = { artifact_type = tournament_favor }
								save_scope_as = favor_artifact
							}
						}
						random_attending_character = {
							limit = {
								NOR = {
									this = root
									this = scope:favor_recipient
								}
								OR = {
									is_consort_of = root
									has_relation_lover = root
								}
							}
							save_scope_as = favor_giver
						}
					}
				}
			}

		}
	}

	option = { # Confront giver
		name = tournament_events.1252.a
		custom_tooltip = tournament_events.1252.a.tt
		scope:favor_giver = {
			trigger_event = {
				id = tournament_events.1253
				days = 1
			}
		}
		stress_impact = {
			trusting = medium_stress_impact_gain
			calm = medium_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_energy = 0.5
				ai_boldness = 0.5
			}
		}
	}

	option = { # No
		name = tournament_events.1252.b
		custom_tooltip = pregnancy.3001.b.tt
		stress_impact = {
			wrathful = medium_stress_impact_gain
			paranoid = medium_stress_impact_gain
			vengeful = medium_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_energy = -1
				ai_boldness = -1
			}
		}
	}
}

tournament_events.1253 = {
	type = activity_event
	title = tournament_events.1253.t
	desc = tournament_events.1253.desc
	theme = tournament_grounds
	left_portrait = {
		character = root
		animation = worry
	}
	right_portrait = {
		character = scope:favor_investigator
		animation = anger
	}
	lower_right_portrait = scope:favor_recipient
	artifact = {
		target = scope:favor_artifact
		position = lower_center_portrait
	}

	option = { #It is true!
		name = tournament_events.1253.a
		trigger = { this = scope:favor_artifact.var:favor_giver }
		custom_tooltip = reveal_illegitimate_pregnancy_to_real_father_tt
		stress_impact = {
			deceitful = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = 1
				ai_honor = 1
				ai_rationality = -1
			}
		}
		scope:favor_investigator = { trigger_event = tournament_events.1254 } #The truth is revealed to them
	}

	option = { #Insist it is not true
		name = tournament_events.1253.b
		stress_impact = {
			honest = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = -1
				ai_honor = -1
				ai_rationality = 1
			}
		}
		scope:favor_investigator = { trigger_event = tournament_events.1255 } #Denial
	}
}

tournament_events.1254 = {
	type = activity_event
	title = tournament_events.1254.t
	desc = tournament_events.1254.desc
	theme = tournament_grounds
	left_portrait = {
		character = root
		animation = stress
	}
	right_portrait = {
		character = scope:favor_giver
		animation = sadness
	}
	lower_right_portrait = { character = scope:favor_recipient }
	artifact = {
		target = scope:favor_artifact
		position = lower_center_portrait
	}

	immediate = {
		progress_towards_rival_effect = {
			REASON = rival_tournament_favor_jealousy
			CHARACTER = scope:favor_recipient
			OPINION = default_rival_opinion
		}
	}

	option = { # Damn!
		name = tournament_events.1254.a
		custom_tooltip = pregnancy.3003.a.tt
	}

	option = {
		name = tournament_events.1254.b
		expose_lover_secret_or_run_consequence_effect = {
			TARGET = scope:favor_giver
			EXPOSER = root
		}
	}
}

tournament_events.1255 = {
	type = activity_event
	title = tournament_events.1255.t
	desc = tournament_events.1255.desc
	theme = pregnancy
	left_portrait = {
		character = root
		animation = stress
	}
	right_portrait = {
		character = scope:favor_giver
		animation = war_over_win
	}
	lower_right_portrait = { character = scope:favor_recipient }
	artifact = {
		target = scope:favor_artifact
		position = lower_center_portrait
	}
	
	option = { #Are they really telling the truth?
		name = tournament_events.1255.a
	}	
}

##################################################
# Keeping the Peace
# by Joe Parkin
# 1260
##################################################

scripted_effect tournament_events_1260_duel_effect = {
	random_list = {
		50 = {
			min = 5
			tournament_duelists_modifier = yes
			modifier = {
				add = 10
				scope:duelist_1 = {
					has_any_bad_relationship_with_character_trigger = { CHARACTER = scope:duelist_2 }
				}
			}
			modifier = {
				exists = scope:encourage_duel
				add = 25
			}
			modifier = {
				exists = scope:duelist_diplomacy
				add = scope:duelist_diplomacy
			}
			hidden_effect = {
				scope:duelist_1 = {
					duel = {
						skill = prowess
						target = scope:duelist_2
						10 = {
							compare_modifier = {
								value = scope:duel_value
								multiplier = 3.5
								min = -49
							}
							save_scope_as = duel_winner
							scope:duelist_2 = { save_scope_as = duel_loser }
						}
						10 = {							
							compare_modifier = {
								value = scope:duel_value
								multiplier = -3.5
								min = -49
							}
							save_scope_as = duel_loser
							scope:duelist_2 = { save_scope_as = duel_winner }
						}
					}
				}
				send_interface_toast = {
					type = event_toast_effect_bad
					title = tournament_events.1260.duel_toast
					left_icon = scope:duel_winner
					right_icon = scope:duel_loser
					scope:activity = {
						if = {
							limit = {
								OR = {
									exists = scope:admonish_duel
									exists = scope:diplomacy_duel
								}
							}
							add_activity_log_entry = {
								key = tournament_failed_defuse_duel_log
								tags = { bad }
								score = 10
								character = root
								target = scope:duel_loser

								# Effect
								root = { add_prestige = minor_prestige_loss }
								scope:duel_loser = {
									increase_wounds_effect = { REASON = duel }
								}
								scope:duel_winner = {
									accolade_minor_glory_gain_with_checks_effect = yes
								}
								scope:duel_loser = {
									accolade_minimal_glory_loss_with_checks_effect = yes
								}
							}
						}
						else = {
							add_activity_log_entry = {
								key = tournament_encouraged_duel_log
								tags = { good }
								score = 10
								character = root
								target = scope:duel_loser

								# Effect
								scope:duel_loser = {
									increase_wounds_effect = { REASON = duel }
								}
								scope:duel_winner = {
									accolade_medium_glory_gain_with_checks_effect = yes
								}
								scope:duel_loser = {
									accolade_minimal_glory_loss_with_checks_effect = yes
								}
							}
						}
					}
				}
			}
			custom_tooltip = tournament_events.1260.duel_tt
		}
		50 = {
			min = 5
			modifier = {
				exists = scope:admonish_duel
				add = {
					value = dread
					multiply = 2
				}
			}			
			modifier = {
				exists = scope:diplomacy_duel
				add = {
					value = scope:host.diplomacy
					multiply = 2
				}
			}
			custom_tooltip = tournament_events.1260.peace_toast
			send_interface_toast = {
				type = event_toast_effect_neutral
				title = tournament_events.1260.peace_toast
				left_icon = scope:duelist_1
				right_icon = scope:duelist_2
				scope:activity = {
					add_activity_log_entry = {
						key = tournament_defused_duel_log
						tags = { good }
						score = 10
						character = root

						# Effects
						root = {
							if = {
								limit = {
									OR = {
										exists = scope:admonish_duel
										exists = scope:diplomacy_duel
									}
								}
								add_character_modifier = {
									modifier = tournament_kept_the_peace_modifier
									years = 10
								}
							}
						}
					}
				}
			}
		}
	}
	scope:duelist_1 = {
		try_to_create_recurring_character_effect = { CHARACTER = root }
	}
}

tournament_events.1260 = {
	type = activity_event
	title = tournament_events.1260.t
	desc = {
		desc = tournament_events.1260.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:duelist_1 = { has_relation_rival = scope:duelist_2 }
				}
				desc = tournament_events.1260.rival
			}
			desc = tournament_events.1260.fallback
		}
	}
	theme = tournament_locale_camp
	left_portrait = {
		character = scope:duelist_1
		animation = anger
	}
	right_portrait = {
		character = scope:duelist_2
		animation = throne_room_one_handed_passive_1
	}
	cooldown = { years = 1 }

	trigger = {
		#DLC check.
		#has_ep2_dlc_trigger = yes

		#Standard checks.
		this = scope:host
		scope:activity = {
			any_attending_character = {
				count >= 2
				NOT = { this = root }
				activity_is_valid_tournament_contestant = yes
			}
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			factor = 2
			has_activity_intent = recruit_knights_intent
		}
		modifier = {
			factor = 2
			scope:activity = {
				any_attending_character = {
					NOT = { this = root }
					activity_is_valid_tournament_contestant = yes
					save_temporary_scope_as = duelist_temp
				}
				any_attending_character = {
					NOR = {
						this = root
						this = scope:duelist_temp
					}
					activity_is_valid_tournament_contestant = yes
					has_any_bad_relationship_with_character_trigger = { CHARACTER = scope:duelist_temp }
				}
			}
		}
	}

	immediate = {
		scope:activity = {
			random_attending_character = {
				limit = {
					NOT = { this = root }
					activity_is_valid_tournament_contestant = yes
					save_temporary_scope_as = duelist_temp
				}
				weight = {
					base = 25
					modifier = {
						add = 50
						scope:activity = {
							any_attending_character = {
								NOR = {
									this = root
									this = scope:duelist_temp
								}
								activity_is_valid_tournament_contestant = yes
								has_any_bad_relationship_with_character_trigger = { CHARACTER = scope:duelist_temp }
							}
						}
					}
					tournament_duelists_modifier = yes
					activity_recurring_character_weight_modifier = { VALUE = 100 }
				}
				save_scope_as = duelist_1
				add_to_list = duelists
			}
			random_attending_character = {
				limit = {
					NOR = {
						this = root
						this = scope:duelist_1
					}
					activity_is_valid_tournament_contestant = yes
				}
				weight = {
					base = 25
					modifier = {
						add = 50
						has_any_bad_relationship_with_character_trigger = { CHARACTER = scope:duelist_1 }
						# Don't weight up a recurring character here, so that we still try to find someone who has a problem with the recurring char.
					}
					tournament_duelists_modifier = yes
				}
				save_scope_as = duelist_2
				add_to_list = duelists
				set_signature_weapon_effect = yes
			}
		}
		random_in_list = {
			list = duelists
			limit = { has_any_good_relationship_with_root_trigger = yes }
			alternative_limit = { is_close_family_of = root }
			alternative_limit = { is_consort_of = root }
			alternative_limit = { is_vassal_of = root }
			alternative_limit = { always = yes }
			save_scope_as = preferred_duelist
		}
		random_in_list = {
			list = duelists
			limit = {
				NOT = { this = scope:preferred_duelist }
			}
			save_scope_as = second_duelist
		}
		scope:duelist_1 = {
			progress_towards_rival_effect = {
				REASON = rival_tournament_duelist
				CHARACTER = scope:duelist_2
				OPINION = default_rival_opinion
			}
		}
		scope:duelist_1 = {
			add_character_flag = wear_armor
		}
		scope:duelist_2 = {
			add_character_flag = wear_armor
		}
	}

	option = { # Admonish
		name = tournament_events.1260.a
		every_in_list = {
			list = duelists
			add_opinion = {
				target = root
				modifier = tournament_admonished_duelist_opinion
				opinion = -10
			}
		}
		save_scope_as = admonish_duel
		tournament_events_1260_duel_effect = yes
		stress_impact = {
			arbitrary = medium_stress_impact_gain
			calm = medium_stress_impact_gain
			patient = medium_stress_impact_gain
			sadistic = medium_stress_impact_gain
		}
		ai_chance = {
			base = 5
			ai_value_modifier = {
				ai_compassion = 1.5
				ai_greed = -1.5
			}
		}
	}

	option = { # Defuse
		name = tournament_events.1260.b
		skill = diplomacy
		save_scope_value_as = {
			name = duelist_diplomacy
			value = {
				value = scope:duelist_1.diplomacy
				add = scope:duelist_2.diplomacy
				divide = 2
			}
		}
		save_scope_as = diplomacy_duel
		tournament_events_1260_duel_effect = yes
		stress_impact = {
			arbitrary = medium_stress_impact_gain
			wrathful = medium_stress_impact_gain
			impatient = medium_stress_impact_gain
			callous = medium_stress_impact_gain
			sadistic = medium_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_compassion = 1
				ai_greed = -1
			}
		}
	}

	option = { # Expel them
		name = tournament_events.1260.c
		if = {
			limit = { activity_is_competing_trigger = yes }
			activity_tournament_change_contestant_score_effect = { SCORE = increase_miniscule }
		}
		every_in_list = {
			list = duelists
			add_opinion = {
				target = root
				modifier = tournament_expelled_opinion
				opinion = -15
			}
			remove_from_activity = scope:activity
		}
		stress_impact = {
			just = medium_stress_impact_gain
			calm = medium_stress_impact_gain
			patient = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain
		}
		ai_chance = {
			base = 20
			ai_value_modifier = {
				ai_compassion = 0.5
				ai_greed = -0.5
			}
		}
	}

	option = { # Encourage
		name = tournament_events.1260.d
		save_scope_as = encourage_duel
		tournament_events_1260_duel_effect = yes
		stress_impact = {
			just = medium_stress_impact_gain
			calm = medium_stress_impact_gain
			patient = medium_stress_impact_gain
			craven = medium_stress_impact_gain
			shy = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain
		}
		ai_chance = {
			base = 20
			ai_value_modifier = {
				ai_compassion = 0.5
				ai_greed = -0.5
			}
		}
	}
	after = {
		scope:duelist_1 = {
			remove_character_flag = wear_armor
		}
		scope:duelist_2 = {
			remove_character_flag = wear_armor
		}
	}
}

##################################################
# Good Sport
# by Joe Parkin
# 1270
##################################################

scripted_trigger tournament_not_close_to_root_trigger = {
	is_alive = yes
	involved_activity = root.involved_activity
	NOR = {
		this = root
		is_consort_of = root
		is_close_family_of = root
		has_relation_friend = root
		has_relation_lover = root
	}
}

scripted_trigger tournament_past_losing_versus_contestant_trigger = {
	involved_activity = {
		NOT = { has_current_phase = tournament_phase_$CONTEST$ }
		trigger_if = {
			limit = {
				any_guest_subset = {
					name = winner
					tournament_not_close_to_root_trigger = yes
					phase = tournament_phase_$CONTEST$
				}
			}
		}
		trigger_else = { always = no }
	}
	trigger_if = {
		limit = { exists = var:contest_qualified_match_$CONTEST$ }	
		var:contest_qualified_match_$CONTEST$ = { tournament_not_close_to_root_trigger = yes }
	}
	trigger_else_if = {
		limit = { exists = var:contest_semi_finalist_match_$CONTEST$ }
		var:contest_semi_finalist_match_$CONTEST$ = { tournament_not_close_to_root_trigger = yes }
	}
	trigger_else_if = {
		limit = { exists = var:contest_finalist_match_$CONTEST$ }
		var:contest_finalist_match_$CONTEST$ = { tournament_not_close_to_root_trigger = yes }
	}
	trigger_else = { always = no }
}

scripted_trigger tournament_past_losing_contestant_trigger = {
	scope:activity = {
		NOT = { has_current_phase = tournament_phase_$CONTEST$ }
		any_guest_subset = {
			name = qualified
			this = root
			phase = tournament_phase_$CONTEST$
		}
		any_guest_subset = {
			name = winner
			NOR = {
				this = root
				is_consort_of = root
				is_close_family_of = root
				has_relation_friend = root
				has_relation_lover = root
			}
			phase = tournament_phase_$CONTEST$
		}
	}
}

scripted_effect tournament_1270_versus_effect = {
	if = {
		limit = {
			exists = var:contest_finalist_match_$CONTEST$
			var:contest_finalist_match_$CONTEST$ = { tournament_not_close_to_root_trigger = yes }
		}
		var:contest_finalist_match_$CONTEST$ = { save_scope_as = congratulate_winner }
	}
	else_if = {
		limit = {
			exists = var:contest_semi_finalist_match_$CONTEST$
			var:contest_semi_finalist_match_$CONTEST$ = { tournament_not_close_to_root_trigger = yes }
		}
		var:contest_semi_finalist_match_$CONTEST$ = { save_scope_as = congratulate_winner }
	}
	else_if = {
		limit = {
			exists = var:contest_qualified_match_$CONTEST$
			var:contest_qualified_match_$CONTEST$ = { tournament_not_close_to_root_trigger = yes }
		}
		var:contest_qualified_match_$CONTEST$ = { save_scope_as = congratulate_winner }
	}
	else = {
		random_guest_subset = {
			name = winner
			phase = tournament_phase_$CONTEST$
			save_scope_as = congratulate_winner
			try_to_create_recurring_character_effect = { CHARACTER = root }
		}
	}
}

tournament_events.1270 = {
	type = activity_event
	title = tournament_events.1270.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:activity = {
						any_guest_subset = {
							name = winner
							this = scope:congratulate_winner
						}
					}
				}
				desc = tournament_events.1270.winner
			}
			desc = tournament_events.1270.matcher
		}
		desc = tournament_events.1270.desc
	}
	theme = tournament_grounds
	left_portrait = {
		character = root
		animation = war_over_tie
	}
	right_portrait = {
		character = scope:congratulate_winner
		animation = war_over_win
	}
	cooldown = { years = 5 }

	trigger = {
		#DLC check.
		#has_ep2_dlc_trigger = yes
		has_activity_state = passive
		OR = {
			# VERSUS BOUT LOSSES
			tournament_past_losing_versus_contestant_trigger = { CONTEST = joust }
			tournament_past_losing_versus_contestant_trigger = { CONTEST = wrestling }
			tournament_past_losing_versus_contestant_trigger = { CONTEST = duel }
			tournament_past_losing_versus_contestant_trigger = { CONTEST = board_game }
			#EK ADDITION
			tournament_past_losing_versus_contestant_trigger = { CONTEST = arcane_clash }
			#EK ADDITION END
			# NON-TEAM CONTEST WINNERS
			tournament_past_losing_contestant_trigger = { CONTEST = joust }
			tournament_past_losing_contestant_trigger = { CONTEST = wrestling }
			tournament_past_losing_contestant_trigger = { CONTEST = duel }
			tournament_past_losing_contestant_trigger = { CONTEST = board_game }
			tournament_past_losing_contestant_trigger = { CONTEST = archery }
			tournament_past_losing_contestant_trigger = { CONTEST = recital }
			tournament_past_losing_contestant_trigger = { CONTEST = horse_race }
			#EK ADDITION
			tournament_past_losing_contestant_trigger = { CONTEST = arcane_clash }
			#EK ADDITION END
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			factor = 2
			OR = {
				has_activity_intent = befriend_attendee_intent
				has_activity_intent = woo_attendee_intent
			}
			scope:activity = {
				any_guest_subset = {
					name = winner
					this = root.intent_target
				}
			}
		}
	}

	immediate = {
		random_list = {
			10 = {
				trigger = {
					tournament_past_losing_versus_contestant_trigger = { CONTEST = joust }
				}
				tournament_1270_versus_effect = { CONTEST = joust }
			}
			10 = {
				trigger = {
					tournament_past_losing_versus_contestant_trigger = { CONTEST = wrestling }
				}
				tournament_1270_versus_effect = { CONTEST = wrestling }
			}
			10 = {
				trigger = {
					tournament_past_losing_versus_contestant_trigger = { CONTEST = duel }
				}
				tournament_1270_versus_effect = { CONTEST = duel }
			}
			10 = {
				trigger = {
					tournament_past_losing_versus_contestant_trigger = { CONTEST = board_game }
				}
				tournament_1270_versus_effect = { CONTEST = board_game }
			}
			#EK ADDITION
			10 = {
				trigger = {
					tournament_past_losing_versus_contestant_trigger = { CONTEST = arcane_clash }
				}
				tournament_1270_versus_effect = { CONTEST = arcane_clash }
			}
			#EK ADDITION END
			50 = {
				trigger = {
					tournament_past_losing_contestant_trigger = { CONTEST = joust }
				}
				scope:activity = {
					random_guest_subset = {
						name = winner
						phase = tournament_phase_joust
						save_scope_as = congratulate_winner
						try_to_create_recurring_character_effect = { CHARACTER = root }
					}
				}
			}
			50 = {
				trigger = {
					tournament_past_losing_contestant_trigger = { CONTEST = wrestling }
				}
				scope:activity = {
					random_guest_subset = {
						name = winner
						phase = tournament_phase_wrestling
						save_scope_as = congratulate_winner
						try_to_create_recurring_character_effect = { CHARACTER = root }
					}
				}
			}
			50 = {
				trigger = {
					tournament_past_losing_contestant_trigger = { CONTEST = duel }
				}
				scope:activity = {
					random_guest_subset = {
						name = winner
						phase = tournament_phase_duel
						save_scope_as = congratulate_winner
						try_to_create_recurring_character_effect = { CHARACTER = root }
					}
				}
			}
			50 = {
				trigger = {
					tournament_past_losing_contestant_trigger = { CONTEST = board_game }
				}
				scope:activity = {
					random_guest_subset = {
						name = winner
						phase = tournament_phase_board_game
						save_scope_as = congratulate_winner
						try_to_create_recurring_character_effect = { CHARACTER = root }
					}
				}
			}
			50 = {
				trigger = {
					tournament_past_losing_contestant_trigger = { CONTEST = archery }
				}
				scope:activity = {
					random_guest_subset = {
						name = winner
						phase = tournament_phase_archery
						save_scope_as = congratulate_winner
						try_to_create_recurring_character_effect = { CHARACTER = root }
					}
				}
			}
			50 = {
				trigger = {
					tournament_past_losing_contestant_trigger = { CONTEST = recital }
				}
				scope:activity = {
					random_guest_subset = {
						name = winner
						phase = tournament_phase_recital
						save_scope_as = congratulate_winner
						try_to_create_recurring_character_effect = { CHARACTER = root }
					}
				}
			}
			50 = {
				trigger = {
					tournament_past_losing_contestant_trigger = { CONTEST = horse_race }
				}
				scope:activity = {
					random_guest_subset = {
						name = winner
						phase = tournament_phase_horse_race
						save_scope_as = congratulate_winner
						try_to_create_recurring_character_effect = { CHARACTER = root }
					}
				}
			}
			#EK ADDITION
			50 = {
				trigger = {
					tournament_past_losing_contestant_trigger = { CONTEST = arcane_clash }
				}
				scope:activity = {
					random_guest_subset = {
						name = winner
						phase = tournament_phase_arcane_clash
						save_scope_as = congratulate_winner
						try_to_create_recurring_character_effect = { CHARACTER = root }
					}
				}
			}
			#EK ADDITION END
		}
	}

	option = { # Toast
		name = tournament_events.1270.a
		trigger = {
			NOT = {
				has_relation_rival = scope:congratulate_winner
			}
		}
		scope:congratulate_winner = {
			if = {
				limit = { has_any_nickname = no }
				random = {
					chance = 33
					root = {
						send_interface_toast = {
							type = event_toast_effect_good
							title = tournament_events.1270.nickname_toast
							left_icon = scope:congragulate_winner
							scope:congratulate_winner = { give_nickname = nick_the_champion }
						}
					}
				}
			}
		}
		if = {
			limit = {
				highest_held_title_tier >= tier_kingdom
			}
			scope:congratulate_winner = {
				accolade_medium_glory_gain_with_checks_effect = yes
			}
		}
		else = {
			scope:congratulate_winner = {
				accolade_minor_glory_gain_with_checks_effect = yes
			}
		}
		
		progress_towards_friend_effect = {
			REASON = friend_toasted_contest_victory
			CHARACTER = scope:congratulate_winner
			OPINION = 0
		}
		reverse_add_opinion = {
			target = scope:congratulate_winner
			modifier = tournament_congratulate_toast_opinion
			opinion = 20
		}
		stress_impact = {
			arrogant = major_stress_impact_gain
			callous = major_stress_impact_gain
			shy = major_stress_impact_gain
		}
		if = {
			limit = {
				OR = {
					has_activity_intent = win_contest_intent
					has_relation_rival = scope:congratulate_winner
				}
			}
			stress_impact = {
				vengeful = major_stress_impact_gain
			}
		}
		ai_chance = {
			base = 10
			modifier = {
				add = 100
				has_activity_intent = befriend_attendee_intent
				intent_target = scope:congratulate_winner
			}
			ai_value_modifier = {
				ai_compassion = 0.5
				ai_honor = 0.25
			}
		}
	}

	option = { # Congratulate
		name = tournament_events.1270.b
		if = {
			limit = {
				highest_held_title_tier >= tier_kingdom
			}
			scope:congratulate_winner = {
				accolade_minor_glory_gain_with_checks_effect = yes
			}
		}
		else = {
			scope:congratulate_winner = {
				accolade_minimal_glory_gain_with_checks_effect = yes
			}
		}
		reverse_add_opinion = {
			target = scope:congratulate_winner
			modifier = tournament_congratulate_opinion
			opinion = 10
		}
		stress_impact = {
			arrogant = medium_stress_impact_gain
			callous = medium_stress_impact_gain
			shy = medium_stress_impact_gain
		}
		if = {
			limit = {
				OR = {
					has_activity_intent = win_contest_intent
					has_relation_rival = scope:congratulate_winner
				}
			}
			stress_impact = {
				vengeful = medium_stress_impact_gain
			}
		}
		ai_chance = {
			base = 50
			opinion_modifier = {
				opinion_target = scope:congratulate_winner
				multiplier = 0.5
			}
			ai_value_modifier = {
				ai_compassion = 1
				ai_honor = 0.5
			}
		}
	}

	option = { # Vague
		name = tournament_events.1270.c
		if = {
			limit = {
				highest_held_title_tier >= tier_kingdom
			}
			scope:congratulate_winner = {
				accolade_minimal_glory_loss_with_checks_effect = yes
			}
		}
		reverse_add_opinion = {
			target = scope:congratulate_winner
			modifier = tournament_congratulate_vague_opinion
			opinion = -10
		}
		stress_impact = {
			humble = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain
			forgiving = medium_stress_impact_gain
			shy = medium_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_boldness = 0.5
				ai_vengefulness = 0.5
				ai_compassion = -0.5
			}
			modifier = {
				has_relation_rival = scope:congratulate_winner
				factor = 2
			}
			modifier = {
				has_activity_intent = win_contest_intent
				factor = 1.5
			}
			modifier = {
				opinion = {
					target = scope:congratulate_winner
					value <= 0
				}
				add = 15
			}
		}
	}

	option = { # Walk away
		name = tournament_events.1270.d
		add_prestige = minor_prestige_loss
		stress_impact = {
			brave = medium_stress_impact_gain
			gregarious = medium_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_boldness = -1
				ai_honor = -0.5
			}
			opinion_modifier = {
				opinion_target = scope:congratulate_winner
				multiplier = 0.5
			}
		}
	}
}

##################################################
# Sloppy Standards
# by Joe Parkin
# 1280
##################################################

tournament_events.1280 = {
	type = activity_event
	title = tournament_events.1280.t
	desc = tournament_events.1280.desc
	window = widget_activity_locale_fullscreen_event
	theme = tournament_grounds
	left_portrait = {
		character = root
		animation = shock
	}
	right_portrait = {
		character = scope:intercessor
		animation = beg
	}
	lower_right_portrait = scope:collapse_victim
	cooldown = { years = 2 }

	trigger = {
		#DLC check.
		#has_ep2_dlc_trigger = yes

		#Standard checks.
		this = scope:host
		NOR = {
			exists = dynasty.var:tournament_1280_cooldown
			has_character_flag = tournament_host_disaster_cooldown
		}
		NOR = {
			government_has_flag = government_is_tribal
			government_has_flag = government_is_nomadic
		}
		culture = { has_cultural_era_or_later = culture_era_high_medieval }
	}

	weight_multiplier = {
		base = 1
		modifier = {
			factor = 2
			scope:activity = {
				has_activity_option = {
					category = tournament_option_accommodations
					option = tournament_accommodations_bad
				}
			}
		}
		modifier = {
			factor = 0.5
			scope:activity = {
				has_activity_option = {
					category = tournament_option_accommodations
					option = tournament_accommodations_good
				}
			}
		}
		modifier = {
			factor = 2
			scope:activity.activity_location = { has_building_or_higher = jousting_lists_01 }
		}
		modifier = {
			add = {
				value = scope:activity.activity_location.county.development_level
				divide = 2
			}
		}
	}

	immediate = {
		add_character_flag = {
			flag = tournament_host_disaster_cooldown
			years = 5
		}
		dynasty ?= {
			set_variable = {
				name = tournament_1280_cooldown
				years = 75
			}
		}
		scope:activity = {
			random_attending_character = {
				limit = {
					is_adult = yes
					OR = {
						has_trait = compassionate
						has_trait = patient
						has_trait = humble
					}
					NOR = {
						this = root
						has_any_bad_relationship_with_character_trigger = { CHARACTER = root }
					}
				}
				alternative_limit = {
					is_adult = yes
					NOR = {
						this = root
						has_any_bad_relationship_with_character_trigger = { CHARACTER = root }
					}
				}
				weight = {
					base = 1
					modifier = { factor = ai_honor }
					modifier = { factor = ai_compassion }
					modifier = {
						factor = {
							value = ai_rationality
							divide = 2
						}
					}
					modifier = {
						factor = {
							value = 0
							subtract = ai_boldness
						}
					}
					modifier = {
						factor = {
							value = 0
							subtract = ai_energy
						}
					}
					modifier = {
						factor = 10
						exists = primary_spouse
						this = root.primary_spouse
					}
					modifier = {
						factor = 10
						is_consort_of = root
					}
					modifier = {
						factor = 10
						is_powerful_vassal_of = root
					}
					modifier = {
						factor = 10
						is_clergy = yes
					}
					modifier = {
						factor = 10
						is_landed = yes
						primary_title.title_province.duchy ?= scope:activity.activity_location.duchy
					}
					# Put this at the bottom to not mess up Joe's delicate factor work; weighted it up a bit more to actually try to drag in recurring characters.
					activity_recurring_character_weight_modifier = { VALUE = 1000 }
				}
				save_scope_as = intercessor
				try_to_create_recurring_character_effect = { CHARACTER = root }
			}
			hidden_effect = {
				random = {
					chance = 33
					random_attending_character = {
						limit = {
							is_ai = yes
							NOR = {
								this = root
								exists = var:contest_aptitude
								is_close_or_extended_family_of = root
								is_landed = yes
							}
						}
						save_scope_as = collapse_victim
					}
				}
			}
			scope:activity = {
				add_activity_log_entry = {
					key = tournament_collapsed_stand_log
					tags = { bad }
					score = 50
					character = scope:host

					# Effect
					scope:activity.activity_location.county = {
						add_county_modifier = {
							modifier = tournament_stands_collapsed_modifier
							years = 5
						}
					}
				}
			}
		}
		if = {
			limit = { exists = scope:collapse_victim }
			scope:collapse_victim = {
				death = { death_reason = death_tournament_stands_collapsed }
				if = {
					limit = {
						any_close_family_member = { count > 0 }
					}
					every_close_family_member = {
						add_opinion = {
							target = root
							modifier = tournament_collapse_victim_family_opinion
							opinion = -20
						}
					}
				}
			}
		}
	}

	option = { # Execute workers
		name = tournament_events.1280.a
		add_dread = minor_dread_gain
		add_character_modifier = {
			modifier = tournament_executed_builders_modifier
			years = 5
		}
		reverse_add_opinion = {
			target = scope:intercessor
			modifier = tournament_executed_workers_opinion
			opinion = -20
		}
		stress_impact = {
			compassionate = medium_stress_impact_gain
			forgiving = medium_stress_impact_gain
			calm = medium_stress_impact_gain
		}
		ai_chance = {
			base = 10
			opinion_modifier = {
				opinion_target = scope:intercessor
				multiplier = -0.5
			}
			ai_value_modifier = {
				ai_compassion = -1
				ai_boldness = 1
				ai_vengefulness = 1
			}
		}
	}

	option = { # Compensate
		name = tournament_events.1280.b
		if = {
			limit = {
				faith = {
					OR = {
						trait_is_virtue = generous
						trait_is_virtue = compassionate
					}
				}
			}
			add_piety = medium_piety_gain
		}
		remove_short_term_gold = medium_gold_value
		add_character_modifier = {
			modifier = tournament_compensated_stands_modifier
			years = 5
		}
		reverse_add_opinion = {
			target = scope:intercessor
			modifier = tournament_compensated_victims_opinion
			opinion = 20
		}
		scope:activity.activity_location.county = {
			remove_county_modifier = tournament_stands_collapsed_modifier
			add_county_modifier = {
				modifier = tournament_stands_compensated_modifier
				years = 5
			}
		}		
		stress_impact = {
			greedy = medium_stress_impact_gain
			arrogant = medium_stress_impact_gain
			callous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 50
			opinion_modifier = {
				opinion_target = scope:intercessor
				multiplier = 1
			}
			ai_value_modifier = {
				ai_compassion = 1
				ai_honor = 1
				ai_vengefulness = -0.5
			}
		}
	}

	option = { # Stay hand
		name = tournament_events.1280.c
		add_prestige = minor_prestige_loss
		reverse_add_opinion = {
			target = scope:intercessor
			modifier = tournament_spared_workers_opinion
			opinion = 10
		}
		stress_impact = {
			arbitrary = medium_stress_impact_gain
			wrathful = medium_stress_impact_gain
			stubborn = medium_stress_impact_gain
		}
		ai_chance = {
			base = 50
			opinion_modifier = {
				opinion_target = scope:intercessor
				multiplier = 0.5
			}
			ai_value_modifier = {
				ai_compassion = 0.5
				ai_honor = 0.5
				ai_vengefulness = -0.5
			}
		}
	}
}

##################################################
# Unmanageable Miscreants
# by Joe Parkin
# 1290
##################################################

scripted_trigger tournament_squire_fire_holder_trigger = {
	OR = {
		any_held_title = {
			OR = {
				AND = {
					tier = tier_county
					this = scope:fire_holding.county
				}
				AND = {
					tier = tier_barony
					county = scope:fire_holding.county
				}
			}
		}
		AND = {
			save_temporary_scope_as = lessee_temp
			scope:fire_holding.barony.county = {
				any_county_province = {
					barony = {
						exists = lessee
						lessee = scope:lessee_temp
					}
				}
			}
		}
	}
}

tournament_events.1290 = {
	type = activity_event
	title = tournament_events.1290.t
	desc = tournament_events.1290.desc
	theme = tournament_grounds
	override_background = { reference = burning_building }
	left_portrait = {
		character = root
		animation = war_over_win
	}
	right_portrait = {
		character = scope:fire_holder
		animation = anger
	}
	cooldown = { years = 25 }

	trigger = {
		#Standard checks.
		this = scope:host
		NOR = {
			exists = dynasty.var:tournament_1290_cooldown
			has_character_flag = tournament_host_disaster_cooldown
		}
		scope:activity = {
			activity_location = {
				num_buildings >= 1
				NOT = { has_holding_type = tribal_holding }
			}
			any_attending_character = {
				NOT = { this = root }
				is_adult = yes
				is_participant_in_activity = scope:activity
			}
			# Stop this firing at the beginning of a tournament
			num_past_phases >= 1
		}
	}

	weight_multiplier = {
		base = 1
	}

	immediate = {
		add_character_flag = {
			flag = tournament_host_disaster_cooldown
			years = 5
		}
		save_scope_value_as = {
			name = development_loss
			value = {
				integer_range = { min = -1 max = -1 }
			}
		}
		dynasty = {
			set_variable = {
				name = tournament_1290_cooldown
				years = 75
			}
		}
		scope:activity = {
			activity_location = {
				save_scope_as = fire_holding
				barony = {
					if = {
						limit = {
							exists = holder
							NOT = { holder = root }
						}
						holder = { add_to_list = fire_barons }
					}
					if = {
						limit = {
							exists = lessee
							NOT = { lessee = root }
						}
						lessee = { add_to_list = fire_barons }
					}
				}
			}
			add_activity_log_entry = {
				key = tournament_squire_fire_log
				tags = { bad }
				score = 25
				character = root

				# Effect
				scope:activity.activity_location = {
					destroy_random_building_variable_effect = yes
					destroy_random_building_effect = yes
					county = {
						add_county_modifier = {
							modifier = tournament_squire_riot_modifier
							years = 5
						}
					}
				}
			}
		}
		every_councillor = {
			limit = {
				is_adult = yes
				is_participant_in_activity = scope:activity
			}
			add_to_list = fire_barons
		}
		every_courtier = {
			limit = {
				is_adult = yes
				is_participant_in_activity = scope:activity
			}
			add_to_list = fire_barons
		}
		random_in_list = {
			list = fire_barons
			limit = {
				NOT = {
					has_any_bad_relationship_with_character_trigger = { CHARACTER = root }
				}
				exists = primary_title.title_province
				primary_title.title_province = scope:fire_holding
			}
			alternative_limit = {
				NOT = {
					has_any_bad_relationship_with_character_trigger = { CHARACTER = root }
				}
				tournament_squire_fire_holder_trigger = yes
			}
			alternative_limit = {
				NOT = {
					has_any_bad_relationship_with_character_trigger = { CHARACTER = root }
				}
			}
			weight = {
				base = 1
				# Adding this at the top to not mess up Joe's delicate factor work too heavily.
				activity_recurring_character_weight_modifier = { VALUE = 5 }
				modifier = {
					is_councillor = yes
					factor = 10
				}
				modifier = { factor = ai_honor }
				modifier = { factor = ai_compassion }
				modifier = {
					factor = {
						value = ai_rationality
						divide = 2
					}
				}
				modifier = {
					factor = {
						value = 0
						subtract = ai_boldness
					}
				}
				modifier = {
					factor = {
						value = 0
						subtract = ai_energy
					}
				}
				modifier = {
					factor = 10
					is_consort_of = root
				}
				modifier = {
					factor = 5
					is_powerful_vassal_of = root
				}
				modifier = {
					factor = 5
					is_clergy = yes
				}
				modifier = {
					factor = 2
					OR = {
						has_trait = compassionate
						has_trait = humble
					}
				}
				modifier = {
					factor = 2
					this = scope:activity.activity_location.county.holder
				}
				modifier = {
					factor = 0
					OR = {
						has_trait = callous
						has_trait = cynical
					}
				}
			}
			save_scope_as = fire_holder
			try_to_create_recurring_character_effect = { CHARACTER = root }
		}
	}

	option = { # Punish squires
		name = tournament_events.1290.a
		every_in_list = {
			list = fire_barons
			limit = { tournament_squire_fire_holder_trigger = yes }
			add_opinion = {
				target = root
				modifier = tournament_punished_arsonists_opinion
				opinion = 10
			}
		}
		scope:activity = {
			add_activity_log_entry = {
				key = tournament_squire_fire_punished_log
				tags = { bad }
				score = 25
				character = root

				# Effect
				root = {
					add_dread = minor_dread_gain
					add_character_modifier = {
						modifier = tournament_punished_arsonists_modifier
						years = 5
					}
				}
				scope:fire_holding.county = {
					add_county_modifier = {
						modifier = recent_arson_modifier
						years = 20
					}
				}
			}
		}
		stress_impact = {
			compassionate = medium_stress_impact_gain
			forgiving = medium_stress_impact_gain
			calm = medium_stress_impact_gain
		}
		ai_chance = {
			base = 10
			opinion_modifier = {
				opinion_target = scope:fire_holder
				multiplier = 0.5
			}
			ai_value_modifier = {
				ai_compassion = -1
				ai_vengefulness = 1
				ai_boldness = 1
			}
		}
	}

	option = { # Donate building materials
		name = tournament_events.1290.b
		every_in_list = {
			list = fire_barons
			limit = { tournament_squire_fire_holder_trigger = yes }
			add_opinion = {
				target = root
				modifier = tournament_donated_materials_opinion
				opinion = 20
			}
		}
		scope:activity = {
			add_activity_log_entry = {
				key = tournament_squire_fire_donate_log
				tags = { bad }
				score = 25
				character = root

				# Effect
				root = { remove_short_term_gold = major_gold_value }
				scope:fire_holding.county = {
					add_county_modifier = {
						modifier = arson_rebuilding_modifier
						years = 20
					}
				}
			}
		}
		stress_impact = {
			arbitrary = medium_stress_impact_gain
			wrathful = medium_stress_impact_gain
			stubborn = medium_stress_impact_gain
			greedy = medium_stress_impact_gain
		}
		ai_chance = {
			base = 50
			opinion_modifier = {
				opinion_target = scope:fire_holder
				multiplier = 1
			}
			modifier = {
				factor = 0
				short_term_gold < major_gold_value
			}
			ai_value_modifier = {
				ai_compassion = 0.5
				ai_honor = 0.5
				ai_greed = -1
				ai_vengefulness = -1
			}
		}
	}

	option = { # Oh well
		name = tournament_events.1290.c
		every_in_list = {
			list = fire_barons
			limit = { tournament_squire_fire_holder_trigger = yes }
			add_opinion = {
				target = root
				modifier = tournament_fire_uncompensated_opinion
				opinion = -10
			}
		}
		scope:activity = {
			add_activity_log_entry = {
				key = tournament_squire_fire_dismiss_log
				tags = { bad }
				score = 25
				character = root

				root = {
					add_prestige = minor_prestige_loss
					add_character_modifier = {
						modifier = tournament_coddled_arsonists_modifier
						years = 5
					}
				}
				scope:fire_holding.county = {
					add_county_modifier = {
						modifier = recent_arson_modifier
						years = 20
					}
				}
			}
		}
		stress_impact = {
			improvident = medium_stress_impact_gain
			generous = medium_stress_impact_gain
			fickle = medium_stress_impact_gain
		}
		ai_chance = {
			base = 50
			opinion_modifier = {
				opinion_target = scope:fire_holder
				multiplier = -1
			}
			ai_value_modifier = {
				ai_compassion = 1
				ai_honor = 1
				ai_greed = 0.5
				ai_vengefulness = -0.5
			}
		}
	}
}


#Aging knight takes a young one under his wing
#by Nick Meredith
tournament_events.1300 = {
	type = activity_event
	title = tournament_events.1300.t
	desc = tournament_events.1300.desc
	theme = martial
	override_background = { reference = army_camp }
	left_portrait = {
		character = scope:old_knight
		animation = personality_honorable
	}
	right_portrait = {
		character = scope:young_knight
		animation = admiration
	}
	lower_center_portrait = {
		character = root
	}

	trigger = {
		this = scope:host
		any_knight = {
			ek_human_age_equivalent >= 55 #EK EDIT: age equivalency
			location = root.location
			is_ai = yes
			is_adult = yes
		}

		any_knight = {
			age <= 30
			location = root.location
			is_ai = yes
			is_adult = yes
			has_trait = tourney_participant
		}
	}

	immediate = {
		random_knight = {
			limit = {
				ek_human_age_equivalent >= 55 #EK EDIT: age equivalency
				location = root.location
				is_ai = yes
				is_adult = yes		
			}
			weight = {
				base = 1
				activity_recurring_character_weight_modifier = { VALUE = 100 }
			}
			save_scope_as = old_knight
		}

		random_knight = {
			limit = {
				age <= 30
				location = root.location
				is_ai = yes
				is_adult = yes
				has_trait = tourney_participant	
			}
			weight = {
				base = 1
				activity_recurring_character_weight_modifier = { VALUE = 100 }
			}
			save_scope_as = young_knight
		}
	}

	# Encourage them
	option = {
		name = tournament_events.1300.a

		scope:young_knight = {
			accolade_medium_glory_gain_with_checks_effect = yes
			random_list = {
				1 = {
					add_trait_xp = {
						trait = tourney_participant
						track = foot
						value = 10
					}
				}
				1 = {
					add_trait_xp = {
						trait = tourney_participant
						track = bow
						value = 10
					}
				}
				1 = {
					add_trait_xp = {
						trait = tourney_participant
						track = horse
						value = 10
					}
				}
				1 = {
					add_trait_xp = {
						trait = tourney_participant
						track = wit
						value = 10
					}
				}
			}
			progress_towards_friend_effect = {
				REASON = friend_tournament_tutor
				CHARACTER = scope:old_knight
				OPINION = 20
			}

			if = {
				limit = { activity_is_competing_trigger = yes }
				activity_tournament_change_contestant_score_effect = { SCORE = increase_miniscule }
			}
		}
		scope:old_knight = {
			accolade_minor_glory_gain_with_checks_effect = yes
		}

		stress_impact = {
			compassionate = miniscule_stress_impact_loss
			callous = medium_stress_impact_gain
			humble = miniscule_stress_impact_loss
			arrogant = minor_stress_impact_gain
		}

		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				has_trait = callous
			}
		}
	}

	# Say that you'll tutor the young knight instead
	option = {
		name = tournament_events.1300.b
		duel = {
			skills = { martial diplomacy }
			value = decent_skill_rating
			50 = { #It works well
				custom_tooltip = tournament_events.1300.b.success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 0.5
				}
				scope:young_knight = {
					hidden_effect = {
						random_list = {
							1 = {
								add_trait_xp = {
									trait = tourney_participant
									track = foot
									value = 10
								}
							}
							1 = {
								add_trait_xp = {
									trait = tourney_participant
									track = bow
									value = 10
								}
							}
							1 = {
								add_trait_xp = {
									trait = tourney_participant
									track = horse
									value = 10
								}
							}
							1 = {
								add_trait_xp = {
									trait = tourney_participant
									track = wit
									value = 10
								}
							}
						}
						accolade_major_glory_gain_with_checks_effect = yes
					}
				}
				send_interface_toast = {
					type = event_toast_effect_good
					title = tournament_events.1300.b.success
					left_icon = root
					right_icon = scope:young_knight
					progress_towards_friend_effect = {
						REASON = friend_bonded_during_tournament
						CHARACTER = scope:young_knight
						OPINION = default_friend_opinion
					}
				}
			}
			50 = { #It doesn't go well
				custom_tooltip = tournament_events.1300.b.failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -0.5
				}
				hidden_effect = {
					scope:young_knight = {
						random_list = {
							1 = {
								add_trait_xp = {
									trait = tourney_participant
									track = foot
									value = -5
								}
							}
							1 = {
								add_trait_xp = {
									trait = tourney_participant
									track = bow
									value = -5
								}
							}
							1 = {
								add_trait_xp = {
									trait = tourney_participant
									track = horse
									value = -5
								}
							}
							1 = {
								add_trait_xp = {
									trait = tourney_participant
									track = wit
									value = -5
								}
							}
						}
						accolade_medium_glory_loss_with_checks_effect = yes
					}
				}
				send_interface_toast = {
					type = event_toast_effect_bad
					title = tournament_events.1300.b.failure
					left_icon = root
					right_icon = scope:young_knight
					add_opinion = {
						target = scope:young_knight
						modifier = angry_opinion
						opinion = -30
					}
				}
			}
		}
		scope:young_knight = {
			try_to_create_recurring_character_effect = { CHARACTER = root }
		}
		reverse_add_opinion = {
			target = scope:old_knight
			modifier = disappointed_opinion
			opinion = -15
		}
		stress_impact = {
			stubborn = miniscule_stress_impact_loss
			fickle = medium_stress_impact_gain
			arrogant = miniscule_stress_impact_loss
			humble = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = humble
					has_trait = fickle
				}
			}
		}
	}

	# Ask to be tutored by the old knight
	option = {
		name = tournament_events.1300.c
		trigger = {
			age <= 30 #Make sure you're young enough to be tutored like this
		}

		random_list = {
			1 = {
				add_trait_xp = {
					trait = tourney_participant
					track = foot
					value = 10
				}
			}
			1 = {
				add_trait_xp = {
					trait = tourney_participant
					track = bow
					value = 10
				}
			}
			1 = {
				add_trait_xp = {
					trait = tourney_participant
					track = horse
					value = 10
				}
			}
			1 = {
				add_trait_xp = {
					trait = tourney_participant
					track = wit
					value = 10
				}
			}
		}
		scope:young_knight = {
			accolade_medium_glory_gain_with_checks_effect = yes
		}
		scope:young_knight = {
			accolade_minor_glory_gain_with_checks_effect = yes
		}
		try_to_create_recurring_character_effect = { CHARACTER = scope:old_knight }

		if = {
			limit = { activity_is_competing_trigger = yes }
			activity_tournament_change_contestant_score_effect = { SCORE = increase_miniscule }
		}

		progress_towards_friend_effect = {
			REASON = friend_tournament_tutor
			CHARACTER = scope:old_knight
			OPINION = 20
		}

		stress_impact = {
			arrogant = major_stress_impact_gain
			lazy = medium_stress_impact_gain
			content = minor_stress_impact_gain
			diligent = miniscule_stress_impact_loss
			ambitious = miniscule_stress_impact_loss
			humble = minor_stress_impact_loss
		}

		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = lazy
					has_trait = ambitious
				}
			}
		}
	}
}

#A famous knight turns up at your Tournament
#Alt. Title: Becks shows up at your kickabout
#by Nick Meredith
tournament_events.1310 = {
	type = activity_event
	title = tournament_events.1310.t
	desc = tournament_events.1310.desc
	theme = tournament_grounds
	left_portrait = {
		character = root
		animation = admiration
	}
	right_portrait = {
		character = scope:famous_knight
		animation = personality_honorable
	}
	cooldown = { months = 2 }

	trigger = {
		this = scope:host
		scope:activity = {
			any_attending_character = {
				NOT = { this = root }
				is_adult = yes
				is_healthy = yes
				is_ai = yes
				has_trait = tourney_participant
				OR = {
					has_trait_xp = {
						trait = tourney_participant
						track = foot
						value >= 50
					}
					has_trait_xp = {
						trait = tourney_participant
						track = bow
						value >= 50
					}
					has_trait_xp = {
						trait = tourney_participant
						track = horse
						value >= 50
					}
					has_trait_xp = {
						trait = tourney_participant
						track = wit
						value >= 50
					}
				}
			}
		}
	}

	immediate = {
		scope:activity = {
			random_attending_character = {
				limit = {
					NOT = { this = root }
					is_adult = yes
					is_healthy = yes
					OR = {
						has_trait_xp = {
							trait = tourney_participant
							track = foot
							value >= 50
						}
						has_trait_xp = {
							trait = tourney_participant
							track = bow
							value >= 50
						}
						has_trait_xp = {
							trait = tourney_participant
							track = horse
							value >= 50
						}
						has_trait_xp = {
							trait = tourney_participant
							track = wit
							value >= 50
						}
					}
				}
				weight = {
					base = 1
					activity_recurring_character_weight_modifier = { VALUE = 100 }
				}
				save_scope_as = famous_knight
				try_to_create_recurring_character_effect = { CHARACTER = root }
			}
		}

		scope:host = {
			add_prestige = major_prestige_value
		}
	}

	# Welcome them
	option = {
		name = tournament_events.1310.a

		progress_towards_friend_effect = {
			REASON = friend_tournament_famous
			CHARACTER = scope:famous_knight
			OPINION = default_friend_opinion
		}

		if = {
			limit = {
				highest_held_title_tier >= tier_kingdom
			}
			scope:famous_knight = {
				accolade_minor_glory_gain_with_checks_effect = yes
			}
		}
		else = {
			scope:famous_knight = {
				accolade_minimal_glory_gain_with_checks_effect = yes
			}
		}

		add_character_modifier = {
			modifier = tournament_star_struck_modifier
			years = 15
		}

		stress_impact = {
			compassionate = miniscule_stress_impact_loss
			callous = medium_stress_impact_gain
			humble = miniscule_stress_impact_loss
			arrogant = major_stress_impact_gain
		}

		ai_chance = {
			base = 100
			modifier = {
				factor = 0

				OR = {
					has_trait = callous
					has_trait = arrogant
				}
			}
		}
	}

	# Learn from them
	option = {
		name = tournament_events.1310.b
		trigger = { activity_is_competing_trigger = yes }
		duel = {
			skills = { diplomacy learning }
			value = high_skill_rating
			# Crit success.
			20 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = tournament_events.1310.b.critsuccess
				send_interface_toast = {
					type = event_toast_effect_good
					title = tournament_events.1310.b.critsuccess
					left_icon = root
					right_icon = scope:famous_knight

					activity_tournament_change_contestant_score_effect = { SCORE = increase_medium }
				}
			}
			# Success.
			40 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = tournament_events.1310.b.success
				send_interface_toast = {
					type = event_toast_effect_good
					title = tournament_events.1310.b.success
					left_icon = root
					right_icon = scope:famous_knight

					activity_tournament_change_contestant_score_effect = { SCORE = increase_miniscule }
				}
			}
			# Failure.
			40 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = tournament_events.1310.b.failure
				send_interface_toast = {
					type = event_toast_effect_bad
					title = tournament_events.1310.b.failure
					left_icon = root
					right_icon = scope:famous_knight

					activity_tournament_change_contestant_score_effect = { SCORE = decrease_minor }
				}
			}
		}
		if = {
			limit = {
				highest_held_title_tier >= tier_kingdom
			}
			scope:famous_knight = {
				accolade_minor_glory_gain_with_checks_effect = yes
			}
		}
		else = {
			scope:famous_knight = {
				accolade_minimal_glory_gain_with_checks_effect = yes
			}
		}		

		stress_impact = {
			compassionate = medium_stress_impact_gain
			callous = miniscule_stress_impact_loss
			humble = major_stress_impact_gain
			arrogant = miniscule_stress_impact_loss
		}

		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = humble
					has_trait = compassionate
				}
			}
		}
	}

	# Ignore them
	option = {
		name = tournament_events.1310.c

		progress_towards_rival_effect = {
			REASON = rival_tournament_famous
			CHARACTER = scope:famous_knight
			OPINION = default_rival_opinion
		}

		add_character_modifier = {
			modifier = tournament_grounded_modifier
			years = 15
		}

		if = {
			limit = {
				highest_held_title_tier >= tier_kingdom
			}
			scope:famous_knight = {
				accolade_minimal_glory_loss_with_checks_effect = yes
			}
		}

		stress_impact = {
			compassionate = medium_stress_impact_gain
			callous = miniscule_stress_impact_loss
			humble = major_stress_impact_gain
			arrogant = miniscule_stress_impact_loss
		}

		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = humble
					has_trait = compassionate
				}
			}
		}
	}
}

#A herald forgets their knight's name
#Alt. Title: Becks shows up at your kickabout and you forget he's called Becks
#by Nick Meredith
tournament_events.1311 = {
	type = activity_event
	title = tournament_events.1311.t
	desc = tournament_events.1311.desc
	theme = martial
	override_background = { reference = army_camp }
	left_portrait = {
		character = root
		animation = personality_rational
	}
	right_portrait = {
		character = scope:knight_herald
		animation = worry
	}
	lower_center_portrait = {
		character = scope:forgotten_knight
	}
	cooldown = { years = 1 }

	trigger = {
		this = scope:host
		scope:activity = {
			any_attending_character = {
				NOT = { this = root }
				is_adult = yes
				is_ai = yes
				is_healthy = yes
				is_participant_in_activity = scope:activity
				is_knight = yes
				can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = THIS }
			}
		}
	}

	immediate = {
		scope:activity = {
			random_attending_character = {
				limit = {
					NOT = { this = root }
					is_adult = yes
					is_ai = yes
					is_healthy = yes
					is_participant_in_activity = scope:activity
					is_knight = yes
					can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = THIS }
				}
				weight = {
					base = 1
					activity_recurring_character_weight_modifier = { VALUE = 100 }
				}
				save_scope_as = forgotten_knight
			}
		}

		if = {
			limit = {
				any_pool_character = {
					province = scope:activity.activity_location
					is_available_ai_adult = yes
					has_no_particular_noble_roots_trigger = yes
					can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = THIS }
				}
			}
			random_pool_character = {
				province = involved_activity.activity_location
				limit = {
					is_available_ai_adult = yes
					has_no_particular_noble_roots_trigger = yes
					can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = THIS }
				}
				weight = {
					base = 1
					activity_recurring_character_weight_modifier = { VALUE = 100 }
				}
				save_scope_as = knight_herald
			}
		}
		else = {
			create_character = {
				template = servant_character
				dynasty = none
				location = scope:activity.activity_location
				gender_female_chance = root_faith_dominant_gender_adjusted_female_chance
				save_scope_as = knight_herald
			}
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			factor = 2
			has_activity_intent = recruit_knights_intent
		}
	}

	# Offer them a replacement herald
	option = {
		name = tournament_events.1311.a

		remove_short_term_gold = minor_gold_value

		scope:forgotten_knight = {
			add_character_modifier = {
				modifier = tournament_well_proclaimed_modifier
				years = 10
			}

			if = {
				limit = { activity_is_competing_trigger = yes }
				activity_tournament_change_contestant_score_effect = { SCORE = increase_miniscule }
			}
		}

		progress_towards_friend_effect = {
			REASON = friend_tournament_herald_knight
			CHARACTER = scope:forgotten_knight
			OPINION = default_friend_opinion
		}

		progress_towards_rival_effect = {
			REASON = rival_tournament_herald
			CHARACTER = scope:knight_herald
			OPINION = default_rival_opinion
		}

		if = {
			limit = {
				highest_held_title_tier >= tier_kingdom
			}
			scope:forgotten_knight = {
				accolade_minimal_glory_gain_with_checks_effect = yes
			}
		}

		hidden_effect = {
			random_list = {
				1 = {
					try_to_create_recurring_character_effect = { CHARACTER = scope:forgotten_knight }
				}
				1 = {
					try_to_create_recurring_character_effect = { CHARACTER = scope:knight_herald }
				}
			}
		}

		stress_impact = {
			generous = miniscule_stress_impact_loss
			callous = medium_stress_impact_gain
			gregarious = miniscule_stress_impact_loss
			sadistic = medium_stress_impact_gain
		}

		ai_chance = {
			base = 100
			modifier = {
				factor = 0

				OR = {
					has_trait = callous
					has_trait = sadistic
				}
			}
		}
	}

	# Offer the herald a job
	option = {
		name = tournament_events.1311.b

		add_courtier = scope:knight_herald

		if = {
			limit = { activity_is_competing_trigger = yes }
			activity_tournament_change_contestant_score_effect = { SCORE = decrease_miniscule }
		}

		add_character_modifier = {
			modifier = tournament_poorly_announced_modifier
			years = 20
		}

		reverse_add_opinion = {
			target = scope:forgotten_knight
			modifier = relieved_opinion
			opinion = 30
		}

		try_to_create_recurring_character_effect = { CHARACTER = scope:knight_herald }

		custom_tooltip = tournament_events.1311.b.tt

		hidden_effect = {
			scope:activity = {
				every_attending_character = {
					limit = {
						NOT = { this = root }
						has_trait = compassionate				
					}

					add_opinion = {
						target = root
						modifier = kindness_opinion
						opinion = 25
					}
				}
			}
		}

		stress_impact = {
			base = miniscule_stress_impact_loss
			gregarious = miniscule_stress_impact_loss
			humble = miniscule_stress_impact_loss
			arrogant = medium_stress_impact_gain
		}

		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				has_trait = arrogant
			}
		}
	}

	# Laugh at them
	option = {
		name = tournament_events.1311.c
		if = {
			limit = { activity_is_competing_trigger = yes }
			activity_tournament_change_contestant_score_effect = { SCORE = increase_miniscule }
		}
		progress_towards_rival_effect = {
			REASON = rival_tournament_herald_knight
			CHARACTER = scope:forgotten_knight
			OPINION = default_rival_opinion
		}

		try_to_create_recurring_character_effect = { CHARACTER = scope:forgotten_knight }

		stress_impact = {
			compassionate = medium_stress_impact_gain
			callous = miniscule_stress_impact_loss
			sadistic = miniscule_stress_impact_loss
		}
		if = {
			limit = {
				highest_held_title_tier >= tier_kingdom
			}
			scope:forgotten_knight = {
				accolade_minor_glory_loss_with_checks_effect = yes
			}
		}

		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				has_trait = compassionate
			}
		}
	}
}

#A foreign knight wows the crowd
#Alt. Title: Becks is Brazilian somehow
#by Nick Meredith
tournament_events.1312 = {
	type = activity_event
	title = tournament_events.1312.t
	desc = tournament_events.1312.desc
	theme = tournament_grounds
	left_portrait = {
		character = root
		animation = admiration
	}
	right_portrait = {
		character = scope:foreign_knight
		animation = marshal
	}
	cooldown = { years = 1 }	

	trigger = {
		scope:activity = {
			any_attending_character = {
				NOR = { #Not you, and also isn't of your culture OR the province's culture
					this = root 
					culture = root.culture
					culture = scope:activity.activity_location.culture
				}
				# Not employed as champion
				NOR = {
					liege.court_position:champion_court_position ?= this
					has_relation_to = root
					is_close_family_of = root
				}
				is_adult = yes
				is_ai = yes
				is_healthy = yes
				is_participant_in_activity = scope:activity
				is_landed = no
				exists = liege
				liege = { is_ai = yes }
				save_temporary_scope_as = foreign_knight_temp
				NOT = {
					liege.primary_title ?= {
						any_title_heir = { scope:foreign_knight_temp ?= this }
					}
				}
			}
		}
		this = scope:host
	}

	immediate = {
		scope:activity = {
			random_attending_character = {
				limit = {
					NOR = { #Not you, and also isn't of your culture OR the province's culture
						this = root 
						culture = root.culture
						culture = scope:activity.activity_location.culture
					}
					# Not employed as champion
					NOR = {
						liege.court_position:champion_court_position ?= this
						has_relation_to = root
						is_close_family_of = root
					}	
					is_adult = yes
					is_ai = yes
					is_healthy = yes
					is_participant_in_activity = scope:activity
					is_landed = no
					exists = liege
					liege = { is_ai = yes }
					save_temporary_scope_as = foreign_knight_temp
					NOT = {
						liege.primary_title = {
							any_title_heir = { this = scope:foreign_knight_temp }
						}
					}
				}
				weight = {
					base = 1
					modifier = {
						factor = 2
						is_lowborn = yes
					}
					modifier = {
						factor = 5
						NOT = {
							culture = {
								has_same_culture_heritage = scope:activity.activity_location.culture
							}
						}
					}
					modifier = {
						factor = 3
						NOT = {
							culture = {
								has_same_culture_heritage = root.culture
							}
						}
					}
					modifier = {
						factor = 0.5
						house = liege.house
					}
					modifier = {
						factor = 0.5
						has_any_good_relationship_with_character_trigger = { CHARACTER = liege }
					}
					modifier = {
						factor = 0.5
						is_close_family_of = liege
					}
					activity_recurring_character_weight_modifier = { VALUE = 100 }
				}
				save_scope_as = foreign_knight
				try_to_create_recurring_character_effect = { CHARACTER = root }
			}
		}

		scope:foreign_knight.liege = {
			save_scope_as = foreign_knight_liege
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			factor = 2
			has_activity_intent = recruit_knights_intent
		}
	}

	# Try to recruit them
	option = {
		name = tournament_events.1312.a

		duel = {
			skill = diplomacy
			value = high_skill_rating
			50 = {
				desc = tournament_events.1312.a.success
				min = 10
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}

				#Putting these outside the toast to reduce clutter
				pay_short_term_gold = {
					target = scope:foreign_knight
					gold = minor_gold_value
				}
				add_courtier = scope:foreign_knight

				send_interface_toast = {
					type = event_toast_effect_good
					title = tournament_events.1312.a.success
					left_icon = scope:foreign_knight
					right_icon = scope:foreign_knight_liege
					scope:foreign_knight = { set_knight_status = force }
					if = {
						limit = { activity_is_competing_trigger = yes }
						activity_tournament_change_contestant_score_effect = { SCORE = increase_miniscule }
					}

					reverse_add_opinion = {
						target = scope:foreign_knight
						modifier = pleased_opinion
						opinion = 20
					}
				}
			}
			50 = {
				desc = tournament_events.1312.a.failure
				min = 10
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				if = {
					limit = {
						highest_held_title_tier >= tier_kingdom
					}
					scope:foreign_knight = {
						accolade_minor_glory_gain_with_checks_effect = yes
					}
				}

				send_interface_toast = {
					type = event_toast_effect_bad
					title = tournament_events.1312.a.failure
					left_icon = scope:foreign_knight
					right_icon = scope:foreign_knight_liege
					reverse_add_opinion = {
						target = scope:foreign_knight_liege
						modifier = angry_opinion
						opinion = -35
					}
				}
			}
		}


		stress_impact = {
			generous = miniscule_stress_impact_loss
			greedy = medium_stress_impact_gain
			content = minor_stress_impact_gain
			ambitious = miniscule_stress_impact_loss
		}

		ai_chance = {
			base = 100
			modifier = {
				factor = 0

				OR = {
					has_trait = content
					has_trait = greedy
					gold < medium_gold_value
				}
			}
		}
	}

	# Impressed, befriend them
	option = {
		name = tournament_events.1312.b

		progress_towards_friend_effect = {
			REASON = friend_tournament_foreign_knight
			CHARACTER = scope:foreign_knight
			OPINION = default_friend_opinion
		}

		add_character_modifier = {
			modifier = tournament_foreign_knight_modifier
			years = 25
		}

		if = {
			limit = {
				highest_held_title_tier >= tier_kingdom
			}
			scope:foreign_knight = {
				accolade_minimal_glory_gain_with_checks_effect = yes
			}
		}

		stress_impact = {
			gregarious = miniscule_stress_impact_loss
			shy = medium_stress_impact_gain
			humble = miniscule_stress_impact_loss
			arrogant = minor_stress_impact_gain
		}

		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				has_trait = shy
			}
		}
	}

	# Dismiss them
	option = {
		name = tournament_events.1312.c

		if = {
			limit = {
				highest_held_title_tier >= tier_kingdom
			}
			scope:foreign_knight = {
				accolade_minimal_glory_loss_with_checks_effect = yes
			}
		}

		reverse_add_opinion = {
			target = scope:foreign_knight
			modifier = rejected_opinion
			opinion = -30
		}

		stress_impact = {
			gregarious = medium_stress_impact_gain
			shy = miniscule_stress_impact_loss
			humble = medium_stress_impact_gain
			arrogant = miniscule_stress_impact_loss
		}

		ai_chance = {
			base = 100
			modifier = {
				factor = 0

				OR = {
					has_trait = gregarious
					has_trait = humble
				}
			}
		}
	}
}

#The Red Coin
#by Nick Meredith
tournament_events.1320 = {
	type = activity_event
	title = tournament_events.1320.t
	desc = tournament_events.1320.desc
	theme = intrigue
	left_portrait = {
		character = root
		animation = throne_room_conversation_4
	}
	right_portrait = {
		character = scope:unusual_stranger
		animation = scheme
		outfit_tags = { western_stealth_hood }
	}
	cooldown = { years = 50 }

	trigger = {
		is_ai = no # Just so we don't have to worry about non-player characters getting this
	}

	immediate = {
		scope:activity = {
			random_attending_character = {
				culture = { save_scope_as = attending_culture }
			}
		}
		scope:attending_culture = {
			random_culture_county = {
				faith = { save_scope_as = attending_faith }
			}
		}
		create_character = {
			template = tournament_unusual_stranger
			location = scope:activity.activity_location
			culture = scope:attending_culture
			faith = scope:attending_faith
			dynasty = none
			save_scope_as = unusual_stranger
		}
	}

	# Accept their offer
	option = {
		name = tournament_events.1320.a

		scope:unusual_stranger = {
			pay_short_term_gold = {
				target = root
				gold = 1
			}

			add_character_flag = red_coin_origin
		}

		add_character_flag = red_coin_flag

		scope:unusual_stranger = {
			hidden_effect = {
				add_gold = 70 #Ensure they have some gold to get by with for later events
				add_to_activity = scope:activity
				scope:activity = {
					add_to_guest_subset = {
						name = spectator
						target = scope:unusual_stranger						
					}
				}
			}
		}

		hidden_effect = {
			scope:activity = { # Add them to here to keep track of them
				add_to_guest_subset = { 
					name = spectator
					target = scope:unusual_stranger
				}
			}
		}

		stress_impact = {
			paranoid = major_stress_impact_gain
			impatient = medium_stress_impact_gain
			trusting = miniscule_stress_impact_loss
			patient = miniscule_stress_impact_loss
		}

		ai_chance = {
			base = 100
			modifier = {
				factor = 0

				OR = {
					has_trait = impatient
					has_trait = paranoid
				}
			}
		}
	}

	# Refuse their offer
	option = {
		name = tournament_events.1320.b

		scope:unusual_stranger = {
			silent_disappearance_effect = yes
		}

		stress_impact = {
			paranoid = miniscule_stress_impact_loss
			impatient = miniscule_stress_impact_loss
			trusting = medium_stress_impact_gain
			patient = medium_stress_impact_gain
			eccentric = medium_stress_impact_gain
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_rationality = -0.5
				ai_boldness = 1
			}
		}
	}
}

#Coin Collection
tournament_events.1321 = {
	type = activity_event
	title = tournament_events.1321.t
	desc = tournament_events.1321.desc
	theme = intrigue
	override_background = { reference = army_camp }
	left_portrait = {
		character = root
		animation = happiness
	}
	right_portrait = {
		character = scope:unusual_stranger
		animation = happiness
		outfit_tags = { western_stealth_hood }
	}

	trigger = {
		has_character_flag = red_coin_flag
		scope:activity = {
			any_attending_character = {
				has_character_flag = red_coin_origin
			}
		}
	}

	immediate = {
		scope:activity.activity_location.county = {
			save_scope_as = county
		}
		scope:activity = {
			random_attending_character = {
				limit = {
					has_character_flag = red_coin_origin 
				}
				save_scope_as = unusual_stranger
			}
		}
	}

	# How would you like a job?
	option = {
		name = tournament_events.1321.a

		pay_short_term_gold = {
			target = scope:unusual_stranger
			gold = 1
		}

		add_courtier = scope:unusual_stranger

		if = {
			limit = {
				NOT = {
					exists = root.cp:councillor_spymaster
				}
			}
			assign_councillor_type = {
				type = councillor_spymaster
				target = scope:unusual_stranger
			}
		}
		else_if = {
			limit = {
				can_appoint_char_to_court_position = {
					CHAR = scope:unusual_stranger
					COURT_POS = keeper_of_swans_court_position
				}
			}
			court_position_grant_effect = {
				EMPLOYER = ROOT
				CANDIDATE = scope:unusual_stranger
				POS = keeper_of_swans
			}
		}

		remove_character_flag = red_coin_flag

		scope:unusual_stranger = {
			remove_character_flag = red_coin_origin
		}

		stress_impact = {
			paranoid = miniscule_stress_impact_loss
			just = miniscule_stress_impact_loss
			generous = minor_stress_impact_loss
			deceitful = minor_stress_impact_gain
			arbitrary = minor_stress_impact_gain
			greedy = medium_stress_impact_gain
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_rationality = 0.5
				ai_boldness = -0.5
			}
		}
	}

	# Hand the coin back
	option = {
		name = tournament_events.1321.b

		scope:unusual_stranger = {
			pay_short_term_gold = {
				target = root
				gold = 49
			}
		}

		remove_character_flag = red_coin_flag

		scope:unusual_stranger = {
			remove_character_flag = red_coin_origin
		}		

		scope:unusual_stranger = {
			silent_disappearance_effect = yes
		}

		stress_impact = {
			paranoid = minor_stress_impact_loss #Because you're not beholden to them any more
			trusting = miniscule_stress_impact_loss #Because your faith was proven right
			generous = minor_stress_impact_loss
			deceitful = minor_stress_impact_gain
			stubborn = minor_stress_impact_gain
			greedy = medium_stress_impact_gain
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = 1
				ai_boldness = -1
			}
		}
	}

	# Refuse to hand the coin back
	option = {
		name = tournament_events.1321.c

		flavor = tournament_events.1321.c.tt

		trigger_event = tournament_events.1322

		stress_impact = {
			arbitrary = miniscule_stress_impact_loss
			greedy = miniscule_stress_impact_loss
			trusting = medium_stress_impact_gain
			just = medium_stress_impact_gain
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_rationality = -1
				ai_boldness = 1
			}
		}
	}
}

#Refusal aftermath
tournament_events.1322 = {
	type = activity_event
	title = tournament_events.1322.t
	desc = tournament_events.1322.desc
	theme = intrigue
	override_background = { reference = army_camp }
	left_portrait = {
		character = root
		animation = paranoia
	}
	right_portrait = {
		character = scope:unusual_stranger
		animation = rage
		outfit_tags = { western_stealth_hood }
	}

	# Uh oh
	option = {
		name = tournament_events.1322.a

		add_character_modifier = tournament_reckoning_modifier

		reverse_add_opinion = {
			target = scope:unusual_stranger
			modifier = tournament_wronged_me_opinion
			opinion = -80
		}

		stress_impact = {
			base = minor_stress_impact_gain
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_rationality = 0.5
				ai_boldness = -0.5
			}
		}
	}
}

#Your heir is also competing
#by Nick Meredith
tournament_events.1330 = {
	type = activity_event
	title = tournament_events.1330.t
	desc = tournament_events.1330.desc
	theme = martial
	override_background = { reference = army_camp }
	left_portrait = {
		character = root
		animation = worry
	}
	right_portrait = {
		character = scope:heir
		animation = beg
	}
	cooldown = { years = 1 }	

	trigger = {
		this = scope:host
		is_in_guest_subset = { name = contestant }
		scope:activity = {
			any_guest_subset_current_phase = {
				name = contestant
				is_primary_heir_of = root
			}
			OR = {
				has_current_phase = tournament_phase_joust
				has_current_phase = tournament_phase_duel
			}
		}
	}

	immediate = {
		scope:activity = {
			random_guest_subset_current_phase = {
				name = contestant
				limit = {
					is_primary_heir_of = root
				}
				save_scope_as = heir
			}
		}
		random_spouse = {
			limit = {
				is_parent_of = root.primary_heir
			}
			save_scope_as = spouse
		}
	}

	# You are too precious to me!
	option = {
		name = tournament_events.1330.a

		trigger = {
			OR = {
				diplomacy > 13
				has_trait = compassionate
				opinion = { target = root.primary_heir value >= 80 }
			}
		}

		scope:heir = {
			save_scope_as = resigner
			custom_tooltip = tournament_not_competing_tt
			add_character_flag = tournament_not_competing
		}
		scope:activity = {
			remove_from_guest_subset = {
				name = contestant
				target = scope:heir
			}
			add_to_guest_subset = {
				name = spectator
				target = scope:heir
			}
		}

		add_character_modifier = {
			modifier = tournament_loving_parent_modifier
			years = 15
		}

		reverse_add_opinion = {
			target = scope:heir
			modifier = honored_opinion
			opinion = 20
		}

		stress_impact = {
			honest = miniscule_stress_impact_loss
			compassionate = miniscule_stress_impact_loss
			callous = medium_stress_impact_gain
			deceitful = minor_stress_impact_gain
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = 1
				ai_vengefulness = -1
			}
		}
	}

	# I'm so proud!
	option = {
		name = tournament_events.1330.b

		trigger = {
			OR = {
				has_trait = gallant
				has_trait = brave
			}
		}

		reverse_add_opinion = {
			target = scope:heir
			modifier = happy_opinion
			opinion = 50
		}

		stress_impact = {
			base = miniscule_stress_impact_loss
			gregarious = miniscule_stress_impact_loss
		}

		ai_chance = {
			base = 75
			ai_value_modifier = {
				ai_compassion = 1
				ai_honor = 1
			}
		}
	}

	# I forbid this!
	option = {
		name = tournament_events.1330.c

		scope:heir = {
			save_scope_as = resigner
			custom_tooltip = tournament_not_competing_tt
			add_character_flag = tournament_not_competing
		}
		scope:activity = {
			remove_from_guest_subset = {
				name = contestant
				target = scope:heir
			}
			add_to_guest_subset = {
				name = spectator
				target = scope:heir
			}
		}

		reverse_add_opinion = {
			target = scope:heir
			modifier = rejected_opinion
			opinion = -30
		}

		stress_impact = {
			ambitious = miniscule_stress_impact_loss
			arbitrary = miniscule_stress_impact_loss
			compassionate = minor_stress_impact_gain
			just = medium_stress_impact_gain
		}

		ai_chance = {
			base = 75
			ai_value_modifier = {
				ai_compassion = -1
				ai_boldness = -0.5
			}
		}
	}

	# If you must
	option = {
		name = tournament_events.1330.d
		trigger = { exists = scope:spouse }

		reverse_add_opinion = {
			target = scope:heir
			modifier = pleased_opinion
			opinion = 15
		}

		stress_impact = {
			fickle = miniscule_stress_impact_loss
			forgiving = miniscule_stress_impact_loss
			vengeful = miniscule_stress_impact_gain
			stubborn = minor_stress_impact_gain
		}

		ai_chance = {
			base = 75
			ai_value_modifier = {
				ai_compassion = 0.5
				ai_boldness = 0.5
			}
		}
	}
}

#Your dynast demands you withdraw
#by Nick Meredith
tournament_events.1331 = {
	type = activity_event
	title = tournament_events.1331.t
	desc = tournament_events.1331.desc
	theme = martial_authority_focus
	override_background = { reference = army_camp }
	left_portrait = {
		character = root
		animation = dismissal
	}
	right_portrait = {
		character = scope:dynast
		animation = disapproval
	}
	cooldown = { years = 1 }	

	trigger = {
		this = scope:host
		dynasty.dynast ?= {
			NOT = { this = root }
			involved_activity = scope:activity
			activity_is_competing_trigger = yes
		}
	}

	immediate = {
		dynasty.dynast = { save_scope_as = dynast }
		scope:activity = {
			random_guest_subset_current_phase = {
				name = contestant
				limit = { activity_is_competing_trigger = yes }
				save_scope_as = heir
			}
		}
	}

	# Intimidate them
	option = {
		name = tournament_events.1331.a

		trigger = {
			NOR = {
				AND = {
					has_trait = kinslayer_1
					faith = { has_doctrine_parameter = kinslaying_any_dynasty_member_crime }
				}
				AND = {
					has_trait = kinslayer_2
					faith = { has_doctrine_parameter = kinslaying_extended_family_crime }
				}
				AND = {
					has_trait = kinslayer_3
					faith = { has_doctrine_parameter = kinslaying_close_kin_crime }
				}
			}
			dread > 50
		}

		scope:dynast = {
			activity_tournament_change_contestant_score_effect = { SCORE = decrease_miniscule }
		}

		reverse_add_opinion = {
			target = scope:dynast
			modifier = scared_opinion
			opinion = -35
		}

		stress_impact = {
			sadistic = miniscule_stress_impact_loss
			wrathful = miniscule_stress_impact_loss
			brave = miniscule_stress_impact_loss
			compassionate = minor_stress_impact_gain
			calm = minor_stress_impact_gain
			craven = minor_stress_impact_gain
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = -1
				ai_vengefulness = 1
				ai_honor = -0.5
			}
		}
	}

	# Maybe we can strike a deal?
	option = {
		name = tournament_events.1331.b

		trigger = {
			has_trait = family_first
		}

		if = {
			limit = {
				can_add_hook = {
					target = scope:dynast
					type = favor_hook
				}
			}
			add_hook = {
				target = scope:dynast
				type = favor_hook
			}
		}

		reverse_add_opinion = {
			target = scope:dynast
			modifier = relieved_opinion
			opinion = 40
		}

		stress_impact = {
			base = miniscule_stress_impact_loss
			compassionate = miniscule_stress_impact_loss
			just = miniscule_stress_impact_loss
			callous = minor_stress_impact_gain
			arbitrary = minor_stress_impact_gain
		}

		ai_chance = {
			base = 75
			ai_value_modifier = {
				ai_compassion = 0.5
				ai_honor = 1
			}
		}
	}

	# Remember that time I Fredo'd that dude?
	option = {
		name = tournament_events.1331.c

		trigger = {
			OR = {
				AND = {
					has_trait = kinslayer_1
					faith = { has_doctrine_parameter = kinslaying_any_dynasty_member_crime }
				}
				AND = {
					has_trait = kinslayer_2
					faith = { has_doctrine_parameter = kinslaying_extended_family_crime }
				}
				AND = {
					has_trait = kinslayer_3
					faith = { has_doctrine_parameter = kinslaying_close_kin_crime }
				}
			}
		}

		scope:dynast = {
			activity_tournament_change_contestant_score_effect = { SCORE = decrease_medium }
		}

		add_dread = medium_dread_gain

		reverse_add_opinion = {
			target = scope:dynast
			modifier = scared_opinion
			opinion = -50
		}

		stress_impact = {
			ambitious = miniscule_stress_impact_loss
			arbitrary = miniscule_stress_impact_loss
			sadistic = miniscule_stress_impact_loss
			compassionate = minor_stress_impact_gain
			just = medium_stress_impact_gain
		}

		ai_chance = {
			base = 75
			ai_value_modifier = {
				ai_compassion = -1
				ai_boldness = 1
			}
		}
	}

	# I won't be coerced!
	option = {
		name = tournament_events.1331.d

		progress_towards_rival_effect = {
			REASON = rival_dynast_tournament_coercion
			CHARACTER = scope:dynast
			OPINION = default_rival_opinion
		}

		stress_impact = {
			content = medium_stress_impact_gain
			fickle = medium_stress_impact_gain			
			ambitious = miniscule_stress_impact_loss
			arrogant = miniscule_stress_impact_loss
			stubborn = miniscule_stress_impact_loss
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_boldness = 1
			}
		}
	}

	# Fine, if I must.
	option = {
		name = tournament_events.1331.e

		add_character_flag = tournament_not_competing
		custom_tooltip = tournament_not_competing_tt
		scope:activity = {
			remove_from_guest_subset = {
				name = contestant
				target = root
			}
			add_to_guest_subset = {
				name = spectator
				target = root
			}
		}

		scope:dynast = {
			activity_tournament_change_contestant_score_effect = { SCORE = increase_medium }
		}

		reverse_add_opinion = {
			target = scope:dynast
			modifier = pleased_opinion
			opinion = 15
		}

		stress_impact = {
			content = miniscule_stress_impact_loss
			fickle = miniscule_stress_impact_loss			
			ambitious = medium_stress_impact_gain
			arrogant = medium_stress_impact_gain
			stubborn = major_stress_impact_gain
		}

		ai_chance = {
			base = 25 #Make sure AI don't withdraw too much
			ai_value_modifier = {
				ai_boldness = -1
			}
		}
	}
}

#Your powerful vassal wants help
#by Nick Meredith
tournament_events.1332 = {
	type = activity_event
	title = tournament_events.1332.t
	desc = tournament_events.1332.desc
	theme = tournament_locale_camp
	left_portrait = {
		character = root
		animation = dismissal
	}
	right_portrait = {
		character = scope:powerful_vassal
		animation = beg
	}
	cooldown = { years = 1 }	

	trigger = {
		this = scope:host
		any_powerful_vassal = {
			is_ai = yes
			involved_activity = scope:activity
			activity_is_competing_trigger = yes
		}
	}

	immediate = {
		random_powerful_vassal = {
			limit = {
				is_ai = yes
				involved_activity = scope:activity
				activity_is_competing_trigger = yes
			}
			save_scope_as = powerful_vassal
		}
	}

	# Agree in exchange for loyalty
	option = {
		name = tournament_events.1332.a

		trigger = {
			diplomacy > 15

			can_add_hook = {
				target = scope:powerful_vassal
				type = loyalty_hook
			}
		}

		scope:powerful_vassal = {
			activity_tournament_change_contestant_score_effect = { SCORE = increase_major }
		}

		if = {
			limit = {
				can_add_hook = {
					target = scope:powerful_vassal
					type = loyalty_hook
				}
			}
			add_hook = {
				target = scope:powerful_vassal
				type = loyalty_hook
			}
		}

		stress_impact = {
			ambitious = miniscule_stress_impact_loss
			arbitrary = miniscule_stress_impact_loss
			content = minor_stress_impact_gain
			just = minor_stress_impact_gain
		}

		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_honor = -1
			}
		}
	}

	# Agree for a hook, depowered compared to A
	option = {
		name = tournament_events.1332.b

		trigger = {
			diplomacy <= 15

			can_add_hook = {
				target = scope:powerful_vassal
				type = favor_hook
			}
		}

		scope:powerful_vassal = {
			activity_tournament_change_contestant_score_effect = { SCORE = increase_medium }
		}

		if = {
			limit = {
				can_add_hook = {
					target = scope:powerful_vassal
					type = favor_hook
				}
			}
			add_hook = {
				target = scope:powerful_vassal
				type = favor_hook
			}
		}

		stress_impact = {
			ambitious = miniscule_stress_impact_loss
			arbitrary = miniscule_stress_impact_loss
			content = minor_stress_impact_gain
			just = minor_stress_impact_gain
		}

		ai_chance = {
			base = 75
			ai_value_modifier = {
				ai_compassion = 0.5
				ai_honor = -1
			}
		}
	}

	# Agree for money
	option = {
		name = tournament_events.1332.c
		trigger = {
			scope:powerful_vassal.gold >= 1
		}

		scope:powerful_vassal = {
			activity_tournament_change_contestant_score_effect = { SCORE = increase_medium }
		}

		scope:powerful_vassal = {
			pay_short_term_gold = {
				target = root
				gold = {
					value = root.medium_gold_value
					max = scope:powerful_vassal.gold
					min = 1
				}
			}
		}

		stress_impact = {
			greedy = miniscule_stress_impact_loss
			impatient = miniscule_stress_impact_loss
			generous = minor_stress_impact_gain
			patient = minor_stress_impact_gain
		}

		ai_chance = {
			base = 75
			ai_value_modifier = {
				ai_compassion = 0.5
				ai_greed = 1
			}
		}
	}

	# Minor agree, for opinion
	option = {
		name = tournament_events.1332.d

		scope:powerful_vassal = {
			activity_tournament_change_contestant_score_effect = { SCORE = increase_minor }
		}

		reverse_add_opinion = {
			target = scope:powerful_vassal
			modifier = pleased_opinion
			opinion = 40
		}

		stress_impact = {
			content = miniscule_stress_impact_loss
			gregarious = miniscule_stress_impact_loss
			ambitious = medium_stress_impact_gain
			shy = miniscule_stress_impact_gain
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_boldness = -1
				ai_greed = -0.5
			}
		}
	}

	# Nah
	option = {
		name = tournament_events.1332.e

		scope:powerful_vassal = {
			activity_tournament_change_contestant_score_effect = { SCORE = decrease_miniscule }
		}

		progress_towards_rival_effect = {
			REASON = rival_dynast_tournament_coercion
			CHARACTER = scope:powerful_vassal
			OPINION = default_rival_opinion
		}

		stress_impact = {
			stubborn = miniscule_stress_impact_loss
			lazy = miniscule_stress_impact_loss			
			just = miniscule_stress_impact_loss
			fickle = minor_stress_impact_gain
			arbitrary = minor_stress_impact_gain
		}

		ai_chance = {
			base = 75
			ai_value_modifier = {
				ai_greed = -1
				ai_honor = -0.5
			}
		}
	}
}

###################################
###################################
###    SPECTATOR-ONLY EVENTS    ###
###			1400-1500		    ###
###################################
###################################

# A tall person is blocking your view!
tournament_events.1400 = {
	type = activity_event
	title = tournament_events.1400.t
	desc = tournament_events.1400.desc
	theme = tournament_grounds
	window = widget_activity_locale_fullscreen_event
	left_portrait = {
		character = root
		animation = stress
	}
	right_portrait = {
		character = scope:tall_person
		animation = dismissal
	}

	cooldown = { years = 1 }

	trigger = {
		is_adult = yes
		is_healthy = yes
		NOR = {
			has_trait = wounded
			highest_held_title_tier >= scope:host.highest_held_title_tier
			scope:host = this
		}
		scope:activity = {
			any_guest_subset_current_phase = {
				name = spectator
				is_ai = yes
				is_healthy = yes
				is_adult = yes
				save_temporary_scope_as = tall_temp
				can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:tall_temp }
				OR = {
					has_trait = giant
					has_trait = physique_good
				}
				NOT = { has_trait = wounded }
				# Dwarves can be seen over unless you're also a dwarf.
				trigger_if = {
					limit = {
						root = {
							NOT = { has_trait = dwarf }
						}
					}
					NOT = { has_trait = dwarf }
				}
			}
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			is_ai = yes 
			factor = 0.25
		}
	}

	immediate = {
		scope:activity = {
			random_guest_subset_current_phase = {
				name = spectator
				limit = {
					is_ai = yes
					is_healthy = yes
					is_adult = yes
					save_temporary_scope_as = tall_temp
					can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:tall_temp }
					OR = {
						has_trait = giant
						has_trait = physique_good
					}
					NOT = { has_trait = wounded }
					# Dwarves can be seen over unless you're also a dwarf.
					trigger_if = {
						limit = {
							root = {
								NOT = { has_trait = dwarf }
							}
						}
						NOT = { has_trait = dwarf }
					}
				}
				weight = {
					base = 1
					activity_recurring_character_weight_modifier = { VALUE = 100 }
				}
				save_scope_as = tall_person
				try_to_create_recurring_character_effect = { CHARACTER = root }
			}
		}
	}

	# Slug them in the back
	option = {
		name = tournament_events.1400.a

		flavor = tournament_events.1400.a.fight

		trigger = {
			can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root }
		}

		increase_wounds_effect = { REASON = fight }

		scope:tall_person = {
			increase_wounds_effect = { REASON = fight }
		}

		progress_towards_rival_effect = {
			REASON = rival_tournament_brawl
			CHARACTER = scope:tall_person
			OPINION = default_rival_opinion
		}

		add_prestige = minor_prestige_loss

		stress_impact = {
			wrathful = medium_stress_impact_loss
			brave = miniscule_stress_impact_loss
			impatient = miniscule_stress_impact_loss
			calm = medium_stress_impact_gain
			craven = medium_stress_impact_gain
			patient = medium_stress_impact_gain
		}

		ai_chance = {
			base = 100
			modifier = {
				factor = 0

				OR = {
					has_trait = craven
					has_trait = patient
					has_trait = calm
				}
			}
		}
	}

	# Ask them to move
	option = {
		name = tournament_events.1400.b

		duel = {
			skill = diplomacy
			value = medium_skill_rating
			50 = { #They acquiesce
				desc = tournament_events.1400.b.success
				min = 10
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}

				modifier = {
					dread >= 30
					add = 10
				}

				send_interface_toast = {
					type = event_toast_effect_good
					title = tournament_events.1400.b.success
					left_icon = root
					right_icon = scope:tall_person

					add_stress = minor_stress_loss
				}
			}
			50 = { #They refuse
				desc = tournament_events.1400.b.failure
				min = 10
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}

				send_interface_toast = {
					type = event_toast_effect_bad
					title = tournament_events.1400.b.failure
					left_icon = root
					right_icon = scope:tall_person

					add_stress = minor_stress_gain
				}
			}
		}

		stress_impact = {
			shy = medium_stress_impact_gain
			gregarious = miniscule_stress_impact_gain
		}

		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				has_trait = shy
			}
		}
	}

	# Attempt to recruit them
	option = {
		name = tournament_events.1400.c

		trigger = {
			scope:tall_person = { #Make sure they're recruitable
				is_knight = no
				is_landed = no
				is_ruler = no
				can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root }
			}
			is_landed = yes
		}

		duel = {
			skill = diplomacy
			value = high_skill_rating
			50 = {
				desc = tournament_events.1400.c.success
				min = 10
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}

				add_courtier = scope:tall_person

				remove_short_term_gold = minor_gold_value
			}
			50 = {
				desc = tournament_events.1400.c.failure
				min = 10
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}

				reverse_add_opinion = {
					target = scope:tall_person
					modifier = refusal_opinion
					opinion = -10
				}
			}
		}

		stress_impact = {
			shy = medium_stress_impact_gain
			lazy = medium_stress_impact_gain
			gregarious = miniscule_stress_impact_gain
			diligent = miniscule_stress_impact_gain
		}

		ai_chance = {
			base = 100
			modifier = {
				factor = 0

				OR = {
					has_trait = shy
					has_trait = lazy
				}
			}
		}
	}

	# Tough it out
	option = {
		name = tournament_events.1400.d

		stress_impact = {
			base = minor_stress_impact_gain
			wrathful = minor_stress_impact_gain
			arrogant = minor_stress_impact_gain
			humble = miniscule_stress_impact_loss
			calm = miniscule_stress_impact_loss
		}

		ai_chance = {
			base = 100
			modifier = {
				factor = 0

				OR = {
					has_trait = wrathful
					has_trait = arrogant
				}
			}
		}
	}
}

# You, a tall person, are blocking someone else's view!
tournament_events.1401 = {
	type = activity_event
	title = tournament_events.1401.t
	desc = tournament_events.1401.desc
	theme = tournament_grounds
	window = widget_activity_locale_fullscreen_event
	left_portrait = {
		character = root
		animation = dismissal
	}
	right_portrait = {
		character = scope:smol_person
		animation = stress
	}

	cooldown = { years = 1 }

	trigger = {
		NOR = {
			highest_held_title_tier >= scope:host.highest_held_title_tier
			scope:host = this
		}
		OR = {
			has_trait = giant
			has_trait = physique_good
		}
		scope:activity = {
			any_guest_subset_current_phase = {
				name = spectator
				this = root
			}
			any_guest_subset_current_phase = {
				name = spectator
				NOR = {
					has_trait = giant
					has_trait = physique_good
				}
				is_ai = yes
				is_healthy = yes
				NOR = {
					highest_held_title_tier >= scope:host.highest_held_title_tier
					scope:host = this
				}
			}
		}
	}

	immediate = {
		scope:activity = {
			random_guest_subset = {
				name = spectator
				limit = {
					NOR = {
						has_trait = giant
						has_trait = physique_good
					}
					is_ai = yes
					is_healthy = yes
					NOR = {
						highest_held_title_tier >= scope:host.highest_held_title_tier
						scope:host = this
					}
				}
				weight = {
					base = 1
					modifier = {
						add = 25
						is_adult = no
					}

					modifier = {
						add = 50
						has_trait = dwarf
					}
					activity_recurring_character_weight_modifier = { VALUE = 100 }
				}
				save_scope_as = smol_person
				try_to_create_recurring_character_effect = { CHARACTER = root }
			}
		}
	}

	# Box them out with your frame
	option = {
		name = tournament_events.1401.a

		duel = {
			skill = prowess
			target = scope:smol_person
			70 = { #You win
				desc = tournament_events.1401.a.success
				min = 10
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}

				send_interface_toast = {
					type = event_toast_effect_good
					title = tournament_events.1401.a.success
					left_icon = root
					right_icon = scope:smol_person

					reverse_add_opinion = {
						target = scope:smol_person
						modifier = annoyed_opinion
						opinion = -30
					}
				}
			}
			30 = { #You lose
				desc = tournament_events.1401.a.failure
				min = 10
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}

				send_interface_toast = {
					type = event_toast_effect_bad
					title = tournament_events.1401.a.failure
					left_icon = root
					right_icon = scope:smol_person

					add_prestige = minor_prestige_loss
				}
			}
		}

		progress_towards_rival_effect = {
			REASON = rival_tournament_blocked
			CHARACTER = scope:smol_person
			OPINION = default_rival_opinion
		}

		stress_impact = {
			base = miniscule_stress_impact_loss
			wrathful = miniscule_stress_impact_loss
			arrogant = miniscule_stress_impact_loss
			calm = medium_stress_impact_gain
			humble = medium_stress_impact_gain
		}

		ai_chance = {
			base = 100
			modifier = {
				factor = 0

				OR = {
					has_trait = humble
					has_trait = calm
				}
			}
		}
	}

	# Let them through
	option = {
		name = tournament_events.1401.b

		progress_towards_friend_effect = {
			REASON = friend_tournament_let_through
			CHARACTER = scope:smol_person
			OPINION = default_friend_opinion
		}

		stress_impact = {
			wrathful = medium_stress_impact_gain
			arrogant = medium_stress_impact_gain
			callous = medium_stress_impact_gain
			calm = miniscule_stress_impact_loss
			humble = miniscule_stress_impact_loss
			compassionate = minor_stress_impact_loss
		}

		ai_chance = {
			base = 100
			modifier = {
				factor = 0

				OR = {
					has_trait = wrathful
					has_trait = arrogant
					has_trait = callous
				}
			}
		}
	}
}

# Person spills a drink on you
tournament_events.1402 = {
	type = activity_event
	title = tournament_events.1402.t
	desc = tournament_events.1402.desc
	theme = tournament_grounds
	window = widget_activity_locale_fullscreen_event
	left_portrait = {
		character = root
		animation = anger
	}
	right_portrait = {
		character = scope:drinking_spectator
		animation = drink
	}

	cooldown = { years = 1 }

	trigger = {
		scope:activity = {
			any_guest_subset_current_phase = {
				name = spectator
				this = root
			}
			any_guest_subset_current_phase = {
				name = spectator
				is_ai = yes
				is_healthy = yes
				OR = {
					has_trait = drunkard
					has_trait = lifestyle_reveler
					has_trait = gluttonous
				}
				NOT = { this = root }
			}
		}
	}

	immediate = {
		scope:activity = {
			random_guest_subset_current_phase = {
				name = spectator
				limit = {
					is_ai = yes
					is_healthy = yes
					OR = {
						has_trait = drunkard
						has_trait = lifestyle_reveler
						has_trait = gluttonous
					}
					NOT = { this = root }
				}
				weight = {
					base = 1
					activity_recurring_character_weight_modifier = { VALUE = 100 }
				}
				save_scope_as = drinking_spectator
				try_to_create_recurring_character_effect = { CHARACTER = root }
			}
		}
	}

	# Ask if they want to share a drink
	option = {
		name = tournament_events.1402.a

		trigger = {
			drinks_alcohol_trigger = yes #Just in case
			OR = {
				has_trait = gregarious
				has_trait = drunkard
				has_trait = lifestyle_reveler
				has_trait = gluttonous
			}
		}

		remove_short_term_gold = tiny_gold_value

		progress_towards_friend_effect = {
			REASON = friend_tournament_drink_shared
			CHARACTER = scope:drinking_spectator
			OPINION = default_friend_opinion
		}

		stress_impact = {
			wrathful = medium_stress_impact_gain
			temperate = medium_stress_impact_gain
			calm = minor_stress_impact_loss
			gluttonous = minor_stress_impact_loss
		}

		ai_chance = {
			base = 100
			modifier = {
				factor = 0

				OR = {
					has_trait = wrathful
					has_trait = temperate
				}
			}
		}
	}

	# Have them taken away
	option = {
		name = tournament_events.1402.b

		reverse_add_opinion = {
			target = scope:drinking_spectator
			modifier = tournament_dragged_off_opinion
			opinion = -40
		}

		stress_impact = {
			base = minor_stress_impact_loss
			wrathful = minor_stress_impact_loss
			temperate = minor_stress_impact_loss
			calm = medium_stress_impact_gain
			gluttonous = medium_stress_impact_gain
		}

		ai_chance = {
			base = 100
			modifier = {
				factor = 0

				OR = {
					has_trait = calm
					has_trait = gluttonous
				}
			}
		}
	}

	# Brush it off
	option = {
		name = tournament_events.1402.c

		add_character_modifier = {
			modifier = tournament_soaked_modifier
			years = 5
		}

		stress_impact = {
			base = minor_stress_impact_gain
			shy = minor_stress_impact_loss
			calm = minor_stress_impact_loss
			humble = miniscule_stress_impact_loss
			temperate = miniscule_stress_impact_loss
			arrogant = minor_stress_impact_gain
			gluttonous = minor_stress_impact_gain
			wrathful = medium_stress_impact_gain
			vengeful = medium_stress_impact_gain
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_vengefulness = -1
				ai_rationality = 1
			}
		}
	}
}

# Priest attempts to stop the Contest, calling it ungodly
tournament_events.1403 = {
	type = activity_event
	title = tournament_events.1403.t
	desc = tournament_events.1403.desc
	theme = tournament_grounds
	window = widget_activity_locale_fullscreen_event
	left_portrait = {
		character = root
		animation = worry
	}
	right_portrait = {
		character = scope:realm_priest
		animation = personality_zealous
	}

	cooldown = { years = 1 }

	trigger = {
		scope:activity = {
			any_guest_subset_current_phase = {
				name = spectator
				this = root
			}
		}
		scope:host = {
			exists = cp:councillor_court_chaplain
			cp:councillor_court_chaplain = {
				is_ai = yes
				is_adult = yes
				location = root.location
			}
		}
		scope:host = {
			cp:councillor_court_chaplain ?= {
				NOT = { this = root }
			}
		}
		# TODO_CD_EP2, check for violent tournament. Priests shouldn't care about your Board Game/Recital Tournament
		scope:host.faith = {
			NOR = {
				has_doctrine_parameter = clergy_can_fight
				has_doctrine_parameter = warmonger
				has_doctrine_parameter = human_sacrifice_active
			}
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			factor = 2
			scope:host.faith = {
				has_doctrine_parameter = pacifist_opinion_active
			}
		}
	}

	immediate = {
		scope:host = {
			cp:councillor_court_chaplain = {
				save_scope_as = realm_priest
				try_to_create_recurring_character_effect = { CHARACTER = root }
			}
		}
	}

	# Agree with them, harangue the crowd
	option = {
		name = tournament_events.1403.a
		trigger = {
			has_trait = zealous
			faith = {
				NOR = {
					has_doctrine_parameter = clergy_can_fight
					has_doctrine_parameter = warmonger
					has_doctrine_parameter = human_sacrifice_active
				}
			}
		}

		if = {
			limit = {
				scope:host = {
					this = root
				}
				scope:activity.activity_location.province_owner = root
			}

			scope:activity.activity_location.county = {
				add_county_modifier = {
					modifier = tournament_annoyed_locals_modifier
					years = 20
				}
			}

			add_character_modifier = {
				modifier = tournament_public_proselytiser_modifier
				years = 20
			}
		}
		else = {
			add_character_modifier = {
				modifier = tournament_public_proselytiser_modifier
				years = 15
			}
		}

		if = {
			limit = {
				scope:realm_priest.faith = root.faith
			}

			add_piety = medium_piety_gain
		}

		reverse_add_opinion = {
			target = scope:realm_priest
			modifier = pious_opinion
			opinion = 30
		}

		stress_impact = {
			base = medium_stress_impact_loss
			wrathful = miniscule_stress_impact_loss
			honest = miniscule_stress_impact_loss
			calm = medium_stress_impact_gain
			deceitful = medium_stress_impact_gain
		}

		ai_chance = {
			base = 100
			modifier = {
				factor = 0

				OR = {
					has_trait = calm
					has_trait = deceitful
				}
			}
		}
	}

	# Harangue the priest back
	option = {
		name = tournament_events.1403.b

		add_character_modifier = {
			modifier = tournament_sports_enthusiast_modifier
			years = 15
		}

		reverse_add_opinion = {
			target = scope:realm_priest
			modifier = impious_opinion
			opinion = -40
		}

		stress_impact = {
			wrathful = miniscule_stress_impact_loss
			calm = medium_stress_impact_gain
			cynical = miniscule_stress_impact_loss
			zealous = medium_stress_impact_gain
		}

		ai_chance = {
			base = 100
			modifier = {
				factor = 0

				OR = {
					has_trait = calm
					has_trait = zealous
				}
			}
		}
	}

	# Keep quiet
	option = {
		name = tournament_events.1403.c

		stress_impact = {
			calm = miniscule_stress_impact_loss
			forgiving = miniscule_stress_impact_loss
			shy = miniscule_stress_impact_loss
			patient = miniscule_stress_impact_loss
			wrathful = medium_stress_impact_gain
			cynical = medium_stress_impact_gain
			zealous = medium_stress_impact_gain
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_vengefulness = -0.5
				ai_rationality = 0.5
			}
		}
	}
}

# You gossip with a friend about who the best looking participant is
tournament_events.1404 = {
	type = activity_event
	title = tournament_events.1404.t
	desc = tournament_events.1404.desc
	theme = tournament_grounds
	window = widget_activity_locale_fullscreen_event
	left_portrait = {
		character = root
		animation = flirtation_left
	}
	right_portrait = {
		character = scope:gossip_friend
		animation = flirtation
	}
	lower_right_portrait = { character = scope:knight_1 }
	lower_left_portrait = {	character = scope:knight_2 }

	cooldown = { years = 1 }

	trigger = {
		is_participant_in_activity = scope:activity
		is_in_guest_subset = { name = spectator }
		scope:activity = {
			any_guest_subset_current_phase = { # Your friend
				name = spectator
				has_relation_friend = root
				is_adult = yes
				save_temporary_scope_as = thirsty_friend
				scope:activity = {
					any_guest_subset_current_phase = {
						name = qualified
						NOT = {
							has_trait = beauty_bad # Make sure you're not swooning over uggos
						}
						save_temporary_scope_as = temp_knight_1
					}
				}
				is_attracted_to_gender_of = scope:temp_knight_1
			}
			any_guest_subset_current_phase = { # Second knight
				name = qualified
				NOR = {
					this = scope:temp_knight_1
					has_trait = beauty_bad # Make sure you're not swooning over uggos
				}
				save_temporary_scope_as = temp_knight_2
				OR = {
					root = { is_attracted_to_gender_of = scope:temp_knight_2 }
					scope:thirsty_friend = { is_attracted_to_gender_of = scope:temp_knight_2 }
				}
			}
		}
	}

	immediate = {
		scope:activity = {
			random_guest_subset_current_phase = { # Your friend
				name = spectator
				limit = {
					has_relation_friend = root
					is_adult = yes
					save_temporary_scope_as = thirsty_friend
					scope:activity = {
						any_guest_subset_current_phase = {
							name = qualified
							NOT = {
								has_trait = beauty_bad # Make sure you're not swooning over uggos
							}
							save_temporary_scope_as = temp_knight_1
						}
					}
					is_attracted_to_gender_of = scope:temp_knight_1
				}
				save_scope_as = gossip_friend
				
				scope:activity = {
					random_guest_subset_current_phase = {
						name = qualified
						limit = {
							NOT = {
								has_trait = beauty_bad # Make sure you're not swooning over uggos
							}
							save_temporary_scope_as = temp_knight_1
							scope:gossip_friend = { is_attracted_to_gender_of = scope:temp_knight_1 }
						}
						save_scope_as = knight_1
					}
				}
			}
			random_guest_subset_current_phase = { # Second knight
				name = qualified
				limit = {
					NOR = {
						this = scope:knight_1
						has_trait = beauty_bad # Make sure you're not swooning over uggos
					}
					save_temporary_scope_as = temp_knight_2
					OR = {
						root = { is_attracted_to_gender_of = scope:temp_knight_2 }
						scope:gossip_friend = { is_attracted_to_gender_of = scope:temp_knight_2 }
					}
				}
				save_scope_as = knight_2
			}
		}
	}

	# I think you might be the best-looking of the lot, actually!
	# But in, like, a flirty way.
	option = {
		name = tournament_events.1404.a
		trigger = {
			is_attracted_to_gender_of = scope:gossip_friend
			scope:gossip_friend = {
				is_attracted_to_gender_of = root
			}
		}

		progress_towards_lover_effect = {
			REASON = lover_tournament_gossiping
			CHARACTER = scope:gossip_friend
			OPINION = default_lover_opinion
		}

		if = {
			limit = {
				scope:host = root
			}
			scope:gossip_friend = {
				add_prestige = medium_prestige_gain
			}
			add_hook_no_toast = {
				type = loyalty_hook
				target = scope:gossip_friend
			}
		}

		try_to_create_recurring_character_effect = { CHARACTER = scope:gossip_friend }

		stress_impact = {
			lustful = miniscule_stress_impact_loss
			chaste = medium_stress_impact_gain
			honest = miniscule_stress_impact_loss
			deceitful = medium_stress_impact_gain
		}

		ai_chance = {
			base = 100
			modifier = {
				factor = 0

				OR = {
					has_trait = chaste
					has_trait = deceitful
				}
			}
		}
	}

	# I think you might be the best-looking of the lot, actually!
	# But in, like, a friendly way
	option = {
		name = tournament_events.1404.b
		trigger = {
			NOR = {
				is_attracted_to_gender_of = scope:gossip_friend
				scope:gossip_friend = {
					is_attracted_to_gender_of = root
				}
			}
		}

		progress_towards_friend_effect = {
			REASON = friend_tournament_gossiping
			CHARACTER = scope:gossip_friend
			OPINION = default_friend_opinion
		}

		if = {
			limit = {
				scope:host = root
			}
			scope:gossip_friend = {
				add_prestige = medium_prestige_gain
			}
			add_hook_no_toast = {
				type = loyalty_hook
				target = scope:gossip_friend
			}
		}

		try_to_create_recurring_character_effect = { CHARACTER = scope:gossip_friend }

		stress_impact = {
			gregarious = miniscule_stress_impact_loss
			shy = medium_stress_impact_gain
			honest = miniscule_stress_impact_loss
			deceitful = medium_stress_impact_gain
		}

		ai_chance = {
			base = 100
			modifier = {
				factor = 0

				OR = {
					has_trait = shy
					has_trait = deceitful
				}
			}
		}
	}

	# I like knight 1!
	option = {
		name = tournament_events.1404.c

		if = {
			limit = {
				is_attracted_to_gender_of = scope:knight_1
			}

			progress_towards_lover_effect = {
				REASON = lover_tournament_stand_flirt
				CHARACTER = scope:knight_1
				OPINION = default_lover_opinion
			}
		}
		else = { # If you're not attracted to them, consider it platonic.
			reverse_add_opinion = {
				target = scope:knight_1
				modifier = flattered_opinion
				opinion = 30
			}
		}
		if = { #if the other knight is attracted to you, then they will be offended by rejection.
			limit = {
				scope:knight_2 = {
					is_attracted_to_gender_of = root
				}
			}
			reverse_add_opinion = {
				target = scope:knight_2
				modifier = rejected_opinion
				opinion = -10
			}
		}
		if = {
			limit = {
				scope:host = root
			}
			scope:knight_1 = {
				add_prestige = medium_prestige_gain
			}
			add_hook_no_toast = {
				type = loyalty_hook
				target = scope:knight_1
			}
		}

		try_to_create_recurring_character_effect = { CHARACTER = scope:knight_1 }

		stress_impact = {
			lustful = miniscule_stress_impact_loss
			honest = miniscule_stress_impact_loss
			gregarious = miniscule_stress_impact_loss
			deceitful = minor_stress_impact_gain
			shy = minor_stress_impact_gain
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_boldness = 0.5
				ai_compassion = 0.5
			}
		}
	}

	# I like knight 2!
	option = {
		name = tournament_events.1404.d

		if = {
			limit = {
				is_attracted_to_gender_of = scope:knight_2
			}

			progress_towards_lover_effect = {
				REASON = lover_tournament_stand_flirt
				CHARACTER = scope:knight_2
				OPINION = default_lover_opinion
			}
		}
		else = { # If you're not attracted to them, consider it platonic.
			reverse_add_opinion = {
				target = scope:knight_2
				modifier = flattered_opinion
				opinion = 30
			}
		}
		if = { #if the other knight is attracted to you, then they will be offended by rejection.
			limit = {
				scope:knight_1 = {
					is_attracted_to_gender_of = root
				}
			}
			reverse_add_opinion = {
				target = scope:knight_1
				modifier = rejected_opinion
				opinion = -10
			}
		}
		if = {
			limit = {
				scope:host = root
			}
			scope:knight_2 = {
				add_prestige = medium_prestige_gain
			}
			add_hook_no_toast = {
				type = loyalty_hook
				target = scope:knight_2
			}
		}

		try_to_create_recurring_character_effect = { CHARACTER = scope:knight_2 }

		stress_impact = {
			lustful = miniscule_stress_impact_loss
			honest = miniscule_stress_impact_loss
			gregarious = miniscule_stress_impact_loss
			deceitful = minor_stress_impact_gain
			shy = minor_stress_impact_gain
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_boldness = 0.5
				ai_compassion = 0.5
			}
		}
	}

	# Keep quiet
	option = {
		name = tournament_events.1404.e

		stress_impact = {
			gregarious = minor_stress_impact_gain
			shy = miniscule_stress_impact_loss
			honest = minor_stress_impact_gain
			deceitful = miniscule_stress_impact_loss
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_boldness = -0.5
				ai_compassion = -0.5
			}
		}
	}
}

# Flirt with another spectator
tournament_events.1405 = {
	type = activity_event
	title = tournament_events.1405.t
	desc = tournament_events.1405.desc
	theme = tournament_grounds
	window = widget_activity_locale_fullscreen_event
	left_portrait = {
		character = root
		animation = flirtation_left
	}
	right_portrait = {
		character = scope:flirty_onlooker
		animation = flirtation
	}

	cooldown = { years = 1 }

	trigger = {
		scope:activity = {
			any_guest_subset_current_phase = {
				name = spectator
				is_ai = yes
				is_healthy = yes
				is_adult = yes
				is_attracted_to_gender_of = root
				OR = { # Ensure they either don't have a spouse or are OK with cheating on them
					NOT = {
						any_spouse = {
							exists = this
						}
					}
					might_cheat_on_every_partner_trigger = yes
				}
				NOT = { this = root }
				save_temporary_scope_as = flirty_spectator
			}
			any_guest_subset_current_phase = {
				name = spectator
				this = root
				is_attracted_to_gender_of = scope:flirty_spectator
			}
		}
	}

	immediate = {
		scope:activity = {
			random_guest_subset_current_phase = {
				name = spectator
				limit = {
					is_ai = yes
					is_healthy = yes
					is_adult = yes
					is_attracted_to_gender_of = root
					OR = { # Ensure they either don't have a spouse or are OK with cheating on them
						NOT = {
							any_spouse = {
								exists = this
							}
						}
						might_cheat_on_every_partner_trigger = yes
					}
					NOT = { this = root }
				}
				save_scope_as = flirty_onlooker
			}
		}
	}

	# Start a boosted seduce scheme
	option = {
		name = tournament_events.1405.a

		trigger = {
			is_attracted_to_gender_of = scope:flirty_onlooker
			can_start_scheme = {
				type = seduce
				target_character = scope:flirty_onlooker
			}
		}

		start_scheme = { 
			type = seduce
			target_character = scope:flirty_onlooker 
		}

		hidden_effect = {
			random_scheme = {
				limit = {
					scheme_type = seduce
					scheme_target_character = scope:flirty_onlooker
				}
				add_scheme_modifier = {
					type = extra_success_chance_modifier
				}
			}
		}

		stress_impact = {
			chaste = medium_stress_impact_gain
			shy = minor_stress_impact_gain
			gregarious = miniscule_stress_impact_loss
			lustful = minor_stress_impact_loss
			arrogant = miniscule_stress_impact_loss
		}

		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				has_trait = chaste
			}
		}
	}

	# Coquettishly smile back
	option = {
		name = tournament_events.1405.b

		flavor = tournament_events.1405.b.tt

		reverse_add_opinion = {
			target = scope:flirty_onlooker
			modifier = flirty_opinion
			opinion = 50
		}

		stress_impact = {
			chaste = minor_stress_impact_gain
			shy = minor_stress_impact_gain
			gregarious = miniscule_stress_impact_loss
			lustful = minor_stress_impact_loss
			arrogant = miniscule_stress_impact_loss
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_honor = -0.5
				ai_boldness = 0.5
			}
		}
	}

	# Take the compliment but do nothing
	option = {
		name = tournament_events.1405.c

		add_character_modifier = {
			modifier = tournament_charm_resistant_modifier
			years = 10
		}

		stress_impact = {
			base = miniscule_stress_impact_loss
			shy = miniscule_stress_impact_loss
			arrogant = miniscule_stress_impact_loss
			lustful = medium_stress_impact_gain
		}

		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				has_trait = lustful
			}
		}
	}
}

# Your child is excited
tournament_events.1406 = {
	type = activity_event
	title = tournament_events.1406.t
	desc = tournament_events.1406.desc
	theme = tournament_grounds
	window = widget_activity_locale_fullscreen_event
	left_portrait = {
		character = root
		animation = personality_honorable
	}
	right_portrait = {
		character = scope:root_child
		animation = ecstasy
	}

	cooldown = { years = 1 }

	trigger = {
		scope:activity = {
			any_guest_subset_current_phase = {
				name = spectator
				this = root
			}
			any_guest_subset_current_phase = {
				name = spectator
				is_ai = yes
				is_healthy = yes
				is_adult = no
				is_child_of = root
			}
		}
	}

	immediate = {
		scope:activity = {
			random_guest_subset_current_phase = {
				name = spectator
				limit = {
					is_ai = yes
					is_healthy = yes
					is_adult = no
					is_child_of = root
				}
				save_scope_as = root_child
			}
		}
	}

	# Calm down
	option = {
		name = tournament_events.1406.a
		trigger = {
			OR = {
				has_trait = callous
				has_trait = sadistic
			}
		}

		progress_towards_rival_effect = {
			CHARACTER = scope:root_child
			REASON = rival_traumatic_childhood
			OPINION = default_rival_opinion
		}

		scope:root_child = {
			add_martial_skill = 1
			add_prowess_skill = 1
		}

		stress_impact = {
			compassionate = medium_stress_impact_gain
			gregarious = medium_stress_impact_gain
			calm = minor_stress_impact_gain
			patient = minor_stress_impact_gain
			lazy = minor_stress_impact_gain
			scholar = minor_stress_impact_loss
			callous = minor_stress_impact_loss
			sadistic = minor_stress_impact_loss
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_vengefulness = 1
				ai_boldness = 0.5
			}
		}
	}

	# Put them on your shoulders
	option = {
		name = tournament_events.1406.b

		add_character_modifier = {
			modifier = tournament_child_friendly_modifier
			years = 15
		}

		reverse_add_opinion = {
			target = scope:root_child
			modifier = supportive_parent
			opinion = 50
		}

		stress_impact = {
			compassionate = miniscule_stress_impact_loss
			gregarious = miniscule_stress_impact_loss
			callous = medium_stress_impact_gain
			sadistic = medium_stress_impact_gain
		}

		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = callous
					has_trait = sadistic
				}
			}
		}
	}

	# I'm excited too!
	option = {
		name = tournament_events.1406.c

		progress_towards_friend_effect = {
			REASON = friend_bonded_during_tournament
			CHARACTER = scope:root_child
			OPINION = default_friend_opinion
		}

		stress_impact = {
			base = minor_stress_impact_loss
			calm = miniscule_stress_impact_loss
			content = miniscule_stress_impact_loss
			gregarious = miniscule_stress_impact_loss
			callous = minor_stress_impact_gain
			sadistic = minor_stress_impact_gain
		}

		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = callous
					has_trait = sadistic
				}
			}
		}
	}
}

# Someone is criticising your family member!
tournament_events.1407 = {
	type = activity_event
	title = tournament_events.1407.t
	desc = tournament_events.1407.desc
	theme = tournament_grounds
	window = widget_activity_locale_fullscreen_event
	left_portrait = {
		character = root
		animation = anger
	}
	right_portrait = {
		character = scope:shouting_fan
		animation = dismissal
	}
	lower_left_portrait = {
		character = scope:competing_family
	}

	cooldown = { years = 1 }

	trigger = {
		activity_is_competing_trigger = no
		any_close_family_member = {
			NOT = { this = root }
			involved_activity = scope:activity
			activity_is_competing_trigger = yes
			save_temporary_scope_as = competing_family
		}
		scope:activity = {
			any_guest_subset_current_phase = { # There is a member of the crowd who dislikes their performance
				name = spectator
				NOR = {
					this = root
					is_close_family_of = scope:competing_family
					has_relation_lover = scope:competing_family
					has_relation_friend = scope:competing_family
					has_relation_best_friend = scope:competing_family
					opinion = {
						target = scope:competing_family
						value >= low_positive_opinion
					}
				}
				is_ai = yes
				is_healthy = yes
				is_adult = yes
				NOT = { has_trait = wounded }
			}
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			is_ai = yes 
			factor = 0.25
		}
	}

	immediate = {
		random_close_family_member = {
			limit = {
				NOT = { this = root }
				involved_activity = scope:activity
				activity_is_competing_trigger = yes
			}
			save_scope_as = competing_family
		}
		scope:activity = {
			random_guest_subset_current_phase = {
				name = spectator
				limit = {
					NOR = {
						this = root
						is_close_family_of = scope:competing_family
						has_relation_lover = scope:competing_family
						has_relation_friend = scope:competing_family
						has_relation_best_friend = scope:competing_family
						opinion = {
							target = scope:competing_family
							value >= low_positive_opinion
						}
					}
					is_ai = yes
					is_healthy = yes
					is_adult = yes
					NOT = { has_trait = wounded }
				}
				save_scope_as = shouting_fan
			}
		}
	}

	# Fight them
	option = {
		name = tournament_events.1407.a

		trigger = {
			has_trait = wrathful
			can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root }
			scope:shouting_fan = {
				can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:shouting_fan }
			}
		}

		duel = {
			skill = prowess
			target = scope:shouting_fan
			50 = {
				desc = tournament_events.1407.a.success
				min = 10
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}

				scope:shouting_fan = {
					increase_wounds_no_death_effect = { REASON = fight }
				}

				scope:competing_family = {
					activity_tournament_change_contestant_score_effect = { SCORE = increase_minor }
				}
			}
			50 = {
				desc = tournament_events.1407.a.failure
				min = 10
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}

				increase_wounds_no_death_effect = { REASON = fight }

				scope:competing_family = {
					activity_tournament_change_contestant_score_effect = { SCORE = decrease_minor }
				}
			}
		}

		reverse_add_opinion = {
			target = scope:shouting_fan
			modifier = angry_opinion
			opinion = -35
		}

		stress_impact = {
			wrathful = miniscule_stress_impact_loss
			sadistic = miniscule_stress_impact_loss
			just = miniscule_stress_impact_loss
			arbitrary = medium_stress_impact_gain
			craven = medium_stress_impact_gain
		}

		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = arbitrary
					has_trait = craven
				}
			}
		}
	}

	# Try to drown them out with support
	option = {
		name = tournament_events.1407.b

		random_list = {
			10 = { #You succeed
				custom_tooltip = tournament_events.1407.b.success

				modifier = { #You're good at this if you aren't shy
					add = 6

					has_trait = gregarious
				}

				modifier = { #Or perhaps if you have big ol' lungs
					add = 8

					has_trait = giant
				}

				modifier = { #Or if you're strong
					add = 8

					OR = {
						has_trait = strong
						has_trait = physique_good
					}
				}

				modifier = { #Throw a little extra on to reward being loyal to your family
					add = 2

					has_trait = loyal
				}

				send_interface_toast = {
					type = event_toast_effect_good
					title = tournament_events.1407.b.success
					left_icon = root
					right_icon = scope:shouting_fan

					add_prestige = minor_prestige_gain

					scope:competing_family = {
						activity_tournament_change_contestant_score_effect = { SCORE = increase_minor }
					}	
				}
			}

			10 = { #You have to go back later and find it
				custom_tooltip = tournament_events.1407.b.failure

				modifier = { #You're bad at this if you stutter or lisp
					add = -8

					OR = {
						has_trait = stuttering
						has_trait = lisping
					}
				}

				modifier = { #Or if you wheeze
					add = -15

					has_trait = wheezing
				}

				modifier = { #Or if you're weak
					add = -5

					OR = {
						has_trait = weak
						has_trait = physique_bad
					}
				}

				send_interface_toast = {
					type = event_toast_effect_bad
					title = tournament_events.1407.b.failure
					left_icon = root
					right_icon = scope:shouting_fan

					add_prestige = minor_prestige_loss

					scope:competing_family = {
						activity_tournament_change_contestant_score_effect = { SCORE = decrease_minor }
					}
				}
			}
		}

		stress_impact = {
			wrathful = medium_stress_impact_gain
			calm = miniscule_stress_impact_loss
			just = miniscule_stress_impact_loss
			arbitrary = medium_stress_impact_gain
			compassionate = miniscule_stress_impact_loss
			callous = medium_stress_impact_gain
		}

		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = wrathful
					has_trait = callous
					has_trait = arbitrary
				}
			}
		}
	}

	# Ignore them
	option = {
		name = tournament_events.1407.c

		scope:competing_family = {
			activity_tournament_change_contestant_score_effect = { SCORE = decrease_minor }
		}

		stress_impact = {
			wrathful = medium_stress_impact_gain
			calm = miniscule_stress_impact_loss
			just = medium_stress_impact_gain
			arbitrary = miniscule_stress_impact_loss
			compassionate = medium_stress_impact_gain
			callous = miniscule_stress_impact_loss
		}

		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = compassionate
					has_trait = just
					has_trait = wrathful
				}
			}
		}
	}
}

# You go for some refreshments
tournament_events.1408 = {
	type = activity_event
	title = tournament_events.1408.t
	desc = tournament_events.1408.desc
	theme = tournament_grounds
	window = widget_activity_locale_fullscreen_event
	left_portrait = {
		character = root
		animation = thinking
	}
	right_portrait = {
		character = scope:drinking_fan
		animation = drink
	}

	cooldown = { years = 1 }

	trigger = {
		NOR = { #Ensure you aren't in the best spot in the house
			highest_held_title_tier >= scope:host.highest_held_title_tier
			scope:host = this
		}
		scope:activity = {
			any_guest_subset_current_phase = {
				name = spectator
				root = this
			}
			any_guest_subset_current_phase = { #Pick random adult spectator
				name = spectator
				is_healthy = yes
				is_adult = yes
			}
		}
	}

	immediate = {
		scope:activity = {
			random_guest_subset_current_phase = {
				name = spectator
				limit = {
					is_healthy = yes
					is_adult = yes
				}
				save_scope_as = drinking_fan
			}
		}
		save_scope_value_as = {
			name = crowd_range
			value = {
				integer_range = {
					min = 1
					max = 9
				}
			}
		}
	}

	# Buy a drink off a bystander
	option = {
		name = tournament_events.1408.a

		trigger = {
			diplomacy >= 8
		}

		show_as_unavailable = {
			always = yes
		}

		flavor = tournament_events.1408.a.tt

		remove_short_term_gold = minor_gold_value

		add_character_modifier = {
			modifier = tournament_refreshed_modifier
			years = 5
		}

		stress_impact = {
			generous = miniscule_stress_impact_loss
			greedy = minor_stress_impact_gain
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_boldness = -0.5
				ai_greed = -1
			}
		}
	}

	# Nip out of the line and chance losing your place
	option = {
		name = tournament_events.1408.b

		random_list = {
			40 = { #You succeed in making it back to your spot
				custom_tooltip = tournament_events.1408.b.success

				modifier = { #Good at running
					add = 15

					has_trait = athletic
				}

				modifier = { #Or if you're big to push through crowds
					add = 8

					OR = {
						has_trait = strong
						has_trait = physique_good
					}
				}

				modifier = { #Fuzzy it up a lil
					add = scope:crowd_range
				}

				send_interface_toast = {
					type = event_toast_effect_good
					title = tournament_events.1408.b.success
					left_icon = root
					right_icon = scope:drinking_fan

					remove_short_term_gold = tiny_gold_value

					add_character_modifier = {
						modifier = tournament_refreshed_modifier
						years = 5
					}
				}
			}

			40 = { #You fail to get back to your spot
				custom_tooltip = tournament_events.1408.b.failure

				modifier = { #Oh no! Unathletic!
					add = 15

					has_trait = wheezing
				}

				modifier = { #You're weak
					add = 5

					OR = {
						has_trait = weak
						has_trait = physique_bad
					}
				}

				send_interface_toast = {
					type = event_toast_effect_bad
					title = tournament_events.1408.b.failure
					left_icon = root
					right_icon = scope:drinking_fan
					
					remove_short_term_gold = tiny_gold_value

					add_character_modifier = {
						modifier = tournament_refreshed_modifier
						years = 5
					}

					add_stress = minor_stress_gain
				}
			}
			20 = { #You lose your spot AND fail to get a drink
				custom_tooltip = tournament_events.1408.b.criticalfailure

				modifier = { #Oh no! Unathletic!
					add = 15

					has_trait = wheezing
				}

				modifier = { #You're weak
					add = 5

					OR = {
						has_trait = weak
						has_trait = physique_bad
					}
				}

				send_interface_toast = {
					type = event_toast_effect_bad
					title = tournament_events.1408.b.criticalfailure
					left_icon = root
					right_icon = scope:drinking_fan

					add_stress = minor_stress_gain
				}
			}
		}

		stress_impact = { #Keep this small since we're handing out stress gains in failed results
			impatient = miniscule_stress_impact_loss
			patient = minor_stress_impact_gain
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_boldness = 0.5
				ai_greed = 1
			}
		}
	}

	# Grin and bear it
	option = {
		name = tournament_events.1408.c

		add_character_modifier = {
			modifier = tournament_parched_modifier
			years = 5
		}

		stress_impact = {
			diligent = minor_stress_impact_gain
			lazy = miniscule_stress_impact_loss
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_boldness = -1
				ai_greed = -0.5
			}
		}
	}
}

# You make a friend cheering for the same person
tournament_events.1409 = {
	type = activity_event
	title = tournament_events.1409.t
	desc = tournament_events.1409.desc
	theme = tournament_grounds
	window = widget_activity_locale_fullscreen_event
	left_portrait = {
		character = root
		animation = admiration
	}
	right_portrait = {
		character = scope:friendly_fan
		animation = happiness
	}
	lower_right_portrait = { character = scope:fan_favourite }
	lower_left_portrait = { character = scope:other_favourite }

	cooldown = { years = 1 }

	trigger = {
		is_in_guest_subset = { name = spectator }
		scope:activity = {
			NOR = { #Make sure it isn't a team game or a horse race
				has_current_phase = tournament_phase_melee
				has_current_phase = tournament_phase_horse_race
			}
			any_guest_subset_current_phase = { #Pick random adult spectator and make them friendly to you
				name = spectator
				is_healthy = yes
				is_adult = yes
				NOT = { this = root }
				NOR = {
					has_trait = callous
					has_trait = sadistic
					opinion = { target = root value < 0 }
				}
			}
			any_guest_subset_current_phase = { #Pick random participant
				name = qualified
				is_healthy = yes
				is_adult = yes
				is_alive = yes
				save_temporary_scope_as = first_participant
			}
			any_guest_subset_current_phase = { #Pick another random participant for juxtaposition
				name = qualified
				is_healthy = yes
				is_adult = yes
				is_alive = yes
				NOT = {
					this = scope:first_participant
				}
			}
		}
	}

	immediate = {
		scope:activity = {
			random_guest_subset_current_phase = {
				name = spectator
				limit = {
					is_healthy = yes
					is_adult = yes
					NOT = { this = root }
					NOR = {
						has_trait = callous
						has_trait = sadistic
						opinion = { target = root value < 0 }
					}
				}
				save_scope_as = friendly_fan
			}
			random_guest_subset_current_phase = {
				name = qualified
				limit = {
					is_healthy = yes
					is_adult = yes
					is_alive = yes
				}
				save_scope_as = fan_favourite
			}
			random_guest_subset_current_phase = {
				name = qualified
				limit = {
					is_healthy = yes
					is_adult = yes
					is_alive = yes
					NOT = {
						this = scope:fan_favourite
					}
				}
				save_scope_as = other_favourite
			}
		}
	}

	# Agree on their favourite
	option = {
		name = tournament_events.1409.a

		reverse_add_opinion = {
			target = scope:fan_favourite
			modifier = pleased_opinion
			opinion = 10
		}

		progress_towards_friend_effect = {
			REASON = friend_agreed_favourite
			CHARACTER = scope:friendly_fan
			OPINION = default_friend_opinion
		}

		stress_impact = {
			gregarious = miniscule_stress_impact_loss
			humble = miniscule_stress_impact_loss
			shy = minor_stress_impact_gain
			arrogant = minor_stress_impact_gain
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_boldness = -0.5
				ai_sociability = 1
			}
		}
	}

	# Disagree
	option = {
		name = tournament_events.1409.b

		reverse_add_opinion = {
			target = scope:other_favourite
			modifier = pleased_opinion
			opinion = 10
		}

		progress_towards_rival_effect = {
			REASON = rival_disagreed_favourite
			CHARACTER = scope:friendly_fan
			OPINION = default_rival_opinion
		}

		stress_impact = {
			gregarious = minor_stress_impact_gain
			humble = minor_stress_impact_gain
			shy = minor_stress_impact_gain
			arrogant = miniscule_stress_impact_loss
			stubborn = miniscule_stress_impact_loss
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_boldness = 0.5
				ai_sociability = -1
			}
		}
	}

	# Smile and nod
	option = {
		name = tournament_events.1409.c

		reverse_add_opinion = {
			target = scope:friendly_fan
			modifier = disappointed_opinion
			opinion = -15
		}

		stress_impact = {
			shy = medium_stress_impact_loss #throwing shy a bone here
			gregarious = minor_stress_impact_gain
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_boldness = -1
				ai_sociability = -1
			}
		}
	}
}

# Two fans begin fighting
tournament_events.1410 = {
	type = activity_event
	title = tournament_events.1410.t
	desc = tournament_events.1410.desc
	theme = tournament_grounds
	window = widget_activity_locale_fullscreen_event
	left_portrait = {
		character = root
		animation = shock
	}
	lower_right_portrait = { character = scope:fan_1 }
	lower_left_portrait = { character = scope:fan_2 }

	cooldown = { years = 1 }

	trigger = {
		NOR = { #Ensure you aren't in the best spot in the house
			highest_held_title_tier >= scope:host.highest_held_title_tier
			scope:host = this
		}
		is_in_guest_subset = { name = spectator }
		scope:activity = {
			any_guest_subset_current_phase = { #Pick random adult spectator
				name = spectator
				NOT = { this = root }
				is_healthy = yes
				is_adult = yes
				is_lowborn = yes #To avoid seeing emperors brawling
				NOT = { has_trait = wounded }
				save_temporary_scope_as = first_fighter
			}
			any_guest_subset_current_phase = { #Pick random adult spectator
				name = spectator
				is_healthy = yes
				NOT = { this = root }
				is_adult = yes
				is_lowborn = yes #To avoid seeing emperors brawling
				NOR = {
					has_trait = wounded
					this = scope:first_fighter
				}
			}
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			is_ai = yes 
			factor = 0.25
		}
	}

	immediate = {
		scope:activity = {
			random_guest_subset_current_phase = {
				name = spectator
				limit = {
					NOT = { this = root }
					is_healthy = yes
					is_adult = yes
					is_lowborn = yes
					NOT = { has_trait = wounded }
				}
				save_scope_as = fan_1
			}
			random_guest_subset_current_phase = {
				name = spectator
				limit = {
					NOT = { this = root }
					is_healthy = yes
					is_adult = yes
					is_lowborn = yes
					NOR = {
						has_trait = wounded
						this = scope:fan_1
					}
				}
				save_scope_as = fan_2
			}
		}
		save_scope_value_as = {
			name = fight_range
			value = {
				integer_range = {
					min = -5
					max = 5
				}
			}
		}
	}

	# Get in between them
	option = {
		name = tournament_events.1410.a

		flavor = tournament_events.1410.a.tt

		random_list = {
			40 = { #You break them up
				custom_tooltip = tournament_events.1410.a.success

				modifier = {
					add = 15

					OR = {
						has_trait = strong
						has_trait = physique_good
					}
				}

				modifier = { #Fuzzy it up a lil
					add = scope:fight_range
				}

				send_interface_toast = {
					type = event_toast_effect_good
					title = tournament_events.1410.a.success
					left_icon = root

					add_prestige = minor_prestige_value
				}
			}

			60 = { #You fail to break them up
				custom_tooltip = tournament_events.1410.b.failure

				modifier = { #You're weak
					add = 5

					OR = {
						has_trait = weak
						has_trait = physique_bad
					}
				}

				send_interface_toast = {
					type = event_toast_effect_bad
					title = tournament_events.1410.a.failure
					left_icon = root
					
					increase_wounds_no_death_effect = { REASON = fight }
				}
			}
		}

		stress_impact = {
			brave = miniscule_stress_impact_loss
			craven = minor_stress_impact_gain
			calm = minor_stress_impact_gain
			wrathful = miniscule_stress_impact_loss
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_boldness = 1
				ai_energy = 0.5
			}
		}
	}

	# Try and talk them down
	option = {
		name = tournament_events.1410.b

		duel = {
			skill = diplomacy
			value = decent_skill_rating
			50 = { #It works
				desc = tournament_events.1410.b.success
				min = 10
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}

				send_interface_toast = {
					type = event_toast_effect_good
					title = tournament_events.1410.b.success
					left_icon = root
					
					reverse_add_opinion = {
						target = scope:fan_1
						modifier = trust_opinion
						opinion = 15
					}
					reverse_add_opinion = {
						target = scope:fan_2
						modifier = trust_opinion
						opinion = 15
					}
				}
			}
			50 = { #It fails
				desc = tournament_events.1410.b.failure
				min = 10
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}

				send_interface_toast = {
					type = event_toast_effect_bad
					title = tournament_events.1410.b.failure
					left_icon = root
					
					add_prestige = minor_prestige_loss
				}
			}
		}

		stress_impact = {
			brave = minor_stress_impact_gain
			craven = miniscule_stress_impact_loss
			calm = miniscule_stress_impact_loss
			wrathful = minor_stress_impact_gain
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_boldness = -1
				ai_energy = -0.5
			}
		}
	}

	# Let them fight
	option = {
		name = tournament_events.1410.c

		random_list = {
			50 = { #Fan 1 wins
				custom_tooltip = tournament_events.1410.c.fan1

				modifier = { #Fuzzy it up a lil
					add = scope:fight_range
				}

				send_interface_toast = {
					type = event_toast_effect_neutral
					title = tournament_events.1410.c.fan1
					left_icon = root

					scope:fan_2 = {
						increase_wounds_no_death_effect = { REASON = fight }
					}
				}
			}

			50 = { #Fan 2 wins
				custom_tooltip = tournament_events.1410.c.fan2

				send_interface_toast = {
					type = event_toast_effect_neutral
					title = tournament_events.1410.c.fan2
					left_icon = root
					
					scope:fan_1 = {
						increase_wounds_no_death_effect = { REASON = fight }
					}
				}
			}
		}

		stress_impact = {
			diligent = minor_stress_impact_gain
			lazy = miniscule_stress_impact_loss
			just = minor_stress_impact_gain
			arbitrary = miniscule_stress_impact_loss
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_honor = -1
				ai_compassion = -0.5
			}
		}
	}
}

###################################
###################################
### 	INTENTS - 6000-6999		###
###################################
###################################

##################################################
# Murder Rival Sabotage - Contest
# by Joe Parkin
# 6000-6001
##################################################

# TODO_CD_CU: make progress toward intent completion

scripted_trigger tournament_murder_next_versus_match_trigger = {
	scope:activity = {
		has_current_phase = tournament_phase_$CONTEST$
		exists = var:contest_versus_progress
	}
	switch = {
		trigger = scope:activity.var:contest_versus_progress
		0 = {
			trigger_if = {
				limit = { exists = scope:murder_target.var:contest_qualified_match_$CONTEST$ }	
				scope:murder_target.var:contest_qualified_match_$CONTEST$ = {
					is_alive = yes
					exists = var:contest_aptitude
					involved_activity = root.involved_activity
				}
			}
			trigger_else = { always = no }
		}
		1 = {
			trigger_if = {
				limit = { exists = scope:murder_target.var:contest_semi_finalist_match_$CONTEST$ }	
				scope:murder_target.var:contest_semi_finalist_match_$CONTEST$ = {
					is_alive = yes
					exists = var:contest_aptitude
					involved_activity = root.involved_activity
				}
			}
			trigger_else = { always = no }
		}
		2 = {
			trigger_if = {
				limit = { exists = scope:murder_target.var:contest_finalist_match_$CONTEST$ }	
				scope:murder_target.var:contest_finalist_match_$CONTEST$ = {
					is_alive = yes
					exists = var:contest_aptitude
					involved_activity = root.involved_activity
				}
			}
			trigger_else = { always = no }
		}
		
	}
}

scripted_effect tournament_murder_next_versus_match_effect = {
	switch = {
		trigger = scope:activity.var:contest_versus_progress
		0 = {
			if = {
				limit = {
					exists = scope:murder_target.var:contest_qualified_match_$CONTEST$
					scope:murder_target.var:contest_qualified_match_$CONTEST$ = {
						is_alive = yes
						exists = var:contest_aptitude
						involved_activity = root.involved_activity
					}
				}
				scope:murder_target.var:contest_qualified_match_$CONTEST$ = { save_scope_as = murder_match }
			}
		}
		1 = {
			if = {
				limit = {
					exists = scope:murder_target.var:contest_semi_finalist_match_$CONTEST$
					scope:murder_target.var:contest_semi_finalist_match_$CONTEST$ = {
						is_alive = yes
						exists = var:contest_aptitude
						involved_activity = root.involved_activity
					}
				}
				scope:murder_target.var:contest_semi_finalist_match_$CONTEST$ = { save_scope_as = murder_match }
			}
		}
		2 = {
			if = {
				limit = {
					exists = scope:murder_target.var:contest_finalist_match_$CONTEST$
					scope:murder_target.var:contest_finalist_match_$CONTEST$ = {
						is_alive = yes
						exists = var:contest_aptitude
						involved_activity = root.involved_activity
					}
				}
				scope:murder_target.var:contest_finalist_match_$CONTEST$ = { save_scope_as = murder_match }
			}
		}
		
	}
}

scripted_effect tournament_murder_intent_sabotage_duel_effect = {
	random_list = {
		10 = {
			trigger = {
				NOT = { exists = scope:murder_match }
			}
			custom_tooltip = tournament_events_murder_sabotage_contest_tt
		}
		10 = {
			trigger = { exists = scope:murder_match }
			min = 5
			modifier = { add = intrigue }
			desc = tournament_events.6000.success
			save_scope_as = murder_success
			custom_tooltip = tournament_events.6000.blame
			if = {
				limit = { scope:murder_target = scope:host }
				custom_tooltip = tournament_events.6000.imprisonment_tt
			}
			random_list = {
				5 = {
					desc = tournament_events.6000.success_tt
					show_chance = no
					show_as_tooltip = {
						scope:murder_target = {
							death = {
								death_reason = death_contest_melee_accident
								killer = scope:murder_match
							}
						}
					}
				}
				5 = {
					desc = tournament_events.6000.injuries
					show_chance = no
					show_as_tooltip = {
						scope:murder_target = {
							increase_wounds_effect = { REASON = contest_melee_accident }
						}
					}
				}
			}
		}
		20 = {
			trigger = {
				exists = scope:murder_match
				NOT = { scope:murder_match = root }
			}
			desc = tournament_events.6000.failure
		}
	}
}

scripted_effect tournament_murder_intent_sabotage_effect = {
	set_variable = {
		name = contest_murder_attempt
		value = scope:murder_target
	}
	if = {
		limit = { has_relation_rival = scope:murder_target }
		stress_impact = {
			base = minor_stress_impact_loss
		}
	}
	stress_impact = {
		humble = medium_stress_impact_gain
		honest = medium_stress_impact_gain
		compassionate = medium_stress_impact_gain
		just = medium_stress_impact_gain
		forgiving = medium_stress_impact_gain
	}
	scope:activity = {
		add_activity_log_entry = {
			key = tournament_murder_attempt_log
			tags = { intent murder crime }
			score = 10
			character = root
			target = scope:murder_target
		}
	}
	trigger_event = {
		id = tournament_events.6001
		days = { 2 3 }
	}
}

scripted_effect tournament_sabotage_flavor_effect = {
	hidden_effect = {
		scope:activity = {
			random_list = {
				10 = {
					trigger = {
						OR = {
							has_current_phase = tournament_phase_melee
							has_current_phase = tournament_phase_duel
						}
					}
					save_scope_value_as = { name = sabotage_flavor value = flag:foot }
				}
				10 = {
					trigger = { has_current_phase = tournament_phase_archery }
					save_scope_value_as = { name = sabotage_flavor value = flag:archery }
				}
				10 = {
					trigger = { has_current_phase = tournament_phase_wrestling }
					save_scope_value_as = { name = sabotage_flavor value = flag:pugilism }
				}
				10 = {
					trigger = { has_current_phase = tournament_phase_joust }
					save_scope_value_as = { name = sabotage_flavor value = flag:horse }
				}
				10 = {
					trigger = { has_current_phase = tournament_phase_horse_race }
					save_scope_value_as = { name = sabotage_flavor value = flag:horse_race }
				}
				#EK ADDITION
				10 = {
					trigger = { has_current_phase = tournament_phase_arcane_clash }
					save_scope_value_as = { name = sabotage_flavor value = flag:magic }
				}
				#EK ADDITION END
			}
		}
	}
}

tournament_events.6000 = { # Setup for contest murder attempts
	type = activity_event
	title = tournament_events.6000.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { exists = var:contest_murder_attempt }
				desc = tournament_events.6000.again
			}
			triggered_desc = {
				trigger = { exists = var:contest_murder_offer }
				desc = tournament_events.6000.deferred
			}
			desc = tournament_events.6000.desc
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:activity = {
						OR = {
							has_current_phase = tournament_phase_melee
							has_current_phase = tournament_phase_duel
						}
					}
				}
				desc = tournament_events.6000.foot
			}
			triggered_desc = {
				trigger = {
					scope:activity = { has_current_phase = tournament_phase_joust }
				}
				desc = tournament_events.6000.joust
			}
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:murder_match
					scope:murder_match = root
				}
				desc = tournament_events.6000.self_match
			}
			triggered_desc = {
				trigger = {
					exists = scope:murder_match
					NOT = { scope:murder_match = root }
				}
				desc = tournament_events.6000.patsy_match
			}
		}
	}
	theme = tournament_grounds
	left_portrait = {
		character = root
		animation = worry
	}
	lower_right_portrait = { character = scope:murder_target }
	lower_left_portrait = {
		trigger = {
			NOT = { root = scope:murder_match }
		}
		character = scope:murder_match
	}
	override_background = { reference = tavern } # TODO_CD_EP2: replace with proper art

	trigger = {
		#DLC check.
		#has_ep2_dlc_trigger = yes
		
		#Standard checks.
		has_activity_intent = murder_attendee_intent
		scope:activity = {
			any_attending_character = {
				NOT = { this = root }
				exists = var:contest_aptitude
				this = root.intent_target
			}
			OR = {
				has_current_phase = tournament_phase_melee
				has_current_phase = tournament_phase_joust
				has_current_phase = tournament_phase_duel
			}
		}
		NOR = {
			exists = var:contest_murder_attempt
			exists = var:contest_murder_match
		}
	}

	immediate = {
		save_scope_as = murder_actor
		intent_target = { save_scope_as = murder_target }
		set_variable = {
			name = contest_murder_target
			value = intent_target
		}
		if = {
			limit = {
				scope:activity = { activity_tournament_versus_contest_trigger = yes }
				intent_target = { exists = var:contest_aptitude }
			}
			if = {
				limit = {
					tournament_murder_next_versus_match_trigger = { CONTEST = joust }
				}
				tournament_murder_next_versus_match_effect = { CONTEST = joust }
			}
			else_if = {
				limit = {
					tournament_murder_next_versus_match_trigger = { CONTEST = duel }
				}
				tournament_murder_next_versus_match_effect = { CONTEST = duel }
			}
		}
		tournament_sabotage_flavor_effect = yes
		if = {
			limit = { exists = var:contest_murder_offer }
			set_variable = {
				name = contest_murder_offer
				value = 1
			}
		}
		else = {
			change_variable = {
				name = contest_murder_offer
				add = 1
			}
		}
	}

	option = { # No match - turn/team
		name = tournament_events.6000.a
		trigger = {
			NOT = { exists = scope:murder_match }
		}
		remove_short_term_gold = minor_gold_value
		tournament_murder_intent_sabotage_duel_effect = yes
		tournament_murder_intent_sabotage_effect = yes
	}

	option = { # Other match - versus
		name = tournament_events.6000.b
		trigger = {
			exists = scope:murder_match
			NOT = { this = scope:murder_match }
		}
		set_variable = {
			name = contest_murder_match
			value = scope:murder_match
		}
		remove_short_term_gold = minor_gold_value
		tournament_murder_intent_sabotage_duel_effect = yes
		tournament_murder_intent_sabotage_effect = yes
	}

	option = { # Self match - versus
		name = tournament_events.6000.c
		trigger = {
			exists = scope:murder_match
			this = scope:murder_match
		}
		set_variable = {
			name = contest_murder_match
			value = scope:murder_match
		}
		remove_short_term_gold = minor_gold_value
		tournament_murder_intent_sabotage_duel_effect = yes
		tournament_murder_intent_sabotage_effect = yes
	}

	option = { # Wait
		name = tournament_events.6000.d
		trigger = {
			exists = scope:murder_match
			NOT = { this = scope:murder_match }
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_vengefulness = 1
				ai_rationality = -1
			}
		}
	}

	option = { # Do nothing
		name = tournament_events.6000.e
		trigger = {
			NOT = { exists = scope:murder_match }
		}
		stress_impact = {
			ambitious = medium_stress_impact_gain
			deceitful = medium_stress_impact_gain
			callous = medium_stress_impact_gain
			arbitrary = medium_stress_impact_gain
			stubborn = medium_stress_impact_gain
			vengeful = medium_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_honor = 1
				ai_boldness = -0.5
			}
		}
	}
}

tournament_events.6001 = { # Sabotage Outcome
	type = activity_event
	title = tournament_events.6001.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:sabotage_flavor = flag:foot }
				desc = tournament_events.6001.foot
			}
			triggered_desc = {
				trigger = { scope:sabotage_flavor = flag:horse }
				desc = tournament_events.6001.horse
			}
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:murder_success
					exists = scope:murder_match
					NOT = { this = scope:murder_match }
				}
				desc = tournament_events.6001.success_patsy
			}
			triggered_desc = {
				trigger = { exists = scope:murder_success }
				desc = tournament_events.6001.success
			}
			desc = tournament_events.6001.failure
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:murder_match
					exists = scope:murder_success
				}
				desc = tournament_events.6001.closing
			}
		}
	}
	theme = tournament_grounds
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = { exists = scope:murder_success }
			animation = schadenfreude
		}
		triggered_animation = {
			trigger = { 
				NOT = { exists = scope:murder_success }
			}
			animation = stress
		}
	}
	lower_right_portrait = {
		trigger = { exists = scope:murder_target }
		character = scope:murder_target
	}
	lower_left_portrait = {
		trigger = { exists = scope:murder_match }
		character = scope:murder_match
	}

	override_background = { reference = armory } # TODO_CD_EP2: replace with proper art

	cooldown = { years = 1 }

	trigger = {
		#DLC check.
		#has_ep2_dlc_trigger = yes
	}

	immediate = {
		scope:murder_target = {
			if = {
				limit = {
					NOT = { exists = var:murder_sabotage_target }
				}
				set_variable = {
					name = murder_sabotage_target
					value = 0
				}
			}
			else = {
				change_variable = {
					name = murder_sabotage_target
					add = 1
				}
			}
		}
	}

	option = { # Success
		name = tournament_events.6001.a
		trigger = { exists = scope:murder_success }
	}

	option = { # Failure
		name = tournament_events.6001.b
		trigger = {
			NOT = { exists = scope:murder_success }
		}
	}
}

##################################################
# Murder Rival Sabotage
# by Joe Parkin
# 6010-6011
##################################################

# TODO_CD_CU: make progress toward intent completion

tournament_events.6010 = {
	type = activity_event
	title = tournament_events.6010.t
	desc = tournament_events.6010.desc
	theme = tournament_grounds
	left_portrait = {
		character = root
		animation = schadenfreude
	}
	lower_center_portrait = {
		character = scope:murder_target
	}
	cooldown = { years = 1 }
	override_background = {
		reference = tavern
		trigger = {
			scope:murder_target.faith = {
				NOT = { trait_is_sin = drunkard }
			}
		}
	}

	trigger = {
		#DLC check.
		#has_ep2_dlc_trigger = yes
		
		#Standard checks.
		has_activity_intent = murder_attendee_intent
		scope:activity = {
			any_attending_character = {
				NOT = { this = root }
				this = root.intent_target
				is_alive = yes
			}
		}
		NOT = { has_variable = tournament_murder_attempt }
	}

	immediate = {
		set_variable = {
			name = tournament_murder_attempt
			years = 1
		}
		save_scope_as = murder_actor
		intent_target = { save_scope_as = murder_target }
	}

	option = { # Attempt to poison them
		name = tournament_events.6010.a
		flavor = tournament_events.6010.a.flavor
		remove_short_term_gold = minor_gold_value
		save_scope_as = poison_method
		scope:murder_target = {
			random_list = {
				30 = { # They just get a little tummy ache
					min  = 5
					desc = tournament_events.6010.a.failure
					modifier = {
						factor = {
							value = health
							multiply = 0.25
						}
					}
					hidden_effect = {
						random = {
							chance = 50
							save_scope_as = poison_second_chance
						}
					}
					show_as_tooltip = {
						add_character_modifier = {
							modifier = tournament_poison_tummy_ache_modifier
							months = 9
						}
					}
				}
				30 = { # They get sick and withdraw from the contest
					min  = 5
					desc = tournament_events.6010.a.ill
					modifier = {
						factor = {
							value = 7
							subtract = health
							multiply = 0.25
						}
					}
					trigger = {
						NOT = { has_trait = ill }
						activity_is_valid_tournament_contestant = yes
					}
					save_scope_as = poison_ill
					show_as_tooltip = { add_trait = ill }
					custom_description = {
						text = tournament_contest_withdraw_tt
						subject = root
					}
				}
				20 = { # They die
					min = 5
					desc = tournament_events.6010.a.success
					modifier = {
						factor = {
							value = 7
							subtract = health
							multiply = 0.25
						}
					}
					save_scope_as = poison_death
					show_as_tooltip = {
						death = {
							killer = root
							death_reason = death_poison
						}
					}
				}
			}
		}
		trigger_event = {
			id = tournament_events.6011
			days = { 2 3 }
		}
		stress_impact = {
			craven = medium_stress_impact_gain
			just = medium_stress_impact_gain
			forgiving = medium_stress_impact_gain
			honest = medium_stress_impact_gain
		}
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_boldness = 0.25
				ai_vengefulness = 0.5
				ai_greed = -0.25
				ai_rationality = -0.25
			}
		}
	}

	option = { # Hire thug
		name = tournament_events.6010.b
		flavor = tournament_events.6010.b.flavor
		remove_short_term_gold = medium_gold_value
		scope:murder_target = {
			random_list = {
				50 = { # They get away
					desc = tournament_events.6010.b.failure
					modifier = {
						add = {
							value = intrigue
							multiply = 0.25
						}
					}
					show_as_tooltip = {
						add_character_modifier = {
							modifier = tournament_thug_escape_modifier
							months = 9
						}
					}
				}
				30 = { # The thug is caught and reveals involvement
					desc = tournament_events.6010.b.caught
					modifier = {
						add = {
							value = prowess
							multiply = 0.25
						}
					}
					show_as_tooltip = {
						add_opinion = {
							target = root
							modifier = attempted_murder_me_crime
						}
					}
					save_scope_as = thug_caught
				}
				20 = { # The thug is successful
					desc = tournament_events.6010.b.success
					modifier = {
						add = {
							value = 20
							subtract = prowess
							multiply = 0.25
						}
					}
					modifier = {
						add = {
							value = 20
							subtract = intrigue
							multiply = 0.25
						}
					}
					show_as_tooltip = {
						death = {
							killer = root
							death_reason = death_poison
						}
					}
					save_scope_as = thug_death
				}
			}	
		}
		trigger_event = {
			id = tournament_events.6011
			days = { 2 3 }
		}
		stress_impact = {
			craven = medium_stress_impact_gain
			just = medium_stress_impact_gain
			forgiving = medium_stress_impact_gain
			honest = medium_stress_impact_gain
		}
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_boldness = 0.75
				ai_vengefulness = 0.5
				ai_greed = -0.5
				ai_rationality = -0.25
			}
		}
	}

	option = { # Do nothing
		name = tournament_events.6010.c
		stress_impact = {
			brave = medium_stress_impact_gain
			arbitrary = medium_stress_impact_gain
			vengeful = medium_stress_impact_gain
			deceitful = medium_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_boldness = -0.5
				ai_vengefulness = 0.5
				ai_greed = 0.5
				ai_rationality = 0.5
			}
		}
	}
}

tournament_events.6011 = { # Murderer event
	type = activity_event
	title = tournament_events.6011.t
	desc = {
		first_valid = {
			first_valid = {
				triggered_desc = {
					trigger = { exists = scope:poison_method }
					desc = tournament_events.6011.poison
				}
				desc = tournament_events.6011.thug
			}
		}
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:poison_death }
				desc = tournament_events.6011.death
			}
			triggered_desc = {
				trigger = { exists = scope:poison_ill }
				desc = tournament_events.6011.ill
			}
			triggered_desc = {
				trigger = { exists = scope:poison_second_chance }
				desc = tournament_events.6011.second_chance
			}
		triggered_desc = {
				trigger = { exists = scope:poison_method }
				desc = tournament_events.6011.ache
			}
			triggered_desc = {
				trigger = { exists = scope:thug_death }
				desc = tournament_events.6011.slain
			}
			triggered_desc = {
				trigger = { exists = scope:thug_caught }
				desc = tournament_events.6011.caught
			}
			desc = tournament_events.6011.escape
		}
	}
	theme = tournament_grounds
	left_portrait = {
		trigger = {	exists = scope:poison_method }
		character = root
		triggered_animation = {
			trigger = { exists = scope:poison_death }
			animation = schadenfreude
		}
		triggered_animation = {
			trigger = {
				NOT = { exists = scope:poison_death }
			}
			animation = worry
		}
	}
	right_portrait = {
		character = scope:murder_target
		triggered_animation = {
			trigger = { exists = scope:poison_death }
			animation = poison
		}
		triggered_animation = {
			trigger = { exists = scope:poison_method }
			animation = sick
		}
		triggered_animation = {
			trigger = {
				NOT = { exists = scope:poison_method }
				exists = scope:thug_death
			}
			animation = loss_1
		}
		triggered_animation = {
			trigger = {
				NOT = { exists = scope:poison_method }
				exists = scope:thug_caught
			}
			animation = anger
		}
		triggered_animation = {
			trigger = {
				NOT = { exists = scope:poison_method }
				NOR = {
					exists = scope:thug_caught
					exists = scope:thug_death
				}
			}
			animation = paranoia
		}
	}
	override_background = {
		trigger = {
			OR = {
				exists = scope:poison_second_chance
				NOT = { exists = scope:poison_method }
			}
		}
		reference = alley_night
	}
	override_background = {
		trigger = {
			NOR = {
				exists = scope:poison_second_chance
				NOT = { exists = scope:poison_method }
			}
		}
		reference = tavern
	}
	immediate = {
		scope:murder_target = {
			trigger_event = tournament_events.6012
			if = {
				limit = { exists = scope:poison_death }
				scope:activity = {
					add_activity_log_entry = {
						key = tournament_poison_death_log
						score = 50
						tags = { intent murder death crime }
						character = root
						target = scope:murder_target

						# Effect
						scope:murder_target = {
							show_as_tooltip = {
								death = { killer = root death_reason = death_poison }
							}
						}
					}
				}
			}
			else_if = {
				limit = { exists = scope:poison_ill }
				scope:activity = {
					add_activity_log_entry = {
						key = tournament_poison_ill_log
						score = 50
						tags = { intent murder crime }
						character = root
						target = scope:murder_target

						# Effect
						scope:murder_target = {
							show_as_tooltip = { add_trait_force_tooltip = ill }
						}
						custom_description = {
							text = tournament_contest_withdraw_tt
							subject = scope:murder_target
						}
					}
				}
			}
			else_if = {
				limit = { exists = scope:poison_method }
				show_as_tooltip = {
					add_character_modifier = {
						modifier = tournament_poison_tummy_ache_modifier
						months = 6
					}
				}
			}
			else_if = {
				limit = { exists = scope:thug_death }
				scope:activity = {
					add_activity_log_entry = {
						key = tournament_thug_death_log
						score = 50
						tags = { intent murder death crime }
						character = root
						target = scope:murder_target

						# Effect
						scope:murder_target = {
							show_as_tooltip = {
								death = { killer = root death_reason = death_poison }
							}
						}
					}
				}
			}
			else_if = {
				limit = { exists = scope:thug_caught }
				scope:activity = {
					add_activity_log_entry = {
						key = tournament_thug_caught_log
						score = 50
						tags = { intent murder crime }
						character = root
						target = scope:murder_target

						# Effect
						show_as_tooltip = {
							attempted_murder_opinion_effect = {
								VICTIM = scope:murder_target
								MURDERER = scope:murder_actor
							}
						}
					}
				}
			}
			else = {
				show_as_tooltip = {
					add_character_modifier = {
						modifier = tournament_thug_escape_modifier
						months = 9
					}
				}
			}
		}
	}

	option = { # Ok
		name = {
			text = tournament_events.6011.a.death
			trigger = { exists = scope:poison_death }
		}
		name = {
			text = tournament_events.6011.a.ill
			trigger = { exists = scope:poison_ill }
		}
		name = {
			text = tournament_events.6011.a.slain
			trigger = { exists = scope:thug_death }
		}
		name = {
			text = tournament_events.6011.a.caught
			trigger = { exists = scope:thug_caught }
		}
		name = {
			text = tournament_events.6011.a
			trigger = {
				NOR = {
					exists = scope:poison_death
					exists = scope:poison_ill
					exists = scope:thug_death
					exists = scope:thug_caught
				}
			}
		}
		trigger = {
			NOT = { exists = scope:poison_second_chance }
		}
		if = {
			limit = {
				scope:murder_target = { is_alive = no }
			}
			add_secret = {
				type = secret_murder
				target = scope:murder_target
			}
			stress_impact = {
				paranoid = medium_stress_impact_gain
			}
		}
		else = {
			add_secret = {
				type = secret_murder_attempt
				target = scope:murder_target
			}
		}
		ai_chance = {
			base = 50
		}
	}
	
	option = { # Attempt to slit throat
		name = tournament_events.6011.b
		trigger = { exists = scope:poison_second_chance }
		duel = {
			skill = prowess
			target = scope:murder_target
			50 = {
				desc = tournament_events.6011.b.success
				min = 10
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				show_as_tooltip = {
					scope:murder_target = {
						death = {
							killer = root
							death_reason = death_murder
						}
					}
				}
				save_scope_as = second_chance_success
			}
			50 = {
				desc = tournament_events.6011.b.failure
				min = 10
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				show_as_tooltip = {
					scope:murder_target = {
						increase_wounds_effect = { REASON = fight }
						add_opinion = {
							modifier = attempted_murder_me_crime
							target = root
						}
					}
				}
			}
		}
		trigger_event = tournament_events.6013
		stress_impact = {
			craven = medium_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_boldness = 1
				ai_energy = 0.5
			}
		}
	}

	option = { # Give up
		name = tournament_events.6011.c
		trigger = { exists = scope:poison_second_chance }
		stress_impact = {
			brave = medium_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_boldness = -0.5
				ai_energy = -0.5
			}
		}
	}
}

tournament_events.6012 = { # Victim event
	type = activity_event
	title = tournament_events.6011.t
	desc = {
		first_valid = {
			first_valid = {
				triggered_desc = {
					trigger = { exists = scope:poison_method }
					desc = tournament_events.6012.poison
				}
				desc = tournament_events.6012.thug
			}
		}
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:poison_death }
				desc = tournament_events.6012.death
			}
			triggered_desc = {
				trigger = { exists = scope:poison_ill }
				desc = tournament_events.6012.ill
			}
			triggered_desc = {
				trigger = { exists = scope:poison_method }
				desc = tournament_events.6012.poison
			}
			triggered_desc = {
				trigger = { exists = scope:thug_death }
				desc = tournament_events.6012.slain
			}
			triggered_desc = {
				trigger = { exists = scope:thug_caught }
				desc = tournament_events.6012.caught
			}
			desc = tournament_events.6012.escape
		}
	}
	theme = tournament_grounds
	left_portrait = {
		character = root
		animation = poison
	}
	override_background = { reference = tavern }

	immediate = {
		if = {
			limit = { exists = scope:poison_death }
			unknown_murder_effect = { VICTIM = scope:murder_target MURDERER = scope:murder_actor REASON = death_poison }
		}
		else_if = {
			limit = { exists = scope:poison_ill }
			contract_disease_effect = { DISEASE = ill TREATMENT_EVENT = yes }
			custom_description = {
				text = tournament_contest_withdraw_tt
				subject = root
			}
		}
		else_if = {
			limit = { exists = scope:poison_method }
			add_character_modifier = {
				modifier = tournament_poison_tummy_ache_modifier
				months = 6
			}
		}
		else_if = {
			limit = { exists = scope:thug_death }
			unknown_murder_effect = { VICTIM = scope:murder_target MURDERER = scope:murder_actor REASON = death_murder }
		}
		else_if = {
			limit = { exists = scope:thug_caught }
			attempted_murder_opinion_effect = {
				VICTIM = scope:murder_target
				MURDERER = scope:murder_actor
			}
		}
		else = {
			add_character_modifier = {
				modifier = tournament_thug_escape_modifier
				months = 9
			}
		}
	}

	option = { # Ok
		name = {
			text = tournament_events.6012.a.death
			trigger = { exists = scope:poison_death }
		}
		name = {
			text = tournament_events.6012.a.ill
			trigger = { exists = scope:poison_ill }
		}
		name = {
			text = tournament_events.6012.a.poison
			trigger = { exists = scope:poison_method }
		}
		name = {
			text = tournament_events.6012.a.slain
			trigger = { exists = scope:thug_death }
		}
		name = {
			text = tournament_events.6012.a.caught
			trigger = { exists = scope:thug_caught }
		}
		name = {
			text = tournament_events.6012.a
			trigger = {
				NOR = {
					exists = scope:poison_death
					exists = scope:poison_ill
					exists = scope:poison_method
					exists = scope:thug_death
					exists = scope:thug_caught
				}
			}
		}
	}
}

tournament_events.6013 = { # Second chance - Murderer event
	type = activity_event
	title = tournament_events.6013.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:second_chance_success }
				desc = tournament_events.6013.death
			}
			desc = tournament_events.6013.fallback
		}
	}
	theme = tournament_grounds
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = { exists = scope:second_chance_success }
			animation = happiness
		}
		triggered_animation = {
			trigger = { is_alive = yes }
			animation = assassin
		}
	}
	right_portrait = {
		trigger = { exists = scope:second_chance_success }
		character = scope:murder_target
		animation = loss_1
	}
	override_background = { reference = alley_night }

	immediate = {
		scope:murder_target = {
			trigger_event = tournament_events.6014
			if = {
				limit = { exists = scope:second_chance_success }
				scope:activity = {
					add_activity_log_entry = {
						key = tournament_murder_death_log
						score = 50
						tags = { intent murder death crime }
						character = root
						target = scope:murder_target

						# Effect
						scope:murder_target = {
							show_as_tooltip = {
								death = {
									killer = root
									# TODO secret
									death_reason = death_poison
								}
							}
						}
					}
				}
			}
			else = {
				scope:activity = {
					add_activity_log_entry = {
						key = tournament_murder_wound_log
						tags = { intent murder crime }
						score = 10
						character = root
						target = scope:murder_target

						# Effect
						root = {
							show_as_tooltip = {
								increase_wounds_effect = { REASON = murder }
								attempted_murder_opinion_effect = {
									MURDERER = root
									VICTIM = scope:murder_target
								}
							}
						}
					}
				}
			}
		}
	}

	option = { # Ok
		name = {
			text = tournament_events.6013.a.death
			trigger = { exists = scope:second_chance_success }
		}
		name = {
			text = tournament_events.6013.a
			trigger = {
				NOT = { exists = scope:second_chance_success }
			}
		}
		if = {
			limit = {
				scope:murder_target = { is_alive = no }
			}
			add_secret = {
				type = secret_murder
				target = scope:murder_target
			}
			stress_impact = {
				paranoid = medium_stress_impact_gain
			}
		}
		else = {
			add_secret = {
				type = secret_murder_attempt
				target = scope:murder_target
			}
		}
	}
}

tournament_events.6014 = { # Second chance - Victim event
	type = activity_event
	title = tournament_events.6014.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:second_chance_success }
				desc = tournament_events.6014.death
			}
			desc = tournament_events.6014.fallback
		}
	}
	theme = tournament_grounds
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = { exists = scope:second_chance_success }
			animation = fear
		}
		triggered_animation = {
			trigger = {
				NOT = { exists = scope:second_chance_success }
			}
			animation = pain
		}
	}
	right_portrait = {
		character = scope:murder_actor
		trigger = { is_alive = yes }
		animation = assassin
	}
	override_background = { reference = tavern }

	immediate = {
		if = {
			limit = { exists = scope:second_chance_success }
			death = { death_reason = death_murder }
		}
		else = {
			increase_wounds_effect = { REASON = murder }
			attempted_murder_opinion_effect = {
				MURDERER = root
				VICTIM = scope:murder_target
			}
		}
	}

	option = { # Ok
		name = {
			text = tournament_events.6013.a.death
			trigger = { exists = scope:second_chance_success }
		}
		name = {
			text = tournament_events.6013.a
			trigger = {
				NOT = { exists = scope:second_chance_success }
			}
		}
	}
}

##################################################
# Win Contest Sabotage
# by Joe Parkin
# 6050-6053
##################################################

scripted_effect tournament_win_intent_sabotage_effect = {
	save_scope_as = sabotage_actor
	$CHARACTER$ = {
		save_scope_as = sabotage_target
		save_scope_as = contest_compare
	}
	set_variable = {
		name = contest_sabotage_attempt
		value = scope:sabotage_target
	}
	# Determine tooltips
	if = { # Much better competitor
		limit = { tournament_contest_aptitude_diff_value < -30 } # Your score minus their score
		if = {
			limit = { scope:activity = { has_current_phase = tournament_phase_horse_race } }
			custom_tooltip = contest_sabotage_score_diff_far_behind_horse_race_tt
		}
		else = { custom_tooltip = contest_sabotage_score_diff_far_behind_tt }
	}
	else_if = { # Better competitor
		limit = { tournament_contest_aptitude_diff_value < -10 } # Your score minus their score
		if = {
			limit = { scope:activity = { has_current_phase = tournament_phase_horse_race } }
			custom_tooltip = contest_sabotage_score_diff_behind_horse_race_tt
		}
		else = { custom_tooltip = contest_sabotage_score_diff_behind_tt }
	}
	else_if = { # Close competitor
		limit = {
			tournament_contest_aptitude_diff_value >= -10 # Your score minus their score
			tournament_contest_aptitude_diff_value <= 10 # Your score minus their score
		}
		if = {
			limit = { scope:activity = { has_current_phase = tournament_phase_horse_race } }
			custom_tooltip = contest_sabotage_score_diff_close_horse_race_tt
		}
		else = { custom_tooltip = contest_sabotage_score_diff_close_tt }
	}
	else_if = { # Worse competitor
		limit = { tournament_contest_aptitude_diff_value > 10 } # Your score minus their score
		if = {
			limit = { scope:activity = { has_current_phase = tournament_phase_horse_race } }
			custom_tooltip = contest_sabotage_score_diff_ahead_horse_race_tt
		}
		else = { custom_tooltip = contest_sabotage_score_diff_ahead_tt }
	}
	else = { # Much worse competitor
		if = {
			limit = { scope:activity = { has_current_phase = tournament_phase_horse_race } }
			custom_tooltip = contest_sabotage_score_diff_far_ahead_horse_race_tt
		}
		else = { custom_tooltip = contest_sabotage_score_diff_far_ahead_tt }
	}
	# Determine outcome
	random_list = {
		# Successful sabotage
		10 = {
			min = 5
			modifier = { add = intrigue }
			desc = tournament_events.6050.success
			save_scope_as = sabotage_success
			show_as_tooltip = {
				scope:sabotage_target = {
					activity_tournament_change_contestant_score_effect = { SCORE = decrease_medium }
				}
			}
		}
		# Sabotage detected
		5 = {
			min = 5
			modifier = { add = scope:sabotage_target.intrigue }
			desc = tournament_events.6050.detected
			save_scope_as = sabotage_detected
			# Add log entry TODO_CD_EP2: configure hiding
			scope:activity = {
				add_activity_log_entry = {
					key = tournament_sabotage_log
					score = 50
					tags = { intent sabotage }
					character = root
					target = scope:sabotage_target

					# Effect
					show_as_tooltip = {
						root = {
							progress_towards_rival_effect = {
								REASON = rival_tournament_attempted_sabotage
								CHARACTER = scope:sabotage_target
								OPINION = 0
							}
							reverse_add_opinion = {
								target = scope:sabotage_target
								modifier = tournament_attempted_sabotage_opinion
								opinion = -20
							}
							add_prestige = minor_prestige_loss
							add_character_modifier = {
								modifier = tournament_attempted_sabotage_modifier
								years = 3
							}
						}
					}
				}
			}
			if = {
				limit = { scope:sabotage_target = scope:host }
				custom_tooltip = tournament_host_disqualification_tt
			}
			else_if = {
				limit = {
					NOT = { root = scope:host }
				}
				custom_tooltip = tournament_contestant_disqualification_tt
			}
		}
		# Sabotage fails
		20 = {
			desc = tournament_events.6050.failure
		}
	}
	if = {
		limit = { has_relation_rival = scope:sabotage_target }
		stress_impact = { base = minor_stress_impact_loss }
	}
	stress_impact = {
		humble = medium_stress_impact_gain
		honest = medium_stress_impact_gain
		compassionate = medium_stress_impact_gain
		just = medium_stress_impact_gain
	}
	# Determine sabotage flavor
	tournament_sabotage_flavor_effect = yes
	if = {
		limit = {
			exists = scope:sabotage_detected
			NOT = { this = scope:host }
			scope:host = { is_ai = no }
		}
		scope:host = {
			trigger_event = {
				id = tournament_events.6052
				days = 1
			}
		}
	}
	else = {
		trigger_event = {
			id = tournament_events.6051
			days = 1
		}
	}
}

tournament_events.6050 = { # Setup
	type = activity_event
	title = tournament_events.6050.t
	desc = tournament_events.6050.desc
	theme = tournament_grounds
	window = widget_activity_locale_fullscreen_event
	left_portrait = {
		character = root
		animation = worry
	}
	right_portrait = { character = scope:sabotage_target_1 }
	lower_right_portrait = { character = scope:sabotage_target_2 }
	lower_left_portrait = { character = scope:sabotage_target_3 }
	cooldown = { years = 1 }

	trigger = {
		#DLC check.
		#has_ep2_dlc_trigger = yes
		
		#Standard checks.
		has_activity_intent = win_contest_intent
		exists = var:contest_aptitude
		scope:activity = {
			any_attending_character = {
				NOT = { this = root }
				exists = var:contest_aptitude
			}
		}
		NOT = { 
			has_variable = contest_sabotage_attempt 
			scope:activity = { has_current_phase = tournament_phase_recital }
		}
	}

	immediate = {
		scope:activity = {
			ordered_attending_character = {
				limit = {
					NOT = { this = root }
					is_in_guest_subset = { name = qualified }
					exists = var:progress_to_victory
				}
				order_by = {
					value = var:progress_to_victory
					if ={
						limit = { root.var:next_versus_match ?= this }
						add = 100
					}
				}
				max = 3
				check_range_bounds = no
				if = {
					limit = {
						NOT = { exists = scope:sabotage_target_1 }
					}
					save_scope_as = sabotage_target_1
				}
				else_if = {
					limit = {
						NOT = { exists = scope:sabotage_target_2 }
					}
					save_scope_as = sabotage_target_2
				}
				else = { save_scope_as = sabotage_target_3 }
				tournament_horse_race_fetch_horse_effect = yes
			}
		}
		if = {
			limit = {
				scope:activity = { has_current_phase = tournament_phase_horse_race }
			}
			tournament_horse_race_fetch_horse_effect = yes
		}
	}

	option = { # Attempt sabotage 1
		name = {
			trigger = {
				scope:activity = { has_current_phase = tournament_phase_horse_race }
			}
			text = tournament_events.6050.a.horse_race
		}
		name = {
			trigger = {
				NOT = {
					scope:activity = { has_current_phase = tournament_phase_horse_race }
				}
			}
			text = tournament_events.6050.a
		}
		trigger = { exists = scope:sabotage_target_1 }
		tournament_win_intent_sabotage_effect = { CHARACTER = scope:sabotage_target_1 }
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_honor = -1
				ai_boldness = 0.5
			}
			opinion_modifier = {
				opinion_target = scope:sabotage_target_1
				multiplier = -0.25
			}
		}
	}

	option = { # Attempt sabotage 2
		name = {
			trigger = {
				scope:activity = { has_current_phase = tournament_phase_horse_race }
			}
			text = tournament_events.6050.b.horse_race
		}
		name = {
			trigger = {
				NOT = {
					scope:activity = { has_current_phase = tournament_phase_horse_race }
				}
			}
			text = tournament_events.6050.b
		}
		trigger = { exists = scope:sabotage_target_2 }
		tournament_win_intent_sabotage_effect = { CHARACTER = scope:sabotage_target_2 }
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_honor = -1
				ai_boldness = 0.5
			}
			opinion_modifier = {
				opinion_target = scope:sabotage_target_2
				multiplier = -0.25
			}
		}
	}

	option = { # Attempt sabotage 3
		name = {
			trigger = {
				scope:activity = { has_current_phase = tournament_phase_horse_race }
			}
			text = tournament_events.6050.c.horse_race
		}
		name = {
			trigger = {
				NOT = {
					scope:activity = { has_current_phase = tournament_phase_horse_race }
				}
			}
			text = tournament_events.6050.c
		}
		trigger = { exists = scope:sabotage_target_3 }
		tournament_win_intent_sabotage_effect = { CHARACTER = scope:sabotage_target_3 }
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_honor = -1
				ai_boldness = 0.5
			}
			opinion_modifier = {
				opinion_target = scope:sabotage_target_3
				multiplier = -0.25
			}
		}
	}

	option = { # Back down
		name = tournament_events.6050.d
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_honor = 1
				ai_boldness = -0.5
			}
		}
	}
}

tournament_events.6051 = { # Sabotage Outcome
	type = activity_event
	title = tournament_events.6051.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:sabotage_flavor = flag:foot }
				desc = tournament_events.6051.foot
			}
			triggered_desc = {
				trigger = { scope:sabotage_flavor = flag:archery }
				desc = tournament_events.6051.archery
			}
			triggered_desc = {
				trigger = { scope:sabotage_flavor = flag:pugilism }
				desc = tournament_events.6051.pugilism
			}
			triggered_desc = {
				trigger = { scope:sabotage_flavor = flag:horse }
				desc = tournament_events.6051.horse
			}
			triggered_desc = {
				trigger = { scope:sabotage_flavor = flag:horse_race }
				desc = tournament_events.6051.horse_race
			}
			triggered_desc = {
				trigger = { scope:sabotage_flavor = flag:falconry }
				desc = tournament_events.6051.falconry
			}
			#EK ADDITION
			triggered_desc = {
				trigger = { scope:sabotage_flavor = flag:magic }
				desc = tournament_events.6051.magic
			}
			#EK ADDITION END
		}
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:sabotage_success }
				desc = tournament_events.6051.success
			}
			triggered_desc = {
				trigger = { exists = scope:sabotage_detected }
				desc = tournament_events.6051.detected
			}
			desc = tournament_events.6051.failure
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:sabotage_detected
					exists = scope:sabotage_disqualified
				}
				desc = tournament_events.6051.disqualified
			}
			triggered_desc = {
				trigger = {
					exists = scope:sabotage_detected
					NOT = { this = scope:host }
				}
				desc = tournament_events.6051.forgiven
			}
		}
	}
	theme = tournament_grounds
	window = widget_activity_locale_fullscreen_event
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = { exists = scope:sabotage_success }
			animation = schadenfreude
		}
		triggered_animation = {
			trigger = {
				NOT = { exists = scope:sabotage_success }
			}
			animation = stress
		}
	}
	lower_left_portrait = {
		trigger = {
			NOT = { this = scope:host }
		}
		character = scope:host
	}
	lower_right_portrait = scope:sabotage_target
	
	override_background = { reference = armory } # TODO_CD_EP2: replace with proper art

	cooldown = { years = 1 }

	trigger = {
		#DLC check.
		#has_ep2_dlc_trigger = yes
	}

	immediate = {
		if = {
			limit = { exists = scope:sabotage_success }
			scope:sabotage_target = {
				activity_tournament_change_contestant_score_effect = { SCORE = decrease_medium }
				add_character_flag = contest_sabotage_target
			}
		}
		else_if = {
			limit = { exists = scope:sabotage_detected }
			progress_towards_rival_effect = {
				REASON = rival_tournament_attempted_sabotage
				CHARACTER = scope:sabotage_target
				OPINION = 0
			}
			reverse_add_opinion = {
				target = scope:sabotage_target
				modifier = tournament_attempted_sabotage_opinion
				opinion = -20
			}
			add_prestige = minor_prestige_loss
			add_character_modifier = {
				modifier = tournament_attempted_sabotage_modifier
				years = 3
			}
			if = {
				limit = {
					NOR = {
						this = scope:host
						exists = scope:sabotage_disqualified
					}
				}
				scope:host = {
					if = {
						limit = { is_ai = yes }
						random_list = {
							100 = {							
								opinion_modifier = {
									who = scope:host
									opinion_target = scope:sabotage_target
								}
								modifier = {
									scope:host = scope:sabotage_target
									add = 200
								}
								save_scope_as = sabotage_disqualified
							}
							50 = {
								opinion_modifier = {
									who = scope:host
									opinion_target = scope:sabotage_actor
								}
								reverse_add_opinion = {
									target = scope:sabotage_target
									modifier = tournament_tolerated_sabotage_opinion
									opinion = -15
								}
							}
						}
					}
					hidden_effect = {
						random = {
							chance = 50
							modifier = {
								scope:host = scope:sabotage_target
								add = 25
							}
							opinion_modifier = {
								who = scope:host
								opinion_target = root
								multiplier = 0.33
							}
							save_scope_as = sabotage_disqualified
						}
					}
				}
			}
		}
		if = {
			limit = { exists = scope:sabotage_disqualified }
			scope:sabotage_actor = { save_scope_as = disqualify_target }
			if = {
				limit = {
					scope:activity = {
						any_guest_subset_current_phase = {
							name = qualified
							this = scope:sabotage_actor
						}
					}
				}
				remove_variable = contest_aptitude
				add_character_flag = {
					flag = resigned_contest_flag
					months = 2
				}
				scope:activity = {
					add_activity_log_entry = {
						key = tournament_disqualified_log
						score = 50
						tags = { contestant removal }
						character = scope:sabotage_actor
						target = scope:host

						# Effects
						custom_description = {
							text =  tournament_contest_disqualify_tt
							subject = scope:sabotage_actor # DISQUALIFIED
						}
						scope:sabotage_actor = {
							if = {
								limit = { is_ai = yes }
								add_opinion = {
									target = scope:host
									modifier = tournament_disqualified_opinion
									opinion = -15
								}
							}
						}
					}
				}
			}
			else = {
				scope:activity = {
					add_activity_log_entry = {
						key = tournament_ejected_log
						score = 50
						tags = { contestant removal }
						character = scope:sabotage_actor
						target = scope:host

						# Effects
						scope:sabotage_actor = {
							remove_from_activity = scope:activity
							if = {
								limit = { is_ai = yes }
								add_opinion = {
									target = scope:host
									modifier = tournament_ejected_opinion
									opinion = -15
								}
							}
						}
					}
				}
			}
		}
	}

	option = {
		name = {
			trigger = { exists = scope:sabotage_success }
			text = tournament_events.6051.a
		}
		name = {
			trigger = { exists = scope:sabotage_disqualified }
			text = tournament_events.6051.a.disqualified
		}
		name = {
			trigger = { exists = scope:sabotage_detected }
			text = tournament_events.6051.a.detected
		}
		name = {
			trigger = {
				NOR = {
					exists = scope:sabotage_success
					exists = scope:sabotage_disqualified
					exists = scope:sabotage_detected
				}
			}
			text = tournament_events.6051.a.failure
		}
	}

	after = {
		if = {
			limit = { exists = scope:sabotage_detected }
			scope:activity = {
				every_attending_character = {
					limit = {
						NOR = {
							this = scope:sabotage_actor
							this = scope:host
						}
						is_ai = no
					}
					trigger_event = tournament_events.6053
				}
			}
		}
	}
}

tournament_events.6052 = { # Host disqualification decision
	type = activity_event
	title = tournament_events.6051.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:sabotage_target = scope:host }
				desc = tournament_events.6052.host
			}
			desc = tournament_events.6052.guest
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:sabotage_flavor
					scope:sabotage_flavor = flag:foot
				}
				desc = tournament_events.6052.foot
			}
			triggered_desc = {
				trigger = {
					exists = scope:sabotage_flavor
					scope:sabotage_flavor = flag:archery
				}
				desc = tournament_events.6052.archery
			}
			triggered_desc = {
				trigger = {
					exists = scope:sabotage_flavor
					scope:sabotage_flavor = flag:pugilism
				}
				desc = tournament_events.6052.pugilism
			}
			triggered_desc = {
				trigger = {
					exists = scope:sabotage_flavor
					scope:sabotage_flavor = flag:horse
				}
				desc = tournament_events.6052.horse
			}
			triggered_desc = {
				trigger = {
					exists = scope:sabotage_flavor
					scope:sabotage_flavor = flag:horse_race
				}
				desc = tournament_events.6052.horse_race
			}
			#EK ADDITION
			triggered_desc = {
				trigger = {
					exists = scope:sabotage_flavor
					scope:sabotage_flavor = flag:magic
				}
				desc = tournament_events.6052.arcane_clash
			}
			#EK ADDITION END
		}
	}
	theme = tournament_grounds
	window = widget_activity_locale_fullscreen_event	
	left_portrait = {
		character = scope:sabotage_target
		animation = anger
	}
	right_portrait = {
		character = scope:sabotage_actor
		animation = stress
	}
	
	override_background = { reference = armory } # TODO_CD_EP2: replace with proper art

	cooldown = { years = 1 }

	trigger = {
		#DLC check.
		#has_ep2_dlc_trigger = yes
	}

	option = { # Disqualify
		name = {
			trigger = {
				scope:activity = {
					any_guest_subset_current_phase = {
						name = qualified
						this = scope:sabotage_actor
					}
				}
			}
			text = tournament_events.6052.a.host
		}
		name = {
			trigger = {
				NOT = {
					scope:activity = {
						any_guest_subset_current_phase = {
							name = qualified
							this = scope:sabotage_actor
						}
					}
				}
			}
			text = tournament_events.6052.a
		}
		if = {
			limit = {
				scope:activity = {
					any_guest_subset_current_phase = {
						name = qualified
						this = scope:sabotage_actor
					}
				}
			}
			scope:activity = {
				switch = {
					trigger = has_current_phase
					# Versus Contests require more specific script
					tournament_phase_joust = {
						tournament_contest_versus_disqualification_effect = { DISQUALIFIED = scope:sabotage_actor MATCH = scope:sabotage_target CONTEST = joust SKILL = horse }
					}
					tournament_phase_wrestling = {
						tournament_contest_versus_disqualification_effect = { DISQUALIFIED = scope:sabotage_actor MATCH = scope:sabotage_target CONTEST = wrestling SKILL = pugilism }
					}
					tournament_phase_duel = {
						tournament_contest_versus_disqualification_effect = { DISQUALIFIED = scope:sabotage_actor MATCH = scope:sabotage_target CONTEST = duel SKILL = foot }
					}
					tournament_phase_board_game = {
						tournament_contest_versus_disqualification_effect = { DISQUALIFIED = scope:sabotage_actor MATCH = scope:sabotage_target CONTEST = board_game SKILL = board_game }
					}
					#EK ADDITION
					tournament_phase_arcane_clash = {
						tournament_contest_versus_disqualification_effect = { DISQUALIFIED = scope:sabotage_actor MATCH = scope:sabotage_target CONTEST = arcane_clash SKILL = magic }
					}
					#EK ADDITION END
					# Non-Versus contests
					fallback = {
						tournament_contest_disqualification_effect = { DISQUALIFIED = scope:sabotage_actor }
					}
				}
			}
		}
		else = {
			scope:sabotage_actor = {
				remove_from_activity = scope:activity
				show_as_tooltip = {
					add_opinion = {
						target = root
						modifier = tournament_ejected_opinion
						opinion = -15
					}
				}
			}
		}
		if = {
			limit = {
				exists = intent_target
				has_activity_intent = befriend_attendee_intent
				intent_target = scope:sabotage_target
			}
			progress_towards_friend_effect = {
				REASON = friend_disqualified_saboteur
				CHARACTER = scope:sabotage_target
				OPINION = default_friend_opinion
			}
		}
		scope:sabotage_actor = { trigger_event = tournament_events.6051 }
		scope:sabotage_actor = {
			accolade_medium_glory_loss_with_checks_effect = yes
		}
		stress_impact = {
			arbitrary = medium_stress_impact_gain
		}
		if = {
			limit = { this = scope:sabotage_target }
			stress_impact = {
				forgiving = medium_stress_impact_gain
			}
		}
		ai_chance = {
			base = 100
			opinion_modifier = {
				who = scope:host
				opinion_target = scope:sabotage_target
				multiplier = 1
			}
			modifier = {
				scope:host = scope:sabotage_target
				add = 200
			}
			ai_value_modifier = {
				ai_honor = 1
			}
		}
	}

	option = { # Forgive
		name = tournament_events.6052.b
		if = {
			limit = {
				NOT = { this = scope:sabotage_target }
			}
			show_as_tooltip = {
				reverse_add_opinion = {
					target = scope:sabotage_target
					modifier = tournament_tolerated_sabotage_opinion
					opinion = -15
				}
			}
		}
		if = {
			limit = {
				exists = intent_target
				has_activity_intent = befriend_attendee_intent
				intent_target = scope:sabotage_actor
			}
			progress_towards_friend_effect = {
				REASON = friend_pardoned_saboteur
				CHARACTER = scope:sabotage_actor
				OPINION = default_friend_opinion
			}
		}
		stress_impact = {
			just = medium_stress_impact_gain
		}
		if = {
			limit = { this = scope:sabotage_target }
			stress_impact = {
				vengeful = medium_stress_impact_gain
			}
		}
		ai_chance = {
			base = 50
			opinion_modifier = {
				who = scope:host
				opinion_target = scope:sabotage_actor
				multiplier = 1
			}
			ai_value_modifier = {
				ai_honor = -1
			}
		}
	}
}

tournament_events.6053 = { # Disqualification ping
	type = activity_event
	title = tournament_events.6053.t
	desc = {
		desc = tournament_events.6053.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:sabotage_flavor = flag:foot
					this = scope:sabotage_target
				}
				desc = tournament_events.6052.foot
			}
			triggered_desc = {
				trigger = { scope:sabotage_flavor = flag:foot }
				desc = tournament_events.6053.foot
			}
			triggered_desc = {
				trigger = {
					scope:sabotage_flavor = flag:archery
					this = scope:sabotage_target
				}
				desc = tournament_events.6052.archery
			}
			triggered_desc = {
				trigger = { scope:sabotage_flavor = flag:archery }
				desc = tournament_events.6053.archery
			}
			triggered_desc = {
				trigger = {
					scope:sabotage_flavor = flag:pugilism
					this = scope:sabotage_target
				}
				desc = tournament_events.6052.pugilism
			}
			triggered_desc = {
				trigger = { scope:sabotage_flavor = flag:pugilism }
				desc = tournament_events.6053.pugilism
			}
			triggered_desc = {
				trigger = {
					scope:sabotage_flavor = flag:horse
					this = scope:sabotage_target
				}
				desc = tournament_events.6052.horse
			}
			triggered_desc = {
				trigger = { scope:sabotage_flavor = flag:horse }
				desc = tournament_events.6053.horse
			}
			triggered_desc = {
				trigger = {
					scope:sabotage_flavor = flag:horse_race
					this = scope:sabotage_target
				}
				desc = tournament_events.6052.horse_race
			}
			triggered_desc = {
				trigger = { scope:sabotage_flavor = flag:horse_race }
				desc = tournament_events.6053.horse_race
			}
			#EK ADDITION
			triggered_desc = {
				trigger = { scope:sabotage_flavor = flag:magic }
				desc = tournament_events.6053.arcane_clash
			}
			#EK ADDITION END
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:sabotage_disqualified
					this = scope:sabotage_target
				}
				desc = tournament_events.6053.disqualified_target
			}
			triggered_desc = {
				trigger = { exists = scope:sabotage_disqualified }
				desc = tournament_events.6053.disqualified
			}
			triggered_desc = {
				trigger = {
					this = scope:sabotage_target
					NOT = { scope:host = scope:sabotage_actor }
				}
				desc = tournament_events.6053.forgiven_target
			}
			triggered_desc = {
				trigger = {
					NOT = { scope:host = scope:sabotage_actor }
				}
				desc = tournament_events.6053.forgiven_target
			}
			
		}
	}
	theme = tournament_grounds
	left_portrait = {
		character = scope:sabotage_actor
		animation = stress
	}
	right_portrait = {
		character = scope:host
		animation = dismissal
		trigger = {
			NOT = { scope:host = scope:sabotage_actor }
		}
	}
	lower_right_portrait = scope:sabotage_target
	window = widget_activity_locale_fullscreen_event

	cooldown = { years = 1 }

	trigger = {
		#DLC check.
		#has_ep2_dlc_trigger = yes
		
		#Standard checks.
	}

	immediate = {
		show_as_tooltip = {
			scope:sabotage_actor = {
				progress_towards_rival_effect = {
					REASON = rival_tournament_attempted_sabotage
					CHARACTER = scope:sabotage_target
					OPINION = 0
				}
				reverse_add_opinion = {
					target = scope:sabotage_target
					modifier = tournament_attempted_sabotage_opinion
					opinion = -20
				}
				add_prestige = minor_prestige_loss
				add_character_modifier = {
					modifier = tournament_attempted_sabotage_modifier
					years = 3
				}
			}
			if = {
				limit = { exists = scope:sabotage_disqualified }
				custom_tooltip = tournament_contest_disqualify_tt
				scope:sabotage_actor = {
					add_opinion = {
						target = scope:host
						modifier = tournament_disqualified_opinion
						opinion = -15
					}
				}
			}
			else_if = {
				limit = {
					NOT = { scope:sabotage_actor = scope:host }
				}
				scope:sabotage_target = {
					add_opinion = {
						target = scope:host
						modifier = tournament_tolerated_sabotage_opinion
						opinion = -15
					}
				}
			}
		}
	}

	option = { # Indeed
		name = tournament_events.6053.a
	}
}

##################################################
# The Things We Do For Love
# by Joe Parkin
# 6500
##################################################

tournament_events.6500 = {
	type = activity_event
	title = tournament_events.6500.t
	desc = tournament_events.6500.desc
	theme = tournament_grounds
	left_portrait = {
		character = root
		animation = flirtation
	}
	right_portrait = {
		character = intent_target
		animation = dismissal
	}
	# TODO_CD_EP2: replace with proper art
	override_background = {
		trigger = {
			OR = {
				AND = {
					is_male = yes
					faith = {
						NOT = { has_doctrine_parameter = adultery_male_accepted }
					}
				}
				AND = {
					is_female = yes
					faith = {
						NOT = { has_doctrine_parameter = adultery_female_accepted }
					}
				}
			}
			OR = {
				is_married = yes
				scope:woo_target = { is_married = yes }
			}
		}
		reference = alley_day
	}
	override_background = {
		trigger = { always = yes }
		reference = terrain_activity
	}
	cooldown = { years = 5 }

	trigger = {
		#DLC check.
		#has_ep2_dlc_trigger = yes
		
		#Standard checks.
		#TODO NOT TEAM PHASE EXISTS
		has_activity_intent = woo_attendee_intent
		intent_target = { is_alive = yes }
		activity_is_valid_tournament_contestant = yes
	}

	immediate = {
		intent_target = { save_scope_as = woo_target }
		add_character_flag = wear_armor
	}

	option = { # Agree
		name = tournament_events.6500.a
		reverse_add_opinion = {
			target = scope:woo_target
			modifier = tournament_vowed_to_lose_opinion
			opinion = 5
		}
		stress_impact = {
			stubborn = medium_stress_impact_gain
			arrogant = medium_stress_impact_gain
			ambitious = medium_stress_impact_gain
			brave = medium_stress_impact_gain
		}
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_compassion = 1
				ai_honor = -1
				ai_energy = -1
			}
		}
	}

	option = { # Refuse
		name = tournament_events.6500.b
		reverse_add_opinion = {
			target = scope:woo_target
			modifier = tournament_refused_to_lose_opinion
			opinion = -10
		}
		stress_impact = {
			fickle = medium_stress_impact_gain
			humble = medium_stress_impact_gain
			content = medium_stress_impact_gain
			craven = medium_stress_impact_gain
		}
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_compassion = -1
				ai_honor = 1
				ai_energy = 1
			}
		}
	}

	after = {
		set_variable = {
			name = vowed_to_lose
			value = scope:woo_target
		}
		remove_character_flag = wear_armor
	}
}

##################################################
# Triumph's Allure
# by Joe Parkin, based on seduce_ongoing.1001
# 6510-11
##################################################

tournament_events.6510 = {
	type = activity_event
	title = tournament_events.6510.t
	desc = {
		desc = tournament_events.6510.opening
		triggered_desc = {
			trigger = {
				exists = scope:woo_target.primary_spouse
				NOT = { is_consort_of = scope:woo_target }
			}
			desc = tournament_events.6510.married
		}
		triggered_desc = {
			trigger = {
				exists = scope:woo_target.primary_spouse
				is_consort_of = scope:woo_target
			}
			desc = tournament_events.6510.currentspouse
		}
		desc = tournament_events.6510.desc
	}
	theme = tournament_grounds
	left_portrait = {
		character = root
		animation = flirtation
	}
	right_portrait = {
		character = scope:woo_target
		animation = happiness
	}
	lower_right_portrait = {
		trigger = { exists = scope:woo_target.primary_spouse }
		character = scope:woo_target.primary_spouse
	}
	cooldown = { years = 1 }

	trigger = {
		#DLC check.
		#has_ep2_dlc_trigger = yes
		
		#Standard checks.
		has_activity_intent = woo_attendee_intent
		intent_target = {
			is_alive = yes
			is_participant_in_activity = scope:activity
		}
		# Has won a contest
		scope:activity = {
			any_guest_subset = {
				name = winner
				this = root
			}
		}
	}

	immediate = {
		save_scope_as = woo_actor
		intent_target = { save_scope_as = woo_target }
		scope:woo_target = { save_scope_as = target }
	}

	option = { # Dedicate victory to target
		name = tournament_events.6510.a
		custom_tooltip = tournament_events.6510.a.tt
		save_scope_value_as = {
			name = woo_approach
			value = flag:dedicate
		}
		stress_impact = {
			callous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = 0.5
			}
		}
	}

	option = { # Dismiss as nothing
		name = tournament_events.6510.b
		custom_tooltip = tournament_events.6510.b.tt
		save_scope_value_as = {
			name = woo_approach
			value = flag:dismiss
		}
		stress_impact = {
			humble = medium_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_boldness = 0.5
			}
		}
	}
	
	option = { # Praise loser
		name = tournament_events.6510.c
		custom_tooltip = tournament_events.6510.c.tt
		save_scope_value_as = {
			name = woo_approach
			value = flag:praise
		}
		stress_impact = {
			arrogant = medium_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_vengefulness = -0.5
			}
		}
	}
	
	option = { # Thank God
		name = tournament_events.6510.d
		custom_tooltip = tournament_events.6510.d.tt
		save_scope_value_as = {
			name = woo_approach
			value = flag:god
		}
		stress_impact = {
			cynical = medium_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_zeal = 0.5
			}
		}
	}

	after = {
		show_as_tooltip = {
			random_list = {
				10 = {
					desc = seduce_ongoing_possible_outcomes_tooltip_effect.success.desc
					show_chance = no
					progress_towards_lover_effect = {
						CHARACTER = scope:woo_target
						OPINION = 15
						REASON =  lover_tournament_victor_impressed
					}
				}
				10 = {
					desc = seduce_ongoing_possible_outcomes_tooltip_effect.failure.desc
					show_chance = no
					reverse_add_opinion = {
						target = scope:woo_target
						modifier = tournament_failed_woo_opinion
						opinion = -10
					}
				}
			}
		}
		scope:woo_target = {
			hidden_effect = {
				#Evaluate what makes for a "right" choice
				if = {
					limit = {
						OR = {
							AND = {
								OR = {
									has_personality_emotional_trigger = yes
									ai_rationality < high_negative_rationality
								}
								exists = scope:woo_approach
								scope:woo_approach = flag:dedicate
							}
							AND = {
								OR = {
									has_personality_extroverted_trigger = yes
									ai_boldness > medium_positive_boldness
								}
								exists = scope:woo_approach
								scope:woo_approach = flag:dismiss
							}
							AND = {
								OR = {
									has_personality_introverted_trigger = yes
									ai_honor > medium_positive_honor
									has_trait = humble
								}
								exists = scope:woo_approach
								scope:woo_approach = flag:praise
							}
							AND = {
								OR = {
									ai_zeal > medium_positive_zeal
									has_trait = zealous
								}
								exists = scope:woo_approach
								scope:woo_approach = flag:god
							}
						}
					}
					save_scope_value_as = {
						name = made_great_choice
						value = yes
					}
				}
				random_list = {
					100 = { #Success
						modifier = {
							add = 100
							exists = scope:woo_approach
							scope:woo_approach = flag:dedicate
							has_trait = compassionate
						}
						modifier = {
							add = 100
							exists = scope:woo_approach
							scope:woo_approach = flag:dismiss
							has_trait = arrogant
						}
						modifier = {
							add = 100
							exists = scope:woo_approach
							scope:woo_approach = flag:praise
							has_trait = humble
						}
						modifier = {
							add = 100
							exists = scope:woo_approach
							scope:woo_approach = flag:god
							has_trait = zealous
						}
						trigger_event = {
							id = tournament_events.6511
							days = { 1 2 }
						}
						scope:woo_actor = {
							trigger_event = {
								id = tournament_events.6513
								days = { 3 4 }
							}
						}
					}
					100 = { #Failure
						trigger = {
							NOT = { exists = scope:made_great_choice }
						}
						modifier = {
							add = 100
							exists = scope:woo_approach
							scope:woo_approach = flag:dedicate
							has_trait = callous
						}
						modifier = {
							add = 100
							exists = scope:woo_approach
							scope:woo_approach = flag:dismiss
							has_trait = humble
						}
						modifier = {
							add = 100
							exists = scope:woo_approach
							scope:woo_approach = flag:praise
							has_trait = arrogant
						}
						modifier = {
							add = 100
							exists = scope:woo_approach
							scope:woo_approach = flag:god
							has_trait = cynical
						}
						trigger_event = {
							id = tournament_events.6512
							days = { 1 2 }
						}
						scope:woo_actor = {
							trigger_event = {
								id = tournament_events.6514
								days = { 3 4 }
							}
						}
					}
				}
			}
		}
	}
}

#Target: Success
tournament_events.6511 = {
	type = activity_event
	title = tournament_events.6510.t
	desc = {
		desc = tournament_events.6511.opening
		first_valid = {
			triggered_desc = {
				trigger = { scope:woo_approach = flag:dedicate }
				desc = tournament_events.6511.dedicate
			}
			triggered_desc = {
				trigger = { scope:woo_approach = flag:dismiss }
				desc = tournament_events.6511.dismiss
			}
			triggered_desc = {
				trigger = { scope:woo_approach = flag:praise }
				desc = tournament_events.6511.praise
			}
			triggered_desc = {
				trigger = { scope:woo_approach = flag:god }
				desc = tournament_events.6511.god
			}
			desc = tournament_events.6511.fallback
		}
	}	
	left_portrait = {
		character = scope:woo_actor
		animation = flirtation
	}
	theme = seduce_scheme

	trigger = { exists = scope:woo_approach }

	option = {
		name = tournament_events.6512.a
		add_stress = minor_stress_loss
		show_as_tooltip = {
			progress_towards_lover_effect = {
				CHARACTER = scope:woo_target
				OPINION = 15
				REASON =  lover_tournament_victor_impressed
			}
		}
	}
}

#Target: Failure
tournament_events.6512 = {
	type = activity_event
	title = tournament_events.6510.t
	desc = {
		desc = tournament_events.6511.opening
		first_valid = {
			triggered_desc = {
				trigger = { scope:woo_approach = flag:dedicate }
				desc = tournament_events.6512.dedicate
			}
			triggered_desc = {
				trigger = { scope:woo_approach = flag:dismiss }
				desc = tournament_events.6512.dismiss
			}
			triggered_desc = {
				trigger = { scope:woo_approach = flag:praise }
				desc = tournament_events.6512.praise
			}
			triggered_desc = {
				trigger = { scope:woo_approach = flag:god }
				desc = tournament_events.6512.god
			}
			desc = tournament_events.6512.fallback
		}
	}
	left_portrait = {
		character = scope:woo_actor
		animation = flirtation
	}
	theme = unfriendly

	trigger = { exists = scope:woo_approach }

	option = {
		name = tournament_events.6512.a
	}
}

#Actor: Success
tournament_events.6513 = {
	type = activity_event
	title = tournament_events.6510.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:woo_approach = flag:dedicate }
				desc = tournament_events.6513.dedicate
			}
			triggered_desc = {
				trigger = { scope:woo_approach = flag:dismiss }
				desc = tournament_events.6513.dismiss
			}
			triggered_desc = {
				trigger = { scope:woo_approach = flag:praise }
				desc = tournament_events.6513.praise
			}
			triggered_desc = {
				trigger = { scope:woo_approach = flag:god }
				desc = tournament_events.6513.god
			}
			desc = tournament_events.6513.fallback
		}
		desc = tournament_events.6513.desc
	}	
	left_portrait = {
		character = scope:woo_target
		animation = flirtation
	}
	theme = seduce_scheme

	trigger = { exists = scope:woo_approach }

	option = {
		name = tournament_events.6513.a
		progress_towards_lover_effect = {
			CHARACTER = scope:woo_target
			OPINION = 15
			REASON = lover_tournament_victor_impressed
		}
	}
}

#Actor: Failure
tournament_events.6514 = {
	type = activity_event
	title = tournament_events.6510.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:woo_approach = flag:dedicate }
				desc = tournament_events.6514.dedicate
			}
			triggered_desc = {
				trigger = { scope:woo_approach = flag:dismiss }
				desc = tournament_events.6514.dismiss
			}
			triggered_desc = {
				trigger = { scope:woo_approach = flag:praise }
				desc = tournament_events.6514.praise
			}
			triggered_desc = {
				trigger = { scope:woo_approach = flag:god }
				desc = tournament_events.6514.god
			}
			desc = tournament_events.6514.fallback
		}
		desc = tournament_events.6514.desc
	}	
	left_portrait = {
		character = scope:woo_target
		#TODO_CD_EP2 awaiting BP1
		# animation = eyeroll
	}
	theme = seduce_scheme

	trigger = { exists = scope:woo_approach }

	option = {
		name = tournament_events.6514.a
		reverse_add_opinion = {
			target = scope:woo_target
			modifier = tournament_failed_woo_opinion
			opinion = -10
		}
	}
}

##################################################
# Local Lancer
# by Joe Parkin
# 6900
##################################################

tournament_events.6900 = {
	type = activity_event
	title = tournament_events.6900.t
	desc = {
		desc = tournament_events.6900.desc
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:attending_culture }
				desc = tournament_events.6900.new
			}
			desc = tournament_events.6900.pool
		}
		desc = tournament_events.6900.closing
	}
	theme = tournament_grounds
	left_portrait = {
		character = scope:local_lancer
		animation = war_over_win
	}
	right_portrait = { character = scope:bidder }
	lower_left_portrait = {
		trigger = {
			NOT = { root = scope:murder_match }
		}
		character = scope:murder_match
	}
	cooldown = { months = 4 }
	
	override_background = { reference = army_camp } # TODO_CD_EP2: replace with proper art

	trigger = {
		#DLC check.
		#has_ep2_dlc_trigger = yes
		
		#Standard checks.
		has_activity_intent = recruit_knights_intent
		scope:activity = {
			any_attending_character = {
				NOR = {
					this = scope:host
					this = root
				}
				is_landed = yes
				is_ai = yes
			}
		}
	}

	immediate = {
		hidden_effect = {
			random_list = {
				50 = {
					trigger = {
						any_pool_guest = {
							prowess >= mediocre_skill_rating
							can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root }
						}
					}
					random_pool_guest = {
						limit = {
							prowess >= mediocre_skill_rating
							can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root }
						}
						weight = {
							base = 1
							modifier = { add = prowess }
							# Weight down a little compared to usual, so that prowess is still a deciding factor.
							activity_recurring_character_weight_modifier = { VALUE = 10 }
						}
						save_scope_as = local_lancer
					}
				}
				50 = {
					scope:activity = {
						random_attending_character = {
							limit = {
								culture = {
									any_culture_county = { count >= 1 }
								}
							}
							culture = { save_scope_as = attending_culture }
						}
					}
					scope:attending_culture = {
						random_culture_county = {
							faith = { save_scope_as = attending_faith }
						}
					}
					create_character = {
						template = tournament_horse_character
						location = scope:activity.activity_location
						culture = scope:attending_culture
						faith = scope:attending_faith
						save_scope_as = local_lancer
					}
					scope:local_lancer = { visit_court_of = scope:host }
				}
			}
		}
		scope:activity = {
			random_attending_character = {
				limit = {
					NOR = {
						this = scope:host
						this = scope:local_lancer
						this = root
					}
					is_landed = yes
					is_ai = yes
				}
				weight = {
					base = 10
					modifier = {
						NOT = { is_vassal_of = root }
						add = 20
					}
					modifier = {
						primary_title.tier = root.primary_title.tier
						add = 20
					}
					modifier = {
						has_activity_intent = recruit_knights_intent
						add = 20
					}
				}
				save_scope_as = bidder
			}
		}
		scope:local_lancer = {
			add_character_flag = wear_armor
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			factor = 2
			has_activity_intent = recruit_knights_intent
		}
	}

	option = { # Outbid
		name = tournament_events.6900.a
		scope:local_lancer = {
			random_list = {
				20 = {
					desc = tournament_events.6900.a.success
					min = 1
					modifier = {
						add = 10
						has_trait = profligate
					}
					modifier = {
						add = 10
						has_trait = improvident
					}
					modifier = {
						add = 10
						gold < 0
					}
					modifier = {
						add = 10
						has_trait = greedy
					}
					opinion_modifier = {
						opinion_target = root
						multiplier = 0.5
					}
					root = {
						send_interface_toast = {
							type = event_toast_effect_good
							title = tournament_events.6900.a.success
							left_icon = scope:local_lancer
							right_icon = scope:bidder
							pay_short_term_gold = {
								target = scope:local_lancer
								gold = minor_gold_value
							}
							scope:local_lancer = { set_employer = root }
							scope:bidder = {
								add_opinion = {
									target = root
									modifier = tournament_lancer_gazumped_opinion
									opinion = -10
								}
							}
						}
					}
				}
				25 = {
					desc = tournament_events.6900.a.failure
					min = 2
					modifier = {
						add = 10
						has_trait = content
					}
					modifier = {
						add = 10
						has_trait = generous
					}
					opinion_modifier = {
						opinion_target = scope:bidder
						multiplier = 0.5
					}
					root = {
						send_interface_toast = {
							type = event_toast_effect_bad
							title = tournament_events.6900.a.failure
							left_icon = scope:local_lancer
							right_icon = scope:bidder
							scope:local_lancer = { set_employer = scope:bidder }
						}
					}
				}
			}
		}
		stress_impact = {
			greedy = medium_stress_impact_gain
		}
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_greed = -1
				ai_boldness = 1
			}
		}
	}

	option = { # Host persuasion
		name = tournament_events.6900.b
		trigger = { scope:bidder.primary_title.tier < root.primary_title.tier }
		scope:local_lancer = {
			random_list = {
				20 = {
					desc = tournament_events.6900.b.success
					min = 1
					modifier = {
						add = 10
						has_trait = comfort_eater
					}
					modifier = {
						add = 10
						has_trait = gluttonous
					}
					modifier = {
						add = 10
						has_trait = gregarious
					}
					opinion_modifier = {
						opinion_target = root
						multiplier = 0.5
					}
					root = {
						send_interface_toast = {
							type = event_toast_effect_good
							title = tournament_events.6900.b.success
							left_icon = scope:local_lancer
							right_icon = scope:bidder
							remove_short_term_gold = tiny_gold_value
							scope:local_lancer = { set_employer = root }
							scope:bidder = {
								add_opinion = {
									target = root
									modifier = tournament_lancer_gazumped_opinion
									opinion = -10
								}
							}
						}
					}
				}
				25 = {
					desc = tournament_events.6900.a.failure
					min = 1
					modifier = {
						add = 10
						has_trait = inappetetic
					}
					modifier = {
						add = 10
						has_trait = temperate
					}
					modifier = {
						add = 10
						has_trait = shy
					}
					opinion_modifier = {
						opinion_target = scope:bidder
						multiplier = 0.5
					}
					root = {
						send_interface_toast = {
							type = event_toast_effect_bad
							title = tournament_events.6900.a.failure
							left_icon = scope:local_lancer
							right_icon = scope:bidder
							scope:local_lancer = { set_employer = scope:bidder }
						}
					}
				}
			}
		}
		stress_impact = {
			arrogant = medium_stress_impact_gain
			greedy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_honor = 0.5
				ai_rationality = 0.5
			}
		}
	}

	option = { # Rank persuasion
		name = tournament_events.6900.c
		trigger = {
			NOT = {
				scope:bidder = { is_vassal_of = root }
			}
			scope:bidder.primary_title.tier < root.primary_title.tier
		}
		scope:local_lancer = {
			random_list = {
				20 = {
					desc = tournament_events.6900.c.success
					min = 1
					modifier = {
						add = 10
						has_trait = arrogant
					}
					modifier = {
						add = 10
						has_trait = ambitious
					}
					modifier = {
						add = 10
						scope:local_lancer = {
							tier_difference = {
								target = root
								value <= -3
							}
						}
					}
					modifier = {
						add = 10
						scope:local_lancer = {
							tier_difference = {
								target = root
								value <= -2
							}
						}
					}
					opinion_modifier = {
						opinion_target = root
						multiplier = 0.5
					}
					root = {
						send_interface_toast = {
							type = event_toast_effect_good
							title = tournament_events.6900.c.success
							left_icon = scope:local_lancer
							right_icon = scope:bidder
							scope:local_lancer = { set_employer = root }
							scope:bidder = {
								add_opinion = {
									target = root
									modifier = tournament_lancer_gazumped_opinion
									opinion = -10
								}
							}
						}
					}
				}
				25 = {
					desc = tournament_events.6900.a.failure
					min = 2
					modifier = {
						add = 10
						has_trait = humble
					}
					modifier = {
						add = 10
						has_trait = content
					}
					opinion_modifier = {
						opinion_target = scope:bidder
						multiplier = 0.5
					}
					root = {
						send_interface_toast = {
							type = event_toast_effect_bad
							title = tournament_events.6900.a.failure
							left_icon = scope:local_lancer
							right_icon = scope:bidder
							scope:local_lancer = { set_employer = scope:bidder }
						}
					}
				}
			}
		}
		stress_impact = {
			humble = medium_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_honor = 0.5
				ai_boldness = 1
			}
		}
	}

	option = { # Vassal tyranny
		name = tournament_events.6900.d
		trigger = {
			scope:bidder = { is_vassal_or_below_of = root }
		}
		scope:local_lancer = { set_employer = root }
		add_tyranny = minor_tyranny_gain
		reverse_add_opinion = {
			target = scope:bidder
			modifier = tournament_lancer_vassal_tyranny_opinion
			opinion = -10
		}
		stress_impact = {
			just = medium_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_honor = -1
				ai_boldness = 1
			}
		}
	}

	option = { # Give up
		name = tournament_events.6900.e
		scope:local_lancer = { set_employer = scope:bidder }
		stress_impact = {
			humble = medium_stress_impact_gain
			generous = medium_stress_impact_gain
			greedy = medium_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_greed = -0.5
				ai_boldness = 1
			}
		}
	}

	after = {
		if = {
			limit = {
				scope:local_lancer = {
					can_join_activity = scope:activity
				}
			}
			scope:local_lancer = {
				hidden_effect = {
					add_to_activity = scope:activity
				}
			}
		}
		scope:local_lancer = {
			remove_character_flag = wear_armor
		}
		random_list = {
			1 = {
				try_to_create_recurring_character_effect = { CHARACTER = scope:local_lancer }
			}
			1 = {
				try_to_create_recurring_character_effect = { CHARACTER = scope:bidder }
			}
		}
	}
}

# Make a man out of you
# by Nick Meredith
tournament_events.7000 = {
	type = activity_event
	title = tournament_events.7000.t
	desc = tournament_events.7000.desc
	theme = tournament_grounds
	left_portrait = {
		character = root
		animation = worry
	}
	right_portrait = {
		character = scope:mulan
		animation = throne_room_bow_2
	}
	cooldown = { years = 1 }

	trigger = {
		is_ai = no #Make this only trigger for players, lest we have a few too many Mulans wandering about!

		scope:activity = {
			any_attending_character = {
				count < 240 #Max is 250, leaving some space for stragglers
			}
		}

		#Make sure that at least one gender is dominant for martial rules
		OR = {
			AND = {
				scope:host.culture = { has_cultural_parameter = martial_custom_female_only_combatant }
				culture = { has_cultural_parameter = martial_custom_female_only_combatant }
			}
			AND = {
				scope:host.culture = { has_cultural_parameter = martial_custom_male_only_combatant }
				culture = { has_cultural_parameter = martial_custom_male_only_combatant }
			}
			AND = {
				scope:host.faith = { has_doctrine_parameter = combatant_must_be_female_if_no_roco }
				faith = { has_doctrine_parameter = combatant_must_be_female_if_no_roco }
			}
			AND = {
				scope:host.faith = { has_doctrine_parameter = combatant_must_be_male_if_no_roco }
				faith = { has_doctrine_parameter = combatant_must_be_male_if_no_roco }
			}
		}
	}

	immediate = {
		scope:activity = {
			random_attending_character = {
				culture = { save_scope_as = attending_culture }
			}
		}
		scope:attending_culture = {
			random_culture_county = {
				faith = { save_scope_as = attending_faith }
			}
		}
		create_character = {
			template = tournament_mulan_character
			location = scope:activity.activity_location
			culture = scope:attending_culture
			faith = scope:attending_faith
			dynasty = none
			save_scope_as = mulan
		}
		scope:mulan = { visit_court_of = scope:host }

		if = {
			limit = {
				scope:mulan = {
					NOT = {
						can_be_combatant_based_on_gender_trigger = {
							ARMY_OWNER = root
						}
					}
				}
			}
			scope:mulan = {
				add_character_modifier = ignores_gender_army_rules
			}
		}
		scope:mulan = {
			add_character_flag = wear_armor
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			factor = 2
			has_activity_intent = recruit_knights_intent
		}
	}

	option = { # Keep their secret
		name = tournament_events.7000.a

		scope:mulan = {
			hidden_effect = {
				add_to_activity = scope:activity
				scope:activity = {
					add_to_guest_subset = {
						name = contestant
						target = scope:mulan						
					}
				}
			}
			custom_tooltip = tournament_events.7000.a.tt
			try_to_create_recurring_character_effect = { CHARACTER = root }
		}
		reverse_add_opinion = {
			modifier = grateful_opinion
			target = scope:mulan
			opinion = 20
		}
		stress_impact = {
			trusting = miniscule_stress_impact_loss
			content = miniscule_stress_impact_loss
			ambitious = minor_stress_impact_gain
			paranoid = minor_stress_impact_gain
		}
		ai_chance = {
			base = 5
			ai_value_modifier = {
				ai_compassion = 1.5
				ai_greed = -1.5
			}
		}
	}

	option = { # Recruit
		name = tournament_events.7000.b

		pay_short_term_gold = {
			target = scope:mulan
			gold = {
				value = minor_gold_value
				max = 20
			}
		}
		hidden_effect = { add_courtier = scope:mulan }
		scope:mulan = {
			hidden_effect = {
				add_to_court_and_entourage_effect = yes
				return_to_court = yes
				set_knight_status = force
			}
			custom_tooltip = ignores_gender_army_rules_tt
			custom_tooltip = tournament_events.7000.a.tt
			custom_tooltip = tournament_events.7000.b.tt
			try_to_create_recurring_character_effect = { CHARACTER = root }
		}

		add_character_flag = knows_mulan_flag #Needed for ep2_tournament_events.1015	

		reverse_add_opinion = {
			modifier = grateful_opinion
			target = scope:mulan
			opinion = 40
		}
		stress_impact = {
			trusting = miniscule_stress_impact_loss
			content = miniscule_stress_impact_loss
			ambitious = medium_stress_impact_gain
			paranoid = medium_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_compassion = 2
				ai_greed = -2
			}
		}
	}

	option = { # Reveal them
		name = tournament_events.7000.c
		if = {
			limit = { activity_is_competing_trigger = yes }
			activity_tournament_change_contestant_score_effect = { SCORE = increase_minor }
		}
		scope:mulan = {
			show_as_tooltip = {
				banish = yes
			}
			move_to_pool = yes
			silent_disappearance_effect = yes
		}
		stress_impact = {
			ambitious = miniscule_stress_impact_loss
			paranoid = miniscule_stress_impact_loss
			content = medium_stress_impact_gain
		}
		ai_chance = {
			base = 20
			ai_value_modifier = {
				ai_boldness = 1
				ai_rationality = -1
				ai_compassion = -1
				ai_greed = 1
			}
		}
	}
	after = {
		scope:mulan = {
			remove_character_flag = wear_armor
		}
	}
}
