﻿# FEAST ACTIVITY KEY EVENTS
# Most custom variables checked here will have been set by the "welcoming" events in feast_activity_standard_events

namespace = feast_main_stable_breakin



######################
# STABLE BREAK-IN
# by Petter Vilberg
######################
# Some guests break into the host's stables and drunkenly ride around on animals.

# Trigger and weight event
feast_main_stable_breakin.0001 = {
	type = activity_event

	hidden = yes

	trigger = {
		trigger_if = {
			limit = {
				scope:activity.activity_host = { has_variable = last_feast_was }
			}
			NOT = { scope:activity.activity_host.var:last_feast_was = flag:stable_breakin }
		}
		scope:activity = {
			any_attending_character = {
				feast_default_participant_including_player_trigger = yes
				NOT = { has_trait = temperate }
				this != scope:activity.activity_host
			}
		}
	}

	immediate = {
		scope:activity = {
			# Someone to be responsible for the break-in.
			random_attending_character = {
				# Either someone who fits the bill
				limit = {
					feast_default_participant_including_player_trigger = yes
					OR = {
						has_trait = lifestyle_reveler
						has_trait = lunatic
						has_trait = shrewd
					}
					this != scope:activity.activity_host
				}
				# Or just someone who's had a little too much to drink
				alternative_limit = {
					feast_default_participant_including_player_trigger = yes
					NOT = { has_trait = temperate }
					this != scope:activity.activity_host
				}
				save_scope_as = breakin_stager
			}

			# If someone is unfortunate enough to be a deviant in the wrong place at the wrong time...
			random_attending_character = {
				limit = {
					feast_default_participant_including_player_trigger = yes
					OR = {
						has_trait = deviant
						any_secret = {
							type = secret_deviant
						}
					}
					NOR = {
						this = scope:breakin_stager
						this = scope:activity.activity_host
					}
				}

				save_scope_as = breakin_deviant

				random = {
					chance = 30
					modifier = {
						add = 20
						scope:breakin_deviant = {
							has_trait = lustful
						}
					}
					scope:activity = {
						set_variable = {
							name = deviant_discovered
							value = yes
						}
					}
				}

			}


			# If there's no deviant, make sure the stager has support from someone
			if = {
				limit = {
					NOT = {
						exists = scope:breakin_deviant
					}
				}
				random_attending_character = {
					limit = {		# A Master of the Horse is the perfect accomplice! 
						feast_default_participant_including_player_trigger = yes
						has_court_position = master_of_horse_court_position
					}
					alternative_limit = {
						feast_default_participant_including_player_trigger = yes
						this != scope:breakin_stager
						this != scope:activity.activity_host
					}

					save_scope_as = breakin_helper
				}
			}

			# We need at least one more bystander, if there are enough guests
			random_attending_character = {
				limit = {
					feast_default_participant_including_player_trigger = yes
					NOR = {
						this = scope:breakin_stager
						AND = {
							exists = scope:breakin_deviant
							this = scope:breakin_deviant
						}
						AND = {
							exists = scope:breakin_helper
							this = scope:breakin_helper
						}
					}
					this != scope:activity.activity_host

				}
				save_scope_as = breakin_bystander
			}

			every_attending_character = {
				limit = {
					feast_default_participant_including_player_trigger = yes
					NOR = {
						this = scope:breakin_stager
						AND = {
							exists = scope:breakin_bystander
							this = scope:breakin_bystander
						}
						AND = {
							exists = scope:breakin_deviant
							this = scope:breakin_deviant
						}
						AND = {
							exists = scope:breakin_helper
							this = scope:breakin_helper
						}
					}
					this != scope:activity.activity_host
				}

				trigger_event = feast_main_stable_breakin.0002
			}

			activity_host = {
				set_variable = {
					name = last_feast_was
					value = flag:stable_breakin
				}
				trigger_event = feast_main_stable_breakin.0003
				
			}

			if = {
				limit = { exists = scope:breakin_bystander }
				scope:breakin_bystander = {
					trigger_event = feast_main_stable_breakin.0007
				}
			}
			# If the one causing the break-in is not also a deviant, the stager gets their event.
			scope:breakin_stager = {	
				trigger_event = feast_main_stable_breakin.0004
			}
			if = {
				limit = {
					exists = scope:breakin_deviant
					scope:breakin_deviant != scope:breakin_stager
				}
				scope:breakin_deviant = {
					trigger_event = feast_main_stable_breakin.0005
				}
			}
			if = {
				limit = { exists = scope:breakin_helper }
				scope:breakin_helper = {
					trigger_event = feast_main_stable_breakin.0006
				}
			}
		}
	}
}



###
# Generic guest event
###
feast_main_stable_breakin.0002 = {
	type = activity_event
	title = feast_main_stable_breakin.0002.t
	desc = {
		# Pick out who the introduction describes the stager as acting with
		first_valid = {
			triggered_desc = {
				# The helper that is chosen if no deviant.
				trigger = {
					exists = scope:breakin_helper
				}
				desc = feast_main_stable_breakin.0002.breakin_with_helper
			}
			triggered_desc = {
				# The deviant, so they are partly responsible for their own demise
				trigger = {
					exists = scope:breakin_deviant
					scope:breakin_deviant != scope:breakin_stager
				}
				desc = feast_main_stable_breakin.0002.breakin_with_deviant
			}
			# A fallback in case your feast doesn't have that many guests.
			desc = feast_main_stable_breakin.0002.breakin_with_noone
		}
		triggered_desc = {
			# Some more fun if there are enough feast participants to sustain it.
			trigger = {
				exists = scope:breakin_bystander
			}
			desc = feast_main_stable_breakin.0002.bystander_riding
		}
		first_valid = {
			# If the deviant is discovered doing deviant things.
			triggered_desc = {
				trigger = {
					scope:activity = { has_variable = deviant_discovered }
				}
				desc = feast_main_stable_breakin.0002.deviant_discovered
			}
			# A signoff in case there is no deviant discovery.
			#desc = feast_main_stable_breakin.0002.what_a_silly_bunch
		}
	}
	theme = feast_activity
	left_portrait = {
		character = scope:activity.activity_host
		animation = shock
	}
	right_portrait = {
		character = scope:breakin_stager
		animation = jockey_victory
		camera = camera_event_horse_right
	}
	lower_center_portrait = scope:breakin_helper
	lower_right_portrait = scope:breakin_deviant

	option = {
		name = feast_main_stable_breakin.0002.a
		trigger = {
			NOT = {
				scope:activity = { has_variable = deviant_discovered }
			}
		}
		add_character_modifier = {
			modifier = feast_livestock_at_feast_modifier
			years = 5
		}
	}

	option = {
		name = feast_main_stable_breakin.0002.b
		trigger = {
			exists = scope:activity.var:deviant_discovered
			NOR = {
				has_trait = deviant
				any_secret = {
					type = secret_deviant
				}
			}
		}
		add_character_modifier = {
			modifier = feast_livestock_at_feast_modifier
			years = 5
		}
		show_as_tooltip = {
			scope:breakin_deviant = {
				add_prestige = major_prestige_loss
			}
		}
	}

	option = {
		name = feast_main_stable_breakin.0002.secret_of_my_own
		trigger = {
			exists = scope:activity.var:deviant_discovered
			OR = {
				has_trait = deviant
				any_secret = {
					type = secret_deviant
				}
			}
		}
		scope:breakin_deviant = {
			add_opinion = {
				target = root
				modifier = respect_opinion
				opinion = 20
			}
		}
		progress_towards_friend_effect = {
			REASON = friend_fellow_deviant
			CHARACTER = scope:breakin_deviant
			OPINION = 0
		}
		hidden_effect = {
			add_opinion = {
				target = scope:breakin_deviant
				modifier = pity_opinion
				opinion = 20
			}
		}
	}
}


###
# Host event
###
feast_main_stable_breakin.0003 = {
	title = feast_main_stable_breakin.0003.t
	type = activity_event
	desc = {
		# Pick out who the introduction describes the stager as acting with
		first_valid = {
			triggered_desc = {
				# The helper that is chosen if no deviant.
				trigger = {
					exists = scope:breakin_helper
				}
				desc = feast_main_stable_breakin.0003.breakin_with_helper
			}
			triggered_desc = {
				# The deviant, so they are partly responsible for their own demise
				trigger = {
					exists = scope:breakin_deviant
					scope:breakin_deviant != scope:breakin_stager
				}
				desc = feast_main_stable_breakin.0003.breakin_with_deviant
			}
			# A fallback in case your feast doesn't have that many guests.
			desc = feast_main_stable_breakin.0003.breakin_with_noone
		}
		triggered_desc = {
			# Some more fun if there are enough feast participants to sustain it.
			trigger = {
				exists = scope:breakin_bystander
			}
			desc = feast_main_stable_breakin.0003.bystander_riding
		}
		first_valid = {
			# If the deviant is discovered doing deviant things.
			triggered_desc = {
				trigger = {
					scope:activity = {
						has_variable = deviant_discovered
					}
				}
				desc = feast_main_stable_breakin.0003.deviant_discovered
			}
			# A signoff in case there is no deviant discovery.
			#desc = feast_main_stable_breakin.0003.what_a_silly_bunch
		}
	}
	theme = feast_activity
	left_portrait = {
		character = scope:breakin_stager
		animation = jockey_victory
		camera = camera_event_horse_left
	}
	right_portrait = {
		character = scope:breakin_helper
		animation = shame
	}
	lower_right_portrait = scope:breakin_deviant

	immediate = {
		play_music_cue = mx_cue_meadandwine
	}
	
	option = {
		name = feast_main_stable_breakin.0003.a
		add_prestige = minor_prestige_loss
		add_character_modifier = {
			modifier = feast_livestock_at_feast_modifier
			years = 10
		}
	}

	after = {
		hidden_effect = {
			# Activity End Event setup
			trigger_event = {
				id = feast_main_stable_breakin.9000
				days = 10
			}
			scope:activity = {
				add_activity_log_entry = {
					key = feast_stable_breakin_log
					tags = { good }
					score = 25
					character = root
					target = scope:breakin_stager
				}
			}
		}
	}

}


####
# Stager event
####
feast_main_stable_breakin.0004 = {
	title = feast_main_stable_breakin.0004.t
	desc = {
		# Start the event by describing who planted the idea.
		first_valid = {
			# The "regular" helper
			triggered_desc = {
				trigger = {
					exists = scope:breakin_helper
				}
				desc = feast_main_stable_breakin.0004.breakin_with_helper
			}
			# The deviant, though you may not know.
			triggered_desc = {
				trigger = {
					exists = scope:breakin_deviant
					scope:breakin_deviant != scope:breakin_stager
				}
				desc = feast_main_stable_breakin.0004.breakin_with_deviant
			}
			# You've come up with the idea all on your own. Sorry, no excuses!
			desc = feast_main_stable_breakin.0004.breakin_with_noone
		}
		# If someone goes crazy
		triggered_desc = {
			trigger = {
				exists = scope:breakin_bystander
			}
			desc = feast_main_stable_breakin.0004.bystander_riding
		}
		# Signoff based on whether the deviant makes poor choices.
		first_valid = {
			# If a deviant is discovered, the stager should also get to know about it.
			triggered_desc = {
				trigger = {
					scope:activity = { has_variable = deviant_discovered }
				}
				desc = feast_main_stable_breakin.0004.deviant_discovered
			}
			# Regular signoff.
			desc = feast_main_stable_breakin.0004.signoff
		}
	}
	theme = feast_activity
	left_portrait = {
		character = scope:activity.activity_host
		animation = shock
	}
	right_portrait = {
		character = scope:breakin_helper
		animation = shame
	}
	lower_center_portrait = scope:breakin_bystander
	lower_right_portrait = scope:breakin_deviant

	option = {
		name = feast_main_stable_breakin.0004.a
		add_prestige = minor_prestige_loss
		increase_wounds_effect = { REASON = horse_riding_accident }
	}
}



###
# Deviant event
###
feast_main_stable_breakin.0005 = {
	title = feast_main_stable_breakin.0005.t
	desc = {
		# Deviant shares a good idea with the stager.
		desc = feast_main_stable_breakin.0005.breakin
		# Things go a little crazy.
		triggered_desc = {
			trigger = {
				exists = scope:breakin_bystander
				scope:activity = { has_variable = deviant_discovered }
			}
			desc = feast_main_stable_breakin.0005.bystander_riding
		}
		first_valid = {
			# Uh-oh.
			triggered_desc = {
				trigger = {
					scope:activity = { NOT = { has_variable = deviant_discovered } }
				}
				desc = feast_main_stable_breakin.0005.deviant_discovered
			}
			# Nothing happened, or...?
			desc = feast_main_stable_breakin.0005.got_away_with_it
		}
	}
	theme = feast_activity
	left_portrait = {
		character = scope:activity.activity_host
		animation = shock
	}
	right_portrait = {
		character = scope:breakin_stager
		animation = jockey_victory
		camera = camera_event_horse_right
	}
	lower_center_portrait = scope:breakin_helper
	lower_right_portrait = scope:breakin_bystander

	option = {
		name = feast_main_stable_breakin.0005.a
		add_prestige = major_prestige_loss
		if = {
			limit = {
				any_secret = {
					type = secret_deviant
				}
				scope:activity = { has_variable = deviant_discovered }
			}
			random_secret = {
				type = secret_deviant
				expose_secret = scope:activity.activity_host
			}
		}
	}
}



###
# Helper event
###
feast_main_stable_breakin.0006 = {
	title = feast_main_stable_breakin.0006.t
	type = activity_event
	desc = {
		# Helping the stager break in, then having fun.
		desc = feast_main_stable_breakin.0006.breakin_with_helper
		# Other people might be having fun, too!
		triggered_desc = {
			trigger = {
				exists = scope:breakin_bystander
				scope:activity = { NOT = { has_variable = deviant_discovered } }
			}
			desc = feast_main_stable_breakin.0006.bystander_riding
		}
		first_valid = {
			# Some people might be having a little too much fun.
			triggered_desc = {
				trigger = {
					scope:activity = { has_variable = deviant_discovered }
				}
				desc = feast_main_stable_breakin.0006.deviant_discovered
			}
			# Everything happens to be at the right level of fun.
			desc = feast_main_stable_breakin.0006.all_in_good_fun
		}
	}
	theme = feast_activity
	left_portrait = {
		character = scope:activity.activity_host
		animation = shock
	}
	right_portrait = {
		character = scope:breakin_stager
		animation = jockey_victory
		camera = camera_event_horse_right
	}
	lower_center_portrait = scope:breakin_bystander
	lower_right_portrait = scope:breakin_deviant

	option = {
		name = feast_main_stable_breakin.0006.a
		scope:breakin_stager = {
			add_opinion = {
				target = root
				modifier = feast_helped_during_breakin
			}
		}
		if = {
			limit = { exists = scope:breakin_bystander }
			scope:breakin_bystander = {
				add_opinion = {
					target = root
					modifier = feast_helped_during_breakin
				}
			}
		}
		if = {
			limit = {
				exists = scope:breakin_deviant
			}
			scope:breakin_deviant = {
				add_opinion = {
					target = root
					modifier = feast_helped_during_breakin
				}
			}
		}
	}
}


###
# Bystander event
###
feast_main_stable_breakin.0007 = {
	title = feast_main_stable_breakin.0007.t
	type = activity_event
	desc = {
		# The stager is mainly responsible themselves.
		desc = feast_main_stable_breakin.0007.breakin
		# Root is having so much fun!
		desc = feast_main_stable_breakin.0007.bystander_riding
		first_valid = {
			# Uuuuh, deviant doing their thing is highly unfortunate.
			triggered_desc = {
				trigger = {
					scope:activity = { has_variable = deviant_discovered }
				}
				desc = feast_main_stable_breakin.0007.deviant_discovered
			}
			# What a great time we had.
			desc = feast_main_stable_breakin.0007.what_a_silly_bunch
		}
	}
	theme = feast_activity
	left_portrait = {
		character = scope:activity.activity_host
		animation = shock
	}
	right_portrait = {
		character = scope:breakin_stager
		animation = jockey_victory
		camera = camera_event_horse_right
	}
	lower_center_portrait = scope:breakin_helper
	lower_right_portrait = scope:breakin_deviant

	option = {
		name = feast_main_stable_breakin.0007.a
		add_prestige = minor_prestige_loss
		scope:breakin_stager = {
			add_opinion = {
				target = root
				modifier = feast_helped_during_breakin
			}
		}
		if = {
			limit = {
				exists = scope:breakin_deviant
			}
			scope:breakin_deviant = {
				add_opinion = {
					target = root
					modifier = feast_helped_during_breakin
				}
			}
		}
	}
}


##################
# END EVENT SETUP
##################
feast_main_stable_breakin.9000 = {
	type = activity_event

	hidden = yes

	trigger = {
		exists = scope:activity
	}

	immediate = {
		scope:activity = {

			# Set up scopes
			activity_host = {
				save_scope_as = host_saying_goodbye
				if = {
					limit = { exists = primary_partner }
					random_consort = {
						limit = {
							this = scope:activity.activity_host.primary_partner
							is_available_ai = yes
						}
						alternative_limit = {
							is_available_ai = yes
						}
						save_scope_as = spouse
					}
				}
			}
	
			# Fire the end event for every participant except specials
			every_attending_character = {
				limit = {
					feast_default_participant_including_player_trigger = yes
					NOR = {
						this = scope:activity.activity_host
						this = scope:breakin_stager
						AND = {
							exists = scope:breakin_helper
							this = scope:breakin_helper
						}
						AND = {
							exists = scope:breakin_bystander
							this = scope:breakin_bystander
						}
						AND = {
							exists = scope:breakin_deviant
							this = scope:breakin_deviant
						}
					}
				}
				trigger_event = feast_main_stable_breakin.9001
			}
	
			# Fire special guest end events
			every_attending_character = {
				limit = {
					feast_default_participant_including_player_trigger = yes
					OR = {
						this = scope:breakin_stager
						AND = {
							exists = scope:breakin_helper
							this = scope:breakin_helper
						}
						AND = {
							exists = scope:breakin_bystander
							this = scope:breakin_bystander
						}
						AND = {
							exists = scope:breakin_deviant
							this = scope:breakin_deviant
						}
					}
				}
				trigger_event = feast_main_stable_breakin.9003
			}

			if = {
				limit = {
					exists = scope:breakin_deviant
				}
				scope:breakin_deviant = {
					trigger_event = feast_main_stable_breakin.9004
					if = {
						limit = { exists = scope:activity.var:deviant_discovered }
						set_variable = {
							name = was_i_discovered
							value = scope:activity.var:deviant_discovered
						}
					}
				}
			}
			activity_host = { trigger_event = feast_main_stable_breakin.9002 }
		}
	}
}


###################
# Guest End event
###################
feast_main_stable_breakin.9001 = {
	type = activity_event
	title = feast_main_stable_breakin.9001.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:breakin_deviant
					scope:breakin_deviant = {
						has_variable = was_i_discovered
					}
				}
				desc = feast_main_stable_breakin.9001.deviant_caught
			}
			desc = feast_main_stable_breakin.9001.in_good_fun
		}
	}
	theme = feast_activity
	left_portrait = {
		character = scope:host_saying_goodbye
		animation = happiness
	}
	center_portrait = {
		character = scope:spouse
		animation = personality_bold
	}
	right_portrait = {
		character = scope:breakin_stager
		animation = jockey_idle
		camera = camera_event_horse_right
	}
	lower_center_portrait = scope:breakin_deviant
	lower_right_portrait = scope:breakin_bystander

	option = {
		name = feast_main_stable_breakin.9001.a
		stress_impact = {
			base = medium_stress_impact_loss
		}
	}
}


######################
# Host End event
######################
feast_main_stable_breakin.9002 = {
	type = activity_event
	title = feast_main_stable_breakin.9001.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:breakin_deviant
					scope:breakin_deviant = { has_variable = was_i_discovered }
				}
				desc = feast_main_stable_breakin.9002.deviant_caught
			}
			triggered_desc = {
				trigger = {
					exists = scope:breakin_deviant
					scope:breakin_deviant = {
						NOT = { has_variable = was_i_discovered }
					}
				}	
				desc = feast_main_stable_breakin.9002.in_good_fun_or_what
			}
			desc = feast_main_stable_breakin.9002.in_good_fun
		}
	}
	theme = feast_activity
	right_portrait = {
		character = scope:breakin_stager
		animation = wedding_drunk
	}
	center_portrait = {
		character = scope:breakin_bystander
		animation = personality_bold
	}
	left_portrait = {
		character = root
		animation = happiness
	}
	lower_center_portrait = scope:breakin_deviant

	option = {
		name = feast_main_stable_breakin.9002.a
		stress_impact = {
			base = medium_stress_impact_loss
		}
	}

}


########################
# Stager, helper and bystander end event
########################
feast_main_stable_breakin.9003 = {
	type = activity_event
	title = feast_main_stable_breakin.9001.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:breakin_deviant
					scope:breakin_deviant = {
						has_variable = was_i_discovered
					}
				}
				desc = feast_main_stable_breakin.9003.deviant_caught
			}
			desc = feast_main_stable_breakin.9003.in_good_fun
		}
	}
	theme = feast_activity
	left_portrait = {
		character = scope:host_saying_goodbye
		animation = happiness
	}
	right_portrait = {
		character = scope:spouse
		animation = personality_bold
	}

	option = {
		name = feast_main_stable_breakin.9003.a
		stress_impact = {
			base = medium_stress_impact_loss
		}
	}
}


#####################
# Deviant end event
#####################
feast_main_stable_breakin.9004 = {
	type = activity_event
	title = feast_main_stable_breakin.9001.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:breakin_deviant
					scope:breakin_deviant = {
						has_variable = was_i_discovered
					}
				}
				desc = feast_main_stable_breakin.9004.deviant_caught
			}
			desc = feast_main_stable_breakin.9004.in_good_fun
		}
	}
	theme = feast_activity
	left_portrait = {
		character = scope:host_saying_goodbye
		animation = happiness
	}
	right_portrait = {
		character = scope:spouse
		animation = personality_bold
	}

	option = {
		name = feast_main_stable_breakin.9004.a
		if = {
			limit = { NOT = { exists = var:was_i_discovered } }
			feast_end_guest_effect = yes
		}
		else = {
			stress_impact = {
				deviant = medium_stress_impact_gain
			}
		}
	}
}
